xref: /reactos/hal/halx86/acpi/halpnpdd.c (revision f75318b6)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * PROJECT:         ReactOS HAL
3c2c66affSColin Finck  * LICENSE:         BSD - See COPYING.ARM in the top level directory
4c2c66affSColin Finck  * FILE:            hal/halx86/acpi/halpnpdd.c
5c2c66affSColin Finck  * PURPOSE:         HAL Plug and Play Device Driver
6c2c66affSColin Finck  * PROGRAMMERS:     ReactOS Portable Systems Group
7c2c66affSColin Finck  */
8c2c66affSColin Finck 
9c2c66affSColin Finck /* INCLUDES *******************************************************************/
10c2c66affSColin Finck 
11c2c66affSColin Finck #include <hal.h>
12c2c66affSColin Finck #define NDEBUG
13c2c66affSColin Finck #include <debug.h>
14c2c66affSColin Finck 
15c2c66affSColin Finck typedef enum _EXTENSION_TYPE
16c2c66affSColin Finck {
17c2c66affSColin Finck     PdoExtensionType = 0xC0,
18c2c66affSColin Finck     FdoExtensionType
19c2c66affSColin Finck } EXTENSION_TYPE;
20c2c66affSColin Finck 
21c2c66affSColin Finck typedef enum _PDO_TYPE
22c2c66affSColin Finck {
23c2c66affSColin Finck     AcpiPdo = 0x80,
24c2c66affSColin Finck     WdPdo
25c2c66affSColin Finck } PDO_TYPE;
26c2c66affSColin Finck 
27c2c66affSColin Finck typedef struct _FDO_EXTENSION
28c2c66affSColin Finck {
29c2c66affSColin Finck     EXTENSION_TYPE ExtensionType;
30c2c66affSColin Finck     struct _PDO_EXTENSION* ChildPdoList;
31c2c66affSColin Finck     PDEVICE_OBJECT PhysicalDeviceObject;
32c2c66affSColin Finck     PDEVICE_OBJECT FunctionalDeviceObject;
33c2c66affSColin Finck     PDEVICE_OBJECT AttachedDeviceObject;
34c2c66affSColin Finck } FDO_EXTENSION, *PFDO_EXTENSION;
35c2c66affSColin Finck 
36c2c66affSColin Finck typedef struct _PDO_EXTENSION
37c2c66affSColin Finck {
38c2c66affSColin Finck     EXTENSION_TYPE ExtensionType;
39c2c66affSColin Finck     struct _PDO_EXTENSION* Next;
40c2c66affSColin Finck     PDEVICE_OBJECT PhysicalDeviceObject;
41c2c66affSColin Finck     PFDO_EXTENSION ParentFdoExtension;
42c2c66affSColin Finck     PDO_TYPE PdoType;
43c2c66affSColin Finck     PDESCRIPTION_HEADER WdTable;
44c2c66affSColin Finck     LONG InterfaceReferenceCount;
45c2c66affSColin Finck } PDO_EXTENSION, *PPDO_EXTENSION;
46c2c66affSColin Finck 
47c2c66affSColin Finck /* GLOBALS ********************************************************************/
48c2c66affSColin Finck 
49c2c66affSColin Finck PDRIVER_OBJECT HalpDriverObject;
50c2c66affSColin Finck 
51c2c66affSColin Finck /* PRIVATE FUNCTIONS **********************************************************/
52c2c66affSColin Finck 
53c2c66affSColin Finck NTSTATUS
54c2c66affSColin Finck NTAPI
55c2c66affSColin Finck HalpAddDevice(IN PDRIVER_OBJECT DriverObject,
56c2c66affSColin Finck               IN PDEVICE_OBJECT TargetDevice)
57c2c66affSColin Finck {
58c2c66affSColin Finck     NTSTATUS Status;
59c2c66affSColin Finck     PFDO_EXTENSION FdoExtension;
60*f75318b6SVictor Perevertkin     PPDO_EXTENSION PdoExtension;
61c2c66affSColin Finck     PDEVICE_OBJECT DeviceObject, AttachedDevice;
62*f75318b6SVictor Perevertkin     PDEVICE_OBJECT PdoDeviceObject;
63*f75318b6SVictor Perevertkin     PDESCRIPTION_HEADER Wdrt;
64c2c66affSColin Finck 
65c2c66affSColin Finck     DPRINT("HAL: PnP Driver ADD!\n");
66c2c66affSColin Finck 
67c2c66affSColin Finck     /* Create the FDO */
68c2c66affSColin Finck     Status = IoCreateDevice(DriverObject,
69c2c66affSColin Finck                             sizeof(FDO_EXTENSION),
70c2c66affSColin Finck                             NULL,
71c2c66affSColin Finck                             FILE_DEVICE_BUS_EXTENDER,
72c2c66affSColin Finck                             0,
73c2c66affSColin Finck                             FALSE,
74c2c66affSColin Finck                             &DeviceObject);
75c2c66affSColin Finck     if (!NT_SUCCESS(Status))
76c2c66affSColin Finck     {
77c2c66affSColin Finck         /* Should not happen */
78c2c66affSColin Finck         DbgBreakPoint();
79c2c66affSColin Finck         return Status;
80c2c66affSColin Finck     }
81c2c66affSColin Finck 
82c2c66affSColin Finck     /* Setup the FDO extension */
83c2c66affSColin Finck     FdoExtension = DeviceObject->DeviceExtension;
84c2c66affSColin Finck     FdoExtension->ExtensionType = FdoExtensionType;
85c2c66affSColin Finck     FdoExtension->PhysicalDeviceObject = TargetDevice;
86c2c66affSColin Finck     FdoExtension->FunctionalDeviceObject = DeviceObject;
87c2c66affSColin Finck     FdoExtension->ChildPdoList = NULL;
88c2c66affSColin Finck 
89c2c66affSColin Finck     /* FDO is done initializing */
90c2c66affSColin Finck     DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
91c2c66affSColin Finck 
92c2c66affSColin Finck     /* Attach to the physical device object (the bus) */
93c2c66affSColin Finck     AttachedDevice = IoAttachDeviceToDeviceStack(DeviceObject, TargetDevice);
94c2c66affSColin Finck     if (!AttachedDevice)
95c2c66affSColin Finck     {
96c2c66affSColin Finck         /* Failed, undo everything */
97c2c66affSColin Finck         IoDeleteDevice(DeviceObject);
98c2c66affSColin Finck         return STATUS_NO_SUCH_DEVICE;
99c2c66affSColin Finck     }
100c2c66affSColin Finck 
101c2c66affSColin Finck     /* Save the attachment */
102c2c66affSColin Finck     FdoExtension->AttachedDeviceObject = AttachedDevice;
103c2c66affSColin Finck 
104*f75318b6SVictor Perevertkin     /* Create the PDO */
105*f75318b6SVictor Perevertkin     Status = IoCreateDevice(DriverObject,
106*f75318b6SVictor Perevertkin                             sizeof(PDO_EXTENSION),
107*f75318b6SVictor Perevertkin                             NULL,
108*f75318b6SVictor Perevertkin                             FILE_DEVICE_BUS_EXTENDER,
109*f75318b6SVictor Perevertkin                             FILE_AUTOGENERATED_DEVICE_NAME,
110*f75318b6SVictor Perevertkin                             FALSE,
111*f75318b6SVictor Perevertkin                             &PdoDeviceObject);
112*f75318b6SVictor Perevertkin     if (!NT_SUCCESS(Status))
113*f75318b6SVictor Perevertkin     {
114*f75318b6SVictor Perevertkin         /* Fail */
115*f75318b6SVictor Perevertkin         DPRINT1("HAL: Could not create ACPI device object status=0x%08x\n", Status);
116*f75318b6SVictor Perevertkin         return Status;
117*f75318b6SVictor Perevertkin     }
118*f75318b6SVictor Perevertkin 
119*f75318b6SVictor Perevertkin     /* Setup the PDO device extension */
120*f75318b6SVictor Perevertkin     PdoExtension = PdoDeviceObject->DeviceExtension;
121*f75318b6SVictor Perevertkin     PdoExtension->ExtensionType = PdoExtensionType;
122*f75318b6SVictor Perevertkin     PdoExtension->PhysicalDeviceObject = PdoDeviceObject;
123*f75318b6SVictor Perevertkin     PdoExtension->ParentFdoExtension = FdoExtension;
124*f75318b6SVictor Perevertkin     PdoExtension->PdoType = AcpiPdo;
125*f75318b6SVictor Perevertkin 
126*f75318b6SVictor Perevertkin     /* Add the PDO to the head of the list */
127*f75318b6SVictor Perevertkin     PdoExtension->Next = FdoExtension->ChildPdoList;
128*f75318b6SVictor Perevertkin     FdoExtension->ChildPdoList = PdoExtension;
129*f75318b6SVictor Perevertkin 
130*f75318b6SVictor Perevertkin     /* Initialization is finished */
131*f75318b6SVictor Perevertkin     PdoDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
132*f75318b6SVictor Perevertkin 
133*f75318b6SVictor Perevertkin     /* Find the ACPI watchdog table */
134*f75318b6SVictor Perevertkin     Wdrt = HalAcpiGetTable(0, 'TRDW');
135*f75318b6SVictor Perevertkin     if (Wdrt)
136*f75318b6SVictor Perevertkin     {
137*f75318b6SVictor Perevertkin         /* FIXME: TODO */
138*f75318b6SVictor Perevertkin         DPRINT1("You have an ACPI Watchdog. That's great! You should be proud ;-)\n");
139*f75318b6SVictor Perevertkin     }
140c2c66affSColin Finck 
141c2c66affSColin Finck     /* Return status */
142c2c66affSColin Finck     DPRINT("Device added %lx\n", Status);
143c2c66affSColin Finck     return Status;
144c2c66affSColin Finck }
145c2c66affSColin Finck 
146c2c66affSColin Finck NTSTATUS
147c2c66affSColin Finck NTAPI
148c2c66affSColin Finck HalpQueryInterface(IN PDEVICE_OBJECT DeviceObject,
149c2c66affSColin Finck                    IN CONST GUID* InterfaceType,
150c2c66affSColin Finck                    IN USHORT Version,
151c2c66affSColin Finck                    IN PVOID InterfaceSpecificData,
152c2c66affSColin Finck                    IN ULONG InterfaceBufferSize,
153c2c66affSColin Finck                    IN PINTERFACE Interface,
154c2c66affSColin Finck                    OUT PULONG Length)
155c2c66affSColin Finck {
156c2c66affSColin Finck     UNIMPLEMENTED;
157c2c66affSColin Finck     return STATUS_NOT_SUPPORTED;
158c2c66affSColin Finck }
159c2c66affSColin Finck 
160c2c66affSColin Finck NTSTATUS
161c2c66affSColin Finck NTAPI
162c2c66affSColin Finck HalpQueryDeviceRelations(IN PDEVICE_OBJECT DeviceObject,
163c2c66affSColin Finck                          IN DEVICE_RELATION_TYPE RelationType,
164c2c66affSColin Finck                          OUT PDEVICE_RELATIONS* DeviceRelations)
165c2c66affSColin Finck {
166c2c66affSColin Finck     EXTENSION_TYPE ExtensionType;
167c2c66affSColin Finck     PPDO_EXTENSION PdoExtension;
168c2c66affSColin Finck     PFDO_EXTENSION FdoExtension;
169c2c66affSColin Finck     PDEVICE_RELATIONS PdoRelations, FdoRelations;
170c2c66affSColin Finck     PDEVICE_OBJECT* ObjectEntry;
171c2c66affSColin Finck     ULONG i = 0, PdoCount = 0;
172c2c66affSColin Finck 
173c2c66affSColin Finck     /* Get FDO device extension and PDO count */
174c2c66affSColin Finck     FdoExtension = DeviceObject->DeviceExtension;
175c2c66affSColin Finck     ExtensionType = FdoExtension->ExtensionType;
176c2c66affSColin Finck 
177c2c66affSColin Finck     /* What do they want? */
178c2c66affSColin Finck     if (RelationType == BusRelations)
179c2c66affSColin Finck     {
180c2c66affSColin Finck         /* This better be an FDO */
181c2c66affSColin Finck         if (ExtensionType == FdoExtensionType)
182c2c66affSColin Finck         {
183c2c66affSColin Finck             /* Count how many PDOs we have */
184c2c66affSColin Finck             PdoExtension = FdoExtension->ChildPdoList;
185c2c66affSColin Finck             while (PdoExtension)
186c2c66affSColin Finck             {
187c2c66affSColin Finck                 /* Next one */
188c2c66affSColin Finck                 PdoExtension = PdoExtension->Next;
189c2c66affSColin Finck                 PdoCount++;
190c2c66affSColin Finck             }
191c2c66affSColin Finck 
192c2c66affSColin Finck             /* Add the PDOs that already exist in the device relations */
193c2c66affSColin Finck             if (*DeviceRelations)
194c2c66affSColin Finck             {
195c2c66affSColin Finck                 PdoCount += (*DeviceRelations)->Count;
196c2c66affSColin Finck             }
197c2c66affSColin Finck 
198c2c66affSColin Finck             /* Allocate our structure */
199c2c66affSColin Finck             FdoRelations = ExAllocatePoolWithTag(PagedPool,
200c2c66affSColin Finck                                                  FIELD_OFFSET(DEVICE_RELATIONS,
201c2c66affSColin Finck                                                               Objects) +
202c2c66affSColin Finck                                                  sizeof(PDEVICE_OBJECT) * PdoCount,
203c2c66affSColin Finck                                                  TAG_HAL);
204c2c66affSColin Finck             if (!FdoRelations) return STATUS_INSUFFICIENT_RESOURCES;
205c2c66affSColin Finck 
206c2c66affSColin Finck             /* Save our count */
207c2c66affSColin Finck             FdoRelations->Count = PdoCount;
208c2c66affSColin Finck 
209c2c66affSColin Finck             /* Query existing relations */
210c2c66affSColin Finck             ObjectEntry = FdoRelations->Objects;
211c2c66affSColin Finck             if (*DeviceRelations)
212c2c66affSColin Finck             {
213c2c66affSColin Finck                 /* Check if there were any */
214c2c66affSColin Finck                 if ((*DeviceRelations)->Count)
215c2c66affSColin Finck                 {
216c2c66affSColin Finck                     /* Loop them all */
217c2c66affSColin Finck                     do
218c2c66affSColin Finck                     {
219c2c66affSColin Finck                         /* Copy into our structure */
220c2c66affSColin Finck                         *ObjectEntry++ = (*DeviceRelations)->Objects[i];
221c2c66affSColin Finck                     }
222c2c66affSColin Finck                     while (++i < (*DeviceRelations)->Count);
223c2c66affSColin Finck                 }
224c2c66affSColin Finck 
225c2c66affSColin Finck                 /* Free existing structure */
226c2c66affSColin Finck                 ExFreePool(*DeviceRelations);
227c2c66affSColin Finck             }
228c2c66affSColin Finck 
229c2c66affSColin Finck             /* Now check if we have a PDO list */
230c2c66affSColin Finck             PdoExtension = FdoExtension->ChildPdoList;
231c2c66affSColin Finck             if (PdoExtension)
232c2c66affSColin Finck             {
233c2c66affSColin Finck                 /* Loop the PDOs */
234c2c66affSColin Finck                 do
235c2c66affSColin Finck                 {
236c2c66affSColin Finck                     /* Save our own PDO and reference it */
237c2c66affSColin Finck                     *ObjectEntry++ = PdoExtension->PhysicalDeviceObject;
238c2c66affSColin Finck                     ObReferenceObject(PdoExtension->PhysicalDeviceObject);
239c2c66affSColin Finck 
240c2c66affSColin Finck                     /* Go to our next PDO */
241c2c66affSColin Finck                     PdoExtension = PdoExtension->Next;
242c2c66affSColin Finck                 }
243c2c66affSColin Finck                 while (PdoExtension);
244c2c66affSColin Finck             }
245c2c66affSColin Finck 
246c2c66affSColin Finck             /* Return the new structure */
247c2c66affSColin Finck             *DeviceRelations = FdoRelations;
248c2c66affSColin Finck             return STATUS_SUCCESS;
249c2c66affSColin Finck         }
250c2c66affSColin Finck     }
251c2c66affSColin Finck     else
252c2c66affSColin Finck     {
253c2c66affSColin Finck         /* The only other thing we support is a target relation for the PDO */
254c2c66affSColin Finck         if ((RelationType == TargetDeviceRelation) &&
255c2c66affSColin Finck             (ExtensionType == PdoExtensionType))
256c2c66affSColin Finck         {
257c2c66affSColin Finck             /* Only one entry */
258c2c66affSColin Finck             PdoRelations = ExAllocatePoolWithTag(PagedPool,
259c2c66affSColin Finck                                                  sizeof(DEVICE_RELATIONS),
260c2c66affSColin Finck                                                  TAG_HAL);
261c2c66affSColin Finck             if (!PdoRelations) return STATUS_INSUFFICIENT_RESOURCES;
262c2c66affSColin Finck 
263c2c66affSColin Finck             /* Fill it out and reference us */
264c2c66affSColin Finck             PdoRelations->Count = 1;
265c2c66affSColin Finck             PdoRelations->Objects[0] = DeviceObject;
266c2c66affSColin Finck             ObReferenceObject(DeviceObject);
267c2c66affSColin Finck 
268c2c66affSColin Finck             /* Return it */
269c2c66affSColin Finck             *DeviceRelations = PdoRelations;
270c2c66affSColin Finck             return STATUS_SUCCESS;
271c2c66affSColin Finck         }
272c2c66affSColin Finck     }
273c2c66affSColin Finck 
274c2c66affSColin Finck     /* We don't support anything else */
275c2c66affSColin Finck     return STATUS_NOT_SUPPORTED;
276c2c66affSColin Finck }
277c2c66affSColin Finck 
278c2c66affSColin Finck NTSTATUS
279c2c66affSColin Finck NTAPI
280c2c66affSColin Finck HalpQueryCapabilities(IN PDEVICE_OBJECT DeviceObject,
281c2c66affSColin Finck                       OUT PDEVICE_CAPABILITIES Capabilities)
282c2c66affSColin Finck {
283c2c66affSColin Finck     //PPDO_EXTENSION PdoExtension;
284c2c66affSColin Finck     NTSTATUS Status;
285c2c66affSColin Finck     PAGED_CODE();
286c2c66affSColin Finck 
287c2c66affSColin Finck     /* Get the extension and check for valid version */
288c2c66affSColin Finck     //PdoExtension = DeviceObject->DeviceExtension;
289c2c66affSColin Finck     ASSERT(Capabilities->Version == 1);
290c2c66affSColin Finck     if (Capabilities->Version == 1)
291c2c66affSColin Finck     {
292c2c66affSColin Finck         /* Can't lock or eject us */
293c2c66affSColin Finck         Capabilities->LockSupported = FALSE;
294c2c66affSColin Finck         Capabilities->EjectSupported = FALSE;
295c2c66affSColin Finck 
296c2c66affSColin Finck         /* Can't remove or dock us */
297c2c66affSColin Finck         Capabilities->Removable = FALSE;
298c2c66affSColin Finck         Capabilities->DockDevice = FALSE;
299c2c66affSColin Finck 
300c2c66affSColin Finck         /* Can't access us raw */
301c2c66affSColin Finck         Capabilities->RawDeviceOK = FALSE;
302c2c66affSColin Finck 
303c2c66affSColin Finck         /* We have a unique ID, and don't bother the user */
304c2c66affSColin Finck         Capabilities->UniqueID = TRUE;
305c2c66affSColin Finck         Capabilities->SilentInstall = TRUE;
306c2c66affSColin Finck 
307c2c66affSColin Finck         /* Fill out the adress */
308c2c66affSColin Finck         Capabilities->Address = InterfaceTypeUndefined;
309c2c66affSColin Finck         Capabilities->UINumber = InterfaceTypeUndefined;
310c2c66affSColin Finck 
311c2c66affSColin Finck         /* Fill out latencies */
312c2c66affSColin Finck         Capabilities->D1Latency = 0;
313c2c66affSColin Finck         Capabilities->D2Latency = 0;
314c2c66affSColin Finck         Capabilities->D3Latency = 0;
315c2c66affSColin Finck 
316c2c66affSColin Finck         /* Fill out supported device states */
317c2c66affSColin Finck         Capabilities->DeviceState[PowerSystemWorking] = PowerDeviceD0;
318c2c66affSColin Finck         Capabilities->DeviceState[PowerSystemHibernate] = PowerDeviceD3;
319c2c66affSColin Finck         Capabilities->DeviceState[PowerSystemShutdown] = PowerDeviceD3;
320c2c66affSColin Finck         Capabilities->DeviceState[PowerSystemSleeping3] = PowerDeviceD3;
321c2c66affSColin Finck 
322c2c66affSColin Finck         /* Done */
323c2c66affSColin Finck         Status = STATUS_SUCCESS;
324c2c66affSColin Finck     }
325c2c66affSColin Finck     else
326c2c66affSColin Finck     {
327c2c66affSColin Finck         /* Fail */
328c2c66affSColin Finck         Status = STATUS_NOT_SUPPORTED;
329c2c66affSColin Finck     }
330c2c66affSColin Finck 
331c2c66affSColin Finck     /* Return status */
332c2c66affSColin Finck     return Status;
333c2c66affSColin Finck }
334c2c66affSColin Finck 
335c2c66affSColin Finck NTSTATUS
336c2c66affSColin Finck NTAPI
337c2c66affSColin Finck HalpQueryResources(IN PDEVICE_OBJECT DeviceObject,
338c2c66affSColin Finck                    OUT PCM_RESOURCE_LIST *Resources)
339c2c66affSColin Finck {
340c2c66affSColin Finck     PPDO_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
341c2c66affSColin Finck     NTSTATUS Status;
342c2c66affSColin Finck     PCM_RESOURCE_LIST ResourceList;
343c2c66affSColin Finck     PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
344c2c66affSColin Finck     PIO_RESOURCE_DESCRIPTOR Descriptor;
345c2c66affSColin Finck     PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDesc;
346c2c66affSColin Finck     ULONG i;
347c2c66affSColin Finck     PAGED_CODE();
348c2c66affSColin Finck 
349c2c66affSColin Finck     /* Only the ACPI PDO has requirements */
350c2c66affSColin Finck     if (DeviceExtension->PdoType == AcpiPdo)
351c2c66affSColin Finck     {
352c2c66affSColin Finck         /* Query ACPI requirements */
353c2c66affSColin Finck         Status = HalpQueryAcpiResourceRequirements(&RequirementsList);
354c2c66affSColin Finck         if (!NT_SUCCESS(Status)) return Status;
355c2c66affSColin Finck 
356c2c66affSColin Finck         ASSERT(RequirementsList->AlternativeLists == 1);
357c2c66affSColin Finck 
358c2c66affSColin Finck         /* Allocate the resourcel ist */
359c2c66affSColin Finck         ResourceList = ExAllocatePoolWithTag(PagedPool,
360c2c66affSColin Finck                                              sizeof(CM_RESOURCE_LIST),
361c2c66affSColin Finck                                              TAG_HAL);
362c2c66affSColin Finck         if (!ResourceList )
363c2c66affSColin Finck         {
364c2c66affSColin Finck             /* Fail, no memory */
365c2c66affSColin Finck             Status = STATUS_INSUFFICIENT_RESOURCES;
366c2c66affSColin Finck             ExFreePoolWithTag(RequirementsList, TAG_HAL);
367c2c66affSColin Finck             return Status;
368c2c66affSColin Finck         }
369c2c66affSColin Finck 
370c2c66affSColin Finck         /* Initialize it */
371c2c66affSColin Finck         RtlZeroMemory(ResourceList, sizeof(CM_RESOURCE_LIST));
372c2c66affSColin Finck         ResourceList->Count = 1;
373c2c66affSColin Finck 
374c2c66affSColin Finck         /* Setup the list fields */
375c2c66affSColin Finck         ResourceList->List[0].BusNumber = -1;
376c2c66affSColin Finck         ResourceList->List[0].InterfaceType = PNPBus;
377c2c66affSColin Finck         ResourceList->List[0].PartialResourceList.Version = 1;
378c2c66affSColin Finck         ResourceList->List[0].PartialResourceList.Revision = 1;
379c2c66affSColin Finck         ResourceList->List[0].PartialResourceList.Count = 0;
380c2c66affSColin Finck 
381c2c66affSColin Finck         /* Setup the first descriptor */
382c2c66affSColin Finck         PartialDesc = ResourceList->List[0].PartialResourceList.PartialDescriptors;
383c2c66affSColin Finck 
384c2c66affSColin Finck         /* Find the requirement descriptor for the SCI */
385c2c66affSColin Finck         for (i = 0; i < RequirementsList->List[0].Count; i++)
386c2c66affSColin Finck         {
387c2c66affSColin Finck             /* Get this descriptor */
388c2c66affSColin Finck             Descriptor = &RequirementsList->List[0].Descriptors[i];
389c2c66affSColin Finck             if (Descriptor->Type == CmResourceTypeInterrupt)
390c2c66affSColin Finck             {
391c2c66affSColin Finck                 /* Copy requirements descriptor into resource descriptor */
392c2c66affSColin Finck                 PartialDesc->Type = CmResourceTypeInterrupt;
393c2c66affSColin Finck                 PartialDesc->ShareDisposition = Descriptor->ShareDisposition;
394c2c66affSColin Finck                 PartialDesc->Flags = Descriptor->Flags;
395c2c66affSColin Finck                 ASSERT(Descriptor->u.Interrupt.MinimumVector ==
396c2c66affSColin Finck                        Descriptor->u.Interrupt.MaximumVector);
397c2c66affSColin Finck                 PartialDesc->u.Interrupt.Vector = Descriptor->u.Interrupt.MinimumVector;
398c2c66affSColin Finck                 PartialDesc->u.Interrupt.Level = Descriptor->u.Interrupt.MinimumVector;
399c2c66affSColin Finck                 PartialDesc->u.Interrupt.Affinity = 0xFFFFFFFF;
400c2c66affSColin Finck 
401c2c66affSColin Finck                 ResourceList->List[0].PartialResourceList.Count++;
402c2c66affSColin Finck 
403c2c66affSColin Finck                 break;
404c2c66affSColin Finck             }
405c2c66affSColin Finck         }
406c2c66affSColin Finck 
407c2c66affSColin Finck         /* Return resources and success */
408c2c66affSColin Finck         *Resources = ResourceList;
409c2c66affSColin Finck 
410c2c66affSColin Finck         ExFreePoolWithTag(RequirementsList, TAG_HAL);
411c2c66affSColin Finck 
412c2c66affSColin Finck         return STATUS_SUCCESS;
413c2c66affSColin Finck     }
414c2c66affSColin Finck     else if (DeviceExtension->PdoType == WdPdo)
415c2c66affSColin Finck     {
416c2c66affSColin Finck         /* Watchdog doesn't */
417c2c66affSColin Finck         return STATUS_NOT_SUPPORTED;
418c2c66affSColin Finck     }
419c2c66affSColin Finck     else
420c2c66affSColin Finck     {
421c2c66affSColin Finck         /* This shouldn't happen */
422c2c66affSColin Finck         return STATUS_UNSUCCESSFUL;
423c2c66affSColin Finck     }
424c2c66affSColin Finck }
425c2c66affSColin Finck 
426c2c66affSColin Finck NTSTATUS
427c2c66affSColin Finck NTAPI
428c2c66affSColin Finck HalpQueryResourceRequirements(IN PDEVICE_OBJECT DeviceObject,
429c2c66affSColin Finck                               OUT PIO_RESOURCE_REQUIREMENTS_LIST *Requirements)
430c2c66affSColin Finck {
431c2c66affSColin Finck     PPDO_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
432c2c66affSColin Finck     PAGED_CODE();
433c2c66affSColin Finck 
434c2c66affSColin Finck     /* Only the ACPI PDO has requirements */
435c2c66affSColin Finck     if (DeviceExtension->PdoType == AcpiPdo)
436c2c66affSColin Finck     {
437c2c66affSColin Finck         /* Query ACPI requirements */
438c2c66affSColin Finck         return HalpQueryAcpiResourceRequirements(Requirements);
439c2c66affSColin Finck     }
440c2c66affSColin Finck     else if (DeviceExtension->PdoType == WdPdo)
441c2c66affSColin Finck     {
442c2c66affSColin Finck         /* Watchdog doesn't */
443c2c66affSColin Finck         return STATUS_NOT_SUPPORTED;
444c2c66affSColin Finck     }
445c2c66affSColin Finck     else
446c2c66affSColin Finck     {
447c2c66affSColin Finck         /* This shouldn't happen */
448c2c66affSColin Finck         return STATUS_UNSUCCESSFUL;
449c2c66affSColin Finck     }
450c2c66affSColin Finck }
451c2c66affSColin Finck 
452c2c66affSColin Finck NTSTATUS
453c2c66affSColin Finck NTAPI
454c2c66affSColin Finck HalpQueryIdPdo(IN PDEVICE_OBJECT DeviceObject,
455c2c66affSColin Finck                IN BUS_QUERY_ID_TYPE IdType,
456c2c66affSColin Finck                OUT PUSHORT *BusQueryId)
457c2c66affSColin Finck {
458c2c66affSColin Finck     PPDO_EXTENSION PdoExtension;
459c2c66affSColin Finck     PDO_TYPE PdoType;
460c2c66affSColin Finck     PWCHAR CurrentId;
461c2c66affSColin Finck     WCHAR Id[100];
462c2c66affSColin Finck     NTSTATUS Status;
463c2c66affSColin Finck     SIZE_T Length = 0;
464c2c66affSColin Finck     PWCHAR Buffer;
465c2c66affSColin Finck 
466c2c66affSColin Finck     /* Get the PDO type */
467c2c66affSColin Finck     PdoExtension = DeviceObject->DeviceExtension;
468c2c66affSColin Finck     PdoType = PdoExtension->PdoType;
469c2c66affSColin Finck 
470c2c66affSColin Finck     /* What kind of ID is being requested? */
471c2c66affSColin Finck     DPRINT("ID: %d\n", IdType);
472c2c66affSColin Finck     switch (IdType)
473c2c66affSColin Finck     {
474c2c66affSColin Finck         case BusQueryDeviceID:
475c2c66affSColin Finck         case BusQueryHardwareIDs:
476c2c66affSColin Finck 
477c2c66affSColin Finck             /* What kind of PDO is this? */
478c2c66affSColin Finck             if (PdoType == AcpiPdo)
479c2c66affSColin Finck             {
480c2c66affSColin Finck                 /* ACPI ID */
481c2c66affSColin Finck                 CurrentId = L"ACPI_HAL\\PNP0C08";
482c2c66affSColin Finck                 RtlCopyMemory(Id, CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL));
483c2c66affSColin Finck                 Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
484c2c66affSColin Finck 
485c2c66affSColin Finck                 CurrentId = L"*PNP0C08";
486c2c66affSColin Finck                 RtlCopyMemory(&Id[wcslen(Id) + 1], CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL));
487c2c66affSColin Finck                 Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
488c2c66affSColin Finck             }
489c2c66affSColin Finck             else if (PdoType == WdPdo)
490c2c66affSColin Finck             {
491c2c66affSColin Finck                 /* WatchDog ID */
492c2c66affSColin Finck                 CurrentId = L"ACPI_HAL\\PNP0C18";
493c2c66affSColin Finck                 RtlCopyMemory(Id, CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL));
494c2c66affSColin Finck                 Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
495c2c66affSColin Finck 
496c2c66affSColin Finck                 CurrentId = L"*PNP0C18";
497c2c66affSColin Finck                 RtlCopyMemory(&Id[wcslen(Id) + 1], CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL));
498c2c66affSColin Finck                 Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
499c2c66affSColin Finck             }
500c2c66affSColin Finck             else
501c2c66affSColin Finck             {
502c2c66affSColin Finck                 /* Unknown */
503c2c66affSColin Finck                 return STATUS_NOT_SUPPORTED;
504c2c66affSColin Finck             }
505c2c66affSColin Finck             break;
506c2c66affSColin Finck 
507c2c66affSColin Finck         case BusQueryInstanceID:
508c2c66affSColin Finck 
509c2c66affSColin Finck             /* Instance ID */
510c2c66affSColin Finck             CurrentId = L"0";
511c2c66affSColin Finck             RtlCopyMemory(Id, CurrentId, (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL));
512c2c66affSColin Finck             Length += (wcslen(CurrentId) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
513c2c66affSColin Finck             break;
514c2c66affSColin Finck 
515c2c66affSColin Finck         case BusQueryCompatibleIDs:
516c2c66affSColin Finck         default:
517c2c66affSColin Finck 
518c2c66affSColin Finck             /* We don't support anything else */
519c2c66affSColin Finck             return STATUS_NOT_SUPPORTED;
520c2c66affSColin Finck     }
521c2c66affSColin Finck 
522c2c66affSColin Finck 
523c2c66affSColin Finck     /* Allocate the buffer */
524c2c66affSColin Finck     Buffer = ExAllocatePoolWithTag(PagedPool,
525c2c66affSColin Finck                                    Length + sizeof(UNICODE_NULL),
526c2c66affSColin Finck                                    TAG_HAL);
527c2c66affSColin Finck     if (Buffer)
528c2c66affSColin Finck     {
529c2c66affSColin Finck         /* Copy the string and null-terminate it */
530c2c66affSColin Finck         RtlCopyMemory(Buffer, Id, Length);
531c2c66affSColin Finck         Buffer[Length / sizeof(WCHAR)] = UNICODE_NULL;
532c2c66affSColin Finck 
533c2c66affSColin Finck         /* Return string */
534c2c66affSColin Finck         *BusQueryId = Buffer;
535c2c66affSColin Finck         Status = STATUS_SUCCESS;
536c2c66affSColin Finck         DPRINT("Returning: %S\n", *BusQueryId);
537c2c66affSColin Finck     }
538c2c66affSColin Finck     else
539c2c66affSColin Finck     {
540c2c66affSColin Finck         /* Fail */
541c2c66affSColin Finck         Status = STATUS_INSUFFICIENT_RESOURCES;
542c2c66affSColin Finck     }
543c2c66affSColin Finck 
544c2c66affSColin Finck     /* Return status */
545c2c66affSColin Finck     return Status;
546c2c66affSColin Finck }
547c2c66affSColin Finck 
548c2c66affSColin Finck NTSTATUS
549c2c66affSColin Finck NTAPI
550c2c66affSColin Finck HalpQueryIdFdo(IN PDEVICE_OBJECT DeviceObject,
551c2c66affSColin Finck                IN BUS_QUERY_ID_TYPE IdType,
552c2c66affSColin Finck                OUT PUSHORT *BusQueryId)
553c2c66affSColin Finck {
554c2c66affSColin Finck     NTSTATUS Status;
555c2c66affSColin Finck     SIZE_T Length;
556c2c66affSColin Finck     PWCHAR Id;
557c2c66affSColin Finck     PWCHAR Buffer;
558c2c66affSColin Finck 
559c2c66affSColin Finck     /* What kind of ID is being requested? */
560c2c66affSColin Finck     DPRINT("ID: %d\n", IdType);
561c2c66affSColin Finck     switch (IdType)
562c2c66affSColin Finck     {
563c2c66affSColin Finck         case BusQueryDeviceID:
564c2c66affSColin Finck             /* HACK */
565c2c66affSColin Finck             Id = L"Root\\ACPI_HAL";
566c2c66affSColin Finck             break;
567c2c66affSColin Finck 
568c2c66affSColin Finck         case BusQueryHardwareIDs:
569c2c66affSColin Finck 
570c2c66affSColin Finck             /* This is our hardware ID */
571c2c66affSColin Finck             Id = HalHardwareIdString;
572c2c66affSColin Finck             break;
573c2c66affSColin Finck 
574c2c66affSColin Finck         case BusQueryInstanceID:
575c2c66affSColin Finck 
576c2c66affSColin Finck             /* And our instance ID */
577c2c66affSColin Finck             Id = L"0";
578c2c66affSColin Finck             break;
579c2c66affSColin Finck 
580c2c66affSColin Finck         default:
581c2c66affSColin Finck 
582c2c66affSColin Finck             /* We don't support anything else */
583c2c66affSColin Finck             return STATUS_NOT_SUPPORTED;
584c2c66affSColin Finck     }
585c2c66affSColin Finck 
586c2c66affSColin Finck     /* Calculate the length */
587c2c66affSColin Finck     Length = (wcslen(Id) * sizeof(WCHAR)) + sizeof(UNICODE_NULL);
588c2c66affSColin Finck 
589c2c66affSColin Finck     /* Allocate the buffer */
590c2c66affSColin Finck     Buffer = ExAllocatePoolWithTag(PagedPool,
591c2c66affSColin Finck                                    Length + sizeof(UNICODE_NULL),
592c2c66affSColin Finck                                    TAG_HAL);
593c2c66affSColin Finck     if (Buffer)
594c2c66affSColin Finck     {
595c2c66affSColin Finck         /* Copy the string and null-terminate it */
596c2c66affSColin Finck         RtlCopyMemory(Buffer, Id, Length);
597c2c66affSColin Finck         Buffer[Length / sizeof(WCHAR)] = UNICODE_NULL;
598c2c66affSColin Finck 
599c2c66affSColin Finck         /* Return string */
600c2c66affSColin Finck         *BusQueryId = Buffer;
601c2c66affSColin Finck         Status = STATUS_SUCCESS;
602c2c66affSColin Finck         DPRINT("Returning: %S\n", *BusQueryId);
603c2c66affSColin Finck     }
604c2c66affSColin Finck     else
605c2c66affSColin Finck     {
606c2c66affSColin Finck         /* Fail */
607c2c66affSColin Finck         Status = STATUS_INSUFFICIENT_RESOURCES;
608c2c66affSColin Finck     }
609c2c66affSColin Finck 
610c2c66affSColin Finck     /* Return status */
611c2c66affSColin Finck     return Status;
612c2c66affSColin Finck }
613c2c66affSColin Finck 
614c2c66affSColin Finck NTSTATUS
615c2c66affSColin Finck NTAPI
616c2c66affSColin Finck HalpDispatchPnp(IN PDEVICE_OBJECT DeviceObject,
617c2c66affSColin Finck                 IN PIRP Irp)
618c2c66affSColin Finck {
619c2c66affSColin Finck     PIO_STACK_LOCATION IoStackLocation;
620c2c66affSColin Finck     //PPDO_EXTENSION PdoExtension;
621c2c66affSColin Finck     PFDO_EXTENSION FdoExtension;
622c2c66affSColin Finck     NTSTATUS Status;
623c2c66affSColin Finck     UCHAR Minor;
624c2c66affSColin Finck 
625c2c66affSColin Finck     /* Get the device extension and stack location */
626c2c66affSColin Finck     FdoExtension = DeviceObject->DeviceExtension;
627c2c66affSColin Finck     IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
628c2c66affSColin Finck     Minor = IoStackLocation->MinorFunction;
629c2c66affSColin Finck 
630c2c66affSColin Finck     /* FDO? */
631c2c66affSColin Finck     if (FdoExtension->ExtensionType == FdoExtensionType)
632c2c66affSColin Finck     {
633c2c66affSColin Finck         /* Query the IRP type */
634c2c66affSColin Finck         switch (Minor)
635c2c66affSColin Finck         {
636c2c66affSColin Finck             case IRP_MN_QUERY_DEVICE_RELATIONS:
637c2c66affSColin Finck 
638c2c66affSColin Finck                 /* Call the worker */
639c2c66affSColin Finck                 DPRINT("Querying device relations for FDO\n");
640c2c66affSColin Finck                 Status = HalpQueryDeviceRelations(DeviceObject,
641c2c66affSColin Finck                                                   IoStackLocation->Parameters.QueryDeviceRelations.Type,
642c2c66affSColin Finck                                                   (PVOID)&Irp->IoStatus.Information);
643c2c66affSColin Finck                 break;
644c2c66affSColin Finck 
645c2c66affSColin Finck             case IRP_MN_QUERY_INTERFACE:
646c2c66affSColin Finck 
647c2c66affSColin Finck                 /* Call the worker */
648c2c66affSColin Finck                 DPRINT("Querying interface for FDO\n");
649c2c66affSColin Finck                 Status = HalpQueryInterface(DeviceObject,
650c2c66affSColin Finck                                             IoStackLocation->Parameters.QueryInterface.InterfaceType,
651c2c66affSColin Finck                                             IoStackLocation->Parameters.QueryInterface.Size,
652c2c66affSColin Finck                                             IoStackLocation->Parameters.QueryInterface.InterfaceSpecificData,
653c2c66affSColin Finck                                             IoStackLocation->Parameters.QueryInterface.Version,
654c2c66affSColin Finck                                             IoStackLocation->Parameters.QueryInterface.Interface,
655c2c66affSColin Finck                                             (PVOID)&Irp->IoStatus.Information);
656c2c66affSColin Finck                 break;
657c2c66affSColin Finck 
658c2c66affSColin Finck 
659c2c66affSColin Finck             case IRP_MN_QUERY_ID:
660c2c66affSColin Finck 
661c2c66affSColin Finck                 /* Call the worker */
662c2c66affSColin Finck                 DPRINT("Querying ID for FDO\n");
663c2c66affSColin Finck                 Status = HalpQueryIdFdo(DeviceObject,
664c2c66affSColin Finck                                         IoStackLocation->Parameters.QueryId.IdType,
665c2c66affSColin Finck                                         (PVOID)&Irp->IoStatus.Information);
666c2c66affSColin Finck                 break;
667c2c66affSColin Finck 
668c2c66affSColin Finck             case IRP_MN_QUERY_CAPABILITIES:
669c2c66affSColin Finck 
670c2c66affSColin Finck                 /* Call the worker */
671c2c66affSColin Finck                 DPRINT("Querying the capabilities for the FDO\n");
672c2c66affSColin Finck                 Status = HalpQueryCapabilities(DeviceObject,
673c2c66affSColin Finck                                                IoStackLocation->Parameters.DeviceCapabilities.Capabilities);
674c2c66affSColin Finck                 break;
675c2c66affSColin Finck 
676c2c66affSColin Finck             default:
677c2c66affSColin Finck 
678c2c66affSColin Finck                 DPRINT("Other IRP: %lx\n", Minor);
679c2c66affSColin Finck                 Status = Irp->IoStatus.Status;
680c2c66affSColin Finck                 break;
681c2c66affSColin Finck         }
682c2c66affSColin Finck 
683c2c66affSColin Finck         /* Nowhere for the IRP to go since we also own the PDO */
684c2c66affSColin Finck         Irp->IoStatus.Status = Status;
685c2c66affSColin Finck         IoCompleteRequest(Irp, IO_NO_INCREMENT);
686c2c66affSColin Finck         return Status;
687c2c66affSColin Finck     }
688c2c66affSColin Finck     else
689c2c66affSColin Finck     {
690c2c66affSColin Finck         /* This is a PDO instead */
691c2c66affSColin Finck         ASSERT(FdoExtension->ExtensionType == PdoExtensionType);
692c2c66affSColin Finck         //PdoExtension = (PPDO_EXTENSION)FdoExtension;
693c2c66affSColin Finck         /* Query the IRP type */
694c2c66affSColin Finck         Status = STATUS_SUCCESS;
695c2c66affSColin Finck         switch (Minor)
696c2c66affSColin Finck         {
697c2c66affSColin Finck             case IRP_MN_START_DEVICE:
698c2c66affSColin Finck 
699c2c66affSColin Finck                 /* We only care about a PCI PDO */
700c2c66affSColin Finck                 DPRINT1("Start device received\n");
701c2c66affSColin Finck                 /* Complete the IRP normally */
702c2c66affSColin Finck                 break;
703c2c66affSColin Finck 
704c2c66affSColin Finck             case IRP_MN_REMOVE_DEVICE:
705c2c66affSColin Finck 
706c2c66affSColin Finck                 /* Check if this is a PCI device */
707c2c66affSColin Finck                 DPRINT1("Remove device received\n");
708c2c66affSColin Finck 
709c2c66affSColin Finck                 /* We're done */
710c2c66affSColin Finck                 Status = STATUS_SUCCESS;
711c2c66affSColin Finck                 break;
712c2c66affSColin Finck 
713c2c66affSColin Finck             case IRP_MN_SURPRISE_REMOVAL:
714c2c66affSColin Finck 
715c2c66affSColin Finck                 /* Inherit whatever status we had */
716c2c66affSColin Finck                 DPRINT1("Surprise removal IRP\n");
717c2c66affSColin Finck                 Status = Irp->IoStatus.Status;
718c2c66affSColin Finck                 break;
719c2c66affSColin Finck 
720c2c66affSColin Finck             case IRP_MN_QUERY_DEVICE_RELATIONS:
721c2c66affSColin Finck 
722c2c66affSColin Finck                 /* Query the device relations */
723c2c66affSColin Finck                 DPRINT("Querying PDO relations\n");
724c2c66affSColin Finck                 Status = HalpQueryDeviceRelations(DeviceObject,
725c2c66affSColin Finck                                                   IoStackLocation->Parameters.QueryDeviceRelations.Type,
726c2c66affSColin Finck                                                   (PVOID)&Irp->IoStatus.Information);
727c2c66affSColin Finck                 break;
728c2c66affSColin Finck 
729c2c66affSColin Finck             case IRP_MN_QUERY_INTERFACE:
730c2c66affSColin Finck 
731c2c66affSColin Finck                 /* Call the worker */
732c2c66affSColin Finck                 DPRINT("Querying interface for PDO\n");
733c2c66affSColin Finck                 Status = HalpQueryInterface(DeviceObject,
734c2c66affSColin Finck                                             IoStackLocation->Parameters.QueryInterface.InterfaceType,
735c2c66affSColin Finck                                             IoStackLocation->Parameters.QueryInterface.Size,
736c2c66affSColin Finck                                             IoStackLocation->Parameters.QueryInterface.InterfaceSpecificData,
737c2c66affSColin Finck                                             IoStackLocation->Parameters.QueryInterface.Version,
738c2c66affSColin Finck                                             IoStackLocation->Parameters.QueryInterface.Interface,
739c2c66affSColin Finck                                             (PVOID)&Irp->IoStatus.Information);
740c2c66affSColin Finck                 break;
741c2c66affSColin Finck 
742c2c66affSColin Finck             case IRP_MN_QUERY_CAPABILITIES:
743c2c66affSColin Finck 
744c2c66affSColin Finck                 /* Call the worker */
745c2c66affSColin Finck                 DPRINT("Querying the capabilities for the PDO\n");
746c2c66affSColin Finck                 Status = HalpQueryCapabilities(DeviceObject,
747c2c66affSColin Finck                                                IoStackLocation->Parameters.DeviceCapabilities.Capabilities);
748c2c66affSColin Finck                 break;
749c2c66affSColin Finck 
750c2c66affSColin Finck             case IRP_MN_QUERY_RESOURCES:
751c2c66affSColin Finck 
752c2c66affSColin Finck                 /* Call the worker */
753c2c66affSColin Finck                 DPRINT("Querying the resources for the PDO\n");
754c2c66affSColin Finck                 Status = HalpQueryResources(DeviceObject, (PVOID)&Irp->IoStatus.Information);
755c2c66affSColin Finck                 break;
756c2c66affSColin Finck 
757c2c66affSColin Finck             case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
758c2c66affSColin Finck 
759c2c66affSColin Finck                 /* Call the worker */
760c2c66affSColin Finck                 DPRINT("Querying the resource requirements for the PDO\n");
761c2c66affSColin Finck                 Status = HalpQueryResourceRequirements(DeviceObject,
762c2c66affSColin Finck                                                        (PVOID)&Irp->IoStatus.Information);
763c2c66affSColin Finck                 break;
764c2c66affSColin Finck 
765c2c66affSColin Finck             case IRP_MN_QUERY_ID:
766c2c66affSColin Finck 
767c2c66affSColin Finck                 /* Call the worker */
768c2c66affSColin Finck                 DPRINT("Query the ID for the PDO\n");
769c2c66affSColin Finck                 Status = HalpQueryIdPdo(DeviceObject,
770c2c66affSColin Finck                                         IoStackLocation->Parameters.QueryId.IdType,
771c2c66affSColin Finck                                         (PVOID)&Irp->IoStatus.Information);
772c2c66affSColin Finck                 break;
773c2c66affSColin Finck 
774c2c66affSColin Finck             default:
775c2c66affSColin Finck 
776c2c66affSColin Finck                 /* We don't handle anything else, so inherit the old state */
777c2c66affSColin Finck                 DPRINT("Illegal IRP: %lx\n", Minor);
778c2c66affSColin Finck                 Status = Irp->IoStatus.Status;
779c2c66affSColin Finck                 break;
780c2c66affSColin Finck         }
781c2c66affSColin Finck 
782c2c66affSColin Finck         /* If it's not supported, inherit the old status */
783c2c66affSColin Finck         if (Status == STATUS_NOT_SUPPORTED) Status = Irp->IoStatus.Status;
784c2c66affSColin Finck 
785c2c66affSColin Finck         /* Complete the IRP */
786c2c66affSColin Finck         DPRINT("IRP completed with status: %lx\n", Status);
787c2c66affSColin Finck         Irp->IoStatus.Status = Status;
788c2c66affSColin Finck         IoCompleteRequest(Irp, IO_NO_INCREMENT);
789c2c66affSColin Finck         return Status;
790c2c66affSColin Finck     }
791c2c66affSColin Finck }
792c2c66affSColin Finck 
793c2c66affSColin Finck NTSTATUS
794c2c66affSColin Finck NTAPI
795c2c66affSColin Finck HalpDispatchWmi(IN PDEVICE_OBJECT DeviceObject,
796c2c66affSColin Finck                 IN PIRP Irp)
797c2c66affSColin Finck {
798c2c66affSColin Finck     UNIMPLEMENTED_DBGBREAK("HAL: PnP Driver WMI!\n");
799c2c66affSColin Finck     return STATUS_SUCCESS;
800c2c66affSColin Finck }
801c2c66affSColin Finck 
802c2c66affSColin Finck NTSTATUS
803c2c66affSColin Finck NTAPI
804c2c66affSColin Finck HalpDispatchPower(IN PDEVICE_OBJECT DeviceObject,
805c2c66affSColin Finck                   IN PIRP Irp)
806c2c66affSColin Finck {
807c2c66affSColin Finck     PFDO_EXTENSION FdoExtension;
808c2c66affSColin Finck 
809c2c66affSColin Finck     DPRINT("HAL: PnP Driver Power!\n");
810c2c66affSColin Finck     FdoExtension = DeviceObject->DeviceExtension;
811c2c66affSColin Finck     if (FdoExtension->ExtensionType == FdoExtensionType)
812c2c66affSColin Finck     {
813c2c66affSColin Finck         PoStartNextPowerIrp(Irp);
814c2c66affSColin Finck         IoSkipCurrentIrpStackLocation(Irp);
815c2c66affSColin Finck         return PoCallDriver(FdoExtension->AttachedDeviceObject, Irp);
816c2c66affSColin Finck     }
817c2c66affSColin Finck     else
818c2c66affSColin Finck     {
819c2c66affSColin Finck         PoStartNextPowerIrp(Irp);
820c2c66affSColin Finck         Irp->IoStatus.Status = STATUS_SUCCESS;
821c2c66affSColin Finck         IoCompleteRequest(Irp, IO_NO_INCREMENT);
822c2c66affSColin Finck         return STATUS_SUCCESS;
823c2c66affSColin Finck     }
824c2c66affSColin Finck }
825c2c66affSColin Finck 
826c2c66affSColin Finck NTSTATUS
827c2c66affSColin Finck NTAPI
828c2c66affSColin Finck HalpDriverEntry(IN PDRIVER_OBJECT DriverObject,
829c2c66affSColin Finck                 IN PUNICODE_STRING RegistryPath)
830c2c66affSColin Finck {
831c2c66affSColin Finck     NTSTATUS Status;
832c2c66affSColin Finck     PDEVICE_OBJECT TargetDevice = NULL;
833c2c66affSColin Finck 
834c2c66affSColin Finck     DPRINT("HAL: PnP Driver ENTRY!\n");
835c2c66affSColin Finck 
836c2c66affSColin Finck     /* This is us */
837c2c66affSColin Finck     HalpDriverObject = DriverObject;
838c2c66affSColin Finck 
839c2c66affSColin Finck     /* Set up add device */
840c2c66affSColin Finck     DriverObject->DriverExtension->AddDevice = HalpAddDevice;
841c2c66affSColin Finck 
842c2c66affSColin Finck     /* Set up the callouts */
843c2c66affSColin Finck     DriverObject->MajorFunction[IRP_MJ_PNP] = HalpDispatchPnp;
844c2c66affSColin Finck     DriverObject->MajorFunction[IRP_MJ_POWER] = HalpDispatchPower;
845c2c66affSColin Finck     DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = HalpDispatchWmi;
846c2c66affSColin Finck 
8478aff2c9dSVictor Perevertkin     /* Create the PDO and tell the PnP manager about us*/
8488aff2c9dSVictor Perevertkin     Status = IoReportDetectedDevice(DriverObject,
8498aff2c9dSVictor Perevertkin                                     InterfaceTypeUndefined,
8508aff2c9dSVictor Perevertkin                                     -1,
8518aff2c9dSVictor Perevertkin                                     -1,
852c2c66affSColin Finck                                     NULL,
8538aff2c9dSVictor Perevertkin                                     NULL,
854c2c66affSColin Finck                                     FALSE,
855c2c66affSColin Finck                                     &TargetDevice);
856c2c66affSColin Finck     if (!NT_SUCCESS(Status))
857c2c66affSColin Finck         return Status;
858c2c66affSColin Finck 
859c2c66affSColin Finck     TargetDevice->Flags &= ~DO_DEVICE_INITIALIZING;
860c2c66affSColin Finck 
861c2c66affSColin Finck     /* Set up the device stack */
862c2c66affSColin Finck     Status = HalpAddDevice(DriverObject, TargetDevice);
863c2c66affSColin Finck     if (!NT_SUCCESS(Status))
864c2c66affSColin Finck     {
865c2c66affSColin Finck         IoDeleteDevice(TargetDevice);
866c2c66affSColin Finck         return Status;
867c2c66affSColin Finck     }
868c2c66affSColin Finck 
869c2c66affSColin Finck     /* Return to kernel */
870c2c66affSColin Finck     return Status;
871c2c66affSColin Finck }
872c2c66affSColin Finck 
873c2c66affSColin Finck NTSTATUS
874c2c66affSColin Finck NTAPI
875c2c66affSColin Finck HaliInitPnpDriver(VOID)
876c2c66affSColin Finck {
877c2c66affSColin Finck     NTSTATUS Status;
878c2c66affSColin Finck     UNICODE_STRING DriverString;
879c2c66affSColin Finck     PAGED_CODE();
880c2c66affSColin Finck 
881c2c66affSColin Finck     /* Create the driver */
882c2c66affSColin Finck     RtlInitUnicodeString(&DriverString, L"\\Driver\\ACPI_HAL");
883c2c66affSColin Finck     Status = IoCreateDriver(&DriverString, HalpDriverEntry);
884c2c66affSColin Finck 
885c2c66affSColin Finck     /* Return status */
886c2c66affSColin Finck     return Status;
887c2c66affSColin Finck }
888c2c66affSColin Finck 
889c2c66affSColin Finck /* EOF */
890