blob: 9196c1cd1565a3568479b03de0dc59cc8b33b6e8 [file] [log] [blame]
Varun Wadekar68e4ee42017-11-15 15:48:51 -08001/*
Ambroise Vincent09a22e72019-05-29 14:04:16 +01002 * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
Varun Wadekarc5e665c2018-06-19 17:07:08 -07003 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Varun Wadekar68e4ee42017-11-15 15:48:51 -08004 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7#include <asm_macros.S>
Ambroise Vincent09a22e72019-05-29 14:04:16 +01008#include <console_macros.S>
Varun Wadekar68e4ee42017-11-15 15:48:51 -08009
10#define CONSOLE_NUM_BYTES_SHIFT 24
11#define CONSOLE_FLUSH_DATA_TO_PORT (1 << 26)
12#define CONSOLE_RING_DOORBELL (1 << 31)
13#define CONSOLE_IS_BUSY (1 << 31)
Varun Wadekar3cb0d8d2019-09-13 16:31:09 -070014#define CONSOLE_TIMEOUT 0xC000 /* 50 ms */
Varun Wadekar68e4ee42017-11-15 15:48:51 -080015
16 /*
17 * This file contains a driver implementation to make use of the
18 * real console implementation provided by the SPE firmware running
19 * SoCs after Tegra186.
20 *
21 * This console is shared by multiple components and the SPE firmware
22 * finally displays everything on the UART port.
23 */
24
Ambroise Vincent09a22e72019-05-29 14:04:16 +010025 .globl console_spe_core_init
26 .globl console_spe_core_putc
27 .globl console_spe_core_getc
28 .globl console_spe_core_flush
29 .globl console_spe_putc
30 .globl console_spe_getc
31 .globl console_spe_flush
32 .globl console_spe_register
Varun Wadekar68e4ee42017-11-15 15:48:51 -080033
Varun Wadekarc5e665c2018-06-19 17:07:08 -070034.macro check_if_console_is_ready base, tmp1, tmp2, label
35 /* wait until spe is ready or timeout expires */
36 mrs \tmp2, cntps_tval_el1
371: ldr \tmp1, [\base]
38 and \tmp1, \tmp1, #CONSOLE_IS_BUSY
39 cbz \tmp1, 2f
40 mrs \tmp1, cntps_tval_el1
41 sub \tmp1, \tmp2, \tmp1
42 cmp \tmp1, #CONSOLE_TIMEOUT
43 b.lt 1b
44 b \label
452:
46.endm
47
Ambroise Vincent09a22e72019-05-29 14:04:16 +010048 /* -------------------------------------------------
49 * int console_spe_register(uintptr_t baseaddr,
50 * uint32_t clock, uint32_t baud,
Andre Przywaraabe890f2020-01-25 00:58:35 +000051 * console_t *console);
Ambroise Vincent09a22e72019-05-29 14:04:16 +010052 * Function to initialize and register a new spe
53 * console. Storage passed in for the console struct
54 * *must* be persistent (i.e. not from the stack).
55 * In: x0 - UART register base address
56 * w1 - UART clock in Hz
Varun Wadekar68e4ee42017-11-15 15:48:51 -080057 * w2 - Baud rate
Andre Przywaraabe890f2020-01-25 00:58:35 +000058 * x3 - pointer to empty console_t struct
Ambroise Vincent09a22e72019-05-29 14:04:16 +010059 * Out: return 1 on success, 0 on error
60 * Clobber list : x0, x1, x2, x6, x7, x14
61 * -------------------------------------------------
Varun Wadekar68e4ee42017-11-15 15:48:51 -080062 */
Ambroise Vincent09a22e72019-05-29 14:04:16 +010063func console_spe_register
Varun Wadekarc5e665c2018-06-19 17:07:08 -070064 /* Check the input base address */
65 cbz x0, register_fail
66
67 /* Dont use clock or baud rate, so ok to overwrite them */
68 check_if_console_is_ready x0, x1, x2, register_fail
69
Ambroise Vincent09a22e72019-05-29 14:04:16 +010070 cbz x3, register_fail
Varun Wadekaraeee4902020-03-04 13:47:13 -080071 str x0, [x3, #CONSOLE_T_BASE]
Ambroise Vincent09a22e72019-05-29 14:04:16 +010072 mov x0, x3
73 finish_console_register spe putc=1, getc=1, flush=1
74
75register_fail:
Varun Wadekar68e4ee42017-11-15 15:48:51 -080076 mov w0, wzr
77 ret
Ambroise Vincent09a22e72019-05-29 14:04:16 +010078endfunc console_spe_register
Varun Wadekar68e4ee42017-11-15 15:48:51 -080079
80 /* --------------------------------------------------------
Ambroise Vincent09a22e72019-05-29 14:04:16 +010081 * int console_spe_core_putc(int c, uintptr_t base_addr)
Varun Wadekar68e4ee42017-11-15 15:48:51 -080082 * Function to output a character over the console. It
83 * returns the character printed on success or -1 on error.
84 * In : w0 - character to be printed
85 * x1 - console base address
86 * Out : return -1 on error else return character.
Varun Wadekarc5e665c2018-06-19 17:07:08 -070087 * Clobber list : x2, x3
Varun Wadekar68e4ee42017-11-15 15:48:51 -080088 * --------------------------------------------------------
89 */
Ambroise Vincent09a22e72019-05-29 14:04:16 +010090func console_spe_core_putc
Varun Wadekar68e4ee42017-11-15 15:48:51 -080091 /* Check the input parameter */
92 cbz x1, putc_error
93
Varun Wadekarcbdcbd12018-05-07 11:21:57 -070094 /* Prepend '\r' to '\n' */
95 cmp w0, #0xA
Varun Wadekarc5e665c2018-06-19 17:07:08 -070096 b.ne not_eol
Varun Wadekarcbdcbd12018-05-07 11:21:57 -070097
Varun Wadekarc5e665c2018-06-19 17:07:08 -070098 check_if_console_is_ready x1, x2, x3, putc_error
Varun Wadekar68e4ee42017-11-15 15:48:51 -080099
100 /* spe is ready */
Varun Wadekarcbdcbd12018-05-07 11:21:57 -0700101 mov w2, #0xD /* '\r' */
102 and w2, w2, #0xFF
Varun Wadekar3cb0d8d2019-09-13 16:31:09 -0700103 mov w3, #(CONSOLE_RING_DOORBELL | (1 << CONSOLE_NUM_BYTES_SHIFT))
Varun Wadekarcbdcbd12018-05-07 11:21:57 -0700104 orr w2, w2, w3
105 str w2, [x1]
106
Varun Wadekarc5e665c2018-06-19 17:07:08 -0700107not_eol:
108 check_if_console_is_ready x1, x2, x3, putc_error
Varun Wadekarcbdcbd12018-05-07 11:21:57 -0700109
110 /* spe is ready */
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800111 mov w2, w0
112 and w2, w2, #0xFF
Varun Wadekar3cb0d8d2019-09-13 16:31:09 -0700113 mov w3, #(CONSOLE_RING_DOORBELL | (1 << CONSOLE_NUM_BYTES_SHIFT))
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800114 orr w2, w2, w3
115 str w2, [x1]
116
117 ret
118putc_error:
119 mov w0, #-1
120 ret
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100121endfunc console_spe_core_putc
122
123 /* --------------------------------------------------------
Andre Przywaraabe890f2020-01-25 00:58:35 +0000124 * int console_spe_putc(int c, console_t *console)
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100125 * Function to output a character over the console. It
126 * returns the character printed on success or -1 on error.
127 * In : w0 - character to be printed
128 * x1 - pointer to console_t structure
129 * Out : return -1 on error else return character.
130 * Clobber list : x2
131 * --------------------------------------------------------
132 */
133func console_spe_putc
Varun Wadekaraeee4902020-03-04 13:47:13 -0800134 ldr x1, [x1, #CONSOLE_T_BASE]
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100135 b console_spe_core_putc
136endfunc console_spe_putc
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800137
138 /* ---------------------------------------------
Andre Przywaraabe890f2020-01-25 00:58:35 +0000139 * int console_spe_getc(console_t *console)
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800140 * Function to get a character from the console.
141 * It returns the character grabbed on success
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100142 * or -1 if no character is available.
143 * In : x0 - pointer to console_t structure
144 * Out: w0 - character if available, else -1
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800145 * Clobber list : x0, x1
146 * ---------------------------------------------
147 */
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100148func console_spe_getc
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800149 mov w0, #-1
150 ret
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100151endfunc console_spe_getc
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800152
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100153 /* -------------------------------------------------
154 * int console_spe_core_flush(uintptr_t base_addr)
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800155 * Function to force a write of all buffered
156 * data that hasn't been output.
157 * In : x0 - console base address
158 * Out : return -1 on error else return 0.
159 * Clobber list : x0, x1
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100160 * -------------------------------------------------
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800161 */
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100162func console_spe_core_flush
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800163 cbz x0, flush_error
164
165 /* flush console */
Varun Wadekar3cb0d8d2019-09-13 16:31:09 -0700166 mov w1, #(CONSOLE_RING_DOORBELL | CONSOLE_FLUSH_DATA_TO_PORT)
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800167 str w1, [x0]
168 mov w0, #0
169 ret
170flush_error:
171 mov w0, #-1
172 ret
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100173endfunc console_spe_core_flush
174
175 /* ---------------------------------------------
Andre Przywaraabe890f2020-01-25 00:58:35 +0000176 * int console_spe_flush(console_t *console)
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100177 * Function to force a write of all buffered
178 * data that hasn't been output.
179 * In : x0 - pointer to console_t structure
180 * Out : return -1 on error else return 0.
181 * Clobber list : x0, x1
182 * ---------------------------------------------
183 */
184func console_spe_flush
Varun Wadekaraeee4902020-03-04 13:47:13 -0800185 ldr x0, [x0, #CONSOLE_T_BASE]
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100186 b console_spe_core_flush
187endfunc console_spe_flush