Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
Madhukar Pappireddy | 7caaa4a | 2022-01-28 17:01:35 -0600 | [diff] [blame] | 2 | * Copyright (c) 2018-2022, Arm Limited. All rights reserved. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 3 | * |
| 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-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 11 | #include <tftf_lib.h> |
Ruari Phipps | ddc661a | 2020-09-10 09:06:14 +0100 | [diff] [blame] | 12 | #include <spm_common.h> |
Madhukar Pappireddy | 7caaa4a | 2022-01-28 17:01:35 -0600 | [diff] [blame] | 13 | #include <spinlock.h> |
| 14 | |
| 15 | /* Currently, Hafnium/SPM supports only 64 virtual interrupt IDs. */ |
| 16 | #define NUM_VINT_ID 64 |
J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 17 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 18 | typedef struct { |
Sandrine Bailleux | 1779506 | 2018-12-13 16:02:41 +0100 | [diff] [blame] | 19 | u_register_t fid; |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 20 | 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 Bailleux | 1779506 | 2018-12-13 16:02:41 +0100 | [diff] [blame] | 36 | * Return the first return value. It is equivalent to args.fid but is also |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 37 | * provided as the return value for convenience. |
| 38 | */ |
| 39 | u_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 | */ |
| 45 | uintptr_t bound_rand(uintptr_t min, uintptr_t max); |
| 46 | |
| 47 | /* |
| 48 | * Check that expr == expected. |
| 49 | * If not, loop forever. |
| 50 | */ |
| 51 | void expect(int expr, int expected); |
| 52 | |
| 53 | /* |
| 54 | * Test framework functions |
| 55 | */ |
| 56 | |
| 57 | void announce_test_section_start(const char *test_sect_desc); |
| 58 | void announce_test_section_end(const char *test_sect_desc); |
| 59 | |
| 60 | void announce_test_start(const char *test_desc); |
| 61 | void announce_test_end(const char *test_desc); |
| 62 | |
Madhukar Pappireddy | a09d5f7 | 2021-10-26 14:50:52 -0500 | [diff] [blame] | 63 | /* Sleep for at least 'ms' milliseconds and return the elapsed time(ms). */ |
| 64 | uint64_t sp_sleep_elapsed_time(uint32_t ms); |
| 65 | |
Antonio Nino Diaz | 2ac6f8f | 2018-07-02 09:04:07 +0100 | [diff] [blame] | 66 | /* Sleep for at least 'ms' milliseconds. */ |
| 67 | void sp_sleep(uint32_t ms); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 68 | |
Madhukar Pappireddy | 7caaa4a | 2022-01-28 17:01:35 -0600 | [diff] [blame] | 69 | void sp_handler_spin_lock_init(void); |
| 70 | |
| 71 | /* Handler invoked at the tail end of interrupt processing by SP. */ |
| 72 | extern void (*sp_interrupt_tail_end_handler[NUM_VINT_ID])(void); |
| 73 | |
| 74 | /* Register the handler. */ |
| 75 | void sp_register_interrupt_tail_end_handler(void (*handler)(void), |
| 76 | uint32_t interrupt_id); |
| 77 | |
| 78 | /* Un-register the handler. */ |
| 79 | void sp_unregister_interrupt_tail_end_handler(uint32_t interrupt_id); |
| 80 | |
Madhukar Pappireddy | ca1e201 | 2022-06-22 17:05:09 -0500 | [diff] [blame] | 81 | void discover_managed_exit_interrupt_id(void); |
| 82 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 83 | #endif /* SP_HELPERS_H */ |