Specifications
D
evice Driver Programming
9-14
manual for additional information. The system buffers are used to implement the tradi-
tional UNIX buffer cache, which is used by block drivers to support I/O operations. The
buffer sizes are the size of a file system block, which depends, in turn, on the file system.
NOTE
Device drivers ported from earlier releases of System V UNIX
kernels often used another kernel buffering technique called
clist. This feature is not supported in this kernel. If you are
porting an existing driver that uses clists, you must modify the
driver.
The kernel provides the following routines for allocating and de-allocating kernel mem-
ory:
kmem_alloc(D3) Allocates space from kernel memory
kmem_free(D3) Frees space allocated with kmem_alloc
kmem_alloc_physcontig(D3) Allocates physically contiguous memory
kmem_free_physcontig(D3) Frees space allocated with
kmem_alloc_physcontig()
All memory allocated via kmem_alloc() is managed by the kernel itself and is allo-
cated from a kernel memory pool available to all drivers. The
kmem_alloc_physcontig() routine is used in the context of DMA programming;
refer to Chapter 14 for additional details.
The kernel also allows a driver to allocate a block of memory from this pool for its own
private use.The private memory pool is allocated as usual via kmem_alloc().The
driver then takes the responsibility of managing the memory. For this purpose, the driver
must use a specially allocated space management map. This map is independent of the
number and size and semantics of the memory units to be managed. The memory units can
be bytes, block, or pages, for example. The kernel routines to be used to manage the pri-
vate memory pool are as follows:
rmallocmap(D3) Allocate and initialize a private space management map
rmalloc(D3) Allocate space from a private space management map
rmfree(D3) Free space into a private space management map; or return space
allocated with a previous call to rmalloc
rmfreemap(D3) Free a private space management map
Typically, these routines are used as follows. The driver allocates its private memory pool
from the kernel memory pool by calling kmem_alloc(). To manage this memory, the
driver invokes rmallocmap() to allocate a private space management map with a suffi-
cient number of entries to span the private memory pool. The driver developer determines
the type and size of the memory units to be managed as desired. For example, for a mem-
ory pool of 16 KB, you can choose a block size of 512 bytes, and thus, to span the memory
pool, at least 32 map entries are required. The driver then adds space to the map by calling
rmfree(). At this point, the driver has reserved the memory for its private use and is