sdei_main.c 25.1 KB
Newer Older
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1
/*
2
 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <arch_helpers.h>
#include <assert.h>
#include <bl31.h>
#include <bl_common.h>
#include <cassert.h>
#include <context.h>
#include <debug.h>
#include <ehf.h>
#include <interrupt_mgmt.h>
#include <platform.h>
#include <pubsub.h>
#include <runtime_svc.h>
#include <sdei.h>
#include <stddef.h>
#include <string.h>
#include <utils.h>
#include "sdei_private.h"

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
25
26
27
#define MAJOR_VERSION	1ULL
#define MINOR_VERSION	0ULL
#define VENDOR_VERSION	0ULL
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
28
29

#define MAKE_SDEI_VERSION(_major, _minor, _vendor) \
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
30
	((((_major)) << 48ULL) | (((_minor)) << 32ULL) | (_vendor))
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

#define LOWEST_INTR_PRIORITY		0xff

#define is_valid_affinity(_mpidr)	(plat_core_pos_by_mpidr(_mpidr) >= 0)

CASSERT(PLAT_SDEI_CRITICAL_PRI < PLAT_SDEI_NORMAL_PRI,
		sdei_critical_must_have_higher_priority);

static unsigned int num_dyn_priv_slots, num_dyn_shrd_slots;

/* Initialise SDEI map entries */
static void init_map(sdei_ev_map_t *map)
{
	map->reg_count = 0;
}

/* Convert mapping to SDEI class */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
48
static sdei_class_t map_to_class(sdei_ev_map_t *map)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{
	return is_event_critical(map) ? SDEI_CRITICAL : SDEI_NORMAL;
}

/* Clear SDEI event entries except state */
static void clear_event_entries(sdei_entry_t *se)
{
	se->ep = 0;
	se->arg = 0;
	se->affinity = 0;
	se->reg_flags = 0;
}

/* Perform CPU-specific state initialisation */
static void *sdei_cpu_on_init(const void *arg)
{
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
65
	unsigned int i;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
66
67
68
69
70
71
72
73
74
75
76
77
78
	sdei_ev_map_t *map;
	sdei_entry_t *se;

	/* Initialize private mappings on this CPU */
	for_each_private_map(i, map) {
		se = get_event_entry(map);
		clear_event_entries(se);
		se->state = 0;
	}

	SDEI_LOG("Private events initialized on %lx\n", read_mpidr_el1());

	/* All PEs start with SDEI events masked */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
79
	(void) sdei_pe_mask();
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
80

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
81
	return NULL;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
82
83
}

84
85
86
87
88
89
90
91
92
93
94
/* CPU initialisation after wakeup from suspend */
static void *sdei_cpu_wakeup_init(const void *arg)
{
	SDEI_LOG("Events masked on %lx\n", read_mpidr_el1());

	/* All PEs wake up with SDEI events masked */
	sdei_pe_mask();

	return 0;
}

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
95
/* Initialise an SDEI class */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
96
static void sdei_class_init(sdei_class_t class)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
97
{
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
98
99
	unsigned int i;
	bool zero_found __unused = false;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
	int ev_num_so_far __unused;
	sdei_ev_map_t *map;

	/* Sanity check and configuration of shared events */
	ev_num_so_far = -1;
	for_each_shared_map(i, map) {
#if ENABLE_ASSERTIONS
		/* Ensure mappings are sorted */
		assert((ev_num_so_far < 0) || (map->ev_num > ev_num_so_far));

		ev_num_so_far = map->ev_num;

		/* Event 0 must not be shared */
		assert(map->ev_num != SDEI_EVENT_0);

		/* Check for valid event */
		assert(map->ev_num >= 0);

		/* Make sure it's a shared event */
		assert(is_event_shared(map));

		/* No shared mapping should have signalable property */
		assert(!is_event_signalable(map));
123
124
125

		/* Shared mappings can't be explicit */
		assert(!is_map_explicit(map));
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
126
127
128
129
130
131
132
133
134
#endif

		/* Skip initializing the wrong priority */
		if (map_to_class(map) != class)
			continue;

		/* Platform events are always bound, so set the bound flag */
		if (is_map_dynamic(map)) {
			assert(map->intr == SDEI_DYN_IRQ);
135
			assert(is_event_normal(map));
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
136
137
138
			num_dyn_shrd_slots++;
		} else {
			/* Shared mappings must be bound to shared interrupt */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
139
			assert(plat_ic_is_spi(map->intr) != 0);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
			set_map_bound(map);
		}

		init_map(map);
	}

	/* Sanity check and configuration of private events for this CPU */
	ev_num_so_far = -1;
	for_each_private_map(i, map) {
#if ENABLE_ASSERTIONS
		/* Ensure mappings are sorted */
		assert((ev_num_so_far < 0) || (map->ev_num > ev_num_so_far));

		ev_num_so_far = map->ev_num;

		if (map->ev_num == SDEI_EVENT_0) {
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
156
			zero_found = true;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176

			/* Event 0 must be a Secure SGI */
			assert(is_secure_sgi(map->intr));

			/*
			 * Event 0 can have only have signalable flag (apart
			 * from being private
			 */
			assert(map->map_flags == (SDEI_MAPF_SIGNALABLE |
						SDEI_MAPF_PRIVATE));
		} else {
			/* No other mapping should have signalable property */
			assert(!is_event_signalable(map));
		}

		/* Check for valid event */
		assert(map->ev_num >= 0);

		/* Make sure it's a private event */
		assert(is_event_private(map));
177
178
179
180
181
182
183
184
185
186

		/*
		 * Other than priority, explicit events can only have explicit
		 * and private flags set.
		 */
		if (is_map_explicit(map)) {
			assert((map->map_flags | SDEI_MAPF_CRITICAL) ==
					(SDEI_MAPF_EXPLICIT | SDEI_MAPF_PRIVATE
					| SDEI_MAPF_CRITICAL));
		}
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
187
188
189
190
191
192
193
194
195
196
#endif

		/* Skip initializing the wrong priority */
		if (map_to_class(map) != class)
			continue;

		/* Platform events are always bound, so set the bound flag */
		if (map->ev_num != SDEI_EVENT_0) {
			if (is_map_dynamic(map)) {
				assert(map->intr == SDEI_DYN_IRQ);
197
				assert(is_event_normal(map));
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
198
				num_dyn_priv_slots++;
199
200
201
202
203
204
			} else if (is_map_explicit(map)) {
				/*
				 * Explicit mappings don't have a backing
				 * SDEI interrupt, but verify that anyway.
				 */
				assert(map->intr == SDEI_DYN_IRQ);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
205
206
207
208
209
			} else {
				/*
				 * Private mappings must be bound to private
				 * interrupt.
				 */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
210
				assert(plat_ic_is_ppi((unsigned) map->intr) != 0);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
211
212
213
214
215
216
217
218
219
220
				set_map_bound(map);
			}
		}

		init_map(map);
	}

	/* Ensure event 0 is in the mapping */
	assert(zero_found);

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
221
	(void) sdei_cpu_on_init(NULL);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
}

/* SDEI dispatcher initialisation */
void sdei_init(void)
{
	sdei_class_init(SDEI_CRITICAL);
	sdei_class_init(SDEI_NORMAL);

	/* Register priority level handlers */
	ehf_register_priority_handler(PLAT_SDEI_CRITICAL_PRI,
			sdei_intr_handler);
	ehf_register_priority_handler(PLAT_SDEI_NORMAL_PRI,
			sdei_intr_handler);
}

/* Populate SDEI event entry */
static void set_sdei_entry(sdei_entry_t *se, uint64_t ep, uint64_t arg,
		unsigned int flags, uint64_t affinity)
{
	assert(se != NULL);

	se->ep = ep;
	se->arg = arg;
	se->affinity = (affinity & MPIDR_AFFINITY_MASK);
	se->reg_flags = flags;
}

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
249
static uint64_t sdei_version(void)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
{
	return MAKE_SDEI_VERSION(MAJOR_VERSION, MINOR_VERSION, VENDOR_VERSION);
}

/* Validate flags and MPIDR values for REGISTER and ROUTING_SET calls */
static int validate_flags(uint64_t flags, uint64_t mpidr)
{
	/* Validate flags */
	switch (flags) {
	case SDEI_REGF_RM_PE:
		if (!is_valid_affinity(mpidr))
			return SDEI_EINVAL;
		break;
	case SDEI_REGF_RM_ANY:
		break;
	default:
		/* Unknown flags */
		return SDEI_EINVAL;
	}

	return 0;
}

/* Set routing of an SDEI event */
static int sdei_event_routing_set(int ev_num, uint64_t flags, uint64_t mpidr)
{
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
276
277
	int ret;
	unsigned int routing;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
278
279
280
281
	sdei_ev_map_t *map;
	sdei_entry_t *se;

	ret = validate_flags(flags, mpidr);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
282
	if (ret != 0)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
283
284
285
286
		return ret;

	/* Check if valid event number */
	map = find_event_map(ev_num);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
287
	if (map == NULL)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
		return SDEI_EINVAL;

	/* The event must not be private */
	if (is_event_private(map))
		return SDEI_EINVAL;

	se = get_event_entry(map);

	sdei_map_lock(map);

	if (!is_map_bound(map) || is_event_private(map)) {
		ret = SDEI_EINVAL;
		goto finish;
	}

	if (!can_sdei_state_trans(se, DO_ROUTING)) {
		ret = SDEI_EDENY;
		goto finish;
	}

	/* Choose appropriate routing */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
309
310
	routing = (unsigned int) ((flags == SDEI_REGF_RM_ANY) ?
		INTR_ROUTING_MODE_ANY : INTR_ROUTING_MODE_PE);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
311
312

	/* Update event registration flag */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
313
	se->reg_flags = (unsigned int) flags;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328

	/*
	 * ROUTING_SET is permissible only when event composite state is
	 * 'registered, disabled, and not running'. This means that the
	 * interrupt is currently disabled, and not active.
	 */
	plat_ic_set_spi_routing(map->intr, routing, (u_register_t) mpidr);

finish:
	sdei_map_unlock(map);

	return ret;
}

/* Register handler and argument for an SDEI event */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
329
static int64_t sdei_event_register(int ev_num, uint64_t ep, uint64_t arg,
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
330
331
332
		uint64_t flags, uint64_t mpidr)
{
	int ret;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
333
	unsigned int routing;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
334
335
336
337
	sdei_entry_t *se;
	sdei_ev_map_t *map;
	sdei_state_t backup_state;

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
338
339
	if ((ep == 0U) || (plat_sdei_validate_entry_point(
					ep, sdei_client_el()) != 0)) {
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
340
		return SDEI_EINVAL;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
341
	}
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
342
343

	ret = validate_flags(flags, mpidr);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
344
	if (ret != 0)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
345
346
347
348
		return ret;

	/* Check if valid event number */
	map = find_event_map(ev_num);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
349
	if (map == NULL)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
		return SDEI_EINVAL;

	/* Private events always target the PE */
	if (is_event_private(map))
		flags = SDEI_REGF_RM_PE;

	se = get_event_entry(map);

	/*
	 * Even though register operation is per-event (additionally for private
	 * events, registration is required individually), it has to be
	 * serialised with respect to bind/release, which are global operations.
	 * So we hold the lock throughout, unconditionally.
	 */
	sdei_map_lock(map);

	backup_state = se->state;
	if (!can_sdei_state_trans(se, DO_REGISTER))
		goto fallback;

	/*
	 * When registering for dynamic events, make sure it's been bound
	 * already. This has to be the case as, without binding, the client
	 * can't know about the event number to register for.
	 */
	if (is_map_dynamic(map) && !is_map_bound(map))
		goto fallback;

	if (is_event_private(map)) {
		/* Multiple calls to register are possible for private events */
		assert(map->reg_count >= 0);
	} else {
		/* Only single call to register is possible for shared events */
		assert(map->reg_count == 0);
	}

	if (is_map_bound(map)) {
		/* Meanwhile, did any PE ACK the interrupt? */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
388
		if (plat_ic_get_interrupt_active(map->intr) != 0U)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
			goto fallback;

		/* The interrupt must currently owned by Non-secure */
		if (plat_ic_get_interrupt_type(map->intr) != INTR_TYPE_NS)
			goto fallback;

		/*
		 * Disable forwarding of new interrupt triggers to CPU
		 * interface.
		 */
		plat_ic_disable_interrupt(map->intr);

		/*
		 * Any events that are triggered after register and before
		 * enable should remain pending. Clear any previous interrupt
		 * triggers which are pending (except for SGIs). This has no
		 * affect on level-triggered interrupts.
		 */
		if (ev_num != SDEI_EVENT_0)
			plat_ic_clear_interrupt_pending(map->intr);

		/* Map interrupt to EL3 and program the correct priority */
		plat_ic_set_interrupt_type(map->intr, INTR_TYPE_EL3);

		/* Program the appropriate interrupt priority */
		plat_ic_set_interrupt_priority(map->intr, sdei_event_priority(map));

		/*
		 * Set the routing mode for shared event as requested. We
		 * already ensure that shared events get bound to SPIs.
		 */
		if (is_event_shared(map)) {
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
421
422
423
			routing = (unsigned int) ((flags == SDEI_REGF_RM_ANY) ?
				INTR_ROUTING_MODE_ANY : INTR_ROUTING_MODE_PE);
			plat_ic_set_spi_routing(map->intr, routing,
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
424
425
426
427
428
					(u_register_t) mpidr);
		}
	}

	/* Populate event entries */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
429
	set_sdei_entry(se, ep, arg, (unsigned int) flags, mpidr);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447

	/* Increment register count */
	map->reg_count++;

	sdei_map_unlock(map);

	return 0;

fallback:
	/* Reinstate previous state */
	se->state = backup_state;

	sdei_map_unlock(map);

	return SDEI_EDENY;
}

/* Enable SDEI event */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
448
static int64_t sdei_event_enable(int ev_num)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
449
450
451
{
	sdei_ev_map_t *map;
	sdei_entry_t *se;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
452
453
	int ret;
	bool before, after;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
454
455
456

	/* Check if valid event number */
	map = find_event_map(ev_num);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
457
	if (map == NULL)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
		return SDEI_EINVAL;

	se = get_event_entry(map);
	ret = SDEI_EDENY;

	if (is_event_shared(map))
		sdei_map_lock(map);

	before = GET_EV_STATE(se, ENABLED);
	if (!can_sdei_state_trans(se, DO_ENABLE))
		goto finish;
	after = GET_EV_STATE(se, ENABLED);

	/*
	 * Enable interrupt for bound events only if there's a change in enabled
	 * state.
	 */
	if (is_map_bound(map) && (!before && after))
		plat_ic_enable_interrupt(map->intr);

	ret = 0;

finish:
	if (is_event_shared(map))
		sdei_map_unlock(map);

	return ret;
}

/* Disable SDEI event */
static int sdei_event_disable(int ev_num)
{
	sdei_ev_map_t *map;
	sdei_entry_t *se;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
492
493
	int ret;
	bool before, after;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
494
495
496

	/* Check if valid event number */
	map = find_event_map(ev_num);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
497
	if (map == NULL)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
		return SDEI_EINVAL;

	se = get_event_entry(map);
	ret = SDEI_EDENY;

	if (is_event_shared(map))
		sdei_map_lock(map);

	before = GET_EV_STATE(se, ENABLED);
	if (!can_sdei_state_trans(se, DO_DISABLE))
		goto finish;
	after = GET_EV_STATE(se, ENABLED);

	/*
	 * Disable interrupt for bound events only if there's a change in
	 * enabled state.
	 */
	if (is_map_bound(map) && (before && !after))
		plat_ic_disable_interrupt(map->intr);

	ret = 0;

finish:
	if (is_event_shared(map))
		sdei_map_unlock(map);

	return ret;
}

/* Query SDEI event information */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
528
static int64_t sdei_event_get_info(int ev_num, int info)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
529
530
531
532
{
	sdei_entry_t *se;
	sdei_ev_map_t *map;

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
533
534
	uint64_t flags;
	bool registered;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
535
536
537
538
	uint64_t affinity;

	/* Check if valid event number */
	map = find_event_map(ev_num);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
539
	if (map == NULL)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
		return SDEI_EINVAL;

	se = get_event_entry(map);

	if (is_event_shared(map))
		sdei_map_lock(map);

	/* Sample state under lock */
	registered = GET_EV_STATE(se, REGISTERED);
	flags = se->reg_flags;
	affinity = se->affinity;

	if (is_event_shared(map))
		sdei_map_unlock(map);

	switch (info) {
	case SDEI_INFO_EV_TYPE:
		return is_event_shared(map);

	case SDEI_INFO_EV_NOT_SIGNALED:
		return !is_event_signalable(map);

	case SDEI_INFO_EV_PRIORITY:
		return is_event_critical(map);

	case SDEI_INFO_EV_ROUTING_MODE:
		if (!is_event_shared(map))
			return SDEI_EINVAL;
		if (!registered)
			return SDEI_EDENY;
		return (flags == SDEI_REGF_RM_PE);

	case SDEI_INFO_EV_ROUTING_AFF:
		if (!is_event_shared(map))
			return SDEI_EINVAL;
		if (!registered)
			return SDEI_EDENY;
		if (flags != SDEI_REGF_RM_PE)
			return SDEI_EINVAL;
		return affinity;

	default:
		return SDEI_EINVAL;
	}
}

/* Unregister an SDEI event */
static int sdei_event_unregister(int ev_num)
{
	int ret = 0;
	sdei_entry_t *se;
	sdei_ev_map_t *map;

	/* Check if valid event number */
	map = find_event_map(ev_num);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
595
	if (map == NULL)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
		return SDEI_EINVAL;

	se = get_event_entry(map);

	/*
	 * Even though unregister operation is per-event (additionally for
	 * private events, unregistration is required individually), it has to
	 * be serialised with respect to bind/release, which are global
	 * operations.  So we hold the lock throughout, unconditionally.
	 */
	sdei_map_lock(map);

	if (!can_sdei_state_trans(se, DO_UNREGISTER)) {
		/*
		 * Even if the call is invalid, and the handler is running (for
		 * example, having unregistered from a running handler earlier),
		 * return pending error code; otherwise, return deny.
		 */
		ret = GET_EV_STATE(se, RUNNING) ? SDEI_EPEND : SDEI_EDENY;

		goto finish;
	}

	map->reg_count--;
	if (is_event_private(map)) {
		/* Multiple calls to register are possible for private events */
		assert(map->reg_count >= 0);
	} else {
		/* Only single call to register is possible for shared events */
		assert(map->reg_count == 0);
	}

	if (is_map_bound(map)) {
		plat_ic_disable_interrupt(map->intr);

		/*
		 * Clear pending interrupt. Skip for SGIs as they may not be
		 * cleared on interrupt controllers.
		 */
		if (ev_num != SDEI_EVENT_0)
			plat_ic_clear_interrupt_pending(map->intr);

		assert(plat_ic_get_interrupt_type(map->intr) == INTR_TYPE_EL3);
		plat_ic_set_interrupt_type(map->intr, INTR_TYPE_NS);
		plat_ic_set_interrupt_priority(map->intr, LOWEST_INTR_PRIORITY);
	}

	clear_event_entries(se);

	/*
	 * If the handler is running at the time of unregister, return the
	 * pending error code.
	 */
	if (GET_EV_STATE(se, RUNNING))
		ret = SDEI_EPEND;

finish:
	sdei_map_unlock(map);

	return ret;
}

/* Query status of an SDEI event */
static int sdei_event_status(int ev_num)
{
	sdei_ev_map_t *map;
	sdei_entry_t *se;
	sdei_state_t state;

	/* Check if valid event number */
	map = find_event_map(ev_num);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
667
	if (map == NULL)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
668
669
670
671
672
673
674
675
676
677
678
679
680
		return SDEI_EINVAL;

	se = get_event_entry(map);

	if (is_event_shared(map))
		sdei_map_lock(map);

	/* State value directly maps to the expected return format */
	state = se->state;

	if (is_event_shared(map))
		sdei_map_unlock(map);

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
681
	return (int) state;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
682
683
684
}

/* Bind an SDEI event to an interrupt */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
685
static int sdei_interrupt_bind(unsigned int intr_num)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
686
687
{
	sdei_ev_map_t *map;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
688
	bool retry = true, shared_mapping;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
689
690

	/* SGIs are not allowed to be bound */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
691
	if (plat_ic_is_sgi(intr_num) != 0)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
692
693
		return SDEI_EINVAL;

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
694
	shared_mapping = (plat_ic_is_spi(intr_num) != 0);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
695
696
697
698
699
700
	do {
		/*
		 * Bail out if there is already an event for this interrupt,
		 * either platform-defined or dynamic.
		 */
		map = find_event_map_by_intr(intr_num, shared_mapping);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
701
		if (map != NULL) {
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
			if (is_map_dynamic(map)) {
				if (is_map_bound(map)) {
					/*
					 * Dynamic event, already bound. Return
					 * event number.
					 */
					return map->ev_num;
				}
			} else {
				/* Binding non-dynamic event */
				return SDEI_EINVAL;
			}
		}

		/*
		 * The interrupt is not bound yet. Try to find a free slot to
		 * bind it. Free dynamic mappings have their interrupt set as
		 * SDEI_DYN_IRQ.
		 */
		map = find_event_map_by_intr(SDEI_DYN_IRQ, shared_mapping);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
722
		if (map == NULL)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
			return SDEI_ENOMEM;

		/* The returned mapping must be dynamic */
		assert(is_map_dynamic(map));

		/*
		 * We cannot assert for bound maps here, as we might be racing
		 * with another bind.
		 */

		/* The requested interrupt must already belong to NS */
		if (plat_ic_get_interrupt_type(intr_num) != INTR_TYPE_NS)
			return SDEI_EDENY;

		/*
		 * Interrupt programming and ownership transfer are deferred
		 * until register.
		 */

		sdei_map_lock(map);
		if (!is_map_bound(map)) {
			map->intr = intr_num;
			set_map_bound(map);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
746
			retry = false;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
		}
		sdei_map_unlock(map);
	} while (retry);

	return map->ev_num;
}

/* Release a bound SDEI event previously to an interrupt */
static int sdei_interrupt_release(int ev_num)
{
	int ret = 0;
	sdei_ev_map_t *map;
	sdei_entry_t *se;

	/* Check if valid event number */
	map = find_event_map(ev_num);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
763
	if (map == NULL)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
		return SDEI_EINVAL;

	if (!is_map_dynamic(map))
		return SDEI_EINVAL;

	se = get_event_entry(map);

	sdei_map_lock(map);

	/* Event must have been unregistered before release */
	if (map->reg_count != 0) {
		ret = SDEI_EDENY;
		goto finish;
	}

	/*
	 * Interrupt release never causes the state to change. We only check
	 * whether it's permissible or not.
	 */
	if (!can_sdei_state_trans(se, DO_RELEASE)) {
		ret = SDEI_EDENY;
		goto finish;
	}

	if (is_map_bound(map)) {
		/*
		 * Deny release if the interrupt is active, which means it's
		 * probably being acknowledged and handled elsewhere.
		 */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
793
		if (plat_ic_get_interrupt_active(map->intr) != 0U) {
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
			ret = SDEI_EDENY;
			goto finish;
		}

		/*
		 * Interrupt programming and ownership transfer are already done
		 * during unregister.
		 */

		map->intr = SDEI_DYN_IRQ;
		clr_map_bound(map);
	} else {
		SDEI_LOG("Error release bound:%d cnt:%d\n", is_map_bound(map),
				map->reg_count);
		ret = SDEI_EINVAL;
	}

finish:
	sdei_map_unlock(map);

	return ret;
}

/* Perform reset of private SDEI events */
static int sdei_private_reset(void)
{
	sdei_ev_map_t *map;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
821
822
	int ret = 0, final_ret = 0;
	unsigned int i;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
823
824
825
826
827
828
829
830
831
832

	/* Unregister all private events */
	for_each_private_map(i, map) {
		/*
		 * The unregister can fail if the event is not registered, which
		 * is allowed, and a deny will be returned. But if the event is
		 * running or unregister pending, the call fails.
		 */
		ret = sdei_event_unregister(map->ev_num);
		if ((ret == SDEI_EPEND) && (final_ret == 0))
833
			final_ret = SDEI_EDENY;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
834
835
836
837
838
839
840
841
842
843
	}

	return final_ret;
}

/* Perform reset of shared SDEI events */
static int sdei_shared_reset(void)
{
	const sdei_mapping_t *mapping;
	sdei_ev_map_t *map;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
844
845
	int ret = 0, final_ret = 0;
	unsigned int i, j;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
846
847
848
849
850
851
852
853
854
855

	/* Unregister all shared events */
	for_each_shared_map(i, map) {
		/*
		 * The unregister can fail if the event is not registered, which
		 * is allowed, and a deny will be returned. But if the event is
		 * running or unregister pending, the call fails.
		 */
		ret = sdei_event_unregister(map->ev_num);
		if ((ret == SDEI_EPEND) && (final_ret == 0))
856
			final_ret = SDEI_EDENY;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
	}

	if (final_ret != 0)
		return final_ret;

	/*
	 * Loop through both private and shared mappings, and release all
	 * bindings.
	 */
	for_each_mapping_type(i, mapping) {
		iterate_mapping(mapping, j, map) {
			/*
			 * Release bindings for mappings that are dynamic and
			 * bound.
			 */
			if (is_map_dynamic(map) && is_map_bound(map)) {
				/*
				 * Any failure to release would mean there is at
				 * least a PE registered for the event.
				 */
				ret = sdei_interrupt_release(map->ev_num);
				if ((ret != 0) && (final_ret == 0))
					final_ret = ret;
			}
		}
	}

	return final_ret;
}

/* Send a signal to another SDEI client PE */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
888
static int sdei_signal(int ev_num, uint64_t target_pe)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
889
890
891
892
{
	sdei_ev_map_t *map;

	/* Only event 0 can be signalled */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
893
	if (ev_num != SDEI_EVENT_0)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
894
895
896
897
		return SDEI_EINVAL;

	/* Find mapping for event 0 */
	map = find_event_map(SDEI_EVENT_0);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
898
	if (map == NULL)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
899
900
901
902
903
904
905
906
907
908
909
		return SDEI_EINVAL;

	/* The event must be signalable */
	if (!is_event_signalable(map))
		return SDEI_EINVAL;

	/* Validate target */
	if (plat_core_pos_by_mpidr(target_pe) < 0)
		return SDEI_EINVAL;

	/* Raise SGI. Platform will validate target_pe */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
910
	plat_ic_raise_el3_sgi((int) map->intr, (u_register_t) target_pe);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
911
912
913
914
915

	return 0;
}

/* Query SDEI dispatcher features */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
916
static uint64_t sdei_features(unsigned int feature)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
917
918
919
920
921
922
{
	if (feature == SDEI_FEATURE_BIND_SLOTS) {
		return FEATURE_BIND_SLOTS(num_dyn_priv_slots,
				num_dyn_shrd_slots);
	}

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
923
	return (uint64_t) SDEI_EINVAL;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
924
925
926
927
928
929
930
931
932
933
934
935
936
937
}

/* SDEI top level handler for servicing SMCs */
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)
{

	uint64_t x5;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
938
	unsigned int ss = (unsigned int) get_interrupt_src_ss(flags);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
939
	int64_t ret;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
940
941
942
	bool resume = false;
	cpu_context_t *ctx = handle;
	int ev_num = (int) x1;
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
943
944

	if (ss != NON_SECURE)
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
945
		SMC_RET1(ctx, SMC_UNK);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
946
947
948

	/* Verify the caller EL */
	if (GET_EL(read_spsr_el3()) != sdei_client_el())
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
949
		SMC_RET1(ctx, SMC_UNK);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
950
951
952
953

	switch (smc_fid) {
	case SDEI_VERSION:
		SDEI_LOG("> VER\n");
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
954
		ret = (int64_t) sdei_version();
955
		SDEI_LOG("< VER:%llx\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
956
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
957
958

	case SDEI_EVENT_REGISTER:
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
959
960
		x5 = SMC_GET_GP(ctx, CTX_GPREG_X5);
		SDEI_LOG("> REG(n:%d e:%llx a:%llx f:%x m:%llx)\n", ev_num,
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
961
				x2, x3, (int) x4, x5);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
962
		ret = sdei_event_register(ev_num, x2, x3, x4, x5);
963
		SDEI_LOG("< REG:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
964
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
965
966
967

	case SDEI_EVENT_ENABLE:
		SDEI_LOG("> ENABLE(n:%d)\n", (int) x1);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
968
		ret = sdei_event_enable(ev_num);
969
		SDEI_LOG("< ENABLE:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
970
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
971
972

	case SDEI_EVENT_DISABLE:
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
973
974
		SDEI_LOG("> DISABLE(n:%d)\n", ev_num);
		ret = sdei_event_disable(ev_num);
975
		SDEI_LOG("< DISABLE:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
976
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
977
978
979

	case SDEI_EVENT_CONTEXT:
		SDEI_LOG("> CTX(p:%d):%lx\n", (int) x1, read_mpidr_el1());
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
980
		ret = sdei_event_context(ctx, (unsigned int) x1);
981
		SDEI_LOG("< CTX:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
982
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
983
984

	case SDEI_EVENT_COMPLETE_AND_RESUME:
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
985
986
		resume = true;
		/* Fallthrough */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
987
988

	case SDEI_EVENT_COMPLETE:
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
989
990
		SDEI_LOG("> COMPLETE(r:%u sta/ep:%llx):%lx\n",
				(unsigned int) resume, x1, read_mpidr_el1());
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
991
		ret = sdei_event_complete(resume, x1);
992
		SDEI_LOG("< COMPLETE:%llx\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
993
994
995
996
997
998
999
1000

		/*
		 * Set error code only if the call failed. If the call
		 * succeeded, we discard the dispatched context, and restore the
		 * interrupted context to a pristine condition, and therefore
		 * shouldn't be modified. We don't return to the caller in this
		 * case anyway.
		 */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1001
1002
		if (ret != 0)
			SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1003

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1004
		SMC_RET0(ctx);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1005
1006

	case SDEI_EVENT_STATUS:
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1007
1008
		SDEI_LOG("> STAT(n:%d)\n", ev_num);
		ret = sdei_event_status(ev_num);
1009
		SDEI_LOG("< STAT:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1010
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1011
1012

	case SDEI_EVENT_GET_INFO:
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1013
1014
		SDEI_LOG("> INFO(n:%d, %d)\n", ev_num, (int) x2);
		ret = sdei_event_get_info(ev_num, (int) x2);
1015
		SDEI_LOG("< INFO:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1016
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1017
1018

	case SDEI_EVENT_UNREGISTER:
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1019
1020
		SDEI_LOG("> UNREG(n:%d)\n", ev_num);
		ret = sdei_event_unregister(ev_num);
1021
		SDEI_LOG("< UNREG:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1022
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1023
1024
1025
1026

	case SDEI_PE_UNMASK:
		SDEI_LOG("> UNMASK:%lx\n", read_mpidr_el1());
		sdei_pe_unmask();
1027
		SDEI_LOG("< UNMASK:%d\n", 0);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1028
		SMC_RET1(ctx, 0);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1029
1030
1031
1032

	case SDEI_PE_MASK:
		SDEI_LOG("> MASK:%lx\n", read_mpidr_el1());
		ret = sdei_pe_mask();
1033
		SDEI_LOG("< MASK:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1034
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1035
1036
1037

	case SDEI_INTERRUPT_BIND:
		SDEI_LOG("> BIND(%d)\n", (int) x1);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1038
		ret = sdei_interrupt_bind((unsigned int) x1);
1039
		SDEI_LOG("< BIND:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1040
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1041
1042

	case SDEI_INTERRUPT_RELEASE:
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1043
1044
		SDEI_LOG("> REL(%d)\n", ev_num);
		ret = sdei_interrupt_release(ev_num);
1045
		SDEI_LOG("< REL:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1046
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1047
1048
1049
1050

	case SDEI_SHARED_RESET:
		SDEI_LOG("> S_RESET():%lx\n", read_mpidr_el1());
		ret = sdei_shared_reset();
1051
		SDEI_LOG("< S_RESET:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1052
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1053
1054
1055
1056

	case SDEI_PRIVATE_RESET:
		SDEI_LOG("> P_RESET():%lx\n", read_mpidr_el1());
		ret = sdei_private_reset();
1057
		SDEI_LOG("< P_RESET:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1058
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1059
1060

	case SDEI_EVENT_ROUTING_SET:
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1061
1062
		SDEI_LOG("> ROUTE_SET(n:%d f:%llx aff:%llx)\n", ev_num, x2, x3);
		ret = sdei_event_routing_set(ev_num, x2, x3);
1063
		SDEI_LOG("< ROUTE_SET:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1064
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1065
1066

	case SDEI_FEATURES:
1067
		SDEI_LOG("> FTRS(f:%llx)\n", x1);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1068
		ret = (int64_t) sdei_features((unsigned int) x1);
1069
		SDEI_LOG("< FTRS:%llx\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1070
		SMC_RET1(ctx, ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1071
1072

	case SDEI_EVENT_SIGNAL:
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1073
1074
		SDEI_LOG("> SIGNAL(e:%d t:%llx)\n", ev_num, x2);
		ret = sdei_signal(ev_num, x2);
1075
		SDEI_LOG("< SIGNAL:%lld\n", ret);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1076
		SMC_RET1(ctx, ret);
1077

Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1078
	default:
1079
		/* Do nothing in default case */
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1080
1081
1082
1083
		break;
	}

	WARN("Unimplemented SDEI Call: 0x%x\n", smc_fid);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1084
	SMC_RET1(ctx, SMC_UNK);
Jeenu Viswambharan's avatar
Jeenu Viswambharan committed
1085
1086
1087
1088
}

/* Subscribe to PSCI CPU on to initialize per-CPU SDEI configuration */
SUBSCRIBE_TO_EVENT(psci_cpu_on_finish, sdei_cpu_on_init);
1089
1090
1091

/* Subscribe to PSCI CPU suspend finisher for per-CPU configuration */
SUBSCRIBE_TO_EVENT(psci_suspend_pwrdown_finish, sdei_cpu_wakeup_init);