2013-08-06 07:42:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013, Michael Ellerman, IBM Corp.
|
|
|
|
* Licensed under GPLv2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SELFTESTS_POWERPC_UTILS_H
|
|
|
|
#define _SELFTESTS_POWERPC_UTILS_H
|
|
|
|
|
2016-05-02 03:51:38 +00:00
|
|
|
#define __cacheline_aligned __attribute__((aligned(128)))
|
|
|
|
|
2013-08-06 07:42:36 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2015-11-24 02:05:39 +00:00
|
|
|
#include <linux/auxvec.h>
|
2015-12-23 05:49:50 +00:00
|
|
|
#include "reg.h"
|
2013-08-06 07:42:36 +00:00
|
|
|
|
|
|
|
/* Avoid headaches with PRI?64 - just use %ll? always */
|
|
|
|
typedef unsigned long long u64;
|
|
|
|
typedef signed long long s64;
|
|
|
|
|
|
|
|
/* Just for familiarity */
|
|
|
|
typedef uint32_t u32;
|
2015-02-23 15:14:44 +00:00
|
|
|
typedef uint16_t u16;
|
2013-08-06 07:42:36 +00:00
|
|
|
typedef uint8_t u8;
|
|
|
|
|
2016-09-23 06:18:17 +00:00
|
|
|
void test_harness_set_timeout(uint64_t time);
|
2013-08-06 07:42:36 +00:00
|
|
|
int test_harness(int (test_function)(void), char *name);
|
2017-02-06 10:13:27 +00:00
|
|
|
|
|
|
|
int read_auxv(char *buf, ssize_t buf_size);
|
|
|
|
void *find_auxv_entry(int type, char *auxv);
|
|
|
|
void *get_auxv_entry(int type);
|
|
|
|
|
2015-12-16 07:59:31 +00:00
|
|
|
int pick_online_cpu(void);
|
2013-08-06 07:42:36 +00:00
|
|
|
|
2016-07-11 05:25:18 +00:00
|
|
|
static inline bool have_hwcap(unsigned long ftr)
|
|
|
|
{
|
|
|
|
return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr;
|
|
|
|
}
|
|
|
|
|
2016-09-23 06:18:07 +00:00
|
|
|
#ifdef AT_HWCAP2
|
2015-11-24 02:05:39 +00:00
|
|
|
static inline bool have_hwcap2(unsigned long ftr2)
|
|
|
|
{
|
|
|
|
return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
|
|
|
|
}
|
2016-09-23 06:18:07 +00:00
|
|
|
#else
|
|
|
|
static inline bool have_hwcap2(unsigned long ftr2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2015-11-24 02:05:39 +00:00
|
|
|
|
2018-07-26 12:24:57 +00:00
|
|
|
bool is_ppc64le(void);
|
|
|
|
|
2013-08-06 07:42:36 +00:00
|
|
|
/* Yes, this is evil */
|
|
|
|
#define FAIL_IF(x) \
|
|
|
|
do { \
|
|
|
|
if ((x)) { \
|
|
|
|
fprintf(stderr, \
|
|
|
|
"[FAIL] Test FAILED on line %d\n", __LINE__); \
|
|
|
|
return 1; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2014-06-10 12:23:09 +00:00
|
|
|
/* The test harness uses this, yes it's gross */
|
|
|
|
#define MAGIC_SKIP_RETURN_VALUE 99
|
|
|
|
|
|
|
|
#define SKIP_IF(x) \
|
|
|
|
do { \
|
|
|
|
if ((x)) { \
|
|
|
|
fprintf(stderr, \
|
|
|
|
"[SKIP] Test skipped on line %d\n", __LINE__); \
|
|
|
|
return MAGIC_SKIP_RETURN_VALUE; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2014-01-21 04:22:17 +00:00
|
|
|
#define _str(s) #s
|
|
|
|
#define str(s) _str(s)
|
|
|
|
|
2016-05-02 03:51:38 +00:00
|
|
|
/* POWER9 feature */
|
|
|
|
#ifndef PPC_FEATURE2_ARCH_3_00
|
|
|
|
#define PPC_FEATURE2_ARCH_3_00 0x00800000
|
|
|
|
#endif
|
|
|
|
|
2013-08-06 07:42:36 +00:00
|
|
|
#endif /* _SELFTESTS_POWERPC_UTILS_H */
|