1 #ifndef _IPXE_CONSOLE_H
2 #define _IPXE_CONSOLE_H
6 #include <ipxe/tables.h>
12 * Various console devices can be selected via the build options
13 * CONSOLE_FIRMWARE, CONSOLE_SERIAL etc. The console functions
14 * putchar(), getchar() and iskey() delegate to the individual console
19 FILE_LICENCE ( GPL2_OR_LATER );
23 /** A console configuration */
24 struct console_configuration {
39 /** Background picture, if any */
40 struct pixel_buffer *pixbuf;
46 * Defines the functions that implement a particular console type.
47 * Must be made part of the console drivers table by using
50 * @note Consoles that cannot be used before their initialisation
51 * function has completed should set #disabled initially. This allows
52 * other console devices to still be used to print out early debugging
55 struct console_driver {
57 * Console disabled flags
59 * This is the bitwise OR of zero or more console disabled
64 * Write a character to the console
66 * @v character Character to be written
68 void ( * putchar ) ( int character );
70 * Read a character from the console
72 * @ret character Character read
74 * If no character is available to be read, this method will
75 * block. The character read should not be echoed back to the
78 int ( * getchar ) ( void );
80 * Check for available input
82 * @ret is_available Input is available
84 * This should return true if a subsequent call to getchar()
87 int ( * iskey ) ( void );
91 * @v config Console configuration, or NULL to reset
92 * @ret rc Return status code
94 int ( * configure ) ( struct console_configuration *config );
96 * Console usage bitmask
98 * This is the bitwise OR of zero or more @c CONSOLE_USAGE_XXX
104 /** Console is disabled for input */
105 #define CONSOLE_DISABLED_INPUT 0x0001
107 /** Console is disabled for output */
108 #define CONSOLE_DISABLED_OUTPUT 0x0002
110 /** Console is disabled for all uses */
111 #define CONSOLE_DISABLED ( CONSOLE_DISABLED_INPUT | CONSOLE_DISABLED_OUTPUT )
113 /** Console driver table */
114 #define CONSOLES __table ( struct console_driver, "consoles" )
117 * Mark a <tt> struct console_driver </tt> as being part of the
118 * console drivers table.
124 * struct console_driver my_console __console_driver = {
125 * .putchar = my_putchar,
126 * .getchar = my_getchar,
133 #define __console_driver __table_entry ( CONSOLES, 01 )
136 * @defgroup consoleusage Console usages
140 /** Standard output */
141 #define CONSOLE_USAGE_STDOUT 0x0001
143 /** Debug messages */
144 #define CONSOLE_USAGE_DEBUG 0x0002
146 /** Text-based user interface */
147 #define CONSOLE_USAGE_TUI 0x0004
150 #define CONSOLE_USAGE_LOG 0x0008
152 /** All console usages */
153 #define CONSOLE_USAGE_ALL ( CONSOLE_USAGE_STDOUT | CONSOLE_USAGE_DEBUG | \
154 CONSOLE_USAGE_TUI | CONSOLE_USAGE_LOG )
159 * Test to see if console has an explicit usage
161 * @v console Console definition (e.g. CONSOLE_PCBIOS)
162 * @ret explicit Console has an explicit usage
164 * This relies upon the trick that the expression ( 2 * N + 1 ) will
165 * be valid even if N is defined to be empty, since it will then
166 * evaluate to give ( 2 * + 1 ) == ( 2 * +1 ) == 2.
168 #define CONSOLE_EXPLICIT( console ) ( ( 2 * console + 1 ) != 2 )
170 /** Default console width */
171 #define CONSOLE_DEFAULT_WIDTH 80
173 /** Default console height */
174 #define CONSOLE_DEFAULT_HEIGHT 25
176 extern int console_usage;
177 extern unsigned int console_width;
178 extern unsigned int console_height;
183 * @v usage New console usage
184 * @ret old_usage Previous console usage
186 static inline __attribute__ (( always_inline )) int
187 console_set_usage ( int usage ) {
188 int old_usage = console_usage;
190 console_usage = usage;
197 * @v width Width, in characters
198 * @v height Height, in characters
200 static inline __attribute__ (( always_inline )) void
201 console_set_size ( unsigned int width, unsigned int height ) {
202 console_width = width;
203 console_height = height;
206 extern int iskey ( void );
207 extern int getkey ( unsigned long timeout );
208 extern int console_configure ( struct console_configuration *config );
214 static inline __attribute__ (( always_inline )) void console_reset ( void ) {
216 console_configure ( NULL );
219 #endif /* _IPXE_CONSOLE_H */