3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/hal/x86/dma.c
6 * PURPOSE: DMA functions
7 * PROGRAMMERS: David Welch (welch@mcmail.com)
12 /* INCLUDES *****************************************************************/
14 #include <ddk/ntddk.h>
16 #include <internal/debug.h>
19 ADAPTER_OBJECT IsaSlaveAdapterObjects[] = {
20 { Isa, FALSE, 0, (PVOID)0x87, (PVOID)0x1, (PVOID)0x0, 0, NULL },
21 { Isa, FALSE, 1, (PVOID)0x83, (PVOID)0x3, (PVOID)0x2, 0, NULL },
22 { Isa, FALSE, 2, (PVOID)0x81, (PVOID)0x5, (PVOID)0x4, 0, NULL },
23 { Isa, FALSE, 3, (PVOID)0x82, (PVOID)0x7, (PVOID)0x6, 0, NULL } };
25 ADAPTER_OBJECT PciBusMasterAdapterObjects[] = {
26 { PCIBus, TRUE, 0, (PVOID)0, (PVOID)0, (PVOID)0x0, 0, NULL } };
29 /* FUNCTIONS *****************************************************************/
32 HalAllocateCommonBuffer (PADAPTER_OBJECT AdapterObject,
34 PPHYSICAL_ADDRESS LogicalAddress,
37 * FUNCTION: Allocates memory that is visible to both the processor(s) and
40 * AdapterObject = Adapter object representing the bus master or
41 * system dma controller
42 * Length = Number of bytes to allocate
43 * LogicalAddress = Logical address the driver can use to access the
45 * CacheEnabled = Specifies if the memory can be cached
46 * RETURNS: The base virtual address of the memory allocated
49 * CacheEnabled is ignored - it's all cache-disabled (like in NT)
52 PHYSICAL_ADDRESS HighestAddress;
55 HighestAddress.u.HighPart = 0;
56 if (AdapterObject->InterfaceType == Isa ||
57 (AdapterObject->InterfaceType == MicroChannel && AdapterObject->Master == FALSE))
59 HighestAddress.u.LowPart = 0x00FFFFFF; /* 24Bit: 16MB address range */
63 HighestAddress.u.LowPart = 0xFFFFFFFF; /* 32Bit: 4GB address range */
66 BaseAddress = MmAllocateContiguousMemory(Length, HighestAddress);
70 *LogicalAddress = MmGetPhysicalAddress(BaseAddress);
76 HalFlushCommonBuffer (ULONG Unknown1,
89 HalFreeCommonBuffer (PADAPTER_OBJECT AdapterObject,
91 PHYSICAL_ADDRESS LogicalAddress,
95 MmFreeContiguousMemory(VirtualAddress);
98 PADAPTER_OBJECT STDCALL
99 HalGetAdapter (PDEVICE_DESCRIPTION DeviceDescription,
100 PULONG NumberOfMapRegisters)
102 * FUNCTION: Returns a pointer to an adapter object for the DMA device
103 * defined in the device description structure
105 * DeviceDescription = Structure describing the attributes of the device
106 * NumberOfMapRegisters (OUT) = Returns the maximum number of map
107 * registers the device driver can
108 * allocate for DMA transfer operations
109 * RETURNS: The allocated adapter object on success
112 * Figure out what to do with the commented-out cases
115 /* Validate parameters in device description, and return a pointer to
116 the adapter object for the requested dma channel */
117 if( DeviceDescription->Version != DEVICE_DESCRIPTION_VERSION )
120 if (DeviceDescription->InterfaceType == PCIBus)
122 if (DeviceDescription->Master == FALSE)
125 return &PciBusMasterAdapterObjects[0];
129 if( DeviceDescription->Master )
131 if( DeviceDescription->ScatterGather )
133 if( DeviceDescription->AutoInitialize )
135 if( DeviceDescription->Dma32BitAddresses )
137 if( DeviceDescription->InterfaceType != Isa )
140 /* if( DeviceDescription->DmaWidth != Width8Bits )
142 *NumberOfMapRegisters = 0x10;
143 IsaSlaveAdapterObjects[DeviceDescription->DmaChannel].Buffer = 0;
144 return &IsaSlaveAdapterObjects[DeviceDescription->DmaChannel];
148 HalReadDmaCounter (PADAPTER_OBJECT AdapterObject)