kernel-api.rst 8.9 KB

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