Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 1 | /* |
| 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 Yamada | b7e8e25 | 2017-05-18 13:29:38 +0900 | [diff] [blame] | 21 | #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 Brezillon | b9f1925 | 2017-10-19 14:57:48 +0200 | [diff] [blame] | 26 | #include "uapi/drm/vc4_drm.h" |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 27 | #include "vc4_drv.h" |
| 28 | #include "vc4_regs.h" |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 29 | |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 30 | enum vc4_scaling_mode { |
| 31 | VC4_SCALING_NONE, |
| 32 | VC4_SCALING_TPZ, |
| 33 | VC4_SCALING_PPF, |
| 34 | }; |
| 35 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 36 | struct vc4_plane_state { |
| 37 | struct drm_plane_state base; |
Eric Anholt | f427fb1 | 2015-12-28 14:14:09 -0800 | [diff] [blame] | 38 | /* System memory copy of the display list for this element, computed |
| 39 | * at atomic_check time. |
| 40 | */ |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 41 | u32 *dlist; |
Eric Anholt | f427fb1 | 2015-12-28 14:14:09 -0800 | [diff] [blame] | 42 | u32 dlist_size; /* Number of dwords allocated for the display list */ |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 43 | u32 dlist_count; /* Number of used dwords in the display list. */ |
Eric Anholt | b501bac | 2015-11-30 12:34:01 -0800 | [diff] [blame] | 44 | |
Eric Anholt | 6674a90 | 2015-12-30 11:50:22 -0800 | [diff] [blame] | 45 | /* 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 Anholt | b501bac | 2015-11-30 12:34:01 -0800 | [diff] [blame] | 51 | |
| 52 | /* Offset where the plane's dlist was last stored in the |
Eric Anholt | f427fb1 | 2015-12-28 14:14:09 -0800 | [diff] [blame] | 53 | * hardware at vc4_crtc_atomic_flush() time. |
| 54 | */ |
Eric Anholt | 17eac75 | 2015-12-28 14:14:57 -0800 | [diff] [blame] | 55 | u32 __iomem *hw_dlist; |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 56 | |
| 57 | /* Clipped coordinates of the plane on the display. */ |
| 58 | int crtc_x, crtc_y, crtc_w, crtc_h; |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 59 | /* Clipped area being scanned from in the FB. */ |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 60 | u32 src_x, src_y; |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 61 | |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 62 | 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 Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 66 | bool is_unity; |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 67 | bool is_yuv; |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 68 | |
| 69 | /* Offset to start scanning out from the start of the plane's |
| 70 | * BO. |
| 71 | */ |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 72 | u32 offsets[3]; |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 73 | |
| 74 | /* Our allocation in LBM for temporary storage during scaling. */ |
| 75 | struct drm_mm_node lbm; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | static inline struct vc4_plane_state * |
| 79 | to_vc4_plane_state(struct drm_plane_state *state) |
| 80 | { |
| 81 | return (struct vc4_plane_state *)state; |
| 82 | } |
| 83 | |
| 84 | static const struct hvs_format { |
| 85 | u32 drm; /* DRM_FORMAT_* */ |
| 86 | u32 hvs; /* HVS_FORMAT_* */ |
| 87 | u32 pixel_order; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 88 | } hvs_formats[] = { |
| 89 | { |
| 90 | .drm = DRM_FORMAT_XRGB8888, .hvs = HVS_PIXEL_FORMAT_RGBA8888, |
Maxime Ripard | 124e5da | 2017-12-22 15:31:27 +0100 | [diff] [blame] | 91 | .pixel_order = HVS_PIXEL_ORDER_ABGR, |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 92 | }, |
| 93 | { |
| 94 | .drm = DRM_FORMAT_ARGB8888, .hvs = HVS_PIXEL_FORMAT_RGBA8888, |
Maxime Ripard | 124e5da | 2017-12-22 15:31:27 +0100 | [diff] [blame] | 95 | .pixel_order = HVS_PIXEL_ORDER_ABGR, |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 96 | }, |
Eric Anholt | fe4cd84 | 2015-10-20 13:59:15 +0100 | [diff] [blame] | 97 | { |
Rob Herring | 9397776 | 2016-06-09 16:19:25 -0500 | [diff] [blame] | 98 | .drm = DRM_FORMAT_ABGR8888, .hvs = HVS_PIXEL_FORMAT_RGBA8888, |
Maxime Ripard | 124e5da | 2017-12-22 15:31:27 +0100 | [diff] [blame] | 99 | .pixel_order = HVS_PIXEL_ORDER_ARGB, |
Rob Herring | 9397776 | 2016-06-09 16:19:25 -0500 | [diff] [blame] | 100 | }, |
| 101 | { |
| 102 | .drm = DRM_FORMAT_XBGR8888, .hvs = HVS_PIXEL_FORMAT_RGBA8888, |
Maxime Ripard | 124e5da | 2017-12-22 15:31:27 +0100 | [diff] [blame] | 103 | .pixel_order = HVS_PIXEL_ORDER_ARGB, |
Rob Herring | 9397776 | 2016-06-09 16:19:25 -0500 | [diff] [blame] | 104 | }, |
| 105 | { |
Eric Anholt | fe4cd84 | 2015-10-20 13:59:15 +0100 | [diff] [blame] | 106 | .drm = DRM_FORMAT_RGB565, .hvs = HVS_PIXEL_FORMAT_RGB565, |
Maxime Ripard | 124e5da | 2017-12-22 15:31:27 +0100 | [diff] [blame] | 107 | .pixel_order = HVS_PIXEL_ORDER_XRGB, |
Eric Anholt | fe4cd84 | 2015-10-20 13:59:15 +0100 | [diff] [blame] | 108 | }, |
| 109 | { |
| 110 | .drm = DRM_FORMAT_BGR565, .hvs = HVS_PIXEL_FORMAT_RGB565, |
Maxime Ripard | 124e5da | 2017-12-22 15:31:27 +0100 | [diff] [blame] | 111 | .pixel_order = HVS_PIXEL_ORDER_XBGR, |
Eric Anholt | fe4cd84 | 2015-10-20 13:59:15 +0100 | [diff] [blame] | 112 | }, |
| 113 | { |
| 114 | .drm = DRM_FORMAT_ARGB1555, .hvs = HVS_PIXEL_FORMAT_RGBA5551, |
Maxime Ripard | 124e5da | 2017-12-22 15:31:27 +0100 | [diff] [blame] | 115 | .pixel_order = HVS_PIXEL_ORDER_ABGR, |
Eric Anholt | fe4cd84 | 2015-10-20 13:59:15 +0100 | [diff] [blame] | 116 | }, |
| 117 | { |
| 118 | .drm = DRM_FORMAT_XRGB1555, .hvs = HVS_PIXEL_FORMAT_RGBA5551, |
Maxime Ripard | 124e5da | 2017-12-22 15:31:27 +0100 | [diff] [blame] | 119 | .pixel_order = HVS_PIXEL_ORDER_ABGR, |
Eric Anholt | fe4cd84 | 2015-10-20 13:59:15 +0100 | [diff] [blame] | 120 | }, |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 121 | { |
Dave Stevenson | 88f8156 | 2017-11-16 14:22:29 +0000 | [diff] [blame] | 122 | .drm = DRM_FORMAT_RGB888, .hvs = HVS_PIXEL_FORMAT_RGB888, |
Maxime Ripard | 124e5da | 2017-12-22 15:31:27 +0100 | [diff] [blame] | 123 | .pixel_order = HVS_PIXEL_ORDER_XRGB, |
Dave Stevenson | 88f8156 | 2017-11-16 14:22:29 +0000 | [diff] [blame] | 124 | }, |
| 125 | { |
| 126 | .drm = DRM_FORMAT_BGR888, .hvs = HVS_PIXEL_FORMAT_RGB888, |
Maxime Ripard | 124e5da | 2017-12-22 15:31:27 +0100 | [diff] [blame] | 127 | .pixel_order = HVS_PIXEL_ORDER_XBGR, |
Dave Stevenson | 88f8156 | 2017-11-16 14:22:29 +0000 | [diff] [blame] | 128 | }, |
| 129 | { |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 130 | .drm = DRM_FORMAT_YUV422, |
| 131 | .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV422_3PLANE, |
Dave Stevenson | 090cb0c | 2017-11-16 14:22:30 +0000 | [diff] [blame] | 132 | .pixel_order = HVS_PIXEL_ORDER_XYCBCR, |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 133 | }, |
| 134 | { |
| 135 | .drm = DRM_FORMAT_YVU422, |
| 136 | .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV422_3PLANE, |
Dave Stevenson | 090cb0c | 2017-11-16 14:22:30 +0000 | [diff] [blame] | 137 | .pixel_order = HVS_PIXEL_ORDER_XYCRCB, |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 138 | }, |
| 139 | { |
| 140 | .drm = DRM_FORMAT_YUV420, |
| 141 | .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV420_3PLANE, |
Dave Stevenson | 090cb0c | 2017-11-16 14:22:30 +0000 | [diff] [blame] | 142 | .pixel_order = HVS_PIXEL_ORDER_XYCBCR, |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 143 | }, |
| 144 | { |
| 145 | .drm = DRM_FORMAT_YVU420, |
| 146 | .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV420_3PLANE, |
Dave Stevenson | 090cb0c | 2017-11-16 14:22:30 +0000 | [diff] [blame] | 147 | .pixel_order = HVS_PIXEL_ORDER_XYCRCB, |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 148 | }, |
| 149 | { |
| 150 | .drm = DRM_FORMAT_NV12, |
| 151 | .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV420_2PLANE, |
Dave Stevenson | 090cb0c | 2017-11-16 14:22:30 +0000 | [diff] [blame] | 152 | .pixel_order = HVS_PIXEL_ORDER_XYCBCR, |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 153 | }, |
| 154 | { |
Dave Stevenson | cb20dd1 | 2017-11-16 14:22:31 +0000 | [diff] [blame] | 155 | .drm = DRM_FORMAT_NV21, |
| 156 | .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV420_2PLANE, |
| 157 | .pixel_order = HVS_PIXEL_ORDER_XYCRCB, |
| 158 | }, |
| 159 | { |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 160 | .drm = DRM_FORMAT_NV16, |
| 161 | .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV422_2PLANE, |
Dave Stevenson | 090cb0c | 2017-11-16 14:22:30 +0000 | [diff] [blame] | 162 | .pixel_order = HVS_PIXEL_ORDER_XYCBCR, |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 163 | }, |
Dave Stevenson | cb20dd1 | 2017-11-16 14:22:31 +0000 | [diff] [blame] | 164 | { |
| 165 | .drm = DRM_FORMAT_NV61, |
| 166 | .hvs = HVS_PIXEL_FORMAT_YCBCR_YUV422_2PLANE, |
| 167 | .pixel_order = HVS_PIXEL_ORDER_XYCRCB, |
| 168 | }, |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | static const struct hvs_format *vc4_get_hvs_format(u32 drm_format) |
| 172 | { |
| 173 | unsigned i; |
| 174 | |
| 175 | for (i = 0; i < ARRAY_SIZE(hvs_formats); i++) { |
| 176 | if (hvs_formats[i].drm == drm_format) |
| 177 | return &hvs_formats[i]; |
| 178 | } |
| 179 | |
| 180 | return NULL; |
| 181 | } |
| 182 | |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 183 | static enum vc4_scaling_mode vc4_get_scaling_mode(u32 src, u32 dst) |
| 184 | { |
| 185 | if (dst > src) |
| 186 | return VC4_SCALING_PPF; |
| 187 | else if (dst < src) |
| 188 | return VC4_SCALING_TPZ; |
| 189 | else |
| 190 | return VC4_SCALING_NONE; |
| 191 | } |
| 192 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 193 | static bool plane_enabled(struct drm_plane_state *state) |
| 194 | { |
| 195 | return state->fb && state->crtc; |
| 196 | } |
| 197 | |
kbuild test robot | 91276ae | 2015-10-22 11:12:26 +0800 | [diff] [blame] | 198 | static struct drm_plane_state *vc4_plane_duplicate_state(struct drm_plane *plane) |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 199 | { |
| 200 | struct vc4_plane_state *vc4_state; |
| 201 | |
| 202 | if (WARN_ON(!plane->state)) |
| 203 | return NULL; |
| 204 | |
| 205 | vc4_state = kmemdup(plane->state, sizeof(*vc4_state), GFP_KERNEL); |
| 206 | if (!vc4_state) |
| 207 | return NULL; |
| 208 | |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 209 | memset(&vc4_state->lbm, 0, sizeof(vc4_state->lbm)); |
| 210 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 211 | __drm_atomic_helper_plane_duplicate_state(plane, &vc4_state->base); |
| 212 | |
| 213 | if (vc4_state->dlist) { |
| 214 | vc4_state->dlist = kmemdup(vc4_state->dlist, |
| 215 | vc4_state->dlist_count * 4, |
| 216 | GFP_KERNEL); |
| 217 | if (!vc4_state->dlist) { |
| 218 | kfree(vc4_state); |
| 219 | return NULL; |
| 220 | } |
| 221 | vc4_state->dlist_size = vc4_state->dlist_count; |
| 222 | } |
| 223 | |
| 224 | return &vc4_state->base; |
| 225 | } |
| 226 | |
kbuild test robot | 91276ae | 2015-10-22 11:12:26 +0800 | [diff] [blame] | 227 | static void vc4_plane_destroy_state(struct drm_plane *plane, |
| 228 | struct drm_plane_state *state) |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 229 | { |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 230 | struct vc4_dev *vc4 = to_vc4_dev(plane->dev); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 231 | struct vc4_plane_state *vc4_state = to_vc4_plane_state(state); |
| 232 | |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 233 | if (vc4_state->lbm.allocated) { |
| 234 | unsigned long irqflags; |
| 235 | |
| 236 | spin_lock_irqsave(&vc4->hvs->mm_lock, irqflags); |
| 237 | drm_mm_remove_node(&vc4_state->lbm); |
| 238 | spin_unlock_irqrestore(&vc4->hvs->mm_lock, irqflags); |
| 239 | } |
| 240 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 241 | kfree(vc4_state->dlist); |
Daniel Vetter | 2f70169 | 2016-05-09 16:34:10 +0200 | [diff] [blame] | 242 | __drm_atomic_helper_plane_destroy_state(&vc4_state->base); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 243 | kfree(state); |
| 244 | } |
| 245 | |
| 246 | /* Called during init to allocate the plane's atomic state. */ |
kbuild test robot | 91276ae | 2015-10-22 11:12:26 +0800 | [diff] [blame] | 247 | static void vc4_plane_reset(struct drm_plane *plane) |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 248 | { |
| 249 | struct vc4_plane_state *vc4_state; |
| 250 | |
| 251 | WARN_ON(plane->state); |
| 252 | |
| 253 | vc4_state = kzalloc(sizeof(*vc4_state), GFP_KERNEL); |
| 254 | if (!vc4_state) |
| 255 | return; |
| 256 | |
| 257 | plane->state = &vc4_state->base; |
| 258 | vc4_state->base.plane = plane; |
| 259 | } |
| 260 | |
| 261 | static void vc4_dlist_write(struct vc4_plane_state *vc4_state, u32 val) |
| 262 | { |
| 263 | if (vc4_state->dlist_count == vc4_state->dlist_size) { |
| 264 | u32 new_size = max(4u, vc4_state->dlist_count * 2); |
| 265 | u32 *new_dlist = kmalloc(new_size * 4, GFP_KERNEL); |
| 266 | |
| 267 | if (!new_dlist) |
| 268 | return; |
| 269 | memcpy(new_dlist, vc4_state->dlist, vc4_state->dlist_count * 4); |
| 270 | |
| 271 | kfree(vc4_state->dlist); |
| 272 | vc4_state->dlist = new_dlist; |
| 273 | vc4_state->dlist_size = new_size; |
| 274 | } |
| 275 | |
| 276 | vc4_state->dlist[vc4_state->dlist_count++] = val; |
| 277 | } |
| 278 | |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 279 | /* Returns the scl0/scl1 field based on whether the dimensions need to |
| 280 | * be up/down/non-scaled. |
| 281 | * |
| 282 | * This is a replication of a table from the spec. |
| 283 | */ |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 284 | static u32 vc4_get_scl_field(struct drm_plane_state *state, int plane) |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 285 | { |
| 286 | struct vc4_plane_state *vc4_state = to_vc4_plane_state(state); |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 287 | |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 288 | switch (vc4_state->x_scaling[plane] << 2 | vc4_state->y_scaling[plane]) { |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 289 | case VC4_SCALING_PPF << 2 | VC4_SCALING_PPF: |
| 290 | return SCALER_CTL0_SCL_H_PPF_V_PPF; |
| 291 | case VC4_SCALING_TPZ << 2 | VC4_SCALING_PPF: |
| 292 | return SCALER_CTL0_SCL_H_TPZ_V_PPF; |
| 293 | case VC4_SCALING_PPF << 2 | VC4_SCALING_TPZ: |
| 294 | return SCALER_CTL0_SCL_H_PPF_V_TPZ; |
| 295 | case VC4_SCALING_TPZ << 2 | VC4_SCALING_TPZ: |
| 296 | return SCALER_CTL0_SCL_H_TPZ_V_TPZ; |
| 297 | case VC4_SCALING_PPF << 2 | VC4_SCALING_NONE: |
| 298 | return SCALER_CTL0_SCL_H_PPF_V_NONE; |
| 299 | case VC4_SCALING_NONE << 2 | VC4_SCALING_PPF: |
| 300 | return SCALER_CTL0_SCL_H_NONE_V_PPF; |
| 301 | case VC4_SCALING_NONE << 2 | VC4_SCALING_TPZ: |
| 302 | return SCALER_CTL0_SCL_H_NONE_V_TPZ; |
| 303 | case VC4_SCALING_TPZ << 2 | VC4_SCALING_NONE: |
| 304 | return SCALER_CTL0_SCL_H_TPZ_V_NONE; |
| 305 | default: |
| 306 | case VC4_SCALING_NONE << 2 | VC4_SCALING_NONE: |
| 307 | /* The unity case is independently handled by |
| 308 | * SCALER_CTL0_UNITY. |
| 309 | */ |
| 310 | return 0; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | static int vc4_plane_setup_clipping_and_scaling(struct drm_plane_state *state) |
| 315 | { |
| 316 | struct drm_plane *plane = state->plane; |
| 317 | struct vc4_plane_state *vc4_state = to_vc4_plane_state(state); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 318 | struct drm_framebuffer *fb = state->fb; |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 319 | struct drm_gem_cma_object *bo = drm_fb_cma_get_gem_obj(fb, 0); |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 320 | u32 subpixel_src_mask = (1 << 16) - 1; |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 321 | u32 format = fb->format->format; |
Ville Syrjälä | bcb0b46 | 2016-12-14 23:30:22 +0200 | [diff] [blame] | 322 | int num_planes = fb->format->num_planes; |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 323 | u32 h_subsample = 1; |
| 324 | u32 v_subsample = 1; |
| 325 | int i; |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 326 | |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 327 | for (i = 0; i < num_planes; i++) |
| 328 | vc4_state->offsets[i] = bo->paddr + fb->offsets[i]; |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 329 | |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 330 | /* We don't support subpixel source positioning for scaling. */ |
| 331 | if ((state->src_x & subpixel_src_mask) || |
| 332 | (state->src_y & subpixel_src_mask) || |
| 333 | (state->src_w & subpixel_src_mask) || |
| 334 | (state->src_h & subpixel_src_mask)) { |
Eric Anholt | bf893ac | 2015-10-23 10:36:27 +0100 | [diff] [blame] | 335 | return -EINVAL; |
| 336 | } |
| 337 | |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 338 | vc4_state->src_x = state->src_x >> 16; |
| 339 | vc4_state->src_y = state->src_y >> 16; |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 340 | vc4_state->src_w[0] = state->src_w >> 16; |
| 341 | vc4_state->src_h[0] = state->src_h >> 16; |
Eric Anholt | f863e35 | 2015-12-28 14:45:25 -0800 | [diff] [blame] | 342 | |
| 343 | vc4_state->crtc_x = state->crtc_x; |
| 344 | vc4_state->crtc_y = state->crtc_y; |
| 345 | vc4_state->crtc_w = state->crtc_w; |
| 346 | vc4_state->crtc_h = state->crtc_h; |
| 347 | |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 348 | vc4_state->x_scaling[0] = vc4_get_scaling_mode(vc4_state->src_w[0], |
| 349 | vc4_state->crtc_w); |
| 350 | vc4_state->y_scaling[0] = vc4_get_scaling_mode(vc4_state->src_h[0], |
| 351 | vc4_state->crtc_h); |
| 352 | |
| 353 | if (num_planes > 1) { |
| 354 | vc4_state->is_yuv = true; |
| 355 | |
| 356 | h_subsample = drm_format_horz_chroma_subsampling(format); |
| 357 | v_subsample = drm_format_vert_chroma_subsampling(format); |
| 358 | vc4_state->src_w[1] = vc4_state->src_w[0] / h_subsample; |
| 359 | vc4_state->src_h[1] = vc4_state->src_h[0] / v_subsample; |
| 360 | |
| 361 | vc4_state->x_scaling[1] = |
| 362 | vc4_get_scaling_mode(vc4_state->src_w[1], |
| 363 | vc4_state->crtc_w); |
| 364 | vc4_state->y_scaling[1] = |
| 365 | vc4_get_scaling_mode(vc4_state->src_h[1], |
| 366 | vc4_state->crtc_h); |
| 367 | |
| 368 | /* YUV conversion requires that scaling be enabled, |
| 369 | * even on a plane that's otherwise 1:1. Choose TPZ |
| 370 | * for simplicity. |
| 371 | */ |
| 372 | if (vc4_state->x_scaling[0] == VC4_SCALING_NONE) |
| 373 | vc4_state->x_scaling[0] = VC4_SCALING_TPZ; |
| 374 | if (vc4_state->y_scaling[0] == VC4_SCALING_NONE) |
| 375 | vc4_state->y_scaling[0] = VC4_SCALING_TPZ; |
| 376 | } |
| 377 | |
| 378 | vc4_state->is_unity = (vc4_state->x_scaling[0] == VC4_SCALING_NONE && |
| 379 | vc4_state->y_scaling[0] == VC4_SCALING_NONE && |
| 380 | vc4_state->x_scaling[1] == VC4_SCALING_NONE && |
| 381 | vc4_state->y_scaling[1] == VC4_SCALING_NONE); |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 382 | |
| 383 | /* No configuring scaling on the cursor plane, since it gets |
| 384 | non-vblank-synced updates, and scaling requires requires |
| 385 | LBM changes which have to be vblank-synced. |
| 386 | */ |
| 387 | if (plane->type == DRM_PLANE_TYPE_CURSOR && !vc4_state->is_unity) |
| 388 | return -EINVAL; |
| 389 | |
| 390 | /* Clamp the on-screen start x/y to 0. The hardware doesn't |
| 391 | * support negative y, and negative x wastes bandwidth. |
| 392 | */ |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 393 | if (vc4_state->crtc_x < 0) { |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 394 | for (i = 0; i < num_planes; i++) { |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 395 | u32 cpp = fb->format->cpp[i]; |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 396 | u32 subs = ((i == 0) ? 1 : h_subsample); |
| 397 | |
| 398 | vc4_state->offsets[i] += (cpp * |
| 399 | (-vc4_state->crtc_x) / subs); |
| 400 | } |
| 401 | vc4_state->src_w[0] += vc4_state->crtc_x; |
| 402 | vc4_state->src_w[1] += vc4_state->crtc_x / h_subsample; |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 403 | vc4_state->crtc_x = 0; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 404 | } |
| 405 | |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 406 | if (vc4_state->crtc_y < 0) { |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 407 | for (i = 0; i < num_planes; i++) { |
| 408 | u32 subs = ((i == 0) ? 1 : v_subsample); |
| 409 | |
| 410 | vc4_state->offsets[i] += (fb->pitches[i] * |
| 411 | (-vc4_state->crtc_y) / subs); |
| 412 | } |
| 413 | vc4_state->src_h[0] += vc4_state->crtc_y; |
| 414 | vc4_state->src_h[1] += vc4_state->crtc_y / v_subsample; |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 415 | vc4_state->crtc_y = 0; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 416 | } |
| 417 | |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 418 | return 0; |
| 419 | } |
| 420 | |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 421 | static void vc4_write_tpz(struct vc4_plane_state *vc4_state, u32 src, u32 dst) |
| 422 | { |
| 423 | u32 scale, recip; |
| 424 | |
| 425 | scale = (1 << 16) * src / dst; |
| 426 | |
| 427 | /* The specs note that while the reciprocal would be defined |
| 428 | * as (1<<32)/scale, ~0 is close enough. |
| 429 | */ |
| 430 | recip = ~0 / scale; |
| 431 | |
| 432 | vc4_dlist_write(vc4_state, |
| 433 | VC4_SET_FIELD(scale, SCALER_TPZ0_SCALE) | |
| 434 | VC4_SET_FIELD(0, SCALER_TPZ0_IPHASE)); |
| 435 | vc4_dlist_write(vc4_state, |
| 436 | VC4_SET_FIELD(recip, SCALER_TPZ1_RECIP)); |
| 437 | } |
| 438 | |
| 439 | static void vc4_write_ppf(struct vc4_plane_state *vc4_state, u32 src, u32 dst) |
| 440 | { |
| 441 | u32 scale = (1 << 16) * src / dst; |
| 442 | |
| 443 | vc4_dlist_write(vc4_state, |
| 444 | SCALER_PPF_AGC | |
| 445 | VC4_SET_FIELD(scale, SCALER_PPF_SCALE) | |
| 446 | VC4_SET_FIELD(0, SCALER_PPF_IPHASE)); |
| 447 | } |
| 448 | |
| 449 | static u32 vc4_lbm_size(struct drm_plane_state *state) |
| 450 | { |
| 451 | struct vc4_plane_state *vc4_state = to_vc4_plane_state(state); |
| 452 | /* This is the worst case number. One of the two sizes will |
| 453 | * be used depending on the scaling configuration. |
| 454 | */ |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 455 | u32 pix_per_line = max(vc4_state->src_w[0], (u32)vc4_state->crtc_w); |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 456 | u32 lbm; |
| 457 | |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 458 | if (!vc4_state->is_yuv) { |
| 459 | if (vc4_state->is_unity) |
| 460 | return 0; |
| 461 | else if (vc4_state->y_scaling[0] == VC4_SCALING_TPZ) |
| 462 | lbm = pix_per_line * 8; |
| 463 | else { |
| 464 | /* In special cases, this multiplier might be 12. */ |
| 465 | lbm = pix_per_line * 16; |
| 466 | } |
| 467 | } else { |
| 468 | /* There are cases for this going down to a multiplier |
| 469 | * of 2, but according to the firmware source, the |
| 470 | * table in the docs is somewhat wrong. |
| 471 | */ |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 472 | lbm = pix_per_line * 16; |
| 473 | } |
| 474 | |
| 475 | lbm = roundup(lbm, 32); |
| 476 | |
| 477 | return lbm; |
| 478 | } |
| 479 | |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 480 | static void vc4_write_scaling_parameters(struct drm_plane_state *state, |
| 481 | int channel) |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 482 | { |
| 483 | struct vc4_plane_state *vc4_state = to_vc4_plane_state(state); |
| 484 | |
| 485 | /* Ch0 H-PPF Word 0: Scaling Parameters */ |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 486 | if (vc4_state->x_scaling[channel] == VC4_SCALING_PPF) { |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 487 | vc4_write_ppf(vc4_state, |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 488 | vc4_state->src_w[channel], vc4_state->crtc_w); |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | /* Ch0 V-PPF Words 0-1: Scaling Parameters, Context */ |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 492 | if (vc4_state->y_scaling[channel] == VC4_SCALING_PPF) { |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 493 | vc4_write_ppf(vc4_state, |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 494 | vc4_state->src_h[channel], vc4_state->crtc_h); |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 495 | vc4_dlist_write(vc4_state, 0xc0c0c0c0); |
| 496 | } |
| 497 | |
| 498 | /* Ch0 H-TPZ Words 0-1: Scaling Parameters, Recip */ |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 499 | if (vc4_state->x_scaling[channel] == VC4_SCALING_TPZ) { |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 500 | vc4_write_tpz(vc4_state, |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 501 | vc4_state->src_w[channel], vc4_state->crtc_w); |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /* Ch0 V-TPZ Words 0-2: Scaling Parameters, Recip, Context */ |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 505 | if (vc4_state->y_scaling[channel] == VC4_SCALING_TPZ) { |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 506 | vc4_write_tpz(vc4_state, |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 507 | vc4_state->src_h[channel], vc4_state->crtc_h); |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 508 | vc4_dlist_write(vc4_state, 0xc0c0c0c0); |
| 509 | } |
| 510 | } |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 511 | |
| 512 | /* Writes out a full display list for an active plane to the plane's |
| 513 | * private dlist state. |
| 514 | */ |
| 515 | static int vc4_plane_mode_set(struct drm_plane *plane, |
| 516 | struct drm_plane_state *state) |
| 517 | { |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 518 | struct vc4_dev *vc4 = to_vc4_dev(plane->dev); |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 519 | struct vc4_plane_state *vc4_state = to_vc4_plane_state(state); |
| 520 | struct drm_framebuffer *fb = state->fb; |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 521 | u32 ctl0_offset = vc4_state->dlist_count; |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 522 | const struct hvs_format *format = vc4_get_hvs_format(fb->format->format); |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 523 | int num_planes = drm_format_num_planes(format->drm); |
Eric Anholt | 98830d91 | 2017-06-07 17:13:35 -0700 | [diff] [blame] | 524 | u32 scl0, scl1, pitch0; |
| 525 | u32 lbm_size, tiling; |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 526 | unsigned long irqflags; |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 527 | int ret, i; |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 528 | |
| 529 | ret = vc4_plane_setup_clipping_and_scaling(state); |
| 530 | if (ret) |
| 531 | return ret; |
| 532 | |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 533 | /* Allocate the LBM memory that the HVS will use for temporary |
| 534 | * storage due to our scaling/format conversion. |
| 535 | */ |
| 536 | lbm_size = vc4_lbm_size(state); |
| 537 | if (lbm_size) { |
| 538 | if (!vc4_state->lbm.allocated) { |
| 539 | spin_lock_irqsave(&vc4->hvs->mm_lock, irqflags); |
Chris Wilson | 4e64e55 | 2017-02-02 21:04:38 +0000 | [diff] [blame] | 540 | ret = drm_mm_insert_node_generic(&vc4->hvs->lbm_mm, |
| 541 | &vc4_state->lbm, |
| 542 | lbm_size, 32, 0, 0); |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 543 | spin_unlock_irqrestore(&vc4->hvs->mm_lock, irqflags); |
| 544 | } else { |
| 545 | WARN_ON_ONCE(lbm_size != vc4_state->lbm.size); |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | if (ret) |
| 550 | return ret; |
| 551 | |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 552 | /* SCL1 is used for Cb/Cr scaling of planar formats. For RGB |
| 553 | * and 4:4:4, scl1 should be set to scl0 so both channels of |
| 554 | * the scaler do the same thing. For YUV, the Y plane needs |
| 555 | * to be put in channel 1 and Cb/Cr in channel 0, so we swap |
| 556 | * the scl fields here. |
| 557 | */ |
| 558 | if (num_planes == 1) { |
| 559 | scl0 = vc4_get_scl_field(state, 1); |
| 560 | scl1 = scl0; |
| 561 | } else { |
| 562 | scl0 = vc4_get_scl_field(state, 1); |
| 563 | scl1 = vc4_get_scl_field(state, 0); |
| 564 | } |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 565 | |
Eric Anholt | 98830d91 | 2017-06-07 17:13:35 -0700 | [diff] [blame] | 566 | switch (fb->modifier) { |
| 567 | case DRM_FORMAT_MOD_LINEAR: |
| 568 | tiling = SCALER_CTL0_TILING_LINEAR; |
| 569 | pitch0 = VC4_SET_FIELD(fb->pitches[0], SCALER_SRC_PITCH); |
| 570 | break; |
Eric Anholt | 652badb | 2017-09-27 12:32:09 -0700 | [diff] [blame] | 571 | |
| 572 | case DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED: { |
| 573 | /* For T-tiled, the FB pitch is "how many bytes from |
| 574 | * one row to the next, such that pitch * tile_h == |
| 575 | * tile_size * tiles_per_row." |
| 576 | */ |
| 577 | u32 tile_size_shift = 12; /* T tiles are 4kb */ |
| 578 | u32 tile_h_shift = 5; /* 16 and 32bpp are 32 pixels high */ |
| 579 | u32 tiles_w = fb->pitches[0] >> (tile_size_shift - tile_h_shift); |
| 580 | |
Eric Anholt | 98830d91 | 2017-06-07 17:13:35 -0700 | [diff] [blame] | 581 | tiling = SCALER_CTL0_TILING_256B_OR_T; |
| 582 | |
Eric Anholt | 652badb | 2017-09-27 12:32:09 -0700 | [diff] [blame] | 583 | pitch0 = (VC4_SET_FIELD(0, SCALER_PITCH0_TILE_Y_OFFSET) | |
| 584 | VC4_SET_FIELD(0, SCALER_PITCH0_TILE_WIDTH_L) | |
| 585 | VC4_SET_FIELD(tiles_w, SCALER_PITCH0_TILE_WIDTH_R)); |
Eric Anholt | 98830d91 | 2017-06-07 17:13:35 -0700 | [diff] [blame] | 586 | break; |
Eric Anholt | 652badb | 2017-09-27 12:32:09 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Eric Anholt | 98830d91 | 2017-06-07 17:13:35 -0700 | [diff] [blame] | 589 | default: |
| 590 | DRM_DEBUG_KMS("Unsupported FB tiling flag 0x%16llx", |
| 591 | (long long)fb->modifier); |
| 592 | return -EINVAL; |
| 593 | } |
| 594 | |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 595 | /* Control word */ |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 596 | vc4_dlist_write(vc4_state, |
| 597 | SCALER_CTL0_VALID | |
| 598 | (format->pixel_order << SCALER_CTL0_ORDER_SHIFT) | |
| 599 | (format->hvs << SCALER_CTL0_PIXEL_FORMAT_SHIFT) | |
Eric Anholt | 98830d91 | 2017-06-07 17:13:35 -0700 | [diff] [blame] | 600 | VC4_SET_FIELD(tiling, SCALER_CTL0_TILING) | |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 601 | (vc4_state->is_unity ? SCALER_CTL0_UNITY : 0) | |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 602 | VC4_SET_FIELD(scl0, SCALER_CTL0_SCL0) | |
| 603 | VC4_SET_FIELD(scl1, SCALER_CTL0_SCL1)); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 604 | |
| 605 | /* Position Word 0: Image Positions and Alpha Value */ |
Eric Anholt | 6674a90 | 2015-12-30 11:50:22 -0800 | [diff] [blame] | 606 | vc4_state->pos0_offset = vc4_state->dlist_count; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 607 | vc4_dlist_write(vc4_state, |
| 608 | VC4_SET_FIELD(0xff, SCALER_POS0_FIXED_ALPHA) | |
Eric Anholt | 5c67999 | 2015-12-28 14:34:44 -0800 | [diff] [blame] | 609 | VC4_SET_FIELD(vc4_state->crtc_x, SCALER_POS0_START_X) | |
| 610 | VC4_SET_FIELD(vc4_state->crtc_y, SCALER_POS0_START_Y)); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 611 | |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 612 | /* Position Word 1: Scaled Image Dimensions. */ |
| 613 | if (!vc4_state->is_unity) { |
| 614 | vc4_dlist_write(vc4_state, |
| 615 | VC4_SET_FIELD(vc4_state->crtc_w, |
| 616 | SCALER_POS1_SCL_WIDTH) | |
| 617 | VC4_SET_FIELD(vc4_state->crtc_h, |
| 618 | SCALER_POS1_SCL_HEIGHT)); |
| 619 | } |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 620 | |
Stefan Schake | 05202c2 | 2018-03-09 01:53:34 +0100 | [diff] [blame^] | 621 | /* Position Word 2: Source Image Size, Alpha */ |
Eric Anholt | 6674a90 | 2015-12-30 11:50:22 -0800 | [diff] [blame] | 622 | vc4_state->pos2_offset = vc4_state->dlist_count; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 623 | vc4_dlist_write(vc4_state, |
Maxime Ripard | 124e5da | 2017-12-22 15:31:27 +0100 | [diff] [blame] | 624 | VC4_SET_FIELD(fb->format->has_alpha ? |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 625 | SCALER_POS2_ALPHA_MODE_PIPELINE : |
| 626 | SCALER_POS2_ALPHA_MODE_FIXED, |
| 627 | SCALER_POS2_ALPHA_MODE) | |
Stefan Schake | 05202c2 | 2018-03-09 01:53:34 +0100 | [diff] [blame^] | 628 | (fb->format->has_alpha ? SCALER_POS2_ALPHA_PREMULT : 0) | |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 629 | VC4_SET_FIELD(vc4_state->src_w[0], SCALER_POS2_WIDTH) | |
| 630 | VC4_SET_FIELD(vc4_state->src_h[0], SCALER_POS2_HEIGHT)); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 631 | |
| 632 | /* Position Word 3: Context. Written by the HVS. */ |
| 633 | vc4_dlist_write(vc4_state, 0xc0c0c0c0); |
| 634 | |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 635 | |
| 636 | /* Pointer Word 0/1/2: RGB / Y / Cb / Cr Pointers |
| 637 | * |
| 638 | * The pointers may be any byte address. |
| 639 | */ |
Eric Anholt | 6674a90 | 2015-12-30 11:50:22 -0800 | [diff] [blame] | 640 | vc4_state->ptr0_offset = vc4_state->dlist_count; |
Dave Stevenson | 090cb0c | 2017-11-16 14:22:30 +0000 | [diff] [blame] | 641 | for (i = 0; i < num_planes; i++) |
| 642 | vc4_dlist_write(vc4_state, vc4_state->offsets[i]); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 643 | |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 644 | /* Pointer Context Word 0/1/2: Written by the HVS */ |
| 645 | for (i = 0; i < num_planes; i++) |
| 646 | vc4_dlist_write(vc4_state, 0xc0c0c0c0); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 647 | |
Eric Anholt | 98830d91 | 2017-06-07 17:13:35 -0700 | [diff] [blame] | 648 | /* Pitch word 0 */ |
| 649 | vc4_dlist_write(vc4_state, pitch0); |
| 650 | |
| 651 | /* Pitch word 1/2 */ |
| 652 | for (i = 1; i < num_planes; i++) { |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 653 | vc4_dlist_write(vc4_state, |
| 654 | VC4_SET_FIELD(fb->pitches[i], SCALER_SRC_PITCH)); |
| 655 | } |
| 656 | |
| 657 | /* Colorspace conversion words */ |
| 658 | if (vc4_state->is_yuv) { |
| 659 | vc4_dlist_write(vc4_state, SCALER_CSC0_ITR_R_601_5); |
| 660 | vc4_dlist_write(vc4_state, SCALER_CSC1_ITR_R_601_5); |
| 661 | vc4_dlist_write(vc4_state, SCALER_CSC2_ITR_R_601_5); |
| 662 | } |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 663 | |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 664 | if (!vc4_state->is_unity) { |
| 665 | /* LBM Base Address. */ |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 666 | if (vc4_state->y_scaling[0] != VC4_SCALING_NONE || |
| 667 | vc4_state->y_scaling[1] != VC4_SCALING_NONE) { |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 668 | vc4_dlist_write(vc4_state, vc4_state->lbm.start); |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 669 | } |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 670 | |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 671 | if (num_planes > 1) { |
| 672 | /* Emit Cb/Cr as channel 0 and Y as channel |
| 673 | * 1. This matches how we set up scl0/scl1 |
| 674 | * above. |
| 675 | */ |
| 676 | vc4_write_scaling_parameters(state, 1); |
| 677 | } |
| 678 | vc4_write_scaling_parameters(state, 0); |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 679 | |
| 680 | /* If any PPF setup was done, then all the kernel |
| 681 | * pointers get uploaded. |
| 682 | */ |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 683 | if (vc4_state->x_scaling[0] == VC4_SCALING_PPF || |
| 684 | vc4_state->y_scaling[0] == VC4_SCALING_PPF || |
| 685 | vc4_state->x_scaling[1] == VC4_SCALING_PPF || |
| 686 | vc4_state->y_scaling[1] == VC4_SCALING_PPF) { |
Eric Anholt | 21af94c | 2015-10-20 16:06:57 +0100 | [diff] [blame] | 687 | u32 kernel = VC4_SET_FIELD(vc4->hvs->mitchell_netravali_filter.start, |
| 688 | SCALER_PPF_KERNEL_OFFSET); |
| 689 | |
| 690 | /* HPPF plane 0 */ |
| 691 | vc4_dlist_write(vc4_state, kernel); |
| 692 | /* VPPF plane 0 */ |
| 693 | vc4_dlist_write(vc4_state, kernel); |
| 694 | /* HPPF plane 1 */ |
| 695 | vc4_dlist_write(vc4_state, kernel); |
| 696 | /* VPPF plane 1 */ |
| 697 | vc4_dlist_write(vc4_state, kernel); |
| 698 | } |
| 699 | } |
| 700 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 701 | vc4_state->dlist[ctl0_offset] |= |
| 702 | VC4_SET_FIELD(vc4_state->dlist_count, SCALER_CTL0_SIZE); |
| 703 | |
| 704 | return 0; |
| 705 | } |
| 706 | |
| 707 | /* If a modeset involves changing the setup of a plane, the atomic |
| 708 | * infrastructure will call this to validate a proposed plane setup. |
| 709 | * However, if a plane isn't getting updated, this (and the |
| 710 | * corresponding vc4_plane_atomic_update) won't get called. Thus, we |
| 711 | * compute the dlist here and have all active plane dlists get updated |
| 712 | * in the CRTC's flush. |
| 713 | */ |
| 714 | static int vc4_plane_atomic_check(struct drm_plane *plane, |
| 715 | struct drm_plane_state *state) |
| 716 | { |
| 717 | struct vc4_plane_state *vc4_state = to_vc4_plane_state(state); |
| 718 | |
| 719 | vc4_state->dlist_count = 0; |
| 720 | |
| 721 | if (plane_enabled(state)) |
| 722 | return vc4_plane_mode_set(plane, state); |
| 723 | else |
| 724 | return 0; |
| 725 | } |
| 726 | |
| 727 | static void vc4_plane_atomic_update(struct drm_plane *plane, |
| 728 | struct drm_plane_state *old_state) |
| 729 | { |
| 730 | /* No contents here. Since we don't know where in the CRTC's |
| 731 | * dlist we should be stored, our dlist is uploaded to the |
| 732 | * hardware with vc4_plane_write_dlist() at CRTC atomic_flush |
| 733 | * time. |
| 734 | */ |
| 735 | } |
| 736 | |
| 737 | u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist) |
| 738 | { |
| 739 | struct vc4_plane_state *vc4_state = to_vc4_plane_state(plane->state); |
| 740 | int i; |
| 741 | |
Eric Anholt | b501bac | 2015-11-30 12:34:01 -0800 | [diff] [blame] | 742 | vc4_state->hw_dlist = dlist; |
| 743 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 744 | /* Can't memcpy_toio() because it needs to be 32-bit writes. */ |
| 745 | for (i = 0; i < vc4_state->dlist_count; i++) |
| 746 | writel(vc4_state->dlist[i], &dlist[i]); |
| 747 | |
| 748 | return vc4_state->dlist_count; |
| 749 | } |
| 750 | |
Daniel Vetter | 2f196b7 | 2016-06-02 16:21:44 +0200 | [diff] [blame] | 751 | u32 vc4_plane_dlist_size(const struct drm_plane_state *state) |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 752 | { |
Daniel Vetter | 2f196b7 | 2016-06-02 16:21:44 +0200 | [diff] [blame] | 753 | const struct vc4_plane_state *vc4_state = |
| 754 | container_of(state, typeof(*vc4_state), base); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 755 | |
| 756 | return vc4_state->dlist_count; |
| 757 | } |
| 758 | |
Eric Anholt | b501bac | 2015-11-30 12:34:01 -0800 | [diff] [blame] | 759 | /* Updates the plane to immediately (well, once the FIFO needs |
| 760 | * refilling) scan out from at a new framebuffer. |
| 761 | */ |
| 762 | void vc4_plane_async_set_fb(struct drm_plane *plane, struct drm_framebuffer *fb) |
| 763 | { |
| 764 | struct vc4_plane_state *vc4_state = to_vc4_plane_state(plane->state); |
| 765 | struct drm_gem_cma_object *bo = drm_fb_cma_get_gem_obj(fb, 0); |
| 766 | uint32_t addr; |
| 767 | |
| 768 | /* We're skipping the address adjustment for negative origin, |
| 769 | * because this is only called on the primary plane. |
| 770 | */ |
| 771 | WARN_ON_ONCE(plane->state->crtc_x < 0 || plane->state->crtc_y < 0); |
| 772 | addr = bo->paddr + fb->offsets[0]; |
| 773 | |
| 774 | /* Write the new address into the hardware immediately. The |
| 775 | * scanout will start from this address as soon as the FIFO |
| 776 | * needs to refill with pixels. |
| 777 | */ |
Eric Anholt | 6674a90 | 2015-12-30 11:50:22 -0800 | [diff] [blame] | 778 | writel(addr, &vc4_state->hw_dlist[vc4_state->ptr0_offset]); |
Eric Anholt | b501bac | 2015-11-30 12:34:01 -0800 | [diff] [blame] | 779 | |
| 780 | /* Also update the CPU-side dlist copy, so that any later |
| 781 | * atomic updates that don't do a new modeset on our plane |
| 782 | * also use our updated address. |
| 783 | */ |
Eric Anholt | 6674a90 | 2015-12-30 11:50:22 -0800 | [diff] [blame] | 784 | vc4_state->dlist[vc4_state->ptr0_offset] = addr; |
Eric Anholt | b501bac | 2015-11-30 12:34:01 -0800 | [diff] [blame] | 785 | } |
| 786 | |
Eric Anholt | 334dbd6 | 2017-06-21 11:49:59 -0700 | [diff] [blame] | 787 | static int vc4_prepare_fb(struct drm_plane *plane, |
| 788 | struct drm_plane_state *state) |
| 789 | { |
| 790 | struct vc4_bo *bo; |
| 791 | struct dma_fence *fence; |
Boris Brezillon | b9f1925 | 2017-10-19 14:57:48 +0200 | [diff] [blame] | 792 | int ret; |
Eric Anholt | 334dbd6 | 2017-06-21 11:49:59 -0700 | [diff] [blame] | 793 | |
| 794 | if ((plane->state->fb == state->fb) || !state->fb) |
| 795 | return 0; |
| 796 | |
| 797 | bo = to_vc4_bo(&drm_fb_cma_get_gem_obj(state->fb, 0)->base); |
Boris Brezillon | b9f1925 | 2017-10-19 14:57:48 +0200 | [diff] [blame] | 798 | |
| 799 | ret = vc4_bo_inc_usecnt(bo); |
| 800 | if (ret) |
| 801 | return ret; |
| 802 | |
Eric Anholt | 334dbd6 | 2017-06-21 11:49:59 -0700 | [diff] [blame] | 803 | fence = reservation_object_get_excl_rcu(bo->resv); |
| 804 | drm_atomic_set_fence_for_plane(state, fence); |
| 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
Boris Brezillon | b9f1925 | 2017-10-19 14:57:48 +0200 | [diff] [blame] | 809 | static void vc4_cleanup_fb(struct drm_plane *plane, |
| 810 | struct drm_plane_state *state) |
| 811 | { |
| 812 | struct vc4_bo *bo; |
| 813 | |
| 814 | if (plane->state->fb == state->fb || !state->fb) |
| 815 | return; |
| 816 | |
| 817 | bo = to_vc4_bo(&drm_fb_cma_get_gem_obj(state->fb, 0)->base); |
| 818 | vc4_bo_dec_usecnt(bo); |
| 819 | } |
| 820 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 821 | static const struct drm_plane_helper_funcs vc4_plane_helper_funcs = { |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 822 | .atomic_check = vc4_plane_atomic_check, |
| 823 | .atomic_update = vc4_plane_atomic_update, |
Eric Anholt | 334dbd6 | 2017-06-21 11:49:59 -0700 | [diff] [blame] | 824 | .prepare_fb = vc4_prepare_fb, |
Boris Brezillon | b9f1925 | 2017-10-19 14:57:48 +0200 | [diff] [blame] | 825 | .cleanup_fb = vc4_cleanup_fb, |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 826 | }; |
| 827 | |
| 828 | static void vc4_plane_destroy(struct drm_plane *plane) |
| 829 | { |
| 830 | drm_plane_helper_disable(plane); |
| 831 | drm_plane_cleanup(plane); |
| 832 | } |
| 833 | |
Eric Anholt | 6674a90 | 2015-12-30 11:50:22 -0800 | [diff] [blame] | 834 | /* Implements immediate (non-vblank-synced) updates of the cursor |
| 835 | * position, or falls back to the atomic helper otherwise. |
| 836 | */ |
| 837 | static int |
| 838 | vc4_update_plane(struct drm_plane *plane, |
| 839 | struct drm_crtc *crtc, |
| 840 | struct drm_framebuffer *fb, |
| 841 | int crtc_x, int crtc_y, |
| 842 | unsigned int crtc_w, unsigned int crtc_h, |
| 843 | uint32_t src_x, uint32_t src_y, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 844 | uint32_t src_w, uint32_t src_h, |
| 845 | struct drm_modeset_acquire_ctx *ctx) |
Eric Anholt | 6674a90 | 2015-12-30 11:50:22 -0800 | [diff] [blame] | 846 | { |
| 847 | struct drm_plane_state *plane_state; |
| 848 | struct vc4_plane_state *vc4_state; |
| 849 | |
| 850 | if (plane != crtc->cursor) |
| 851 | goto out; |
| 852 | |
| 853 | plane_state = plane->state; |
| 854 | vc4_state = to_vc4_plane_state(plane_state); |
| 855 | |
| 856 | if (!plane_state) |
| 857 | goto out; |
| 858 | |
Eric Anholt | 6674a90 | 2015-12-30 11:50:22 -0800 | [diff] [blame] | 859 | /* No configuring new scaling in the fast path. */ |
| 860 | if (crtc_w != plane_state->crtc_w || |
| 861 | crtc_h != plane_state->crtc_h || |
| 862 | src_w != plane_state->src_w || |
| 863 | src_h != plane_state->src_h) { |
| 864 | goto out; |
| 865 | } |
| 866 | |
Michael Zoran | 6d24c1c | 2017-02-23 17:54:31 -0800 | [diff] [blame] | 867 | if (fb != plane_state->fb) { |
| 868 | drm_atomic_set_fb_for_plane(plane->state, fb); |
| 869 | vc4_plane_async_set_fb(plane, fb); |
| 870 | } |
| 871 | |
Eric Anholt | 6674a90 | 2015-12-30 11:50:22 -0800 | [diff] [blame] | 872 | /* Set the cursor's position on the screen. This is the |
| 873 | * expected change from the drm_mode_cursor_universal() |
| 874 | * helper. |
| 875 | */ |
| 876 | plane_state->crtc_x = crtc_x; |
| 877 | plane_state->crtc_y = crtc_y; |
| 878 | |
| 879 | /* Allow changing the start position within the cursor BO, if |
| 880 | * that matters. |
| 881 | */ |
| 882 | plane_state->src_x = src_x; |
| 883 | plane_state->src_y = src_y; |
| 884 | |
| 885 | /* Update the display list based on the new crtc_x/y. */ |
| 886 | vc4_plane_atomic_check(plane, plane_state); |
| 887 | |
| 888 | /* Note that we can't just call vc4_plane_write_dlist() |
| 889 | * because that would smash the context data that the HVS is |
| 890 | * currently using. |
| 891 | */ |
| 892 | writel(vc4_state->dlist[vc4_state->pos0_offset], |
| 893 | &vc4_state->hw_dlist[vc4_state->pos0_offset]); |
| 894 | writel(vc4_state->dlist[vc4_state->pos2_offset], |
| 895 | &vc4_state->hw_dlist[vc4_state->pos2_offset]); |
| 896 | writel(vc4_state->dlist[vc4_state->ptr0_offset], |
| 897 | &vc4_state->hw_dlist[vc4_state->ptr0_offset]); |
| 898 | |
| 899 | return 0; |
| 900 | |
| 901 | out: |
| 902 | return drm_atomic_helper_update_plane(plane, crtc, fb, |
| 903 | crtc_x, crtc_y, |
| 904 | crtc_w, crtc_h, |
| 905 | src_x, src_y, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 906 | src_w, src_h, |
| 907 | ctx); |
Eric Anholt | 6674a90 | 2015-12-30 11:50:22 -0800 | [diff] [blame] | 908 | } |
| 909 | |
Daniel Stone | 423ad7b | 2017-08-08 17:44:48 +0100 | [diff] [blame] | 910 | static bool vc4_format_mod_supported(struct drm_plane *plane, |
| 911 | uint32_t format, |
| 912 | uint64_t modifier) |
| 913 | { |
| 914 | /* Support T_TILING for RGB formats only. */ |
| 915 | switch (format) { |
| 916 | case DRM_FORMAT_XRGB8888: |
| 917 | case DRM_FORMAT_ARGB8888: |
| 918 | case DRM_FORMAT_ABGR8888: |
| 919 | case DRM_FORMAT_XBGR8888: |
| 920 | case DRM_FORMAT_RGB565: |
| 921 | case DRM_FORMAT_BGR565: |
| 922 | case DRM_FORMAT_ARGB1555: |
| 923 | case DRM_FORMAT_XRGB1555: |
| 924 | return true; |
| 925 | case DRM_FORMAT_YUV422: |
| 926 | case DRM_FORMAT_YVU422: |
| 927 | case DRM_FORMAT_YUV420: |
| 928 | case DRM_FORMAT_YVU420: |
| 929 | case DRM_FORMAT_NV12: |
| 930 | case DRM_FORMAT_NV16: |
| 931 | default: |
| 932 | return (modifier == DRM_FORMAT_MOD_LINEAR); |
| 933 | } |
| 934 | } |
| 935 | |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 936 | static const struct drm_plane_funcs vc4_plane_funcs = { |
Eric Anholt | 6674a90 | 2015-12-30 11:50:22 -0800 | [diff] [blame] | 937 | .update_plane = vc4_update_plane, |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 938 | .disable_plane = drm_atomic_helper_disable_plane, |
| 939 | .destroy = vc4_plane_destroy, |
| 940 | .set_property = NULL, |
| 941 | .reset = vc4_plane_reset, |
| 942 | .atomic_duplicate_state = vc4_plane_duplicate_state, |
| 943 | .atomic_destroy_state = vc4_plane_destroy_state, |
Daniel Stone | 423ad7b | 2017-08-08 17:44:48 +0100 | [diff] [blame] | 944 | .format_mod_supported = vc4_format_mod_supported, |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 945 | }; |
| 946 | |
| 947 | struct drm_plane *vc4_plane_init(struct drm_device *dev, |
| 948 | enum drm_plane_type type) |
| 949 | { |
| 950 | struct drm_plane *plane = NULL; |
| 951 | struct vc4_plane *vc4_plane; |
| 952 | u32 formats[ARRAY_SIZE(hvs_formats)]; |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 953 | u32 num_formats = 0; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 954 | int ret = 0; |
| 955 | unsigned i; |
Daniel Stone | 423ad7b | 2017-08-08 17:44:48 +0100 | [diff] [blame] | 956 | static const uint64_t modifiers[] = { |
| 957 | DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED, |
| 958 | DRM_FORMAT_MOD_LINEAR, |
| 959 | DRM_FORMAT_MOD_INVALID |
| 960 | }; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 961 | |
| 962 | vc4_plane = devm_kzalloc(dev->dev, sizeof(*vc4_plane), |
| 963 | GFP_KERNEL); |
Colin Ian King | 7b34734 | 2017-03-16 18:54:18 +0000 | [diff] [blame] | 964 | if (!vc4_plane) |
| 965 | return ERR_PTR(-ENOMEM); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 966 | |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 967 | for (i = 0; i < ARRAY_SIZE(hvs_formats); i++) { |
| 968 | /* Don't allow YUV in cursor planes, since that means |
| 969 | * tuning on the scaler, which we don't allow for the |
| 970 | * cursor. |
| 971 | */ |
| 972 | if (type != DRM_PLANE_TYPE_CURSOR || |
| 973 | hvs_formats[i].hvs < HVS_PIXEL_FORMAT_YCBCR_YUV420_3PLANE) { |
| 974 | formats[num_formats++] = hvs_formats[i].drm; |
| 975 | } |
| 976 | } |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 977 | plane = &vc4_plane->base; |
Andrzej Pietrasiewicz | 49d29a0 | 2017-02-01 10:35:08 +0100 | [diff] [blame] | 978 | ret = drm_universal_plane_init(dev, plane, 0, |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 979 | &vc4_plane_funcs, |
Eric Anholt | fc04023 | 2015-12-30 12:25:44 -0800 | [diff] [blame] | 980 | formats, num_formats, |
Daniel Stone | 423ad7b | 2017-08-08 17:44:48 +0100 | [diff] [blame] | 981 | modifiers, type, NULL); |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 982 | |
| 983 | drm_plane_helper_add(plane, &vc4_plane_helper_funcs); |
| 984 | |
| 985 | return plane; |
Eric Anholt | c8b75bc | 2015-03-02 13:01:12 -0800 | [diff] [blame] | 986 | } |