xref: /rk3399_ARM-atf/include/drivers/console.h (revision 0f8aee4e45d3e74f5ebb385c8afcdee6c3b4c73a)
14ecca339SDan Handley /*
2bc1a03c7SDan Handley  * Copyright (c) 2013-2018, 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 
109536bae6SJulius Werner #include <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)
179536bae6SJulius Werner #define CONSOLE_T_DRVDATA		(U(5) * REGSZ)
189536bae6SJulius Werner 
1988a0523eSAntonio Nino Diaz #define CONSOLE_FLAG_BOOT		(U(1) << 0)
2088a0523eSAntonio Nino Diaz #define CONSOLE_FLAG_RUNTIME		(U(1) << 1)
2188a0523eSAntonio Nino Diaz #define CONSOLE_FLAG_CRASH		(U(1) << 2)
229536bae6SJulius Werner /* Bits 3 to 7 reserved for additional scopes in future expansion. */
239536bae6SJulius Werner #define CONSOLE_FLAG_SCOPE_MASK		((U(1) << 8) - 1)
249536bae6SJulius Werner /* Bits 8 to 31 reserved for non-scope use in future expansion. */
259536bae6SJulius Werner 
269536bae6SJulius Werner /* Returned by getc callbacks when receive FIFO is empty. */
279536bae6SJulius Werner #define ERROR_NO_PENDING_CHAR		(-1)
289536bae6SJulius Werner /* Returned by console_xxx() if no registered console implements xxx. */
299536bae6SJulius Werner #define ERROR_NO_VALID_CONSOLE		(-128)
309536bae6SJulius Werner 
319536bae6SJulius Werner #ifndef __ASSEMBLY__
329536bae6SJulius Werner 
3393c78ed2SAntonio Nino Diaz #include <stdint.h>
349536bae6SJulius Werner 
359536bae6SJulius Werner typedef struct console {
369536bae6SJulius Werner 	struct console *next;
378abcdf92SDaniel Boulby 	/*
388abcdf92SDaniel Boulby 	 * Only the low 32 bits are used. The type is u_register_t to align the
398abcdf92SDaniel Boulby 	 * fields of the struct to 64 bits in AArch64 and 32 bits in AArch32
408abcdf92SDaniel Boulby 	 */
419536bae6SJulius Werner 	u_register_t flags;
42455bca21SDaniel Boulby 	int (*const putc)(int character, struct console *console);
43455bca21SDaniel Boulby 	int (*const getc)(struct console *console);
44455bca21SDaniel Boulby 	int (*const flush)(struct console *console);
459536bae6SJulius Werner 	/* Additional private driver data may follow here. */
469536bae6SJulius Werner } console_t;
479536bae6SJulius Werner #include <console_assertions.h> /* offset macro assertions for console_t */
489536bae6SJulius Werner 
499536bae6SJulius Werner /*
509536bae6SJulius Werner  * NOTE: There is no publicly accessible console_register() function. Consoles
519536bae6SJulius Werner  * are registered by directly calling the register function of a specific
529536bae6SJulius Werner  * implementation, e.g. console_16550_register() from <uart_16550.h>. Consoles
539536bae6SJulius Werner  * registered that way can be unregistered/reconfigured with below functions.
549536bae6SJulius Werner  */
55*0f8aee4eSJulius Werner /* Remove a single console_t instance from the console list. Return a pointer to
56*0f8aee4eSJulius Werner  * the console that was removed if it was found, or NULL if not. */
57*0f8aee4eSJulius Werner console_t *console_unregister(console_t *console);
58c2e05bb7SAntonio Nino Diaz /* Returns 1 if this console is already registered, 0 if not */
59c2e05bb7SAntonio Nino Diaz int console_is_registered(console_t *console);
60c2e05bb7SAntonio Nino Diaz /*
61c2e05bb7SAntonio Nino Diaz  * Set scope mask of a console that determines in what states it is active.
62c2e05bb7SAntonio Nino Diaz  * By default they are registered with (CONSOLE_FLAG_BOOT|CONSOLE_FLAG_CRASH).
63c2e05bb7SAntonio Nino Diaz  */
649536bae6SJulius Werner void console_set_scope(console_t *console, unsigned int scope);
659536bae6SJulius Werner 
669536bae6SJulius Werner /* Switch to a new global console state (CONSOLE_FLAG_BOOT/RUNTIME/CRASH). */
679536bae6SJulius Werner void console_switch_state(unsigned int new_state);
689536bae6SJulius Werner /* Output a character on all consoles registered for the current state. */
694ecca339SDan Handley int console_putc(int c);
709536bae6SJulius Werner /* Read a character (blocking) from any console registered for current state. */
714ecca339SDan Handley int console_getc(void);
729536bae6SJulius Werner /* Flush all consoles registered for the current state. */
7373e05284SAntonio Nino Diaz int console_flush(void);
744ecca339SDan Handley 
759536bae6SJulius Werner #if !MULTI_CONSOLE_API
76bc1a03c7SDan Handley /* REMOVED on AArch64 -- use console_<driver>_register() instead! */
779536bae6SJulius Werner int console_init(uintptr_t base_addr,
78bc1a03c7SDan Handley 		 unsigned int uart_clk, unsigned int baud_rate);
79bc1a03c7SDan Handley void console_uninit(void);
809536bae6SJulius Werner #endif
819536bae6SJulius Werner 
829536bae6SJulius Werner #endif /* __ASSEMBLY__ */
839536bae6SJulius Werner 
84c3cf06f1SAntonio Nino Diaz #endif /* CONSOLE_H */
85