blob: 8a07152c701a594f8d5f88f82337d15ad73d07a3 [file] [log] [blame]
Eric Anholt8c641832009-03-26 17:15:11 -07001/*
Damien Lespiaubb33d082013-02-13 16:29:01 +00002 * Copyright © 2007, 2011, 2013 Intel Corporation
Eric Anholt8c641832009-03-26 17:15:11 -07003 *
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>
Daniel Vetteraa67b222012-01-10 14:59:58 +010025 * Daniel Vetter <daniel.vetter@ffwll.ch>
Eric Anholt8c641832009-03-26 17:15:11 -070026 *
27 */
28
Daniel Vetter00215dd2017-09-05 14:36:05 +020029#ifdef HAVE_LIBGEN_H
Oscar Mateo235ff9c2013-11-12 11:50:43 +000030#include <libgen.h>
31#endif
Ben Widawsky2585bea2012-03-25 16:04:07 -070032#include <stdio.h>
Eric Anholt8c641832009-03-26 17:15:11 -070033#include <fcntl.h>
34#include <sys/stat.h>
35#include <sys/ioctl.h>
Daniel Vetteraa67b222012-01-10 14:59:58 +010036#include <string.h>
Daniel Vetter527cad12012-01-10 18:41:46 +010037#include <sys/mman.h>
Daniel Vettercbaa8a32012-01-11 15:33:00 +010038#include <signal.h>
Daniel Vetter7b14b092012-01-15 17:40:41 +010039#include <pciaccess.h>
Damien Lespiaubb33d082013-02-13 16:29:01 +000040#include <stdlib.h>
Damien Lespiau4b347652013-04-29 16:04:52 +010041#include <unistd.h>
Daniel Vetter7553ad62013-08-12 10:43:59 +020042#include <sys/wait.h>
Tvrtko Ursulin139c72f2013-12-03 16:44:55 +000043#include <sys/types.h>
44#include <sys/syscall.h>
Daniel Vetterf1c4ec92013-12-10 09:26:08 +010045#include <sys/utsname.h>
Damien Lespiau377f48a2014-02-06 21:06:07 +000046#include <termios.h>
Daniel Vetter662d7322012-05-22 14:37:19 +020047
Eric Anholt8c641832009-03-26 17:15:11 -070048#include "drmtest.h"
Chris Wilson3c5c8ba2011-02-01 13:35:36 +000049#include "i915_drm.h"
50#include "intel_chipset.h"
Daniel Vetterc03c6ce2014-03-22 21:34:29 +010051#include "intel_io.h"
Oscar Mateoaa252d02013-11-05 14:15:19 +000052#include "igt_debugfs.h"
Chris Wilson137360f2017-03-23 17:09:26 +000053#include "igt_gt.h"
54#include "igt_kmod.h"
Rodrigo Vivi82ad15f2014-06-09 11:15:47 -070055#include "version.h"
Ben Widawsky8c33e9a2013-12-06 20:35:29 -080056#include "config.h"
Daniel Vetter6cfcd712014-03-22 20:07:35 +010057#include "intel_reg.h"
Daniel Vettere49ceb82014-03-22 21:07:37 +010058#include "ioctl_wrappers.h"
Abdiel Janulgue35fa2ca2016-10-11 21:30:08 +030059#include "igt_dummyload.h"
Chris Wilson3c5c8ba2011-02-01 13:35:36 +000060
Daniel Vetter187b66d2014-03-23 15:03:14 +010061/**
62 * SECTION:drmtest
63 * @short_description: Base library for drm tests and tools
64 * @title: drmtest
Thomas Woodf0381d12015-09-07 09:26:01 +010065 * @include: igt.h
Daniel Vetter187b66d2014-03-23 15:03:14 +010066 *
67 * This library contains the basic support for writing tests, with the most
68 * important part being the helper function to open drm device nodes.
69 *
70 * But there's also a bit of other assorted stuff here.
71 *
72 * Note that this library's header pulls in the [i-g-t core](intel-gpu-tools-i-g-t-core.html)
Daniel Vetterc6c2b2b2014-03-26 15:15:49 +010073 * and [batchbuffer](intel-gpu-tools-intel-batchbuffer.html) libraries as dependencies.
Daniel Vetter187b66d2014-03-23 15:03:14 +010074 */
Daniel Vetteraa67b222012-01-10 14:59:58 +010075
Chris Wilsoneaa7e612015-02-18 15:58:06 +000076uint16_t __drm_device_id;
77
Micah Fedkee2241802015-07-22 21:42:51 +000078static int __get_drm_device_name(int fd, char *name)
Chris Wilsona6e6c5b2014-07-25 17:34:06 +010079{
80 drm_version_t version;
Chris Wilsona6e6c5b2014-07-25 17:34:06 +010081
82 memset(&version, 0, sizeof(version));
83 version.name_len = 4;
84 version.name = name;
85
Micah Fedkee2241802015-07-22 21:42:51 +000086 if (!drmIoctl(fd, DRM_IOCTL_VERSION, &version)){
Chris Wilsona6e6c5b2014-07-25 17:34:06 +010087 return 0;
Micah Fedkee2241802015-07-22 21:42:51 +000088 }
Chris Wilsona6e6c5b2014-07-25 17:34:06 +010089
Micah Fedkee2241802015-07-22 21:42:51 +000090 return -1;
Chris Wilsona6e6c5b2014-07-25 17:34:06 +010091}
92
Chris Wilson7ce63892016-06-18 00:17:06 +010093static bool __is_device(int fd, const char *expect)
Micah Fedkee2241802015-07-22 21:42:51 +000094{
Micah Fedkee2241802015-07-22 21:42:51 +000095 char name[5] = "";
96
Chris Wilson7ce63892016-06-18 00:17:06 +010097 if (__get_drm_device_name(fd, name))
98 return false;
Micah Fedkee2241802015-07-22 21:42:51 +000099
Chris Wilson7ce63892016-06-18 00:17:06 +0100100 return strcmp(expect, name) == 0;
101}
102
103bool is_i915_device(int fd)
104{
105 return __is_device(fd, "i915");
Micah Fedkee2241802015-07-22 21:42:51 +0000106}
107
Eric Anholt3f83f072016-01-22 17:18:56 -0800108static bool is_vc4_device(int fd)
109{
Chris Wilson7ce63892016-06-18 00:17:06 +0100110 return __is_device(fd, "vc4");
111}
Eric Anholt3f83f072016-01-22 17:18:56 -0800112
Chris Wilson7ce63892016-06-18 00:17:06 +0100113static bool is_vgem_device(int fd)
114{
115 return __is_device(fd, "vgem");
Eric Anholt3f83f072016-01-22 17:18:56 -0800116}
117
Gustavo Padovan22779a72016-06-30 18:29:47 -0300118static bool is_virtio_device(int fd)
119{
120 return __is_device(fd, "virt");
121}
122
Chris Wilson36b92e82017-04-22 13:45:18 +0100123static bool is_amd_device(int fd)
124{
125 return __is_device(fd, "amdg");
126}
127
Tomeu Vizoso0eadf632016-03-08 09:18:45 +0100128static bool has_known_intel_chipset(int fd)
Chris Wilson3c5c8ba2011-02-01 13:35:36 +0000129{
130 struct drm_i915_getparam gp;
Chris Wilsonacca7242014-07-21 07:57:25 +0100131 int devid = 0;
Chris Wilson3c5c8ba2011-02-01 13:35:36 +0000132
Chris Wilsonacca7242014-07-21 07:57:25 +0100133 memset(&gp, 0, sizeof(gp));
Chris Wilson3c5c8ba2011-02-01 13:35:36 +0000134 gp.param = I915_PARAM_CHIPSET_ID;
135 gp.value = &devid;
136
137 if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp)))
Micah Fedkee2241802015-07-22 21:42:51 +0000138 return false;
Chris Wilson3c5c8ba2011-02-01 13:35:36 +0000139
Chris Wilsond308bb02016-06-29 08:28:58 +0100140 if (!intel_gen(devid))
Micah Fedkee2241802015-07-22 21:42:51 +0000141 return false;
Chris Wilsoneaa7e612015-02-18 15:58:06 +0000142
143 __drm_device_id = devid;
Micah Fedkee2241802015-07-22 21:42:51 +0000144 return true;
Chris Wilson3c5c8ba2011-02-01 13:35:36 +0000145}
Eric Anholt8c641832009-03-26 17:15:11 -0700146
Imre Deaka3b47db2013-05-28 17:22:57 +0300147#define LOCAL_I915_EXEC_VEBOX (4 << 0)
Daniel Vetter187b66d2014-03-23 15:03:14 +0100148/**
149 * gem_quiescent_gpu:
150 * @fd: open i915 drm file descriptor
151 *
152 * Ensure the gpu is idle by launching a nop execbuf and stalling for it. This
153 * is automatically run when opening a drm device node and is also installed as
154 * an exit handler to have the best assurance that the test is run in a pristine
155 * and controlled environment.
156 *
157 * This function simply allows tests to make additional calls in-between, if so
158 * desired.
159 */
Daniel Vetter9f876602012-01-11 17:19:53 +0100160void gem_quiescent_gpu(int fd)
161{
Chris Wilson0501dcf2016-03-04 15:35:24 +0000162 uint32_t bbe = MI_BATCH_BUFFER_END;
Daniel Vetter9f876602012-01-11 17:19:53 +0100163 struct drm_i915_gem_execbuffer2 execbuf;
Chris Wilson0501dcf2016-03-04 15:35:24 +0000164 struct drm_i915_gem_exec_object2 obj;
165 unsigned ring;
Daniel Vetter9f876602012-01-11 17:19:53 +0100166
Abdiel Janulgue35fa2ca2016-10-11 21:30:08 +0300167 igt_terminate_spin_batches();
168
Chris Wilson0501dcf2016-03-04 15:35:24 +0000169 memset(&obj, 0, sizeof(obj));
170 obj.handle = gem_create(fd, 4096);
171 gem_write(fd, obj.handle, 0, &bbe, sizeof(&bbe));
Daniel Vetter9f876602012-01-11 17:19:53 +0100172
Chris Wilson59f076a2015-11-20 11:23:37 +0000173 memset(&execbuf, 0, sizeof(execbuf));
Chris Wilson39858a12017-01-02 11:05:21 +0000174 execbuf.buffers_ptr = to_user_pointer(&obj);
Daniel Vetter9f876602012-01-11 17:19:53 +0100175 execbuf.buffer_count = 1;
Daniel Vetter9f876602012-01-11 17:19:53 +0100176
Chris Wilson0501dcf2016-03-04 15:35:24 +0000177 for (ring = 0; ring < 1<<6; ring++) {
178 execbuf.flags = ring;
179 __gem_execbuf(fd, &execbuf);
Imre Deaka3b47db2013-05-28 17:22:57 +0300180 }
181
Chris Wilson310f99c2016-03-04 15:03:42 +0000182 if (gem_has_bsd2(fd)) {
183 execbuf.flags = I915_EXEC_BSD | (2 << 13);
Chris Wilson0501dcf2016-03-04 15:35:24 +0000184 __gem_execbuf(fd, &execbuf);
Chris Wilson310f99c2016-03-04 15:03:42 +0000185 }
186
Chris Wilson0501dcf2016-03-04 15:35:24 +0000187 gem_sync(fd, obj.handle);
188 gem_close(fd, obj.handle);
Imre Deaka3b47db2013-05-28 17:22:57 +0300189
Chris Wilson83884e92017-03-21 17:16:03 +0000190 igt_drop_caches_set(fd, DROP_RETIRE | DROP_FREED);
Daniel Vetter9f876602012-01-11 17:19:53 +0100191}
192
Ben Widawsky2585bea2012-03-25 16:04:07 -0700193/**
Thomas Wood2d443862014-03-11 16:04:29 +0000194 * drm_get_card:
Ben Widawsky2585bea2012-03-25 16:04:07 -0700195 *
Daniel Vetter187b66d2014-03-23 15:03:14 +0100196 * Get an i915 drm card index number for use in /dev or /sys. The minor index of
197 * the legacy node is returned, not of the control or render node.
Thomas Wood2d443862014-03-11 16:04:29 +0000198 *
Daniel Vetter187b66d2014-03-23 15:03:14 +0100199 * Returns:
200 * The i915 drm index or -1 on error
Ben Widawsky2585bea2012-03-25 16:04:07 -0700201 */
Daniel Vetter5951ffb2013-08-19 10:34:34 +0200202int drm_get_card(void)
Ben Widawsky2585bea2012-03-25 16:04:07 -0700203{
204 char *name;
Eric Anholt8c641832009-03-26 17:15:11 -0700205 int i, fd;
206
207 for (i = 0; i < 16; i++) {
Ben Widawsky2585bea2012-03-25 16:04:07 -0700208 int ret;
209
210 ret = asprintf(&name, "/dev/dri/card%u", i);
Daniel Vetter8dbd1fb2013-08-19 11:09:25 +0200211 igt_assert(ret != -1);
212
Eric Anholt8c641832009-03-26 17:15:11 -0700213 fd = open(name, O_RDWR);
Ben Widawsky2585bea2012-03-25 16:04:07 -0700214 free(name);
215
Chris Wilson3c5c8ba2011-02-01 13:35:36 +0000216 if (fd == -1)
217 continue;
218
Tomeu Vizoso0eadf632016-03-08 09:18:45 +0100219 if (!is_i915_device(fd) || !has_known_intel_chipset(fd)) {
Damien Lespiau8329acb2013-10-24 15:04:26 +0100220 close(fd);
Daniel Vetter8dbd1fb2013-08-19 11:09:25 +0200221 continue;
Damien Lespiau8329acb2013-10-24 15:04:26 +0100222 }
Chris Wilson3c5c8ba2011-02-01 13:35:36 +0000223
224 close(fd);
Daniel Vetter8dbd1fb2013-08-19 11:09:25 +0200225 return i;
Eric Anholt8c641832009-03-26 17:15:11 -0700226 }
Ben Widawsky2585bea2012-03-25 16:04:07 -0700227
Daniel Vetter8dbd1fb2013-08-19 11:09:25 +0200228 igt_skip("No intel gpu found\n");
229
230 return -1;
Eric Anholt8c641832009-03-26 17:15:11 -0700231}
232
Chris Wilsond86d6eb2016-06-23 21:07:36 +0100233static int modprobe(const char *driver)
Chris Wilson7ce63892016-06-18 00:17:06 +0100234{
Chris Wilson137360f2017-03-23 17:09:26 +0000235 return igt_kmod_load(driver, "");
Chris Wilson7ce63892016-06-18 00:17:06 +0100236}
237
Micah Fedkee2241802015-07-22 21:42:51 +0000238/**
239 * __drm_open_driver:
Thomas Wood683316c2015-11-30 16:36:16 +0000240 * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL
Micah Fedkee2241802015-07-22 21:42:51 +0000241 *
242 * Open the first DRM device we can find, searching up to 16 device nodes
243 *
Micah Fedkee2241802015-07-22 21:42:51 +0000244 * Returns:
245 * An open DRM fd or -1 on error
246 */
247int __drm_open_driver(int chipset)
Ben Widawsky2585bea2012-03-25 16:04:07 -0700248{
Chris Wilson7ce63892016-06-18 00:17:06 +0100249 if (chipset & DRIVER_VGEM)
250 modprobe("vgem");
251
Chris Wilsona6e6c5b2014-07-25 17:34:06 +0100252 for (int i = 0; i < 16; i++) {
253 char name[80];
254 int fd;
Ben Widawsky2585bea2012-03-25 16:04:07 -0700255
Chris Wilsona6e6c5b2014-07-25 17:34:06 +0100256 sprintf(name, "/dev/dri/card%u", i);
257 fd = open(name, O_RDWR);
258 if (fd == -1)
259 continue;
Ben Widawsky2585bea2012-03-25 16:04:07 -0700260
Chris Wilson7ce63892016-06-18 00:17:06 +0100261 if (chipset & DRIVER_INTEL && is_i915_device(fd) &&
262 has_known_intel_chipset(fd))
263 return fd;
Micah Fedkee2241802015-07-22 21:42:51 +0000264
Chris Wilson7ce63892016-06-18 00:17:06 +0100265 if (chipset & DRIVER_VC4 &&
266 is_vc4_device(fd))
267 return fd;
Eric Anholt3f83f072016-01-22 17:18:56 -0800268
Chris Wilson7ce63892016-06-18 00:17:06 +0100269 if (chipset & DRIVER_VGEM &&
270 is_vgem_device(fd))
Chris Wilsona6e6c5b2014-07-25 17:34:06 +0100271 return fd;
Ben Widawsky2585bea2012-03-25 16:04:07 -0700272
Gustavo Padovan22779a72016-06-30 18:29:47 -0300273 if (chipset & DRIVER_VIRTIO &&
274 is_virtio_device(fd))
275 return fd;
276
Chris Wilson36b92e82017-04-22 13:45:18 +0100277 if (chipset & DRIVER_AMDGPU && is_amd_device(fd))
278 return fd;
279
Tomeu Vizoso9921aff2016-10-17 10:05:20 +0200280 /* Only VGEM-specific tests should be run on VGEM */
Tomeu Vizosoa8d774b2016-10-27 10:21:05 +0200281 if (chipset == DRIVER_ANY && !is_vgem_device(fd))
Tomeu Vizoso9921aff2016-10-17 10:05:20 +0200282 return fd;
283
Chris Wilson9eb7d892013-07-03 09:58:28 +0100284 close(fd);
Chris Wilson9eb7d892013-07-03 09:58:28 +0100285 }
Ben Widawsky2585bea2012-03-25 16:04:07 -0700286
Chris Wilsona6e6c5b2014-07-25 17:34:06 +0100287 return -1;
Ben Widawsky2585bea2012-03-25 16:04:07 -0700288}
Eric Anholt8c641832009-03-26 17:15:11 -0700289
Micah Fedkee2241802015-07-22 21:42:51 +0000290static int __drm_open_driver_render(int chipset)
Damien Lespiau69c200b2013-10-24 15:19:32 +0100291{
292 char *name;
293 int i, fd;
294
295 for (i = 128; i < (128 + 16); i++) {
296 int ret;
297
298 ret = asprintf(&name, "/dev/dri/renderD%u", i);
299 igt_assert(ret != -1);
300
301 fd = open(name, O_RDWR);
302 free(name);
303
304 if (fd == -1)
305 continue;
306
Tomeu Vizoso0eadf632016-03-08 09:18:45 +0100307 if (!is_i915_device(fd) || !has_known_intel_chipset(fd)) {
Damien Lespiau69c200b2013-10-24 15:19:32 +0100308 close(fd);
309 fd = -1;
310 continue;
311 }
312
313 return fd;
314 }
315
316 return fd;
317}
318
Imre Deak2423b6c2014-02-05 13:48:26 +0200319static int at_exit_drm_fd = -1;
320static int at_exit_drm_render_fd = -1;
321
Imre Deak1cb4f902013-05-28 17:35:32 +0300322static void quiescent_gpu_at_exit(int sig)
323{
Imre Deak2423b6c2014-02-05 13:48:26 +0200324 if (at_exit_drm_fd < 0)
325 return;
Imre Deak1cb4f902013-05-28 17:35:32 +0300326
Imre Deak2423b6c2014-02-05 13:48:26 +0200327 gem_quiescent_gpu(at_exit_drm_fd);
328 close(at_exit_drm_fd);
329 at_exit_drm_fd = -1;
Imre Deak1cb4f902013-05-28 17:35:32 +0300330}
331
Damien Lespiau69c200b2013-10-24 15:19:32 +0100332static void quiescent_gpu_at_exit_render(int sig)
333{
Imre Deak2423b6c2014-02-05 13:48:26 +0200334 if (at_exit_drm_render_fd < 0)
335 return;
Damien Lespiau69c200b2013-10-24 15:19:32 +0100336
Imre Deak2423b6c2014-02-05 13:48:26 +0200337 gem_quiescent_gpu(at_exit_drm_render_fd);
338 close(at_exit_drm_render_fd);
339 at_exit_drm_render_fd = -1;
Damien Lespiau69c200b2013-10-24 15:19:32 +0100340}
341
Daniel Vetter542658a2017-07-25 13:36:17 +0200342static const char *chipset_to_str(int chipset)
343{
344 switch (chipset) {
345 case DRIVER_INTEL:
346 return "intel";
347 case DRIVER_VC4:
348 return "vc4";
349 case DRIVER_VGEM:
350 return "vgem";
351 case DRIVER_VIRTIO:
352 return "virtio";
353 case DRIVER_AMDGPU:
354 return "amdgpu";
355 case DRIVER_ANY:
356 return "any";
357 default:
358 return "otehr";
359 }
360}
361
Daniel Vetter187b66d2014-03-23 15:03:14 +0100362/**
Micah Fedkee2241802015-07-22 21:42:51 +0000363 * drm_open_driver:
Thomas Wood683316c2015-11-30 16:36:16 +0000364 * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL
Daniel Vetter187b66d2014-03-23 15:03:14 +0100365 *
Micah Fedkee2241802015-07-22 21:42:51 +0000366 * Open a drm legacy device node. This function always returns a valid
Thomas Wood032f30c2015-01-13 13:33:57 +0000367 * file descriptor.
Daniel Vetter187b66d2014-03-23 15:03:14 +0100368 *
Micah Fedkee2241802015-07-22 21:42:51 +0000369 * Returns: a drm file descriptor
Daniel Vetter187b66d2014-03-23 15:03:14 +0100370 */
Micah Fedkee2241802015-07-22 21:42:51 +0000371int drm_open_driver(int chipset)
Imre Deak1cb4f902013-05-28 17:35:32 +0300372{
373 static int open_count;
Chris Wilson250f0472016-07-19 18:33:27 +0100374 int fd;
Imre Deak1cb4f902013-05-28 17:35:32 +0300375
Chris Wilson250f0472016-07-19 18:33:27 +0100376 fd = __drm_open_driver(chipset);
Daniel Vetter542658a2017-07-25 13:36:17 +0200377 igt_skip_on_f(fd<0, "No known gpu found for chipset flags 0x%u (%s)\n",
378 chipset, chipset_to_str(chipset));
Chris Wilson9eb7d892013-07-03 09:58:28 +0100379
Chris Wilson27d30702016-10-18 12:37:20 +0100380 /* For i915, at least, we ensure that the driver is idle before
381 * starting a test and we install an exit handler to wait until
382 * idle before quitting.
383 */
Robert Fosse1c3cde2016-06-28 10:01:48 +0100384 if (is_i915_device(fd)) {
Chris Wilson27d30702016-10-18 12:37:20 +0100385 if (__sync_fetch_and_add(&open_count, 1) == 0) {
386 gem_quiescent_gpu(fd);
387
388 at_exit_drm_fd = __drm_open_driver(chipset);
389 igt_install_exit_handler(quiescent_gpu_at_exit);
390 }
Micah Fedkee2241802015-07-22 21:42:51 +0000391 }
Imre Deak1cb4f902013-05-28 17:35:32 +0300392
393 return fd;
394}
395
Daniel Vetter187b66d2014-03-23 15:03:14 +0100396/**
Micah Fedkee2241802015-07-22 21:42:51 +0000397 * drm_open_driver_master:
Thomas Wood683316c2015-11-30 16:36:16 +0000398 * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL
Imre Deakbfda78c2014-09-18 18:25:37 +0300399 *
Micah Fedkee2241802015-07-22 21:42:51 +0000400 * Open a drm legacy device node and ensure that it is drm master.
Imre Deakbfda78c2014-09-18 18:25:37 +0300401 *
402 * Returns:
Micah Fedkee2241802015-07-22 21:42:51 +0000403 * The drm file descriptor or -1 on error
Imre Deakbfda78c2014-09-18 18:25:37 +0300404 */
Micah Fedkee2241802015-07-22 21:42:51 +0000405int drm_open_driver_master(int chipset)
Imre Deakbfda78c2014-09-18 18:25:37 +0300406{
Micah Fedkee2241802015-07-22 21:42:51 +0000407 int fd = drm_open_driver(chipset);
Imre Deakbfda78c2014-09-18 18:25:37 +0300408
Imre Deakbfda78c2014-09-18 18:25:37 +0300409 igt_require_f(drmSetMaster(fd) == 0, "Can't become DRM master, "
410 "please check if no other DRM client is running.\n");
411
412 return fd;
413}
414
415/**
Micah Fedkee2241802015-07-22 21:42:51 +0000416 * drm_open_driver_render:
Thomas Wood683316c2015-11-30 16:36:16 +0000417 * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL
Daniel Vetter187b66d2014-03-23 15:03:14 +0100418 *
Micah Fedkee2241802015-07-22 21:42:51 +0000419 * Open a drm render device node.
Daniel Vetter187b66d2014-03-23 15:03:14 +0100420 *
421 * Returns:
Micah Fedkee2241802015-07-22 21:42:51 +0000422 * The drm file descriptor or -1 on error
Daniel Vetter187b66d2014-03-23 15:03:14 +0100423 */
Micah Fedkee2241802015-07-22 21:42:51 +0000424int drm_open_driver_render(int chipset)
Damien Lespiau69c200b2013-10-24 15:19:32 +0100425{
426 static int open_count;
Micah Fedkee2241802015-07-22 21:42:51 +0000427 int fd = __drm_open_driver_render(chipset);
Damien Lespiau69c200b2013-10-24 15:19:32 +0100428
Micah Fedkee2241802015-07-22 21:42:51 +0000429 /* no render nodes, fallback to drm_open_driver() */
Damien Lespiau69c200b2013-10-24 15:19:32 +0100430 if (fd == -1)
Micah Fedkee2241802015-07-22 21:42:51 +0000431 return drm_open_driver(chipset);
Damien Lespiau69c200b2013-10-24 15:19:32 +0100432
433 if (__sync_fetch_and_add(&open_count, 1))
434 return fd;
435
Micah Fedkee2241802015-07-22 21:42:51 +0000436 at_exit_drm_render_fd = __drm_open_driver(chipset);
437 if(chipset & DRIVER_INTEL){
438 gem_quiescent_gpu(fd);
439 igt_install_exit_handler(quiescent_gpu_at_exit_render);
440 }
Damien Lespiau69c200b2013-10-24 15:19:32 +0100441
442 return fd;
443}
Tomeu Vizoso3fee80e2016-02-09 10:16:51 +0100444
445void igt_require_intel(int fd)
446{
447 igt_require(is_i915_device(fd) && has_known_intel_chipset(fd));
448}