wiki/2020-08-28-19-26-43.org

32 lines
2.5 KiB
Org Mode
Raw Normal View History

#+TITLE: Linux drivers
#+AUTHOR: "Gabriel Arazas"
#+EMAIL: "foo.dogsquared@gmail.com"
2020-11-14 21:13:01 +00:00
#+DATE: "2020-09-09 05:27:17 +08:00"
#+DATE_MODIFIED: "2020-09-18 03:06:06 +08:00"
#+LANGUAGE: en
#+OPTIONS: toc:t
#+PROPERTY: header-args :exports both
2020-11-14 21:13:01 +00:00
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 [[http://linuxwacom.sourceforge.net/][the Linux Wacom project]] to make Wacom graphics tablet usable in Linux, those sort of stuff.
[[https://www.youtube.com/watch?v=juGNPLdjLH4][Liveoverflow's video summary]]:
- A driver is just a compiled module (e.g., ~driver.o~) that makes use of the code in the Linux header and does the communication from the associated device.
- Each driver may have functions attached to an event (e.g., opening in ~module_open~, closing in ~module_exit~).
- You can insert a driver with the ~insmod~ program and remove it with the ~rmmod~ program.
- Each driver will appear on a special filesystem in ~/dev~ as a special type of file which you can view what type of file it is with ~ls -l~.
- You can print out events (i.e., ~printk~) and view it in the system log (e.g., ~/var/log/syslog~).
- 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 ~module_write~ (or something equivalent) event will run.
- NEEDS INVESTIGATION: Another interesting of note here is how the kernel does not immediately writes the bytes in the device file until closing it.
- [[https://everything-is-sheep.herokuapp.com/posts/on-developing-a-linux-driver=-][An overview from a student without prior experience]]
- [[https://unix.stackexchange.com/questions/507687/graphic-tablet-veikk-pressure-sensitivity-on-linux][Creating a driver for a graphics tablet]] on Unix StackExchange
- [[https://lwn.net/Kernel/LDD3/][The de-facto reference on creating Linux drivers]]
2020-11-14 21:13:01 +00:00
- [[https://www.youtube.com/watch?v=juGNPLdjLH4][How do Linux kernel drivers work?]] from LiveOverflow
- [[https://www.youtube.com/watch?v=RyY01fRyGhM][Writing Linux kernel modules in safe Rust]] from the Linux Foundation
- [[https://lwn.net/Kernel/LDD3/][Linux device drivers, 3rd edition]], the de-facto reference for kernel modules