mirror of
https://github.com/foo-dogsquared/wiki.git
synced 2025-01-31 04:58:21 +00:00
28 lines
13 KiB
HTML
28 lines
13 KiB
HTML
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>Linux drivers</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
|
|
MathJax = {
|
|
tex: {
|
|
inlineMath: [ ['$','$'], ['\(','\)'] ],
|
|
displayMath: [ ['$$','$$'], ['[',']'] ]
|
|
},
|
|
options = {
|
|
processHtmlClass = "math"
|
|
}
|
|
}
|
|
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>Linux drivers</h1><section class="post-metadata"><span>Date: <!-- -->2020-09-09 05:27:17 +08:00</span><span>Date modified: <!-- -->2021-05-04 20:51:26 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"></ol></nav><p>Linux drivers (also called as kernel modules) are software executed in the kernel.
|
|
Usually, they are used to communicate between hardware and create an inteface with it, making them usable.
|
|
Examples include <a href="http://linuxwacom.sourceforge.net/">the Linux Wacom project</a> to make Wacom graphics tablet usable in Linux, those sort of stuff.
|
|
</p><p><a href="https://www.youtube.com/watch?v=juGNPLdjLH4">Liveoverflow's video summary</a>:
|
|
</p><ul><li><p>A driver is just a compiled module (e.g., <code class="inline-code">driver.o</code>) that makes use of the code in the Linux header and does the communication from the associated device.
|
|
</p></li><li><p>Each driver may have functions attached to an event (e.g., opening in <code class="inline-code">module_open</code>, closing in <code class="inline-code">module_exit</code>).
|
|
</p></li><li><p>You can insert a driver with the <code class="inline-code">insmod</code> program and remove it with the <code class="inline-code">rmmod</code> program.
|
|
</p></li><li><p>Each driver will appear on a special filesystem in <code class="inline-code">/dev</code> as a special type of file which you can view what type of file it is with <code class="inline-code">ls -l</code>.
|
|
</p></li><li><p>You can print out events (i.e., <code class="inline-code">printk</code>) and view it in the system log (e.g., <code class="inline-code">/var/log/syslog</code>).
|
|
</p></li><li><p>Essentially, a driver is basically a handler that does its magic whenever an associated system call (syscall) has been invoked by the kernel.
|
|
The kernel provides an abstraction for the events associated with the syscall.
|
|
For example, whenever the kernel invokes a syscall for writing in the device file, the associated code defined in <code class="inline-code">module_write</code> (or something equivalent) event will run.
|
|
</p></li><li><p>NEEDS INVESTIGATION: Another interesting of note here is how the kernel does not immediately writes the bytes in the device file until closing it.
|
|
</p></li><li><p><a href="https://everything-is-sheep.herokuapp.com/posts/on-developing-a-linux-driver=-">An overview from a student without prior experience</a></p></li><li><p><a href="https://unix.stackexchange.com/questions/507687/graphic-tablet-veikk-pressure-sensitivity-on-linux">Creating a driver for a graphics tablet</a> on Unix StackExchange
|
|
</p></li><li><p><a href="https://lwn.net/Kernel/LDD3/">The de-facto reference on creating Linux drivers</a></p></li><li><p><a href="https://www.youtube.com/watch?v=juGNPLdjLH4">How do Linux kernel drivers work?</a> from LiveOverflow
|
|
</p></li><li><p><a href="https://www.youtube.com/watch?v=RyY01fRyGhM">Writing Linux kernel modules in safe Rust</a> from the Linux Foundation
|
|
</p></li><li><p><a href="https://lwn.net/Kernel/LDD3/">Linux device drivers, 3rd edition</a>, the de-facto reference for kernel modules
|
|
</p></li></ul><section><h2>Backlinks</h2><ul><li><a href="/wiki/linux.network-configuration">Network configuration in Linux</a></li></ul></section></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"metadata":{"date":"\"2020-09-09 05:27:17 +08:00\"","date_modified":"\"2021-05-04 20:51:26 +08:00\"","language":"en","source":""},"title":"Linux drivers","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Linux drivers (also called as kernel modules) are software executed in the kernel.\nUsually, they are used to communicate between hardware and create an inteface with it, making them usable.\nExamples include "},{"type":"element","tagName":"a","properties":{"href":"http://linuxwacom.sourceforge.net/"},"children":[{"type":"text","value":"the Linux Wacom project"}]},{"type":"text","value":" to make Wacom graphics tablet usable in Linux, those sort of stuff.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.youtube.com/watch?v=juGNPLdjLH4"},"children":[{"type":"text","value":"Liveoverflow's video summary"}]},{"type":"text","value":":\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"A driver is just a compiled module (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"driver.o"}]},{"type":"text","value":") that makes use of the code in the Linux header and does the communication from the associated device.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Each driver may have functions attached to an event (e.g., opening in "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"module_open"}]},{"type":"text","value":", closing in "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"module_exit"}]},{"type":"text","value":").\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can insert a driver with the "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"insmod"}]},{"type":"text","value":" program and remove it with the "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"rmmod"}]},{"type":"text","value":" program.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Each driver will appear on a special filesystem in "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"/dev"}]},{"type":"text","value":" as a special type of file which you can view what type of file it is with "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"ls -l"}]},{"type":"text","value":".\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can print out events (i.e., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"printk"}]},{"type":"text","value":") and view it in the system log (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"/var/log/syslog"}]},{"type":"text","value":").\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Essentially, a driver is basically a handler that does its magic whenever an associated system call (syscall) has been invoked by the kernel.\n The kernel provides an abstraction for the events associated with the syscall.\n For example, whenever the kernel invokes a syscall for writing in the device file, the associated code defined in "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"module_write"}]},{"type":"text","value":" (or something equivalent) event will run.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"NEEDS INVESTIGATION: Another interesting of note here is how the kernel does not immediately writes the bytes in the device file until closing it.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://everything-is-sheep.herokuapp.com/posts/on-developing-a-linux-driver=-"},"children":[{"type":"text","value":"An overview from a student without prior experience"}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://unix.stackexchange.com/questions/507687/graphic-tablet-veikk-pressure-sensitivity-on-linux"},"children":[{"type":"text","value":"Creating a driver for a graphics tablet"}]},{"type":"text","value":" on Unix StackExchange\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://lwn.net/Kernel/LDD3/"},"children":[{"type":"text","value":"The de-facto reference on creating Linux drivers"}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.youtube.com/watch?v=juGNPLdjLH4"},"children":[{"type":"text","value":"How do Linux kernel drivers work?"}]},{"type":"text","value":" from LiveOverflow\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.youtube.com/watch?v=RyY01fRyGhM"},"children":[{"type":"text","value":"Writing Linux kernel modules in safe Rust"}]},{"type":"text","value":" from the Linux Foundation\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://lwn.net/Kernel/LDD3/"},"children":[{"type":"text","value":"Linux device drivers, 3rd edition"}]},{"type":"text","value":", the de-facto reference for kernel modules\n"}]}]}]}]},"backlinks":[{"path":"/linux.network-configuration","title":"Network configuration in Linux"}]},"__N_SSG":true},"page":"/[[...slug]]","query":{"slug":["linux.drivers"]},"buildId":"Ie9t5zutrXP6Of75Cb5xF","assetPrefix":"/wiki","nextExport":false,"isFallback":false,"gsp":true}</script><script nomodule="" src="/wiki/_next/static/chunks/polyfills-99d808df29361cf7ffb1.js"></script><script src="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" async=""></script><script src="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" async=""></script><script src="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" async=""></script><script src="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" async=""></script><script src="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" async=""></script><script src="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" async=""></script><script src="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_buildManifest.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_ssgManifest.js" async=""></script></body></html> |