The Linux Kernel/Human interfaces

Welcome to the first article of the book. The article is named after and Linux facility  (HID). HID facility in Linux supports keyboard, mouse and other. Console, multimedia (or just media), sound (audio), video, graphics also are in the focus of this article. Additionally, this chapter covers security and debugging topics as they are closely linked to user and human interactions.

Text interfaces
In the world of Linux, a text s and s are essential components of the operating system that allow users to interact with applications trough kernel. A text terminal is a device that provides a text-based interface for communicating with the kernel, while the console is the physical device that houses the terminal and displays the output of the kernel.

The Linux kernel includes a built-in console driver that provides a basic interface for communicating with the console and controlling the terminal. The console driver also supports various input and output devices, such as keyboards and displays, to enable users to interact with the system through a terminal.

The use of text and s in Linux can be traced back to the early days of computing, when  were not yet widely available. Despite the widespread adoption of graphical user interfaces, and consoles remain popular among Linux users and developers for their simplicity, efficiency, and flexibility. Overall, the text terminal and console play a crucial role in the Linux kernel, providing users with a powerful interface for managing and interacting with the operating system.

Char devices
– "character device" is a type of device driver that provides an implementation for character in the /dev directory. The word "device" here means abstract interface, to a usually peripheral physical device. A character device is a type of device that can be accessed as a stream of bytes, rather than as a block of data like a block device. Cdev drivers are commonly used for devices that provide a of data, such as keyboards, mouses, terminals, serial ports, and printers. They are also used for devices that provide access to memory-mapped I/O regions, such as frame buffers and network devices. A cdev driver typically consists of a set of functions that implement the low-level I/O operations for the device, such as open, read and write. These functions are called by the kernel when a user space program accesses the character device file. To create a cdev driver, a kernel developer must first initialize a cdev structure using or. The cdev structure contains information about the device, such as its major and minor numbers and the set of I/O functions that the driver implements. Once the cdev structure has been initialized, it can be registered with the kernel using the function. This function creates the character device file in the /dev directory and associates it with the cdev driver.

You can find a list of registered char devices on the beginning the listing of /proc/devices. Input devices keyboard and mouse are examples of char devices.

Tip: Browse the cross-referencing site to explore nearby API and use cases

💾 ''Historical: It is one of the most simple, fundamental and oldest concepts derived from UNIX. ''

⚲ API
 * - device id consists of and  numbers
 * - core char device struct
 * or
 * - helper function, uses
 * - common key function to add a char device to the system.
 * - obviously registers char device by major number, name and file operations
 * - static definitions of many major numbers, including obsolete.
 * - static definitions of many major numbers, including obsolete.
 * - static definitions of many major numbers, including obsolete.
 * - static definitions of many major numbers, including obsolete.
 * - static definitions of many major numbers, including obsolete.

⚙️ Internals

📖 References
 * Character device drivers, linux-kernel-labs
 * Character device files, on opensourceforu
 * Character device files, on opensourceforu

💾 Historical
 * LDD3:Char Drivers
 * LDD3:Advanced Char Driver Operations
 * LDD1:#3
 * LDD1:#5

Text terminals and console
🗝️ Acronyms
 * - 💾 historically TeleTYpewriter, means just terminal
 * - pseudoterminal
 * pts - pseudoterminal slave
 * ptmx - pseudoterminal master

⚲ API
 * To find out current terminal:
 * readlink /proc/self/fd/0
 * -m
 * obviously registers
 * 👁 example
 * obviously registers
 * 👁 example

⚙️ Internals

📖 References
 * – controlling terminal
 * and pts – pseudoterminal master and slave
 * – pseudoterminal interfaces

💾 Historical
 * LDD3:TTY Drivers

Security
The goal of security is to restrict access through interfaces. From access control and authentication mechanisms to secure boot and memory protection, the Linux kernel employs a variety of techniques to safeguard the system and its users. Basic Linux security is quite simple. It consists of tree ownership classes and tree access modes. One of the most frequently executed functions is. It rejects access of unauthorized users to open a file.

See article ../Security/ for new features.

Authorization
is the function of specifying rights/s to system resources. The main goal of authorization is prevention of under any circumstances.

🔧 TODO. Keywords: permission, capabilities, ownership,.

⚲ API



Basic classic UNIX authorization is based on ownership and tree access modes: reading, writing and execution.

Ownership is encoded by owning user id and owning group id.

- just typedef used for encoding access mode. - minimal "read only by user/owner" access mode. - full access mode. Please read the source for details for other modes.

Binary of access modes:


 * ↪ changes ownership for file or directory
 * ↪ changes access mode for file or directory
 * , ↪  checks access rights

Common authorization errors
 * – "Operation not permitted"
 * – "Permission denied"

🚀 Advanced features
 * and capget – set/get capabilities of thread(s)
 * – run a program with different privilege settings
 * and capget – set/get capabilities of thread(s)
 * – run a program with different privilege settings
 * – run a program with different privilege settings

⚙️ Internals
 * rejects unauthorized file opening
 * checks for access rights to a given inode

📖 References

Credentials
🔧 TODO. Keywords:, user IDs, group IDs, Process group ID, session ID.

⚲ API
 * struct - the security context of a task
 * struct - the security context of a task
 * struct - the security context of a task
 * struct - the security context of a task


 * , - shell utilities
 * is used by utility
 * Real, effective, and saved user/group IDs:
 * , getresgid
 * , setregid
 * - set user identity used for filesystem checks
 * - sets file mode creation mask
 * - set user identity used for filesystem checks
 * - sets file mode creation mask

⚙️ Internals
 * etc
 * etc
 * etc

📖 References
 * https://www.geeksforgeeks.org/real-effective-and-saved-userid-in-linux/
 * https://www.geeksforgeeks.org/real-effective-and-saved-userid-in-linux/
 * https://www.geeksforgeeks.org/real-effective-and-saved-userid-in-linux/

Cryptography
🔧 TODO

🗝️ Acronyms
 * AES -

⚲ API
 * - Scatterlist Cryptographic API.
 * - Scatterlist Cryptographic API.

⚙️ Internals
 * - per-file encryption
 * eCrypt FS - Encrypted filesystem that operates on the VFS layer.
 * - per-file encryption
 * eCrypt FS - Encrypted filesystem that operates on the VFS layer.
 * - per-file encryption
 * eCrypt FS - Encrypted filesystem that operates on the VFS layer.

📖 References
 * devicetree/bindings/crypto
 * devicetree/bindings/crypto
 * devicetree/bindings/crypto

Audit


📖 References
 * https://capsule8.com/blog/auditd-what-is-the-linux-auditing-system/
 * https://wiki.archlinux.org/title/Audit_framework

See also eBPF and BPF

Appendix for Security:

🔧 TODO

📖 References
 * Perf events and tool security
 * http://kernsec.org/wiki/index.php/Main_Page
 * http://selinuxproject.org/
 * http://kernsec.org/wiki/index.php/Main_Page
 * http://selinuxproject.org/
 * http://kernsec.org/wiki/index.php/Main_Page
 * http://selinuxproject.org/
 * http://kernsec.org/wiki/index.php/Main_Page
 * http://selinuxproject.org/
 * http://kernsec.org/wiki/index.php/Main_Page
 * http://selinuxproject.org/
 * http://selinuxproject.org/

Debugging
See Debugging Linux kernel

Graphics
Old graphics (not to be confused with v4l):

⚲ API

⚙️ Internals

(DRM)
DRM is responsible for interfacing with GPUs of modern video cards. DRM exposes an API that user-space programs can use to send commands and data to the GPU and perform operations such as configuring the mode setting of the display. User-space programs can use the DRM API to command the GPU to do hardware-accelerated 3D rendering and video decoding, as well as computing.

⚲ API
 * /sys/class/drm/

⚙️ Internals
 * – Graphics Execution Manager Driver Interfaces
 * registers
 * registers

(ALSA)
ALSA is a software framework and part of the Linux kernel that provides an API for sound card device drivers. Some of the goals of the ALSA project at its inception were automatic configuration of sound-card hardware and graceful handling of multiple sound devices in a system.

The sound servers PulseAudio, JACK (low-latency professional-grade audio editing and mixing) and PipeWire, the higher-level abstraction APIs OpenAL, SDL audio, etc. work on top of ALSA and implemented sound card device drivers. On Linux systems, ALSA succeeded the older (OSS).

⚲ API
 * /proc/asound/cards, /sys/class/sound/
 * - central struct
 * creates an ALSA device component
 * creates an ALSA device component
 * creates an ALSA device component
 * creates an ALSA device component

⚙️ Internals
 * See ASoC
 * See ASoC
 * See ASoC

📖 References

(V4L2)
V4L is a collection of device drivers and an API for supporting realtime video capture on Linux systems. It supports many USB webcams, TV tuners, and related devices, standardizing their output, so programmers can easily add video support to their applications. MythTV, tvtime and Tvheadend are typical applications that use the V4L framework.

⚲ API
 * registers
 * registers
 * 👁 examples

📖 References
 * Media subsystem kernel internal API
 * Media subsystem kernel internal API
 * Media subsystem kernel internal API
 * Media subsystem kernel internal API

HID
Generic human interface devices. Don't confuse with hiddev.

Input devices
Input device files are kind of char devices with id. Classic input devices are keyboard and mouse.

⚲ API
 * In shell: cat /proc/bus/input/devices

👁 Examples

⌨️ Hands onInternals

sudo hexdump /dev/input/mice # dump your mouse movements events from your kernel

⚙️ Internals

📖 References

HID devices
🔧 TODO

⚲ API
 * - device report descriptor. Operations:, . 👁 Example

Camera
🔧 TODO

⚲ API

📖 References

HI device drivers
This section is about low level drivers to human interface peripheral devices.

⚲ HID API
 * registers
 * registers

⚙️ Internals
 * - 👁 example of user mode HID driver
 * : keyboard & mouse, misc, serio, tablet, touchscreen, gameport, joystick
 * ⌨️ Hands on
 * echo "module atkbd +pfl" | sudo tee /sys/kernel/debug/dynamic_debug/control
 * - 👁 example of user mode HID driver
 * : keyboard & mouse, misc, serio, tablet, touchscreen, gameport, joystick
 * ⌨️ Hands on
 * echo "module atkbd +pfl" | sudo tee /sys/kernel/debug/dynamic_debug/control
 * echo "module atkbd +pfl" | sudo tee /sys/kernel/debug/dynamic_debug/control

USB HID

⚲ HID API

⚙️ Internals

📖 References

Graphics
🔧 TODO

🗝️ Acronyms
 * FB -
 * GPU -
 * TFT (LCD) - used for 🤖 embedded devices
 * MIPI - 📱
 * DBI - Display Bus Interface
 * DSI -
 * DCS - The Display Command Set

⚲ API
 * cat /proc/fb
 * ls -l /sys/class/graphics

⚙️ Internals

👁 Examples

📖 References
 * LWN: Graphics
 * LWN: Graphics
 * LWN: Graphics
 * LWN: Graphics

Sound SoC - ASoC
ALSA System on Chip (ASoC) layer for or 🤖 embedded systems. ASoC is designed to handle complex audio processing and routing on low-power and resource-constrained systems, making it an ideal solution for embedded devices such as smartphones, tablets, and other IoT devices.

ASoC provides a comprehensive framework for audio drivers, enabling the creation of modular audio drivers that can be easily integrated with the rest of the kernel. It also supports a wide range of audio interfaces, including I2S, PCM, AC97, and SPDIF, making it highly versatile and capable of handling a variety of audio formats.

One of the key features of ASoC is its ability to handle audio routing and processing using Digital Signal Processing (DSP) techniques.

This enables ASoC to support advanced audio features such as noise reduction, echo cancellation, and dynamic range compression, among others.

Overall, ASoC is a powerful and flexible subsystem that enables Linux to support a wide range of audio hardware in embedded devices. It has become an essential component of many embedded Linux distributions and is widely used in the development of modern audio-enabled devices.

⚲ API
 * is registered by ⇾
 * is registered by ⇾
 * is registered by ⇾





👁 Examples
 * uses
 * uses

⚙️ Internals

📖 References
 * https://www.alsa-project.org/wiki/ASoC
 * https://www.alsa-project.org/wiki/DAPM
 * https://www.alsa-project.org/wiki/ASoC
 * https://www.alsa-project.org/wiki/DAPM

🗝️ Acronyms SAI could be
 * STM Serial Audio Interface:
 * Freescale (FSL) Synchronous Audio Interface:

⚙️ Internals