After you decide that neither the simple nor complex lock method is appropriate, use the funnel method to make your driver safe in an SMP environment. To use funnels to force execution of the device driver onto a single CPU, perform the following tasks:
Each of these tasks is described in the following sections.
Use of funnels to force execution of a device driver onto a single CPU works if the device driver's resources are self-contained. This means that the resources are not shared by another device driver or some other entity. If two different device drivers share a resource (for example, a RAM I/O space), then using the funnel mechanism does not protect the integrity of the resource. In this case, you must use the simple or complex lock mechanism to lock the resource in addition to funneling the driver.
You must also use the simple or complex lock mechanism to lock the resource in addition to funneling the driver if your device driver makes use of system resources and the kernel interfaces associated with these resources do not take care of the locking; for example, the kernel passes a map structure to device drivers that call the rminit, rmalloc, rmget, and rmfree interfaces. In this case, the driver is responsible for providing any locking necessary for the map structure that the kernel passes to these interfaces. See Writing Device Drivers: Reference for those kernel interfaces that require your drivers to provide any locking on associated system resources.
To use funnels to force execution of the device driver onto a single CPU, you declare and set the d_funnel member of a dsent structure. You then call the devsw_add interface, which adds your entry to the dsent table and also returns an associated major number. The d_funnel member schedules block and character device drivers onto a CPU in a multiprocessor configuration. You set this member to one of the following constants:
Value | Meaning |
DEV_FUNNEL |
Specifies that you want to funnel the device driver
because you have not made it SMP safe.
This means that the driver is forced to execute on a single (the
master) CPU.
Even if you funnel your device driver, you must follow the SMP locking conventions when accessing kernel data structures external to the driver. Typically, you use kernel interfaces that Digital supplies to indirectly access kernel data structures outside the driver. |
DEV_FUNNEL_NULL | Specifies that you do not want to funnel the device driver because you have made it SMP safe. This means that the driver can execute on multiple CPUs. You make a device driver SMP safe by using the simple or complex lock mechanism. |
You pass the address of this initialized structure to the devsw_add interface.
See Writing Device Drivers: Tutorial for detailed examples and explanations of how to initialize the dsent structure and how to call the devsw_add interface.