ReactOS 0.4.15-dev-5669-g09dde2c
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
25static CODE_SEG("PAGE") DRIVER_DISPATCH_PAGED IsaStubCreateClose;
26
27static
28CODE_SEG("PAGE")
31IsaStubCreateClose(
34{
36
37 PAGED_CODE();
38
39 Irp->IoStatus.Status = STATUS_SUCCESS;
41
42 return STATUS_SUCCESS;
43}
44
47static CODE_SEG("PAGE") DRIVER_DISPATCH_PAGED IsaStubForward;
48
49static
50CODE_SEG("PAGE")
53IsaStubForward(
56{
57 PISAPNP_FDO_EXTENSION FdoExt = DeviceObject->DeviceExtension;
58
59 PAGED_CODE();
60
62 return IoCallDriver(FdoExt->Ldo, Irp);
63}
64
66static CODE_SEG("PAGE") DRIVER_DISPATCH_PAGED IsaStubPnp;
67
68static
69CODE_SEG("PAGE")
72IsaStubPnp(
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,
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 {
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
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
183static DRIVER_DISPATCH_RAISED IsaStubPower;
184
185static
187NTAPI
188IsaStubPower(
191{
192 PISAPNP_FDO_EXTENSION FdoExt = DeviceObject->DeviceExtension;
193
196 return PoCallDriver(FdoExt->Ldo, Irp);
197}
198
199static CODE_SEG("PAGE") DRIVER_ADD_DEVICE IsaStubAddDevice;
200
201static
202CODE_SEG("PAGE")
204NTAPI
205IsaStubAddDevice(
208{
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 {
242 }
243
244 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
245
246 return STATUS_SUCCESS;
247}
248
249static CODE_SEG("PAGE") DRIVER_UNLOAD IsaStubUnload;
250
251static
252CODE_SEG("PAGE")
253VOID
254NTAPI
255IsaStubUnload(
257{
259
260 PAGED_CODE();
261
262 NOTHING;
263}
264
265CODE_SEG("INIT")
267NTAPI
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 PAGED_CODE()
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define _Dispatch_type_(a)
Definition: btrfs_drv.h:204
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
_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
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
NTSTATUS IsaFdoQueryInterface(_In_ PISAPNP_FDO_EXTENSION FdoExt, _In_ PIO_STACK_LOCATION IrpSp)
Definition: interface.c:19
static CODE_SEG("PAGE")
Definition: stub.c:199
#define __FUNCTION__
Definition: types.h:112
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define ULONG_PTR
Definition: config.h:101
VOID CompleteIrp(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: pnp.c:12
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
#define NOTHING
Definition: input_list.c:10
#define TAG_ISAPNP
Definition: isapnp.h:24
@ IsaPnpBus
Definition: isapnp.h:143
#define _Inout_
Definition: ms_sal.h:378
#define _In_
Definition: ms_sal.h:308
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
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
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define IoCompleteRequest
Definition: irp.c:1240
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
#define IoCallDriver
Definition: irp.c:1225
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:746
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define STATUS_DEVICE_REMOVED
Definition: ntstatus.h:809
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:148
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
ISAPNP_SIGNATURE Signature
Definition: isapnp.h:150
PDEVICE_OBJECT Self
Definition: isapnp.h:151
PDRIVER_OBJECT DriverObject
Definition: isapnp.h:170
PDEVICE_OBJECT Pdo
Definition: isapnp.h:159
ISAPNP_COMMON_EXTENSION Common
Definition: isapnp.h:157
PDEVICE_OBJECT Ldo
Definition: isapnp.h:158
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define IRP_MN_CANCEL_STOP_DEVICE
@ BusRelations
Definition: iotypes.h:2152
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define PNP_DEVICE_NOT_DISABLEABLE
Definition: iotypes.h:1006
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_QUERY_INTERFACE
DRIVER_DISPATCH DRIVER_DISPATCH_RAISED
Definition: iotypes.h:2263
#define IRP_MN_START_DEVICE
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define IRP_MN_STOP_DEVICE
#define IRP_MJ_POWER
#define IRP_MN_QUERY_REMOVE_DEVICE