ReactOS  0.4.14-dev-368-gfa26425
pnp.c File Reference
#include "processr.h"
#include <stdio.h>
#include <debug.h>
Include dependency graph for pnp.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static NTSTATUS GetDeviceId (PDEVICE_OBJECT DeviceObject, BUS_QUERY_ID_TYPE IdType, PWSTR *DeviceId)
 
static VOID ProcessorSetFriendlyName (PDEVICE_OBJECT DeviceObject)
 
static NTSTATUS ProcessorStartDevice (IN PDEVICE_OBJECT DeviceObject, IN PCM_RESOURCE_LIST ResourceList, IN PCM_RESOURCE_LIST ResourceListTranslated)
 
NTSTATUS NTAPI ProcessorPnp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI ProcessorAddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT Pdo)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file pnp.c.

Function Documentation

◆ GetDeviceId()

static NTSTATUS GetDeviceId ( PDEVICE_OBJECT  DeviceObject,
BUS_QUERY_ID_TYPE  IdType,
PWSTR DeviceId 
)
static

Definition at line 21 of file pnp.c.

25 {
26  PIO_STACK_LOCATION IrpStack;
28  PDEVICE_OBJECT TargetObject;
29  KEVENT Event;
30  PIRP Irp;
32 
33  PAGED_CODE();
34 
35  /* Initialize the event */
37 
39 
40  /* Build the IRP */
42  TargetObject,
43  NULL,
44  0,
45  NULL,
46  &Event,
47  &IoStatus);
48  if (Irp == NULL)
49  {
51  goto done;
52  }
53 
54  /* PNP IRPs all begin life as STATUS_NOT_SUPPORTED */
55  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
56 
57  /* Get the top of stack */
58  IrpStack = IoGetNextIrpStackLocation(Irp);
59 
60  /* Set the top of stack */
61  RtlZeroMemory(IrpStack, sizeof(IO_STACK_LOCATION));
62  IrpStack->MajorFunction = IRP_MJ_PNP;
63  IrpStack->MinorFunction = IRP_MN_QUERY_ID;
64  IrpStack->Parameters.QueryId.IdType = IdType;
65 
66  /* Call the driver */
67  Status = IoCallDriver(TargetObject, Irp);
68  if (Status == STATUS_PENDING)
69  {
71  Executive,
72  KernelMode,
73  FALSE,
74  NULL);
75 
76  Status = IoStatus.Status;
77  }
78 
79  if (NT_SUCCESS(Status))
80  {
81  *DeviceId = (PWSTR)IoStatus.Information;
82  }
83 
84 done:
85  /* Dereference the target device object */
86  ObDereferenceObject(TargetObject);
87 
88  return Status;
89 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IRP_MN_QUERY_ID
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
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:1069
_In_ PIRP Irp
Definition: csq.h:116
uint16_t * PWSTR
Definition: typedefs.h:54
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
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
#define PAGED_CODE()
Definition: video.h:57
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
_In_ BUS_QUERY_ID_TYPE IdType
Definition: classpnp.h:357
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772

Referenced by ProcessorSetFriendlyName().

◆ ProcessorAddDevice()

NTSTATUS NTAPI ProcessorAddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  Pdo 
)

Definition at line 357 of file pnp.c.

360 {
361  PDEVICE_EXTENSION DeviceExtension = NULL;
362  PDEVICE_OBJECT Fdo = NULL;
364 
365  DPRINT("ProcessorAddDevice()\n");
366 
368  ASSERT(Pdo);
369 
370  /* Create functional device object */
372  sizeof(DEVICE_EXTENSION),
373  NULL,
376  FALSE,
377  &Fdo);
378  if (NT_SUCCESS(Status))
379  {
380  DeviceExtension = (PDEVICE_EXTENSION)Fdo->DeviceExtension;
381  RtlZeroMemory(DeviceExtension, sizeof(DEVICE_EXTENSION));
382 
383  DeviceExtension->DeviceObject = Fdo;
384 
385  Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
386  if (!NT_SUCCESS(Status))
387  {
388  DPRINT1("IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
389  IoDeleteDevice(Fdo);
390  return Status;
391  }
392 
393  Fdo->Flags |= DO_DIRECT_IO;
394  Fdo->Flags |= DO_POWER_PAGABLE;
395 
396  Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
397  }
398 
399  return Status;
400 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_POWER_PAGABLE
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:301
LONG NTSTATUS
Definition: precomp.h:26
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:980
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:139
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION

Referenced by DriverEntry().

◆ ProcessorPnp()

NTSTATUS NTAPI ProcessorPnp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 262 of file pnp.c.

265 {
269 
270  DPRINT("ProcessorPnp()\n");
271 
273 
274  switch (IrpSp->MinorFunction)
275  {
276  case IRP_MN_START_DEVICE:
277  DPRINT(" IRP_MN_START_DEVICE received\n");
278 
279  /* Call lower driver */
281  if (NT_SUCCESS(Status))
282  {
284  IrpSp->Parameters.StartDevice.AllocatedResources,
285  IrpSp->Parameters.StartDevice.AllocatedResourcesTranslated);
286  }
287  break;
288 
290  DPRINT(" IRP_MN_QUERY_REMOVE_DEVICE\n");
292 
294  DPRINT(" IRP_MN_REMOVE_DEVICE received\n");
296 
298  DPRINT(" IRP_MN_CANCEL_REMOVE_DEVICE\n");
300 
301  case IRP_MN_STOP_DEVICE:
302  DPRINT(" IRP_MN_STOP_DEVICE received\n");
304 
306  DPRINT(" IRP_MN_QUERY_STOP_DEVICE received\n");
308 
310  DPRINT(" IRP_MN_CANCEL_STOP_DEVICE\n");
312 
314  DPRINT(" IRP_MN_QUERY_DEVICE_RELATIONS\n");
315 
316  switch (IrpSp->Parameters.QueryDeviceRelations.Type)
317  {
318  case BusRelations:
319  DPRINT(" IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations\n");
321  break;
322 
323  case RemovalRelations:
324  DPRINT(" IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / RemovalRelations\n");
326 
327  default:
328  DPRINT(" IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n",
329  IrpSp->Parameters.QueryDeviceRelations.Type);
331  }
332  break;
333 
335  DPRINT(" IRP_MN_SURPRISE_REMOVAL received\n");
337 
338  case IRP_MN_FILTER_RESOURCE_REQUIREMENTS: /* (optional) 0xd */
339  DPRINT(" IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
341 
342  default:
343  DPRINT(" Unknown IOCTL 0x%lx\n", IrpSp->MinorFunction);
345  }
346 
347  Irp->IoStatus.Information = Information;
348  Irp->IoStatus.Status = Status;
350 
351  return Status;
352 }
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define IRP_MN_REMOVE_DEVICE
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define IRP_MN_QUERY_REMOVE_DEVICE
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IRP_MN_STOP_DEVICE
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MN_START_DEVICE
DRIVER_DISPATCH ForwardIrpAndWait
Definition: i8042prt.h:343
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define IO_NO_INCREMENT
Definition: iotypes.h:566
static NTSTATUS ProcessorStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PCM_RESOURCE_LIST ResourceList, IN PCM_RESOURCE_LIST ResourceListTranslated)
Definition: pnp.c:247
#define IRP_MN_CANCEL_STOP_DEVICE
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
Iosb Information
Definition: create.c:4377

Referenced by DriverEntry().

◆ ProcessorSetFriendlyName()

static VOID ProcessorSetFriendlyName ( PDEVICE_OBJECT  DeviceObject)
static

Definition at line 95 of file pnp.c.

97 {
100  UNICODE_STRING HardwareKeyName, ValueName, EnumKeyName;
102  ULONG DataLength = 0;
103  ULONG BufferLength = 0;
105  PWSTR KeyNameBuffer = NULL;
106  PWSTR DeviceId = NULL;
108  PWSTR pszPrefix = L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum";
109 
110  RtlInitUnicodeString(&HardwareKeyName,
111  L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
113  &HardwareKeyName,
115  NULL,
116  NULL);
117  Status = ZwOpenKey(&KeyHandle,
118  KEY_READ,
120  if (!NT_SUCCESS(Status))
121  {
122  DPRINT1("ZwOpenKey() failed (Status 0x%08lx)\n", Status);
123  return;
124  }
125 
127  L"ProcessorNameString");
128  Status = ZwQueryValueKey(KeyHandle,
129  &ValueName,
131  NULL,
132  0,
133  &DataLength);
135  {
136  DPRINT1("ZwQueryValueKey() failed (Status 0x%08lx)\n", Status);
137  goto done;
138  }
139 
142  if (Buffer == NULL)
143  {
144  DPRINT1("ExAllocatePool() failed\n");
145  goto done;
146  }
147 
148  Status = ZwQueryValueKey(KeyHandle,
149  &ValueName,
151  Buffer,
153  &DataLength);
154  if (!NT_SUCCESS(Status))
155  {
156  DPRINT1("ZwQueryValueKey() failed (Status 0x%08lx)\n", Status);
157  goto done;
158  }
159 
160  DPRINT("ProcessorNameString: %S\n", (PWSTR)&Buffer->Data[0]);
161 
163  KeyHandle = NULL;
164 
167  &DeviceId);
168  if (!NT_SUCCESS(Status))
169  {
170  DPRINT1("GetDeviceId() failed (Status 0x%08lx)\n", Status);
171  goto done;
172  }
173 
174  DPRINT("DeviceId: %S\n", DeviceId);
175 
178  &InstanceId);
179  if (!NT_SUCCESS(Status))
180  {
181  DPRINT1("GetDeviceId() failed (Status 0x%08lx)\n", Status);
182  goto done;
183  }
184 
185  DPRINT("InstanceId: %S\n", InstanceId);
186 
187  BufferLength = wcslen(pszPrefix) + 1 + wcslen(DeviceId) + 1 + wcslen(InstanceId) + 1;
188 
189  KeyNameBuffer = ExAllocatePool(PagedPool, BufferLength * sizeof(WCHAR));
190  if (KeyNameBuffer == NULL)
191  {
192  DPRINT1("ExAllocatePool() failed\n");
193  goto done;
194  }
195 
196  swprintf(KeyNameBuffer, L"%s\\%s\\%s", pszPrefix, DeviceId, InstanceId);
197 
198  RtlInitUnicodeString(&EnumKeyName, KeyNameBuffer);
200  &EnumKeyName,
202  NULL,
203  NULL);
204  Status = ZwOpenKey(&KeyHandle,
205  KEY_WRITE,
207  if (!NT_SUCCESS(Status))
208  {
209  DPRINT1("ZwOpenKey() failed (Status 0x%08lx)\n", Status);
210  goto done;
211  }
212 
214  L"FriendlyName");
215  Status = ZwSetValueKey(KeyHandle,
216  &ValueName,
217  0,
218  REG_SZ,
219  (PVOID)&Buffer->Data[0],
220  Buffer->DataLength);
221  if (!NT_SUCCESS(Status))
222  {
223  DPRINT1("ZwSetValueKey() failed (Status 0x%08lx)\n", Status);
224  goto done;
225  }
226 
227 done:
228  if (KeyHandle != NULL)
230 
231  if (KeyNameBuffer != NULL)
232  ExFreePool(KeyNameBuffer);
233 
234  if (InstanceId != NULL)
236 
237  if (DeviceId != NULL)
238  ExFreePool(DeviceId);
239 
240  if (Buffer != NULL)
242 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
uint16_t * PWSTR
Definition: typedefs.h:54
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS GetDeviceId(PDEVICE_OBJECT DeviceObject, BUS_QUERY_ID_TYPE IdType, PWSTR *DeviceId)
Definition: pnp.c:21
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
_In_ ULONG BufferLength
Definition: usbdlib.h:225
_Must_inspect_result_ _In_opt_ PVOID _In_opt_ PVOID InstanceId
Definition: fsrtlfuncs.h:907
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
#define KEY_WRITE
Definition: nt_native.h:1031
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static const WCHAR L[]
Definition: oid.c:1250
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define DPRINT1
Definition: precomp.h:8
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_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG DataLength
Definition: hidpi.h:333
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define REG_SZ
Definition: layer.c:22

Referenced by ProcessorStartDevice().

◆ ProcessorStartDevice()

static NTSTATUS ProcessorStartDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PCM_RESOURCE_LIST  ResourceList,
IN PCM_RESOURCE_LIST  ResourceListTranslated 
)
static

Definition at line 247 of file pnp.c.

251 {
252  DPRINT("ProcessorStartDevice()\n");
253 
255 
256  return STATUS_SUCCESS;
257 }
static VOID ProcessorSetFriendlyName(PDEVICE_OBJECT DeviceObject)
Definition: pnp.c:95
void DPRINT(...)
Definition: polytest.cpp:61
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by ProcessorPnp().