blob: 9fcab9316bc4feca2dba4d5ab9639f3ece70860d [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
Micah Fedkee2241802015-07-22 21:42:51 +000041#define DRIVER_ANY 0x1
42#define DRIVER_INTEL (0x1 << 1)
Eric Anholt3f83f072016-01-22 17:18:56 -080043#define DRIVER_VC4 (0x1 << 2)
Micah Fedkee2241802015-07-22 21:42:51 +000044
Daniel Vetterbff22f72014-03-22 19:21:26 +010045#ifdef ANDROID
Tim Gore52888df2015-04-21 14:53:03 +010046#if (!(defined HAVE_MMAP64)) && (!(defined __x86_64__))
Daniel Vetterbff22f72014-03-22 19:21:26 +010047extern void* __mmap2(void *, size_t, int, int, int, off_t);
tgorea96c6342014-03-28 12:54:58 +000048
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
52static inline void *igt_mmap64(void *addr, size_t length, int prot, int flags,
Daniel Vetterbff22f72014-03-22 19:21:26 +010053 int fd, off64_t offset)
54{
55 return __mmap2(addr, length, prot, flags, fd, offset >> 12);
56}
57#endif
58#endif
59
Daniel Vetter187b66d2014-03-23 15:03:14 +010060/**
61 * ARRAY_SIZE:
62 * @arr: static array
63 *
64 * Macro to compute the size of the static array @arr.
65 */
Daniel Vetterbff22f72014-03-22 19:21:26 +010066#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
67
Tvrtko Ursulindc14bf42014-04-23 16:07:55 +010068/**
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 Vetter5951ffb2013-08-19 10:34:34 +020077int drm_get_card(void);
Micah Fedkee2241802015-07-22 21:42:51 +000078int drm_open_driver(int chipset);
79int drm_open_driver_master(int chipset);
80int drm_open_driver_render(int chipset);
81int __drm_open_driver(int chipset);
Daniel Vetteraa67b222012-01-10 14:59:58 +010082
Daniel Vetter9f876602012-01-11 17:19:53 +010083void gem_quiescent_gpu(int fd);
Daniel Vetteraa67b222012-01-10 14:59:58 +010084
Daniel Vetter187b66d2014-03-23 15:03:14 +010085/**
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 Vetter79abed32013-08-15 11:55:32 +020093#define do_or_die(x) igt_assert((x) == 0)
Daniel Vetter187b66d2014-03-23 15:03:14 +010094
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 Wilsonb918a3b2014-04-25 07:40:34 +0100104#define do_ioctl(fd, ioc, ioc_data) do { \
Daniel Stonec8cec6b2015-10-01 13:02:38 +0100105 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 Wilsonb918a3b2014-04-25 07:40:34 +0100122 errno = 0; \
123} while (0)
Imre Deakcf264352013-05-08 19:06:42 +0300124
Chris Wilsond0ed9122013-08-29 15:11:47 +0100125#endif /* DRMTEST_H */