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