Next | Prev | Up | Top | Contents | Index

General Data Transfer

The kernel supplies functions for clearing and copying memory within the kernel virtual address space, and between the kernel address space and the address space of the user process that is the current context. These general-purpose functions are summarized in Table 9-7.

Functions for General Data Transfer
Function NameHeader FilesCan Sleep?Purpose
bcopy(D3) ddi.hNCopy data between address locations in the kernel.
bzero(D3) ddi.hNClear memory for a given number of bytes.
copyin(D3) ddi.hYCopy data from a user buffer to a driver buffer.
copyout(D3) ddi.hYCopy data from a driver buffer to a user buffer.
fubyte(D3) systm.h & types.hYLoad a byte from user space.
fuword(D3) systm.h & types.hYLoad a word from user space.
hwcpin(D3) systm.h & types.hNCopy data from device registers to kernel memory.
hwcpout(D3) systm.h & types.hNCopy data from kernel memory to device registers.
subyte(D3) systm.h & types.hYStore a byte to user space.
suword(D3) systm.h & types.hYStore a word to user space.


Block Copy Functions

The bcopy() and bzero() functions are used to copy and clear data areas within the kernel address space, for example driver buffers or work areas. These are optimized routines that take advantage of available hardware features.

The bcopy() function is not appropriate for copying data between a buffer and a device; that is, for copying between virtual memory and the physical memory addresses that represent a range of device registers (or indeed any uncached memory). The reason is that bcopy() uses doubleword moves and any other special hardware features available, and devices many not be able to accept data in these units. The hwcpin() and hwcpout() functions copy data in 16-bit units; use them to transfer bulk data between device space and memory. (Use simple assignment to move single words or bytes.)

The copyin() and copyout() functions take a kernel virtual address, a process virtual address, and a length. They copy the specified number of bytes between the kernel space and the user space. They select the best algorithm for copying, and take advantage of memory alignment and other hardware features.

If there is no current context, or if the address in user space is invalid, or if the address plus length is not contained in the user space, the functions return -1. This indicates an error in the request passed to the driver entry point, and the driver normally returns an EFAULT error.


Byte and Word Functions

The functions fubyte(), subyte(), fuword(), and suword() are used to move single items to or from user space. When only a single byte or word is needed, these functions have less overhead than the corresponding copyin() or copyout() call. For example you could use fuword() to pick up a parameter using an address passed to the pfxioctl() entry point. When transferring more than a few bytes, a block move is more efficient.


Next | Prev | Up | Top | Contents | Index