From nobody Sat Nov 2 16:31:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zoho.com; 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 1486658445546509.4666162340069; Thu, 9 Feb 2017 08:40:45 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 52DEA81FF0; Thu, 9 Feb 2017 08:40:43 -0800 (PST) Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on062b.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe48::62b]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 86EC681F53 for ; Thu, 9 Feb 2017 08:40:42 -0800 (PST) Received: from leduran-Precision-WorkStation-T5400.amd.com (165.204.77.1) by MWHPR12MB1245.namprd12.prod.outlook.com (10.169.204.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.888.16; Thu, 9 Feb 2017 16:40:40 +0000 X-Original-To: edk2-devel@ml01.01.org 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=ksC/2/trLJ1MBh3OUsgrY4H/KuydnuSCoKJ93pWRR/s=; b=RfF77OSuUrPkI0YXQkpBGC2Oi2brvh/bfkEYDetxXWltUW/qfNMyOEEVTZeQvBT4yD8AGhK2npq+Qap/rJOVT+AfhxDZGFTjgELG+nwrjU7ihSclC/mjMCDUSdAH7NERtAQT/1i3fD8gBdEwkRNteHBVPF3F5mJY53zz5PJSbO8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=leo.duran@amd.com; From: Leo Duran To: Date: Thu, 9 Feb 2017 10:40:22 -0600 Message-ID: <1486658427-6551-2-git-send-email-leo.duran@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486658427-6551-1-git-send-email-leo.duran@amd.com> References: <1486658427-6551-1-git-send-email-leo.duran@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: YTOPR01CA0009.CANPRD01.PROD.OUTLOOK.COM (10.166.147.19) To MWHPR12MB1245.namprd12.prod.outlook.com (10.169.204.149) X-MS-Office365-Filtering-Correlation-Id: cff3c7c2-a1bb-431c-82ee-08d4510a627e X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:MWHPR12MB1245; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1245; 3:APe6ul5hQtg0UPhtwtWhVMK9bpuW/+NXRJyTMloXE0VVgDFxNbXSg9HS+77gCFz1VV7HBl0h5cGhRqy9e7zIqLlqXWrDCWbko9FgkB8yxj1QvC1wkye0L16+ixbvOtaDX/jE3plf6ZsUgI+Zy/Iw+7R+ptQZXP/xlfGa8B9ArCTXqaO+73O0RY3P/XwJndNsXsuCUX0vtxoohj6n12WW3oQW6q9pq+4DvNs0HZKXhqYEtgox3wNqyow4bHR5plqoWgMOgpPdtrUnhXDv5TG11qnrkRoRY6ewI/uyVuex62g=; 25:En0esSN2XVD4QbKtrBaamxB+SNpF6kw0mlulgZajqey2ABD9NqHXKa2fAslv8we28e1bNvQ9Neh6YPmjvdyuqcbH9eyb0mtdnuI/qvRPECIpviDg6R8FzOeoWbZvHEy7TgyFeAaSllwyzRcu5l8zY5JOfIPTcLsxhYfjsHbUX8mJyQoQAKYgr2ClfzqyH0KgvBUtZWQbFqyCSB+FB+E9jLrVUiL2gv27u7opelc25sVTy2jVvPzzyLUJFrMqE9jPDOnyQ90h6JUrBNF8fYrIWP9XGrI9NPNpeaZiNM/YIu0GXsYdoHFGf34k+6qhCg3hUAJ0HFY4iQmD7vktNm4aprjvoRhN3i9JOrdpHbYnmTreMGFut5tgkOEhtLv7Ni3cg88ncS6fbpSHnDtCn9ptJldDjZ7l2qWwxDV+ezqrb0HtWaoW+D91/hp3ct2LPFczAT69C4fibPBl5vmWZEF9Zg== X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1245; 31:FflO/Rqi51PzsN/iyJYCwJE1vl0SES8dQ5IzPTG+zO7C/7N9fgW9EjH9Bid/SPbHd3NxoUH49bryzE/uJnFBOHw+bzVAbhASwwXvkThrMR58sLSGtKqrtbB8xbGI3kzaowaFZp1c5/v4cTn4h3Uff+OAXm6SnLiTd8Ux+6cZppb+ns5+T5zDgLNy6s4XdDsev2zbWxJRqLMj5x9iqMBf1YkXiMqy7q2Jm03uLJ4CBEujcXrJclwa1CTMAdp9J+4Kl7vEzbw0BHR0cCaLmAAF/Q==; 20:axb6zinQDtB/kvP5/3maM+zcVpfV7GhXoW0YdrRJaEITuh+vzaCSI0/07V+c/d8gNXuYReapv1CyW8u4ypUBODHgssSrWXtNPNsewzk5YVqX9WQZeRSSPSgYAcIN1+HAjsoIhKmL5kcPdABUkaTq0JBAahJp4TzBenmbkx33VunYXUMks8v5Bf5DdsjL5svuuund9K4kD2NEa7qN9bK+0y5VFECKfQYRyyiFq9w/j9Z+frwe/cXyDemsTUMsBAKUe8Us1Xvr3p3BnFz+Kffh057XKvZXYsr29uWBVKeS2ZbPJNVpvYZlr/UZWJwBgoC2J3K4mef1NfxYlnijYFXN8D3Ikqbfjk8EuNuQQoKRAwjPBBukhD1sNjBewXPHuxCk8TldK4HarOKorx+DBRVUm31J1xl2ImdYRKm9JOsv5nd7mLv4BrmxRX3PnxEhq5758UTzNoJRh/fB4ODxaDNn0KxNg0JBpHrojbyDwKXVYi3Z0h1llYHYvSbA0epuS1KC 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)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6041248)(20161123560025)(20161123564025)(20161123558025)(20161123555025)(20161123562025)(6072148); SRVR:MWHPR12MB1245; BCL:0; PCL:0; RULEID:; SRVR:MWHPR12MB1245; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1245; 4:BToaNRMTAbXDIOGgQjMo4ihOsJ/+oOG9Qloz1C17NyLpJEUiUlZPNQLY7wNG7I0DTWNgizIhAm8jPEYsVaVnpE0vY7NqtlJ6jSEHoQxtiZ4hrYJ0uo1uS5y1AB5Zz6Q9gof7y9PNdvqSyv44gauGmeiE3x9hgDQJ7DN8SdD3v+Ge2a+w9uBYv0Q1RyAVaVw6IU/GF2bEoB4mG37gH4+gVa22NKyXMi9ckHxV8ozNg7Yd+h+E1JVRF5BUrOFnc7mL9mrtaJI7kjZL36w29/a1wixnJm+6eh/VXcM9NES1sbZWEXkZqBDMPAgLAa1K1A7cfMlg+MOX9c2TrSo5zgWxbrk/GBLDZRKXxzAY13Vz0rRJg87ynI6nCf00LVPlxV+bCezCPis1mzw1UYg35ertkF9W+RRcLbRG+sLPdbxnIiO0k/7vKlZsyhKWTrWhdXl6f0MbSTHF9anP70o/v4jrQGAx9rQX9M2hC5PMNOHs1D4CXNBQlA7rJsjcUiAm7gaMzinjRwgTPtVQQY4TbB7YdCNrPbNe8aVO8PO/4CivbX897QOTxnoC7OSqQyK5j25PBP7yVoDkwZ1icr5TI33On32fKbxSMfTKYFZLStTbaK7+HCcscS5QIU+8bnoL1RlQfRuABgwvahXfm9HGHjtDPYefSBtMtYrl8fVKhMwej+Nxo6Rjd18IjpzaIaC26yUcLmHVsV5cL40I1rSAuaHXEA== X-Forefront-PRVS: 02135EB356 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6029001)(6009001)(7916002)(39860400002)(39840400002)(39410400002)(39450400003)(39850400002)(189002)(199003)(101416001)(15188155005)(76176999)(66066001)(2906002)(47776003)(189998001)(54906002)(4326007)(305945005)(53416004)(2351001)(105586002)(106356001)(6306002)(50986999)(42186005)(5003940100001)(31430400001)(25786008)(92566002)(68736007)(7736002)(50466002)(16799955002)(50226002)(3846002)(6116002)(48376002)(966004)(6486002)(97736004)(81156014)(8676002)(81166006)(36756003)(110136004)(2950100002)(38730400002)(33646002)(6916009)(6666003)(575784001)(86362001)(53376002)(53936002)(5660300001); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1245; H:leduran-Precision-WorkStation-T5400.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; 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: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR12MB1245; 23:6opktY0bREscUXJmdApBXd6pstUDDZfSu0Xpkpj0E?= =?us-ascii?Q?73sDyzr72GEyvd4T8I33ZGvwAbyUFFNYOZIyGCF7Q1hg5bzKGfBEpiytIekI?= =?us-ascii?Q?WbsPiOmLlqDB+a6Ms3326gpAd91l+wWlGfYDot8ShUUD+pzbL8sMpsAq58xI?= =?us-ascii?Q?vmCHB3mauwM8uWwkXt8ocqRjHmAdjnOpJHv4UPn7w8BMLN0mwDp+lkhmeCiv?= =?us-ascii?Q?mrcAFuV6E7JmmDu4WpyTIR1PZel2fyGT9obRU419BXopCjTZq+zZiMDc+78u?= =?us-ascii?Q?yjHE27vOSfyVSFIN1HEvlHozd8nuCZTzNUdj3bzsXe1UurJqz9DeuIkkq/O4?= =?us-ascii?Q?FXaltsTm3TbkaWo29581x/YCwLI/DFTOaYLLDizgJi4nR2HIFdav8HMkWNs4?= =?us-ascii?Q?WTt7mdxwbsyRV4SNBcxcp2bHD5IdOgjy+DGXrOlNDFJ11nmiYqAQjLUpk8tU?=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qIOPkCxp0e7IKscXVHB3PF0EGGFQ0YStna7f9kQIgXVYRVJDRfwQ1wtRRV5XvIgIqldhnR6Y20aqL4ZnHiD0Lrvr+z1jwuefq1GRcPukMdsSwLR+MZZfkGe0QvHy48egyrPJkTrWU3UnS7WdJO4pDNxtJcNjMn/dwHVwuc+Xq7vnItY+WlhYrKu1ODklLDwSWi0ROIaljyc3qzVlu+oGGYZZZaEL33IfAJrUQmcmZ1lgv18gm8A26vDYPRjH5m1rutVf/6YFiXQSTZfAWRTDxU+NgDZwrZmfvjD5SFBl4hiCit1i0X4o97Zdrgv1WzqIOmTGLsFuA2d6tt4e9JeO9e5fOh8WU6pHJg==; 20:aOmd7QdH4Ad8oKRqhdYJ22Q0L8+DXfERS8gc5dwUxIEoxi367enOHcD+hbLeXPHUZEeJzbAqxctUhh7zjLMYwa/ikfe+XHPcJCJB8tQKkdSDHMRT7dmi7gtxaqn/j7Thrs9VVq6aWqTmg7N21ODlKiBdty/fcAGkbDalFX7iegx4R/HZ6JpJcZ0vTiebk+2pSJUmJpfkb10r5CQQ+anVcsoT/A9t86dRk3XA12WMS0fQ1IlWocAGfCPV2JnomoAE X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2017 16:40:40.2587 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1245 Subject: [edk2] [PATCH v3 1/6] MdeModulePkg: Add DxeBmDmaLib (BmDmaLib class) 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: , Cc: Feng Tian , Leo Duran , Star Zeng Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch provides an abstraction layer for Bus-master DMA operations as currently implemented by the PciHostBridgeDxe driver. The intent is to then allow override of this library as may be required by specific hardware implementations, such as AMD's Secure Encrypted Virtualization (SEV). This new BmDmaLib class library is cloned from the existing DmaLib with an additional DmaAbove4GB (BOOLEAN) parameter for the Map and Allocate interfaces, so that decisions can be made about the need to allocate DMA buffers below the 4GB boundary. Cc: Feng Tian Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Leo Duran --- MdeModulePkg/Include/Library/BmDmaLib.h | 161 +++++++++++ MdeModulePkg/Library/DxeBmDmaLib/DxeBmDmaLib.c | 351 +++++++++++++++++++= ++++ MdeModulePkg/Library/DxeBmDmaLib/DxeBmDmaLib.inf | 41 +++ MdeModulePkg/MdeModulePkg.dsc | 1 + 4 files changed, 554 insertions(+) create mode 100644 MdeModulePkg/Include/Library/BmDmaLib.h create mode 100644 MdeModulePkg/Library/DxeBmDmaLib/DxeBmDmaLib.c create mode 100644 MdeModulePkg/Library/DxeBmDmaLib/DxeBmDmaLib.inf diff --git a/MdeModulePkg/Include/Library/BmDmaLib.h b/MdeModulePkg/Include= /Library/BmDmaLib.h new file mode 100644 index 0000000..2c0e50f --- /dev/null +++ b/MdeModulePkg/Include/Library/BmDmaLib.h @@ -0,0 +1,161 @@ +/** @file + DMA abstraction library APIs. Based on PCI IO protocol DMA abstractions. + + Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+ Copyright (c) 2017, AMD Inc. All rights reserved.
+ + DMA Bus Master Read Operation: + Call BmDmaMap() for DmaOperationBusMasterRead. + Program the DMA Bus Master with the DeviceAddress returned by BmDmaMap= (). + Start the DMA Bus Master. + Wait for DMA Bus Master to complete the read operation. + Call BmDmaUnmap(). + + DMA Bus Master Write Operation: + Call BmDmaMap() for DmaOperationBusMasterWrite. + Program the DMA Bus Master with the DeviceAddress returned by BmDmaMap= (). + Start the DMA Bus Master. + Wait for DMA Bus Master to complete the write operation. + Call BmDmaUnmap(). + + DMA Bus Master Common Buffer Operation: + Call BmDmaAllocateBuffer() to allocate a common buffer. + Call BmDmaMap() for DmaOperationBusMasterCommonBuffer. + Program the DMA Bus Master with the DeviceAddress returned by BmDmaMap= (). + The common buffer can now be accessed equally by the processor and the= DMA bus master. + Call BmDmaUnmap(). + Call BmDmaFreeBuffer(). + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + + Derived from: + EmbeddedPkg/Include/Library/DmaLib.h + +**/ + +#ifndef __BM_DMA_LIB_H__ +#define __BM_DMA_LIB_H__ + + +typedef enum { + /// + /// A read operation from system memory by a bus master. + /// + DmaOperationBusMasterRead, + /// + /// A write operation from system memory by a bus master. + /// + DmaOperationBusMasterWrite, + /// + /// Provides both read and write access to system memory by both the pro= cessor and a + /// bus master. The buffer is coherent from both the processor's and the= bus master's point of view. + /// + DmaOperationBusMasterCommonBuffer, + DmaOperationBusMasterMaximum +} BM_DMA_OPERATION; + + +/** + Provides the DMA controller-specific addresses needed to access system m= emory. + + Operation is relative to the DMA bus master. + + @param DmaAbove4GB Indicates capability of DMA operations abo= ve 4GB. + @param Operation Indicates if the bus master is going to re= ad or write to system memory. + @param HostAddress The system memory address to map to the DM= A controller. + @param NumberOfBytes On input the number of bytes to map. On ou= tput the number of bytes + that were mapped. + @param DeviceAddress The resulting map address for the bus mast= er controller to use to + access the hosts HostAddress. + @param Mapping A resulting value to pass to BmDmaUnmap(). + + @retval EFI_SUCCESS The range was mapped for the returned Numb= erOfBytes. + @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a comm= on buffer. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to = a lack of resources. + @retval EFI_DEVICE_ERROR The system hardware could not map the requ= ested address. + +**/ +EFI_STATUS +EFIAPI +BmDmaMap ( + IN BOOLEAN DmaAbove4GB, + IN BM_DMA_OPERATION Operation, + IN VOID *HostAddress, + IN OUT UINTN *NumberOfBytes, + OUT PHYSICAL_ADDRESS *DeviceAddress, + OUT VOID **Mapping + ); + + +/** + Completes the DmaOperationBusMasterRead/Write/CommonBuffer operation + and releases any corresponding resources. + + @param Mapping The mapping value returned from BmDmaMap(). + + @retval EFI_SUCCESS The range was unmapped. + @retval EFI_DEVICE_ERROR The data was not committed to the target s= ystem memory. + +**/ +EFI_STATUS +EFIAPI +BmDmaUnmap ( + IN VOID *Mapping + ); + + +/** + Allocates pages that are suitable for a BmDmaMap() of type DmaOperationB= usMasterCommonBuffer. + + @param DmaAbove4GB Indicates capability of DMA operations abo= ve 4GB. + @param MemoryType The type of memory to allocate: EfiBootSer= vicesData or + EfiRuntimeServicesData. + @param Pages The number of pages to allocate. + @param HostAddress A pointer to store the base system memory = address of the + allocated range. + + @retval EFI_SUCCESS The requested memory pages were allocated. + @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal = attribute bits are + MEMORY_WRITE_COMBINE and MEMORY_CACHED. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. + +**/ +EFI_STATUS +EFIAPI +BmDmaAllocateBuffer ( + IN BOOLEAN DmaAbove4GB, + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages, + OUT VOID **HostAddress + ); + + +/** + Frees memory that was allocated with BmDmaAllocateBuffer(). + + @param Pages The number of pages to free. + @param HostAddress The base system memory address of the allo= cated range. + + @retval EFI_SUCCESS The requested memory pages were freed. + @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress = and Pages + was not allocated with BmDmaAllocateBuffer= (). + +**/ +EFI_STATUS +EFIAPI +BmDmaFreeBuffer ( + IN UINTN Pages, + IN VOID *HostAddress + ); + + +#endif + diff --git a/MdeModulePkg/Library/DxeBmDmaLib/DxeBmDmaLib.c b/MdeModulePkg/= Library/DxeBmDmaLib/DxeBmDmaLib.c new file mode 100644 index 0000000..824b51f --- /dev/null +++ b/MdeModulePkg/Library/DxeBmDmaLib/DxeBmDmaLib.c @@ -0,0 +1,351 @@ +/** @file + DMA abstraction library APIs. Based on PCI IO protocol DMA abstractions. + + Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+ Copyright (c) 2017, AMD Inc. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + + Derived from: + MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + + +#define FORCE_BELOW_4GB_TRUE TRUE +#define FORCE_BELOW_4GB_FALSE FALSE +#define NO_MAPPING (VOID *) (UINTN) -1 + + +typedef struct { + BM_DMA_OPERATION Operation; + UINTN NumberOfBytes; + UINTN NumberOfPages; + EFI_PHYSICAL_ADDRESS HostAddress; + EFI_PHYSICAL_ADDRESS MappedHostAddress; +} MAP_INFO; + + +EFI_STATUS +AllocateBounceBuffer ( + IN BOOLEAN ForceBelow4GB, + IN BM_DMA_OPERATION Operation, + IN EFI_PHYSICAL_ADDRESS HostAddress, + IN OUT UINTN *NumberOfBytes, + OUT PHYSICAL_ADDRESS *DeviceAddress, + OUT VOID **Mapping + ) +{ + EFI_STATUS Status; + MAP_INFO *MapInfo; + EFI_ALLOCATE_TYPE AllocateType; + + // + // Allocate a MAP_INFO structure to remember the mapping when Unmap() is + // called later. + // + MapInfo =3D AllocatePool (sizeof (MAP_INFO)); + if (MapInfo =3D=3D NULL) { + *NumberOfBytes =3D 0; + return EFI_OUT_OF_RESOURCES; + } + + // + // Initialize the MAP_INFO structure + // + MapInfo->Operation =3D Operation; + MapInfo->NumberOfBytes =3D *NumberOfBytes; + MapInfo->NumberOfPages =3D EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes); + MapInfo->HostAddress =3D HostAddress; + + if (ForceBelow4GB) { + // + // Limit allocations to memory below 4GB + // + AllocateType =3D AllocateMaxAddress; + MapInfo->MappedHostAddress =3D SIZE_4GB - 1; + } else { + AllocateType =3D AllocateAnyPages; + } + + // + // Allocate DMA bounce buffer + // + Status =3D gBS->AllocatePages ( + AllocateType, + EfiBootServicesData, + MapInfo->NumberOfPages, + &MapInfo->MappedHostAddress + ); + + if (EFI_ERROR (Status)) { + FreePool (MapInfo); + *NumberOfBytes =3D 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 =3D=3D DmaOperationBusMasterRead) { + CopyMem ( + (VOID *) (UINTN) MapInfo->MappedHostAddress, + (VOID *) (UINTN) MapInfo->HostAddress, + MapInfo->NumberOfBytes + ); + } + + // + // The DeviceAddress is the address of the mapped buffer + // + *DeviceAddress =3D MapInfo->MappedHostAddress; + + // + // Return a pointer to the MAP_INFO structure in Mapping + // + *Mapping =3D MapInfo; + + return EFI_SUCCESS; +} + + +/** + Provides the DMA controller-specific addresses needed to access system m= emory. + + Operation is relative to the DMA bus master. + + @param DmaAbove4GB Indicates capability of DMA operations abo= ve 4GB. + @param Operation Indicates if the bus master is going to re= ad or write to system memory. + @param HostAddress The system memory address to map to the DM= A controller. + @param NumberOfBytes On input the number of bytes to map. On ou= tput the number of bytes + that were mapped. + @param DeviceAddress The resulting map address for the bus mast= er controller to use to + access the hosts HostAddress. + @param Mapping A resulting value to pass to BmDmaUnmap(). + + @retval EFI_SUCCESS The range was mapped for the returned Numb= erOfBytes. + @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a comm= on buffer. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to = a lack of resources. + @retval EFI_DEVICE_ERROR The system hardware could not map the requ= ested address. + +**/ +EFI_STATUS +EFIAPI +BmDmaMap ( + IN BOOLEAN DmaAbove4GB, + IN BM_DMA_OPERATION Operation, + IN VOID *HostAddress, + IN OUT UINTN *NumberOfBytes, + OUT PHYSICAL_ADDRESS *DeviceAddress, + OUT VOID **Mapping + ) +{ + EFI_PHYSICAL_ADDRESS PhysicalAddress; + + // + // Check for invalid inputs + // + if (HostAddress =3D=3D NULL || NumberOfBytes =3D=3D NULL || DeviceAddres= s =3D=3D NULL || + Mapping =3D=3D NULL || (UINT32) Operation >=3D DmaOperationBusMaster= Maximum) { + return EFI_INVALID_PARAMETER; + } + + PhysicalAddress =3D (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress; + if (DmaAbove4GB || (PhysicalAddress + *NumberOfBytes) <=3D SIZE_4GB) { + // + // If we CAN handle DMA above 4GB or the transfer is below 4GB, + // the DeviceAddress is simply the HostAddress + // + *DeviceAddress =3D PhysicalAddress; + *Mapping =3D NO_MAPPING; + + return EFI_SUCCESS; + }=20 + + // + // If we cannot handle DMA above 4GB and any part of the DMA transfer + // being is above 4GB, then map the DMA transfer to a buffer below 4GB. + // + if (Operation =3D=3D DmaOperationBusMasterCommonBuffer) { + // + // Common Buffer operations cannot be remapped, so return an error. + // + return EFI_UNSUPPORTED; + } + + return AllocateBounceBuffer (=20 + Operation, + FORCE_BELOW_4GB_TRUE, =20 + PhysicalAddress, + NumberOfBytes, + DeviceAddress, + Mapping + ); +} + + +/** + Completes the DmaOperationBusMasterRead/Write/CommonBuffer operation + and releases any corresponding resources. + + @param Mapping The mapping value returned from BmDmaMap(). + + @retval EFI_SUCCESS The range was unmapped. + @retval EFI_DEVICE_ERROR The data was not committed to the target s= ystem memory. + +**/ +EFI_STATUS +EFIAPI +BmDmaUnmap ( + IN VOID *Mapping + ) +{ + MAP_INFO *MapInfo; + + // + // Check for invalid inputs + // + if (Mapping =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // See if the Map() operation associated with this Unmap() required a ma= pping + // buffer. If a mapping buffer was not required, then this function simp= ly + // returns EFI_SUCCESS. + // + if (Mapping =3D=3D NO_MAPPING) { + return EFI_SUCCESS; + } + + // + // 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. + // + MapInfo =3D (MAP_INFO *)Mapping; + if (MapInfo->Operation =3D=3D DmaOperationBusMasterWrite) { + 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; +} + + +/** + Allocates pages that are suitable for a BmDmaMap() of type DmaOperationB= usMasterCommonBuffer. + + @param DmaAbove4GB Indicates capability of DMA operations abo= ve 4GB. + @param MemoryType The type of memory to allocate: EfiBootSer= vicesData or + EfiRuntimeServicesData. + @param Pages The number of pages to allocate. + @param HostAddress A pointer to store the base system memory = address of the + allocated range. + + @retval EFI_SUCCESS The requested memory pages were allocated. + @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal = attribute bits are + MEMORY_WRITE_COMBINE and MEMORY_CACHED. + @retval EFI_INVALID_PARAMETER One or more parameters are invalid. + @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated. + +**/ +EFI_STATUS +EFIAPI +BmDmaAllocateBuffer ( + IN BOOLEAN DmaAbove4GB, + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages, + OUT VOID **HostAddress + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS PhysicalAddress; + EFI_ALLOCATE_TYPE AllocateType; + + // + // Check for invalid inputs + // + if (HostAddress =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // The only valid memory types are EfiBootServicesData and + // EfiRuntimeServicesData + // + if (MemoryType !=3D EfiBootServicesData && + MemoryType !=3D EfiRuntimeServicesData) { + return EFI_INVALID_PARAMETER; + } + + if (DmaAbove4GB) { + AllocateType =3D AllocateAnyPages; + } else { + // + // Limit allocations to memory below 4GB + // + AllocateType =3D AllocateMaxAddress; + PhysicalAddress =3D (EFI_PHYSICAL_ADDRESS) (SIZE_4GB - 1); + } + Status =3D gBS->AllocatePages ( + AllocateType, + MemoryType, + Pages, + &PhysicalAddress + ); + if (!EFI_ERROR (Status)) { + *HostAddress =3D (VOID *) (UINTN) PhysicalAddress; + } + + return Status; +} + + +/** + Frees memory that was allocated with BmDmaAllocateBuffer(). + + @param Pages The number of pages to free. + @param HostAddress The base system memory address of the allo= cated range. + + @retval EFI_SUCCESS The requested memory pages were freed. + @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress = and Pages + was not allocated with BmDmaAllocateBuffer= (). + +**/ +EFI_STATUS +EFIAPI +BmDmaFreeBuffer ( + IN UINTN Pages, + IN VOID *HostAddress + ) +{ + return gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress, Pages= ); +} + diff --git a/MdeModulePkg/Library/DxeBmDmaLib/DxeBmDmaLib.inf b/MdeModulePk= g/Library/DxeBmDmaLib/DxeBmDmaLib.inf new file mode 100644 index 0000000..4ddb27d --- /dev/null +++ b/MdeModulePkg/Library/DxeBmDmaLib/DxeBmDmaLib.inf @@ -0,0 +1,41 @@ +## @file +# +# DMA abstraction library APIs. Based on PCI IO protocol DMA abstractions. +# +# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+# Copyright (c) 2017, AMD Inc. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may = be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DxeBmDmaLib + FILE_GUID =3D daa403e0-071d-44ef-95cf-7f2472e4a4d5 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D BmDmaLib|DXE_DRIVER + +[Sources.common] + DxeBmDmaLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + DxeServicesTableLib + MemoryAllocationLib + UefiBootServicesTableLib + + diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 5996fe5..311922e 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -275,6 +275,7 @@ [Components] MdeModulePkg/Core/Pei/PeiMain.inf MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf =20 + MdeModulePkg/Library/DxeBmDmaLib/DxeBmDmaLib.inf MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf MdeModulePkg/Library/UefiMemoryAllocationProfileLib/UefiMemoryAllocation= ProfileLib.inf MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationL= ib.inf --=20 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel