ReactOS  0.4.15-dev-2704-gd5265b0
pnpreport.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for pnpreport.c:

Go to the source code of this file.

Classes

struct  _INTERNAL_WORK_QUEUE_ITEM
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _INTERNAL_WORK_QUEUE_ITEM INTERNAL_WORK_QUEUE_ITEM
 
typedef struct _INTERNAL_WORK_QUEUE_ITEMPINTERNAL_WORK_QUEUE_ITEM
 

Functions

NTSTATUS IopSetDeviceInstanceData (HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
 
NTSTATUS PpSetCustomTargetEvent (IN PDEVICE_OBJECT DeviceObject, IN OUT PKEVENT SyncEvent OPTIONAL, IN OUT PNTSTATUS SyncStatus OPTIONAL, IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback OPTIONAL, IN PVOID Context OPTIONAL, IN PTARGET_DEVICE_CUSTOM_NOTIFICATION NotificationStructure)
 
PWCHAR IopGetInterfaceTypeString (INTERFACE_TYPE IfType)
 
VOID NTAPI IopReportTargetDeviceChangeAsyncWorker (PVOID Context)
 
NTSTATUS NTAPI IoReportDetectedDevice (_In_ PDRIVER_OBJECT DriverObject, _In_ INTERFACE_TYPE LegacyBusType, _In_ ULONG BusNumber, _In_ ULONG SlotNumber, _In_opt_ PCM_RESOURCE_LIST ResourceList, _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements, _In_ BOOLEAN ResourceAssigned, _Inout_ PDEVICE_OBJECT *DeviceObject)
 
NTSTATUS NTAPI IoReportResourceForDetection (IN PDRIVER_OBJECT DriverObject, IN PCM_RESOURCE_LIST DriverList OPTIONAL, IN ULONG DriverListSize OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PCM_RESOURCE_LIST DeviceList OPTIONAL, IN ULONG DeviceListSize OPTIONAL, OUT PBOOLEAN ConflictDetected)
 
VOID NTAPI IopSetEvent (IN PVOID Context)
 
NTSTATUS NTAPI IoReportTargetDeviceChange (IN PDEVICE_OBJECT PhysicalDeviceObject, IN PVOID NotificationStructure)
 
NTSTATUS NTAPI IoReportTargetDeviceChangeAsynchronous (IN PDEVICE_OBJECT PhysicalDeviceObject, IN PVOID NotificationStructure, IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback OPTIONAL, IN PVOID Context OPTIONAL)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file pnpreport.c.

Typedef Documentation

◆ INTERNAL_WORK_QUEUE_ITEM

◆ PINTERNAL_WORK_QUEUE_ITEM

Function Documentation

◆ IopGetInterfaceTypeString()

PWCHAR IopGetInterfaceTypeString ( INTERFACE_TYPE  IfType)

Definition at line 42 of file pnpreport.c.

43 {
44  switch (IfType)
45  {
46  case Internal:
47  return L"Internal";
48 
49  case Isa:
50  return L"Isa";
51 
52  case Eisa:
53  return L"Eisa";
54 
55  case MicroChannel:
56  return L"MicroChannel";
57 
58  case TurboChannel:
59  return L"TurboChannel";
60 
61  case PCIBus:
62  return L"PCIBus";
63 
64  case VMEBus:
65  return L"VMEBus";
66 
67  case NuBus:
68  return L"NuBus";
69 
70  case PCMCIABus:
71  return L"PCMCIABus";
72 
73  case CBus:
74  return L"CBus";
75 
76  case MPIBus:
77  return L"MPIBus";
78 
79  case MPSABus:
80  return L"MPSABus";
81 
82  case ProcessorInternal:
83  return L"ProcessorInternal";
84 
85  case PNPISABus:
86  return L"PNPISABus";
87 
88  case PNPBus:
89  return L"PNPBus";
90 
91  case Vmcs:
92  return L"Vmcs";
93 
94  default:
95  DPRINT1("Invalid bus type: %d\n", IfType);
96  return NULL;
97  }
98 }
static const WCHAR L[]
Definition: oid.c:1250
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8

Referenced by IoReportDetectedDevice().

◆ IopReportTargetDeviceChangeAsyncWorker()

VOID NTAPI IopReportTargetDeviceChangeAsyncWorker ( PVOID  Context)

Definition at line 102 of file pnpreport.c.

103 {
105 
107  PpSetCustomTargetEvent(Item->PhysicalDeviceObject, NULL, NULL, Item->Callback, Item->Context, Item->NotificationStructure);
108  ObDereferenceObject(Item->PhysicalDeviceObject);
109  ExFreePoolWithTag(Context, ' pP');
110 }
struct _INTERNAL_WORK_QUEUE_ITEM * PINTERNAL_WORK_QUEUE_ITEM
NTSTATUS PpSetCustomTargetEvent(IN PDEVICE_OBJECT DeviceObject, IN OUT PKEVENT SyncEvent OPTIONAL, IN OUT PNTSTATUS SyncStatus OPTIONAL, IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback OPTIONAL, IN PVOID Context OPTIONAL, IN PTARGET_DEVICE_CUSTOM_NOTIFICATION NotificationStructure)
Definition: pnpreport.c:113
#define ObDereferenceObject
Definition: obfuncs.h:203
#define NULL
Definition: types.h:112
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by IoReportTargetDeviceChangeAsynchronous().

◆ IopSetDeviceInstanceData()

NTSTATUS IopSetDeviceInstanceData ( HANDLE  InstanceKey,
PDEVICE_NODE  DeviceNode 
)

Definition at line 607 of file pnpmgr.c.

609 {
612  HANDLE LogConfKey, ControlKey, DeviceParamsKey;
613  ULONG ResCount;
616 
617  DPRINT("IopSetDeviceInstanceData() called\n");
618 
619  /* Create the 'LogConf' key */
620  RtlInitUnicodeString(&KeyName, L"LogConf");
622  &KeyName,
624  InstanceKey,
625  NULL);
626  Status = ZwCreateKey(&LogConfKey,
629  0,
630  NULL,
631  // FIXME? In r53694 it was silently turned from non-volatile into this,
632  // without any extra warning. Is this still needed??
634  NULL);
635  if (NT_SUCCESS(Status))
636  {
637  /* Set 'BootConfig' value */
638  if (DeviceNode->BootResources != NULL)
639  {
640  ResCount = DeviceNode->BootResources->Count;
641  if (ResCount != 0)
642  {
643  RtlInitUnicodeString(&KeyName, L"BootConfig");
644  Status = ZwSetValueKey(LogConfKey,
645  &KeyName,
646  0,
648  DeviceNode->BootResources,
649  PnpDetermineResourceListSize(DeviceNode->BootResources));
650  }
651  }
652 
653  /* Set 'BasicConfigVector' value */
654  if (DeviceNode->ResourceRequirements != NULL &&
655  DeviceNode->ResourceRequirements->ListSize != 0)
656  {
657  RtlInitUnicodeString(&KeyName, L"BasicConfigVector");
658  Status = ZwSetValueKey(LogConfKey,
659  &KeyName,
660  0,
662  DeviceNode->ResourceRequirements,
663  DeviceNode->ResourceRequirements->ListSize);
664  }
665 
666  ZwClose(LogConfKey);
667  }
668 
669  /* Set the 'ConfigFlags' value */
670  RtlInitUnicodeString(&KeyName, L"ConfigFlags");
671  Status = ZwQueryValueKey(InstanceKey,
672  &KeyName,
674  NULL,
675  0,
676  &ResultLength);
678  {
679  /* Write the default value */
680  ULONG DefaultConfigFlags = 0;
681  Status = ZwSetValueKey(InstanceKey,
682  &KeyName,
683  0,
684  REG_DWORD,
685  &DefaultConfigFlags,
686  sizeof(DefaultConfigFlags));
687  }
688 
689  /* Create the 'Control' key */
690  RtlInitUnicodeString(&KeyName, L"Control");
692  &KeyName,
694  InstanceKey,
695  NULL);
696  Status = ZwCreateKey(&ControlKey,
697  0,
699  0,
700  NULL,
702  NULL);
703  if (NT_SUCCESS(Status))
704  ZwClose(ControlKey);
705 
706  /* Create the 'Device Parameters' key and set the 'FirmwareIdentified' value for all ACPI-enumerated devices */
707  if (_wcsnicmp(DeviceNode->InstancePath.Buffer, L"ACPI\\", 5) == 0)
708  {
709  RtlInitUnicodeString(&KeyName, L"Device Parameters");
711  &KeyName,
713  InstanceKey,
714  NULL);
715  Status = ZwCreateKey(&DeviceParamsKey,
716  0,
718  0,
719  NULL,
721  NULL);
722  if (NT_SUCCESS(Status))
723  {
724  ULONG FirmwareIdentified = 1;
725  RtlInitUnicodeString(&KeyName, L"FirmwareIdentified");
726  Status = ZwSetValueKey(DeviceParamsKey,
727  &KeyName,
728  0,
729  REG_DWORD,
730  &FirmwareIdentified,
731  sizeof(FirmwareIdentified));
732 
733  ZwClose(DeviceParamsKey);
734  }
735  }
736 
737  DPRINT("IopSetDeviceInstanceData() done\n");
738 
739  return Status;
740 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define REG_RESOURCE_REQUIREMENTS_LIST
Definition: nt_native.h:1504
#define REG_RESOURCE_LIST
Definition: nt_native.h:1502
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
Status
Definition: gdiplustypes.h:24
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: Node.h:9
static const WCHAR L[]
Definition: oid.c:1250
ULONG NTAPI PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList)
Definition: pnpmgr.c:1808
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define DPRINT
Definition: sndvol32.h:71
#define REG_DWORD
Definition: sdbapi.c:596

Referenced by IoReportDetectedDevice().

◆ IopSetEvent()

VOID NTAPI IopSetEvent ( IN PVOID  Context)

Definition at line 397 of file pnpreport.c.

398 {
400 
401  /* Set the event */
403 }
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117
struct tagContext Context
Definition: acpixf.h:1034
#define IO_NO_INCREMENT
Definition: iotypes.h:598

◆ IoReportDetectedDevice()

NTSTATUS NTAPI IoReportDetectedDevice ( _In_ PDRIVER_OBJECT  DriverObject,
_In_ INTERFACE_TYPE  LegacyBusType,
_In_ ULONG  BusNumber,
_In_ ULONG  SlotNumber,
_In_opt_ PCM_RESOURCE_LIST  ResourceList,
_In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST  ResourceRequirements,
_In_ BOOLEAN  ResourceAssigned,
_Inout_ PDEVICE_OBJECT DeviceObject 
)

Definition at line 148 of file pnpreport.c.

157 {
161  HANDLE InstanceKey;
162  UNICODE_STRING ValueName, ServiceLongName, ServiceName;
163  WCHAR HardwareId[256];
164  PWCHAR IfString;
165  ULONG IdLength;
166  ULONG LegacyValue;
167 
168  DPRINT("IoReportDetectedDevice (DeviceObject %p, *DeviceObject %p)\n",
170 
171  ServiceLongName = DriverObject->DriverExtension->ServiceKeyName;
172  ServiceName = ServiceLongName;
173 
174  /* If the interface type is unknown, treat it as internal */
177 
178  /* Get the string equivalent of the interface type */
180 
181  /* If NULL is returned then it's a bad type */
182  if (!IfString)
184 
185  /*
186  * Drivers that have been created via a direct IoCreateDriver() call
187  * have their ServiceKeyName set to \Driver\DriverName. We need to
188  * strip everything up to the last path separator and keep what remains.
189  */
190  if (DriverObject->Flags & DRVO_BUILTIN_DRIVER)
191  {
192  /*
193  * Find the last path separator.
194  * NOTE: Since ServiceName is not necessarily NULL-terminated,
195  * we cannot use wcsrchr().
196  */
197  if (ServiceName.Buffer && ServiceName.Length >= sizeof(WCHAR))
198  {
199  ValueName.Length = 1;
200  ValueName.Buffer = ServiceName.Buffer + (ServiceName.Length / sizeof(WCHAR)) - 1;
201 
202  while ((ValueName.Buffer > ServiceName.Buffer) && (*ValueName.Buffer != L'\\'))
203  {
204  --ValueName.Buffer;
205  ++ValueName.Length;
206  }
207  if (*ValueName.Buffer == L'\\')
208  {
209  ++ValueName.Buffer;
210  --ValueName.Length;
211  }
212  ValueName.Length *= sizeof(WCHAR);
213 
214  /* Shorten the string */
215  ServiceName.MaximumLength -= (ServiceName.Length - ValueName.Length);
216  ServiceName.Length = ValueName.Length;
217  ServiceName.Buffer = ValueName.Buffer;
218  }
219  }
220 
221  /* We use the caller's PDO if they supplied one */
222  UNICODE_STRING instancePath;
223  if (DeviceObject && *DeviceObject)
224  {
225  Pdo = *DeviceObject;
226  }
227  else
228  {
229  /* Create the PDO */
230  Status = PnpRootCreateDevice(&ServiceName, NULL, &Pdo, &instancePath);
231  if (!NT_SUCCESS(Status))
232  {
233  DPRINT("PnpRootCreateDevice() failed (Status 0x%08lx)\n", Status);
234  return Status;
235  }
236  }
237 
238  /* Create the device node for the new PDO */
240  if (!DeviceNode)
241  {
242  DPRINT("PipAllocateDeviceNode() failed\n");
244  }
245 
246  Status = RtlDuplicateUnicodeString(0, &instancePath, &DeviceNode->InstancePath);
247 
248  /* Open a handle to the instance path key */
249  Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_NON_VOLATILE, &InstanceKey);
250  if (!NT_SUCCESS(Status))
251  return Status;
252 
253  /* Save the driver name */
254  RtlInitUnicodeString(&ValueName, L"Service");
255  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_SZ, ServiceLongName.Buffer, ServiceLongName.Length + sizeof(UNICODE_NULL));
256  if (!NT_SUCCESS(Status))
257  {
258  DPRINT("Failed to write the Service name value: 0x%x\n", Status);
259  }
260 
261  /* Report as non-legacy driver */
262  RtlInitUnicodeString(&ValueName, L"Legacy");
263  LegacyValue = 0;
264  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_DWORD, &LegacyValue, sizeof(LegacyValue));
265  if (!NT_SUCCESS(Status))
266  {
267  DPRINT("Failed to write the Legacy value: 0x%x\n", Status);
268  }
269 
270  /* Add DETECTEDInterfaceType\DriverName */
271  IdLength = 0;
272  IdLength += swprintf(&HardwareId[IdLength],
273  L"DETECTED%ls\\%wZ",
274  IfString,
275  &ServiceName);
276  IdLength++;
277 
278  /* Add DETECTED\DriverName */
279  IdLength += swprintf(&HardwareId[IdLength],
280  L"DETECTED\\%wZ",
281  &ServiceName);
282  IdLength++;
283 
284  /* Terminate the string with another null */
285  HardwareId[IdLength++] = UNICODE_NULL;
286 
287  /* Store the value for CompatibleIDs */
288  RtlInitUnicodeString(&ValueName, L"CompatibleIDs");
289  Status = ZwSetValueKey(InstanceKey, &ValueName, 0, REG_MULTI_SZ, HardwareId, IdLength * sizeof(WCHAR));
290  if (!NT_SUCCESS(Status))
291  {
292  DPRINT("Failed to write the compatible IDs: 0x%x\n", Status);
293  ZwClose(InstanceKey);
294  return Status;
295  }
296 
297  // Set the device's DeviceDesc and LocationInformation fields
298  PiSetDevNodeText(DeviceNode, InstanceKey);
299 
300  /* Assign the resources to the device node */
301  DeviceNode->BootResources = ResourceList;
302  DeviceNode->ResourceRequirements = ResourceRequirements;
303 
304  /* Set appropriate flags */
305  if (DeviceNode->BootResources)
307 
308  if (!DeviceNode->ResourceRequirements && !DeviceNode->BootResources)
310 
311  /* Write the resource information to the registry */
312  IopSetDeviceInstanceData(InstanceKey, DeviceNode);
313 
314  /* If the caller didn't get the resources assigned for us, do it now */
315  if (!ResourceAssigned)
316  {
318 
319  /* See if we failed */
320  if (!NT_SUCCESS(Status))
321  {
322  DPRINT("Assigning resources failed: 0x%x\n", Status);
323  ZwClose(InstanceKey);
324  return Status;
325  }
326  }
327 
328  /* Close the instance key handle */
329  ZwClose(InstanceKey);
330 
331  /* Register the given DO with PnP root if required */
332  if (DeviceObject && *DeviceObject)
334 
337 
338  // we still need to query IDs, send events and reenumerate this node
340 
341  DPRINT("Reported device: %S (%wZ)\n", HardwareId, &DeviceNode->InstancePath);
342 
344 
345  /* Return the PDO */
346  if (DeviceObject) *DeviceObject = Pdo;
347 
348  return STATUS_SUCCESS;
349 }
NTSTATUS PnpRootRegisterDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: pnproot.c:129
#define DRVO_BUILTIN_DRIVER
Definition: iotypes.h:2227
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PNP_DEVNODE_STATE PiSetDevNodeState(_In_ PDEVICE_NODE DeviceNode, _In_ PNP_DEVNODE_STATE NewState)
Definition: devnode.c:108
VOID PiQueueDeviceAction(_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action, _In_opt_ PKEVENT CompletionEvent, _Out_opt_ NTSTATUS *CompletionStatus)
Queue a device operation to a worker thread.
Definition: devaction.c:2616
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
Definition: pnpmgr.c:523
LONG NTSTATUS
Definition: precomp.h:26
#define DNF_NO_RESOURCE_REQUIRED
Definition: iotypes.h:178
#define DNF_HAS_BOOT_CONFIG
Definition: iotypes.h:176
uint16_t * PWCHAR
Definition: typedefs.h:56
#define swprintf
Definition: precomp.h:40
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:304
NTSTATUS IopSetDeviceInstanceData(HANDLE InstanceKey, PDEVICE_NODE DeviceNode)
Definition: pnpmgr.c:607
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define UNICODE_NULL
PDEVICE_NODE PipAllocateDeviceNode(IN PDEVICE_OBJECT PhysicalDeviceObject)
#define REG_MULTI_SZ
Definition: nt_native.h:1501
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_ WDFDRIVER _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT Pdo
Definition: wdfminiport.h:64
#define IopDeviceNodeSetFlag(DeviceNode, Flag)
Definition: io.h:142
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
Status
Definition: gdiplustypes.h:24
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
LPTSTR ServiceName
Definition: ServiceMain.c:15
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
Definition: Node.h:9
_In_ INTERFACE_TYPE LegacyBusType
Definition: iofuncs.h:1547
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
static const WCHAR L[]
Definition: oid.c:1250
VOID PiSetDevNodeText(_In_ PDEVICE_NODE DeviceNode, _In_ HANDLE InstanceKey)
Sets the DeviceNode's DeviceDesc and LocationInformation registry values.
Definition: devaction.c:1088
#define NULL
Definition: types.h:112
VOID PiInsertDevNode(_In_ PDEVICE_NODE DeviceNode, _In_ PDEVICE_NODE ParentNode)
Definition: devnode.c:80
NTSTATUS NTAPI IopAssignDeviceResources(IN PDEVICE_NODE DeviceNode)
Definition: pnpres.c:1106
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define DNF_ENUMERATED
Definition: iotypes.h:174
_In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG _In_opt_ PCM_RESOURCE_LIST _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements
Definition: iofuncs.h:1547
#define DNF_MADEUP
Definition: iotypes.h:170
#define STATUS_SUCCESS
Definition: shellext.h:65
_In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG _In_opt_ PCM_RESOURCE_LIST _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST _In_ BOOLEAN ResourceAssigned
Definition: iofuncs.h:1547
#define DPRINT
Definition: sndvol32.h:71
PWCHAR IopGetInterfaceTypeString(INTERFACE_TYPE IfType)
Definition: pnpreport.c:42
#define REG_DWORD
Definition: sdbapi.c:596
NTSTATUS PnpRootCreateDevice(IN PUNICODE_STRING ServiceName, IN OPTIONAL PDRIVER_OBJECT DriverObject, OUT PDEVICE_OBJECT *PhysicalDeviceObject, OUT OPTIONAL PUNICODE_STRING FullInstancePath)
Definition: pnproot.c:185
#define REG_SZ
Definition: layer.c:22

Referenced by _Function_class_(), add_volume_device(), DriverEntry(), HalpDriverEntry(), ReportGreenPdo(), and ScsiPortInitialize().

◆ IoReportResourceForDetection()

NTSTATUS NTAPI IoReportResourceForDetection ( IN PDRIVER_OBJECT  DriverObject,
IN PCM_RESOURCE_LIST DriverList  OPTIONAL,
IN ULONG DriverListSize  OPTIONAL,
IN PDEVICE_OBJECT DeviceObject  OPTIONAL,
IN PCM_RESOURCE_LIST DeviceList  OPTIONAL,
IN ULONG DeviceListSize  OPTIONAL,
OUT PBOOLEAN  ConflictDetected 
)

Definition at line 356 of file pnpreport.c.

363 {
366 
367  *ConflictDetected = FALSE;
368 
369  if (!DriverList && !DeviceList)
371 
372  /* Find the real list */
373  if (!DriverList)
375  else
376  ResourceList = DriverList;
377 
378  /* Look for a resource conflict */
381  {
382  /* Oh noes */
383  *ConflictDetected = TRUE;
384  }
385  else if (NT_SUCCESS(Status))
386  {
387  /* Looks like we're good to go */
388 
389  /* TODO: Claim the resources in the ResourceMap */
390  }
391 
392  return Status;
393 }
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_LIST DeviceList
Definition: utils.c:27
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:304
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NULL
Definition: types.h:112
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:261
NTSTATUS NTAPI IopDetectResourceConflict(IN PCM_RESOURCE_LIST ResourceList, IN BOOLEAN Silent, OUT OPTIONAL PCM_PARTIAL_RESOURCE_DESCRIPTOR ConflictingDescriptor)
Definition: pnpres.c:1245

Referenced by VideoPortVerifyAccessRanges().

◆ IoReportTargetDeviceChange()

NTSTATUS NTAPI IoReportTargetDeviceChange ( IN PDEVICE_OBJECT  PhysicalDeviceObject,
IN PVOID  NotificationStructure 
)

Definition at line 410 of file pnpreport.c.

412 {
413  KEVENT NotifyEvent;
414  NTSTATUS Status, NotifyStatus;
416 
417  ASSERT(notifyStruct);
418 
419  /* Check for valid PDO */
421  {
422  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0);
423  }
424 
425  /* FileObject must be null. PnP will fill in it */
426  ASSERT(notifyStruct->FileObject == NULL);
427 
428  /* Do not handle system PnP events */
429  if ((RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_QUERY_REMOVE), sizeof(GUID)) != sizeof(GUID)) ||
430  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_CANCELLED), sizeof(GUID)) != sizeof(GUID)) ||
431  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_COMPLETE), sizeof(GUID)) != sizeof(GUID)))
432  {
434  }
435 
436  if (notifyStruct->Version != 1)
437  {
439  }
440 
441  /* Initialize even that will let us know when PnP will have finished notify */
442  KeInitializeEvent(&NotifyEvent, NotificationEvent, FALSE);
443 
444  Status = PpSetCustomTargetEvent(PhysicalDeviceObject, &NotifyEvent, &NotifyStatus, NULL, NULL, notifyStruct);
445  /* If no error, wait for the notify to end and return the status of the notify and not of the event */
446  if (NT_SUCCESS(Status))
447  {
449  Status = NotifyStatus;
450  }
451 
452  return Status;
453 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1206
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
NTSTATUS PpSetCustomTargetEvent(IN PDEVICE_OBJECT DeviceObject, IN OUT PKEVENT SyncEvent OPTIONAL, IN OUT PNTSTATUS SyncStatus OPTIONAL, IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback OPTIONAL, IN PVOID Context OPTIONAL, IN PTARGET_DEVICE_CUSTOM_NOTIFICATION NotificationStructure)
Definition: pnpreport.c:113
struct _TARGET_DEVICE_CUSTOM_NOTIFICATION * PTARGET_DEVICE_CUSTOM_NOTIFICATION
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:238
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NULL
Definition: types.h:112
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
struct _FILE_OBJECT * FileObject
Definition: iotypes.h:1012
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

Referenced by FsRtlNotifyVolumeEvent(), and NtSetVolumeInformationFile().

◆ IoReportTargetDeviceChangeAsynchronous()

NTSTATUS NTAPI IoReportTargetDeviceChangeAsynchronous ( IN PDEVICE_OBJECT  PhysicalDeviceObject,
IN PVOID  NotificationStructure,
IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback  OPTIONAL,
IN PVOID Context  OPTIONAL 
)

Definition at line 460 of file pnpreport.c.

464 {
467 
468  ASSERT(notifyStruct);
469 
470  /* Check for valid PDO */
472  {
473  KeBugCheckEx(PNP_DETECTED_FATAL_ERROR, 0x2, (ULONG_PTR)PhysicalDeviceObject, 0, 0);
474  }
475 
476  /* FileObject must be null. PnP will fill in it */
477  ASSERT(notifyStruct->FileObject == NULL);
478 
479  /* Do not handle system PnP events */
480  if ((RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_QUERY_REMOVE), sizeof(GUID)) != sizeof(GUID)) ||
481  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_CANCELLED), sizeof(GUID)) != sizeof(GUID)) ||
482  (RtlCompareMemory(&(notifyStruct->Event), &(GUID_TARGET_DEVICE_REMOVE_COMPLETE), sizeof(GUID)) != sizeof(GUID)))
483  {
485  }
486 
487  if (notifyStruct->Version != 1)
488  {
490  }
491 
492  /* We need to store all the data given by the caller with the WorkItem, so use our own struct */
494  if (!Item) return STATUS_INSUFFICIENT_RESOURCES;
495 
496  /* Initialize all stuff */
498  Item->NotificationStructure = notifyStruct;
499  Item->PhysicalDeviceObject = PhysicalDeviceObject;
500  Item->Callback = Callback;
501  Item->Context = Context;
503 
504  /* Finally, queue the item, our work here is done */
505  ExQueueWorkItem(&(Item->WorkItem), DelayedWorkQueue);
506 
507  return STATUS_PENDING;
508 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1206
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:711
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
uint32_t ULONG_PTR
Definition: typedefs.h:65
struct _TARGET_DEVICE_CUSTOM_NOTIFICATION * PTARGET_DEVICE_CUSTOM_NOTIFICATION
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_PENDING
Definition: ntstatus.h:82
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
Definition: io.h:238
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:456
VOID NTAPI IopReportTargetDeviceChangeAsyncWorker(PVOID Context)
Definition: pnpreport.c:102
#define NULL
Definition: types.h:112
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
struct tagContext Context
Definition: acpixf.h:1034
#define ObReferenceObject
Definition: obfuncs.h:204
struct _FILE_OBJECT * FileObject
Definition: iotypes.h:1012
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

Referenced by _IRQL_requires_max_(), DeviceSendNotification(), DiskIoctlUpdateDriveSize(), FdoIoctlDiskSetDriveLayout(), FdoIoctlDiskSetDriveLayoutEx(), FsRtlNotifyVolumeEvent(), and MountMgrNotifyNameChange().

◆ PpSetCustomTargetEvent()

NTSTATUS PpSetCustomTargetEvent ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PKEVENT SyncEvent  OPTIONAL,
IN OUT PNTSTATUS SyncStatus  OPTIONAL,
IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback  OPTIONAL,
IN PVOID Context  OPTIONAL,
IN PTARGET_DEVICE_CUSTOM_NOTIFICATION  NotificationStructure 
)

Definition at line 113 of file pnpreport.c.

119 {
122 
123  if (SyncEvent)
124  {
127  }
128 
129  /* That call is totally wrong but notifications handler must be fixed first */
130  PiNotifyTargetDeviceChange(&GUID_PNP_CUSTOM_NOTIFICATION, DeviceObject, NotificationStructure);
131 
132  if (SyncEvent)
133  {
134  KeSetEvent(SyncEvent, IO_NO_INCREMENT, FALSE);
136  }
137 
138  return STATUS_SUCCESS;
139 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1206
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
#define ASSERT(a)
Definition: mode.c:44
SYNC_STATUS SyncStatus
Definition: internettime.c:14
#define STATUS_PENDING
Definition: ntstatus.h:82
#define NULL
Definition: types.h:112
VOID PiNotifyTargetDeviceChange(_In_ LPCGUID Event, _In_ PDEVICE_OBJECT DeviceObject, _In_opt_ PTARGET_DEVICE_CUSTOM_NOTIFICATION CustomNotification)
Delivers the event to all drivers subscribed to EventCategoryTargetDeviceChange PnP event.
Definition: pnpnotify.c:258
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by IopReportTargetDeviceChangeAsyncWorker(), and IoReportTargetDeviceChange().