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