1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
5 <book id="LinuxKernelAPI">
7 <title>The Linux Kernel API</title>
11 This documentation is free software; you can redistribute
12 it and/or modify it under the terms of the GNU General Public
13 License as published by the Free Software Foundation; either
14 version 2 of the License, or (at your option) any later
19 This program is distributed in the hope that it will be
20 useful, but WITHOUT ANY WARRANTY; without even the implied
21 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 See the GNU General Public License for more details.
26 You should have received a copy of the GNU General Public
27 License along with this program; if not, write to the Free
28 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
33 For more details see the file COPYING in the source
34 distribution of Linux.
42 <title>Driver Basics</title>
43 <sect1><title>Driver Entry and Exit points</title>
44 !Iinclude/linux/init.h
47 <sect1><title>Atomic and pointer manipulation</title>
48 !Iinclude/asm-i386/atomic.h
49 !Iinclude/asm-i386/unaligned.h
52 <sect1><title>Delaying, scheduling, and timer routines</title>
53 !Iinclude/linux/sched.h
57 <sect1><title>High-resolution timers</title>
58 !Iinclude/linux/ktime.h
59 !Iinclude/linux/hrtimer.h
62 <sect1><title>Workqueues and Kevents</title>
65 <sect1><title>Internal Functions</title>
68 !Iinclude/linux/kthread.h
72 <sect1><title>Kernel objects manipulation</title>
74 X!Iinclude/linux/kobject.h
79 <sect1><title>Kernel utility functions</title>
80 !Iinclude/linux/kernel.h
87 <sect1><title>Device Resource Management</title>
88 !Edrivers/base/devres.c
94 <title>Data Types</title>
95 <sect1><title>Doubly Linked Lists</title>
96 !Iinclude/linux/list.h
101 <title>Basic C Library Functions</title>
104 When writing drivers, you cannot in general use routines which are
105 from the C Library. Some of the functions have been found generally
106 useful and they are listed below. The behaviour of these functions
107 may vary slightly from those defined by ANSI, and these deviations
108 are noted in the text.
111 <sect1><title>String Conversions</title>
115 <sect1><title>String Manipulation</title>
116 <!-- All functions are exported at now
121 <sect1><title>Bit Operations</title>
122 !Iinclude/asm-i386/bitops.h
126 <chapter id="kernel-lib">
127 <title>Basic Kernel Library Functions</title>
130 The Linux kernel provides more basic utility functions.
133 <sect1><title>Bitmap Operations</title>
138 <sect1><title>Command-line Parsing</title>
142 <sect1><title>CRC Functions</title>
150 <title>Memory Management in Linux</title>
151 <sect1><title>The Slab Cache</title>
152 !Iinclude/linux/slab.h
155 <sect1><title>User Space Memory Access</title>
156 !Iinclude/asm-i386/uaccess.h
157 !Earch/i386/lib/usercopy.c
159 <sect1><title>More Memory Management Functions</title>
160 !Iinclude/linux/rmap.h
167 !Emm/page-writeback.c
174 <title>Kernel IPC facilities</title>
176 <sect1><title>IPC utilities</title>
182 <title>FIFO Buffer</title>
183 <sect1><title>kfifo interface</title>
184 !Iinclude/linux/kfifo.h
189 <chapter id="relayfs">
190 <title>relay interface support</title>
193 Relay interface support
194 is designed to provide an efficient mechanism for tools and
195 facilities to relay large amounts of data from kernel space to
199 <sect1><title>relay interface</title>
205 <chapter id="netcore">
206 <title>Linux Networking</title>
207 <sect1><title>Networking Base Types</title>
208 !Iinclude/linux/net.h
210 <sect1><title>Socket Buffer Functions</title>
211 !Iinclude/linux/skbuff.h
216 !Enet/core/datagram.c
219 <sect1><title>Socket Filter</title>
222 <sect1><title>Generic Network Statistics</title>
223 !Iinclude/linux/gen_stats.h
224 !Enet/core/gen_stats.c
225 !Enet/core/gen_estimator.c
227 <sect1><title>SUN RPC subsystem</title>
228 <!-- The !D functionality is not perfect, garbage has to be protected by comments
229 !Dnet/sunrpc/sunrpc_syms.c
232 !Enet/sunrpc/svcsock.c
237 <chapter id="netdev">
238 <title>Network device support</title>
239 <sect1><title>Driver Support</title>
242 !Iinclude/linux/etherdevice.h
243 !Edrivers/net/phy/phy.c
244 !Idrivers/net/phy/phy.c
245 !Edrivers/net/phy/phy_device.c
246 !Idrivers/net/phy/phy_device.c
247 !Edrivers/net/phy/mdio_bus.c
248 !Idrivers/net/phy/mdio_bus.c
249 <!-- FIXME: Removed for now since no structured comments in source
250 X!Enet/core/wireless.c
253 <sect1><title>Synchronous PPP</title>
254 !Edrivers/net/wan/syncppp.c
258 <chapter id="modload">
259 <title>Module Support</title>
260 <sect1><title>Module Loading</title>
263 <sect1><title>Inter Module support</title>
265 Refer to the file kernel/module.c for more information.
267 <!-- FIXME: Removed for now since no structured comments in source
273 <chapter id="hardware">
274 <title>Hardware Interfaces</title>
275 <sect1><title>Interrupt Handling</title>
276 !Ekernel/irq/manage.c
279 <sect1><title>DMA Channels</title>
283 <sect1><title>Resources Management</title>
288 <sect1><title>MTRR Handling</title>
289 !Earch/i386/kernel/cpu/mtrr/main.c
292 <sect1><title>PCI Support Library</title>
294 !Edrivers/pci/pci-driver.c
295 !Edrivers/pci/remove.c
296 !Edrivers/pci/pci-acpi.c
297 !Edrivers/pci/search.c
300 <!-- FIXME: Removed for now since no structured comments in source
301 X!Edrivers/pci/hotplug.c
303 !Edrivers/pci/probe.c
306 <sect1><title>PCI Hotplug Support Library</title>
307 !Edrivers/pci/hotplug/pci_hotplug_core.c
309 <sect1><title>MCA Architecture</title>
310 <sect2><title>MCA Device Functions</title>
312 Refer to the file arch/i386/kernel/mca.c for more information.
314 <!-- FIXME: Removed for now since no structured comments in source
315 X!Earch/i386/kernel/mca.c
318 <sect2><title>MCA Bus DMA</title>
319 !Iinclude/asm-i386/mca_dma.h
324 <chapter id="firmware">
325 <title>Firmware Interfaces</title>
326 <sect1><title>DMI Interfaces</title>
327 !Edrivers/firmware/dmi_scan.c
329 <sect1><title>EDD Interfaces</title>
330 !Idrivers/firmware/edd.c
334 <chapter id="security">
335 <title>Security Framework</title>
336 !Esecurity/security.c
340 <title>Audit Interfaces</title>
343 !Ikernel/auditfilter.c
346 <chapter id="accounting">
347 <title>Accounting Framework</title>
351 <chapter id="pmfuncs">
352 <title>Power Management</title>
356 <chapter id="devdrivers">
357 <title>Device drivers infrastructure</title>
358 <sect1><title>Device Drivers Base</title>
360 X!Iinclude/linux/device.h
362 !Edrivers/base/driver.c
363 !Edrivers/base/core.c
364 !Edrivers/base/class.c
365 !Edrivers/base/firmware_class.c
366 !Edrivers/base/transport_class.c
367 !Edrivers/base/dmapool.c
368 <!-- Cannot be included, because
369 attribute_container_add_class_device_adapter
370 and attribute_container_classdev_to_container
371 exceed allowed 44 characters maximum
372 X!Edrivers/base/attribute_container.c
376 X!Edrivers/base/interface.c
378 !Edrivers/base/platform.c
381 <sect1><title>Device Drivers Power Management</title>
382 !Edrivers/base/power/main.c
383 !Edrivers/base/power/resume.c
384 !Edrivers/base/power/suspend.c
386 <sect1><title>Device Drivers ACPI Support</title>
387 <!-- Internal functions only
388 X!Edrivers/acpi/sleep/main.c
389 X!Edrivers/acpi/sleep/wakeup.c
390 X!Edrivers/acpi/motherboard.c
391 X!Edrivers/acpi/bus.c
393 !Edrivers/acpi/scan.c
394 !Idrivers/acpi/scan.c
395 <!-- No correct structured comments
396 X!Edrivers/acpi/pci_bind.c
399 <sect1><title>Device drivers PnP support</title>
401 <!-- No correct structured comments
402 X!Edrivers/pnp/system.c
405 !Edrivers/pnp/driver.c
406 !Edrivers/pnp/manager.c
407 !Edrivers/pnp/support.c
411 <chapter id="blkdev">
412 <title>Block Devices</title>
416 <chapter id="chrdev">
417 <title>Char devices</title>
421 <chapter id="miscdev">
422 <title>Miscellaneous Devices</title>
423 !Edrivers/char/misc.c
426 <chapter id="parportdev">
427 <title>Parallel Port Devices</title>
428 !Iinclude/linux/parport.h
429 !Edrivers/parport/ieee1284.c
430 !Edrivers/parport/share.c
431 !Idrivers/parport/daisy.c
434 <chapter id="message_devices">
435 <title>Message-based devices</title>
436 <sect1><title>Fusion message devices</title>
437 !Edrivers/message/fusion/mptbase.c
438 !Idrivers/message/fusion/mptbase.c
439 !Edrivers/message/fusion/mptscsih.c
440 !Idrivers/message/fusion/mptscsih.c
441 !Idrivers/message/fusion/mptctl.c
442 !Idrivers/message/fusion/mptspi.c
443 !Idrivers/message/fusion/mptfc.c
444 !Idrivers/message/fusion/mptlan.c
446 <sect1><title>I2O message devices</title>
447 !Iinclude/linux/i2o.h
448 !Idrivers/message/i2o/core.h
449 !Edrivers/message/i2o/iop.c
450 !Idrivers/message/i2o/iop.c
451 !Idrivers/message/i2o/config-osm.c
452 !Edrivers/message/i2o/exec-osm.c
453 !Idrivers/message/i2o/exec-osm.c
454 !Idrivers/message/i2o/bus-osm.c
455 !Edrivers/message/i2o/device.c
456 !Idrivers/message/i2o/device.c
457 !Idrivers/message/i2o/driver.c
458 !Idrivers/message/i2o/pci.c
459 !Idrivers/message/i2o/i2o_block.c
460 !Idrivers/message/i2o/i2o_scsi.c
461 !Idrivers/message/i2o/i2o_proc.c
465 <chapter id="snddev">
466 <title>Sound Devices</title>
467 !Iinclude/sound/core.h
469 !Iinclude/sound/pcm.h
471 !Esound/core/device.c
473 !Esound/core/rawmidi.c
475 !Esound/core/memory.c
476 !Esound/core/pcm_memory.c
478 !Esound/core/isadma.c
479 !Esound/core/control.c
480 !Esound/core/pcm_lib.c
482 !Esound/core/pcm_native.c
483 !Esound/core/memalloc.c
484 <!-- FIXME: Removed for now since no structured comments in source
485 X!Isound/sound_firmware.c
489 <chapter id="uart16x50">
490 <title>16x50 UART Driver</title>
491 !Iinclude/linux/serial_core.h
492 !Edrivers/serial/serial_core.c
493 !Edrivers/serial/8250.c
496 <chapter id="z85230">
497 <title>Z85230 Support Library</title>
498 !Edrivers/net/wan/z85230.c
502 <title>Frame Buffer Library</title>
505 The frame buffer drivers depend heavily on four data structures.
506 These structures are declared in include/linux/fb.h. They are
507 fb_info, fb_var_screeninfo, fb_fix_screeninfo and fb_monospecs.
508 The last three can be made available to and from userland.
512 fb_info defines the current state of a particular video card.
513 Inside fb_info, there exists a fb_ops structure which is a
514 collection of needed functions to make fbdev and fbcon work.
515 fb_info is only visible to the kernel.
519 fb_var_screeninfo is used to describe the features of a video card
520 that are user defined. With fb_var_screeninfo, things such as
521 depth and the resolution may be defined.
525 The next structure is fb_fix_screeninfo. This defines the
526 properties of a card that are created when a mode is set and can't
527 be changed otherwise. A good example of this is the start of the
528 frame buffer memory. This "locks" the address of the frame buffer
529 memory, so that it cannot be changed or moved.
533 The last structure is fb_monospecs. In the old API, there was
534 little importance for fb_monospecs. This allowed for forbidden things
535 such as setting a mode of 800x600 on a fix frequency monitor. With
536 the new API, fb_monospecs prevents such things, and if used
537 correctly, can prevent a monitor from being cooked. fb_monospecs
538 will not be useful until kernels 2.5.x.
541 <sect1><title>Frame Buffer Memory</title>
542 !Edrivers/video/fbmem.c
545 <sect1><title>Frame Buffer Console</title>
546 X!Edrivers/video/console/fbcon.c
549 <sect1><title>Frame Buffer Colormap</title>
550 !Edrivers/video/fbcmap.c
553 drivers/video/fbgen.c has no docs, which stuffs up the sgml. Comment
554 out until somebody adds docs. KAO
555 <sect1><title>Frame Buffer Generic Functions</title>
556 X!Idrivers/video/fbgen.c
559 <sect1><title>Frame Buffer Video Mode Database</title>
560 !Idrivers/video/modedb.c
561 !Edrivers/video/modedb.c
563 <sect1><title>Frame Buffer Macintosh Video Mode Database</title>
564 !Edrivers/video/macmodes.c
566 <sect1><title>Frame Buffer Fonts</title>
568 Refer to the file drivers/video/console/fonts.c for more information.
570 <!-- FIXME: Removed for now since no structured comments in source
571 X!Idrivers/video/console/fonts.c
576 <chapter id="input_subsystem">
577 <title>Input Subsystem</title>
578 !Iinclude/linux/input.h
579 !Edrivers/input/input.c
580 !Edrivers/input/ff-core.c
581 !Edrivers/input/ff-memless.c
585 <title>Serial Peripheral Interface (SPI)</title>
587 SPI is the "Serial Peripheral Interface", widely used with
588 embedded systems because it is a simple and efficient
589 interface: basically a multiplexed shift register.
590 Its three signal wires hold a clock (SCK, often in the range
591 of 1-20 MHz), a "Master Out, Slave In" (MOSI) data line, and
592 a "Master In, Slave Out" (MISO) data line.
593 SPI is a full duplex protocol; for each bit shifted out the
594 MOSI line (one per clock) another is shifted in on the MISO line.
595 Those bits are assembled into words of various sizes on the
596 way to and from system memory.
597 An additional chipselect line is usually active-low (nCS);
598 four signals are normally used for each peripheral, plus
599 sometimes an interrupt.
602 The SPI bus facilities listed here provide a generalized
603 interface to declare SPI busses and devices, manage them
604 according to the standard Linux driver model, and perform
605 input/output operations.
606 At this time, only "master" side interfaces are supported,
607 where Linux talks to SPI peripherals and does not implement
608 such a peripheral itself.
609 (Interfaces to support implementing SPI slaves would
610 necessarily look different.)
613 The programming interface is structured around two kinds of driver,
614 and two kinds of device.
615 A "Controller Driver" abstracts the controller hardware, which may
616 be as simple as a set of GPIO pins or as complex as a pair of FIFOs
617 connected to dual DMA engines on the other side of the SPI shift
618 register (maximizing throughput). Such drivers bridge between
619 whatever bus they sit on (often the platform bus) and SPI, and
620 expose the SPI side of their device as a
621 <structname>struct spi_master</structname>.
622 SPI devices are children of that master, represented as a
623 <structname>struct spi_device</structname> and manufactured from
624 <structname>struct spi_board_info</structname> descriptors which
625 are usually provided by board-specific initialization code.
626 A <structname>struct spi_driver</structname> is called a
627 "Protocol Driver", and is bound to a spi_device using normal
631 The I/O model is a set of queued messages. Protocol drivers
632 submit one or more <structname>struct spi_message</structname>
633 objects, which are processed and completed asynchronously.
634 (There are synchronous wrappers, however.) Messages are
635 built from one or more <structname>struct spi_transfer</structname>
636 objects, each of which wraps a full duplex SPI transfer.
637 A variety of protocol tweaking options are needed, because
638 different chips adopt very different policies for how they
639 use the bits transferred with SPI.
641 !Iinclude/linux/spi/spi.h
642 !Fdrivers/spi/spi.c spi_register_board_info