ReactOS  0.4.15-dev-3440-g915569a
stub.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS ISA PnP Bus driver
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Stub driver
5  * COPYRIGHT: Copyright 2021 Dmitry Borisov <di.sean@protonmail.com>
6  */
7 
8 /*
9  * This driver does nothing, and only used if a platform has no ISA PnP support.
10  * We need to keep FDO because ACPI driver depends on it. The ACPI bus filter
11  * attaches legacy ISA/LPC devices to this FDO.
12  */
13 
14 /* INCLUDES *******************************************************************/
15 
16 #include "isapnp.h"
17 
18 #define NDEBUG
19 #include <debug.h>
20 
21 /* FUNCTIONS ******************************************************************/
22 
25 static CODE_SEG("PAGE") DRIVER_DISPATCH_PAGED IsaStubCreateClose;
26 
27 static
28 CODE_SEG("PAGE")
30 NTAPI
31 IsaStubCreateClose(
34 {
36 
37  PAGED_CODE();
38 
39  Irp->IoStatus.Status = STATUS_SUCCESS;
41 
42  return STATUS_SUCCESS;
43 }
44 
47 static CODE_SEG("PAGE") DRIVER_DISPATCH_PAGED IsaStubForward;
48 
49 static
50 CODE_SEG("PAGE")
52 NTAPI
53 IsaStubForward(
56 {
57  PISAPNP_FDO_EXTENSION FdoExt = DeviceObject->DeviceExtension;
58 
59  PAGED_CODE();
60 
62  return IoCallDriver(FdoExt->Ldo, Irp);
63 }
64 
66 static CODE_SEG("PAGE") DRIVER_DISPATCH_PAGED IsaStubPnp;
67 
68 static
69 CODE_SEG("PAGE")
71 NTAPI
72 IsaStubPnp(
75 {
76  PISAPNP_FDO_EXTENSION FdoExt = DeviceObject->DeviceExtension;
79 
80  PAGED_CODE();
81 
82  DPRINT("%s(%p, %p) Minor - %X\n",
84  FdoExt,
85  Irp,
87 
88  switch (IrpSp->MinorFunction)
89  {
91  {
92  if (IoForwardIrpSynchronously(FdoExt->Ldo, Irp))
93  Status = Irp->IoStatus.Status;
94  else
96 
97  goto CompleteIrp;
98  }
99 
101  {
102  PDEVICE_RELATIONS DeviceRelations;
103 
104  if (IrpSp->Parameters.QueryDeviceRelations.Type != BusRelations)
105  break;
106 
107  DeviceRelations = ExAllocatePoolWithTag(PagedPool,
108  FIELD_OFFSET(DEVICE_RELATIONS, Objects),
109  TAG_ISAPNP);
110  if (!DeviceRelations)
111  {
113  goto CompleteIrp;
114  }
115 
116  DeviceRelations->Count = 0;
117 
118  Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
119  Irp->IoStatus.Status = STATUS_SUCCESS;
120  break;
121  }
122 
124  {
125  Irp->IoStatus.Status = STATUS_SUCCESS;
127  Status = IoCallDriver(FdoExt->Ldo, Irp);
128 
129  IoDetachDevice(FdoExt->Ldo);
130  IoDeleteDevice(FdoExt->Common.Self);
131 
132  return Status;
133  }
134 
136  {
137  Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
138  Irp->IoStatus.Status = STATUS_SUCCESS;
139  break;
140  }
141 
143  {
144  Status = IsaFdoQueryInterface(FdoExt, IrpSp);
146  {
147  break;
148  }
149  else if (!NT_SUCCESS(Status))
150  {
151  goto CompleteIrp;
152  }
153 
154  Irp->IoStatus.Status = Status;
155  break;
156  }
157 
162  case IRP_MN_STOP_DEVICE:
164  {
165  Irp->IoStatus.Status = STATUS_SUCCESS;
166  break;
167  }
168 
169  default:
170  break;
171  }
172 
174  return IoCallDriver(FdoExt->Ldo, Irp);
175 
177  Irp->IoStatus.Status = Status;
179  return Status;
180 }
181 
183 static DRIVER_DISPATCH_RAISED IsaStubPower;
184 
185 static
186 NTSTATUS
187 NTAPI
188 IsaStubPower(
190  _Inout_ PIRP Irp)
191 {
192  PISAPNP_FDO_EXTENSION FdoExt = DeviceObject->DeviceExtension;
193 
196  return PoCallDriver(FdoExt->Ldo, Irp);
197 }
198 
199 static CODE_SEG("PAGE") DRIVER_ADD_DEVICE IsaStubAddDevice;
200 
201 static
202 CODE_SEG("PAGE")
203 NTSTATUS
204 NTAPI
205 IsaStubAddDevice(
208 {
210  PISAPNP_FDO_EXTENSION FdoExt;
212 
213  PAGED_CODE();
214 
216 
218  sizeof(ISAPNP_FDO_EXTENSION),
219  NULL,
222  FALSE,
223  &Fdo);
224  if (!NT_SUCCESS(Status))
225  {
226  DPRINT1("Failed to create FDO (0x%08lx)\n", Status);
227  return Status;
228  }
229 
230  FdoExt = Fdo->DeviceExtension;
231 
232  RtlZeroMemory(FdoExt, sizeof(ISAPNP_FDO_EXTENSION));
233  FdoExt->Common.Self = Fdo;
234  FdoExt->Common.Signature = IsaPnpBus;
235  FdoExt->DriverObject = DriverObject;
236  FdoExt->Pdo = PhysicalDeviceObject;
238  if (!FdoExt->Ldo)
239  {
241  return STATUS_DEVICE_REMOVED;
242  }
243 
244  Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
245 
246  return STATUS_SUCCESS;
247 }
248 
249 static CODE_SEG("PAGE") DRIVER_UNLOAD IsaStubUnload;
250 
251 static
252 CODE_SEG("PAGE")
253 VOID
254 NTAPI
255 IsaStubUnload(
257 {
259 
260  PAGED_CODE();
261 
262  NOTHING;
263 }
264 
265 CODE_SEG("INIT")
266 NTSTATUS
267 NTAPI
271 {
272  DPRINT("%s(%p, %wZ)\n", __FUNCTION__, DriverObject, RegistryPath);
273 
274  DriverObject->MajorFunction[IRP_MJ_CREATE] = IsaStubCreateClose;
275  DriverObject->MajorFunction[IRP_MJ_CLOSE] = IsaStubCreateClose;
276  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = IsaStubForward;
277  DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = IsaStubForward;
278  DriverObject->MajorFunction[IRP_MJ_PNP] = IsaStubPnp;
279  DriverObject->MajorFunction[IRP_MJ_POWER] = IsaStubPower;
280  DriverObject->DriverExtension->AddDevice = IsaStubAddDevice;
281  DriverObject->DriverUnload = IsaStubUnload;
282 
283  return STATUS_SUCCESS;
284 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define IRP_MN_CANCEL_REMOVE_DEVICE
return STATUS_NOT_SUPPORTED
#define STATUS_DEVICE_REMOVED
Definition: ntstatus.h:809
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MN_REMOVE_DEVICE
#define _Inout_
Definition: ms_sal.h:378
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
PDEVICE_OBJECT Pdo
Definition: isapnp.h:159
NTSTATUS NTAPI DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
Definition: stub.c:268
VOID CompleteIrp(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: pnp.c:12
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_QUERY_REMOVE_DEVICE
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
#define _In_
Definition: ms_sal.h:308
#define IoCompleteRequest
Definition: irp.c:1240
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#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
ISAPNP_COMMON_EXTENSION Common
Definition: isapnp.h:157
#define IRP_MN_START_DEVICE
#define PNP_DEVICE_NOT_DISABLEABLE
Definition: iotypes.h:1006
#define IRP_MN_QUERY_INTERFACE
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static CODE_SEG("PAGE")
Definition: stub.c:199
#define NOTHING
Definition: env_spec_w32.h:461
#define IRP_MJ_SYSTEM_CONTROL
__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
_Dispatch_type_(IRP_MJ_CREATE)
Definition: stub.c:23
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:746
PDRIVER_OBJECT DriverObject
Definition: isapnp.h:170
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NULL
Definition: types.h:112
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
ISAPNP_SIGNATURE Signature
Definition: isapnp.h:150
NTSTATUS IsaFdoQueryInterface(_In_ PISAPNP_FDO_EXTENSION FdoExt, _In_ PIO_STACK_LOCATION IrpSp)
Definition: interface.c:19
#define IO_NO_INCREMENT
Definition: iotypes.h:598
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
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define IRP_MN_CANCEL_STOP_DEVICE
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
PDEVICE_OBJECT Ldo
Definition: isapnp.h:158
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
DRIVER_DISPATCH DRIVER_DISPATCH_RAISED
Definition: iotypes.h:2263
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:148
#define __FUNCTION__
Definition: types.h:112
PDEVICE_OBJECT Self
Definition: isapnp.h:151
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define TAG_ISAPNP
Definition: isapnp.h:24
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define PAGED_CODE()