Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 5 | */ |
| 6 | #include <arch.h> |
| 7 | #include <asm_macros.S> |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 8 | #include <assert_macros.S> |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 9 | #include <cadence/cdns_uart.h> |
Soby Mathew | 58873ae | 2018-10-10 16:03:09 +0100 | [diff] [blame] | 10 | #define USE_FINISH_CONSOLE_REG_2 |
| 11 | #include <console_macros.S> |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 12 | |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 13 | /* |
| 14 | * "core" functions are low-level implementations that don't require |
| 15 | * writable memory and are thus safe to call in BL1 crash context. |
| 16 | */ |
| 17 | .globl console_cdns_core_init |
| 18 | .globl console_cdns_core_putc |
| 19 | .globl console_cdns_core_getc |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 20 | .globl console_cdns_core_flush |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 21 | |
| 22 | .globl console_cdns_putc |
| 23 | .globl console_cdns_getc |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 24 | .globl console_cdns_flush |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 25 | |
| 26 | /* ----------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 27 | * int console_cdns_core_init(uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 28 | * Function to initialize the console without a |
| 29 | * C Runtime to print debug information. This |
| 30 | * function will be accessed by console_init and |
| 31 | * crash reporting. |
| 32 | * We assume that the bootloader already set up |
| 33 | * the HW (baud, ...) and only enable the trans- |
| 34 | * mitter and receiver here. |
| 35 | * In: x0 - console base address |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 36 | * Out: return 1 on success else 0 on error |
| 37 | * Clobber list : x1, x2, x3 |
| 38 | * ----------------------------------------------- |
| 39 | */ |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 40 | func console_cdns_core_init |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 41 | /* Check the input base address */ |
| 42 | cbz x0, core_init_fail |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 43 | |
| 44 | /* RX/TX enabled & reset */ |
| 45 | mov w3, #(R_UART_CR_TX_EN | R_UART_CR_RX_EN | R_UART_CR_TXRST | R_UART_CR_RXRST) |
| 46 | str w3, [x0, #R_UART_CR] |
| 47 | |
| 48 | mov w0, #1 |
| 49 | ret |
| 50 | core_init_fail: |
| 51 | mov w0, wzr |
| 52 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 53 | endfunc console_cdns_core_init |
| 54 | |
| 55 | #if MULTI_CONSOLE_API |
| 56 | .globl console_cdns_register |
| 57 | |
| 58 | /* ----------------------------------------------- |
Antonio Nino Diaz | 992c5ac | 2018-10-08 13:26:48 +0100 | [diff] [blame] | 59 | * int console_cdns_register(uint64_t baseaddr, |
| 60 | * uint32_t clock, uint32_t baud, |
| 61 | * console_cdns_t *console); |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 62 | * Function to initialize and register a new CDNS |
| 63 | * console. Storage passed in for the console struct |
| 64 | * *must* be persistent (i.e. not from the stack). |
| 65 | * In: x0 - UART register base address |
| 66 | * x1 - pointer to empty console_cdns_t struct |
| 67 | * Out: return 1 on success, 0 on error |
| 68 | * Clobber list : x0, x1, x2, x6, x7, x14 |
| 69 | * ----------------------------------------------- |
| 70 | */ |
| 71 | func console_cdns_register |
| 72 | mov x7, x30 |
| 73 | mov x6, x1 |
| 74 | cbz x6, register_fail |
| 75 | str x0, [x6, #CONSOLE_T_CDNS_BASE] |
| 76 | |
| 77 | bl console_cdns_core_init |
| 78 | cbz x0, register_fail |
| 79 | |
| 80 | mov x0, x6 |
| 81 | mov x30, v7 |
Soby Mathew | 58873ae | 2018-10-10 16:03:09 +0100 | [diff] [blame] | 82 | finish_console_register cdns putc=1, getc=1, flush=1 |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 83 | |
| 84 | register_fail: |
| 85 | ret x7 |
| 86 | endfunc console_cdns_register |
| 87 | #else |
| 88 | .globl console_core_init |
| 89 | .globl console_core_putc |
| 90 | .globl console_core_getc |
| 91 | .globl console_core_flush |
| 92 | .equ console_core_init,console_cdns_core_init |
| 93 | .equ console_core_putc,console_cdns_core_putc |
| 94 | .equ console_core_getc,console_cdns_core_getc |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 95 | .equ console_core_flush,console_cdns_core_flush |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 96 | #endif |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 97 | |
| 98 | /* -------------------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 99 | * int console_cdns_core_putc(int c, uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 100 | * Function to output a character over the console. It |
| 101 | * returns the character printed on success or -1 on error. |
| 102 | * In : w0 - character to be printed |
| 103 | * x1 - console base address |
| 104 | * Out : return -1 on error else return character. |
| 105 | * Clobber list : x2 |
| 106 | * -------------------------------------------------------- |
| 107 | */ |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 108 | func console_cdns_core_putc |
| 109 | #if ENABLE_ASSERTIONS |
| 110 | cmp x1, #0 |
| 111 | ASM_ASSERT(ne) |
| 112 | #endif /* ENABLE_ASSERTIONS */ |
| 113 | |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 114 | /* Prepend '\r' to '\n' */ |
| 115 | cmp w0, #0xA |
| 116 | b.ne 2f |
| 117 | 1: |
| 118 | /* Check if the transmit FIFO is full */ |
| 119 | ldr w2, [x1, #R_UART_SR] |
| 120 | tbnz w2, #UART_SR_INTR_TFUL_BIT, 1b |
| 121 | mov w2, #0xD |
| 122 | str w2, [x1, #R_UART_TX] |
| 123 | 2: |
| 124 | /* Check if the transmit FIFO is full */ |
| 125 | ldr w2, [x1, #R_UART_SR] |
| 126 | tbnz w2, #UART_SR_INTR_TFUL_BIT, 2b |
| 127 | str w0, [x1, #R_UART_TX] |
| 128 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 129 | endfunc console_cdns_core_putc |
| 130 | |
| 131 | /* -------------------------------------------------------- |
| 132 | * int console_cdns_putc(int c, console_cdns_t *cdns) |
| 133 | * Function to output a character over the console. It |
| 134 | * returns the character printed on success or -1 on error. |
| 135 | * In : w0 - character to be printed |
| 136 | * x1 - pointer to console_t structure |
| 137 | * Out : return -1 on error else return character. |
| 138 | * Clobber list : x2 |
| 139 | * -------------------------------------------------------- |
| 140 | */ |
| 141 | func console_cdns_putc |
| 142 | #if ENABLE_ASSERTIONS |
| 143 | cmp x1, #0 |
| 144 | ASM_ASSERT(ne) |
| 145 | #endif /* ENABLE_ASSERTIONS */ |
| 146 | ldr x1, [x1, #CONSOLE_T_CDNS_BASE] |
| 147 | b console_cdns_core_putc |
| 148 | endfunc console_cdns_putc |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 149 | |
| 150 | /* --------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 151 | * int console_cdns_core_getc(uintptr_t base_addr) |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 152 | * Function to get a character from the console. |
| 153 | * It returns the character grabbed on success |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 154 | * or -1 if no character is available. |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 155 | * In : x0 - console base address |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 156 | * Out: w0 - character if available, else -1 |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 157 | * Clobber list : x0, x1 |
| 158 | * --------------------------------------------- |
| 159 | */ |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 160 | func console_cdns_core_getc |
| 161 | #if ENABLE_ASSERTIONS |
| 162 | cmp x0, #0 |
| 163 | ASM_ASSERT(ne) |
| 164 | #endif /* ENABLE_ASSERTIONS */ |
| 165 | |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 166 | /* Check if the receive FIFO is empty */ |
| 167 | ldr w1, [x0, #R_UART_SR] |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 168 | tbnz w1, #UART_SR_INTR_REMPTY_BIT, no_char |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 169 | ldr w1, [x0, #R_UART_RX] |
| 170 | mov w0, w1 |
| 171 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 172 | no_char: |
| 173 | mov w0, #ERROR_NO_PENDING_CHAR |
Soby Mathew | 7abebe8 | 2016-08-08 12:38:52 +0100 | [diff] [blame] | 174 | ret |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 175 | endfunc console_cdns_core_getc |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 176 | |
| 177 | /* --------------------------------------------- |
Julius Werner | 1343ad5 | 2017-09-18 17:01:06 -0700 | [diff] [blame] | 178 | * int console_cdns_getc(console_cdns_t *console) |
| 179 | * Function to get a character from the console. |
| 180 | * It returns the character grabbed on success |
| 181 | * or -1 if no character is available. |
| 182 | * In : x0 - pointer to console_t structure |
| 183 | * Out: w0 - character if available, else -1 |
| 184 | * Clobber list : x0, x1 |
| 185 | * --------------------------------------------- |
| 186 | */ |
| 187 | func console_cdns_getc |
| 188 | #if ENABLE_ASSERTIONS |
| 189 | cmp x0, #0 |
| 190 | ASM_ASSERT(ne) |
| 191 | #endif /* ENABLE_ASSERTIONS */ |
| 192 | ldr x0, [x0, #CONSOLE_T_CDNS_BASE] |
| 193 | b console_cdns_core_getc |
| 194 | endfunc console_cdns_getc |
| 195 | |
| 196 | /* --------------------------------------------- |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 197 | * int console_cdns_core_flush(uintptr_t base_addr) |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 198 | * Function to force a write of all buffered |
| 199 | * data that hasn't been output. |
| 200 | * In : x0 - console base address |
| 201 | * Out : return -1 on error else return 0. |
| 202 | * Clobber list : x0, x1 |
| 203 | * --------------------------------------------- |
| 204 | */ |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 205 | func console_cdns_core_flush |
| 206 | #if ENABLE_ASSERTIONS |
| 207 | cmp x0, #0 |
| 208 | ASM_ASSERT(ne) |
| 209 | #endif /* ENABLE_ASSERTIONS */ |
Antonio Nino Diaz | 56ec1d5 | 2017-02-08 15:58:12 +0000 | [diff] [blame] | 210 | /* Placeholder */ |
| 211 | mov w0, #0 |
| 212 | ret |
Antonio Nino Diaz | ebfa408 | 2018-09-24 22:07:58 +0100 | [diff] [blame] | 213 | endfunc console_cdns_core_flush |
| 214 | |
| 215 | /* --------------------------------------------- |
| 216 | * int console_cdns_flush(console_pl011_t *console) |
| 217 | * Function to force a write of all buffered |
| 218 | * data that hasn't been output. |
| 219 | * In : x0 - pointer to console_t structure |
| 220 | * Out : return -1 on error else return 0. |
| 221 | * Clobber list : x0, x1 |
| 222 | * --------------------------------------------- |
| 223 | */ |
| 224 | func console_cdns_flush |
| 225 | #if ENABLE_ASSERTIONS |
| 226 | cmp x0, #0 |
| 227 | ASM_ASSERT(ne) |
| 228 | #endif /* ENABLE_ASSERTIONS */ |
| 229 | ldr x0, [x0, #CONSOLE_T_CDNS_BASE] |
| 230 | b console_cdns_core_flush |
| 231 | endfunc console_cdns_flush |