generic-arm64-smcall.c 2.19 KB
Newer Older
1
/*
2
 * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved.
3
 *
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
 */

7
#include <stdio.h>
8

9
10
#include <common/debug.h>
#include <common/runtime_svc.h>
11
#include <platform_def.h>
12

13
14
#include "generic-arm64-smcall.h"

15
16
17
18
#ifndef PLAT_ARM_GICD_BASE
#ifdef GICD_BASE
#define PLAT_ARM_GICD_BASE GICD_BASE
#define PLAT_ARM_GICC_BASE GICC_BASE
19
20
21
#ifdef GICR_BASE
#define PLAT_ARM_GICR_BASE GICR_BASE
#endif
22
23
24
25
26
#else
#error PLAT_ARM_GICD_BASE or GICD_BASE must be defined
#endif
#endif

27
28
29
30
#ifndef PLAT_ARM_GICR_BASE
#define PLAT_ARM_GICR_BASE SMC_UNK
#endif

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
int trusty_disable_serial_debug;

struct dputc_state {
	char linebuf[128];
	unsigned l;
};

static struct dputc_state dputc_state[2];

static void trusty_dputc(char ch, int secure)
{
	unsigned i;
	struct dputc_state *s = &dputc_state[!secure];

	if (trusty_disable_serial_debug)
		return;

	s->linebuf[s->l++] = ch;
	if (s->l == sizeof(s->linebuf) || ch == '\n') {
		if (secure)
51
			printf("secure os: ");
52
		else
53
			printf("non-secure os: ");
54
55
56
57
		for (i = 0; i < s->l; i++) {
			putchar(s->linebuf[i]);
		}
		if (ch != '\n') {
58
			printf(" <...>\n");
59
60
61
62
63
64
65
66
		}
		s->l = 0;
	}
}

static uint64_t trusty_get_reg_base(uint32_t reg)
{
	switch (reg) {
67
	case SMC_GET_GIC_BASE_GICD:
68
69
		return PLAT_ARM_GICD_BASE;

70
	case SMC_GET_GIC_BASE_GICC:
71
72
		return PLAT_ARM_GICC_BASE;

73
74
75
	case SMC_GET_GIC_BASE_GICR:
		return PLAT_ARM_GICR_BASE;

76
77
78
79
80
81
	default:
		NOTICE("%s(0x%x) unknown reg\n", __func__, reg);
		return SMC_UNK;
	}
}

82
83
84
85
86
static uintptr_t trusty_generic_platform_smc(uint32_t smc_fid,
			 u_register_t x1,
			 u_register_t x2,
			 u_register_t x3,
			 u_register_t x4,
87
88
			 void *cookie,
			 void *handle,
89
			 u_register_t flags)
90
{
91
	switch (smc_fid) {
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
	case SMC_FC_DEBUG_PUTC:
		trusty_dputc(x1, is_caller_secure(flags));
		SMC_RET1(handle, 0);

	case SMC_FC_GET_REG_BASE:
	case SMC_FC64_GET_REG_BASE:
		SMC_RET1(handle, trusty_get_reg_base(x1));

	default:
		NOTICE("%s(0x%x, 0x%lx) unknown smc\n", __func__, smc_fid, x1);
		SMC_RET1(handle, SMC_UNK);
	}
}

/* Define a SPD runtime service descriptor for fast SMC calls */
DECLARE_RT_SVC(
	trusty_fast,

	SMC_ENTITY_PLATFORM_MONITOR,
	SMC_ENTITY_PLATFORM_MONITOR,
	SMC_TYPE_FAST,
	NULL,
	trusty_generic_platform_smc
);