]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / XhciPei / UsbHcMem.c
index 6a3f3a5df306270651ac217b1639028de6e27f79..56c0b900f35a1c746a2302d2a25c199873af90bb 100644 (file)
@@ -4,14 +4,7 @@ which is used to enable recovery function from USB Drivers.
 \r
 Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
 \r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions\r
-of the BSD License which accompanies this distribution.  The\r
-full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -31,6 +24,9 @@ UsbHcAllocMemBlock (
   )\r
 {\r
   USBHC_MEM_BLOCK       *Block;\r
+  VOID                  *BufHost;\r
+  VOID                  *Mapping;\r
+  EFI_PHYSICAL_ADDRESS  MappedAddr;\r
   EFI_STATUS            Status;\r
   UINTN                 PageNumber;\r
   EFI_PHYSICAL_ADDRESS  TempPtr;\r
@@ -71,18 +67,20 @@ UsbHcAllocMemBlock (
 \r
   Block->Bits = (UINT8 *) (UINTN) TempPtr;\r
 \r
-  Status = PeiServicesAllocatePages (\r
-             EfiBootServicesData,\r
+  Status = IoMmuAllocateBuffer (\r
              Pages,\r
-             &TempPtr\r
+             &BufHost,\r
+             &MappedAddr,\r
+             &Mapping\r
              );\r
   if (EFI_ERROR (Status)) {\r
     return NULL;\r
   }\r
-  ZeroMem ((VOID *) (UINTN) TempPtr, EFI_PAGES_TO_SIZE (Pages));\r
+  ZeroMem ((VOID *) (UINTN) BufHost, EFI_PAGES_TO_SIZE (Pages));\r
 \r
-  Block->BufHost = (UINT8 *) (UINTN) TempPtr;;\r
-  Block->Buf = (UINT8 *) (UINTN) TempPtr;\r
+  Block->BufHost = (UINT8 *) (UINTN) BufHost;\r
+  Block->Buf = (UINT8 *) (UINTN) MappedAddr;\r
+  Block->Mapping  = Mapping;\r
   Block->Next = NULL;\r
 \r
   return Block;\r
@@ -102,6 +100,9 @@ UsbHcFreeMemBlock (
   )\r
 {\r
   ASSERT ((Pool != NULL) && (Block != NULL));\r
+\r
+  IoMmuFreeBuffer (EFI_SIZE_TO_PAGES (Block->BufLen), Block->BufHost, Block->Mapping);\r
+\r
   //\r
   // No free memory in PEI.\r
   //\r
@@ -320,31 +321,7 @@ UsbHcIsMemBlockEmpty (
   return TRUE;\r
 }\r
 \r
-/**\r
-  Unlink the memory block from the pool's list.\r
-\r
-  @param  Head          The block list head of the memory's pool.\r
-  @param  BlockToUnlink The memory block to unlink.\r
-\r
-**/\r
-VOID\r
-UsbHcUnlinkMemBlock (\r
-  IN USBHC_MEM_BLOCK    *Head,\r
-  IN USBHC_MEM_BLOCK    *BlockToUnlink\r
-  )\r
-{\r
-  USBHC_MEM_BLOCK       *Block;\r
-\r
-  ASSERT ((Head != NULL) && (BlockToUnlink != NULL));\r
 \r
-  for (Block = Head; Block != NULL; Block = Block->Next) {\r
-    if (Block->Next == BlockToUnlink) {\r
-      Block->Next         = BlockToUnlink->Next;\r
-      BlockToUnlink->Next = NULL;\r
-      break;\r
-    }\r
-  }\r
-}\r
 \r
 /**\r
   Initialize the memory management pool for the host controller.\r
@@ -567,6 +544,7 @@ UsbHcFreeMem (
   @param  HostAddress           The system memory address to map to the PCI controller.\r
   @param  DeviceAddress         The resulting map address for the bus master PCI controller to\r
                                 use to access the hosts HostAddress.\r
+  @param  Mapping               A resulting value to pass to Unmap().\r
 \r
   @retval EFI_SUCCESS           Success to allocate aligned pages.\r
   @retval EFI_INVALID_PARAMETER Pages or Alignment is not valid.\r
@@ -578,13 +556,16 @@ UsbHcAllocateAlignedPages (
   IN UINTN                      Pages,\r
   IN UINTN                      Alignment,\r
   OUT VOID                      **HostAddress,\r
-  OUT EFI_PHYSICAL_ADDRESS      *DeviceAddress\r
+  OUT EFI_PHYSICAL_ADDRESS      *DeviceAddress,\r
+  OUT VOID                      **Mapping\r
   )\r
 {\r
   EFI_STATUS            Status;\r
-  EFI_PHYSICAL_ADDRESS  Memory;\r
+  VOID                  *Memory;\r
   UINTN                 AlignedMemory;\r
   UINTN                 AlignmentMask;\r
+  EFI_PHYSICAL_ADDRESS  DeviceMemory;\r
+  UINTN                 AlignedDeviceMemory;\r
   UINTN                 RealPages;\r
 \r
   //\r
@@ -611,32 +592,36 @@ UsbHcAllocateAlignedPages (
     //\r
     ASSERT (RealPages > Pages);\r
 \r
-    Status = PeiServicesAllocatePages (\r
-               EfiBootServicesData,\r
+    Status = IoMmuAllocateBuffer (\r
                Pages,\r
-               &Memory\r
+               &Memory,\r
+               &DeviceMemory,\r
+               Mapping\r
                );\r
     if (EFI_ERROR (Status)) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
     AlignedMemory = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask;\r
+    AlignedDeviceMemory = ((UINTN) DeviceMemory + AlignmentMask) & ~AlignmentMask;\r
   } else {\r
     //\r
     // Do not over-allocate pages in this case.\r
     //\r
-    Status = PeiServicesAllocatePages (\r
-               EfiBootServicesData,\r
+    Status = IoMmuAllocateBuffer (\r
                Pages,\r
-               &Memory\r
+               &Memory,\r
+               &DeviceMemory,\r
+               Mapping\r
                );\r
     if (EFI_ERROR (Status)) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
     AlignedMemory = (UINTN) Memory;\r
+    AlignedDeviceMemory = (UINTN) DeviceMemory;\r
   }\r
 \r
   *HostAddress = (VOID *) AlignedMemory;\r
-  *DeviceAddress = (EFI_PHYSICAL_ADDRESS) AlignedMemory;\r
+  *DeviceAddress = (EFI_PHYSICAL_ADDRESS) AlignedDeviceMemory;\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -646,17 +631,18 @@ UsbHcAllocateAlignedPages (
 \r
   @param  HostAddress           The system memory address to map to the PCI controller.\r
   @param  Pages                 The number of pages to free.\r
+  @param  Mapping               The mapping value returned from Map().\r
 \r
 **/\r
 VOID\r
 UsbHcFreeAlignedPages (\r
   IN VOID               *HostAddress,\r
-  IN UINTN              Pages\r
+  IN UINTN              Pages,\r
+  IN VOID               *Mapping\r
   )\r
 {\r
   ASSERT (Pages != 0);\r
-  //\r
-  // No free memory in PEI.\r
-  //\r
+\r
+  IoMmuFreeBuffer (Pages, HostAddress, Mapping);\r
 }\r
 \r