xref: /rk3399_ARM-atf/include/drivers/console.h (revision ac71344e9eca1f7d1e0ce4a67aca776470639b1c)
14ecca339SDan Handley /*
2f51df475SMasahiro Yamada  * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved.
34ecca339SDan Handley  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
54ecca339SDan Handley  */
64ecca339SDan Handley 
7c3cf06f1SAntonio Nino Diaz #ifndef CONSOLE_H
8c3cf06f1SAntonio Nino Diaz #define CONSOLE_H
94ecca339SDan Handley 
1009d40e0eSAntonio Nino Diaz #include <lib/utils_def.h>
1102462972SJuan Castillo 
129536bae6SJulius Werner #define CONSOLE_T_NEXT			(U(0) * REGSZ)
139536bae6SJulius Werner #define CONSOLE_T_FLAGS			(U(1) * REGSZ)
149536bae6SJulius Werner #define CONSOLE_T_PUTC			(U(2) * REGSZ)
159536bae6SJulius Werner #define CONSOLE_T_GETC			(U(3) * REGSZ)
169536bae6SJulius Werner #define CONSOLE_T_FLUSH			(U(4) * REGSZ)
17*ac71344eSAndre Przywara #define CONSOLE_T_BASE			(U(5) * REGSZ)
18*ac71344eSAndre Przywara #define CONSOLE_T_DRVDATA		(U(6) * REGSZ)
199536bae6SJulius Werner 
2088a0523eSAntonio Nino Diaz #define CONSOLE_FLAG_BOOT		(U(1) << 0)
2188a0523eSAntonio Nino Diaz #define CONSOLE_FLAG_RUNTIME		(U(1) << 1)
2288a0523eSAntonio Nino Diaz #define CONSOLE_FLAG_CRASH		(U(1) << 2)
239536bae6SJulius Werner /* Bits 3 to 7 reserved for additional scopes in future expansion. */
249536bae6SJulius Werner #define CONSOLE_FLAG_SCOPE_MASK		((U(1) << 8) - 1)
25f51df475SMasahiro Yamada /* Bits 8 to 31 for non-scope use. */
26f51df475SMasahiro Yamada #define CONSOLE_FLAG_TRANSLATE_CRLF	(U(1) << 8)
279536bae6SJulius Werner 
289536bae6SJulius Werner /* Returned by getc callbacks when receive FIFO is empty. */
299536bae6SJulius Werner #define ERROR_NO_PENDING_CHAR		(-1)
309536bae6SJulius Werner /* Returned by console_xxx() if no registered console implements xxx. */
319536bae6SJulius Werner #define ERROR_NO_VALID_CONSOLE		(-128)
329536bae6SJulius Werner 
33d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__
349536bae6SJulius Werner 
3593c78ed2SAntonio Nino Diaz #include <stdint.h>
369536bae6SJulius Werner 
379536bae6SJulius Werner typedef struct console {
389536bae6SJulius Werner 	struct console *next;
398abcdf92SDaniel Boulby 	/*
408abcdf92SDaniel Boulby 	 * Only the low 32 bits are used. The type is u_register_t to align the
418abcdf92SDaniel Boulby 	 * fields of the struct to 64 bits in AArch64 and 32 bits in AArch32
428abcdf92SDaniel Boulby 	 */
439536bae6SJulius Werner 	u_register_t flags;
44455bca21SDaniel Boulby 	int (*const putc)(int character, struct console *console);
45455bca21SDaniel Boulby 	int (*const getc)(struct console *console);
46455bca21SDaniel Boulby 	int (*const flush)(struct console *console);
47*ac71344eSAndre Przywara 	uintptr_t base;
489536bae6SJulius Werner 	/* Additional private driver data may follow here. */
499536bae6SJulius Werner } console_t;
5009d40e0eSAntonio Nino Diaz 
5109d40e0eSAntonio Nino Diaz /* offset macro assertions for console_t */
5209d40e0eSAntonio Nino Diaz #include <drivers/console_assertions.h>
539536bae6SJulius Werner 
549536bae6SJulius Werner /*
55609e053cSAmbroise Vincent  * Add a console_t instance to the console list. This should only be called by
56609e053cSAmbroise Vincent  * console drivers after they have initialized all fields in the console
57609e053cSAmbroise Vincent  * structure. Platforms seeking to register a new console need to call the
58609e053cSAmbroise Vincent  * respective console__register() function instead.
599536bae6SJulius Werner  */
60609e053cSAmbroise Vincent int console_register(console_t *console);
610f8aee4eSJulius Werner /* Remove a single console_t instance from the console list. Return a pointer to
620f8aee4eSJulius Werner  * the console that was removed if it was found, or NULL if not. */
630f8aee4eSJulius Werner console_t *console_unregister(console_t *console);
64c2e05bb7SAntonio Nino Diaz /* Returns 1 if this console is already registered, 0 if not */
65c2e05bb7SAntonio Nino Diaz int console_is_registered(console_t *console);
66c2e05bb7SAntonio Nino Diaz /*
67c2e05bb7SAntonio Nino Diaz  * Set scope mask of a console that determines in what states it is active.
68c2e05bb7SAntonio Nino Diaz  * By default they are registered with (CONSOLE_FLAG_BOOT|CONSOLE_FLAG_CRASH).
69c2e05bb7SAntonio Nino Diaz  */
709536bae6SJulius Werner void console_set_scope(console_t *console, unsigned int scope);
719536bae6SJulius Werner 
729536bae6SJulius Werner /* Switch to a new global console state (CONSOLE_FLAG_BOOT/RUNTIME/CRASH). */
739536bae6SJulius Werner void console_switch_state(unsigned int new_state);
749536bae6SJulius Werner /* Output a character on all consoles registered for the current state. */
754ecca339SDan Handley int console_putc(int c);
769536bae6SJulius Werner /* Read a character (blocking) from any console registered for current state. */
774ecca339SDan Handley int console_getc(void);
789536bae6SJulius Werner /* Flush all consoles registered for the current state. */
7973e05284SAntonio Nino Diaz int console_flush(void);
804ecca339SDan Handley 
81d5dfdeb6SJulius Werner #endif /* __ASSEMBLER__ */
829536bae6SJulius Werner 
83c3cf06f1SAntonio Nino Diaz #endif /* CONSOLE_H */
84