Device driver overview

Driver structure

The following discussion gives an overview of the structure used for drivers. For a more detailed discussion, see ``DDI: 8 sample driver'', which provides a detailed commentary that can be viewed in parallel with a sample DDI 8 driver.

The source code for a device driver is structured as a series of entry point routines that are documented in the following manual page sections:

Other interfaces have their own D2* section that documents the entry point routines that are used with that interface.

Each interface-specific D2* manual page section includes a manual page for every entry point routine that can be used with that interface. This means, for example, that there are config(D2), config(D2mdi), and config(D2sdi) manual pages. The D2 and D2oddi pages provide the basic information that is relative to all drivers; the interface-specific pages add ``Usage'' information and other material that is relevant only to that interface.

Traditionally, entry point routines are given the name of the routine as documented on the manual pages, with the driver prefix(D1) prepended. For example, if the driver prefix is my, the driver has entry point routines named myopen( ), myclose( ), and so forth. Beginning with DDI 8, SVR5 drivers declare these entry point routines in the drvops(D4) structure rather than being accessed through switch tables that require strict adherence to this naming scheme, but driver code is easier to maintain if the traditional naming scheme is used. All SCO OpenServer 5 drivers use the named entry-point system and must be prefixed.

Each entry point routine runs in a specific context (see ``Context of a driver'') which is identified on the man page for that routine. The context determines which synchronization primitives can be used and whether the driver can call functions that access the user context such as copyout(D3).

This overview of driver code structure is divided into five parts:

This discussion is based on DDI 8. SCO OpenServer 5 and DDI versions prior to version 8 use a different set of entry point routines. See Intro(D2) for a table comparing DDI 8 and DDI 7 entry point routines. See Intro(D2oddi) for a table that lists all SCO OpenServer 5 entry point routines.

After reading this overview, look at the code samples that are provided in the HDK to get a better understanding of driver structure. We recommend that you use a copy of the code samples as a template for your own driver. ``Guidelines for all kernel drivers'' lists guidelines for making your driver robust and maintainable.

© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005