Device Driver Tutorial

Adding the Template Driver

Make sure you are user root when you add the driver. Use the add_drv(1M) command to add the driver:


# add_drv dummy

You should see the following messages in the window where you are viewing /var/adm/messages:


date time machine dummy: [ID 513080 kern.notice] NOTICE: Inside _info
date time machine dummy: [ID 874762 kern.notice] NOTICE: Inside _init
date time machine dummy: [ID 678704 kern.notice] NOTICE: Inside dummy_attach

The _info(9E), _init(9E), and attach(9E) entry points are called in that order when you add a driver.

The dummy driver has been added to the /devices directory:


% ls -l /devices/pseudo | grep dummy
drwxr-xr-x   2 root     sys          512 date time dummy@0
crw-------   1 root     sys       92,  0 date time dummy@0:0

The dummy driver also is the most recent module listed by modinfo(1M):


% modinfo
 Id Loadaddr   Size Info Rev Module Name
180 ed192b70    544  92   1  dummy (dummy driver)

The module name, dummy driver, is the value you entered for the second member of the modldrv(9S) structure. The value 92 is the major number of this module.


% grep dummy /etc/name_to_major
dummy 92

The Loadaddr address of ed192b70 is the address of the first instruction in the dummy driver. This address might be useful, for example, in debugging.


% mdb -k
> dummy`_init $m
    BASE    LIMIT     SIZE NAME
ed192b70 ed192ff0      480 dummy
> $q

The dummy driver also is the most recent module listed by prtconf(1M) in the pseudo device section:


% prtconf -P
    pseudo, instance #0
        dummy, instance #0 (driver not attached)

A driver is automatically loaded when a device that the driver manages is accessed. A driver might be automatically unloaded when the driver is not in use.

If your driver is in the /devices directory but modinfo(1M) does not list your driver, you can use either of the following methods to load your driver: