blob: 776cc75eabd830e8359bd0e364adde8f71cfd6c3 [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>
Olivier Deprez2661ba52024-02-19 18:50:53 +010011
12#include <debug.h>
J-Alves5aecd982020-06-11 10:25:33 +010013#include <tftf_lib.h>
Ruari Phippsddc661a2020-09-10 09:06:14 +010014#include <spm_common.h>
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060015#include <spinlock.h>
16
Raghu Krishnamurthy9e267a02022-08-11 21:25:26 -070017/*
18 * Use extended SPI interrupt ID range, hafnium/SPMC maps virtual interrupts
19 * to physical interrupts 1 to 1.
20 */
21#define NUM_VINT_ID 5120
J-Alves5aecd982020-06-11 10:25:33 +010022
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020023typedef struct {
Sandrine Bailleux17795062018-12-13 16:02:41 +010024 u_register_t fid;
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020025 u_register_t arg1;
26 u_register_t arg2;
27 u_register_t arg3;
28 u_register_t arg4;
29 u_register_t arg5;
30 u_register_t arg6;
31 u_register_t arg7;
32} svc_args;
33
34/*
35 * Trigger an SVC call.
36 *
37 * The arguments to pass through the SVC call must be stored in the svc_args
38 * structure. The return values of the SVC call will be stored in the same
39 * structure (overriding the input arguments).
40 *
Sandrine Bailleux17795062018-12-13 16:02:41 +010041 * Return the first return value. It is equivalent to args.fid but is also
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020042 * provided as the return value for convenience.
43 */
44u_register_t sp_svc(svc_args *args);
45
46/*
47 * Choose a pseudo-random number within the [min,max] range (both limits are
48 * inclusive).
49 */
50uintptr_t bound_rand(uintptr_t min, uintptr_t max);
51
52/*
53 * Check that expr == expected.
54 * If not, loop forever.
55 */
Karl Meakinc884d6b2024-04-16 14:01:10 +010056#define EXPECT(lhs, rhs) \
57 do { \
58 int lhs_value = (lhs); \
59 int rhs_value = (rhs); \
60 if (lhs_value != rhs_value) { \
61 ERROR("%s:%d: Assertion failed: `%s == %s`\n", \
62 __FILE__, __LINE__, #lhs, #rhs); \
63 ERROR("lhs = %d (0x%x)\n", lhs_value, lhs_value); \
64 ERROR("rhs = %d (0x%x)\n", rhs_value, rhs_value); \
65 while (1) { \
66 continue; \
67 } \
68 } \
69 } while (0)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020070
71/*
72 * Test framework functions
73 */
74
75void announce_test_section_start(const char *test_sect_desc);
76void announce_test_section_end(const char *test_sect_desc);
77
78void announce_test_start(const char *test_desc);
79void announce_test_end(const char *test_desc);
80
Madhukar Pappireddya09d5f72021-10-26 14:50:52 -050081/* Sleep for at least 'ms' milliseconds and return the elapsed time(ms). */
82uint64_t sp_sleep_elapsed_time(uint32_t ms);
83
Antonio Nino Diaz2ac6f8f2018-07-02 09:04:07 +010084/* Sleep for at least 'ms' milliseconds. */
85void sp_sleep(uint32_t ms);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020086
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060087void sp_handler_spin_lock_init(void);
88
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -050089/* Handler invoked by SP while processing interrupt. */
90extern void (*sp_interrupt_handler[NUM_VINT_ID])(void);
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060091
92/* Register the handler. */
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -050093void sp_register_interrupt_handler(void (*handler)(void),
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060094 uint32_t interrupt_id);
95
96/* Un-register the handler. */
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -050097void sp_unregister_interrupt_handler(uint32_t interrupt_id);
Madhukar Pappireddy7caaa4a2022-01-28 17:01:35 -060098
Madhukar Pappireddyca1e2012022-06-22 17:05:09 -050099void discover_managed_exit_interrupt_id(void);
100
Madhukar Pappireddy4d1f1122023-03-16 17:54:24 -0500101void register_maintenance_interrupt_handlers(void);
102
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200103#endif /* SP_HELPERS_H */