sdei.h 4.06 KB
Newer Older
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1
/*
2
 * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
3
4
5
6
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
7
8
#ifndef SDEI_H
#define SDEI_H
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
9

10
11
#include <lib/spinlock.h>
#include <lib/utils_def.h>
12
#include <services/sdei_flags.h>
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
13
14

/* Range 0xC4000020 - 0xC400003F reserved for SDE 64bit smc calls */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#define SDEI_VERSION				0xC4000020U
#define SDEI_EVENT_REGISTER			0xC4000021U
#define SDEI_EVENT_ENABLE			0xC4000022U
#define SDEI_EVENT_DISABLE			0xC4000023U
#define SDEI_EVENT_CONTEXT			0xC4000024U
#define SDEI_EVENT_COMPLETE			0xC4000025U
#define SDEI_EVENT_COMPLETE_AND_RESUME		0xC4000026U

#define SDEI_EVENT_UNREGISTER			0xC4000027U
#define SDEI_EVENT_STATUS			0xC4000028U
#define SDEI_EVENT_GET_INFO			0xC4000029U
#define SDEI_EVENT_ROUTING_SET			0xC400002AU
#define SDEI_PE_MASK				0xC400002BU
#define SDEI_PE_UNMASK				0xC400002CU

#define SDEI_INTERRUPT_BIND			0xC400002DU
#define SDEI_INTERRUPT_RELEASE			0xC400002EU
#define SDEI_EVENT_SIGNAL			0xC400002FU
#define SDEI_FEATURES				0xC4000030U
#define SDEI_PRIVATE_RESET			0xC4000031U
#define SDEI_SHARED_RESET			0xC4000032U
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
36
37

/* SDEI_EVENT_REGISTER flags */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
38
39
#define SDEI_REGF_RM_ANY	0ULL
#define SDEI_REGF_RM_PE		1ULL
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
40
41

/* SDEI_EVENT_COMPLETE status flags */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
42
43
#define SDEI_EV_HANDLED		0U
#define SDEI_EV_FAILED		1U
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
44
45

/* Indices of private and shared mappings */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
46
47
48
#define SDEI_MAP_IDX_PRIV_	0U
#define SDEI_MAP_IDX_SHRD_	1U
#define SDEI_MAP_IDX_MAX_	2U
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
49
50
51
52
53
54
55
56
57
58

/* The macros below are used to identify SDEI calls from the SMC function ID */
#define SDEI_FID_MASK		U(0xffe0)
#define SDEI_FID_VALUE		U(0x20)
#define is_sdei_fid(_fid) \
	((((_fid) & SDEI_FID_MASK) == SDEI_FID_VALUE) && \
	 (((_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_64))

#define SDEI_EVENT_MAP(_event, _intr, _flags) \
	{ \
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
59
60
61
		.ev_num = (_event), \
		.intr = (_intr), \
		.map_flags = (_flags) \
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
62
63
64
65
66
67
	}

#define SDEI_SHARED_EVENT(_event, _intr, _flags) \
	SDEI_EVENT_MAP(_event, _intr, _flags)

#define SDEI_PRIVATE_EVENT(_event, _intr, _flags) \
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
68
	SDEI_EVENT_MAP(_event, _intr, (_flags) | SDEI_MAPF_PRIVATE)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
69
70

#define SDEI_DEFINE_EVENT_0(_intr) \
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
71
	SDEI_PRIVATE_EVENT(SDEI_EVENT_0, (_intr), SDEI_MAPF_SIGNALABLE)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
72

73
#define SDEI_EXPLICIT_EVENT(_event, _pri) \
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
74
	SDEI_EVENT_MAP((_event), 0, (_pri) | SDEI_MAPF_EXPLICIT | SDEI_MAPF_PRIVATE)
75

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Declare shared and private entries for each core. Also declare a global
 * structure containing private and share entries.
 *
 * This macro must be used in the same file as the platform SDEI mappings are
 * declared. Only then would ARRAY_SIZE() yield a meaningful value.
 */
#define REGISTER_SDEI_MAP(_private, _shared) \
	sdei_entry_t sdei_private_event_table \
		[PLATFORM_CORE_COUNT * ARRAY_SIZE(_private)]; \
	sdei_entry_t sdei_shared_event_table[ARRAY_SIZE(_shared)]; \
	const sdei_mapping_t sdei_global_mappings[] = { \
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
88
89
		[SDEI_MAP_IDX_PRIV_] = { \
			.map = (_private), \
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
90
91
			.num_maps = ARRAY_SIZE(_private) \
		}, \
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
92
93
		[SDEI_MAP_IDX_SHRD_] = { \
			.map = (_shared), \
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
			.num_maps = ARRAY_SIZE(_shared) \
		}, \
	}

typedef uint8_t sdei_state_t;

/* Runtime data of SDEI event */
typedef struct sdei_entry {
	uint64_t ep;		/* Entry point */
	uint64_t arg;		/* Entry point argument */
	uint64_t affinity;	/* Affinity of shared event */
	unsigned int reg_flags;	/* Registration flags */

	/* Event handler states: registered, enabled, running */
	sdei_state_t state;
} sdei_entry_t;

/* Mapping of SDEI events to interrupts, and associated data */
typedef struct sdei_ev_map {
	int32_t ev_num;		/* Event number */
	unsigned int intr;	/* Physical interrupt number for a bound map */
	unsigned int map_flags;	/* Mapping flags, see SDEI_MAPF_* */
116
	int reg_count;		/* Registration count */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
	spinlock_t lock;	/* Per-event lock */
} sdei_ev_map_t;

typedef struct sdei_mapping {
	sdei_ev_map_t *map;
	size_t num_maps;
} sdei_mapping_t;

/* Handler to be called to handle SDEI smc calls */
uint64_t sdei_smc_handler(uint32_t smc_fid,
		uint64_t x1,
		uint64_t x2,
		uint64_t x3,
		uint64_t x4,
		void *cookie,
		void *handle,
		uint64_t flags);

void sdei_init(void);

137
/* Public API to dispatch an event to Normal world */
138
int sdei_dispatch_event(int ev_num);
139

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
140
#endif /* SDEI_H */