About This Manual

This book discusses topics related to writing kernel modules for computer systems running the Compaq Tru64TM UNIX® (formerly DIGITAL UNIX) operating system.

Audience

This book is intended for systems engineers who:

This book assumes that you have a strong background in operating systems based on the UNIX operating system. It also assumes that you have a strong background in systems and C programming. In addition, the book assumes that you have no source code licenses.

New and Changed Features

Writing Kernel Modules is a new book. However, it contains information incorporated from the last released version of Writing Device Drivers: Advanced Topics. The following list summarize changes and additions made since the last release of Writing Device Drivers: Advanced Topics:

Scope of the Book

This book is for users of the Tru64 UNIX operating system on computer systems developed by Compaq Computer Corporation. It describes how to develop a kernel module and presents examples where kernel modules can be used. The book also presents examples that show how to use routines associated with symmetric multiprocessing and kernel threads.

The book assumes that you are new to writing kernel modules but may have experience writing device drivers or programming in the UNIX kernel.

Organization

The book contains the following chapters:

Chapter 1

Introduction to Kernel Modules

Provides an overview of the chapters in this book. Defines kernel modules, presents a high-level model for using kernel modules, presents reasons for writing a kernel module, and describes general rules for writing a kernel module.

Chapter 2

Module Initialization

Describes how to initialize a kernel module using the configure routine.

Chapter 3

Module Attributes

Describes setting module attributes and the module attribute table.

Chapter 4

Dispatch Point Callbacks

Describes the boot timeline and how to implement callbacks in a kernel module.

Chapter 5

Kernel-Mode Capabilities

Describes programming capabilities available in kernel mode.

Chapter 6

Symmetric Multiprocessing and Locking Methods

Provides an overview of the SMP environment, including guidelines for selecting a locking method.

Chapter 7

Simple Lock Routines

Describes how to define and use simple locks in an SMP environment.

Chapter 8

Complex Lock Routines

Describes how to define and use complex locks in an SMP environment.

Chapter 9

Kernel Threads

Provides an introduction to multithreaded programming for kernel modules and discusses using kernel threads.

Chapter 10

Building and Testing a Kernel Module

Describes key steps for creating a single binary module (.mod file) and testing the module.

Related Documentation

Icons on Tru64 UNIX Printed Books

The printed version of the Tru64 UNIX documentation uses letter icons on the spines of the books to help specific audiences quickly find the books that meet their needs. (You can order the printed documentation from Compaq.) The following list describes this convention:

  G Books for general users
  S Books for system and network administrators
  P Books for programmers
  D Books for device driver writers
  R Books for reference page users

Some books in the documentation help meet the needs of several audiences. For example, the information in some system books is also used by programmers. Keep this in mind when searching for information on specific topics.

The Documentation Overview provides information on all of the books in the Tru64 UNIX documentation set.

Writing kernel modules is a complex task; writers require knowledge in a variety of areas. One way to acquire this knowledge is to have at least the following categories of documentation available:

The following sections list the documentation associated with each of these categories.

Hardware Documentation

If your kernel module is a device driver, you should have available the hardware manual associated with the device for which you are writing the module. You should also have access to the manual that describes the architecture associated with the CPU on which the driver operates, for example, the Alpha Architecture Reference Manual.

Bus-Specific Device Driver Documentation

Writing Device Drivers is the core book for developing device driver kernel modules on the Tru64 UNIX Version 5.0A operating system. It contains information needed for developing modules on any bus that operates on Compaq platforms.

Reference Pages, Section 9r, Device Drivers (Volume 1) and Reference Pages, Section 9s, 9u, and 9v, Device Drivers (Volume 2) describe the routines, data structures, and global variables that device drivers use.

The following books provide information about writing device drivers for a specific bus:

Operating System Overview Documentation

Refer to the Technical Overview for a technical introduction to the Tru64 UNIX operating system.

This manual provides a technical overview of the Tru64 UNIX system, focusing on the networking subsystem, the file system, virtual memory, and the development environment. This manual does not supersede the Software Product Description (SPD), which is the definitive description of the Tru64 UNIX system.

Programming Tools Documentation

To create your kernel modules, you use a number of programming development tools and should have on hand the manuals that describe how to use these tools. The following manuals provide information related to programming tools used in the Tru64 UNIX operating system environment:

System Management Documentation

Refer to the System Administration manual for information about building a kernel and for general information on system administration.

This manual describes how to configure, use, and maintain the Tru64 UNIX operating system. It includes information on general day-to-day activities and tasks, changing your system configuration, and locating and eliminating sources of trouble. This manual is for the system administrators responsible for managing the operating system. It assumes a knowledge of operating system concepts, commands, and configurations.

Reader's Comments

Compaq welcomes any comments and suggestions you have on this and other Tru64 UNIX manuals.

You can send your comments in the following ways:

Please include the following information along with your comments:

The Tru64 UNIX Publications group cannot respond to system problems or technical support inquiries. Please address technical questions to your local system vendor or to the appropriate Compaq technical support office. Information provided with the software media explains how to send problem reports to Compaq.

Conventions

This book uses the following conventions:


.
.
.

A vertical ellipsis indicates that a portion of an example that would normally be present is not shown.

. . .

In syntax definitions, a horizontal ellipsis indicates that the preceding item can be repeated one or more times.

file

Italic type indicates variable values, placeholders, and function argument names.

buf

In function definitions and syntax definitions used in module configuration, this typeface is used to indicate names that you must type exactly as shown.

[ ]

In formal parameter declarations in function definitions and in structure declarations, brackets indicate arrays. Brackets are also used to specify ranges for device minor numbers and device special files in file fragments. However, for syntax definitions, these brackets indicate items that are optional.

|

Vertical bars separating items that appear in syntax definitions indicate that you choose one item from among those listed.