Writing Device Drivers

Context Management Additions to the State Structure

This chapter adds the following fields to the state structure. See "Software State Structure" for more information.

	kmutex_t				ctx_lock;				/* lock for context switching */
void					*ctx_shared;			/* pointer to shared context */
struct xxctx		*current_ctx;			/* current context structure */

The structure xxctx is the driver private device context structure for the examples used in this section. It looks like this:

	struct xxctx {
 		devmap_cookie_t					handle;
 		offset_t					off;
 		size_t					len;
 		uint_t					flags;
 		void						*context;
 		struct xxstate			*xsp;
 	};
	#define		 XXCTX_SIZE				0x1000		/* size of the context */

The context field stores the actual device context. In this case, it is simply a pointer to a chunk of memory; in other cases, it may actually be a series of structure fields corresponding to device registers.