]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / EhciDxe / UsbHcMem.c
index 177c49f1e4070f0cbcf481c0e4d8b048cd8f9abe..baac29df66419b3f2ba9068edf58542dbf048558 100644 (file)
@@ -2,8 +2,8 @@
 \r
   Routine procedures for memory allocate/free.\r
 \r
-Copyright (c) 2007 - 2009, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.<BR>\r
+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
@@ -218,15 +218,15 @@ UsbHcAllocMemFromBlock (
     NEXT_BIT (Byte, Bit);\r
   }\r
 \r
-  return Block->Buf + (StartByte * 8 + StartBit) * USBHC_MEM_UNIT;\r
+  return Block->BufHost + (StartByte * 8 + StartBit) * USBHC_MEM_UNIT;\r
 }\r
 \r
 /**\r
-  Get the pci memory address according to the allocated host memory address.\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 memory to free.\r
-  @param  Size           The size of the memory to free.\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
@@ -246,12 +246,16 @@ UsbHcGetPciAddressForHostMem (
   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->Buf <= (UINT8 *) Mem) && (((UINT8 *) Mem + AllocSize) <= (Block->Buf + Block->BufLen))) {\r
+    if ((Block->BufHost <= (UINT8 *) Mem) && (((UINT8 *) Mem + AllocSize) <= (Block->BufHost + Block->BufLen))) {\r
       break;\r
     }\r
   }\r
@@ -261,7 +265,7 @@ UsbHcGetPciAddressForHostMem (
   // calculate the pci memory address for host memory address.\r
   //\r
   Offset = (UINT8 *)Mem - Block->BufHost;\r
-  PhyAddr = (EFI_PHYSICAL_ADDRESS)(Block->Buf + Offset);\r
+  PhyAddr = (EFI_PHYSICAL_ADDRESS)(UINTN) (Block->Buf + Offset);\r
   return PhyAddr;\r
 }\r
 \r
@@ -522,12 +526,12 @@ UsbHcFreeMem (
     // scan the memory block list for the memory block that\r
     // completely contains the memory to free.\r
     //\r
-    if ((Block->Buf <= ToFree) && ((ToFree + AllocSize) <= (Block->Buf + Block->BufLen))) {\r
+    if ((Block->BufHost <= ToFree) && ((ToFree + AllocSize) <= (Block->BufHost + Block->BufLen))) {\r
       //\r
       // compute the start byte and bit in the bit array\r
       //\r
-      Byte  = ((ToFree - Block->Buf) / USBHC_MEM_UNIT) / 8;\r
-      Bit   = ((ToFree - Block->Buf) / USBHC_MEM_UNIT) % 8;\r
+      Byte  = ((ToFree - Block->BufHost) / USBHC_MEM_UNIT) / 8;\r
+      Bit   = ((ToFree - Block->BufHost) / USBHC_MEM_UNIT) % 8;\r
 \r
       //\r
       // reset associated bits in bit arry\r