14ecca339SDan Handley /* 2*6d6aa1daSSigned-off-by: Maheedhar Bollapalli * Copyright (c) 2013-2025, 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) 1585bebe18SSandrine Bailleux #if ENABLE_CONSOLE_GETC 169536bae6SJulius Werner #define CONSOLE_T_GETC (U(3) * REGSZ) 179536bae6SJulius Werner #define CONSOLE_T_FLUSH (U(4) * REGSZ) 18ac71344eSAndre Przywara #define CONSOLE_T_BASE (U(5) * REGSZ) 19ac71344eSAndre Przywara #define CONSOLE_T_DRVDATA (U(6) * REGSZ) 2085bebe18SSandrine Bailleux #else 2185bebe18SSandrine Bailleux #define CONSOLE_T_FLUSH (U(3) * REGSZ) 2285bebe18SSandrine Bailleux #define CONSOLE_T_BASE (U(4) * REGSZ) 2385bebe18SSandrine Bailleux #define CONSOLE_T_DRVDATA (U(5) * REGSZ) 2485bebe18SSandrine Bailleux #endif 259536bae6SJulius Werner 261ec2c39bSSaivardhan Thatikonda #define CONSOLE_FLAG_BOOT BIT_32(0) 271ec2c39bSSaivardhan Thatikonda #define CONSOLE_FLAG_RUNTIME BIT_32(1) 281ec2c39bSSaivardhan Thatikonda #define CONSOLE_FLAG_CRASH BIT_32(2) 299536bae6SJulius Werner /* Bits 3 to 7 reserved for additional scopes in future expansion. */ 3097eefd99SNithin G #define CONSOLE_FLAG_SCOPE_MASK GENMASK(7, 0) 31f51df475SMasahiro Yamada /* Bits 8 to 31 for non-scope use. */ 321ec2c39bSSaivardhan Thatikonda #define CONSOLE_FLAG_TRANSLATE_CRLF BIT_32(8) 339536bae6SJulius Werner 349536bae6SJulius Werner /* Returned by getc callbacks when receive FIFO is empty. */ 359536bae6SJulius Werner #define ERROR_NO_PENDING_CHAR (-1) 369536bae6SJulius Werner /* Returned by console_xxx() if no registered console implements xxx. */ 379536bae6SJulius Werner #define ERROR_NO_VALID_CONSOLE (-128) 389536bae6SJulius Werner 39d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__ 409536bae6SJulius Werner 4193c78ed2SAntonio Nino Diaz #include <stdint.h> 429536bae6SJulius Werner 43*6d6aa1daSSigned-off-by: Maheedhar Bollapalli typedef struct core_console { 44*6d6aa1daSSigned-off-by: Maheedhar Bollapalli struct core_console *next; 458abcdf92SDaniel Boulby /* 468abcdf92SDaniel Boulby * Only the low 32 bits are used. The type is u_register_t to align the 478abcdf92SDaniel Boulby * fields of the struct to 64 bits in AArch64 and 32 bits in AArch32 488abcdf92SDaniel Boulby */ 499536bae6SJulius Werner u_register_t flags; 50*6d6aa1daSSigned-off-by: Maheedhar Bollapalli int (*const putc)(int character, struct core_console *console); 5185bebe18SSandrine Bailleux #if ENABLE_CONSOLE_GETC 52*6d6aa1daSSigned-off-by: Maheedhar Bollapalli int (*const getc)(struct core_console *console); 5385bebe18SSandrine Bailleux #endif 54*6d6aa1daSSigned-off-by: Maheedhar Bollapalli void (*const flush)(struct core_console *console); 55ac71344eSAndre Przywara uintptr_t base; 569536bae6SJulius Werner /* Additional private driver data may follow here. */ 579536bae6SJulius Werner } console_t; 5809d40e0eSAntonio Nino Diaz 5903bd4810SYann Gautier extern console_t *console_list; 6003bd4810SYann Gautier 6109d40e0eSAntonio Nino Diaz /* offset macro assertions for console_t */ 6209d40e0eSAntonio Nino Diaz #include <drivers/console_assertions.h> 639536bae6SJulius Werner 649536bae6SJulius Werner /* 65609e053cSAmbroise Vincent * Add a console_t instance to the console list. This should only be called by 66609e053cSAmbroise Vincent * console drivers after they have initialized all fields in the console 67609e053cSAmbroise Vincent * structure. Platforms seeking to register a new console need to call the 68609e053cSAmbroise Vincent * respective console__register() function instead. 699536bae6SJulius Werner */ 70609e053cSAmbroise Vincent int console_register(console_t *console); 710f8aee4eSJulius Werner /* Remove a single console_t instance from the console list. Return a pointer to 720f8aee4eSJulius Werner * the console that was removed if it was found, or NULL if not. */ 73acad3b0fSSaivardhan Thatikonda console_t *console_unregister(console_t *to_be_deleted); 74c2e05bb7SAntonio Nino Diaz /* Returns 1 if this console is already registered, 0 if not */ 75acad3b0fSSaivardhan Thatikonda int console_is_registered(console_t *to_find); 76c2e05bb7SAntonio Nino Diaz /* 77c2e05bb7SAntonio Nino Diaz * Set scope mask of a console that determines in what states it is active. 78c2e05bb7SAntonio Nino Diaz * By default they are registered with (CONSOLE_FLAG_BOOT|CONSOLE_FLAG_CRASH). 79c2e05bb7SAntonio Nino Diaz */ 809536bae6SJulius Werner void console_set_scope(console_t *console, unsigned int scope); 819536bae6SJulius Werner 829536bae6SJulius Werner /* Switch to a new global console state (CONSOLE_FLAG_BOOT/RUNTIME/CRASH). */ 839536bae6SJulius Werner void console_switch_state(unsigned int new_state); 849536bae6SJulius Werner /* Output a character on all consoles registered for the current state. */ 854ecca339SDan Handley int console_putc(int c); 8685bebe18SSandrine Bailleux #if ENABLE_CONSOLE_GETC 879536bae6SJulius Werner /* Read a character (blocking) from any console registered for current state. */ 884ecca339SDan Handley int console_getc(void); 8985bebe18SSandrine Bailleux #endif 909536bae6SJulius Werner /* Flush all consoles registered for the current state. */ 91831b0e98SJimmy Brisson void console_flush(void); 924ecca339SDan Handley 93d5dfdeb6SJulius Werner #endif /* __ASSEMBLER__ */ 949536bae6SJulius Werner 95c3cf06f1SAntonio Nino Diaz #endif /* CONSOLE_H */ 96