xref: /linux/Documentation/core-api/kernel-api.rst (revision 573a6d4c7a21e34d7a2174b8d3c7ca67a5e850b6)
1====================
2The Linux Kernel API
3====================
4
5
6Basic C Library Functions
7=========================
8
9When writing drivers, you cannot in general use routines which are from
10the C Library. Some of the functions have been found generally useful
11and they are listed below. The behaviour of these functions may vary
12slightly from those defined by ANSI, and these deviations are noted in
13the text.
14
15String Conversions
16------------------
17
18.. kernel-doc:: lib/vsprintf.c
19   :export:
20
21.. kernel-doc:: include/linux/kstrtox.h
22   :functions: kstrtol kstrtoul
23
24.. kernel-doc:: lib/kstrtox.c
25   :export:
26
27.. kernel-doc:: lib/string_helpers.c
28   :export:
29
30String Manipulation
31-------------------
32
33.. kernel-doc:: include/linux/fortify-string.h
34   :internal:
35
36.. kernel-doc:: lib/string.c
37   :export:
38
39.. kernel-doc:: include/linux/string.h
40   :internal:
41
42.. kernel-doc:: mm/util.c
43   :functions: kstrdup kstrdup_const kstrndup kmemdup kmemdup_nul memdup_user
44               vmemdup_user strndup_user memdup_user_nul
45
46Basic Kernel Library Functions
47==============================
48
49The Linux kernel provides more basic utility functions.
50
51Bit Operations
52--------------
53
54.. kernel-doc:: include/asm-generic/bitops/instrumented-atomic.h
55   :internal:
56
57.. kernel-doc:: include/asm-generic/bitops/instrumented-non-atomic.h
58   :internal:
59
60.. kernel-doc:: include/asm-generic/bitops/instrumented-lock.h
61   :internal:
62
63Bitmap Operations
64-----------------
65
66.. kernel-doc:: lib/bitmap.c
67   :doc: bitmap introduction
68
69.. kernel-doc:: include/linux/bitmap.h
70   :doc: declare bitmap
71
72.. kernel-doc:: include/linux/bitmap.h
73   :doc: bitmap overview
74
75.. kernel-doc:: include/linux/bitmap.h
76   :doc: bitmap bitops
77
78.. kernel-doc:: lib/bitmap.c
79   :export:
80
81.. kernel-doc:: lib/bitmap.c
82   :internal:
83
84.. kernel-doc:: include/linux/bitmap.h
85   :internal:
86
87Command-line Parsing
88--------------------
89
90.. kernel-doc:: lib/cmdline.c
91   :export:
92
93Error Pointers
94--------------
95
96.. kernel-doc:: include/linux/err.h
97   :internal:
98
99Sequence Buffers
100----------------
101
102.. kernel-doc:: include/linux/seq_buf.h
103   :internal:
104
105.. kernel-doc:: lib/seq_buf.c
106   :no-identifiers: seq_buf_can_fit
107
108Sorting
109-------
110
111.. kernel-doc:: lib/sort.c
112   :export:
113
114.. kernel-doc:: lib/list_sort.c
115   :export:
116
117Text Searching
118--------------
119
120.. kernel-doc:: lib/textsearch.c
121   :doc: ts_intro
122
123.. kernel-doc:: lib/textsearch.c
124   :export:
125
126.. kernel-doc:: include/linux/textsearch.h
127   :functions: textsearch_find textsearch_next \
128               textsearch_get_pattern textsearch_get_pattern_len
129
130CRC and Math Functions in Linux
131===============================
132
133Arithmetic Overflow Checking
134----------------------------
135
136.. kernel-doc:: include/linux/overflow.h
137   :internal:
138
139CRC Functions
140-------------
141
142.. kernel-doc:: lib/crc/crc4.c
143   :export:
144
145.. kernel-doc:: lib/crc/crc7.c
146   :export:
147
148.. kernel-doc:: lib/crc/crc8.c
149   :export:
150
151.. kernel-doc:: lib/crc/crc16.c
152   :export:
153
154.. kernel-doc:: lib/crc/crc-ccitt.c
155   :export:
156
157.. kernel-doc:: lib/crc/crc-itu-t.c
158   :export:
159
160.. kernel-doc:: include/linux/crc32.h
161
162.. kernel-doc:: include/linux/crc64.h
163
164Base 2 log and power Functions
165------------------------------
166
167.. kernel-doc:: include/linux/log2.h
168   :internal:
169
170Integer log and power Functions
171-------------------------------
172
173.. kernel-doc:: include/linux/int_log.h
174
175.. kernel-doc:: lib/math/int_pow.c
176   :export:
177
178.. kernel-doc:: lib/math/int_sqrt.c
179   :export:
180
181Division Functions
182------------------
183
184.. kernel-doc:: include/asm-generic/div64.h
185   :functions: do_div
186
187.. kernel-doc:: include/linux/math64.h
188   :internal:
189
190.. kernel-doc:: lib/math/gcd.c
191   :export:
192
193UUID/GUID
194---------
195
196.. kernel-doc:: lib/uuid.c
197   :export:
198
199Kernel IPC facilities
200=====================
201
202IPC utilities
203-------------
204
205.. kernel-doc:: ipc/util.c
206   :internal:
207
208FIFO Buffer
209===========
210
211kfifo interface
212---------------
213
214.. kernel-doc:: include/linux/kfifo.h
215   :internal:
216
217relay interface support
218=======================
219
220Relay interface support is designed to provide an efficient mechanism
221for tools and facilities to relay large amounts of data from kernel
222space to user space.
223
224relay interface
225---------------
226
227.. kernel-doc:: kernel/relay.c
228   :export:
229
230.. kernel-doc:: kernel/relay.c
231   :internal:
232
233Module Support
234==============
235
236Kernel module auto-loading
237--------------------------
238
239.. kernel-doc:: kernel/module/kmod.c
240   :export:
241
242Module debugging
243----------------
244
245.. kernel-doc:: kernel/module/stats.c
246   :doc: module debugging statistics overview
247
248dup_failed_modules - tracks duplicate failed modules
249****************************************************
250
251.. kernel-doc:: kernel/module/stats.c
252   :doc: dup_failed_modules - tracks duplicate failed modules
253
254module statistics debugfs counters
255**********************************
256
257.. kernel-doc:: kernel/module/stats.c
258   :doc: module statistics debugfs counters
259
260Inter Module support
261--------------------
262
263Refer to the files in kernel/module/ for more information.
264
265Hardware Interfaces
266===================
267
268DMA Channels
269------------
270
271.. kernel-doc:: kernel/dma.c
272   :export:
273
274Resources Management
275--------------------
276
277.. kernel-doc:: kernel/resource.c
278   :internal:
279
280.. kernel-doc:: kernel/resource.c
281   :export:
282
283MTRR Handling
284-------------
285
286.. kernel-doc:: arch/x86/kernel/cpu/mtrr/mtrr.c
287   :export:
288
289Security Framework
290==================
291
292.. kernel-doc:: security/security.c
293   :internal:
294
295.. kernel-doc:: security/inode.c
296   :export:
297
298Audit Interfaces
299================
300
301.. kernel-doc:: kernel/audit.c
302   :export:
303
304.. kernel-doc:: kernel/auditsc.c
305   :internal:
306
307.. kernel-doc:: kernel/auditfilter.c
308   :internal:
309
310Accounting Framework
311====================
312
313.. kernel-doc:: kernel/acct.c
314   :internal:
315
316Block Devices
317=============
318
319.. kernel-doc:: include/linux/bvec.h
320.. kernel-doc:: include/linux/bio.h
321.. kernel-doc:: block/blk-core.c
322   :export:
323
324.. kernel-doc:: block/blk-core.c
325   :internal:
326
327.. kernel-doc:: block/blk-map.c
328   :export:
329
330.. kernel-doc:: block/blk-sysfs.c
331   :internal:
332
333.. kernel-doc:: block/blk-settings.c
334   :export:
335
336.. kernel-doc:: block/blk-flush.c
337   :export:
338
339.. kernel-doc:: block/blk-lib.c
340   :export:
341
342.. kernel-doc:: block/blk-integrity.c
343   :export:
344
345.. kernel-doc:: kernel/trace/blktrace.c
346   :internal:
347
348.. kernel-doc:: block/genhd.c
349   :internal:
350
351.. kernel-doc:: block/genhd.c
352   :export:
353
354.. kernel-doc:: block/bdev.c
355   :export:
356
357Char devices
358============
359
360.. kernel-doc:: fs/char_dev.c
361   :export:
362
363Clock Framework
364===============
365
366The clock framework defines programming interfaces to support software
367management of the system clock tree. This framework is widely used with
368System-On-Chip (SOC) platforms to support power management and various
369devices which may need custom clock rates. Note that these "clocks"
370don't relate to timekeeping or real time clocks (RTCs), each of which
371have separate frameworks. These :c:type:`struct clk <clk>`
372instances may be used to manage for example a 96 MHz signal that is used
373to shift bits into and out of peripherals or busses, or otherwise
374trigger synchronous state machine transitions in system hardware.
375
376Power management is supported by explicit software clock gating: unused
377clocks are disabled, so the system doesn't waste power changing the
378state of transistors that aren't in active use. On some systems this may
379be backed by hardware clock gating, where clocks are gated without being
380disabled in software. Sections of chips that are powered but not clocked
381may be able to retain their last state. This low power state is often
382called a *retention mode*. This mode still incurs leakage currents,
383especially with finer circuit geometries, but for CMOS circuits power is
384mostly used by clocked state changes.
385
386Power-aware drivers only enable their clocks when the device they manage
387is in active use. Also, system sleep states often differ according to
388which clock domains are active: while a "standby" state may allow wakeup
389from several active domains, a "mem" (suspend-to-RAM) state may require
390a more wholesale shutdown of clocks derived from higher speed PLLs and
391oscillators, limiting the number of possible wakeup event sources. A
392driver's suspend method may need to be aware of system-specific clock
393constraints on the target sleep state.
394
395Some platforms support programmable clock generators. These can be used
396by external chips of various kinds, such as other CPUs, multimedia
397codecs, and devices with strict requirements for interface clocking.
398
399.. kernel-doc:: include/linux/clk.h
400   :internal:
401
402Synchronization Primitives
403==========================
404
405Read-Copy Update (RCU)
406----------------------
407
408.. kernel-doc:: include/linux/rcupdate.h
409
410.. kernel-doc:: kernel/rcu/tree.c
411
412.. kernel-doc:: kernel/rcu/tree_exp.h
413
414.. kernel-doc:: kernel/rcu/update.c
415
416.. kernel-doc:: include/linux/srcu.h
417
418.. kernel-doc:: kernel/rcu/srcutree.c
419
420.. kernel-doc:: include/linux/rculist_bl.h
421
422.. kernel-doc:: include/linux/rculist.h
423
424.. kernel-doc:: include/linux/rculist_nulls.h
425
426.. kernel-doc:: include/linux/rcu_sync.h
427
428.. kernel-doc:: kernel/rcu/sync.c
429
430.. kernel-doc:: kernel/rcu/tasks.h
431
432.. kernel-doc:: kernel/rcu/tree_stall.h
433
434.. kernel-doc:: include/linux/rcupdate_trace.h
435
436.. kernel-doc:: include/linux/rcupdate_wait.h
437
438.. kernel-doc:: include/linux/rcuref.h
439
440.. kernel-doc:: include/linux/rcutree.h
441