ReactOS 0.4.15-dev-7934-g1dc8d80
fdo.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Serial enumerator driver
4 * FILE: drivers/bus/serenum/fdo.c
5 * PURPOSE: IRP_MJ_PNP operations for FDOs
6 *
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
8 */
9
10#include "serenum.h"
11
12#include <debug.h>
13
18{
20 PFDO_DEVICE_EXTENSION DeviceExtension;
22
23 TRACE_(SERENUM, "SerenumAddDevice called. Pdo = %p\n", Pdo);
24
25 /* Create new device object */
28 NULL,
31 FALSE,
32 &Fdo);
33 if (!NT_SUCCESS(Status))
34 {
35 WARN_(SERENUM, "IoCreateDevice() failed with status 0x%08lx\n", Status);
36 return Status;
37 }
38 DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
39 RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION));
40
41 /* Register device interface */
43 Pdo,
44 &GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR,
45 NULL,
46 &DeviceExtension->SerenumInterfaceName);
47 if (!NT_SUCCESS(Status))
48 {
49 WARN_(SERENUM, "IoRegisterDeviceInterface() failed with status 0x%08lx\n", Status);
51 return Status;
52 }
53
54 DeviceExtension->Common.IsFDO = TRUE;
55 DeviceExtension->Common.PnpState = dsStopped;
56 DeviceExtension->Pdo = Pdo;
57 IoInitializeRemoveLock(&DeviceExtension->RemoveLock, SERENUM_TAG, 0, 0);
59 if (!NT_SUCCESS(Status))
60 {
61 WARN_(SERENUM, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status);
63 return Status;
64 }
65 if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
66 Fdo->Flags |= DO_POWER_PAGABLE;
67 if (DeviceExtension->LowerDevice->Flags & DO_BUFFERED_IO)
68 Fdo->Flags |= DO_BUFFERED_IO;
69 if (DeviceExtension->LowerDevice->Flags & DO_DIRECT_IO)
70 Fdo->Flags |= DO_DIRECT_IO;
71 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
72
73 return STATUS_SUCCESS;
74}
75
76static NTSTATUS NTAPI
79 IN PIRP Irp)
80{
81 PFDO_DEVICE_EXTENSION DeviceExtension;
83
84 TRACE_(SERENUM, "SerenumFdoStartDevice() called\n");
85 DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
86
87 ASSERT(DeviceExtension->Common.PnpState == dsStopped);
88
90 if (!NT_SUCCESS(Status))
91 {
92 WARN_(SERENUM, "IoSetDeviceInterfaceState() failed with status 0x%08lx\n", Status);
93 return Status;
94 }
95
96 DeviceExtension->Common.PnpState = dsStarted;
97
98 return STATUS_SUCCESS;
99}
100
101static NTSTATUS
104 OUT PDEVICE_RELATIONS* pDeviceRelations)
105{
106 PFDO_DEVICE_EXTENSION DeviceExtension;
107 PDEVICE_RELATIONS DeviceRelations;
108 ULONG NumPDO;
109 ULONG i;
111
112 DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
113 ASSERT(DeviceExtension->Common.IsFDO);
114
115 /* Do enumeration if needed */
116 if (!(DeviceExtension->Flags & FLAG_ENUMERATION_DONE))
117 {
118 ASSERT(DeviceExtension->AttachedPdo == NULL);
119 /* Detect plug-and-play devices */
122 {
123 /* Detect legacy devices */
127 }
128 DeviceExtension->Flags |= FLAG_ENUMERATION_DONE;
129 }
130 NumPDO = (DeviceExtension->AttachedPdo != NULL ? 1 : 0);
131
132 DeviceRelations = (PDEVICE_RELATIONS)ExAllocatePoolWithTag(
133 PagedPool,
134 sizeof(DEVICE_RELATIONS) + sizeof(PDEVICE_OBJECT) * (NumPDO - 1),
136 if (!DeviceRelations)
138
139 /* Fill returned structure */
140 DeviceRelations->Count = NumPDO;
141 for (i = 0; i < NumPDO; i++)
142 {
143 ObReferenceObject(DeviceExtension->AttachedPdo);
144 DeviceRelations->Objects[i] = DeviceExtension->AttachedPdo;
145 }
146
147 *pDeviceRelations = DeviceRelations;
148 return Status;
149}
150
154 IN PIRP Irp)
155{
161
163 MinorFunction = Stack->MinorFunction;
164
165 switch (MinorFunction)
166 {
167 /* FIXME: do all these minor functions
168 IRP_MN_QUERY_REMOVE_DEVICE 0x1
169 IRP_MN_REMOVE_DEVICE 0x2
170 IRP_MN_CANCEL_REMOVE_DEVICE 0x3
171 IRP_MN_STOP_DEVICE 0x4
172 IRP_MN_QUERY_STOP_DEVICE 0x5
173 IRP_MN_CANCEL_STOP_DEVICE 0x6
174 IRP_MN_QUERY_DEVICE_RELATIONS / RemovalRelations (optional) 0x7
175 IRP_MN_QUERY_INTERFACE (optional) 0x8
176 IRP_MN_QUERY_CAPABILITIES (optional) 0x9
177 IRP_MN_QUERY_PNP_DEVICE_STATE (optional) 0x14
178 IRP_MN_DEVICE_USAGE_NOTIFICATION (required or optional) 0x16
179 IRP_MN_SURPRISE_REMOVAL 0x17
180 */
181 case IRP_MN_START_DEVICE: /* 0x0 */
182 {
183 TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
184 /* Call lower driver */
185 FdoExtension = DeviceObject->DeviceExtension;
187
188 if (IoForwardIrpSynchronously(FdoExtension->LowerDevice, Irp))
189 {
190 Status = Irp->IoStatus.Status;
191 if (NT_SUCCESS(Status))
192 {
194 }
195 }
196
197 break;
198 }
199 case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x7 */
200 {
201 switch (Stack->Parameters.QueryDeviceRelations.Type)
202 {
203 case BusRelations:
204 {
205 PDEVICE_RELATIONS DeviceRelations = NULL;
206 TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations\n");
208 Information = (ULONG_PTR)DeviceRelations;
209 break;
210 }
211 default:
212 TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n",
213 Stack->Parameters.QueryDeviceRelations.Type);
215 }
216 break;
217 }
219 {
220 TRACE_(SERENUM, "IRP_MJ_PNP / IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
222 }
223 default:
224 {
225 TRACE_(SERENUM, "IRP_MJ_PNP / unknown minor function 0x%lx\n", MinorFunction);
227 }
228 }
229
230 Irp->IoStatus.Information = Information;
231 Irp->IoStatus.Status = Status;
233 return Status;
234}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define TRACE_(x)
Definition: compat.h:76
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
NTSTATUS SerenumDetectPnpDevice(IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT LowerDevice)
Definition: detect.c:223
NTSTATUS SerenumDetectLegacyDevice(IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT LowerDevice)
Definition: detect.c:444
#define ULONG_PTR
Definition: config.h:101
@ FdoExtension
Definition: precomp.h:48
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
struct _DEVICE_OBJECT * PDEVICE_OBJECT
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
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
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
@ dsStopped
Definition: isapnp.h:34
@ dsStarted
Definition: isapnp.h:35
#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
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
#define IoCompleteRequest
Definition: irp.c:1240
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:148
#define WARN_(ch,...)
Definition: debug.h:157
DRIVER_ADD_DEVICE SerenumAddDevice
Definition: serenum.h:77
#define FLAG_ENUMERATION_DONE
Definition: serenum.h:61
#define SERENUM_TAG
Definition: serenum.h:58
NTSTATUS SerenumFdoPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:152
static NTSTATUS SerenumFdoQueryBusRelations(IN PDEVICE_OBJECT DeviceObject, OUT PDEVICE_RELATIONS *pDeviceRelations)
Definition: fdo.c:102
static NTSTATUS NTAPI SerenumFdoStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:77
#define STATUS_SUCCESS
Definition: shellext.h:65
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
UNICODE_STRING SerenumInterfaceName
Definition: serenum.h:39
PDEVICE_OBJECT LowerDevice
Definition: i8042prt.h:130
PDEVICE_OBJECT AttachedPdo[2]
Definition: parport.h:44
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:84
IO_REMOVE_LOCK RemoveLock
Definition: serenum.h:37
PDEVICE_OBJECT Pdo
Definition: i8042prt.h:128
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1699
_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
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049
#define IoInitializeRemoveLock(Lock, AllocateTag, MaxLockedMinutes, HighWatermark)
Definition: iofuncs.h:2833
@ BusRelations
Definition: iotypes.h:2152
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_START_DEVICE
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define DO_POWER_PAGABLE
#define ObReferenceObject
Definition: obfuncs.h:204