ReactOS  0.4.15-dev-3718-g2318f7f
fdo.c File Reference
#include "pci.h"
#include <debug.h>
Include dependency graph for fdo.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static NTSTATUS FdoLocateChildDevice (PPCI_DEVICE *Device, PFDO_DEVICE_EXTENSION DeviceExtension, PCI_SLOT_NUMBER SlotNumber, PPCI_COMMON_CONFIG PciConfig)
 
static NTSTATUS FdoEnumerateDevices (PDEVICE_OBJECT DeviceObject)
 
static NTSTATUS FdoQueryBusRelations (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
static NTSTATUS FdoStartDevice (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS FdoPnpControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS FdoPowerControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file fdo.c.

Function Documentation

◆ FdoEnumerateDevices()

static NTSTATUS FdoEnumerateDevices ( PDEVICE_OBJECT  DeviceObject)
static

Definition at line 54 of file fdo.c.

56 {
57  PFDO_DEVICE_EXTENSION DeviceExtension;
58  PCI_COMMON_CONFIG PciConfig;
62  ULONG FunctionNumber;
63  ULONG Size;
65 
66  DPRINT("Called\n");
67 
68  DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
69 
70  DeviceExtension->DeviceListCount = 0;
71 
72  /* Enumerate devices on the PCI bus */
73  SlotNumber.u.AsULONG = 0;
75  {
76  SlotNumber.u.bits.DeviceNumber = DeviceNumber;
77  for (FunctionNumber = 0; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
78  {
79  SlotNumber.u.bits.FunctionNumber = FunctionNumber;
80 
81  DPRINT("Bus %1lu Device %2lu Func %1lu\n",
82  DeviceExtension->BusNumber,
84  FunctionNumber);
85 
86  RtlZeroMemory(&PciConfig,
87  sizeof(PCI_COMMON_CONFIG));
88 
90  DeviceExtension->BusNumber,
91  SlotNumber.u.AsULONG,
92  &PciConfig,
94  DPRINT("Size %lu\n", Size);
96  {
97  if (FunctionNumber == 0)
98  {
99  break;
100  }
101  else
102  {
103  continue;
104  }
105  }
106 
107  DPRINT("Bus %1lu Device %2lu Func %1lu VenID 0x%04hx DevID 0x%04hx\n",
108  DeviceExtension->BusNumber,
109  DeviceNumber,
110  FunctionNumber,
111  PciConfig.VendorID,
112  PciConfig.DeviceID);
113 
114  if (PciConfig.VendorID == 0 && PciConfig.DeviceID == 0)
115  {
116  DPRINT("Filter out devices with null vendor and device ID\n");
117  continue;
118  }
119 
120  Status = FdoLocateChildDevice(&Device, DeviceExtension, SlotNumber, &PciConfig);
121  if (!NT_SUCCESS(Status))
122  {
124  if (!Device)
125  {
126  /* FIXME: Cleanup resources for already discovered devices */
128  }
129 
131  sizeof(PCI_DEVICE));
132 
133  Device->BusNumber = DeviceExtension->BusNumber;
134 
135  RtlCopyMemory(&Device->SlotNumber,
136  &SlotNumber,
137  sizeof(PCI_SLOT_NUMBER));
138 
139  RtlCopyMemory(&Device->PciConfig,
140  &PciConfig,
141  sizeof(PCI_COMMON_CONFIG));
142 
144  &DeviceExtension->DeviceListHead,
145  &Device->ListEntry,
146  &DeviceExtension->DeviceListLock);
147  }
148 
149  DeviceExtension->DeviceListCount++;
150 
151  /* Skip to next device if the current one is not a multifunction device */
152  if ((FunctionNumber == 0) &&
153  ((PciConfig.HeaderType & 0x80) == 0))
154  {
155  break;
156  }
157  }
158  }
159 
160  DPRINT("Done\n");
161 
162  return STATUS_SUCCESS;
163 }
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:65
ULONG DeviceListCount
Definition: pci.h:91
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
Definition: pci.h:9
KSPIN_LOCK DeviceListLock
Definition: pci.h:93
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define PCI_MAX_DEVICES
Definition: iotypes.h:3598
#define for
Definition: utility.h:88
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG BusNumber
Definition: pci.h:85
#define TAG_PCI
Definition: pci.h:7
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
LIST_ENTRY DeviceListHead
Definition: pci.h:89
#define PCI_MAX_FUNCTION
Definition: iotypes.h:3599
unsigned int ULONG
Definition: retypes.h:1
NTHALAPI ULONG NTAPI HalGetBusData(BUS_DATA_TYPE, ULONG, ULONG, PVOID, ULONG)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
static NTSTATUS FdoLocateChildDevice(PPCI_DEVICE *Device, PFDO_DEVICE_EXTENSION DeviceExtension, PCI_SLOT_NUMBER SlotNumber, PPCI_COMMON_CONFIG PciConfig)
Definition: fdo.c:18
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1229
#define DPRINT
Definition: sndvol32.h:71
#define PCI_COMMON_HDR_LENGTH
Definition: iotypes.h:3594

Referenced by FdoQueryBusRelations().

◆ FdoLocateChildDevice()

static NTSTATUS FdoLocateChildDevice ( PPCI_DEVICE Device,
PFDO_DEVICE_EXTENSION  DeviceExtension,
PCI_SLOT_NUMBER  SlotNumber,
PPCI_COMMON_CONFIG  PciConfig 
)
static

Definition at line 18 of file fdo.c.

23 {
24  PLIST_ENTRY CurrentEntry;
25  PPCI_DEVICE CurrentDevice;
26 
27  DPRINT("Called\n");
28 
29  CurrentEntry = DeviceExtension->DeviceListHead.Flink;
30  while (CurrentEntry != &DeviceExtension->DeviceListHead)
31  {
32  CurrentDevice = CONTAINING_RECORD(CurrentEntry, PCI_DEVICE, ListEntry);
33 
34  /* If both vendor ID and device ID match, it is the same device */
35  if ((PciConfig->VendorID == CurrentDevice->PciConfig.VendorID) &&
36  (PciConfig->DeviceID == CurrentDevice->PciConfig.DeviceID) &&
37  (SlotNumber.u.AsULONG == CurrentDevice->SlotNumber.u.AsULONG))
38  {
39  *Device = CurrentDevice;
40  DPRINT("Done\n");
41  return STATUS_SUCCESS;
42  }
43 
44  CurrentEntry = CurrentEntry->Flink;
45  }
46 
47  *Device = NULL;
48  DPRINT("Done\n");
49  return STATUS_UNSUCCESSFUL;
50 }
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:65
Definition: pci.h:9
union _PCI_SLOT_NUMBER::@3770 u
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Definition: typedefs.h:119
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
LIST_ENTRY DeviceListHead
Definition: pci.h:89
PCI_SLOT_NUMBER SlotNumber
Definition: pci.h:18
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
PCI_COMMON_CONFIG PciConfig
Definition: pci.h:20

Referenced by FdoEnumerateDevices().

◆ FdoPnpControl()

NTSTATUS FdoPnpControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 428 of file fdo.c.

439 {
440  PFDO_DEVICE_EXTENSION DeviceExtension;
442  NTSTATUS Status = Irp->IoStatus.Status;
443 
444  DPRINT("Called\n");
445 
446  DeviceExtension = DeviceObject->DeviceExtension;
447 
449  switch (IrpSp->MinorFunction)
450  {
451 #if 0
454  break;
455 
458  break;
459 
462  break;
463 
466  break;
467 #endif
469  if (IrpSp->Parameters.QueryDeviceRelations.Type != BusRelations)
470  break;
471 
473  Irp->IoStatus.Status = Status;
475  return Status;
476 #if 0
479  break;
480 
483  break;
484 #endif
485  case IRP_MN_START_DEVICE:
486  DPRINT("IRP_MN_START_DEVICE received\n");
488 
489  if (IoForwardIrpSynchronously(DeviceExtension->Ldo, Irp))
490  {
491  Status = Irp->IoStatus.Status;
492  if (NT_SUCCESS(Status))
493  {
495  }
496  }
497 
498  Irp->IoStatus.Status = Status;
500  return Status;
501 
503  /* We don't support stopping yet */
505  Irp->IoStatus.Status = Status;
507  return Status;
508 
509  case IRP_MN_STOP_DEVICE:
510  /* We can't fail this one so we fail the QUERY_STOP request that precedes it */
511  break;
512 #if 0
515  break;
516 #endif
517 
519  break;
520 
522  /* Detach the device object from the device stack */
523  IoDetachDevice(DeviceExtension->Ldo);
524 
525  /* Delete the device object */
527 
528  /* Return success */
530  break;
531 
534  /* Don't print the warning, too much noise */
535  break;
536 
537  default:
538  DPRINT1("Unknown PNP minor function 0x%x\n", IrpSp->MinorFunction);
539  break;
540  }
541 
542  Irp->IoStatus.Status = Status;
544  Status = IoCallDriver(DeviceExtension->Ldo, Irp);
545 
546  DPRINT("Leaving. Status 0x%lx\n", Status);
547 
548  return Status;
549 }
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define IRP_MN_REMOVE_DEVICE
static NTSTATUS FdoStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:352
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
PDEVICE_OBJECT Ldo
Definition: pci.h:95
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
return STATUS_NOT_IMPLEMENTED
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_QUERY_REMOVE_DEVICE
#define IoCompleteRequest
Definition: irp.c:1240
#define IRP_MN_QUERY_STOP_DEVICE
Status
Definition: gdiplustypes.h:24
#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
static NTSTATUS FdoQueryBusRelations(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: fdo.c:167
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_CANCEL_STOP_DEVICE
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IRP_MN_DEVICE_USAGE_NOTIFICATION
#define DPRINT
Definition: sndvol32.h:71
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define IRP_MN_QUERY_CAPABILITIES

Referenced by PciPnpControl().

◆ FdoPowerControl()

NTSTATUS FdoPowerControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 553 of file fdo.c.

564 {
565  PFDO_DEVICE_EXTENSION DeviceExtension;
567 
568  DPRINT("Called\n");
569 
570  DeviceExtension = DeviceObject->DeviceExtension;
571 
574  Status = PoCallDriver(DeviceExtension->Ldo, Irp);
575 
576  DPRINT("Leaving. Status 0x%X\n", Status);
577 
578  return Status;
579 }
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT Ldo
Definition: pci.h:95
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
Status
Definition: gdiplustypes.h:24
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:746
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define DPRINT
Definition: sndvol32.h:71

Referenced by PciPowerControl().

◆ FdoQueryBusRelations()

static NTSTATUS FdoQueryBusRelations ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)
static

Definition at line 167 of file fdo.c.

171 {
172  PPDO_DEVICE_EXTENSION PdoDeviceExtension = NULL;
173  PFDO_DEVICE_EXTENSION DeviceExtension;
174  PDEVICE_RELATIONS Relations;
175  PLIST_ENTRY CurrentEntry;
178  BOOLEAN ErrorOccurred;
179  NTSTATUS ErrorStatus;
180  ULONG Size;
181  ULONG i;
182 
184 
185  DPRINT("Called\n");
186 
187  ErrorStatus = STATUS_INSUFFICIENT_RESOURCES;
188 
190 
191  ErrorOccurred = FALSE;
192 
194 
195  DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
196 
197  if (Irp->IoStatus.Information)
198  {
199  /* FIXME: Another bus driver has already created a DEVICE_RELATIONS
200  structure so we must merge this structure with our own */
201  DPRINT1("FIXME: leaking old bus relations\n");
202  }
203 
204  Size = sizeof(DEVICE_RELATIONS) +
205  sizeof(Relations->Objects) * (DeviceExtension->DeviceListCount - 1);
207  if (!Relations)
209 
210  Relations->Count = DeviceExtension->DeviceListCount;
211 
212  i = 0;
213  CurrentEntry = DeviceExtension->DeviceListHead.Flink;
214  while (CurrentEntry != &DeviceExtension->DeviceListHead)
215  {
216  Device = CONTAINING_RECORD(CurrentEntry, PCI_DEVICE, ListEntry);
217 
218  PdoDeviceExtension = NULL;
219 
220  if (!Device->Pdo)
221  {
222  /* Create a physical device object for the
223  device as it does not already have one */
224  Status = IoCreateDevice(DeviceObject->DriverObject,
225  sizeof(PDO_DEVICE_EXTENSION),
226  NULL,
229  FALSE,
230  &Device->Pdo);
231  if (!NT_SUCCESS(Status))
232  {
233  DPRINT("IoCreateDevice() failed with status 0x%X\n", Status);
234  ErrorStatus = Status;
235  ErrorOccurred = TRUE;
236  break;
237  }
238 
239  Device->Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
240 
241  //Device->Pdo->Flags |= DO_POWER_PAGABLE;
242 
243  PdoDeviceExtension = (PPDO_DEVICE_EXTENSION)Device->Pdo->DeviceExtension;
244 
245  RtlZeroMemory(PdoDeviceExtension, sizeof(PDO_DEVICE_EXTENSION));
246 
247  PdoDeviceExtension->Common.IsFDO = FALSE;
248 
249  PdoDeviceExtension->Common.DeviceObject = Device->Pdo;
250 
251  PdoDeviceExtension->Common.DevicePowerState = PowerDeviceD0;
252 
253  PdoDeviceExtension->Fdo = DeviceObject;
254 
255  PdoDeviceExtension->PciDevice = Device;
256 
257  /* Add Device ID string */
258  Status = PciCreateDeviceIDString(&PdoDeviceExtension->DeviceID, Device);
259  if (!NT_SUCCESS(Status))
260  {
261  ErrorStatus = Status;
262  ErrorOccurred = TRUE;
263  break;
264  }
265 
266  DPRINT("DeviceID: %S\n", PdoDeviceExtension->DeviceID.Buffer);
267 
268  /* Add Instance ID string */
269  Status = PciCreateInstanceIDString(&PdoDeviceExtension->InstanceID, Device);
270  if (!NT_SUCCESS(Status))
271  {
272  ErrorStatus = Status;
273  ErrorOccurred = TRUE;
274  break;
275  }
276 
277  /* Add Hardware IDs string */
278  Status = PciCreateHardwareIDsString(&PdoDeviceExtension->HardwareIDs, Device);
279  if (!NT_SUCCESS(Status))
280  {
281  ErrorStatus = Status;
282  ErrorOccurred = TRUE;
283  break;
284  }
285 
286  /* Add Compatible IDs string */
287  Status = PciCreateCompatibleIDsString(&PdoDeviceExtension->CompatibleIDs, Device);
288  if (!NT_SUCCESS(Status))
289  {
290  ErrorStatus = Status;
291  ErrorOccurred = TRUE;
292  break;
293  }
294 
295  /* Add device description string */
297  if (!NT_SUCCESS(Status))
298  {
299  ErrorStatus = Status;
300  ErrorOccurred = TRUE;
301  break;
302  }
303 
304  /* Add device location string */
306  if (!NT_SUCCESS(Status))
307  {
308  ErrorStatus = Status;
309  ErrorOccurred = TRUE;
310  break;
311  }
312  }
313 
314  /* Reference the physical device object. The PnP manager
315  will dereference it again when it is no longer needed */
317 
318  Relations->Objects[i] = Device->Pdo;
319 
320  i++;
321 
322  CurrentEntry = CurrentEntry->Flink;
323  }
324 
325  if (ErrorOccurred)
326  {
327  /* FIXME: Cleanup all new PDOs created in this call. Please give me SEH!!! ;-) */
328  /* FIXME: Should IoAttachDeviceToDeviceStack() be undone? */
329  if (PdoDeviceExtension)
330  {
331  RtlFreeUnicodeString(&PdoDeviceExtension->DeviceID);
332  RtlFreeUnicodeString(&PdoDeviceExtension->InstanceID);
333  RtlFreeUnicodeString(&PdoDeviceExtension->HardwareIDs);
334  RtlFreeUnicodeString(&PdoDeviceExtension->CompatibleIDs);
335  RtlFreeUnicodeString(&PdoDeviceExtension->DeviceDescription);
336  RtlFreeUnicodeString(&PdoDeviceExtension->DeviceLocation);
337  }
338 
339  ExFreePoolWithTag(Relations, TAG_PCI);
340  return ErrorStatus;
341  }
342 
343  Irp->IoStatus.Information = (ULONG_PTR)Relations;
344 
345  DPRINT("Done\n");
346 
347  return Status;
348 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
ULONG DeviceListCount
Definition: pci.h:91
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TRUE
Definition: types.h:120
NTSTATUS PciCreateDeviceDescriptionString(PUNICODE_STRING DeviceDescription, PPCI_DEVICE Device)
Definition: pci.c:378
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
LONG NTSTATUS
Definition: precomp.h:26
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
PDEVICE_OBJECT Fdo
Definition: pci.h:58
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
PPCI_DEVICE PciDevice
Definition: pci.h:60
static NTSTATUS PciCreateCompatibleIDsString(PUNICODE_STRING CompatibleIDs)
Definition: fdo.c:246
Definition: pci.h:9
if(dx==0 &&dy==0)
Definition: linetemp.h:174
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
PDEVICE_OBJECT DeviceObject
Definition: kstypes.h:153
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FILE_DEVICE_CONTROLLER
Definition: winioctl.h:110
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
unsigned char BOOLEAN
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:56
#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
Status
Definition: gdiplustypes.h:24
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
UNICODE_STRING DeviceLocation
Definition: pci.h:72
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
UNICODE_STRING HardwareIDs
Definition: pci.h:66
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
UNICODE_STRING DeviceDescription
Definition: pci.h:70
static NTSTATUS FdoEnumerateDevices(PDEVICE_OBJECT DeviceObject)
Definition: fdo.c:54
#define TAG_PCI
Definition: pci.h:7
Definition: typedefs.h:119
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
LIST_ENTRY DeviceListHead
Definition: pci.h:89
struct _DEVICE_RELATIONS DEVICE_RELATIONS
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
static NTSTATUS PciCreateHardwareIDsString(PUNICODE_STRING HardwareIDs)
Definition: fdo.c:224
static NTSTATUS PciCreateInstanceIDString(PUNICODE_STRING InstanceID, ULONG PeripheralNumber)
Definition: fdo.c:268
NTSTATUS PciCreateDeviceIDString(PUNICODE_STRING DeviceID, PPCI_DEVICE Device)
Definition: pci.c:232
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
UNICODE_STRING InstanceID
Definition: pci.h:64
NTSTATUS PciCreateDeviceLocationString(PUNICODE_STRING DeviceLocation, PPCI_DEVICE Device)
Definition: pci.c:646
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define ObReferenceObject
Definition: obfuncs.h:204
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
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
UNICODE_STRING DeviceID
Definition: pci.h:62
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
UNICODE_STRING CompatibleIDs
Definition: pci.h:68
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by FdoPnpControl().

◆ FdoStartDevice()

static NTSTATUS FdoStartDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 352 of file fdo.c.

355 {
356  PFDO_DEVICE_EXTENSION DeviceExtension;
358  PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor;
359  ULONG FoundBusNumber = FALSE;
360  ULONG i;
361 
362  DPRINT("Called\n");
363 
364  DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
365 
366  AllocatedResources = IoGetCurrentIrpStackLocation(Irp)->Parameters.StartDevice.AllocatedResources;
367  if (!AllocatedResources)
368  {
369  DPRINT("No allocated resources sent to driver\n");
371  }
372 
373  if (AllocatedResources->Count < 1)
374  {
375  DPRINT("Not enough allocated resources sent to driver\n");
377  }
378 
379  if (AllocatedResources->List[0].PartialResourceList.Version != 1 ||
380  AllocatedResources->List[0].PartialResourceList.Revision != 1)
382 
383  ASSERT(DeviceExtension->State == dsStopped);
384 
385  /* By default, use the bus number in the resource list header */
386  DeviceExtension->BusNumber = AllocatedResources->List[0].BusNumber;
387 
388  for (i = 0; i < AllocatedResources->List[0].PartialResourceList.Count; i++)
389  {
390  ResourceDescriptor = &AllocatedResources->List[0].PartialResourceList.PartialDescriptors[i];
391  switch (ResourceDescriptor->Type)
392  {
394  if (FoundBusNumber || ResourceDescriptor->u.BusNumber.Length < 1)
396 
397  /* Use this one instead */
398  ASSERT(AllocatedResources->List[0].BusNumber == ResourceDescriptor->u.BusNumber.Start);
399  DeviceExtension->BusNumber = ResourceDescriptor->u.BusNumber.Start;
400  DPRINT("Found bus number resource: %lu\n", DeviceExtension->BusNumber);
401  FoundBusNumber = TRUE;
402  break;
403 
404  default:
405  DPRINT("Unknown resource descriptor type 0x%x\n", ResourceDescriptor->Type);
406  }
407  }
408 
409  InitializeListHead(&DeviceExtension->DeviceListHead);
410  KeInitializeSpinLock(&DeviceExtension->DeviceListLock);
411  DeviceExtension->DeviceListCount = 0;
412  DeviceExtension->State = dsStarted;
413 
416  &DeviceExtension->ListEntry,
418 
419  Irp->IoStatus.Information = 0;
420 
421  return STATUS_SUCCESS;
422 }
#define STATUS_REVISION_MISMATCH
Definition: ntstatus.h:325
ULONG DeviceListCount
Definition: pci.h:91
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResources
Definition: ndis.h:4640
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LIST_ENTRY ListEntry
Definition: pci.h:83
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@377::@385 BusNumber
KSPIN_LOCK DeviceListLock
Definition: pci.h:93
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@377 u
#define ASSERT(a)
Definition: mode.c:44
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
KSPIN_LOCK BusListLock
Definition: pci.h:105
PCI_DEVICE_STATE State
Definition: pci.h:87
ULONG BusNumber
Definition: pci.h:85
LIST_ENTRY BusListHead
Definition: pci.h:103
LIST_ENTRY DeviceListHead
Definition: pci.h:89
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
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 InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:31
unsigned int ULONG
Definition: retypes.h:1
#define CmResourceTypeBusNumber
Definition: hwresource.cpp:128
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128

Referenced by FdoPnpControl().