blob: 3ffc13dcf7f8293f8ed14e15d4e6c22697645578 [file] [log] [blame]
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -07001/*
Antonio Nino Diazdfc1d3c2019-02-27 15:11:18 +00002 * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved.
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -07003 *
Arve Hjønnevåg0a661622018-02-01 15:44:04 -08004 * SPDX-License-Identifier: BSD-3-Clause
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -07005 */
6
Antonio Nino Diaz00086e32018-08-16 16:46:06 +01007#include <stdio.h>
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -07008
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <common/debug.h>
10#include <common/runtime_svc.h>
Antonio Nino Diazdfc1d3c2019-02-27 15:11:18 +000011#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070013#include "generic-arm64-smcall.h"
14
Arve Hjønnevåg743822a2018-04-11 16:09:35 -070015#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
19#else
20#error PLAT_ARM_GICD_BASE or GICD_BASE must be defined
21#endif
22#endif
23
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070024int trusty_disable_serial_debug;
25
26struct dputc_state {
27 char linebuf[128];
28 unsigned l;
29};
30
31static struct dputc_state dputc_state[2];
32
33static void trusty_dputc(char ch, int secure)
34{
35 unsigned i;
36 struct dputc_state *s = &dputc_state[!secure];
37
38 if (trusty_disable_serial_debug)
39 return;
40
41 s->linebuf[s->l++] = ch;
42 if (s->l == sizeof(s->linebuf) || ch == '\n') {
43 if (secure)
Antonio Nino Diaz00086e32018-08-16 16:46:06 +010044 printf("secure os: ");
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070045 else
Antonio Nino Diaz00086e32018-08-16 16:46:06 +010046 printf("non-secure os: ");
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070047 for (i = 0; i < s->l; i++) {
48 putchar(s->linebuf[i]);
49 }
50 if (ch != '\n') {
Antonio Nino Diaz00086e32018-08-16 16:46:06 +010051 printf(" <...>\n");
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070052 }
53 s->l = 0;
54 }
55}
56
57static uint64_t trusty_get_reg_base(uint32_t reg)
58{
59 switch (reg) {
60 case 0:
61 return PLAT_ARM_GICD_BASE;
62
63 case 1:
64 return PLAT_ARM_GICC_BASE;
65
66 default:
67 NOTICE("%s(0x%x) unknown reg\n", __func__, reg);
68 return SMC_UNK;
69 }
70}
71
Sandrine Bailleux3ed16a12018-08-01 15:55:34 +020072static uintptr_t trusty_generic_platform_smc(uint32_t smc_fid,
73 u_register_t x1,
74 u_register_t x2,
75 u_register_t x3,
76 u_register_t x4,
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070077 void *cookie,
78 void *handle,
Sandrine Bailleux3ed16a12018-08-01 15:55:34 +020079 u_register_t flags)
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070080{
Arve Hjønnevågee8c3032018-02-28 17:18:55 -080081 switch (smc_fid) {
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070082 case SMC_FC_DEBUG_PUTC:
83 trusty_dputc(x1, is_caller_secure(flags));
84 SMC_RET1(handle, 0);
85
86 case SMC_FC_GET_REG_BASE:
87 case SMC_FC64_GET_REG_BASE:
88 SMC_RET1(handle, trusty_get_reg_base(x1));
89
90 default:
91 NOTICE("%s(0x%x, 0x%lx) unknown smc\n", __func__, smc_fid, x1);
92 SMC_RET1(handle, SMC_UNK);
93 }
94}
95
96/* Define a SPD runtime service descriptor for fast SMC calls */
97DECLARE_RT_SVC(
98 trusty_fast,
99
100 SMC_ENTITY_PLATFORM_MONITOR,
101 SMC_ENTITY_PLATFORM_MONITOR,
102 SMC_TYPE_FAST,
103 NULL,
104 trusty_generic_platform_smc
105);
106