xref: /reactos/drivers/bus/isapnp/isapnp.h (revision fdc1d96d)
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:     Common header file
5  * COPYRIGHT:   Copyright 2010 Cameron Gutman <cameron.gutman@reactos.org>
6  *              Copyright 2020 Hervé Poussineau <hpoussin@reactos.org>
7  */
8 
9 #ifndef _ISAPNP_PCH_
10 #define _ISAPNP_PCH_
11 
12 #include <ntddk.h>
13 #include <ntstrsafe.h>
14 #include <section_attribs.h>
15 
16 #include "isapnphw.h"
17 #include "isapnpres.h"
18 
19 #include <initguid.h>
20 #include <wdmguid.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define TAG_ISAPNP 'pasI'
27 
28 typedef enum
29 {
30     dsStopped,
31     dsStarted
32 } ISAPNP_DEVICE_STATE;
33 
34 typedef enum _ISAPNP_SIGNATURE
35 {
36     IsaPnpBus = 'odFI',
37     IsaPnpLogicalDevice = 'veDI',
38     IsaPnpReadDataPort = 'pdRI'
39 } ISAPNP_SIGNATURE;
40 
41 typedef struct _ISAPNP_COMMON_EXTENSION
42 {
43     ISAPNP_SIGNATURE Signature;
44     PDEVICE_OBJECT Self;
45     ISAPNP_DEVICE_STATE State;
46 } ISAPNP_COMMON_EXTENSION, *PISAPNP_COMMON_EXTENSION;
47 
48 typedef struct _ISAPNP_FDO_EXTENSION
49 {
50     ISAPNP_COMMON_EXTENSION Common;
51     PDEVICE_OBJECT Ldo;
52     PDEVICE_OBJECT Pdo;
53     PDEVICE_OBJECT ReadPortPdo; /**< @remarks The pointer is NULL for all inactive FDOs. */
54     ULONG BusNumber;
55     KEVENT DeviceSyncEvent;
56 
57     _Guarded_by_(DeviceSyncEvent)
58     LIST_ENTRY DeviceListHead;
59 
60     _Guarded_by_(DeviceSyncEvent)
61     ULONG DeviceCount;
62 
63     PDRIVER_OBJECT DriverObject;
64     PUCHAR ReadDataPort;
65     ULONG Cards;
66     LIST_ENTRY BusLink;
67 } ISAPNP_FDO_EXTENSION, *PISAPNP_FDO_EXTENSION;
68 
69 typedef struct _ISAPNP_PDO_EXTENSION
70 {
71     ISAPNP_COMMON_EXTENSION Common;
72     PISAPNP_FDO_EXTENSION FdoExt;
73 
74     ULONG Flags;
75 #define ISAPNP_ENUMERATED               0x00000001 /**< @brief Whether the device has been reported to the PnP manager. */
76 #define ISAPNP_SCANNED_BY_READ_PORT     0x00000002 /**< @brief The bus has been scanned by Read Port PDO. */
77 #define ISAPNP_READ_PORT_ALLOW_FDO_SCAN 0x00000004 /**< @brief Allows the active FDO to scan the bus. */
78 #define ISAPNP_READ_PORT_NEED_REBALANCE 0x00000008 /**< @brief The I/O resource requirements have changed. */
79 
80     union
81     {
82         /* Data belonging to logical devices */
83         struct
84         {
85             PISAPNP_LOGICAL_DEVICE IsaPnpDevice;
86 
87             PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
88 
89             PCM_RESOURCE_LIST ResourceList;
90             ULONG ResourceListSize;
91         };
92 
93         ULONG SelectedPort;
94     };
95 
96     _Write_guarded_by_(_Global_interlock_)
97     volatile LONG SpecialFiles;
98 } ISAPNP_PDO_EXTENSION, *PISAPNP_PDO_EXTENSION;
99 
100 extern KEVENT BusSyncEvent;
101 
102 _Guarded_by_(BusSyncEvent)
103 extern BOOLEAN ReadPortCreated;
104 
105 _Guarded_by_(BusSyncEvent)
106 extern LIST_ENTRY BusListHead;
107 
108 _Requires_lock_not_held_(BusSyncEvent)
_Acquires_lock_(BusSyncEvent)109 _Acquires_lock_(BusSyncEvent)
110 FORCEINLINE
111 VOID
112 IsaPnpAcquireBusDataLock(VOID)
113 {
114     ASSERT(PsGetCurrentProcess() == PsInitialSystemProcess);
115 
116     KeWaitForSingleObject(&BusSyncEvent, Executive, KernelMode, FALSE, NULL);
117 }
118 
_Releases_lock_(BusSyncEvent)119 _Releases_lock_(BusSyncEvent)
120 FORCEINLINE
121 VOID
122 IsaPnpReleaseBusDataLock(VOID)
123 {
124     KeSetEvent(&BusSyncEvent, IO_NO_INCREMENT, FALSE);
125 }
126 
127 _Requires_lock_not_held_(FdoExt->DeviceSyncEvent)
128 _Acquires_lock_(FdoExt->DeviceSyncEvent)
129 FORCEINLINE
130 VOID
IsaPnpAcquireDeviceDataLock(_In_ PISAPNP_FDO_EXTENSION FdoExt)131 IsaPnpAcquireDeviceDataLock(
132     _In_ PISAPNP_FDO_EXTENSION FdoExt)
133 {
134     ASSERT(PsGetCurrentProcess() == PsInitialSystemProcess);
135 
136     KeWaitForSingleObject(&FdoExt->DeviceSyncEvent, Executive, KernelMode, FALSE, NULL);
137 }
138 
139 _Releases_lock_(FdoExt->DeviceSyncEvent)
140 FORCEINLINE
141 VOID
IsaPnpReleaseDeviceDataLock(_In_ PISAPNP_FDO_EXTENSION FdoExt)142 IsaPnpReleaseDeviceDataLock(
143     _In_ PISAPNP_FDO_EXTENSION FdoExt)
144 {
145     KeSetEvent(&FdoExt->DeviceSyncEvent, IO_NO_INCREMENT, FALSE);
146 }
147 
148 /* isapnp.c */
149 
150 CODE_SEG("PAGE")
151 BOOLEAN
152 FindIoDescriptor(
153     _In_ PISAPNP_LOGICAL_DEVICE LogDevice,
154     _In_opt_ ULONG Base,
155     _In_ ULONG RangeStart,
156     _In_ ULONG RangeEnd,
157     _Out_opt_ PUCHAR Information,
158     _Out_opt_ PULONG Length);
159 
160 CODE_SEG("PAGE")
161 BOOLEAN
162 FindIrqDescriptor(
163     _In_ PISAPNP_LOGICAL_DEVICE LogDevice,
164     _In_ ULONG Vector);
165 
166 CODE_SEG("PAGE")
167 BOOLEAN
168 FindDmaDescriptor(
169     _In_ PISAPNP_LOGICAL_DEVICE LogDevice,
170     _In_ ULONG Channel);
171 
172 CODE_SEG("PAGE")
173 BOOLEAN
174 FindMemoryDescriptor(
175     _In_ PISAPNP_LOGICAL_DEVICE LogDevice,
176     _In_ ULONG RangeStart,
177     _In_ ULONG RangeEnd,
178     _Out_opt_ PUCHAR Information);
179 
180 CODE_SEG("PAGE")
181 PIO_RESOURCE_REQUIREMENTS_LIST
182 IsaPnpCreateReadPortDORequirements(
183     _In_opt_ ULONG SelectedReadPort);
184 
185 CODE_SEG("PAGE")
186 PCM_RESOURCE_LIST
187 IsaPnpCreateReadPortDOResources(VOID);
188 
189 CODE_SEG("PAGE")
190 VOID
191 IsaPnpRemoveReadPortDO(
192     _In_ PDEVICE_OBJECT Pdo);
193 
194 CODE_SEG("PAGE")
195 NTSTATUS
196 IsaPnpFillDeviceRelations(
197     _In_ PISAPNP_FDO_EXTENSION FdoExt,
198     _Inout_ PIRP Irp,
199     _In_ BOOLEAN IncludeDataPort);
200 
201 CODE_SEG("INIT")
202 DRIVER_INITIALIZE DriverEntry;
203 
204 /* fdo.c */
205 CODE_SEG("PAGE")
206 NTSTATUS
207 IsaFdoPnp(
208     _In_ PISAPNP_FDO_EXTENSION FdoExt,
209     _Inout_ PIRP Irp,
210     _In_ PIO_STACK_LOCATION IrpSp);
211 
212 /* interface.c */
213 CODE_SEG("PAGE")
214 NTSTATUS
215 IsaFdoQueryInterface(
216     _In_ PISAPNP_FDO_EXTENSION FdoExt,
217     _In_ PIO_STACK_LOCATION IrpSp);
218 
219 /* pdo.c */
220 CODE_SEG("PAGE")
221 NTSTATUS
222 IsaPdoPnp(
223     _In_ PISAPNP_PDO_EXTENSION PdoDeviceExtension,
224     _Inout_ PIRP Irp,
225     _In_ PIO_STACK_LOCATION IrpSp);
226 
227 CODE_SEG("PAGE")
228 VOID
229 IsaPnpRemoveLogicalDeviceDO(
230     _In_ PDEVICE_OBJECT Pdo);
231 
232 /* hardware.c */
233 CODE_SEG("PAGE")
234 UCHAR
235 IsaHwTryReadDataPort(
236     _In_ PUCHAR ReadDataPort);
237 
238 _Requires_lock_held_(FdoExt->DeviceSyncEvent)
239 CODE_SEG("PAGE")
240 NTSTATUS
241 IsaHwFillDeviceList(
242     _In_ PISAPNP_FDO_EXTENSION FdoExt);
243 
244 CODE_SEG("PAGE")
245 NTSTATUS
246 IsaHwConfigureDevice(
247     _In_ PISAPNP_FDO_EXTENSION FdoExt,
248     _In_ PISAPNP_LOGICAL_DEVICE LogicalDevice,
249     _In_ PCM_RESOURCE_LIST Resources);
250 
251 CODE_SEG("PAGE")
252 VOID
253 IsaHwWakeDevice(
254     _In_ PISAPNP_LOGICAL_DEVICE LogicalDevice);
255 
256 CODE_SEG("PAGE")
257 VOID
258 IsaHwDeactivateDevice(
259     _In_ PISAPNP_LOGICAL_DEVICE LogicalDevice);
260 
261 CODE_SEG("PAGE")
262 VOID
263 IsaHwActivateDevice(
264     _In_ PISAPNP_FDO_EXTENSION FdoExt,
265     _In_ PISAPNP_LOGICAL_DEVICE LogicalDevice);
266 
267 CODE_SEG("PAGE")
268 VOID
269 IsaHwWaitForKey(VOID);
270 
271 #ifdef __cplusplus
272 }
273 #endif
274 
275 #endif /* _ISAPNP_PCH_ */
276