勇闖新世界︰ 《 Kernel 4.X 》之整裝蓄勢‧設備管理及應用‧一

什麼是『evdev』的呢?為了弄清楚所指,首先引用核心之驅動程式原始碼『evdev.c』︰

Linux/drivers/input/evdev.c

1 /*
2 * Event char devices, giving access to raw input device events.
3 *
4 * Copyright (c) 1999-2002 Vojtech Pavlik
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10
11 #define pr_fmt(fmt) KBUILD_MODNAME “: ” fmt
12
13 #define EVDEV_MINOR_BASE 64
14 #define EVDEV_MINORS 32
15 #define EVDEV_MIN_BUFFER_SIZE 64U
16 #define EVDEV_BUF_PACKETS 8
17
18 #include <linux/poll.h>
19 #include <linux/sched.h>
20 #include <linux/slab.h>
21 #include <linux/vmalloc.h>
22 #include <linux/mm.h>
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/input/mt.h>
26 #include <linux/major.h>
27 #include <linux/device.h>
28 #include <linux/cdev.h>
29 #include “input-compat.h”

………

,當可知道它處理『原始』 raw 的『輸入裝置』之『事件』。維基百科詞條講︰

evdev

evdev is a generic input event interface in the Linux kernel.[1] It generalizes raw input events from device drivers and makes them available through character devices in the /dev/input/ directory.

The user-space library for the Linux kernel component evdev is called libevdev. Libevdev abstracts the evdev ioctls through type-safe interfaces and provides functions to change the appearance of the device. Libevdev shares similarities with the read system call.

It sits below the process that handles input events, in between the kernel and that process.

Linux kernel → libevdev → xf86-input-evdev → X server → X client

For Weston/Wayland, the stack would look like this:

Linux kernel → libevdev → libinput → Weston → Wayland client

evdev is primarily used by display servers like X.org (via xf86-input-evdev driver and libevdev) and Weston.

Linux_API.svg

Evdev and libevdev form a prominent part of the Linux API.

Linux_kernel_and_gaming_input-output_latency.svg

Ergonomy requires the response time to be below a certain threshold.

正是『人機介面』構成的主要裝置。

 

Free_and_open-source-software_display_servers_and_UI_toolkits.svg

udev has been incorporated into systemd

 

曾經裝置管理是個複雜且麻煩又容易錯的事情,就如維基百科 udev 詞條說︰

udev is a device manager for the Linux kernel. As the successor of devfsd and hotplug, udev primarily manages device nodes in the /dev directory. At the same time, udev also handles all user space events raised while hardware devices are added into the system or removed from it, including firmware loading as required by certain devices.

Overview

Unlike traditional Unix systems, where the device nodes in the /dev directory have been a static set of files, the Linux udev device manager dynamically provides only the nodes for the devices actually present on a system. Although devfs used to provide similar functionality, Greg Kroah-Hartman cited a number of reasons[2] for preferring udev’s implementation over devfs’:

  • udev supports persistent device naming, which does not depend on, for example, the order in which the devices are plugged into the system. The default udev setup provides persistent names for storage devices. Any hard disk is recognized by its unique filesystem id, the name of the disk and the physical location on the hardware it is connected to.
  • udev executes entirely in user space, as opposed to devfs’ kernel space. One consequence is that udev moved the naming policy out of the kernel and can run arbitrary programs to compose a name for the device from the device’s properties, before the node is created; there, the whole process is also interruptible and it runs with a lower priority.

The udev, as a whole, is divided into three parts:

  • Library libudev that allows access to device information; it was incorporated into the systemd software bundle.
  • User space daemon udevd that manages the virtual /dev.
  • Administrative command-line utility udevadm for diagnostics.

The system gets calls from the kernel via netlink socket. Earlier versions used hotplug, adding a link to themselves in /etc/hotplug.d/default with this purpose.

 

既然裝置之界面有了『使用者空間』對應的存取端︰

作業系統中,虛擬記憶體通常會被分成使用者空間英語User space,又譯為用戶空間),與核心空間英語Kernel space,又譯為內核空間)這兩個區段。

這是記憶體保護機制中的一環。內核核心擴充(kernel extensions)、以及驅動程式,運行在核心空間上。而其他的應用程式,則運行在使用者空間上。所有運行在使用者空間的應用程式,都被統稱為用戶級(userland)。

 

而且在未來『智慧型 □□』多半有『感測器』,與裝置打交道日子看來長得很哩!何不趁此機會講講『libevdev』和『libudev』的『派生觀 』 的耶!!也算是與『潮流』偕行的乎??