- Copy the map registers to the buffer only, if they are used (in IoFlushAdapterBuffers).

- Do not use the byte offset into the page from a given buffer if the map registers are used, 
  because the caller didn't request for one additional register in the call to IoAllocateAdapterChannel 
  and it will not work for a 64k buffer.

svn path=/trunk/; revision=17665
This commit is contained in:
Hartmut Birr 2005-09-05 20:25:31 +00:00
parent 0389203146
commit ce7e038415
2 changed files with 10 additions and 22 deletions

View file

@ -646,12 +646,7 @@ HalGetAdapter(
} }
else else
{ {
/* MapRegisters = BYTES_TO_PAGES(MaximumLength);
* In the equation below the additional map register added by
* the "+1" accounts for the case when a transfer does not start
* at a page-aligned address.
*/
MapRegisters = BYTES_TO_PAGES(MaximumLength) + 1;
if (MapRegisters > 16) if (MapRegisters > 16)
MapRegisters = 16; MapRegisters = 16;
} }
@ -1466,7 +1461,6 @@ HalpCopyBufferMap(
{ {
ULONG CurrentLength; ULONG CurrentLength;
ULONG_PTR CurrentAddress; ULONG_PTR CurrentAddress;
ULONG ByteOffset;
PVOID VirtualAddress; PVOID VirtualAddress;
VirtualAddress = MmGetSystemAddressForMdlSafe(Mdl, HighPagePriority); VirtualAddress = MmGetSystemAddressForMdlSafe(Mdl, HighPagePriority);
@ -1487,15 +1481,11 @@ HalpCopyBufferMap(
while (Length > 0) while (Length > 0)
{ {
ByteOffset = BYTE_OFFSET(CurrentAddress); CurrentLength = min(PAGE_SIZE, Length);
CurrentLength = PAGE_SIZE - ByteOffset;
if (CurrentLength > Length)
CurrentLength = Length;
if (WriteToDevice) if (WriteToDevice)
{ {
RtlCopyMemory( RtlCopyMemory(
(PVOID)((ULONG_PTR)MapRegisterBase->VirtualAddress + ByteOffset), MapRegisterBase->VirtualAddress,
(PVOID)CurrentAddress, (PVOID)CurrentAddress,
CurrentLength); CurrentLength);
} }
@ -1503,7 +1493,7 @@ HalpCopyBufferMap(
{ {
RtlCopyMemory( RtlCopyMemory(
(PVOID)CurrentAddress, (PVOID)CurrentAddress,
(PVOID)((ULONG_PTR)MapRegisterBase->VirtualAddress + ByteOffset), MapRegisterBase->VirtualAddress,
CurrentLength); CurrentLength);
} }
@ -1584,7 +1574,7 @@ IoFlushAdapterBuffers(
RealMapRegisterBase = RealMapRegisterBase =
(PMAP_REGISTER_ENTRY)((ULONG_PTR)MapRegisterBase & ~MAP_BASE_SW_SG); (PMAP_REGISTER_ENTRY)((ULONG_PTR)MapRegisterBase & ~MAP_BASE_SW_SG);
if (!WriteToDevice) if (!WriteToDevice && RealMapRegisterBase->UseMapRegisters)
{ {
if ((ULONG_PTR)MapRegisterBase & MAP_BASE_SW_SG) if ((ULONG_PTR)MapRegisterBase & MAP_BASE_SW_SG)
{ {
@ -1654,7 +1644,6 @@ IoMapTransfer(
ULONG ByteOffset; ULONG ByteOffset;
ULONG TransferOffset; ULONG TransferOffset;
ULONG TransferLength; ULONG TransferLength;
BOOLEAN UseMapRegisters;
PMAP_REGISTER_ENTRY RealMapRegisterBase; PMAP_REGISTER_ENTRY RealMapRegisterBase;
PHYSICAL_ADDRESS PhysicalAddress; PHYSICAL_ADDRESS PhysicalAddress;
PHYSICAL_ADDRESS HighestAcceptableAddress; PHYSICAL_ADDRESS HighestAcceptableAddress;
@ -1754,9 +1743,8 @@ IoMapTransfer(
if ((ULONG_PTR)MapRegisterBase & MAP_BASE_SW_SG && if ((ULONG_PTR)MapRegisterBase & MAP_BASE_SW_SG &&
TransferLength < *Length) TransferLength < *Length)
{ {
UseMapRegisters = TRUE; RealMapRegisterBase->UseMapRegisters = TRUE;
PhysicalAddress = RealMapRegisterBase->PhysicalAddress; PhysicalAddress = RealMapRegisterBase->PhysicalAddress;
PhysicalAddress.QuadPart += ByteOffset;
TransferLength = *Length; TransferLength = *Length;
RealMapRegisterBase->Counter = ~0; RealMapRegisterBase->Counter = ~0;
Counter = 0; Counter = 0;
@ -1769,7 +1757,7 @@ IoMapTransfer(
* the transfer progress. * the transfer progress.
*/ */
UseMapRegisters = FALSE; RealMapRegisterBase->UseMapRegisters = FALSE;
Counter = RealMapRegisterBase->Counter; Counter = RealMapRegisterBase->Counter;
RealMapRegisterBase->Counter += BYTES_TO_PAGES(ByteOffset + TransferLength); RealMapRegisterBase->Counter += BYTES_TO_PAGES(ByteOffset + TransferLength);
@ -1783,9 +1771,8 @@ IoMapTransfer(
if (PhysicalAddress.QuadPart + TransferLength > if (PhysicalAddress.QuadPart + TransferLength >
HighestAcceptableAddress.QuadPart) HighestAcceptableAddress.QuadPart)
{ {
UseMapRegisters = TRUE; RealMapRegisterBase->UseMapRegisters = TRUE;
PhysicalAddress = RealMapRegisterBase->PhysicalAddress; PhysicalAddress = RealMapRegisterBase->PhysicalAddress;
PhysicalAddress.QuadPart += ByteOffset;
if ((ULONG_PTR)MapRegisterBase & MAP_BASE_SW_SG) if ((ULONG_PTR)MapRegisterBase & MAP_BASE_SW_SG)
{ {
RealMapRegisterBase->Counter = ~0; RealMapRegisterBase->Counter = ~0;
@ -1799,7 +1786,7 @@ IoMapTransfer(
* register memory. * register memory.
*/ */
if (UseMapRegisters && WriteToDevice) if (RealMapRegisterBase->UseMapRegisters && WriteToDevice)
{ {
HalpCopyBufferMap(Mdl, RealMapRegisterBase + Counter, HalpCopyBufferMap(Mdl, RealMapRegisterBase + Counter,
CurrentVa, TransferLength, WriteToDevice); CurrentVa, TransferLength, WriteToDevice);

View file

@ -315,6 +315,7 @@ typedef struct _MAP_REGISTER_ENTRY
PVOID VirtualAddress; PVOID VirtualAddress;
PHYSICAL_ADDRESS PhysicalAddress; PHYSICAL_ADDRESS PhysicalAddress;
ULONG Counter; ULONG Counter;
BOOLEAN UseMapRegisters;
} MAP_REGISTER_ENTRY, *PMAP_REGISTER_ENTRY; } MAP_REGISTER_ENTRY, *PMAP_REGISTER_ENTRY;
struct _ADAPTER_OBJECT { struct _ADAPTER_OBJECT {