ReactOS  0.4.14-dev-323-g6fe6a88
pnp.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for pnp.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS Bus_PlugInDevice (struct acpi_device *Device, PFDO_DEVICE_DATA FdoData)
 
NTSTATUS NTAPI Bus_PnP (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS Bus_FDO_PnP (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpStack, PFDO_DEVICE_DATA DeviceData)
 
NTSTATUS Bus_StartFdo (PFDO_DEVICE_DATA FdoData, PIRP Irp)
 
NTSTATUS Bus_SendIrpSynchronously (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI Bus_CompletionRoutine (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
 
NTSTATUS Bus_DestroyPdo (PDEVICE_OBJECT Device, PPDO_DEVICE_DATA PdoData)
 
VOID Bus_InitializePdo (PDEVICE_OBJECT Pdo, PFDO_DEVICE_DATA FdoData)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 3 of file pnp.c.

Function Documentation

◆ Bus_CompletionRoutine()

NTSTATUS NTAPI Bus_CompletionRoutine ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PVOID  Context 
)

Definition at line 369 of file pnp.c.

374 {
376 
377  //
378  // If the lower driver didn't return STATUS_PENDING, we don't need to
379  // set the event because we won't be waiting on it.
380  // This optimization avoids grabbing the dispatcher lock and improves perf.
381  //
382  if (Irp->PendingReturned != FALSE) {
383 
385  }
386  return STATUS_MORE_PROCESSING_REQUIRED; // Keep this IRP
387 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define IO_NO_INCREMENT
Definition: iotypes.h:566

Referenced by Bus_SendIrpSynchronously().

◆ Bus_DestroyPdo()

NTSTATUS Bus_DestroyPdo ( PDEVICE_OBJECT  Device,
PPDO_DEVICE_DATA  PdoData 
)

Definition at line 390 of file pnp.c.

394 {
395  PAGED_CODE ();
396 
397  //
398  // BusEnum does not queue any irps at this time so we have nothing to do.
399  //
400 
401  //
402  // Free any resources.
403  //
404 
405  if (PdoData->HardwareIDs) {
406  ExFreePoolWithTag(PdoData->HardwareIDs, 'DpcA');
407  PdoData->HardwareIDs = NULL;
408  }
409 
410  DPRINT("\tDeleting PDO: 0x%p\n", Device);
412  return STATUS_SUCCESS;
413 }
_In_ PIRP _In_ PDEVICE_OBJECT Device
Definition: fatprocs.h:2020
#define PAGED_CODE()
Definition: video.h:57
PWCHAR HardwareIDs
Definition: acpisys.h:44
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ Bus_FDO_PnP()

NTSTATUS Bus_FDO_PnP ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpStack,
PFDO_DEVICE_DATA  DeviceData 
)

Definition at line 72 of file pnp.c.

78 {
80  ULONG length, prevcount, numPdosPresent;
82  PPDO_DEVICE_DATA pdoData;
83  PDEVICE_RELATIONS relations, oldRelations;
84 
85  PAGED_CODE ();
86 
87  switch (IrpStack->MinorFunction) {
88 
90 
92 
93 
94  //
95  // We must now complete the IRP, since we stopped it in the
96  // completion routine with MORE_PROCESSING_REQUIRED.
97  //
98 
99  Irp->IoStatus.Status = status;
101 
102  return status;
103 
105 
106  //
107  // The PnP manager is trying to stop the device
108  // for resource rebalancing.
109  //
111  Irp->IoStatus.Status = STATUS_SUCCESS;
112  break;
113 
115 
116  //
117  // The PnP Manager sends this IRP, at some point after an
118  // IRP_MN_QUERY_STOP_DEVICE, to inform the drivers for a
119  // device that the device will not be stopped for
120  // resource reconfiguration.
121  //
122  //
123  // First check to see whether you have received cancel-stop
124  // without first receiving a query-stop. This could happen if
125  // someone above us fails a query-stop and passes down the subsequent
126  // cancel-stop.
127  //
128 
129  if (StopPending == DeviceData->Common.DevicePnPState)
130  {
131  //
132  // We did receive a query-stop, so restore.
133  //
135  ASSERT(DeviceData->Common.DevicePnPState == Started);
136  }
137  Irp->IoStatus.Status = STATUS_SUCCESS; // We must not fail the IRP.
138  break;
139 
141 
142  DPRINT("\tQueryDeviceRelation Type: %s\n",
144  IrpStack->Parameters.QueryDeviceRelations.Type));
145 
146  if (BusRelations != IrpStack->Parameters.QueryDeviceRelations.Type) {
147  //
148  // We don't support any other Device Relations
149  //
150  break;
151  }
152 
153 
154  ExAcquireFastMutex (&DeviceData->Mutex);
155 
156  oldRelations = (PDEVICE_RELATIONS) Irp->IoStatus.Information;
157  if (oldRelations) {
158  prevcount = oldRelations->Count;
159  if (!DeviceData->NumPDOs) {
160  //
161  // There is a device relations struct already present and we have
162  // nothing to add to it, so just call IoSkip and IoCall
163  //
164  ExReleaseFastMutex (&DeviceData->Mutex);
165  break;
166  }
167  }
168  else {
169  prevcount = 0;
170  }
171 
172  //
173  // Calculate the number of PDOs actually present on the bus
174  //
175  numPdosPresent = 0;
176  for (entry = DeviceData->ListOfPDOs.Flink;
177  entry != &DeviceData->ListOfPDOs;
178  entry = entry->Flink) {
180  numPdosPresent++;
181  }
182 
183  //
184  // Need to allocate a new relations structure and add our
185  // PDOs to it.
186  //
187 
188  length = sizeof(DEVICE_RELATIONS) +
189  (((numPdosPresent + prevcount) - 1) * sizeof (PDEVICE_OBJECT));
190 
191  relations = ExAllocatePoolWithTag(PagedPool, length, 'IpcA');
192 
193  if (NULL == relations) {
194  //
195  // Fail the IRP
196  //
197  ExReleaseFastMutex (&DeviceData->Mutex);
198  Irp->IoStatus.Status = status = STATUS_INSUFFICIENT_RESOURCES;
200  return status;
201 
202  }
203 
204  //
205  // Copy in the device objects so far
206  //
207  if (prevcount) {
208  RtlCopyMemory (relations->Objects, oldRelations->Objects,
209  prevcount * sizeof (PDEVICE_OBJECT));
210  }
211 
212  relations->Count = prevcount + numPdosPresent;
213 
214  //
215  // For each PDO present on this bus add a pointer to the device relations
216  // buffer, being sure to take out a reference to that object.
217  // The Plug & Play system will dereference the object when it is done
218  // with it and free the device relations buffer.
219  //
220 
221  for (entry = DeviceData->ListOfPDOs.Flink;
222  entry != &DeviceData->ListOfPDOs;
223  entry = entry->Flink) {
224 
226  relations->Objects[prevcount] = pdoData->Common.Self;
227  ObReferenceObject (pdoData->Common.Self);
228  prevcount++;
229  }
230 
231  DPRINT("\t#PDOs present = %d\n\t#PDOs reported = %d\n",
232  DeviceData->NumPDOs, relations->Count);
233 
234  //
235  // Replace the relations structure in the IRP with the new
236  // one.
237  //
238  if (oldRelations) {
239  ExFreePoolWithTag(oldRelations, 0);
240  }
241  Irp->IoStatus.Information = (ULONG_PTR) relations;
242 
243  ExReleaseFastMutex (&DeviceData->Mutex);
244 
245  //
246  // Set up and pass the IRP further down the stack
247  //
248  Irp->IoStatus.Status = STATUS_SUCCESS;
249  break;
250 
251  default:
252 
253  //
254  // In the default case we merely call the next driver.
255  // We must not modify Irp->IoStatus.Status or complete the IRP.
256  //
257 
258  break;
259  }
260 
262  status = IoCallDriver (DeviceData->NextLowerDriver, Irp);
263  return STATUS_SUCCESS;
264 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
_In_ PIRP Irp
Definition: csq.h:116
struct _DEVICE_OBJECT * PDEVICE_OBJECT
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2055
LONG NTSTATUS
Definition: precomp.h:26
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
static int Link(const char **args)
Definition: vfdcmd.c:2414
#define PAGED_CODE()
Definition: video.h:57
PDEVICE_OBJECT Self
Definition: acpisys.h:28
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define IRP_MN_QUERY_STOP_DEVICE
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define RESTORE_PREVIOUS_PNP_STATE(_Data_)
Definition: fbtusb.h:115
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define IRP_MN_START_DEVICE
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
uint32_t entry
Definition: isohybrid.c:63
Definition: typedefs.h:117
struct _DEVICE_RELATIONS DEVICE_RELATIONS
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
NTSTATUS Bus_StartFdo(PFDO_DEVICE_DATA FdoData, PIRP Irp)
Definition: pnp.c:267
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define SET_NEW_PNP_STATE(_Data_, _state_)
Definition: fbtusb.h:111
#define ObReferenceObject
Definition: obfuncs.h:204
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define ULONG_PTR
Definition: config.h:101
#define IRP_MN_CANCEL_STOP_DEVICE
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
PCHAR DbgDeviceRelationString(DEVICE_RELATION_TYPE Type)
COMMON_DEVICE_DATA Common
Definition: acpisys.h:38
Definition: ps.c:97

Referenced by Bus_PnP().

◆ Bus_InitializePdo()

VOID Bus_InitializePdo ( PDEVICE_OBJECT  Pdo,
PFDO_DEVICE_DATA  FdoData 
)

Definition at line 417 of file pnp.c.

421 {
422  PPDO_DEVICE_DATA pdoData;
423  int acpistate;
424  DEVICE_POWER_STATE ntState;
425 
426  PAGED_CODE ();
427 
428  pdoData = (PPDO_DEVICE_DATA) Pdo->DeviceExtension;
429 
430  DPRINT("pdo 0x%p, extension 0x%p\n", Pdo, pdoData);
431 
432  if (pdoData->AcpiHandle)
433  acpi_bus_get_power(pdoData->AcpiHandle, &acpistate);
434  else
435  acpistate = ACPI_STATE_D0;
436 
437  switch(acpistate)
438  {
439  case ACPI_STATE_D0:
440  ntState = PowerDeviceD0;
441  break;
442  case ACPI_STATE_D1:
443  ntState = PowerDeviceD1;
444  break;
445  case ACPI_STATE_D2:
446  ntState = PowerDeviceD2;
447  break;
448  case ACPI_STATE_D3:
449  ntState = PowerDeviceD3;
450  break;
451  default:
452  DPRINT1("Unknown power state (%d) returned by acpi\n",acpistate);
453  ntState = PowerDeviceUnspecified;
454  break;
455  }
456 
457  //
458  // Initialize the rest
459  //
460  pdoData->Common.IsFDO = FALSE;
461  pdoData->Common.Self = Pdo;
462 
463  pdoData->ParentFdo = FdoData->Common.Self;
464 
465 
466  INITIALIZE_PNP_STATE(pdoData->Common);
467 
468  pdoData->Common.DevicePowerState = ntState;
469  pdoData->Common.SystemPowerState = FdoData->Common.SystemPowerState;
470 
471  ExAcquireFastMutex (&FdoData->Mutex);
472  InsertTailList(&FdoData->ListOfPDOs, &pdoData->Link);
473  FdoData->NumPDOs++;
474  ExReleaseFastMutex (&FdoData->Mutex);
475 
476  // This should be the last step in initialization.
478 
479 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
DEVICE_POWER_STATE DevicePowerState
Definition: acpisys.h:33
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:301
#define InsertTailList(ListHead, Entry)
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define PAGED_CODE()
Definition: video.h:57
PDEVICE_OBJECT Self
Definition: acpisys.h:28
SYSTEM_POWER_STATE SystemPowerState
Definition: acpisys.h:32
FAST_MUTEX Mutex
Definition: acpisys.h:72
PVOID DeviceExtension
Definition: env_spec_w32.h:418
void DPRINT(...)
Definition: polytest.cpp:61
LIST_ENTRY ListOfPDOs
Definition: acpisys.h:66
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE
struct _PDO_DEVICE_DATA * PPDO_DEVICE_DATA
int acpi_bus_get_power(ACPI_HANDLE handle, int *state)
Definition: bus.c:198
#define ACPI_STATE_D3
Definition: actypes.h:627
COMMON_DEVICE_DATA Common
Definition: acpisys.h:58
PDEVICE_OBJECT ParentFdo
Definition: acpisys.h:41
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
ULONG NumPDOs
Definition: acpisys.h:69
ACPI_HANDLE AcpiHandle
Definition: acpisys.h:39
#define DPRINT1
Definition: precomp.h:8
#define INITIALIZE_PNP_STATE(_Data_)
Definition: fbtusb.h:107
#define ACPI_STATE_D0
Definition: actypes.h:624
#define ACPI_STATE_D1
Definition: actypes.h:625
LIST_ENTRY Link
Definition: acpisys.h:46
#define ACPI_STATE_D2
Definition: actypes.h:626
COMMON_DEVICE_DATA Common
Definition: acpisys.h:38

Referenced by Bus_PlugInDevice().

◆ Bus_PlugInDevice()

NTSTATUS Bus_PlugInDevice ( struct acpi_device Device,
PFDO_DEVICE_DATA  FdoData 
)

Definition at line 22 of file acpienum.c.

26 {
27  PDEVICE_OBJECT pdo;
28  PPDO_DEVICE_DATA pdoData;
30  ULONG index;
31  WCHAR temp[256];
33 
34  PAGED_CODE ();
35 
36  //Don't enumerate the root device
37  if (Device->handle == ACPI_ROOT_OBJECT)
38  return STATUS_SUCCESS;
39 
40  /* Check we didnt add this already */
41  for (entry = FdoData->ListOfPDOs.Flink;
42  entry != &FdoData->ListOfPDOs; entry = entry->Flink)
43  {
44  struct acpi_device *CurrentDevice;
45 
47 
48  //dont duplicate devices
49  if (pdoData->AcpiHandle == Device->handle)
50  return STATUS_SUCCESS;
51 
52  //check everything but fixed feature devices
53  if (pdoData->AcpiHandle)
54  acpi_bus_get_device(pdoData->AcpiHandle, &CurrentDevice);
55  else
56  continue;
57 
58  //check if the HID matches
59  if (!strcmp(Device->pnp.hardware_id, CurrentDevice->pnp.hardware_id))
60  {
61  //check if UID exists for both and matches
62  if (Device->flags.unique_id && CurrentDevice->flags.unique_id &&
63  !strcmp(Device->pnp.unique_id, CurrentDevice->pnp.unique_id))
64  {
65  /* We have a UID on both but they're the same so we have to ignore it */
66  DPRINT1("Detected duplicate device: %hs %hs\n", Device->pnp.hardware_id, Device->pnp.unique_id);
67  return STATUS_SUCCESS;
68  }
69  else if (!Device->flags.unique_id && !CurrentDevice->flags.unique_id)
70  {
71  /* No UID so we can only legally have 1 of these devices */
72  DPRINT1("Detected duplicate device: %hs\n", Device->pnp.hardware_id);
73  return STATUS_SUCCESS;
74  }
75  }
76  }
77 
78  DPRINT("Exposing PDO\n"
79  "======AcpiHandle: %p\n"
80  "======HardwareId: %s\n",
81  Device->handle,
82  Device->pnp.hardware_id);
83 
84 
85  //
86  // Create the PDO
87  //
88 
89  DPRINT("FdoData->NextLowerDriver = 0x%p\n", FdoData->NextLowerDriver);
90 
91  status = IoCreateDevice(FdoData->Common.Self->DriverObject,
92  sizeof(PDO_DEVICE_DATA),
93  NULL,
96  FALSE,
97  &pdo);
98 
99  if (!NT_SUCCESS (status)) {
100  return status;
101  }
102 
103  pdoData = (PPDO_DEVICE_DATA) pdo->DeviceExtension;
104  pdoData->AcpiHandle = Device->handle;
105 
106  //
107  // Copy the hardware IDs
108  //
109  index = 0;
110  index += swprintf(&temp[index],
111  L"ACPI\\%hs",
112  Device->pnp.hardware_id);
113  temp[index++] = UNICODE_NULL;
114 
115  index += swprintf(&temp[index],
116  L"*%hs",
117  Device->pnp.hardware_id);
118  temp[index++] = UNICODE_NULL;
119  temp[index++] = UNICODE_NULL;
120 
121  pdoData->HardwareIDs = ExAllocatePoolWithTag(NonPagedPool, index*sizeof(WCHAR), 'DpcA');
122 
123 
124  if (!pdoData->HardwareIDs) {
125  IoDeleteDevice(pdo);
127  }
128 
129  RtlCopyMemory (pdoData->HardwareIDs, temp, index*sizeof(WCHAR));
130  Bus_InitializePdo (pdo, FdoData);
131 
132  //
133  // Device Relation changes if a new pdo is created. So let
134  // the PNP system now about that. This forces it to send bunch of pnp
135  // queries and cause the function driver to be loaded.
136  //
137 
138  //IoInvalidateDeviceRelations (FdoData->UnderlyingPDO, BusRelations);
139 
140  return status;
141 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP _In_ PDEVICE_OBJECT Device
Definition: fatprocs.h:2020
int acpi_bus_get_device(ACPI_HANDLE handle, struct acpi_device **device)
Definition: bus.c:108
LONG NTSTATUS
Definition: precomp.h:26
static int Link(const char **args)
Definition: vfdcmd.c:2414
#define PAGED_CODE()
Definition: video.h:57
PDEVICE_OBJECT Self
Definition: acpisys.h:28
#define FILE_DEVICE_CONTROLLER
Definition: winioctl.h:109
#define UNICODE_NULL
PWCHAR HardwareIDs
Definition: acpisys.h:44
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
GLuint index
Definition: glext.h:6031
#define ACPI_ROOT_OBJECT
Definition: actypes.h:500
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY ListOfPDOs
Definition: acpisys.h:66
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
struct _PDO_DEVICE_DATA * PPDO_DEVICE_DATA
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define index(s, c)
Definition: various.h:29
static const WCHAR L[]
Definition: oid.c:1250
COMMON_DEVICE_DATA Common
Definition: acpisys.h:58
uint32_t entry
Definition: isohybrid.c:63
Definition: typedefs.h:117
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
ACPI_HANDLE AcpiHandle
Definition: acpisys.h:39
static calc_node_t temp
Definition: rpn_ieee.c:38
struct acpi_device_flags flags
Definition: acpi_bus.h:276
#define DPRINT1
Definition: precomp.h:8
PDEVICE_OBJECT NextLowerDriver
Definition: acpisys.h:63
unsigned int ULONG
Definition: retypes.h:1
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
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
struct acpi_device_pnp pnp
Definition: acpi_bus.h:277
VOID Bus_InitializePdo(PDEVICE_OBJECT Pdo, PFDO_DEVICE_DATA FdoData)
Definition: pnp.c:417
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by ACPIEnumerateDevices().

◆ Bus_PnP()

NTSTATUS NTAPI Bus_PnP ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 25 of file pnp.c.

29 {
30  PIO_STACK_LOCATION irpStack;
32  PCOMMON_DEVICE_DATA commonData;
33 
34  PAGED_CODE ();
35 
36  irpStack = IoGetCurrentIrpStackLocation (Irp);
37  ASSERT (IRP_MJ_PNP == irpStack->MajorFunction);
38 
40 
41 
42  if (commonData->IsFDO) {
43  DPRINT("FDO %s IRP:0x%p\n",
45  Irp);
46  //
47  // Request is for the bus FDO
48  //
51  Irp,
52  irpStack,
53  (PFDO_DEVICE_DATA) commonData);
54  } else {
55  DPRINT("PDO %s IRP: 0x%p\n",
57  Irp);
58  //
59  // Request is for the child PDO.
60  //
63  Irp,
64  irpStack,
65  (PPDO_DEVICE_DATA) commonData);
66  }
67 
68  return status;
69 }
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS Bus_PDO_PnP(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpStack, PPDO_DEVICE_DATA DeviceData)
Definition: buspdo.c:22
#define PAGED_CODE()
Definition: video.h:57
struct _COMMON_DEVICE_DATA * PCOMMON_DEVICE_DATA
PVOID DeviceExtension
Definition: env_spec_w32.h:418
void DPRINT(...)
Definition: polytest.cpp:61
if(!(yy_init))
Definition: macro.lex.yy.c:714
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PCHAR NTAPI PnPMinorFunctionString(UCHAR MinorFunction)
Definition: fbtpnp.c:1831
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
NTSTATUS Bus_FDO_PnP(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpStack, PFDO_DEVICE_DATA DeviceData)
Definition: pnp.c:72
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by DriverEntry().

◆ Bus_SendIrpSynchronously()

NTSTATUS Bus_SendIrpSynchronously ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 322 of file pnp.c.

326 {
327  KEVENT event;
329 
330  PAGED_CODE();
331 
333 
335 
338  &event,
339  TRUE,
340  TRUE,
341  TRUE
342  );
343 
345 
346  //
347  // Wait for lower drivers to be done with the Irp.
348  // Important thing to note here is when you allocate
349  // the memory for an event in the stack you must do a
350  // KernelMode wait instead of UserMode to prevent
351  // the stack from getting paged out.
352  //
353 
354  if (status == STATUS_PENDING) {
356  Executive,
357  KernelMode,
358  FALSE,
359  NULL
360  );
361  status = Irp->IoStatus.Status;
362  }
363 
364  return status;
365 }
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
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
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI Bus_CompletionRoutine(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: pnp.c:369
#define STATUS_PENDING
Definition: ntstatus.h:82
struct _cl_event * event
Definition: glext.h:7739
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
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ Bus_StartFdo()

NTSTATUS Bus_StartFdo ( PFDO_DEVICE_DATA  FdoData,
PIRP  Irp 
)

Definition at line 267 of file pnp.c.

270 {
272  POWER_STATE powerState;
273  ACPI_STATUS AcpiStatus;
274 
275  PAGED_CODE ();
276 
278  powerState.DeviceState = PowerDeviceD0;
279  PoSetPowerState ( FdoData->Common.Self, DevicePowerState, powerState );
280 
281  SET_NEW_PNP_STATE(FdoData->Common, Started);
282 
283  AcpiStatus = AcpiInitializeSubsystem();
284  if(ACPI_FAILURE(AcpiStatus)){
285  DPRINT1("Unable to AcpiInitializeSubsystem\n");
286  return STATUS_UNSUCCESSFUL;
287  }
288 
289  AcpiStatus = AcpiInitializeTables(NULL, 16, 0);
290  if (ACPI_FAILURE(AcpiStatus)){
291  DPRINT1("Unable to AcpiInitializeTables\n");
292  return STATUS_UNSUCCESSFUL;
293  }
294 
295  AcpiStatus = AcpiLoadTables();
296  if(ACPI_FAILURE(AcpiStatus)){
297  DPRINT1("Unable to AcpiLoadTables\n");
298  AcpiTerminate();
299  return STATUS_UNSUCCESSFUL;
300  }
301 
303  if (!NT_SUCCESS(status))
304  {
305  DPRINT1("Unable to create ACPI tables in registry\n");
306  }
307 
308  DPRINT("Acpi subsystem init\n");
309  /* Initialize ACPI bus manager */
310  AcpiStatus = acpi_init();
311  if (!ACPI_SUCCESS(AcpiStatus)) {
312  DPRINT1("acpi_init() failed with status 0x%X\n", AcpiStatus);
313  AcpiTerminate();
314  return STATUS_UNSUCCESSFUL;
315  }
316  status = ACPIEnumerateDevices(FdoData);
317 
318  return status;
319 }
DEVICE_POWER_STATE DevicePowerState
Definition: acpisys.h:33
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
LONG NTSTATUS
Definition: precomp.h:26
UINT32 ACPI_STATUS
Definition: actypes.h:460
ACPI_STATUS ACPI_INIT_FUNCTION AcpiInitializeSubsystem(void)
Definition: utxfinit.c:76
#define PAGED_CODE()
Definition: video.h:57
PDEVICE_OBJECT Self
Definition: acpisys.h:28
NTSTATUS ACPIEnumerateDevices(PFDO_DEVICE_DATA DeviceExtension)
Definition: acpienum.c:146
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
ACPI_STATUS ACPI_INIT_FUNCTION AcpiLoadTables(void)
Definition: tbxfload.c:69
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
ACPI_STATUS ACPI_INIT_FUNCTION AcpiTerminate(void)
Definition: utxface.c:67
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ACPI_STATUS ACPI_INIT_FUNCTION AcpiInitializeTables(ACPI_TABLE_DESC *InitialTableArray, UINT32 InitialTableCount, BOOLEAN AllowResize)
Definition: tbxface.c:107
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
COMMON_DEVICE_DATA Common
Definition: acpisys.h:58
NTSTATUS acpi_create_volatile_registry_tables(void)
Definition: utils.c:522
#define DPRINT1
Definition: precomp.h:8
#define SET_NEW_PNP_STATE(_Data_, _state_)
Definition: fbtusb.h:111
POWER_STATE NTAPI PoSetPowerState(IN PDEVICE_OBJECT DeviceObject, IN POWER_STATE_TYPE Type, IN POWER_STATE State)
Definition: power.c:597
static SERVICE_STATUS status
Definition: service.c:31
int acpi_init(void)
Definition: bus.c:1754
Definition: ps.c:97

Referenced by Bus_FDO_PnP().