| 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* Copyright (C) 2019 ARM Limited */ |
| 3 | |
| 4 | #ifndef __TEST_SIGNALS_H__ |
| 5 | #define __TEST_SIGNALS_H__ |
| 6 | |
| 7 | #include <signal.h> |
| 8 | #include <stdbool.h> |
| 9 | #include <ucontext.h> |
| 10 | |
| 11 | /* |
| 12 | * Using ARCH specific and sanitized Kernel headers from the tree. |
| 13 | */ |
| 14 | #include <asm/ptrace.h> |
| 15 | #include <asm/hwcap.h> |
| 16 | |
| 17 | #define __stringify_1(x...) #x |
| 18 | #define __stringify(x...) __stringify_1(x) |
| 19 | |
| 20 | #define get_regval(regname, out) \ |
| 21 | { \ |
| 22 | asm volatile("mrs %0, " __stringify(regname) \ |
| 23 | : "=r" (out) \ |
| 24 | : \ |
| 25 | : "memory"); \ |
| 26 | } |
| 27 | |
| 28 | /* |
| 29 | * Feature flags used in tdescr.feats_required to specify |
| 30 | * any feature by the test |
| 31 | */ |
| 32 | enum { |
| 33 | FSSBS_BIT, |
| 34 | FSVE_BIT, |
| 35 | FSME_BIT, |
| 36 | FSME_FA64_BIT, |
| 37 | FSME2_BIT, |
| 38 | FGCS_BIT, |
| 39 | FMAX_END |
| 40 | }; |
| 41 | |
| 42 | #define FEAT_SSBS (1UL << FSSBS_BIT) |
| 43 | #define FEAT_SVE (1UL << FSVE_BIT) |
| 44 | #define FEAT_SME (1UL << FSME_BIT) |
| 45 | #define FEAT_SME_FA64 (1UL << FSME_FA64_BIT) |
| 46 | #define FEAT_SME2 (1UL << FSME2_BIT) |
| 47 | #define FEAT_GCS (1UL << FGCS_BIT) |
| 48 | |
| 49 | /* |
| 50 | * A descriptor used to describe and configure a test case. |
| 51 | * Fields with a non-trivial meaning are described inline in the following. |
| 52 | */ |
| 53 | struct tdescr { |
| 54 | /* KEEP THIS FIELD FIRST for easier lookup from assembly */ |
| 55 | void *token; |
| 56 | /* when disabled token based sanity checking is skipped in handler */ |
| 57 | bool sanity_disabled; |
| 58 | /* just a name for the test-case; manadatory field */ |
| 59 | char *name; |
| 60 | char *descr; |
| 61 | unsigned long feats_required; |
| 62 | unsigned long feats_incompatible; |
| 63 | /* bitmask of effectively supported feats: populated at run-time */ |
| 64 | unsigned long feats_supported; |
| 65 | bool initialized; |
| 66 | unsigned int minsigstksz; |
| 67 | /* signum used as a test trigger. Zero if no trigger-signal is used */ |
| 68 | int sig_trig; |
| 69 | /* |
| 70 | * signum considered as a successful test completion. |
| 71 | * Zero when no signal is expected on success |
| 72 | */ |
| 73 | int sig_ok; |
| 74 | /* |
| 75 | * expected si_code for sig_ok, or 0 to not check |
| 76 | */ |
| 77 | int sig_ok_code; |
| 78 | /* signum expected on unsupported CPU features. */ |
| 79 | int sig_unsupp; |
| 80 | /* a timeout in second for test completion */ |
| 81 | unsigned int timeout; |
| 82 | bool triggered; |
| 83 | bool pass; |
| 84 | unsigned int result; |
| 85 | /* optional sa_flags for the installed handler */ |
| 86 | int sa_flags; |
| 87 | ucontext_t saved_uc; |
| 88 | /* used by get_current_ctx() */ |
| 89 | size_t live_sz; |
| 90 | ucontext_t *live_uc; |
| 91 | volatile sig_atomic_t live_uc_valid; |
| 92 | /* optional test private data */ |
| 93 | void *priv; |
| 94 | |
| 95 | /* a custom setup: called alternatively to default_setup */ |
| 96 | int (*setup)(struct tdescr *td); |
| 97 | /* a custom init: called by default test init after test_setup */ |
| 98 | bool (*init)(struct tdescr *td); |
| 99 | /* a custom cleanup function called before test exits */ |
| 100 | void (*cleanup)(struct tdescr *td); |
| 101 | /* an optional function to be used as a trigger for starting test */ |
| 102 | int (*trigger)(struct tdescr *td); |
| 103 | /* |
| 104 | * the actual test-core: invoked differently depending on the |
| 105 | * presence of the trigger function above; this is mandatory |
| 106 | */ |
| 107 | int (*run)(struct tdescr *td, siginfo_t *si, ucontext_t *uc); |
| 108 | /* an optional function for custom results' processing */ |
| 109 | void (*check_result)(struct tdescr *td); |
| 110 | }; |
| 111 | |
| 112 | extern struct tdescr tde; |
| 113 | #endif |
| 114 | |