# The Linux Kernel API

This documentation is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

For more details see the file COPYING in the source distribution of Linux.

## Driver Basics

### Driver Entry and Exit points

!Iinclude/linux/init.h

### Atomic and pointer manipulation

!Iinclude/asm-i386/atomic.h !Iinclude/asm-i386/unaligned.h

### Delaying, scheduling, and timer routines

!Iinclude/linux/sched.h !Ekernel/sched.c !Ekernel/timer.c

### High-resolution timers

!Iinclude/linux/ktime.h !Iinclude/linux/hrtimer.h !Ekernel/hrtimer.c

### Internal Functions

!Ikernel/exit.c !Ikernel/signal.c

### Kernel objects manipulation

!Elib/kobject.c

### Kernel utility functions

!Iinclude/linux/kernel.h !Ekernel/printk.c !Ekernel/panic.c !Ekernel/sys.c !Ekernel/rcupdate.c

## Data Types

### Doubly Linked Lists

!Iinclude/linux/list.h

## Basic C Library Functions

When writing drivers, you cannot in general use routines which are from the C Library. Some of the functions have been found generally useful and they are listed below. The behaviour of these functions may vary slightly from those defined by ANSI, and these deviations are noted in the text.

### String Conversions

!Ilib/vsprintf.c !Elib/vsprintf.c

### String Manipulation

!Elib/string.c

### Bit Operations

!Iinclude/asm-i386/bitops.h

## Memory Management in Linux

### The Slab Cache

!Emm/slab.c

### User Space Memory Access

!Iinclude/asm-i386/uaccess.h !Earch/i386/lib/usercopy.c

### More Memory Management Functions

!Iinclude/linux/rmap.h !Emm/readahead.c !Emm/filemap.c !Emm/memory.c !Emm/vmalloc.c !Emm/mempool.c !Emm/page-writeback.c !Emm/truncate.c

## Kernel IPC facilities

### IPC utilities

!Iipc/util.c

## FIFO Buffer

### kfifo interface

!Iinclude/linux/kfifo.h !Ekernel/kfifo.c

## The proc filesystem

### sysctl interface

!Ekernel/sysctl.c

### proc filesystem interface

!Ifs/proc/base.c

## The debugfs filesystem

### debugfs interface

!Efs/debugfs/inode.c !Efs/debugfs/file.c

## The Linux VFS

### The Filesystem types

!Iinclude/linux/fs.h

### The Directory Cache

!Efs/dcache.c !Iinclude/linux/dcache.h

### Inode Handling

!Efs/inode.c !Efs/bad_inode.c

### Registration and Superblocks

!Efs/super.c

### File Locks

!Efs/locks.c !Ifs/locks.c

### Other Functions

!Efs/mpage.c !Efs/namei.c !Efs/buffer.c !Efs/bio.c !Efs/seq_file.c !Efs/filesystems.c !Efs/fs-writeback.c !Efs/block_dev.c

## Linux Networking

### Networking Base Types

!Iinclude/linux/net.h

### Socket Buffer Functions

!Iinclude/linux/skbuff.h !Iinclude/net/sock.h !Enet/socket.c !Enet/core/skbuff.c !Enet/core/sock.c !Enet/core/datagram.c !Enet/core/stream.c

### Socket Filter

!Enet/core/filter.c

### Generic Network Statistics

!Iinclude/linux/gen_stats.h !Enet/core/gen_stats.c !Enet/core/gen_estimator.c

### SUN RPC subsystem

!Enet/sunrpc/xdr.c !Enet/sunrpc/svcsock.c !Enet/sunrpc/sched.c

## Network device support

### Driver Support

!Enet/core/dev.c !Enet/ethernet/eth.c !Iinclude/linux/etherdevice.h

### Synchronous PPP

!Edrivers/net/wan/syncppp.c

## Module Support

### Module Loading

!Ekernel/kmod.c

### Inter Module support

Refer to the file kernel/module.c for more information.

## Hardware Interfaces

### Interrupt Handling

!Ekernel/irq/manage.c

### Resources Management

!Ekernel/resource.c

### MTRR Handling

!Earch/i386/kernel/cpu/mtrr/main.c

### PCI Support Library

!Edrivers/pci/pci.c !Edrivers/pci/pci-driver.c !Edrivers/pci/remove.c !Edrivers/pci/pci-acpi.c !Edrivers/pci/msi.c !Edrivers/pci/bus.c !Edrivers/pci/probe.c !Edrivers/pci/rom.c

### PCI Hotplug Support Library

!Edrivers/pci/hotplug/pci_hotplug_core.c

### MCA Architecture

#### MCA Device Functions

Refer to the file arch/i386/kernel/mca.c for more information.

#### MCA Bus DMA

!Iinclude/asm-i386/mca_dma.h

## The Device File System

!Efs/devfs/base.c

## The Filesystem for Exporting Kernel Objects

!Efs/sysfs/file.c !Efs/sysfs/dir.c !Efs/sysfs/symlink.c !Efs/sysfs/bin.c

## Security Framework

!Esecurity/security.c

## Power Management

!Ekernel/power/pm.c

## Device drivers infrastructure

### Device Drivers Base

!Edrivers/base/driver.c !Edrivers/base/core.c !Edrivers/base/firmware_class.c !Edrivers/base/transport_class.c !Edrivers/base/dmapool.c !Edrivers/base/sys.c !Edrivers/base/platform.c !Edrivers/base/bus.c

### Device Drivers Power Management

!Edrivers/base/power/main.c !Edrivers/base/power/resume.c !Edrivers/base/power/suspend.c

### Device Drivers ACPI Support

!Edrivers/acpi/scan.c !Idrivers/acpi/scan.c

### Device drivers PnP support

!Edrivers/pnp/core.c !Edrivers/pnp/card.c !Edrivers/pnp/driver.c !Edrivers/pnp/manager.c !Edrivers/pnp/support.c

## Block Devices

!Eblock/ll_rw_blk.c

## Miscellaneous Devices

!Edrivers/char/misc.c

## Video4Linux

!Edrivers/media/video/videodev.c

## Sound Devices

!Iinclude/sound/core.h !Esound/sound_core.c !Iinclude/sound/pcm.h !Esound/core/pcm.c !Esound/core/device.c !Esound/core/info.c !Esound/core/rawmidi.c !Esound/core/sound.c !Esound/core/memory.c !Esound/core/pcm_memory.c !Esound/core/init.c !Esound/core/isadma.c !Esound/core/control.c !Esound/core/pcm_lib.c !Esound/core/hwdep.c !Esound/core/pcm_native.c !Esound/core/memalloc.c

## 16x50 UART Driver

!Iinclude/linux/serial_core.h !Edrivers/serial/serial_core.c !Edrivers/serial/8250.c

## Z85230 Support Library

!Edrivers/net/wan/z85230.c

## Frame Buffer Library

The frame buffer drivers depend heavily on four data structures. These structures are declared in include/linux/fb.h. They are fb_info, fb_var_screeninfo, fb_fix_screeninfo and fb_monospecs. The last three can be made available to and from userland.

fb_info defines the current state of a particular video card. Inside fb_info, there exists a fb_ops structure which is a collection of needed functions to make fbdev and fbcon work. fb_info is only visible to the kernel.

fb_var_screeninfo is used to describe the features of a video card that are user defined. With fb_var_screeninfo, things such as depth and the resolution may be defined.

The next structure is fb_fix_screeninfo. This defines the properties of a card that are created when a mode is set and can't be changed otherwise. A good example of this is the start of the frame buffer memory. This "locks" the address of the frame buffer memory, so that it cannot be changed or moved.

The last structure is fb_monospecs. In the old API, there was little importance for fb_monospecs. This allowed for forbidden things such as setting a mode of 800x600 on a fix frequency monitor. With the new API, fb_monospecs prevents such things, and if used correctly, can prevent a monitor from being cooked. fb_monospecs will not be useful until kernels 2.5.x.

### Frame Buffer Memory

!Edrivers/video/fbmem.c

### Frame Buffer Colormap

!Edrivers/video/fbcmap.c

### Frame Buffer Video Mode Database

!Idrivers/video/modedb.c !Edrivers/video/modedb.c

### Frame Buffer Macintosh Video Mode Database

!Edrivers/video/macmodes.c

### Frame Buffer Fonts

Refer to the file drivers/video/console/fonts.c for more information.