blob: 2e67be384321dbfbc68549244aef97f84c2fcebe [file] [log] [blame]
Manish Pandey29495372020-04-09 15:19:26 +01001/*
Daniel Boulbyce386b12022-03-29 18:36:36 +01002 * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
Manish Pandey29495372020-04-09 15:19:26 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <drivers/arm/pl011.h>
8#include <drivers/console.h>
Daniel Boulbyce386b12022-03-29 18:36:36 +01009#include <ffa_helpers.h>
Ruari Phippsddc661a2020-09-10 09:06:14 +010010#include <sp_debug.h>
Olivier Deprez6967c242021-04-09 09:24:08 +020011#include <spm_helpers.h>
Manish Pandey29495372020-04-09 15:19:26 +010012
Manish Pandey29495372020-04-09 15:19:26 +010013static int (*putc_impl)(int);
14
15static int putc_hypcall(int c)
16{
17 spm_debug_log((char)c);
18
19 return c;
20}
21
Olivier Deprez2765ebf2020-12-16 15:46:14 +010022static int putc_svccall(int c)
23{
Daniel Boulbyce386b12022-03-29 18:36:36 +010024 struct ffa_value args = {
Olivier Deprez2765ebf2020-12-16 15:46:14 +010025 .fid = SPM_DEBUG_LOG,
26 .arg1 = c
27 };
Daniel Boulbyce386b12022-03-29 18:36:36 +010028 ffa_svc(&args);
Olivier Deprez2765ebf2020-12-16 15:46:14 +010029
30 return c;
31}
32
Manish Pandey29495372020-04-09 15:19:26 +010033static int putc_uart(int c)
34{
35 console_pl011_putc(c);
36
37 return c;
38}
39
40void set_putc_impl(enum stdout_route route)
41{
42 switch (route) {
43
44 case HVC_CALL_AS_STDOUT:
45 putc_impl = putc_hypcall;
46 return;
47
Olivier Deprez2765ebf2020-12-16 15:46:14 +010048 case SVC_CALL_AS_STDOUT:
49 putc_impl = putc_svccall;
50 return;
51
Manish Pandey29495372020-04-09 15:19:26 +010052 case PL011_AS_STDOUT:
53 default:
54 break;
55 }
56
57 putc_impl = putc_uart;
58}
59
60int console_putc(int c)
61{
62 if (!putc_impl) {
63 return -1;
64 }
65
66 return putc_impl(c);
67}