| 1 |
/* |
| 2 |
* Copyright © 2022 Imagination Technologies Ltd. |
| 3 |
* |
| 4 |
* based in part on anv driver which is: |
| 5 |
* Copyright © 2015 Intel Corporation |
| 6 |
* |
| 7 |
* based in part on radv driver which is: |
| 8 |
* Copyright © 2016 Red Hat. |
| 9 |
* Copyright © 2016 Bas Nieuwenhuizen |
| 10 |
* |
| 11 |
* SPDX-License-Identifier: MIT |
| 12 |
*/ |
| 13 |
|
| 14 |
#ifndef PVR_MACROS_H |
| 15 |
#define PVR_MACROS_H |
| 16 |
|
| 17 |
#ifdef HAVE_VALGRIND |
| 18 |
# include <valgrind/valgrind.h> |
| 19 |
# include <valgrind/memcheck.h> |
| 20 |
# define VG(x) x |
| 21 |
#else |
| 22 |
# define VG(x) ((void)0) |
| 23 |
#endif |
| 24 |
|
| 25 |
/** |
| 26 |
* Print a FINISHME message, including its source location. |
| 27 |
*/ |
| 28 |
#define pvr_finishme(format, ...) \ |
| 29 |
do { \ |
| 30 |
static bool reported = false; \ |
| 31 |
if (!reported) { \ |
| 32 |
mesa_logw("%s:%d: FINISHME: " format, \ |
| 33 |
__FILE__, \ |
| 34 |
__LINE__, \ |
| 35 |
##__VA_ARGS__); \ |
| 36 |
reported = true; \ |
| 37 |
} \ |
| 38 |
} while (false) |
| 39 |
|
| 40 |
#define PVR_WRITE(_buffer, _value, _offset, _max) \ |
| 41 |
do { \ |
| 42 |
__typeof__(_value) __value = _value; \ |
| 43 |
uint64_t __offset = _offset; \ |
| 44 |
uint32_t __nr_dwords = sizeof(__value) / sizeof(uint32_t); \ |
| 45 |
static_assert(__same_type(*_buffer, __value), \ |
| 46 |
"Buffer and value type mismatch"); \ |
| 47 |
assert((__offset + __nr_dwords) <= (_max)); \ |
| 48 |
assert((__offset % __nr_dwords) == 0U); \ |
| 49 |
_buffer[__offset / __nr_dwords] = __value; \ |
| 50 |
} while (0) |
| 51 |
|
| 52 |
#define PVR_ARCH_NAME(name, arch) pvr_##arch##_##name |
| 53 |
|
| 54 |
#define PVR_ARCH_DISPATCH(name, arch, ...) \ |
| 55 |
do { \ |
| 56 |
switch (arch) { \ |
| 57 |
case PVR_DEVICE_ARCH_ROGUE: \ |
| 58 |
PVR_ARCH_NAME(name, rogue)(__VA_ARGS__); \ |
| 59 |
break; \ |
| 60 |
default: \ |
| 61 |
UNREACHABLE("Unsupported architecture"); \ |
| 62 |
} \ |
| 63 |
} while (0) |
| 64 |
|
| 65 |
#define PVR_ARCH_DISPATCH_RET(name, arch, ret, ...) \ |
| 66 |
do { \ |
| 67 |
switch (arch) { \ |
| 68 |
case PVR_DEVICE_ARCH_ROGUE: \ |
| 69 |
ret = PVR_ARCH_NAME(name, rogue)(__VA_ARGS__); \ |
| 70 |
break; \ |
| 71 |
default: \ |
| 72 |
UNREACHABLE("Unsupported architecture"); \ |
| 73 |
} \ |
| 74 |
} while (0) |
| 75 |
|
| 76 |
#if defined(PVR_BUILD_ARCH_ROGUE) |
| 77 |
# define PVR_PER_ARCH(name) PVR_ARCH_NAME(name, rogue) |
| 78 |
#endif |
| 79 |
|
| 80 |
#endif /* PVR_MACROS_H */ |