xref: /linux/Documentation/core-api/kernel-api.rst (revision 989fe6771266bdb82a815d78802c5aa7c918fdfd)
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
99Sorting
100-------
101
102.. kernel-doc:: lib/sort.c
103   :export:
104
105.. kernel-doc:: lib/list_sort.c
106   :export:
107
108Text Searching
109--------------
110
111.. kernel-doc:: lib/textsearch.c
112   :doc: ts_intro
113
114.. kernel-doc:: lib/textsearch.c
115   :export:
116
117.. kernel-doc:: include/linux/textsearch.h
118   :functions: textsearch_find textsearch_next \
119               textsearch_get_pattern textsearch_get_pattern_len
120
121CRC and Math Functions in Linux
122===============================
123
124Arithmetic Overflow Checking
125----------------------------
126
127.. kernel-doc:: include/linux/overflow.h
128   :internal:
129
130CRC Functions
131-------------
132
133.. kernel-doc:: lib/crc/crc4.c
134   :export:
135
136.. kernel-doc:: lib/crc/crc7.c
137   :export:
138
139.. kernel-doc:: lib/crc/crc8.c
140   :export:
141
142.. kernel-doc:: lib/crc/crc16.c
143   :export:
144
145.. kernel-doc:: lib/crc/crc-ccitt.c
146   :export:
147
148.. kernel-doc:: lib/crc/crc-itu-t.c
149   :export:
150
151.. kernel-doc:: include/linux/crc32.h
152
153.. kernel-doc:: include/linux/crc64.h
154
155Base 2 log and power Functions
156------------------------------
157
158.. kernel-doc:: include/linux/log2.h
159   :internal:
160
161Integer log and power Functions
162-------------------------------
163
164.. kernel-doc:: include/linux/int_log.h
165
166.. kernel-doc:: lib/math/int_pow.c
167   :export:
168
169.. kernel-doc:: lib/math/int_sqrt.c
170   :export:
171
172Division Functions
173------------------
174
175.. kernel-doc:: include/asm-generic/div64.h
176   :functions: do_div
177
178.. kernel-doc:: include/linux/math64.h
179   :internal:
180
181.. kernel-doc:: lib/math/gcd.c
182   :export:
183
184UUID/GUID
185---------
186
187.. kernel-doc:: lib/uuid.c
188   :export:
189
190Kernel IPC facilities
191=====================
192
193IPC utilities
194-------------
195
196.. kernel-doc:: ipc/util.c
197   :internal:
198
199FIFO Buffer
200===========
201
202kfifo interface
203---------------
204
205.. kernel-doc:: include/linux/kfifo.h
206   :internal:
207
208relay interface support
209=======================
210
211Relay interface support is designed to provide an efficient mechanism
212for tools and facilities to relay large amounts of data from kernel
213space to user space.
214
215relay interface
216---------------
217
218.. kernel-doc:: kernel/relay.c
219   :export:
220
221.. kernel-doc:: kernel/relay.c
222   :internal:
223
224Module Support
225==============
226
227Kernel module auto-loading
228--------------------------
229
230.. kernel-doc:: kernel/module/kmod.c
231   :export:
232
233Module debugging
234----------------
235
236.. kernel-doc:: kernel/module/stats.c
237   :doc: module debugging statistics overview
238
239dup_failed_modules - tracks duplicate failed modules
240****************************************************
241
242.. kernel-doc:: kernel/module/stats.c
243   :doc: dup_failed_modules - tracks duplicate failed modules
244
245module statistics debugfs counters
246**********************************
247
248.. kernel-doc:: kernel/module/stats.c
249   :doc: module statistics debugfs counters
250
251Inter Module support
252--------------------
253
254Refer to the files in kernel/module/ for more information.
255
256Hardware Interfaces
257===================
258
259DMA Channels
260------------
261
262.. kernel-doc:: kernel/dma.c
263   :export:
264
265Resources Management
266--------------------
267
268.. kernel-doc:: kernel/resource.c
269   :internal:
270
271.. kernel-doc:: kernel/resource.c
272   :export:
273
274MTRR Handling
275-------------
276
277.. kernel-doc:: arch/x86/kernel/cpu/mtrr/mtrr.c
278   :export:
279
280Security Framework
281==================
282
283.. kernel-doc:: security/security.c
284   :internal:
285
286.. kernel-doc:: security/inode.c
287   :export:
288
289Audit Interfaces
290================
291
292.. kernel-doc:: kernel/audit.c
293   :export:
294
295.. kernel-doc:: kernel/auditsc.c
296   :internal:
297
298.. kernel-doc:: kernel/auditfilter.c
299   :internal:
300
301Accounting Framework
302====================
303
304.. kernel-doc:: kernel/acct.c
305   :internal:
306
307Block Devices
308=============
309
310.. kernel-doc:: include/linux/bio.h
311.. kernel-doc:: block/blk-core.c
312   :export:
313
314.. kernel-doc:: block/blk-core.c
315   :internal:
316
317.. kernel-doc:: block/blk-map.c
318   :export:
319
320.. kernel-doc:: block/blk-sysfs.c
321   :internal:
322
323.. kernel-doc:: block/blk-settings.c
324   :export:
325
326.. kernel-doc:: block/blk-flush.c
327   :export:
328
329.. kernel-doc:: block/blk-lib.c
330   :export:
331
332.. kernel-doc:: block/blk-integrity.c
333   :export:
334
335.. kernel-doc:: kernel/trace/blktrace.c
336   :internal:
337
338.. kernel-doc:: block/genhd.c
339   :internal:
340
341.. kernel-doc:: block/genhd.c
342   :export:
343
344.. kernel-doc:: block/bdev.c
345   :export:
346
347Char devices
348============
349
350.. kernel-doc:: fs/char_dev.c
351   :export:
352
353Clock Framework
354===============
355
356The clock framework defines programming interfaces to support software
357management of the system clock tree. This framework is widely used with
358System-On-Chip (SOC) platforms to support power management and various
359devices which may need custom clock rates. Note that these "clocks"
360don't relate to timekeeping or real time clocks (RTCs), each of which
361have separate frameworks. These :c:type:`struct clk <clk>`
362instances may be used to manage for example a 96 MHz signal that is used
363to shift bits into and out of peripherals or busses, or otherwise
364trigger synchronous state machine transitions in system hardware.
365
366Power management is supported by explicit software clock gating: unused
367clocks are disabled, so the system doesn't waste power changing the
368state of transistors that aren't in active use. On some systems this may
369be backed by hardware clock gating, where clocks are gated without being
370disabled in software. Sections of chips that are powered but not clocked
371may be able to retain their last state. This low power state is often
372called a *retention mode*. This mode still incurs leakage currents,
373especially with finer circuit geometries, but for CMOS circuits power is
374mostly used by clocked state changes.
375
376Power-aware drivers only enable their clocks when the device they manage
377is in active use. Also, system sleep states often differ according to
378which clock domains are active: while a "standby" state may allow wakeup
379from several active domains, a "mem" (suspend-to-RAM) state may require
380a more wholesale shutdown of clocks derived from higher speed PLLs and
381oscillators, limiting the number of possible wakeup event sources. A
382driver's suspend method may need to be aware of system-specific clock
383constraints on the target sleep state.
384
385Some platforms support programmable clock generators. These can be used
386by external chips of various kinds, such as other CPUs, multimedia
387codecs, and devices with strict requirements for interface clocking.
388
389.. kernel-doc:: include/linux/clk.h
390   :internal:
391
392Synchronization Primitives
393==========================
394
395Read-Copy Update (RCU)
396----------------------
397
398.. kernel-doc:: include/linux/rcupdate.h
399
400.. kernel-doc:: kernel/rcu/tree.c
401
402.. kernel-doc:: kernel/rcu/tree_exp.h
403
404.. kernel-doc:: kernel/rcu/update.c
405
406.. kernel-doc:: include/linux/srcu.h
407
408.. kernel-doc:: kernel/rcu/srcutree.c
409
410.. kernel-doc:: include/linux/rculist_bl.h
411
412.. kernel-doc:: include/linux/rculist.h
413
414.. kernel-doc:: include/linux/rculist_nulls.h
415
416.. kernel-doc:: include/linux/rcu_sync.h
417
418.. kernel-doc:: kernel/rcu/sync.c
419
420.. kernel-doc:: kernel/rcu/tasks.h
421
422.. kernel-doc:: kernel/rcu/tree_stall.h
423
424.. kernel-doc:: include/linux/rcupdate_trace.h
425
426.. kernel-doc:: include/linux/rcupdate_wait.h
427
428.. kernel-doc:: include/linux/rcuref.h
429
430.. kernel-doc:: include/linux/rcutree.h
431