From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on061d.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe49::61d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D9FDA81C7C for ; Fri, 13 Jan 2017 14:14:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Z+ydKwM4oL+HTEfOI1Xqx7y2Jb7juA4gz6j3bDzaPkY=; b=Bbi3LoGr2FMbrgR3sjynlRygfGow0tHAegmglNhGeGb21PiTLcylocvqNAgJ+QAhK0CejASmHeU2WqPGXZQreNNzHbH46AhAy3RlDQT/lHxBm6JqyiWf8pCblU9CdOlGpX0paq5T2LGXS5PM3EfaR3ldST3qwzVYvFTMWNxAJ4U= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=leo.duran@amd.com; Received: from leduran-Precision-WorkStation-T5400.amd.com (165.204.77.1) by MWHPR12MB1248.namprd12.prod.outlook.com (10.169.205.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.845.12; Fri, 13 Jan 2017 22:14:46 +0000 From: Leo Duran To: CC: , , , , , , , , Leo Duran Date: Fri, 13 Jan 2017 16:14:16 -0600 Message-ID: <1484345656-3574-7-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484345656-3574-1-git-send-email-leo.duran@amd.com> References: <1484345656-3574-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: YQXPR01CA0019.CANPRD01.PROD.OUTLOOK.COM (10.165.102.157) To MWHPR12MB1248.namprd12.prod.outlook.com (10.169.205.8) X-MS-Office365-Filtering-Correlation-Id: 13686f2e-b414-474f-22b1-08d43c019653 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:MWHPR12MB1248; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1248; 3:CcLXLizSR2s0Epo/htAsan5Nl/M9DDnCtOSQY7OJWNyuP+e6g4PKKw/TaySJjJLuFbU+a3XdY0YHdLPvbms6SVtL9YF9Oa5cYvsrqWh2Q18k/Eo18FpJgG0wbWO9EqGDGxnRd/hKUJbxmq8aTJ5iVNSDEKQWhIRf7w7gMd2imb8cyzI/QFV8lR7HAfKtg4Z/E5RpQjLyLO2gyZFXzdA3pHI9aENsoOdAhuZ8cR5SMqqckvkgFRJaH80WHp5bE2Y7jt0T5zTG3Gpy11jXz8L2eA==; 25:jfYuaUCqUzgLBRMd8AJPXvFskruea35Tere7RL+3O85M146harvwcfFvGDDWWEU6RzfjC4n88xqHCp4mV9giumONPEXCSQI7beWf4E2cyxUStZlNMa2zYhfWJqQShwaM+TQsmKU6TCbafiU2wYNonl7n9FuwstbAGjxKW2KqJ7nAm9F1ngPpb2rtm1yNImMMF/2AHIxtehJLKhirbeAjBhj4HaK4xITII3Sf3CvbbhCPKsWGDw4/94cDD9GcauNGHPVJmWOXgjvmt5cpeS/KJ6RIKSZ0AMXR+wOvETDrElKNlAlOV1DBdiJgr2a8TDLzUVtigpF1q2lnwagzK8r2y4Waer+hXcMvPijLUJa16GjXGivAehhlYsyKhqGsPa5cp2xuPEfSi7de8e5W05x5M1pQLh6HlOqevaFDQEnh8cJVbnjF/FAx3nzfouEuzGNNdc4RlCTmcOZn08VgKBQfjw== X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1248; 31:ZyElzBg5rFTDbaIso2KEftMgm+L/DNG82uGEyAFMC1Bq4L688ad6Ic9rgRE7n3ba7v4BZ9Rseth8rNRhZby06e0aNkFroqal2fWjaqq8pN3ect05Hehvm8+D4cTwCR9pmMJcDeSh3+r4wOy4pSq4yLn2ubgfVIpFi7p9eSthbRlNG5RqV39C6KqzOz3Y0HMsPqHVT6TTBaf9kFvP13zn3D0fXWBiJikcBZ4g1nHx8zgXU2QyX7KggHHzCanSI+iEG/TkiLvAa4LvtVdGkvrPEA==; 20:wP7C8W1knXyhLBcE+5kzrhgq5LLo+4ZQ8CNiMl+S504+cjsqGiRralxwwPvm55B/ydSv1Nd+kWEvz3Q8OjfL291fMREfbWbFDVx47lfubQz026DeTN6LsI6aaXTfZ3Ix4XlG8P1xh6WzURX/EZktp557Q3+ewyDQzGcOgr6jLArZQ50y+X9AapAFRbYM5Yh2pyejqd8e51KujAWZDShccUQblrufoQeEL0uj6wRI648+n/dHS834cJTFcP0MOmOJJF9QeoaxKVSwufDtKvhIxjIwUSfQAt8guD20b2fn1agXwvWr3lANlxO5voY6PbQivuIxjBn7ulyt3Mx36yJ9LZQcuC8I3NmqbUYLC0YDtg70BmBggN/qoNRXQzBSBddZ2ADnvI3RhDGvA9z1cF7GFaarZvuKnLYyaQSTZUcP7BQBsUY4aYnNOLDmvg+jrMvYxpDqVzkZJZmYgM3kW5UpWVMBhOyWn2vHFfRoKYbb0VIj+w4niXpJHvQPLvsQbLfo X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123560025)(20161123558021)(20161123555025)(20161123562025)(20161123564025)(6072148); SRVR:MWHPR12MB1248; BCL:0; PCL:0; RULEID:; SRVR:MWHPR12MB1248; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1248; 4:C6YM9x/QMKgoBbc355lCRxb+HxswtyffgjHC64j75/lHZbAVagdU7ppYs/d/WAPPt8X6DL3xGUWScLARDst95uSE30+6jnnCXMK7ql2UBh8rRbAv4ALBs7UWfN6I0q08ilarCaul+Sk+ItAGZlnUpogps8tQUzgi1t0Y2By4I89AjruXyOExkJIliENA9lRvFaw4akzgiyr+i81sBNzM1q+DJE0ufvQ9Nf4wX+qEXxOHpJ77X/O8xUGOZDaskBojN1G/SdxykT5EK4RvaCsKmJVIXUdizgm/7q2DwzWAPwj4sViiCW5nNO+XZZYCHIvrc1YhPKZVewAFRJ/cjGKyvbI7sNYxGDQXhjW4ZwSR0WUL/uJvcqgw3YBnKqGD3vviTMaV6FpVSyIP6hgFGdWPl98ISCIApXyBorWP0e63PSrLEuPrDtF7AXMJc/Yr6KetHn4esUh8k44dzEocdZYXdHqrozdN0HaXWwrO7wnOKpU2J3dS3faHhfyF6ZXiceVfGD5kkEwE7Hdjjm2hu2qbQkrdxb8hQxZ5CoBOeXLbYyo1t9Yqbts+sfT9DqW2VVyg9F0D33AvWkRVWj6HX9kHVzl7CoMeNOf5Z4FbgdJmFNUSIXD/cTvpbfB7WhfzxRCfZXW0cE9XgywOSA2vKkQ/1fAX2KXZMvz7/59fefKy96DzTUdcmyCu8em4j/yJSGujbYV6YXYXAkhcMNW0wdpRnQ== X-Forefront-PRVS: 018632C080 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6029001)(6009001)(7916002)(39450400003)(39410400002)(39860400002)(39840400002)(39850400002)(199003)(189002)(5003940100001)(50466002)(48376002)(50986999)(76176999)(92566002)(25786008)(5660300001)(38730400001)(54906002)(6916009)(2950100002)(6486002)(110136003)(305945005)(7736002)(6666003)(81166006)(81156014)(36756003)(189998001)(68736007)(97736004)(86362001)(8676002)(53416004)(42186005)(33646002)(106356001)(101416001)(2351001)(47776003)(50226002)(6116002)(3846002)(2906002)(4326007)(105586002)(66066001)(27001)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1248; H:leduran-Precision-WorkStation-T5400.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =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enant-OriginalArrivalTime: 13 Jan 2017 22:14:46.5314 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1248 Subject: [RFC v2 6/6] MdeModulePkg: Modify PciHostBridgeDxe to use new BmDmaLib library X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Jan 2017 22:14:50 -0000 Content-Type: text/plain Cc: Feng Tian Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Leo Duran --- .../Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf | 1 + .../Bus/Pci/PciHostBridgeDxe/PciRootBridge.h | 13 +- .../Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c | 272 +++++---------------- MdeModulePkg/MdeModulePkg.dsc | 1 + 4 files changed, 67 insertions(+), 220 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf index d8b0439..35bb5c4 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf @@ -42,6 +42,7 @@ [LibraryClasses] BaseLib PciSegmentLib PciHostBridgeLib + BmDmaLib [Protocols] gEfiMetronomeArchProtocolGuid ## CONSUMES diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridge.h b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridge.h index 13185b4..c125fcd 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridge.h +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridge.h @@ -34,6 +34,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include "PciHostResource.h" @@ -43,17 +44,6 @@ typedef enum { PciOperation } OPERATION_TYPE; -#define MAP_INFO_SIGNATURE SIGNATURE_32 ('_', 'm', 'a', 'p') -typedef struct { - UINT32 Signature; - LIST_ENTRY Link; - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation; - UINTN NumberOfBytes; - UINTN NumberOfPages; - EFI_PHYSICAL_ADDRESS HostAddress; - EFI_PHYSICAL_ADDRESS MappedHostAddress; -} MAP_INFO; -#define MAP_INFO_FROM_LINK(a) CR (a, MAP_INFO, Link, MAP_INFO_SIGNATURE) #define PCI_ROOT_BRIDGE_SIGNATURE SIGNATURE_32 ('_', 'p', 'r', 'b') @@ -79,7 +69,6 @@ typedef struct { EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL RootBridgeIo; BOOLEAN ResourceSubmitted; - LIST_ENTRY Maps; } PCI_ROOT_BRIDGE_INSTANCE; #define ROOT_BRIDGE_FROM_THIS(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, RootBridgeIo, PCI_ROOT_BRIDGE_SIGNATURE) diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c index 8af131b..8a74bf6 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c @@ -17,7 +17,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "PciRootBridge.h" #include "PciHostResource.h" -#define NO_MAPPING (VOID *) (UINTN) -1 // // Lookup table for increment values based on transfer widths @@ -55,6 +54,39 @@ UINT8 mOutStride[] = { 0 // EfiPciWidthFillUint64 }; + +BM_DMA_OPERATION +ConvertDmaOperation ( + IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION RbOperation + ) +{ + BM_DMA_OPERATION BmOperation; + + switch (RbOperation) { + case EfiPciOperationBusMasterRead: + case EfiPciOperationBusMasterRead64: + BmOperation = DmaOperationBusMasterRead; + break; + + case EfiPciOperationBusMasterWrite: + case EfiPciOperationBusMasterWrite64: + BmOperation = DmaOperationBusMasterWrite; + break; + + case EfiPciOperationBusMasterCommonBuffer: + case EfiPciOperationBusMasterCommonBuffer64: + BmOperation = DmaOperationBusMasterCommonBuffer; + break; + + default: + BmOperation = DmaOperationBusMasterMaximum; + break; + } + + return BmOperation; +} + + /** Construct the Pci Root Bridge instance. @@ -168,7 +200,6 @@ CreateRootBridge ( TypeMax * sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR) ); ASSERT (RootBridge->ConfigBuffer != NULL); - InitializeListHead (&RootBridge->Maps); CopyMem (&RootBridge->Bus, &Bridge->Bus, sizeof (PCI_ROOT_BRIDGE_APERTURE)); CopyMem (&RootBridge->Io, &Bridge->Io, sizeof (PCI_ROOT_BRIDGE_APERTURE)); @@ -1053,118 +1084,27 @@ RootBridgeIoMap ( OUT VOID **Mapping ) { - EFI_STATUS Status; - PCI_ROOT_BRIDGE_INSTANCE *RootBridge; - EFI_PHYSICAL_ADDRESS PhysicalAddress; - MAP_INFO *MapInfo; - - if (HostAddress == NULL || NumberOfBytes == NULL || DeviceAddress == NULL || - Mapping == NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // Make sure that Operation is valid - // - if ((UINT32) Operation >= EfiPciOperationMaximum) { - return EFI_INVALID_PARAMETER; - } + PCI_ROOT_BRIDGE_INSTANCE *RootBridge; + BOOLEAN DmaAbove4GB; + BM_DMA_OPERATION BmOperation; RootBridge = ROOT_BRIDGE_FROM_THIS (This); - - PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress; - if ((!RootBridge->DmaAbove4G || - (Operation != EfiPciOperationBusMasterRead64 && - Operation != EfiPciOperationBusMasterWrite64 && - Operation != EfiPciOperationBusMasterCommonBuffer64)) && - ((PhysicalAddress + *NumberOfBytes) > SIZE_4GB)) { - - // - // If the root bridge or the device cannot handle performing DMA above - // 4GB but any part of the DMA transfer being mapped is above 4GB, then - // map the DMA transfer to a buffer below 4GB. - // - - if (Operation == EfiPciOperationBusMasterCommonBuffer || - Operation == EfiPciOperationBusMasterCommonBuffer64) { - // - // Common Buffer operations can not be remapped. If the common buffer - // if above 4GB, then it is not possible to generate a mapping, so return - // an error. - // - return EFI_UNSUPPORTED; - } - - // - // Allocate a MAP_INFO structure to remember the mapping when Unmap() is - // called later. - // - MapInfo = AllocatePool (sizeof (MAP_INFO)); - if (MapInfo == NULL) { - *NumberOfBytes = 0; - return EFI_OUT_OF_RESOURCES; - } - - // - // Initialize the MAP_INFO structure - // - MapInfo->Signature = MAP_INFO_SIGNATURE; - MapInfo->Operation = Operation; - MapInfo->NumberOfBytes = *NumberOfBytes; - MapInfo->NumberOfPages = EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes); - MapInfo->HostAddress = PhysicalAddress; - MapInfo->MappedHostAddress = SIZE_4GB - 1; - - // - // Allocate a buffer below 4GB to map the transfer to. - // - Status = gBS->AllocatePages ( - AllocateMaxAddress, - EfiBootServicesData, - MapInfo->NumberOfPages, - &MapInfo->MappedHostAddress - ); - if (EFI_ERROR (Status)) { - FreePool (MapInfo); - *NumberOfBytes = 0; - return Status; - } - - // - // If this is a read operation from the Bus Master's point of view, - // then copy the contents of the real buffer into the mapped buffer - // so the Bus Master can read the contents of the real buffer. - // - if (Operation == EfiPciOperationBusMasterRead || - Operation == EfiPciOperationBusMasterRead64) { - CopyMem ( - (VOID *) (UINTN) MapInfo->MappedHostAddress, - (VOID *) (UINTN) MapInfo->HostAddress, - MapInfo->NumberOfBytes - ); - } - - InsertTailList (&RootBridge->Maps, &MapInfo->Link); - - // - // The DeviceAddress is the address of the maped buffer below 4GB - // - *DeviceAddress = MapInfo->MappedHostAddress; - // - // Return a pointer to the MAP_INFO structure in Mapping - // - *Mapping = MapInfo; - } else { - // - // If the root bridge CAN handle performing DMA above 4GB or - // the transfer is below 4GB, so the DeviceAddress is simply the - // HostAddress - // - *DeviceAddress = PhysicalAddress; - *Mapping = NO_MAPPING; - } - - return EFI_SUCCESS; + DmaAbove4GB = RootBridge->DmaAbove4G && ( + Operation == EfiPciOperationBusMasterRead64 || + Operation == EfiPciOperationBusMasterWrite64 || + Operation == EfiPciOperationBusMasterCommonBuffer64 + ); + + BmOperation = ConvertDmaOperation (Operation); + + return BmDmaMap ( + DmaAbove4GB, + BmOperation, + HostAddress, + NumberOfBytes, + DeviceAddress, + Mapping + ); } /** @@ -1191,58 +1131,7 @@ RootBridgeIoUnmap ( IN VOID *Mapping ) { - MAP_INFO *MapInfo; - LIST_ENTRY *Link; - PCI_ROOT_BRIDGE_INSTANCE *RootBridge; - - RootBridge = ROOT_BRIDGE_FROM_THIS (This); - // - // See if the Map() operation associated with this Unmap() required a mapping - // buffer. If a mapping buffer was not required, then this function simply - // returns EFI_SUCCESS. - // - if (Mapping == NO_MAPPING) { - return EFI_SUCCESS; - } - - MapInfo = NO_MAPPING; - for (Link = GetFirstNode (&RootBridge->Maps) - ; !IsNull (&RootBridge->Maps, Link) - ; Link = GetNextNode (&RootBridge->Maps, Link) - ) { - MapInfo = MAP_INFO_FROM_LINK (Link); - if (MapInfo == Mapping) { - break; - } - } - // - // Mapping is not a valid value returned by Map() - // - if (MapInfo != Mapping) { - return EFI_INVALID_PARAMETER; - } - RemoveEntryList (&MapInfo->Link); - - // - // If this is a write operation from the Bus Master's point of view, - // then copy the contents of the mapped buffer into the real buffer - // so the processor can read the contents of the real buffer. - // - if (MapInfo->Operation == EfiPciOperationBusMasterWrite || - MapInfo->Operation == EfiPciOperationBusMasterWrite64) { - CopyMem ( - (VOID *) (UINTN) MapInfo->HostAddress, - (VOID *) (UINTN) MapInfo->MappedHostAddress, - MapInfo->NumberOfBytes - ); - } - - // - // Free the mapped buffer and the MAP_INFO structure. - // - gBS->FreePages (MapInfo->MappedHostAddress, MapInfo->NumberOfPages); - FreePool (Mapping); - return EFI_SUCCESS; + return BmDmaUnmap (Mapping); } /** @@ -1282,56 +1171,23 @@ RootBridgeIoAllocateBuffer ( IN UINT64 Attributes ) { - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS PhysicalAddress; - PCI_ROOT_BRIDGE_INSTANCE *RootBridge; - EFI_ALLOCATE_TYPE AllocateType; + PCI_ROOT_BRIDGE_INSTANCE *RootBridge; + BOOLEAN DmaAbove4GB; - // - // Validate Attributes - // if ((Attributes & EFI_PCI_ATTRIBUTE_INVALID_FOR_ALLOCATE_BUFFER) != 0) { return EFI_UNSUPPORTED; } - // - // Check for invalid inputs - // - if (HostAddress == NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // The only valid memory types are EfiBootServicesData and - // EfiRuntimeServicesData - // - if (MemoryType != EfiBootServicesData && - MemoryType != EfiRuntimeServicesData) { - return EFI_INVALID_PARAMETER; - } - RootBridge = ROOT_BRIDGE_FROM_THIS (This); + DmaAbove4GB = RootBridge->DmaAbove4G && + (Attributes & EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE) != 0; - AllocateType = AllocateAnyPages; - if (!RootBridge->DmaAbove4G || - (Attributes & EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE) == 0) { - // - // Limit allocations to memory below 4GB - // - AllocateType = AllocateMaxAddress; - PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (SIZE_4GB - 1); - } - Status = gBS->AllocatePages ( - AllocateType, - MemoryType, - Pages, - &PhysicalAddress - ); - if (!EFI_ERROR (Status)) { - *HostAddress = (VOID *) (UINTN) PhysicalAddress; - } - - return Status; + return BmDmaAllocateBuffer ( + DmaAbove4GB, + MemoryType, + Pages, + HostAddress + ); } /** @@ -1356,7 +1212,7 @@ RootBridgeIoFreeBuffer ( OUT VOID *HostAddress ) { - return gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress, Pages); + return BmDmaFreeBuffer (Pages, HostAddress); } /** diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index b343c19..47aa9b9 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -83,6 +83,7 @@ [LibraryClasses] PalLib|MdePkg/Library/BasePalLibNull/BasePalLibNull.inf CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf + BmDmaLib|MdeModulePkg/Library/DxeBmDmaLib/DxeBmDmaLib.inf # # Misc # -- 1.9.1