Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2007 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | * |
| 26 | */ |
| 27 | |
Chris Wilson | d0ed912 | 2013-08-29 15:11:47 +0100 | [diff] [blame] | 28 | #ifndef DRMTEST_H |
| 29 | #define DRMTEST_H |
| 30 | |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 31 | #include <unistd.h> |
Daniel Vetter | afbdc7a | 2012-03-22 13:47:57 +0100 | [diff] [blame] | 32 | #include <stdbool.h> |
Daniel Vetter | 254f19b | 2014-03-22 21:29:01 +0100 | [diff] [blame] | 33 | #include <stdint.h> |
Daniel Vetter | 225a91b | 2013-09-03 10:38:29 +0200 | [diff] [blame] | 34 | #include <sys/mman.h> |
Chris Wilson | b918a3b | 2014-04-25 07:40:34 +0100 | [diff] [blame] | 35 | #include <errno.h> |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 36 | |
Daniel Vetter | 254f19b | 2014-03-22 21:29:01 +0100 | [diff] [blame] | 37 | #include <xf86drm.h> |
Daniel Vetter | f5daeec | 2014-03-23 13:35:09 +0100 | [diff] [blame] | 38 | |
| 39 | #include "intel_batchbuffer.h" |
Daniel Vetter | 766c5bc | 2014-03-11 22:58:07 +0100 | [diff] [blame] | 40 | |
Micah Fedke | e224180 | 2015-07-22 21:42:51 +0000 | [diff] [blame] | 41 | #define DRIVER_ANY 0x1 |
| 42 | #define DRIVER_INTEL (0x1 << 1) |
Eric Anholt | 3f83f07 | 2016-01-22 17:18:56 -0800 | [diff] [blame] | 43 | #define DRIVER_VC4 (0x1 << 2) |
Micah Fedke | e224180 | 2015-07-22 21:42:51 +0000 | [diff] [blame] | 44 | |
Daniel Vetter | bff22f7 | 2014-03-22 19:21:26 +0100 | [diff] [blame] | 45 | #ifdef ANDROID |
Tim Gore | 52888df | 2015-04-21 14:53:03 +0100 | [diff] [blame] | 46 | #if (!(defined HAVE_MMAP64)) && (!(defined __x86_64__)) |
Daniel Vetter | bff22f7 | 2014-03-22 19:21:26 +0100 | [diff] [blame] | 47 | extern void* __mmap2(void *, size_t, int, int, int, off_t); |
tgore | a96c634 | 2014-03-28 12:54:58 +0000 | [diff] [blame] | 48 | |
| 49 | /* mmap64 is a recent addition to bionic and not available in all android builds. */ |
| 50 | /* I can find no reliable way to know if it is defined or not - so just avoid it */ |
| 51 | #define mmap64 igt_mmap64 |
| 52 | static inline void *igt_mmap64(void *addr, size_t length, int prot, int flags, |
Daniel Vetter | bff22f7 | 2014-03-22 19:21:26 +0100 | [diff] [blame] | 53 | int fd, off64_t offset) |
| 54 | { |
| 55 | return __mmap2(addr, length, prot, flags, fd, offset >> 12); |
| 56 | } |
| 57 | #endif |
| 58 | #endif |
| 59 | |
Daniel Vetter | 187b66d | 2014-03-23 15:03:14 +0100 | [diff] [blame] | 60 | /** |
| 61 | * ARRAY_SIZE: |
| 62 | * @arr: static array |
| 63 | * |
| 64 | * Macro to compute the size of the static array @arr. |
| 65 | */ |
Daniel Vetter | bff22f7 | 2014-03-22 19:21:26 +0100 | [diff] [blame] | 66 | #define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) |
| 67 | |
Tvrtko Ursulin | dc14bf4 | 2014-04-23 16:07:55 +0100 | [diff] [blame] | 68 | /** |
| 69 | * ALIGN: |
| 70 | * @v: value to be aligned |
| 71 | * @a: alignment unit in bytes |
| 72 | * |
| 73 | * Macro to align a value @v to a specified unit @a. |
| 74 | */ |
| 75 | #define ALIGN(v, a) (((v) + (a)-1) & ~((a)-1)) |
| 76 | |
Daniel Vetter | 5951ffb | 2013-08-19 10:34:34 +0200 | [diff] [blame] | 77 | int drm_get_card(void); |
Micah Fedke | e224180 | 2015-07-22 21:42:51 +0000 | [diff] [blame] | 78 | int drm_open_driver(int chipset); |
| 79 | int drm_open_driver_master(int chipset); |
| 80 | int drm_open_driver_render(int chipset); |
| 81 | int __drm_open_driver(int chipset); |
Daniel Vetter | aa67b22 | 2012-01-10 14:59:58 +0100 | [diff] [blame] | 82 | |
Daniel Vetter | 9f87660 | 2012-01-11 17:19:53 +0100 | [diff] [blame] | 83 | void gem_quiescent_gpu(int fd); |
Daniel Vetter | aa67b22 | 2012-01-10 14:59:58 +0100 | [diff] [blame] | 84 | |
Daniel Vetter | 187b66d | 2014-03-23 15:03:14 +0100 | [diff] [blame] | 85 | /** |
| 86 | * do_or_die: |
| 87 | * @x: command |
| 88 | * |
| 89 | * Simple macro to execute x and check that it's return value is 0. Presumes |
| 90 | * that in any failure case the return value is non-zero and a precise error is |
| 91 | * logged into errno. Uses igt_assert() internally. |
| 92 | */ |
Daniel Vetter | 79abed3 | 2013-08-15 11:55:32 +0200 | [diff] [blame] | 93 | #define do_or_die(x) igt_assert((x) == 0) |
Daniel Vetter | 187b66d | 2014-03-23 15:03:14 +0100 | [diff] [blame] | 94 | |
| 95 | /** |
| 96 | * do_ioctl: |
| 97 | * @fd: open i915 drm file descriptor |
| 98 | * @ioc: ioctl op definition from drm headers |
| 99 | * @ioc_data: data pointer for the ioctl operation |
| 100 | * |
| 101 | * This macro wraps drmIoctl() and uses igt_assert to check that it has been |
| 102 | * successfully executed. |
| 103 | */ |
Chris Wilson | b918a3b | 2014-04-25 07:40:34 +0100 | [diff] [blame] | 104 | #define do_ioctl(fd, ioc, ioc_data) do { \ |
Daniel Stone | c8cec6b | 2015-10-01 13:02:38 +0100 | [diff] [blame] | 105 | igt_assert_eq(drmIoctl((fd), (ioc), (ioc_data)), 0); \ |
| 106 | errno = 0; \ |
| 107 | } while (0) |
| 108 | |
| 109 | /** |
| 110 | * do_ioctl_err: |
| 111 | * @fd: open i915 drm file descriptor |
| 112 | * @ioc: ioctl op definition from drm headers |
| 113 | * @ioc_data: data pointer for the ioctl operation |
| 114 | * @err: value to expect in errno |
| 115 | * |
| 116 | * This macro wraps drmIoctl() and uses igt_assert to check that it fails, |
| 117 | * returning a particular value in errno. |
| 118 | */ |
| 119 | #define do_ioctl_err(fd, ioc, ioc_data, err) do { \ |
| 120 | igt_assert_eq(drmIoctl((fd), (ioc), (ioc_data)), -1); \ |
| 121 | igt_assert_eq(errno, err); \ |
Chris Wilson | b918a3b | 2014-04-25 07:40:34 +0100 | [diff] [blame] | 122 | errno = 0; \ |
| 123 | } while (0) |
Imre Deak | cf26435 | 2013-05-08 19:06:42 +0300 | [diff] [blame] | 124 | |
Chris Wilson | d0ed912 | 2013-08-29 15:11:47 +0100 | [diff] [blame] | 125 | #endif /* DRMTEST_H */ |