ReactOS  0.4.15-dev-3193-g74513a7
fdo.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: FDO-specific code
5  * COPYRIGHT: Copyright 2010 Cameron Gutman <cameron.gutman@reactos.org>
6  * Copyright 2020 HervĂ© Poussineau <hpoussin@reactos.org>
7  * Copyright 2021 Dmitry Borisov <di.sean@protonmail.com>
8  */
9 
10 #include "isapnp.h"
11 
12 #define NDEBUG
13 #include <debug.h>
14 
15 static
16 CODE_SEG("PAGE")
21 {
23 
24  PAGED_CODE();
25 
26  if (!IoForwardIrpSynchronously(FdoExt->Ldo, Irp))
27  {
28  return STATUS_UNSUCCESSFUL;
29  }
30  Status = Irp->IoStatus.Status;
31  if (!NT_SUCCESS(Status))
32  {
33  return Status;
34  }
35 
36  FdoExt->Common.State = dsStarted;
37 
38  return STATUS_SUCCESS;
39 }
40 
41 static
42 CODE_SEG("PAGE")
47 {
48  PAGED_CODE();
49 
50  return IsaPnpFillDeviceRelations(FdoExt, Irp, TRUE);
51 }
52 
53 static
54 CODE_SEG("PAGE")
59 {
62 
63  PAGED_CODE();
64 
65  IsaPnpAcquireDeviceDataLock(FdoExt);
66 
67  /* Remove our logical devices */
68  while (!IsListEmpty(&FdoExt->DeviceListHead))
69  {
73  DeviceLink);
74 
75  --FdoExt->DeviceCount;
76 
77  if (LogDevice->Pdo)
78  {
79  IsaPnpRemoveLogicalDeviceDO(LogDevice->Pdo);
80  }
81  }
82 
83  IsaPnpReleaseDeviceDataLock(FdoExt);
84 
85  IsaPnpAcquireBusDataLock();
86 
87  /* Remove the Read Port */
88  if (FdoExt->ReadPortPdo)
89  {
90  IsaPnpRemoveReadPortDO(FdoExt->ReadPortPdo);
91  ReadPortCreated = FALSE;
92  }
93 
94  /* Find the next ISA bus, if any */
95  Entry = BusListHead.Flink;
96  if (Entry != &BusListHead)
97  {
100  BusLink);
101 
102  /* Create a new Read Port for it */
103  if (!ReadPortCreated)
105  }
106 
107  RemoveEntryList(&FdoExt->BusLink);
108 
109  IsaPnpReleaseBusDataLock();
110 
111  Irp->IoStatus.Status = STATUS_SUCCESS;
113  Status = IoCallDriver(FdoExt->Ldo, Irp);
114 
115  IoDetachDevice(FdoExt->Ldo);
116  IoDeleteDevice(FdoExt->Common.Self);
117 
118  return Status;
119 }
120 
121 CODE_SEG("PAGE")
122 NTSTATUS
125  _Inout_ PIRP Irp,
127 {
129 
130  PAGED_CODE();
131 
132  DPRINT("%s(%p, %p) FDO %lu, Minor - %X\n",
133  __FUNCTION__,
134  FdoExt,
135  Irp,
136  FdoExt->BusNumber,
138 
139  switch (IrpSp->MinorFunction)
140  {
141  case IRP_MN_START_DEVICE:
142  Status = IsaFdoStartDevice(FdoExt, Irp);
143 
144  Irp->IoStatus.Status = Status;
146  return Status;
147 
149  {
150  if (IrpSp->Parameters.QueryDeviceRelations.Type != BusRelations)
151  break;
152 
154  if (!NT_SUCCESS(Status))
155  {
156  Irp->IoStatus.Status = Status;
158 
159  return Status;
160  }
161 
162  Irp->IoStatus.Status = Status;
163  break;
164  }
165 
167  return IsaFdoRemoveDevice(FdoExt, Irp);
168 
170  Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
171  Irp->IoStatus.Status = STATUS_SUCCESS;
172  break;
173 
175  {
176  Status = IsaFdoQueryInterface(FdoExt, IrpSp);
178  {
179  break;
180  }
181  else if (!NT_SUCCESS(Status))
182  {
183  Irp->IoStatus.Status = Status;
185 
186  return Status;
187  }
188 
189  Irp->IoStatus.Status = Status;
190  break;
191  }
192 
198  case IRP_MN_STOP_DEVICE:
199  Irp->IoStatus.Status = STATUS_SUCCESS;
200  break;
201 
202  default:
203  DPRINT("Unknown PnP code: %X\n", IrpSp->MinorFunction);
204  break;
205  }
206 
208 
209  return IoCallDriver(FdoExt->Ldo, Irp);
210 }
#define IRP_MN_CANCEL_REMOVE_DEVICE
return STATUS_NOT_SUPPORTED
#define IRP_MN_REMOVE_DEVICE
#define _Inout_
Definition: ms_sal.h:378
struct _Entry Entry
Definition: kefuncs.h:627
NTSTATUS IsaPnpFillDeviceRelations(_In_ PISAPNP_FDO_EXTENSION FdoExt, _Inout_ PIRP Irp, _In_ BOOLEAN IncludeDataPort)
Definition: isapnp.c:1304
static LIST_ENTRY DeviceListHead
Definition: fs.c:52
#define TRUE
Definition: types.h:120
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
VOID IsaPnpRemoveReadPortDO(_In_ PDEVICE_OBJECT Pdo)
Definition: isapnp.c:1284
PDEVICE_OBJECT Pdo
Definition: isapnp.h:159
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
static NTSTATUS IsaFdoRemoveDevice(_In_ PISAPNP_FDO_EXTENSION FdoExt, _Inout_ PIRP Irp)
Definition: fdo.c:56
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_QUERY_REMOVE_DEVICE
#define _In_
Definition: ms_sal.h:308
#define IoCompleteRequest
Definition: irp.c:1240
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PDEVICE_OBJECT Pdo
Definition: isapnp.h:103
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
Status
Definition: gdiplustypes.h:24
static NTSTATUS IsaFdoQueryBusRelations(_In_ PISAPNP_FDO_EXTENSION FdoExt, _Inout_ PIRP Irp)
Definition: fdo.c:44
#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
#define PNP_DEVICE_NOT_DISABLEABLE
Definition: iotypes.h:1006
#define IRP_MN_QUERY_INTERFACE
static NTSTATUS IsaFdoStartDevice(_In_ PISAPNP_FDO_EXTENSION FdoExt, _Inout_ PIRP Irp)
Definition: fdo.c:18
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Definition: typedefs.h:119
VOID IsaPnpRemoveLogicalDeviceDO(_In_ PDEVICE_OBJECT Pdo)
Definition: pdo.c:820
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:2342
_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
NTSTATUS IsaFdoPnp(_In_ PISAPNP_FDO_EXTENSION FdoExt, _Inout_ PIRP Irp, _In_ PIO_STACK_LOCATION IrpSp)
Definition: fdo.c:123
NTSTATUS IsaFdoQueryInterface(_In_ PISAPNP_FDO_EXTENSION FdoExt, _In_ PIO_STACK_LOCATION IrpSp)
Definition: interface.c:19
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_CANCEL_STOP_DEVICE
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
#define __FUNCTION__
Definition: types.h:112
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
base of all file and directory entries
Definition: entries.h:82
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define PAGED_CODE()