blob: 1663b7f8092b05a462e3e397363d29c58cedc147 [file] [log] [blame]
Daniel Vetter766c5bc2014-03-11 22:58:07 +01001/*
2 * Copyright © 2007,2014 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 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 *
27 */
28
29
30#ifndef IOCTL_WRAPPERS_H
31#define IOCTL_WRAPPERS_H
32
Daniel Vettere49ceb82014-03-22 21:07:37 +010033#include <stdint.h>
34#include <stdbool.h>
Chris Wilsondddbc2e2017-09-06 15:34:13 +010035#include <sys/mman.h>
Daniel Vettere49ceb82014-03-22 21:07:37 +010036#include <intel_bufmgr.h>
37#include <i915_drm.h>
38
Daniel Vetterd7050f92016-05-11 17:06:28 +020039/**
40 * igt_ioctl:
41 * @fd: file descriptor
42 * @request: IOCTL request number
43 * @arg: argument pointer
44 *
45 * This is a wrapper around drmIoctl(), which can be augmented with special code
46 * blocks like #igt_while_interruptible.
47 */
Chris Wilsonc1fed522016-03-19 13:00:29 +000048extern int (*igt_ioctl)(int fd, unsigned long request, void *arg);
49
Daniel Vetter556c49f2014-03-11 23:27:06 +010050/* libdrm interfacing */
51drm_intel_bo * gem_handle_to_libdrm_bo(drm_intel_bufmgr *bufmgr, int fd,
52 const char *name, uint32_t handle);
53
Daniel Vetter766c5bc2014-03-11 22:58:07 +010054/* ioctl_wrappers.c:
55 *
56 * ioctl wrappers and similar stuff for bare metal testing */
Chris Wilsone2762682016-10-19 14:07:25 +010057bool gem_get_tiling(int fd, uint32_t handle, uint32_t *tiling, uint32_t *swizzle);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010058void gem_set_tiling(int fd, uint32_t handle, uint32_t tiling, uint32_t stride);
59int __gem_set_tiling(int fd, uint32_t handle, uint32_t tiling, uint32_t stride);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010060
Daniel Vetter556c49f2014-03-11 23:27:06 +010061void gem_set_caching(int fd, uint32_t handle, uint32_t caching);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010062uint32_t gem_get_caching(int fd, uint32_t handle);
63uint32_t gem_flink(int fd, uint32_t handle);
64uint32_t gem_open(int fd, uint32_t name);
65void gem_close(int fd, uint32_t handle);
Chris Wilson8fcca192017-03-08 12:22:58 +000066int __gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint64_t length);
Chris Wilsonfc69bb02015-04-27 21:05:33 +010067void gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint64_t length);
68void gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length);
Michał Winiarski7b46ae12015-06-30 17:01:10 +020069int __gem_set_domain(int fd, uint32_t handle, uint32_t read, uint32_t write);
70void gem_set_domain(int fd, uint32_t handle, uint32_t read, uint32_t write);
Chris Wilsonf27d2952016-02-23 17:45:49 +000071int gem_wait(int fd, uint32_t handle, int64_t *timeout_ns);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010072void gem_sync(int fd, uint32_t handle);
Ankitprasad Sharma70c3be82015-12-02 14:54:50 +053073bool gem_create__has_stolen_support(int fd);
74uint32_t __gem_create_stolen(int fd, uint64_t size);
75uint32_t gem_create_stolen(int fd, uint64_t size);
Chris Wilson7fd0cae2017-10-03 14:52:27 +010076int __gem_create(int fd, uint64_t size, uint32_t *handle);
Chris Wilson236bab52015-04-26 11:11:55 +010077uint32_t gem_create(int fd, uint64_t size);
Lukasz Fiedorowicz9fc445d2017-05-25 09:40:54 +020078void gem_execbuf_wr(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
79int __gem_execbuf_wr(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010080void gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
Chris Wilsone3b68bb2016-01-23 09:44:19 +000081int __gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010082
Chris Wilson019ae902015-04-26 12:16:44 +010083void *gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot);
84void *gem_mmap__cpu(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
Chris Wilsona464fb72015-01-02 16:33:29 +053085
86bool gem_mmap__has_wc(int fd);
Chris Wilson019ae902015-04-26 12:16:44 +010087void *gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
Daniel Vettera3e34ce2015-02-06 11:05:28 +010088
Chris Wilson3bdafec2017-04-13 08:18:10 +010089#ifndef I915_GEM_DOMAIN_WC
90#define I915_GEM_DOMAIN_WC 0x80
91#endif
92
Ville Syrjäläb8a77dd2015-10-09 18:29:28 +030093void *__gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot);
94void *__gem_mmap__cpu(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
95void *__gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
96
Maarten Lankhorstd930b642017-02-09 10:42:01 +010097int gem_munmap(void *ptr, uint64_t size);
98
Daniel Vettera3e34ce2015-02-06 11:05:28 +010099/**
Ankitprasad Sharma70c3be82015-12-02 14:54:50 +0530100 * gem_require_stolen_support:
101 * @fd: open i915 drm file descriptor
102 *
103 * Test macro to query whether support for allocating objects from stolen
104 * memory is available. Automatically skips through igt_require() if not.
105 */
106#define gem_require_stolen_support(fd) \
Ankitprasad Sharmabeef31a2016-06-06 14:52:42 +0530107 igt_require(gem_create__has_stolen_support(fd) && \
108 (gem_total_stolen_size(fd) > 0))
Ankitprasad Sharma70c3be82015-12-02 14:54:50 +0530109
110/**
Daniel Vettera3e34ce2015-02-06 11:05:28 +0100111 * gem_require_mmap_wc:
112 * @fd: open i915 drm file descriptor
113 *
114 * Feature test macro to query whether direct (i.e. cpu access path, bypassing
115 * the gtt) write-combine memory mappings are available. Automatically skips
116 * through igt_require() if not.
117 */
Thomas Wooda22548f2015-02-16 11:17:11 +0000118#define gem_require_mmap_wc(fd) igt_require(gem_mmap__has_wc(fd))
Chris Wilsona464fb72015-01-02 16:33:29 +0530119
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100120int gem_madvise(int fd, uint32_t handle, int state);
121
122uint32_t gem_context_create(int fd);
Daniel Vetter09b82112015-02-06 17:15:13 +0100123void gem_context_destroy(int fd, uint32_t ctx_id);
124int __gem_context_destroy(int fd, uint32_t ctx_id);
Daniel Vetter75c075c2015-02-06 17:13:59 +0100125struct local_i915_gem_context_param {
126 uint32_t context;
127 uint32_t size;
128 uint64_t param;
Chris Wilson5ec54d82015-10-19 11:36:17 +0100129#define LOCAL_CONTEXT_PARAM_BAN_PERIOD 0x1
130#define LOCAL_CONTEXT_PARAM_NO_ZEROMAP 0x2
131#define LOCAL_CONTEXT_PARAM_GTT_SIZE 0x3
Chris Wilson171b21d2016-10-13 22:46:47 +0100132#define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE 0x4
Mika Kuoppala773ac7c2016-11-08 12:31:06 +0200133#define LOCAL_CONTEXT_PARAM_BANNABLE 0x5
Daniel Vetter75c075c2015-02-06 17:13:59 +0100134 uint64_t value;
135};
Mika Kuoppala773ac7c2016-11-08 12:31:06 +0200136void gem_context_require_bannable(int fd);
Daniel Vetter75c075c2015-02-06 17:13:59 +0100137void gem_context_require_param(int fd, uint64_t param);
138void gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
139void gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
Chris Wilson19642c62015-12-11 13:27:49 +0000140int __gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
Chris Wilson7b349f32016-10-13 22:44:08 +0100141int __gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100142
Tiago Vignattie1f663b2015-08-12 15:57:12 -0300143#define LOCAL_I915_GEM_USERPTR 0x33
144#define LOCAL_IOCTL_I915_GEM_USERPTR DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_USERPTR, struct local_i915_gem_userptr)
145struct local_i915_gem_userptr {
146 uint64_t user_ptr;
147 uint64_t user_size;
148 uint32_t flags;
149#define LOCAL_I915_USERPTR_READ_ONLY (1<<0)
150#define LOCAL_I915_USERPTR_UNSYNCHRONIZED (1<<31)
151 uint32_t handle;
152};
153void gem_userptr(int fd, void *ptr, int size, int read_only, uint32_t flags, uint32_t *handle);
154int __gem_userptr(int fd, void *ptr, int size, int read_only, uint32_t flags, uint32_t *handle);
155
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100156void gem_sw_finish(int fd, uint32_t handle);
157
158bool gem_bo_busy(int fd, uint32_t handle);
159
160/* feature test helpers */
Chris Wilson9518cb52017-02-22 15:24:54 +0000161void igt_require_gem(int fd);
Chris Wilsonb76f1d82014-09-08 10:28:41 +0100162bool gem_has_llc(int fd);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100163bool gem_has_bsd(int fd);
164bool gem_has_blt(int fd);
165bool gem_has_vebox(int fd);
Zhipeng Gong17937a02015-01-13 08:50:19 +0800166bool gem_has_bsd2(int fd);
Michał Winiarski52b5d502016-01-25 19:35:01 +0100167int gem_gtt_type(int fd);
168bool gem_uses_ppgtt(int fd);
169bool gem_uses_full_ppgtt(int fd);
Michel Thierrybcb9d6f2017-06-28 11:36:54 -0700170int gem_gpu_reset_type(int fd);
171bool gem_gpu_reset_enabled(int fd);
172bool gem_engine_reset_enabled(int fd);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100173int gem_available_fences(int fd);
Ankitprasad Sharmabeef31a2016-06-06 14:52:42 +0530174uint64_t gem_total_mappable_size(int fd);
175uint64_t gem_total_stolen_size(int fd);
Chris Wilson16038902016-02-18 10:35:10 +0000176uint64_t gem_available_aperture_size(int fd);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100177uint64_t gem_aperture_size(int fd);
Chris Wilson391b32c2016-02-05 18:35:21 +0000178uint64_t gem_global_aperture_size(int fd);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100179uint64_t gem_mappable_aperture_size(void);
Michał Winiarskie6ca4bd2016-01-25 19:35:02 +0100180bool gem_has_softpin(int fd);
Daniele Ceraolo Spurio25b5a742017-02-03 14:45:30 -0800181bool gem_has_exec_fence(int fd);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100182
Daniel Vetter556c49f2014-03-11 23:27:06 +0100183/* check functions which auto-skip tests by calling igt_skip() */
184void gem_require_caching(int fd);
Chris Wilson60eafc52016-03-04 09:40:51 +0000185bool gem_has_ring(int fd, unsigned ring);
186void gem_require_ring(int fd, unsigned ring);
Peter Antoine8af67d12016-04-11 17:50:09 +0100187bool gem_has_mocs_registers(int fd);
188void gem_require_mocs_registers(int fd);
Daniel Vetter556c49f2014-03-11 23:27:06 +0100189
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100190/* prime */
Tiago Vignatti35debab2015-12-11 18:50:35 -0200191struct local_dma_buf_sync {
192 uint64_t flags;
193};
194
195#define LOCAL_DMA_BUF_SYNC_READ (1 << 0)
196#define LOCAL_DMA_BUF_SYNC_WRITE (2 << 0)
197#define LOCAL_DMA_BUF_SYNC_RW (LOCAL_DMA_BUF_SYNC_READ | LOCAL_DMA_BUF_SYNC_WRITE)
198#define LOCAL_DMA_BUF_SYNC_START (0 << 2)
199#define LOCAL_DMA_BUF_SYNC_END (1 << 2)
200#define LOCAL_DMA_BUF_SYNC_VALID_FLAGS_MASK \
201 (LOCAL_DMA_BUF_SYNC_RW | LOCAL_DMA_BUF_SYNC_END)
202
203#define LOCAL_DMA_BUF_BASE 'b'
204#define LOCAL_DMA_BUF_IOCTL_SYNC _IOW(LOCAL_DMA_BUF_BASE, 0, struct local_dma_buf_sync)
205
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100206int prime_handle_to_fd(int fd, uint32_t handle);
Tiago Vignatti4edfa092015-07-29 18:26:29 -0300207#ifndef DRM_RDWR
208#define DRM_RDWR O_RDWR
209#endif
210int prime_handle_to_fd_for_mmap(int fd, uint32_t handle);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100211uint32_t prime_fd_to_handle(int fd, int dma_buf_fd);
212off_t prime_get_size(int dma_buf_fd);
Chris Wilsonaed69b52016-02-25 21:43:01 +0000213void prime_sync_start(int dma_buf_fd, bool write);
214void prime_sync_end(int dma_buf_fd, bool write);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100215
Tvrtko Ursulin0a087732015-03-03 14:10:54 +0000216/* addfb2 fb modifiers */
217struct local_drm_mode_fb_cmd2 {
218 uint32_t fb_id;
219 uint32_t width, height;
220 uint32_t pixel_format;
221 uint32_t flags;
222 uint32_t handles[4];
223 uint32_t pitches[4];
224 uint32_t offsets[4];
225 uint64_t modifier[4];
226};
227
228#define LOCAL_DRM_MODE_FB_MODIFIERS (1<<1)
229
230#define LOCAL_DRM_FORMAT_MOD_VENDOR_INTEL 0x01
231
232#define local_fourcc_mod_code(vendor, val) \
233 ((((uint64_t)LOCAL_DRM_FORMAT_MOD_VENDOR_## vendor) << 56) | \
234 (val & 0x00ffffffffffffffL))
235
236#define LOCAL_DRM_FORMAT_MOD_NONE (0)
237#define LOCAL_I915_FORMAT_MOD_X_TILED local_fourcc_mod_code(INTEL, 1)
Tvrtko Ursulin0c15e062015-03-03 14:10:56 +0000238#define LOCAL_I915_FORMAT_MOD_Y_TILED local_fourcc_mod_code(INTEL, 2)
239#define LOCAL_I915_FORMAT_MOD_Yf_TILED local_fourcc_mod_code(INTEL, 3)
Tomeu Vizosod900dd82016-12-06 16:06:50 +0100240#define LOCAL_I915_FORMAT_MOD_Y_TILED_CCS local_fourcc_mod_code(INTEL, 4)
241#define LOCAL_I915_FORMAT_MOD_Yf_TILED_CCS local_fourcc_mod_code(INTEL, 5)
Tvrtko Ursulin0a087732015-03-03 14:10:54 +0000242
243#define LOCAL_DRM_IOCTL_MODE_ADDFB2 DRM_IOWR(0xB8, \
244 struct local_drm_mode_fb_cmd2)
245
246#define LOCAL_DRM_CAP_ADDFB2_MODIFIERS 0x10
247
248void igt_require_fb_modifiers(int fd);
249
Tvrtko Ursulinc7bac3c2015-03-03 14:11:02 +0000250/**
251 * __kms_addfb:
252 *
253 * Creates a framebuffer object.
254 */
255int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
256 uint32_t stride, uint32_t pixel_format, uint64_t modifier,
257 uint32_t flags, uint32_t *buf_id);
258
Robert Foss091a4522017-01-02 05:07:10 -0500259/**
260 * to_user_pointer:
261 *
262 * Makes sure that pointer on 32 and 64-bit systems
263 * are casted properly for being sent through an ioctl.
264 */
Robert Foss0517d872017-01-02 05:25:55 -0500265static inline uint64_t to_user_pointer(const void *ptr)
Robert Foss091a4522017-01-02 05:07:10 -0500266{
Robert Foss0517d872017-01-02 05:25:55 -0500267 return (uintptr_t)ptr;
Robert Foss091a4522017-01-02 05:07:10 -0500268}
269
Chris Wilson8f393102017-01-02 11:23:33 +0000270/**
271 * from_user_pointer:
272 *
273 * Casts a 64bit value from an ioctl into a pointer.
274 */
275static inline void *from_user_pointer(uint64_t u64)
276{
277 return (void *)(uintptr_t)u64;
278}
279
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100280#endif /* IOCTL_WRAPPERS_H */