1
2
3
4
5
6#ifndef _SELFTESTS_POWERPC_UTILS_H
7#define _SELFTESTS_POWERPC_UTILS_H
8
9#define __cacheline_aligned __attribute__((aligned(128)))
10
11#include <stdint.h>
12#include <stdbool.h>
13#include <linux/auxvec.h>
14#include <linux/perf_event.h>
15#include "reg.h"
16
17
18typedef unsigned long long u64;
19typedef signed long long s64;
20
21
22typedef uint32_t u32;
23typedef uint16_t u16;
24typedef uint8_t u8;
25
26void test_harness_set_timeout(uint64_t time);
27int test_harness(int (test_function)(void), char *name);
28
29int read_auxv(char *buf, ssize_t buf_size);
30void *find_auxv_entry(int type, char *auxv);
31void *get_auxv_entry(int type);
32
33int pick_online_cpu(void);
34
35int read_debugfs_file(char *debugfs_file, int *result);
36int write_debugfs_file(char *debugfs_file, int result);
37void set_dscr(unsigned long val);
38int perf_event_open_counter(unsigned int type,
39 unsigned long config, int group_fd);
40int perf_event_enable(int fd);
41int perf_event_disable(int fd);
42int perf_event_reset(int fd);
43
44static inline bool have_hwcap(unsigned long ftr)
45{
46 return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr;
47}
48
49#ifdef AT_HWCAP2
50static inline bool have_hwcap2(unsigned long ftr2)
51{
52 return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
53}
54#else
55static inline bool have_hwcap2(unsigned long ftr2)
56{
57 return false;
58}
59#endif
60
61bool is_ppc64le(void);
62
63
64#define FAIL_IF(x) \
65do { \
66 if ((x)) { \
67 fprintf(stderr, \
68 "[FAIL] Test FAILED on line %d\n", __LINE__); \
69 return 1; \
70 } \
71} while (0)
72
73
74#define MAGIC_SKIP_RETURN_VALUE 99
75
76#define SKIP_IF(x) \
77do { \
78 if ((x)) { \
79 fprintf(stderr, \
80 "[SKIP] Test skipped on line %d\n", __LINE__); \
81 return MAGIC_SKIP_RETURN_VALUE; \
82 } \
83} while (0)
84
85#define SKIP_IF_MSG(x, msg) \
86do { \
87 if ((x)) { \
88 fprintf(stderr, \
89 "[SKIP] Test skipped on line %d: %s\n", \
90 __LINE__, msg); \
91 return MAGIC_SKIP_RETURN_VALUE; \
92 } \
93} while (0)
94
95#define _str(s) #s
96#define str(s) _str(s)
97
98
99#ifndef PPC_FEATURE2_ARCH_3_00
100#define PPC_FEATURE2_ARCH_3_00 0x00800000
101#endif
102
103#if defined(__powerpc64__)
104#define UCONTEXT_NIA(UC) (UC)->uc_mcontext.gp_regs[PT_NIP]
105#define UCONTEXT_MSR(UC) (UC)->uc_mcontext.gp_regs[PT_MSR]
106#elif defined(__powerpc__)
107#define UCONTEXT_NIA(UC) (UC)->uc_mcontext.uc_regs->gregs[PT_NIP]
108#define UCONTEXT_MSR(UC) (UC)->uc_mcontext.uc_regs->gregs[PT_MSR]
109#else
110#error implement UCONTEXT_NIA
111#endif
112
113#endif
114