ReactOS 0.4.15-dev-7842-g558ab78
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;
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 */
59
60 /* Set the top of stack */
61 RtlZeroMemory(IrpStack, sizeof(IO_STACK_LOCATION));
62 IrpStack->MajorFunction = IRP_MJ_PNP;
64 IrpStack->Parameters.QueryId.IdType = IdType;
65
66 /* Call the driver */
67 Status = IoCallDriver(TargetObject, Irp);
69 {
73 FALSE,
74 NULL);
75
76 Status = IoStatus.Status;
77 }
78
79 if (NT_SUCCESS(Status))
80 {
81 *DeviceId = (PWSTR)IoStatus.Information;
82 }
83
84done:
85 /* Dereference the target device object */
86 ObDereferenceObject(TargetObject);
87
88 return Status;
89}
#define PAGED_CODE()
LONG NTSTATUS
Definition: precomp.h:26
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
_In_ BUS_QUERY_ID_TYPE IdType
Definition: classpnp.h:374
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
Status
Definition: gdiplustypes.h:25
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define KernelMode
Definition: asm.h:34
@ NotificationEvent
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
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
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
uint16_t * PWSTR
Definition: typedefs.h:56
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define IRP_MN_QUERY_ID
@ Executive
Definition: ketypes.h:415
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by ProcessorSetFriendlyName().

◆ ProcessorAddDevice()

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

Definition at line 364 of file pnp.c.

367{
368 PDEVICE_EXTENSION DeviceExtension = NULL;
371
372 DPRINT("ProcessorAddDevice()\n");
373
375 ASSERT(Pdo);
376
377 /* Create functional device object */
379 sizeof(DEVICE_EXTENSION),
380 NULL,
383 FALSE,
384 &Fdo);
385 if (NT_SUCCESS(Status))
386 {
387 DeviceExtension = (PDEVICE_EXTENSION)Fdo->DeviceExtension;
388 RtlZeroMemory(DeviceExtension, sizeof(DEVICE_EXTENSION));
389
390 DeviceExtension->DeviceObject = Fdo;
391
392 Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
393 if (!NT_SUCCESS(Status))
394 {
395 DPRINT1("IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
397 return Status;
398 }
399
400 Fdo->Flags |= DO_DIRECT_IO;
401 Fdo->Flags |= DO_POWER_PAGABLE;
402
403 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
404 }
405
406 return Status;
407}
#define DPRINT1
Definition: precomp.h:8
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define ASSERT(a)
Definition: mode.c:44
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
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:980
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:140
#define DPRINT
Definition: sndvol32.h:71
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
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:72
#define DO_POWER_PAGABLE

Referenced by DriverEntry().

◆ ProcessorPnp()

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

Definition at line 262 of file pnp.c.

265{
266 PDEVICE_EXTENSION DeviceExtension;
270
271 DPRINT("ProcessorPnp()\n");
272
274
275 switch (IrpSp->MinorFunction)
276 {
278 DPRINT(" IRP_MN_START_DEVICE received\n");
279
280 /* Call lower driver */
281 DeviceExtension = DeviceObject->DeviceExtension;
283
284 if (IoForwardIrpSynchronously(DeviceExtension->LowerDevice, Irp))
285 {
286 Status = Irp->IoStatus.Status;
287 if (NT_SUCCESS(Status))
288 {
290 IrpSp->Parameters.StartDevice.AllocatedResources,
291 IrpSp->Parameters.StartDevice.AllocatedResourcesTranslated);
292 }
293 }
294 break;
295
297 DPRINT(" IRP_MN_QUERY_REMOVE_DEVICE\n");
299
301 DPRINT(" IRP_MN_REMOVE_DEVICE received\n");
303
305 DPRINT(" IRP_MN_CANCEL_REMOVE_DEVICE\n");
307
309 DPRINT(" IRP_MN_STOP_DEVICE received\n");
311
313 DPRINT(" IRP_MN_QUERY_STOP_DEVICE received\n");
315
317 DPRINT(" IRP_MN_CANCEL_STOP_DEVICE\n");
319
321 DPRINT(" IRP_MN_QUERY_DEVICE_RELATIONS\n");
322
323 switch (IrpSp->Parameters.QueryDeviceRelations.Type)
324 {
325 case BusRelations:
326 DPRINT(" IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations\n");
328 break;
329
330 case RemovalRelations:
331 DPRINT(" IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / RemovalRelations\n");
333
334 default:
335 DPRINT(" IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n",
336 IrpSp->Parameters.QueryDeviceRelations.Type);
338 }
339 break;
340
342 DPRINT(" IRP_MN_SURPRISE_REMOVAL received\n");
344
345 case IRP_MN_FILTER_RESOURCE_REQUIREMENTS: /* (optional) 0xd */
346 DPRINT(" IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
348
349 default:
350 DPRINT(" Unknown IOCTL 0x%lx\n", IrpSp->MinorFunction);
352 }
353
354 Irp->IoStatus.Information = Information;
355 Irp->IoStatus.Status = Status;
357
358 return Status;
359}
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
static NTSTATUS ProcessorStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PCM_RESOURCE_LIST ResourceList, IN PCM_RESOURCE_LIST ResourceListTranslated)
Definition: pnp.c:247
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IoCompleteRequest
Definition: irp.c:1240
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define IRP_MN_CANCEL_STOP_DEVICE
@ RemovalRelations
Definition: iotypes.h:2155
@ BusRelations
Definition: iotypes.h:2152
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_START_DEVICE
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define IRP_MN_STOP_DEVICE
#define IRP_MN_QUERY_REMOVE_DEVICE

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;
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
227done:
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_ ULONG _In_opt_ WDFREQUEST _In_opt_ PVOID _In_ size_t _In_ PVOID _In_ size_t _Out_ size_t * DataLength
Definition: cdrom.h:1444
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define swprintf
Definition: precomp.h:40
static NTSTATUS GetDeviceId(PDEVICE_OBJECT DeviceObject, BUS_QUERY_ID_TYPE IdType, PWSTR *DeviceId)
Definition: pnp.c:21
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PagedPool
Definition: env_spec_w32.h:308
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
_Must_inspect_result_ _In_opt_ PVOID _In_opt_ PVOID InstanceId
Definition: fsrtlfuncs.h:908
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define REG_SZ
Definition: layer.c:22
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
@ KeyValuePartialInformation
Definition: nt_native.h:1182
#define KEY_READ
Definition: nt_native.h:1023
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define KEY_WRITE
Definition: nt_native.h:1031
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
@ BusQueryInstanceID
Definition: iotypes.h:2939
@ BusQueryDeviceID
Definition: iotypes.h:2936
__wchar_t WCHAR
Definition: xmlstorage.h:180

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

Referenced by ProcessorPnp().