Mauro Carvalho Chehab | 1dc4bbf | 2016-11-17 08:32:33 -0200 | [diff] [blame] | 1 | Writing kernel-doc comments |
| 2 | =========================== |
| 3 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 4 | The Linux kernel source files may contain structured documentation |
| 5 | comments in the kernel-doc format to describe the functions, types |
| 6 | and design of the code. It is easier to keep documentation up-to-date |
| 7 | when it is embedded in source files. |
Mauro Carvalho Chehab | 1dc4bbf | 2016-11-17 08:32:33 -0200 | [diff] [blame] | 8 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 9 | .. note:: The kernel-doc format is deceptively similar to javadoc, |
| 10 | gtk-doc or Doxygen, yet distinctively different, for historical |
| 11 | reasons. The kernel source contains tens of thousands of kernel-doc |
| 12 | comments. Please stick to the style described here. |
Mauro Carvalho Chehab | 1dc4bbf | 2016-11-17 08:32:33 -0200 | [diff] [blame] | 13 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 14 | The kernel-doc structure is extracted from the comments, and proper |
| 15 | `Sphinx C Domain`_ function and type descriptions with anchors are |
| 16 | generated from them. The descriptions are filtered for special kernel-doc |
| 17 | highlights and cross-references. See below for details. |
Mauro Carvalho Chehab | 1dc4bbf | 2016-11-17 08:32:33 -0200 | [diff] [blame] | 18 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 19 | .. _Sphinx C Domain: http://www.sphinx-doc.org/en/stable/domains.html |
| 20 | |
| 21 | Every function that is exported to loadable modules using |
| 22 | ``EXPORT_SYMBOL`` or ``EXPORT_SYMBOL_GPL`` should have a kernel-doc |
| 23 | comment. Functions and data structures in header files which are intended |
| 24 | to be used by modules should also have kernel-doc comments. |
| 25 | |
| 26 | It is good practice to also provide kernel-doc formatted documentation |
| 27 | for functions externally visible to other kernel files (not marked |
| 28 | ``static``). We also recommend providing kernel-doc formatted |
| 29 | documentation for private (file ``static``) routines, for consistency of |
| 30 | kernel source code layout. This is lower priority and at the discretion |
| 31 | of the maintainer of that kernel source file. |
Mauro Carvalho Chehab | 1dc4bbf | 2016-11-17 08:32:33 -0200 | [diff] [blame] | 32 | |
| 33 | How to format kernel-doc comments |
| 34 | --------------------------------- |
| 35 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 36 | The opening comment mark ``/**`` is used for kernel-doc comments. The |
| 37 | ``kernel-doc`` tool will extract comments marked this way. The rest of |
| 38 | the comment is formatted like a normal multi-line comment with a column |
| 39 | of asterisks on the left side, closing with ``*/`` on a line by itself. |
Mauro Carvalho Chehab | 1dc4bbf | 2016-11-17 08:32:33 -0200 | [diff] [blame] | 40 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 41 | The function and type kernel-doc comments should be placed just before |
| 42 | the function or type being described in order to maximise the chance |
| 43 | that somebody changing the code will also change the documentation. The |
| 44 | overview kernel-doc comments may be placed anywhere at the top indentation |
| 45 | level. |
Mauro Carvalho Chehab | 01f2c18 | 2017-12-18 10:30:03 -0200 | [diff] [blame] | 46 | |
Mauro Carvalho Chehab | fc275bf | 2017-12-18 10:30:04 -0200 | [diff] [blame] | 47 | Function documentation |
| 48 | ---------------------- |
| 49 | |
| 50 | The general format of a function and function-like macro kernel-doc comment is:: |
| 51 | |
| 52 | /** |
| 53 | * function_name() - Brief description of function. |
| 54 | * @arg1: Describe the first argument. |
| 55 | * @arg2: Describe the second argument. |
| 56 | * One can provide multiple line descriptions |
| 57 | * for arguments. |
| 58 | * |
| 59 | * A longer description, with more discussion of the function function_name() |
| 60 | * that might be useful to those using or modifying it. Begins with an |
| 61 | * empty comment line, and may include additional embedded empty |
| 62 | * comment lines. |
| 63 | * |
| 64 | * The longer description may have multiple paragraphs. |
| 65 | * |
Matthew Wilcox | da70b8c | 2018-02-13 13:15:33 -0800 | [diff] [blame] | 66 | * Context: Describes whether the function can sleep, what locks it takes, |
| 67 | * releases, or expects to be held. It can extend over multiple |
| 68 | * lines. |
Mauro Carvalho Chehab | fc275bf | 2017-12-18 10:30:04 -0200 | [diff] [blame] | 69 | * Return: Describe the return value of foobar. |
| 70 | * |
| 71 | * The return value description can also have multiple paragraphs, and should |
| 72 | * be placed at the end of the comment block. |
| 73 | */ |
| 74 | |
| 75 | The brief description following the function name may span multiple lines, and |
| 76 | ends with an argument description, a blank comment line, or the end of the |
| 77 | comment block. |
| 78 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 79 | Function parameters |
| 80 | ~~~~~~~~~~~~~~~~~~~ |
| 81 | |
| 82 | Each function argument should be described in order, immediately following |
| 83 | the short function description. Do not leave a blank line between the |
| 84 | function description and the arguments, nor between the arguments. |
| 85 | |
| 86 | Each ``@argument:`` description may span multiple lines. |
| 87 | |
| 88 | .. note:: |
| 89 | |
| 90 | If the ``@argument`` description has multiple lines, the continuation |
| 91 | of the description should start at the same column as the previous line:: |
| 92 | |
| 93 | * @argument: some long description |
| 94 | * that continues on next lines |
| 95 | |
| 96 | or:: |
| 97 | |
| 98 | * @argument: |
| 99 | * some long description |
| 100 | * that continues on next lines |
| 101 | |
| 102 | If a function has a variable number of arguments, its description should |
| 103 | be written in kernel-doc notation as:: |
| 104 | |
| 105 | * @...: description |
| 106 | |
Matthew Wilcox | da70b8c | 2018-02-13 13:15:33 -0800 | [diff] [blame] | 107 | Function context |
| 108 | ~~~~~~~~~~~~~~~~ |
| 109 | |
| 110 | The context in which a function can be called should be described in a |
| 111 | section named ``Context``. This should include whether the function |
| 112 | sleeps or can be called from interrupt context, as well as what locks |
| 113 | it takes, releases and expects to be held by its caller. |
| 114 | |
| 115 | Examples:: |
| 116 | |
| 117 | * Context: Any context. |
| 118 | * Context: Any context. Takes and releases the RCU lock. |
| 119 | * Context: Any context. Expects <lock> to be held by caller. |
| 120 | * Context: Process context. May sleep if @gfp flags permit. |
| 121 | * Context: Process context. Takes and releases <mutex>. |
| 122 | * Context: Softirq or process context. Takes and releases <lock>, BH-safe. |
| 123 | * Context: Interrupt context. |
| 124 | |
Mauro Carvalho Chehab | fc275bf | 2017-12-18 10:30:04 -0200 | [diff] [blame] | 125 | Return values |
| 126 | ~~~~~~~~~~~~~ |
| 127 | |
| 128 | The return value, if any, should be described in a dedicated section |
| 129 | named ``Return``. |
| 130 | |
| 131 | .. note:: |
| 132 | |
| 133 | #) The multi-line descriptive text you provide does *not* recognize |
| 134 | line breaks, so if you try to format some text nicely, as in:: |
| 135 | |
| 136 | * Return: |
| 137 | * 0 - OK |
| 138 | * -EINVAL - invalid argument |
| 139 | * -ENOMEM - out of memory |
| 140 | |
| 141 | this will all run together and produce:: |
| 142 | |
| 143 | Return: 0 - OK -EINVAL - invalid argument -ENOMEM - out of memory |
| 144 | |
| 145 | So, in order to produce the desired line breaks, you need to use a |
| 146 | ReST list, e. g.:: |
| 147 | |
| 148 | * Return: |
| 149 | * * 0 - OK to runtime suspend the device |
| 150 | * * -EBUSY - Device should not be runtime suspended |
| 151 | |
| 152 | #) If the descriptive text you provide has lines that begin with |
| 153 | some phrase followed by a colon, each of those phrases will be taken |
Matthew Wilcox | dcb50d9 | 2018-02-13 13:15:34 -0800 | [diff] [blame] | 154 | as a new section heading, which probably won't produce the desired |
Mauro Carvalho Chehab | fc275bf | 2017-12-18 10:30:04 -0200 | [diff] [blame] | 155 | effect. |
| 156 | |
Mauro Carvalho Chehab | 553aa3c | 2017-12-18 10:30:05 -0200 | [diff] [blame] | 157 | Structure, union, and enumeration documentation |
| 158 | ----------------------------------------------- |
| 159 | |
| 160 | The general format of a struct, union, and enum kernel-doc comment is:: |
| 161 | |
| 162 | /** |
| 163 | * struct struct_name - Brief description. |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 164 | * @member1: Description of member1. |
| 165 | * @member2: Description of member2. |
| 166 | * One can provide multiple line descriptions |
| 167 | * for members. |
Mauro Carvalho Chehab | 553aa3c | 2017-12-18 10:30:05 -0200 | [diff] [blame] | 168 | * |
| 169 | * Description of the structure. |
| 170 | */ |
| 171 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 172 | You can replace the ``struct`` in the above example with ``union`` or |
| 173 | ``enum`` to describe unions or enums. ``member`` is used to mean struct |
| 174 | and union member names as well as enumerations in an enum. |
Mauro Carvalho Chehab | 553aa3c | 2017-12-18 10:30:05 -0200 | [diff] [blame] | 175 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 176 | The brief description following the structure name may span multiple |
| 177 | lines, and ends with a member description, a blank comment line, or the |
| 178 | end of the comment block. |
Mauro Carvalho Chehab | 553aa3c | 2017-12-18 10:30:05 -0200 | [diff] [blame] | 179 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 180 | Members |
| 181 | ~~~~~~~ |
| 182 | |
| 183 | Members of structs, unions and enums should be documented the same way |
| 184 | as function parameters; they immediately succeed the short description |
| 185 | and may be multi-line. |
| 186 | |
| 187 | Inside a struct or union description, you can use the ``private:`` and |
| 188 | ``public:`` comment tags. Structure fields that are inside a ``private:`` |
| 189 | area are not listed in the generated output documentation. |
| 190 | |
| 191 | The ``private:`` and ``public:`` tags must begin immediately following a |
| 192 | ``/*`` comment marker. They may optionally include comments between the |
| 193 | ``:`` and the ending ``*/`` marker. |
| 194 | |
| 195 | Example:: |
| 196 | |
| 197 | /** |
| 198 | * struct my_struct - short description |
| 199 | * @a: first member |
| 200 | * @b: second member |
| 201 | * @d: fourth member |
| 202 | * |
| 203 | * Longer description |
| 204 | */ |
| 205 | struct my_struct { |
| 206 | int a; |
| 207 | int b; |
| 208 | /* private: internal use only */ |
| 209 | int c; |
| 210 | /* public: the next one is public */ |
| 211 | int d; |
| 212 | }; |
| 213 | |
| 214 | In-line member documentation comments |
| 215 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 216 | |
| 217 | The structure members may also be documented in-line within the definition. |
| 218 | There are two styles, single-line comments where both the opening ``/**`` and |
| 219 | closing ``*/`` are on the same line, and multi-line comments where they are each |
| 220 | on a line of their own, like all other kernel-doc comments:: |
| 221 | |
| 222 | /** |
| 223 | * struct foo - Brief description. |
| 224 | * @foo: The Foo member. |
| 225 | */ |
| 226 | struct foo { |
| 227 | int foo; |
| 228 | /** |
| 229 | * @bar: The Bar member. |
| 230 | */ |
| 231 | int bar; |
| 232 | /** |
| 233 | * @baz: The Baz member. |
| 234 | * |
| 235 | * Here, the member description may contain several paragraphs. |
| 236 | */ |
| 237 | int baz; |
| 238 | /** @foobar: Single line description. */ |
| 239 | int foobar; |
| 240 | } |
Mauro Carvalho Chehab | 553aa3c | 2017-12-18 10:30:05 -0200 | [diff] [blame] | 241 | |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 242 | Nested structs/unions |
| 243 | ~~~~~~~~~~~~~~~~~~~~~ |
| 244 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 245 | It is possible to document nested structs and unions, like:: |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 246 | |
| 247 | /** |
| 248 | * struct nested_foobar - a struct with nested unions and structs |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 249 | * @memb1: first member of anonymous union/anonymous struct |
| 250 | * @memb2: second member of anonymous union/anonymous struct |
| 251 | * @memb3: third member of anonymous union/anonymous struct |
| 252 | * @memb4: fourth member of anonymous union/anonymous struct |
Mauro Carvalho Chehab | 3651d45 | 2018-02-16 11:48:15 -0200 | [diff] [blame^] | 253 | * @bar: non-anonymous union |
| 254 | * @bar.st1: struct st1 inside @bar |
| 255 | * @bar.st2: struct st2 inside @bar |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 256 | * @bar.st1.memb1: first member of struct st1 on union bar |
| 257 | * @bar.st1.memb2: second member of struct st1 on union bar |
| 258 | * @bar.st2.memb1: first member of struct st2 on union bar |
| 259 | * @bar.st2.memb2: second member of struct st2 on union bar |
Mauro Carvalho Chehab | 3651d45 | 2018-02-16 11:48:15 -0200 | [diff] [blame^] | 260 | */ |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 261 | struct nested_foobar { |
| 262 | /* Anonymous union/struct*/ |
| 263 | union { |
| 264 | struct { |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 265 | int memb1; |
| 266 | int memb2; |
Matthew Wilcox | dcb50d9 | 2018-02-13 13:15:34 -0800 | [diff] [blame] | 267 | } |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 268 | struct { |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 269 | void *memb3; |
| 270 | int memb4; |
Matthew Wilcox | dcb50d9 | 2018-02-13 13:15:34 -0800 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | union { |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 274 | struct { |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 275 | int memb1; |
| 276 | int memb2; |
Matthew Wilcox | dcb50d9 | 2018-02-13 13:15:34 -0800 | [diff] [blame] | 277 | } st1; |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 278 | struct { |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 279 | void *memb1; |
| 280 | int memb2; |
Matthew Wilcox | dcb50d9 | 2018-02-13 13:15:34 -0800 | [diff] [blame] | 281 | } st2; |
| 282 | } bar; |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | .. note:: |
| 286 | |
| 287 | #) When documenting nested structs or unions, if the struct/union ``foo`` |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 288 | is named, the member ``bar`` inside it should be documented as |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 289 | ``@foo.bar:`` |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 290 | #) When the nested struct/union is anonymous, the member ``bar`` in it |
Mauro Carvalho Chehab | 8ad7216 | 2017-12-18 10:30:13 -0200 | [diff] [blame] | 291 | should be documented as ``@bar:`` |
Mauro Carvalho Chehab | 553aa3c | 2017-12-18 10:30:05 -0200 | [diff] [blame] | 292 | |
Mauro Carvalho Chehab | bdb76f9 | 2017-12-18 10:30:06 -0200 | [diff] [blame] | 293 | Typedef documentation |
| 294 | --------------------- |
| 295 | |
| 296 | The general format of a typedef kernel-doc comment is:: |
| 297 | |
| 298 | /** |
| 299 | * typedef type_name - Brief description. |
| 300 | * |
| 301 | * Description of the type. |
| 302 | */ |
| 303 | |
| 304 | Typedefs with function prototypes can also be documented:: |
| 305 | |
| 306 | /** |
| 307 | * typedef type_name - Brief description. |
| 308 | * @arg1: description of arg1 |
| 309 | * @arg2: description of arg2 |
| 310 | * |
| 311 | * Description of the type. |
Matthew Wilcox | da70b8c | 2018-02-13 13:15:33 -0800 | [diff] [blame] | 312 | * |
| 313 | * Context: Locking context. |
| 314 | * Return: Meaning of the return value. |
Mauro Carvalho Chehab | bdb76f9 | 2017-12-18 10:30:06 -0200 | [diff] [blame] | 315 | */ |
| 316 | typedef void (*type_name)(struct v4l2_ctrl *arg1, void *arg2); |
| 317 | |
Mauro Carvalho Chehab | 1dc4bbf | 2016-11-17 08:32:33 -0200 | [diff] [blame] | 318 | Highlights and cross-references |
| 319 | ------------------------------- |
| 320 | |
| 321 | The following special patterns are recognized in the kernel-doc comment |
| 322 | descriptive text and converted to proper reStructuredText markup and `Sphinx C |
| 323 | Domain`_ references. |
| 324 | |
| 325 | .. attention:: The below are **only** recognized within kernel-doc comments, |
| 326 | **not** within normal reStructuredText documents. |
| 327 | |
| 328 | ``funcname()`` |
| 329 | Function reference. |
| 330 | |
| 331 | ``@parameter`` |
| 332 | Name of a function parameter. (No cross-referencing, just formatting.) |
| 333 | |
| 334 | ``%CONST`` |
| 335 | Name of a constant. (No cross-referencing, just formatting.) |
| 336 | |
Mauro Carvalho Chehab | 5d47c31 | 2017-05-16 08:17:49 -0300 | [diff] [blame] | 337 | ````literal```` |
| 338 | A literal block that should be handled as-is. The output will use a |
| 339 | ``monospaced font``. |
| 340 | |
| 341 | Useful if you need to use special characters that would otherwise have some |
| 342 | meaning either by kernel-doc script of by reStructuredText. |
| 343 | |
| 344 | This is particularly useful if you need to use things like ``%ph`` inside |
| 345 | a function description. |
| 346 | |
Mauro Carvalho Chehab | 1dc4bbf | 2016-11-17 08:32:33 -0200 | [diff] [blame] | 347 | ``$ENVVAR`` |
| 348 | Name of an environment variable. (No cross-referencing, just formatting.) |
| 349 | |
| 350 | ``&struct name`` |
| 351 | Structure reference. |
| 352 | |
| 353 | ``&enum name`` |
| 354 | Enum reference. |
| 355 | |
| 356 | ``&typedef name`` |
| 357 | Typedef reference. |
| 358 | |
| 359 | ``&struct_name->member`` or ``&struct_name.member`` |
| 360 | Structure or union member reference. The cross-reference will be to the struct |
| 361 | or union definition, not the member directly. |
| 362 | |
| 363 | ``&name`` |
| 364 | A generic type reference. Prefer using the full reference described above |
| 365 | instead. This is mostly for legacy comments. |
| 366 | |
| 367 | Cross-referencing from reStructuredText |
| 368 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 369 | |
| 370 | To cross-reference the functions and types defined in the kernel-doc comments |
| 371 | from reStructuredText documents, please use the `Sphinx C Domain`_ |
| 372 | references. For example:: |
| 373 | |
| 374 | See function :c:func:`foo` and struct/union/enum/typedef :c:type:`bar`. |
| 375 | |
| 376 | While the type reference works with just the type name, without the |
| 377 | struct/union/enum/typedef part in front, you may want to use:: |
| 378 | |
| 379 | See :c:type:`struct foo <foo>`. |
| 380 | See :c:type:`union bar <bar>`. |
| 381 | See :c:type:`enum baz <baz>`. |
| 382 | See :c:type:`typedef meh <meh>`. |
| 383 | |
| 384 | This will produce prettier links, and is in line with how kernel-doc does the |
| 385 | cross-references. |
| 386 | |
| 387 | For further details, please refer to the `Sphinx C Domain`_ documentation. |
| 388 | |
Mauro Carvalho Chehab | 1dc4bbf | 2016-11-17 08:32:33 -0200 | [diff] [blame] | 389 | Overview documentation comments |
| 390 | ------------------------------- |
| 391 | |
| 392 | To facilitate having source code and comments close together, you can include |
| 393 | kernel-doc documentation blocks that are free-form comments instead of being |
| 394 | kernel-doc for functions, structures, unions, enums, or typedefs. This could be |
| 395 | used for something like a theory of operation for a driver or library code, for |
| 396 | example. |
| 397 | |
| 398 | This is done by using a ``DOC:`` section keyword with a section title. |
| 399 | |
| 400 | The general format of an overview or high-level documentation comment is:: |
| 401 | |
| 402 | /** |
| 403 | * DOC: Theory of Operation |
| 404 | * |
| 405 | * The whizbang foobar is a dilly of a gizmo. It can do whatever you |
| 406 | * want it to do, at any time. It reads your mind. Here's how it works. |
| 407 | * |
| 408 | * foo bar splat |
| 409 | * |
| 410 | * The only drawback to this gizmo is that is can sometimes damage |
| 411 | * hardware, software, or its subject(s). |
| 412 | */ |
| 413 | |
| 414 | The title following ``DOC:`` acts as a heading within the source file, but also |
| 415 | as an identifier for extracting the documentation comment. Thus, the title must |
| 416 | be unique within the file. |
| 417 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 418 | Including kernel-doc comments |
| 419 | ============================= |
Mauro Carvalho Chehab | 1dc4bbf | 2016-11-17 08:32:33 -0200 | [diff] [blame] | 420 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 421 | The documentation comments may be included in any of the reStructuredText |
| 422 | documents using a dedicated kernel-doc Sphinx directive extension. |
Mauro Carvalho Chehab | 1dc4bbf | 2016-11-17 08:32:33 -0200 | [diff] [blame] | 423 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 424 | The kernel-doc directive is of the format:: |
Mauro Carvalho Chehab | 1dc4bbf | 2016-11-17 08:32:33 -0200 | [diff] [blame] | 425 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 426 | .. kernel-doc:: source |
| 427 | :option: |
Mauro Carvalho Chehab | 1dc4bbf | 2016-11-17 08:32:33 -0200 | [diff] [blame] | 428 | |
Matthew Wilcox | 4634750 | 2018-02-13 13:15:37 -0800 | [diff] [blame] | 429 | The *source* is the path to a source file, relative to the kernel source |
| 430 | tree. The following directive options are supported: |
| 431 | |
| 432 | export: *[source-pattern ...]* |
| 433 | Include documentation for all functions in *source* that have been exported |
| 434 | using ``EXPORT_SYMBOL`` or ``EXPORT_SYMBOL_GPL`` either in *source* or in any |
| 435 | of the files specified by *source-pattern*. |
| 436 | |
| 437 | The *source-pattern* is useful when the kernel-doc comments have been placed |
| 438 | in header files, while ``EXPORT_SYMBOL`` and ``EXPORT_SYMBOL_GPL`` are next to |
| 439 | the function definitions. |
| 440 | |
| 441 | Examples:: |
| 442 | |
| 443 | .. kernel-doc:: lib/bitmap.c |
| 444 | :export: |
| 445 | |
| 446 | .. kernel-doc:: include/net/mac80211.h |
| 447 | :export: net/mac80211/*.c |
| 448 | |
| 449 | internal: *[source-pattern ...]* |
| 450 | Include documentation for all functions and types in *source* that have |
| 451 | **not** been exported using ``EXPORT_SYMBOL`` or ``EXPORT_SYMBOL_GPL`` either |
| 452 | in *source* or in any of the files specified by *source-pattern*. |
| 453 | |
| 454 | Example:: |
| 455 | |
| 456 | .. kernel-doc:: drivers/gpu/drm/i915/intel_audio.c |
| 457 | :internal: |
| 458 | |
| 459 | doc: *title* |
| 460 | Include documentation for the ``DOC:`` paragraph identified by *title* in |
| 461 | *source*. Spaces are allowed in *title*; do not quote the *title*. The *title* |
| 462 | is only used as an identifier for the paragraph, and is not included in the |
| 463 | output. Please make sure to have an appropriate heading in the enclosing |
| 464 | reStructuredText document. |
| 465 | |
| 466 | Example:: |
| 467 | |
| 468 | .. kernel-doc:: drivers/gpu/drm/i915/intel_audio.c |
| 469 | :doc: High Definition Audio over HDMI and Display Port |
| 470 | |
| 471 | functions: *function* *[...]* |
| 472 | Include documentation for each *function* in *source*. |
| 473 | |
| 474 | Example:: |
| 475 | |
| 476 | .. kernel-doc:: lib/bitmap.c |
| 477 | :functions: bitmap_parselist bitmap_parselist_user |
| 478 | |
| 479 | Without options, the kernel-doc directive includes all documentation comments |
| 480 | from the source file. |
| 481 | |
| 482 | The kernel-doc extension is included in the kernel source tree, at |
| 483 | ``Documentation/sphinx/kerneldoc.py``. Internally, it uses the |
| 484 | ``scripts/kernel-doc`` script to extract the documentation comments from the |
| 485 | source. |
| 486 | |
| 487 | .. _kernel_doc: |
Mauro Carvalho Chehab | 93626d7 | 2017-12-18 10:30:07 -0200 | [diff] [blame] | 488 | |
| 489 | How to use kernel-doc to generate man pages |
| 490 | ------------------------------------------- |
| 491 | |
| 492 | If you just want to use kernel-doc to generate man pages you can do this |
Matthew Wilcox | 5b229fb | 2018-02-13 13:15:35 -0800 | [diff] [blame] | 493 | from the kernel git tree:: |
Mauro Carvalho Chehab | 93626d7 | 2017-12-18 10:30:07 -0200 | [diff] [blame] | 494 | |
Matthew Wilcox | 5b229fb | 2018-02-13 13:15:35 -0800 | [diff] [blame] | 495 | $ scripts/kernel-doc -man $(git grep -l '/\*\*' -- :^Documentation :^tools) | scripts/split-man.pl /tmp/man |