blob: 6f766c4db93f40c889f9718b05736de5db9a8fac [file] [log] [blame]
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -07001/*
Antonio Nino Diaz6bca8be2018-08-09 15:30:28 +01002 * Copyright (c) 2016-2018, 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
7#include <debug.h>
8#include <runtime_svc.h>
Antonio Nino Diaz00086e32018-08-16 16:46:06 +01009#include <stdio.h>
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070010
11#include "generic-arm64-smcall.h"
12
13int trusty_disable_serial_debug;
14
15struct dputc_state {
16 char linebuf[128];
17 unsigned l;
18};
19
20static struct dputc_state dputc_state[2];
21
22static 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 Diaz00086e32018-08-16 16:46:06 +010033 printf("secure os: ");
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070034 else
Antonio Nino Diaz00086e32018-08-16 16:46:06 +010035 printf("non-secure os: ");
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070036 for (i = 0; i < s->l; i++) {
37 putchar(s->linebuf[i]);
38 }
39 if (ch != '\n') {
Antonio Nino Diaz00086e32018-08-16 16:46:06 +010040 printf(" <...>\n");
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070041 }
42 s->l = 0;
43 }
44}
45
46static 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 Bailleux3ed16a12018-08-01 15:55:34 +020061static 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åg2db97ad2015-05-12 19:23:24 -070066 void *cookie,
67 void *handle,
Sandrine Bailleux3ed16a12018-08-01 15:55:34 +020068 u_register_t flags)
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070069{
Arve Hjønnevågee8c3032018-02-28 17:18:55 -080070 switch (smc_fid) {
Arve Hjønnevåg2db97ad2015-05-12 19:23:24 -070071 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 */
86DECLARE_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