Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 
0003 ===============
0004 Console Drivers
0005 ===============
0006 
0007 The Linux kernel has 2 general types of console drivers.  The first type is
0008 assigned by the kernel to all the virtual consoles during the boot process.
0009 This type will be called 'system driver', and only one system driver is allowed
0010 to exist. The system driver is persistent and it can never be unloaded, though
0011 it may become inactive.
0012 
0013 The second type has to be explicitly loaded and unloaded. This will be called
0014 'modular driver' by this document. Multiple modular drivers can coexist at
0015 any time with each driver sharing the console with other drivers including
0016 the system driver. However, modular drivers cannot take over the console
0017 that is currently occupied by another modular driver. (Exception: Drivers that
0018 call do_take_over_console() will succeed in the takeover regardless of the type
0019 of driver occupying the consoles.) They can only take over the console that is
0020 occupied by the system driver. In the same token, if the modular driver is
0021 released by the console, the system driver will take over.
0022 
0023 Modular drivers, from the programmer's point of view, have to call::
0024 
0025          do_take_over_console() - load and bind driver to console layer
0026          give_up_console() - unload driver; it will only work if driver
0027                              is fully unbound
0028 
0029 In newer kernels, the following are also available::
0030 
0031          do_register_con_driver()
0032          do_unregister_con_driver()
0033 
0034 If sysfs is enabled, the contents of /sys/class/vtconsole can be
0035 examined. This shows the console backends currently registered by the
0036 system which are named vtcon<n> where <n> is an integer from 0 to 15.
0037 Thus::
0038 
0039        ls /sys/class/vtconsole
0040        .  ..  vtcon0  vtcon1
0041 
0042 Each directory in /sys/class/vtconsole has 3 files::
0043 
0044      ls /sys/class/vtconsole/vtcon0
0045      .  ..  bind  name  uevent
0046 
0047 What do these files signify?
0048 
0049      1. bind - this is a read/write file. It shows the status of the driver if
0050         read, or acts to bind or unbind the driver to the virtual consoles
0051         when written to. The possible values are:
0052 
0053         0
0054           - means the driver is not bound and if echo'ed, commands the driver
0055             to unbind
0056 
0057         1
0058           - means the driver is bound and if echo'ed, commands the driver to
0059             bind
0060 
0061      2. name - read-only file. Shows the name of the driver in this format::
0062 
0063           cat /sys/class/vtconsole/vtcon0/name
0064           (S) VGA+
0065 
0066               '(S)' stands for a (S)ystem driver, i.e., it cannot be directly
0067               commanded to bind or unbind
0068 
0069               'VGA+' is the name of the driver
0070 
0071           cat /sys/class/vtconsole/vtcon1/name
0072           (M) frame buffer device
0073 
0074               In this case, '(M)' stands for a (M)odular driver, one that can be
0075               directly commanded to bind or unbind.
0076 
0077      3. uevent - ignore this file
0078 
0079 When unbinding, the modular driver is detached first, and then the system
0080 driver takes over the consoles vacated by the driver. Binding, on the other
0081 hand, will bind the driver to the consoles that are currently occupied by a
0082 system driver.
0083 
0084 NOTE1:
0085   Binding and unbinding must be selected in Kconfig. It's under::
0086 
0087     Device Drivers ->
0088         Character devices ->
0089                 Support for binding and unbinding console drivers
0090 
0091 NOTE2:
0092   If any of the virtual consoles are in KD_GRAPHICS mode, then binding or
0093   unbinding will not succeed. An example of an application that sets the
0094   console to KD_GRAPHICS is X.
0095 
0096 How useful is this feature? This is very useful for console driver
0097 developers. By unbinding the driver from the console layer, one can unload the
0098 driver, make changes, recompile, reload and rebind the driver without any need
0099 for rebooting the kernel. For regular users who may want to switch from
0100 framebuffer console to VGA console and vice versa, this feature also makes
0101 this possible. (NOTE NOTE NOTE: Please read fbcon.txt under Documentation/fb
0102 for more details.)
0103 
0104 Notes for developers
0105 ====================
0106 
0107 do_take_over_console() is now broken up into::
0108 
0109      do_register_con_driver()
0110      do_bind_con_driver() - private function
0111 
0112 give_up_console() is a wrapper to do_unregister_con_driver(), and a driver must
0113 be fully unbound for this call to succeed. con_is_bound() will check if the
0114 driver is bound or not.
0115 
0116 Guidelines for console driver writers
0117 =====================================
0118 
0119 In order for binding to and unbinding from the console to properly work,
0120 console drivers must follow these guidelines:
0121 
0122 1. All drivers, except system drivers, must call either do_register_con_driver()
0123    or do_take_over_console(). do_register_con_driver() will just add the driver
0124    to the console's internal list. It won't take over the
0125    console. do_take_over_console(), as it name implies, will also take over (or
0126    bind to) the console.
0127 
0128 2. All resources allocated during con->con_init() must be released in
0129    con->con_deinit().
0130 
0131 3. All resources allocated in con->con_startup() must be released when the
0132    driver, which was previously bound, becomes unbound.  The console layer
0133    does not have a complementary call to con->con_startup() so it's up to the
0134    driver to check when it's legal to release these resources. Calling
0135    con_is_bound() in con->con_deinit() will help.  If the call returned
0136    false(), then it's safe to release the resources.  This balance has to be
0137    ensured because con->con_startup() can be called again when a request to
0138    rebind the driver to the console arrives.
0139 
0140 4. Upon exit of the driver, ensure that the driver is totally unbound. If the
0141    condition is satisfied, then the driver must call do_unregister_con_driver()
0142    or give_up_console().
0143 
0144 5. do_unregister_con_driver() can also be called on conditions which make it
0145    impossible for the driver to service console requests.  This can happen
0146    with the framebuffer console that suddenly lost all of its drivers.
0147 
0148 The current crop of console drivers should still work correctly, but binding
0149 and unbinding them may cause problems. With minimal fixes, these drivers can
0150 be made to work correctly.
0151 
0152 Antonino Daplas <adaplas@pol.net>