tests/intel/xe_sriov_flr: Add flr-twice subtest
[drm/igt-gpu-tools.git] / lib / intel_batchbuffer.h
blob178aaa9d83e8ebedd3c4cff46421d661950068be
1 #ifndef INTEL_BATCHBUFFER_H
2 #define INTEL_BATCHBUFFER_H
4 #include <stdint.h>
5 #include <i915_drm.h>
7 #include "igt_core.h"
8 #include "igt_list.h"
9 #include "intel_reg.h"
10 #include "drmtest.h"
11 #include "intel_allocator.h"
13 #define BATCH_SZ 4096
16 * Yf/Ys/4/64 tiling
18 * Tiling mode in the I915_TILING_... namespace for new tiling modes which are
19 * defined in the kernel. (They are not fenceable so the kernel does not need
20 * to know about them.)
22 * They are to be used the the blitting routines below.
24 #define I915_TILING_4 (I915_TILING_LAST + 1)
25 #define I915_TILING_Yf (I915_TILING_LAST + 2)
26 #define I915_TILING_Ys (I915_TILING_LAST + 3)
27 #define I915_TILING_64 (I915_TILING_LAST + 4)
29 enum i915_compression {
30 I915_COMPRESSION_NONE,
31 I915_COMPRESSION_RENDER,
32 I915_COMPRESSION_MEDIA,
35 uint32_t fast_copy_dword0(unsigned int src_tiling,
36 unsigned int dst_tiling);
37 uint32_t fast_copy_dword1(int fd, unsigned int src_tiling,
38 unsigned int dst_tiling,
39 int bpp);
40 void igt_blitter_copy(int fd,
41 uint64_t ahnd,
42 uint32_t ctx,
43 const intel_ctx_cfg_t *cfg,
44 /* src */
45 uint32_t src_handle,
46 uint32_t src_delta,
47 uint32_t src_stride,
48 uint32_t src_tiling,
49 uint32_t src_x, uint32_t src_y,
50 uint64_t src_size,
51 /* size */
52 uint32_t width, uint32_t height,
53 /* bpp */
54 uint32_t bpp,
55 /* dst */
56 uint32_t dst_handle,
57 uint32_t dst_delta,
58 uint32_t dst_stride,
59 uint32_t dst_tiling,
60 uint32_t dst_x, uint32_t dst_y,
61 uint64_t dst_size);
63 void igt_blitter_src_copy(int fd,
64 uint64_t ahnd,
65 uint32_t ctx,
66 const intel_ctx_cfg_t *cfg,
67 /* src */
68 uint32_t src_handle,
69 uint32_t src_delta,
70 uint32_t src_stride,
71 uint32_t src_tiling,
72 uint32_t src_x, uint32_t src_y,
73 uint64_t src_size,
75 /* size */
76 uint32_t width, uint32_t height,
78 /* bpp */
79 uint32_t bpp,
81 /* dst */
82 uint32_t dst_handle,
83 uint32_t dst_delta,
84 uint32_t dst_stride,
85 uint32_t dst_tiling,
86 uint32_t dst_x, uint32_t dst_y,
87 uint64_t dst_size);
89 void igt_blitter_fast_copy__raw(int fd,
90 uint64_t ahnd,
91 uint32_t ctx,
92 const intel_ctx_cfg_t *cfg,
93 /* src */
94 uint32_t src_handle,
95 unsigned int src_delta,
96 unsigned int src_stride,
97 unsigned int src_tiling,
98 unsigned int src_x, unsigned src_y,
99 uint64_t src_size,
101 /* size */
102 unsigned int width, unsigned int height,
104 /* bpp */
105 int bpp,
107 /* dst */
108 uint32_t dst_handle,
109 unsigned int dst_delta,
110 unsigned int dst_stride,
111 unsigned int dst_tiling,
112 unsigned int dst_x, unsigned dst_y,
113 uint64_t dst_size);
116 * igt_render_copyfunc_t:
117 * @ibb: batchbuffer
118 * @ctx: context to use
119 * @src: intel_buf source object
120 * @src_x: source pixel x-coordination
121 * @src_y: source pixel y-coordination
122 * @width: width of the copied rectangle
123 * @height: height of the copied rectangle
124 * @dst: intel_buf destination object
125 * @dst_x: destination pixel x-coordination
126 * @dst_y: destination pixel y-coordination
128 * This is the type of the per-platform render copy functions. The
129 * platform-specific implementation can be obtained by calling
130 * igt_get_render_copyfunc().
132 * A render copy function will emit a batchbuffer to the kernel which executes
133 * the specified blit copy operation using the render engine. @ctx is
134 * optional and can be 0.
136 struct intel_bb;
137 struct intel_buf;
139 typedef void (*igt_render_copyfunc_t)(struct intel_bb *ibb,
140 struct intel_buf *src,
141 uint32_t src_x, uint32_t src_y,
142 uint32_t width, uint32_t height,
143 struct intel_buf *dst,
144 uint32_t dst_x, uint32_t dst_y);
146 igt_render_copyfunc_t igt_get_render_copyfunc(int devid);
150 * igt_vebox_copyfunc_t:
151 * @ibb: batchbuffer
152 * @src: intel_buf source object
153 * @width: width of the copied rectangle
154 * @height: height of the copied rectangle
155 * @dst: intel_buf destination object
157 * This is the type of the per-platform vebox copy functions. The
158 * platform-specific implementation can be obtained by calling
159 * igt_get_vebox_copyfunc().
161 * A vebox copy function will emit a batchbuffer to the kernel which executes
162 * the specified blit copy operation using the vebox engine.
164 typedef void (*igt_vebox_copyfunc_t)(struct intel_bb *ibb,
165 struct intel_buf *src,
166 unsigned int width, unsigned int height,
167 struct intel_buf *dst);
169 igt_vebox_copyfunc_t igt_get_vebox_copyfunc(int devid);
171 typedef void (*igt_render_clearfunc_t)(struct intel_bb *ibb,
172 struct intel_buf *dst, unsigned int dst_x, unsigned int dst_y,
173 unsigned int width, unsigned int height,
174 const float cc_color[4]);
175 igt_render_clearfunc_t igt_get_render_clearfunc(int devid);
178 * igt_fillfunc_t:
179 * @i915: drm fd
180 * @buf: destination intel_buf object
181 * @x: destination pixel x-coordination
182 * @y: destination pixel y-coordination
183 * @width: width of the filled rectangle
184 * @height: height of the filled rectangle
185 * @color: fill color to use
187 * This is the type of the per-platform fill functions using media
188 * or gpgpu pipeline. The platform-specific implementation can be obtained
189 * by calling igt_get_media_fillfunc() or igt_get_gpgpu_fillfunc().
191 * A fill function will emit a batchbuffer to the kernel which executes
192 * the specified blit fill operation using the media/gpgpu engine.
194 typedef void (*igt_fillfunc_t)(int i915,
195 struct intel_buf *buf,
196 unsigned x, unsigned y,
197 unsigned width, unsigned height,
198 uint8_t color);
200 igt_fillfunc_t igt_get_gpgpu_fillfunc(int devid);
201 igt_fillfunc_t igt_get_media_fillfunc(int devid);
203 typedef void (*igt_vme_func_t)(int i915,
204 uint32_t ctx,
205 struct intel_buf *src,
206 unsigned int width, unsigned int height,
207 struct intel_buf *dst);
209 igt_vme_func_t igt_get_media_vme_func(int devid);
212 * igt_media_spinfunc_t:
213 * @i915: drm fd
214 * @buf: destination buffer object
215 * @spins: number of loops to execute
217 * This is the type of the per-platform media spin functions. The
218 * platform-specific implementation can be obtained by calling
219 * igt_get_media_spinfunc().
221 * The media spin function emits a batchbuffer for the render engine with
222 * the media pipeline selected. The workload consists of a single thread
223 * which spins in a tight loop the requested number of times. Each spin
224 * increments a counter whose final 32-bit value is written to the
225 * destination buffer on completion. This utility provides a simple way
226 * to keep the render engine busy for a set time for various tests.
228 typedef void (*igt_media_spinfunc_t)(int i915,
229 struct intel_buf *buf, uint32_t spins);
231 igt_media_spinfunc_t igt_get_media_spinfunc(int devid);
233 struct igt_pxp {
234 bool enabled;
235 uint32_t apptype;
236 uint32_t appid;
240 * Batchbuffer without libdrm dependency
242 struct intel_bb {
243 struct igt_list_head link;
245 uint64_t allocator_handle;
246 uint64_t allocator_start, allocator_end;
247 uint8_t allocator_type;
248 enum allocator_strategy allocator_strategy;
250 enum intel_driver driver;
251 int fd;
252 unsigned int gen;
253 bool debug;
254 bool dump_base64;
255 bool enforce_relocs;
256 uint32_t devid;
257 uint32_t handle;
258 uint32_t size;
259 uint32_t *batch;
260 uint32_t *ptr;
261 uint64_t alignment;
262 int fence;
264 uint64_t gtt_size;
265 bool supports_48b_address;
266 bool uses_full_ppgtt;
267 bool allows_obj_alignment;
269 struct igt_pxp pxp;
270 uint32_t ctx;
271 uint32_t vm_id;
273 bool xe_bound;
274 uint32_t engine_syncobj;
275 uint32_t engine_id;
276 uint32_t last_engine;
278 /* Context configuration */
279 intel_ctx_cfg_t *cfg;
281 /* Cache */
282 void *root;
284 /* Current objects for execbuf */
285 void *current;
287 /* Objects for current execbuf */
288 struct drm_i915_gem_exec_object2 **objects;
289 uint32_t num_objects;
290 uint32_t allocated_objects;
291 uint64_t batch_offset;
293 struct drm_i915_gem_relocation_entry *relocs;
294 uint32_t num_relocs;
295 uint32_t allocated_relocs;
297 /* Tracked intel_bufs */
298 struct igt_list_head intel_bufs;
301 * BO recreate in reset path only when refcount == 0
302 * Currently we don't need to use atomics because intel_bb
303 * is not thread-safe.
305 int32_t refcount;
307 /* long running mode */
308 bool lr_mode;
309 int64_t user_fence_offset;
310 uint64_t user_fence_value;
313 struct intel_bb *
314 intel_bb_create_full(int fd, uint32_t ctx, uint32_t vm,
315 const intel_ctx_cfg_t *cfg, uint32_t size, uint64_t start,
316 uint64_t end, uint64_t alignment, uint8_t allocator_type,
317 enum allocator_strategy strategy, uint64_t region);
318 struct intel_bb *
319 intel_bb_create_with_allocator(int fd, uint32_t ctx, uint32_t vm,
320 const intel_ctx_cfg_t *cfg, uint32_t size,
321 uint8_t allocator_type);
322 struct intel_bb *intel_bb_create(int fd, uint32_t size);
323 struct intel_bb *
324 intel_bb_create_with_context(int fd, uint32_t ctx, uint32_t vm,
325 const intel_ctx_cfg_t *cfg, uint32_t size);
326 struct intel_bb *
327 intel_bb_create_with_context_in_region(int fd, uint32_t ctx, uint32_t vm,
328 const intel_ctx_cfg_t *cfg, uint32_t size, uint64_t region);
329 struct intel_bb *intel_bb_create_with_relocs(int fd, uint32_t size);
330 struct intel_bb *
331 intel_bb_create_with_relocs_and_context(int fd, uint32_t ctx,
332 const intel_ctx_cfg_t *cfg, uint32_t size);
333 struct intel_bb *intel_bb_create_no_relocs(int fd, uint32_t size);
334 void intel_bb_destroy(struct intel_bb *ibb);
336 /* make it safe to use intel_allocator after failed test */
337 void intel_bb_reinit_allocator(void);
338 void intel_bb_track(bool do_tracking);
340 static inline void intel_bb_ref(struct intel_bb *ibb)
342 ibb->refcount++;
345 static inline void intel_bb_unref(struct intel_bb *ibb)
347 igt_assert_f(ibb->refcount > 0, "intel_bb refcount is 0!");
348 ibb->refcount--;
351 void intel_bb_reset(struct intel_bb *ibb, bool purge_objects_cache);
352 int intel_bb_sync(struct intel_bb *ibb);
354 void intel_bb_print(struct intel_bb *ibb);
355 void intel_bb_dump(struct intel_bb *ibb, const char *filename, bool in_hex);
356 void intel_bb_set_debug(struct intel_bb *ibb, bool debug);
357 void intel_bb_set_dump_base64(struct intel_bb *ibb, bool dump);
359 static inline uint32_t intel_bb_offset(struct intel_bb *ibb)
361 return (uint32_t) ((uint8_t *) ibb->ptr - (uint8_t *) ibb->batch);
364 static inline void *intel_bb_ptr_get(struct intel_bb *ibb, uint32_t offset)
366 igt_assert(offset < ibb->size);
368 return ((uint8_t *) ibb->batch + offset);
371 static inline void intel_bb_ptr_set(struct intel_bb *ibb, uint32_t offset)
373 ibb->ptr = (void *) ((uint8_t *) ibb->batch + offset);
375 igt_assert(intel_bb_offset(ibb) <= ibb->size);
378 static inline void intel_bb_ptr_add(struct intel_bb *ibb, uint32_t offset)
380 intel_bb_ptr_set(ibb, intel_bb_offset(ibb) + offset);
383 static inline uint32_t intel_bb_ptr_add_return_prev_offset(struct intel_bb *ibb,
384 uint32_t offset)
386 uint32_t previous_offset = intel_bb_offset(ibb);
388 intel_bb_ptr_set(ibb, previous_offset + offset);
390 return previous_offset;
393 static inline void *intel_bb_ptr_align(struct intel_bb *ibb, uint32_t alignment)
395 intel_bb_ptr_set(ibb, ALIGN(intel_bb_offset(ibb), alignment));
397 return (void *) ibb->ptr;
400 static inline void *intel_bb_ptr(struct intel_bb *ibb)
402 return (void *) ibb->ptr;
405 static inline void intel_bb_out(struct intel_bb *ibb, uint32_t dword)
407 *ibb->ptr = dword;
408 ibb->ptr++;
410 igt_assert(intel_bb_offset(ibb) <= ibb->size);
413 void intel_bb_set_pxp(struct intel_bb *ibb, bool new_state,
414 uint32_t apptype, uint32_t appid);
416 static inline bool intel_bb_pxp_enabled(struct intel_bb *ibb)
418 igt_assert(ibb);
419 return ibb->pxp.enabled;
422 static inline uint32_t intel_bb_pxp_apptype(struct intel_bb *ibb)
424 igt_assert(ibb);
425 return ibb->pxp.apptype;
428 static inline uint32_t intel_bb_pxp_appid(struct intel_bb *ibb)
430 igt_assert(ibb);
431 return ibb->pxp.appid;
434 static inline void intel_bb_set_lr_mode(struct intel_bb *ibb, bool lr_mode)
436 igt_assert(ibb);
437 ibb->lr_mode = lr_mode;
440 static inline bool intel_bb_get_lr_mode(struct intel_bb *ibb)
442 igt_assert(ibb);
443 return ibb->lr_mode;
446 struct drm_i915_gem_exec_object2 *
447 intel_bb_add_object(struct intel_bb *ibb, uint32_t handle, uint64_t size,
448 uint64_t offset, uint64_t alignment, bool write);
449 bool intel_bb_remove_object(struct intel_bb *ibb, uint32_t handle,
450 uint64_t offset, uint64_t size);
451 struct drm_i915_gem_exec_object2 *
452 intel_bb_add_intel_buf(struct intel_bb *ibb, struct intel_buf *buf, bool write);
453 struct drm_i915_gem_exec_object2 *
454 intel_bb_add_intel_buf_with_alignment(struct intel_bb *ibb, struct intel_buf *buf,
455 uint64_t alignment, bool write);
456 bool intel_bb_remove_intel_buf(struct intel_bb *ibb, struct intel_buf *buf);
457 void intel_bb_print_intel_bufs(struct intel_bb *ibb);
458 struct drm_i915_gem_exec_object2 *
459 intel_bb_find_object(struct intel_bb *ibb, uint32_t handle);
461 bool
462 intel_bb_object_set_flag(struct intel_bb *ibb, uint32_t handle, uint64_t flag);
463 bool
464 intel_bb_object_clear_flag(struct intel_bb *ibb, uint32_t handle, uint64_t flag);
466 uint64_t intel_bb_emit_reloc(struct intel_bb *ibb,
467 uint32_t handle,
468 uint32_t read_domains,
469 uint32_t write_domain,
470 uint64_t delta,
471 uint64_t presumed_offset);
473 uint64_t intel_bb_emit_reloc_fenced(struct intel_bb *ibb,
474 uint32_t handle,
475 uint32_t read_domains,
476 uint32_t write_domain,
477 uint64_t delta,
478 uint64_t presumed_offset);
480 uint64_t intel_bb_offset_reloc(struct intel_bb *ibb,
481 uint32_t handle,
482 uint32_t read_domains,
483 uint32_t write_domain,
484 uint32_t offset,
485 uint64_t presumed_offset);
487 uint64_t intel_bb_offset_reloc_with_delta(struct intel_bb *ibb,
488 uint32_t handle,
489 uint32_t read_domains,
490 uint32_t write_domain,
491 uint32_t delta,
492 uint32_t offset,
493 uint64_t presumed_offset);
495 uint64_t intel_bb_offset_reloc_to_object(struct intel_bb *ibb,
496 uint32_t handle,
497 uint32_t to_handle,
498 uint32_t read_domains,
499 uint32_t write_domain,
500 uint32_t delta,
501 uint32_t offset,
502 uint64_t presumed_offset);
504 int __intel_bb_exec(struct intel_bb *ibb, uint32_t end_offset,
505 uint64_t flags, bool sync);
507 void intel_bb_dump_cache(struct intel_bb *ibb);
509 void intel_bb_exec(struct intel_bb *ibb, uint32_t end_offset,
510 uint64_t flags, bool sync);
512 uint64_t intel_bb_get_object_offset(struct intel_bb *ibb, uint32_t handle);
513 bool intel_bb_object_offset_to_buf(struct intel_bb *ibb, struct intel_buf *buf);
515 uint32_t intel_bb_emit_bbe(struct intel_bb *ibb);
516 uint32_t intel_bb_emit_flush_common(struct intel_bb *ibb);
517 void intel_bb_flush(struct intel_bb *ibb, uint32_t ring);
518 void intel_bb_flush_render(struct intel_bb *ibb);
519 void intel_bb_flush_blit(struct intel_bb *ibb);
521 uint32_t intel_bb_copy_data(struct intel_bb *ibb,
522 const void *data, unsigned int bytes,
523 uint32_t align);
525 void intel_bb_blit_start(struct intel_bb *ibb, uint32_t flags);
526 void intel_bb_emit_blt_copy(struct intel_bb *ibb,
527 struct intel_buf *src,
528 int src_x1, int src_y1, int src_pitch,
529 struct intel_buf *dst,
530 int dst_x1, int dst_y1, int dst_pitch,
531 int width, int height, int bpp);
532 void intel_bb_blt_copy(struct intel_bb *ibb,
533 struct intel_buf *src,
534 int src_x1, int src_y1, int src_pitch,
535 struct intel_buf *dst,
536 int dst_x1, int dst_y1, int dst_pitch,
537 int width, int height, int bpp);
538 void intel_bb_copy_intel_buf(struct intel_bb *ibb,
539 struct intel_buf *dst, struct intel_buf *src,
540 long int size);
543 * igt_huc_copyfunc_t:
544 * @fd: drm fd
545 * @ahnd: allocator handle, if it is equal to 0 we use relocations
546 * @obj: drm_i915_gem_exec_object2 buffer array
547 * obj[0] is source buffer
548 * obj[1] is destination buffer
549 * obj[2] is execution buffer
550 * @objsize: corresponding buffer sizes to @obj
552 * This is the type of the per-platform huc copy functions.
554 * The huc copy function emits a batchbuffer to the VDBOX engine to
555 * invoke the HuC Copy kernel to copy 4K bytes from the source buffer
556 * to the destination buffer.
558 typedef void (*igt_huc_copyfunc_t)(int fd, uint64_t ahnd,
559 struct drm_i915_gem_exec_object2 *obj, uint64_t *objsize);
561 igt_huc_copyfunc_t igt_get_huc_copyfunc(int devid);
562 #endif