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