ChorusOS 4.0 Device Driver Framework Guide

Register the Driver (using main function)

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 is called by the system once the driver component is downloaded. The only task of the driver main routine is to perform the self-registration of the driver component within the ChorusOS 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, the future driver management is largely undertaken by its parent bus/nexus driver using the properties specified in the DrvRegEntry structure.

DrvRegEntry specifies four driver entry points as follows:

drv_probe

invoked by the parent bus/nexus driver when bus_class specified in the registry entry matches the parent bus/nexus driver class

drv_bind

invoked by the parent bus/nexus driver when bus_class specified in the registry entry matches the parent bus/nexus driver class

drv_init

invoked by the parent bus/nexus driver when bus_class specified in the registry entry matches the parent bus/nexus class and there is a node in the device tree to which the driver is bound (a hardware device to be managed by the driver exists)

drv_unload

invoked by the driver registry module when an application wishes to unload the driver component from the system

    /*
     * NS16550 driver registry entry.
     * 
     * The driver requires the common bus driver interface
     * implemented by the parent bus driver. Thus, the driver
     * should work on any bus providing such an API (e.g. ISA,
     * PCI, PCMCIA).
     *
     * Note that the driver does not provide any probe routine because
     * the probing mechanism is bus class specific. Thus, if one wants
     * to implement the NS16550 device probing, it may either add probe
     * routine(s) to the driver code or implement probe-only driver(s)
     * for NS16550 device.      
     */
static DrvRegEntry ns16_drv = {
    NS16_DRV_NAME,		  			   					/* drv_name    */
    "NS16x50 UART driver [#ident \"@(#)ns16550.c 1.16 99/02/16 SMI\"]",
    BUS_CLASS,											/* bus_class   */
    BUS_VERSION_INITIAL,								/* bus_version */
    NULL,												/* drv_probe   */
    NULL,												/* drv_bind   */
    ns16_init,											/* drv_init    */
    ns16_unload										/* drv_unload  */
};

    /*
     * Driver main() routine.
     * Called by microkernel at driver initialization time.
     */
    int
main ()
{
    KnError res;
			/*
			 * Register the driver component in the driver registry.
			 */
    res = svDriverRegister(&ns16_drv);
    if (res != K_OK) {
		  	  DKI_ERR(("%s: error -- svDriverRegister() failed (%d)\n",
	                 NS16_DRV_NAME, res));
	  }
	  return res;
}