blob: ef6022134b53ef002aec7ab665134df9eba7a202 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -06002 * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef SP_HELPERS_H
8#define SP_HELPERS_H
9
10#include <stdint.h>
J-Alves5aecd982020-06-11 10:25:33 +010011#include <tftf_lib.h>
Ruari Phippsddc661a2020-09-10 09:06:14 +010012#include <spm_common.h>
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060013#include <spinlock.h>
14
15/* Currently, Hafnium/SPM supports only 64 virtual interrupt IDs. */
16#define NUM_VINT_ID 64
J-Alves5aecd982020-06-11 10:25:33 +010017
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020018typedef struct {
Sandrine Bailleux17795062018-12-13 16:02:41 +010019 u_register_t fid;
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020020 u_register_t arg1;
21 u_register_t arg2;
22 u_register_t arg3;
23 u_register_t arg4;
24 u_register_t arg5;
25 u_register_t arg6;
26 u_register_t arg7;
27} svc_args;
28
29/*
30 * Trigger an SVC call.
31 *
32 * The arguments to pass through the SVC call must be stored in the svc_args
33 * structure. The return values of the SVC call will be stored in the same
34 * structure (overriding the input arguments).
35 *
Sandrine Bailleux17795062018-12-13 16:02:41 +010036 * Return the first return value. It is equivalent to args.fid but is also
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020037 * provided as the return value for convenience.
38 */
39u_register_t sp_svc(svc_args *args);
40
41/*
42 * Choose a pseudo-random number within the [min,max] range (both limits are
43 * inclusive).
44 */
45uintptr_t bound_rand(uintptr_t min, uintptr_t max);
46
47/*
48 * Check that expr == expected.
49 * If not, loop forever.
50 */
51void expect(int expr, int expected);
52
53/*
54 * Test framework functions
55 */
56
57void announce_test_section_start(const char *test_sect_desc);
58void announce_test_section_end(const char *test_sect_desc);
59
60void announce_test_start(const char *test_desc);
61void announce_test_end(const char *test_desc);
62
Madhukar Pappireddya09d5f72021-10-26 14:50:52 -050063/* Sleep for at least 'ms' milliseconds and return the elapsed time(ms). */
64uint64_t sp_sleep_elapsed_time(uint32_t ms);
65
Antonio Nino Diaz2ac6f8f2018-07-02 09:04:07 +010066/* Sleep for at least 'ms' milliseconds. */
67void sp_sleep(uint32_t ms);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020068
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060069void sp_handler_spin_lock_init(void);
70
71/* Handler invoked at the tail end of interrupt processing by SP. */
72extern void (*sp_interrupt_tail_end_handler[NUM_VINT_ID])(void);
73
74/* Register the handler. */
75void sp_register_interrupt_tail_end_handler(void (*handler)(void),
76 uint32_t interrupt_id);
77
78/* Un-register the handler. */
79void sp_unregister_interrupt_tail_end_handler(uint32_t interrupt_id);
80
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020081#endif /* SP_HELPERS_H */