blob: d1b18dd4485bfe30e15d9059592955a2c44369c5 [file] [log] [blame]
Varun Wadekar68e4ee42017-11-15 15:48:51 -08001/*
Jimmy Brisson39f9eee2020-08-05 13:44:05 -05002 * Copyright (c) 2017-2020, 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>
Jimmy Brisson39f9eee2020-08-05 13:44:05 -05008#include <assert_macros.S>
Ambroise Vincent09a22e72019-05-29 14:04:16 +01009#include <console_macros.S>
Varun Wadekar68e4ee42017-11-15 15:48:51 -080010
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 Wadekar3cb0d8d2019-09-13 16:31:09 -070015#define CONSOLE_TIMEOUT 0xC000 /* 50 ms */
Varun Wadekar68e4ee42017-11-15 15:48:51 -080016
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
Varun Wadekar3cb0d8d2019-09-13 16:31:09 -0700104 mov w3, #(CONSOLE_RING_DOORBELL | (1 << CONSOLE_NUM_BYTES_SHIFT))
Varun Wadekarcbdcbd12018-05-07 11:21:57 -0700105 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
Varun Wadekar3cb0d8d2019-09-13 16:31:09 -0700114 mov w3, #(CONSOLE_RING_DOORBELL | (1 << CONSOLE_NUM_BYTES_SHIFT))
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800115 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 /* -------------------------------------------------
Jimmy Brisson39f9eee2020-08-05 13:44:05 -0500155 * void 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
Jimmy Brisson39f9eee2020-08-05 13:44:05 -0500159 * Out : void.
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800160 * 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
Jimmy Brisson39f9eee2020-08-05 13:44:05 -0500164#if ENABLE_ASSERTIONS
165 cmp x0, #0
166 ASM_ASSERT(ne)
167#endif /* ENABLE_ASSERTIONS */
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800168
169 /* flush console */
Varun Wadekar3cb0d8d2019-09-13 16:31:09 -0700170 mov w1, #(CONSOLE_RING_DOORBELL | CONSOLE_FLUSH_DATA_TO_PORT)
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800171 str w1, [x0]
Varun Wadekar68e4ee42017-11-15 15:48:51 -0800172 ret
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100173endfunc console_spe_core_flush
174
175 /* ---------------------------------------------
Jimmy Brisson39f9eee2020-08-05 13:44:05 -0500176 * void 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
Jimmy Brisson39f9eee2020-08-05 13:44:05 -0500180 * Out : void.
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100181 * 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