Specifications

D
evice Driver Programming
9-16
btopr(D3) Convert size in bytes to size in pages (round up)
ptob(D3) Convert size in pages to size in bytes
vtop(D3) Convert virtual address to physical address
Data Transfer Routines 9
As mentioned previously, one of the roles of device drivers is to perform data transfers
between user address space and kernel address space. The kernel provides support rou-
tines for this purpose. These routines are often used within the read(D2) and
write(D2) entry points of drivers to transfer data one byte at a time or one or more
bytes at a time.
The kernel provides the following routines for this purpose:
ureadc(D3) Copy a character to space described by uio(D4) structure
uwritec(D3) Return a character from space described by uio(D4) structure
uiomove(D3) Copy data using the uio(D4) structure
These routines use the uio(D4) structure that is passed to the driver through the driver’s
read() and write() entry points. Refer to “The iovec and uio Structures” on page 9-7
for a description of the uio and iovec structures. If the copy is successful, these routines
update the appropriate components of the uio(D4) and iovec(D4) structures. These
components are uio_offset, iov_base, uio_resid, and iov_len.
The ureadc(D3) routine copies a character to the space described by the uio(D4)
structure. The uwritec(D3) routine copies a character from the space described by the
uio(D4) structure and returns the character to the caller.
The uiomove(D3) routine copies data associated with user I/O operations (read and
write). Most frequently, it is used to copy data between user space and kernel space. It can
also be used to copy data exclusively in kernel space.
If the UIO_READ flag is set, uiomove() transfers a specified number of characters from
kernel space to the user’s I/O buffers.
If the UIO_WRITE flag is set, uiomove() transfers a specified number of characters
from the user’s I/O buffers to the kernel space.
The uiomove() routine returns zero on success or an error number on failure.
NOTE
The above three routines exist in both small and large offset ver-
sions. Driver writers should not normally be concerned by this,
since the selections of the correct version needed by their particu-
lar driver is automatically made at compile time. See section
“Small vs. Large Offset Drivers” on page 9-21 for more informa-
tion.