Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <drivers/arm/pl011.h> |
| 8 | #include <drivers/console.h> |
Olivier Deprez | 6967c24 | 2021-04-09 09:24:08 +0200 | [diff] [blame^] | 9 | #include <spm_helpers.h> |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 10 | |
| 11 | #include "cactus.h" |
Manish Pandey | 2949537 | 2020-04-09 15:19:26 +0100 | [diff] [blame] | 12 | |
| 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 | |
| 22 | static int putc_uart(int c) |
| 23 | { |
| 24 | console_pl011_putc(c); |
| 25 | |
| 26 | return c; |
| 27 | } |
| 28 | |
| 29 | void set_putc_impl(enum stdout_route route) |
| 30 | { |
| 31 | switch (route) { |
| 32 | |
| 33 | case HVC_CALL_AS_STDOUT: |
| 34 | putc_impl = putc_hypcall; |
| 35 | return; |
| 36 | |
| 37 | case PL011_AS_STDOUT: |
| 38 | default: |
| 39 | break; |
| 40 | } |
| 41 | |
| 42 | putc_impl = putc_uart; |
| 43 | } |
| 44 | |
| 45 | int console_putc(int c) |
| 46 | { |
| 47 | if (!putc_impl) { |
| 48 | return -1; |
| 49 | } |
| 50 | |
| 51 | return putc_impl(c); |
| 52 | } |