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 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 !Ilib/string.c !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 !Iarch/i386/lib/usercopy.c FIFO Buffer kfifo interface !Iinclude/linux/kfifo.h !Ekernel/kfifo.c The proc filesystem sysctl interface !Ekernel/sysctl.c The debugfs filesystem debugfs interface !Efs/debugfs/inode.c !Efs/debugfs/file.c The Linux VFS 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 Linux Networking Socket Buffer Functions !Iinclude/linux/skbuff.h !Enet/core/skbuff.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 Network device support Driver Support !Enet/core/dev.c 8390 Based Network Cards !Edrivers/net/8390.c 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 !Iarch/i386/kernel/irq.c MTRR Handling !Earch/i386/kernel/cpu/mtrr/main.c PCI Support Library !Edrivers/pci/pci.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 Security Framework !Esecurity/security.c Power Management !Ekernel/power/pm.c Block Devices !Edrivers/block/ll_rw_blk.c Miscellaneous Devices !Edrivers/char/misc.c Video4Linux !Edrivers/media/video/videodev.c Sound Devices !Esound/sound_core.c 16x50 UART Driver !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 Console !Edrivers/video/console/fbcon.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 !Idrivers/video/macmodes.c Frame Buffer Fonts Refer to the file drivers/video/console/fonts.c for more information.