You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

console.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #ifndef _IPXE_CONSOLE_H
  2. #define _IPXE_CONSOLE_H
  3. #include <stddef.h>
  4. #include <stdio.h>
  5. #include <ipxe/tables.h>
  6. /** @file
  7. *
  8. * User interaction.
  9. *
  10. * Various console devices can be selected via the build options
  11. * CONSOLE_FIRMWARE, CONSOLE_SERIAL etc. The console functions
  12. * putchar(), getchar() and iskey() delegate to the individual console
  13. * drivers.
  14. *
  15. */
  16. FILE_LICENCE ( GPL2_OR_LATER );
  17. struct pixel_buffer;
  18. /** A console configuration */
  19. struct console_configuration {
  20. /** Width */
  21. unsigned int width;
  22. /** Height */
  23. unsigned int height;
  24. /** Colour depth */
  25. unsigned int bpp;
  26. /** Background picture, if any */
  27. struct pixel_buffer *pixbuf;
  28. };
  29. /**
  30. * A console driver
  31. *
  32. * Defines the functions that implement a particular console type.
  33. * Must be made part of the console drivers table by using
  34. * #__console_driver.
  35. *
  36. * @note Consoles that cannot be used before their initialisation
  37. * function has completed should set #disabled initially. This allows
  38. * other console devices to still be used to print out early debugging
  39. * messages.
  40. */
  41. struct console_driver {
  42. /**
  43. * Console disabled flags
  44. *
  45. * This is the bitwise OR of zero or more console disabled
  46. * flags.
  47. */
  48. int disabled;
  49. /**
  50. * Write a character to the console
  51. *
  52. * @v character Character to be written
  53. */
  54. void ( * putchar ) ( int character );
  55. /**
  56. * Read a character from the console
  57. *
  58. * @ret character Character read
  59. *
  60. * If no character is available to be read, this method will
  61. * block. The character read should not be echoed back to the
  62. * console.
  63. */
  64. int ( * getchar ) ( void );
  65. /**
  66. * Check for available input
  67. *
  68. * @ret is_available Input is available
  69. *
  70. * This should return true if a subsequent call to getchar()
  71. * will not block.
  72. */
  73. int ( * iskey ) ( void );
  74. /**
  75. * Configure console
  76. *
  77. * @v config Console configuration, or NULL to reset
  78. * @ret rc Return status code
  79. */
  80. int ( * configure ) ( struct console_configuration *config );
  81. /**
  82. * Console usage bitmask
  83. *
  84. * This is the bitwise OR of zero or more @c CONSOLE_USAGE_XXX
  85. * values.
  86. */
  87. int usage;
  88. };
  89. /** Console is disabled for input */
  90. #define CONSOLE_DISABLED_INPUT 0x0001
  91. /** Console is disabled for output */
  92. #define CONSOLE_DISABLED_OUTPUT 0x0002
  93. /** Console is disabled for all uses */
  94. #define CONSOLE_DISABLED ( CONSOLE_DISABLED_INPUT | CONSOLE_DISABLED_OUTPUT )
  95. /** Console driver table */
  96. #define CONSOLES __table ( struct console_driver, "consoles" )
  97. /**
  98. * Mark a <tt> struct console_driver </tt> as being part of the
  99. * console drivers table.
  100. *
  101. * Use as e.g.
  102. *
  103. * @code
  104. *
  105. * struct console_driver my_console __console_driver = {
  106. * .putchar = my_putchar,
  107. * .getchar = my_getchar,
  108. * .iskey = my_iskey,
  109. * };
  110. *
  111. * @endcode
  112. *
  113. */
  114. #define __console_driver __table_entry ( CONSOLES, 01 )
  115. /**
  116. * @defgroup consoleusage Console usages
  117. * @{
  118. */
  119. /** Standard output */
  120. #define CONSOLE_USAGE_STDOUT 0x0001
  121. /** Debug messages */
  122. #define CONSOLE_USAGE_DEBUG 0x0002
  123. /** Text-based user interface */
  124. #define CONSOLE_USAGE_TUI 0x0004
  125. /** Log messages */
  126. #define CONSOLE_USAGE_LOG 0x0008
  127. /** All console usages */
  128. #define CONSOLE_USAGE_ALL ( CONSOLE_USAGE_STDOUT | CONSOLE_USAGE_DEBUG | \
  129. CONSOLE_USAGE_TUI | CONSOLE_USAGE_LOG )
  130. /** @} */
  131. /**
  132. * Test to see if console has an explicit usage
  133. *
  134. * @v console Console definition (e.g. CONSOLE_PCBIOS)
  135. * @ret explicit Console has an explicit usage
  136. *
  137. * This relies upon the trick that the expression ( 2 * N + 1 ) will
  138. * be valid even if N is defined to be empty, since it will then
  139. * evaluate to give ( 2 * + 1 ) == ( 2 * +1 ) == 2.
  140. */
  141. #define CONSOLE_EXPLICIT( console ) ( ( 2 * console + 1 ) != 2 )
  142. extern int console_usage;
  143. /**
  144. * Set console usage
  145. *
  146. * @v usage New console usage
  147. * @ret old_usage Previous console usage
  148. */
  149. static inline __attribute__ (( always_inline )) int
  150. console_set_usage ( int usage ) {
  151. int old_usage = console_usage;
  152. console_usage = usage;
  153. return old_usage;
  154. }
  155. extern int iskey ( void );
  156. extern int getkey ( unsigned long timeout );
  157. extern int console_configure ( struct console_configuration *config );
  158. /**
  159. * Reset console
  160. *
  161. */
  162. static inline __attribute__ (( always_inline )) void console_reset ( void ) {
  163. console_configure ( NULL );
  164. }
  165. #endif /* _IPXE_CONSOLE_H */