blob: cf33da872ff66c807d8538da948c7f03a562b8c9 [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>
35#include <intel_bufmgr.h>
36#include <i915_drm.h>
37
Daniel Vetterd7050f92016-05-11 17:06:28 +020038/**
39 * igt_ioctl:
40 * @fd: file descriptor
41 * @request: IOCTL request number
42 * @arg: argument pointer
43 *
44 * This is a wrapper around drmIoctl(), which can be augmented with special code
45 * blocks like #igt_while_interruptible.
46 */
Chris Wilsonc1fed522016-03-19 13:00:29 +000047extern int (*igt_ioctl)(int fd, unsigned long request, void *arg);
48
Daniel Vetter556c49f2014-03-11 23:27:06 +010049/* libdrm interfacing */
50drm_intel_bo * gem_handle_to_libdrm_bo(drm_intel_bufmgr *bufmgr, int fd,
51 const char *name, uint32_t handle);
52
Daniel Vetter766c5bc2014-03-11 22:58:07 +010053/* ioctl_wrappers.c:
54 *
55 * ioctl wrappers and similar stuff for bare metal testing */
Chris Wilsone2762682016-10-19 14:07:25 +010056bool gem_get_tiling(int fd, uint32_t handle, uint32_t *tiling, uint32_t *swizzle);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010057void gem_set_tiling(int fd, uint32_t handle, uint32_t tiling, uint32_t stride);
58int __gem_set_tiling(int fd, uint32_t handle, uint32_t tiling, uint32_t stride);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010059
Daniel Vetter556c49f2014-03-11 23:27:06 +010060void gem_set_caching(int fd, uint32_t handle, uint32_t caching);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010061uint32_t gem_get_caching(int fd, uint32_t handle);
62uint32_t gem_flink(int fd, uint32_t handle);
63uint32_t gem_open(int fd, uint32_t name);
64void gem_close(int fd, uint32_t handle);
Chris Wilsonfc69bb02015-04-27 21:05:33 +010065void gem_write(int fd, uint32_t handle, uint64_t offset, const void *buf, uint64_t length);
66void gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t length);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010067void gem_set_domain(int fd, uint32_t handle,
68 uint32_t read_domains, uint32_t write_domain);
Chris Wilsonf27d2952016-02-23 17:45:49 +000069int gem_wait(int fd, uint32_t handle, int64_t *timeout_ns);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010070void gem_sync(int fd, uint32_t handle);
Ankitprasad Sharma70c3be82015-12-02 14:54:50 +053071bool gem_create__has_stolen_support(int fd);
72uint32_t __gem_create_stolen(int fd, uint64_t size);
73uint32_t gem_create_stolen(int fd, uint64_t size);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010074uint32_t __gem_create(int fd, int size);
Chris Wilson236bab52015-04-26 11:11:55 +010075uint32_t gem_create(int fd, uint64_t size);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010076void gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
Chris Wilsone3b68bb2016-01-23 09:44:19 +000077int __gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
Daniel Vetter766c5bc2014-03-11 22:58:07 +010078
Chris Wilson019ae902015-04-26 12:16:44 +010079void *gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot);
80void *gem_mmap__cpu(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
Chris Wilsona464fb72015-01-02 16:33:29 +053081
82bool gem_mmap__has_wc(int fd);
Chris Wilson019ae902015-04-26 12:16:44 +010083void *gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
Daniel Vettera3e34ce2015-02-06 11:05:28 +010084
Ville Syrjäläb8a77dd2015-10-09 18:29:28 +030085void *__gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot);
86void *__gem_mmap__cpu(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
87void *__gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, unsigned prot);
88
Daniel Vettera3e34ce2015-02-06 11:05:28 +010089/**
Ankitprasad Sharma70c3be82015-12-02 14:54:50 +053090 * gem_require_stolen_support:
91 * @fd: open i915 drm file descriptor
92 *
93 * Test macro to query whether support for allocating objects from stolen
94 * memory is available. Automatically skips through igt_require() if not.
95 */
96#define gem_require_stolen_support(fd) \
Ankitprasad Sharmabeef31a2016-06-06 14:52:42 +053097 igt_require(gem_create__has_stolen_support(fd) && \
98 (gem_total_stolen_size(fd) > 0))
Ankitprasad Sharma70c3be82015-12-02 14:54:50 +053099
100/**
Daniel Vettera3e34ce2015-02-06 11:05:28 +0100101 * gem_require_mmap_wc:
102 * @fd: open i915 drm file descriptor
103 *
104 * Feature test macro to query whether direct (i.e. cpu access path, bypassing
105 * the gtt) write-combine memory mappings are available. Automatically skips
106 * through igt_require() if not.
107 */
Thomas Wooda22548f2015-02-16 11:17:11 +0000108#define gem_require_mmap_wc(fd) igt_require(gem_mmap__has_wc(fd))
Chris Wilsona464fb72015-01-02 16:33:29 +0530109
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100110int gem_madvise(int fd, uint32_t handle, int state);
111
112uint32_t gem_context_create(int fd);
Daniel Vetter09b82112015-02-06 17:15:13 +0100113void gem_context_destroy(int fd, uint32_t ctx_id);
114int __gem_context_destroy(int fd, uint32_t ctx_id);
Daniel Vetter75c075c2015-02-06 17:13:59 +0100115struct local_i915_gem_context_param {
116 uint32_t context;
117 uint32_t size;
118 uint64_t param;
Chris Wilson5ec54d82015-10-19 11:36:17 +0100119#define LOCAL_CONTEXT_PARAM_BAN_PERIOD 0x1
120#define LOCAL_CONTEXT_PARAM_NO_ZEROMAP 0x2
121#define LOCAL_CONTEXT_PARAM_GTT_SIZE 0x3
Chris Wilson171b21d2016-10-13 22:46:47 +0100122#define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE 0x4
Mika Kuoppala773ac7c2016-11-08 12:31:06 +0200123#define LOCAL_CONTEXT_PARAM_BANNABLE 0x5
Daniel Vetter75c075c2015-02-06 17:13:59 +0100124 uint64_t value;
125};
Mika Kuoppala773ac7c2016-11-08 12:31:06 +0200126void gem_context_require_bannable(int fd);
Daniel Vetter75c075c2015-02-06 17:13:59 +0100127void gem_context_require_param(int fd, uint64_t param);
128void gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
129void gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
Chris Wilson19642c62015-12-11 13:27:49 +0000130int __gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
Chris Wilson7b349f32016-10-13 22:44:08 +0100131int __gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100132
Tiago Vignattie1f663b2015-08-12 15:57:12 -0300133#define LOCAL_I915_GEM_USERPTR 0x33
134#define LOCAL_IOCTL_I915_GEM_USERPTR DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_USERPTR, struct local_i915_gem_userptr)
135struct local_i915_gem_userptr {
136 uint64_t user_ptr;
137 uint64_t user_size;
138 uint32_t flags;
139#define LOCAL_I915_USERPTR_READ_ONLY (1<<0)
140#define LOCAL_I915_USERPTR_UNSYNCHRONIZED (1<<31)
141 uint32_t handle;
142};
143void gem_userptr(int fd, void *ptr, int size, int read_only, uint32_t flags, uint32_t *handle);
144int __gem_userptr(int fd, void *ptr, int size, int read_only, uint32_t flags, uint32_t *handle);
145
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100146void gem_sw_finish(int fd, uint32_t handle);
147
148bool gem_bo_busy(int fd, uint32_t handle);
149
150/* feature test helpers */
Chris Wilson9518cb52017-02-22 15:24:54 +0000151void igt_require_gem(int fd);
Chris Wilsonb76f1d82014-09-08 10:28:41 +0100152bool gem_has_llc(int fd);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100153bool gem_has_bsd(int fd);
154bool gem_has_blt(int fd);
155bool gem_has_vebox(int fd);
Zhipeng Gong17937a02015-01-13 08:50:19 +0800156bool gem_has_bsd2(int fd);
Michał Winiarski52b5d502016-01-25 19:35:01 +0100157int gem_gtt_type(int fd);
158bool gem_uses_ppgtt(int fd);
159bool gem_uses_full_ppgtt(int fd);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100160int gem_available_fences(int fd);
Ankitprasad Sharmabeef31a2016-06-06 14:52:42 +0530161uint64_t gem_total_mappable_size(int fd);
162uint64_t gem_total_stolen_size(int fd);
Chris Wilson16038902016-02-18 10:35:10 +0000163uint64_t gem_available_aperture_size(int fd);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100164uint64_t gem_aperture_size(int fd);
Chris Wilson391b32c2016-02-05 18:35:21 +0000165uint64_t gem_global_aperture_size(int fd);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100166uint64_t gem_mappable_aperture_size(void);
Michał Winiarskie6ca4bd2016-01-25 19:35:02 +0100167bool gem_has_softpin(int fd);
Daniele Ceraolo Spurio25b5a742017-02-03 14:45:30 -0800168bool gem_has_exec_fence(int fd);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100169
Daniel Vetter556c49f2014-03-11 23:27:06 +0100170/* check functions which auto-skip tests by calling igt_skip() */
171void gem_require_caching(int fd);
Chris Wilson60eafc52016-03-04 09:40:51 +0000172bool gem_has_ring(int fd, unsigned ring);
173void gem_require_ring(int fd, unsigned ring);
Peter Antoine8af67d12016-04-11 17:50:09 +0100174bool gem_has_mocs_registers(int fd);
175void gem_require_mocs_registers(int fd);
Daniel Vetter556c49f2014-03-11 23:27:06 +0100176
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100177/* prime */
Tiago Vignatti35debab2015-12-11 18:50:35 -0200178struct local_dma_buf_sync {
179 uint64_t flags;
180};
181
182#define LOCAL_DMA_BUF_SYNC_READ (1 << 0)
183#define LOCAL_DMA_BUF_SYNC_WRITE (2 << 0)
184#define LOCAL_DMA_BUF_SYNC_RW (LOCAL_DMA_BUF_SYNC_READ | LOCAL_DMA_BUF_SYNC_WRITE)
185#define LOCAL_DMA_BUF_SYNC_START (0 << 2)
186#define LOCAL_DMA_BUF_SYNC_END (1 << 2)
187#define LOCAL_DMA_BUF_SYNC_VALID_FLAGS_MASK \
188 (LOCAL_DMA_BUF_SYNC_RW | LOCAL_DMA_BUF_SYNC_END)
189
190#define LOCAL_DMA_BUF_BASE 'b'
191#define LOCAL_DMA_BUF_IOCTL_SYNC _IOW(LOCAL_DMA_BUF_BASE, 0, struct local_dma_buf_sync)
192
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100193int prime_handle_to_fd(int fd, uint32_t handle);
Tiago Vignatti4edfa092015-07-29 18:26:29 -0300194#ifndef DRM_RDWR
195#define DRM_RDWR O_RDWR
196#endif
197int prime_handle_to_fd_for_mmap(int fd, uint32_t handle);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100198uint32_t prime_fd_to_handle(int fd, int dma_buf_fd);
199off_t prime_get_size(int dma_buf_fd);
Chris Wilsonaed69b52016-02-25 21:43:01 +0000200void prime_sync_start(int dma_buf_fd, bool write);
201void prime_sync_end(int dma_buf_fd, bool write);
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100202
Tvrtko Ursulin0a087732015-03-03 14:10:54 +0000203/* addfb2 fb modifiers */
204struct local_drm_mode_fb_cmd2 {
205 uint32_t fb_id;
206 uint32_t width, height;
207 uint32_t pixel_format;
208 uint32_t flags;
209 uint32_t handles[4];
210 uint32_t pitches[4];
211 uint32_t offsets[4];
212 uint64_t modifier[4];
213};
214
215#define LOCAL_DRM_MODE_FB_MODIFIERS (1<<1)
216
217#define LOCAL_DRM_FORMAT_MOD_VENDOR_INTEL 0x01
218
219#define local_fourcc_mod_code(vendor, val) \
220 ((((uint64_t)LOCAL_DRM_FORMAT_MOD_VENDOR_## vendor) << 56) | \
221 (val & 0x00ffffffffffffffL))
222
223#define LOCAL_DRM_FORMAT_MOD_NONE (0)
224#define LOCAL_I915_FORMAT_MOD_X_TILED local_fourcc_mod_code(INTEL, 1)
Tvrtko Ursulin0c15e062015-03-03 14:10:56 +0000225#define LOCAL_I915_FORMAT_MOD_Y_TILED local_fourcc_mod_code(INTEL, 2)
226#define LOCAL_I915_FORMAT_MOD_Yf_TILED local_fourcc_mod_code(INTEL, 3)
Tomeu Vizosod900dd82016-12-06 16:06:50 +0100227#define LOCAL_I915_FORMAT_MOD_Y_TILED_CCS local_fourcc_mod_code(INTEL, 4)
228#define LOCAL_I915_FORMAT_MOD_Yf_TILED_CCS local_fourcc_mod_code(INTEL, 5)
Tvrtko Ursulin0a087732015-03-03 14:10:54 +0000229
230#define LOCAL_DRM_IOCTL_MODE_ADDFB2 DRM_IOWR(0xB8, \
231 struct local_drm_mode_fb_cmd2)
232
233#define LOCAL_DRM_CAP_ADDFB2_MODIFIERS 0x10
234
235void igt_require_fb_modifiers(int fd);
236
Tvrtko Ursulinc7bac3c2015-03-03 14:11:02 +0000237/**
238 * __kms_addfb:
239 *
240 * Creates a framebuffer object.
241 */
242int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
243 uint32_t stride, uint32_t pixel_format, uint64_t modifier,
244 uint32_t flags, uint32_t *buf_id);
245
Robert Foss091a4522017-01-02 05:07:10 -0500246/**
247 * to_user_pointer:
248 *
249 * Makes sure that pointer on 32 and 64-bit systems
250 * are casted properly for being sent through an ioctl.
251 */
Robert Foss0517d872017-01-02 05:25:55 -0500252static inline uint64_t to_user_pointer(const void *ptr)
Robert Foss091a4522017-01-02 05:07:10 -0500253{
Robert Foss0517d872017-01-02 05:25:55 -0500254 return (uintptr_t)ptr;
Robert Foss091a4522017-01-02 05:07:10 -0500255}
256
Chris Wilson8f393102017-01-02 11:23:33 +0000257/**
258 * from_user_pointer:
259 *
260 * Casts a 64bit value from an ioctl into a pointer.
261 */
262static inline void *from_user_pointer(uint64_t u64)
263{
264 return (void *)(uintptr_t)u64;
265}
266
Daniel Vetter766c5bc2014-03-11 22:58:07 +0100267#endif /* IOCTL_WRAPPERS_H */