Specifications

D
evice Driver Programming
17-6
Shared Memory Regions 17
Shared memory regions are needed to provide access to a device’s registers and to provide
access to driver-related status information that must be shared by multiple processes. Two
shared memory regions are required for each device controller--a device register region
and a driver status region. The shared memory regions created for a particular controller
are used by all of the user processes that perform I/0 to the controller. Processes’ access to
the shared memory regions must be synchronized.
To provide access to a controller’s registers, you can define a structure that describes the
registers in the user-level driver’s header file. The configuration program for the device
should create a shared memory region for the registers and bind it to the physical location
of the registers in (H)VME space. This shared memory region is hereinafter referred to as
the device register region.
The data structure for the DR11W emulator’s registers, which is defined in the DR11W
user-level driver’s header file, is presented as an example:
/*
* DR11W emulator’s registers
*/
typedef volatile struct dr11w_registers {
unsigned short r_cr_sr;/* CR when written; SR when read */
unsigned short r_data;/* DMA data register (input/output) */
unsigned char r_modifier;/* VME address modifier */
unsigned char r_vector;/* interrupt vector register */
unsigned short r_pcr;/* pulse command register (PCR) */
unsigned char r_unused1[10];
unsigned short r_dma_addr_lo;/* low word of DMA addr (write only) */
unsigned short r_dma_range_lo;/* low word of DMA range (xfer) count */
unsigned short ro_dma_addr_lo;/* low word of DMA addr (read only) */
unsigned char r_unused2[2];
unsigned short r_dma_addr_hi;/* high word of DMA addr (write only) */
unsigned short r_dma_range_hi;/* high byte of DMA range (xfer) count */
unsigned short ro_dma_addr_hi;/* high word of DMA addr (read only) */
} DR11W_REGISTERS;
To provide access to driver status information, you can define a structure to contain such
information in the user-level device driver’s header file. You can then ensure that the
device configuration program creates a shared memory region for the driver status
information. This shared memory region is hereinafter referred to as the driver status
region.
The data structure for the DR11W emulator driver status information, which is defined in
the DR11W user-level driver’s header file, is presented as an example:
typedef volatile struct dr11w_shared {
int owner_pid; /* use owner_pid to mark device opened */
u_int ienb:1; /* flag to mark interrupts enabled */
u_int initial_ienb:1:/* previous status of ienb before
driver */
u_int debug_mode:1; /* flag to mark in debug mode */
u_int initialized:1; /* flag says device has been
initialized */
int shared_id; /* IPC id for status region */