blob: 6df73ec242e5fddf78f7367a5a625c73f0f71aa8 [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 Wadekarc5e665c2018-06-19 17:07:08 -070014#define CONSOLE_TIMEOUT 0xC000 /* approx. 50 ms */
Varun Wadekar68e4ee42017-11-15 15:48:51 -080015#define CONSOLE_WRITE (CONSOLE_RING_DOORBELL | CONSOLE_FLUSH_DATA_TO_PORT)
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 Vincent09a22e72019-05-29 14:04:16 +010026 .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 Wadekar68e4ee42017-11-15 15:48:51 -080034
Varun Wadekarc5e665c2018-06-19 17:07:08 -070035.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
381: 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
462:
47.endm
48
Ambroise Vincent09a22e72019-05-29 14:04:16 +010049 /* -------------------------------------------------
50 * int console_spe_register(uintptr_t baseaddr,
51 * uint32_t clock, uint32_t baud,
Andre Przywaraabe890f2020-01-25 00:58:35 +000052 * console_t *console);
Ambroise Vincent09a22e72019-05-29 14:04:16 +010053 * 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 Wadekar68e4ee42017-11-15 15:48:51 -080058 * w2 - Baud rate
Andre Przywaraabe890f2020-01-25 00:58:35 +000059 * x3 - pointer to empty console_t struct
Ambroise Vincent09a22e72019-05-29 14:04:16 +010060 * Out: return 1 on success, 0 on error
61 * Clobber list : x0, x1, x2, x6, x7, x14
62 * -------------------------------------------------
Varun Wadekar68e4ee42017-11-15 15:48:51 -080063 */
Ambroise Vincent09a22e72019-05-29 14:04:16 +010064func console_spe_register
Varun Wadekarc5e665c2018-06-19 17:07:08 -070065 /* 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 Vincent09a22e72019-05-29 14:04:16 +010071 cbz x3, register_fail
Varun Wadekaraeee4902020-03-04 13:47:13 -080072 str x0, [x3, #CONSOLE_T_BASE]
Ambroise Vincent09a22e72019-05-29 14:04:16 +010073 mov x0, x3
74 finish_console_register spe putc=1, getc=1, flush=1
75
76register_fail:
Varun Wadekar68e4ee42017-11-15 15:48:51 -080077 mov w0, wzr
78 ret
Ambroise Vincent09a22e72019-05-29 14:04:16 +010079endfunc console_spe_register
Varun Wadekar68e4ee42017-11-15 15:48:51 -080080
81 /* --------------------------------------------------------
Ambroise Vincent09a22e72019-05-29 14:04:16 +010082 * int console_spe_core_putc(int c, uintptr_t base_addr)
Varun Wadekar68e4ee42017-11-15 15:48:51 -080083 * 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 Wadekarc5e665c2018-06-19 17:07:08 -070088 * Clobber list : x2, x3
Varun Wadekar68e4ee42017-11-15 15:48:51 -080089 * --------------------------------------------------------
90 */
Ambroise Vincent09a22e72019-05-29 14:04:16 +010091func console_spe_core_putc
Varun Wadekar68e4ee42017-11-15 15:48:51 -080092 /* Check the input parameter */
93 cbz x1, putc_error
94
Varun Wadekarcbdcbd12018-05-07 11:21:57 -070095 /* Prepend '\r' to '\n' */
96 cmp w0, #0xA
Varun Wadekarc5e665c2018-06-19 17:07:08 -070097 b.ne not_eol
Varun Wadekarcbdcbd12018-05-07 11:21:57 -070098
Varun Wadekarc5e665c2018-06-19 17:07:08 -070099 check_if_console_is_ready x1, x2, x3, putc_error
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800100
101 /* spe is ready */
Varun Wadekarcbdcbd12018-05-07 11:21:57 -0700102 mov w2, #0xD /* '\r' */
103 and w2, w2, #0xFF
104 mov w3, #(CONSOLE_WRITE | (1 << CONSOLE_NUM_BYTES_SHIFT))
105 orr w2, w2, w3
106 str w2, [x1]
107
Varun Wadekarc5e665c2018-06-19 17:07:08 -0700108not_eol:
109 check_if_console_is_ready x1, x2, x3, putc_error
Varun Wadekarcbdcbd12018-05-07 11:21:57 -0700110
111 /* spe is ready */
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800112 mov w2, w0
113 and w2, w2, #0xFF
114 mov w3, #(CONSOLE_WRITE | (1 << CONSOLE_NUM_BYTES_SHIFT))
115 orr w2, w2, w3
116 str w2, [x1]
117
118 ret
119putc_error:
120 mov w0, #-1
121 ret
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100122endfunc console_spe_core_putc
123
124 /* --------------------------------------------------------
Andre Przywaraabe890f2020-01-25 00:58:35 +0000125 * int console_spe_putc(int c, console_t *console)
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100126 * 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 */
134func console_spe_putc
Varun Wadekaraeee4902020-03-04 13:47:13 -0800135 ldr x1, [x1, #CONSOLE_T_BASE]
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100136 b console_spe_core_putc
137endfunc console_spe_putc
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800138
139 /* ---------------------------------------------
Andre Przywaraabe890f2020-01-25 00:58:35 +0000140 * int console_spe_getc(console_t *console)
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800141 * Function to get a character from the console.
142 * It returns the character grabbed on success
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100143 * or -1 if no character is available.
144 * In : x0 - pointer to console_t structure
145 * Out: w0 - character if available, else -1
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800146 * Clobber list : x0, x1
147 * ---------------------------------------------
148 */
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100149func console_spe_getc
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800150 mov w0, #-1
151 ret
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100152endfunc console_spe_getc
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800153
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100154 /* -------------------------------------------------
155 * int console_spe_core_flush(uintptr_t base_addr)
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800156 * Function to force a write of all buffered
157 * data that hasn't been output.
158 * In : x0 - console base address
159 * Out : return -1 on error else return 0.
160 * Clobber list : x0, x1
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100161 * -------------------------------------------------
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800162 */
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100163func console_spe_core_flush
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800164 cbz x0, flush_error
165
166 /* flush console */
167 mov w1, #CONSOLE_WRITE
168 str w1, [x0]
169 mov w0, #0
170 ret
171flush_error:
172 mov w0, #-1
173 ret
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100174endfunc console_spe_core_flush
175
176 /* ---------------------------------------------
Andre Przywaraabe890f2020-01-25 00:58:35 +0000177 * int console_spe_flush(console_t *console)
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100178 * Function to force a write of all buffered
179 * data that hasn't been output.
180 * In : x0 - pointer to console_t structure
181 * Out : return -1 on error else return 0.
182 * Clobber list : x0, x1
183 * ---------------------------------------------
184 */
185func console_spe_flush
Varun Wadekaraeee4902020-03-04 13:47:13 -0800186 ldr x0, [x0, #CONSOLE_T_BASE]
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100187 b console_spe_core_flush
188endfunc console_spe_flush