This chapter describes:
The descriptions of the header files associated with device drivers are presented in alphabetical order and in reference (man) page style. The descriptions can include the following sections.
This section lists the name of the header file along with a summary description of its contents.
This section presents the pathname for the header file. The pathname makes it easier for you to locate specific header files.
This section briefly describes the contents of the header file.
This section explains when to include a header file for block and character drivers.
This section lists specific structures, macros, constant values, and so forth that are of interest to device driver writers.
This section lists related kernel interfaces, structures, system calls, and so forth.
Table 1-1 lists the header files related to device drivers, along with short descriptions of their contents. For convenience, the header files are listed in alphabetical order. Note that device drivers should include header files that use the relative pathname instead of the explicit pathname. For example, although buf.h resides in /usr/sys/include/sys/buf.h, device drivers should include it as:
<sys/buf.h>
Not all of the header files reside in <sys>. The following include files reside in other directories:
<kern/lock.h> <machine/cpu.h> <io/common/devdriver.h>
Header File | Contents |
<sys/buf.h> | Defines the buf structure. |
<sys/conf.h> | Defines the dsent structure. |
<machine/cpu.h> | Defines structures and constants related to the CPU. |
<io/common/devdriver.h> | Defines the structures, constants, and external interfaces that device drivers and the autoconfiguration software use. |
<io/common/devdriver_loadable.h> | Defines constants and declares external functions associated with dynamically configured drivers. |
<io/common/devgetinfo.h> | Defines various data structures used by the DEVGETINFO ioctl command. |
<io/common/devio.h> | Defines common structures and definitions for device drivers and ioctl commands. |
<sys/disklabel.h> | Defines structures and macros that operate on Digital UNIX disk labels. |
<sys/errno.h> | Defines the error codes that a device driver returns to a user process. |
<sys/fcntl.h> | Defines I/O mode flags that user programs supply to open and fcntl system calls. |
<sys/ioctl.h> | Defines commands for ioctl interfaces in different device drivers. |
<io/common/iotypes.h> | Defines constants that 64-bit conversions use. |
<sys/kernel.h> | Defines global variables that the kernel uses. |
<kern/lock.h> | Defines simple and complex lock structures. |
<sys/malloc.h> | Defines kernel memory allocator-related information. |
<sys/map.h> | Defines structures associated with resource allocation maps. |
<sys/mman.h> | Defines constants associated with the mmap kernel interface. |
<sys/mode.h> | Defines constants that driver interfaces use. |
<sys/mtio.h> | Defines commands and structures for magnetic tape operations. |
<sys/param.h> | Defines constants and interfaces that the kernel uses. |
<sys/poll.h> | Defines polling bit masks. |
<sys/proc.h> | Defines the proc structure, which defines a user process. |
<kern/sched_prim.h> | Defines scheduling interfaces. |
<sys/security.h> | Defines structures, constants, and data types that UNIX security software uses. |
<sys/select.h> | Defines select-related data structures and interfaces. |
<sys/sysconfig.h> | Defines cfgmgr framework operation codes and data structures used in the device driver's configure interface. |
<sys/systm.h> | Defines generic kernel global variables. |
<kern/task.h> | Defines structures that tasks use. |
<kern/thread.h> | Defines structures that kernel threads use. |
<sys/time.h> | Contains structures and symbolic names that time-related interfaces use. |
<sys/types.h> | Defines system data types and major and minor device interfaces. |
<sys/uio.h> | Contains the definition of the uio structure. |
<sys/user.h> | Defines the user structure. |
<sys/vm.h> | Contains a sequence of include statements that includes all of the virtual memory-related files. |
<sys/vmmac.h> | Contains definitions for byte conversions. |
Defines the buf structure
The buf.h file defines the buf structure used to pass I/O requests to the strategy interface of a block device driver. Character device drivers can also use the buf structure, typically in the xxstrategy interface.
You include the buf.h file in block device drivers because they use file system block-sized buffers from a buffer cache supplied by the kernel to perform I/O.
Items of interest to device driver writers are:
Defines the dsent structure
The conf.h file defines the dsent structure (for block and character device drivers).
You should include the conf.h file in block and character device drivers because these drivers declare an instance of and set the associated members of the dsent structure.
Items of interest to device driver writers are:
You use the defines to initialize the d_funnel member of the dsent structure.
Defines structures and constants related to the CPU
/usr/sys/include/machine/cpu.h
The cpu.h file defines a variety of structures and constants related to the CPU.
You include the cpu.h file in block and character device drivers when calling any of the spl interfaces. The reason for this is that the spl interfaces map to an assembler interface.
The items contained in cpu.h are opaque to device driver writers. In other words, device driver writers need not know the details of how the spl interfaces map to the assembler-specific interface.
Defines the structures, constants, and external interfaces that device drivers and the autoconfiguration software use
/usr/sys/include/io/common/devdriver.h
The devdriver.h file defines the structures, constants, and external interfaces that device drivers and the autoconfiguration software use.
You must include the devdriver.h file in block and character device drivers because you initialize the driver structure and reference the controller, device, and bus structures.
Items of interest to device driver writers are:
bus, controller, device, driver
Defines constants and declares external functions associated with dynamically configured drivers
/usr/sys/include/io/common/devdriver_loadable.h
The devdriver_loadable.h file defines constants and declares external functions associated with drivers that are dynamically configured into the kernel. The file also defines constants and declares external functions associated with bus support.
You do not need to include this file in your device driver.
Items of interest to systems engineers who implement a new bus or make changes to an existing bus are the external declarations for interfaces used in bus adapter driver development. Examples of these external declarations are ldbl_find_bus, ldbl_search_bus_local, and ldbl_find_ctlr.
Defines various data structures used by the DEVGETINFO ioctl command
/usr/sys/include/io/common/devgetinfo.h
The devgetinfo.h file defines various data structures that the DEVGETINFO ioctl command uses.
You include the devgetinfo.h file in disk device drivers.
Items of interest to device driver writers are the following data structures:
DEVGETINFO, v1_bustype_info_t, v1_device_info_t, v1_devtype_info_t, v1_disk_dev_info_t, v1_tape_dev_info_t
Defines common structures and definitions for device drivers and ioctl commands
/usr/sys/include/io/common/devio.h
The devio.h file defines common structures and definitions for device drivers and ioctl commands, such as DEVGETGEOM. This file also contains descriptions of device types, attributes, and names.
You include the devio.h file in your device driver if you plan to use any of the ioctl commands such as DEVGETGEOM.
Items of interest to device driver writers are:
Defines structures and macros that operate on Digital UNIX disk labels
/usr/sys/include/sys/disklabel.h
The disklabel.h file defines structures and macros that operate on Digital UNIX disk labels. Each disk has a label that includes information about the hardware disk geometry, file system partitions, and drive-specific information.
You include the disklabel.h file if your block device driver needs to operate on disk labels.
Items of interest to device driver writers are:
The values for this member can be set to describe the drive type. Some examples are DTYPE_MSCP (the drive type is an MSCP) and DTYPE_SCSI (the drive type is a SCSI).
Reference Pages Section 4: disktab
Defines the error codes that a device driver returns to a user process
The errno.h file defines the error codes returned to a user process by a device driver. Some of the error codes that a device driver can use are EIO, ENXIO, EACCES, EBUSY, ENODEV, and EINVAL.
You include the errno.h file in both block and character device drivers to use the systemwide error codes.
Defines I/O mode flags that user programs supply to open and fcntl system calls
The fcntl.h file defines I/O mode flags supplied by user programs to the open and fcntl system calls.
You include the fcntl.h file in both block and character device drivers because these I/O mode flags get passed to the driver's open, close, and ioctl interfaces.
Reference Pages Section 2: fcntl, open
Defines commands for ioctl interfaces in different device drivers
The ioctl.h file defines commands for ioctl interfaces in different device drivers. The ioctl commands are driver entry points that perform tasks other than the general I/O operations such as read and write. Thus, you can consider ioctl operations as a way to perform any task other than read and write tasks.
You include the ioctl.h file in both block and character device drivers only when there is an ioctl entry point; that is, the driver has an ioctl interface that uses I/O control commands.
Defines constants that 64-bit conversions use
/usr/sys/include/io/common/iotypes.h
The iotypes.h file defines constants that 64-bit conversions use.
You include the iotypes.h file if you use the constants defined for 64-bit conversions in your device driver.
The following table lists some of the 64-bit conversion constants:
Constant | Meaning |
I8 | char |
U8 | unsigned char |
I16 | short |
U16 | unsigned short |
I32 | int |
U32 | unsigned int |
I64 | long long |
U64 | unsigned long long |
I_WORD | long |
U_WORD | unsigned long |
Defines global variables that the kernel uses
The kernel.h file defines global variables that the kernel uses.
You include the kernel.h file in both block and character device drivers to make use of the kernel global variables.
The kernel global variables that are of particular interest to device driver writers are:
This structure is defined as an external structure. This structure is defined in the file time.h.
Defines simple and complex lock structures
The lock.h file defines the simple spin lock and complex lock structures that device drivers use for synchronization on single processor and multiprocessor systems.
You include the lock.h file in device drivers if you use simple or complex locks to synchronize access to device driver structures and device registers.
Items of interest to the device driver writer are:
This is the simple spin lock structure.
The simple_lock_data_t typedef is an alternate name for the slock structure and the simple_lock_t typedef is an alternate name for a pointer to the slock structure.
This is the complex lock structure.
The lock_data_t typedef is an alternate name for the lock structure and the lock_t typedef is an alternate name for a pointer to the lock structure.
Defines kernel memory allocator-related information
The malloc.h file defines the constants, data structures, and interfaces associated with the kernel memory allocator interfaces MALLOC and FREE.
You include the malloc.h file in block and character device drivers when calling the interfaces associated with the kernel memory allocator.
Items of interest to device driver writers are the defines for the different memory types that device drivers can pass to the type argument of the MALLOC interface. For example, you can pass the M_DEVBUF constant to indicate that device driver memory is being allocated (or freed).
Defines structures associated with resource allocation maps
The map.h file defines structures associated with resource allocation maps.
You include the map.h file in both block and character device drivers when you need to make reference to the members of the map and mapent structures.
Defines constants associated with the mmap kernel interface
The mman.h file defines constants associated with the mmap kernel interface. It also defines protection bits that the mmap system call uses.
You include the mman.h file in any character device driver that needs to call the mmap kernel interface.
Items of interest to device driver writers are the following protection bits:
Reference Pages Section 2: mmap, munmap
Defines constants that driver interfaces use
The mode.h file defines constants that driver interfaces use.
You include the mode.h file when you use any of the constants defined in this file in your device driver.
Items of interest to device driver writers are:
Driver writers can use these constants to check the format argument for the xxclose and xxopen interfaces to determine whether the request is for a block or character device special file.
Defines commands and structures for magnetic tape operations
The mtio.h file defines commands and structures for magnetic tape operations.
You include the mtio.h file in tape device drivers. Commands defined in this file are used to communicate with the device driver's ioctl interface.
Items of interest to device driver writers are:
Reference Pages Section 4: mtio
Defines constants and interfaces that the kernel uses
The param.h file defines constants and interfaces that the kernel uses.
You include the param.h file in block and character device drivers when calling the sleep interface. The reason for this is that the sleep interface maps to another kernel interface.
One item of interest to device driver writers is the PCATCH constant.
Defines polling bit masks
The poll.h file defines bit polling bit masks that a device driver's xxselect interface uses.
You include the poll.h file in character device drivers if you want to use the polling bit masks to determine the state of the specified device.
Items of interest to device driver writers are the following polling bit masks:
select_dequeue, select_dequeue_all, select_enqueue, select_wakeup, xxselect
Reference Pages Section 2: select
Defines the proc structure, which defines a user process
The proc.h file defines the proc structure, which defines a user process.
You include the proc.h file in block and character device drivers if you want to access different members of the user's process structure.
Defines scheduling interfaces
/usr/sys/include/kern/sched_prim.h
The sched_prim.h file defines scheduling interfaces (macros) and kernel threads-related constants.
You include the sched_prim.h file when your driver references any kernel threads-related constants or scheduling interfaces.
Items of interest to driver writers are the following interfaces:
assert_wait_mesg, thread_block, thread_wakeup, thread_wakeup_one
Defines structures, constants, and data types that UNIX security software uses
/usr/sys/include/sys/security.h
The security.h file defines structures, constants, and data types that UNIX security software uses.
You include the security.h file in block and character device drivers if you call the privileged kernel interface.
Items of interest to device driver writers are the privilege constants. Examples of these constants include:
Defines select-related data structures and interfaces
The select.h file defines the data structure and interfaces that device drivers use with the select_enqueue and select_dequeue interfaces.
You include the select.h file when your device driver uses the sel_queue data structure and calls the select_enqueue and select_dequeue interfaces.
Items of interest to device driver writers are:
select_dequeue, select_enqueue, sel_queue
Defines cfgmgr framework operation codes and data structures used in the device driver's configure interface
/usr/sys/include/sys/sysconfig.h
The sysconfig.h file defines operation codes and data structures used in the device driver's configure interface. The operation codes define the action to be performed by the configure interface. Examples of the operation types include configure, unconfigure, and query. This file also defines many of the constants that are shared between the cfgmgr framework and device drivers. The definition of the cfg_attr_t data structure that the device driver method of cfgmgr passes to the driver's configure interface appears in this file. The definition of the cfg_subsys_attr_t data structure that a driver's configure interface initializes also appears in this file.
You include the sysconfig.h file in block and character device drivers.
Items of interest to device driver writers are the following constants:
You use these constants as follows:
The following constants are used with the point argument of the register_callback interface:
The following constants are used with the order argument of the register_callback interface:
You may also find the following interfaces (macros) useful for setting and checking dispatch points (through the register_callback interface): SET_CFGPOINT, BEFORE_CFGPOINT, and PAST_CFGPOINT.
cfg_attr_t, cfg_subsys_attr_t, register_callback, unregister_callback, xxcallback, xxconfigure
Defines generic kernel global variables
The systm.h file defines generic kernel global variables that some kernel interfaces use.
You include the systm.h file in character and block device drivers only if you need to reference one of the generic kernel global variables. Most device drivers will not need this file.
Items of interest to device driver writers are:
This global variable specifies the physical memory on this CPU.
This global variable is a character array that specifies the system version.
These casts are made to satisfy the lint program.
Defines structures that tasks use
The task.h file defines structures that tasks use.
You include the task.h file when your driver references any of the data structures related to tasks.
One item of interest to the device driver writer is the typedef task_t, which is an alternate name for struct task *.
Defines structures that kernel threads use
/usr/sys/include/kern/thread.h
The thread.h file defines structures that kernel threads use.
You include the thread.h file when your driver references any of the data structures related to kernel threads.
One item of interest to the device driver writer is the typedef thread_t, which is an alternate name for struct thread *.
Contains structures and symbolic names that time-related interfaces use
The time.h file contains structures and symbolic names that time-related interfaces use.
You include the time.h file in block and character device drivers if the driver needs to look at:
Items of interest to device driver writers are:
Defines system data types and major and minor device interfaces
The types.h file defines system data types and major and minor device interfaces.
You include the types.h file in most block and character device drivers in order to use the defined data types.
Contains the definition of the uio structure
The uio.h file contains the definition of the uio structure.
You include the uio.h file in character device drivers that access the uio structure.
Items of interest to device driver writers are:
This member is an enumerated data type that can be set to the flag UIO_READ or UIO_WRITE.
This member is an enumerated data type that can be set to the flag UIO_USERSPACE, UIO_SYSSPACE, or UIO_USERISPACE.
Defines the user structure
The user.h file defines the user structure.
You include the user.h file in block and character device drivers only if the driver needs to access different members of the user's user context structure.
Items of interest to device driver writers are:
Contains a sequence of include statements that includes all of the virtual memory-related files
The vm.h file contains a sequence of include statements that includes all of the virtual memory-related files.
Including the vm.h file is a quick way of including all of the virtual memory-related files.
Contains definitions for byte conversions
The vmmac.h file contains definitions for converting from bytes to pages and from pages to bytes.
You include the vmmac.h file in device drivers if the driver needs to perform virtual memory calculations directly.