OpenCBM
Macros | Functions
PortAccess.c File Reference

Functions for communicating with the parallel port driver. More...

#include <initguid.h>
#include <wdm.h>
#include "cbm_driver.h"

Go to the source code of this file.

Macros

#define DBG_PPORT_VERBOSE(_yy, _xxx, _type)   DBG_PPORT((DBG_PREFIX " --- " #_xxx " = " _type, PnpInfo->_xxx))
 

Functions

NTSTATUS ParPortAllocate (PDEVICE_EXTENSION Pdx)
 Allocate a parallel port for using it. More...
 
NTSTATUS ParPortFree (PDEVICE_EXTENSION Pdx)
 Free a parallel port after using it. More...
 
NTSTATUS ParPortInit (PUNICODE_STRING ParallelPortName, PDEVICE_EXTENSION Pdx)
 Initialize the knowledge on a parallel port. More...
 
NTSTATUS ParPortDeinit (PDEVICE_EXTENSION Pdx)
 Undoes anything ParPortInit has done. More...
 
NTSTATUS ParPortSetModeWdm (PDEVICE_EXTENSION Pdx)
 Set the operational mode of the parallel port, WDM Version. More...
 
NTSTATUS ParPortUnsetModeWdm (PDEVICE_EXTENSION Pdx)
 Unset the operational mode of the parallel port, WDM Version. More...
 
NTSTATUS ParPortAllocInterrupt (PDEVICE_EXTENSION Pdx, PKSERVICE_ROUTINE Isr)
 Allocate an interrupt routine for a parallel port. More...
 
NTSTATUS ParPortFreeInterrupt (PDEVICE_EXTENSION Pdx)
 Free an interrupt routine for a parallel port after using it. More...
 
NTSTATUS ParPortAllowInterruptIoctl (PDEVICE_EXTENSION Pdx)
 Set registry key such that we can get the interrupt of a parallel port. More...
 

Detailed Description

Functions for communicating with the parallel port driver.



Author
Spiro Trikaliotis

Definition in file PortAccess.c.

Macro Definition Documentation

#define DBG_PPORT_VERBOSE (   _yy,
  _xxx,
  _type 
)    DBG_PPORT((DBG_PREFIX " --- " #_xxx " = " _type, PnpInfo->_xxx))

Verbose output of parallel port parameters

Definition at line 369 of file PortAccess.c.

Function Documentation

NTSTATUS ParPortAllocate ( PDEVICE_EXTENSION  Pdx)

Allocate a parallel port for using it.

This function allocates a parallel port, preventing other drivers from accessing it.

Parameters
PdxPointer to a device extension which contains the DEVICE_OBJECT of the parallel port driver.

This function has to be balanced with a corresponding ParPortFree() This function must be run at IRQL == PASSIVE_LEVEL.

Definition at line 157 of file PortAccess.c.

References DBG_ASSERT, and FUNC_ENTER.

Referenced by cbm_lock_parport().

NTSTATUS ParPortAllocInterrupt ( PDEVICE_EXTENSION  Pdx,
PKSERVICE_ROUTINE  Isr 
)

Allocate an interrupt routine for a parallel port.

This function allocates an interrupt service routine for a parallel port.

Parameters
PdxPointer to a device extension which contains the DEVICE_OBJECT of the parallel port driver.
IsrPointer to the interrupt service routine (ISR) which the caller wants to be installed.

This function has to be balanced with a corresponding ParPortFreeInterrupt()

The parallel port has to be already allocated!

This function must be run at IRQL == PASSIVE_LEVEL.

Definition at line 628 of file PortAccess.c.

References DBG_ASSERT, DBG_PREFIX, DBG_WARN, FUNC_ENTER, and LogErrorOnly.

Referenced by cbm_lock_parport().

NTSTATUS ParPortAllowInterruptIoctl ( PDEVICE_EXTENSION  Pdx)

Set registry key such that we can get the interrupt of a parallel port.

This function sets some specific registry key which allows us to allocate an interrupt service routine for a parallel port. Without this key, allocating the interrupt is forbidden for Win 2000, XP, and above.

This is not true for NT4.

Parameters
PdxPointer to a device extension which contains the DEVICE_OBJECT of the parallel port driver.

This function must be run at IRQL == PASSIVE_LEVEL.

Warning
This function cannot be used on NT4! In fact, it is unnecessary there.

Definition at line 729 of file PortAccess.c.

References cbm_registry_close_hardwarekey(), cbm_registry_open_hardwarekey(), cbm_registry_read_ulong(), cbm_registry_write_ulong(), DBG_ASSERT, and FUNC_ENTER.

Referenced by cbm_install().

NTSTATUS ParPortDeinit ( PDEVICE_EXTENSION  Pdx)

Undoes anything ParPortInit has done.

This function undoes anything ParPortInit() has done.

Parameters
PdxDevice extension which will be initialized with the needed knowledge on the parallel port.

This function should be called as part of the unloading process of the driver

One of the purposes of this function is to allow the parallel port driver to be unloaded from memory (via calling ObDereferenceObject()).

This function must be run at IRQL <= DISPATCH_LEVEL.

Definition at line 339 of file PortAccess.c.

References FUNC_ENTER.

Referenced by DriverUnload().

NTSTATUS ParPortFree ( PDEVICE_EXTENSION  Pdx)

Free a parallel port after using it.

This function frees a previously allocated parallel port.

Parameters
PdxPointer to a device extension which contains the DEVICE_OBJECT of the parallel port driver.

If the parallel port has not been already allocated, this function just returns.

This function must be run at IRQL == PASSIVE_LEVEL.

Definition at line 195 of file PortAccess.c.

References DBG_ASSERT, and FUNC_ENTER.

Referenced by cbm_lock_parport(), and cbm_unlock_parport().

NTSTATUS ParPortFreeInterrupt ( PDEVICE_EXTENSION  Pdx)

Free an interrupt routine for a parallel port after using it.

This function frees a previously allocated parallel port.

Parameters
PdxPointer to a device extension which contains the DEVICE_OBJECT of the parallel port driver.

If the parallel port interrupt has not been already allocated, this function just returns.

This function must be run at IRQL == PASSIVE_LEVEL.

Definition at line 680 of file PortAccess.c.

References DBG_ASSERT, and FUNC_ENTER.

Referenced by cbm_lock_parport(), and cbm_unlock_parport().

NTSTATUS ParPortInit ( PUNICODE_STRING  ParallelPortName,
PDEVICE_EXTENSION  Pdx 
)

Initialize the knowledge on a parallel port.

This function gets some knowledge on a parallel port, and stores this info into the given DEVICE_EXTENSION.

Parameters
ParallelPortNameUNICODE_STRING which holds the name of the parallel port driver
PdxDevice extension which will be initialized with the needed knowledge on the parallel port.

This function should be called before any other parallel port function is called. Usually, it is done in the driver's AddDevice (WDM) or DriverEntry (WKM, WDM) function.

One of the purposes of this function is to make sure the parallel port driver is not unloaded from memory (via IoGetDeviceObjectPointer()).

This function must be run at IRQL == PASSIVE_LEVEL.

Definition at line 253 of file PortAccess.c.

References DBG_ASSERT, DBG_PPORT, DBG_PREFIX, DBG_WARN, FUNC_ENTER, and MTAG_PPINFO.

Referenced by AddDeviceCommonInit().

NTSTATUS ParPortSetModeWdm ( PDEVICE_EXTENSION  Pdx)

Set the operational mode of the parallel port, WDM Version.

This function sets the operational mode of the parallel port.

Parameters
PdxPointer to a device extension which contains the DEVICE_OBJECT of the parallel port driver.

This function has to be balanced with a corresponding ParPortUnsetModeWdm()

This function must be run at IRQL == PASSIVE_LEVEL.

Definition at line 461 of file PortAccess.c.

References DBG_PPORT, DBG_PREFIX, DebugNtStatus(), FUNC_ENTER, ParPortUnsetMode(), and READ_PORT_UCHAR.

Referenced by ParPortSetMode().

NTSTATUS ParPortUnsetModeWdm ( PDEVICE_EXTENSION  Pdx)

Unset the operational mode of the parallel port, WDM Version.

This function unsets the operational mode of the parallel port.

Parameters
PdxPointer to a device extension which contains the DEVICE_OBJECT of the parallel port driver.

This function mustn't be called without a prior call to ParPortSetModeWdm()

This function must be run at IRQL == PASSIVE_LEVEL.

Definition at line 549 of file PortAccess.c.

References DBG_PPORT, DBG_PREFIX, DebugNtStatus(), FUNC_ENTER, and READ_PORT_UCHAR.

Referenced by ParPortUnsetMode().