blob: 513b4b1175bb77fd8e1fc38aa2670f8aa94ffff8 [file] [log] [blame]
Eric Anholtc8b75bc2015-03-02 13:01:12 -08001/*
2 * Copyright (C) 2015 Broadcom
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9/**
10 * DOC: VC4 plane module
11 *
12 * Each DRM plane is a layer of pixels being scanned out by the HVS.
13 *
14 * At atomic modeset check time, we compute the HVS display element
15 * state that would be necessary for displaying the plane (giving us a
16 * chance to figure out if a plane configuration is invalid), then at
17 * atomic flush time the CRTC will ask us to write our element state
18 * into the region of the HVS that it has allocated for us.
19 */
20
Masahiro Yamadab7e8e252017-05-18 13:29:38 +090021#include <drm/drm_atomic.h>
22#include <drm/drm_atomic_helper.h>
23#include <drm/drm_fb_cma_helper.h>
24#include <drm/drm_plane_helper.h>
25
Boris Brezillonb9f19252017-10-19 14:57:48 +020026#include "uapi/drm/vc4_drm.h"
Eric Anholtc8b75bc2015-03-02 13:01:12 -080027#include "vc4_drv.h"
28#include "vc4_regs.h"
Eric Anholtc8b75bc2015-03-02 13:01:12 -080029
Eric Anholt21af94c2015-10-20 16:06:57 +010030enum vc4_scaling_mode {
31 VC4_SCALING_NONE,
32 VC4_SCALING_TPZ,
33 VC4_SCALING_PPF,
34};
35
Eric Anholtc8b75bc2015-03-02 13:01:12 -080036struct vc4_plane_state {
37 struct drm_plane_state base;
Eric Anholtf427fb12015-12-28 14:14:09 -080038 /* System memory copy of the display list for this element, computed
39 * at atomic_check time.
40 */
Eric Anholtc8b75bc2015-03-02 13:01:12 -080041 u32 *dlist;
Eric Anholtf427fb12015-12-28 14:14:09 -080042 u32 dlist_size; /* Number of dwords allocated for the display list */
Eric Anholtc8b75bc2015-03-02 13:01:12 -080043 u32 dlist_count; /* Number of used dwords in the display list. */
Eric Anholtb501bac2015-11-30 12:34:01 -080044
Eric Anholt6674a9042015-12-30 11:50:22 -080045 /* Offset in the dlist to various words, for pageflip or
46 * cursor updates.
47 */
48 u32 pos0_offset;
49 u32 pos2_offset;
50 u32 ptr0_offset;
Eric Anholtb501bac2015-11-30 12:34:01 -080051
52 /* Offset where the plane's dlist was last stored in the
Eric Anholtf427fb12015-12-28 14:14:09 -080053 * hardware at vc4_crtc_atomic_flush() time.
54 */
Eric Anholt17eac752015-12-28 14:14:57 -080055 u32 __iomem *hw_dlist;
Eric Anholt5c679992015-12-28 14:34:44 -080056
57 /* Clipped coordinates of the plane on the display. */
58 int crtc_x, crtc_y, crtc_w, crtc_h;
Eric Anholt21af94c2015-10-20 16:06:57 +010059 /* Clipped area being scanned from in the FB. */
Eric Anholtfc040232015-12-30 12:25:44 -080060 u32 src_x, src_y;
Eric Anholt21af94c2015-10-20 16:06:57 +010061
Eric Anholtfc040232015-12-30 12:25:44 -080062 u32 src_w[2], src_h[2];
63
64 /* Scaling selection for the RGB/Y plane and the Cb/Cr planes. */
65 enum vc4_scaling_mode x_scaling[2], y_scaling[2];
Eric Anholt21af94c2015-10-20 16:06:57 +010066 bool is_unity;
Eric Anholtfc040232015-12-30 12:25:44 -080067 bool is_yuv;
Eric Anholt5c679992015-12-28 14:34:44 -080068
69 /* Offset to start scanning out from the start of the plane's
70 * BO.
71 */
Eric Anholtfc040232015-12-30 12:25:44 -080072 u32 offsets[3];
Eric Anholt21af94c2015-10-20 16:06:57 +010073
74 /* Our allocation in LBM for temporary storage during scaling. */
75 struct drm_mm_node lbm;
Eric Anholtc8b75bc2015-03-02 13:01:12 -080076};
77
78static inline struct vc4_plane_state *
79to_vc4_plane_state(struct drm_plane_state *state)
80{
81 return (struct vc4_plane_state *)state;
82}
83
84static const struct hvs_format {
85 u32 drm; /* DRM_FORMAT_* */
86 u32 hvs; /* HVS_FORMAT_* */
87 u32 pixel_order;
88 bool has_alpha;
Eric Anholtfc040232015-12-30 12:25:44 -080089 bool flip_cbcr;
Eric Anholtc8b75bc2015-03-02 13:01:12 -080090} hvs_formats[] = {
91 {
92 .drm = DRM_FORMAT_XRGB8888, .hvs = HVS_PIXEL_FORMAT_RGBA8888,
93 .pixel_order = HVS_PIXEL_ORDER_ABGR, .has_alpha = false,
94 },
95 {
96 .drm = DRM_FORMAT_ARGB8888, .hvs = HVS_PIXEL_FORMAT_RGBA8888,
97 .pixel_order = HVS_PIXEL_ORDER_ABGR, .has_alpha = true,
98 },
Eric Anholtfe4cd842015-10-20 13:59:15 +010099 {
Rob Herring93977762016-06-09 16:19:25 -0500100 .drm = DRM_FORMAT_ABGR8888, .hvs = HVS_PIXEL_FORMAT_RGBA8888,
101 .pixel_order = HVS_PIXEL_ORDER_ARGB, .has_alpha = true,
102 },
103 {
104 .drm = DRM_FORMAT_XBGR8888, .hvs = HVS_PIXEL_FORMAT_RGBA8888,
105 .pixel_order = HVS_PIXEL_ORDER_ARGB, .has_alpha = false,
106 },
107 {
Eric Anholtfe4cd842015-10-20 13:59:15 +0100108 .drm = DRM_FORMAT_RGB565, .hvs = HVS_PIXEL_FORMAT_RGB565,
109 .pixel_order = HVS_PIXEL_ORDER_XRGB, .has_alpha = false,
110 },
111 {
112 .drm = DRM_FORMAT_BGR565, .hvs = HVS_PIXEL_FORMAT_RGB565,
113 .pixel_order = HVS_PIXEL_ORDER_XBGR, .has_alpha = false,
114 },
115 {
116 .drm = DRM_FORMAT_ARGB1555, .hvs = HVS_PIXEL_FORMAT_RGBA5551,
117 .pixel_order = HVS_PIXEL_ORDER_ABGR, .has_alpha = true,
118 },
119 {
120 .drm = DRM_FORMAT_XRGB1555, .hvs = HVS_PIXEL_FORMAT_RGBA5551,
121 .pixel_order = HVS_PIXEL_ORDER_ABGR, .has_alpha = false,
122 },
Eric Anholtfc040232015-12-30 12:25:44 -0800123 {
Dave Stevenson88f81562017-11-16 14:22:29 +0000124 .drm = DRM_FORMAT_RGB888, .hvs = HVS_PIXEL_FORMAT_RGB888,
125 .pixel_order = HVS_PIXEL_ORDER_XRGB, .has_alpha = false,
126 },
127 {
128 .drm = DRM_FORMAT_BGR888, .hvs = HVS_PIXEL_FORMAT_RGB888,
129 .pixel_order = HVS_PIXEL_ORDER_XBGR, .has_alpha = false,
130 },
131 {
Eric Anholtfc040232015-12-30 12:25:44 -0800132 .drm = DRM_FORMAT_YUV422,
133 .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV422_3PLANE,
134 },
135 {
136 .drm = DRM_FORMAT_YVU422,
137 .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV422_3PLANE,
138 .flip_cbcr = true,
139 },
140 {
141 .drm = DRM_FORMAT_YUV420,
142 .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV420_3PLANE,
143 },
144 {
145 .drm = DRM_FORMAT_YVU420,
146 .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV420_3PLANE,
147 .flip_cbcr = true,
148 },
149 {
150 .drm = DRM_FORMAT_NV12,
151 .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV420_2PLANE,
152 },
153 {
154 .drm = DRM_FORMAT_NV16,
155 .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV422_2PLANE,
156 },
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800157};
158
159static const struct hvs_format *vc4_get_hvs_format(u32 drm_format)
160{
161 unsigned i;
162
163 for (i = 0; i < ARRAY_SIZE(hvs_formats); i++) {
164 if (hvs_formats[i].drm == drm_format)
165 return &hvs_formats[i];
166 }
167
168 return NULL;
169}
170
Eric Anholt21af94c2015-10-20 16:06:57 +0100171static enum vc4_scaling_mode vc4_get_scaling_mode(u32 src, u32 dst)
172{
173 if (dst > src)
174 return VC4_SCALING_PPF;
175 else if (dst < src)
176 return VC4_SCALING_TPZ;
177 else
178 return VC4_SCALING_NONE;
179}
180
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800181static bool plane_enabled(struct drm_plane_state *state)
182{
183 return state->fb && state->crtc;
184}
185
kbuild test robot91276ae2015-10-22 11:12:26 +0800186static struct drm_plane_state *vc4_plane_duplicate_state(struct drm_plane *plane)
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800187{
188 struct vc4_plane_state *vc4_state;
189
190 if (WARN_ON(!plane->state))
191 return NULL;
192
193 vc4_state = kmemdup(plane->state, sizeof(*vc4_state), GFP_KERNEL);
194 if (!vc4_state)
195 return NULL;
196
Eric Anholt21af94c2015-10-20 16:06:57 +0100197 memset(&vc4_state->lbm, 0, sizeof(vc4_state->lbm));
198
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800199 __drm_atomic_helper_plane_duplicate_state(plane, &vc4_state->base);
200
201 if (vc4_state->dlist) {
202 vc4_state->dlist = kmemdup(vc4_state->dlist,
203 vc4_state->dlist_count * 4,
204 GFP_KERNEL);
205 if (!vc4_state->dlist) {
206 kfree(vc4_state);
207 return NULL;
208 }
209 vc4_state->dlist_size = vc4_state->dlist_count;
210 }
211
212 return &vc4_state->base;
213}
214
kbuild test robot91276ae2015-10-22 11:12:26 +0800215static void vc4_plane_destroy_state(struct drm_plane *plane,
216 struct drm_plane_state *state)
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800217{
Eric Anholt21af94c2015-10-20 16:06:57 +0100218 struct vc4_dev *vc4 = to_vc4_dev(plane->dev);
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800219 struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
220
Eric Anholt21af94c2015-10-20 16:06:57 +0100221 if (vc4_state->lbm.allocated) {
222 unsigned long irqflags;
223
224 spin_lock_irqsave(&vc4->hvs->mm_lock, irqflags);
225 drm_mm_remove_node(&vc4_state->lbm);
226 spin_unlock_irqrestore(&vc4->hvs->mm_lock, irqflags);
227 }
228
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800229 kfree(vc4_state->dlist);
Daniel Vetter2f701692016-05-09 16:34:10 +0200230 __drm_atomic_helper_plane_destroy_state(&vc4_state->base);
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800231 kfree(state);
232}
233
234/* Called during init to allocate the plane's atomic state. */
kbuild test robot91276ae2015-10-22 11:12:26 +0800235static void vc4_plane_reset(struct drm_plane *plane)
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800236{
237 struct vc4_plane_state *vc4_state;
238
239 WARN_ON(plane->state);
240
241 vc4_state = kzalloc(sizeof(*vc4_state), GFP_KERNEL);
242 if (!vc4_state)
243 return;
244
245 plane->state = &vc4_state->base;
246 vc4_state->base.plane = plane;
247}
248
249static void vc4_dlist_write(struct vc4_plane_state *vc4_state, u32 val)
250{
251 if (vc4_state->dlist_count == vc4_state->dlist_size) {
252 u32 new_size = max(4u, vc4_state->dlist_count * 2);
253 u32 *new_dlist = kmalloc(new_size * 4, GFP_KERNEL);
254
255 if (!new_dlist)
256 return;
257 memcpy(new_dlist, vc4_state->dlist, vc4_state->dlist_count * 4);
258
259 kfree(vc4_state->dlist);
260 vc4_state->dlist = new_dlist;
261 vc4_state->dlist_size = new_size;
262 }
263
264 vc4_state->dlist[vc4_state->dlist_count++] = val;
265}
266
Eric Anholt21af94c2015-10-20 16:06:57 +0100267/* Returns the scl0/scl1 field based on whether the dimensions need to
268 * be up/down/non-scaled.
269 *
270 * This is a replication of a table from the spec.
271 */
Eric Anholtfc040232015-12-30 12:25:44 -0800272static u32 vc4_get_scl_field(struct drm_plane_state *state, int plane)
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800273{
274 struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
Eric Anholt21af94c2015-10-20 16:06:57 +0100275
Eric Anholtfc040232015-12-30 12:25:44 -0800276 switch (vc4_state->x_scaling[plane] << 2 | vc4_state->y_scaling[plane]) {
Eric Anholt21af94c2015-10-20 16:06:57 +0100277 case VC4_SCALING_PPF << 2 | VC4_SCALING_PPF:
278 return SCALER_CTL0_SCL_H_PPF_V_PPF;
279 case VC4_SCALING_TPZ << 2 | VC4_SCALING_PPF:
280 return SCALER_CTL0_SCL_H_TPZ_V_PPF;
281 case VC4_SCALING_PPF << 2 | VC4_SCALING_TPZ:
282 return SCALER_CTL0_SCL_H_PPF_V_TPZ;
283 case VC4_SCALING_TPZ << 2 | VC4_SCALING_TPZ:
284 return SCALER_CTL0_SCL_H_TPZ_V_TPZ;
285 case VC4_SCALING_PPF << 2 | VC4_SCALING_NONE:
286 return SCALER_CTL0_SCL_H_PPF_V_NONE;
287 case VC4_SCALING_NONE << 2 | VC4_SCALING_PPF:
288 return SCALER_CTL0_SCL_H_NONE_V_PPF;
289 case VC4_SCALING_NONE << 2 | VC4_SCALING_TPZ:
290 return SCALER_CTL0_SCL_H_NONE_V_TPZ;
291 case VC4_SCALING_TPZ << 2 | VC4_SCALING_NONE:
292 return SCALER_CTL0_SCL_H_TPZ_V_NONE;
293 default:
294 case VC4_SCALING_NONE << 2 | VC4_SCALING_NONE:
295 /* The unity case is independently handled by
296 * SCALER_CTL0_UNITY.
297 */
298 return 0;
299 }
300}
301
302static int vc4_plane_setup_clipping_and_scaling(struct drm_plane_state *state)
303{
304 struct drm_plane *plane = state->plane;
305 struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800306 struct drm_framebuffer *fb = state->fb;
Eric Anholtfc040232015-12-30 12:25:44 -0800307 struct drm_gem_cma_object *bo = drm_fb_cma_get_gem_obj(fb, 0);
Eric Anholt21af94c2015-10-20 16:06:57 +0100308 u32 subpixel_src_mask = (1 << 16) - 1;
Ville Syrjälä438b74a2016-12-14 23:32:55 +0200309 u32 format = fb->format->format;
Ville Syrjäläbcb0b462016-12-14 23:30:22 +0200310 int num_planes = fb->format->num_planes;
Eric Anholtfc040232015-12-30 12:25:44 -0800311 u32 h_subsample = 1;
312 u32 v_subsample = 1;
313 int i;
Eric Anholt5c679992015-12-28 14:34:44 -0800314
Eric Anholtfc040232015-12-30 12:25:44 -0800315 for (i = 0; i < num_planes; i++)
316 vc4_state->offsets[i] = bo->paddr + fb->offsets[i];
Eric Anholt5c679992015-12-28 14:34:44 -0800317
Eric Anholt21af94c2015-10-20 16:06:57 +0100318 /* We don't support subpixel source positioning for scaling. */
319 if ((state->src_x & subpixel_src_mask) ||
320 (state->src_y & subpixel_src_mask) ||
321 (state->src_w & subpixel_src_mask) ||
322 (state->src_h & subpixel_src_mask)) {
Eric Anholtbf893ac2015-10-23 10:36:27 +0100323 return -EINVAL;
324 }
325
Eric Anholt21af94c2015-10-20 16:06:57 +0100326 vc4_state->src_x = state->src_x >> 16;
327 vc4_state->src_y = state->src_y >> 16;
Eric Anholtfc040232015-12-30 12:25:44 -0800328 vc4_state->src_w[0] = state->src_w >> 16;
329 vc4_state->src_h[0] = state->src_h >> 16;
Eric Anholtf863e352015-12-28 14:45:25 -0800330
331 vc4_state->crtc_x = state->crtc_x;
332 vc4_state->crtc_y = state->crtc_y;
333 vc4_state->crtc_w = state->crtc_w;
334 vc4_state->crtc_h = state->crtc_h;
335
Eric Anholtfc040232015-12-30 12:25:44 -0800336 vc4_state->x_scaling[0] = vc4_get_scaling_mode(vc4_state->src_w[0],
337 vc4_state->crtc_w);
338 vc4_state->y_scaling[0] = vc4_get_scaling_mode(vc4_state->src_h[0],
339 vc4_state->crtc_h);
340
341 if (num_planes > 1) {
342 vc4_state->is_yuv = true;
343
344 h_subsample = drm_format_horz_chroma_subsampling(format);
345 v_subsample = drm_format_vert_chroma_subsampling(format);
346 vc4_state->src_w[1] = vc4_state->src_w[0] / h_subsample;
347 vc4_state->src_h[1] = vc4_state->src_h[0] / v_subsample;
348
349 vc4_state->x_scaling[1] =
350 vc4_get_scaling_mode(vc4_state->src_w[1],
351 vc4_state->crtc_w);
352 vc4_state->y_scaling[1] =
353 vc4_get_scaling_mode(vc4_state->src_h[1],
354 vc4_state->crtc_h);
355
356 /* YUV conversion requires that scaling be enabled,
357 * even on a plane that's otherwise 1:1. Choose TPZ
358 * for simplicity.
359 */
360 if (vc4_state->x_scaling[0] == VC4_SCALING_NONE)
361 vc4_state->x_scaling[0] = VC4_SCALING_TPZ;
362 if (vc4_state->y_scaling[0] == VC4_SCALING_NONE)
363 vc4_state->y_scaling[0] = VC4_SCALING_TPZ;
364 }
365
366 vc4_state->is_unity = (vc4_state->x_scaling[0] == VC4_SCALING_NONE &&
367 vc4_state->y_scaling[0] == VC4_SCALING_NONE &&
368 vc4_state->x_scaling[1] == VC4_SCALING_NONE &&
369 vc4_state->y_scaling[1] == VC4_SCALING_NONE);
Eric Anholt21af94c2015-10-20 16:06:57 +0100370
371 /* No configuring scaling on the cursor plane, since it gets
372 non-vblank-synced updates, and scaling requires requires
373 LBM changes which have to be vblank-synced.
374 */
375 if (plane->type == DRM_PLANE_TYPE_CURSOR && !vc4_state->is_unity)
376 return -EINVAL;
377
378 /* Clamp the on-screen start x/y to 0. The hardware doesn't
379 * support negative y, and negative x wastes bandwidth.
380 */
Eric Anholt5c679992015-12-28 14:34:44 -0800381 if (vc4_state->crtc_x < 0) {
Eric Anholtfc040232015-12-30 12:25:44 -0800382 for (i = 0; i < num_planes; i++) {
Ville Syrjälä353c8592016-12-14 23:30:57 +0200383 u32 cpp = fb->format->cpp[i];
Eric Anholtfc040232015-12-30 12:25:44 -0800384 u32 subs = ((i == 0) ? 1 : h_subsample);
385
386 vc4_state->offsets[i] += (cpp *
387 (-vc4_state->crtc_x) / subs);
388 }
389 vc4_state->src_w[0] += vc4_state->crtc_x;
390 vc4_state->src_w[1] += vc4_state->crtc_x / h_subsample;
Eric Anholt5c679992015-12-28 14:34:44 -0800391 vc4_state->crtc_x = 0;
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800392 }
393
Eric Anholt5c679992015-12-28 14:34:44 -0800394 if (vc4_state->crtc_y < 0) {
Eric Anholtfc040232015-12-30 12:25:44 -0800395 for (i = 0; i < num_planes; i++) {
396 u32 subs = ((i == 0) ? 1 : v_subsample);
397
398 vc4_state->offsets[i] += (fb->pitches[i] *
399 (-vc4_state->crtc_y) / subs);
400 }
401 vc4_state->src_h[0] += vc4_state->crtc_y;
402 vc4_state->src_h[1] += vc4_state->crtc_y / v_subsample;
Eric Anholt5c679992015-12-28 14:34:44 -0800403 vc4_state->crtc_y = 0;
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800404 }
405
Eric Anholt5c679992015-12-28 14:34:44 -0800406 return 0;
407}
408
Eric Anholt21af94c2015-10-20 16:06:57 +0100409static void vc4_write_tpz(struct vc4_plane_state *vc4_state, u32 src, u32 dst)
410{
411 u32 scale, recip;
412
413 scale = (1 << 16) * src / dst;
414
415 /* The specs note that while the reciprocal would be defined
416 * as (1<<32)/scale, ~0 is close enough.
417 */
418 recip = ~0 / scale;
419
420 vc4_dlist_write(vc4_state,
421 VC4_SET_FIELD(scale, SCALER_TPZ0_SCALE) |
422 VC4_SET_FIELD(0, SCALER_TPZ0_IPHASE));
423 vc4_dlist_write(vc4_state,
424 VC4_SET_FIELD(recip, SCALER_TPZ1_RECIP));
425}
426
427static void vc4_write_ppf(struct vc4_plane_state *vc4_state, u32 src, u32 dst)
428{
429 u32 scale = (1 << 16) * src / dst;
430
431 vc4_dlist_write(vc4_state,
432 SCALER_PPF_AGC |
433 VC4_SET_FIELD(scale, SCALER_PPF_SCALE) |
434 VC4_SET_FIELD(0, SCALER_PPF_IPHASE));
435}
436
437static u32 vc4_lbm_size(struct drm_plane_state *state)
438{
439 struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
440 /* This is the worst case number. One of the two sizes will
441 * be used depending on the scaling configuration.
442 */
Eric Anholtfc040232015-12-30 12:25:44 -0800443 u32 pix_per_line = max(vc4_state->src_w[0], (u32)vc4_state->crtc_w);
Eric Anholt21af94c2015-10-20 16:06:57 +0100444 u32 lbm;
445
Eric Anholtfc040232015-12-30 12:25:44 -0800446 if (!vc4_state->is_yuv) {
447 if (vc4_state->is_unity)
448 return 0;
449 else if (vc4_state->y_scaling[0] == VC4_SCALING_TPZ)
450 lbm = pix_per_line * 8;
451 else {
452 /* In special cases, this multiplier might be 12. */
453 lbm = pix_per_line * 16;
454 }
455 } else {
456 /* There are cases for this going down to a multiplier
457 * of 2, but according to the firmware source, the
458 * table in the docs is somewhat wrong.
459 */
Eric Anholt21af94c2015-10-20 16:06:57 +0100460 lbm = pix_per_line * 16;
461 }
462
463 lbm = roundup(lbm, 32);
464
465 return lbm;
466}
467
Eric Anholtfc040232015-12-30 12:25:44 -0800468static void vc4_write_scaling_parameters(struct drm_plane_state *state,
469 int channel)
Eric Anholt21af94c2015-10-20 16:06:57 +0100470{
471 struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
472
473 /* Ch0 H-PPF Word 0: Scaling Parameters */
Eric Anholtfc040232015-12-30 12:25:44 -0800474 if (vc4_state->x_scaling[channel] == VC4_SCALING_PPF) {
Eric Anholt21af94c2015-10-20 16:06:57 +0100475 vc4_write_ppf(vc4_state,
Eric Anholtfc040232015-12-30 12:25:44 -0800476 vc4_state->src_w[channel], vc4_state->crtc_w);
Eric Anholt21af94c2015-10-20 16:06:57 +0100477 }
478
479 /* Ch0 V-PPF Words 0-1: Scaling Parameters, Context */
Eric Anholtfc040232015-12-30 12:25:44 -0800480 if (vc4_state->y_scaling[channel] == VC4_SCALING_PPF) {
Eric Anholt21af94c2015-10-20 16:06:57 +0100481 vc4_write_ppf(vc4_state,
Eric Anholtfc040232015-12-30 12:25:44 -0800482 vc4_state->src_h[channel], vc4_state->crtc_h);
Eric Anholt21af94c2015-10-20 16:06:57 +0100483 vc4_dlist_write(vc4_state, 0xc0c0c0c0);
484 }
485
486 /* Ch0 H-TPZ Words 0-1: Scaling Parameters, Recip */
Eric Anholtfc040232015-12-30 12:25:44 -0800487 if (vc4_state->x_scaling[channel] == VC4_SCALING_TPZ) {
Eric Anholt21af94c2015-10-20 16:06:57 +0100488 vc4_write_tpz(vc4_state,
Eric Anholtfc040232015-12-30 12:25:44 -0800489 vc4_state->src_w[channel], vc4_state->crtc_w);
Eric Anholt21af94c2015-10-20 16:06:57 +0100490 }
491
492 /* Ch0 V-TPZ Words 0-2: Scaling Parameters, Recip, Context */
Eric Anholtfc040232015-12-30 12:25:44 -0800493 if (vc4_state->y_scaling[channel] == VC4_SCALING_TPZ) {
Eric Anholt21af94c2015-10-20 16:06:57 +0100494 vc4_write_tpz(vc4_state,
Eric Anholtfc040232015-12-30 12:25:44 -0800495 vc4_state->src_h[channel], vc4_state->crtc_h);
Eric Anholt21af94c2015-10-20 16:06:57 +0100496 vc4_dlist_write(vc4_state, 0xc0c0c0c0);
497 }
498}
Eric Anholt5c679992015-12-28 14:34:44 -0800499
500/* Writes out a full display list for an active plane to the plane's
501 * private dlist state.
502 */
503static int vc4_plane_mode_set(struct drm_plane *plane,
504 struct drm_plane_state *state)
505{
Eric Anholt21af94c2015-10-20 16:06:57 +0100506 struct vc4_dev *vc4 = to_vc4_dev(plane->dev);
Eric Anholt5c679992015-12-28 14:34:44 -0800507 struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
508 struct drm_framebuffer *fb = state->fb;
Eric Anholt5c679992015-12-28 14:34:44 -0800509 u32 ctl0_offset = vc4_state->dlist_count;
Ville Syrjälä438b74a2016-12-14 23:32:55 +0200510 const struct hvs_format *format = vc4_get_hvs_format(fb->format->format);
Eric Anholtfc040232015-12-30 12:25:44 -0800511 int num_planes = drm_format_num_planes(format->drm);
Eric Anholt98830d912017-06-07 17:13:35 -0700512 u32 scl0, scl1, pitch0;
513 u32 lbm_size, tiling;
Eric Anholt21af94c2015-10-20 16:06:57 +0100514 unsigned long irqflags;
Eric Anholtfc040232015-12-30 12:25:44 -0800515 int ret, i;
Eric Anholt5c679992015-12-28 14:34:44 -0800516
517 ret = vc4_plane_setup_clipping_and_scaling(state);
518 if (ret)
519 return ret;
520
Eric Anholt21af94c2015-10-20 16:06:57 +0100521 /* Allocate the LBM memory that the HVS will use for temporary
522 * storage due to our scaling/format conversion.
523 */
524 lbm_size = vc4_lbm_size(state);
525 if (lbm_size) {
526 if (!vc4_state->lbm.allocated) {
527 spin_lock_irqsave(&vc4->hvs->mm_lock, irqflags);
Chris Wilson4e64e552017-02-02 21:04:38 +0000528 ret = drm_mm_insert_node_generic(&vc4->hvs->lbm_mm,
529 &vc4_state->lbm,
530 lbm_size, 32, 0, 0);
Eric Anholt21af94c2015-10-20 16:06:57 +0100531 spin_unlock_irqrestore(&vc4->hvs->mm_lock, irqflags);
532 } else {
533 WARN_ON_ONCE(lbm_size != vc4_state->lbm.size);
534 }
535 }
536
537 if (ret)
538 return ret;
539
Eric Anholtfc040232015-12-30 12:25:44 -0800540 /* SCL1 is used for Cb/Cr scaling of planar formats. For RGB
541 * and 4:4:4, scl1 should be set to scl0 so both channels of
542 * the scaler do the same thing. For YUV, the Y plane needs
543 * to be put in channel 1 and Cb/Cr in channel 0, so we swap
544 * the scl fields here.
545 */
546 if (num_planes == 1) {
547 scl0 = vc4_get_scl_field(state, 1);
548 scl1 = scl0;
549 } else {
550 scl0 = vc4_get_scl_field(state, 1);
551 scl1 = vc4_get_scl_field(state, 0);
552 }
Eric Anholt21af94c2015-10-20 16:06:57 +0100553
Eric Anholt98830d912017-06-07 17:13:35 -0700554 switch (fb->modifier) {
555 case DRM_FORMAT_MOD_LINEAR:
556 tiling = SCALER_CTL0_TILING_LINEAR;
557 pitch0 = VC4_SET_FIELD(fb->pitches[0], SCALER_SRC_PITCH);
558 break;
Eric Anholt652badb2017-09-27 12:32:09 -0700559
560 case DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED: {
561 /* For T-tiled, the FB pitch is "how many bytes from
562 * one row to the next, such that pitch * tile_h ==
563 * tile_size * tiles_per_row."
564 */
565 u32 tile_size_shift = 12; /* T tiles are 4kb */
566 u32 tile_h_shift = 5; /* 16 and 32bpp are 32 pixels high */
567 u32 tiles_w = fb->pitches[0] >> (tile_size_shift - tile_h_shift);
568
Eric Anholt98830d912017-06-07 17:13:35 -0700569 tiling = SCALER_CTL0_TILING_256B_OR_T;
570
Eric Anholt652badb2017-09-27 12:32:09 -0700571 pitch0 = (VC4_SET_FIELD(0, SCALER_PITCH0_TILE_Y_OFFSET) |
572 VC4_SET_FIELD(0, SCALER_PITCH0_TILE_WIDTH_L) |
573 VC4_SET_FIELD(tiles_w, SCALER_PITCH0_TILE_WIDTH_R));
Eric Anholt98830d912017-06-07 17:13:35 -0700574 break;
Eric Anholt652badb2017-09-27 12:32:09 -0700575 }
576
Eric Anholt98830d912017-06-07 17:13:35 -0700577 default:
578 DRM_DEBUG_KMS("Unsupported FB tiling flag 0x%16llx",
579 (long long)fb->modifier);
580 return -EINVAL;
581 }
582
Eric Anholt21af94c2015-10-20 16:06:57 +0100583 /* Control word */
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800584 vc4_dlist_write(vc4_state,
585 SCALER_CTL0_VALID |
586 (format->pixel_order << SCALER_CTL0_ORDER_SHIFT) |
587 (format->hvs << SCALER_CTL0_PIXEL_FORMAT_SHIFT) |
Eric Anholt98830d912017-06-07 17:13:35 -0700588 VC4_SET_FIELD(tiling, SCALER_CTL0_TILING) |
Eric Anholt21af94c2015-10-20 16:06:57 +0100589 (vc4_state->is_unity ? SCALER_CTL0_UNITY : 0) |
Eric Anholtfc040232015-12-30 12:25:44 -0800590 VC4_SET_FIELD(scl0, SCALER_CTL0_SCL0) |
591 VC4_SET_FIELD(scl1, SCALER_CTL0_SCL1));
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800592
593 /* Position Word 0: Image Positions and Alpha Value */
Eric Anholt6674a9042015-12-30 11:50:22 -0800594 vc4_state->pos0_offset = vc4_state->dlist_count;
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800595 vc4_dlist_write(vc4_state,
596 VC4_SET_FIELD(0xff, SCALER_POS0_FIXED_ALPHA) |
Eric Anholt5c679992015-12-28 14:34:44 -0800597 VC4_SET_FIELD(vc4_state->crtc_x, SCALER_POS0_START_X) |
598 VC4_SET_FIELD(vc4_state->crtc_y, SCALER_POS0_START_Y));
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800599
Eric Anholt21af94c2015-10-20 16:06:57 +0100600 /* Position Word 1: Scaled Image Dimensions. */
601 if (!vc4_state->is_unity) {
602 vc4_dlist_write(vc4_state,
603 VC4_SET_FIELD(vc4_state->crtc_w,
604 SCALER_POS1_SCL_WIDTH) |
605 VC4_SET_FIELD(vc4_state->crtc_h,
606 SCALER_POS1_SCL_HEIGHT));
607 }
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800608
609 /* Position Word 2: Source Image Size, Alpha Mode */
Eric Anholt6674a9042015-12-30 11:50:22 -0800610 vc4_state->pos2_offset = vc4_state->dlist_count;
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800611 vc4_dlist_write(vc4_state,
612 VC4_SET_FIELD(format->has_alpha ?
613 SCALER_POS2_ALPHA_MODE_PIPELINE :
614 SCALER_POS2_ALPHA_MODE_FIXED,
615 SCALER_POS2_ALPHA_MODE) |
Eric Anholtfc040232015-12-30 12:25:44 -0800616 VC4_SET_FIELD(vc4_state->src_w[0], SCALER_POS2_WIDTH) |
617 VC4_SET_FIELD(vc4_state->src_h[0], SCALER_POS2_HEIGHT));
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800618
619 /* Position Word 3: Context. Written by the HVS. */
620 vc4_dlist_write(vc4_state, 0xc0c0c0c0);
621
Eric Anholtfc040232015-12-30 12:25:44 -0800622
623 /* Pointer Word 0/1/2: RGB / Y / Cb / Cr Pointers
624 *
625 * The pointers may be any byte address.
626 */
Eric Anholt6674a9042015-12-30 11:50:22 -0800627 vc4_state->ptr0_offset = vc4_state->dlist_count;
Eric Anholtfc040232015-12-30 12:25:44 -0800628 if (!format->flip_cbcr) {
629 for (i = 0; i < num_planes; i++)
630 vc4_dlist_write(vc4_state, vc4_state->offsets[i]);
631 } else {
632 WARN_ON_ONCE(num_planes != 3);
633 vc4_dlist_write(vc4_state, vc4_state->offsets[0]);
634 vc4_dlist_write(vc4_state, vc4_state->offsets[2]);
635 vc4_dlist_write(vc4_state, vc4_state->offsets[1]);
636 }
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800637
Eric Anholtfc040232015-12-30 12:25:44 -0800638 /* Pointer Context Word 0/1/2: Written by the HVS */
639 for (i = 0; i < num_planes; i++)
640 vc4_dlist_write(vc4_state, 0xc0c0c0c0);
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800641
Eric Anholt98830d912017-06-07 17:13:35 -0700642 /* Pitch word 0 */
643 vc4_dlist_write(vc4_state, pitch0);
644
645 /* Pitch word 1/2 */
646 for (i = 1; i < num_planes; i++) {
Eric Anholtfc040232015-12-30 12:25:44 -0800647 vc4_dlist_write(vc4_state,
648 VC4_SET_FIELD(fb->pitches[i], SCALER_SRC_PITCH));
649 }
650
651 /* Colorspace conversion words */
652 if (vc4_state->is_yuv) {
653 vc4_dlist_write(vc4_state, SCALER_CSC0_ITR_R_601_5);
654 vc4_dlist_write(vc4_state, SCALER_CSC1_ITR_R_601_5);
655 vc4_dlist_write(vc4_state, SCALER_CSC2_ITR_R_601_5);
656 }
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800657
Eric Anholt21af94c2015-10-20 16:06:57 +0100658 if (!vc4_state->is_unity) {
659 /* LBM Base Address. */
Eric Anholtfc040232015-12-30 12:25:44 -0800660 if (vc4_state->y_scaling[0] != VC4_SCALING_NONE ||
661 vc4_state->y_scaling[1] != VC4_SCALING_NONE) {
Eric Anholt21af94c2015-10-20 16:06:57 +0100662 vc4_dlist_write(vc4_state, vc4_state->lbm.start);
Eric Anholtfc040232015-12-30 12:25:44 -0800663 }
Eric Anholt21af94c2015-10-20 16:06:57 +0100664
Eric Anholtfc040232015-12-30 12:25:44 -0800665 if (num_planes > 1) {
666 /* Emit Cb/Cr as channel 0 and Y as channel
667 * 1. This matches how we set up scl0/scl1
668 * above.
669 */
670 vc4_write_scaling_parameters(state, 1);
671 }
672 vc4_write_scaling_parameters(state, 0);
Eric Anholt21af94c2015-10-20 16:06:57 +0100673
674 /* If any PPF setup was done, then all the kernel
675 * pointers get uploaded.
676 */
Eric Anholtfc040232015-12-30 12:25:44 -0800677 if (vc4_state->x_scaling[0] == VC4_SCALING_PPF ||
678 vc4_state->y_scaling[0] == VC4_SCALING_PPF ||
679 vc4_state->x_scaling[1] == VC4_SCALING_PPF ||
680 vc4_state->y_scaling[1] == VC4_SCALING_PPF) {
Eric Anholt21af94c2015-10-20 16:06:57 +0100681 u32 kernel = VC4_SET_FIELD(vc4->hvs->mitchell_netravali_filter.start,
682 SCALER_PPF_KERNEL_OFFSET);
683
684 /* HPPF plane 0 */
685 vc4_dlist_write(vc4_state, kernel);
686 /* VPPF plane 0 */
687 vc4_dlist_write(vc4_state, kernel);
688 /* HPPF plane 1 */
689 vc4_dlist_write(vc4_state, kernel);
690 /* VPPF plane 1 */
691 vc4_dlist_write(vc4_state, kernel);
692 }
693 }
694
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800695 vc4_state->dlist[ctl0_offset] |=
696 VC4_SET_FIELD(vc4_state->dlist_count, SCALER_CTL0_SIZE);
697
698 return 0;
699}
700
701/* If a modeset involves changing the setup of a plane, the atomic
702 * infrastructure will call this to validate a proposed plane setup.
703 * However, if a plane isn't getting updated, this (and the
704 * corresponding vc4_plane_atomic_update) won't get called. Thus, we
705 * compute the dlist here and have all active plane dlists get updated
706 * in the CRTC's flush.
707 */
708static int vc4_plane_atomic_check(struct drm_plane *plane,
709 struct drm_plane_state *state)
710{
711 struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
712
713 vc4_state->dlist_count = 0;
714
715 if (plane_enabled(state))
716 return vc4_plane_mode_set(plane, state);
717 else
718 return 0;
719}
720
721static void vc4_plane_atomic_update(struct drm_plane *plane,
722 struct drm_plane_state *old_state)
723{
724 /* No contents here. Since we don't know where in the CRTC's
725 * dlist we should be stored, our dlist is uploaded to the
726 * hardware with vc4_plane_write_dlist() at CRTC atomic_flush
727 * time.
728 */
729}
730
731u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist)
732{
733 struct vc4_plane_state *vc4_state = to_vc4_plane_state(plane->state);
734 int i;
735
Eric Anholtb501bac2015-11-30 12:34:01 -0800736 vc4_state->hw_dlist = dlist;
737
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800738 /* Can't memcpy_toio() because it needs to be 32-bit writes. */
739 for (i = 0; i < vc4_state->dlist_count; i++)
740 writel(vc4_state->dlist[i], &dlist[i]);
741
742 return vc4_state->dlist_count;
743}
744
Daniel Vetter2f196b72016-06-02 16:21:44 +0200745u32 vc4_plane_dlist_size(const struct drm_plane_state *state)
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800746{
Daniel Vetter2f196b72016-06-02 16:21:44 +0200747 const struct vc4_plane_state *vc4_state =
748 container_of(state, typeof(*vc4_state), base);
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800749
750 return vc4_state->dlist_count;
751}
752
Eric Anholtb501bac2015-11-30 12:34:01 -0800753/* Updates the plane to immediately (well, once the FIFO needs
754 * refilling) scan out from at a new framebuffer.
755 */
756void vc4_plane_async_set_fb(struct drm_plane *plane, struct drm_framebuffer *fb)
757{
758 struct vc4_plane_state *vc4_state = to_vc4_plane_state(plane->state);
759 struct drm_gem_cma_object *bo = drm_fb_cma_get_gem_obj(fb, 0);
760 uint32_t addr;
761
762 /* We're skipping the address adjustment for negative origin,
763 * because this is only called on the primary plane.
764 */
765 WARN_ON_ONCE(plane->state->crtc_x < 0 || plane->state->crtc_y < 0);
766 addr = bo->paddr + fb->offsets[0];
767
768 /* Write the new address into the hardware immediately. The
769 * scanout will start from this address as soon as the FIFO
770 * needs to refill with pixels.
771 */
Eric Anholt6674a9042015-12-30 11:50:22 -0800772 writel(addr, &vc4_state->hw_dlist[vc4_state->ptr0_offset]);
Eric Anholtb501bac2015-11-30 12:34:01 -0800773
774 /* Also update the CPU-side dlist copy, so that any later
775 * atomic updates that don't do a new modeset on our plane
776 * also use our updated address.
777 */
Eric Anholt6674a9042015-12-30 11:50:22 -0800778 vc4_state->dlist[vc4_state->ptr0_offset] = addr;
Eric Anholtb501bac2015-11-30 12:34:01 -0800779}
780
Eric Anholt334dbd62017-06-21 11:49:59 -0700781static int vc4_prepare_fb(struct drm_plane *plane,
782 struct drm_plane_state *state)
783{
784 struct vc4_bo *bo;
785 struct dma_fence *fence;
Boris Brezillonb9f19252017-10-19 14:57:48 +0200786 int ret;
Eric Anholt334dbd62017-06-21 11:49:59 -0700787
788 if ((plane->state->fb == state->fb) || !state->fb)
789 return 0;
790
791 bo = to_vc4_bo(&drm_fb_cma_get_gem_obj(state->fb, 0)->base);
Boris Brezillonb9f19252017-10-19 14:57:48 +0200792
793 ret = vc4_bo_inc_usecnt(bo);
794 if (ret)
795 return ret;
796
Eric Anholt334dbd62017-06-21 11:49:59 -0700797 fence = reservation_object_get_excl_rcu(bo->resv);
798 drm_atomic_set_fence_for_plane(state, fence);
799
800 return 0;
801}
802
Boris Brezillonb9f19252017-10-19 14:57:48 +0200803static void vc4_cleanup_fb(struct drm_plane *plane,
804 struct drm_plane_state *state)
805{
806 struct vc4_bo *bo;
807
808 if (plane->state->fb == state->fb || !state->fb)
809 return;
810
811 bo = to_vc4_bo(&drm_fb_cma_get_gem_obj(state->fb, 0)->base);
812 vc4_bo_dec_usecnt(bo);
813}
814
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800815static const struct drm_plane_helper_funcs vc4_plane_helper_funcs = {
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800816 .atomic_check = vc4_plane_atomic_check,
817 .atomic_update = vc4_plane_atomic_update,
Eric Anholt334dbd62017-06-21 11:49:59 -0700818 .prepare_fb = vc4_prepare_fb,
Boris Brezillonb9f19252017-10-19 14:57:48 +0200819 .cleanup_fb = vc4_cleanup_fb,
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800820};
821
822static void vc4_plane_destroy(struct drm_plane *plane)
823{
824 drm_plane_helper_disable(plane);
825 drm_plane_cleanup(plane);
826}
827
Eric Anholt6674a9042015-12-30 11:50:22 -0800828/* Implements immediate (non-vblank-synced) updates of the cursor
829 * position, or falls back to the atomic helper otherwise.
830 */
831static int
832vc4_update_plane(struct drm_plane *plane,
833 struct drm_crtc *crtc,
834 struct drm_framebuffer *fb,
835 int crtc_x, int crtc_y,
836 unsigned int crtc_w, unsigned int crtc_h,
837 uint32_t src_x, uint32_t src_y,
Daniel Vetter34a2ab52017-03-22 22:50:41 +0100838 uint32_t src_w, uint32_t src_h,
839 struct drm_modeset_acquire_ctx *ctx)
Eric Anholt6674a9042015-12-30 11:50:22 -0800840{
841 struct drm_plane_state *plane_state;
842 struct vc4_plane_state *vc4_state;
843
844 if (plane != crtc->cursor)
845 goto out;
846
847 plane_state = plane->state;
848 vc4_state = to_vc4_plane_state(plane_state);
849
850 if (!plane_state)
851 goto out;
852
Eric Anholt6674a9042015-12-30 11:50:22 -0800853 /* No configuring new scaling in the fast path. */
854 if (crtc_w != plane_state->crtc_w ||
855 crtc_h != plane_state->crtc_h ||
856 src_w != plane_state->src_w ||
857 src_h != plane_state->src_h) {
858 goto out;
859 }
860
Michael Zoran6d24c1c2017-02-23 17:54:31 -0800861 if (fb != plane_state->fb) {
862 drm_atomic_set_fb_for_plane(plane->state, fb);
863 vc4_plane_async_set_fb(plane, fb);
864 }
865
Eric Anholt6674a9042015-12-30 11:50:22 -0800866 /* Set the cursor's position on the screen. This is the
867 * expected change from the drm_mode_cursor_universal()
868 * helper.
869 */
870 plane_state->crtc_x = crtc_x;
871 plane_state->crtc_y = crtc_y;
872
873 /* Allow changing the start position within the cursor BO, if
874 * that matters.
875 */
876 plane_state->src_x = src_x;
877 plane_state->src_y = src_y;
878
879 /* Update the display list based on the new crtc_x/y. */
880 vc4_plane_atomic_check(plane, plane_state);
881
882 /* Note that we can't just call vc4_plane_write_dlist()
883 * because that would smash the context data that the HVS is
884 * currently using.
885 */
886 writel(vc4_state->dlist[vc4_state->pos0_offset],
887 &vc4_state->hw_dlist[vc4_state->pos0_offset]);
888 writel(vc4_state->dlist[vc4_state->pos2_offset],
889 &vc4_state->hw_dlist[vc4_state->pos2_offset]);
890 writel(vc4_state->dlist[vc4_state->ptr0_offset],
891 &vc4_state->hw_dlist[vc4_state->ptr0_offset]);
892
893 return 0;
894
895out:
896 return drm_atomic_helper_update_plane(plane, crtc, fb,
897 crtc_x, crtc_y,
898 crtc_w, crtc_h,
899 src_x, src_y,
Daniel Vetter34a2ab52017-03-22 22:50:41 +0100900 src_w, src_h,
901 ctx);
Eric Anholt6674a9042015-12-30 11:50:22 -0800902}
903
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800904static const struct drm_plane_funcs vc4_plane_funcs = {
Eric Anholt6674a9042015-12-30 11:50:22 -0800905 .update_plane = vc4_update_plane,
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800906 .disable_plane = drm_atomic_helper_disable_plane,
907 .destroy = vc4_plane_destroy,
908 .set_property = NULL,
909 .reset = vc4_plane_reset,
910 .atomic_duplicate_state = vc4_plane_duplicate_state,
911 .atomic_destroy_state = vc4_plane_destroy_state,
912};
913
914struct drm_plane *vc4_plane_init(struct drm_device *dev,
915 enum drm_plane_type type)
916{
917 struct drm_plane *plane = NULL;
918 struct vc4_plane *vc4_plane;
919 u32 formats[ARRAY_SIZE(hvs_formats)];
Eric Anholtfc040232015-12-30 12:25:44 -0800920 u32 num_formats = 0;
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800921 int ret = 0;
922 unsigned i;
923
924 vc4_plane = devm_kzalloc(dev->dev, sizeof(*vc4_plane),
925 GFP_KERNEL);
Colin Ian King7b347342017-03-16 18:54:18 +0000926 if (!vc4_plane)
927 return ERR_PTR(-ENOMEM);
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800928
Eric Anholtfc040232015-12-30 12:25:44 -0800929 for (i = 0; i < ARRAY_SIZE(hvs_formats); i++) {
930 /* Don't allow YUV in cursor planes, since that means
931 * tuning on the scaler, which we don't allow for the
932 * cursor.
933 */
934 if (type != DRM_PLANE_TYPE_CURSOR ||
935 hvs_formats[i].hvs < HVS_PIXEL_FORMAT_YCBCR_YUV420_3PLANE) {
936 formats[num_formats++] = hvs_formats[i].drm;
937 }
938 }
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800939 plane = &vc4_plane->base;
Andrzej Pietrasiewicz49d29a02017-02-01 10:35:08 +0100940 ret = drm_universal_plane_init(dev, plane, 0,
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800941 &vc4_plane_funcs,
Eric Anholtfc040232015-12-30 12:25:44 -0800942 formats, num_formats,
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700943 NULL, type, NULL);
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800944
945 drm_plane_helper_add(plane, &vc4_plane_helper_funcs);
946
947 return plane;
Eric Anholtc8b75bc2015-03-02 13:01:12 -0800948}