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