Next | Prev | Up | Top | Contents | Index

Allocating Objects of Specific Kinds

The kernel provides a number of functions with the purpose of allocating and freeing objects of specific kinds. Many of these are variants of kmem_alloc() and kmem_free(), but others use special techniques suited to the type of object.


Allocating pollhead Objects

Table 9-4 summarizes the functions you use to allocate and free the pollhead structure that is used within the pfxpoll() entry point (see "Entry Point poll()"). Typically you would call phalloc() while initializing each minor device, and call phfree() in the pfxunload() entry point.

Functions for Allocating pollhead Structures
Function NameHeader FilesCan Sleep?Purpose
phalloc(D3) ddi.h & kmem.h & poll.hYAllocate and initialize a pollhead structure.
phfree(D3) ddi.h & poll.hNFree a pollhead structure.


Allocating Semaphores and Locks

There are symmetrical pairs of functions to allocate and free all types of lock and synchronization objects. These functions are summarized together with the other locking functions under "Waiting and Mutual Exclusion".


Allocating buf_t Objects and Buffers

The argument to the pfxstrategy() entry point is a buf_t structure that describes a buffer (see "Entry Point strategy()" and "Structure buf_t").

Ordinarily, both the buf_t and the buffer are allocated and initialized by the kernel or the filesystem that calls pfxstrategy(). However, some drivers need to create a buf_t and associated buffer for special uses. The functions summarized in Table 9-5 are used for this.

Functions for Allocating buf_t Objects and Buffers
Function NameHeader FilesCan Sleep?Purpose
geteblk(D3) ddi.hYAllocate a buf_t and a buffer of 1024 bytes.
ngeteblk(D3) ddi.hYAllocate a buf_t and a buffer of specified size.
brelse(D3) ddi.hNReturn a buffer header and buffer to the system.
getrbuf(D3) ddi.hYAllocate a buf_t with no buffer.
freerbuf(D3) ddi.hNFree a buf_t with no buffer.

To allocate a buf_t and its associated buffer in kernel virtual memory, use either geteblk() or ngeteblk(). Free this pair of objects using brelse(), or by calling biodone().

You can allocate a buf_t to describe an existing buffer--one in user space, statically allocated in the driver, or allocated with kmem_alloc()--using getrbuf(). Free such a buf_t using freerbuf().


Next | Prev | Up | Top | Contents | Index