1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Test cases for the drm_framebuffer functions
4*4882a593Smuzhiyun */
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun #include <linux/kernel.h>
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include <drm/drm_device.h>
9*4882a593Smuzhiyun #include <drm/drm_mode.h>
10*4882a593Smuzhiyun #include <drm/drm_fourcc.h>
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun #include "../drm_crtc_internal.h"
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun #include "test-drm_modeset_common.h"
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #define MIN_WIDTH 4
17*4882a593Smuzhiyun #define MAX_WIDTH 4096
18*4882a593Smuzhiyun #define MIN_HEIGHT 4
19*4882a593Smuzhiyun #define MAX_HEIGHT 4096
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun struct drm_framebuffer_test {
22*4882a593Smuzhiyun int buffer_created;
23*4882a593Smuzhiyun struct drm_mode_fb_cmd2 cmd;
24*4882a593Smuzhiyun const char *name;
25*4882a593Smuzhiyun };
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun static struct drm_framebuffer_test createbuffer_tests[] = {
28*4882a593Smuzhiyun { .buffer_created = 1, .name = "ABGR8888 normal sizes",
29*4882a593Smuzhiyun .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_ABGR8888,
30*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 4 * 600, 0, 0 },
31*4882a593Smuzhiyun }
32*4882a593Smuzhiyun },
33*4882a593Smuzhiyun { .buffer_created = 1, .name = "ABGR8888 max sizes",
34*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
35*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun },
38*4882a593Smuzhiyun { .buffer_created = 1, .name = "ABGR8888 pitch greater than min required",
39*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
40*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH + 1, 0, 0 },
41*4882a593Smuzhiyun }
42*4882a593Smuzhiyun },
43*4882a593Smuzhiyun { .buffer_created = 0, .name = "ABGR8888 pitch less than min required",
44*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
45*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH - 1, 0, 0 },
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun },
48*4882a593Smuzhiyun { .buffer_created = 0, .name = "ABGR8888 Invalid width",
49*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH + 1, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
50*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 4 * (MAX_WIDTH + 1), 0, 0 },
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun },
53*4882a593Smuzhiyun { .buffer_created = 0, .name = "ABGR8888 Invalid buffer handle",
54*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
55*4882a593Smuzhiyun .handles = { 0, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun },
58*4882a593Smuzhiyun { .buffer_created = 0, .name = "No pixel format",
59*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = 0,
60*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
61*4882a593Smuzhiyun }
62*4882a593Smuzhiyun },
63*4882a593Smuzhiyun { .buffer_created = 0, .name = "ABGR8888 Width 0",
64*4882a593Smuzhiyun .cmd = { .width = 0, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
65*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun },
68*4882a593Smuzhiyun { .buffer_created = 0, .name = "ABGR8888 Height 0",
69*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = 0, .pixel_format = DRM_FORMAT_ABGR8888,
70*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun },
73*4882a593Smuzhiyun { .buffer_created = 0, .name = "ABGR8888 Out of bound height * pitch combination",
74*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
75*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .offsets = { UINT_MAX - 1, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun },
78*4882a593Smuzhiyun { .buffer_created = 1, .name = "ABGR8888 Large buffer offset",
79*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
80*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun },
83*4882a593Smuzhiyun { .buffer_created = 1, .name = "ABGR8888 Set DRM_MODE_FB_MODIFIERS without modifiers",
84*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
85*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 },
86*4882a593Smuzhiyun .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS,
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun },
89*4882a593Smuzhiyun { .buffer_created = 1, .name = "ABGR8888 Valid buffer modifier",
90*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
91*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
92*4882a593Smuzhiyun .flags = DRM_MODE_FB_MODIFIERS, .modifier = { AFBC_FORMAT_MOD_YTR, 0, 0 },
93*4882a593Smuzhiyun }
94*4882a593Smuzhiyun },
95*4882a593Smuzhiyun { .buffer_created = 0, .name = "ABGR8888 Invalid buffer modifier(DRM_FORMAT_MOD_SAMSUNG_64_32_TILE)",
96*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
97*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 },
98*4882a593Smuzhiyun .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS,
99*4882a593Smuzhiyun .modifier = { DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, 0, 0 },
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun },
102*4882a593Smuzhiyun { .buffer_created = 1, .name = "ABGR8888 Extra pitches without DRM_MODE_FB_MODIFIERS",
103*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
104*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 },
105*4882a593Smuzhiyun .pitches = { 4 * MAX_WIDTH, 4 * MAX_WIDTH, 0 },
106*4882a593Smuzhiyun }
107*4882a593Smuzhiyun },
108*4882a593Smuzhiyun { .buffer_created = 0, .name = "ABGR8888 Extra pitches with DRM_MODE_FB_MODIFIERS",
109*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
110*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS,
111*4882a593Smuzhiyun .pitches = { 4 * MAX_WIDTH, 4 * MAX_WIDTH, 0 },
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun },
114*4882a593Smuzhiyun { .buffer_created = 1, .name = "NV12 Normal sizes",
115*4882a593Smuzhiyun .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_NV12,
116*4882a593Smuzhiyun .handles = { 1, 1, 0 }, .pitches = { 600, 600, 0 },
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun },
119*4882a593Smuzhiyun { .buffer_created = 1, .name = "NV12 Max sizes",
120*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12,
121*4882a593Smuzhiyun .handles = { 1, 1, 0 }, .pitches = { MAX_WIDTH, MAX_WIDTH, 0 },
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun },
124*4882a593Smuzhiyun { .buffer_created = 0, .name = "NV12 Invalid pitch",
125*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12,
126*4882a593Smuzhiyun .handles = { 1, 1, 0 }, .pitches = { MAX_WIDTH, MAX_WIDTH - 1, 0 },
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun },
129*4882a593Smuzhiyun { .buffer_created = 0, .name = "NV12 Invalid modifier/missing DRM_MODE_FB_MODIFIERS flag",
130*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12,
131*4882a593Smuzhiyun .handles = { 1, 1, 0 }, .modifier = { DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, 0, 0 },
132*4882a593Smuzhiyun .pitches = { MAX_WIDTH, MAX_WIDTH, 0 },
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun },
135*4882a593Smuzhiyun { .buffer_created = 0, .name = "NV12 different modifier per-plane",
136*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12,
137*4882a593Smuzhiyun .handles = { 1, 1, 0 }, .flags = DRM_MODE_FB_MODIFIERS,
138*4882a593Smuzhiyun .modifier = { DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, 0, 0 },
139*4882a593Smuzhiyun .pitches = { MAX_WIDTH, MAX_WIDTH, 0 },
140*4882a593Smuzhiyun }
141*4882a593Smuzhiyun },
142*4882a593Smuzhiyun { .buffer_created = 1, .name = "NV12 with DRM_FORMAT_MOD_SAMSUNG_64_32_TILE",
143*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12,
144*4882a593Smuzhiyun .handles = { 1, 1, 0 }, .flags = DRM_MODE_FB_MODIFIERS,
145*4882a593Smuzhiyun .modifier = { DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, 0 },
146*4882a593Smuzhiyun .pitches = { MAX_WIDTH, MAX_WIDTH, 0 },
147*4882a593Smuzhiyun }
148*4882a593Smuzhiyun },
149*4882a593Smuzhiyun { .buffer_created = 0, .name = "NV12 Valid modifiers without DRM_MODE_FB_MODIFIERS",
150*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12,
151*4882a593Smuzhiyun .handles = { 1, 1, 0 }, .modifier = { DRM_FORMAT_MOD_SAMSUNG_64_32_TILE,
152*4882a593Smuzhiyun DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, 0 },
153*4882a593Smuzhiyun .pitches = { MAX_WIDTH, MAX_WIDTH, 0 },
154*4882a593Smuzhiyun }
155*4882a593Smuzhiyun },
156*4882a593Smuzhiyun { .buffer_created = 0, .name = "NV12 Modifier for inexistent plane",
157*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12,
158*4882a593Smuzhiyun .handles = { 1, 1, 0 }, .flags = DRM_MODE_FB_MODIFIERS,
159*4882a593Smuzhiyun .modifier = { DRM_FORMAT_MOD_SAMSUNG_64_32_TILE, DRM_FORMAT_MOD_SAMSUNG_64_32_TILE,
160*4882a593Smuzhiyun DRM_FORMAT_MOD_SAMSUNG_64_32_TILE },
161*4882a593Smuzhiyun .pitches = { MAX_WIDTH, MAX_WIDTH, 0 },
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun },
164*4882a593Smuzhiyun { .buffer_created = 0, .name = "NV12 Handle for inexistent plane",
165*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_NV12,
166*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .flags = DRM_MODE_FB_MODIFIERS, .pitches = { MAX_WIDTH, MAX_WIDTH, 0 },
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun },
169*4882a593Smuzhiyun { .buffer_created = 1, .name = "NV12 Handle for inexistent plane without DRM_MODE_FB_MODIFIERS",
170*4882a593Smuzhiyun .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_NV12,
171*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .pitches = { 600, 600, 600 },
172*4882a593Smuzhiyun }
173*4882a593Smuzhiyun },
174*4882a593Smuzhiyun { .buffer_created = 1, .name = "YVU420 Normal sizes",
175*4882a593Smuzhiyun .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_YVU420,
176*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .flags = DRM_MODE_FB_MODIFIERS,
177*4882a593Smuzhiyun .pitches = { 600, 300, 300 },
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun },
180*4882a593Smuzhiyun { .buffer_created = 1, .name = "YVU420 DRM_MODE_FB_MODIFIERS set without modifier",
181*4882a593Smuzhiyun .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_YVU420,
182*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .pitches = { 600, 300, 300 },
183*4882a593Smuzhiyun }
184*4882a593Smuzhiyun },
185*4882a593Smuzhiyun { .buffer_created = 1, .name = "YVU420 Max sizes",
186*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420,
187*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2),
188*4882a593Smuzhiyun DIV_ROUND_UP(MAX_WIDTH, 2) },
189*4882a593Smuzhiyun }
190*4882a593Smuzhiyun },
191*4882a593Smuzhiyun { .buffer_created = 0, .name = "YVU420 Invalid pitch",
192*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420,
193*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2) - 1,
194*4882a593Smuzhiyun DIV_ROUND_UP(MAX_WIDTH, 2) },
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun },
197*4882a593Smuzhiyun { .buffer_created = 1, .name = "YVU420 Different pitches",
198*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420,
199*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2) + 1,
200*4882a593Smuzhiyun DIV_ROUND_UP(MAX_WIDTH, 2) + 7 },
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun },
203*4882a593Smuzhiyun { .buffer_created = 1, .name = "YVU420 Different buffer offsets/pitches",
204*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420,
205*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .offsets = { MAX_WIDTH, MAX_WIDTH + MAX_WIDTH * MAX_HEIGHT,
206*4882a593Smuzhiyun MAX_WIDTH + 2 * MAX_WIDTH * MAX_HEIGHT },
207*4882a593Smuzhiyun .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2) + 1, DIV_ROUND_UP(MAX_WIDTH, 2) + 7 },
208*4882a593Smuzhiyun }
209*4882a593Smuzhiyun },
210*4882a593Smuzhiyun { .buffer_created = 0, .name = "YVU420 Modifier set just for plane 0, without DRM_MODE_FB_MODIFIERS",
211*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420,
212*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .modifier = { AFBC_FORMAT_MOD_SPARSE, 0, 0 },
213*4882a593Smuzhiyun .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) },
214*4882a593Smuzhiyun }
215*4882a593Smuzhiyun },
216*4882a593Smuzhiyun { .buffer_created = 0, .name = "YVU420 Modifier set just for planes 0, 1, without DRM_MODE_FB_MODIFIERS",
217*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420,
218*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .modifier = { AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE, 0 },
219*4882a593Smuzhiyun .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) },
220*4882a593Smuzhiyun }
221*4882a593Smuzhiyun },
222*4882a593Smuzhiyun { .buffer_created = 0, .name = "YVU420 Modifier set just for plane 0, 1, with DRM_MODE_FB_MODIFIERS",
223*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420,
224*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .flags = DRM_MODE_FB_MODIFIERS,
225*4882a593Smuzhiyun .modifier = { AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE, 0 },
226*4882a593Smuzhiyun .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) },
227*4882a593Smuzhiyun }
228*4882a593Smuzhiyun },
229*4882a593Smuzhiyun { .buffer_created = 1, .name = "YVU420 Valid modifier",
230*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420,
231*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .flags = DRM_MODE_FB_MODIFIERS,
232*4882a593Smuzhiyun .modifier = { AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE },
233*4882a593Smuzhiyun .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) },
234*4882a593Smuzhiyun }
235*4882a593Smuzhiyun },
236*4882a593Smuzhiyun { .buffer_created = 0, .name = "YVU420 Different modifiers per plane",
237*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420,
238*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .flags = DRM_MODE_FB_MODIFIERS,
239*4882a593Smuzhiyun .modifier = { AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE | AFBC_FORMAT_MOD_YTR,
240*4882a593Smuzhiyun AFBC_FORMAT_MOD_SPARSE },
241*4882a593Smuzhiyun .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) },
242*4882a593Smuzhiyun }
243*4882a593Smuzhiyun },
244*4882a593Smuzhiyun { .buffer_created = 0, .name = "YVU420 Modifier for inexistent plane",
245*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_YVU420,
246*4882a593Smuzhiyun .handles = { 1, 1, 1 }, .flags = DRM_MODE_FB_MODIFIERS,
247*4882a593Smuzhiyun .modifier = { AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE,
248*4882a593Smuzhiyun AFBC_FORMAT_MOD_SPARSE },
249*4882a593Smuzhiyun .pitches = { MAX_WIDTH, DIV_ROUND_UP(MAX_WIDTH, 2), DIV_ROUND_UP(MAX_WIDTH, 2) },
250*4882a593Smuzhiyun }
251*4882a593Smuzhiyun },
252*4882a593Smuzhiyun { .buffer_created = 1, .name = "X0L2 Normal sizes",
253*4882a593Smuzhiyun .cmd = { .width = 600, .height = 600, .pixel_format = DRM_FORMAT_X0L2,
254*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 1200, 0, 0 }
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun },
257*4882a593Smuzhiyun { .buffer_created = 1, .name = "X0L2 Max sizes",
258*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2,
259*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 2 * MAX_WIDTH, 0, 0 }
260*4882a593Smuzhiyun }
261*4882a593Smuzhiyun },
262*4882a593Smuzhiyun { .buffer_created = 0, .name = "X0L2 Invalid pitch",
263*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2,
264*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 2 * MAX_WIDTH - 1, 0, 0 }
265*4882a593Smuzhiyun }
266*4882a593Smuzhiyun },
267*4882a593Smuzhiyun { .buffer_created = 1, .name = "X0L2 Pitch greater than minimum required",
268*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2,
269*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 2 * MAX_WIDTH + 1, 0, 0 }
270*4882a593Smuzhiyun }
271*4882a593Smuzhiyun },
272*4882a593Smuzhiyun { .buffer_created = 0, .name = "X0L2 Handle for inexistent plane",
273*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2,
274*4882a593Smuzhiyun .handles = { 1, 1, 0 }, .flags = DRM_MODE_FB_MODIFIERS,
275*4882a593Smuzhiyun .pitches = { 2 * MAX_WIDTH + 1, 0, 0 }
276*4882a593Smuzhiyun }
277*4882a593Smuzhiyun },
278*4882a593Smuzhiyun { .buffer_created = 1, .name = "X0L2 Offset for inexistent plane, without DRM_MODE_FB_MODIFIERS set",
279*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2,
280*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .offsets = { 0, 0, 3 },
281*4882a593Smuzhiyun .pitches = { 2 * MAX_WIDTH + 1, 0, 0 }
282*4882a593Smuzhiyun }
283*4882a593Smuzhiyun },
284*4882a593Smuzhiyun { .buffer_created = 0, .name = "X0L2 Modifier without DRM_MODE_FB_MODIFIERS set",
285*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2,
286*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 2 * MAX_WIDTH + 1, 0, 0 },
287*4882a593Smuzhiyun .modifier = { AFBC_FORMAT_MOD_SPARSE, 0, 0 },
288*4882a593Smuzhiyun }
289*4882a593Smuzhiyun },
290*4882a593Smuzhiyun { .buffer_created = 1, .name = "X0L2 Valid modifier",
291*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_X0L2,
292*4882a593Smuzhiyun .handles = { 1, 0, 0 }, .pitches = { 2 * MAX_WIDTH + 1, 0, 0 },
293*4882a593Smuzhiyun .modifier = { AFBC_FORMAT_MOD_SPARSE, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS,
294*4882a593Smuzhiyun }
295*4882a593Smuzhiyun },
296*4882a593Smuzhiyun { .buffer_created = 0, .name = "X0L2 Modifier for inexistent plane",
297*4882a593Smuzhiyun .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT,
298*4882a593Smuzhiyun .pixel_format = DRM_FORMAT_X0L2, .handles = { 1, 0, 0 },
299*4882a593Smuzhiyun .pitches = { 2 * MAX_WIDTH + 1, 0, 0 },
300*4882a593Smuzhiyun .modifier = { AFBC_FORMAT_MOD_SPARSE, AFBC_FORMAT_MOD_SPARSE, 0 },
301*4882a593Smuzhiyun .flags = DRM_MODE_FB_MODIFIERS,
302*4882a593Smuzhiyun }
303*4882a593Smuzhiyun },
304*4882a593Smuzhiyun };
305*4882a593Smuzhiyun
fb_create_mock(struct drm_device * dev,struct drm_file * file_priv,const struct drm_mode_fb_cmd2 * mode_cmd)306*4882a593Smuzhiyun static struct drm_framebuffer *fb_create_mock(struct drm_device *dev,
307*4882a593Smuzhiyun struct drm_file *file_priv,
308*4882a593Smuzhiyun const struct drm_mode_fb_cmd2 *mode_cmd)
309*4882a593Smuzhiyun {
310*4882a593Smuzhiyun int *buffer_created = dev->dev_private;
311*4882a593Smuzhiyun *buffer_created = 1;
312*4882a593Smuzhiyun return ERR_PTR(-EINVAL);
313*4882a593Smuzhiyun }
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun static struct drm_mode_config_funcs mock_config_funcs = {
316*4882a593Smuzhiyun .fb_create = fb_create_mock,
317*4882a593Smuzhiyun };
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun static struct drm_device mock_drm_device = {
320*4882a593Smuzhiyun .mode_config = {
321*4882a593Smuzhiyun .min_width = MIN_WIDTH,
322*4882a593Smuzhiyun .max_width = MAX_WIDTH,
323*4882a593Smuzhiyun .min_height = MIN_HEIGHT,
324*4882a593Smuzhiyun .max_height = MAX_HEIGHT,
325*4882a593Smuzhiyun .allow_fb_modifiers = true,
326*4882a593Smuzhiyun .funcs = &mock_config_funcs,
327*4882a593Smuzhiyun },
328*4882a593Smuzhiyun };
329*4882a593Smuzhiyun
execute_drm_mode_fb_cmd2(struct drm_mode_fb_cmd2 * r)330*4882a593Smuzhiyun static int execute_drm_mode_fb_cmd2(struct drm_mode_fb_cmd2 *r)
331*4882a593Smuzhiyun {
332*4882a593Smuzhiyun int buffer_created = 0;
333*4882a593Smuzhiyun struct drm_framebuffer *fb;
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun mock_drm_device.dev_private = &buffer_created;
336*4882a593Smuzhiyun fb = drm_internal_framebuffer_create(&mock_drm_device, r, NULL);
337*4882a593Smuzhiyun return buffer_created;
338*4882a593Smuzhiyun }
339*4882a593Smuzhiyun
igt_check_drm_framebuffer_create(void * ignored)340*4882a593Smuzhiyun int igt_check_drm_framebuffer_create(void *ignored)
341*4882a593Smuzhiyun {
342*4882a593Smuzhiyun int i = 0;
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(createbuffer_tests); i++) {
345*4882a593Smuzhiyun FAIL(createbuffer_tests[i].buffer_created !=
346*4882a593Smuzhiyun execute_drm_mode_fb_cmd2(&createbuffer_tests[i].cmd),
347*4882a593Smuzhiyun "Test %d: \"%s\" failed\n", i, createbuffer_tests[i].name);
348*4882a593Smuzhiyun }
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun return 0;
351*4882a593Smuzhiyun }
352