blob: 396253b6a7af5cf4c1717f6209188f438a3f4b4a [file] [log] [blame]
Manish Pandey29495372020-04-09 15:19:26 +01001/*
Ruari Phippsddc661a2020-09-10 09:06:14 +01002 * Copyright (c) 2020-2021, 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>
Ruari Phippsddc661a2020-09-10 09:06:14 +01009#include <sp_debug.h>
Olivier Deprez2765ebf2020-12-16 15:46:14 +010010#include <sp_helpers.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{
24 /* TODO svc call */
25 svc_args args = {
26 .fid = SPM_DEBUG_LOG,
27 .arg1 = c
28 };
29 sp_svc(&args);
30
31 return c;
32}
33
Manish Pandey29495372020-04-09 15:19:26 +010034static int putc_uart(int c)
35{
36 console_pl011_putc(c);
37
38 return c;
39}
40
41void set_putc_impl(enum stdout_route route)
42{
43 switch (route) {
44
45 case HVC_CALL_AS_STDOUT:
46 putc_impl = putc_hypcall;
47 return;
48
Olivier Deprez2765ebf2020-12-16 15:46:14 +010049 case SVC_CALL_AS_STDOUT:
50 putc_impl = putc_svccall;
51 return;
52
Manish Pandey29495372020-04-09 15:19:26 +010053 case PL011_AS_STDOUT:
54 default:
55 break;
56 }
57
58 putc_impl = putc_uart;
59}
60
61int console_putc(int c)
62{
63 if (!putc_impl) {
64 return -1;
65 }
66
67 return putc_impl(c);
68}