blob: 5c3a628496655533519a3b5f897e699e15eae83d [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
Arve Hjønnevåg8bd1e932019-11-15 14:25:43 -080019#ifdef GICR_BASE
20#define PLAT_ARM_GICR_BASE GICR_BASE
21#endif
Arve Hjønnevåg743822a2018-04-11 16:09:35 -070022#else
23#error PLAT_ARM_GICD_BASE or GICD_BASE must be defined
24#endif
Arve Hjønnevåg8bd1e932019-11-15 14:25:43 -080025#endif
26
27#ifndef PLAT_ARM_GICR_BASE
28#define PLAT_ARM_GICR_BASE SMC_UNK
Arve Hjønnevåg743822a2018-04-11 16:09:35 -070029#endif
30
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070031int trusty_disable_serial_debug;
32
33struct dputc_state {
34 char linebuf[128];
35 unsigned l;
36};
37
38static struct dputc_state dputc_state[2];
39
40static 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 Diaz00086e32018-08-16 16:46:06 +010051 printf("secure os: ");
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070052 else
Antonio Nino Diaz00086e32018-08-16 16:46:06 +010053 printf("non-secure os: ");
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070054 for (i = 0; i < s->l; i++) {
55 putchar(s->linebuf[i]);
56 }
57 if (ch != '\n') {
Antonio Nino Diaz00086e32018-08-16 16:46:06 +010058 printf(" <...>\n");
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070059 }
60 s->l = 0;
61 }
62}
63
64static uint64_t trusty_get_reg_base(uint32_t reg)
65{
66 switch (reg) {
Arve Hjønnevåg8bd1e932019-11-15 14:25:43 -080067 case SMC_GET_GIC_BASE_GICD:
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070068 return PLAT_ARM_GICD_BASE;
69
Arve Hjønnevåg8bd1e932019-11-15 14:25:43 -080070 case SMC_GET_GIC_BASE_GICC:
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070071 return PLAT_ARM_GICC_BASE;
72
Arve Hjønnevåg8bd1e932019-11-15 14:25:43 -080073 case SMC_GET_GIC_BASE_GICR:
74 return PLAT_ARM_GICR_BASE;
75
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070076 default:
77 NOTICE("%s(0x%x) unknown reg\n", __func__, reg);
78 return SMC_UNK;
79 }
80}
81
Sandrine Bailleux3ed16a12018-08-01 15:55:34 +020082static 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åg2db97ad2015-05-12 19:23:24 -070087 void *cookie,
88 void *handle,
Sandrine Bailleux3ed16a12018-08-01 15:55:34 +020089 u_register_t flags)
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070090{
Arve Hjønnevågee8c3032018-02-28 17:18:55 -080091 switch (smc_fid) {
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070092 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 */
107DECLARE_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