18c2ecf20Sopenharmony_ciWriting kernel-doc comments
28c2ecf20Sopenharmony_ci===========================
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciThe Linux kernel source files may contain structured documentation
58c2ecf20Sopenharmony_cicomments in the kernel-doc format to describe the functions, types
68c2ecf20Sopenharmony_ciand design of the code. It is easier to keep documentation up-to-date
78c2ecf20Sopenharmony_ciwhen it is embedded in source files.
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci.. note:: The kernel-doc format is deceptively similar to javadoc,
108c2ecf20Sopenharmony_ci   gtk-doc or Doxygen, yet distinctively different, for historical
118c2ecf20Sopenharmony_ci   reasons. The kernel source contains tens of thousands of kernel-doc
128c2ecf20Sopenharmony_ci   comments. Please stick to the style described here.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciThe kernel-doc structure is extracted from the comments, and proper
158c2ecf20Sopenharmony_ci`Sphinx C Domain`_ function and type descriptions with anchors are
168c2ecf20Sopenharmony_cigenerated from them. The descriptions are filtered for special kernel-doc
178c2ecf20Sopenharmony_cihighlights and cross-references. See below for details.
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci.. _Sphinx C Domain: http://www.sphinx-doc.org/en/stable/domains.html
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciEvery function that is exported to loadable modules using
228c2ecf20Sopenharmony_ci``EXPORT_SYMBOL`` or ``EXPORT_SYMBOL_GPL`` should have a kernel-doc
238c2ecf20Sopenharmony_cicomment. Functions and data structures in header files which are intended
248c2ecf20Sopenharmony_cito be used by modules should also have kernel-doc comments.
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciIt is good practice to also provide kernel-doc formatted documentation
278c2ecf20Sopenharmony_cifor functions externally visible to other kernel files (not marked
288c2ecf20Sopenharmony_ci``static``). We also recommend providing kernel-doc formatted
298c2ecf20Sopenharmony_cidocumentation for private (file ``static``) routines, for consistency of
308c2ecf20Sopenharmony_cikernel source code layout. This is lower priority and at the discretion
318c2ecf20Sopenharmony_ciof the maintainer of that kernel source file.
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ciHow to format kernel-doc comments
348c2ecf20Sopenharmony_ci---------------------------------
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ciThe opening comment mark ``/**`` is used for kernel-doc comments. The
378c2ecf20Sopenharmony_ci``kernel-doc`` tool will extract comments marked this way. The rest of
388c2ecf20Sopenharmony_cithe comment is formatted like a normal multi-line comment with a column
398c2ecf20Sopenharmony_ciof asterisks on the left side, closing with ``*/`` on a line by itself.
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciThe function and type kernel-doc comments should be placed just before
428c2ecf20Sopenharmony_cithe function or type being described in order to maximise the chance
438c2ecf20Sopenharmony_cithat somebody changing the code will also change the documentation. The
448c2ecf20Sopenharmony_cioverview kernel-doc comments may be placed anywhere at the top indentation
458c2ecf20Sopenharmony_cilevel.
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciRunning the ``kernel-doc`` tool with increased verbosity and without actual
488c2ecf20Sopenharmony_cioutput generation may be used to verify proper formatting of the
498c2ecf20Sopenharmony_cidocumentation comments. For example::
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	scripts/kernel-doc -v -none drivers/foo/bar.c
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ciThe documentation format is verified by the kernel build when it is
548c2ecf20Sopenharmony_cirequested to perform extra gcc checks::
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	make W=n
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciFunction documentation
598c2ecf20Sopenharmony_ci----------------------
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ciThe general format of a function and function-like macro kernel-doc comment is::
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci  /**
648c2ecf20Sopenharmony_ci   * function_name() - Brief description of function.
658c2ecf20Sopenharmony_ci   * @arg1: Describe the first argument.
668c2ecf20Sopenharmony_ci   * @arg2: Describe the second argument.
678c2ecf20Sopenharmony_ci   *        One can provide multiple line descriptions
688c2ecf20Sopenharmony_ci   *        for arguments.
698c2ecf20Sopenharmony_ci   *
708c2ecf20Sopenharmony_ci   * A longer description, with more discussion of the function function_name()
718c2ecf20Sopenharmony_ci   * that might be useful to those using or modifying it. Begins with an
728c2ecf20Sopenharmony_ci   * empty comment line, and may include additional embedded empty
738c2ecf20Sopenharmony_ci   * comment lines.
748c2ecf20Sopenharmony_ci   *
758c2ecf20Sopenharmony_ci   * The longer description may have multiple paragraphs.
768c2ecf20Sopenharmony_ci   *
778c2ecf20Sopenharmony_ci   * Context: Describes whether the function can sleep, what locks it takes,
788c2ecf20Sopenharmony_ci   *          releases, or expects to be held. It can extend over multiple
798c2ecf20Sopenharmony_ci   *          lines.
808c2ecf20Sopenharmony_ci   * Return: Describe the return value of function_name.
818c2ecf20Sopenharmony_ci   *
828c2ecf20Sopenharmony_ci   * The return value description can also have multiple paragraphs, and should
838c2ecf20Sopenharmony_ci   * be placed at the end of the comment block.
848c2ecf20Sopenharmony_ci   */
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ciThe brief description following the function name may span multiple lines, and
878c2ecf20Sopenharmony_ciends with an argument description, a blank comment line, or the end of the
888c2ecf20Sopenharmony_cicomment block.
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ciFunction parameters
918c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ciEach function argument should be described in order, immediately following
948c2ecf20Sopenharmony_cithe short function description.  Do not leave a blank line between the
958c2ecf20Sopenharmony_cifunction description and the arguments, nor between the arguments.
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ciEach ``@argument:`` description may span multiple lines.
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci.. note::
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci   If the ``@argument`` description has multiple lines, the continuation
1028c2ecf20Sopenharmony_ci   of the description should start at the same column as the previous line::
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci      * @argument: some long description
1058c2ecf20Sopenharmony_ci      *            that continues on next lines
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci   or::
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci      * @argument:
1108c2ecf20Sopenharmony_ci      *		some long description
1118c2ecf20Sopenharmony_ci      *		that continues on next lines
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ciIf a function has a variable number of arguments, its description should
1148c2ecf20Sopenharmony_cibe written in kernel-doc notation as::
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci      * @...: description
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ciFunction context
1198c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ciThe context in which a function can be called should be described in a
1228c2ecf20Sopenharmony_cisection named ``Context``. This should include whether the function
1238c2ecf20Sopenharmony_cisleeps or can be called from interrupt context, as well as what locks
1248c2ecf20Sopenharmony_ciit takes, releases and expects to be held by its caller.
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ciExamples::
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci  * Context: Any context.
1298c2ecf20Sopenharmony_ci  * Context: Any context. Takes and releases the RCU lock.
1308c2ecf20Sopenharmony_ci  * Context: Any context. Expects <lock> to be held by caller.
1318c2ecf20Sopenharmony_ci  * Context: Process context. May sleep if @gfp flags permit.
1328c2ecf20Sopenharmony_ci  * Context: Process context. Takes and releases <mutex>.
1338c2ecf20Sopenharmony_ci  * Context: Softirq or process context. Takes and releases <lock>, BH-safe.
1348c2ecf20Sopenharmony_ci  * Context: Interrupt context.
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ciReturn values
1378c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ciThe return value, if any, should be described in a dedicated section
1408c2ecf20Sopenharmony_cinamed ``Return``.
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci.. note::
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci  #) The multi-line descriptive text you provide does *not* recognize
1458c2ecf20Sopenharmony_ci     line breaks, so if you try to format some text nicely, as in::
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	* Return:
1488c2ecf20Sopenharmony_ci	* 0 - OK
1498c2ecf20Sopenharmony_ci	* -EINVAL - invalid argument
1508c2ecf20Sopenharmony_ci	* -ENOMEM - out of memory
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci     this will all run together and produce::
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	Return: 0 - OK -EINVAL - invalid argument -ENOMEM - out of memory
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci     So, in order to produce the desired line breaks, you need to use a
1578c2ecf20Sopenharmony_ci     ReST list, e. g.::
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci      * Return:
1608c2ecf20Sopenharmony_ci      * * 0		- OK to runtime suspend the device
1618c2ecf20Sopenharmony_ci      * * -EBUSY	- Device should not be runtime suspended
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci  #) If the descriptive text you provide has lines that begin with
1648c2ecf20Sopenharmony_ci     some phrase followed by a colon, each of those phrases will be taken
1658c2ecf20Sopenharmony_ci     as a new section heading, which probably won't produce the desired
1668c2ecf20Sopenharmony_ci     effect.
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ciStructure, union, and enumeration documentation
1698c2ecf20Sopenharmony_ci-----------------------------------------------
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ciThe general format of a struct, union, and enum kernel-doc comment is::
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci  /**
1748c2ecf20Sopenharmony_ci   * struct struct_name - Brief description.
1758c2ecf20Sopenharmony_ci   * @member1: Description of member1.
1768c2ecf20Sopenharmony_ci   * @member2: Description of member2.
1778c2ecf20Sopenharmony_ci   *           One can provide multiple line descriptions
1788c2ecf20Sopenharmony_ci   *           for members.
1798c2ecf20Sopenharmony_ci   *
1808c2ecf20Sopenharmony_ci   * Description of the structure.
1818c2ecf20Sopenharmony_ci   */
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ciYou can replace the ``struct`` in the above example with ``union`` or
1848c2ecf20Sopenharmony_ci``enum``  to describe unions or enums. ``member`` is used to mean struct
1858c2ecf20Sopenharmony_ciand union member names as well as enumerations in an enum.
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ciThe brief description following the structure name may span multiple
1888c2ecf20Sopenharmony_cilines, and ends with a member description, a blank comment line, or the
1898c2ecf20Sopenharmony_ciend of the comment block.
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ciMembers
1928c2ecf20Sopenharmony_ci~~~~~~~
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ciMembers of structs, unions and enums should be documented the same way
1958c2ecf20Sopenharmony_cias function parameters; they immediately succeed the short description
1968c2ecf20Sopenharmony_ciand may be multi-line.
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ciInside a struct or union description, you can use the ``private:`` and
1998c2ecf20Sopenharmony_ci``public:`` comment tags. Structure fields that are inside a ``private:``
2008c2ecf20Sopenharmony_ciarea are not listed in the generated output documentation.
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ciThe ``private:`` and ``public:`` tags must begin immediately following a
2038c2ecf20Sopenharmony_ci``/*`` comment marker. They may optionally include comments between the
2048c2ecf20Sopenharmony_ci``:`` and the ending ``*/`` marker.
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ciExample::
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci  /**
2098c2ecf20Sopenharmony_ci   * struct my_struct - short description
2108c2ecf20Sopenharmony_ci   * @a: first member
2118c2ecf20Sopenharmony_ci   * @b: second member
2128c2ecf20Sopenharmony_ci   * @d: fourth member
2138c2ecf20Sopenharmony_ci   *
2148c2ecf20Sopenharmony_ci   * Longer description
2158c2ecf20Sopenharmony_ci   */
2168c2ecf20Sopenharmony_ci  struct my_struct {
2178c2ecf20Sopenharmony_ci      int a;
2188c2ecf20Sopenharmony_ci      int b;
2198c2ecf20Sopenharmony_ci  /* private: internal use only */
2208c2ecf20Sopenharmony_ci      int c;
2218c2ecf20Sopenharmony_ci  /* public: the next one is public */
2228c2ecf20Sopenharmony_ci      int d;
2238c2ecf20Sopenharmony_ci  };
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ciNested structs/unions
2268c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ciIt is possible to document nested structs and unions, like::
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci      /**
2318c2ecf20Sopenharmony_ci       * struct nested_foobar - a struct with nested unions and structs
2328c2ecf20Sopenharmony_ci       * @memb1: first member of anonymous union/anonymous struct
2338c2ecf20Sopenharmony_ci       * @memb2: second member of anonymous union/anonymous struct
2348c2ecf20Sopenharmony_ci       * @memb3: third member of anonymous union/anonymous struct
2358c2ecf20Sopenharmony_ci       * @memb4: fourth member of anonymous union/anonymous struct
2368c2ecf20Sopenharmony_ci       * @bar: non-anonymous union
2378c2ecf20Sopenharmony_ci       * @bar.st1: struct st1 inside @bar
2388c2ecf20Sopenharmony_ci       * @bar.st2: struct st2 inside @bar
2398c2ecf20Sopenharmony_ci       * @bar.st1.memb1: first member of struct st1 on union bar
2408c2ecf20Sopenharmony_ci       * @bar.st1.memb2: second member of struct st1 on union bar
2418c2ecf20Sopenharmony_ci       * @bar.st2.memb1: first member of struct st2 on union bar
2428c2ecf20Sopenharmony_ci       * @bar.st2.memb2: second member of struct st2 on union bar
2438c2ecf20Sopenharmony_ci       */
2448c2ecf20Sopenharmony_ci      struct nested_foobar {
2458c2ecf20Sopenharmony_ci        /* Anonymous union/struct*/
2468c2ecf20Sopenharmony_ci        union {
2478c2ecf20Sopenharmony_ci          struct {
2488c2ecf20Sopenharmony_ci            int memb1;
2498c2ecf20Sopenharmony_ci            int memb2;
2508c2ecf20Sopenharmony_ci        }
2518c2ecf20Sopenharmony_ci          struct {
2528c2ecf20Sopenharmony_ci            void *memb3;
2538c2ecf20Sopenharmony_ci            int memb4;
2548c2ecf20Sopenharmony_ci          }
2558c2ecf20Sopenharmony_ci        }
2568c2ecf20Sopenharmony_ci        union {
2578c2ecf20Sopenharmony_ci          struct {
2588c2ecf20Sopenharmony_ci            int memb1;
2598c2ecf20Sopenharmony_ci            int memb2;
2608c2ecf20Sopenharmony_ci          } st1;
2618c2ecf20Sopenharmony_ci          struct {
2628c2ecf20Sopenharmony_ci            void *memb1;
2638c2ecf20Sopenharmony_ci            int memb2;
2648c2ecf20Sopenharmony_ci          } st2;
2658c2ecf20Sopenharmony_ci        } bar;
2668c2ecf20Sopenharmony_ci      };
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci.. note::
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci   #) When documenting nested structs or unions, if the struct/union ``foo``
2718c2ecf20Sopenharmony_ci      is named, the member ``bar`` inside it should be documented as
2728c2ecf20Sopenharmony_ci      ``@foo.bar:``
2738c2ecf20Sopenharmony_ci   #) When the nested struct/union is anonymous, the member ``bar`` in it
2748c2ecf20Sopenharmony_ci      should be documented as ``@bar:``
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ciIn-line member documentation comments
2778c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ciThe structure members may also be documented in-line within the definition.
2808c2ecf20Sopenharmony_ciThere are two styles, single-line comments where both the opening ``/**`` and
2818c2ecf20Sopenharmony_ciclosing ``*/`` are on the same line, and multi-line comments where they are each
2828c2ecf20Sopenharmony_cion a line of their own, like all other kernel-doc comments::
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci  /**
2858c2ecf20Sopenharmony_ci   * struct foo - Brief description.
2868c2ecf20Sopenharmony_ci   * @foo: The Foo member.
2878c2ecf20Sopenharmony_ci   */
2888c2ecf20Sopenharmony_ci  struct foo {
2898c2ecf20Sopenharmony_ci        int foo;
2908c2ecf20Sopenharmony_ci        /**
2918c2ecf20Sopenharmony_ci         * @bar: The Bar member.
2928c2ecf20Sopenharmony_ci         */
2938c2ecf20Sopenharmony_ci        int bar;
2948c2ecf20Sopenharmony_ci        /**
2958c2ecf20Sopenharmony_ci         * @baz: The Baz member.
2968c2ecf20Sopenharmony_ci         *
2978c2ecf20Sopenharmony_ci         * Here, the member description may contain several paragraphs.
2988c2ecf20Sopenharmony_ci         */
2998c2ecf20Sopenharmony_ci        int baz;
3008c2ecf20Sopenharmony_ci        union {
3018c2ecf20Sopenharmony_ci                /** @foobar: Single line description. */
3028c2ecf20Sopenharmony_ci                int foobar;
3038c2ecf20Sopenharmony_ci        };
3048c2ecf20Sopenharmony_ci        /** @bar2: Description for struct @bar2 inside @foo */
3058c2ecf20Sopenharmony_ci        struct {
3068c2ecf20Sopenharmony_ci                /**
3078c2ecf20Sopenharmony_ci                 * @bar2.barbar: Description for @barbar inside @foo.bar2
3088c2ecf20Sopenharmony_ci                 */
3098c2ecf20Sopenharmony_ci                int barbar;
3108c2ecf20Sopenharmony_ci        } bar2;
3118c2ecf20Sopenharmony_ci  };
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ciTypedef documentation
3148c2ecf20Sopenharmony_ci---------------------
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ciThe general format of a typedef kernel-doc comment is::
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci  /**
3198c2ecf20Sopenharmony_ci   * typedef type_name - Brief description.
3208c2ecf20Sopenharmony_ci   *
3218c2ecf20Sopenharmony_ci   * Description of the type.
3228c2ecf20Sopenharmony_ci   */
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ciTypedefs with function prototypes can also be documented::
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci  /**
3278c2ecf20Sopenharmony_ci   * typedef type_name - Brief description.
3288c2ecf20Sopenharmony_ci   * @arg1: description of arg1
3298c2ecf20Sopenharmony_ci   * @arg2: description of arg2
3308c2ecf20Sopenharmony_ci   *
3318c2ecf20Sopenharmony_ci   * Description of the type.
3328c2ecf20Sopenharmony_ci   *
3338c2ecf20Sopenharmony_ci   * Context: Locking context.
3348c2ecf20Sopenharmony_ci   * Return: Meaning of the return value.
3358c2ecf20Sopenharmony_ci   */
3368c2ecf20Sopenharmony_ci   typedef void (*type_name)(struct v4l2_ctrl *arg1, void *arg2);
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ciHighlights and cross-references
3398c2ecf20Sopenharmony_ci-------------------------------
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ciThe following special patterns are recognized in the kernel-doc comment
3428c2ecf20Sopenharmony_cidescriptive text and converted to proper reStructuredText markup and `Sphinx C
3438c2ecf20Sopenharmony_ciDomain`_ references.
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci.. attention:: The below are **only** recognized within kernel-doc comments,
3468c2ecf20Sopenharmony_ci	       **not** within normal reStructuredText documents.
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci``funcname()``
3498c2ecf20Sopenharmony_ci  Function reference.
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci``@parameter``
3528c2ecf20Sopenharmony_ci  Name of a function parameter. (No cross-referencing, just formatting.)
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci``%CONST``
3558c2ecf20Sopenharmony_ci  Name of a constant. (No cross-referencing, just formatting.)
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci````literal````
3588c2ecf20Sopenharmony_ci  A literal block that should be handled as-is. The output will use a
3598c2ecf20Sopenharmony_ci  ``monospaced font``.
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci  Useful if you need to use special characters that would otherwise have some
3628c2ecf20Sopenharmony_ci  meaning either by kernel-doc script or by reStructuredText.
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci  This is particularly useful if you need to use things like ``%ph`` inside
3658c2ecf20Sopenharmony_ci  a function description.
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci``$ENVVAR``
3688c2ecf20Sopenharmony_ci  Name of an environment variable. (No cross-referencing, just formatting.)
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci``&struct name``
3718c2ecf20Sopenharmony_ci  Structure reference.
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci``&enum name``
3748c2ecf20Sopenharmony_ci  Enum reference.
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci``&typedef name``
3778c2ecf20Sopenharmony_ci  Typedef reference.
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci``&struct_name->member`` or ``&struct_name.member``
3808c2ecf20Sopenharmony_ci  Structure or union member reference. The cross-reference will be to the struct
3818c2ecf20Sopenharmony_ci  or union definition, not the member directly.
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci``&name``
3848c2ecf20Sopenharmony_ci  A generic type reference. Prefer using the full reference described above
3858c2ecf20Sopenharmony_ci  instead. This is mostly for legacy comments.
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ciCross-referencing from reStructuredText
3888c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ciNo additional syntax is needed to cross-reference the functions and types
3918c2ecf20Sopenharmony_cidefined in the kernel-doc comments from reStructuredText documents.
3928c2ecf20Sopenharmony_ciJust end function names with ``()`` and write ``struct``, ``union``, ``enum``
3938c2ecf20Sopenharmony_cior ``typedef`` before types.
3948c2ecf20Sopenharmony_ciFor example::
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci  See foo().
3978c2ecf20Sopenharmony_ci  See struct foo.
3988c2ecf20Sopenharmony_ci  See union bar.
3998c2ecf20Sopenharmony_ci  See enum baz.
4008c2ecf20Sopenharmony_ci  See typedef meh.
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ciHowever, if you want custom text in the cross-reference link, that can be done
4038c2ecf20Sopenharmony_cithrough the following syntax::
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci  See :c:func:`my custom link text for function foo <foo>`.
4068c2ecf20Sopenharmony_ci  See :c:type:`my custom link text for struct bar <bar>`.
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ciFor further details, please refer to the `Sphinx C Domain`_ documentation.
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ciOverview documentation comments
4118c2ecf20Sopenharmony_ci-------------------------------
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ciTo facilitate having source code and comments close together, you can include
4148c2ecf20Sopenharmony_cikernel-doc documentation blocks that are free-form comments instead of being
4158c2ecf20Sopenharmony_cikernel-doc for functions, structures, unions, enums, or typedefs. This could be
4168c2ecf20Sopenharmony_ciused for something like a theory of operation for a driver or library code, for
4178c2ecf20Sopenharmony_ciexample.
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ciThis is done by using a ``DOC:`` section keyword with a section title.
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ciThe general format of an overview or high-level documentation comment is::
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_ci  /**
4248c2ecf20Sopenharmony_ci   * DOC: Theory of Operation
4258c2ecf20Sopenharmony_ci   *
4268c2ecf20Sopenharmony_ci   * The whizbang foobar is a dilly of a gizmo. It can do whatever you
4278c2ecf20Sopenharmony_ci   * want it to do, at any time. It reads your mind. Here's how it works.
4288c2ecf20Sopenharmony_ci   *
4298c2ecf20Sopenharmony_ci   * foo bar splat
4308c2ecf20Sopenharmony_ci   *
4318c2ecf20Sopenharmony_ci   * The only drawback to this gizmo is that is can sometimes damage
4328c2ecf20Sopenharmony_ci   * hardware, software, or its subject(s).
4338c2ecf20Sopenharmony_ci   */
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ciThe title following ``DOC:`` acts as a heading within the source file, but also
4368c2ecf20Sopenharmony_cias an identifier for extracting the documentation comment. Thus, the title must
4378c2ecf20Sopenharmony_cibe unique within the file.
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ciIncluding kernel-doc comments
4408c2ecf20Sopenharmony_ci=============================
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ciThe documentation comments may be included in any of the reStructuredText
4438c2ecf20Sopenharmony_cidocuments using a dedicated kernel-doc Sphinx directive extension.
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ciThe kernel-doc directive is of the format::
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci  .. kernel-doc:: source
4488c2ecf20Sopenharmony_ci     :option:
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ciThe *source* is the path to a source file, relative to the kernel source
4518c2ecf20Sopenharmony_citree. The following directive options are supported:
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ciexport: *[source-pattern ...]*
4548c2ecf20Sopenharmony_ci  Include documentation for all functions in *source* that have been exported
4558c2ecf20Sopenharmony_ci  using ``EXPORT_SYMBOL`` or ``EXPORT_SYMBOL_GPL`` either in *source* or in any
4568c2ecf20Sopenharmony_ci  of the files specified by *source-pattern*.
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci  The *source-pattern* is useful when the kernel-doc comments have been placed
4598c2ecf20Sopenharmony_ci  in header files, while ``EXPORT_SYMBOL`` and ``EXPORT_SYMBOL_GPL`` are next to
4608c2ecf20Sopenharmony_ci  the function definitions.
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci  Examples::
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci    .. kernel-doc:: lib/bitmap.c
4658c2ecf20Sopenharmony_ci       :export:
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci    .. kernel-doc:: include/net/mac80211.h
4688c2ecf20Sopenharmony_ci       :export: net/mac80211/*.c
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ciinternal: *[source-pattern ...]*
4718c2ecf20Sopenharmony_ci  Include documentation for all functions and types in *source* that have
4728c2ecf20Sopenharmony_ci  **not** been exported using ``EXPORT_SYMBOL`` or ``EXPORT_SYMBOL_GPL`` either
4738c2ecf20Sopenharmony_ci  in *source* or in any of the files specified by *source-pattern*.
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_ci  Example::
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci    .. kernel-doc:: drivers/gpu/drm/i915/intel_audio.c
4788c2ecf20Sopenharmony_ci       :internal:
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ciidentifiers: *[ function/type ...]*
4818c2ecf20Sopenharmony_ci  Include documentation for each *function* and *type* in *source*.
4828c2ecf20Sopenharmony_ci  If no *function* is specified, the documentation for all functions
4838c2ecf20Sopenharmony_ci  and types in the *source* will be included.
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci  Examples::
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci    .. kernel-doc:: lib/bitmap.c
4888c2ecf20Sopenharmony_ci       :identifiers: bitmap_parselist bitmap_parselist_user
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ci    .. kernel-doc:: lib/idr.c
4918c2ecf20Sopenharmony_ci       :identifiers:
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_cino-identifiers: *[ function/type ...]*
4948c2ecf20Sopenharmony_ci  Exclude documentation for each *function* and *type* in *source*.
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci  Example::
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci    .. kernel-doc:: lib/bitmap.c
4998c2ecf20Sopenharmony_ci       :no-identifiers: bitmap_parselist
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_cifunctions: *[ function/type ...]*
5028c2ecf20Sopenharmony_ci  This is an alias of the 'identifiers' directive and deprecated.
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_cidoc: *title*
5058c2ecf20Sopenharmony_ci  Include documentation for the ``DOC:`` paragraph identified by *title* in
5068c2ecf20Sopenharmony_ci  *source*. Spaces are allowed in *title*; do not quote the *title*. The *title*
5078c2ecf20Sopenharmony_ci  is only used as an identifier for the paragraph, and is not included in the
5088c2ecf20Sopenharmony_ci  output. Please make sure to have an appropriate heading in the enclosing
5098c2ecf20Sopenharmony_ci  reStructuredText document.
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ci  Example::
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_ci    .. kernel-doc:: drivers/gpu/drm/i915/intel_audio.c
5148c2ecf20Sopenharmony_ci       :doc: High Definition Audio over HDMI and Display Port
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ciWithout options, the kernel-doc directive includes all documentation comments
5178c2ecf20Sopenharmony_cifrom the source file.
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ciThe kernel-doc extension is included in the kernel source tree, at
5208c2ecf20Sopenharmony_ci``Documentation/sphinx/kerneldoc.py``. Internally, it uses the
5218c2ecf20Sopenharmony_ci``scripts/kernel-doc`` script to extract the documentation comments from the
5228c2ecf20Sopenharmony_cisource.
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci.. _kernel_doc:
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ciHow to use kernel-doc to generate man pages
5278c2ecf20Sopenharmony_ci-------------------------------------------
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_ciIf you just want to use kernel-doc to generate man pages you can do this
5308c2ecf20Sopenharmony_cifrom the kernel git tree::
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci  $ scripts/kernel-doc -man \
5338c2ecf20Sopenharmony_ci    $(git grep -l '/\*\*' -- :^Documentation :^tools) \
5348c2ecf20Sopenharmony_ci    | scripts/split-man.pl /tmp/man
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ciSome older versions of git do not support some of the variants of syntax for
5378c2ecf20Sopenharmony_cipath exclusion.  One of the following commands may work for those versions::
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci  $ scripts/kernel-doc -man \
5408c2ecf20Sopenharmony_ci    $(git grep -l '/\*\*' -- . ':!Documentation' ':!tools') \
5418c2ecf20Sopenharmony_ci    | scripts/split-man.pl /tmp/man
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_ci  $ scripts/kernel-doc -man \
5448c2ecf20Sopenharmony_ci    $(git grep -l '/\*\*' -- . ":(exclude)Documentation" ":(exclude)tools") \
5458c2ecf20Sopenharmony_ci    | scripts/split-man.pl /tmp/man
546