blob: 9c91c5603fff02d4496113c7ea90402bdff1deb7 [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>
Kathleen Capella3cb74252023-03-14 17:51:09 -040010#include <ffa_svc.h>
Ruari Phippsddc661a2020-09-10 09:06:14 +010011#include <sp_debug.h>
Olivier Deprez6967c242021-04-09 09:24:08 +020012#include <spm_helpers.h>
Manish Pandey29495372020-04-09 15:19:26 +010013
Manish Pandey29495372020-04-09 15:19:26 +010014static int (*putc_impl)(int);
15
16static int putc_hypcall(int c)
17{
Kathleen Capella3cb74252023-03-14 17:51:09 -040018 hvc_args args = {
19 .fid = FFA_CONSOLE_LOG_SMC32,
20 .arg1 = 1,
21 .arg2 = c
22 };
Manish Pandey29495372020-04-09 15:19:26 +010023
Kathleen Capella3cb74252023-03-14 17:51:09 -040024 (void)tftf_hvc(&args);
Manish Pandey29495372020-04-09 15:19:26 +010025 return c;
26}
Kathleen Capella3cb74252023-03-14 17:51:09 -040027static int putc_ffacall(int c)
Olivier Deprez2765ebf2020-12-16 15:46:14 +010028{
Daniel Boulbyce386b12022-03-29 18:36:36 +010029 struct ffa_value args = {
Kathleen Capella3cb74252023-03-14 17:51:09 -040030 .fid = FFA_CONSOLE_LOG_SMC32,
31 .arg1 = 1,
32 .arg2 = c
Olivier Deprez2765ebf2020-12-16 15:46:14 +010033 };
Kathleen Capella3cb74252023-03-14 17:51:09 -040034
35 ffa_service_call(&args);
Olivier Deprez2765ebf2020-12-16 15:46:14 +010036
37 return c;
38}
39
Manish Pandey29495372020-04-09 15:19:26 +010040static int putc_uart(int c)
41{
42 console_pl011_putc(c);
43
44 return c;
45}
46
47void set_putc_impl(enum stdout_route route)
48{
49 switch (route) {
50
Kathleen Capella3cb74252023-03-14 17:51:09 -040051 case FFA_HVC_CALL_AS_STDOUT:
Manish Pandey29495372020-04-09 15:19:26 +010052 putc_impl = putc_hypcall;
53 return;
Kathleen Capella3cb74252023-03-14 17:51:09 -040054 case FFA_SVC_SMC_CALL_AS_STDOUT:
55 putc_impl = putc_ffacall;
Olivier Deprez2765ebf2020-12-16 15:46:14 +010056 return;
Manish Pandey29495372020-04-09 15:19:26 +010057 case PL011_AS_STDOUT:
58 default:
59 break;
60 }
61
62 putc_impl = putc_uart;
63}
64
65int console_putc(int c)
66{
67 if (!putc_impl) {
68 return -1;
69 }
70
71 return putc_impl(c);
72}