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