Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 1 | /* |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020-2022, Arm Limited. All rights reserved. |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 3 | * |
4 | * SPDX-License-Identifier: BSD-3-Clause | ||||
5 | */ | ||||
6 | |||||
7 | #include <drivers/arm/pl011.h> | ||||
8 | #include <drivers/console.h> | ||||
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 9 | #include <ffa_helpers.h> |
Kathleen Capella | 3cb7425 | 2023-03-14 17:51:09 -0400 | [diff] [blame] | 10 | #include <ffa_svc.h> |
Ruari Phipps | ddc661a | 2020-09-10 09:06:14 +0100 | [diff] [blame] | 11 | #include <sp_debug.h> |
Olivier Deprez | 6967c24 | 2021-04-09 09:24:08 +0200 | [diff] [blame] | 12 | #include <spm_helpers.h> |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 13 | |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 14 | static int (*putc_impl)(int); |
15 | |||||
16 | static int putc_hypcall(int c) | ||||
17 | { | ||||
Kathleen Capella | 3cb7425 | 2023-03-14 17:51:09 -0400 | [diff] [blame] | 18 | hvc_args args = { |
19 | .fid = FFA_CONSOLE_LOG_SMC32, | ||||
20 | .arg1 = 1, | ||||
21 | .arg2 = c | ||||
22 | }; | ||||
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 23 | |
Kathleen Capella | 3cb7425 | 2023-03-14 17:51:09 -0400 | [diff] [blame] | 24 | (void)tftf_hvc(&args); |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 25 | return c; |
26 | } | ||||
Kathleen Capella | 3cb7425 | 2023-03-14 17:51:09 -0400 | [diff] [blame] | 27 | static int putc_ffacall(int c) |
Olivier Deprez | 2765ebf | 2020-12-16 15:46:14 +0100 | [diff] [blame] | 28 | { |
Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 29 | struct ffa_value args = { |
Kathleen Capella | 3cb7425 | 2023-03-14 17:51:09 -0400 | [diff] [blame] | 30 | .fid = FFA_CONSOLE_LOG_SMC32, |
31 | .arg1 = 1, | ||||
32 | .arg2 = c | ||||
Olivier Deprez | 2765ebf | 2020-12-16 15:46:14 +0100 | [diff] [blame] | 33 | }; |
Kathleen Capella | 3cb7425 | 2023-03-14 17:51:09 -0400 | [diff] [blame] | 34 | |
35 | ffa_service_call(&args); | ||||
Olivier Deprez | 2765ebf | 2020-12-16 15:46:14 +0100 | [diff] [blame] | 36 | |
37 | return c; | ||||
38 | } | ||||
39 | |||||
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 40 | static int putc_uart(int c) |
41 | { | ||||
42 | console_pl011_putc(c); | ||||
43 | |||||
44 | return c; | ||||
45 | } | ||||
46 | |||||
47 | void set_putc_impl(enum stdout_route route) | ||||
48 | { | ||||
49 | switch (route) { | ||||
50 | |||||
Kathleen Capella | 3cb7425 | 2023-03-14 17:51:09 -0400 | [diff] [blame] | 51 | case FFA_HVC_CALL_AS_STDOUT: |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 52 | putc_impl = putc_hypcall; |
53 | return; | ||||
Kathleen Capella | 3cb7425 | 2023-03-14 17:51:09 -0400 | [diff] [blame] | 54 | case FFA_SVC_SMC_CALL_AS_STDOUT: |
55 | putc_impl = putc_ffacall; | ||||
Olivier Deprez | 2765ebf | 2020-12-16 15:46:14 +0100 | [diff] [blame] | 56 | return; |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 57 | case PL011_AS_STDOUT: |
58 | default: | ||||
59 | break; | ||||
60 | } | ||||
61 | |||||
62 | putc_impl = putc_uart; | ||||
63 | } | ||||
64 | |||||
65 | int console_putc(int c) | ||||
66 | { | ||||
67 | if (!putc_impl) { | ||||
68 | return -1; | ||||
69 | } | ||||
70 | |||||
71 | return putc_impl(c); | ||||
72 | } |