2 * Copyright © 2013 Intel Corporation
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:
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
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
24 * Daniel Vetter <daniel.vetter@ffwll.ch>
36 #include <sys/ioctl.h>
38 #include "ioctl_wrappers.h"
40 #include "drm_fourcc.h"
43 uint32_t gem_bo_small;
45 static void pitch_tests(int fd)
47 struct drm_mode_fb_cmd2 f = {};
48 int bad_pitches[] = { 0, 32, 63, 128, 256, 256*4, 999, 64*1024 };
53 f.pixel_format = DRM_FORMAT_XRGB8888;
54 f.pitches[0] = 1024*4;
57 gem_bo = gem_create(fd, 1024*1024*4);
61 igt_subtest("no-handle") {
62 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f) == -1 &&
66 f.handles[0] = gem_bo;
67 igt_subtest("normal") {
68 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f) == 0);
69 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_RMFB, &f.fb_id) == 0);
73 for (i = 0; i < ARRAY_SIZE(bad_pitches); i++) {
74 igt_subtest_f("bad-pitch-%i", bad_pitches[i]) {
75 f.pitches[0] = bad_pitches[i];
76 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f) == -1 &&
82 gem_set_tiling(fd, gem_bo, I915_TILING_X, 1024*4);
83 f.pitches[0] = 1024*4;
85 igt_subtest("X-tiled") {
86 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f) == 0);
87 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_RMFB, &f.fb_id) == 0);
91 igt_subtest("framebuffer-vs-set-tiling") {
92 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f) == 0);
93 igt_assert(__gem_set_tiling(fd, gem_bo, I915_TILING_X, 512*4) == -EBUSY);
94 igt_assert(__gem_set_tiling(fd, gem_bo, I915_TILING_X, 1024*4) == -EBUSY);
95 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_RMFB, &f.fb_id) == 0);
100 igt_subtest("tile-pitch-mismatch") {
101 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f) == -1 &&
106 gem_set_tiling(fd, gem_bo, I915_TILING_Y, 1024*4);
107 f.pitches[0] = 1024*4;
108 igt_subtest("Y-tiled") {
109 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f) == -1 &&
114 gem_close(fd, gem_bo);
117 static void size_tests(int fd)
119 struct drm_mode_fb_cmd2 f = {};
120 struct drm_mode_fb_cmd2 f_16 = {};
121 struct drm_mode_fb_cmd2 f_8 = {};
125 f.pixel_format = DRM_FORMAT_XRGB8888;
126 f.pitches[0] = 1024*4;
129 f_16.height = 1024*2;
130 f_16.pixel_format = DRM_FORMAT_RGB565;
131 f_16.pitches[0] = 1024*2;
135 f_8.pixel_format = DRM_FORMAT_C8;
136 f_8.pitches[0] = 1024*2;
139 gem_bo = gem_create(fd, 1024*1024*4);
141 gem_bo_small = gem_create(fd, 1024*1024*4 - 4096);
142 igt_assert(gem_bo_small);
145 f.handles[0] = gem_bo;
146 f_16.handles[0] = gem_bo;
147 f_8.handles[0] = gem_bo;
149 igt_subtest("size-max") {
150 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f) == 0);
151 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_RMFB, &f.fb_id) == 0);
153 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f_16) == 0);
154 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_RMFB, &f_16.fb_id) == 0);
156 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f_8) == 0);
157 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_RMFB, &f_8.fb_id) == 0);
164 igt_subtest("too-wide") {
165 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f) == -1 &&
167 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f_16) == -1 &&
169 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f_8) == -1 &&
178 igt_subtest("too-high") {
179 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f) == -1 &&
181 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f_16) == -1 &&
183 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f_8) == -1 &&
187 f.handles[0] = gem_bo_small;
188 igt_subtest("bo-too-small") {
189 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f) == -1 &&
193 /* Just to check that the parameters would work. */
195 igt_subtest("small-bo") {
196 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f) == 0);
197 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_RMFB, &f.fb_id) == 0);
202 gem_set_tiling(fd, gem_bo_small, I915_TILING_X, 1024*4);
204 igt_subtest("bo-too-small-due-to-tiling") {
205 igt_assert(drmIoctl(fd, DRM_IOCTL_MODE_ADDFB2, &f) == -1 &&
211 gem_close(fd, gem_bo);
212 gem_close(fd, gem_bo_small);