ReactOS 0.4.17-dev-1190-g4c812f4
utils.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS PCI Bus Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/bus/pci/utils.c
5 * PURPOSE: Utility/Helper Support Code
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <pci.h>
12
13#define NDEBUG
14#include <debug.h>
15
16/* GLOBALS ********************************************************************/
17
20
23
24/* FUNCTIONS ******************************************************************/
25
29 IN PCUNICODE_STRING EqualString,
31{
32 UNICODE_STRING PartialString;
33 LONG EqualChars, TotalChars;
34
35 /* Build a partial string with the smaller substring */
36 PartialString.Length = EqualString->Length;
37 PartialString.MaximumLength = InputString->MaximumLength;
38 PartialString.Buffer = InputString->Buffer;
39
40 /* Check how many characters that need comparing */
41 EqualChars = 0;
42 TotalChars = (InputString->Length - EqualString->Length) / sizeof(WCHAR);
43
44 /* If the substring is bigger, just fail immediately */
45 if (TotalChars < 0) return FALSE;
46
47 /* Keep checking each character */
48 while (!RtlEqualUnicodeString(EqualString, &PartialString, CaseInSensitive))
49 {
50 /* Continue checking until all the required characters are equal */
51 PartialString.Buffer++;
52 PartialString.MaximumLength -= sizeof(WCHAR);
53 if (++EqualChars > TotalChars) return FALSE;
54 }
55
56 /* The string is equal */
57 return TRUE;
58}
59
64{
67 WCHAR Char;
68
69 /* Initialize everything to zero */
70 Short = 0;
71 Length = 0;
72 while (TRUE)
73 {
74 /* Get the character and set the high byte based on the previous one */
75 Char = *String++;
76 High = 16 * Short;
77
78 /* Check for numbers */
79 if ( Char >= '0' && Char <= '9' )
80 {
81 /* Convert them to a byte */
82 Low = Char - '0';
83 }
84 else if ( Char >= 'A' && Char <= 'F' )
85 {
86 /* Convert upper-case hex letters into a byte */
87 Low = Char - '7';
88 }
89 else if ( Char >= 'a' && Char <= 'f' )
90 {
91 /* Convert lower-case hex letters into a byte */
92 Low = Char - 'W';
93 }
94 else
95 {
96 /* Invalid string, fail the conversion */
97 return FALSE;
98 }
99
100 /* Combine the high and low byte */
101 Short = High | Low;
102
103 /* If 4 letters have been reached, the 16-bit integer should exist */
104 if (++Length >= 4)
105 {
106 /* Return it to the caller */
107 *Value = Short;
108 return TRUE;
109 }
110 }
111}
112
114NTAPI
116{
117 ULONGLONG Mask = 0;
119
120 /* Initialize the version information */
123 VersionInfo.wSuiteMask = SuiteMask;
124
125 /* Set the comparison mask and return if the passed suite mask matches */
128}
129
131NTAPI
133{
135 PVOID Value;
138
139 /* Assume this isn't Datacenter */
140 Result = FALSE;
141
142 /* First, try opening the setup key */
144 L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Services\\setupdd",
145 0,
147 &Value,
148 &ResultLength);
149 if (!NT_SUCCESS(Status))
150 {
151 /* This is not an in-progress Setup boot, so query the suite version */
153 }
154 else
155 {
156 /* This scenario shouldn't happen yet, since SetupDD isn't used */
157 UNIMPLEMENTED_FATAL("ReactOS doesn't use SetupDD for its installation program. Therefore this scenario must not happen!\n");
158 }
159
160 /* Return if this is Datacenter or not */
161 return Result;
162}
163
165NTAPI
170 OUT PNTSTATUS KeyStatus)
171{
174 UNICODE_STRING KeyString;
175 PAGED_CODE();
176
177 /* Initialize the object attributes */
178 RtlInitUnicodeString(&KeyString, KeyName);
180 &KeyString,
182 RootKey,
183 NULL);
184
185 /* Open the key, returning a boolean, and the status, if requested */
187 if (KeyStatus) *KeyStatus = Status;
188 return NT_SUCCESS(Status);
189}
190
192NTAPI
195 IN HANDLE RootHandle,
196 IN ULONG Type,
198 OUT PULONG OutputLength)
199{
202 ULONG NeededLength, ActualLength;
203 UNICODE_STRING ValueString;
206
207 /* So we know what to free at the end of the body */
208 PartialInfo = NULL;
209 KeyHandle = NULL;
210 do
211 {
212 /* Open the key by name, rooted off the handle passed */
214 RootHandle,
216 &KeyHandle,
217 &Status);
218 if (!Result) break;
219
220 /* Query for the size that's needed for the value that was passed in */
221 RtlInitUnicodeString(&ValueString, ValueName);
222 Status = ZwQueryValueKey(KeyHandle,
223 &ValueString,
225 NULL,
226 0,
227 &NeededLength);
229 if (Status != STATUS_BUFFER_TOO_SMALL) break;
230
231 /* Allocate an appropriate buffer for the size that was returned */
232 ASSERT(NeededLength != 0);
234 PartialInfo = ExAllocatePoolWithTag(PagedPool,
235 NeededLength,
237 if (!PartialInfo) break;
238
239 /* Query the actual value information now that the size is known */
240 Status = ZwQueryValueKey(KeyHandle,
241 &ValueString,
243 PartialInfo,
244 NeededLength,
245 &ActualLength);
246 if (!NT_SUCCESS(Status)) break;
247
248 /* Make sure it's of the type that the caller expects */
250 if (PartialInfo->Type != Type) break;
251
252 ASSERT(NeededLength == ActualLength);
253 NeededLength = PartialInfo->DataLength;
254
255 /* Allocate a buffer to hold the data and return it to the caller */
258 NeededLength,
260 if (!*OutputBuffer) break;
261
262 /* Copy the data into the buffer and return its length to the caller */
263 RtlCopyMemory(*OutputBuffer, PartialInfo->Data, NeededLength);
264 if (OutputLength) *OutputLength = NeededLength;
266 } while (0);
267
268 /* Close any opened keys and free temporary allocations */
270 if (PartialInfo) ExFreePoolWithTag(PartialInfo, 0);
271 return Status;
272}
273
275NTAPI
277{
278 ULONG Start;
282
283 /* Initialize the range lists */
286
287 /* Loop x86 I/O ranges */
288 for (Start = 0x100; Start <= 0xFEFF; Start += 0x400)
289 {
290 /* Add the ISA I/O ranges */
292 Start,
293 Start + 0x2FF,
294 0,
296 NULL,
297 NULL);
298 if (!NT_SUCCESS(Status)) break;
299
300 /* Add the ISA I/O ranges */
302 Start,
303 Start + 0x2AF,
304 0,
306 NULL,
307 NULL);
308 if (!NT_SUCCESS(Status)) break;
309
310 /* Add the VGA I/O range for Monochrome Video */
312 Start + 0x2BC,
313 Start + 0x2BF,
314 0,
316 NULL,
317 NULL);
318 if (!NT_SUCCESS(Status)) break;
319
320 /* Add the VGA I/O range for certain CGA adapters */
322 Start + 0x2E0,
323 Start + 0x2FF,
324 0,
326 NULL,
327 NULL);
328 if (!NT_SUCCESS(Status)) break;
329
330 /* Success, ranges added done */
331 };
332
335 return Status;
336}
337
339NTAPI
342{
343 PPCI_FDO_EXTENSION DeviceExtension;
344 PPCI_PDO_EXTENSION SearchExtension, FoundExtension;
345
346 /* Assume we'll find nothing */
347 SearchExtension = DeviceObject->DeviceExtension;
348 FoundExtension = NULL;
349
350 /* Check if a lock was specified */
351 if (Lock)
352 {
353 /* Wait for the lock to be released */
356 }
357
358 /* Now search for the extension */
360 while (DeviceExtension)
361 {
362 /* Acquire this device's lock */
364 KeWaitForSingleObject(&DeviceExtension->ChildListLock,
365 Executive,
367 FALSE,
368 NULL);
369
370 /* Scan all children PDO, stop when no more PDOs, or found it */
371 for (FoundExtension = DeviceExtension->ChildPdoList;
372 ((FoundExtension) && (FoundExtension != SearchExtension));
373 FoundExtension = FoundExtension->Next);
374
375 /* Release this device's lock */
376 KeSetEvent(&DeviceExtension->ChildListLock, IO_NO_INCREMENT, FALSE);
378
379 /* If we found it, break out */
380 if (FoundExtension) break;
381
382 /* Move to the next device */
383 DeviceExtension = (PPCI_FDO_EXTENSION)DeviceExtension->List.Next;
384 }
385
386 /* Check if we had acquired a lock previously */
387 if (Lock)
388 {
389 /* Release it */
392 }
393
394 /* Return which extension was found, if any */
395 return DeviceExtension;
396}
397
398VOID
399NTAPI
401 IN PPCI_FDO_EXTENSION DeviceExtension,
403{
404 PSINGLE_LIST_ENTRY NextEntry;
405 PAGED_CODE();
406
407 /* Check if a lock was specified */
408 if (Lock)
409 {
410 /* Wait for the lock to be released */
413 }
414
415 /* Loop the list until we get to the end, then insert this entry there */
416 for (NextEntry = ListHead; NextEntry->Next; NextEntry = NextEntry->Next);
417 NextEntry->Next = &DeviceExtension->List;
418
419 /* Check if we had acquired a lock previously */
420 if (Lock)
421 {
422 /* Release it */
425 }
426}
427
428VOID
429NTAPI
433{
434 PAGED_CODE();
435
436 /* Check if a lock was specified */
437 if (Lock)
438 {
439 /* Wait for the lock to be released */
442 }
443
444 /* Make the entry point to the current head and make the head point to it */
445 Entry->Next = ListHead->Next;
446 ListHead->Next = Entry;
447
448 /* Check if we had acquired a lock previously */
449 if (Lock)
450 {
451 /* Release it */
454 }
455}
456
457VOID
458NTAPI
460 IN PVOID Lock,
461 IN PPCI_SECONDARY_EXTENSION SecondaryExtension,
462 IN PCI_SIGNATURE ExtensionType,
463 IN PVOID Destructor)
464{
465 PAGED_CODE();
466
467 /* Setup the extension data, and insert it into the primary's list */
468 SecondaryExtension->ExtensionType = ExtensionType;
469 SecondaryExtension->Destructor = Destructor;
470 PciInsertEntryAtHead(List, &SecondaryExtension->List, Lock);
471}
472
474NTAPI
478{
482 do
483 {
484 /* Query the requested property size */
487 0,
488 NULL,
489 &BufferLength);
491 {
492 /* Call should've failed with buffer too small! */
493 DPRINT1("PCIX - Unexpected status from GetDeviceProperty, saw %08X, expected %08X.\n",
494 Status,
497 ASSERTMSG("PCI Successfully did the impossible!\n", FALSE);
498 break;
499 }
500
501 /* Allocate the required buffer */
503 if (!Buffer)
504 {
505 /* No memory, fail the request */
506 DPRINT1("PCIX - Failed to allocate DeviceProperty buffer (%u bytes).\n", BufferLength);
508 break;
509 }
510
511 /* Do the actual property query call */
515 Buffer,
516 &ResultLength);
517 if (!NT_SUCCESS(Status)) break;
518
519 /* Return the buffer to the caller */
522 return STATUS_SUCCESS;
523 } while (FALSE);
524
525 /* Failure path */
526 return STATUS_UNSUCCESSFUL;
527}
528
530NTAPI
537{
538 PIRP Irp;
542 PDEVICE_OBJECT AttachedDevice;
543 PAGED_CODE();
544
545 /* Initialize the pending IRP event */
547
548 /* Get a reference to the root PDO (ACPI) */
550 if (!AttachedDevice) return STATUS_INVALID_PARAMETER;
551
552 /* Build the requested IOCTL IRP */
554 AttachedDevice,
559 0,
560 &Event,
563
564 /* Send the IOCTL to the driver */
565 Status = IoCallDriver(AttachedDevice, Irp);
566 if (Status == STATUS_PENDING)
567 {
568 /* Wait for a response */
570 Executive,
572 FALSE,
573 NULL);
574 Status = Irp->IoStatus.Status;
575 }
576
577 /* Take away the reference we took and return the result to the caller */
578 ObDereferenceObject(AttachedDevice);
579 return Status;
580}
581
583NTAPI
585 IN PCI_SIGNATURE ExtensionType)
586{
587 PSINGLE_LIST_ENTRY NextEntry;
589
590 /* Scan the list */
591 for (NextEntry = ListHead; NextEntry; NextEntry = NextEntry->Next)
592 {
593 /* Grab each extension and check if it's the one requested */
595 if (Extension->ExtensionType == ExtensionType) return Extension;
596 }
597
598 /* Nothing was found */
599 return NULL;
600}
601
603NTAPI
605 IN USHORT DeviceId,
606 IN USHORT SubVendorId,
607 IN USHORT SubSystemId,
608 IN UCHAR RevisionId)
609{
610 PPCI_HACK_ENTRY HackEntry;
612 ULONG LastWeight, MatchWeight;
613 ULONG EntryFlags;
614
615 /* ReactOS SetupLDR Hack */
616 if (!PciHackTable) return 0;
617
618 /* Initialize the variables before looping */
619 LastWeight = 0;
620 HackFlags = 0;
622
623 /* Scan the hack table */
624 for (HackEntry = PciHackTable;
625 HackEntry->VendorID != PCI_INVALID_VENDORID;
626 ++HackEntry)
627 {
628 /* Check if there's an entry for this device */
629 if ((HackEntry->DeviceID == DeviceId) &&
630 (HackEntry->VendorID == VendorId))
631 {
632 /* This is a basic match */
633 EntryFlags = HackEntry->Flags;
634 MatchWeight = 1;
635
636 /* Does the entry have revision information? */
637 if (EntryFlags & PCI_HACK_HAS_REVISION_INFO)
638 {
639 /* Check if the revision matches, if so, this is a better match */
640 if (HackEntry->RevisionID != RevisionId) continue;
641 MatchWeight = 3;
642 }
643
644 /* Does the netry have subsystem information? */
645 if (EntryFlags & PCI_HACK_HAS_SUBSYSTEM_INFO)
646 {
647 /* Check if it matches, if so, this is the best possible match */
648 if ((HackEntry->SubVendorID != SubVendorId) ||
649 (HackEntry->SubSystemID != SubSystemId))
650 {
651 continue;
652 }
653 MatchWeight += 4;
654 }
655
656 /* Is this the best match yet? */
657 if (MatchWeight > LastWeight)
658 {
659 /* This is the best match for now, use this as the hack flags */
660 HackFlags = HackEntry->HackFlags;
661 LastWeight = MatchWeight;
662 }
663 }
664 }
665
666 /* Return the best match */
667 return HackFlags;
668}
669
671NTAPI
673 IN UCHAR SubClass)
674{
675 /* Check for system or bridge devices */
676 if (BaseClass == PCI_CLASS_BASE_SYSTEM_DEV)
677 {
678 /* Interrupt controllers are critical */
679 return SubClass == PCI_SUBCLASS_SYS_INTERRUPT_CTLR;
680 }
681 else if (BaseClass == PCI_CLASS_BRIDGE_DEV)
682 {
683 /* ISA Bridges are critical */
684 return SubClass == PCI_SUBCLASS_BR_ISA;
685 }
686 else
687 {
688 /* All display controllers are critical */
689 return BaseClass == PCI_CLASS_DISPLAY_CTLR;
690 }
691}
692
694NTAPI
696 IN ULONG FunctionNumber,
697 IN PPCI_COMMON_HEADER PciData)
698{
699 KIRQL Irql;
701
702 /* Get the current IRQL when this call was made */
704
705 /* Is this a low-IRQL call? */
706 if (Irql < DISPATCH_LEVEL)
707 {
708 /* Acquire this device's lock */
710 KeWaitForSingleObject(&DeviceExtension->ChildListLock,
711 Executive,
713 FALSE,
714 NULL);
715 }
716
717 /* Loop every child PDO */
718 for (PdoExtension = DeviceExtension->ChildPdoList;
721 {
722 /* Find only enumerated PDOs */
723 if (!PdoExtension->ReportedMissing)
724 {
725 /* Same slot, and the IDs match as the device's hack flags allow */
726 if ((FunctionNumber == PdoExtension->Slot.u.AsULONG) &&
727 (PcipIsSameDevice(PdoExtension, PciData)))
728 {
729 /* This is considered to be the same PDO */
730 break;
731 }
732 }
733 }
734
735 /* Was this a low-IRQL call? */
736 if (Irql < DISPATCH_LEVEL)
737 {
738 /* Release this device's lock */
739 KeSetEvent(&DeviceExtension->ChildListLock, IO_NO_INCREMENT, FALSE);
741 }
742
743 /* If the search found something, this is non-NULL, otherwise it's NULL */
744 return PdoExtension;
745}
746
752static
755 _In_ PPCI_PDO_EXTENSION BridgeExtension,
756 _Out_ PUCHAR SecondaryBus,
757 _Out_ PUCHAR SubordinateBus)
758{
760
761 if (!NT_SUCCESS(PciGetBiosConfig(BridgeExtension, &BiosData)))
762 return FALSE;
763
764 if (BridgeExtension->HeaderType == PCI_CARDBUS_BRIDGE_TYPE)
765 {
766 *SecondaryBus = BiosData.u.type2.SecondaryBus;
767 *SubordinateBus = BiosData.u.type2.SubordinateBus;
768 }
769 else
770 {
771 *SecondaryBus = BiosData.u.type1.SecondaryBus;
772 *SubordinateBus = BiosData.u.type1.SubordinateBus;
773 }
774
775 return ((*SecondaryBus != 0) && (*SubordinateBus != 0));
776}
777
779NTAPI
781 _In_ PPCI_PDO_EXTENSION DeviceExtension)
782{
783 PPCI_FDO_EXTENSION ParentFdo;
784 UCHAR LowBus, HighBus;
785 BOOLEAN IsBridge;
786 ULONG i;
787 PAGED_CODE();
788
789 /* Check for too many, or no, debug ports */
791 if (!PciDebugPortsCount) return FALSE;
792
793 IsBridge = ((DeviceExtension->HeaderType == PCI_BRIDGE_TYPE) ||
794 (DeviceExtension->HeaderType == PCI_CARDBUS_BRIDGE_TYPE));
795 ParentFdo = DeviceExtension->ParentFdoExtension;
796
797 /* Work out which firmware bus numbers a debugging device has to be on */
798 if (IsBridge)
799 {
800 if (!PciGetBiosBusRange(DeviceExtension, &LowBus, &HighBus))
801 return FALSE;
802 }
803 else if (PCI_IS_ROOT_FDO(ParentFdo))
804 {
805 LowBus = HighBus = ParentFdo->BaseBus;
806 }
807 else
808 {
810 &LowBus,
811 &HighBus))
812 {
813 return FALSE;
814 }
815
816 HighBus = LowBus;
817 }
818
819 for (i = 0; i < PciDebugPortsCount; i++)
820 {
821 if ((PciDebuggingDevices[i].Bus < LowBus) ||
822 (PciDebuggingDevices[i].Bus > HighBus))
823 {
824 continue;
825 }
826
827 /* A bridge covers its whole range, anything else must be the device itself */
828 if (IsBridge ||
829 (PciDebuggingDevices[i].Slot.u.AsULONG == DeviceExtension->Slot.u.AsULONG))
830 {
831 return TRUE;
832 }
833 }
834
835 return FALSE;
836}
837
839NTAPI
841 OUT PPCI_COMMON_HEADER PciData)
842{
845 UNICODE_STRING KeyName, KeyValue;
846 WCHAR Buffer[32];
848 PKEY_VALUE_PARTIAL_INFORMATION PartialInfo = (PVOID)DataBuffer;
851 PAGED_CODE();
852
853 /* Open the PCI key */
854 Status = IoOpenDeviceRegistryKey(DeviceExtension->ParentFdoExtension->
856 TRUE,
858 &KeyHandle);
859 if (!NT_SUCCESS(Status)) return Status;
860
861 /* Create a volatile BIOS configuration key */
862 RtlInitUnicodeString(&KeyName, L"BiosConfig");
864 &KeyName,
866 KeyHandle,
867 NULL);
868 Status = ZwCreateKey(&SubKeyHandle,
869 KEY_READ,
871 0,
872 NULL,
874 NULL);
876 if (!NT_SUCCESS(Status)) return Status;
877
878 /* Create the key value based on the device and function number */
880 L"DEV_%02x&FUN_%02x",
881 DeviceExtension->Slot.u.bits.DeviceNumber,
882 DeviceExtension->Slot.u.bits.FunctionNumber);
883 RtlInitUnicodeString(&KeyValue, Buffer);
884
885 /* Query the value information (PCI BIOS configuration header) */
886 Status = ZwQueryValueKey(SubKeyHandle,
887 &KeyValue,
889 PartialInfo,
890 sizeof(DataBuffer),
891 &ResultLength);
893 if (!NT_SUCCESS(Status)) return Status;
894
895 /* If any information was returned, go ahead and copy its data */
896 ASSERT(PartialInfo->DataLength == PCI_COMMON_HDR_LENGTH);
897 RtlCopyMemory(PciData, PartialInfo->Data, PCI_COMMON_HDR_LENGTH);
898 return Status;
899}
900
902NTAPI
904 IN PPCI_COMMON_HEADER PciData)
905{
908 UNICODE_STRING KeyName, KeyValue;
909 WCHAR Buffer[32];
911 PAGED_CODE();
912
913 /* Open the PCI key */
914 Status = IoOpenDeviceRegistryKey(DeviceExtension->ParentFdoExtension->
916 TRUE,
918 &KeyHandle);
919 if (!NT_SUCCESS(Status)) return Status;
920
921 /* Create a volatile BIOS configuration key */
922 RtlInitUnicodeString(&KeyName, L"BiosConfig");
924 &KeyName,
926 KeyHandle,
927 NULL);
928 Status = ZwCreateKey(&SubKeyHandle,
931 0,
932 NULL,
934 NULL);
936 if (!NT_SUCCESS(Status)) return Status;
937
938 /* Create the key value based on the device and function number */
940 L"DEV_%02x&FUN_%02x",
941 DeviceExtension->Slot.u.bits.DeviceNumber,
942 DeviceExtension->Slot.u.bits.FunctionNumber);
943 RtlInitUnicodeString(&KeyValue, Buffer);
944
945 /* Set the value data (the PCI BIOS configuration header) */
946 Status = ZwSetValueKey(SubKeyHandle,
947 &KeyValue,
948 0,
950 PciData,
953 return Status;
954}
955
956UCHAR
957NTAPI
960 IN ULONG CapabilityId,
963{
964 ULONG CapabilityCount = 0;
965
966 /* If the device has no capabilility list, fail */
967 if (!Offset) return 0;
968
969 /* Validate a PDO with capabilities, a valid buffer, and a valid length */
970 ASSERT(DeviceExtension->ExtensionType == PciPdoExtensionType);
971 ASSERT(DeviceExtension->CapabilitiesPtr != 0);
972 ASSERT(Buffer);
974
975 /* Loop all capabilities */
976 while (Offset)
977 {
978 /* Make sure the pointer is spec-aligned and spec-sized */
979 ASSERT((Offset >= PCI_COMMON_HDR_LENGTH) && ((Offset & 0x3) == 0));
980
981 /* Read the capability header */
982 PciReadDeviceConfig(DeviceExtension,
983 Buffer,
984 Offset,
986
987 /* Check if this is the capability being looked up */
988 if ((Buffer->CapabilityID == CapabilityId) || !(CapabilityId))
989 {
990 /* Check if was at a valid offset and length */
991 if ((Offset) && (Length > sizeof(PCI_CAPABILITIES_HEADER)))
992 {
993 /* Sanity check */
994 ASSERT(Length <= (sizeof(PCI_COMMON_CONFIG) - Offset));
995
996 /* Now read the whole capability data into the buffer */
997 PciReadDeviceConfig(DeviceExtension,
1002 }
1003
1004 /* Return the offset where the capability was found */
1005 return Offset;
1006 }
1007
1008 /* Try the next capability instead */
1009 CapabilityCount++;
1010 Offset = Buffer->Next;
1011
1012 /* There can't be more than 48 capabilities (256 bytes max) */
1013 if (CapabilityCount > 48)
1014 {
1015 /* Fail, since this is basically a broken PCI device */
1016 DPRINT1("PCIX - Device %p capabilities list is broken.\n", DeviceExtension);
1017 return 0;
1018 }
1019 }
1020
1021 /* Capability wasn't found, fail */
1022 return 0;
1023}
1024
1025BOOLEAN
1026NTAPI
1030 IN BOOLEAN ForPowerDown)
1031{
1032 UCHAR BaseClass, SubClass;
1033 BOOLEAN IsVga, KeepPower = FALSE;
1034
1035 /* Is there a device extension or should the PCI header be used? */
1036 if (DeviceExtension)
1037 {
1038 /* Never disable decodes for a debug PCI Device */
1039 if (DeviceExtension->OnDebugPath) return FALSE;
1040
1041 /* Hack flags will be obtained from the extension, not the caller */
1042 ASSERT(HackFlags == 0);
1043
1044 /* Get hacks and classification from the device extension */
1045 HackFlags = DeviceExtension->HackFlags;
1046 SubClass = DeviceExtension->SubClass;
1047 BaseClass = DeviceExtension->BaseClass;
1048 KeepPower = DeviceExtension->DisablePowerDown;
1049 }
1050 else
1051 {
1052 /* There must be a PCI header, go read the classification information */
1053 ASSERT(Config != NULL);
1054 BaseClass = Config->BaseClass;
1055 SubClass = Config->SubClass;
1056 }
1057
1058 /* Check for hack flags that prevent disabling the decodes */
1063 {
1064 /* Don't do it */
1065 return FALSE;
1066 }
1067
1068 if (ForPowerDown)
1069 {
1070 /* IDE controllers, legacy bridges and flagged functions may stop but not power down */
1071 if (KeepPower || (HackFlags & PCI_HACK_NEVER_POWER_DOWN))
1072 return FALSE;
1073 }
1075 {
1076 /* Flagged functions may power down, but keep decoding while stopped or removed */
1077 return FALSE;
1078 }
1079
1080 /* VGA adapters keep decoding unless they are being powered down */
1081 if (((BaseClass == PCI_CLASS_DISPLAY_CTLR) && (SubClass == PCI_SUBCLASS_VID_VGA_CTLR)) ||
1082 ((BaseClass == PCI_CLASS_PRE_20) && (SubClass == PCI_SUBCLASS_PRE_20_VGA)))
1083 {
1084 return ForPowerDown;
1085 }
1086
1087 if (BaseClass == PCI_CLASS_BRIDGE_DEV)
1088 {
1089 /* Check for legacy bridges */
1090 if ((SubClass == PCI_SUBCLASS_BR_ISA) ||
1091 (SubClass == PCI_SUBCLASS_BR_EISA) ||
1092 (SubClass == PCI_SUBCLASS_BR_MCA) ||
1093 (SubClass == PCI_SUBCLASS_BR_HOST) ||
1094 (SubClass == PCI_SUBCLASS_BR_OTHER))
1095 {
1096 /* Never disable these */
1097 return FALSE;
1098 }
1099 else if ((SubClass == PCI_SUBCLASS_BR_PCI_TO_PCI) ||
1100 (SubClass == PCI_SUBCLASS_BR_CARDBUS))
1101 {
1102 /* This is a supported bridge, but does it have a VGA card? */
1103 if (!DeviceExtension)
1104 {
1105 /* Read the bridge control flag from the PCI header */
1106 IsVga = Config->u.type1.BridgeControl & PCI_ENABLE_BRIDGE_VGA;
1107 }
1108 else
1109 {
1110 /* Read the cached flag in the device extension */
1111 IsVga = DeviceExtension->Dependent.type1.VgaBitSet;
1112 }
1113
1114 /* A bridge forwarding VGA follows the same rule as the adapter behind it */
1115 if (IsVga)
1116 return ForPowerDown;
1117 }
1118 }
1119
1120 /* Nothing else has to keep decoding */
1121 return TRUE;
1122}
1123
1125NTAPI
1127{
1128 ASSERT(PdoExtension->ExtensionType == PciPdoExtensionType);
1129
1130 /* Differentiate between devices and bridges */
1131 if (PdoExtension->BaseClass != PCI_CLASS_BRIDGE_DEV) return PciTypeDevice;
1132
1133 /* The PCI Bus driver handles only CardBus and PCI bridges (plus host) */
1134 if (PdoExtension->SubClass == PCI_SUBCLASS_BR_HOST) return PciTypeHostBridge;
1137
1138 /* Any other kind of bridge is treated like a device */
1139 return PciTypeDevice;
1140}
1141
1143NTAPI
1145{
1147
1148 /* Check if the IPI is already running */
1149 if (!InterlockedDecrement(&Context->RunCount))
1150 {
1151 /* Nope, this is the first instance, so execute the IPI function */
1152 Context->Function(Context->DeviceExtension, Context->Context);
1153
1154 /* Notify anyone that was spinning that they can stop now */
1155 Context->Barrier = 0;
1156 }
1157 else
1158 {
1159 /* Spin until it has finished running */
1160 while (Context->Barrier);
1161 }
1162
1163 /* Done */
1164 return 0;
1165}
1166
1167BOOLEAN
1168NTAPI
1170 IN ULONG Method)
1171{
1172 BOOLEAN FoundSlot;
1176 ULONG i, Length;
1178 PAGED_CODE();
1179
1180 /* Assume slot is not part of the parent method */
1181 FoundSlot = FALSE;
1182
1183 /* Allocate a 2KB buffer for the method return parameters */
1184 Length = sizeof(ACPI_EVAL_OUTPUT_BUFFER) + 2048;
1186 if (OutputBuffer)
1187 {
1188 /* Clear out the output buffer */
1190
1191 /* Initialize the input buffer with the method requested */
1192 InputBuffer.Signature = 0;
1193 *(PULONG)InputBuffer.MethodName = Method;
1195
1196 /* Send it to the ACPI driver */
1197 Status = PciSendIoctl(PdoExtension->ParentFdoExtension->PhysicalDeviceObject,
1199 &InputBuffer,
1200 sizeof(ACPI_EVAL_INPUT_BUFFER),
1202 Length);
1203 if (NT_SUCCESS(Status))
1204 {
1205 /* Scan all output arguments */
1206 for (i = 0; i < OutputBuffer->Count; i++)
1207 {
1208 /* Make sure it's an integer */
1209 Argument = &OutputBuffer->Argument[i];
1210 if (Argument->Type != ACPI_METHOD_ARGUMENT_INTEGER) continue;
1211
1212 /* Check if the argument matches this PCI slot structure */
1213 if (Argument->Argument == ((PdoExtension->Slot.u.bits.DeviceNumber) |
1214 ((PdoExtension->Slot.u.bits.FunctionNumber) << 16)))
1215 {
1216 /* This slot has been found, return it */
1217 FoundSlot = TRUE;
1218 break;
1219 }
1220 }
1221 }
1222
1223 /* Finished with the buffer, free it */
1225 }
1226
1227 /* Return if the slot was found */
1228 return FoundSlot;
1229}
1230
1250BOOLEAN
1251NTAPI
1253 _Out_ PIO_RESOURCE_DESCRIPTOR ResourceDescriptor,
1254 _In_ ULONG Bar,
1255 _In_ ULONG NextBar,
1256 _In_ BOOLEAN Rom)
1257{
1258 ULONGLONG AddressBits, Length, Alignment;
1260 UCHAR Type;
1261 BOOLEAN Is64BitBar = FALSE;
1262
1263 /* Check if the BAR is nor I/O nor memory */
1264 if (!(Bar & ~PCI_ADDRESS_IO_SPACE))
1265 {
1266 /* Fail this descriptor */
1267 ResourceDescriptor->Type = CmResourceTypeNull;
1268 return FALSE;
1269 }
1270
1271 /* Set default flag */
1272 ResourceDescriptor->Flags = 0;
1273
1274 /* Check for ROM AddressBits */
1275 if (Rom)
1276 {
1277 /* Clean up the BAR to get just the address */
1279 if (!Bar)
1280 {
1281 /* Invalid ar, fail this descriptor */
1282 ResourceDescriptor->Type = CmResourceTypeNull;
1283 return FALSE;
1284 }
1285
1286 /* ROM Addresses are always read only */
1287 ResourceDescriptor->Flags = CM_RESOURCE_MEMORY_READ_ONLY;
1288 }
1289
1290 /* Check what kind of BAR this is */
1292 {
1293 /* Set this as an I/O Port descriptor */
1295 ResourceDescriptor->Flags = CM_RESOURCE_PORT_IO;
1296 AddressBits = Bar & PCI_ADDRESS_IO_ADDRESS_MASK;
1297 }
1298 else
1299 {
1300 /* Set this as a memory descriptor */
1302 AddressBits = Bar & PCI_ADDRESS_MEMORY_ADDRESS_MASK;
1303
1304 /* A 64-bit BAR takes the high half of its address from the next BAR */
1306 {
1307 AddressBits |= (ULONGLONG)NextBar << 32;
1308 Is64BitBar = TRUE;
1309 }
1310
1311 /* Check if the BAR is listed as prefetchable memory */
1313 {
1314 /* Mark the descriptor in the same way */
1315 ResourceDescriptor->Flags |= CM_RESOURCE_MEMORY_PREFETCHABLE;
1316 }
1317 }
1318
1319 /* The probe leaves only the bits the BAR implements, so the lowest one is its length */
1320 Length = AddressBits & (~AddressBits + 1);
1321
1322 /* A BAR that implements no address bits is not there */
1323 if (!Length)
1324 {
1325 ResourceDescriptor->Type = CmResourceTypeNull;
1326 return FALSE;
1327 }
1328
1329 /* A legacy memory BAR can only be placed below 1MB */
1330 if ((Type == CmResourceTypeMemory) &&
1332 {
1333 AddressBits &= 0xFFFFF;
1334 }
1335
1336 /* A BAR aligns to its own length and decodes nothing above the bits it implements */
1337 Alignment = Length;
1338 MinimumAddress = 0;
1339 MaximumAddress = AddressBits | (Length - 1);
1340
1341 /* A length of 4GB or more takes the large memory form */
1342 if (!NT_SUCCESS(RtlIoEncodeMemIoResource(ResourceDescriptor,
1343 Type,
1344 Length,
1345 Alignment,
1348 {
1349 /* Fail this descriptor */
1350 ResourceDescriptor->Type = CmResourceTypeNull;
1351 }
1352
1353 /* Return if this is a 64-bit BAR, so the loop code knows to skip the next one */
1354 return Is64BitBar;
1355}
1356
1357VOID
1358NTAPI
1362{
1363 USHORT CommandValue;
1364
1365 /*
1366 * If decodes are being disabled, make sure it's allowed, and in both cases,
1367 * make sure that a hackflag isn't preventing touching the decodes at all.
1368 */
1369 if (((Enable) || (PciCanDisableDecodes(PdoExtension, 0, 0, 0))) &&
1371 {
1372 /* Did the caller already have a command word? */
1373 if (Command)
1374 {
1375 /* Use the caller's */
1376 CommandValue = *Command;
1377 }
1378 else
1379 {
1380 /* Otherwise, read the current command */
1382 &CommandValue,
1384 sizeof(USHORT));
1385 }
1386
1387 /* Turn off decodes by default */
1388 CommandValue &= ~(PCI_ENABLE_IO_SPACE |
1391
1392 /* If requested, enable the decodes that were enabled at init time */
1393 if (Enable) CommandValue |= PdoExtension->CommandEnables &
1397
1398 /* Update the command word */
1400 &CommandValue,
1402 sizeof(USHORT));
1403 }
1404}
1405
1407NTAPI
1410{
1411 PPNP_BUS_INFORMATION BusInfo;
1412
1413 /* Allocate a structure for the bus information */
1415 sizeof(PNP_BUS_INFORMATION),
1416 'BicP');
1417 if (!BusInfo) return STATUS_INSUFFICIENT_RESOURCES;
1418
1419 /* Write the correct GUID and bus type identifier, and fill the bus number */
1420 BusInfo->BusTypeGuid = GUID_BUS_TYPE_PCI;
1421 BusInfo->LegacyBusType = PCIBus;
1422 BusInfo->BusNumber = PdoExtension->ParentFdoExtension->BaseBus;
1423
1424 *Buffer = BusInfo;
1425
1426 return STATUS_SUCCESS;
1427}
1428
1430NTAPI
1433{
1434 PPCI_FDO_EXTENSION ParentExtension;
1437 PSLOT_INFO SlotInfo;
1438
1439 /* Check if a $PIR from the BIOS is used (legacy IRQ routing) */
1440 ParentExtension = PdoExtension->ParentFdoExtension;
1441 DPRINT("PCIX - Slot lookup for %d.%u.%u\n",
1442 ParentExtension ? ParentExtension->BaseBus : -1,
1443 PdoExtension->Slot.u.bits.DeviceNumber,
1444 PdoExtension->Slot.u.bits.FunctionNumber);
1445 if ((PciIrqRoutingTable) && (ParentExtension))
1446 {
1447 /* Read every slot information entry */
1448 SlotInfo = &PciIrqRoutingTable->Slot[0];
1449 DPRINT("PCIX - $PIR %p is %u bytes, slot 0 is at: %p\n",
1451 while (SlotInfo < (PSLOT_INFO)((ULONG_PTR)PciIrqRoutingTable +
1453 {
1454 DPRINT("PCIX - Slot Info: %u.%u->#%u\n",
1455 SlotInfo->BusNumber,
1456 SlotInfo->DeviceNumber,
1457 SlotInfo->SlotNumber);
1458
1459 /* Check if this slot information matches the PDO being queried */
1460 if ((ParentExtension->BaseBus == SlotInfo->BusNumber) &&
1461 (PdoExtension->Slot.u.bits.DeviceNumber == SlotInfo->DeviceNumber >> 3) &&
1462 (SlotInfo->SlotNumber))
1463 {
1464 /* We found it, return it and return success */
1465 *SlotNumber = SlotInfo->SlotNumber;
1466 return STATUS_SUCCESS;
1467 }
1468
1469 /* Try the next slot */
1470 SlotInfo++;
1471 }
1472 }
1473
1474 /* Otherwise, grab the parent FDO and check if it's the root */
1475 if (PCI_IS_ROOT_FDO(ParentExtension))
1476 {
1477 /* The root FDO doesn't have a slot number */
1479 }
1480 else
1481 {
1482 /* Otherwise, query the slot/UI address/number as a device property */
1485 sizeof(ULONG),
1486 SlotNumber,
1487 &ResultLength);
1488 }
1489
1490 /* Return the status of this endeavour */
1491 return Status;
1492}
1493
1495NTAPI
1497 IN OUT PDEVICE_CAPABILITIES DeviceCapability)
1498{
1499 PIRP Irp;
1501 KEVENT Event;
1502 PDEVICE_OBJECT AttachedDevice;
1505 PAGED_CODE();
1506
1507 /* Zero out capabilities and set undefined values to start with */
1508 RtlZeroMemory(DeviceCapability, sizeof(DEVICE_CAPABILITIES));
1509 DeviceCapability->Size = sizeof(DEVICE_CAPABILITIES);
1510 DeviceCapability->Version = 1;
1511 DeviceCapability->Address = -1;
1512 DeviceCapability->UINumber = -1;
1513
1514 /* Build the wait event for the IOCTL */
1516
1517 /* Find the device the PDO is attached to */
1519
1520 /* And build an IRP for it */
1522 AttachedDevice,
1523 NULL,
1524 0,
1525 NULL,
1526 &Event,
1527 &IoStatusBlock);
1528 if (!Irp)
1529 {
1530 /* The IRP failed, fail the request as well */
1531 ObDereferenceObject(AttachedDevice);
1533 }
1534
1535 /* Set default status */
1536 Irp->IoStatus.Information = 0;
1537 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
1538
1539 /* Get a stack location in this IRP */
1542
1543 /* Initialize it as a query capabilities IRP, with no completion routine */
1547 IoStackLocation->Parameters.DeviceCapabilities.Capabilities = DeviceCapability;
1549
1550 /* Send the IOCTL to the driver */
1551 Status = IoCallDriver(AttachedDevice, Irp);
1552 if (Status == STATUS_PENDING)
1553 {
1554 /* Wait for a response and update the actual status */
1556 Executive,
1557 KernelMode,
1558 FALSE,
1559 NULL);
1560 Status = Irp->IoStatus.Status;
1561 }
1562
1563 /* Done, dereference the attached device and return the final result */
1564 ObDereferenceObject(AttachedDevice);
1565 return Status;
1566}
1567
1569NTAPI
1571 IN PDEVICE_CAPABILITIES DeviceCapability)
1572{
1575 DEVICE_CAPABILITIES AttachedCaps;
1576 DEVICE_POWER_STATE NewPowerState, DevicePowerState, DeviceWakeLevel, DeviceWakeState;
1577 SYSTEM_POWER_STATE SystemWakeState, DeepestWakeState, CurrentState;
1578
1579 /* Nothing is known at first */
1580 DeviceWakeState = PowerDeviceUnspecified;
1581 SystemWakeState = DeepestWakeState = PowerSystemUnspecified;
1582
1583 /* Get the PCI capabilities for the parent PDO */
1584 DeviceObject = PdoExtension->ParentFdoExtension->PhysicalDeviceObject;
1587 if (!NT_SUCCESS(Status)) return Status;
1588
1589 /* Check if there's not an existing device state for S0 */
1590 if (!AttachedCaps.DeviceState[PowerSystemWorking])
1591 {
1592 /* Set D0<->S0 mapping */
1593 AttachedCaps.DeviceState[PowerSystemWorking] = PowerDeviceD0;
1594 }
1595
1596 /* Check if there's not an existing device state for S3 */
1597 if (!AttachedCaps.DeviceState[PowerSystemShutdown])
1598 {
1599 /* Set D3<->S3 mapping */
1600 AttachedCaps.DeviceState[PowerSystemShutdown] = PowerDeviceD3;
1601 }
1602
1603 /* Check for a PDO with broken, or no, power capabilities */
1604 if (PdoExtension->HackFlags & PCI_HACK_NO_PM_CAPS)
1605 {
1606 /* Unknown wake device states */
1607 DeviceCapability->DeviceWake = PowerDeviceUnspecified;
1608 DeviceCapability->SystemWake = PowerSystemUnspecified;
1609
1610 /* No device state support */
1611 DeviceCapability->DeviceD1 = FALSE;
1612 DeviceCapability->DeviceD2 = FALSE;
1613
1614 /* No waking from any low-power device state is supported */
1615 DeviceCapability->WakeFromD0 = FALSE;
1616 DeviceCapability->WakeFromD1 = FALSE;
1617 DeviceCapability->WakeFromD2 = FALSE;
1618 DeviceCapability->WakeFromD3 = FALSE;
1619
1620 /* For the rest, copy whatever the parent PDO had */
1621 RtlCopyMemory(DeviceCapability->DeviceState,
1622 AttachedCaps.DeviceState,
1623 sizeof(DeviceCapability->DeviceState));
1624 return STATUS_SUCCESS;
1625 }
1626
1627 /* The PCI Device has power capabilities, so read which ones are supported */
1628 DeviceCapability->DeviceD1 = PdoExtension->PowerCapabilities.Support.D1;
1629 DeviceCapability->DeviceD2 = PdoExtension->PowerCapabilities.Support.D2;
1630 DeviceCapability->WakeFromD0 = PdoExtension->PowerCapabilities.Support.PMED0;
1631 DeviceCapability->WakeFromD1 = PdoExtension->PowerCapabilities.Support.PMED1;
1632 DeviceCapability->WakeFromD2 = PdoExtension->PowerCapabilities.Support.PMED2;
1633
1634 /* Can the attached device wake from D3? */
1635 if (AttachedCaps.DeviceWake != PowerDeviceD3)
1636 {
1637 /* It can't, so check if this PDO supports hot D3 wake */
1638 DeviceCapability->WakeFromD3 = PdoExtension->PowerCapabilities.Support.PMED3Hot;
1639 }
1640 else
1641 {
1642 /* It can, is this the root bus? */
1643 if (PCI_IS_ROOT_FDO(PdoExtension->ParentFdoExtension))
1644 {
1645 /* This is the root bus, so just check if it supports hot D3 wake */
1646 DeviceCapability->WakeFromD3 = PdoExtension->PowerCapabilities.Support.PMED3Hot;
1647 }
1648 else
1649 {
1650 /* The bridge above may be in D3 too, which leaves this device in D3cold */
1651 DeviceCapability->WakeFromD3 = PdoExtension->PowerCapabilities.Support.PMED3Cold;
1652 }
1653 }
1654
1655 /* Now loop each system power state to determine its device state mapping */
1658 CurrentState++)
1659 {
1660 /* Read the current mapping from the attached device */
1661 DevicePowerState = AttachedCaps.DeviceState[CurrentState];
1662 NewPowerState = DevicePowerState;
1663
1664 /* The attachee supports D1, but this PDO does not */
1665 if ((NewPowerState == PowerDeviceD1) &&
1666 !(PdoExtension->PowerCapabilities.Support.D1))
1667 {
1668 /* Fall back to D2 */
1669 NewPowerState = PowerDeviceD2;
1670 }
1671
1672 /* The attachee supports D2, but this PDO does not */
1673 if ((NewPowerState == PowerDeviceD2) &&
1674 !(PdoExtension->PowerCapabilities.Support.D2))
1675 {
1676 /* Fall back to D3 */
1677 NewPowerState = PowerDeviceD3;
1678 }
1679
1680 /* Set the mapping based on the best state supported */
1681 DeviceCapability->DeviceState[CurrentState] = NewPowerState;
1682
1683 /* Check if sleep states are being processed, and a mapping was found */
1685 (NewPowerState != PowerDeviceUnspecified))
1686 {
1687 /* Save this state as being the deepest one found until now */
1688 DeepestWakeState = CurrentState;
1689 }
1690
1691 /*
1692 * Finally, check if the computed sleep state is within the states that
1693 * this device can wake the system from, and if it's higher or equal to
1694 * the sleep state mapping that came from the attachee, assuming that it
1695 * had a valid mapping to begin with.
1696 *
1697 * It this is the case, then make sure that the computed sleep state is
1698 * matched by the device's ability to actually wake from that state.
1699 *
1700 * For devices that support D3, the PCI device only needs Hot D3 as long
1701 * as the attachee's state is less than D3. Otherwise, if the attachee
1702 * might also be at D3, this would require a Cold D3 wake, so check that
1703 * the device actually support this.
1704 */
1705 if ((CurrentState < AttachedCaps.SystemWake) &&
1706 (NewPowerState >= DevicePowerState) &&
1708 (((NewPowerState == PowerDeviceD0) && (DeviceCapability->WakeFromD0)) ||
1709 ((NewPowerState == PowerDeviceD1) && (DeviceCapability->WakeFromD1)) ||
1710 ((NewPowerState == PowerDeviceD2) && (DeviceCapability->WakeFromD2)) ||
1711 ((NewPowerState == PowerDeviceD3) &&
1712 (PdoExtension->PowerCapabilities.Support.PMED3Hot) &&
1714 (PdoExtension->PowerCapabilities.Support.PMED3Cold)))))
1715 {
1716 /* The mapping is valid, so this will be the lowest wake state */
1717 SystemWakeState = CurrentState;
1718 DeviceWakeState = NewPowerState;
1719 }
1720 }
1721
1722 /* Read the current wake level */
1723 DeviceWakeLevel = PdoExtension->PowerState.DeviceWakeLevel;
1724
1725 /* Check if the attachee's wake levels are valid, and the PDO's is higher */
1726 if ((AttachedCaps.SystemWake != PowerSystemUnspecified) &&
1727 (AttachedCaps.DeviceWake != PowerDeviceUnspecified) &&
1728 (DeviceWakeLevel != PowerDeviceUnspecified) &&
1729 (DeviceWakeLevel >= AttachedCaps.DeviceWake))
1730 {
1731 /* Inherit the system wake from the attachee, and this PDO's wake level */
1732 DeviceCapability->SystemWake = AttachedCaps.SystemWake;
1733 DeviceCapability->DeviceWake = DeviceWakeLevel;
1734
1735 /* Now check if the wake level is D0, but the PDO doesn't support it */
1736 if ((DeviceCapability->DeviceWake == PowerDeviceD0) &&
1737 !(DeviceCapability->WakeFromD0))
1738 {
1739 /* Bump to D1 */
1740 DeviceCapability->DeviceWake = PowerDeviceD1;
1741 }
1742
1743 /* Now check if the wake level is D1, but the PDO doesn't support it */
1744 if ((DeviceCapability->DeviceWake == PowerDeviceD1) &&
1745 !(DeviceCapability->WakeFromD1))
1746 {
1747 /* Bump to D2 */
1748 DeviceCapability->DeviceWake = PowerDeviceD2;
1749 }
1750
1751 /* Now check if the wake level is D2, but the PDO doesn't support it */
1752 if ((DeviceCapability->DeviceWake == PowerDeviceD2) &&
1753 !(DeviceCapability->WakeFromD2))
1754 {
1755 /* Bump it to D3 */
1756 DeviceCapability->DeviceWake = PowerDeviceD3;
1757 }
1758
1759 /* Now check if the wake level is D3, but the PDO doesn't support it */
1760 if ((DeviceCapability->DeviceWake == PowerDeviceD3) &&
1761 !(DeviceCapability->WakeFromD3))
1762 {
1763 /* Then no valid wake state exists */
1764 DeviceCapability->DeviceWake = PowerDeviceUnspecified;
1765 DeviceCapability->SystemWake = PowerSystemUnspecified;
1766 }
1767
1768 /* Check if no valid wake state was found */
1769 if ((DeviceCapability->DeviceWake == PowerDeviceUnspecified) ||
1770 (DeviceCapability->SystemWake == PowerSystemUnspecified))
1771 {
1772 /* Check if one was computed earlier */
1773 if ((SystemWakeState != PowerSystemUnspecified) &&
1774 (DeviceWakeState != PowerDeviceUnspecified))
1775 {
1776 /* Use the wake state that had been computed earlier */
1777 DeviceCapability->DeviceWake = DeviceWakeState;
1778 DeviceCapability->SystemWake = SystemWakeState;
1779
1780 /* If that state was D3, then the device supports Hot/Cold D3 */
1781 if (DeviceWakeState == PowerDeviceD3) DeviceCapability->WakeFromD3 = TRUE;
1782 }
1783 }
1784
1785 /*
1786 * Finally, check for off states (lower than S3, such as hibernate) and
1787 * make sure that the device both supports waking from D3 as well as
1788 * supports a Cold wake
1789 */
1790 if ((DeviceCapability->SystemWake > PowerSystemSleeping3) &&
1791 ((DeviceCapability->DeviceWake != PowerDeviceD3) ||
1792 !(PdoExtension->PowerCapabilities.Support.PMED3Cold)))
1793 {
1794 /* It doesn't, so pick the computed lowest wake state from earlier */
1795 DeviceCapability->SystemWake = DeepestWakeState;
1796 }
1797
1798 /* Set the PCI Specification mandated maximum latencies for transitions */
1799 DeviceCapability->D1Latency = 0;
1800 DeviceCapability->D2Latency = 2;
1801 DeviceCapability->D3Latency = 100;
1802
1803 /* Sanity check */
1804 ASSERT(DeviceCapability->DeviceState[PowerSystemWorking] == PowerDeviceD0);
1805 }
1806 else
1807 {
1808 /* No valid sleep states, no latencies to worry about */
1809 DeviceCapability->D1Latency = 0;
1810 DeviceCapability->D2Latency = 0;
1811 DeviceCapability->D3Latency = 0;
1812 }
1813
1814 /* This function always succeeds, even without power management support */
1815 return STATUS_SUCCESS;
1816}
1817
1819NTAPI
1821 IN OUT PDEVICE_CAPABILITIES DeviceCapability)
1822{
1824
1825 /* A PDO ID is never unique, and its address is its function and device */
1826 DeviceCapability->UniqueID = FALSE;
1827 DeviceCapability->Address = PdoExtension->Slot.u.bits.FunctionNumber |
1828 (PdoExtension->Slot.u.bits.DeviceNumber << 16);
1829
1830 /* Check for host bridges */
1831 if ((PdoExtension->BaseClass == PCI_CLASS_BRIDGE_DEV) &&
1832 (PdoExtension->SubClass == PCI_SUBCLASS_BR_HOST))
1833 {
1834 /* Raw device opens to a host bridge are acceptable */
1835 DeviceCapability->RawDeviceOK = TRUE;
1836 }
1837 else
1838 {
1839 /* Otherwise, other PDOs cannot be directly opened */
1840 DeviceCapability->RawDeviceOK = FALSE;
1841 }
1842
1843 /* PCI PDOs are pretty fixed things */
1844 DeviceCapability->LockSupported = FALSE;
1845 DeviceCapability->EjectSupported = FALSE;
1846 DeviceCapability->Removable = FALSE;
1847 DeviceCapability->DockDevice = FALSE;
1848
1849 /* The slot number is stored as a device property, go query it */
1850 PciDetermineSlotNumber(PdoExtension, &DeviceCapability->UINumber);
1851
1852 /* Finally, query and power capabilities and convert them for PnP usage */
1853 Status = PciQueryPowerCapabilities(PdoExtension, DeviceCapability);
1854
1855 /* Dump the capabilities if it all worked, and return the status */
1856 if (NT_SUCCESS(Status)) PciDebugDumpQueryCapabilities(DeviceCapability);
1857 return Status;
1858}
1859
1860/* EOF */
#define PAGED_CODE()
static _Out_opt_ PULONGLONG _Out_opt_ PULONGLONG MinimumAddress
static _Out_opt_ PULONGLONG Start
static _Out_opt_ PULONGLONG _Out_opt_ PULONGLONG _Out_opt_ PULONGLONG MaximumAddress
Type
Definition: Type.h:7
ACPI_METHOD_ARGUMENT UNALIGNED * PACPI_METHOD_ARGUMENT
Definition: acpiioct.h:80
struct _ACPI_EVAL_OUTPUT_BUFFER ACPI_EVAL_OUTPUT_BUFFER
#define ACPI_METHOD_ARGUMENT_INTEGER
Definition: acpiioct.h:30
#define ACPI_EVAL_INPUT_BUFFER_SIGNATURE
Definition: acpiioct.h:12
#define IOCTL_ACPI_EVAL_METHOD
Definition: acpiioct.h:194
ACPI_EVAL_OUTPUT_BUFFER UNALIGNED * PACPI_EVAL_OUTPUT_BUFFER
Definition: acpiioct.h:99
unsigned char BOOLEAN
Definition: actypes.h:127
#define InterlockedDecrement
Definition: armddk.h:52
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
OSVERSIONINFOW VersionInfo
Definition: wkssvc.c:40
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
SINGLE_LIST_ENTRY PciFdoExtensionListHead
Definition: fdo.c:18
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
_In_ ULONG_PTR HackFlags
Definition: cdrom.h:983
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
_Out_ PKIRQL Irql
Definition: csq.h:179
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
_In_ PIO_STATUS_BLOCK IoStatusBlock
Definition: dispmprt.h:608
_Check_return_ _In_ DXGK_EVENT_TYPE _In_ ULONG _In_ PVOID Argument
Definition: dispmprt.h:1288
_Check_return_ _In_ DXGK_EVENT_TYPE _In_ ULONG Event
Definition: dispmprt.h:1287
_Check_return_ _In_ ULONG _In_ DEVICE_POWER_STATE DevicePowerState
Definition: dispmprt.h:1274
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
VOID NTAPI PciDebugDumpQueryCapabilities(IN PDEVICE_CAPABILITIES DeviceCaps)
Definition: debug.c:221
BOOLEAN NTAPI PcipIsSameDevice(IN PPCI_PDO_EXTENSION DeviceExtension, IN PPCI_COMMON_HEADER PciData)
Definition: enum.c:1333
PPCI_IRQ_ROUTING_TABLE PciIrqRoutingTable
Definition: init.c:26
PPCI_HACK_ENTRY PciHackTable
Definition: init.c:28
#define MAX_DEBUGGING_DEVICES_SUPPORTED
Definition: pci.h:116
VOID NTAPI PciWriteDeviceConfig(IN PPCI_PDO_EXTENSION DeviceExtension, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: config.c:133
enum _PCI_SIGNATURE PCI_SIGNATURE
#define PCI_HACK_HAS_REVISION_INFO
Definition: pci.h:61
#define PCI_IS_ROOT_FDO(x)
Definition: pci.h:42
struct _PCI_IPI_CONTEXT * PPCI_IPI_CONTEXT
@ PciTypeHostBridge
Definition: pci.h:157
@ PciTypeDevice
Definition: pci.h:160
@ PciTypePciBridge
Definition: pci.h:158
@ PciTypeCardbusBridge
Definition: pci.h:159
#define PCI_POOL_TAG
Definition: pci.h:27
KIPI_BROADCAST_WORKER PciExecuteCriticalSystemRoutine
Definition: pci.h:1204
VOID NTAPI PciReadDeviceConfig(IN PPCI_PDO_EXTENSION DeviceExtension, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: config.c:149
#define PCI_HACK_HAS_SUBSYSTEM_INFO
Definition: pci.h:62
enum _PCI_DEVICE_TYPES PCI_DEVICE_TYPES
struct _PCI_FDO_EXTENSION * PPCI_FDO_EXTENSION
@ PciPdoExtensionType
Definition: pci.h:133
BOOLEAN NTAPI PciIsSuiteVersion(IN USHORT SuiteMask)
Definition: utils.c:115
NTSTATUS NTAPI PciSaveBiosConfig(IN PPCI_PDO_EXTENSION DeviceExtension, IN PPCI_COMMON_HEADER PciData)
Definition: utils.c:903
VOID NTAPI PciInsertEntryAtTail(IN PSINGLE_LIST_ENTRY ListHead, IN PPCI_FDO_EXTENSION DeviceExtension, IN PKEVENT Lock)
Definition: utils.c:400
NTSTATUS NTAPI PciQueryBusInformation(IN PPCI_PDO_EXTENSION PdoExtension, OUT PPNP_BUS_INFORMATION *Buffer)
Definition: utils.c:1408
PPCI_SECONDARY_EXTENSION NTAPI PciFindNextSecondaryExtension(IN PSINGLE_LIST_ENTRY ListHead, IN PCI_SIGNATURE ExtensionType)
Definition: utils.c:584
BOOLEAN NTAPI PciIsSlotPresentInParentMethod(IN PPCI_PDO_EXTENSION PdoExtension, IN ULONG Method)
Definition: utils.c:1169
NTSTATUS NTAPI PciGetDeviceCapabilities(IN PDEVICE_OBJECT DeviceObject, IN OUT PDEVICE_CAPABILITIES DeviceCapability)
Definition: utils.c:1496
NTSTATUS NTAPI PciQueryPowerCapabilities(IN PPCI_PDO_EXTENSION PdoExtension, IN PDEVICE_CAPABILITIES DeviceCapability)
Definition: utils.c:1570
PCI_DEVICE_TYPES NTAPI PciClassifyDeviceType(IN PPCI_PDO_EXTENSION PdoExtension)
Definition: utils.c:1126
NTSTATUS NTAPI PciQueryCapabilities(IN PPCI_PDO_EXTENSION PdoExtension, IN OUT PDEVICE_CAPABILITIES DeviceCapability)
Definition: utils.c:1820
VOID NTAPI PciInsertEntryAtHead(IN PSINGLE_LIST_ENTRY ListHead, IN PSINGLE_LIST_ENTRY Entry, IN PKEVENT Lock)
Definition: utils.c:430
NTSTATUS NTAPI PciDetermineSlotNumber(IN PPCI_PDO_EXTENSION PdoExtension, OUT PULONG SlotNumber)
Definition: utils.c:1431
ULONG PciDebugPortsCount
Definition: utils.c:19
NTSTATUS NTAPI PciGetBiosConfig(IN PPCI_PDO_EXTENSION DeviceExtension, OUT PPCI_COMMON_HEADER PciData)
Definition: utils.c:840
VOID NTAPI PcipLinkSecondaryExtension(IN PSINGLE_LIST_ENTRY List, IN PVOID Lock, IN PPCI_SECONDARY_EXTENSION SecondaryExtension, IN PCI_SIGNATURE ExtensionType, IN PVOID Destructor)
Definition: utils.c:459
PCI_DEBUGGING_DEVICE PciDebuggingDevices[MAX_DEBUGGING_DEVICES_SUPPORTED]
Definition: utils.c:18
PPCI_PDO_EXTENSION NTAPI PciFindPdoByFunction(IN PPCI_FDO_EXTENSION DeviceExtension, IN ULONG FunctionNumber, IN PPCI_COMMON_HEADER PciData)
Definition: utils.c:695
BOOLEAN NTAPI PciOpenKey(IN PWCHAR KeyName, IN HANDLE RootKey, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle, OUT PNTSTATUS KeyStatus)
Definition: utils.c:166
static BOOLEAN PciGetBiosBusRange(_In_ PPCI_PDO_EXTENSION BridgeExtension, _Out_ PUCHAR SecondaryBus, _Out_ PUCHAR SubordinateBus)
Reads the bus range the firmware gave a bridge.
Definition: utils.c:754
BOOLEAN NTAPI PciIsDeviceOnDebugPath(_In_ PPCI_PDO_EXTENSION DeviceExtension)
Definition: utils.c:780
VOID NTAPI PciDecodeEnable(IN PPCI_PDO_EXTENSION PdoExtension, IN BOOLEAN Enable, OUT PUSHORT Command)
Definition: utils.c:1359
RTL_RANGE_LIST PciVgaAndIsaBitExclusionList
Definition: utils.c:22
BOOLEAN NTAPI PciIsCriticalDeviceClass(IN UCHAR BaseClass, IN UCHAR SubClass)
Definition: utils.c:672
UCHAR NTAPI PciReadDeviceCapability(IN PPCI_PDO_EXTENSION DeviceExtension, IN UCHAR Offset, IN ULONG CapabilityId, OUT PPCI_CAPABILITIES_HEADER Buffer, IN ULONG Length)
Definition: utils.c:958
BOOLEAN NTAPI PciStringToUSHORT(IN PWCHAR String, OUT PUSHORT Value)
Definition: utils.c:62
ULONGLONG NTAPI PciGetHackFlags(IN USHORT VendorId, IN USHORT DeviceId, IN USHORT SubVendorId, IN USHORT SubSystemId, IN UCHAR RevisionId)
Definition: utils.c:604
BOOLEAN NTAPI PciCanDisableDecodes(IN PPCI_PDO_EXTENSION DeviceExtension, IN PPCI_COMMON_HEADER Config, IN ULONGLONG HackFlags, IN BOOLEAN ForPowerDown)
Definition: utils.c:1027
PPCI_FDO_EXTENSION NTAPI PciFindParentPciFdoExtension(IN PDEVICE_OBJECT DeviceObject, IN PKEVENT Lock)
Definition: utils.c:340
NTSTATUS NTAPI PciGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, OUT PVOID *OutputBuffer)
Definition: utils.c:475
NTSTATUS NTAPI PciGetRegistryValue(IN PWCHAR ValueName, IN PWCHAR KeyName, IN HANDLE RootHandle, IN ULONG Type, OUT PVOID *OutputBuffer, OUT PULONG OutputLength)
Definition: utils.c:193
BOOLEAN NTAPI PciUnicodeStringStrStr(IN PUNICODE_STRING InputString, IN PCUNICODE_STRING EqualString, IN BOOLEAN CaseInSensitive)
Definition: utils.c:28
NTSTATUS NTAPI PciBuildDefaultExclusionLists(VOID)
Definition: utils.c:276
BOOLEAN NTAPI PciCreateIoDescriptorFromBarLimit(_Out_ PIO_RESOURCE_DESCRIPTOR ResourceDescriptor, _In_ ULONG Bar, _In_ ULONG NextBar, _In_ BOOLEAN Rom)
Builds the requirement of a BAR from the value it reads back after all ones were written to it.
Definition: utils.c:1252
BOOLEAN NTAPI PciIsDatacenter(VOID)
Definition: utils.c:132
RTL_RANGE_LIST PciIsaBitExclusionList
Definition: utils.c:21
NTSTATUS NTAPI PciSendIoctl(IN PDEVICE_OBJECT DeviceObject, IN ULONG IoControlCode, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength)
Definition: utils.c:531
@ PdoExtension
Definition: precomp.h:61
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define PagedPool
Definition: env_spec_w32.h:308
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
unsigned int Mask
Definition: fpcontrol.c:82
union Alignment_ Alignment
short Short
Definition: ftraster.c:309
Status
Definition: gdiplustypes.h:24
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
_In_ PIRP Irp
Definition: kse.h:79
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_ PVOID Context
Definition: kse.h:81
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
void Bar(void)
Definition: terminate.cpp:70
* PNTSTATUS
Definition: strlen.c:14
#define _swprintf(buf, format,...)
Definition: sprintf.c:56
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ PNDIS_STRING _Out_ PNDIS_HANDLE SubKeyHandle
Definition: ndis.h:4726
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
#define CM_RESOURCE_MEMORY_PREFETCHABLE
Definition: cmtypes.h:125
#define CM_RESOURCE_PORT_IO
Definition: cmtypes.h:109
#define CM_RESOURCE_MEMORY_READ_ONLY
Definition: cmtypes.h:122
#define KernelMode
Definition: asm.h:38
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI NTSTATUS NTAPI RtlAddRange(_Inout_ PRTL_RANGE_LIST RangeList, _In_ ULONGLONG Start, _In_ ULONGLONG End, _In_ UCHAR Attributes, _In_ ULONG Flags, _In_opt_ PVOID UserData, _In_opt_ PVOID Owner)
_In_ const STRING _In_ BOOLEAN CaseInSensitive
Definition: rtlfuncs.h:2437
NTSYSAPI VOID NTAPI RtlInitializeRangeList(_Out_ PRTL_RANGE_LIST RangeList)
NTSYSAPI VOID NTAPI RtlFreeRangeList(_In_ PRTL_RANGE_LIST RangeList)
#define RTL_RANGE_LIST_ADD_IF_CONFLICT
Definition: rtltypes.h:81
#define VER_AND
Definition: rtltypes.h:252
#define VER_SUITENAME
Definition: rtltypes.h:242
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define REG_BINARY
Definition: nt_native.h:1499
@ KeyValuePartialInformation
Definition: nt_native.h:1185
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define KEY_READ
Definition: nt_native.h:1026
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
ULONG ACCESS_MASK
Definition: nt_native.h:40
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define KEY_QUERY_VALUE
Definition: nt_native.h:1019
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
#define KEY_WRITE
Definition: nt_native.h:1034
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1063
#define VER_SUITE_DATACENTER
#define VER_SET_CONDITION(ConditionMask, TypeBitMask, ComparisonType)
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142
@ SynchronizationEvent
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1416
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1101
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:913
#define IoCallDriver
Definition: irp.c:1257
@ PowerSystemMaximum
Definition: ntpoapi.h:42
@ PowerSystemUnspecified
Definition: ntpoapi.h:35
@ PowerSystemSleeping3
Definition: ntpoapi.h:39
@ PowerSystemShutdown
Definition: ntpoapi.h:41
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerSystemHibernate
Definition: ntpoapi.h:40
@ PowerDeviceD1
Definition: ntpoapi.h:50
@ PowerDeviceUnspecified
Definition: ntpoapi.h:48
@ PowerDeviceD0
Definition: ntpoapi.h:49
@ PowerDeviceD2
Definition: ntpoapi.h:51
@ PowerDeviceD3
Definition: ntpoapi.h:52
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE
enum _SYSTEM_POWER_STATE SYSTEM_POWER_STATE
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
short WCHAR
Definition: pedump.c:58
long LONG
Definition: pedump.c:60
unsigned short USHORT
Definition: pedump.c:61
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:1621
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:1382
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define CmResourceTypeNull
Definition: restypes.h:103
#define CmResourceTypeMemory
Definition: restypes.h:106
@ PCIBus
Definition: restypes.h:127
#define CmResourceTypePort
Definition: restypes.h:104
#define UNIMPLEMENTED_FATAL(...)
Definition: debug.h:244
#define PCI_HACK_PRESERVE_COMMAND
Definition: pci.h:25
#define PCI_ENABLE_BRIDGE_VGA
Definition: pci.h:63
#define PCI_HACK_CB_SHARE_CMD_BITS
Definition: pci.h:27
#define PCI_HACK_NEVER_DISCONNECT
Definition: pci.h:17
#define PCI_HACK_DONT_DISABLE
Definition: pci.h:18
#define PCI_HACK_NEVER_POWER_DOWN
Definition: pci.h:41
#define PCI_HACK_NO_PM_CAPS
Definition: pci.h:40
#define PCI_HACK_KEEP_DECODES_ON_STOP
Definition: pci.h:12
static PMEMKEY RootKey
Definition: registry.c:55
Entry
Definition: section.c:5216
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define DPRINT
Definition: sndvol32.h:73
@ High
Definition: strmini.h:378
@ Low
Definition: strmini.h:380
Definition: shell.h:41
PVOID DeviceExtension
Definition: env_spec_w32.h:418
struct _IO_STACK_LOCATION::@5020::@5047 DeviceCapabilities
union _IO_STACK_LOCATION::@1814 Parameters
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:246
PCI_SLOT_NUMBER Slot
Definition: pci.h:297
PDEVICE_OBJECT PhysicalDeviceObject
Definition: pci.h:249
struct _PCI_FDO_EXTENSION * ParentFdoExtension
Definition: pci.h:255
SINGLE_LIST_ENTRY List
Definition: pci.h:243
struct _PCI_PDO_EXTENSION * ChildPdoList
Definition: pci.h:253
BOOLEAN BaseBus
Definition: pci.h:260
KEVENT ChildListLock
Definition: pci.h:252
Definition: pci.h:192
ULONGLONG HackFlags
Definition: pci.h:197
USHORT SubSystemID
Definition: pci.h:196
USHORT VendorID
Definition: pci.h:193
USHORT RevisionID
Definition: pci.h:198
USHORT DeviceID
Definition: pci.h:194
UCHAR Flags
Definition: pci.h:199
USHORT SubVendorID
Definition: pci.h:195
PCI_IPI_FUNCTION Function
Definition: pci.h:579
SLOT_INFO Slot[ANYSIZE_ARRAY]
Definition: pci.h:102
USHORT TableSize
Definition: pci.h:94
PVOID Next
Definition: pci.h:325
union _PCI_SLOT_NUMBER::@5064 u
INTERFACE_TYPE LegacyBusType
Definition: cmtypes.h:366
Definition: ntbasedef.h:640
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:641
Definition: pci.h:79
UCHAR DeviceNumber
Definition: pci.h:81
UCHAR BusNumber
Definition: pci.h:80
UCHAR SlotNumber
Definition: pci.h:83
USHORT MaximumLength
Definition: env_spec_w32.h:370
PBIOS_DATA BiosData
Definition: bios.c:42
#define STATUS_PENDING
Definition: telnetd.h:14
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: typedefs.h:53
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
uint64_t ULONGLONG
Definition: typedefs.h:67
uint16_t * PUSHORT
Definition: typedefs.h:56
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
_In_ PGUID _In_ ULONG _Out_ PULONG ResultLength
Definition: ucxcontroller.h:83
_Must_inspect_result_ _In_ WDFDEVICE _In_ PUCX_CONTROLLER_CONFIG Config
_In_ PGUID _In_ ULONG OutputBufferLength
Definition: ucxcontroller.h:81
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIO_STACK_LOCATION IoStackLocation
Definition: usbdlib.h:292
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2664
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty
Definition: wdfdevice.h:3775
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3777
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2439
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:68
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127
NTSYSAPI NTSTATUS WINAPI RtlVerifyVersionInfo(const RTL_OSVERSIONINFOEXW *, DWORD, DWORDLONG)
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2702
#define PCI_TYPE_64BIT
Definition: iotypes.h:4255
DEVICE_CAPABILITIES
Definition: iotypes.h:965
#define PCI_INVALID_VENDORID
Definition: iotypes.h:3616
#define PCI_SUBCLASS_BR_OTHER
Definition: iotypes.h:4186
#define PCI_ADDRESS_IO_ADDRESS_MASK
Definition: iotypes.h:4249
#define PCI_ENABLE_BUS_MASTER
Definition: iotypes.h:3633
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define PCI_SUBCLASS_BR_EISA
Definition: iotypes.h:4179
#define PCI_SUBCLASS_BR_HOST
Definition: iotypes.h:4177
#define PCI_ENABLE_IO_SPACE
Definition: iotypes.h:3631
#define PCI_SUBCLASS_BR_PCI_TO_PCI
Definition: iotypes.h:4181
#define PCI_SUBCLASS_SYS_INTERRUPT_CTLR
Definition: iotypes.h:4194
#define PCI_ADDRESS_IO_SPACE
Definition: iotypes.h:4246
#define PCI_ENABLE_MEMORY_SPACE
Definition: iotypes.h:3632
#define PCI_SUBCLASS_BR_MCA
Definition: iotypes.h:4180
DEVICE_REGISTRY_PROPERTY
Definition: iotypes.h:1194
@ DevicePropertyUINumber
Definition: iotypes.h:1212
#define PCI_BRIDGE_TYPE
Definition: iotypes.h:3621
#define PCI_TYPE_20BIT
Definition: iotypes.h:4254
#define PCI_ADDRESS_ROM_ADDRESS_MASK
Definition: iotypes.h:4251
#define PCI_ADDRESS_MEMORY_ADDRESS_MASK
Definition: iotypes.h:4250
#define PCI_COMMON_HDR_LENGTH
Definition: iotypes.h:3609
#define PCI_SUBCLASS_BR_ISA
Definition: iotypes.h:4178
#define PCI_CLASS_BRIDGE_DEV
Definition: iotypes.h:4124
#define IRP_MN_QUERY_CAPABILITIES
#define PCI_SUBCLASS_BR_CARDBUS
Definition: iotypes.h:4184
#define PCI_CLASS_PRE_20
Definition: iotypes.h:4118
* PDEVICE_CAPABILITIES
Definition: iotypes.h:965
#define PCI_CLASS_BASE_SYSTEM_DEV
Definition: iotypes.h:4126
#define PCI_SUBCLASS_VID_VGA_CTLR
Definition: iotypes.h:4160
#define PCI_ADDRESS_MEMORY_PREFETCHABLE
Definition: iotypes.h:4248
#define PCI_ADDRESS_MEMORY_TYPE_MASK
Definition: iotypes.h:4247
#define PCI_SUBCLASS_PRE_20_VGA
Definition: iotypes.h:4140
#define PCI_CLASS_DISPLAY_CTLR
Definition: iotypes.h:4121
#define PCI_CARDBUS_BRIDGE_TYPE
Definition: iotypes.h:3622
@ Executive
Definition: ketypes.h:467
#define ObDereferenceObject
Definition: obfuncs.h:203
NTSYSAPI NTSTATUS NTAPI RtlIoEncodeMemIoResource(_In_ struct _IO_RESOURCE_DESCRIPTOR *Descriptor, _In_ UCHAR Type, _In_ ULONGLONG Length, _In_ ULONGLONG Alignment, _In_ ULONGLONG MinimumAddress, _In_ ULONGLONG MaximumAddress)
struct _OSVERSIONINFOEXW RTL_OSVERSIONINFOEXW
_Out_opt_ PBOOLEAN CurrentState
Definition: zwfuncs.h:393