- Handle ACPI_RESOURCE_TYPE_EXTENDED_IRQ and ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64
[reactos.git] / reactos / drivers / bus / acpi / buspdo.c
1 #include <ntddk.h>
2
3 #include <acpi.h>
4 #include <acpisys.h>
5 #include <wdmguid.h>
6 #include <stdio.h>
7
8 #include <acpi_bus.h>
9 #include <acpi_drivers.h>
10
11 //#define NDEBUG
12 #include <debug.h>
13
14 #ifdef ALLOC_PRAGMA
15 #pragma alloc_text (PAGE, Bus_PDO_PnP)
16 #pragma alloc_text (PAGE, Bus_PDO_QueryDeviceCaps)
17 #pragma alloc_text (PAGE, Bus_PDO_QueryDeviceId)
18 #pragma alloc_text (PAGE, Bus_PDO_QueryDeviceText)
19 #pragma alloc_text (PAGE, Bus_PDO_QueryResources)
20 #pragma alloc_text (PAGE, Bus_PDO_QueryResourceRequirements)
21 #pragma alloc_text (PAGE, Bus_PDO_QueryDeviceRelations)
22 #pragma alloc_text (PAGE, Bus_PDO_QueryBusInformation)
23 #pragma alloc_text (PAGE, Bus_GetDeviceCapabilities)
24 #endif
25
26 NTSTATUS
27 Bus_PDO_PnP (
28 PDEVICE_OBJECT DeviceObject,
29 PIRP Irp,
30 PIO_STACK_LOCATION IrpStack,
31 PPDO_DEVICE_DATA DeviceData
32 )
33 {
34 NTSTATUS status;
35 POWER_STATE state;
36
37 PAGED_CODE ();
38
39 //
40 // NB: Because we are a bus enumerator, we have no one to whom we could
41 // defer these irps. Therefore we do not pass them down but merely
42 // return them.
43 //
44
45 switch (IrpStack->MinorFunction) {
46
47 case IRP_MN_START_DEVICE:
48
49 //
50 // Here we do what ever initialization and ``turning on'' that is
51 // required to allow others to access this device.
52 // Power up the device.
53 //
54 if (DeviceData->AcpiHandle && acpi_bus_power_manageable(DeviceData->AcpiHandle) &&
55 !ACPI_SUCCESS(acpi_bus_set_power(DeviceData->AcpiHandle, ACPI_STATE_D0)))
56 {
57 DPRINT1("Device %x failed to start!\n", DeviceData->AcpiHandle);
58 status = STATUS_UNSUCCESSFUL;
59 break;
60 }
61
62 state.DeviceState = PowerDeviceD0;
63 PoSetPowerState(DeviceData->Common.Self, DevicePowerState, state);
64 DeviceData->Common.DevicePowerState = PowerDeviceD0;
65 SET_NEW_PNP_STATE(DeviceData->Common, Started);
66 status = STATUS_SUCCESS;
67 break;
68
69 case IRP_MN_STOP_DEVICE:
70
71 //
72 // Here we shut down the device and give up and unmap any resources
73 // we acquired for the device.
74 //
75 if (DeviceData->AcpiHandle && acpi_bus_power_manageable(DeviceData->AcpiHandle) &&
76 !ACPI_SUCCESS(acpi_bus_set_power(DeviceData->AcpiHandle, ACPI_STATE_D3)))
77 {
78 DPRINT1("Device %x failed to stop!\n", DeviceData->AcpiHandle);
79 status = STATUS_UNSUCCESSFUL;
80 break;
81 }
82
83 state.DeviceState = PowerDeviceD3;
84 PoSetPowerState(DeviceData->Common.Self, DevicePowerState, state);
85 DeviceData->Common.DevicePowerState = PowerDeviceD3;
86 SET_NEW_PNP_STATE(DeviceData->Common, Stopped);
87 status = STATUS_SUCCESS;
88 break;
89
90
91 case IRP_MN_QUERY_STOP_DEVICE:
92
93 //
94 // No reason here why we can't stop the device.
95 // If there were a reason we should speak now, because answering success
96 // here may result in a stop device irp.
97 //
98
99 SET_NEW_PNP_STATE(DeviceData->Common, StopPending);
100 status = STATUS_SUCCESS;
101 break;
102
103 case IRP_MN_CANCEL_STOP_DEVICE:
104
105 //
106 // The stop was canceled. Whatever state we set, or resources we put
107 // on hold in anticipation of the forthcoming STOP device IRP should be
108 // put back to normal. Someone, in the long list of concerned parties,
109 // has failed the stop device query.
110 //
111
112 //
113 // First check to see whether you have received cancel-stop
114 // without first receiving a query-stop. This could happen if someone
115 // above us fails a query-stop and passes down the subsequent
116 // cancel-stop.
117 //
118
119 if (StopPending == DeviceData->Common.DevicePnPState)
120 {
121 //
122 // We did receive a query-stop, so restore.
123 //
124 RESTORE_PREVIOUS_PNP_STATE(DeviceData->Common);
125 }
126 status = STATUS_SUCCESS;// We must not fail this IRP.
127 break;
128 case IRP_MN_QUERY_CAPABILITIES:
129
130 //
131 // Return the capabilities of a device, such as whether the device
132 // can be locked or ejected..etc
133 //
134
135 status = Bus_PDO_QueryDeviceCaps(DeviceData, Irp);
136
137 break;
138
139 case IRP_MN_QUERY_ID:
140
141 // Query the IDs of the device
142 status = Bus_PDO_QueryDeviceId(DeviceData, Irp);
143
144 break;
145
146 case IRP_MN_QUERY_DEVICE_RELATIONS:
147
148 DPRINT("\tQueryDeviceRelation Type: %s\n",DbgDeviceRelationString(\
149 IrpStack->Parameters.QueryDeviceRelations.Type));
150
151 status = Bus_PDO_QueryDeviceRelations(DeviceData, Irp);
152
153 break;
154
155 case IRP_MN_QUERY_DEVICE_TEXT:
156
157 status = Bus_PDO_QueryDeviceText(DeviceData, Irp);
158
159 break;
160
161 case IRP_MN_QUERY_RESOURCES:
162
163 status = Bus_PDO_QueryResources(DeviceData, Irp);
164
165 break;
166
167 case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
168
169 status = Bus_PDO_QueryResourceRequirements(DeviceData, Irp);
170
171 break;
172
173 case IRP_MN_QUERY_BUS_INFORMATION:
174
175 status = Bus_PDO_QueryBusInformation(DeviceData, Irp);
176
177 break;
178
179
180 case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
181
182 //
183 // OPTIONAL for bus drivers.
184 // The PnP Manager sends this IRP to a device
185 // stack so filter and function drivers can adjust the
186 // resources required by the device, if appropriate.
187 //
188
189 //break;
190
191 //case IRP_MN_QUERY_PNP_DEVICE_STATE:
192
193 //
194 // OPTIONAL for bus drivers.
195 // The PnP Manager sends this IRP after the drivers for
196 // a device return success from the IRP_MN_START_DEVICE
197 // request. The PnP Manager also sends this IRP when a
198 // driver for the device calls IoInvalidateDeviceState.
199 //
200
201 // break;
202
203 //case IRP_MN_READ_CONFIG:
204 //case IRP_MN_WRITE_CONFIG:
205
206 //
207 // Bus drivers for buses with configuration space must handle
208 // this request for their child devices. Our devices don't
209 // have a config space.
210 //
211
212 // break;
213
214 //case IRP_MN_SET_LOCK:
215
216 // break;
217
218 default:
219
220 //
221 // For PnP requests to the PDO that we do not understand we should
222 // return the IRP WITHOUT setting the status or information fields.
223 // These fields may have already been set by a filter (eg acpi).
224 status = Irp->IoStatus.Status;
225
226 break;
227 }
228
229 Irp->IoStatus.Status = status;
230 IoCompleteRequest (Irp, IO_NO_INCREMENT);
231
232 return status;
233 }
234
235 NTSTATUS
236 Bus_PDO_QueryDeviceCaps(
237 PPDO_DEVICE_DATA DeviceData,
238 PIRP Irp )
239 {
240
241 PIO_STACK_LOCATION stack;
242 PDEVICE_CAPABILITIES deviceCapabilities;
243 struct acpi_device *device = NULL;
244 ULONG i;
245
246 PAGED_CODE ();
247
248 if (DeviceData->AcpiHandle)
249 acpi_bus_get_device(DeviceData->AcpiHandle, &device);
250
251 stack = IoGetCurrentIrpStackLocation (Irp);
252
253 //
254 // Get the packet.
255 //
256 deviceCapabilities=stack->Parameters.DeviceCapabilities.Capabilities;
257
258 //
259 // Set the capabilities.
260 //
261
262 if (deviceCapabilities->Version != 1 ||
263 deviceCapabilities->Size < sizeof(DEVICE_CAPABILITIES))
264 {
265 return STATUS_UNSUCCESSFUL;
266 }
267
268 deviceCapabilities->D1Latency = 0;
269 deviceCapabilities->D2Latency = 0;
270 deviceCapabilities->D3Latency = 0;
271
272 deviceCapabilities->DeviceState[PowerSystemWorking] = PowerDeviceD0;
273 deviceCapabilities->DeviceState[PowerSystemSleeping1] = PowerDeviceD3;
274 deviceCapabilities->DeviceState[PowerSystemSleeping2] = PowerDeviceD3;
275 deviceCapabilities->DeviceState[PowerSystemSleeping3] = PowerDeviceD3;
276
277 for (i = 0; i < ACPI_D_STATE_COUNT && device; i++)
278 {
279 if (!device->power.states[i].flags.valid)
280 continue;
281
282 switch (i)
283 {
284 case ACPI_STATE_D0:
285 deviceCapabilities->DeviceState[PowerSystemWorking] = PowerDeviceD0;
286 break;
287
288 case ACPI_STATE_D1:
289 deviceCapabilities->DeviceState[PowerSystemSleeping1] = PowerDeviceD1;
290 deviceCapabilities->D1Latency = device->power.states[i].latency;
291 break;
292
293 case ACPI_STATE_D2:
294 deviceCapabilities->DeviceState[PowerSystemSleeping2] = PowerDeviceD2;
295 deviceCapabilities->D2Latency = device->power.states[i].latency;
296 break;
297
298 case ACPI_STATE_D3:
299 deviceCapabilities->DeviceState[PowerSystemSleeping3] = PowerDeviceD3;
300 deviceCapabilities->D3Latency = device->power.states[i].latency;
301 break;
302 }
303 }
304
305 // We can wake the system from D1
306 deviceCapabilities->DeviceWake = PowerDeviceD1;
307
308
309 deviceCapabilities->DeviceD1 =
310 (deviceCapabilities->DeviceState[PowerSystemSleeping1] == PowerDeviceD1) ? TRUE : FALSE;
311 deviceCapabilities->DeviceD2 =
312 (deviceCapabilities->DeviceState[PowerSystemSleeping2] == PowerDeviceD2) ? TRUE : FALSE;
313
314 deviceCapabilities->WakeFromD0 = FALSE;
315 deviceCapabilities->WakeFromD1 = TRUE; //Yes we can
316 deviceCapabilities->WakeFromD2 = FALSE;
317 deviceCapabilities->WakeFromD3 = FALSE;
318
319 if (device)
320 {
321 deviceCapabilities->EjectSupported = device->flags.ejectable;
322 deviceCapabilities->HardwareDisabled = !device->status.enabled;
323 deviceCapabilities->Removable = device->flags.removable;
324 deviceCapabilities->SurpriseRemovalOK = device->flags.suprise_removal_ok;
325 deviceCapabilities->UniqueID = device->flags.unique_id;
326 deviceCapabilities->NoDisplayInUI = !device->status.show_in_ui;
327 deviceCapabilities->Address = device->pnp.bus_address;
328 deviceCapabilities->RawDeviceOK = FALSE;
329 }
330 else
331 {
332 deviceCapabilities->EjectSupported = FALSE;
333 deviceCapabilities->HardwareDisabled = FALSE;
334 deviceCapabilities->Removable = FALSE;
335 deviceCapabilities->SurpriseRemovalOK = FALSE;
336 deviceCapabilities->UniqueID = FALSE;
337 deviceCapabilities->NoDisplayInUI = FALSE;
338 deviceCapabilities->Address = 0;
339
340 /* The ACPI driver will run fixed buttons */
341 deviceCapabilities->RawDeviceOK = TRUE;
342 }
343
344 deviceCapabilities->SilentInstall = FALSE;
345 deviceCapabilities->UINumber = (ULONG)-1;
346
347 return STATUS_SUCCESS;
348
349 }
350
351 NTSTATUS
352 Bus_PDO_QueryDeviceId(
353 PPDO_DEVICE_DATA DeviceData,
354 PIRP Irp )
355 {
356 PIO_STACK_LOCATION stack;
357 PWCHAR buffer;
358 WCHAR temp[256];
359 ULONG length;
360 NTSTATUS status = STATUS_SUCCESS;
361 struct acpi_device *Device;
362
363 PAGED_CODE ();
364
365 stack = IoGetCurrentIrpStackLocation (Irp);
366
367 switch (stack->Parameters.QueryId.IdType) {
368
369 case BusQueryDeviceID:
370 if (DeviceData->AcpiHandle)
371 {
372 acpi_bus_get_device(DeviceData->AcpiHandle, &Device);
373
374 length = swprintf(temp,
375 L"ACPI\\%hs",
376 Device->pnp.hardware_id);
377 }
378 else
379 {
380 /* We know it's a fixed feature button because
381 * these are direct children of the ACPI root device
382 * and therefore have no handle
383 */
384 length = swprintf(temp,
385 L"ACPI\\FixedButton");
386 }
387
388 temp[++length] = UNICODE_NULL;
389
390 buffer = ExAllocatePoolWithTag (PagedPool, length * sizeof(WCHAR), 'IPCA');
391
392 if (!buffer) {
393 status = STATUS_INSUFFICIENT_RESOURCES;
394 break;
395 }
396
397 RtlCopyMemory (buffer, temp, length * sizeof(WCHAR));
398 Irp->IoStatus.Information = (ULONG_PTR) buffer;
399 DPRINT("BusQueryDeviceID: %ls\n",buffer);
400 break;
401
402 case BusQueryInstanceID:
403 /* See comment in BusQueryDeviceID case */
404 if(DeviceData->AcpiHandle)
405 {
406 acpi_bus_get_device(DeviceData->AcpiHandle, &Device);
407
408 if (Device->flags.unique_id)
409 length = swprintf(temp,
410 L"%hs",
411 Device->pnp.unique_id);
412 else
413 /* FIXME: Generate unique id! */
414 length = swprintf(temp, L"%ls", L"0000");
415 }
416 else
417 /* FIXME: Generate unique id! */
418 length = swprintf(temp, L"%ls", L"0000");
419
420 temp[++length] = UNICODE_NULL;
421
422 buffer = ExAllocatePoolWithTag (PagedPool, length * sizeof (WCHAR), 'IPCA');
423 if (!buffer) {
424 status = STATUS_INSUFFICIENT_RESOURCES;
425 break;
426 }
427
428 RtlCopyMemory (buffer, temp, length * sizeof (WCHAR));
429 DPRINT("BusQueryInstanceID: %ls\n",buffer);
430 Irp->IoStatus.Information = (ULONG_PTR) buffer;
431 break;
432
433 case BusQueryHardwareIDs:
434 length = 0;
435
436 /* See comment in BusQueryDeviceID case */
437 if (DeviceData->AcpiHandle)
438 {
439 acpi_bus_get_device(DeviceData->AcpiHandle, &Device);
440
441 length += swprintf(&temp[length],
442 L"ACPI\\%hs",
443 Device->pnp.hardware_id);
444 length++;
445
446 length += swprintf(&temp[length],
447 L"*%hs",
448 Device->pnp.hardware_id);
449 length++;
450 }
451 else
452 {
453 length += swprintf(&temp[length],
454 L"ACPI\\FixedButton");
455 length++;
456
457 length += swprintf(&temp[length],
458 L"*FixedButton");
459 length++;
460 }
461
462 temp[length] = UNICODE_NULL;
463
464 length++;
465
466 temp[length] = UNICODE_NULL;
467
468 buffer = ExAllocatePoolWithTag (PagedPool, length * sizeof(WCHAR), 'IPCA');
469
470 if (!buffer) {
471 status = STATUS_INSUFFICIENT_RESOURCES;
472 break;
473 }
474
475 RtlCopyMemory (buffer, temp, length * sizeof(WCHAR));
476 Irp->IoStatus.Information = (ULONG_PTR) buffer;
477 DPRINT("BusQueryHardwareIDs: %ls\n",buffer);
478 break;
479
480 default:
481 status = Irp->IoStatus.Status;
482 }
483 return status;
484 }
485
486 NTSTATUS
487 Bus_PDO_QueryDeviceText(
488 PPDO_DEVICE_DATA DeviceData,
489 PIRP Irp )
490 {
491 PWCHAR Buffer;
492 PIO_STACK_LOCATION stack;
493 NTSTATUS status;
494 PAGED_CODE ();
495
496 stack = IoGetCurrentIrpStackLocation (Irp);
497
498 switch (stack->Parameters.QueryDeviceText.DeviceTextType) {
499
500 case DeviceTextDescription:
501
502 if (!Irp->IoStatus.Information) {
503 if (wcsstr (DeviceData->HardwareIDs, L"PNP000") != 0)
504 Buffer = L"Programmable interrupt controller";
505 else if (wcsstr(DeviceData->HardwareIDs, L"PNP010") != 0)
506 Buffer = L"System timer";
507 else if (wcsstr(DeviceData->HardwareIDs, L"PNP020") != 0)
508 Buffer = L"DMA controller";
509 else if (wcsstr(DeviceData->HardwareIDs, L"PNP03") != 0)
510 Buffer = L"Keyboard";
511 else if (wcsstr(DeviceData->HardwareIDs, L"PNP040") != 0)
512 Buffer = L"Parallel port";
513 else if (wcsstr(DeviceData->HardwareIDs, L"PNP05") != 0)
514 Buffer = L"Serial port";
515 else if (wcsstr(DeviceData->HardwareIDs, L"PNP06") != 0)
516 Buffer = L"Disk controller";
517 else if (wcsstr(DeviceData->HardwareIDs, L"PNP07") != 0)
518 Buffer = L"Disk controller";
519 else if (wcsstr(DeviceData->HardwareIDs, L"PNP09") != 0)
520 Buffer = L"Display adapter";
521 else if (wcsstr(DeviceData->HardwareIDs, L"PNP0A0") != 0)
522 Buffer = L"Bus controller";
523 else if (wcsstr(DeviceData->HardwareIDs, L"PNP0E0") != 0)
524 Buffer = L"PCMCIA controller";
525 else if (wcsstr(DeviceData->HardwareIDs, L"PNP0F") != 0)
526 Buffer = L"Mouse device";
527 else if (wcsstr(DeviceData->HardwareIDs, L"PNP8") != 0)
528 Buffer = L"Network adapter";
529 else if (wcsstr(DeviceData->HardwareIDs, L"PNPA0") != 0)
530 Buffer = L"SCSI controller";
531 else if (wcsstr(DeviceData->HardwareIDs, L"PNPB0") != 0)
532 Buffer = L"Multimedia device";
533 else if (wcsstr(DeviceData->HardwareIDs, L"PNPC00") != 0)
534 Buffer = L"Modem";
535 else if (wcsstr(DeviceData->HardwareIDs, L"PNP0C0C") != 0)
536 Buffer = L"Power Button";
537 else if (wcsstr(DeviceData->HardwareIDs, L"PNP0C0E") != 0)
538 Buffer = L"Sleep Button";
539 else if (wcsstr(DeviceData->HardwareIDs, L"PNP0C0D") != 0)
540 Buffer = L"Lid Switch";
541 else if (wcsstr(DeviceData->HardwareIDs, L"PNP0C09") != 0)
542 Buffer = L"ACPI Embedded Controller";
543 else if (wcsstr(DeviceData->HardwareIDs, L"PNP0C0B") != 0)
544 Buffer = L"ACPI Fan";
545 else if (wcsstr(DeviceData->HardwareIDs, L"PNP0A03") != 0)
546 Buffer = L"PCI Root Bridge";
547 else if (wcsstr(DeviceData->HardwareIDs, L"PNP0C0A") != 0)
548 Buffer = L"ACPI Battery";
549 else if (wcsstr(DeviceData->HardwareIDs, L"PNP0C0F") != 0)
550 Buffer = L"PCI Interrupt Link";
551 else if (wcsstr(DeviceData->HardwareIDs, L"ACPI_PWR") != 0)
552 Buffer = L"ACPI Power Resource";
553 else if (wcsstr(DeviceData->HardwareIDs, L"Processor") != 0)
554 Buffer = L"Processor";
555 else if (wcsstr(DeviceData->HardwareIDs, L"ThermalZone") != 0)
556 Buffer = L"ACPI Thermal Zone";
557 else if (wcsstr(DeviceData->HardwareIDs, L"ACPI0002") != 0)
558 Buffer = L"Smart Battery";
559 else if (wcsstr(DeviceData->HardwareIDs, L"ACPI0003") != 0)
560 Buffer = L"AC Adapter";
561 /* Simply checking if AcpiHandle is NULL eliminates the need to check
562 * for the 4 different names that ACPI knows the fixed feature button as internally
563 */
564 else if (!DeviceData->AcpiHandle)
565 Buffer = L"ACPI Fixed Feature Button";
566 else
567 Buffer = L"Other ACPI device";
568
569 DPRINT("\tDeviceTextDescription :%ws\n", Buffer);
570
571 Irp->IoStatus.Information = (ULONG_PTR) Buffer;
572 }
573 status = STATUS_SUCCESS;
574 break;
575
576 default:
577 status = Irp->IoStatus.Status;
578 break;
579 }
580
581 return status;
582
583 }
584
585 NTSTATUS
586 Bus_PDO_QueryResources(
587 PPDO_DEVICE_DATA DeviceData,
588 PIRP Irp )
589 {
590 ULONG NumberOfResources = 0;
591 PCM_RESOURCE_LIST ResourceList;
592 PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor;
593 ACPI_STATUS AcpiStatus;
594 ACPI_BUFFER Buffer;
595 ACPI_RESOURCE* resource;
596 ULONG ResourceListSize;
597 ULONG i;
598
599 /* Get current resources */
600 Buffer.Length = 0;
601 AcpiStatus = AcpiGetCurrentResources(DeviceData->AcpiHandle, &Buffer);
602 if ((!ACPI_SUCCESS(AcpiStatus) && AcpiStatus != AE_BUFFER_OVERFLOW) ||
603 Buffer.Length == 0)
604 {
605 return Irp->IoStatus.Status;
606 }
607
608 Buffer.Pointer = ExAllocatePool(PagedPool, Buffer.Length);
609 if (!Buffer.Pointer)
610 return STATUS_INSUFFICIENT_RESOURCES;
611
612 AcpiStatus = AcpiGetCurrentResources(DeviceData->AcpiHandle, &Buffer);
613 if (!ACPI_SUCCESS(AcpiStatus))
614 {
615 DPRINT1("AcpiGetCurrentResources #2 failed (0x%x)\n", AcpiStatus);
616 ASSERT(FALSE);
617 return STATUS_UNSUCCESSFUL;
618 }
619
620 resource= Buffer.Pointer;
621 /* Count number of resources */
622 while (resource->Type != ACPI_RESOURCE_TYPE_END_TAG)
623 {
624 switch (resource->Type)
625 {
626 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
627 {
628 ACPI_RESOURCE_EXTENDED_IRQ *irq_data = (ACPI_RESOURCE_EXTENDED_IRQ*) &resource->Data;
629 NumberOfResources += irq_data->InterruptCount;
630 break;
631 }
632 case ACPI_RESOURCE_TYPE_IRQ:
633 {
634 ACPI_RESOURCE_IRQ *irq_data = (ACPI_RESOURCE_IRQ*) &resource->Data;
635 NumberOfResources += irq_data->InterruptCount;
636 break;
637 }
638 case ACPI_RESOURCE_TYPE_DMA:
639 {
640 ACPI_RESOURCE_DMA *dma_data = (ACPI_RESOURCE_DMA*) &resource->Data;
641 NumberOfResources += dma_data->ChannelCount;
642 break;
643 }
644 case ACPI_RESOURCE_TYPE_ADDRESS16:
645 case ACPI_RESOURCE_TYPE_ADDRESS32:
646 case ACPI_RESOURCE_TYPE_ADDRESS64:
647 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
648 case ACPI_RESOURCE_TYPE_MEMORY24:
649 case ACPI_RESOURCE_TYPE_MEMORY32:
650 case ACPI_RESOURCE_TYPE_IO:
651 {
652 NumberOfResources++;
653 break;
654 }
655 default:
656 {
657 DPRINT1("Unknown resource type: %d\n", resource->Type);
658 break;
659 }
660 }
661 resource = ACPI_NEXT_RESOURCE(resource);
662 }
663
664 /* Allocate memory */
665 ResourceListSize = sizeof(CM_RESOURCE_LIST) + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * (NumberOfResources - 1);
666 ResourceList = (PCM_RESOURCE_LIST)ExAllocatePool(PagedPool, ResourceListSize);
667
668 if (!ResourceList)
669 {
670 ExFreePool(Buffer.Pointer);
671 return STATUS_INSUFFICIENT_RESOURCES;
672 }
673 ResourceList->Count = 1;
674 ResourceList->List[0].InterfaceType = Internal; /* FIXME */
675 ResourceList->List[0].BusNumber = 0; /* We're the only ACPI bus device in the system */
676 ResourceList->List[0].PartialResourceList.Version = 1;
677 ResourceList->List[0].PartialResourceList.Revision = 1;
678 ResourceList->List[0].PartialResourceList.Count = NumberOfResources;
679 ResourceDescriptor = ResourceList->List[0].PartialResourceList.PartialDescriptors;
680
681 /* Fill resources list structure */
682 while (resource->Type != ACPI_RESOURCE_TYPE_END_TAG)
683 {
684 switch (resource->Type)
685 {
686 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
687 {
688 ACPI_RESOURCE_EXTENDED_IRQ *irq_data = (ACPI_RESOURCE_EXTENDED_IRQ*) &resource->Data;
689 for (i = 0; i < irq_data->InterruptCount; i++)
690 {
691 ResourceDescriptor->Type = CmResourceTypeInterrupt;
692
693 ResourceDescriptor->ShareDisposition =
694 (irq_data->Sharable == ACPI_SHARED ? CmResourceShareShared : CmResourceShareDeviceExclusive);
695 ResourceDescriptor->Flags =
696 (irq_data->Triggering == ACPI_LEVEL_SENSITIVE ? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE : CM_RESOURCE_INTERRUPT_LATCHED);
697 ResourceDescriptor->u.Interrupt.Level = irq_data->Interrupts[i];
698 ResourceDescriptor->u.Interrupt.Vector = 0;
699 ResourceDescriptor->u.Interrupt.Affinity = (KAFFINITY)(-1);
700
701 ResourceDescriptor++;
702 }
703 break;
704 }
705 case ACPI_RESOURCE_TYPE_IRQ:
706 {
707 ACPI_RESOURCE_IRQ *irq_data = (ACPI_RESOURCE_IRQ*) &resource->Data;
708 for (i = 0; i < irq_data->InterruptCount; i++)
709 {
710 ResourceDescriptor->Type = CmResourceTypeInterrupt;
711
712 ResourceDescriptor->ShareDisposition =
713 (irq_data->Sharable == ACPI_SHARED ? CmResourceShareShared : CmResourceShareDeviceExclusive);
714 ResourceDescriptor->Flags =
715 (irq_data->Triggering == ACPI_LEVEL_SENSITIVE ? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE : CM_RESOURCE_INTERRUPT_LATCHED);
716 ResourceDescriptor->u.Interrupt.Level = irq_data->Interrupts[i];
717 ResourceDescriptor->u.Interrupt.Vector = 0;
718 ResourceDescriptor->u.Interrupt.Affinity = (KAFFINITY)(-1);
719
720 ResourceDescriptor++;
721 }
722 break;
723 }
724 case ACPI_RESOURCE_TYPE_DMA:
725 {
726 ACPI_RESOURCE_DMA *dma_data = (ACPI_RESOURCE_DMA*) &resource->Data;
727 for (i = 0; i < dma_data->ChannelCount; i++)
728 {
729 ResourceDescriptor->Type = CmResourceTypeDma;
730 ResourceDescriptor->Flags = 0;
731 switch (dma_data->Type)
732 {
733 case ACPI_TYPE_A: ResourceDescriptor->Flags |= CM_RESOURCE_DMA_TYPE_A; break;
734 case ACPI_TYPE_B: ResourceDescriptor->Flags |= CM_RESOURCE_DMA_TYPE_B; break;
735 case ACPI_TYPE_F: ResourceDescriptor->Flags |= CM_RESOURCE_DMA_TYPE_F; break;
736 }
737 if (dma_data->BusMaster == ACPI_BUS_MASTER)
738 ResourceDescriptor->Flags |= CM_RESOURCE_DMA_BUS_MASTER;
739 switch (dma_data->Transfer)
740 {
741 case ACPI_TRANSFER_8: ResourceDescriptor->Flags |= CM_RESOURCE_DMA_8; break;
742 case ACPI_TRANSFER_16: ResourceDescriptor->Flags |= CM_RESOURCE_DMA_16; break;
743 case ACPI_TRANSFER_8_16: ResourceDescriptor->Flags |= CM_RESOURCE_DMA_8_AND_16; break;
744 }
745 ResourceDescriptor->u.Dma.Channel = dma_data->Channels[i];
746
747 ResourceDescriptor++;
748 }
749 break;
750 }
751 case ACPI_RESOURCE_TYPE_IO:
752 {
753 ACPI_RESOURCE_IO *io_data = (ACPI_RESOURCE_IO*) &resource->Data;
754 ResourceDescriptor->Type = CmResourceTypePort;
755 ResourceDescriptor->ShareDisposition = CmResourceShareDriverExclusive;
756 ResourceDescriptor->Flags = CM_RESOURCE_PORT_IO;
757 if (io_data->IoDecode == ACPI_DECODE_16)
758 ResourceDescriptor->Flags |= CM_RESOURCE_PORT_16_BIT_DECODE;
759 else
760 ResourceDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE;
761 ResourceDescriptor->u.Port.Start.QuadPart = io_data->Minimum;
762 ResourceDescriptor->u.Port.Length = io_data->AddressLength;
763
764 ResourceDescriptor++;
765 break;
766 }
767 case ACPI_RESOURCE_TYPE_ADDRESS16:
768 {
769 ACPI_RESOURCE_ADDRESS16 *addr16_data = (ACPI_RESOURCE_ADDRESS16*) &resource->Data;
770 if (addr16_data->ResourceType == ACPI_BUS_NUMBER_RANGE)
771 {
772 ResourceDescriptor->Type = CmResourceTypeBusNumber;
773 ResourceDescriptor->ShareDisposition = CmResourceShareShared;
774 ResourceDescriptor->Flags = 0;
775 ResourceDescriptor->u.BusNumber.Start = addr16_data->Minimum;
776 ResourceDescriptor->u.BusNumber.Length = addr16_data->AddressLength;
777 }
778 else if (addr16_data->ResourceType == ACPI_IO_RANGE)
779 {
780 ResourceDescriptor->Type = CmResourceTypePort;
781 ResourceDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
782 ResourceDescriptor->Flags = CM_RESOURCE_PORT_IO;
783 if (addr16_data->Decode == ACPI_POS_DECODE)
784 ResourceDescriptor->Flags |= CM_RESOURCE_PORT_POSITIVE_DECODE;
785 ResourceDescriptor->u.Port.Start.QuadPart = addr16_data->Minimum;
786 ResourceDescriptor->u.Port.Length = addr16_data->AddressLength;
787 }
788 else
789 {
790 ResourceDescriptor->Type = CmResourceTypeMemory;
791 ResourceDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
792 ResourceDescriptor->Flags = 0;
793 if (addr16_data->Info.Mem.WriteProtect == ACPI_READ_ONLY_MEMORY)
794 ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
795 else
796 ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
797 switch (addr16_data->Info.Mem.Caching)
798 {
799 case ACPI_CACHABLE_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
800 case ACPI_WRITE_COMBINING_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
801 case ACPI_PREFETCHABLE_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
802 }
803 ResourceDescriptor->u.Memory.Start.QuadPart = addr16_data->Minimum;
804 ResourceDescriptor->u.Memory.Length = addr16_data->AddressLength;
805 }
806 ResourceDescriptor++;
807 break;
808 }
809 case ACPI_RESOURCE_TYPE_ADDRESS32:
810 {
811 ACPI_RESOURCE_ADDRESS32 *addr32_data = (ACPI_RESOURCE_ADDRESS32*) &resource->Data;
812 if (addr32_data->ResourceType == ACPI_BUS_NUMBER_RANGE)
813 {
814 ResourceDescriptor->Type = CmResourceTypeBusNumber;
815 ResourceDescriptor->ShareDisposition = CmResourceShareShared;
816 ResourceDescriptor->Flags = 0;
817 ResourceDescriptor->u.BusNumber.Start = addr32_data->Minimum;
818 ResourceDescriptor->u.BusNumber.Length = addr32_data->AddressLength;
819 }
820 else if (addr32_data->ResourceType == ACPI_IO_RANGE)
821 {
822 ResourceDescriptor->Type = CmResourceTypePort;
823 ResourceDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
824 ResourceDescriptor->Flags = CM_RESOURCE_PORT_IO;
825 if (addr32_data->Decode == ACPI_POS_DECODE)
826 ResourceDescriptor->Flags |= CM_RESOURCE_PORT_POSITIVE_DECODE;
827 ResourceDescriptor->u.Port.Start.QuadPart = addr32_data->Minimum;
828 ResourceDescriptor->u.Port.Length = addr32_data->AddressLength;
829 }
830 else
831 {
832 ResourceDescriptor->Type = CmResourceTypeMemory;
833 ResourceDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
834 ResourceDescriptor->Flags = 0;
835 if (addr32_data->Info.Mem.WriteProtect == ACPI_READ_ONLY_MEMORY)
836 ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
837 else
838 ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
839 switch (addr32_data->Info.Mem.Caching)
840 {
841 case ACPI_CACHABLE_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
842 case ACPI_WRITE_COMBINING_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
843 case ACPI_PREFETCHABLE_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
844 }
845 ResourceDescriptor->u.Memory.Start.QuadPart = addr32_data->Minimum;
846 ResourceDescriptor->u.Memory.Length = addr32_data->AddressLength;
847 }
848 ResourceDescriptor++;
849 break;
850 }
851 case ACPI_RESOURCE_TYPE_ADDRESS64:
852 {
853 ACPI_RESOURCE_ADDRESS64 *addr64_data = (ACPI_RESOURCE_ADDRESS64*) &resource->Data;
854 if (addr64_data->ResourceType == ACPI_BUS_NUMBER_RANGE)
855 {
856 DPRINT1("64-bit bus address is not supported!\n");
857 ResourceDescriptor->Type = CmResourceTypeBusNumber;
858 ResourceDescriptor->ShareDisposition = CmResourceShareShared;
859 ResourceDescriptor->Flags = 0;
860 ResourceDescriptor->u.BusNumber.Start = (ULONG)addr64_data->Minimum;
861 ResourceDescriptor->u.BusNumber.Length = addr64_data->AddressLength;
862 }
863 else if (addr64_data->ResourceType == ACPI_IO_RANGE)
864 {
865 ResourceDescriptor->Type = CmResourceTypePort;
866 ResourceDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
867 ResourceDescriptor->Flags = CM_RESOURCE_PORT_IO;
868 if (addr64_data->Decode == ACPI_POS_DECODE)
869 ResourceDescriptor->Flags |= CM_RESOURCE_PORT_POSITIVE_DECODE;
870 ResourceDescriptor->u.Port.Start.QuadPart = addr64_data->Minimum;
871 ResourceDescriptor->u.Port.Length = addr64_data->AddressLength;
872 }
873 else
874 {
875 ResourceDescriptor->Type = CmResourceTypeMemory;
876 ResourceDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
877 ResourceDescriptor->Flags = 0;
878 if (addr64_data->Info.Mem.WriteProtect == ACPI_READ_ONLY_MEMORY)
879 ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
880 else
881 ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
882 switch (addr64_data->Info.Mem.Caching)
883 {
884 case ACPI_CACHABLE_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
885 case ACPI_WRITE_COMBINING_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
886 case ACPI_PREFETCHABLE_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
887 }
888 ResourceDescriptor->u.Memory.Start.QuadPart = addr64_data->Minimum;
889 ResourceDescriptor->u.Memory.Length = addr64_data->AddressLength;
890 }
891 ResourceDescriptor++;
892 break;
893 }
894 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
895 {
896 ACPI_RESOURCE_EXTENDED_ADDRESS64 *addr64_data = (ACPI_RESOURCE_EXTENDED_ADDRESS64*) &resource->Data;
897 if (addr64_data->ResourceType == ACPI_BUS_NUMBER_RANGE)
898 {
899 DPRINT1("64-bit bus address is not supported!\n");
900 ResourceDescriptor->Type = CmResourceTypeBusNumber;
901 ResourceDescriptor->ShareDisposition = CmResourceShareShared;
902 ResourceDescriptor->Flags = 0;
903 ResourceDescriptor->u.BusNumber.Start = (ULONG)addr64_data->Minimum;
904 ResourceDescriptor->u.BusNumber.Length = addr64_data->AddressLength;
905 }
906 else if (addr64_data->ResourceType == ACPI_IO_RANGE)
907 {
908 ResourceDescriptor->Type = CmResourceTypePort;
909 ResourceDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
910 ResourceDescriptor->Flags = CM_RESOURCE_PORT_IO;
911 if (addr64_data->Decode == ACPI_POS_DECODE)
912 ResourceDescriptor->Flags |= CM_RESOURCE_PORT_POSITIVE_DECODE;
913 ResourceDescriptor->u.Port.Start.QuadPart = addr64_data->Minimum;
914 ResourceDescriptor->u.Port.Length = addr64_data->AddressLength;
915 }
916 else
917 {
918 ResourceDescriptor->Type = CmResourceTypeMemory;
919 ResourceDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
920 ResourceDescriptor->Flags = 0;
921 if (addr64_data->Info.Mem.WriteProtect == ACPI_READ_ONLY_MEMORY)
922 ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
923 else
924 ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
925 switch (addr64_data->Info.Mem.Caching)
926 {
927 case ACPI_CACHABLE_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
928 case ACPI_WRITE_COMBINING_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
929 case ACPI_PREFETCHABLE_MEMORY: ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
930 }
931 ResourceDescriptor->u.Memory.Start.QuadPart = addr64_data->Minimum;
932 ResourceDescriptor->u.Memory.Length = addr64_data->AddressLength;
933 }
934 ResourceDescriptor++;
935 break;
936 }
937 case ACPI_RESOURCE_TYPE_MEMORY24:
938 {
939 ACPI_RESOURCE_MEMORY24 *mem24_data = (ACPI_RESOURCE_MEMORY24*) &resource->Data;
940 ResourceDescriptor->Type = CmResourceTypeMemory;
941 ResourceDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
942 ResourceDescriptor->Flags = CM_RESOURCE_MEMORY_24;
943 if (mem24_data->WriteProtect == ACPI_READ_ONLY_MEMORY)
944 ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
945 else
946 ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
947 ResourceDescriptor->u.Memory.Start.QuadPart = mem24_data->Minimum;
948 ResourceDescriptor->u.Memory.Length = mem24_data->AddressLength;
949
950 ResourceDescriptor++;
951 break;
952 }
953 case ACPI_RESOURCE_TYPE_MEMORY32:
954 {
955 ACPI_RESOURCE_MEMORY32 *mem32_data = (ACPI_RESOURCE_MEMORY32*) &resource->Data;
956 ResourceDescriptor->Type = CmResourceTypeMemory;
957 ResourceDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
958 ResourceDescriptor->Flags = 0;
959 if (mem32_data->WriteProtect == ACPI_READ_ONLY_MEMORY)
960 ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
961 else
962 ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
963 ResourceDescriptor->u.Memory.Start.QuadPart = mem32_data->Minimum;
964 ResourceDescriptor->u.Memory.Length = mem32_data->AddressLength;
965
966 ResourceDescriptor++;
967 break;
968 }
969 default:
970 {
971 break;
972 }
973 }
974 resource = ACPI_NEXT_RESOURCE(resource);
975 }
976
977 ExFreePool(Buffer.Pointer);
978 Irp->IoStatus.Information = (ULONG_PTR)ResourceList;
979 return STATUS_SUCCESS;
980 }
981
982 NTSTATUS
983 Bus_PDO_QueryResourceRequirements(
984 PPDO_DEVICE_DATA DeviceData,
985 PIRP Irp )
986 {
987 ULONG NumberOfResources = 0;
988 ACPI_STATUS AcpiStatus;
989 ACPI_BUFFER Buffer;
990 ACPI_RESOURCE* resource;
991 ULONG i, RequirementsListSize;
992 PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
993 PIO_RESOURCE_DESCRIPTOR RequirementDescriptor;
994 BOOLEAN CurrentRes = FALSE;
995
996 PAGED_CODE ();
997
998
999 /* Get current resources */
1000 while (TRUE)
1001 {
1002 Buffer.Length = 0;
1003 if (CurrentRes)
1004 AcpiStatus = AcpiGetCurrentResources(DeviceData->AcpiHandle, &Buffer);
1005 else
1006 AcpiStatus = AcpiGetPossibleResources(DeviceData->AcpiHandle, &Buffer);
1007 if ((!ACPI_SUCCESS(AcpiStatus) && AcpiStatus != AE_BUFFER_OVERFLOW) ||
1008 Buffer.Length == 0)
1009 {
1010 if (!CurrentRes)
1011 CurrentRes = TRUE;
1012 else
1013 return Irp->IoStatus.Status;
1014 }
1015 else
1016 break;
1017 }
1018
1019 Buffer.Pointer = ExAllocatePool(PagedPool, Buffer.Length);
1020 if (!Buffer.Pointer)
1021 return STATUS_INSUFFICIENT_RESOURCES;
1022
1023 if (CurrentRes)
1024 AcpiStatus = AcpiGetCurrentResources(DeviceData->AcpiHandle, &Buffer);
1025 else
1026 AcpiStatus = AcpiGetPossibleResources(DeviceData->AcpiHandle, &Buffer);
1027 if (!ACPI_SUCCESS(AcpiStatus))
1028 {
1029 DPRINT1("AcpiGetCurrentResources #2 failed (0x%x)\n", AcpiStatus);
1030 ASSERT(FALSE);
1031 return STATUS_UNSUCCESSFUL;
1032 }
1033
1034 resource= Buffer.Pointer;
1035 /* Count number of resources */
1036 while (resource->Type != ACPI_RESOURCE_TYPE_END_TAG)
1037 {
1038 switch (resource->Type)
1039 {
1040 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
1041 {
1042 ACPI_RESOURCE_EXTENDED_IRQ *irq_data = (ACPI_RESOURCE_EXTENDED_IRQ*) &resource->Data;
1043 NumberOfResources += irq_data->InterruptCount;
1044 break;
1045 }
1046 case ACPI_RESOURCE_TYPE_IRQ:
1047 {
1048 ACPI_RESOURCE_IRQ *irq_data = (ACPI_RESOURCE_IRQ*) &resource->Data;
1049 NumberOfResources += irq_data->InterruptCount;
1050 break;
1051 }
1052 case ACPI_RESOURCE_TYPE_DMA:
1053 {
1054 ACPI_RESOURCE_DMA *dma_data = (ACPI_RESOURCE_DMA*) &resource->Data;
1055 NumberOfResources += dma_data->ChannelCount;
1056 break;
1057 }
1058 case ACPI_RESOURCE_TYPE_ADDRESS16:
1059 case ACPI_RESOURCE_TYPE_ADDRESS32:
1060 case ACPI_RESOURCE_TYPE_ADDRESS64:
1061 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
1062 case ACPI_RESOURCE_TYPE_MEMORY24:
1063 case ACPI_RESOURCE_TYPE_MEMORY32:
1064 case ACPI_RESOURCE_TYPE_IO:
1065 {
1066 NumberOfResources++;
1067 break;
1068 }
1069 default:
1070 {
1071 break;
1072 }
1073 }
1074 resource = ACPI_NEXT_RESOURCE(resource);
1075 }
1076
1077 RequirementsListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) + sizeof(IO_RESOURCE_DESCRIPTOR) * (NumberOfResources - 1);
1078 RequirementsList = (PIO_RESOURCE_REQUIREMENTS_LIST)ExAllocatePool(PagedPool, RequirementsListSize);
1079
1080 if (!RequirementsList)
1081 {
1082 ExFreePool(Buffer.Pointer);
1083 return STATUS_INSUFFICIENT_RESOURCES;
1084 }
1085 RequirementsList->ListSize = RequirementsListSize;
1086 RequirementsList->InterfaceType = Internal;
1087 RequirementsList->BusNumber = 0;
1088 RequirementsList->SlotNumber = 0; /* Not used by WDM drivers */
1089 RequirementsList->AlternativeLists = 1;
1090 RequirementsList->List[0].Version = 1;
1091 RequirementsList->List[0].Revision = 1;
1092 RequirementsList->List[0].Count = NumberOfResources;
1093 RequirementDescriptor = RequirementsList->List[0].Descriptors;
1094
1095 /* Fill resources list structure */
1096 while (resource->Type != ACPI_RESOURCE_TYPE_END_TAG)
1097 {
1098 switch (resource->Type)
1099 {
1100 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
1101 {
1102 ACPI_RESOURCE_EXTENDED_IRQ *irq_data = (ACPI_RESOURCE_EXTENDED_IRQ*) &resource->Data;
1103 for (i = 0; i < irq_data->InterruptCount; i++)
1104 {
1105 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1106 RequirementDescriptor->Type = CmResourceTypeInterrupt;
1107 RequirementDescriptor->ShareDisposition = (irq_data->Sharable == ACPI_SHARED ? CmResourceShareShared : CmResourceShareDeviceExclusive);
1108 RequirementDescriptor->Flags =(irq_data->Triggering == ACPI_LEVEL_SENSITIVE ? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE : CM_RESOURCE_INTERRUPT_LATCHED);
1109 RequirementDescriptor->u.Interrupt.MinimumVector =
1110 RequirementDescriptor->u.Interrupt.MaximumVector = irq_data->Interrupts[i];
1111
1112 RequirementDescriptor++;
1113 }
1114 break;
1115 }
1116 case ACPI_RESOURCE_TYPE_IRQ:
1117 {
1118 ACPI_RESOURCE_IRQ *irq_data = (ACPI_RESOURCE_IRQ*) &resource->Data;
1119 for (i = 0; i < irq_data->InterruptCount; i++)
1120 {
1121 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1122 RequirementDescriptor->Type = CmResourceTypeInterrupt;
1123 RequirementDescriptor->ShareDisposition = (irq_data->Sharable == ACPI_SHARED ? CmResourceShareShared : CmResourceShareDeviceExclusive);
1124 RequirementDescriptor->Flags =(irq_data->Triggering == ACPI_LEVEL_SENSITIVE ? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE : CM_RESOURCE_INTERRUPT_LATCHED);
1125 RequirementDescriptor->u.Interrupt.MinimumVector =
1126 RequirementDescriptor->u.Interrupt.MaximumVector = irq_data->Interrupts[i];
1127
1128 RequirementDescriptor++;
1129 }
1130 break;
1131 }
1132 case ACPI_RESOURCE_TYPE_DMA:
1133 {
1134 ACPI_RESOURCE_DMA *dma_data = (ACPI_RESOURCE_DMA*) &resource->Data;
1135 for (i = 0; i < dma_data->ChannelCount; i++)
1136 {
1137 RequirementDescriptor->Type = CmResourceTypeDma;
1138 RequirementDescriptor->Flags = 0;
1139 switch (dma_data->Type)
1140 {
1141 case ACPI_TYPE_A: RequirementDescriptor->Flags |= CM_RESOURCE_DMA_TYPE_A; break;
1142 case ACPI_TYPE_B: RequirementDescriptor->Flags |= CM_RESOURCE_DMA_TYPE_B; break;
1143 case ACPI_TYPE_F: RequirementDescriptor->Flags |= CM_RESOURCE_DMA_TYPE_F; break;
1144 }
1145 if (dma_data->BusMaster == ACPI_BUS_MASTER)
1146 RequirementDescriptor->Flags |= CM_RESOURCE_DMA_BUS_MASTER;
1147 switch (dma_data->Transfer)
1148 {
1149 case ACPI_TRANSFER_8: RequirementDescriptor->Flags |= CM_RESOURCE_DMA_8; break;
1150 case ACPI_TRANSFER_16: RequirementDescriptor->Flags |= CM_RESOURCE_DMA_16; break;
1151 case ACPI_TRANSFER_8_16: RequirementDescriptor->Flags |= CM_RESOURCE_DMA_8_AND_16; break;
1152 }
1153
1154 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1155 RequirementDescriptor->ShareDisposition = CmResourceShareDriverExclusive;
1156 RequirementDescriptor->u.Dma.MinimumChannel =
1157 RequirementDescriptor->u.Dma.MaximumChannel = dma_data->Channels[i];
1158 RequirementDescriptor++;
1159 }
1160 break;
1161 }
1162 case ACPI_RESOURCE_TYPE_IO:
1163 {
1164 ACPI_RESOURCE_IO *io_data = (ACPI_RESOURCE_IO*) &resource->Data;
1165 RequirementDescriptor->Flags = CM_RESOURCE_PORT_IO;
1166 if (io_data->IoDecode == ACPI_DECODE_16)
1167 RequirementDescriptor->Flags |= CM_RESOURCE_PORT_16_BIT_DECODE;
1168 else
1169 RequirementDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE;
1170 RequirementDescriptor->u.Port.Length = io_data->AddressLength;
1171 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1172 RequirementDescriptor->Type = CmResourceTypePort;
1173 RequirementDescriptor->ShareDisposition = CmResourceShareDriverExclusive;
1174 RequirementDescriptor->u.Port.Alignment = io_data->Alignment;
1175 RequirementDescriptor->u.Port.MinimumAddress.QuadPart = io_data->Minimum;
1176 RequirementDescriptor->u.Port.MaximumAddress.QuadPart = io_data->Maximum;
1177
1178 RequirementDescriptor++;
1179 break;
1180 }
1181 case ACPI_RESOURCE_TYPE_ADDRESS16:
1182 {
1183 ACPI_RESOURCE_ADDRESS16 *addr16_data = (ACPI_RESOURCE_ADDRESS16*) &resource->Data;
1184 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1185 if (addr16_data->ResourceType == ACPI_BUS_NUMBER_RANGE)
1186 {
1187 RequirementDescriptor->Type = CmResourceTypeBusNumber;
1188 RequirementDescriptor->ShareDisposition = CmResourceShareShared;
1189 RequirementDescriptor->Flags = 0;
1190 RequirementDescriptor->u.BusNumber.MinBusNumber = addr16_data->Minimum;
1191 RequirementDescriptor->u.BusNumber.MaxBusNumber = addr16_data->Maximum;
1192 RequirementDescriptor->u.BusNumber.Length = addr16_data->AddressLength;
1193 }
1194 else if (addr16_data->ResourceType == ACPI_IO_RANGE)
1195 {
1196 RequirementDescriptor->Type = CmResourceTypePort;
1197 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1198 RequirementDescriptor->Flags = CM_RESOURCE_PORT_IO;
1199 if (addr16_data->Decode == ACPI_POS_DECODE)
1200 RequirementDescriptor->Flags |= CM_RESOURCE_PORT_POSITIVE_DECODE;
1201 RequirementDescriptor->u.Port.MinimumAddress.QuadPart = addr16_data->Minimum;
1202 RequirementDescriptor->u.Port.MaximumAddress.QuadPart = addr16_data->Maximum;
1203 RequirementDescriptor->u.Port.Length = addr16_data->AddressLength;
1204 }
1205 else
1206 {
1207 RequirementDescriptor->Type = CmResourceTypeMemory;
1208 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1209 RequirementDescriptor->Flags = 0;
1210 if (addr16_data->Info.Mem.WriteProtect == ACPI_READ_ONLY_MEMORY)
1211 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
1212 else
1213 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
1214 switch (addr16_data->Info.Mem.Caching)
1215 {
1216 case ACPI_CACHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
1217 case ACPI_WRITE_COMBINING_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
1218 case ACPI_PREFETCHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
1219 }
1220 RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = addr16_data->Minimum;
1221 RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = addr16_data->Maximum;
1222 RequirementDescriptor->u.Memory.Length = addr16_data->AddressLength;
1223 }
1224 RequirementDescriptor++;
1225 break;
1226 }
1227 case ACPI_RESOURCE_TYPE_ADDRESS32:
1228 {
1229 ACPI_RESOURCE_ADDRESS32 *addr32_data = (ACPI_RESOURCE_ADDRESS32*) &resource->Data;
1230 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1231 if (addr32_data->ResourceType == ACPI_BUS_NUMBER_RANGE)
1232 {
1233 RequirementDescriptor->Type = CmResourceTypeBusNumber;
1234 RequirementDescriptor->ShareDisposition = CmResourceShareShared;
1235 RequirementDescriptor->Flags = 0;
1236 RequirementDescriptor->u.BusNumber.MinBusNumber = addr32_data->Minimum;
1237 RequirementDescriptor->u.BusNumber.MaxBusNumber = addr32_data->Maximum;
1238 RequirementDescriptor->u.BusNumber.Length = addr32_data->AddressLength;
1239 }
1240 else if (addr32_data->ResourceType == ACPI_IO_RANGE)
1241 {
1242 RequirementDescriptor->Type = CmResourceTypePort;
1243 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1244 RequirementDescriptor->Flags = CM_RESOURCE_PORT_IO;
1245 if (addr32_data->Decode == ACPI_POS_DECODE)
1246 RequirementDescriptor->Flags |= CM_RESOURCE_PORT_POSITIVE_DECODE;
1247 RequirementDescriptor->u.Port.MinimumAddress.QuadPart = addr32_data->Minimum;
1248 RequirementDescriptor->u.Port.MaximumAddress.QuadPart = addr32_data->Maximum;
1249 RequirementDescriptor->u.Port.Length = addr32_data->AddressLength;
1250 }
1251 else
1252 {
1253 RequirementDescriptor->Type = CmResourceTypeMemory;
1254 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1255 RequirementDescriptor->Flags = 0;
1256 if (addr32_data->Info.Mem.WriteProtect == ACPI_READ_ONLY_MEMORY)
1257 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
1258 else
1259 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
1260 switch (addr32_data->Info.Mem.Caching)
1261 {
1262 case ACPI_CACHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
1263 case ACPI_WRITE_COMBINING_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
1264 case ACPI_PREFETCHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
1265 }
1266 RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = addr32_data->Minimum;
1267 RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = addr32_data->Maximum;
1268 RequirementDescriptor->u.Memory.Length = addr32_data->AddressLength;
1269 }
1270 RequirementDescriptor++;
1271 break;
1272 }
1273 case ACPI_RESOURCE_TYPE_ADDRESS64:
1274 {
1275 ACPI_RESOURCE_ADDRESS64 *addr64_data = (ACPI_RESOURCE_ADDRESS64*) &resource->Data;
1276 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1277 if (addr64_data->ResourceType == ACPI_BUS_NUMBER_RANGE)
1278 {
1279 DPRINT1("64-bit bus address is not supported!\n");
1280 RequirementDescriptor->Type = CmResourceTypeBusNumber;
1281 RequirementDescriptor->ShareDisposition = CmResourceShareShared;
1282 RequirementDescriptor->Flags = 0;
1283 RequirementDescriptor->u.BusNumber.MinBusNumber = (ULONG)addr64_data->Minimum;
1284 RequirementDescriptor->u.BusNumber.MaxBusNumber = (ULONG)addr64_data->Maximum;
1285 RequirementDescriptor->u.BusNumber.Length = addr64_data->AddressLength;
1286 }
1287 else if (addr64_data->ResourceType == ACPI_IO_RANGE)
1288 {
1289 RequirementDescriptor->Type = CmResourceTypePort;
1290 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1291 RequirementDescriptor->Flags = CM_RESOURCE_PORT_IO;
1292 if (addr64_data->Decode == ACPI_POS_DECODE)
1293 RequirementDescriptor->Flags |= CM_RESOURCE_PORT_POSITIVE_DECODE;
1294 RequirementDescriptor->u.Port.MinimumAddress.QuadPart = addr64_data->Minimum;
1295 RequirementDescriptor->u.Port.MaximumAddress.QuadPart = addr64_data->Maximum;
1296 RequirementDescriptor->u.Port.Length = addr64_data->AddressLength;
1297 }
1298 else
1299 {
1300 RequirementDescriptor->Type = CmResourceTypeMemory;
1301 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1302 RequirementDescriptor->Flags = 0;
1303 if (addr64_data->Info.Mem.WriteProtect == ACPI_READ_ONLY_MEMORY)
1304 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
1305 else
1306 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
1307 switch (addr64_data->Info.Mem.Caching)
1308 {
1309 case ACPI_CACHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
1310 case ACPI_WRITE_COMBINING_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
1311 case ACPI_PREFETCHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
1312 }
1313 RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = addr64_data->Minimum;
1314 RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = addr64_data->Maximum;
1315 RequirementDescriptor->u.Memory.Length = addr64_data->AddressLength;
1316 }
1317 RequirementDescriptor++;
1318 break;
1319 }
1320 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
1321 {
1322 ACPI_RESOURCE_EXTENDED_ADDRESS64 *addr64_data = (ACPI_RESOURCE_EXTENDED_ADDRESS64*) &resource->Data;
1323 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1324 if (addr64_data->ResourceType == ACPI_BUS_NUMBER_RANGE)
1325 {
1326 DPRINT1("64-bit bus address is not supported!\n");
1327 RequirementDescriptor->Type = CmResourceTypeBusNumber;
1328 RequirementDescriptor->ShareDisposition = CmResourceShareShared;
1329 RequirementDescriptor->Flags = 0;
1330 RequirementDescriptor->u.BusNumber.MinBusNumber = (ULONG)addr64_data->Minimum;
1331 RequirementDescriptor->u.BusNumber.MaxBusNumber = (ULONG)addr64_data->Maximum;
1332 RequirementDescriptor->u.BusNumber.Length = addr64_data->AddressLength;
1333 }
1334 else if (addr64_data->ResourceType == ACPI_IO_RANGE)
1335 {
1336 RequirementDescriptor->Type = CmResourceTypePort;
1337 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1338 RequirementDescriptor->Flags = CM_RESOURCE_PORT_IO;
1339 if (addr64_data->Decode == ACPI_POS_DECODE)
1340 RequirementDescriptor->Flags |= CM_RESOURCE_PORT_POSITIVE_DECODE;
1341 RequirementDescriptor->u.Port.MinimumAddress.QuadPart = addr64_data->Minimum;
1342 RequirementDescriptor->u.Port.MaximumAddress.QuadPart = addr64_data->Maximum;
1343 RequirementDescriptor->u.Port.Length = addr64_data->AddressLength;
1344 }
1345 else
1346 {
1347 RequirementDescriptor->Type = CmResourceTypeMemory;
1348 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1349 RequirementDescriptor->Flags = 0;
1350 if (addr64_data->Info.Mem.WriteProtect == ACPI_READ_ONLY_MEMORY)
1351 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
1352 else
1353 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
1354 switch (addr64_data->Info.Mem.Caching)
1355 {
1356 case ACPI_CACHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
1357 case ACPI_WRITE_COMBINING_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
1358 case ACPI_PREFETCHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
1359 }
1360 RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = addr64_data->Minimum;
1361 RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = addr64_data->Maximum;
1362 RequirementDescriptor->u.Memory.Length = addr64_data->AddressLength;
1363 }
1364 RequirementDescriptor++;
1365 break;
1366 }
1367 case ACPI_RESOURCE_TYPE_MEMORY24:
1368 {
1369 ACPI_RESOURCE_MEMORY24 *mem24_data = (ACPI_RESOURCE_MEMORY24*) &resource->Data;
1370 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1371 RequirementDescriptor->Type = CmResourceTypeMemory;
1372 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1373 RequirementDescriptor->Flags = CM_RESOURCE_MEMORY_24;
1374 if (mem24_data->WriteProtect == ACPI_READ_ONLY_MEMORY)
1375 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
1376 else
1377 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
1378 RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = mem24_data->Minimum;
1379 RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = mem24_data->Maximum;
1380 RequirementDescriptor->u.Memory.Length = mem24_data->AddressLength;
1381
1382 RequirementDescriptor++;
1383 break;
1384 }
1385 case ACPI_RESOURCE_TYPE_MEMORY32:
1386 {
1387 ACPI_RESOURCE_MEMORY32 *mem32_data = (ACPI_RESOURCE_MEMORY32*) &resource->Data;
1388 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1389 RequirementDescriptor->Type = CmResourceTypeMemory;
1390 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1391 RequirementDescriptor->Flags = 0;
1392 if (mem32_data->WriteProtect == ACPI_READ_ONLY_MEMORY)
1393 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
1394 else
1395 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
1396 RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = mem32_data->Minimum;
1397 RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = mem32_data->Maximum;
1398 RequirementDescriptor->u.Memory.Length = mem32_data->AddressLength;
1399
1400 RequirementDescriptor++;
1401 break;
1402 }
1403 default:
1404 {
1405 break;
1406 }
1407 }
1408 resource = ACPI_NEXT_RESOURCE(resource);
1409 }
1410 ExFreePool(Buffer.Pointer);
1411
1412 Irp->IoStatus.Information = (ULONG_PTR)RequirementsList;
1413
1414 return STATUS_SUCCESS;
1415 }
1416
1417 NTSTATUS
1418 Bus_PDO_QueryDeviceRelations(
1419 PPDO_DEVICE_DATA DeviceData,
1420 PIRP Irp )
1421 /*++
1422
1423 Routine Description:
1424
1425 The PnP Manager sends this IRP to gather information about
1426 devices with a relationship to the specified device.
1427 Bus drivers must handle this request for TargetDeviceRelation
1428 for their child devices (child PDOs).
1429
1430 If a driver returns relations in response to this IRP,
1431 it allocates a DEVICE_RELATIONS structure from paged
1432 memory containing a count and the appropriate number of
1433 device object pointers. The PnP Manager frees the structure
1434 when it is no longer needed. If a driver replaces a
1435 DEVICE_RELATIONS structure allocated by another driver,
1436 it must free the previous structure.
1437
1438 A driver must reference the PDO of any device that it
1439 reports in this IRP (ObReferenceObject). The PnP Manager
1440 removes the reference when appropriate.
1441
1442 Arguments:
1443
1444 DeviceData - Pointer to the PDO's device extension.
1445 Irp - Pointer to the irp.
1446
1447 Return Value:
1448
1449 NT STATUS
1450
1451 --*/
1452 {
1453
1454 PIO_STACK_LOCATION stack;
1455 PDEVICE_RELATIONS deviceRelations;
1456 NTSTATUS status;
1457
1458 PAGED_CODE ();
1459
1460 stack = IoGetCurrentIrpStackLocation (Irp);
1461
1462 switch (stack->Parameters.QueryDeviceRelations.Type) {
1463
1464 case TargetDeviceRelation:
1465
1466 deviceRelations = (PDEVICE_RELATIONS) Irp->IoStatus.Information;
1467 if (deviceRelations) {
1468 //
1469 // Only PDO can handle this request. Somebody above
1470 // is not playing by rule.
1471 //
1472 ASSERTMSG("Someone above is handling TargetDeviceRelation", !deviceRelations);
1473 }
1474
1475 deviceRelations = (PDEVICE_RELATIONS)
1476 ExAllocatePoolWithTag (PagedPool,
1477 sizeof(DEVICE_RELATIONS),
1478 'IPCA');
1479 if (!deviceRelations) {
1480 status = STATUS_INSUFFICIENT_RESOURCES;
1481 break;
1482 }
1483
1484 //
1485 // There is only one PDO pointer in the structure
1486 // for this relation type. The PnP Manager removes
1487 // the reference to the PDO when the driver or application
1488 // un-registers for notification on the device.
1489 //
1490
1491 deviceRelations->Count = 1;
1492 deviceRelations->Objects[0] = DeviceData->Common.Self;
1493 ObReferenceObject(DeviceData->Common.Self);
1494
1495 status = STATUS_SUCCESS;
1496 Irp->IoStatus.Information = (ULONG_PTR) deviceRelations;
1497 break;
1498
1499 case BusRelations: // Not handled by PDO
1500 case EjectionRelations: // optional for PDO
1501 case RemovalRelations: // // optional for PDO
1502 default:
1503 status = Irp->IoStatus.Status;
1504 }
1505
1506 return status;
1507 }
1508
1509 NTSTATUS
1510 Bus_PDO_QueryBusInformation(
1511 PPDO_DEVICE_DATA DeviceData,
1512 PIRP Irp )
1513 /*++
1514
1515 Routine Description:
1516
1517 The PnP Manager uses this IRP to request the type and
1518 instance number of a device's parent bus. Bus drivers
1519 should handle this request for their child devices (PDOs).
1520
1521 Arguments:
1522
1523 DeviceData - Pointer to the PDO's device extension.
1524 Irp - Pointer to the irp.
1525
1526 Return Value:
1527
1528 NT STATUS
1529
1530 --*/
1531 {
1532
1533 PPNP_BUS_INFORMATION busInfo;
1534
1535 PAGED_CODE ();
1536
1537 busInfo = ExAllocatePoolWithTag (PagedPool, sizeof(PNP_BUS_INFORMATION),
1538 'IPCA');
1539
1540 if (busInfo == NULL) {
1541 return STATUS_INSUFFICIENT_RESOURCES;
1542 }
1543
1544 busInfo->BusTypeGuid = GUID_ACPI_INTERFACE_STANDARD;
1545
1546 busInfo->LegacyBusType = InternalPowerBus;
1547
1548 busInfo->BusNumber = 0; //fixme
1549
1550 Irp->IoStatus.Information = (ULONG_PTR)busInfo;
1551
1552 return STATUS_SUCCESS;
1553 }
1554
1555
1556 NTSTATUS
1557 Bus_GetDeviceCapabilities(
1558 PDEVICE_OBJECT DeviceObject,
1559 PDEVICE_CAPABILITIES DeviceCapabilities
1560 )
1561 {
1562 IO_STATUS_BLOCK ioStatus;
1563 KEVENT pnpEvent;
1564 NTSTATUS status;
1565 PDEVICE_OBJECT targetObject;
1566 PIO_STACK_LOCATION irpStack;
1567 PIRP pnpIrp;
1568
1569 PAGED_CODE();
1570
1571 //
1572 // Initialize the capabilities that we will send down
1573 //
1574 RtlZeroMemory( DeviceCapabilities, sizeof(DEVICE_CAPABILITIES) );
1575 DeviceCapabilities->Size = sizeof(DEVICE_CAPABILITIES);
1576 DeviceCapabilities->Version = 1;
1577 DeviceCapabilities->Address = -1;
1578 DeviceCapabilities->UINumber = -1;
1579
1580 //
1581 // Initialize the event
1582 //
1583 KeInitializeEvent( &pnpEvent, NotificationEvent, FALSE );
1584
1585 targetObject = IoGetAttachedDeviceReference( DeviceObject );
1586
1587 //
1588 // Build an Irp
1589 //
1590 pnpIrp = IoBuildSynchronousFsdRequest(
1591 IRP_MJ_PNP,
1592 targetObject,
1593 NULL,
1594 0,
1595 NULL,
1596 &pnpEvent,
1597 &ioStatus
1598 );
1599 if (pnpIrp == NULL) {
1600
1601 status = STATUS_INSUFFICIENT_RESOURCES;
1602 goto GetDeviceCapabilitiesExit;
1603
1604 }
1605
1606 //
1607 // Pnp Irps all begin life as STATUS_NOT_SUPPORTED;
1608 //
1609 pnpIrp->IoStatus.Status = STATUS_NOT_SUPPORTED;
1610
1611 //
1612 // Get the top of stack
1613 //
1614 irpStack = IoGetNextIrpStackLocation( pnpIrp );
1615
1616 //
1617 // Set the top of stack
1618 //
1619 RtlZeroMemory( irpStack, sizeof(IO_STACK_LOCATION ) );
1620 irpStack->MajorFunction = IRP_MJ_PNP;
1621 irpStack->MinorFunction = IRP_MN_QUERY_CAPABILITIES;
1622 irpStack->Parameters.DeviceCapabilities.Capabilities = DeviceCapabilities;
1623
1624 //
1625 // Call the driver
1626 //
1627 status = IoCallDriver( targetObject, pnpIrp );
1628 if (status == STATUS_PENDING) {
1629
1630 //
1631 // Block until the irp comes back.
1632 // Important thing to note here is when you allocate
1633 // the memory for an event in the stack you must do a
1634 // KernelMode wait instead of UserMode to prevent
1635 // the stack from getting paged out.
1636 //
1637
1638 KeWaitForSingleObject(
1639 &pnpEvent,
1640 Executive,
1641 KernelMode,
1642 FALSE,
1643 NULL
1644 );
1645 status = ioStatus.Status;
1646
1647 }
1648
1649 GetDeviceCapabilitiesExit:
1650 //
1651 // Done with reference
1652 //
1653 ObDereferenceObject( targetObject );
1654
1655 //
1656 // Done
1657 //
1658 return status;
1659
1660 }
1661
1662