1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright 2013, Michael Ellerman, IBM Corp.
6 #ifndef _SELFTESTS_POWERPC_UTILS_H
7 #define _SELFTESTS_POWERPC_UTILS_H
9 #define __cacheline_aligned __attribute__((aligned(128)))
13 #include <linux/auxvec.h>
14 #include <linux/perf_event.h>
15 #include <asm/cputable.h>
18 /* Avoid headaches with PRI?64 - just use %ll? always */
19 typedef unsigned long long u64;
20 typedef signed long long s64;
22 /* Just for familiarity */
27 void test_harness_set_timeout(uint64_t time);
28 int test_harness(int (test_function)(void), char *name);
30 int read_auxv(char *buf, ssize_t buf_size);
31 void *find_auxv_entry(int type, char *auxv);
32 void *get_auxv_entry(int type);
34 int pick_online_cpu(void);
36 int read_debugfs_file(char *debugfs_file, int *result);
37 int write_debugfs_file(char *debugfs_file, int result);
38 int read_sysfs_file(char *debugfs_file, char *result, size_t result_size);
39 int perf_event_open_counter(unsigned int type,
40 unsigned long config, int group_fd);
41 int perf_event_enable(int fd);
42 int perf_event_disable(int fd);
43 int perf_event_reset(int fd);
45 struct perf_event_read {
50 #if !defined(__GLIBC_PREREQ) || !__GLIBC_PREREQ(2, 30)
52 #include <sys/syscall.h>
54 static inline pid_t gettid(void)
56 return syscall(SYS_gettid);
60 static inline bool have_hwcap(unsigned long ftr)
62 return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr;
66 static inline bool have_hwcap2(unsigned long ftr2)
68 return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
71 static inline bool have_hwcap2(unsigned long ftr2)
77 bool is_ppc64le(void);
78 int using_hash_mmu(bool *using_hash);
80 /* Yes, this is evil */
85 "[FAIL] Test FAILED on line %d\n", __LINE__); \
90 #define FAIL_IF_EXIT(x) \
94 "[FAIL] Test FAILED on line %d\n", __LINE__); \
99 /* The test harness uses this, yes it's gross */
100 #define MAGIC_SKIP_RETURN_VALUE 99
106 "[SKIP] Test skipped on line %d\n", __LINE__); \
107 return MAGIC_SKIP_RETURN_VALUE; \
111 #define SKIP_IF_MSG(x, msg) \
115 "[SKIP] Test skipped on line %d: %s\n", \
117 return MAGIC_SKIP_RETURN_VALUE; \
122 #define str(s) _str(s)
124 #define sigsafe_err(msg) ({ \
125 ssize_t nbytes __attribute__((unused)); \
126 nbytes = write(STDERR_FILENO, msg, strlen(msg)); })
129 #ifndef PPC_FEATURE2_ARCH_3_00
130 #define PPC_FEATURE2_ARCH_3_00 0x00800000
133 /* POWER10 feature */
134 #ifndef PPC_FEATURE2_ARCH_3_1
135 #define PPC_FEATURE2_ARCH_3_1 0x00040000
138 #if defined(__powerpc64__)
139 #define UCONTEXT_NIA(UC) (UC)->uc_mcontext.gp_regs[PT_NIP]
140 #define UCONTEXT_MSR(UC) (UC)->uc_mcontext.gp_regs[PT_MSR]
141 #elif defined(__powerpc__)
142 #define UCONTEXT_NIA(UC) (UC)->uc_mcontext.uc_regs->gregs[PT_NIP]
143 #define UCONTEXT_MSR(UC) (UC)->uc_mcontext.uc_regs->gregs[PT_MSR]
145 #error implement UCONTEXT_NIA
148 #endif /* _SELFTESTS_POWERPC_UTILS_H */