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