blob: e0e749d683b73a3fdeeeb89084b46067aee4bbd1 [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 */
Karl Meakinc884d6b2024-04-16 14:01:10 +010054#define EXPECT(lhs, rhs) \
55 do { \
56 int lhs_value = (lhs); \
57 int rhs_value = (rhs); \
58 if (lhs_value != rhs_value) { \
59 ERROR("%s:%d: Assertion failed: `%s == %s`\n", \
60 __FILE__, __LINE__, #lhs, #rhs); \
61 ERROR("lhs = %d (0x%x)\n", lhs_value, lhs_value); \
62 ERROR("rhs = %d (0x%x)\n", rhs_value, rhs_value); \
63 while (1) { \
64 continue; \
65 } \
66 } \
67 } while (0)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020068
69/*
70 * Test framework functions
71 */
72
73void announce_test_section_start(const char *test_sect_desc);
74void announce_test_section_end(const char *test_sect_desc);
75
76void announce_test_start(const char *test_desc);
77void announce_test_end(const char *test_desc);
78
Madhukar Pappireddya09d5f72021-10-26 14:50:52 -050079/* Sleep for at least 'ms' milliseconds and return the elapsed time(ms). */
80uint64_t sp_sleep_elapsed_time(uint32_t ms);
81
Antonio Nino Diaz2ac6f8f2018-07-02 09:04:07 +010082/* Sleep for at least 'ms' milliseconds. */
83void sp_sleep(uint32_t ms);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020084
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060085void sp_handler_spin_lock_init(void);
86
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -050087/* Handler invoked by SP while processing interrupt. */
88extern void (*sp_interrupt_handler[NUM_VINT_ID])(void);
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060089
90/* Register the handler. */
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -050091void sp_register_interrupt_handler(void (*handler)(void),
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060092 uint32_t interrupt_id);
93
94/* Un-register the handler. */
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -050095void sp_unregister_interrupt_handler(uint32_t interrupt_id);
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060096
Madhukar Pappireddyca1e2012022-06-22 17:05:09 -050097void discover_managed_exit_interrupt_id(void);
98
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -050099void register_maintenance_interrupt_handlers(void);
100
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200101#endif /* SP_HELPERS_H */