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