Cleanup IoGetDmaAdapter and use HalGetDmaAdapter instead of HalGetAdapter.
[reactos.git] / reactos / ntoskrnl / io / pnpdma.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/pnpdma.c
6 * PURPOSE: PnP manager DMA routines
7 *
8 * PROGRAMMERS: Filip Navara (xnavara@volny.cz)
9 */
10
11 /* INCLUDES ******************************************************************/
12
13 #include <ntoskrnl.h>
14 #define NDEBUG
15 #include <internal/debug.h>
16 #include <ddk/wdmguid.h>
17
18 /* FUNCTIONS *****************************************************************/
19
20 /*
21 * @implemented
22 */
23 PDMA_ADAPTER STDCALL
24 IoGetDmaAdapter(
25 IN PDEVICE_OBJECT PhysicalDeviceObject,
26 IN PDEVICE_DESCRIPTION DeviceDescription,
27 IN OUT PULONG NumberOfMapRegisters)
28 {
29 NTSTATUS Status;
30 ULONG ResultLength;
31 BUS_INTERFACE_STANDARD BusInterface;
32 IO_STATUS_BLOCK IoStatusBlock;
33 IO_STACK_LOCATION Stack;
34 DEVICE_DESCRIPTION PrivateDeviceDescription;
35 PDMA_ADAPTER Adapter = NULL;
36
37 DPRINT("IoGetDmaAdapter called\n");
38
39 /*
40 * Try to create DMA adapter through bus driver.
41 */
42
43 if (PhysicalDeviceObject != NULL)
44 {
45 if (DeviceDescription->InterfaceType == PNPBus ||
46 DeviceDescription->InterfaceType == InterfaceTypeUndefined)
47 {
48 RtlCopyMemory(&PrivateDeviceDescription, DeviceDescription,
49 sizeof(DEVICE_DESCRIPTION));
50 Status = IoGetDeviceProperty(PhysicalDeviceObject,
51 DevicePropertyLegacyBusType, sizeof(INTERFACE_TYPE),
52 &PrivateDeviceDescription.InterfaceType, &ResultLength);
53 if (!NT_SUCCESS(Status))
54 PrivateDeviceDescription.InterfaceType = Internal;
55 DeviceDescription = &PrivateDeviceDescription;
56 }
57
58 Stack.Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD);
59 Stack.Parameters.QueryInterface.Version = 1;
60 Stack.Parameters.QueryInterface.Interface = (PINTERFACE)&BusInterface;
61 Stack.Parameters.QueryInterface.InterfaceType =
62 &GUID_BUS_INTERFACE_STANDARD;
63 Status = IopInitiatePnpIrp(PhysicalDeviceObject, &IoStatusBlock,
64 IRP_MN_QUERY_INTERFACE, &Stack);
65 if (NT_SUCCESS(Status))
66 {
67 Adapter = BusInterface.GetDmaAdapter(BusInterface.Context,
68 DeviceDescription, NumberOfMapRegisters);
69 BusInterface.InterfaceDereference(BusInterface.Context);
70 if (Adapter != NULL)
71 return Adapter;
72 }
73 }
74
75 /*
76 * Fallback to HAL.
77 */
78
79 return HalGetDmaAdapter(PhysicalDeviceObject, DeviceDescription,
80 NumberOfMapRegisters);
81 }
82
83 /* EOF */