1*61496151SArve Hjønnevåg /* 2*61496151SArve Hjønnevåg * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. 3*61496151SArve Hjønnevåg * 4*61496151SArve Hjønnevåg * Redistribution and use in source and binary forms, with or without 5*61496151SArve Hjønnevåg * modification, are permitted provided that the following conditions are met: 6*61496151SArve Hjønnevåg * 7*61496151SArve Hjønnevåg * Redistributions of source code must retain the above copyright notice, this 8*61496151SArve Hjønnevåg * list of conditions and the following disclaimer. 9*61496151SArve Hjønnevåg * 10*61496151SArve Hjønnevåg * Redistributions in binary form must reproduce the above copyright notice, 11*61496151SArve Hjønnevåg * this list of conditions and the following disclaimer in the documentation 12*61496151SArve Hjønnevåg * and/or other materials provided with the distribution. 13*61496151SArve Hjønnevåg * 14*61496151SArve Hjønnevåg * Neither the name of ARM nor the names of its contributors may be used 15*61496151SArve Hjønnevåg * to endorse or promote products derived from this software without specific 16*61496151SArve Hjønnevåg * prior written permission. 17*61496151SArve Hjønnevåg * 18*61496151SArve Hjønnevåg * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*61496151SArve Hjønnevåg * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*61496151SArve Hjønnevåg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*61496151SArve Hjønnevåg * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*61496151SArve Hjønnevåg * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*61496151SArve Hjønnevåg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*61496151SArve Hjønnevåg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*61496151SArve Hjønnevåg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*61496151SArve Hjønnevåg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*61496151SArve Hjønnevåg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*61496151SArve Hjønnevåg * POSSIBILITY OF SUCH DAMAGE. 29*61496151SArve Hjønnevåg */ 30*61496151SArve Hjønnevåg 31*61496151SArve Hjønnevåg #include <debug.h> 32*61496151SArve Hjønnevåg #include <runtime_svc.h> 33*61496151SArve Hjønnevåg 34*61496151SArve Hjønnevåg #include "generic-arm64-smcall.h" 35*61496151SArve Hjønnevåg 36*61496151SArve Hjønnevåg int trusty_disable_serial_debug; 37*61496151SArve Hjønnevåg 38*61496151SArve Hjønnevåg struct dputc_state { 39*61496151SArve Hjønnevåg char linebuf[128]; 40*61496151SArve Hjønnevåg unsigned l; 41*61496151SArve Hjønnevåg }; 42*61496151SArve Hjønnevåg 43*61496151SArve Hjønnevåg static struct dputc_state dputc_state[2]; 44*61496151SArve Hjønnevåg 45*61496151SArve Hjønnevåg static void trusty_dputc(char ch, int secure) 46*61496151SArve Hjønnevåg { 47*61496151SArve Hjønnevåg unsigned i; 48*61496151SArve Hjønnevåg struct dputc_state *s = &dputc_state[!secure]; 49*61496151SArve Hjønnevåg 50*61496151SArve Hjønnevåg if (trusty_disable_serial_debug) 51*61496151SArve Hjønnevåg return; 52*61496151SArve Hjønnevåg 53*61496151SArve Hjønnevåg s->linebuf[s->l++] = ch; 54*61496151SArve Hjønnevåg if (s->l == sizeof(s->linebuf) || ch == '\n') { 55*61496151SArve Hjønnevåg if (secure) 56*61496151SArve Hjønnevåg printf("secure os: "); 57*61496151SArve Hjønnevåg else 58*61496151SArve Hjønnevåg printf("non-secure os: "); 59*61496151SArve Hjønnevåg for (i = 0; i < s->l; i++) { 60*61496151SArve Hjønnevåg putchar(s->linebuf[i]); 61*61496151SArve Hjønnevåg } 62*61496151SArve Hjønnevåg if (ch != '\n') { 63*61496151SArve Hjønnevåg printf(" <...>\n"); 64*61496151SArve Hjønnevåg } 65*61496151SArve Hjønnevåg s->l = 0; 66*61496151SArve Hjønnevåg } 67*61496151SArve Hjønnevåg } 68*61496151SArve Hjønnevåg 69*61496151SArve Hjønnevåg static uint64_t trusty_get_reg_base(uint32_t reg) 70*61496151SArve Hjønnevåg { 71*61496151SArve Hjønnevåg switch (reg) { 72*61496151SArve Hjønnevåg case 0: 73*61496151SArve Hjønnevåg return PLAT_ARM_GICD_BASE; 74*61496151SArve Hjønnevåg 75*61496151SArve Hjønnevåg case 1: 76*61496151SArve Hjønnevåg return PLAT_ARM_GICC_BASE; 77*61496151SArve Hjønnevåg 78*61496151SArve Hjønnevåg default: 79*61496151SArve Hjønnevåg NOTICE("%s(0x%x) unknown reg\n", __func__, reg); 80*61496151SArve Hjønnevåg return SMC_UNK; 81*61496151SArve Hjønnevåg } 82*61496151SArve Hjønnevåg } 83*61496151SArve Hjønnevåg 84*61496151SArve Hjønnevåg static uint64_t trusty_generic_platform_smc(uint32_t smc_fid, 85*61496151SArve Hjønnevåg uint64_t x1, 86*61496151SArve Hjønnevåg uint64_t x2, 87*61496151SArve Hjønnevåg uint64_t x3, 88*61496151SArve Hjønnevåg uint64_t x4, 89*61496151SArve Hjønnevåg void *cookie, 90*61496151SArve Hjønnevåg void *handle, 91*61496151SArve Hjønnevåg uint64_t flags) 92*61496151SArve Hjønnevåg { 93*61496151SArve Hjønnevåg switch(smc_fid) { 94*61496151SArve Hjønnevåg case SMC_FC_DEBUG_PUTC: 95*61496151SArve Hjønnevåg trusty_dputc(x1, is_caller_secure(flags)); 96*61496151SArve Hjønnevåg SMC_RET1(handle, 0); 97*61496151SArve Hjønnevåg 98*61496151SArve Hjønnevåg case SMC_FC_GET_REG_BASE: 99*61496151SArve Hjønnevåg case SMC_FC64_GET_REG_BASE: 100*61496151SArve Hjønnevåg SMC_RET1(handle, trusty_get_reg_base(x1)); 101*61496151SArve Hjønnevåg 102*61496151SArve Hjønnevåg default: 103*61496151SArve Hjønnevåg NOTICE("%s(0x%x, 0x%lx) unknown smc\n", __func__, smc_fid, x1); 104*61496151SArve Hjønnevåg SMC_RET1(handle, SMC_UNK); 105*61496151SArve Hjønnevåg } 106*61496151SArve Hjønnevåg } 107*61496151SArve Hjønnevåg 108*61496151SArve Hjønnevåg /* Define a SPD runtime service descriptor for fast SMC calls */ 109*61496151SArve Hjønnevåg DECLARE_RT_SVC( 110*61496151SArve Hjønnevåg trusty_fast, 111*61496151SArve Hjønnevåg 112*61496151SArve Hjønnevåg SMC_ENTITY_PLATFORM_MONITOR, 113*61496151SArve Hjønnevåg SMC_ENTITY_PLATFORM_MONITOR, 114*61496151SArve Hjønnevåg SMC_TYPE_FAST, 115*61496151SArve Hjønnevåg NULL, 116*61496151SArve Hjønnevåg trusty_generic_platform_smc 117*61496151SArve Hjønnevåg ); 118*61496151SArve Hjønnevåg 119