Example 5–2 shows a typical _init(9E) interface.
static void *xxstatep; int _init(void) { int error; const int max_instance = 20; /* estimated max device instances */ ddi_soft_state_init(&xxstatep, sizeof (struct xxstate), max_instance); error = mod_install(&xxmodlinkage); if (error != 0) { /* * Cleanup after a failure */ ddi_soft_state_fini(&xxstatep); } return (error); }
The driver should perform any one-time resource allocation or data initialization during driver loading in _init(). For example, it should initialize any mutexes global to the driver in this routine. The driver should not, however, use _init(9E) to allocate or initialize anything that has to do with a particular instance of the device. Per-instance initialization must be done in attach(9E). For example, if a driver for a printer can handle more than one printer at the same time, it should allocate resources specific to each printer instance in attach(9E).
Once _init(9E) has called mod_install(9F), the driver should not change any of the data structures attached to the modlinkage(9S) structure, as the system may make copies of them or change them.