blob: a82924b8ed02bab6690024acfea54c1ea166c720 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -05002 * Copyright (c) 2018-2023, 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
Raghu Krishnamurthy9e267a02022-08-11 21:25:26 -070015/*
16 * Use extended SPI interrupt ID range, hafnium/SPMC maps virtual interrupts
17 * to physical interrupts 1 to 1.
18 */
19#define NUM_VINT_ID 5120
J-Alves5aecd982020-06-11 10:25:33 +010020
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020021typedef struct {
Sandrine Bailleux17795062018-12-13 16:02:41 +010022 u_register_t fid;
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020023 u_register_t arg1;
24 u_register_t arg2;
25 u_register_t arg3;
26 u_register_t arg4;
27 u_register_t arg5;
28 u_register_t arg6;
29 u_register_t arg7;
30} svc_args;
31
32/*
33 * Trigger an SVC call.
34 *
35 * The arguments to pass through the SVC call must be stored in the svc_args
36 * structure. The return values of the SVC call will be stored in the same
37 * structure (overriding the input arguments).
38 *
Sandrine Bailleux17795062018-12-13 16:02:41 +010039 * Return the first return value. It is equivalent to args.fid but is also
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020040 * provided as the return value for convenience.
41 */
42u_register_t sp_svc(svc_args *args);
43
44/*
45 * Choose a pseudo-random number within the [min,max] range (both limits are
46 * inclusive).
47 */
48uintptr_t bound_rand(uintptr_t min, uintptr_t max);
49
50/*
51 * Check that expr == expected.
52 * If not, loop forever.
53 */
54void expect(int expr, int expected);
55
56/*
57 * Test framework functions
58 */
59
60void announce_test_section_start(const char *test_sect_desc);
61void announce_test_section_end(const char *test_sect_desc);
62
63void announce_test_start(const char *test_desc);
64void announce_test_end(const char *test_desc);
65
Madhukar Pappireddya09d5f72021-10-26 14:50:52 -050066/* Sleep for at least 'ms' milliseconds and return the elapsed time(ms). */
67uint64_t sp_sleep_elapsed_time(uint32_t ms);
68
Antonio Nino Diaz2ac6f8f2018-07-02 09:04:07 +010069/* Sleep for at least 'ms' milliseconds. */
70void sp_sleep(uint32_t ms);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020071
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060072void sp_handler_spin_lock_init(void);
73
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -050074/* Handler invoked by SP while processing interrupt. */
75extern void (*sp_interrupt_handler[NUM_VINT_ID])(void);
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060076
77/* Register the handler. */
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -050078void sp_register_interrupt_handler(void (*handler)(void),
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060079 uint32_t interrupt_id);
80
81/* Un-register the handler. */
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -050082void sp_unregister_interrupt_handler(uint32_t interrupt_id);
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060083
Madhukar Pappireddyca1e2012022-06-22 17:05:09 -050084void discover_managed_exit_interrupt_id(void);
85
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -050086void register_maintenance_interrupt_handlers(void);
87
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020088#endif /* SP_HELPERS_H */