Commit 34b5b76b42226a2dcb2962f8a52ae581d6d24fb6
Committed by
Peng Fan
1 parent
5b27f2dca5
Exists in
smarc_8mq-imx_v2020.04_5.4.24_2.1.0
and in
1 other branch
MA-14318-1 Support dual bootloader for xen
Trusty is not supported for xen so we don't need to check the keyslot package or rollback index in spl. Reassign the dram address for spl and u-boot to avoid conflicts. Support serial init functions to enable debug console in spl when xen is running. Test: Boot and A/B slot switch on imx8qm_mek. Change-Id: If6829252f1ec2e32255f951715c8747181951fd0 Signed-off-by: Ji Luo <ji.luo@nxp.com> Reviewed-by: Peng Fan <peng.fan@nxp.com> (cherry picked from commit 30beee3fe6d4b35166c6e17203909231d33bc2db) (cherry picked from commit a4ffa905d90d14ccdd146e4b38a69d40a568b747) (cherry picked from commit 4729a057e8ad699ec01357dd219abdf296afe354)
Showing 3 changed files with 61 additions and 6 deletions Inline Diff
drivers/serial/serial.c
1 | // SPDX-License-Identifier: GPL-2.0+ | 1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | /* | 2 | /* |
3 | * (C) Copyright 2004 | 3 | * (C) Copyright 2004 |
4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <common.h> | 7 | #include <common.h> |
8 | #include <env_internal.h> | 8 | #include <env_internal.h> |
9 | #include <hang.h> | 9 | #include <hang.h> |
10 | #include <serial.h> | 10 | #include <serial.h> |
11 | #include <stdio_dev.h> | 11 | #include <stdio_dev.h> |
12 | #include <post.h> | 12 | #include <post.h> |
13 | #include <linux/compiler.h> | 13 | #include <linux/compiler.h> |
14 | #include <errno.h> | 14 | #include <errno.h> |
15 | 15 | ||
16 | DECLARE_GLOBAL_DATA_PTR; | 16 | DECLARE_GLOBAL_DATA_PTR; |
17 | 17 | ||
18 | static struct serial_device *serial_devices; | 18 | static struct serial_device *serial_devices; |
19 | static struct serial_device *serial_current; | 19 | static struct serial_device *serial_current; |
20 | /* | 20 | /* |
21 | * Table with supported baudrates (defined in config_xyz.h) | 21 | * Table with supported baudrates (defined in config_xyz.h) |
22 | */ | 22 | */ |
23 | static const unsigned long baudrate_table[] = CONFIG_SYS_BAUDRATE_TABLE; | 23 | static const unsigned long baudrate_table[] = CONFIG_SYS_BAUDRATE_TABLE; |
24 | 24 | ||
25 | /** | 25 | /** |
26 | * serial_null() - Void registration routine of a serial driver | 26 | * serial_null() - Void registration routine of a serial driver |
27 | * | 27 | * |
28 | * This routine implements a void registration routine of a serial | 28 | * This routine implements a void registration routine of a serial |
29 | * driver. The registration routine of a particular driver is aliased | 29 | * driver. The registration routine of a particular driver is aliased |
30 | * to this empty function in case the driver is not compiled into | 30 | * to this empty function in case the driver is not compiled into |
31 | * U-Boot. | 31 | * U-Boot. |
32 | */ | 32 | */ |
33 | static void serial_null(void) | 33 | static void serial_null(void) |
34 | { | 34 | { |
35 | } | 35 | } |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * on_baudrate() - Update the actual baudrate when the env var changes | 38 | * on_baudrate() - Update the actual baudrate when the env var changes |
39 | * | 39 | * |
40 | * @name: changed environment variable | 40 | * @name: changed environment variable |
41 | * @value: new value of the environment variable | 41 | * @value: new value of the environment variable |
42 | * @op: operation (create, overwrite, or delete) | 42 | * @op: operation (create, overwrite, or delete) |
43 | * @flags: attributes of environment variable change, | 43 | * @flags: attributes of environment variable change, |
44 | * see flags H_* in include/search.h | 44 | * see flags H_* in include/search.h |
45 | * | 45 | * |
46 | * This will check for a valid baudrate and only apply it if valid. | 46 | * This will check for a valid baudrate and only apply it if valid. |
47 | * | 47 | * |
48 | * Return: 0 on success, 1 on error | 48 | * Return: 0 on success, 1 on error |
49 | */ | 49 | */ |
50 | static int on_baudrate(const char *name, const char *value, enum env_op op, | 50 | static int on_baudrate(const char *name, const char *value, enum env_op op, |
51 | int flags) | 51 | int flags) |
52 | { | 52 | { |
53 | int i; | 53 | int i; |
54 | int baudrate; | 54 | int baudrate; |
55 | 55 | ||
56 | switch (op) { | 56 | switch (op) { |
57 | case env_op_create: | 57 | case env_op_create: |
58 | case env_op_overwrite: | 58 | case env_op_overwrite: |
59 | /* | 59 | /* |
60 | * Switch to new baudrate if new baudrate is supported | 60 | * Switch to new baudrate if new baudrate is supported |
61 | */ | 61 | */ |
62 | baudrate = simple_strtoul(value, NULL, 10); | 62 | baudrate = simple_strtoul(value, NULL, 10); |
63 | 63 | ||
64 | /* Not actually changing */ | 64 | /* Not actually changing */ |
65 | if (gd->baudrate == baudrate) | 65 | if (gd->baudrate == baudrate) |
66 | return 0; | 66 | return 0; |
67 | 67 | ||
68 | for (i = 0; i < ARRAY_SIZE(baudrate_table); ++i) { | 68 | for (i = 0; i < ARRAY_SIZE(baudrate_table); ++i) { |
69 | if (baudrate == baudrate_table[i]) | 69 | if (baudrate == baudrate_table[i]) |
70 | break; | 70 | break; |
71 | } | 71 | } |
72 | if (i == ARRAY_SIZE(baudrate_table)) { | 72 | if (i == ARRAY_SIZE(baudrate_table)) { |
73 | if ((flags & H_FORCE) == 0) | 73 | if ((flags & H_FORCE) == 0) |
74 | printf("## Baudrate %d bps not supported\n", | 74 | printf("## Baudrate %d bps not supported\n", |
75 | baudrate); | 75 | baudrate); |
76 | return 1; | 76 | return 1; |
77 | } | 77 | } |
78 | if ((flags & H_INTERACTIVE) != 0) { | 78 | if ((flags & H_INTERACTIVE) != 0) { |
79 | printf("## Switch baudrate to %d" | 79 | printf("## Switch baudrate to %d" |
80 | " bps and press ENTER ...\n", baudrate); | 80 | " bps and press ENTER ...\n", baudrate); |
81 | udelay(50000); | 81 | udelay(50000); |
82 | } | 82 | } |
83 | 83 | ||
84 | gd->baudrate = baudrate; | 84 | gd->baudrate = baudrate; |
85 | 85 | ||
86 | serial_setbrg(); | 86 | serial_setbrg(); |
87 | 87 | ||
88 | udelay(50000); | 88 | udelay(50000); |
89 | 89 | ||
90 | if ((flags & H_INTERACTIVE) != 0) | 90 | if ((flags & H_INTERACTIVE) != 0) |
91 | while (1) { | 91 | while (1) { |
92 | if (getc() == '\r') | 92 | if (getc() == '\r') |
93 | break; | 93 | break; |
94 | } | 94 | } |
95 | 95 | ||
96 | return 0; | 96 | return 0; |
97 | case env_op_delete: | 97 | case env_op_delete: |
98 | printf("## Baudrate may not be deleted\n"); | 98 | printf("## Baudrate may not be deleted\n"); |
99 | return 1; | 99 | return 1; |
100 | default: | 100 | default: |
101 | return 0; | 101 | return 0; |
102 | } | 102 | } |
103 | } | 103 | } |
104 | U_BOOT_ENV_CALLBACK(baudrate, on_baudrate); | 104 | U_BOOT_ENV_CALLBACK(baudrate, on_baudrate); |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * serial_initfunc() - Forward declare of driver registration routine | 107 | * serial_initfunc() - Forward declare of driver registration routine |
108 | * @name: Name of the real driver registration routine. | 108 | * @name: Name of the real driver registration routine. |
109 | * | 109 | * |
110 | * This macro expands onto forward declaration of a driver registration | 110 | * This macro expands onto forward declaration of a driver registration |
111 | * routine, which is then used below in serial_initialize() function. | 111 | * routine, which is then used below in serial_initialize() function. |
112 | * The declaration is made weak and aliases to serial_null() so in case | 112 | * The declaration is made weak and aliases to serial_null() so in case |
113 | * the driver is not compiled in, the function is still declared and can | 113 | * the driver is not compiled in, the function is still declared and can |
114 | * be used, but aliases to serial_null() and thus is optimized away. | 114 | * be used, but aliases to serial_null() and thus is optimized away. |
115 | */ | 115 | */ |
116 | #define serial_initfunc(name) \ | 116 | #define serial_initfunc(name) \ |
117 | void name(void) \ | 117 | void name(void) \ |
118 | __attribute__((weak, alias("serial_null"))); | 118 | __attribute__((weak, alias("serial_null"))); |
119 | 119 | ||
120 | serial_initfunc(atmel_serial_initialize); | 120 | serial_initfunc(atmel_serial_initialize); |
121 | serial_initfunc(mcf_serial_initialize); | 121 | serial_initfunc(mcf_serial_initialize); |
122 | serial_initfunc(mpc85xx_serial_initialize); | 122 | serial_initfunc(mpc85xx_serial_initialize); |
123 | serial_initfunc(mxc_serial_initialize); | 123 | serial_initfunc(mxc_serial_initialize); |
124 | serial_initfunc(xen_serial_initialize); | ||
124 | serial_initfunc(ns16550_serial_initialize); | 125 | serial_initfunc(ns16550_serial_initialize); |
125 | serial_initfunc(pl01x_serial_initialize); | 126 | serial_initfunc(pl01x_serial_initialize); |
126 | serial_initfunc(pxa_serial_initialize); | 127 | serial_initfunc(pxa_serial_initialize); |
127 | serial_initfunc(sh_serial_initialize); | 128 | serial_initfunc(sh_serial_initialize); |
128 | serial_initfunc(mtk_serial_initialize); | 129 | serial_initfunc(mtk_serial_initialize); |
129 | serial_initfunc(xen_debug_serial_initialize); | 130 | serial_initfunc(xen_debug_serial_initialize); |
130 | 131 | ||
131 | /** | 132 | /** |
132 | * serial_register() - Register serial driver with serial driver core | 133 | * serial_register() - Register serial driver with serial driver core |
133 | * @dev: Pointer to the serial driver structure | 134 | * @dev: Pointer to the serial driver structure |
134 | * | 135 | * |
135 | * This function registers the serial driver supplied via @dev with | 136 | * This function registers the serial driver supplied via @dev with |
136 | * serial driver core, thus making U-Boot aware of it and making it | 137 | * serial driver core, thus making U-Boot aware of it and making it |
137 | * available for U-Boot to use. On platforms that still require manual | 138 | * available for U-Boot to use. On platforms that still require manual |
138 | * relocation of constant variables, relocation of the supplied structure | 139 | * relocation of constant variables, relocation of the supplied structure |
139 | * is performed. | 140 | * is performed. |
140 | */ | 141 | */ |
141 | void serial_register(struct serial_device *dev) | 142 | void serial_register(struct serial_device *dev) |
142 | { | 143 | { |
143 | #ifdef CONFIG_NEEDS_MANUAL_RELOC | 144 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
144 | if (dev->start) | 145 | if (dev->start) |
145 | dev->start += gd->reloc_off; | 146 | dev->start += gd->reloc_off; |
146 | if (dev->stop) | 147 | if (dev->stop) |
147 | dev->stop += gd->reloc_off; | 148 | dev->stop += gd->reloc_off; |
148 | if (dev->setbrg) | 149 | if (dev->setbrg) |
149 | dev->setbrg += gd->reloc_off; | 150 | dev->setbrg += gd->reloc_off; |
150 | if (dev->getc) | 151 | if (dev->getc) |
151 | dev->getc += gd->reloc_off; | 152 | dev->getc += gd->reloc_off; |
152 | if (dev->tstc) | 153 | if (dev->tstc) |
153 | dev->tstc += gd->reloc_off; | 154 | dev->tstc += gd->reloc_off; |
154 | if (dev->putc) | 155 | if (dev->putc) |
155 | dev->putc += gd->reloc_off; | 156 | dev->putc += gd->reloc_off; |
156 | if (dev->puts) | 157 | if (dev->puts) |
157 | dev->puts += gd->reloc_off; | 158 | dev->puts += gd->reloc_off; |
158 | #endif | 159 | #endif |
159 | 160 | ||
160 | dev->next = serial_devices; | 161 | dev->next = serial_devices; |
161 | serial_devices = dev; | 162 | serial_devices = dev; |
162 | } | 163 | } |
163 | 164 | ||
164 | /** | 165 | /** |
165 | * serial_initialize() - Register all compiled-in serial port drivers | 166 | * serial_initialize() - Register all compiled-in serial port drivers |
166 | * | 167 | * |
167 | * This function registers all serial port drivers that are compiled | 168 | * This function registers all serial port drivers that are compiled |
168 | * into the U-Boot binary with the serial core, thus making them | 169 | * into the U-Boot binary with the serial core, thus making them |
169 | * available to U-Boot to use. Lastly, this function assigns a default | 170 | * available to U-Boot to use. Lastly, this function assigns a default |
170 | * serial port to the serial core. That serial port is then used as a | 171 | * serial port to the serial core. That serial port is then used as a |
171 | * default output. | 172 | * default output. |
172 | */ | 173 | */ |
173 | void serial_initialize(void) | 174 | void serial_initialize(void) |
174 | { | 175 | { |
175 | atmel_serial_initialize(); | 176 | atmel_serial_initialize(); |
176 | mcf_serial_initialize(); | 177 | mcf_serial_initialize(); |
177 | mpc85xx_serial_initialize(); | 178 | mpc85xx_serial_initialize(); |
178 | mxc_serial_initialize(); | 179 | mxc_serial_initialize(); |
180 | xen_serial_initialize(); | ||
179 | ns16550_serial_initialize(); | 181 | ns16550_serial_initialize(); |
180 | pl01x_serial_initialize(); | 182 | pl01x_serial_initialize(); |
181 | pxa_serial_initialize(); | 183 | pxa_serial_initialize(); |
182 | sh_serial_initialize(); | 184 | sh_serial_initialize(); |
183 | mtk_serial_initialize(); | 185 | mtk_serial_initialize(); |
184 | xen_debug_serial_initialize(); | 186 | xen_debug_serial_initialize(); |
185 | 187 | ||
186 | serial_assign(default_serial_console()->name); | 188 | serial_assign(default_serial_console()->name); |
187 | } | 189 | } |
188 | 190 | ||
189 | static int serial_stub_start(struct stdio_dev *sdev) | 191 | static int serial_stub_start(struct stdio_dev *sdev) |
190 | { | 192 | { |
191 | struct serial_device *dev = sdev->priv; | 193 | struct serial_device *dev = sdev->priv; |
192 | 194 | ||
193 | return dev->start(); | 195 | return dev->start(); |
194 | } | 196 | } |
195 | 197 | ||
196 | static int serial_stub_stop(struct stdio_dev *sdev) | 198 | static int serial_stub_stop(struct stdio_dev *sdev) |
197 | { | 199 | { |
198 | struct serial_device *dev = sdev->priv; | 200 | struct serial_device *dev = sdev->priv; |
199 | 201 | ||
200 | return dev->stop(); | 202 | return dev->stop(); |
201 | } | 203 | } |
202 | 204 | ||
203 | static void serial_stub_putc(struct stdio_dev *sdev, const char ch) | 205 | static void serial_stub_putc(struct stdio_dev *sdev, const char ch) |
204 | { | 206 | { |
205 | struct serial_device *dev = sdev->priv; | 207 | struct serial_device *dev = sdev->priv; |
206 | 208 | ||
207 | dev->putc(ch); | 209 | dev->putc(ch); |
208 | } | 210 | } |
209 | 211 | ||
210 | static void serial_stub_puts(struct stdio_dev *sdev, const char *str) | 212 | static void serial_stub_puts(struct stdio_dev *sdev, const char *str) |
211 | { | 213 | { |
212 | struct serial_device *dev = sdev->priv; | 214 | struct serial_device *dev = sdev->priv; |
213 | 215 | ||
214 | dev->puts(str); | 216 | dev->puts(str); |
215 | } | 217 | } |
216 | 218 | ||
217 | static int serial_stub_getc(struct stdio_dev *sdev) | 219 | static int serial_stub_getc(struct stdio_dev *sdev) |
218 | { | 220 | { |
219 | struct serial_device *dev = sdev->priv; | 221 | struct serial_device *dev = sdev->priv; |
220 | 222 | ||
221 | return dev->getc(); | 223 | return dev->getc(); |
222 | } | 224 | } |
223 | 225 | ||
224 | static int serial_stub_tstc(struct stdio_dev *sdev) | 226 | static int serial_stub_tstc(struct stdio_dev *sdev) |
225 | { | 227 | { |
226 | struct serial_device *dev = sdev->priv; | 228 | struct serial_device *dev = sdev->priv; |
227 | 229 | ||
228 | return dev->tstc(); | 230 | return dev->tstc(); |
229 | } | 231 | } |
230 | 232 | ||
231 | /** | 233 | /** |
232 | * serial_stdio_init() - Register serial ports with STDIO core | 234 | * serial_stdio_init() - Register serial ports with STDIO core |
233 | * | 235 | * |
234 | * This function generates a proxy driver for each serial port driver. | 236 | * This function generates a proxy driver for each serial port driver. |
235 | * These proxy drivers then register with the STDIO core, making the | 237 | * These proxy drivers then register with the STDIO core, making the |
236 | * serial drivers available as STDIO devices. | 238 | * serial drivers available as STDIO devices. |
237 | */ | 239 | */ |
238 | void serial_stdio_init(void) | 240 | void serial_stdio_init(void) |
239 | { | 241 | { |
240 | struct stdio_dev dev; | 242 | struct stdio_dev dev; |
241 | struct serial_device *s = serial_devices; | 243 | struct serial_device *s = serial_devices; |
242 | 244 | ||
243 | while (s) { | 245 | while (s) { |
244 | memset(&dev, 0, sizeof(dev)); | 246 | memset(&dev, 0, sizeof(dev)); |
245 | 247 | ||
246 | strcpy(dev.name, s->name); | 248 | strcpy(dev.name, s->name); |
247 | dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT; | 249 | dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT; |
248 | 250 | ||
249 | dev.start = serial_stub_start; | 251 | dev.start = serial_stub_start; |
250 | dev.stop = serial_stub_stop; | 252 | dev.stop = serial_stub_stop; |
251 | dev.putc = serial_stub_putc; | 253 | dev.putc = serial_stub_putc; |
252 | dev.puts = serial_stub_puts; | 254 | dev.puts = serial_stub_puts; |
253 | dev.getc = serial_stub_getc; | 255 | dev.getc = serial_stub_getc; |
254 | dev.tstc = serial_stub_tstc; | 256 | dev.tstc = serial_stub_tstc; |
255 | dev.priv = s; | 257 | dev.priv = s; |
256 | 258 | ||
257 | stdio_register(&dev); | 259 | stdio_register(&dev); |
258 | 260 | ||
259 | s = s->next; | 261 | s = s->next; |
260 | } | 262 | } |
261 | } | 263 | } |
262 | 264 | ||
263 | /** | 265 | /** |
264 | * serial_assign() - Select the serial output device by name | 266 | * serial_assign() - Select the serial output device by name |
265 | * @name: Name of the serial driver to be used as default output | 267 | * @name: Name of the serial driver to be used as default output |
266 | * | 268 | * |
267 | * This function configures the serial output multiplexing by | 269 | * This function configures the serial output multiplexing by |
268 | * selecting which serial device will be used as default. In case | 270 | * selecting which serial device will be used as default. In case |
269 | * the STDIO "serial" device is selected as stdin/stdout/stderr, | 271 | * the STDIO "serial" device is selected as stdin/stdout/stderr, |
270 | * the serial device previously configured by this function will be | 272 | * the serial device previously configured by this function will be |
271 | * used for the particular operation. | 273 | * used for the particular operation. |
272 | * | 274 | * |
273 | * Returns 0 on success, negative on error. | 275 | * Returns 0 on success, negative on error. |
274 | */ | 276 | */ |
275 | int serial_assign(const char *name) | 277 | int serial_assign(const char *name) |
276 | { | 278 | { |
277 | struct serial_device *s; | 279 | struct serial_device *s; |
278 | 280 | ||
279 | for (s = serial_devices; s; s = s->next) { | 281 | for (s = serial_devices; s; s = s->next) { |
280 | if (strcmp(s->name, name)) | 282 | if (strcmp(s->name, name)) |
281 | continue; | 283 | continue; |
282 | serial_current = s; | 284 | serial_current = s; |
283 | return 0; | 285 | return 0; |
284 | } | 286 | } |
285 | 287 | ||
286 | return -EINVAL; | 288 | return -EINVAL; |
287 | } | 289 | } |
288 | 290 | ||
289 | /** | 291 | /** |
290 | * serial_reinit_all() - Reinitialize all compiled-in serial ports | 292 | * serial_reinit_all() - Reinitialize all compiled-in serial ports |
291 | * | 293 | * |
292 | * This function reinitializes all serial ports that are compiled | 294 | * This function reinitializes all serial ports that are compiled |
293 | * into U-Boot by calling their serial_start() functions. | 295 | * into U-Boot by calling their serial_start() functions. |
294 | */ | 296 | */ |
295 | void serial_reinit_all(void) | 297 | void serial_reinit_all(void) |
296 | { | 298 | { |
297 | struct serial_device *s; | 299 | struct serial_device *s; |
298 | 300 | ||
299 | for (s = serial_devices; s; s = s->next) | 301 | for (s = serial_devices; s; s = s->next) |
300 | s->start(); | 302 | s->start(); |
301 | } | 303 | } |
302 | 304 | ||
303 | /** | 305 | /** |
304 | * get_current() - Return pointer to currently selected serial port | 306 | * get_current() - Return pointer to currently selected serial port |
305 | * | 307 | * |
306 | * This function returns a pointer to currently selected serial port. | 308 | * This function returns a pointer to currently selected serial port. |
307 | * The currently selected serial port is altered by serial_assign() | 309 | * The currently selected serial port is altered by serial_assign() |
308 | * function. | 310 | * function. |
309 | * | 311 | * |
310 | * In case this function is called before relocation or before any serial | 312 | * In case this function is called before relocation or before any serial |
311 | * port is configured, this function calls default_serial_console() to | 313 | * port is configured, this function calls default_serial_console() to |
312 | * determine the serial port. Otherwise, the configured serial port is | 314 | * determine the serial port. Otherwise, the configured serial port is |
313 | * returned. | 315 | * returned. |
314 | * | 316 | * |
315 | * Returns pointer to the currently selected serial port on success, | 317 | * Returns pointer to the currently selected serial port on success, |
316 | * NULL on error. | 318 | * NULL on error. |
317 | */ | 319 | */ |
318 | static struct serial_device *get_current(void) | 320 | static struct serial_device *get_current(void) |
319 | { | 321 | { |
320 | struct serial_device *dev; | 322 | struct serial_device *dev; |
321 | 323 | ||
322 | if (!(gd->flags & GD_FLG_RELOC)) | 324 | if (!(gd->flags & GD_FLG_RELOC)) |
323 | dev = default_serial_console(); | 325 | dev = default_serial_console(); |
324 | else if (!serial_current) | 326 | else if (!serial_current) |
325 | dev = default_serial_console(); | 327 | dev = default_serial_console(); |
326 | else | 328 | else |
327 | dev = serial_current; | 329 | dev = serial_current; |
328 | 330 | ||
329 | /* We must have a console device */ | 331 | /* We must have a console device */ |
330 | if (!dev) { | 332 | if (!dev) { |
331 | #ifdef CONFIG_SPL_BUILD | 333 | #ifdef CONFIG_SPL_BUILD |
332 | puts("Cannot find console\n"); | 334 | puts("Cannot find console\n"); |
333 | hang(); | 335 | hang(); |
334 | #else | 336 | #else |
335 | panic("Cannot find console\n"); | 337 | panic("Cannot find console\n"); |
336 | #endif | 338 | #endif |
337 | } | 339 | } |
338 | 340 | ||
339 | return dev; | 341 | return dev; |
340 | } | 342 | } |
341 | 343 | ||
342 | /** | 344 | /** |
343 | * serial_init() - Initialize currently selected serial port | 345 | * serial_init() - Initialize currently selected serial port |
344 | * | 346 | * |
345 | * This function initializes the currently selected serial port. This | 347 | * This function initializes the currently selected serial port. This |
346 | * usually involves setting up the registers of that particular port, | 348 | * usually involves setting up the registers of that particular port, |
347 | * enabling clock and such. This function uses the get_current() call | 349 | * enabling clock and such. This function uses the get_current() call |
348 | * to determine which port is selected. | 350 | * to determine which port is selected. |
349 | * | 351 | * |
350 | * Returns 0 on success, negative on error. | 352 | * Returns 0 on success, negative on error. |
351 | */ | 353 | */ |
352 | int serial_init(void) | 354 | int serial_init(void) |
353 | { | 355 | { |
354 | gd->flags |= GD_FLG_SERIAL_READY; | 356 | gd->flags |= GD_FLG_SERIAL_READY; |
355 | return get_current()->start(); | 357 | return get_current()->start(); |
356 | } | 358 | } |
357 | 359 | ||
358 | /** | 360 | /** |
359 | * serial_setbrg() - Configure baud-rate of currently selected serial port | 361 | * serial_setbrg() - Configure baud-rate of currently selected serial port |
360 | * | 362 | * |
361 | * This function configures the baud-rate of the currently selected | 363 | * This function configures the baud-rate of the currently selected |
362 | * serial port. The baud-rate is retrieved from global data within | 364 | * serial port. The baud-rate is retrieved from global data within |
363 | * the serial port driver. This function uses the get_current() call | 365 | * the serial port driver. This function uses the get_current() call |
364 | * to determine which port is selected. | 366 | * to determine which port is selected. |
365 | * | 367 | * |
366 | * Returns 0 on success, negative on error. | 368 | * Returns 0 on success, negative on error. |
367 | */ | 369 | */ |
368 | void serial_setbrg(void) | 370 | void serial_setbrg(void) |
369 | { | 371 | { |
370 | get_current()->setbrg(); | 372 | get_current()->setbrg(); |
371 | } | 373 | } |
372 | 374 | ||
373 | /** | 375 | /** |
374 | * serial_getc() - Read character from currently selected serial port | 376 | * serial_getc() - Read character from currently selected serial port |
375 | * | 377 | * |
376 | * This function retrieves a character from currently selected serial | 378 | * This function retrieves a character from currently selected serial |
377 | * port. In case there is no character waiting on the serial port, | 379 | * port. In case there is no character waiting on the serial port, |
378 | * this function will block and wait for the character to appear. This | 380 | * this function will block and wait for the character to appear. This |
379 | * function uses the get_current() call to determine which port is | 381 | * function uses the get_current() call to determine which port is |
380 | * selected. | 382 | * selected. |
381 | * | 383 | * |
382 | * Returns the character on success, negative on error. | 384 | * Returns the character on success, negative on error. |
383 | */ | 385 | */ |
384 | int serial_getc(void) | 386 | int serial_getc(void) |
385 | { | 387 | { |
386 | return get_current()->getc(); | 388 | return get_current()->getc(); |
387 | } | 389 | } |
388 | 390 | ||
389 | /** | 391 | /** |
390 | * serial_tstc() - Test if data is available on currently selected serial port | 392 | * serial_tstc() - Test if data is available on currently selected serial port |
391 | * | 393 | * |
392 | * This function tests if one or more characters are available on | 394 | * This function tests if one or more characters are available on |
393 | * currently selected serial port. This function never blocks. This | 395 | * currently selected serial port. This function never blocks. This |
394 | * function uses the get_current() call to determine which port is | 396 | * function uses the get_current() call to determine which port is |
395 | * selected. | 397 | * selected. |
396 | * | 398 | * |
397 | * Returns positive if character is available, zero otherwise. | 399 | * Returns positive if character is available, zero otherwise. |
398 | */ | 400 | */ |
399 | int serial_tstc(void) | 401 | int serial_tstc(void) |
400 | { | 402 | { |
401 | return get_current()->tstc(); | 403 | return get_current()->tstc(); |
402 | } | 404 | } |
403 | 405 | ||
404 | /** | 406 | /** |
405 | * serial_putc() - Output character via currently selected serial port | 407 | * serial_putc() - Output character via currently selected serial port |
406 | * @c: Single character to be output from the serial port. | 408 | * @c: Single character to be output from the serial port. |
407 | * | 409 | * |
408 | * This function outputs a character via currently selected serial | 410 | * This function outputs a character via currently selected serial |
409 | * port. This character is passed to the serial port driver responsible | 411 | * port. This character is passed to the serial port driver responsible |
410 | * for controlling the hardware. The hardware may still be in process | 412 | * for controlling the hardware. The hardware may still be in process |
411 | * of transmitting another character, therefore this function may block | 413 | * of transmitting another character, therefore this function may block |
412 | * for a short amount of time. This function uses the get_current() | 414 | * for a short amount of time. This function uses the get_current() |
413 | * call to determine which port is selected. | 415 | * call to determine which port is selected. |
414 | */ | 416 | */ |
415 | void serial_putc(const char c) | 417 | void serial_putc(const char c) |
416 | { | 418 | { |
417 | get_current()->putc(c); | 419 | get_current()->putc(c); |
418 | } | 420 | } |
419 | 421 | ||
420 | /** | 422 | /** |
421 | * serial_puts() - Output string via currently selected serial port | 423 | * serial_puts() - Output string via currently selected serial port |
422 | * @s: Zero-terminated string to be output from the serial port. | 424 | * @s: Zero-terminated string to be output from the serial port. |
423 | * | 425 | * |
424 | * This function outputs a zero-terminated string via currently | 426 | * This function outputs a zero-terminated string via currently |
425 | * selected serial port. This function behaves as an accelerator | 427 | * selected serial port. This function behaves as an accelerator |
426 | * in case the hardware can queue multiple characters for transfer. | 428 | * in case the hardware can queue multiple characters for transfer. |
427 | * The whole string that is to be output is available to the function | 429 | * The whole string that is to be output is available to the function |
428 | * implementing the hardware manipulation. Transmitting the whole | 430 | * implementing the hardware manipulation. Transmitting the whole |
429 | * string may take some time, thus this function may block for some | 431 | * string may take some time, thus this function may block for some |
430 | * amount of time. This function uses the get_current() call to | 432 | * amount of time. This function uses the get_current() call to |
431 | * determine which port is selected. | 433 | * determine which port is selected. |
432 | */ | 434 | */ |
433 | void serial_puts(const char *s) | 435 | void serial_puts(const char *s) |
434 | { | 436 | { |
435 | get_current()->puts(s); | 437 | get_current()->puts(s); |
436 | } | 438 | } |
437 | 439 | ||
438 | /** | 440 | /** |
439 | * default_serial_puts() - Output string by calling serial_putc() in loop | 441 | * default_serial_puts() - Output string by calling serial_putc() in loop |
440 | * @s: Zero-terminated string to be output from the serial port. | 442 | * @s: Zero-terminated string to be output from the serial port. |
441 | * | 443 | * |
442 | * This function outputs a zero-terminated string by calling serial_putc() | 444 | * This function outputs a zero-terminated string by calling serial_putc() |
443 | * in a loop. Most drivers do not support queueing more than one byte for | 445 | * in a loop. Most drivers do not support queueing more than one byte for |
444 | * transfer, thus this function precisely implements their serial_puts(). | 446 | * transfer, thus this function precisely implements their serial_puts(). |
445 | * | 447 | * |
446 | * To optimize the number of get_current() calls, this function only | 448 | * To optimize the number of get_current() calls, this function only |
447 | * calls get_current() once and then directly accesses the putc() call | 449 | * calls get_current() once and then directly accesses the putc() call |
448 | * of the &struct serial_device . | 450 | * of the &struct serial_device . |
449 | */ | 451 | */ |
450 | void default_serial_puts(const char *s) | 452 | void default_serial_puts(const char *s) |
451 | { | 453 | { |
452 | struct serial_device *dev = get_current(); | 454 | struct serial_device *dev = get_current(); |
453 | while (*s) | 455 | while (*s) |
454 | dev->putc(*s++); | 456 | dev->putc(*s++); |
455 | } | 457 | } |
456 | 458 | ||
457 | #if CONFIG_POST & CONFIG_SYS_POST_UART | 459 | #if CONFIG_POST & CONFIG_SYS_POST_UART |
458 | static const int bauds[] = CONFIG_SYS_BAUDRATE_TABLE; | 460 | static const int bauds[] = CONFIG_SYS_BAUDRATE_TABLE; |
459 | 461 | ||
460 | /** | 462 | /** |
461 | * uart_post_test() - Test the currently selected serial port using POST | 463 | * uart_post_test() - Test the currently selected serial port using POST |
462 | * @flags: POST framework flags | 464 | * @flags: POST framework flags |
463 | * | 465 | * |
464 | * Do a loopback test of the currently selected serial port. This | 466 | * Do a loopback test of the currently selected serial port. This |
465 | * function is only useful in the context of the POST testing framwork. | 467 | * function is only useful in the context of the POST testing framwork. |
466 | * The serial port is first configured into loopback mode and then | 468 | * The serial port is first configured into loopback mode and then |
467 | * characters are sent through it. | 469 | * characters are sent through it. |
468 | * | 470 | * |
469 | * Returns 0 on success, value otherwise. | 471 | * Returns 0 on success, value otherwise. |
470 | */ | 472 | */ |
471 | /* Mark weak until post/cpu/.../uart.c migrate over */ | 473 | /* Mark weak until post/cpu/.../uart.c migrate over */ |
472 | __weak | 474 | __weak |
473 | int uart_post_test(int flags) | 475 | int uart_post_test(int flags) |
474 | { | 476 | { |
475 | unsigned char c; | 477 | unsigned char c; |
476 | int ret, saved_baud, b; | 478 | int ret, saved_baud, b; |
477 | struct serial_device *saved_dev, *s; | 479 | struct serial_device *saved_dev, *s; |
478 | 480 | ||
479 | /* Save current serial state */ | 481 | /* Save current serial state */ |
480 | ret = 0; | 482 | ret = 0; |
481 | saved_dev = serial_current; | 483 | saved_dev = serial_current; |
482 | saved_baud = gd->baudrate; | 484 | saved_baud = gd->baudrate; |
483 | 485 | ||
484 | for (s = serial_devices; s; s = s->next) { | 486 | for (s = serial_devices; s; s = s->next) { |
485 | /* If this driver doesn't support loop back, skip it */ | 487 | /* If this driver doesn't support loop back, skip it */ |
486 | if (!s->loop) | 488 | if (!s->loop) |
487 | continue; | 489 | continue; |
488 | 490 | ||
489 | /* Test the next device */ | 491 | /* Test the next device */ |
490 | serial_current = s; | 492 | serial_current = s; |
491 | 493 | ||
492 | ret = serial_init(); | 494 | ret = serial_init(); |
493 | if (ret) | 495 | if (ret) |
494 | goto done; | 496 | goto done; |
495 | 497 | ||
496 | /* Consume anything that happens to be queued */ | 498 | /* Consume anything that happens to be queued */ |
497 | while (serial_tstc()) | 499 | while (serial_tstc()) |
498 | serial_getc(); | 500 | serial_getc(); |
499 | 501 | ||
500 | /* Enable loop back */ | 502 | /* Enable loop back */ |
501 | s->loop(1); | 503 | s->loop(1); |
502 | 504 | ||
503 | /* Test every available baud rate */ | 505 | /* Test every available baud rate */ |
504 | for (b = 0; b < ARRAY_SIZE(bauds); ++b) { | 506 | for (b = 0; b < ARRAY_SIZE(bauds); ++b) { |
505 | gd->baudrate = bauds[b]; | 507 | gd->baudrate = bauds[b]; |
506 | serial_setbrg(); | 508 | serial_setbrg(); |
507 | 509 | ||
508 | /* | 510 | /* |
509 | * Stick to printable chars to avoid issues: | 511 | * Stick to printable chars to avoid issues: |
510 | * - terminal corruption | 512 | * - terminal corruption |
511 | * - serial program reacting to sequences and sending | 513 | * - serial program reacting to sequences and sending |
512 | * back random extra data | 514 | * back random extra data |
513 | * - most serial drivers add in extra chars (like \r\n) | 515 | * - most serial drivers add in extra chars (like \r\n) |
514 | */ | 516 | */ |
515 | for (c = 0x20; c < 0x7f; ++c) { | 517 | for (c = 0x20; c < 0x7f; ++c) { |
516 | /* Send it out */ | 518 | /* Send it out */ |
517 | serial_putc(c); | 519 | serial_putc(c); |
518 | 520 | ||
519 | /* Make sure it's the same one */ | 521 | /* Make sure it's the same one */ |
520 | ret = (c != serial_getc()); | 522 | ret = (c != serial_getc()); |
521 | if (ret) { | 523 | if (ret) { |
522 | s->loop(0); | 524 | s->loop(0); |
523 | goto done; | 525 | goto done; |
524 | } | 526 | } |
525 | 527 | ||
526 | /* Clean up the output in case it was sent */ | 528 | /* Clean up the output in case it was sent */ |
527 | serial_putc('\b'); | 529 | serial_putc('\b'); |
528 | ret = ('\b' != serial_getc()); | 530 | ret = ('\b' != serial_getc()); |
529 | if (ret) { | 531 | if (ret) { |
530 | s->loop(0); | 532 | s->loop(0); |
531 | goto done; | 533 | goto done; |
532 | } | 534 | } |
533 | } | 535 | } |
534 | } | 536 | } |
535 | 537 | ||
536 | /* Disable loop back */ | 538 | /* Disable loop back */ |
537 | s->loop(0); | 539 | s->loop(0); |
538 | 540 | ||
539 | /* XXX: There is no serial_stop() !? */ | 541 | /* XXX: There is no serial_stop() !? */ |
540 | if (s->stop) | 542 | if (s->stop) |
541 | s->stop(); | 543 | s->stop(); |
542 | } | 544 | } |
543 | 545 | ||
544 | done: | 546 | done: |
545 | /* Restore previous serial state */ | 547 | /* Restore previous serial state */ |
546 | serial_current = saved_dev; | 548 | serial_current = saved_dev; |
547 | gd->baudrate = saved_baud; | 549 | gd->baudrate = saved_baud; |
548 | serial_reinit_all(); | 550 | serial_reinit_all(); |
549 | serial_setbrg(); | 551 | serial_setbrg(); |
550 | 552 | ||
551 | return ret; | 553 | return ret; |
552 | } | 554 | } |
553 | #endif | 555 | #endif |
554 | 556 |
drivers/serial/serial_xen.c
1 | /* | 1 | /* |
2 | * Copyright 2018 NXP | 2 | * Copyright 2018 NXP |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: GPL-2.0+ | 4 | * SPDX-License-Identifier: GPL-2.0+ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <common.h> | 7 | #include <common.h> |
8 | #include <debug_uart.h> | 8 | #include <debug_uart.h> |
9 | #include <dm.h> | 9 | #include <dm.h> |
10 | #include <errno.h> | 10 | #include <errno.h> |
11 | #include <fdtdec.h> | 11 | #include <fdtdec.h> |
12 | #include <linux/compiler.h> | 12 | #include <linux/compiler.h> |
13 | #include <serial.h> | 13 | #include <serial.h> |
14 | 14 | ||
15 | #include <xen/events.h> | 15 | #include <xen/events.h> |
16 | #include <xen/hvm.h> | 16 | #include <xen/hvm.h> |
17 | #include <xen/interface/sched.h> | 17 | #include <xen/interface/sched.h> |
18 | #include <xen/interface/hvm/hvm_op.h> | 18 | #include <xen/interface/hvm/hvm_op.h> |
19 | #include <xen/interface/hvm/params.h> | 19 | #include <xen/interface/hvm/params.h> |
20 | #include <xen/interface/io/console.h> | 20 | #include <xen/interface/io/console.h> |
21 | #include <xen/interface/io/ring.h> | 21 | #include <xen/interface/io/ring.h> |
22 | 22 | ||
23 | DECLARE_GLOBAL_DATA_PTR; | 23 | DECLARE_GLOBAL_DATA_PTR; |
24 | 24 | ||
25 | #ifdef CONFIG_DM_SERIAL | 25 | #if CONFIG_IS_ENABLED(DM_SERIAL) |
26 | struct xen_uart_priv { | 26 | struct xen_uart_priv { |
27 | struct xencons_interface *intf; | 27 | struct xencons_interface *intf; |
28 | u32 evtchn; | 28 | u32 evtchn; |
29 | int vtermno; | 29 | int vtermno; |
30 | struct hvc_struct *hvc; | 30 | struct hvc_struct *hvc; |
31 | grant_ref_t gntref; | 31 | grant_ref_t gntref; |
32 | }; | 32 | }; |
33 | 33 | ||
34 | int xen_serial_setbrg(struct udevice *dev, int baudrate) | 34 | int xen_serial_setbrg(struct udevice *dev, int baudrate) |
35 | { | 35 | { |
36 | return 0; | 36 | return 0; |
37 | } | 37 | } |
38 | 38 | ||
39 | static int xen_serial_probe(struct udevice *dev) | 39 | static int xen_serial_probe(struct udevice *dev) |
40 | { | 40 | { |
41 | struct xen_uart_priv *priv = dev_get_priv(dev); | 41 | struct xen_uart_priv *priv = dev_get_priv(dev); |
42 | u64 v = 0; | 42 | u64 v = 0; |
43 | unsigned long gfn; | 43 | unsigned long gfn; |
44 | int r; | 44 | int r; |
45 | 45 | ||
46 | r = hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN, &v); | 46 | r = hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN, &v); |
47 | if (r < 0 || v == 0) | 47 | if (r < 0 || v == 0) |
48 | return r; | 48 | return r; |
49 | 49 | ||
50 | priv->evtchn = v; | 50 | priv->evtchn = v; |
51 | 51 | ||
52 | r = hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v); | 52 | r = hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v); |
53 | if (r < 0 || v == 0) | 53 | if (r < 0 || v == 0) |
54 | return -ENODEV; | 54 | return -ENODEV; |
55 | 55 | ||
56 | gfn = v; | 56 | gfn = v; |
57 | 57 | ||
58 | priv->intf = (struct xencons_interface *)(gfn << XEN_PAGE_SHIFT); | 58 | priv->intf = (struct xencons_interface *)(gfn << XEN_PAGE_SHIFT); |
59 | if (!priv->intf) | 59 | if (!priv->intf) |
60 | return -EINVAL; | 60 | return -EINVAL; |
61 | 61 | ||
62 | return 0; | 62 | return 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | static int xen_serial_pending(struct udevice *dev, bool input) | 65 | static int xen_serial_pending(struct udevice *dev, bool input) |
66 | { | 66 | { |
67 | struct xen_uart_priv *priv = dev_get_priv(dev); | 67 | struct xen_uart_priv *priv = dev_get_priv(dev); |
68 | struct xencons_interface *intf = priv->intf; | 68 | struct xencons_interface *intf = priv->intf; |
69 | 69 | ||
70 | if (!input || intf->in_cons == intf->in_prod) | 70 | if (!input || intf->in_cons == intf->in_prod) |
71 | return 0; | 71 | return 0; |
72 | 72 | ||
73 | return 1; | 73 | return 1; |
74 | } | 74 | } |
75 | 75 | ||
76 | static int xen_serial_getc(struct udevice *dev) | 76 | static int xen_serial_getc(struct udevice *dev) |
77 | { | 77 | { |
78 | struct xen_uart_priv *priv = dev_get_priv(dev); | 78 | struct xen_uart_priv *priv = dev_get_priv(dev); |
79 | struct xencons_interface *intf = priv->intf; | 79 | struct xencons_interface *intf = priv->intf; |
80 | XENCONS_RING_IDX cons; | 80 | XENCONS_RING_IDX cons; |
81 | char c; | 81 | char c; |
82 | 82 | ||
83 | while (intf->in_cons == intf->in_prod) { | 83 | while (intf->in_cons == intf->in_prod) { |
84 | mb(); /* wait */ | 84 | mb(); /* wait */ |
85 | } | 85 | } |
86 | 86 | ||
87 | cons = intf->in_cons; | 87 | cons = intf->in_cons; |
88 | mb(); /* get pointers before reading ring */ | 88 | mb(); /* get pointers before reading ring */ |
89 | 89 | ||
90 | c = intf->in[MASK_XENCONS_IDX(cons++, intf->in)]; | 90 | c = intf->in[MASK_XENCONS_IDX(cons++, intf->in)]; |
91 | 91 | ||
92 | mb(); /* read ring before consuming */ | 92 | mb(); /* read ring before consuming */ |
93 | intf->in_cons = cons; | 93 | intf->in_cons = cons; |
94 | 94 | ||
95 | notify_remote_via_evtchn(priv->evtchn); | 95 | notify_remote_via_evtchn(priv->evtchn); |
96 | 96 | ||
97 | return c; | 97 | return c; |
98 | } | 98 | } |
99 | 99 | ||
100 | static int __write_console(struct udevice *dev, const char *data, int len) | 100 | static int __write_console(struct udevice *dev, const char *data, int len) |
101 | { | 101 | { |
102 | struct xen_uart_priv *priv = dev_get_priv(dev); | 102 | struct xen_uart_priv *priv = dev_get_priv(dev); |
103 | struct xencons_interface *intf = priv->intf; | 103 | struct xencons_interface *intf = priv->intf; |
104 | XENCONS_RING_IDX cons, prod; | 104 | XENCONS_RING_IDX cons, prod; |
105 | int sent = 0; | 105 | int sent = 0; |
106 | 106 | ||
107 | cons = intf->out_cons; | 107 | cons = intf->out_cons; |
108 | prod = intf->out_prod; | 108 | prod = intf->out_prod; |
109 | mb(); /* Update pointer */ | 109 | mb(); /* Update pointer */ |
110 | 110 | ||
111 | WARN_ON((prod - cons) > sizeof(intf->out)); | 111 | WARN_ON((prod - cons) > sizeof(intf->out)); |
112 | 112 | ||
113 | while ((sent < len) && ((prod - cons) < sizeof(intf->out))) | 113 | while ((sent < len) && ((prod - cons) < sizeof(intf->out))) |
114 | intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++]; | 114 | intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++]; |
115 | 115 | ||
116 | mb(); /* Update data before pointer */ | 116 | mb(); /* Update data before pointer */ |
117 | intf->out_prod = prod; | 117 | intf->out_prod = prod; |
118 | 118 | ||
119 | if (sent) | 119 | if (sent) |
120 | notify_remote_via_evtchn(priv->evtchn); | 120 | notify_remote_via_evtchn(priv->evtchn); |
121 | 121 | ||
122 | if (data[sent - 1] == '\n') | 122 | if (data[sent - 1] == '\n') |
123 | serial_puts("\r"); | 123 | serial_puts("\r"); |
124 | 124 | ||
125 | return sent; | 125 | return sent; |
126 | } | 126 | } |
127 | 127 | ||
128 | static int write_console(struct udevice *dev, const char *data, int len) | 128 | static int write_console(struct udevice *dev, const char *data, int len) |
129 | { | 129 | { |
130 | /* | 130 | /* |
131 | * Make sure the whole buffer is emitted, polling if | 131 | * Make sure the whole buffer is emitted, polling if |
132 | * necessary. We don't ever want to rely on the hvc daemon | 132 | * necessary. We don't ever want to rely on the hvc daemon |
133 | * because the most interesting console output is when the | 133 | * because the most interesting console output is when the |
134 | * kernel is crippled. | 134 | * kernel is crippled. |
135 | */ | 135 | */ |
136 | while (len) { | 136 | while (len) { |
137 | int sent = __write_console(dev, data, len); | 137 | int sent = __write_console(dev, data, len); |
138 | 138 | ||
139 | data += sent; | 139 | data += sent; |
140 | len -= sent; | 140 | len -= sent; |
141 | 141 | ||
142 | if (unlikely(len)) | 142 | if (unlikely(len)) |
143 | HYPERVISOR_sched_op(SCHEDOP_yield, NULL); | 143 | HYPERVISOR_sched_op(SCHEDOP_yield, NULL); |
144 | } | 144 | } |
145 | 145 | ||
146 | return 0; | 146 | return 0; |
147 | } | 147 | } |
148 | 148 | ||
149 | static int xen_serial_puts(struct udevice *dev, const char *str) | 149 | static int xen_serial_puts(struct udevice *dev, const char *str) |
150 | { | 150 | { |
151 | #ifdef CONFIG_SPL_BUILD | 151 | #ifdef CONFIG_SPL_BUILD |
152 | (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(str), str); | 152 | (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(str), (char *)str); |
153 | #else | 153 | #else |
154 | write_console(dev, str, strlen(str)); | 154 | write_console(dev, str, strlen(str)); |
155 | #endif | 155 | #endif |
156 | 156 | ||
157 | return 0; | 157 | return 0; |
158 | } | 158 | } |
159 | 159 | ||
160 | static int xen_serial_putc(struct udevice *dev, const char ch) | 160 | static int xen_serial_putc(struct udevice *dev, const char ch) |
161 | { | 161 | { |
162 | #ifdef CONFIG_SPL_BUILD | 162 | #ifdef CONFIG_SPL_BUILD |
163 | (void)HYPERVISOR_console_io(CONSOLEIO_write, 1, &ch); | 163 | (void)HYPERVISOR_console_io(CONSOLEIO_write, 1, (char *)&ch); |
164 | #else | 164 | #else |
165 | write_console(dev, &ch, 1); | 165 | write_console(dev, &ch, 1); |
166 | #endif | 166 | #endif |
167 | 167 | ||
168 | return 0; | 168 | return 0; |
169 | } | 169 | } |
170 | 170 | ||
171 | static const struct dm_serial_ops xen_serial_ops = { | 171 | static const struct dm_serial_ops xen_serial_ops = { |
172 | .puts = xen_serial_puts, | 172 | .puts = xen_serial_puts, |
173 | .putc = xen_serial_putc, | 173 | .putc = xen_serial_putc, |
174 | .getc = xen_serial_getc, | 174 | .getc = xen_serial_getc, |
175 | .pending = xen_serial_pending, | 175 | .pending = xen_serial_pending, |
176 | }; | 176 | }; |
177 | 177 | ||
178 | static const struct udevice_id xen_serial_ids[] = { | 178 | static const struct udevice_id xen_serial_ids[] = { |
179 | { .compatible = "xen,xen" }, | 179 | { .compatible = "xen,xen" }, |
180 | { } | 180 | { } |
181 | }; | 181 | }; |
182 | 182 | ||
183 | U_BOOT_DRIVER(serial_xen) = { | 183 | U_BOOT_DRIVER(serial_xen) = { |
184 | .name = "serial_xen", | 184 | .name = "serial_xen", |
185 | .id = UCLASS_SERIAL, | 185 | .id = UCLASS_SERIAL, |
186 | .of_match = xen_serial_ids, | 186 | .of_match = xen_serial_ids, |
187 | .priv_auto_alloc_size = sizeof(struct xen_uart_priv), | 187 | .priv_auto_alloc_size = sizeof(struct xen_uart_priv), |
188 | .probe = xen_serial_probe, | 188 | .probe = xen_serial_probe, |
189 | .ops = &xen_serial_ops, | 189 | .ops = &xen_serial_ops, |
190 | .flags = DM_FLAG_PRE_RELOC | DM_FLAG_IGNORE_DEFAULT_CLKS, | 190 | .flags = DM_FLAG_PRE_RELOC | DM_FLAG_IGNORE_DEFAULT_CLKS, |
191 | }; | 191 | }; |
192 | #else | 192 | #else |
193 | static void xen_serial_putc(const char c) | ||
194 | { | ||
195 | (void)HYPERVISOR_console_io(CONSOLEIO_write, 1, (char *)&c); | ||
196 | } | ||
197 | |||
198 | static void xen_serial_puts(const char *str) | ||
199 | { | ||
200 | (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(str), (char *)str); | ||
201 | } | ||
202 | |||
203 | static int xen_serial_tstc(void) | ||
204 | { | ||
205 | return 0; | ||
206 | } | ||
207 | |||
208 | static int xen_serial_init(void) | ||
209 | { | ||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | static void xen_serial_setbrg(void) | ||
214 | { | ||
215 | } | ||
216 | |||
217 | static struct serial_device xen_serial_drv = { | ||
218 | .name = "xen_serial", | ||
219 | .start = xen_serial_init, | ||
220 | .stop = NULL, | ||
221 | .setbrg = xen_serial_setbrg, | ||
222 | .getc = NULL, | ||
223 | .putc = xen_serial_putc, | ||
224 | .puts = xen_serial_puts, | ||
225 | .tstc = xen_serial_tstc, | ||
226 | }; | ||
227 | |||
193 | __weak struct serial_device *default_serial_console(void) | 228 | __weak struct serial_device *default_serial_console(void) |
194 | { | 229 | { |
195 | return NULL; | 230 | return &xen_serial_drv; |
196 | } | 231 | } |
197 | 232 | ||
198 | #endif | 233 | #endif |
199 | 234 | ||
200 | #ifdef CONFIG_DEBUG_UART_XEN | 235 | #ifdef CONFIG_DEBUG_UART_XEN |
201 | void _debug_uart_init(void) | 236 | void _debug_uart_init(void) |
202 | { | 237 | { |
203 | } | 238 | } |
204 | 239 | ||
205 | void _debug_uart_putc(int ch) | 240 | void _debug_uart_putc(int ch) |
206 | { | 241 | { |
207 | /* If \n, also do \r */ | 242 | /* If \n, also do \r */ |
208 | if (ch == '\n') | 243 | if (ch == '\n') |
209 | serial_putc('\r'); | 244 | serial_putc('\r'); |
210 | 245 | ||
211 | (void)HYPERVISOR_console_io(CONSOLEIO_write, 1, &ch); | 246 | (void)HYPERVISOR_console_io(CONSOLEIO_write, 1, (char *)&ch); |
212 | 247 | ||
213 | return; | 248 | return; |
214 | } | 249 | } |
215 | 250 | ||
216 | DEBUG_UART_FUNCS | 251 | DEBUG_UART_FUNCS |
217 | 252 | ||
218 | #endif | 253 | #endif |
219 | 254 |
include/configs/imx8qm_mek_android_auto_xen.h
1 | /* | 1 | /* |
2 | * Copyright 2018 NXP | 2 | * Copyright 2018 NXP |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: GPL-2.0+ | 4 | * SPDX-License-Identifier: GPL-2.0+ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef IMX8QM_MEK_ANDROID_AUTO_XEN_H | 7 | #ifndef IMX8QM_MEK_ANDROID_AUTO_XEN_H |
8 | #define IMX8QM_MEK_ANDROID_AUTO_XEN_H | 8 | #define IMX8QM_MEK_ANDROID_AUTO_XEN_H |
9 | 9 | ||
10 | #undef CONFIG_SYS_SDRAM_BASE | 10 | #undef CONFIG_SYS_SDRAM_BASE |
11 | #undef CONFIG_NR_DRAM_BANKS | 11 | #undef CONFIG_NR_DRAM_BANKS |
12 | #undef PHYS_SDRAM_1 | 12 | #undef PHYS_SDRAM_1 |
13 | #undef PHYS_SDRAM_2 | 13 | #undef PHYS_SDRAM_2 |
14 | #undef PHYS_SDRAM_1_SIZE | 14 | #undef PHYS_SDRAM_1_SIZE |
15 | #undef PHYS_SDRAM_2_SIZE | 15 | #undef PHYS_SDRAM_2_SIZE |
16 | 16 | ||
17 | #define CONFIG_SYS_SDRAM_BASE 0x80000000 | 17 | #define CONFIG_SYS_SDRAM_BASE 0x80000000 |
18 | #define CONFIG_NR_DRAM_BANKS 2 | 18 | #define CONFIG_NR_DRAM_BANKS 2 |
19 | #define PHYS_SDRAM_1 0x80000000 | 19 | #define PHYS_SDRAM_1 0x80000000 |
20 | #define PHYS_SDRAM_2 0x200000000 | 20 | #define PHYS_SDRAM_2 0x200000000 |
21 | #define PHYS_SDRAM_1_SIZE 0x80000000 /* 2 GB */ | 21 | #define PHYS_SDRAM_1_SIZE 0x80000000 /* 2 GB */ |
22 | #define PHYS_SDRAM_2_SIZE 0x60000000 /* 1536 MB */ | 22 | #define PHYS_SDRAM_2_SIZE 0x60000000 /* 1536 MB */ |
23 | 23 | ||
24 | #undef CONFIG_LOADADDR | 24 | #undef CONFIG_LOADADDR |
25 | #define CONFIG_LOADADDR 0x80080000 | 25 | #define CONFIG_LOADADDR 0x80080000 |
26 | #undef CONFIG_SYS_INIT_SP_ADDR | 26 | #undef CONFIG_SYS_INIT_SP_ADDR |
27 | #define CONFIG_SYS_INIT_SP_ADDR 0x80200000 | 27 | #define CONFIG_SYS_INIT_SP_ADDR 0x81200000 |
28 | 28 | ||
29 | #undef CONFIG_REQUIRE_SERIAL_CONSOLE | 29 | #undef CONFIG_REQUIRE_SERIAL_CONSOLE |
30 | #undef CONFIG_IMX_SMMU | 30 | #undef CONFIG_IMX_SMMU |
31 | 31 | ||
32 | #undef CONFIG_FASTBOOT_USB_DEV | 32 | #undef CONFIG_FASTBOOT_USB_DEV |
33 | #define CONFIG_FASTBOOT_USB_DEV 0 /* Use OTG port, not typec port */ | 33 | #define CONFIG_FASTBOOT_USB_DEV 0 /* Use OTG port, not typec port */ |
34 | 34 | ||
35 | /* This needs to be stay same in iomem in domu.cfg */ | 35 | /* This needs to be stay same in iomem in domu.cfg */ |
36 | #define SC_IPC_CH 0x5d1d0000 | 36 | #define SC_IPC_CH 0x5d1d0000 |
37 | |||
38 | #ifdef CONFIG_SPL_BUILD | ||
39 | #undef CONFIG_SPL_BSS_START_ADDR | ||
40 | #undef CONFIG_SYS_SPL_MALLOC_START | ||
41 | #undef CONFIG_MALLOC_F_ADDR | ||
42 | #undef CONFIG_SPL_TEXT_BASE | ||
43 | #undef CONFIG_SPL_STACK | ||
44 | |||
45 | #define CONFIG_SPL_TEXT_BASE 0x80080000 | ||
46 | #define CONFIG_MALLOC_F_ADDR 0x80100000 | ||
47 | #define CONFIG_SYS_SPL_MALLOC_START 0x80200000 | ||
48 | #define CONFIG_SPL_BSS_START_ADDR 0x80300000 | ||
49 | #define CONFIG_SPL_STACK 0x80400000 | ||
50 | |||
51 | #define CONFIG_SYS_SPL_PTE_RAM_BASE 0x80500000 | ||
52 | #endif | ||
53 | |||
54 | #define AVB_AB_I_UNDERSTAND_LIBAVB_AB_IS_DEPRECATED | ||
37 | 55 | ||
38 | #endif /* IMX8QM_MEK_ANDROID_AUTO_XEN_H */ | 56 | #endif /* IMX8QM_MEK_ANDROID_AUTO_XEN_H */ |
39 | 57 |