shared_console.S 5.3 KB

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