blob: 8394ad7747ac6e6015c4c483d11c8d555d9d2fd0 [file] [log] [blame]
Mauro Carvalho Chehabbaa293e2019-06-27 15:39:22 -03001.. SPDX-License-Identifier: GPL-2.0
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -03002
3===============
Antonino A. Daplas79062a02006-06-26 00:27:11 -07004Console Drivers
5===============
6
Randy Dunlap3d83d312018-08-06 16:24:55 -07007The Linux kernel has 2 general types of console drivers. The first type is
Antonino A. Daplas79062a02006-06-26 00:27:11 -07008assigned by the kernel to all the virtual consoles during the boot process.
9This type will be called 'system driver', and only one system driver is allowed
10to exist. The system driver is persistent and it can never be unloaded, though
11it may become inactive.
12
13The second type has to be explicitly loaded and unloaded. This will be called
14'modular driver' by this document. Multiple modular drivers can coexist at
15any time with each driver sharing the console with other drivers including
16the system driver. However, modular drivers cannot take over the console
17that is currently occupied by another modular driver. (Exception: Drivers that
Wang YanQing6b5f1462013-05-21 23:29:11 +080018call do_take_over_console() will succeed in the takeover regardless of the type
Antonino A. Daplas79062a02006-06-26 00:27:11 -070019of driver occupying the consoles.) They can only take over the console that is
20occupied by the system driver. In the same token, if the modular driver is
21released by the console, the system driver will take over.
22
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030023Modular drivers, from the programmer's point of view, have to call::
Antonino A. Daplas79062a02006-06-26 00:27:11 -070024
Wang YanQing6b5f1462013-05-21 23:29:11 +080025 do_take_over_console() - load and bind driver to console layer
Randy Dunlap3d83d312018-08-06 16:24:55 -070026 give_up_console() - unload driver; it will only work if driver
27 is fully unbound
Antonino A. Daplas79062a02006-06-26 00:27:11 -070028
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030029In newer kernels, the following are also available::
Antonino A. Daplas79062a02006-06-26 00:27:11 -070030
Wang YanQing6b5f1462013-05-21 23:29:11 +080031 do_register_con_driver()
32 do_unregister_con_driver()
Antonino A. Daplas79062a02006-06-26 00:27:11 -070033
Antonino A. Daplas66900752006-06-26 00:27:14 -070034If sysfs is enabled, the contents of /sys/class/vtconsole can be
35examined. This shows the console backends currently registered by the
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030036system which are named vtcon<n> where <n> is an integer from 0 to 15.
37Thus::
Antonino A. Daplas79062a02006-06-26 00:27:11 -070038
Antonino A. Daplas66900752006-06-26 00:27:14 -070039 ls /sys/class/vtconsole
40 . .. vtcon0 vtcon1
Antonino A. Daplas79062a02006-06-26 00:27:11 -070041
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030042Each directory in /sys/class/vtconsole has 3 files::
Antonino A. Daplas79062a02006-06-26 00:27:11 -070043
Antonino A. Daplas66900752006-06-26 00:27:14 -070044 ls /sys/class/vtconsole/vtcon0
45 . .. bind name uevent
Antonino A. Daplas79062a02006-06-26 00:27:11 -070046
Antonino A. Daplas66900752006-06-26 00:27:14 -070047What do these files signify?
Antonino A. Daplas79062a02006-06-26 00:27:11 -070048
Antonino A. Daplas66900752006-06-26 00:27:14 -070049 1. bind - this is a read/write file. It shows the status of the driver if
50 read, or acts to bind or unbind the driver to the virtual consoles
51 when written to. The possible values are:
Antonino A. Daplas79062a02006-06-26 00:27:11 -070052
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030053 0
54 - means the driver is not bound and if echo'ed, commands the driver
Antonino A. Daplas66900752006-06-26 00:27:14 -070055 to unbind
Antonino A. Daplas79062a02006-06-26 00:27:11 -070056
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030057 1
58 - means the driver is bound and if echo'ed, commands the driver to
Antonino A. Daplas66900752006-06-26 00:27:14 -070059 bind
Antonino A. Daplas79062a02006-06-26 00:27:11 -070060
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030061 2. name - read-only file. Shows the name of the driver in this format::
Antonino A. Daplas66900752006-06-26 00:27:14 -070062
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030063 cat /sys/class/vtconsole/vtcon0/name
64 (S) VGA+
Antonino A. Daplas66900752006-06-26 00:27:14 -070065
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030066 '(S)' stands for a (S)ystem driver, i.e., it cannot be directly
67 commanded to bind or unbind
Antonino A. Daplas66900752006-06-26 00:27:14 -070068
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030069 'VGA+' is the name of the driver
Antonino A. Daplas66900752006-06-26 00:27:14 -070070
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030071 cat /sys/class/vtconsole/vtcon1/name
72 (M) frame buffer device
Antonino A. Daplas66900752006-06-26 00:27:14 -070073
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030074 In this case, '(M)' stands for a (M)odular driver, one that can be
75 directly commanded to bind or unbind.
Antonino A. Daplas66900752006-06-26 00:27:14 -070076
77 3. uevent - ignore this file
Antonino A. Daplas79062a02006-06-26 00:27:11 -070078
79When unbinding, the modular driver is detached first, and then the system
80driver takes over the consoles vacated by the driver. Binding, on the other
81hand, will bind the driver to the consoles that are currently occupied by a
82system driver.
83
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030084NOTE1:
85 Binding and unbinding must be selected in Kconfig. It's under::
Antonino A. Daplas66900752006-06-26 00:27:14 -070086
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030087 Device Drivers ->
88 Character devices ->
89 Support for binding and unbinding console drivers
Antonino A. Daplas66900752006-06-26 00:27:14 -070090
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -030091NOTE2:
92 If any of the virtual consoles are in KD_GRAPHICS mode, then binding or
93 unbinding will not succeed. An example of an application that sets the
94 console to KD_GRAPHICS is X.
Antonino A. Daplas66900752006-06-26 00:27:14 -070095
Antonino A. Daplas79062a02006-06-26 00:27:11 -070096How useful is this feature? This is very useful for console driver
97developers. By unbinding the driver from the console layer, one can unload the
98driver, make changes, recompile, reload and rebind the driver without any need
99for rebooting the kernel. For regular users who may want to switch from
100framebuffer console to VGA console and vice versa, this feature also makes
101this possible. (NOTE NOTE NOTE: Please read fbcon.txt under Documentation/fb
Randy Dunlap3d83d312018-08-06 16:24:55 -0700102for more details.)
Antonino A. Daplas79062a02006-06-26 00:27:11 -0700103
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -0300104Notes for developers
105====================
Antonino A. Daplas79062a02006-06-26 00:27:11 -0700106
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -0300107do_take_over_console() is now broken up into::
Antonino A. Daplas79062a02006-06-26 00:27:11 -0700108
Wang YanQing6b5f1462013-05-21 23:29:11 +0800109 do_register_con_driver()
110 do_bind_con_driver() - private function
Antonino A. Daplas79062a02006-06-26 00:27:11 -0700111
Wang YanQing6b5f1462013-05-21 23:29:11 +0800112give_up_console() is a wrapper to do_unregister_con_driver(), and a driver must
Antonino A. Daplas79062a02006-06-26 00:27:11 -0700113be fully unbound for this call to succeed. con_is_bound() will check if the
114driver is bound or not.
115
Mauro Carvalho Chehab8db8ace2019-04-14 08:44:17 -0300116Guidelines for console driver writers
Antonino A. Daplas79062a02006-06-26 00:27:11 -0700117=====================================
118
119In order for binding to and unbinding from the console to properly work,
120console drivers must follow these guidelines:
121
Wang YanQing6b5f1462013-05-21 23:29:11 +08001221. All drivers, except system drivers, must call either do_register_con_driver()
Randy Dunlap3d83d312018-08-06 16:24:55 -0700123 or do_take_over_console(). do_register_con_driver() will just add the driver
124 to the console's internal list. It won't take over the
Wang YanQing6b5f1462013-05-21 23:29:11 +0800125 console. do_take_over_console(), as it name implies, will also take over (or
Antonino A. Daplas79062a02006-06-26 00:27:11 -0700126 bind to) the console.
127
1282. All resources allocated during con->con_init() must be released in
129 con->con_deinit().
130
1313. All resources allocated in con->con_startup() must be released when the
132 driver, which was previously bound, becomes unbound. The console layer
133 does not have a complementary call to con->con_startup() so it's up to the
134 driver to check when it's legal to release these resources. Calling
135 con_is_bound() in con->con_deinit() will help. If the call returned
136 false(), then it's safe to release the resources. This balance has to be
137 ensured because con->con_startup() can be called again when a request to
138 rebind the driver to the console arrives.
139
1404. Upon exit of the driver, ensure that the driver is totally unbound. If the
Wang YanQing6b5f1462013-05-21 23:29:11 +0800141 condition is satisfied, then the driver must call do_unregister_con_driver()
Antonino A. Daplas79062a02006-06-26 00:27:11 -0700142 or give_up_console().
143
Wang YanQing6b5f1462013-05-21 23:29:11 +08001445. do_unregister_con_driver() can also be called on conditions which make it
Antonino A. Daplas79062a02006-06-26 00:27:11 -0700145 impossible for the driver to service console requests. This can happen
146 with the framebuffer console that suddenly lost all of its drivers.
147
148The current crop of console drivers should still work correctly, but binding
149and unbinding them may cause problems. With minimal fixes, these drivers can
150be made to work correctly.
151
Antonino A. Daplas79062a02006-06-26 00:27:11 -0700152Antonino Daplas <adaplas@pol.net>