Blame view
Documentation/driver-api/console.rst
5.83 KB
baa293e95 docs: driver-api:... |
1 |
.. SPDX-License-Identifier: GPL-2.0 |
8db8acee4 docs: console.txt... |
2 3 |
=============== |
79062a0d3 [PATCH] VT bindin... |
4 5 |
Console Drivers =============== |
3d83d3188 Documentation: co... |
6 |
The Linux kernel has 2 general types of console drivers. The first type is |
79062a0d3 [PATCH] VT bindin... |
7 8 9 10 11 12 13 14 15 16 |
assigned by the kernel to all the virtual consoles during the boot process. This type will be called 'system driver', and only one system driver is allowed to exist. The system driver is persistent and it can never be unloaded, though it may become inactive. The second type has to be explicitly loaded and unloaded. This will be called 'modular driver' by this document. Multiple modular drivers can coexist at any time with each driver sharing the console with other drivers including the system driver. However, modular drivers cannot take over the console that is currently occupied by another modular driver. (Exception: Drivers that |
6b5f14653 TTY:console: upda... |
17 |
call do_take_over_console() will succeed in the takeover regardless of the type |
79062a0d3 [PATCH] VT bindin... |
18 19 20 |
of driver occupying the consoles.) They can only take over the console that is occupied by the system driver. In the same token, if the modular driver is released by the console, the system driver will take over. |
8db8acee4 docs: console.txt... |
21 |
Modular drivers, from the programmer's point of view, have to call:: |
79062a0d3 [PATCH] VT bindin... |
22 |
|
6b5f14653 TTY:console: upda... |
23 |
do_take_over_console() - load and bind driver to console layer |
3d83d3188 Documentation: co... |
24 25 |
give_up_console() - unload driver; it will only work if driver is fully unbound |
79062a0d3 [PATCH] VT bindin... |
26 |
|
8db8acee4 docs: console.txt... |
27 |
In newer kernels, the following are also available:: |
79062a0d3 [PATCH] VT bindin... |
28 |
|
6b5f14653 TTY:console: upda... |
29 30 |
do_register_con_driver() do_unregister_con_driver() |
79062a0d3 [PATCH] VT bindin... |
31 |
|
6690075d0 [PATCH] VT bindin... |
32 33 |
If sysfs is enabled, the contents of /sys/class/vtconsole can be examined. This shows the console backends currently registered by the |
8db8acee4 docs: console.txt... |
34 35 |
system which are named vtcon<n> where <n> is an integer from 0 to 15. Thus:: |
79062a0d3 [PATCH] VT bindin... |
36 |
|
6690075d0 [PATCH] VT bindin... |
37 38 |
ls /sys/class/vtconsole . .. vtcon0 vtcon1 |
79062a0d3 [PATCH] VT bindin... |
39 |
|
8db8acee4 docs: console.txt... |
40 |
Each directory in /sys/class/vtconsole has 3 files:: |
79062a0d3 [PATCH] VT bindin... |
41 |
|
6690075d0 [PATCH] VT bindin... |
42 43 |
ls /sys/class/vtconsole/vtcon0 . .. bind name uevent |
79062a0d3 [PATCH] VT bindin... |
44 |
|
6690075d0 [PATCH] VT bindin... |
45 |
What do these files signify? |
79062a0d3 [PATCH] VT bindin... |
46 |
|
6690075d0 [PATCH] VT bindin... |
47 48 49 |
1. bind - this is a read/write file. It shows the status of the driver if read, or acts to bind or unbind the driver to the virtual consoles when written to. The possible values are: |
79062a0d3 [PATCH] VT bindin... |
50 |
|
8db8acee4 docs: console.txt... |
51 52 |
0 - means the driver is not bound and if echo'ed, commands the driver |
6690075d0 [PATCH] VT bindin... |
53 |
to unbind |
79062a0d3 [PATCH] VT bindin... |
54 |
|
8db8acee4 docs: console.txt... |
55 56 |
1 - means the driver is bound and if echo'ed, commands the driver to |
6690075d0 [PATCH] VT bindin... |
57 |
bind |
79062a0d3 [PATCH] VT bindin... |
58 |
|
8db8acee4 docs: console.txt... |
59 |
2. name - read-only file. Shows the name of the driver in this format:: |
6690075d0 [PATCH] VT bindin... |
60 |
|
8db8acee4 docs: console.txt... |
61 62 |
cat /sys/class/vtconsole/vtcon0/name (S) VGA+ |
6690075d0 [PATCH] VT bindin... |
63 |
|
8db8acee4 docs: console.txt... |
64 65 |
'(S)' stands for a (S)ystem driver, i.e., it cannot be directly commanded to bind or unbind |
6690075d0 [PATCH] VT bindin... |
66 |
|
8db8acee4 docs: console.txt... |
67 |
'VGA+' is the name of the driver |
6690075d0 [PATCH] VT bindin... |
68 |
|
8db8acee4 docs: console.txt... |
69 70 |
cat /sys/class/vtconsole/vtcon1/name (M) frame buffer device |
6690075d0 [PATCH] VT bindin... |
71 |
|
8db8acee4 docs: console.txt... |
72 73 |
In this case, '(M)' stands for a (M)odular driver, one that can be directly commanded to bind or unbind. |
6690075d0 [PATCH] VT bindin... |
74 75 |
3. uevent - ignore this file |
79062a0d3 [PATCH] VT bindin... |
76 77 78 79 80 |
When unbinding, the modular driver is detached first, and then the system driver takes over the consoles vacated by the driver. Binding, on the other hand, will bind the driver to the consoles that are currently occupied by a system driver. |
8db8acee4 docs: console.txt... |
81 82 |
NOTE1: Binding and unbinding must be selected in Kconfig. It's under:: |
6690075d0 [PATCH] VT bindin... |
83 |
|
8db8acee4 docs: console.txt... |
84 85 86 |
Device Drivers -> Character devices -> Support for binding and unbinding console drivers |
6690075d0 [PATCH] VT bindin... |
87 |
|
8db8acee4 docs: console.txt... |
88 89 90 91 |
NOTE2: If any of the virtual consoles are in KD_GRAPHICS mode, then binding or unbinding will not succeed. An example of an application that sets the console to KD_GRAPHICS is X. |
6690075d0 [PATCH] VT bindin... |
92 |
|
79062a0d3 [PATCH] VT bindin... |
93 94 95 96 97 98 |
How useful is this feature? This is very useful for console driver developers. By unbinding the driver from the console layer, one can unload the driver, make changes, recompile, reload and rebind the driver without any need for rebooting the kernel. For regular users who may want to switch from framebuffer console to VGA console and vice versa, this feature also makes this possible. (NOTE NOTE NOTE: Please read fbcon.txt under Documentation/fb |
3d83d3188 Documentation: co... |
99 |
for more details.) |
79062a0d3 [PATCH] VT bindin... |
100 |
|
8db8acee4 docs: console.txt... |
101 102 |
Notes for developers ==================== |
79062a0d3 [PATCH] VT bindin... |
103 |
|
8db8acee4 docs: console.txt... |
104 |
do_take_over_console() is now broken up into:: |
79062a0d3 [PATCH] VT bindin... |
105 |
|
6b5f14653 TTY:console: upda... |
106 107 |
do_register_con_driver() do_bind_con_driver() - private function |
79062a0d3 [PATCH] VT bindin... |
108 |
|
6b5f14653 TTY:console: upda... |
109 |
give_up_console() is a wrapper to do_unregister_con_driver(), and a driver must |
79062a0d3 [PATCH] VT bindin... |
110 111 |
be fully unbound for this call to succeed. con_is_bound() will check if the driver is bound or not. |
8db8acee4 docs: console.txt... |
112 |
Guidelines for console driver writers |
79062a0d3 [PATCH] VT bindin... |
113 114 115 116 |
===================================== In order for binding to and unbinding from the console to properly work, console drivers must follow these guidelines: |
6b5f14653 TTY:console: upda... |
117 |
1. All drivers, except system drivers, must call either do_register_con_driver() |
3d83d3188 Documentation: co... |
118 119 |
or do_take_over_console(). do_register_con_driver() will just add the driver to the console's internal list. It won't take over the |
6b5f14653 TTY:console: upda... |
120 |
console. do_take_over_console(), as it name implies, will also take over (or |
79062a0d3 [PATCH] VT bindin... |
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
bind to) the console. 2. All resources allocated during con->con_init() must be released in con->con_deinit(). 3. All resources allocated in con->con_startup() must be released when the driver, which was previously bound, becomes unbound. The console layer does not have a complementary call to con->con_startup() so it's up to the driver to check when it's legal to release these resources. Calling con_is_bound() in con->con_deinit() will help. If the call returned false(), then it's safe to release the resources. This balance has to be ensured because con->con_startup() can be called again when a request to rebind the driver to the console arrives. 4. Upon exit of the driver, ensure that the driver is totally unbound. If the |
6b5f14653 TTY:console: upda... |
136 |
condition is satisfied, then the driver must call do_unregister_con_driver() |
79062a0d3 [PATCH] VT bindin... |
137 |
or give_up_console(). |
6b5f14653 TTY:console: upda... |
138 |
5. do_unregister_con_driver() can also be called on conditions which make it |
79062a0d3 [PATCH] VT bindin... |
139 140 141 142 143 144 |
impossible for the driver to service console requests. This can happen with the framebuffer console that suddenly lost all of its drivers. The current crop of console drivers should still work correctly, but binding and unbinding them may cause problems. With minimal fixes, these drivers can be made to work correctly. |
79062a0d3 [PATCH] VT bindin... |
145 |
Antonino Daplas <adaplas@pol.net> |