1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (c) 2024-2025, NVIDIA CORPORATION 4 */ 5 6 #include <compiler.h> 7 #include <console.h> 8 #include <drivers/ffa_console.h> 9 #include <drivers/serial.h> 10 #include <kernel/dt_driver.h> 11 #include <kernel/thread_arch.h> 12 13 #define FFA_CONSOLE_LOG_32 (0x8400008A) 14 15 static void ffa_console_putc(struct serial_chip *chip __unused, int ch) 16 { 17 thread_hvc(FFA_CONSOLE_LOG_32, 1, ch, 0); 18 } 19 20 static const struct serial_ops ffa_console_ops = { 21 .putc = ffa_console_putc, 22 }; 23 DECLARE_KEEP_PAGER(ffa_console_ops); 24 25 static struct serial_chip ffa_console = { 26 .ops = &ffa_console_ops 27 }; 28 29 void ffa_console_init(void) 30 { 31 register_serial_console(&ffa_console); 32 } 33 34 #ifdef CFG_DT 35 36 static struct serial_chip *ffa_console_dev_alloc(void) 37 { 38 return &ffa_console; 39 } 40 41 static int ffa_console_dev_init(struct serial_chip *chip __unused, 42 const void *fdt __unused, int offs __unused, 43 const char *params __unused) 44 { 45 return 0; 46 } 47 48 static void ffa_console_dev_free(struct serial_chip *chip __unused) 49 { 50 } 51 52 static const struct serial_driver ffa_console_driver = { 53 .dev_alloc = ffa_console_dev_alloc, 54 .dev_init = ffa_console_dev_init, 55 .dev_free = ffa_console_dev_free, 56 }; 57 58 static const struct dt_device_match ffa_console_match_table[] = { 59 { .compatible = "arm,ffa-console" }, 60 { } 61 }; 62 63 DEFINE_DT_DRIVER(ffa_console_dt_driver) = { 64 .name = "ffa-console", 65 .type = DT_DRIVER_UART, 66 .match_table = ffa_console_match_table, 67 .driver = &ffa_console_driver, 68 }; 69 70 #endif /* CFG_DT */ 71