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