1 /* 2 * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <debug.h> 8 #include <runtime_svc.h> 9 #include <stdio.h> 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) 33 printf("secure os: "); 34 else 35 printf("non-secure os: "); 36 for (i = 0; i < s->l; i++) { 37 putchar(s->linebuf[i]); 38 } 39 if (ch != '\n') { 40 printf(" <...>\n"); 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 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, 66 void *cookie, 67 void *handle, 68 u_register_t flags) 69 { 70 switch (smc_fid) { 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 96