18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Copyright (C) 2019 ARM Limited */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef __TEST_SIGNALS_H__ 58c2ecf20Sopenharmony_ci#define __TEST_SIGNALS_H__ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <signal.h> 88c2ecf20Sopenharmony_ci#include <stdbool.h> 98c2ecf20Sopenharmony_ci#include <ucontext.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci/* 128c2ecf20Sopenharmony_ci * Using ARCH specific and sanitized Kernel headers installed by KSFT 138c2ecf20Sopenharmony_ci * framework since we asked for it by setting flag KSFT_KHDR_INSTALL 148c2ecf20Sopenharmony_ci * in our Makefile. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci#include <asm/ptrace.h> 178c2ecf20Sopenharmony_ci#include <asm/hwcap.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define __stringify_1(x...) #x 208c2ecf20Sopenharmony_ci#define __stringify(x...) __stringify_1(x) 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define get_regval(regname, out) \ 238c2ecf20Sopenharmony_ci{ \ 248c2ecf20Sopenharmony_ci asm volatile("mrs %0, " __stringify(regname) \ 258c2ecf20Sopenharmony_ci : "=r" (out) \ 268c2ecf20Sopenharmony_ci : \ 278c2ecf20Sopenharmony_ci : "memory"); \ 288c2ecf20Sopenharmony_ci} 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* 318c2ecf20Sopenharmony_ci * Feature flags used in tdescr.feats_required to specify 328c2ecf20Sopenharmony_ci * any feature by the test 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_cienum { 358c2ecf20Sopenharmony_ci FSSBS_BIT, 368c2ecf20Sopenharmony_ci FSVE_BIT, 378c2ecf20Sopenharmony_ci FMAX_END 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#define FEAT_SSBS (1UL << FSSBS_BIT) 418c2ecf20Sopenharmony_ci#define FEAT_SVE (1UL << FSVE_BIT) 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* 448c2ecf20Sopenharmony_ci * A descriptor used to describe and configure a test case. 458c2ecf20Sopenharmony_ci * Fields with a non-trivial meaning are described inline in the following. 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_cistruct tdescr { 488c2ecf20Sopenharmony_ci /* KEEP THIS FIELD FIRST for easier lookup from assembly */ 498c2ecf20Sopenharmony_ci void *token; 508c2ecf20Sopenharmony_ci /* when disabled token based sanity checking is skipped in handler */ 518c2ecf20Sopenharmony_ci bool sanity_disabled; 528c2ecf20Sopenharmony_ci /* just a name for the test-case; manadatory field */ 538c2ecf20Sopenharmony_ci char *name; 548c2ecf20Sopenharmony_ci char *descr; 558c2ecf20Sopenharmony_ci unsigned long feats_required; 568c2ecf20Sopenharmony_ci /* bitmask of effectively supported feats: populated at run-time */ 578c2ecf20Sopenharmony_ci unsigned long feats_supported; 588c2ecf20Sopenharmony_ci bool initialized; 598c2ecf20Sopenharmony_ci unsigned int minsigstksz; 608c2ecf20Sopenharmony_ci /* signum used as a test trigger. Zero if no trigger-signal is used */ 618c2ecf20Sopenharmony_ci int sig_trig; 628c2ecf20Sopenharmony_ci /* 638c2ecf20Sopenharmony_ci * signum considered as a successful test completion. 648c2ecf20Sopenharmony_ci * Zero when no signal is expected on success 658c2ecf20Sopenharmony_ci */ 668c2ecf20Sopenharmony_ci int sig_ok; 678c2ecf20Sopenharmony_ci /* signum expected on unsupported CPU features. */ 688c2ecf20Sopenharmony_ci int sig_unsupp; 698c2ecf20Sopenharmony_ci /* a timeout in second for test completion */ 708c2ecf20Sopenharmony_ci unsigned int timeout; 718c2ecf20Sopenharmony_ci bool triggered; 728c2ecf20Sopenharmony_ci bool pass; 738c2ecf20Sopenharmony_ci unsigned int result; 748c2ecf20Sopenharmony_ci /* optional sa_flags for the installed handler */ 758c2ecf20Sopenharmony_ci int sa_flags; 768c2ecf20Sopenharmony_ci ucontext_t saved_uc; 778c2ecf20Sopenharmony_ci /* used by get_current_ctx() */ 788c2ecf20Sopenharmony_ci size_t live_sz; 798c2ecf20Sopenharmony_ci ucontext_t *live_uc; 808c2ecf20Sopenharmony_ci volatile sig_atomic_t live_uc_valid; 818c2ecf20Sopenharmony_ci /* optional test private data */ 828c2ecf20Sopenharmony_ci void *priv; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci /* a custom setup: called alternatively to default_setup */ 858c2ecf20Sopenharmony_ci int (*setup)(struct tdescr *td); 868c2ecf20Sopenharmony_ci /* a custom init: called by default test init after test_setup */ 878c2ecf20Sopenharmony_ci bool (*init)(struct tdescr *td); 888c2ecf20Sopenharmony_ci /* a custom cleanup function called before test exits */ 898c2ecf20Sopenharmony_ci void (*cleanup)(struct tdescr *td); 908c2ecf20Sopenharmony_ci /* an optional function to be used as a trigger for starting test */ 918c2ecf20Sopenharmony_ci int (*trigger)(struct tdescr *td); 928c2ecf20Sopenharmony_ci /* 938c2ecf20Sopenharmony_ci * the actual test-core: invoked differently depending on the 948c2ecf20Sopenharmony_ci * presence of the trigger function above; this is mandatory 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_ci int (*run)(struct tdescr *td, siginfo_t *si, ucontext_t *uc); 978c2ecf20Sopenharmony_ci /* an optional function for custom results' processing */ 988c2ecf20Sopenharmony_ci void (*check_result)(struct tdescr *td); 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ciextern struct tdescr tde; 1028c2ecf20Sopenharmony_ci#endif 103