]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/UhciDxe/UsbHcMem.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / UhciDxe / UsbHcMem.c
index 7cc99ba5276ed15371a0e640346d407a7ac076e6..9aade19f8edce1150eea546726122d0a20a040ba 100644 (file)
@@ -2,14 +2,8 @@
 \r
   The routine procedure for uhci memory allocate/free.\r
 \r
-Copyright (c) 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The 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
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -123,8 +117,6 @@ FREE_BITARRAY:
   @param  Pool           The memory pool to free the block from.\r
   @param  Block          The memory block to free.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 UsbHcFreeMemBlock (\r
@@ -222,6 +214,53 @@ UsbHcAllocMemFromBlock (
   return Block->Buf + (StartByte * 8 + StartBit) * USBHC_MEM_UNIT;\r
 }\r
 \r
+/**\r
+  Calculate the corresponding pci bus address according to the Mem parameter.\r
+\r
+  @param  Pool           The memory pool of the host controller.\r
+  @param  Mem            The pointer to host memory.\r
+  @param  Size           The size of the memory region.\r
+\r
+  @return the pci memory address\r
+**/\r
+EFI_PHYSICAL_ADDRESS\r
+UsbHcGetPciAddressForHostMem (\r
+  IN USBHC_MEM_POOL       *Pool,\r
+  IN VOID                 *Mem,\r
+  IN UINTN                Size\r
+  )\r
+{\r
+  USBHC_MEM_BLOCK         *Head;\r
+  USBHC_MEM_BLOCK         *Block;\r
+  UINTN                   AllocSize;\r
+  EFI_PHYSICAL_ADDRESS    PhyAddr;\r
+  UINTN                   Offset;\r
+\r
+  Head      = Pool->Head;\r
+  AllocSize = USBHC_MEM_ROUND (Size);\r
+\r
+  if (Mem == NULL) {\r
+    return 0;\r
+  }\r
+\r
+  for (Block = Head; Block != NULL; Block = Block->Next) {\r
+    //\r
+    // scan the memory block list for the memory block that\r
+    // completely contains the allocated memory.\r
+    //\r
+    if ((Block->BufHost <= (UINT8 *) Mem) && (((UINT8 *) Mem + AllocSize) <= (Block->BufHost + Block->BufLen))) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  ASSERT ((Block != NULL));\r
+  //\r
+  // calculate the pci memory address for host memory address.\r
+  //\r
+  Offset = (UINT8 *)Mem - Block->BufHost;\r
+  PhyAddr = (EFI_PHYSICAL_ADDRESS)(UINTN) (Block->Buf + Offset);\r
+  return PhyAddr;\r
+}\r
 \r
 /**\r
   Insert the memory block to the pool's list of the blocks.\r
@@ -229,8 +268,6 @@ UsbHcAllocMemFromBlock (
   @param  Head           The head of the memory pool's block list.\r
   @param  Block          The memory block to insert.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 UsbHcInsertMemBlockToPool (\r
@@ -276,8 +313,6 @@ UsbHcIsMemBlockEmpty (
   @param  Head           The block list head of the memory's pool.\r
   @param  BlockToUnlink  The memory block to unlink.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 UsbHcUnlinkMemBlock (\r
@@ -458,8 +493,6 @@ UsbHcAllocateMem (
   @param  Mem            The memory to free.\r
   @param  Size           The size of the memory to free.\r
 \r
-  @return None.\r
-\r
 **/\r
 VOID\r
 UsbHcFreeMem (\r
@@ -493,7 +526,7 @@ UsbHcFreeMem (
       Bit   = ((ToFree - Block->Buf) / USBHC_MEM_UNIT) % 8;\r
 \r
       //\r
-      // reset associated bits in bit arry\r
+      // reset associated bits in bit array\r
       //\r
       for (Count = 0; Count < (AllocSize / USBHC_MEM_UNIT); Count++) {\r
         ASSERT (USB_HC_BIT_IS_SET (Block->Bits[Byte], Bit));\r