[USB]
[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 /* Handle the PCI root manually */
1140 if (wcsstr(DeviceData->HardwareIDs, L"PNP0A03") != 0)
1141 {
1142 return Irp->IoStatus.Status;
1143 }
1144
1145 /* Get current resources */
1146 while (TRUE)
1147 {
1148 Buffer.Length = 0;
1149 if (CurrentRes)
1150 AcpiStatus = AcpiGetCurrentResources(DeviceData->AcpiHandle, &Buffer);
1151 else
1152 AcpiStatus = AcpiGetPossibleResources(DeviceData->AcpiHandle, &Buffer);
1153 if ((!ACPI_SUCCESS(AcpiStatus) && AcpiStatus != AE_BUFFER_OVERFLOW) ||
1154 Buffer.Length == 0)
1155 {
1156 if (!CurrentRes)
1157 CurrentRes = TRUE;
1158 else
1159 return Irp->IoStatus.Status;
1160 }
1161 else
1162 break;
1163 }
1164
1165 Buffer.Pointer = ExAllocatePoolWithTag(PagedPool, Buffer.Length, 'IPCA');
1166 if (!Buffer.Pointer)
1167 return STATUS_INSUFFICIENT_RESOURCES;
1168
1169 if (CurrentRes)
1170 AcpiStatus = AcpiGetCurrentResources(DeviceData->AcpiHandle, &Buffer);
1171 else
1172 AcpiStatus = AcpiGetPossibleResources(DeviceData->AcpiHandle, &Buffer);
1173 if (!ACPI_SUCCESS(AcpiStatus))
1174 {
1175 DPRINT1("AcpiGetCurrentResources #2 failed (0x%x)\n", AcpiStatus);
1176 ASSERT(FALSE);
1177 return STATUS_UNSUCCESSFUL;
1178 }
1179
1180 resource= Buffer.Pointer;
1181 /* Count number of resources */
1182 while (resource->Type != ACPI_RESOURCE_TYPE_END_TAG)
1183 {
1184 switch (resource->Type)
1185 {
1186 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
1187 {
1188 ACPI_RESOURCE_EXTENDED_IRQ *irq_data = (ACPI_RESOURCE_EXTENDED_IRQ*) &resource->Data;
1189 NumberOfResources += irq_data->InterruptCount;
1190 break;
1191 }
1192 case ACPI_RESOURCE_TYPE_IRQ:
1193 {
1194 ACPI_RESOURCE_IRQ *irq_data = (ACPI_RESOURCE_IRQ*) &resource->Data;
1195 NumberOfResources += irq_data->InterruptCount;
1196 break;
1197 }
1198 case ACPI_RESOURCE_TYPE_DMA:
1199 {
1200 ACPI_RESOURCE_DMA *dma_data = (ACPI_RESOURCE_DMA*) &resource->Data;
1201 NumberOfResources += dma_data->ChannelCount;
1202 break;
1203 }
1204 case ACPI_RESOURCE_TYPE_ADDRESS16:
1205 case ACPI_RESOURCE_TYPE_ADDRESS32:
1206 case ACPI_RESOURCE_TYPE_ADDRESS64:
1207 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
1208 case ACPI_RESOURCE_TYPE_MEMORY24:
1209 case ACPI_RESOURCE_TYPE_MEMORY32:
1210 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
1211 case ACPI_RESOURCE_TYPE_IO:
1212 {
1213 NumberOfResources++;
1214 break;
1215 }
1216 default:
1217 {
1218 break;
1219 }
1220 }
1221 resource = ACPI_NEXT_RESOURCE(resource);
1222 }
1223
1224 RequirementsListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) + sizeof(IO_RESOURCE_DESCRIPTOR) * (NumberOfResources - 1);
1225 RequirementsList = (PIO_RESOURCE_REQUIREMENTS_LIST)ExAllocatePoolWithTag(PagedPool, RequirementsListSize, 'IPCA');
1226
1227 if (!RequirementsList)
1228 {
1229 ExFreePoolWithTag(Buffer.Pointer, 'IPCA');
1230 return STATUS_INSUFFICIENT_RESOURCES;
1231 }
1232 RequirementsList->ListSize = RequirementsListSize;
1233 RequirementsList->InterfaceType = Internal;
1234 RequirementsList->BusNumber = 0;
1235 RequirementsList->SlotNumber = 0; /* Not used by WDM drivers */
1236 RequirementsList->AlternativeLists = 1;
1237 RequirementsList->List[0].Version = 1;
1238 RequirementsList->List[0].Revision = 1;
1239 RequirementsList->List[0].Count = NumberOfResources;
1240 RequirementDescriptor = RequirementsList->List[0].Descriptors;
1241
1242 /* Fill resources list structure */
1243 resource = Buffer.Pointer;
1244 while (resource->Type != ACPI_RESOURCE_TYPE_END_TAG)
1245 {
1246 switch (resource->Type)
1247 {
1248 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
1249 {
1250 ACPI_RESOURCE_EXTENDED_IRQ *irq_data = (ACPI_RESOURCE_EXTENDED_IRQ*) &resource->Data;
1251 for (i = 0; i < irq_data->InterruptCount; i++)
1252 {
1253 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1254 RequirementDescriptor->Type = CmResourceTypeInterrupt;
1255 RequirementDescriptor->ShareDisposition = (irq_data->Sharable == ACPI_SHARED ? CmResourceShareShared : CmResourceShareDeviceExclusive);
1256 RequirementDescriptor->Flags =(irq_data->Triggering == ACPI_LEVEL_SENSITIVE ? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE : CM_RESOURCE_INTERRUPT_LATCHED);
1257 RequirementDescriptor->u.Interrupt.MinimumVector =
1258 RequirementDescriptor->u.Interrupt.MaximumVector = irq_data->Interrupts[i];
1259
1260 RequirementDescriptor++;
1261 }
1262 break;
1263 }
1264 case ACPI_RESOURCE_TYPE_IRQ:
1265 {
1266 ACPI_RESOURCE_IRQ *irq_data = (ACPI_RESOURCE_IRQ*) &resource->Data;
1267 for (i = 0; i < irq_data->InterruptCount; i++)
1268 {
1269 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1270 RequirementDescriptor->Type = CmResourceTypeInterrupt;
1271 RequirementDescriptor->ShareDisposition = (irq_data->Sharable == ACPI_SHARED ? CmResourceShareShared : CmResourceShareDeviceExclusive);
1272 RequirementDescriptor->Flags =(irq_data->Triggering == ACPI_LEVEL_SENSITIVE ? CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE : CM_RESOURCE_INTERRUPT_LATCHED);
1273 RequirementDescriptor->u.Interrupt.MinimumVector =
1274 RequirementDescriptor->u.Interrupt.MaximumVector = irq_data->Interrupts[i];
1275
1276 RequirementDescriptor++;
1277 }
1278 break;
1279 }
1280 case ACPI_RESOURCE_TYPE_DMA:
1281 {
1282 ACPI_RESOURCE_DMA *dma_data = (ACPI_RESOURCE_DMA*) &resource->Data;
1283 for (i = 0; i < dma_data->ChannelCount; i++)
1284 {
1285 RequirementDescriptor->Type = CmResourceTypeDma;
1286 RequirementDescriptor->Flags = 0;
1287 switch (dma_data->Type)
1288 {
1289 case ACPI_TYPE_A: RequirementDescriptor->Flags |= CM_RESOURCE_DMA_TYPE_A; break;
1290 case ACPI_TYPE_B: RequirementDescriptor->Flags |= CM_RESOURCE_DMA_TYPE_B; break;
1291 case ACPI_TYPE_F: RequirementDescriptor->Flags |= CM_RESOURCE_DMA_TYPE_F; break;
1292 }
1293 if (dma_data->BusMaster == ACPI_BUS_MASTER)
1294 RequirementDescriptor->Flags |= CM_RESOURCE_DMA_BUS_MASTER;
1295 switch (dma_data->Transfer)
1296 {
1297 case ACPI_TRANSFER_8: RequirementDescriptor->Flags |= CM_RESOURCE_DMA_8; break;
1298 case ACPI_TRANSFER_16: RequirementDescriptor->Flags |= CM_RESOURCE_DMA_16; break;
1299 case ACPI_TRANSFER_8_16: RequirementDescriptor->Flags |= CM_RESOURCE_DMA_8_AND_16; break;
1300 }
1301
1302 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1303 RequirementDescriptor->ShareDisposition = CmResourceShareDriverExclusive;
1304 RequirementDescriptor->u.Dma.MinimumChannel =
1305 RequirementDescriptor->u.Dma.MaximumChannel = dma_data->Channels[i];
1306 RequirementDescriptor++;
1307 }
1308 break;
1309 }
1310 case ACPI_RESOURCE_TYPE_IO:
1311 {
1312 ACPI_RESOURCE_IO *io_data = (ACPI_RESOURCE_IO*) &resource->Data;
1313 RequirementDescriptor->Flags = CM_RESOURCE_PORT_IO;
1314 if (io_data->IoDecode == ACPI_DECODE_16)
1315 RequirementDescriptor->Flags |= CM_RESOURCE_PORT_16_BIT_DECODE;
1316 else
1317 RequirementDescriptor->Flags |= CM_RESOURCE_PORT_10_BIT_DECODE;
1318 RequirementDescriptor->u.Port.Length = io_data->AddressLength;
1319 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1320 RequirementDescriptor->Type = CmResourceTypePort;
1321 RequirementDescriptor->ShareDisposition = CmResourceShareDriverExclusive;
1322 RequirementDescriptor->u.Port.Alignment = io_data->Alignment;
1323 RequirementDescriptor->u.Port.MinimumAddress.QuadPart = io_data->Minimum;
1324 RequirementDescriptor->u.Port.MaximumAddress.QuadPart = io_data->Maximum + io_data->AddressLength - 1;
1325
1326 RequirementDescriptor++;
1327 break;
1328 }
1329 case ACPI_RESOURCE_TYPE_ADDRESS16:
1330 {
1331 ACPI_RESOURCE_ADDRESS16 *addr16_data = (ACPI_RESOURCE_ADDRESS16*) &resource->Data;
1332 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1333 if (addr16_data->ResourceType == ACPI_BUS_NUMBER_RANGE)
1334 {
1335 RequirementDescriptor->Type = CmResourceTypeBusNumber;
1336 RequirementDescriptor->ShareDisposition = CmResourceShareShared;
1337 RequirementDescriptor->Flags = 0;
1338 RequirementDescriptor->u.BusNumber.MinBusNumber = addr16_data->Minimum;
1339 RequirementDescriptor->u.BusNumber.MaxBusNumber = addr16_data->Maximum + addr16_data->AddressLength - 1;
1340 RequirementDescriptor->u.BusNumber.Length = addr16_data->AddressLength;
1341 }
1342 else if (addr16_data->ResourceType == ACPI_IO_RANGE)
1343 {
1344 RequirementDescriptor->Type = CmResourceTypePort;
1345 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1346 RequirementDescriptor->Flags = CM_RESOURCE_PORT_IO;
1347 if (addr16_data->Decode == ACPI_POS_DECODE)
1348 RequirementDescriptor->Flags |= CM_RESOURCE_PORT_POSITIVE_DECODE;
1349 RequirementDescriptor->u.Port.MinimumAddress.QuadPart = addr16_data->Minimum;
1350 RequirementDescriptor->u.Port.MaximumAddress.QuadPart = addr16_data->Maximum + addr16_data->AddressLength - 1;
1351 RequirementDescriptor->u.Port.Length = addr16_data->AddressLength;
1352 }
1353 else
1354 {
1355 RequirementDescriptor->Type = CmResourceTypeMemory;
1356 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1357 RequirementDescriptor->Flags = 0;
1358 if (addr16_data->Info.Mem.WriteProtect == ACPI_READ_ONLY_MEMORY)
1359 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
1360 else
1361 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
1362 switch (addr16_data->Info.Mem.Caching)
1363 {
1364 case ACPI_CACHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
1365 case ACPI_WRITE_COMBINING_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
1366 case ACPI_PREFETCHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
1367 }
1368 RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = addr16_data->Minimum;
1369 RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = addr16_data->Maximum + addr16_data->AddressLength - 1;
1370 RequirementDescriptor->u.Memory.Length = addr16_data->AddressLength;
1371 }
1372 RequirementDescriptor++;
1373 break;
1374 }
1375 case ACPI_RESOURCE_TYPE_ADDRESS32:
1376 {
1377 ACPI_RESOURCE_ADDRESS32 *addr32_data = (ACPI_RESOURCE_ADDRESS32*) &resource->Data;
1378 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1379 if (addr32_data->ResourceType == ACPI_BUS_NUMBER_RANGE)
1380 {
1381 RequirementDescriptor->Type = CmResourceTypeBusNumber;
1382 RequirementDescriptor->ShareDisposition = CmResourceShareShared;
1383 RequirementDescriptor->Flags = 0;
1384 RequirementDescriptor->u.BusNumber.MinBusNumber = addr32_data->Minimum;
1385 RequirementDescriptor->u.BusNumber.MaxBusNumber = addr32_data->Maximum + addr32_data->AddressLength - 1;
1386 RequirementDescriptor->u.BusNumber.Length = addr32_data->AddressLength;
1387 }
1388 else if (addr32_data->ResourceType == ACPI_IO_RANGE)
1389 {
1390 RequirementDescriptor->Type = CmResourceTypePort;
1391 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1392 RequirementDescriptor->Flags = CM_RESOURCE_PORT_IO;
1393 if (addr32_data->Decode == ACPI_POS_DECODE)
1394 RequirementDescriptor->Flags |= CM_RESOURCE_PORT_POSITIVE_DECODE;
1395 RequirementDescriptor->u.Port.MinimumAddress.QuadPart = addr32_data->Minimum;
1396 RequirementDescriptor->u.Port.MaximumAddress.QuadPart = addr32_data->Maximum + addr32_data->AddressLength - 1;
1397 RequirementDescriptor->u.Port.Length = addr32_data->AddressLength;
1398 }
1399 else
1400 {
1401 RequirementDescriptor->Type = CmResourceTypeMemory;
1402 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1403 RequirementDescriptor->Flags = 0;
1404 if (addr32_data->Info.Mem.WriteProtect == ACPI_READ_ONLY_MEMORY)
1405 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
1406 else
1407 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
1408 switch (addr32_data->Info.Mem.Caching)
1409 {
1410 case ACPI_CACHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
1411 case ACPI_WRITE_COMBINING_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
1412 case ACPI_PREFETCHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
1413 }
1414 RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = addr32_data->Minimum;
1415 RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = addr32_data->Maximum + addr32_data->AddressLength - 1;
1416 RequirementDescriptor->u.Memory.Length = addr32_data->AddressLength;
1417 }
1418 RequirementDescriptor++;
1419 break;
1420 }
1421 case ACPI_RESOURCE_TYPE_ADDRESS64:
1422 {
1423 ACPI_RESOURCE_ADDRESS64 *addr64_data = (ACPI_RESOURCE_ADDRESS64*) &resource->Data;
1424 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1425 if (addr64_data->ResourceType == ACPI_BUS_NUMBER_RANGE)
1426 {
1427 DPRINT1("64-bit bus address is not supported!\n");
1428 RequirementDescriptor->Type = CmResourceTypeBusNumber;
1429 RequirementDescriptor->ShareDisposition = CmResourceShareShared;
1430 RequirementDescriptor->Flags = 0;
1431 RequirementDescriptor->u.BusNumber.MinBusNumber = (ULONG)addr64_data->Minimum;
1432 RequirementDescriptor->u.BusNumber.MaxBusNumber = (ULONG)addr64_data->Maximum + addr64_data->AddressLength - 1;
1433 RequirementDescriptor->u.BusNumber.Length = addr64_data->AddressLength;
1434 }
1435 else if (addr64_data->ResourceType == ACPI_IO_RANGE)
1436 {
1437 RequirementDescriptor->Type = CmResourceTypePort;
1438 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1439 RequirementDescriptor->Flags = CM_RESOURCE_PORT_IO;
1440 if (addr64_data->Decode == ACPI_POS_DECODE)
1441 RequirementDescriptor->Flags |= CM_RESOURCE_PORT_POSITIVE_DECODE;
1442 RequirementDescriptor->u.Port.MinimumAddress.QuadPart = addr64_data->Minimum;
1443 RequirementDescriptor->u.Port.MaximumAddress.QuadPart = addr64_data->Maximum + addr64_data->AddressLength - 1;
1444 RequirementDescriptor->u.Port.Length = addr64_data->AddressLength;
1445 }
1446 else
1447 {
1448 RequirementDescriptor->Type = CmResourceTypeMemory;
1449 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1450 RequirementDescriptor->Flags = 0;
1451 if (addr64_data->Info.Mem.WriteProtect == ACPI_READ_ONLY_MEMORY)
1452 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
1453 else
1454 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
1455 switch (addr64_data->Info.Mem.Caching)
1456 {
1457 case ACPI_CACHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
1458 case ACPI_WRITE_COMBINING_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
1459 case ACPI_PREFETCHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
1460 }
1461 RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = addr64_data->Minimum;
1462 RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = addr64_data->Maximum + addr64_data->AddressLength - 1;
1463 RequirementDescriptor->u.Memory.Length = addr64_data->AddressLength;
1464 }
1465 RequirementDescriptor++;
1466 break;
1467 }
1468 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
1469 {
1470 ACPI_RESOURCE_EXTENDED_ADDRESS64 *addr64_data = (ACPI_RESOURCE_EXTENDED_ADDRESS64*) &resource->Data;
1471 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1472 if (addr64_data->ResourceType == ACPI_BUS_NUMBER_RANGE)
1473 {
1474 DPRINT1("64-bit bus address is not supported!\n");
1475 RequirementDescriptor->Type = CmResourceTypeBusNumber;
1476 RequirementDescriptor->ShareDisposition = CmResourceShareShared;
1477 RequirementDescriptor->Flags = 0;
1478 RequirementDescriptor->u.BusNumber.MinBusNumber = (ULONG)addr64_data->Minimum;
1479 RequirementDescriptor->u.BusNumber.MaxBusNumber = (ULONG)addr64_data->Maximum + addr64_data->AddressLength - 1;
1480 RequirementDescriptor->u.BusNumber.Length = addr64_data->AddressLength;
1481 }
1482 else if (addr64_data->ResourceType == ACPI_IO_RANGE)
1483 {
1484 RequirementDescriptor->Type = CmResourceTypePort;
1485 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1486 RequirementDescriptor->Flags = CM_RESOURCE_PORT_IO;
1487 if (addr64_data->Decode == ACPI_POS_DECODE)
1488 RequirementDescriptor->Flags |= CM_RESOURCE_PORT_POSITIVE_DECODE;
1489 RequirementDescriptor->u.Port.MinimumAddress.QuadPart = addr64_data->Minimum;
1490 RequirementDescriptor->u.Port.MaximumAddress.QuadPart = addr64_data->Maximum + addr64_data->AddressLength - 1;
1491 RequirementDescriptor->u.Port.Length = addr64_data->AddressLength;
1492 }
1493 else
1494 {
1495 RequirementDescriptor->Type = CmResourceTypeMemory;
1496 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1497 RequirementDescriptor->Flags = 0;
1498 if (addr64_data->Info.Mem.WriteProtect == ACPI_READ_ONLY_MEMORY)
1499 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
1500 else
1501 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
1502 switch (addr64_data->Info.Mem.Caching)
1503 {
1504 case ACPI_CACHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_CACHEABLE; break;
1505 case ACPI_WRITE_COMBINING_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_COMBINEDWRITE; break;
1506 case ACPI_PREFETCHABLE_MEMORY: RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE; break;
1507 }
1508 RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = addr64_data->Minimum;
1509 RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = addr64_data->Maximum + addr64_data->AddressLength - 1;
1510 RequirementDescriptor->u.Memory.Length = addr64_data->AddressLength;
1511 }
1512 RequirementDescriptor++;
1513 break;
1514 }
1515 case ACPI_RESOURCE_TYPE_MEMORY24:
1516 {
1517 ACPI_RESOURCE_MEMORY24 *mem24_data = (ACPI_RESOURCE_MEMORY24*) &resource->Data;
1518 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1519 RequirementDescriptor->Type = CmResourceTypeMemory;
1520 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1521 RequirementDescriptor->Flags = CM_RESOURCE_MEMORY_24;
1522 if (mem24_data->WriteProtect == ACPI_READ_ONLY_MEMORY)
1523 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
1524 else
1525 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
1526 RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = mem24_data->Minimum;
1527 RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = mem24_data->Maximum + mem24_data->AddressLength - 1;
1528 RequirementDescriptor->u.Memory.Length = mem24_data->AddressLength;
1529
1530 RequirementDescriptor++;
1531 break;
1532 }
1533 case ACPI_RESOURCE_TYPE_MEMORY32:
1534 {
1535 ACPI_RESOURCE_MEMORY32 *mem32_data = (ACPI_RESOURCE_MEMORY32*) &resource->Data;
1536 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1537 RequirementDescriptor->Type = CmResourceTypeMemory;
1538 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1539 RequirementDescriptor->Flags = 0;
1540 if (mem32_data->WriteProtect == ACPI_READ_ONLY_MEMORY)
1541 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
1542 else
1543 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
1544 RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = mem32_data->Minimum;
1545 RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = mem32_data->Maximum + mem32_data->AddressLength - 1;
1546 RequirementDescriptor->u.Memory.Length = mem32_data->AddressLength;
1547
1548 RequirementDescriptor++;
1549 break;
1550 }
1551 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
1552 {
1553 ACPI_RESOURCE_FIXED_MEMORY32 *fixedmem32_data = (ACPI_RESOURCE_FIXED_MEMORY32*) &resource->Data;
1554 RequirementDescriptor->Option = CurrentRes ? 0 : IO_RESOURCE_PREFERRED;
1555 RequirementDescriptor->Type = CmResourceTypeMemory;
1556 RequirementDescriptor->ShareDisposition = CmResourceShareDeviceExclusive;
1557 RequirementDescriptor->Flags = 0;
1558 if (fixedmem32_data->WriteProtect == ACPI_READ_ONLY_MEMORY)
1559 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_ONLY;
1560 else
1561 RequirementDescriptor->Flags |= CM_RESOURCE_MEMORY_READ_WRITE;
1562 RequirementDescriptor->u.Memory.MinimumAddress.QuadPart = fixedmem32_data->Address;
1563 RequirementDescriptor->u.Memory.MaximumAddress.QuadPart = fixedmem32_data->Address + fixedmem32_data->AddressLength - 1;
1564 RequirementDescriptor->u.Memory.Length = fixedmem32_data->AddressLength;
1565
1566 RequirementDescriptor++;
1567 break;
1568 }
1569 default:
1570 {
1571 break;
1572 }
1573 }
1574 resource = ACPI_NEXT_RESOURCE(resource);
1575 }
1576 ExFreePoolWithTag(Buffer.Pointer, 'IPCA');
1577
1578 Irp->IoStatus.Information = (ULONG_PTR)RequirementsList;
1579
1580 return STATUS_SUCCESS;
1581 }
1582
1583 NTSTATUS
1584 Bus_PDO_QueryDeviceRelations(
1585 PPDO_DEVICE_DATA DeviceData,
1586 PIRP Irp )
1587 /*++
1588
1589 Routine Description:
1590
1591 The PnP Manager sends this IRP to gather information about
1592 devices with a relationship to the specified device.
1593 Bus drivers must handle this request for TargetDeviceRelation
1594 for their child devices (child PDOs).
1595
1596 If a driver returns relations in response to this IRP,
1597 it allocates a DEVICE_RELATIONS structure from paged
1598 memory containing a count and the appropriate number of
1599 device object pointers. The PnP Manager frees the structure
1600 when it is no longer needed. If a driver replaces a
1601 DEVICE_RELATIONS structure allocated by another driver,
1602 it must free the previous structure.
1603
1604 A driver must reference the PDO of any device that it
1605 reports in this IRP (ObReferenceObject). The PnP Manager
1606 removes the reference when appropriate.
1607
1608 Arguments:
1609
1610 DeviceData - Pointer to the PDO's device extension.
1611 Irp - Pointer to the irp.
1612
1613 Return Value:
1614
1615 NT STATUS
1616
1617 --*/
1618 {
1619
1620 PIO_STACK_LOCATION stack;
1621 PDEVICE_RELATIONS deviceRelations;
1622 NTSTATUS status;
1623
1624 PAGED_CODE ();
1625
1626 stack = IoGetCurrentIrpStackLocation (Irp);
1627
1628 switch (stack->Parameters.QueryDeviceRelations.Type) {
1629
1630 case TargetDeviceRelation:
1631
1632 deviceRelations = (PDEVICE_RELATIONS) Irp->IoStatus.Information;
1633 if (deviceRelations) {
1634 //
1635 // Only PDO can handle this request. Somebody above
1636 // is not playing by rule.
1637 //
1638 ASSERTMSG("Someone above is handling TargetDeviceRelation", !deviceRelations);
1639 }
1640
1641 deviceRelations = (PDEVICE_RELATIONS)
1642 ExAllocatePoolWithTag (PagedPool,
1643 sizeof(DEVICE_RELATIONS),
1644 'IPCA');
1645 if (!deviceRelations) {
1646 status = STATUS_INSUFFICIENT_RESOURCES;
1647 break;
1648 }
1649
1650 //
1651 // There is only one PDO pointer in the structure
1652 // for this relation type. The PnP Manager removes
1653 // the reference to the PDO when the driver or application
1654 // un-registers for notification on the device.
1655 //
1656
1657 deviceRelations->Count = 1;
1658 deviceRelations->Objects[0] = DeviceData->Common.Self;
1659 ObReferenceObject(DeviceData->Common.Self);
1660
1661 status = STATUS_SUCCESS;
1662 Irp->IoStatus.Information = (ULONG_PTR) deviceRelations;
1663 break;
1664
1665 case BusRelations: // Not handled by PDO
1666 case EjectionRelations: // optional for PDO
1667 case RemovalRelations: // // optional for PDO
1668 default:
1669 status = Irp->IoStatus.Status;
1670 }
1671
1672 return status;
1673 }
1674
1675 NTSTATUS
1676 Bus_PDO_QueryBusInformation(
1677 PPDO_DEVICE_DATA DeviceData,
1678 PIRP Irp )
1679 /*++
1680
1681 Routine Description:
1682
1683 The PnP Manager uses this IRP to request the type and
1684 instance number of a device's parent bus. Bus drivers
1685 should handle this request for their child devices (PDOs).
1686
1687 Arguments:
1688
1689 DeviceData - Pointer to the PDO's device extension.
1690 Irp - Pointer to the irp.
1691
1692 Return Value:
1693
1694 NT STATUS
1695
1696 --*/
1697 {
1698
1699 PPNP_BUS_INFORMATION busInfo;
1700
1701 PAGED_CODE ();
1702
1703 busInfo = ExAllocatePoolWithTag (PagedPool, sizeof(PNP_BUS_INFORMATION),
1704 'IPCA');
1705
1706 if (busInfo == NULL) {
1707 return STATUS_INSUFFICIENT_RESOURCES;
1708 }
1709
1710 busInfo->BusTypeGuid = GUID_ACPI_INTERFACE_STANDARD;
1711
1712 busInfo->LegacyBusType = InternalPowerBus;
1713
1714 busInfo->BusNumber = 0; //fixme
1715
1716 Irp->IoStatus.Information = (ULONG_PTR)busInfo;
1717
1718 return STATUS_SUCCESS;
1719 }
1720
1721
1722 NTSTATUS
1723 Bus_GetDeviceCapabilities(
1724 PDEVICE_OBJECT DeviceObject,
1725 PDEVICE_CAPABILITIES DeviceCapabilities
1726 )
1727 {
1728 IO_STATUS_BLOCK ioStatus;
1729 KEVENT pnpEvent;
1730 NTSTATUS status;
1731 PDEVICE_OBJECT targetObject;
1732 PIO_STACK_LOCATION irpStack;
1733 PIRP pnpIrp;
1734
1735 PAGED_CODE();
1736
1737 //
1738 // Initialize the capabilities that we will send down
1739 //
1740 RtlZeroMemory( DeviceCapabilities, sizeof(DEVICE_CAPABILITIES) );
1741 DeviceCapabilities->Size = sizeof(DEVICE_CAPABILITIES);
1742 DeviceCapabilities->Version = 1;
1743 DeviceCapabilities->Address = -1;
1744 DeviceCapabilities->UINumber = -1;
1745
1746 //
1747 // Initialize the event
1748 //
1749 KeInitializeEvent( &pnpEvent, NotificationEvent, FALSE );
1750
1751 targetObject = IoGetAttachedDeviceReference( DeviceObject );
1752
1753 //
1754 // Build an Irp
1755 //
1756 pnpIrp = IoBuildSynchronousFsdRequest(
1757 IRP_MJ_PNP,
1758 targetObject,
1759 NULL,
1760 0,
1761 NULL,
1762 &pnpEvent,
1763 &ioStatus
1764 );
1765 if (pnpIrp == NULL) {
1766
1767 status = STATUS_INSUFFICIENT_RESOURCES;
1768 goto GetDeviceCapabilitiesExit;
1769
1770 }
1771
1772 //
1773 // Pnp Irps all begin life as STATUS_NOT_SUPPORTED;
1774 //
1775 pnpIrp->IoStatus.Status = STATUS_NOT_SUPPORTED;
1776
1777 //
1778 // Get the top of stack
1779 //
1780 irpStack = IoGetNextIrpStackLocation( pnpIrp );
1781
1782 //
1783 // Set the top of stack
1784 //
1785 RtlZeroMemory( irpStack, sizeof(IO_STACK_LOCATION ) );
1786 irpStack->MajorFunction = IRP_MJ_PNP;
1787 irpStack->MinorFunction = IRP_MN_QUERY_CAPABILITIES;
1788 irpStack->Parameters.DeviceCapabilities.Capabilities = DeviceCapabilities;
1789
1790 //
1791 // Call the driver
1792 //
1793 status = IoCallDriver( targetObject, pnpIrp );
1794 if (status == STATUS_PENDING) {
1795
1796 //
1797 // Block until the irp comes back.
1798 // Important thing to note here is when you allocate
1799 // the memory for an event in the stack you must do a
1800 // KernelMode wait instead of UserMode to prevent
1801 // the stack from getting paged out.
1802 //
1803
1804 KeWaitForSingleObject(
1805 &pnpEvent,
1806 Executive,
1807 KernelMode,
1808 FALSE,
1809 NULL
1810 );
1811 status = ioStatus.Status;
1812
1813 }
1814
1815 GetDeviceCapabilitiesExit:
1816 //
1817 // Done with reference
1818 //
1819 ObDereferenceObject( targetObject );
1820
1821 //
1822 // Done
1823 //
1824 return status;
1825
1826 }
1827
1828