Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 1 | /* |
Ruari Phipps | ddc661a | 2020-09-10 09:06:14 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020-2021, 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> |
Ruari Phipps | ddc661a | 2020-09-10 09:06:14 +0100 | [diff] [blame] | 9 | #include <sp_debug.h> |
Olivier Deprez | 2765ebf | 2020-12-16 15:46:14 +0100 | [diff] [blame] | 10 | #include <sp_helpers.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 | { |
| 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 Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 34 | static int putc_uart(int c) |
| 35 | { |
| 36 | console_pl011_putc(c); |
| 37 | |
| 38 | return c; |
| 39 | } |
| 40 | |
| 41 | void 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 Deprez | 2765ebf | 2020-12-16 15:46:14 +0100 | [diff] [blame] | 49 | case SVC_CALL_AS_STDOUT: |
| 50 | putc_impl = putc_svccall; |
| 51 | return; |
| 52 | |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 53 | case PL011_AS_STDOUT: |
| 54 | default: |
| 55 | break; |
| 56 | } |
| 57 | |
| 58 | putc_impl = putc_uart; |
| 59 | } |
| 60 | |
| 61 | int console_putc(int c) |
| 62 | { |
| 63 | if (!putc_impl) { |
| 64 | return -1; |
| 65 | } |
| 66 | |
| 67 | return putc_impl(c); |
| 68 | } |