blob: b182440fcd639be7f0a5f1e15ef1aa2c63a0d445 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass24b852a2015-11-08 23:47:45 -07002/*
3 * (C) Copyright 2000-2009
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Simon Glass24b852a2015-11-08 23:47:45 -07005 */
6
7#ifndef __CONSOLE_H
8#define __CONSOLE_H
9
Simon Glass493a4c82020-07-02 21:12:13 -060010#include <stdbool.h>
Andy Shevchenko41f668b2020-12-21 14:30:00 +020011#include <stdio_dev.h>
Simon Glassbd347152020-07-28 19:41:11 -060012#include <linux/errno.h>
Simon Glass493a4c82020-07-02 21:12:13 -060013
Simon Glass24b852a2015-11-08 23:47:45 -070014extern char console_buffer[];
15
16/* common/console.c */
17int console_init_f(void); /* Before relocation; uses the serial stuff */
18int console_init_r(void); /* After relocation; uses the console stuff */
Andy Shevchenko41f668b2020-12-21 14:30:00 +020019int console_start(int file, struct stdio_dev *sdev); /* Start a console device */
20void console_stop(int file, struct stdio_dev *sdev); /* Stop a console device */
Simon Glass24b852a2015-11-08 23:47:45 -070021int console_assign(int file, const char *devname); /* Assign the console */
22int ctrlc(void);
23int had_ctrlc(void); /* have we had a Control-C since last clear? */
24void clear_ctrlc(void); /* clear the Control-C condition */
25int disable_ctrlc(int); /* 1 to disable, 0 to enable Control-C detect */
26int confirm_yesno(void); /* 1 if input is "y", "Y", "yes" or "YES" */
27
Andy Shevchenkoae697382020-12-21 14:30:04 +020028/**
29 * console_search_dev() - search for stdio device with given flags and name
30 * @flags: device flags as per input/output/system
31 * @name: device name
32 *
33 * Iterates over registered STDIO devices and match them with given @flags
34 * and @name.
35 *
36 * @return pointer to the &struct stdio_dev if found, or NULL otherwise
37 */
Andy Shevchenko32324872020-12-21 14:30:03 +020038struct stdio_dev *console_search_dev(int flags, const char *name);
Andy Shevchenkoe645b9b2020-12-21 14:30:02 +020039
Simon Glassbd347152020-07-28 19:41:11 -060040#ifdef CONFIG_CONSOLE_RECORD
Simon Glass9854a872015-11-08 23:47:48 -070041/**
42 * console_record_init() - set up the console recording buffers
43 *
44 * This should be called as soon as malloc() is available so that the maximum
45 * amount of console output can be recorded.
Simon Glassbd347152020-07-28 19:41:11 -060046 *
47 * @return 0 if OK, -ENOMEM if out of memory
Simon Glass9854a872015-11-08 23:47:48 -070048 */
49int console_record_init(void);
50
51/**
52 * console_record_reset() - reset the console recording buffers
53 *
54 * Removes any data in the buffers
55 */
56void console_record_reset(void);
57
58/**
59 * console_record_reset_enable() - reset and enable the console buffers
60 *
61 * This should be called to enable the console buffer.
Simon Glassbd347152020-07-28 19:41:11 -060062 *
63 * @return 0 (always)
Simon Glass9854a872015-11-08 23:47:48 -070064 */
Simon Glassbd347152020-07-28 19:41:11 -060065int console_record_reset_enable(void);
Simon Glass9854a872015-11-08 23:47:48 -070066
Simon Glassb0895382017-06-15 21:37:50 -060067/**
Simon Glassb6123122020-01-27 08:49:54 -070068 * console_record_readline() - Read a line from the console output
69 *
70 * This reads the next available line from the console output previously
71 * recorded.
72 *
73 * @str: Place to put string
74 * @maxlen: Maximum length of @str including nul terminator
Simon Glassc1a2bb42021-05-08 06:59:56 -060075 * @return length of string returned, or -ENOSPC if the console buffer was
76 * overflowed by the output
Simon Glassb6123122020-01-27 08:49:54 -070077 */
78int console_record_readline(char *str, int maxlen);
79
80/**
81 * console_record_avail() - Get the number of available bytes in console output
82 *
83 * @return available bytes (0 if empty)
84 */
85int console_record_avail(void);
Steffen Jaeckel25c8b9f2021-07-08 15:57:40 +020086
87/**
88 * console_in_puts() - Write a string to the console input buffer
89 *
90 * This writes the given string to the console_in buffer which will then be
91 * returned if a function calls e.g. `getc()`
92 *
93 * @str: the string to write
94 * @return the number of bytes added
95 */
96int console_in_puts(const char *str);
Simon Glassbd347152020-07-28 19:41:11 -060097#else
98static inline int console_record_init(void)
99{
100 /* Always succeed, since it is not enabled */
101
102 return 0;
103}
104
105static inline void console_record_reset(void)
106{
107 /* Nothing to do here */
108}
109
110static inline int console_record_reset_enable(void)
111{
112 /* Cannot enable it as it is not supported */
113 return -ENOSYS;
114}
115
116static inline int console_record_readline(char *str, int maxlen)
117{
118 /* Nothing to read */
119 return 0;
120}
121
122static inline int console_record_avail(void)
123{
124 /* There is never anything available */
125 return 0;
126}
127
Steffen Jaeckel25c8b9f2021-07-08 15:57:40 +0200128static inline int console_in_puts(const char *str)
129{
130 /* There is never anything written */
131 return 0;
132}
133
Simon Glassbd347152020-07-28 19:41:11 -0600134#endif /* !CONFIG_CONSOLE_RECORD */
Simon Glassb6123122020-01-27 08:49:54 -0700135
136/**
Simon Glassb0895382017-06-15 21:37:50 -0600137 * console_announce_r() - print a U-Boot console on non-serial consoles
138 *
139 * When U-Boot starts up with a display it generally does not announce itself
140 * on the display. The banner is instead emitted on the UART before relocation.
141 * This function prints a banner on devices which (we assume) did not receive
142 * it before relocation.
143 *
144 * @return 0 (meaning no errors)
145 */
146int console_announce_r(void);
147
Simon Glass493a4c82020-07-02 21:12:13 -0600148/**
149 * console_puts_select_stderr() - Output a string to selected console devices
150 *
151 * This writes to stderr only. It is useful for outputting errors
152 *
153 * @serial_only: true to output only to serial, false to output to everything
154 * else
155 * @s: String to output
156 */
157void console_puts_select_stderr(bool serial_only, const char *s);
158
Simon Glass24b852a2015-11-08 23:47:45 -0700159/*
160 * CONSOLE multiplexing.
161 */
162#ifdef CONFIG_CONSOLE_MUX
163#include <iomux.h>
164#endif
165
166#endif