xref: /aosp_15_r20/external/igt-gpu-tools/tests/kms_big_fb.c (revision d83cc019efdc2edc6c4b16e9034a3ceb8d35d77c)
1 /*
2  * Copyright © 2019 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 
24 #include "igt.h"
25 #include <errno.h>
26 #include <stdbool.h>
27 #include <stdio.h>
28 #include <string.h>
29 
30 IGT_TEST_DESCRIPTION("Test big framebuffers");
31 
32 typedef struct {
33 	int drm_fd;
34 	uint32_t devid;
35 	igt_display_t display;
36 	enum pipe pipe;
37 	igt_output_t *output;
38 	igt_plane_t *plane;
39 	igt_pipe_crc_t *pipe_crc;
40 	struct igt_fb small_fb, big_fb;
41 	uint32_t format;
42 	uint64_t modifier;
43 	int width, height;
44 	igt_rotation_t rotation;
45 	int max_fb_width, max_fb_height;
46 	int big_fb_width, big_fb_height;
47 	uint64_t ram_size, aper_size, mappable_size;
48 	igt_render_copyfunc_t render_copy;
49 	drm_intel_bufmgr *bufmgr;
50 	struct intel_batchbuffer *batch;
51 } data_t;
52 
init_buf(data_t * data,struct igt_buf * buf,const struct igt_fb * fb,const char * name)53 static void init_buf(data_t *data,
54 		     struct igt_buf *buf,
55 		     const struct igt_fb *fb,
56 		     const char *name)
57 {
58 	igt_assert_eq(fb->offsets[0], 0);
59 
60 	buf->bo = gem_handle_to_libdrm_bo(data->bufmgr, data->drm_fd,
61 					  name, fb->gem_handle);
62 	buf->tiling = igt_fb_mod_to_tiling(fb->modifier);
63 	buf->stride = fb->strides[0];
64 	buf->bpp = fb->plane_bpp[0];
65 	buf->size = fb->size;
66 }
67 
fini_buf(struct igt_buf * buf)68 static void fini_buf(struct igt_buf *buf)
69 {
70 	drm_intel_bo_unreference(buf->bo);
71 }
72 
copy_pattern(data_t * data,struct igt_fb * dst_fb,int dx,int dy,struct igt_fb * src_fb,int sx,int sy,int w,int h)73 static void copy_pattern(data_t *data,
74 			 struct igt_fb *dst_fb, int dx, int dy,
75 			 struct igt_fb *src_fb, int sx, int sy,
76 			 int w, int h)
77 {
78 	struct igt_buf src = {}, dst = {};
79 
80 	init_buf(data, &src, src_fb, "big fb src");
81 	init_buf(data, &dst, dst_fb, "big fb dst");
82 
83 	gem_set_domain(data->drm_fd, dst_fb->gem_handle,
84 		       I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
85 	gem_set_domain(data->drm_fd, src_fb->gem_handle,
86 		       I915_GEM_DOMAIN_GTT, 0);
87 
88 	/*
89 	 * We expect the kernel to limit the max fb
90 	 * size/stride to something that can still
91 	 * rendered with the blitter/render engine.
92 	 */
93 	if (data->render_copy) {
94 		data->render_copy(data->batch, NULL, &src, sx, sy, w, h, &dst, dx, dy);
95 	} else {
96 		w = min(w, src_fb->width - sx);
97 		w = min(w, dst_fb->width - dx);
98 
99 		h = min(h, src_fb->height - sy);
100 		h = min(h, dst_fb->height - dy);
101 
102 		intel_blt_copy(data->batch, src.bo, sx, sy, src.stride,
103 			       dst.bo, dx, dy, dst.stride, w, h, dst.bpp);
104 	}
105 
106 	fini_buf(&dst);
107 	fini_buf(&src);
108 }
109 
generate_pattern(data_t * data,struct igt_fb * fb,int w,int h)110 static void generate_pattern(data_t *data,
111 			     struct igt_fb *fb,
112 			     int w, int h)
113 {
114 	struct igt_fb pat_fb;
115 
116 	igt_create_pattern_fb(data->drm_fd, w, h,
117 			      data->format, data->modifier,
118 			      &pat_fb);
119 
120 	for (int y = 0; y < fb->height; y += h) {
121 		for (int x = 0; x < fb->width; x += w) {
122 			copy_pattern(data, fb, x, y,
123 				     &pat_fb, 0, 0,
124 				     pat_fb.width, pat_fb.height);
125 			w++;
126 			h++;
127 		}
128 	}
129 
130 	igt_remove_fb(data->drm_fd, &pat_fb);
131 }
132 
size_ok(data_t * data,uint64_t size)133 static bool size_ok(data_t *data, uint64_t size)
134 {
135 	/*
136 	 * The kernel limits scanout to the
137 	 * mappable portion of ggtt on gmch platforms.
138 	 */
139 	if ((intel_gen(data->devid) < 5 ||
140 	     IS_VALLEYVIEW(data->devid) ||
141 	     IS_CHERRYVIEW(data->devid)) &&
142 	    size > data->mappable_size / 2)
143 		return false;
144 
145 	/*
146 	 * Limit the big fb size to at most half the RAM or half
147 	 * the aperture size. Could go a bit higher I suppose since
148 	 * we shouldn't need more than one big fb at a time.
149 	 */
150 	if (size > data->ram_size / 2 || size > data->aper_size / 2)
151 		return false;
152 
153 	return true;
154 }
155 
156 
max_fb_size(data_t * data,int * width,int * height,uint32_t format,uint64_t modifier)157 static void max_fb_size(data_t *data, int *width, int *height,
158 			uint32_t format, uint64_t modifier)
159 {
160 	unsigned int stride;
161 	uint64_t size;
162 	int i = 0;
163 
164 	*width = data->max_fb_width;
165 	*height = data->max_fb_height;
166 
167 	/* max fence stride is only 8k bytes on gen3 */
168 	if (intel_gen(data->devid) < 4 &&
169 	    format == DRM_FORMAT_XRGB8888)
170 		*width = min(*width, 8192 / 4);
171 
172 	igt_calc_fb_size(data->drm_fd, *width, *height,
173 			 format, modifier, &size, &stride);
174 
175 	while (!size_ok(data, size)) {
176 		if (i++ & 1)
177 			*width >>= 1;
178 		else
179 			*height >>= 1;
180 
181 		igt_calc_fb_size(data->drm_fd, *width, *height,
182 				 format, modifier, &size, &stride);
183 	}
184 
185 	igt_info("Max usable framebuffer size for format "IGT_FORMAT_FMT" / modifier 0x%"PRIx64": %dx%d\n",
186 		 IGT_FORMAT_ARGS(format), modifier,
187 		 *width, *height);
188 }
189 
prep_fb(data_t * data)190 static void prep_fb(data_t *data)
191 {
192 	if (data->big_fb.fb_id)
193 		return;
194 
195 	igt_create_fb(data->drm_fd,
196 		      data->big_fb_width, data->big_fb_height,
197 		      data->format, data->modifier,
198 		      &data->big_fb);
199 
200 	generate_pattern(data, &data->big_fb, 640, 480);
201 }
202 
cleanup_fb(data_t * data)203 static void cleanup_fb(data_t *data)
204 {
205 	igt_remove_fb(data->drm_fd, &data->big_fb);
206 	data->big_fb.fb_id = 0;
207 }
208 
set_c8_lut(data_t * data)209 static void set_c8_lut(data_t *data)
210 {
211 	igt_pipe_t *pipe = &data->display.pipes[data->pipe];
212 	struct drm_color_lut *lut;
213 	int i, lut_size = 256;
214 
215 	lut = calloc(lut_size, sizeof(lut[0]));
216 
217 	/* igt_fb uses RGB332 for C8 */
218 	for (i = 0; i < lut_size; i++) {
219 		lut[i].red = ((i & 0xe0) >> 5) * 0xffff / 0x7;
220 		lut[i].green = ((i & 0x1c) >> 2) * 0xffff / 0x7;
221 		lut[i].blue = ((i & 0x03) >> 0) * 0xffff / 0x3;
222 	}
223 
224 	igt_pipe_obj_replace_prop_blob(pipe, IGT_CRTC_GAMMA_LUT, lut,
225 				       lut_size * sizeof(lut[0]));
226 
227 	free(lut);
228 }
229 
unset_lut(data_t * data)230 static void unset_lut(data_t *data)
231 {
232 	igt_pipe_t *pipe = &data->display.pipes[data->pipe];
233 
234 	igt_pipe_obj_replace_prop_blob(pipe, IGT_CRTC_GAMMA_LUT, NULL, 0);
235 }
236 
test_plane(data_t * data)237 static bool test_plane(data_t *data)
238 {
239 	igt_plane_t *plane = data->plane;
240 	struct igt_fb *small_fb = &data->small_fb;
241 	struct igt_fb *big_fb = &data->big_fb;
242 	int w = data->big_fb_width - small_fb->width;
243 	int h = data->big_fb_height - small_fb->height;
244 	struct {
245 		int x, y;
246 	} coords[] = {
247 		/* bunch of coordinates pulled out of thin air */
248 		{ 0, 0, },
249 		{ w * 4 / 7, h / 5, },
250 		{ w * 3 / 7, h / 3, },
251 		{ w / 2, h / 2, },
252 		{ w / 3, h * 3 / 4, },
253 		{ w, h, },
254 	};
255 
256 	if (!igt_plane_has_format_mod(plane, data->format, data->modifier))
257 		return false;
258 
259 	if (data->rotation != IGT_ROTATION_0 &&
260 	    !igt_plane_has_prop(plane, IGT_PLANE_ROTATION))
261 		return false;
262 
263 	/* FIXME need atomic on i965/g4x */
264 	if (data->rotation != IGT_ROTATION_0 &&
265 	    data->rotation != IGT_ROTATION_180 &&
266 	    !data->display.is_atomic)
267 		return false;
268 
269 	if (igt_plane_has_prop(plane, IGT_PLANE_ROTATION))
270 		igt_plane_set_rotation(plane, data->rotation);
271 	igt_plane_set_position(plane, 0, 0);
272 
273 	for (int i = 0; i < ARRAY_SIZE(coords); i++) {
274 		igt_crc_t small_crc, big_crc;
275 		int x = coords[i].x;
276 		int y = coords[i].y;
277 
278 		/* Hardware limitation */
279 		if (data->format == DRM_FORMAT_RGB565 &&
280 		    (data->rotation == IGT_ROTATION_90 ||
281 		     data->rotation == IGT_ROTATION_270)) {
282 			x &= ~1;
283 			y &= ~1;
284 		}
285 
286 		igt_plane_set_fb(plane, small_fb);
287 		igt_plane_set_size(plane, data->width, data->height);
288 
289 		/*
290 		 * Try to check that the rotation+format+modifier
291 		 * combo is supported.
292 		 */
293 		if (i == 0 && data->display.is_atomic &&
294 		    igt_display_try_commit_atomic(&data->display,
295 						  DRM_MODE_ATOMIC_TEST_ONLY,
296 						  NULL) != 0) {
297 			if (igt_plane_has_prop(plane, IGT_PLANE_ROTATION))
298 				igt_plane_set_rotation(plane, IGT_ROTATION_0);
299 			igt_plane_set_fb(plane, NULL);
300 			return false;
301 		}
302 
303 		/*
304 		 * To speed up skips we delay the big fb creation until
305 		 * the above rotation related check has been performed.
306 		 */
307 		prep_fb(data);
308 
309 		/*
310 		 * Make a 1:1 copy of the desired part of the big fb
311 		 * rather than try to render the same pattern (translated
312 		 * accordinly) again via cairo. Something in cairo's
313 		 * rendering pipeline introduces slight differences into
314 		 * the result if we try that, and so the crc will not match.
315 		 */
316 		copy_pattern(data, small_fb, 0, 0, big_fb, x, y,
317 			     small_fb->width, small_fb->height);
318 
319 		igt_display_commit2(&data->display, data->display.is_atomic ?
320 				    COMMIT_ATOMIC : COMMIT_UNIVERSAL);
321 
322 
323 		igt_pipe_crc_collect_crc(data->pipe_crc, &small_crc);
324 
325 		igt_plane_set_fb(plane, big_fb);
326 		igt_fb_set_position(big_fb, plane, x, y);
327 		igt_fb_set_size(big_fb, plane, small_fb->width, small_fb->height);
328 		igt_plane_set_size(plane, data->width, data->height);
329 		igt_display_commit2(&data->display, data->display.is_atomic ?
330 				    COMMIT_ATOMIC : COMMIT_UNIVERSAL);
331 
332 		igt_pipe_crc_collect_crc(data->pipe_crc, &big_crc);
333 
334 		igt_plane_set_fb(plane, NULL);
335 
336 		igt_assert_crc_equal(&big_crc, &small_crc);
337 	}
338 
339 	return true;
340 }
341 
test_pipe(data_t * data)342 static bool test_pipe(data_t *data)
343 {
344 	drmModeModeInfo *mode;
345 	igt_plane_t *primary;
346 	int width, height;
347 	bool ret = false;
348 
349 	if (data->format == DRM_FORMAT_C8 &&
350 	    !igt_pipe_obj_has_prop(&data->display.pipes[data->pipe],
351 				   IGT_CRTC_GAMMA_LUT))
352 		return false;
353 
354 	mode = igt_output_get_mode(data->output);
355 
356 	data->width = mode->hdisplay;
357 	data->height = mode->vdisplay;
358 
359 	width = mode->hdisplay;
360 	height = mode->vdisplay;
361 	if (data->rotation == IGT_ROTATION_90 ||
362 	    data->rotation == IGT_ROTATION_270)
363 		igt_swap(width, height);
364 
365 	igt_create_color_fb(data->drm_fd, width, height,
366 			    data->format, data->modifier,
367 			    0, 1, 0, &data->small_fb);
368 
369 	igt_output_set_pipe(data->output, data->pipe);
370 
371 	primary = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_PRIMARY);
372 	igt_plane_set_fb(primary, NULL);
373 
374 	if (!data->display.is_atomic) {
375 		struct igt_fb fb;
376 
377 		igt_create_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
378 			      DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_LINEAR,
379 			      &fb);
380 
381 		/* legacy setcrtc needs an fb */
382 		igt_plane_set_fb(primary, &fb);
383 		igt_display_commit2(&data->display, COMMIT_LEGACY);
384 
385 		igt_plane_set_fb(primary, NULL);
386 		igt_display_commit2(&data->display, COMMIT_UNIVERSAL);
387 
388 		igt_remove_fb(data->drm_fd, &fb);
389 	}
390 
391 	if (data->format == DRM_FORMAT_C8)
392 		set_c8_lut(data);
393 
394 	igt_display_commit2(&data->display, data->display.is_atomic ?
395 			    COMMIT_ATOMIC : COMMIT_UNIVERSAL);
396 
397 	data->pipe_crc = igt_pipe_crc_new(data->drm_fd, data->pipe,
398 					  INTEL_PIPE_CRC_SOURCE_AUTO);
399 
400 	for_each_plane_on_pipe(&data->display, data->pipe, data->plane) {
401 		ret = test_plane(data);
402 		if (ret)
403 			break;
404 	}
405 
406 	if (data->format == DRM_FORMAT_C8)
407 		unset_lut(data);
408 
409 	igt_pipe_crc_free(data->pipe_crc);
410 
411 	igt_output_set_pipe(data->output, PIPE_ANY);
412 
413 	igt_remove_fb(data->drm_fd, &data->small_fb);
414 
415 	return ret;
416 }
417 
test_scanout(data_t * data)418 static void test_scanout(data_t *data)
419 {
420 	max_fb_size(data, &data->big_fb_width, &data->big_fb_height,
421 		    data->format, data->modifier);
422 
423 	for_each_pipe_with_valid_output(&data->display, data->pipe, data->output) {
424 		if (test_pipe(data))
425 			return;
426 		break;
427 	}
428 
429 	igt_skip("unsupported configuration\n");
430 }
431 
432 static void
test_size_overflow(data_t * data)433 test_size_overflow(data_t *data)
434 {
435 	uint32_t fb_id;
436 	uint32_t bo;
437 	uint32_t offsets[4] = {};
438 	uint32_t strides[4] = { 256*1024, };
439 	int ret;
440 
441 	igt_require(igt_display_has_format_mod(&data->display,
442 					       DRM_FORMAT_XRGB8888,
443 					       data->modifier));
444 
445 	/*
446 	 * Try to hit a specific integer overflow in i915 fb size
447 	 * calculations. 256k * 16k == 1<<32 which is checked
448 	 * against the bo size. The check should fail on account
449 	 * of the bo being smaller, but due to the overflow the
450 	 * computed fb size is 0 and thus the check never trips.
451 	 */
452 	igt_require(data->max_fb_width >= 16383 &&
453 		    data->max_fb_height >= 16383);
454 
455 	bo = gem_create(data->drm_fd, (1ULL << 32) - 4096);
456 	igt_require(bo);
457 
458 	ret = __kms_addfb(data->drm_fd, bo,
459 			  16383, 16383,
460 			  DRM_FORMAT_XRGB8888,
461 			  data->modifier,
462 			  strides, offsets, 1,
463 			  DRM_MODE_FB_MODIFIERS, &fb_id);
464 
465 	igt_assert_neq(ret, 0);
466 
467 	gem_close(data->drm_fd, bo);
468 }
469 
470 static void
test_size_offset_overflow(data_t * data)471 test_size_offset_overflow(data_t *data)
472 {
473 	uint32_t fb_id;
474 	uint32_t bo;
475 	uint32_t offsets[4] = {};
476 	uint32_t strides[4] = { 8192, };
477 	int ret;
478 
479 	igt_require(igt_display_has_format_mod(&data->display,
480 					       DRM_FORMAT_NV12,
481 					       data->modifier));
482 
483 	/*
484 	 * Try to hit a specific integer overflow in i915 fb size
485 	 * calculations. This time it's offsets[1] + the tile
486 	 * aligned chroma plane size that overflows and
487 	 * incorrectly passes the bo size check.
488 	 */
489 	igt_require(igt_display_has_format_mod(&data->display,
490 					       DRM_FORMAT_NV12,
491 					       data->modifier));
492 
493 	bo = gem_create(data->drm_fd, (1ULL << 32) - 4096);
494 	igt_require(bo);
495 
496 	offsets[0] = 0;
497 	offsets[1] = (1ULL << 32) - 8192 * 4096;
498 
499 	ret = __kms_addfb(data->drm_fd, bo,
500 			  8192, 8188,
501 			  DRM_FORMAT_NV12,
502 			  data->modifier,
503 			  strides, offsets, 1,
504 			  DRM_MODE_FB_MODIFIERS, &fb_id);
505 	igt_assert_neq(ret, 0);
506 
507 	gem_close(data->drm_fd, bo);
508 }
509 
rmfb(int fd,uint32_t id)510 static int rmfb(int fd, uint32_t id)
511 {
512 	int err;
513 
514 	err = 0;
515 	if (igt_ioctl(fd, DRM_IOCTL_MODE_RMFB, &id))
516 		err = -errno;
517 
518 	errno = 0;
519 	return err;
520 }
521 
522 static void
test_addfb(data_t * data)523 test_addfb(data_t *data)
524 {
525 	uint64_t size;
526 	uint32_t fb_id;
527 	uint32_t bo;
528 	uint32_t offsets[4] = {};
529 	uint32_t strides[4] = {};
530 	uint32_t format;
531 	int ret;
532 
533 	/*
534 	 * gen3 max tiled stride is 8k bytes, but
535 	 * max fb size of 4k pixels, hence we can't test
536 	 * with 32bpp and must use 16bpp instead.
537 	 */
538 	if (intel_gen(data->devid) == 3)
539 		format = DRM_FORMAT_RGB565;
540 	else
541 		format = DRM_FORMAT_XRGB8888;
542 
543 	igt_require(igt_display_has_format_mod(&data->display,
544 					       format, data->modifier));
545 
546 	igt_calc_fb_size(data->drm_fd,
547 			 data->max_fb_width,
548 			 data->max_fb_height,
549 			 format, data->modifier,
550 			 &size, &strides[0]);
551 
552 	bo = gem_create(data->drm_fd, size);
553 	igt_require(bo);
554 
555 	if (intel_gen(data->devid) < 4)
556 		gem_set_tiling(data->drm_fd, bo,
557 			       igt_fb_mod_to_tiling(data->modifier), strides[0]);
558 
559 	ret = __kms_addfb(data->drm_fd, bo,
560 			  data->max_fb_width,
561 			  data->max_fb_height,
562 			  format, data->modifier,
563 			  strides, offsets, 1,
564 			  DRM_MODE_FB_MODIFIERS, &fb_id);
565 	igt_assert_eq(ret, 0);
566 
567 	rmfb(data->drm_fd, fb_id);
568 	gem_close(data->drm_fd, bo);
569 }
570 
571 static data_t data;
572 
573 static const struct {
574 	uint64_t modifier;
575 	const char *name;
576 } modifiers[] = {
577 	{ DRM_FORMAT_MOD_LINEAR, "linear", },
578 	{ I915_FORMAT_MOD_X_TILED, "x-tiled", },
579 	{ I915_FORMAT_MOD_Y_TILED, "y-tiled", },
580 	{ I915_FORMAT_MOD_Yf_TILED, "yf-tiled", },
581 };
582 
583 static const struct {
584 	uint32_t format;
585 	uint8_t bpp;
586 } formats[] = {
587 	{ DRM_FORMAT_C8, 8, },
588 	{ DRM_FORMAT_RGB565, 16, },
589 	{ DRM_FORMAT_XRGB8888, 32, },
590 	{ DRM_FORMAT_XBGR16161616F, 64, },
591 };
592 
593 static const struct {
594 	igt_rotation_t rotation;
595 	uint16_t angle;
596 } rotations[] = {
597 	{ IGT_ROTATION_0, 0, },
598 	{ IGT_ROTATION_90, 90, },
599 	{ IGT_ROTATION_180, 180, },
600 	{ IGT_ROTATION_270, 270, },
601 };
602 
603 igt_main
604 {
605 	igt_fixture {
606 		drmModeResPtr res;
607 
608 		igt_skip_on_simulation();
609 
610 		data.drm_fd = drm_open_driver_master(DRIVER_INTEL);
611 
612 		igt_require(is_i915_device(data.drm_fd));
613 
614 		data.devid = intel_get_drm_devid(data.drm_fd);
615 
616 		kmstest_set_vt_graphics_mode();
617 
618 		igt_require_pipe_crc(data.drm_fd);
619 		igt_display_require(&data.display, data.drm_fd);
620 
621 		res = drmModeGetResources(data.drm_fd);
622 		igt_assert(res);
623 
624 		data.max_fb_width = res->max_width;
625 		data.max_fb_height = res->max_height;
626 
627 		drmModeFreeResources(res);
628 
629 		igt_info("Max driver framebuffer size %dx%d\n",
630 			 data.max_fb_width, data.max_fb_height);
631 
632 		data.ram_size = intel_get_total_ram_mb() << 20;
633 		data.aper_size = gem_aperture_size(data.drm_fd);
634 		data.mappable_size = gem_mappable_aperture_size();
635 
636 		igt_info("RAM: %"PRIu64" MiB, GPU address space: %"PRId64" MiB, GGTT mappable size: %"PRId64" MiB\n",
637 			 data.ram_size >> 20, data.aper_size >> 20,
638 			 data.mappable_size >> 20);
639 
640 		/*
641 		 * Gen3 render engine is limited to 2kx2k, whereas
642 		 * the display engine can do 4kx4k. Use the blitter
643 		 * on gen3 to avoid exceeding the render engine limits.
644 		 * On gen2 we could use either, but let's go for the
645 		 * blitter there as well.
646 		 */
647 		if (intel_gen(data.devid) >= 4)
648 			data.render_copy = igt_get_render_copyfunc(data.devid);
649 
650 		data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
651 		data.batch = intel_batchbuffer_alloc(data.bufmgr, data.devid);
652 	}
653 
654 	/*
655 	 * Skip linear as it doesn't hit the overflow we want
656 	 * on account of the tile height being effectively one,
657 	 * and thus the kenrnel rounding up to the next tile
658 	 * height won't do anything.
659 	 */
660 	for (int i = 1; i < ARRAY_SIZE(modifiers); i++) {
661 		igt_subtest_f("%s-addfb-size-overflow",
662 			      modifiers[i].name) {
663 			data.modifier = modifiers[i].modifier;
664 			test_size_overflow(&data);
665 		}
666 	}
667 
668 	for (int i = 1; i < ARRAY_SIZE(modifiers); i++) {
669 		igt_subtest_f("%s-addfb-size-offset-overflow",
670 			      modifiers[i].name) {
671 			data.modifier = modifiers[i].modifier;
672 			test_size_offset_overflow(&data);
673 		}
674 	}
675 
676 	for (int i = 0; i < ARRAY_SIZE(modifiers); i++) {
677 		igt_subtest_f("%s-addfb", modifiers[i].name) {
678 			data.modifier = modifiers[i].modifier;
679 
680 			test_addfb(&data);
681 		}
682 	}
683 
684 	for (int i = 0; i < ARRAY_SIZE(modifiers); i++) {
685 		data.modifier = modifiers[i].modifier;
686 
687 		for (int j = 0; j < ARRAY_SIZE(formats); j++) {
688 			data.format = formats[j].format;
689 
690 			for (int k = 0; k < ARRAY_SIZE(rotations); k++) {
691 				data.rotation = rotations[k].rotation;
692 
693 				igt_subtest_f("%s-%dbpp-rotate-%d", modifiers[i].name,
694 					      formats[j].bpp, rotations[k].angle) {
695 					igt_require(data.format == DRM_FORMAT_C8 ||
696 						    igt_fb_supported_format(data.format));
697 					igt_require(igt_display_has_format_mod(&data.display, data.format, data.modifier));
698 					test_scanout(&data);
699 				}
700 			}
701 
702 			igt_fixture
703 				cleanup_fb(&data);
704 		}
705 	}
706 
707 	igt_fixture {
708 		igt_display_fini(&data.display);
709 
710 		intel_batchbuffer_free(data.batch);
711 		drm_intel_bufmgr_destroy(data.bufmgr);
712 	}
713 }
714