Arve Hjønnevåg | 2db97ad | 2015-05-12 19:23:24 -0700 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 6bca8be | 2018-08-09 15:30:28 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved. |
Arve Hjønnevåg | 2db97ad | 2015-05-12 19:23:24 -0700 | [diff] [blame] | 3 | * |
Arve Hjønnevåg | 0a66162 | 2018-02-01 15:44:04 -0800 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Arve Hjønnevåg | 2db97ad | 2015-05-12 19:23:24 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <debug.h> |
| 8 | #include <runtime_svc.h> |
| 9 | |
| 10 | #include "generic-arm64-smcall.h" |
| 11 | |
| 12 | int trusty_disable_serial_debug; |
| 13 | |
| 14 | struct dputc_state { |
| 15 | char linebuf[128]; |
| 16 | unsigned l; |
| 17 | }; |
| 18 | |
| 19 | static struct dputc_state dputc_state[2]; |
| 20 | |
| 21 | static void trusty_dputc(char ch, int secure) |
| 22 | { |
| 23 | unsigned i; |
| 24 | struct dputc_state *s = &dputc_state[!secure]; |
| 25 | |
| 26 | if (trusty_disable_serial_debug) |
| 27 | return; |
| 28 | |
| 29 | s->linebuf[s->l++] = ch; |
| 30 | if (s->l == sizeof(s->linebuf) || ch == '\n') { |
| 31 | if (secure) |
Antonio Nino Diaz | 6bca8be | 2018-08-09 15:30:28 +0100 | [diff] [blame] | 32 | tf_printf("secure os: "); |
Arve Hjønnevåg | 2db97ad | 2015-05-12 19:23:24 -0700 | [diff] [blame] | 33 | else |
Antonio Nino Diaz | 6bca8be | 2018-08-09 15:30:28 +0100 | [diff] [blame] | 34 | tf_printf("non-secure os: "); |
Arve Hjønnevåg | 2db97ad | 2015-05-12 19:23:24 -0700 | [diff] [blame] | 35 | for (i = 0; i < s->l; i++) { |
| 36 | putchar(s->linebuf[i]); |
| 37 | } |
| 38 | if (ch != '\n') { |
Antonio Nino Diaz | 6bca8be | 2018-08-09 15:30:28 +0100 | [diff] [blame] | 39 | tf_printf(" <...>\n"); |
Arve Hjønnevåg | 2db97ad | 2015-05-12 19:23:24 -0700 | [diff] [blame] | 40 | } |
| 41 | s->l = 0; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | static uint64_t trusty_get_reg_base(uint32_t reg) |
| 46 | { |
| 47 | switch (reg) { |
| 48 | case 0: |
| 49 | return PLAT_ARM_GICD_BASE; |
| 50 | |
| 51 | case 1: |
| 52 | return PLAT_ARM_GICC_BASE; |
| 53 | |
| 54 | default: |
| 55 | NOTICE("%s(0x%x) unknown reg\n", __func__, reg); |
| 56 | return SMC_UNK; |
| 57 | } |
| 58 | } |
| 59 | |
Sandrine Bailleux | 3ed16a1 | 2018-08-01 15:55:34 +0200 | [diff] [blame] | 60 | static uintptr_t trusty_generic_platform_smc(uint32_t smc_fid, |
| 61 | u_register_t x1, |
| 62 | u_register_t x2, |
| 63 | u_register_t x3, |
| 64 | u_register_t x4, |
Arve Hjønnevåg | 2db97ad | 2015-05-12 19:23:24 -0700 | [diff] [blame] | 65 | void *cookie, |
| 66 | void *handle, |
Sandrine Bailleux | 3ed16a1 | 2018-08-01 15:55:34 +0200 | [diff] [blame] | 67 | u_register_t flags) |
Arve Hjønnevåg | 2db97ad | 2015-05-12 19:23:24 -0700 | [diff] [blame] | 68 | { |
Arve Hjønnevåg | ee8c303 | 2018-02-28 17:18:55 -0800 | [diff] [blame] | 69 | switch (smc_fid) { |
Arve Hjønnevåg | 2db97ad | 2015-05-12 19:23:24 -0700 | [diff] [blame] | 70 | case SMC_FC_DEBUG_PUTC: |
| 71 | trusty_dputc(x1, is_caller_secure(flags)); |
| 72 | SMC_RET1(handle, 0); |
| 73 | |
| 74 | case SMC_FC_GET_REG_BASE: |
| 75 | case SMC_FC64_GET_REG_BASE: |
| 76 | SMC_RET1(handle, trusty_get_reg_base(x1)); |
| 77 | |
| 78 | default: |
| 79 | NOTICE("%s(0x%x, 0x%lx) unknown smc\n", __func__, smc_fid, x1); |
| 80 | SMC_RET1(handle, SMC_UNK); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /* Define a SPD runtime service descriptor for fast SMC calls */ |
| 85 | DECLARE_RT_SVC( |
| 86 | trusty_fast, |
| 87 | |
| 88 | SMC_ENTITY_PLATFORM_MONITOR, |
| 89 | SMC_ENTITY_PLATFORM_MONITOR, |
| 90 | SMC_TYPE_FAST, |
| 91 | NULL, |
| 92 | trusty_generic_platform_smc |
| 93 | ); |
| 94 | |