Writing Device Drivers

Soft State Management

These interfaces comprise the soft-state structure allocator, a facility that simplifies the management of state structures for driver instances. For best results, use these routines to keep track of per-instance data.

int ddi_soft_state_init(void **state_p,  	
			size_t size, size_t n_items);

ddi_soft_state_init(9F) sets up the soft-state allocator to keep track of soft-state structures for all device instances. state_p points to a pointer to an opaque object that keeps track of the soft-state structures.

void ddi_soft_state_fini(void **state_p);

ddi_soft_state_fini(9F) is the inverse operation to ddi_soft_state_init(9F). state_p points to a pointer to an opaque object that keeps track of the soft-state structures.

int ddi_soft_state_zalloc(void *state, int item);

ddi_soft_state_zalloc(9F) allocates and zeroes a new instance of a soft-state structure. state points to an opaque object that keeps track of the soft-state structures.

void *ddi_get_soft_state(void *state, int item);

ddi_get_soft_state(9F) returns a pointer to the soft-state structure for the device instance item. state points to an opaque object that keeps track of the soft-state structures.

void ddi_soft_state_free(void *state, int item);

ddi_soft_state_free(9F) releases the resources associated with the soft-state structure for item. state points to an opaque object that keeps track of the soft-state structures.