summaryrefslogtreecommitdiffstats
path: root/src/include/ipxe/console.h
blob: 5188f98558501a2ef8bb5a13f14c6bbbd90e9745 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef _IPXE_CONSOLE_H
#define _IPXE_CONSOLE_H

#include <stdio.h>
#include <ipxe/tables.h>

/** @file
 *
 * User interaction.
 *
 * Various console devices can be selected via the build options
 * CONSOLE_FIRMWARE, CONSOLE_SERIAL etc.  The console functions
 * putchar(), getchar() and iskey() delegate to the individual console
 * drivers.
 *
 */

FILE_LICENCE ( GPL2_OR_LATER );

/**
 * A console driver
 *
 * Defines the functions that implement a particular console type.
 * Must be made part of the console drivers table by using
 * #__console_driver.
 *
 * @note Consoles that cannot be used before their initialisation
 * function has completed should set #disabled=1 initially.  This
 * allows other console devices to still be used to print out early
 * debugging messages.
 *
 */
struct console_driver {
	/** Console is disabled.
	 *
	 * The console's putchar(), getchar() and iskey() methods will
	 * not be called while #disabled==1.  Typically the console's
	 * initialisation functions will set #disabled=0 upon
	 * completion.
	 *
	 */
	int disabled;

	/** Write a character to the console.
	 *
	 * @v character		Character to be written
	 * @ret None		-
	 * @err None		-
	 *
	 */
	void ( *putchar ) ( int character );

	/** Read a character from the console.
	 *
	 * @v None		-
	 * @ret character	Character read
	 * @err None		-
	 *
	 * If no character is available to be read, this method will
	 * block.  The character read should not be echoed back to the
	 * console.
	 *
	 */
	int ( *getchar ) ( void );

	/** Check for available input.
	 *
	 * @v None		-
	 * @ret True		Input is available
	 * @ret False		Input is not available
	 * @err None		-
	 *
	 * This should return True if a subsequent call to getchar()
	 * will not block.
	 *
	 */
	int ( *iskey ) ( void );
};

/** Console driver table */
#define CONSOLES __table ( struct console_driver, "consoles" )

/**
 * Mark a <tt> struct console_driver </tt> as being part of the
 * console drivers table.
 *
 * Use as e.g.
 *
 * @code
 *
 *   struct console_driver my_console __console_driver = {
 *      .putchar = my_putchar,
 *	.getchar = my_getchar,
 *	.iskey = my_iskey,
 *   };
 *
 * @endcode
 *
 */
#define __console_driver __table_entry ( CONSOLES, 01 )

/* Function prototypes */

extern int iskey ( void );
extern int getkey ( unsigned long timeout );

#endif /* _IPXE_CONSOLE_H */