| 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> |
| Ruari Phipps | ddc661a | 2020-09-10 09:06:14 +0100 | [diff] [blame] | 10 | #include <sp_debug.h> |
| Olivier Deprez | 6967c24 | 2021-04-09 09:24:08 +0200 | [diff] [blame] | 11 | #include <spm_helpers.h> |
| Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 12 | |
| Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 13 | static int (*putc_impl)(int); |
| 14 | |||||
| 15 | static int putc_hypcall(int c) | ||||
| 16 | { | ||||
| 17 | spm_debug_log((char)c); | ||||
| 18 | |||||
| 19 | return c; | ||||
| 20 | } | ||||
| 21 | |||||
| Olivier Deprez | 2765ebf | 2020-12-16 15:46:14 +0100 | [diff] [blame] | 22 | static int putc_svccall(int c) |
| 23 | { | ||||
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 24 | struct ffa_value args = { |
| Olivier Deprez | 2765ebf | 2020-12-16 15:46:14 +0100 | [diff] [blame] | 25 | .fid = SPM_DEBUG_LOG, |
| 26 | .arg1 = c | ||||
| 27 | }; | ||||
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 28 | ffa_svc(&args); |
| Olivier Deprez | 2765ebf | 2020-12-16 15:46:14 +0100 | [diff] [blame] | 29 | |
| 30 | return c; | ||||
| 31 | } | ||||
| 32 | |||||
| Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 33 | static int putc_uart(int c) |
| 34 | { | ||||
| 35 | console_pl011_putc(c); | ||||
| 36 | |||||
| 37 | return c; | ||||
| 38 | } | ||||
| 39 | |||||
| 40 | void 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 Deprez | 2765ebf | 2020-12-16 15:46:14 +0100 | [diff] [blame] | 48 | case SVC_CALL_AS_STDOUT: |
| 49 | putc_impl = putc_svccall; | ||||
| 50 | return; | ||||
| 51 | |||||
| Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 52 | case PL011_AS_STDOUT: |
| 53 | default: | ||||
| 54 | break; | ||||
| 55 | } | ||||
| 56 | |||||
| 57 | putc_impl = putc_uart; | ||||
| 58 | } | ||||
| 59 | |||||
| 60 | int console_putc(int c) | ||||
| 61 | { | ||||
| 62 | if (!putc_impl) { | ||||
| 63 | return -1; | ||||
| 64 | } | ||||
| 65 | |||||
| 66 | return putc_impl(c); | ||||
| 67 | } | ||||