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 <[email protected]> 25 * 26 */ 27 28 #ifndef DRMTEST_H 29 #define DRMTEST_H 30 31 #include <unistd.h> 32 #include <stdbool.h> 33 #include <stdint.h> 34 #include <sys/mman.h> 35 #include <errno.h> 36 37 #include <xf86drm.h> 38 39 #include "igt_core.h" 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /* 46 * NOTE: Theser are _only_ for testcases exercising driver specific rendering 47 * ioctls and uapi (and a bunch of historical reasons). And KMS testcase should 48 * be build on top of DRIVER_ANY. Do _NOT_ add your driver here for enabling KMS 49 * tests. 50 */ 51 #define DRIVER_INTEL (1 << 0) 52 #define DRIVER_VC4 (1 << 1) 53 #define DRIVER_VGEM (1 << 2) 54 #define DRIVER_AMDGPU (1 << 3) 55 #define DRIVER_V3D (1 << 4) 56 #define DRIVER_PANFROST (1 << 5) 57 /* 58 * Exclude DRVER_VGEM from DRIVER_ANY since if you run on a system 59 * with vgem as well as a supported driver, you can end up with a 60 * near-100% skip rate if you don't explicitly specify the device, 61 * depending on device-load ordering. 62 */ 63 #define DRIVER_ANY ~(DRIVER_VGEM) 64 65 void __set_forced_driver(const char *name); 66 67 /** 68 * ARRAY_SIZE: 69 * @arr: static array 70 * 71 * Macro to compute the size of the static array @arr. 72 */ 73 #define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0])) 74 75 /** 76 * ALIGN: 77 * @v: value to be aligned 78 * @a: alignment unit in bytes 79 * 80 * Macro to align a value @v to a specified unit @a. 81 */ 82 #define ALIGN(v, a) (((v) + (a)-1) & ~((a)-1)) 83 84 int drm_open_driver(int chipset); 85 int drm_open_driver_master(int chipset); 86 int drm_open_driver_render(int chipset); 87 int __drm_open_driver(int chipset); 88 89 void gem_quiescent_gpu(int fd); 90 91 void igt_require_amdgpu(int fd); 92 void igt_require_intel(int fd); 93 void igt_require_vc4(int fd); 94 95 bool is_amdgpu_device(int fd); 96 bool is_i915_device(int fd); 97 bool is_vc4_device(int fd); 98 99 /** 100 * do_or_die: 101 * @x: command 102 * 103 * Simple macro to execute x and check that it's return value is 0. Presumes 104 * that in any failure case the return value is non-zero and a precise error is 105 * logged into errno. Uses igt_assert() internally. 106 */ 107 #define do_or_die(x) igt_assert((x) == 0) 108 109 /** 110 * do_ioctl: 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 * 115 * This macro wraps drmIoctl() and uses igt_assert to check that it has been 116 * successfully executed. 117 */ 118 #define do_ioctl(fd, ioc, ioc_data) do { \ 119 igt_assert_eq(igt_ioctl((fd), (ioc), (ioc_data)), 0); \ 120 errno = 0; \ 121 } while (0) 122 123 /** 124 * do_ioctl_err: 125 * @fd: open i915 drm file descriptor 126 * @ioc: ioctl op definition from drm headers 127 * @ioc_data: data pointer for the ioctl operation 128 * @err: value to expect in errno 129 * 130 * This macro wraps drmIoctl() and uses igt_assert to check that it fails, 131 * returning a particular value in errno. 132 */ 133 #define do_ioctl_err(fd, ioc, ioc_data, err) do { \ 134 igt_assert_eq(igt_ioctl((fd), (ioc), (ioc_data)), -1); \ 135 igt_assert_eq(errno, err); \ 136 errno = 0; \ 137 } while (0) 138 139 #ifdef __cplusplus 140 } 141 #endif 142 143 #endif /* DRMTEST_H */ 144