mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 18:15:11 +00:00
Export the HalGetDmaAdapter callback and use some nice macros where appropriate.
svn path=/trunk/; revision=17472
This commit is contained in:
parent
8872cc5e5d
commit
4fd4530977
2 changed files with 439 additions and 409 deletions
|
@ -139,6 +139,13 @@ HalpInitDma(VOID)
|
||||||
KeInitializeEvent(&HalpDmaLock, NotificationEvent, TRUE);
|
KeInitializeEvent(&HalpDmaLock, NotificationEvent, TRUE);
|
||||||
|
|
||||||
HalpMasterAdapter = HalpDmaAllocateMasterAdapter();
|
HalpMasterAdapter = HalpDmaAllocateMasterAdapter();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Setup the HalDispatchTable callback for creating PnP DMA adapters. It's
|
||||||
|
* used by IoGetDmaAdapter in the kernel.
|
||||||
|
*/
|
||||||
|
|
||||||
|
HalGetDmaAdapter = HalpGetDmaAdapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -760,6 +767,24 @@ HalGetAdapter(
|
||||||
return AdapterObject;
|
return AdapterObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name HalpGetDmaAdapter
|
||||||
|
*
|
||||||
|
* Internal routine to allocate PnP DMA adapter object. It's exported through
|
||||||
|
* HalDispatchTable and used by IoGetDmaAdapter.
|
||||||
|
*
|
||||||
|
* @see HalGetAdapter
|
||||||
|
*/
|
||||||
|
|
||||||
|
PDMA_ADAPTER STDCALL
|
||||||
|
HalpGetDmaAdapter(
|
||||||
|
IN PVOID Context,
|
||||||
|
IN PDEVICE_DESCRIPTION DeviceDescription,
|
||||||
|
OUT PULONG NumberOfMapRegisters)
|
||||||
|
{
|
||||||
|
return &HalGetAdapter(DeviceDescription, NumberOfMapRegisters)->DmaHeader;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name HalPutDmaAdapter
|
* @name HalPutDmaAdapter
|
||||||
*
|
*
|
||||||
|
@ -1431,7 +1456,7 @@ HalpCopyBufferMap(
|
||||||
{
|
{
|
||||||
ULONG CurrentLength;
|
ULONG CurrentLength;
|
||||||
ULONG_PTR CurrentAddress;
|
ULONG_PTR CurrentAddress;
|
||||||
ULONG PageOffset;
|
ULONG ByteOffset;
|
||||||
PVOID VirtualAddress;
|
PVOID VirtualAddress;
|
||||||
|
|
||||||
VirtualAddress = MmGetSystemAddressForMdlSafe(Mdl, HighPagePriority);
|
VirtualAddress = MmGetSystemAddressForMdlSafe(Mdl, HighPagePriority);
|
||||||
|
@ -1446,20 +1471,20 @@ HalpCopyBufferMap(
|
||||||
KEBUGCHECK(0);
|
KEBUGCHECK(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentAddress = (ULONG_PTR)CurrentVa - (ULONG_PTR)Mdl->StartVa -
|
CurrentAddress = (ULONG_PTR)CurrentVa -
|
||||||
Mdl->ByteOffset;
|
(ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
|
||||||
|
|
||||||
while (Length > 0)
|
while (Length > 0)
|
||||||
{
|
{
|
||||||
PageOffset = CurrentAddress & (PAGE_SIZE - 1);
|
ByteOffset = BYTE_OFFSET(CurrentAddress);
|
||||||
CurrentLength = PAGE_SIZE - PageOffset;
|
CurrentLength = PAGE_SIZE - ByteOffset;
|
||||||
if (CurrentLength > Length)
|
if (CurrentLength > Length)
|
||||||
CurrentLength = Length;
|
CurrentLength = Length;
|
||||||
|
|
||||||
if (WriteToDevice)
|
if (WriteToDevice)
|
||||||
{
|
{
|
||||||
RtlCopyMemory(
|
RtlCopyMemory(
|
||||||
(PVOID)((ULONG_PTR)MapRegisterBase->VirtualAddress + PageOffset),
|
(PVOID)((ULONG_PTR)MapRegisterBase->VirtualAddress + ByteOffset),
|
||||||
(PVOID)CurrentAddress,
|
(PVOID)CurrentAddress,
|
||||||
CurrentLength);
|
CurrentLength);
|
||||||
}
|
}
|
||||||
|
@ -1467,7 +1492,7 @@ HalpCopyBufferMap(
|
||||||
{
|
{
|
||||||
RtlCopyMemory(
|
RtlCopyMemory(
|
||||||
(PVOID)CurrentAddress,
|
(PVOID)CurrentAddress,
|
||||||
(PVOID)((ULONG_PTR)MapRegisterBase->VirtualAddress + PageOffset),
|
(PVOID)((ULONG_PTR)MapRegisterBase->VirtualAddress + ByteOffset),
|
||||||
CurrentLength);
|
CurrentLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1613,9 +1638,9 @@ IoMapTransfer(
|
||||||
IN OUT PULONG Length,
|
IN OUT PULONG Length,
|
||||||
IN BOOLEAN WriteToDevice)
|
IN BOOLEAN WriteToDevice)
|
||||||
{
|
{
|
||||||
PPFN_TYPE MdlPagesPtr;
|
PPFN_NUMBER MdlPagesPtr;
|
||||||
PFN_TYPE MdlPage1, MdlPage2;
|
PFN_NUMBER MdlPage1, MdlPage2;
|
||||||
ULONG PageOffset;
|
ULONG ByteOffset;
|
||||||
ULONG TransferOffset;
|
ULONG TransferOffset;
|
||||||
ULONG TransferLength;
|
ULONG TransferLength;
|
||||||
BOOLEAN UseMapRegisters;
|
BOOLEAN UseMapRegisters;
|
||||||
|
@ -1629,7 +1654,7 @@ IoMapTransfer(
|
||||||
/*
|
/*
|
||||||
* Precalculate some values that are used in all cases.
|
* Precalculate some values that are used in all cases.
|
||||||
*
|
*
|
||||||
* PageOffset is offset inside the page at which the transfer starts.
|
* ByteOffset is offset inside the page at which the transfer starts.
|
||||||
* MdlPagesPtr is pointer inside the MDL page chain at the page where the
|
* MdlPagesPtr is pointer inside the MDL page chain at the page where the
|
||||||
* transfer start.
|
* transfer start.
|
||||||
* PhysicalAddress is physical address corresponding to the transfer
|
* PhysicalAddress is physical address corresponding to the transfer
|
||||||
|
@ -1641,15 +1666,15 @@ IoMapTransfer(
|
||||||
* takes place below. These are just initial values.
|
* takes place below. These are just initial values.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PageOffset = (ULONG_PTR)CurrentVa & (PAGE_SIZE - 1);
|
ByteOffset = BYTE_OFFSET(CurrentVa);
|
||||||
|
|
||||||
MdlPagesPtr = (PPFN_TYPE)(Mdl + 1);
|
MdlPagesPtr = MmGetMdlPfnArray(Mdl);
|
||||||
MdlPagesPtr += ((ULONG_PTR)CurrentVa - (ULONG_PTR)Mdl->StartVa) >> PAGE_SHIFT;
|
MdlPagesPtr += ((ULONG_PTR)CurrentVa - (ULONG_PTR)Mdl->StartVa) >> PAGE_SHIFT;
|
||||||
|
|
||||||
PhysicalAddress.QuadPart = *MdlPagesPtr << PAGE_SHIFT;
|
PhysicalAddress.QuadPart = *MdlPagesPtr << PAGE_SHIFT;
|
||||||
PhysicalAddress.QuadPart += PageOffset;
|
PhysicalAddress.QuadPart += ByteOffset;
|
||||||
|
|
||||||
TransferLength = PAGE_SIZE - PageOffset;
|
TransferLength = PAGE_SIZE - ByteOffset;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Special case for bus master adapters with S/G support. We can directly
|
* Special case for bus master adapters with S/G support. We can directly
|
||||||
|
@ -1720,7 +1745,7 @@ IoMapTransfer(
|
||||||
{
|
{
|
||||||
UseMapRegisters = TRUE;
|
UseMapRegisters = TRUE;
|
||||||
PhysicalAddress = RealMapRegisterBase->PhysicalAddress;
|
PhysicalAddress = RealMapRegisterBase->PhysicalAddress;
|
||||||
PhysicalAddress.QuadPart += PageOffset;
|
PhysicalAddress.QuadPart += ByteOffset;
|
||||||
TransferLength = *Length;
|
TransferLength = *Length;
|
||||||
RealMapRegisterBase->Counter = ~0;
|
RealMapRegisterBase->Counter = ~0;
|
||||||
Counter = 0;
|
Counter = 0;
|
||||||
|
@ -1735,8 +1760,7 @@ IoMapTransfer(
|
||||||
|
|
||||||
UseMapRegisters = FALSE;
|
UseMapRegisters = FALSE;
|
||||||
Counter = RealMapRegisterBase->Counter;
|
Counter = RealMapRegisterBase->Counter;
|
||||||
RealMapRegisterBase->Counter +=
|
RealMapRegisterBase->Counter += BYTES_TO_PAGES(ByteOffset + TransferLength);
|
||||||
(PageOffset + TransferLength + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if the buffer doesn't exceed the highest phisical address
|
* Check if the buffer doesn't exceed the highest phisical address
|
||||||
|
@ -1750,7 +1774,7 @@ IoMapTransfer(
|
||||||
{
|
{
|
||||||
UseMapRegisters = TRUE;
|
UseMapRegisters = TRUE;
|
||||||
PhysicalAddress = RealMapRegisterBase->PhysicalAddress;
|
PhysicalAddress = RealMapRegisterBase->PhysicalAddress;
|
||||||
PhysicalAddress.QuadPart += PageOffset;
|
PhysicalAddress.QuadPart += ByteOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1791,7 +1815,7 @@ IoMapTransfer(
|
||||||
if (AdapterObject->IgnoreCount)
|
if (AdapterObject->IgnoreCount)
|
||||||
{
|
{
|
||||||
RtlZeroMemory((PUCHAR)RealMapRegisterBase[Counter].VirtualAddress +
|
RtlZeroMemory((PUCHAR)RealMapRegisterBase[Counter].VirtualAddress +
|
||||||
PageOffset, TransferLength);
|
ByteOffset, TransferLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -370,6 +370,12 @@ typedef struct _GROW_WORK_ITEM {
|
||||||
PADAPTER_OBJECT STDCALL
|
PADAPTER_OBJECT STDCALL
|
||||||
HalpDmaAllocateMasterAdapter(VOID);
|
HalpDmaAllocateMasterAdapter(VOID);
|
||||||
|
|
||||||
|
PDMA_ADAPTER STDCALL
|
||||||
|
HalpGetDmaAdapter(
|
||||||
|
IN PVOID Context,
|
||||||
|
IN PDEVICE_DESCRIPTION DeviceDescription,
|
||||||
|
OUT PULONG NumberOfMapRegisters);
|
||||||
|
|
||||||
VOID STDCALL
|
VOID STDCALL
|
||||||
HalPutDmaAdapter(
|
HalPutDmaAdapter(
|
||||||
PADAPTER_OBJECT AdapterObject);
|
PADAPTER_OBJECT AdapterObject);
|
||||||
|
|
Loading…
Reference in a new issue