console.rst 5.8 KB

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