Linux Kernel Documentation — The Linux Kernel documentation (2024)

  • Docs »
  • Linux Kernel Documentation
  • View page source

Introduction

The Linux kernel uses Sphinx to generate pretty documentation fromreStructuredText files under Documentation. To build the documentation inHTML or PDF formats, use make htmldocs or make pdfdocs. The generateddocumentation is placed in Documentation/output.

The reStructuredText files may contain directives to include structureddocumentation comments, or kernel-doc comments, from source files. Usually theseare used to describe the functions and types and design of the code. Thekernel-doc comments have some special structure and formatting, but beyond thatthey are also treated as reStructuredText.

There is also the deprecated DocBook toolchain to generate documentation fromDocBook XML template files under Documentation/DocBook. The DocBook filesare to be converted to reStructuredText, and the toolchain is slated to beremoved.

Finally, there are thousands of plain text documentation files scattered aroundDocumentation. Some of these will likely be converted to reStructuredTextover time, but the bulk of them will remain in plain text.

Sphinx Build

The usual way to generate the documentation is to run make htmldocs ormake pdfdocs. There are also other formats available, see the documentationsection of make help. The generated documentation is placed informat-specific subdirectories under Documentation/output.

To generate documentation, Sphinx (sphinx-build) must obviously beinstalled. For prettier HTML output, the Read the Docs Sphinx theme(sphinx_rtd_theme) is used if available. For PDF output, rst2pdf is alsoneeded. All of these are widely available and packaged in distributions.

To pass extra options to Sphinx, you can use the SPHINXOPTS makevariable. For example, use make SPHINXOPTS=-v htmldocs to get more verboseoutput.

To remove the generated documentation, run make cleandocs.

Writing Documentation

Adding new documentation can be as simple as:

  1. Add a new .rst file somewhere under Documentation.
  2. Refer to it from the Sphinx main TOC tree in Documentation/index.rst.

This is usually good enough for simple documentation (like the one you’rereading right now), but for larger documents it may be advisable to create asubdirectory (or use an existing one). For example, the graphics subsystemdocumentation is under Documentation/gpu, split to several .rst files,and has a separate index.rst (with a toctree of its own) referenced fromthe main index.

See the documentation for Sphinx and reStructuredText on what you can dowith them. In particular, the Sphinx reStructuredText Primer is a good placeto get started with reStructuredText. There are also some Sphinx specificmarkup constructs.

Specific guidelines for the kernel documentation

Here are some specific guidelines for the kernel documentation:

  • Please don’t go overboard with reStructuredText markup. Keep it simple.

  • Please stick to this order of heading adornments:

    1. = with overline for document title:

      ==============Document title==============
    2. = for chapters:

      Chapters========
    3. - for sections:

      Section-------
    4. ~ for subsections:

      Subsection~~~~~~~~~~

    Although RST doesn’t mandate a specific order (“Rather than imposing a fixednumber and order of section title adornment styles, the order enforced will bethe order as encountered.”), having the higher levels the same overall makesit easier to follow the documents.

the C domain

The Sphinx C Domain (name c) is suited for documentation of C API. E.g. afunction prototype:

The C domain of the kernel-doc has some additional features. E.g. you canrename the reference name of a function with a common name like open orioctl:

.. c:function:: int ioctl( int fd, int request ) :name: VIDIOC_LOG_STATUS

The func-name (e.g. ioctl) remains in the output but the ref-name changed fromioctl to VIDIOC_LOG_STATUS. The index entry for this function is alsochanged to VIDIOC_LOG_STATUS and the function can now referenced by:

:c:func:`VIDIOC_LOG_STATUS`

list tables

We recommend the use of list table formats. The list table formats aredouble-stage lists. Compared to the ASCII-art they might not be ascomfortable forreaders of the text files. Their advantage is that they are easy tocreate or modify and that the diff of a modification is much more meaningful,because it is limited to the modified content.

The flat-table is a double-stage list similar to the list-table withsome additional features:

  • column-span: with the role cspan a cell can be extended throughadditional columns
  • row-span: with the role rspan a cell can be extended throughadditional rows
  • auto span rightmost cell of a table row over the missing cells on the rightside of that table-row. With Option :fill-cells: this behavior canchanged from auto span to auto fill, which automatically inserts (empty)cells instead of spanning the last cell.

options:

  • :header-rows: [int] count of header rows
  • :stub-columns: [int] count of stub columns
  • :widths: [[int] [int] ... ] widths of columns
  • :fill-cells: instead of auto-spanning missing cells, insert missing cells

roles:

  • :cspan: [int] additional columns (morecols)
  • :rspan: [int] additional rows (morerows)

The example below shows how to use this markup. The first level of the stagedlist is the table-row. In the table-row there is only one markup allowed,the list of the cells in this table-row. Exceptions are comments ( .. )and targets (e.g. a ref to :ref:`last row <last row>` / last row).

.. flat-table:: table title :widths: 2 1 1 3 * - head col 1 - head col 2 - head col 3 - head col 4 * - column 1 - field 1.1 - field 1.2 with autospan * - column 2 - field 2.1 - :rspan:`1` :cspan:`1` field 2.2 - 3.3 * .. _`last row`: - column 3

Rendered as:

table title
head col 1head col 2head col 3head col 4
column 1field 1.1field 1.2 with autospan
column 2field 2.1 field 2.2 - 3.3

column 3

Including kernel-doc comments

The Linux kernel source files may contain structured documentation comments, orkernel-doc comments to describe the functions and types and design of thecode. The documentation comments may be included to any of the reStructuredTextdocuments using a dedicated kernel-doc Sphinx directive extension.

The kernel-doc directive is of the format:

.. kernel-doc:: source :option:

The source is the path to a source file, relative to the kernel sourcetree. The following directive options are supported:

export: [source-pattern ...]

Include documentation for all functions in source that have been exportedusing EXPORT_SYMBOL or EXPORT_SYMBOL_GPL either in source or in anyof the files specified by source-pattern.

The source-pattern is useful when the kernel-doc comments have been placedin header files, while EXPORT_SYMBOL and EXPORT_SYMBOL_GPL are next tothe function definitions.

Examples:

.. kernel-doc:: lib/bitmap.c :export:.. kernel-doc:: include/net/mac80211.h :export: net/mac80211/*.c
internal: [source-pattern ...]

Include documentation for all functions and types in source that havenot been exported using EXPORT_SYMBOL or EXPORT_SYMBOL_GPL eitherin source or in any of the files specified by source-pattern.

Example:

.. kernel-doc:: drivers/gpu/drm/i915/intel_audio.c :internal:
doc: title

Include documentation for the DOC: paragraph identified by title insource. Spaces are allowed in title; do not quote the title. The titleis only used as an identifier for the paragraph, and is not included in theoutput. Please make sure to have an appropriate heading in the enclosingreStructuredText document.

Example:

.. kernel-doc:: drivers/gpu/drm/i915/intel_audio.c :doc: High Definition Audio over HDMI and Display Port
functions: function [...]

Include documentation for each function in source.

Example:

.. kernel-doc:: lib/bitmap.c :functions: bitmap_parselist bitmap_parselist_user

Without options, the kernel-doc directive includes all documentation commentsfrom the source file.

The kernel-doc extension is included in the kernel source tree, atDocumentation/sphinx/kernel-doc.py. Internally, it uses thescripts/kernel-doc script to extract the documentation comments from thesource.

Writing kernel-doc comments

In order to provide embedded, “C” friendly, easy to maintain, but consistent andextractable overview, function and type documentation, the Linux kernel hasadopted a consistent style for documentation comments. The format for thisdocumentation is called the kernel-doc format, described below. This styleembeds the documentation within the source files, using a few simple conventionsfor adding documentation paragraphs and documenting functions and theirparameters, structures and unions and their members, enumerations, and typedefs.

Note

The kernel-doc format is deceptively similar to gtk-doc or Doxygen,yet distinctively different, for historical reasons. The kernel sourcecontains tens of thousands of kernel-doc comments. Please stick to the styledescribed here.

The scripts/kernel-doc script is used by the Sphinx kernel-doc extension inthe documentation build to extract this embedded documentation into the variousHTML, PDF, and other format documents.

In order to provide good documentation of kernel functions and data structures,please use the following conventions to format your kernel-doc comments in theLinux kernel source.

How to format kernel-doc comments

The opening comment mark /** is reserved for kernel-doc comments. Onlycomments so marked will be considered by the kernel-doc tool. Use it onlyfor comment blocks that contain kernel-doc formatted comments. The usual */should be used as the closing comment marker. The lines in between should beprefixed by * (space star space).

The function and type kernel-doc comments should be placed just before thefunction or type being described. The overview kernel-doc comments may be freelyplaced at the top indentation level.

Example kernel-doc function comment:

/** * foobar() - Brief description of foobar. * @arg: Description of argument of foobar. * * Longer description of foobar. * * Return: Description of return value of foobar. */int foobar(int arg)

The format is similar for documentation for structures, enums, paragraphs,etc. See the sections below for details.

The kernel-doc structure is extracted from the comments, and proper Sphinx CDomain function and type descriptions with anchors are generated for them. Thedescriptions are filtered for special kernel-doc highlights andcross-references. See below for details.

Highlights and cross-references

The following special patterns are recognized in the kernel-doc commentdescriptive text and converted to proper reStructuredText markup and Sphinx CDomain references.

Attention

The below are only recognized within kernel-doc comments,not within normal reStructuredText documents.

funcname()
Function reference.
@parameter
Name of a function parameter. (No cross-referencing, just formatting.)
%CONST
Name of a constant. (No cross-referencing, just formatting.)
$ENVVAR
Name of an environment variable. (No cross-referencing, just formatting.)
&struct name
Structure reference.
&enum name
Enum reference.
&typedef name
Typedef reference.
&struct_name->member or &struct_name.member
Structure or union member reference. The cross-reference will be to the structor union definition, not the member directly.
&name
A generic type reference. Prefer using the full reference described aboveinstead. This is mostly for legacy comments.

Cross-referencing from reStructuredText

To cross-reference the functions and types defined in the kernel-doc commentsfrom reStructuredText documents, please use the Sphinx C Domainreferences. For example:

See function :c:func:`foo` and struct/union/enum/typedef :c:type:`bar`.

While the type reference works with just the type name, without thestruct/union/enum/typedef part in front, you may want to use:

See :c:type:`struct foo <foo>`.See :c:type:`union bar <bar>`.See :c:type:`enum baz <baz>`.See :c:type:`typedef meh <meh>`.

This will produce prettier links, and is in line with how kernel-doc does thecross-references.

For further details, please refer to the Sphinx C Domain documentation.

Function documentation

The general format of a function and function-like macro kernel-doc comment is:

/** * function_name() - Brief description of function. * @arg1: Describe the first argument. * @arg2: Describe the second argument. * One can provide multiple line descriptions * for arguments. * * A longer description, with more discussion of the function function_name() * that might be useful to those using or modifying it. Begins with an * empty comment line, and may include additional embedded empty * comment lines. * * The longer description may have multiple paragraphs. * * Return: Describe the return value of foobar. * * The return value description can also have multiple paragraphs, and should * be placed at the end of the comment block. */

The brief description following the function name may span multiple lines, andends with an @argument: description, a blank comment line, or the end of thecomment block.

The kernel-doc function comments describe each parameter to the function, inorder, with the @argument: descriptions. The @argument: descriptionsmust begin on the very next line following the opening brief functiondescription line, with no intervening blank comment lines. The @argument:descriptions may span multiple lines. The continuation lines may containindentation. If a function parameter is ... (varargs), it should be listedin kernel-doc notation as: @...:.

The return value, if any, should be described in a dedicated section at the endof the comment starting with “Return:”.

Structure, union, and enumeration documentation

The general format of a struct, union, and enum kernel-doc comment is:

/** * struct struct_name - Brief description. * @member_name: Description of member member_name. * * Description of the structure. */

Below, “struct” is used to mean structs, unions and enums, and “member” is usedto mean struct and union members as well as enumerations in an enum.

The brief description following the structure name may span multiple lines, andends with a @member: description, a blank comment line, or the end of thecomment block.

The kernel-doc data structure comments describe each member of the structure, inorder, with the @member: descriptions. The @member: descriptions mustbegin on the very next line following the opening brief function descriptionline, with no intervening blank comment lines. The @member: descriptions mayspan multiple lines. The continuation lines may contain indentation.

In-line member documentation comments

The structure members may also be documented in-line within the definition:

/** * struct foo - Brief description. * @foo: The Foo member. */struct foo { int foo; /** * @bar: The Bar member. */ int bar; /** * @baz: The Baz member. * * Here, the member description may contain several paragraphs. */ int baz;}

Private members

Inside a struct description, you can use the “private:” and “public:” commenttags. Structure fields that are inside a “private:” area are not listed in thegenerated output documentation. The “private:” and “public:” tags must beginimmediately following a /* comment marker. They may optionally includecomments between the : and the ending */ marker.

Example:

/** * struct my_struct - short description * @a: first member * @b: second member * * Longer description */struct my_struct { int a; int b;/* private: internal use only */ int c;};

Typedef documentation

The general format of a typedef kernel-doc comment is:

/** * typedef type_name - Brief description. * * Description of the type. */

Overview documentation comments

To facilitate having source code and comments close together, you can includekernel-doc documentation blocks that are free-form comments instead of beingkernel-doc for functions, structures, unions, enums, or typedefs. This could beused for something like a theory of operation for a driver or library code, forexample.

This is done by using a DOC: section keyword with a section title.

The general format of an overview or high-level documentation comment is:

/** * DOC: Theory of Operation * * The whizbang foobar is a dilly of a gizmo. It can do whatever you * want it to do, at any time. It reads your mind. Here's how it works. * * foo bar splat * * The only drawback to this gizmo is that is can sometimes damage * hardware, software, or its subject(s). */

The title following DOC: acts as a heading within the source file, but alsoas an identifier for extracting the documentation comment. Thus, the title mustbe unique within the file.

Recommendations

We definitely need kernel-doc formatted documentation for functions that areexported to loadable modules using EXPORT_SYMBOL or EXPORT_SYMBOL_GPL.

We also look to provide kernel-doc formatted documentation for functionsexternally visible to other kernel files (not marked “static”).

We also recommend providing kernel-doc formatted documentation for private (file“static”) routines, for consistency of kernel source code layout. But this islower priority and at the discretion of the MAINTAINER of that kernel sourcefile.

Data structures visible in kernel include files should also be documented usingkernel-doc formatted comments.

DocBook XML [DEPRECATED]

Attention

This section describes the deprecated DocBook XML toolchain. Please do notcreate new DocBook XML template files. Please consider converting existingDocBook XML templates files to Sphinx/reStructuredText.

Converting DocBook to Sphinx

Over time, we expect all of the documents under Documentation/DocBook to beconverted to Sphinx and reStructuredText. For most DocBook XML documents, a goodenough solution is to use the simple Documentation/sphinx/tmplcvt script,which uses pandoc under the hood. For example:

$ cd Documentation/sphinx$ ./tmplcvt ../DocBook/in.tmpl ../out.rst

Then edit the resulting rst files to fix any remaining issues, and add thedocument in the toctree in Documentation/index.rst.

Components of the kernel-doc system

Many places in the source tree have extractable documentation in the form ofblock comments above functions. The components of this system are:

  • scripts/kernel-doc

    This is a perl script that hunts for the block comments and can mark them updirectly into reStructuredText, DocBook, man, text, and HTML. (No, nottexinfo.)

  • Documentation/DocBook/*.tmpl

    These are XML template files, which are normal XML files with specialplace-holders for where the extracted documentation should go.

  • scripts/docproc.c

    This is a program for converting XML template files into XML files. When afile is referenced it is searched for symbols exported (EXPORT_SYMBOL), to beable to distinguish between internal and external functions.

    It invokes kernel-doc, giving it the list of functions that are to bedocumented.

    Additionally it is used to scan the XML template files to locate all the filesreferenced herein. This is used to generate dependency information as used bymake.

  • Makefile

    The targets ‘xmldocs’, ‘psdocs’, ‘pdfdocs’, and ‘htmldocs’ are used to buildDocBook XML files, PostScript files, PDF files, and html files inDocumentation/DocBook. The older target ‘sgmldocs’ is equivalent to ‘xmldocs’.

  • Documentation/DocBook/Makefile

    This is where C files are associated with SGML templates.

How to use kernel-doc comments in DocBook XML template files

DocBook XML template files (*.tmpl) are like normal XML files, except that theycan contain escape sequences where extracted documentation should be inserted.

!E<filename> is replaced by the documentation, in <filename>, forfunctions that are exported using EXPORT_SYMBOL: the function list iscollected from files listed in Documentation/DocBook/Makefile.

!I<filename> is replaced by the documentation for functions that are notexported using EXPORT_SYMBOL.

!D<filename> is used to name additional files to search for functionsexported using EXPORT_SYMBOL.

!F<filename> <function [functions...]> is replaced by the documentation, in<filename>, for the functions listed.

!P<filename> <section title> is replaced by the contents of the DOC:section titled <section title> from <filename>. Spaces are allowed in<section title>; do not quote the <section title>.

!C<filename> is replaced by nothing, but makes the tools check that all DOC:sections and documented functions, symbols, etc. are used. This makes sense touse when you use !F or !P only and want to verify that all documentationis included.

Linux Kernel Documentation — The Linux Kernel  documentation (2024)
Top Articles
XLM to XRP Exchange | Convert Stellar to XRP on SimpleSwap
Mines and environmental impact
Pixel Speedrun Unblocked 76
Craigslist Free En Dallas Tx
Star Sessions Imx
Robot or human?
Ixl Elmoreco.com
Is Sportsurge Safe and Legal in 2024? Any Alternatives?
Flights to Miami (MIA)
Dark Souls 2 Soft Cap
Citi Card Thomas Rhett Presale
Ohiohealth Esource Employee Login
A.e.a.o.n.m.s
Top Hat Trailer Wiring Diagram
Pro Groom Prices – The Pet Centre
The fabulous trio of the Miller sisters
DoorDash, Inc. (DASH) Stock Price, Quote & News - Stock Analysis
使用 RHEL 8 时的注意事项 | Red Hat Product Documentation
Spider-Man: Across The Spider-Verse Showtimes Near Marcus Bay Park Cinema
Erica Banks Net Worth | Boyfriend
Poe Str Stacking
Dragonvale Valor Dragon
Lost Pizza Nutrition
MyCase Pricing | Start Your 10-Day Free Trial Today
Bn9 Weather Radar
2021 MTV Video Music Awards: See the Complete List of Nominees - E! Online
Copper Pint Chaska
Alternatieven - Acteamo - WebCatalog
Craigslist Middletown Ohio
25Cc To Tbsp
Ancestors The Humankind Odyssey Wikia
Chadrad Swap Shop
Adecco Check Stubs
Green Bay Crime Reports Police Fire And Rescue
Amici Pizza Los Alamitos
Gold Nugget at the Golden Nugget
Sams La Habra Gas Price
Gun Mayhem Watchdocumentaries
Danielle Ranslow Obituary
Does Target Have Slime Lickers
Trending mods at Kenshi Nexus
Craigslist Mendocino
Stitch And Angel Tattoo Black And White
Crigslist Tucson
City Of Irving Tx Jail In-Custody List
Upcoming Live Online Auctions - Online Hunting Auctions
Used Sawmill For Sale - Craigslist Near Tennessee
Missed Connections Dayton Ohio
Round Yellow Adderall
Bloons Tower Defense 1 Unblocked
The Ultimate Guide To 5 Movierulz. Com: Exploring The World Of Online Movies
Www.card-Data.com/Comerica Prepaid Balance
Latest Posts
Article information

Author: Manual Maggio

Last Updated:

Views: 6217

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Manual Maggio

Birthday: 1998-01-20

Address: 359 Kelvin Stream, Lake Eldonview, MT 33517-1242

Phone: +577037762465

Job: Product Hospitality Supervisor

Hobby: Gardening, Web surfing, Video gaming, Amateur radio, Flag Football, Reading, Table tennis

Introduction: My name is Manual Maggio, I am a thankful, tender, adventurous, delightful, fantastic, proud, graceful person who loves writing and wants to share my knowledge and understanding with you.