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);
37int read_sysfs_file(char *debugfs_file, char *result, size_t result_size);
38void set_dscr(unsigned long val);
39int perf_event_open_counter(unsigned int type,
40 unsigned long config, int group_fd);
41int perf_event_enable(int fd);
42int perf_event_disable(int fd);
43int perf_event_reset(int fd);
44
45static inline bool have_hwcap(unsigned long ftr)
46{
47 return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr;
48}
49
50#ifdef AT_HWCAP2
51static inline bool have_hwcap2(unsigned long ftr2)
52{
53 return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
54}
55#else
56static inline bool have_hwcap2(unsigned long ftr2)
57{
58 return false;
59}
60#endif
61
62bool is_ppc64le(void);
63
64
65#define FAIL_IF(x) \
66do { \
67 if ((x)) { \
68 fprintf(stderr, \
69 "[FAIL] Test FAILED on line %d\n", __LINE__); \
70 return 1; \
71 } \
72} while (0)
73
74
75#define MAGIC_SKIP_RETURN_VALUE 99
76
77#define SKIP_IF(x) \
78do { \
79 if ((x)) { \
80 fprintf(stderr, \
81 "[SKIP] Test skipped on line %d\n", __LINE__); \
82 return MAGIC_SKIP_RETURN_VALUE; \
83 } \
84} while (0)
85
86#define SKIP_IF_MSG(x, msg) \
87do { \
88 if ((x)) { \
89 fprintf(stderr, \
90 "[SKIP] Test skipped on line %d: %s\n", \
91 __LINE__, msg); \
92 return MAGIC_SKIP_RETURN_VALUE; \
93 } \
94} while (0)
95
96#define _str(s) #s
97#define str(s) _str(s)
98
99
100#ifndef PPC_FEATURE2_ARCH_3_00
101#define PPC_FEATURE2_ARCH_3_00 0x00800000
102#endif
103
104#if defined(__powerpc64__)
105#define UCONTEXT_NIA(UC) (UC)->uc_mcontext.gp_regs[PT_NIP]
106#define UCONTEXT_MSR(UC) (UC)->uc_mcontext.gp_regs[PT_MSR]
107#elif defined(__powerpc__)
108#define UCONTEXT_NIA(UC) (UC)->uc_mcontext.uc_regs->gregs[PT_NIP]
109#define UCONTEXT_MSR(UC) (UC)->uc_mcontext.uc_regs->gregs[PT_MSR]
110#else
111#error implement UCONTEXT_NIA
112#endif
113
114#endif
115