Specifications

D
evice Driver Programming
17-8
1. Define a reserved section of physical memory by initializing the
res_sects[] array in the /etc/conf/pack.d/mm/space.c file.
The size of the section that you reserve should be bound by the size of the
largest single data transfer that can be made by using the particular DMA
device or the size of the largest single transfer that the application makes.
2. Create a region of shared memory, and bind it to the reserved section of
physical memory by using the /usr/sbin/shmconfig(1M)
command. Completing this step provides a user-level process access to the
reserved memory.
3. Obtain the shared memory identifier associated with the shared memory
region.
Procedures for completing each of these steps are explained in detail in the PowerUX Pro-
gramming Guide. After these steps have been performed, a user application can attach the
shared memory region to its virtual address space and use the region as an I/O buffer.
A user-level device driver can require that the application’s I/O buffer be contained within
a single page. You can ensure that the I/O buffer fits within a page by using the
valloc(3C) library routine to allocate memory that begins on a page boundary and by
limiting the size of the buffer to less than the size of a page (for information on the
valloc(3C) library routine, refer to the corresponding system manual page).
The udbuf_t structure has been defined to describe the layout in physical memory of the
user’s I/O buffer. For user-level device drivers written by Concurrent Computer Corpora-
tion personnel, routines that perform I/O operations are required to use this structure to
describe the buffer where I/O is to be performed. The user creates a udbuf_t structure by
supplying the virtual address and length of the I/O buffer on a call to the
udbufalloc(3X) routine. This routine is described in “The userdma(2) System Call”
on page 17-15.
The udbuf_t structure is defined in the file <userdrive.h> as follows:
typedef struct udbuf{
char *virtual_addr;
int length;
int flags;
int nfrags;
struct dmavec *dma_vec;
} udbuf_t;
The fields in the structure are described as follows:
virtual_addr a pointer to the virtual address of the user’s I/O buffer
length the length in bytes of the buffer pointed to by virtual_addr
flags the control flags that have been passed to udbufalloc(3X)
nfrags the number of physical buffer fragments described by the array
pointed to by dma_vec
dma_vec a pointer to an array of dmavec structures that describe the
physical location of the buffer. These structures are created when