blob: a86799d54834c2a23102b2f3c68ad9c0778eb76d [file] [log] [blame]
Eric Anholt8c641832009-03-26 17:15:11 -07001/*
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 Wilsond0ed9122013-08-29 15:11:47 +010028#ifndef DRMTEST_H
29#define DRMTEST_H
30
Eric Anholt8c641832009-03-26 17:15:11 -070031#include <unistd.h>
Daniel Vetterafbdc7a2012-03-22 13:47:57 +010032#include <stdbool.h>
Daniel Vetter254f19b2014-03-22 21:29:01 +010033#include <stdint.h>
Daniel Vetter225a91b2013-09-03 10:38:29 +020034#include <sys/mman.h>
Chris Wilsonb918a3b2014-04-25 07:40:34 +010035#include <errno.h>
Eric Anholt8c641832009-03-26 17:15:11 -070036
Daniel Vetter254f19b2014-03-22 21:29:01 +010037#include <xf86drm.h>
Daniel Vetterf5daeec2014-03-23 13:35:09 +010038
39#include "intel_batchbuffer.h"
Daniel Vetter766c5bc2014-03-11 22:58:07 +010040
Chris Wilson7ce63892016-06-18 00:17:06 +010041#define DRIVER_INTEL (1 << 0)
42#define DRIVER_VC4 (1 << 1)
43#define DRIVER_VGEM (1 << 2)
Gustavo Padovan22779a72016-06-30 18:29:47 -030044#define DRIVER_VIRTIO (1 << 3)
Chris Wilson36b92e82017-04-22 13:45:18 +010045#define DRIVER_AMDGPU (1 << 4)
Robert Foss7b9499f2017-01-30 10:09:42 -050046/*
47 * Exclude DRVER_VGEM from DRIVER_ANY since if you run on a system
48 * with vgem as well as a supported driver, you can end up with a
49 * near-100% skip rate if you don't explicitly specify the device,
50 * depending on device-load ordering.
51 */
Chris Wilson7ce63892016-06-18 00:17:06 +010052#define DRIVER_ANY ~(DRIVER_VGEM)
Micah Fedkee2241802015-07-22 21:42:51 +000053
Robert Foss7b9499f2017-01-30 10:09:42 -050054
Daniel Vetterbff22f72014-03-22 19:21:26 +010055#ifdef ANDROID
Tim Gore52888df2015-04-21 14:53:03 +010056#if (!(defined HAVE_MMAP64)) && (!(defined __x86_64__))
Daniel Vetterbff22f72014-03-22 19:21:26 +010057extern void* __mmap2(void *, size_t, int, int, int, off_t);
tgorea96c6342014-03-28 12:54:58 +000058
59/* mmap64 is a recent addition to bionic and not available in all android builds. */
60/* I can find no reliable way to know if it is defined or not - so just avoid it */
61#define mmap64 igt_mmap64
62static inline void *igt_mmap64(void *addr, size_t length, int prot, int flags,
Daniel Vetterbff22f72014-03-22 19:21:26 +010063 int fd, off64_t offset)
64{
65 return __mmap2(addr, length, prot, flags, fd, offset >> 12);
66}
67#endif
68#endif
69
Daniel Vetter187b66d2014-03-23 15:03:14 +010070/**
71 * ARRAY_SIZE:
72 * @arr: static array
73 *
74 * Macro to compute the size of the static array @arr.
75 */
Daniel Vetterbff22f72014-03-22 19:21:26 +010076#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
77
Tvrtko Ursulindc14bf42014-04-23 16:07:55 +010078/**
79 * ALIGN:
80 * @v: value to be aligned
81 * @a: alignment unit in bytes
82 *
83 * Macro to align a value @v to a specified unit @a.
84 */
85#define ALIGN(v, a) (((v) + (a)-1) & ~((a)-1))
86
Daniel Vetter5951ffb2013-08-19 10:34:34 +020087int drm_get_card(void);
Micah Fedkee2241802015-07-22 21:42:51 +000088int drm_open_driver(int chipset);
89int drm_open_driver_master(int chipset);
90int drm_open_driver_render(int chipset);
91int __drm_open_driver(int chipset);
Daniel Vetteraa67b222012-01-10 14:59:58 +010092
Daniel Vetter9f876602012-01-11 17:19:53 +010093void gem_quiescent_gpu(int fd);
Daniel Vetteraa67b222012-01-10 14:59:58 +010094
Tomeu Vizoso3fee80e2016-02-09 10:16:51 +010095void igt_require_intel(int fd);
96
Tomeu Vizosoe0e3a062016-02-18 14:25:43 +010097bool is_i915_device(int fd);
98
Daniel Vetter187b66d2014-03-23 15:03:14 +010099/**
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 */
Daniel Vetter79abed32013-08-15 11:55:32 +0200107#define do_or_die(x) igt_assert((x) == 0)
Daniel Vetter187b66d2014-03-23 15:03:14 +0100108
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 */
Chris Wilsonb918a3b2014-04-25 07:40:34 +0100118#define do_ioctl(fd, ioc, ioc_data) do { \
Chris Wilsonc1fed522016-03-19 13:00:29 +0000119 igt_assert_eq(igt_ioctl((fd), (ioc), (ioc_data)), 0); \
Daniel Stonec8cec6b2015-10-01 13:02:38 +0100120 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 { \
Chris Wilsonc1fed522016-03-19 13:00:29 +0000134 igt_assert_eq(igt_ioctl((fd), (ioc), (ioc_data)), -1); \
Daniel Stonec8cec6b2015-10-01 13:02:38 +0100135 igt_assert_eq(errno, err); \
Chris Wilsonb918a3b2014-04-25 07:40:34 +0100136 errno = 0; \
137} while (0)
Imre Deakcf264352013-05-08 19:06:42 +0300138
Chris Wilsond0ed9122013-08-29 15:11:47 +0100139#endif /* DRMTEST_H */