blob: 98826fa6ea0f3d4b7eaf1f7fe9c52e09dbd07366 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +01002 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __CONSOLE_H__
8#define __CONSOLE_H__
9
10/* Returned by getc callbacks when receive FIFO is empty. */
11#define ERROR_NO_PENDING_CHAR -1
12/* Returned by console_xxx() if the registered console doesn't implement xxx. */
13#define ERROR_NO_VALID_CONSOLE (-128)
14
15#ifndef __ASSEMBLY__
16
Ambroise Vincent602b7f52019-02-11 14:13:43 +000017#include <stdint.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020018
Mark Dykesf41d8ee2025-07-10 16:41:28 -050019#ifdef SMC_FUZZ_VARIABLE_COVERAGE
20#define CONSOLE_FLAG_PLAT_UART 0
21#define CONSOLE_FLAG_SMC_FUZZER 1
22#endif
23
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +010024/*
25 * Function to initialize the console without a C Runtime to print debug
26 * information. It saves the console base to the data section. Returns 1 on
27 * success, 0 on error.
28 */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020029int console_init(uintptr_t base_addr,
30 unsigned int uart_clk, unsigned int baud_rate);
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +010031
Mark Dykesf41d8ee2025-07-10 16:41:28 -050032#ifdef SMC_FUZZ_VARIABLE_COVERAGE
33/*
34 * Function to initialize the console without a C Runtime to print debug
35 * information. It saves the console base to the data section. Returns 1 on
36 * success, 0 on error.
37 */
38int console_init_fuzzer(uintptr_t base_addr,
39 unsigned int uart_clk, unsigned int baud_rate);
40void tftf_switch_console_state(int state);
41int tftf_get_console_state(void);
42#endif
43
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +010044/*
45 * Function to output a character over the console. It returns the character
46 * printed on success or an error code.
47 */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020048int console_putc(int c);
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +010049
Mark Dykesf41d8ee2025-07-10 16:41:28 -050050#ifdef SMC_FUZZ_VARIABLE_COVERAGE
51/*
52 * Function to output a character over the console. It returns the character
53 * printed on success or an error code.
54 */
55int console_putc_fuzzer(int c);
56#endif
57
58
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +010059/*
60 * Function to get a character from the console. It returns the character
61 * grabbed on success or an error code on error. This function is blocking, it
62 * waits until there is an available character to return. Returns a character or
63 * error code.
64 */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020065int console_getc(void);
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +010066
67/*
68 * Function to get a character from the console. It returns the character
69 * grabbed on success or an error code on error. This function is non-blocking,
70 * it returns immediately.
71 */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020072int console_try_getc(void);
Antonio Nino Diaz3da9cb12019-04-23 10:53:45 +010073
74/*
75 * Function to force a write of all buffered data that hasn't been output. It
76 * returns 0 upon successful completion, otherwise it returns an error code.
77 */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020078int console_flush(void);
79
80#endif /* __ASSEMBLY__ */
81
82#endif /* __CONSOLE_H__ */