Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 1 | /* |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | c5e665c | 2018-06-19 17:07:08 -0700 | [diff] [blame] | 3 | * Copyright (c) 2020, NVIDIA Corporation. All rights reserved. |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 4 | * |
| 5 | * SPDX-License-Identifier: BSD-3-Clause |
| 6 | */ |
| 7 | #include <asm_macros.S> |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 8 | #include <assert_macros.S> |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 9 | #include <console_macros.S> |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 10 | |
| 11 | #define CONSOLE_NUM_BYTES_SHIFT 24 |
| 12 | #define CONSOLE_FLUSH_DATA_TO_PORT (1 << 26) |
| 13 | #define CONSOLE_RING_DOORBELL (1 << 31) |
| 14 | #define CONSOLE_IS_BUSY (1 << 31) |
Varun Wadekar | 3cb0d8d | 2019-09-13 16:31:09 -0700 | [diff] [blame] | 15 | #define CONSOLE_TIMEOUT 0xC000 /* 50 ms */ |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 16 | |
| 17 | /* |
| 18 | * This file contains a driver implementation to make use of the |
| 19 | * real console implementation provided by the SPE firmware running |
| 20 | * SoCs after Tegra186. |
| 21 | * |
| 22 | * This console is shared by multiple components and the SPE firmware |
| 23 | * finally displays everything on the UART port. |
| 24 | */ |
| 25 | |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 26 | .globl console_spe_core_init |
| 27 | .globl console_spe_core_putc |
| 28 | .globl console_spe_core_getc |
| 29 | .globl console_spe_core_flush |
| 30 | .globl console_spe_putc |
| 31 | .globl console_spe_getc |
| 32 | .globl console_spe_flush |
| 33 | .globl console_spe_register |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 34 | |
Varun Wadekar | c5e665c | 2018-06-19 17:07:08 -0700 | [diff] [blame] | 35 | .macro check_if_console_is_ready base, tmp1, tmp2, label |
| 36 | /* wait until spe is ready or timeout expires */ |
| 37 | mrs \tmp2, cntps_tval_el1 |
| 38 | 1: ldr \tmp1, [\base] |
| 39 | and \tmp1, \tmp1, #CONSOLE_IS_BUSY |
| 40 | cbz \tmp1, 2f |
| 41 | mrs \tmp1, cntps_tval_el1 |
| 42 | sub \tmp1, \tmp2, \tmp1 |
| 43 | cmp \tmp1, #CONSOLE_TIMEOUT |
| 44 | b.lt 1b |
| 45 | b \label |
| 46 | 2: |
| 47 | .endm |
| 48 | |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 49 | /* ------------------------------------------------- |
| 50 | * int console_spe_register(uintptr_t baseaddr, |
| 51 | * uint32_t clock, uint32_t baud, |
Andre Przywara | abe890f | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 52 | * console_t *console); |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 53 | * Function to initialize and register a new spe |
| 54 | * console. Storage passed in for the console struct |
| 55 | * *must* be persistent (i.e. not from the stack). |
| 56 | * In: x0 - UART register base address |
| 57 | * w1 - UART clock in Hz |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 58 | * w2 - Baud rate |
Andre Przywara | abe890f | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 59 | * x3 - pointer to empty console_t struct |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 60 | * Out: return 1 on success, 0 on error |
| 61 | * Clobber list : x0, x1, x2, x6, x7, x14 |
| 62 | * ------------------------------------------------- |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 63 | */ |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 64 | func console_spe_register |
Varun Wadekar | c5e665c | 2018-06-19 17:07:08 -0700 | [diff] [blame] | 65 | /* Check the input base address */ |
| 66 | cbz x0, register_fail |
| 67 | |
| 68 | /* Dont use clock or baud rate, so ok to overwrite them */ |
| 69 | check_if_console_is_ready x0, x1, x2, register_fail |
| 70 | |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 71 | cbz x3, register_fail |
Varun Wadekar | aeee490 | 2020-03-04 13:47:13 -0800 | [diff] [blame] | 72 | str x0, [x3, #CONSOLE_T_BASE] |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 73 | mov x0, x3 |
Sandrine Bailleux | f57e203 | 2023-10-11 08:38:00 +0200 | [diff] [blame] | 74 | finish_console_register spe putc=1, getc=ENABLE_CONSOLE_GETC, flush=1 |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 75 | |
| 76 | register_fail: |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 77 | mov w0, wzr |
| 78 | ret |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 79 | endfunc console_spe_register |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 80 | |
| 81 | /* -------------------------------------------------------- |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 82 | * int console_spe_core_putc(int c, uintptr_t base_addr) |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 83 | * Function to output a character over the console. It |
| 84 | * returns the character printed on success or -1 on error. |
| 85 | * In : w0 - character to be printed |
| 86 | * x1 - console base address |
| 87 | * Out : return -1 on error else return character. |
Varun Wadekar | c5e665c | 2018-06-19 17:07:08 -0700 | [diff] [blame] | 88 | * Clobber list : x2, x3 |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 89 | * -------------------------------------------------------- |
| 90 | */ |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 91 | func console_spe_core_putc |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 92 | /* Check the input parameter */ |
| 93 | cbz x1, putc_error |
| 94 | |
Varun Wadekar | cbdcbd1 | 2018-05-07 11:21:57 -0700 | [diff] [blame] | 95 | /* Prepend '\r' to '\n' */ |
| 96 | cmp w0, #0xA |
Varun Wadekar | c5e665c | 2018-06-19 17:07:08 -0700 | [diff] [blame] | 97 | b.ne not_eol |
Varun Wadekar | cbdcbd1 | 2018-05-07 11:21:57 -0700 | [diff] [blame] | 98 | |
Varun Wadekar | c5e665c | 2018-06-19 17:07:08 -0700 | [diff] [blame] | 99 | check_if_console_is_ready x1, x2, x3, putc_error |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 100 | |
| 101 | /* spe is ready */ |
Varun Wadekar | cbdcbd1 | 2018-05-07 11:21:57 -0700 | [diff] [blame] | 102 | mov w2, #0xD /* '\r' */ |
| 103 | and w2, w2, #0xFF |
Varun Wadekar | 3cb0d8d | 2019-09-13 16:31:09 -0700 | [diff] [blame] | 104 | mov w3, #(CONSOLE_RING_DOORBELL | (1 << CONSOLE_NUM_BYTES_SHIFT)) |
Varun Wadekar | cbdcbd1 | 2018-05-07 11:21:57 -0700 | [diff] [blame] | 105 | orr w2, w2, w3 |
| 106 | str w2, [x1] |
| 107 | |
Varun Wadekar | c5e665c | 2018-06-19 17:07:08 -0700 | [diff] [blame] | 108 | not_eol: |
| 109 | check_if_console_is_ready x1, x2, x3, putc_error |
Varun Wadekar | cbdcbd1 | 2018-05-07 11:21:57 -0700 | [diff] [blame] | 110 | |
| 111 | /* spe is ready */ |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 112 | mov w2, w0 |
| 113 | and w2, w2, #0xFF |
Varun Wadekar | 3cb0d8d | 2019-09-13 16:31:09 -0700 | [diff] [blame] | 114 | mov w3, #(CONSOLE_RING_DOORBELL | (1 << CONSOLE_NUM_BYTES_SHIFT)) |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 115 | orr w2, w2, w3 |
| 116 | str w2, [x1] |
| 117 | |
| 118 | ret |
| 119 | putc_error: |
| 120 | mov w0, #-1 |
| 121 | ret |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 122 | endfunc console_spe_core_putc |
| 123 | |
| 124 | /* -------------------------------------------------------- |
Andre Przywara | abe890f | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 125 | * int console_spe_putc(int c, console_t *console) |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 126 | * Function to output a character over the console. It |
| 127 | * returns the character printed on success or -1 on error. |
| 128 | * In : w0 - character to be printed |
| 129 | * x1 - pointer to console_t structure |
| 130 | * Out : return -1 on error else return character. |
| 131 | * Clobber list : x2 |
| 132 | * -------------------------------------------------------- |
| 133 | */ |
| 134 | func console_spe_putc |
Varun Wadekar | aeee490 | 2020-03-04 13:47:13 -0800 | [diff] [blame] | 135 | ldr x1, [x1, #CONSOLE_T_BASE] |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 136 | b console_spe_core_putc |
| 137 | endfunc console_spe_putc |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 138 | |
| 139 | /* --------------------------------------------- |
Andre Przywara | abe890f | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 140 | * int console_spe_getc(console_t *console) |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 141 | * Function to get a character from the console. |
| 142 | * It returns the character grabbed on success |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 143 | * or -1 if no character is available. |
| 144 | * In : x0 - pointer to console_t structure |
| 145 | * Out: w0 - character if available, else -1 |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 146 | * Clobber list : x0, x1 |
| 147 | * --------------------------------------------- |
| 148 | */ |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 149 | func console_spe_getc |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 150 | mov w0, #-1 |
| 151 | ret |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 152 | endfunc console_spe_getc |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 153 | |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 154 | /* ------------------------------------------------- |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 155 | * void console_spe_core_flush(uintptr_t base_addr) |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 156 | * Function to force a write of all buffered |
| 157 | * data that hasn't been output. |
| 158 | * In : x0 - console base address |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 159 | * Out : void. |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 160 | * Clobber list : x0, x1 |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 161 | * ------------------------------------------------- |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 162 | */ |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 163 | func console_spe_core_flush |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 164 | #if ENABLE_ASSERTIONS |
| 165 | cmp x0, #0 |
| 166 | ASM_ASSERT(ne) |
| 167 | #endif /* ENABLE_ASSERTIONS */ |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 168 | |
| 169 | /* flush console */ |
Varun Wadekar | 3cb0d8d | 2019-09-13 16:31:09 -0700 | [diff] [blame] | 170 | mov w1, #(CONSOLE_RING_DOORBELL | CONSOLE_FLUSH_DATA_TO_PORT) |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 171 | str w1, [x0] |
Varun Wadekar | 68e4ee4 | 2017-11-15 15:48:51 -0800 | [diff] [blame] | 172 | ret |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 173 | endfunc console_spe_core_flush |
| 174 | |
| 175 | /* --------------------------------------------- |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 176 | * void console_spe_flush(console_t *console) |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 177 | * Function to force a write of all buffered |
| 178 | * data that hasn't been output. |
| 179 | * In : x0 - pointer to console_t structure |
Jimmy Brisson | 39f9eee | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 180 | * Out : void. |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 181 | * Clobber list : x0, x1 |
| 182 | * --------------------------------------------- |
| 183 | */ |
| 184 | func console_spe_flush |
Varun Wadekar | aeee490 | 2020-03-04 13:47:13 -0800 | [diff] [blame] | 185 | ldr x0, [x0, #CONSOLE_T_BASE] |
Ambroise Vincent | 09a22e7 | 2019-05-29 14:04:16 +0100 | [diff] [blame] | 186 | b console_spe_core_flush |
| 187 | endfunc console_spe_flush |