OpenCBM
arch_cbm_driver.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 2005-2007 Spiro Trikaliotis
8  *
9  */
10 
19 /* Include any configuration definitions */
20 #include "config.h"
21 
24 #define DVRH_USE_PARPORT_ECP_ADDR 1
25 
26 #include <parallel.h>
27 
29 #define DBG_PROGNAME "OPENCBM.SYS"
30 
31 #include "cbmioctl.h"
32 #include "memtags.h"
33 #include "util.h"
34 #include "queue.h"
35 #include "cbmlog.h"
36 
38 #define CBMDEVICENAME L"\\DosDevices\\opencbm"
39 
41 typedef
43 
44  /* Windows book keeping: */
45 
47  PDEVICE_OBJECT Fdo;
48 
50  BOOLEAN IsNT4;
51 
58 
64  UNICODE_STRING DeviceName;
65 
68 
70  PFILE_OBJECT ParallelPortFileObject;
71 
73  PDEVICE_OBJECT ParallelPortFdo;
74 
76  PPARALLEL_PORT_INFORMATION PortInfo;
77 
79  PARALLEL_INTERRUPT_SERVICE_ROUTINE Pisr;
80 
82  PARALLEL_INTERRUPT_INFORMATION Pii;
83 
87 
90 
93 
96 
99 
102 
107 
109  HANDLE ThreadHandle;
110 
112  PKTHREAD Thread;
113 
115  BOOLEAN QuitThread;
116 
119 
121 #if DBG
123 #endif
124 
127 
129 
130 extern VOID
131 DriverUnload(IN PDRIVER_OBJECT DriverObject);
132 
133 extern NTSTATUS
134 DriverCommonInit(IN PDRIVER_OBJECT Driverobject, IN PUNICODE_STRING RegistryPath);
135 
136 extern VOID
137 DriverCommonUninit(VOID);
138 
139 extern NTSTATUS
140 AddDeviceCommonInit(IN PDEVICE_OBJECT Fdo, IN PUNICODE_STRING DeviceName, IN PCWSTR ParallelPortName);
141 
142 extern NTSTATUS
143 cbm_install(IN PDEVICE_EXTENSION Pdx, OUT PCBMT_I_INSTALL_OUT ReturnBuffer, IN OUT PULONG ReturnLength);
144 
145 extern NTSTATUS
146 cbm_lock(IN PDEVICE_EXTENSION Pdx);
147 
148 extern NTSTATUS
149 cbm_unlock(IN PDEVICE_EXTENSION Pdx);
150 
151 extern NTSTATUS
152 cbm_lock_parport(IN PDEVICE_EXTENSION Pdx);
153 
154 extern NTSTATUS
155 cbm_unlock_parport(IN PDEVICE_EXTENSION Pdx);
156 
157 #if DBG
158 extern NTSTATUS
159 cbm_dbg_readbuffer(IN PDEVICE_EXTENSION Pdx, OUT PCHAR ReturnBuffer, IN OUT PULONG ReturnLength);
160 #endif // #if DBG
161 
162 extern VOID
163 cbm_init_registry(IN PUNICODE_STRING RegistryPath, IN PDEVICE_EXTENSION Pdx);
164 
165 extern VOID
166 cbm_initialize_cable_deferred(IN PDEVICE_EXTENSION Pdx);
167 
168 extern NTSTATUS
169 cbm_startio(IN PDEVICE_OBJECT Fdo, IN PIRP Irp);
170 
171 extern NTSTATUS
172 cbm_createopenclose(IN PDEVICE_OBJECT Fdo, IN PIRP Irp);
173 
174 extern NTSTATUS
175 cbm_readwrite(IN PDEVICE_OBJECT Fdo, IN PIRP Irp);
176 
177 extern NTSTATUS
178 cbm_execute_readwrite(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp);
179 
180 extern NTSTATUS
181 cbm_execute_createopen(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp);
182 
183 extern NTSTATUS
184 cbm_cleanup(IN PDEVICE_OBJECT Fdo, IN PIRP Irp);
185 
186 extern NTSTATUS
187 cbm_execute_close(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp);
188 
189 extern NTSTATUS
190 cbm_devicecontrol(IN PDEVICE_OBJECT Fdo, IN PIRP Irp);
191 
192 extern NTSTATUS
193 cbm_execute_devicecontrol(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp);
194 
195 extern BOOLEAN
196 cbm_isr(IN PKINTERRUPT Interrupt, IN PVOID Pdx);
197 
198 extern VOID
199 cbm_thread(IN PVOID Context);
200 
201 extern NTSTATUS
202 cbm_start_thread(IN PDEVICE_EXTENSION Pdx);
203 
204 extern VOID
205 cbm_stop_thread(IN PDEVICE_EXTENSION Pdx);
206 
207 #ifndef PENUMERATE_DEFINED
208 
209  typedef PVOID PENUMERATE;
210 #endif
211 
212 extern NTSTATUS
213 ParPortEnumerateOpen(PENUMERATE *EnumStruct);
214 
215 extern NTSTATUS
216 ParPortEnumerate(PENUMERATE EnumStruct, PCWSTR *DriverName);
217 
218 extern VOID
220 
221 extern NTSTATUS
222 ParPortInit(PUNICODE_STRING ParallelPortName, PDEVICE_EXTENSION Pdx);
223 
224 extern NTSTATUS
225 ParPortDeinit(PDEVICE_EXTENSION Pdx);
226 
227 extern NTSTATUS
228 ParPortAllocate(PDEVICE_EXTENSION Pdx);
229 
230 extern NTSTATUS
231 ParPortFree(PDEVICE_EXTENSION Pdx);
232 
233 extern NTSTATUS
234 ParPortSetMode(PDEVICE_EXTENSION Pdx);
235 
236 extern NTSTATUS
237 ParPortUnsetMode(PDEVICE_EXTENSION Pdx);
238 
239 extern NTSTATUS
240 ParPortSetModeWdm(PDEVICE_EXTENSION Pdx);
241 
242 extern NTSTATUS
243 ParPortUnsetModeWdm(PDEVICE_EXTENSION Pdx);
244 
245 extern NTSTATUS
246 ParPortAllocInterrupt(PDEVICE_EXTENSION Pdx, PKSERVICE_ROUTINE Isr);
247 
248 extern NTSTATUS
249 ParPortFreeInterrupt(PDEVICE_EXTENSION Pdx);
250 
251 extern NTSTATUS
252 ParPortAllowInterruptIoctl(PDEVICE_EXTENSION Pdx);
253 
254 extern NTSTATUS
255 cbm_registry_open_for_read(OUT PHANDLE HandleKey, IN PUNICODE_STRING Path);
256 
257 extern NTSTATUS
258 cbm_registry_open_hardwarekey(OUT PHANDLE HandleKey, OUT PDEVICE_OBJECT *Pdo,
259  IN PDEVICE_EXTENSION Pdx);
260 
261 extern NTSTATUS
262 cbm_registry_close(IN HANDLE HandleKey);
263 
264 extern NTSTATUS
265 cbm_registry_close_hardwarekey(IN HANDLE HandleKey, IN PDEVICE_OBJECT Pdo);
266 
267 extern NTSTATUS
268 cbm_registry_read_ulong(IN HANDLE HandleKey, IN PCWSTR KeyName, OUT PULONG Value);
269 
270 extern NTSTATUS
271 cbm_registry_write_ulong(IN HANDLE HandleKey, IN PCWSTR KeyName, IN ULONG Value);
272 
273 extern NTSTATUS
274 CbmOpenDeviceRegistryKey(IN PDEVICE_OBJECT a, IN ULONG b, IN ACCESS_MASK c, OUT PHANDLE d);
275 
276 extern ULONG
278 
279 extern ULONG
281 
282 extern VOID
283 CLI(VOID);
284 
285 extern VOID
286 STI(VOID);
NTSTATUS cbm_lock(IN PDEVICE_EXTENSION Pdx)
Lock the parallel port for the driver.
Definition: lockunlock.c:179
BOOLEAN cbm_isr(IN PKINTERRUPT Interrupt, IN PVOID Pdx)
Interrupt Service Routine (ISR)
Definition: isr.c:38
NTSTATUS cbm_execute_createopen(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp)
Execute IRPs containing the IRP_MJ_CREATEOPEN I/O function code.
PARALLEL_INTERRUPT_INFORMATION Pii
struct _ARCH_DEVICE_EXTENSION ARCH_DEVICE_EXTENSION
PDEVICE_OBJECT ParallelPortFdo
NTSTATUS cbm_start_thread(IN PDEVICE_EXTENSION Pdx)
Start the worker thread.
Definition: thread.c:34
PARALLEL_INTERRUPT_SERVICE_ROUTINE Pisr
VOID CLI(VOID)
Stop interrupts with CLI assembler command.
Definition: amd64/clisti.c:28
NTSTATUS cbm_unlock_parport(IN PDEVICE_EXTENSION Pdx)
Unlock the parallel port for the driver.
Definition: lockunlock.c:128
NTSTATUS AddDeviceCommonInit(IN PDEVICE_OBJECT Fdo, IN PUNICODE_STRING DeviceName, IN PCWSTR ParallelPortName)
Initialize device object, common to WDM and NT4 driver.
UNICODE_STRING DeviceName
NTSTATUS cbm_execute_readwrite(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp)
Executes reads from or writes to the driver.
Definition: readwrite.c:178
VOID cbm_initialize_cable_deferred(IN PDEVICE_EXTENSION Pdx)
Initialize the cable.
NTSTATUS DriverCommonInit(IN PDRIVER_OBJECT Driverobject, IN PUNICODE_STRING RegistryPath)
Perform driver initialization, common to WDM and NT4 driver.
NTSTATUS ParPortSetMode(PDEVICE_EXTENSION Pdx)
Set the operational mode of the parallel port.
Definitions for the configuration of the cbm4win driver.
VOID DriverUnload(IN PDRIVER_OBJECT DriverObject)
Unload routine of the driver.
ULONG CbmGetCurrentProcessorNumber(VOID)
Wrapper for KeGetCurrentProcessorNumber()
Definition: processor.c:31
NTSTATUS ParPortAllowInterruptIoctl(PDEVICE_EXTENSION Pdx)
Set registry key such that we can get the interrupt of a parallel port.
Definition: PortAccess.c:729
Define the IOCTL codes for the opencbm driver.
NTSTATUS cbm_readwrite(IN PDEVICE_OBJECT Fdo, IN PIRP Irp)
Services reads from or writes to the driver.
Definition: readwrite.c:84
NTSTATUS CbmOpenDeviceRegistryKey(IN PDEVICE_OBJECT a, IN ULONG b, IN ACCESS_MASK c, OUT PHANDLE d)
Stub for a function.
Definition: nt4/PortEnum.c:303
NTSTATUS cbm_registry_close(IN HANDLE HandleKey)
Close a registry key.
Definition: util-reg.c:230
NTSTATUS ParPortEnumerate(PENUMERATE EnumStruct, PCWSTR *DriverName)
Get next enumerated parallel port driver.
Definition: nt4/PortEnum.c:196
VOID cbm_thread(IN PVOID Context)
The thread function.
Definition: thread.c:165
NTSTATUS cbm_registry_open_hardwarekey(OUT PHANDLE HandleKey, OUT PDEVICE_OBJECT *Pdo, IN PDEVICE_EXTENSION Pdx)
Open the hardware key for another driver.
Definition: util-reg.c:95
NTSTATUS cbm_dbg_readbuffer(IN PDEVICE_EXTENSION Pdx, OUT PCHAR ReturnBuffer, IN OUT PULONG ReturnLength)
Give the debug buffer contents to the installer.
A QUEUE object A QUEUE object is an object which can be used to queue IRPs for processing. This QUEUE object is optimized for being polled from an own worker thread. Anyway, a concept called FastStart is also implemented, which allows some IRPs to be completed immediately, without being queued, if no IRP is executed yet and the caller has stated that he wants this IRP to be started fast if possible.
Definition: queue.h:40
Definitions for the queueing functions.
VOID cbm_stop_thread(IN PDEVICE_EXTENSION Pdx)
Stop the worker thread.
Definition: thread.c:117
VOID ParPortEnumerateClose(PENUMERATE EnumStruct)
Stop enumeration of the parallel port drivers.
Definition: nt4/PortEnum.c:264
NTSTATUS cbm_createopenclose(IN PDEVICE_OBJECT Fdo, IN PIRP Irp)
Services IRPs containing the IRP_MJ_CREATE or IRP_MJ_CLOSE I/O function code.
NTSTATUS cbm_registry_read_ulong(IN HANDLE HandleKey, IN PCWSTR KeyName, OUT PULONG Value)
Read a ULONG value out of a registry key.
Definition: util-reg.c:299
NTSTATUS ParPortSetModeWdm(PDEVICE_EXTENSION Pdx)
Set the operational mode of the parallel port, WDM Version.
Definition: PortAccess.c:461
NTSTATUS cbm_cleanup(IN PDEVICE_OBJECT Fdo, IN PIRP Irp)
Services IRPs containing the IRP_MJ_CLEANUP I/O function code.
Definition: cleanup.c:44
Define tags for ExAllocatePoolWithTag()
NTSTATUS cbm_devicecontrol(IN PDEVICE_OBJECT Fdo, IN PIRP Irp)
Services IOCTLs.
Definition: ioctl.c:115
Some utility helpers.
NTSTATUS ParPortFree(PDEVICE_EXTENSION Pdx)
Free a parallel port after using it.
Definition: PortAccess.c:195
NTSTATUS cbm_lock_parport(IN PDEVICE_EXTENSION Pdx)
Lock the parallel port for the driver.
Definition: lockunlock.c:39
NTSTATUS ParPortUnsetMode(PDEVICE_EXTENSION Pdx)
Unset the operational mode of the parallel port.
VOID cbm_init_registry(IN PUNICODE_STRING RegistryPath, IN PDEVICE_EXTENSION Pdx)
Initialize from registry.
VOID DriverCommonUninit(VOID)
Undo what DriverCommonInit() has done.
PFILE_OBJECT ParallelPortFileObject
VOID STI(VOID)
Restart interrupts with STI assembler command.
Definition: amd64/clisti.c:38
NTSTATUS ParPortEnumerateOpen(PENUMERATE *EnumStruct)
Start enumeration of the parallel port drivers.
Definition: nt4/PortEnum.c:74
BOOLEAN ParallelPortAllocatedInterrupt
NTSTATUS cbm_startio(IN PDEVICE_OBJECT Fdo, IN PIRP Irp)
Execute an IRP.
Definition: startio.c:39
NTSTATUS cbm_unlock(IN PDEVICE_EXTENSION Pdx)
Unlock the parallel port for the driver.
Definition: lockunlock.c:208
NTSTATUS cbm_install(IN PDEVICE_EXTENSION Pdx, OUT PCBMT_I_INSTALL_OUT ReturnBuffer, IN OUT PULONG ReturnLength)
Complete driver installation.
ULONG CbmGetNumberProcessors(VOID)
Get the number of processors in the system.
Definition: processor.c:57
NTSTATUS ParPortInit(PUNICODE_STRING ParallelPortName, PDEVICE_EXTENSION Pdx)
Initialize the knowledge on a parallel port.
Definition: PortAccess.c:253
NTSTATUS ParPortDeinit(PDEVICE_EXTENSION Pdx)
Undoes anything ParPortInit has done.
Definition: PortAccess.c:339
NTSTATUS cbm_execute_devicecontrol(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp)
Executes IOCTLs.
Definition: ioctl.c:363
NTSTATUS ParPortAllocate(PDEVICE_EXTENSION Pdx)
Allocate a parallel port for using it.
Definition: PortAccess.c:157
NTSTATUS cbm_registry_close_hardwarekey(IN HANDLE HandleKey, IN PDEVICE_OBJECT Pdo)
Close a hardware registry key.
Definition: util-reg.c:260
NTSTATUS ParPortAllocInterrupt(PDEVICE_EXTENSION Pdx, PKSERVICE_ROUTINE Isr)
Allocate an interrupt routine for a parallel port.
Definition: PortAccess.c:628
NTSTATUS cbm_execute_close(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp)
Execute IRPs containing the IRP_MJ_CLOSE I/O function code.
PPARALLEL_PORT_INFORMATION PortInfo
NTSTATUS ParPortUnsetModeWdm(PDEVICE_EXTENSION Pdx)
Unset the operational mode of the parallel port, WDM Version.
Definition: PortAccess.c:549
NTSTATUS cbm_registry_open_for_read(OUT PHANDLE HandleKey, IN PUNICODE_STRING Path)
Open a registry path for reading.
Definition: util-reg.c:43
NTSTATUS ParPortFreeInterrupt(PDEVICE_EXTENSION Pdx)
Free an interrupt routine for a parallel port after using it.
Definition: PortAccess.c:680
PVOID PENUMERATE
NTSTATUS cbm_registry_write_ulong(IN HANDLE HandleKey, IN PCWSTR KeyName, IN ULONG Value)
Write a ULONG value out of a registry key.
Definition: util-reg.c:356