blob: a9e13ec44c96c4e9c656232664a05ddb3617febd [file] [log] [blame]
Soby Mathew420cc372016-03-24 16:52:40 +00001/*
Jimmy Brisson39f9eee2020-08-05 13:44:05 -05002 * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved.
Soby Mathew420cc372016-03-24 16:52:40 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew420cc372016-03-24 16:52:40 +00005 */
6#include <asm_macros.S>
Ambroise Vincent35e08da2019-05-31 16:21:59 +01007#include <console_macros.S>
Soby Mathew420cc372016-03-24 16:52:40 +00008
9 /*
Ambroise Vincent35e08da2019-05-31 16:21:59 +010010 * This file contains a skeleton console driver that can be used as a
11 * basis for a real console driver. Console drivers in Trusted Firmware
12 * can be instantiated multiple times. Each instance is described by a
13 * separate console_t structure which must be registered with the common
14 * console framework via console_register(). Console drivers should
15 * define a console_xxx_register() function that initializes a new
16 * console_t structure passed in from the caller and registers it after
17 * initializing the console hardware. Drivers may define their own
18 * structures extending console_t to store private driver information.
19 * Console drivers *MUST* ensure that the console callbacks they
20 * implement only change registers allowed in the clobber lists defined
21 * in this file. (Note that in addition to the explicit clobber lists,
22 * any function may always clobber the intra-procedure-call register
23 * r12, but may never depend on it retaining its value across any
24 * function call.)
Soby Mathew420cc372016-03-24 16:52:40 +000025 */
26
Ambroise Vincent35e08da2019-05-31 16:21:59 +010027 .globl console_xxx_register
28 .globl console_xxx_putc
29 .globl console_xxx_getc
30 .globl console_xxx_flush
Soby Mathew420cc372016-03-24 16:52:40 +000031
32 /* -----------------------------------------------
Ambroise Vincent35e08da2019-05-31 16:21:59 +010033 * int console_xxx_register(console_xxx_t *console,
34 * ...additional parameters as desired...)
35 * Function to initialize and register the console.
36 * The caller needs to pass an empty console_xxx_t
37 * structure in which *MUST* be allocated in
38 * persistent memory (e.g. a global or static local
39 * variable, *NOT* on the stack).
40 * In : r0 - pointer to empty console_t structure
41 * r1 through r7: additional parameters as desired
42 * Out: r0 - 1 on success, 0 on error
43 * Clobber list : r0 - r7
Soby Mathew420cc372016-03-24 16:52:40 +000044 * -----------------------------------------------
45 */
Ambroise Vincent35e08da2019-05-31 16:21:59 +010046func console_xxx_register
47 /*
48 * Store parameters (e.g. hardware base address) in driver-specific
49 * console_xxx_t structure field if they will need to be retrieved
50 * by later console callback (e.g. putc).
51 * Example:
52 */
Andre Przywarabc39cac2020-01-25 00:58:35 +000053 str r1, [r0, #CONSOLE_T_BASE]
Ambroise Vincent35e08da2019-05-31 16:21:59 +010054 str r2, [r0, #CONSOLE_T_XXX_SOME_OTHER_VALUE]
55
56 /*
57 * Initialize console hardware, using r1 - r7 parameters as needed.
58 * Keep console_t pointer in r0 for later.
59 */
60
61 /*
62 * Macro to finish up registration and return (needs valid r0 + lr).
63 * If any of the argument is unspecified, then the corresponding
64 * entry in console_t is set to 0.
65 */
66 finish_console_register xxx putc=1, getc=1, flush=1
67
68 /* Jump here if hardware init fails or parameters are invalid. */
69register_fail:
Soby Mathew420cc372016-03-24 16:52:40 +000070 mov r0, #0
71 bx lr
Ambroise Vincent35e08da2019-05-31 16:21:59 +010072endfunc console_xxx_register
Soby Mathew420cc372016-03-24 16:52:40 +000073
74 /* --------------------------------------------------------
Ambroise Vincent35e08da2019-05-31 16:21:59 +010075 * int console_xxx_putc(int c, console_xxx_t *console)
Soby Mathew420cc372016-03-24 16:52:40 +000076 * Function to output a character over the console. It
77 * returns the character printed on success or -1 on error.
78 * In : r0 - character to be printed
Ambroise Vincent35e08da2019-05-31 16:21:59 +010079 * r1 - pointer to console_t struct
80 * Out: r0 - printed character on success, < 0 on error.
81 * Clobber list : r0, r1, r2
Soby Mathew420cc372016-03-24 16:52:40 +000082 * --------------------------------------------------------
83 */
Ambroise Vincent35e08da2019-05-31 16:21:59 +010084func console_xxx_putc
85 /*
86 * Retrieve values we need (e.g. hardware base address) from
87 * console_xxx_t structure pointed to by r1.
88 * Example:
89 */
Andre Przywarabc39cac2020-01-25 00:58:35 +000090 ldr r1, [r1, #CONSOLE_T_BASE]
Ambroise Vincent35e08da2019-05-31 16:21:59 +010091
92 /*
93 * Write r0 to hardware.
94 */
95
Soby Mathew420cc372016-03-24 16:52:40 +000096 bx lr
Ambroise Vincent35e08da2019-05-31 16:21:59 +010097
98 /* Jump here if output fails for any reason. */
Soby Mathew420cc372016-03-24 16:52:40 +000099putc_error:
100 mov r0, #-1
101 bx lr
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100102endfunc console_xxx_putc
Soby Mathew420cc372016-03-24 16:52:40 +0000103
104 /* ---------------------------------------------
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100105 * int console_xxx_getc(console_xxx_t *console)
Soby Mathew420cc372016-03-24 16:52:40 +0000106 * Function to get a character from the console.
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100107 * Even though console_getc() is blocking, this
108 * callback has to be non-blocking and always
109 * return immediately to allow polling multiple
110 * drivers concurrently.
111 * Returns the character grabbed on success,
112 * ERROR_NO_PENDING_CHAR if no character was
113 * available at this time, or any value
114 * between -2 and -127 if there was an error.
115 * In : r0 - pointer to console_t struct
116 * Out: r0 - character on success,
117 * ERROR_NO_PENDING_CHAR if no char,
118 * < -1 on error
Soby Mathew420cc372016-03-24 16:52:40 +0000119 * Clobber list : r0, r1
120 * ---------------------------------------------
121 */
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100122func console_xxx_getc
123 /*
124 * Retrieve values we need (e.g. hardware base address) from
125 * console_xxx_t structure pointed to by r0.
126 * Example:
127 */
Andre Przywarabc39cac2020-01-25 00:58:35 +0000128 ldr r1, [r0, #CONSOLE_T_BASE]
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100129
130 /*
131 * Try to read character into r0 from hardware.
132 */
133
Soby Mathew420cc372016-03-24 16:52:40 +0000134 bx lr
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100135
136 /* Jump here if there is no character available at this time. */
137getc_no_char:
138 mov r0, #ERROR_NO_PENDING_CHAR
139 bx lr
140
141 /* Jump here if there was any hardware error. */
Soby Mathew420cc372016-03-24 16:52:40 +0000142getc_error:
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100143 mov r0, #-2 /* may pick error codes between -2 and -127 */
Soby Mathew420cc372016-03-24 16:52:40 +0000144 bx lr
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100145endfunc console_xxx_getc
Antonio Nino Diaz8377ae42017-02-06 16:03:41 +0000146
147 /* ---------------------------------------------
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100148 * int console_xxx_flush(console_xxx_t *console)
Antonio Nino Diaz8377ae42017-02-06 16:03:41 +0000149 * Function to force a write of all buffered
150 * data that hasn't been output.
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100151 * In : r0 - pointer to console_xxx_t struct
Jimmy Brisson39f9eee2020-08-05 13:44:05 -0500152 * Out: void
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100153 * Clobber list : r0, r1, r2, r3, r4, r5
Antonio Nino Diaz8377ae42017-02-06 16:03:41 +0000154 * ---------------------------------------------
155 */
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100156func console_xxx_flush
157 /*
158 * Retrieve values we need (e.g. hardware base address) from
159 * console_xxx_t structure pointed to by r0.
160 * Example:
161 */
Andre Przywarabc39cac2020-01-25 00:58:35 +0000162 ldr r1, [r0, #CONSOLE_T_BASE]
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100163
164 /*
165 * Flush all remaining output from hardware FIFOs. Do not return until
166 * all data has been flushed or there was an unrecoverable error.
167 */
168
Antonio Nino Diaz8377ae42017-02-06 16:03:41 +0000169 bx lr
Ambroise Vincent35e08da2019-05-31 16:21:59 +0100170endfunc console_xxx_flush