blob: c695ddec46ca57b89c7729f2c603b8e794ac935c [file] [log] [blame]
Soby Mathew7abebe82016-08-08 12:38:52 +01001/*
Antonio Nino Diaz8377ae42017-02-06 16:03:41 +00002 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
Soby Mathew7abebe82016-08-08 12:38:52 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew7abebe82016-08-08 12:38:52 +01005 */
6#include <asm_macros.S>
Julius Werner94f89072017-07-31 18:15:11 -07007#include <console_macros.S>
Soby Mathew7abebe82016-08-08 12:38:52 +01008
9 /*
Julius Werner94f89072017-07-31 18:15:11 -070010 * This file contains a skeleton console driver that can be used as
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* take care 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 registers
23 * X16 and X17, but may never depend on them retaining their values
24 * across any function call.)
Soby Mathew7abebe82016-08-08 12:38:52 +010025 */
26
Julius Werner94f89072017-07-31 18:15:11 -070027 .globl console_xxx_register
28 .globl console_xxx_putc
29 .globl console_xxx_getc
30 .globl console_xxx_flush
Soby Mathew7abebe82016-08-08 12:38:52 +010031
32 /* -----------------------------------------------
Julius Werner94f89072017-07-31 18:15:11 -070033 * 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 : x0 - pointer to empty console_t structure
41 * x1 through x7: additional parameters as desired
42 * Out: x0 - 1 on success, 0 on error
43 * Clobber list : x0 - x7
Soby Mathew7abebe82016-08-08 12:38:52 +010044 * -----------------------------------------------
45 */
Julius Werner94f89072017-07-31 18:15:11 -070046func 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 */
53 str x1, [x0, #CONSOLE_T_XXX_BASE]
54 str x2, [x0, #CONSOLE_T_XXX_SOME_OTHER_VALUE]
55
56 /*
57 * Initialize console hardware, using x1 - x7 parameters as needed.
58 * Keep console_t pointer in x0 for later.
59 */
60
Soby Mathew58873ae2018-10-10 16:03:09 +010061 /*
62 * Macro to finish up registration and return (needs valid x0 + x30).
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
Julius Werner94f89072017-07-31 18:15:11 -070067
68 /* Jump here if hardware init fails or parameters are invalid. */
69register_fail:
70 mov w0, #0
Soby Mathew7abebe82016-08-08 12:38:52 +010071 ret
Julius Werner94f89072017-07-31 18:15:11 -070072endfunc console_xxx_register
Soby Mathew7abebe82016-08-08 12:38:52 +010073
74 /* --------------------------------------------------------
Julius Werner94f89072017-07-31 18:15:11 -070075 * int console_xxx_putc(int c, console_xxx_t *console)
Soby Mathew7abebe82016-08-08 12:38:52 +010076 * Function to output a character over the console. It
77 * returns the character printed on success or -1 on error.
78 * In : w0 - character to be printed
Julius Werner94f89072017-07-31 18:15:11 -070079 * x1 - pointer to console_t struct
80 * Out: w0 - printed character on success, < 0 on error.
81 * Clobber list : x0, x1, x2
Soby Mathew7abebe82016-08-08 12:38:52 +010082 * --------------------------------------------------------
83 */
Julius Werner94f89072017-07-31 18:15:11 -070084func console_xxx_putc
85 /*
86 * Retrieve values we need (e.g. hardware base address) from
87 * console_xxx_t structure pointed to by x1.
88 * Example:
89 */
90 ldr x1, [x1, #CONSOLE_T_XXX_BASE]
91
92 /*
93 * Write w0 to hardware.
94 */
95
Soby Mathew7abebe82016-08-08 12:38:52 +010096 ret
Julius Werner94f89072017-07-31 18:15:11 -070097
98 /* Jump here if output fails for any reason. */
Soby Mathew7abebe82016-08-08 12:38:52 +010099putc_error:
100 mov w0, #-1
101 ret
Julius Werner94f89072017-07-31 18:15:11 -0700102endfunc console_xxx_putc
Soby Mathew7abebe82016-08-08 12:38:52 +0100103
104 /* ---------------------------------------------
Julius Werner94f89072017-07-31 18:15:11 -0700105 * int console_xxx_getc(console_xxx_t *console)
Soby Mathew7abebe82016-08-08 12:38:52 +0100106 * Function to get a character from the console.
Julius Werner94f89072017-07-31 18:15:11 -0700107 * 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 : x0 - pointer to console_t struct
116 * Out: w0 - character on success,
117 * ERROR_NO_PENDING_CHAR if no char,
118 * < -1 on error
Soby Mathew7abebe82016-08-08 12:38:52 +0100119 * Clobber list : x0, x1
120 * ---------------------------------------------
121 */
Julius Werner94f89072017-07-31 18:15:11 -0700122func console_xxx_getc
123 /*
124 * Retrieve values we need (e.g. hardware base address) from
125 * console_xxx_t structure pointed to by x0.
126 * Example:
127 */
128 ldr x1, [x0, #CONSOLE_T_XXX_BASE]
129
130 /*
131 * Try to read character into w0 from hardware.
132 */
133
Soby Mathew7abebe82016-08-08 12:38:52 +0100134 ret
Julius Werner94f89072017-07-31 18:15:11 -0700135
136 /* Jump here if there is no character available at this time. */
137getc_no_char:
138 mov w0, #ERROR_NO_PENDING_CHAR
139 ret
140
141 /* Jump here if there was any hardware error. */
Soby Mathew7abebe82016-08-08 12:38:52 +0100142getc_error:
Julius Werner94f89072017-07-31 18:15:11 -0700143 mov w0, #-2 /* may pick error codes between -2 and -127 */
Soby Mathew7abebe82016-08-08 12:38:52 +0100144 ret
Julius Werner94f89072017-07-31 18:15:11 -0700145endfunc console_xxx_getc
Antonio Nino Diaz8377ae42017-02-06 16:03:41 +0000146
147 /* ---------------------------------------------
Julius Werner94f89072017-07-31 18:15:11 -0700148 * 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.
Julius Werner94f89072017-07-31 18:15:11 -0700151 * In : x0 - pointer to console_xxx_t struct
152 * Out: w0 - 0 on success, < 0 on error
153 * Clobber list : x0, x1, x2, x3, x4, x5
Antonio Nino Diaz8377ae42017-02-06 16:03:41 +0000154 * ---------------------------------------------
155 */
Julius Werner94f89072017-07-31 18:15:11 -0700156func console_xxx_flush
157 /*
158 * Retrieve values we need (e.g. hardware base address) from
159 * console_xxx_t structure pointed to by x0.
160 * Example:
161 */
162 ldr x1, [x0, #CONSOLE_T_XXX_BASE]
163
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 mov w0, #0
170 ret
Julius Werner94f89072017-07-31 18:15:11 -0700171
172 /* Jump here if an unrecoverable error has been encountered. */
Antonio Nino Diaz8377ae42017-02-06 16:03:41 +0000173flush_error:
174 mov w0, #-1
175 ret
Julius Werner94f89072017-07-31 18:15:11 -0700176endfunc console_xxx_flush