3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/pnpmgr.c
6 * PURPOSE: PnP manager DMA routines
7 * PROGRAMMER: Filip Navara (xnavara@volny.cz)
9 * 22/09/2003 FiN Created
12 /* INCLUDES ******************************************************************/
16 #include <internal/debug.h>
20 #include <ole32/guiddef.h>
22 #include <ddk/wdmguid.h>
24 typedef struct _DMA_ADAPTER_INTERNAL
{
27 PDMA_OPERATIONS DmaOperations
;
28 PADAPTER_OBJECT HalAdapter
;
29 } DMA_ADAPTER_INTERNAL
, *PDMA_ADAPTER_INTERNAL
;
31 /* FUNCTIONS *****************************************************************/
36 PDMA_ADAPTER DmaAdapter
)
38 DPRINT("IopPutDmaAdapter\n");
39 ExFreePool(DmaAdapter
);
45 IopAllocateCommonBuffer(
46 IN PDMA_ADAPTER DmaAdapter
,
48 OUT PPHYSICAL_ADDRESS LogicalAddress
,
49 IN BOOLEAN CacheEnabled
)
51 DPRINT("IopAllocateCommonBuffer\n");
52 return HalAllocateCommonBuffer(
53 ((PDMA_ADAPTER_INTERNAL
)DmaAdapter
)->HalAdapter
,
54 Length
, LogicalAddress
, CacheEnabled
);
61 IN PDMA_ADAPTER DmaAdapter
,
63 IN PHYSICAL_ADDRESS LogicalAddress
,
64 IN PVOID VirtualAddress
,
65 IN BOOLEAN CacheEnabled
)
67 DPRINT("IopFreeCommonBuffer\n");
69 ((PDMA_ADAPTER_INTERNAL
)DmaAdapter
)->HalAdapter
,
70 Length
, LogicalAddress
, VirtualAddress
, CacheEnabled
);
76 IopAllocateAdapterChannel(
77 IN PDMA_ADAPTER DmaAdapter
,
78 IN PDEVICE_OBJECT DeviceObject
,
79 IN ULONG NumberOfMapRegisters
,
80 IN PDRIVER_CONTROL ExecutionRoutine
,
83 DPRINT("IopAllocateAdapterChannel\n");
84 return IoAllocateAdapterChannel(
85 ((PDMA_ADAPTER_INTERNAL
)DmaAdapter
)->HalAdapter
,
86 DeviceObject
, NumberOfMapRegisters
, ExecutionRoutine
, Context
);
92 IopFlushAdapterBuffers(
93 IN PDMA_ADAPTER DmaAdapter
,
95 IN PVOID MapRegisterBase
,
98 IN BOOLEAN WriteToDevice
)
100 DPRINT("IopFlushAdapterBuffers\n");
101 return IoFlushAdapterBuffers(
102 ((PDMA_ADAPTER_INTERNAL
)DmaAdapter
)->HalAdapter
,
103 Mdl
, MapRegisterBase
, CurrentVa
, Length
, WriteToDevice
);
109 IopFreeAdapterChannel(
110 IN PDMA_ADAPTER DmaAdapter
)
112 DPRINT("IopFreeAdapterChannel\n");
113 IoFreeAdapterChannel(((PDMA_ADAPTER_INTERNAL
)DmaAdapter
)->HalAdapter
);
120 IN PDMA_ADAPTER DmaAdapter
,
121 PVOID MapRegisterBase
,
122 ULONG NumberOfMapRegisters
)
124 DPRINT("IopFreeMapRegisters\n");
126 ((PDMA_ADAPTER_INTERNAL
)DmaAdapter
)->HalAdapter
,
127 MapRegisterBase
, NumberOfMapRegisters
);
134 IN PDMA_ADAPTER DmaAdapter
,
136 IN PVOID MapRegisterBase
,
138 IN OUT PULONG Length
,
139 IN BOOLEAN WriteToDevice
)
141 DPRINT("IopMapTransfer\n");
142 return IoMapTransfer(
143 ((PDMA_ADAPTER_INTERNAL
)DmaAdapter
)->HalAdapter
,
144 Mdl
, MapRegisterBase
, CurrentVa
, Length
, WriteToDevice
);
151 IN PDMA_ADAPTER DmaAdapter
)
153 DPRINT("IopGetDmaAlignment\n");
154 /* FIXME: This is actually true only on i386 and Amd64 */
162 IN PDMA_ADAPTER DmaAdapter
)
164 DPRINT("IopReadDmaCounter\n");
165 return HalReadDmaCounter(((PDMA_ADAPTER_INTERNAL
)DmaAdapter
)->HalAdapter
);
171 IopGetScatterGatherList(
172 IN PDMA_ADAPTER DmaAdapter
,
173 IN PDEVICE_OBJECT DeviceObject
,
177 IN PDRIVER_LIST_CONTROL ExecutionRoutine
,
179 IN BOOLEAN WriteToDevice
)
181 DPRINT("IopGetScatterGatherList\n");
183 return STATUS_UNSUCCESSFUL
;
189 IopPutScatterGatherList(
190 IN PDMA_ADAPTER DmaAdapter
,
191 IN PSCATTER_GATHER_LIST ScatterGather
,
192 IN BOOLEAN WriteToDevice
)
194 DPRINT("IopPutScatterGatherList\n");
204 IN PDEVICE_OBJECT PhysicalDeviceObject
,
205 IN PDEVICE_DESCRIPTION DeviceDescription
,
206 IN OUT PULONG NumberOfMapRegisters
)
208 static DMA_OPERATIONS HalDmaOperations
= {
209 sizeof(DMA_OPERATIONS
),
211 IopAllocateCommonBuffer
,
213 IopAllocateAdapterChannel
,
214 IopFlushAdapterBuffers
,
215 IopFreeAdapterChannel
,
220 IopGetScatterGatherList
,
221 IopPutScatterGatherList
225 BUS_INTERFACE_STANDARD BusInterface
;
226 IO_STATUS_BLOCK IoStatusBlock
;
227 IO_STACK_LOCATION Stack
;
228 DEVICE_DESCRIPTION PrivateDeviceDescription
;
229 PDMA_ADAPTER Result
= NULL
;
230 PDMA_ADAPTER_INTERNAL ResultInternal
= NULL
;
231 PADAPTER_OBJECT HalAdapter
;
233 DPRINT("IoGetDmaAdapter called\n");
236 * Try to create DMA adapter through bus driver
238 if (PhysicalDeviceObject
!= NULL
)
240 if (DeviceDescription
->InterfaceType
== 0x0F /*PNPBus*/ ||
241 DeviceDescription
->InterfaceType
== 0xFFFFFFFF)
243 RtlCopyMemory(&PrivateDeviceDescription
, DeviceDescription
,
244 sizeof(DEVICE_DESCRIPTION
));
245 Status
= IoGetDeviceProperty(PhysicalDeviceObject
,
246 DevicePropertyLegacyBusType
, sizeof(INTERFACE_TYPE
),
247 &PrivateDeviceDescription
.InterfaceType
, &ResultLength
);
248 if (!NT_SUCCESS(Status
))
250 PrivateDeviceDescription
.InterfaceType
= Internal
;
252 DeviceDescription
= &PrivateDeviceDescription
;
255 Stack
.Parameters
.QueryInterface
.Size
= sizeof(BUS_INTERFACE_STANDARD
);
256 Stack
.Parameters
.QueryInterface
.Version
= 1;
257 Stack
.Parameters
.QueryInterface
.Interface
= (PINTERFACE
)&BusInterface
;
258 Stack
.Parameters
.QueryInterface
.InterfaceType
=
259 &GUID_BUS_INTERFACE_STANDARD
;
260 Status
= IopInitiatePnpIrp(PhysicalDeviceObject
, &IoStatusBlock
,
261 IRP_MN_QUERY_INTERFACE
, &Stack
);
262 if (NT_SUCCESS(Status
))
264 Result
= BusInterface
.GetDmaAdapter(BusInterface
.Context
,
265 DeviceDescription
, NumberOfMapRegisters
);
266 BusInterface
.InterfaceDereference(BusInterface
.Context
);
276 HalAdapter
= HalGetAdapter(DeviceDescription
, NumberOfMapRegisters
);
277 if (HalAdapter
== NULL
)
280 ResultInternal
= ExAllocatePool(PagedPool
, sizeof(DMA_ADAPTER_INTERNAL
));
281 if (ResultInternal
== NULL
)
284 ResultInternal
->Version
= DEVICE_DESCRIPTION_VERSION
;
285 ResultInternal
->Size
= sizeof(DMA_ADAPTER
);
286 ResultInternal
->DmaOperations
= &HalDmaOperations
;
287 ResultInternal
->HalAdapter
= HalAdapter
;
289 return (PDMA_ADAPTER
)ResultInternal
;