Writing Device Drivers

Software State Structure

For each device that the driver handles, the driver must keep some state information. At a minimum, this consists of a pointer to the dev_info node for the device (required by getinfo(9E)). The driver can define a structure that contains all the information needed about a single device:

	struct xxstate {
 		dev_info_t			*dip;
 	};

This structure will grow as the device driver evolves. Additional useful fields might be a pointer to each of the device's mapped registers, or flags such as busy or suspended. The initial state structure the examples in this book use is given in Example 3-3.


Example 3-3 Initial State Structure

struct xxstate {
		dev_info_t								*dip;
		struct device_reg								*regp;
		int 								xx_busy;					
		struct xx_saved_device_state									device_state;
};

Subsequent chapters in this manual may require that new fields be added to the state structure. Each chapter will list any additions.