ChorusOS 5.0 Board Support Package Developer's Guide

The Bus Driver main() Routine

A driver component may be downloaded in various ways. It may be built into the system bootable image or it may be downloaded dynamically as a supervisor actor using the afexec system call. In either case, the driver code must contain the main routine which will be called by the system once the driver component is downloaded.

The only task of the driver's main routine is to perform the self-registration of the driver component within the system. To accomplish this task, the driver invokes the svDriverRegister microkernel call, passing as an argument a DrvRegEntry data structure which specifies the driver component properties.

Once the driver component is self-registered, any future driver management is mostly undertaken by its parent bus/nexus driver (or the DKI module for a host bus driver) using the properties specified in the DrvRegEntry structure. The DrvRegEntry specifies four driver entry points as follows:

drv_probe()

drv_probe() is invoked by the parent bus/nexus driver (or the DKI module for a host bus driver) when bus_class specified in the registry entry matches the parent bus/nexus driver class.

drv_bind()

drv_bind() is invoked by the parent bus/nexus driver (or the DKI module for a host bus driver) when bus_class specified in the registry entry matches the parent bus/nexus driver class.

drv_init()

drv_init() is invoked by the parent bus/nexus driver (or the DKI module for a host bus driver) when bus_class (specified in the registry entry) matches the parent bus class and the driver is bound to a node in the device tree. (Or put more simply, when a hardware device to be managed by the driver exists.)

drv_unload()

drv_unload() is invoked by the driver registry module when an application wishes to unload the driver component from the system.

    /*
     * Driver registry entry for Winbond w83c553 PCI/ISA bridge
     */
static void    drv_bind   (DevNode myNode);
static void    drv_init   (DevNode myNode, void* pciOps, void* pciId);
static KnError drv_unload ();

static DrvRegEntry w83c553Drv = {
    W83C553_DRV_NAME,
    "Winbond w83c553 PCI to ISA bridge" 
    "[#ident \"@(#)w83c553.c 1.5 99/02/23 SMI\"]",
    PCI_CLASS,           /* parent bus class      */
    PCI_VERSION_INITIAL, /* required bus version  */
    NULL,                /* probe method          */
    drv_bind,            /* bind method           */
    drv_init,            /* init method           */
    drv_unload           /* unload method         */
};
    /*
     * Driver main() routine.
     * Called by kernel at driver startup time.
     */
    int
main (int argc, char** argv)
{
    KnError res = svDriverRegister(&w83c553Drv);

    if (res != K_OK) {
        DKI_ERR(("%s: error -- svDriverRegister() failed (%d)\n",
                 w83c553Drv.drv_name, res));
    }
    return res;
}