Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013, Michael Ellerman, IBM Corp. |
| 3 | * Licensed under GPLv2. |
| 4 | */ |
| 5 | |
| 6 | #ifndef _SELFTESTS_POWERPC_UTILS_H |
| 7 | #define _SELFTESTS_POWERPC_UTILS_H |
| 8 | |
Chris Smart | 438517e | 2016-05-02 13:51:38 +1000 | [diff] [blame] | 9 | #define __cacheline_aligned __attribute__((aligned(128))) |
| 10 | |
Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 11 | #include <stdint.h> |
| 12 | #include <stdbool.h> |
Michael Ellerman | ede8ef3 | 2015-11-24 13:05:39 +1100 | [diff] [blame] | 13 | #include <linux/auxvec.h> |
Rashmica Gupta | 2d59b3b | 2015-12-23 16:49:50 +1100 | [diff] [blame] | 14 | #include "reg.h" |
Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 15 | |
| 16 | /* Avoid headaches with PRI?64 - just use %ll? always */ |
| 17 | typedef unsigned long long u64; |
| 18 | typedef signed long long s64; |
| 19 | |
| 20 | /* Just for familiarity */ |
| 21 | typedef uint32_t u32; |
Greg Kurz | 58dae82 | 2015-02-23 16:14:44 +0100 | [diff] [blame] | 22 | typedef uint16_t u16; |
Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 23 | typedef uint8_t u8; |
| 24 | |
Cyril Bur | 0886c6d | 2016-09-23 16:18:17 +1000 | [diff] [blame] | 25 | void test_harness_set_timeout(uint64_t time); |
Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 26 | int test_harness(int (test_function)(void), char *name); |
Sam bobroff | 2b03fc1 | 2015-04-10 14:16:48 +1000 | [diff] [blame] | 27 | extern void *get_auxv_entry(int type); |
Michael Ellerman | d1301af | 2015-12-16 18:59:31 +1100 | [diff] [blame] | 28 | int pick_online_cpu(void); |
Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 29 | |
Michael Ellerman | 24af8c5 | 2016-07-11 15:25:18 +1000 | [diff] [blame] | 30 | static inline bool have_hwcap(unsigned long ftr) |
| 31 | { |
| 32 | return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr; |
| 33 | } |
| 34 | |
Cyril Bur | 96c4470 | 2016-09-23 16:18:07 +1000 | [diff] [blame] | 35 | #ifdef AT_HWCAP2 |
Michael Ellerman | ede8ef3 | 2015-11-24 13:05:39 +1100 | [diff] [blame] | 36 | static inline bool have_hwcap2(unsigned long ftr2) |
| 37 | { |
| 38 | return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2; |
| 39 | } |
Cyril Bur | 96c4470 | 2016-09-23 16:18:07 +1000 | [diff] [blame] | 40 | #else |
| 41 | static inline bool have_hwcap2(unsigned long ftr2) |
| 42 | { |
| 43 | return false; |
| 44 | } |
| 45 | #endif |
Michael Ellerman | ede8ef3 | 2015-11-24 13:05:39 +1100 | [diff] [blame] | 46 | |
Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 47 | /* Yes, this is evil */ |
| 48 | #define FAIL_IF(x) \ |
| 49 | do { \ |
| 50 | if ((x)) { \ |
| 51 | fprintf(stderr, \ |
| 52 | "[FAIL] Test FAILED on line %d\n", __LINE__); \ |
| 53 | return 1; \ |
| 54 | } \ |
| 55 | } while (0) |
| 56 | |
Michael Ellerman | 33b4819 | 2014-06-10 22:23:09 +1000 | [diff] [blame] | 57 | /* The test harness uses this, yes it's gross */ |
| 58 | #define MAGIC_SKIP_RETURN_VALUE 99 |
| 59 | |
| 60 | #define SKIP_IF(x) \ |
| 61 | do { \ |
| 62 | if ((x)) { \ |
| 63 | fprintf(stderr, \ |
| 64 | "[SKIP] Test skipped on line %d\n", __LINE__); \ |
| 65 | return MAGIC_SKIP_RETURN_VALUE; \ |
| 66 | } \ |
| 67 | } while (0) |
| 68 | |
Michael Ellerman | 22d651d | 2014-01-21 15:22:17 +1100 | [diff] [blame] | 69 | #define _str(s) #s |
| 70 | #define str(s) _str(s) |
| 71 | |
Chris Smart | 438517e | 2016-05-02 13:51:38 +1000 | [diff] [blame] | 72 | /* POWER9 feature */ |
| 73 | #ifndef PPC_FEATURE2_ARCH_3_00 |
| 74 | #define PPC_FEATURE2_ARCH_3_00 0x00800000 |
| 75 | #endif |
| 76 | |
Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 77 | #endif /* _SELFTESTS_POWERPC_UTILS_H */ |