\r
*Mapping = Map;\r
\r
- if (((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) {\r
+ if ((((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) ||\r
+ ((*NumberOfBytes % gCacheAlignment) != 0)) {\r
+ //\r
+ // If the buffer does not fill entire cache lines we must double buffer into \r
+ // uncached memory. Device (PCI) address becomes uncached page.\r
+ //\r
Map->DoubleBuffer = TRUE;\r
Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (*NumberOfBytes), &Buffer);\r
if (EFI_ERROR (Status)) {\r
Map->DoubleBuffer = FALSE;\r
}\r
\r
- *NumberOfBytes &= *NumberOfBytes & ~(gCacheAlignment - 1); // Only do it on full cache lines\r
- \r
Map->HostAddress = (UINTN)HostAddress;\r
Map->DeviceAddress = *DeviceAddress;\r
Map->NumberOfBytes = *NumberOfBytes;\r