From nobody Wed May 1 22:14:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1516027618723352.8715403223006; Mon, 15 Jan 2018 06:46:58 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 957812094561A; Mon, 15 Jan 2018 06:41:38 -0800 (PST) Received: from mail-pl0-x244.google.com (mail-pl0-x244.google.com [IPv6:2607:f8b0:400e:c01::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BD29C222DDBF2 for ; Mon, 15 Jan 2018 06:41:36 -0800 (PST) Received: by mail-pl0-x244.google.com with SMTP id 66so3878973plc.13 for ; Mon, 15 Jan 2018 06:46:54 -0800 (PST) Received: from localhost.localdomain ([119.145.15.121]) by smtp.gmail.com with ESMTPSA id f78sm15989889pfk.144.2018.01.15.06.46.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Jan 2018 06:46:53 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c01::244; helo=mail-pl0-x244.google.com; envelope-from=heyi.guo@linaro.org; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=idAkWO7mHWOmHWXXyVjPV5GVOReD6Yc7gMWjsDGFXHY=; b=FxFmChQt+D61aw7XO1dr51pO6RbJ306zXuEe3u7L3kEGhrXEo7mRY0a7PT81jntSrz mBwrx8/uAzrSoWOdPRfH1srzlRt35qsCnerL9cjrZxgWGWR543gsjLnvcFtrXcYDeqGX P81d+VMwfVS2cNCLeXb+alG6WnwKTmg4GY1fU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=idAkWO7mHWOmHWXXyVjPV5GVOReD6Yc7gMWjsDGFXHY=; b=H9scNdNTfOo4nIGm8DuvYoNvaUKt6N39dnSm/eVlMWdgdn7tzrdZQVPwzqM0yBfrQd GjD15x7HcH5UiC+Q/An7nbjk2ZZwSaElz/Ur/+Gr38wB/r1mhhN9Q9vkSMCJhtJ124Tn fJzhzfsxaHGCG2CyZFHvh+V6BUmqDTYHfH5MJey2mLQgTdgW8kJ+WYxiff8fOMVEDnBG d2r6oikSQGzPhEq6yU4or7g6OPiNEAiiRyKj7YinP9OTEDTj1niidEmGKyzIY8PRFGio fe7v70xJlkXrtrI/kLhbhWr6oWZ76ip1nZVkYDC/cv2X2rANZfe3fHT2VcDfi2elkL0P WGDw== X-Gm-Message-State: AKwxytdtTLDvNNGTrG4MAwkeZ30tn3xcI99sH3Okzcvq47lkBJZlyZzN ZKA/e7CnCWSXNe12KG6P9IYaEg== X-Google-Smtp-Source: ACJfBot3pdxjypv7XZY4Ca4ies39zKPcTcPGVds69TQHJCFAFyrwZA7Alm0pIdHv3P2EhAe34LDOVA== X-Received: by 10.159.218.4 with SMTP id v4mr11798747plp.252.1516027614229; Mon, 15 Jan 2018 06:46:54 -0800 (PST) From: Heyi Guo To: linaro-uefi@lists.linaro.org, edk2-devel@lists.01.org Date: Mon, 15 Jan 2018 22:46:40 +0800 Message-Id: <1516027600-32172-1-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [edk2] [RFC] MdeModulePkg/PciHostBridgeDxe: Add support for address translation X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Heyi Guo , Eric Dong , Star Zeng , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is the draft patch for the discussion posted in edk2-devel mailing list: https://lists.01.org/pipermail/edk2-devel/2017-December/019289.html As discussed in the mailing list, we'd like to add support for PCI address translation which is necessary for some non-x86 platforms. I also want to minimize the changes to the generic host bridge driver and platform PciHostBridgeLib implemetations, so additional two interfaces are added to expose translation information of the platform. To be generic, I add translation for each type of IO or memory resources. The patch is still a RFC, so I only passed the build for qemu64 and the function has not been tested yet. Please let me know your comments about it. Thanks. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Heyi Guo Cc: Ruiyu Ni Cc: Ard Biesheuvel Cc: Star Zeng Cc: Eric Dong --- .../FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 19 ++++ .../Bus/Pci/PciHostBridgeDxe/PciHostBridge.c | 53 ++++++++--- .../Bus/Pci/PciHostBridgeDxe/PciRootBridge.h | 8 +- .../Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c | 101 +++++++++++++++++= +--- MdeModulePkg/Include/Library/PciHostBridgeLib.h | 36 ++++++++ 5 files changed, 192 insertions(+), 25 deletions(-) diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b= /ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c index 5b9c887..0c8371a 100644 --- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c +++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c @@ -360,6 +360,16 @@ PciHostBridgeGetRootBridges ( return &mRootBridge; } =20 +PCI_ROOT_BRIDGE_TRANSLATION * +EFIAPI +PciHostBridgeGetTranslations ( + UINTN *Count + ) +{ + *Count =3D 0; + return NULL; +} + /** Free the root bridge instances array returned from PciHostBridgeGetRootBridges(). @@ -377,6 +387,15 @@ PciHostBridgeFreeRootBridges ( ASSERT (Count =3D=3D 1); } =20 +VOID +EFIAPI +PciHostBridgeFreeTranslations ( + PCI_ROOT_BRIDGE_TRANSLATION *Translations, + UINTN Count + ) +{ +} + /** Inform the platform that the resource conflict happens. =20 diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c b/MdeMod= ulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c index 1494848..835e411 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c @@ -360,18 +360,38 @@ InitializePciHostBridge ( PCI_HOST_BRIDGE_INSTANCE *HostBridge; PCI_ROOT_BRIDGE_INSTANCE *RootBridge; PCI_ROOT_BRIDGE *RootBridges; + PCI_ROOT_BRIDGE_TRANSLATION *Translations; UINTN RootBridgeCount; + UINTN TranslationCount; UINTN Index; PCI_ROOT_BRIDGE_APERTURE *MemApertures[4]; + UINT64 MemTranslation[4]; UINTN MemApertureIndex; BOOLEAN ResourceAssigned; LIST_ENTRY *Link; + UINT64 Trans; =20 RootBridges =3D PciHostBridgeGetRootBridges (&RootBridgeCount); if ((RootBridges =3D=3D NULL) || (RootBridgeCount =3D=3D 0)) { return EFI_UNSUPPORTED; } =20 + Translations =3D PciHostBridgeGetTranslations (&TranslationCount); + if (Translations =3D=3D NULL || TranslationCount =3D=3D 0) { + TranslationCount =3D 0; + Translations =3D AllocateZeroPool (RootBridgeCount * sizeof (*Translat= ions)); + if (Translations =3D=3D NULL) { + PciHostBridgeFreeRootBridges (RootBridges, RootBridgeCount); + return EFI_OUT_OF_RESOURCES; + } + } + + if (TranslationCount !=3D 0 && TranslationCount !=3D RootBridgeCount) { + DEBUG ((DEBUG_ERROR, "Error: count of root bridges (%d) and translatio= n (%d) are different!\n", + RootBridgeCount, TranslationCount)); + return EFI_INVALID_PARAMETER; + } + Status =3D gBS->LocateProtocol (&gEfiMetronomeArchProtocolGuid, NULL, (V= OID **) &mMetronome); ASSERT_EFI_ERROR (Status); Status =3D gBS->LocateProtocol (&gEfiCpuIo2ProtocolGuid, NULL, (VOID **)= &mCpuIo); @@ -395,7 +415,7 @@ InitializePciHostBridge ( // // Create Root Bridge Handle Instance // - RootBridge =3D CreateRootBridge (&RootBridges[Index]); + RootBridge =3D CreateRootBridge (&RootBridges[Index], &Translations[In= dex]); ASSERT (RootBridge !=3D NULL); if (RootBridge =3D=3D NULL) { continue; @@ -411,8 +431,9 @@ InitializePciHostBridge ( } =20 if (RootBridges[Index].Io.Base <=3D RootBridges[Index].Io.Limit) { + Trans =3D Translations[Index].IoTranslation; Status =3D AddIoSpace ( - RootBridges[Index].Io.Base, + RootBridges[Index].Io.Base + Trans, RootBridges[Index].Io.Limit - RootBridges[Index].Io.Base = + 1 ); ASSERT_EFI_ERROR (Status); @@ -422,7 +443,7 @@ InitializePciHostBridge ( EfiGcdIoTypeIo, 0, RootBridges[Index].Io.Limit - RootBridges[Index].I= o.Base + 1, - &RootBridges[Index].Io.Base, + &RootBridges[Index].Io.Base + Trans, gImageHandle, NULL ); @@ -437,20 +458,24 @@ InitializePciHostBridge ( // the MEM aperture in Mem // MemApertures[0] =3D &RootBridges[Index].Mem; + MemTranslation[0] =3D Translations[Index].MemTranslation; MemApertures[1] =3D &RootBridges[Index].MemAbove4G; + MemTranslation[1] =3D Translations[Index].MemAbove4GTranslation; MemApertures[2] =3D &RootBridges[Index].PMem; + MemTranslation[2] =3D Translations[Index].PMemTranslation; MemApertures[3] =3D &RootBridges[Index].PMemAbove4G; + MemTranslation[3] =3D Translations[Index].PMemAbove4GTranslation; =20 for (MemApertureIndex =3D 0; MemApertureIndex < ARRAY_SIZE (MemApertur= es); MemApertureIndex++) { if (MemApertures[MemApertureIndex]->Base <=3D MemApertures[MemApertu= reIndex]->Limit) { Status =3D AddMemoryMappedIoSpace ( - MemApertures[MemApertureIndex]->Base, + MemApertures[MemApertureIndex]->Base + MemTranslation[M= emApertureIndex], MemApertures[MemApertureIndex]->Limit - MemApertures[Me= mApertureIndex]->Base + 1, EFI_MEMORY_UC ); ASSERT_EFI_ERROR (Status); Status =3D gDS->SetMemorySpaceAttributes ( - MemApertures[MemApertureIndex]->Base, + MemApertures[MemApertureIndex]->Base + MemTranslat= ion[MemApertureIndex], MemApertures[MemApertureIndex]->Limit - MemApertur= es[MemApertureIndex]->Base + 1, EFI_MEMORY_UC ); @@ -463,7 +488,7 @@ InitializePciHostBridge ( EfiGcdMemoryTypeMemoryMappedIo, 0, MemApertures[MemApertureIndex]->Limit - MemApert= ures[MemApertureIndex]->Base + 1, - &MemApertures[MemApertureIndex]->Base, + &MemApertures[MemApertureIndex]->Base + MemTrans= lation[MemApertureIndex], gImageHandle, NULL ); @@ -514,7 +539,13 @@ InitializePciHostBridge ( ); ASSERT_EFI_ERROR (Status); } + PciHostBridgeFreeRootBridges (RootBridges, RootBridgeCount); + if (TranslationCount =3D=3D 0) { + FreePool (Translations); + } else { + PciHostBridgeFreeTranslations (Translations, TranslationCount); + } =20 if (!EFI_ERROR (Status)) { mIoMmuEvent =3D EfiCreateProtocolNotifyEvent ( @@ -828,7 +859,7 @@ NotifyPhase ( FALSE, RootBridge->ResAllocNode[Index].Length, MIN (15, BitsOfAlignment), - ALIGN_VALUE (RootBridge->Io.Base, Alignment + = 1), + ALIGN_VALUE (RootBridge->Io.Base, Alignment + = 1) + RootBridge->IoTranslation, RootBridge->Io.Limit ); break; @@ -838,7 +869,7 @@ NotifyPhase ( TRUE, RootBridge->ResAllocNode[Index].Length, MIN (63, BitsOfAlignment), - ALIGN_VALUE (RootBridge->MemAbove4G.Base, Alig= nment + 1), + ALIGN_VALUE (RootBridge->MemAbove4G.Base, Alig= nment + 1) + RootBridge->MemAbove4GTranslation, RootBridge->MemAbove4G.Limit ); if (BaseAddress !=3D MAX_UINT64) { @@ -853,7 +884,7 @@ NotifyPhase ( TRUE, RootBridge->ResAllocNode[Index].Length, MIN (31, BitsOfAlignment), - ALIGN_VALUE (RootBridge->Mem.Base, Alignment += 1), + ALIGN_VALUE (RootBridge->Mem.Base, Alignment += 1) + RootBridge->MemTranslation, RootBridge->Mem.Limit ); break; @@ -863,7 +894,7 @@ NotifyPhase ( TRUE, RootBridge->ResAllocNode[Index].Length, MIN (63, BitsOfAlignment), - ALIGN_VALUE (RootBridge->PMemAbove4G.Base, Ali= gnment + 1), + ALIGN_VALUE (RootBridge->PMemAbove4G.Base, Ali= gnment + 1) + RootBridge->PMemAbove4GTranslation, RootBridge->PMemAbove4G.Limit ); if (BaseAddress !=3D MAX_UINT64) { @@ -877,7 +908,7 @@ NotifyPhase ( TRUE, RootBridge->ResAllocNode[Index].Length, MIN (31, BitsOfAlignment), - ALIGN_VALUE (RootBridge->PMem.Base, Alignment = + 1), + ALIGN_VALUE (RootBridge->PMem.Base, Alignment = + 1) + RootBridge->PMemTranslation, RootBridge->PMem.Limit ); break; diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridge.h b/MdeMod= ulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridge.h index d3dfb57..449c4b3 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridge.h +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridge.h @@ -73,6 +73,11 @@ typedef struct { PCI_ROOT_BRIDGE_APERTURE PMem; PCI_ROOT_BRIDGE_APERTURE MemAbove4G; PCI_ROOT_BRIDGE_APERTURE PMemAbove4G; + UINT64 IoTranslation; + UINT64 MemTranslation; + UINT64 MemAbove4GTranslation; + UINT64 PMemTranslation; + UINT64 PMemAbove4GTranslation; BOOLEAN DmaAbove4G; BOOLEAN NoExtendedConfigSpace; VOID *ConfigBuffer; @@ -98,7 +103,8 @@ typedef struct { **/ PCI_ROOT_BRIDGE_INSTANCE * CreateRootBridge ( - IN PCI_ROOT_BRIDGE *Bridge + IN PCI_ROOT_BRIDGE *Bridge, + IN PCI_ROOT_BRIDGE_TRANSLATION *Translation ); =20 // diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c b/MdeM= odulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c index dc06c16..84b2d5a 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c @@ -67,7 +67,8 @@ UINT8 mOutStride[] =3D { **/ PCI_ROOT_BRIDGE_INSTANCE * CreateRootBridge ( - IN PCI_ROOT_BRIDGE *Bridge + IN PCI_ROOT_BRIDGE *Bridge, + IN PCI_ROOT_BRIDGE_TRANSLATION *Translation ) { PCI_ROOT_BRIDGE_INSTANCE *RootBridge; @@ -87,11 +88,21 @@ CreateRootBridge ( (Bridge->AllocationAttributes & EFI_PCI_HOST_BRIDGE_MEM64_DECODE= ) !=3D 0 ? L"Mem64Decode" : L"" )); DEBUG ((EFI_D_INFO, " Bus: %lx - %lx\n", Bridge->Bus.Base, Bri= dge->Bus.Limit)); - DEBUG ((EFI_D_INFO, " Io: %lx - %lx\n", Bridge->Io.Base, Brid= ge->Io.Limit)); - DEBUG ((EFI_D_INFO, " Mem: %lx - %lx\n", Bridge->Mem.Base, Bri= dge->Mem.Limit)); - DEBUG ((EFI_D_INFO, " MemAbove4G: %lx - %lx\n", Bridge->MemAbove4G.Ba= se, Bridge->MemAbove4G.Limit)); - DEBUG ((EFI_D_INFO, " PMem: %lx - %lx\n", Bridge->PMem.Base, Br= idge->PMem.Limit)); - DEBUG ((EFI_D_INFO, " PMemAbove4G: %lx - %lx\n", Bridge->PMemAbove4G.B= ase, Bridge->PMemAbove4G.Limit)); + DEBUG ((DEBUG_INFO, " Io: %lx - %lx translation=3D%lx\n", + Bridge->Io.Base, Bridge->Io.Limit, Translation->IoTranslation + )); + DEBUG ((DEBUG_INFO, " Mem: %lx - %lx translation=3D%lx\n", + Bridge->Mem.Base, Bridge->Mem.Limit, Translation->MemTranslation + )); + DEBUG ((DEBUG_INFO, " MemAbove4G: %lx - %lx translation=3D%lx\n", + Bridge->MemAbove4G.Base, Bridge->MemAbove4G.Limit, Translation->= MemAbove4GTranslation + )); + DEBUG ((DEBUG_INFO, " PMem: %lx - %lx translation=3D%lx\n", + Bridge->PMem.Base, Bridge->PMem.Limit, Translation->PMemTranslat= ion + )); + DEBUG ((DEBUG_INFO, " PMemAbove4G: %lx - %lx translation=3D%lx\n", + Bridge->PMemAbove4G.Base, Bridge->PMemAbove4G.Limit, Translation= ->PMemAbove4GTranslation + )); =20 // // Make sure Mem and MemAbove4G apertures are valid @@ -174,10 +185,15 @@ CreateRootBridge ( =20 CopyMem (&RootBridge->Bus, &Bridge->Bus, sizeof (PCI_ROOT_BRIDGE_APERTUR= E)); CopyMem (&RootBridge->Io, &Bridge->Io, sizeof (PCI_ROOT_BRIDGE_APERTURE)= ); + RootBridge->IoTranslation =3D Translation->IoTranslation; CopyMem (&RootBridge->Mem, &Bridge->Mem, sizeof (PCI_ROOT_BRIDGE_APERTUR= E)); + RootBridge->MemTranslation =3D Translation->MemTranslation; CopyMem (&RootBridge->MemAbove4G, &Bridge->MemAbove4G, sizeof (PCI_ROOT_= BRIDGE_APERTURE)); + RootBridge->MemAbove4GTranslation =3D Translation->MemAbove4GTranslation; CopyMem (&RootBridge->PMem, &Bridge->PMem, sizeof (PCI_ROOT_BRIDGE_APERT= URE)); + RootBridge->PMemTranslation =3D Translation->PMemTranslation; CopyMem (&RootBridge->PMemAbove4G, &Bridge->PMemAbove4G, sizeof (PCI_ROO= T_BRIDGE_APERTURE)); + RootBridge->PMemAbove4GTranslation =3D Translation->PMemAbove4GTranslati= on; =20 for (Index =3D TypeIo; Index < TypeMax; Index++) { switch (Index) { @@ -403,6 +419,28 @@ RootBridgeIoCheckParameter ( return EFI_SUCCESS; } =20 +EFI_STATUS +RootBridgeIoGetMemTranslation ( + IN PCI_ROOT_BRIDGE_INSTANCE *RootBridge, + IN UINT64 Address, + IN OUT UINT64 *Translation + ) +{ + if (Address >=3D RootBridge->Mem.Base && Address <=3D RootBridge->Mem.Li= mit) { + *Translation =3D RootBridge->MemTranslation; + } else if (Address >=3D RootBridge->PMem.Base && Address <=3D RootBridge= ->PMem.Limit) { + *Translation =3D RootBridge->PMemTranslation; + } else if (Address >=3D RootBridge->MemAbove4G.Base && Address <=3D Root= Bridge->MemAbove4G.Limit) { + *Translation =3D RootBridge->MemAbove4GTranslation; + } else if (Address >=3D RootBridge->PMemAbove4G.Base && Address <=3D Roo= tBridge->PMemAbove4G.Limit) { + *Translation =3D RootBridge->PMemAbove4GTranslation; + } else { + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + /** Polls an address in memory mapped I/O space until an exit condition is m= et, or a timeout occurs. @@ -658,13 +696,22 @@ RootBridgeIoMemRead ( ) { EFI_STATUS Status; + PCI_ROOT_BRIDGE_INSTANCE *RootBridge; + UINT64 Translation; =20 Status =3D RootBridgeIoCheckParameter (This, MemOperation, Width, Addres= s, Count, Buffer); if (EFI_ERROR (Status)) { return Status; } - return mCpuIo->Mem.Read (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, Addr= ess, Count, Buffer); + + RootBridge =3D ROOT_BRIDGE_FROM_THIS (This); + Status =3D RootBridgeIoGetMemTranslation (RootBridge, Address, &Translat= ion); + if (EFI_ERROR (Status)) { + return Status; + } + + return mCpuIo->Mem.Read (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, Addr= ess + Translation, Count, Buffer); } =20 /** @@ -705,13 +752,22 @@ RootBridgeIoMemWrite ( ) { EFI_STATUS Status; + PCI_ROOT_BRIDGE_INSTANCE *RootBridge; + UINT64 Translation; =20 Status =3D RootBridgeIoCheckParameter (This, MemOperation, Width, Addres= s, Count, Buffer); if (EFI_ERROR (Status)) { return Status; } - return mCpuIo->Mem.Write (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, Add= ress, Count, Buffer); + + RootBridge =3D ROOT_BRIDGE_FROM_THIS (This); + Status =3D RootBridgeIoGetMemTranslation (RootBridge, Address, &Translat= ion); + if (EFI_ERROR (Status)) { + return Status; + } + + return mCpuIo->Mem.Write (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, Add= ress + Translation, Count, Buffer); } =20 /** @@ -746,6 +802,8 @@ RootBridgeIoIoRead ( ) { EFI_STATUS Status; + PCI_ROOT_BRIDGE_INSTANCE *RootBridge; + Status =3D RootBridgeIoCheckParameter ( This, IoOperation, Width, Address, Count, Buffer @@ -753,7 +811,10 @@ RootBridgeIoIoRead ( if (EFI_ERROR (Status)) { return Status; } - return mCpuIo->Io.Read (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, Addre= ss, Count, Buffer); + + RootBridge =3D ROOT_BRIDGE_FROM_THIS (This); + + return mCpuIo->Io.Read (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, Addre= ss + RootBridge->IoTranslation, Count, Buffer); } =20 /** @@ -788,6 +849,8 @@ RootBridgeIoIoWrite ( ) { EFI_STATUS Status; + PCI_ROOT_BRIDGE_INSTANCE *RootBridge; + Status =3D RootBridgeIoCheckParameter ( This, IoOperation, Width, Address, Count, Buffer @@ -795,7 +858,10 @@ RootBridgeIoIoWrite ( if (EFI_ERROR (Status)) { return Status; } - return mCpuIo->Io.Write (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, Addr= ess, Count, Buffer); + + RootBridge =3D ROOT_BRIDGE_FROM_THIS (This); + + return mCpuIo->Io.Write (mCpuIo, (EFI_CPU_IO_PROTOCOL_WIDTH) Width, Addr= ess + RootBridge->IoTranslation, Count, Buffer); } =20 /** @@ -1621,19 +1687,28 @@ RootBridgeIoConfiguration ( switch (ResAllocNode->Type) { =20 case TypeIo: - Descriptor->ResType =3D ACPI_ADDRESS_SPACE_TYPE_IO; + Descriptor->ResType =3D ACPI_ADDRESS_SPACE_TYPE_IO; + Descriptor->AddrTranslationOffset =3D RootBridge->IoTranslation; break; =20 case TypePMem32: - Descriptor->SpecificFlag =3D EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_= CACHEABLE_PREFETCHABLE; + Descriptor->SpecificFlag =3D EFI_ACPI_MEMORY_RESOURCE_SPECI= FIC_FLAG_CACHEABLE_PREFETCHABLE; + Descriptor->AddrTranslationOffset =3D RootBridge->PMemTranslation; + Descriptor->ResType =3D ACPI_ADDRESS_SPACE_TYPE_MEM; + Descriptor->AddrSpaceGranularity =3D 32; case TypeMem32: + Descriptor->AddrTranslationOffset =3D RootBridge->MemTranslation; Descriptor->ResType =3D ACPI_ADDRESS_SPACE_TYPE_MEM; Descriptor->AddrSpaceGranularity =3D 32; break; =20 case TypePMem64: - Descriptor->SpecificFlag =3D EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_= CACHEABLE_PREFETCHABLE; + Descriptor->SpecificFlag =3D EFI_ACPI_MEMORY_RESOURCE_SPECI= FIC_FLAG_CACHEABLE_PREFETCHABLE; + Descriptor->AddrTranslationOffset =3D RootBridge->PMemAbove4GTransla= tion; + Descriptor->ResType =3D ACPI_ADDRESS_SPACE_TYPE_MEM; + Descriptor->AddrSpaceGranularity =3D 64; case TypeMem64: + Descriptor->AddrTranslationOffset =3D RootBridge->MemAbove4GTranslat= ion; Descriptor->ResType =3D ACPI_ADDRESS_SPACE_TYPE_MEM; Descriptor->AddrSpaceGranularity =3D 64; break; diff --git a/MdeModulePkg/Include/Library/PciHostBridgeLib.h b/MdeModulePkg= /Include/Library/PciHostBridgeLib.h index d42e9ec..4c297fd 100644 --- a/MdeModulePkg/Include/Library/PciHostBridgeLib.h +++ b/MdeModulePkg/Include/Library/PciHostBridgeLib.h @@ -53,6 +53,14 @@ typedef struct { EFI_DEVICE_PATH_PROTOCOL *DevicePath; ///< Device path. } PCI_ROOT_BRIDGE; =20 +typedef struct { + UINT64 IoTranslation; + UINT64 MemTranslation; + UINT64 MemAbove4GTranslation; + UINT64 PMemTranslation; + UINT64 PMemAbove4GTranslation; +} PCI_ROOT_BRIDGE_TRANSLATION; + /** Return all the root bridge instances in an array. =20 @@ -69,6 +77,21 @@ PciHostBridgeGetRootBridges ( ); =20 /** + Return all the root bridge instances in an array. + + @param Count Return the count of root bridge instances. + + @return All the root bridge instances in an array. + The array should be passed into PciHostBridgeFreeRootBridges() + when it's not used. +**/ +PCI_ROOT_BRIDGE_TRANSLATION * +EFIAPI +PciHostBridgeGetTranslations ( + UINTN *Count + ); + +/** Free the root bridge instances array returned from PciHostBridgeGetRootB= ridges(). =20 @param Bridges The root bridge instances array. @@ -82,6 +105,19 @@ PciHostBridgeFreeRootBridges ( ); =20 /** + Free the root bridge instances array returned from PciHostBridgeGetRootB= ridges(). + + @param Bridges The root bridge instances array. + @param Count The count of the array. +**/ +VOID +EFIAPI +PciHostBridgeFreeTranslations ( + PCI_ROOT_BRIDGE_TRANSLATION *Bridges, + UINTN Count + ); + +/** Inform the platform that the resource conflict happens. =20 @param HostBridgeHandle Handle of the Host Bridge. --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel