From ce7e03841552490d4230f60feb00972a1eded234 Mon Sep 17 00:00:00 2001 From: Hartmut Birr Date: Mon, 5 Sep 2005 20:25:31 +0000 Subject: [PATCH] - 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 --- reactos/hal/halx86/generic/dma.c | 31 +++++++++-------------------- reactos/hal/halx86/include/haldma.h | 1 + 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/reactos/hal/halx86/generic/dma.c b/reactos/hal/halx86/generic/dma.c index cb41e29bb47..572d5dcff19 100644 --- a/reactos/hal/halx86/generic/dma.c +++ b/reactos/hal/halx86/generic/dma.c @@ -646,12 +646,7 @@ HalGetAdapter( } else { - /* - * 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; + MapRegisters = BYTES_TO_PAGES(MaximumLength); if (MapRegisters > 16) MapRegisters = 16; } @@ -1466,7 +1461,6 @@ HalpCopyBufferMap( { ULONG CurrentLength; ULONG_PTR CurrentAddress; - ULONG ByteOffset; PVOID VirtualAddress; VirtualAddress = MmGetSystemAddressForMdlSafe(Mdl, HighPagePriority); @@ -1487,15 +1481,11 @@ HalpCopyBufferMap( while (Length > 0) { - ByteOffset = BYTE_OFFSET(CurrentAddress); - CurrentLength = PAGE_SIZE - ByteOffset; - if (CurrentLength > Length) - CurrentLength = Length; - + CurrentLength = min(PAGE_SIZE, Length); if (WriteToDevice) { RtlCopyMemory( - (PVOID)((ULONG_PTR)MapRegisterBase->VirtualAddress + ByteOffset), + MapRegisterBase->VirtualAddress, (PVOID)CurrentAddress, CurrentLength); } @@ -1503,7 +1493,7 @@ HalpCopyBufferMap( { RtlCopyMemory( (PVOID)CurrentAddress, - (PVOID)((ULONG_PTR)MapRegisterBase->VirtualAddress + ByteOffset), + MapRegisterBase->VirtualAddress, CurrentLength); } @@ -1584,7 +1574,7 @@ IoFlushAdapterBuffers( RealMapRegisterBase = (PMAP_REGISTER_ENTRY)((ULONG_PTR)MapRegisterBase & ~MAP_BASE_SW_SG); - if (!WriteToDevice) + if (!WriteToDevice && RealMapRegisterBase->UseMapRegisters) { if ((ULONG_PTR)MapRegisterBase & MAP_BASE_SW_SG) { @@ -1654,7 +1644,6 @@ IoMapTransfer( ULONG ByteOffset; ULONG TransferOffset; ULONG TransferLength; - BOOLEAN UseMapRegisters; PMAP_REGISTER_ENTRY RealMapRegisterBase; PHYSICAL_ADDRESS PhysicalAddress; PHYSICAL_ADDRESS HighestAcceptableAddress; @@ -1754,9 +1743,8 @@ IoMapTransfer( if ((ULONG_PTR)MapRegisterBase & MAP_BASE_SW_SG && TransferLength < *Length) { - UseMapRegisters = TRUE; + RealMapRegisterBase->UseMapRegisters = TRUE; PhysicalAddress = RealMapRegisterBase->PhysicalAddress; - PhysicalAddress.QuadPart += ByteOffset; TransferLength = *Length; RealMapRegisterBase->Counter = ~0; Counter = 0; @@ -1769,7 +1757,7 @@ IoMapTransfer( * the transfer progress. */ - UseMapRegisters = FALSE; + RealMapRegisterBase->UseMapRegisters = FALSE; Counter = RealMapRegisterBase->Counter; RealMapRegisterBase->Counter += BYTES_TO_PAGES(ByteOffset + TransferLength); @@ -1783,9 +1771,8 @@ IoMapTransfer( if (PhysicalAddress.QuadPart + TransferLength > HighestAcceptableAddress.QuadPart) { - UseMapRegisters = TRUE; + RealMapRegisterBase->UseMapRegisters = TRUE; PhysicalAddress = RealMapRegisterBase->PhysicalAddress; - PhysicalAddress.QuadPart += ByteOffset; if ((ULONG_PTR)MapRegisterBase & MAP_BASE_SW_SG) { RealMapRegisterBase->Counter = ~0; @@ -1799,7 +1786,7 @@ IoMapTransfer( * register memory. */ - if (UseMapRegisters && WriteToDevice) + if (RealMapRegisterBase->UseMapRegisters && WriteToDevice) { HalpCopyBufferMap(Mdl, RealMapRegisterBase + Counter, CurrentVa, TransferLength, WriteToDevice); diff --git a/reactos/hal/halx86/include/haldma.h b/reactos/hal/halx86/include/haldma.h index 163cd1f7d8d..bab43023838 100644 --- a/reactos/hal/halx86/include/haldma.h +++ b/reactos/hal/halx86/include/haldma.h @@ -315,6 +315,7 @@ typedef struct _MAP_REGISTER_ENTRY PVOID VirtualAddress; PHYSICAL_ADDRESS PhysicalAddress; ULONG Counter; + BOOLEAN UseMapRegisters; } MAP_REGISTER_ENTRY, *PMAP_REGISTER_ENTRY; struct _ADAPTER_OBJECT {