| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright 2013, Michael Ellerman, IBM Corp. |
|---|
| 3 | | - * Licensed under GPLv2. |
|---|
| 4 | 4 | */ |
|---|
| 5 | 5 | |
|---|
| 6 | 6 | #ifndef _SELFTESTS_POWERPC_UTILS_H |
|---|
| .. | .. |
|---|
| 11 | 11 | #include <stdint.h> |
|---|
| 12 | 12 | #include <stdbool.h> |
|---|
| 13 | 13 | #include <linux/auxvec.h> |
|---|
| 14 | +#include <linux/perf_event.h> |
|---|
| 15 | +#include <asm/cputable.h> |
|---|
| 14 | 16 | #include "reg.h" |
|---|
| 15 | 17 | |
|---|
| 16 | 18 | /* Avoid headaches with PRI?64 - just use %ll? always */ |
|---|
| .. | .. |
|---|
| 31 | 33 | |
|---|
| 32 | 34 | int pick_online_cpu(void); |
|---|
| 33 | 35 | |
|---|
| 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); |
|---|
| 44 | + |
|---|
| 45 | +struct perf_event_read { |
|---|
| 46 | + __u64 nr; |
|---|
| 47 | + __u64 l1d_misses; |
|---|
| 48 | +}; |
|---|
| 49 | + |
|---|
| 50 | +#if !defined(__GLIBC_PREREQ) || !__GLIBC_PREREQ(2, 30) |
|---|
| 51 | +#include <unistd.h> |
|---|
| 52 | +#include <sys/syscall.h> |
|---|
| 53 | + |
|---|
| 54 | +static inline pid_t gettid(void) |
|---|
| 55 | +{ |
|---|
| 56 | + return syscall(SYS_gettid); |
|---|
| 57 | +} |
|---|
| 58 | +#endif |
|---|
| 59 | + |
|---|
| 34 | 60 | static inline bool have_hwcap(unsigned long ftr) |
|---|
| 35 | 61 | { |
|---|
| 36 | 62 | return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr; |
|---|
| .. | .. |
|---|
| 49 | 75 | #endif |
|---|
| 50 | 76 | |
|---|
| 51 | 77 | bool is_ppc64le(void); |
|---|
| 78 | +int using_hash_mmu(bool *using_hash); |
|---|
| 52 | 79 | |
|---|
| 53 | 80 | /* Yes, this is evil */ |
|---|
| 54 | 81 | #define FAIL_IF(x) \ |
|---|
| .. | .. |
|---|
| 57 | 84 | fprintf(stderr, \ |
|---|
| 58 | 85 | "[FAIL] Test FAILED on line %d\n", __LINE__); \ |
|---|
| 59 | 86 | return 1; \ |
|---|
| 87 | + } \ |
|---|
| 88 | +} while (0) |
|---|
| 89 | + |
|---|
| 90 | +#define FAIL_IF_EXIT(x) \ |
|---|
| 91 | +do { \ |
|---|
| 92 | + if ((x)) { \ |
|---|
| 93 | + fprintf(stderr, \ |
|---|
| 94 | + "[FAIL] Test FAILED on line %d\n", __LINE__); \ |
|---|
| 95 | + _exit(1); \ |
|---|
| 60 | 96 | } \ |
|---|
| 61 | 97 | } while (0) |
|---|
| 62 | 98 | |
|---|
| .. | .. |
|---|
| 72 | 108 | } \ |
|---|
| 73 | 109 | } while (0) |
|---|
| 74 | 110 | |
|---|
| 111 | +#define SKIP_IF_MSG(x, msg) \ |
|---|
| 112 | +do { \ |
|---|
| 113 | + if ((x)) { \ |
|---|
| 114 | + fprintf(stderr, \ |
|---|
| 115 | + "[SKIP] Test skipped on line %d: %s\n", \ |
|---|
| 116 | + __LINE__, msg); \ |
|---|
| 117 | + return MAGIC_SKIP_RETURN_VALUE; \ |
|---|
| 118 | + } \ |
|---|
| 119 | +} while (0) |
|---|
| 120 | + |
|---|
| 75 | 121 | #define _str(s) #s |
|---|
| 76 | 122 | #define str(s) _str(s) |
|---|
| 123 | + |
|---|
| 124 | +#define sigsafe_err(msg) ({ \ |
|---|
| 125 | + ssize_t nbytes __attribute__((unused)); \ |
|---|
| 126 | + nbytes = write(STDERR_FILENO, msg, strlen(msg)); }) |
|---|
| 77 | 127 | |
|---|
| 78 | 128 | /* POWER9 feature */ |
|---|
| 79 | 129 | #ifndef PPC_FEATURE2_ARCH_3_00 |
|---|
| 80 | 130 | #define PPC_FEATURE2_ARCH_3_00 0x00800000 |
|---|
| 81 | 131 | #endif |
|---|
| 82 | 132 | |
|---|
| 133 | +/* POWER10 feature */ |
|---|
| 134 | +#ifndef PPC_FEATURE2_ARCH_3_1 |
|---|
| 135 | +#define PPC_FEATURE2_ARCH_3_1 0x00040000 |
|---|
| 136 | +#endif |
|---|
| 137 | + |
|---|
| 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] |
|---|
| 144 | +#else |
|---|
| 145 | +#error implement UCONTEXT_NIA |
|---|
| 146 | +#endif |
|---|
| 147 | + |
|---|
| 83 | 148 | #endif /* _SELFTESTS_POWERPC_UTILS_H */ |
|---|