Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/omap: Add a 'right overlay' to plane state

If the drm_plane has a source width that's greater than the max width
supported by a single hw overlay, then we assign a 'r_overlay' to it in
omap_plane_atomic_check().

Both overlays should have the capabilities required to handle the source
framebuffer. The only parameters that vary between the left and right
hwoverlays are the src_w, crtc_w, src_x and crtc_x as we just even chop
the fb into left and right halves.

We also take care of not creating odd width size when dealing with YUV
formats.

Since both halves need to be 'appear' side by side the zpos is
recalculated when dealing with dual overlay cases so that the other
planes zpos is consistent.

Depending on user space usage it is possible that on occasion the number
of requested planes exceeds the numbers of overlays required to display
them. In that case a failure would be returned for the plane that cannot
be handled at that time. It is up to user space to make sure the H/W
resource are not over-subscribed.

Signed-off-by: Benoit Parrot <bparrot@ti.com>
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20211117141928.771082-10-narmstrong@baylibre.com

authored by

Benoit Parrot and committed by
Tomi Valkeinen
e02b5cc9 19e2d266

+267 -12
+97 -1
drivers/gpu/drm/omapdrm/omap_drv.c
··· 117 117 dispc_runtime_put(priv->dispc); 118 118 } 119 119 120 + static int drm_atomic_state_normalized_zpos_cmp(const void *a, const void *b) 121 + { 122 + const struct drm_plane_state *sa = *(struct drm_plane_state **)a; 123 + const struct drm_plane_state *sb = *(struct drm_plane_state **)b; 124 + 125 + if (sa->normalized_zpos != sb->normalized_zpos) 126 + return sa->normalized_zpos - sb->normalized_zpos; 127 + else 128 + return sa->plane->base.id - sb->plane->base.id; 129 + } 130 + 131 + /* 132 + * This replaces the drm_atomic_normalize_zpos to handle the dual overlay case. 133 + * 134 + * Since both halves need to be 'appear' side by side the zpos is 135 + * recalculated when dealing with dual overlay cases so that the other 136 + * planes zpos is consistent. 137 + */ 138 + static int omap_atomic_update_normalize_zpos(struct drm_device *dev, 139 + struct drm_atomic_state *state) 140 + { 141 + struct drm_crtc *crtc; 142 + struct drm_crtc_state *old_state, *new_state; 143 + struct drm_plane *plane; 144 + int c, i, n, inc; 145 + int total_planes = dev->mode_config.num_total_plane; 146 + struct drm_plane_state **states; 147 + int ret = 0; 148 + 149 + states = kmalloc_array(total_planes, sizeof(*states), GFP_KERNEL); 150 + if (!states) 151 + return -ENOMEM; 152 + 153 + for_each_oldnew_crtc_in_state(state, crtc, old_state, new_state, c) { 154 + if (old_state->plane_mask == new_state->plane_mask && 155 + !new_state->zpos_changed) 156 + continue; 157 + 158 + /* Reset plane increment and index value for every crtc */ 159 + n = 0; 160 + 161 + /* 162 + * Normalization process might create new states for planes 163 + * which normalized_zpos has to be recalculated. 164 + */ 165 + drm_for_each_plane_mask(plane, dev, new_state->plane_mask) { 166 + struct drm_plane_state *plane_state = 167 + drm_atomic_get_plane_state(new_state->state, 168 + plane); 169 + if (IS_ERR(plane_state)) { 170 + ret = PTR_ERR(plane_state); 171 + goto done; 172 + } 173 + states[n++] = plane_state; 174 + } 175 + 176 + sort(states, n, sizeof(*states), 177 + drm_atomic_state_normalized_zpos_cmp, NULL); 178 + 179 + for (i = 0, inc = 0; i < n; i++) { 180 + plane = states[i]->plane; 181 + 182 + states[i]->normalized_zpos = i + inc; 183 + DRM_DEBUG_ATOMIC("[PLANE:%d:%s] updated normalized zpos value %d\n", 184 + plane->base.id, plane->name, 185 + states[i]->normalized_zpos); 186 + 187 + if (is_omap_plane_dual_overlay(states[i])) 188 + inc++; 189 + } 190 + new_state->zpos_changed = true; 191 + } 192 + 193 + done: 194 + kfree(states); 195 + return ret; 196 + } 197 + 198 + static int omap_atomic_check(struct drm_device *dev, 199 + struct drm_atomic_state *state) 200 + { 201 + int ret; 202 + 203 + ret = drm_atomic_helper_check(dev, state); 204 + if (ret) 205 + return ret; 206 + 207 + if (dev->mode_config.normalize_zpos) { 208 + ret = omap_atomic_update_normalize_zpos(dev, state); 209 + if (ret) 210 + return ret; 211 + } 212 + 213 + return 0; 214 + } 215 + 120 216 static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs = { 121 217 .atomic_commit_tail = omap_atomic_commit_tail, 122 218 }; ··· 220 124 static const struct drm_mode_config_funcs omap_mode_config_funcs = { 221 125 .fb_create = omap_framebuffer_create, 222 126 .output_poll_changed = drm_fb_helper_output_poll_changed, 223 - .atomic_check = drm_atomic_helper_check, 127 + .atomic_check = omap_atomic_check, 224 128 .atomic_commit = drm_atomic_helper_commit, 225 129 }; 226 130
+32 -1
drivers/gpu/drm/omapdrm/omap_fb.c
··· 131 131 /* update ovl info for scanout, handles cases of multi-planar fb's, etc. 132 132 */ 133 133 void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, 134 - struct drm_plane_state *state, struct omap_overlay_info *info) 134 + struct drm_plane_state *state, 135 + struct omap_overlay_info *info, 136 + struct omap_overlay_info *r_info) 135 137 { 136 138 struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb); 137 139 const struct drm_format_info *format = omap_fb->format; ··· 219 217 } 220 218 } else { 221 219 info->p_uv_addr = 0; 220 + } 221 + 222 + if (r_info) { 223 + info->width /= 2; 224 + info->out_width /= 2; 225 + 226 + *r_info = *info; 227 + 228 + if (fb->format->is_yuv) { 229 + if (info->width & 1) { 230 + info->width++; 231 + r_info->width--; 232 + } 233 + 234 + if (info->out_width & 1) { 235 + info->out_width++; 236 + r_info->out_width--; 237 + } 238 + } 239 + 240 + r_info->pos_x = info->pos_x + info->out_width; 241 + 242 + r_info->paddr = get_linear_addr(fb, format, 0, 243 + x + info->width, y); 244 + if (fb->format->format == DRM_FORMAT_NV12) { 245 + r_info->p_uv_addr = 246 + get_linear_addr(fb, format, 1, 247 + x + info->width, y); 248 + } 222 249 } 223 250 } 224 251
+3 -1
drivers/gpu/drm/omapdrm/omap_fb.h
··· 26 26 int omap_framebuffer_pin(struct drm_framebuffer *fb); 27 27 void omap_framebuffer_unpin(struct drm_framebuffer *fb); 28 28 void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, 29 - struct drm_plane_state *state, struct omap_overlay_info *info); 29 + struct drm_plane_state *state, 30 + struct omap_overlay_info *info, 31 + struct omap_overlay_info *r_info); 30 32 bool omap_framebuffer_supports_rotation(struct drm_framebuffer *fb); 31 33 void omap_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m); 32 34
+21 -2
drivers/gpu/drm/omapdrm/omap_overlay.c
··· 67 67 * next global overlay_map to be enabled when atomic transaction is valid. 68 68 */ 69 69 int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane, 70 - u32 caps, u32 fourcc, struct omap_hw_overlay **overlay) 70 + u32 caps, u32 fourcc, struct omap_hw_overlay **overlay, 71 + struct omap_hw_overlay **r_overlay) 71 72 { 72 73 /* Get the global state of the current atomic transaction */ 73 74 struct omap_global_state *state = omap_get_global_state(s); 74 75 struct drm_plane **overlay_map = state->hwoverlay_to_plane; 75 - struct omap_hw_overlay *ovl; 76 + struct omap_hw_overlay *ovl, *r_ovl; 76 77 77 78 ovl = omap_plane_find_free_overlay(s->dev, overlay_map, caps, fourcc); 78 79 if (!ovl) ··· 82 81 overlay_map[ovl->idx] = plane; 83 82 *overlay = ovl; 84 83 84 + if (r_overlay) { 85 + r_ovl = omap_plane_find_free_overlay(s->dev, overlay_map, 86 + caps, fourcc); 87 + if (!r_ovl) { 88 + overlay_map[r_ovl->idx] = NULL; 89 + *overlay = NULL; 90 + return -ENOMEM; 91 + } 92 + 93 + overlay_map[r_ovl->idx] = plane; 94 + *r_overlay = r_ovl; 95 + } 96 + 85 97 DBG("%s: assign to plane %s caps %x", ovl->name, plane->name, caps); 98 + 99 + if (r_overlay) { 100 + DBG("%s: assign to right of plane %s caps %x", 101 + r_ovl->name, plane->name, caps); 102 + } 86 103 87 104 return 0; 88 105 }
+2 -1
drivers/gpu/drm/omapdrm/omap_overlay.h
··· 28 28 int omap_hwoverlays_init(struct omap_drm_private *priv); 29 29 void omap_hwoverlays_destroy(struct omap_drm_private *priv); 30 30 int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane, 31 - u32 caps, u32 fourcc, struct omap_hw_overlay **overlay); 31 + u32 caps, u32 fourcc, struct omap_hw_overlay **overlay, 32 + struct omap_hw_overlay **r_overlay); 32 33 void omap_overlay_release(struct drm_atomic_state *s, struct omap_hw_overlay *overlay); 33 34 void omap_overlay_update_state(struct omap_drm_private *priv, struct omap_hw_overlay *overlay); 34 35 #endif /* __OMAPDRM_OVERLAY_H__ */
+111 -6
drivers/gpu/drm/omapdrm/omap_plane.c
··· 24 24 struct drm_plane_state base; 25 25 26 26 struct omap_hw_overlay *overlay; 27 + struct omap_hw_overlay *r_overlay; /* right overlay */ 27 28 }; 28 29 29 30 #define to_omap_plane(x) container_of(x, struct omap_plane, base) ··· 33 32 struct drm_plane base; 34 33 enum omap_plane_id id; 35 34 }; 35 + 36 + bool is_omap_plane_dual_overlay(struct drm_plane_state *state) 37 + { 38 + struct omap_plane_state *omap_state = to_omap_plane_state(state); 39 + 40 + return !!omap_state->r_overlay; 41 + } 36 42 37 43 static int omap_plane_prepare_fb(struct drm_plane *plane, 38 44 struct drm_plane_state *new_state) ··· 69 61 plane); 70 62 struct omap_plane_state *new_omap_state; 71 63 struct omap_plane_state *old_omap_state; 72 - struct omap_overlay_info info; 73 - enum omap_plane_id ovl_id; 64 + struct omap_overlay_info info, r_info; 65 + enum omap_plane_id ovl_id, r_ovl_id; 74 66 int ret; 67 + bool dual_ovl; 75 68 76 69 new_omap_state = to_omap_plane_state(new_state); 77 70 old_omap_state = to_omap_plane_state(old_state); 78 71 72 + dual_ovl = is_omap_plane_dual_overlay(new_state); 73 + 79 74 /* Cleanup previously held overlay if needed */ 80 75 if (old_omap_state->overlay) 81 76 omap_overlay_update_state(priv, old_omap_state->overlay); 77 + if (old_omap_state->r_overlay) 78 + omap_overlay_update_state(priv, old_omap_state->r_overlay); 82 79 83 80 if (!new_omap_state->overlay) { 84 81 DBG("[PLANE:%d:%s] no overlay attached", plane->base.id, plane->name); ··· 106 93 info.color_encoding = new_state->color_encoding; 107 94 info.color_range = new_state->color_range; 108 95 96 + r_info = info; 97 + 109 98 /* update scanout: */ 110 - omap_framebuffer_update_scanout(new_state->fb, new_state, &info); 99 + omap_framebuffer_update_scanout(new_state->fb, new_state, &info, 100 + dual_ovl ? &r_info : NULL); 111 101 112 102 DBG("%s: %dx%d -> %dx%d (%d)", 113 103 new_omap_state->overlay->name, info.width, info.height, 114 104 info.out_width, info.out_height, info.screen_width); 115 105 DBG("%d,%d %pad %pad", info.pos_x, info.pos_y, 116 106 &info.paddr, &info.p_uv_addr); 107 + 108 + if (dual_ovl) { 109 + r_ovl_id = new_omap_state->r_overlay->id; 110 + /* 111 + * If the current plane uses 2 hw planes the very next 112 + * zorder is used by the r_overlay so we just use the 113 + * main overlay zorder + 1 114 + */ 115 + r_info.zorder = info.zorder + 1; 116 + 117 + DBG("%s: %dx%d -> %dx%d (%d)", 118 + new_omap_state->r_overlay->name, 119 + r_info.width, r_info.height, 120 + r_info.out_width, r_info.out_height, r_info.screen_width); 121 + DBG("%d,%d %pad %pad", r_info.pos_x, r_info.pos_y, 122 + &r_info.paddr, &r_info.p_uv_addr); 123 + } 117 124 118 125 /* and finally, update omapdss: */ 119 126 ret = dispc_ovl_setup(priv->dispc, ovl_id, &info, ··· 147 114 } 148 115 149 116 dispc_ovl_enable(priv->dispc, ovl_id, true); 117 + 118 + if (dual_ovl) { 119 + ret = dispc_ovl_setup(priv->dispc, r_ovl_id, &r_info, 120 + omap_crtc_timings(new_state->crtc), false, 121 + omap_crtc_channel(new_state->crtc)); 122 + if (ret) { 123 + dev_err(plane->dev->dev, "Failed to setup plane right-overlay %s\n", 124 + plane->name); 125 + dispc_ovl_enable(priv->dispc, r_ovl_id, false); 126 + dispc_ovl_enable(priv->dispc, ovl_id, false); 127 + return; 128 + } 129 + 130 + dispc_ovl_enable(priv->dispc, r_ovl_id, true); 131 + } 150 132 } 151 133 152 134 static void omap_plane_atomic_disable(struct drm_plane *plane, ··· 187 139 188 140 omap_overlay_update_state(priv, old_omap_state->overlay); 189 141 new_omap_state->overlay = NULL; 142 + 143 + if (is_omap_plane_dual_overlay(old_state)) { 144 + omap_overlay_update_state(priv, old_omap_state->r_overlay); 145 + new_omap_state->r_overlay = NULL; 146 + } 190 147 } 191 148 192 149 #define FRAC_16_16(mult, div) (((mult) << 16) / (div)) ··· 207 154 struct omap_plane_state *omap_state = to_omap_plane_state(new_plane_state); 208 155 struct omap_global_state *omap_overlay_global_state; 209 156 struct drm_crtc_state *crtc_state; 157 + bool new_r_hw_overlay = false; 210 158 bool new_hw_overlay = false; 211 159 u32 max_width, max_height; 212 160 struct drm_crtc *crtc; ··· 250 196 251 197 if (!new_plane_state->visible) { 252 198 omap_overlay_release(state, omap_state->overlay); 199 + omap_overlay_release(state, omap_state->r_overlay); 253 200 omap_state->overlay = NULL; 201 + omap_state->r_overlay = NULL; 254 202 return 0; 255 203 } 256 204 ··· 269 213 if (new_plane_state->src_h > max_height || new_plane_state->crtc_h > height) 270 214 return -EINVAL; 271 215 272 - if (new_plane_state->src_w > max_width || new_plane_state->crtc_w > width) 273 - return -EINVAL; 216 + 217 + if (new_plane_state->src_w > max_width || new_plane_state->crtc_w > width) { 218 + bool is_fourcc_yuv = new_plane_state->fb->format->is_yuv; 219 + 220 + if (is_fourcc_yuv && (((new_plane_state->src_w >> 16) / 2 & 1) || 221 + new_plane_state->crtc_w / 2 & 1)) { 222 + /* 223 + * When calculating the split overlay width 224 + * and it yield an odd value we will need to adjust 225 + * the indivual width +/- 1. So make sure it fits 226 + */ 227 + if (new_plane_state->src_w <= ((2 * width - 1) << 16) && 228 + new_plane_state->crtc_w <= (2 * width - 1)) 229 + new_r_hw_overlay = true; 230 + else 231 + return -EINVAL; 232 + } else { 233 + if (new_plane_state->src_w <= (2 * max_width) && 234 + new_plane_state->crtc_w <= (2 * width)) 235 + new_r_hw_overlay = true; 236 + else 237 + return -EINVAL; 238 + } 239 + } 274 240 275 241 if (new_plane_state->rotation != DRM_MODE_ROTATE_0 && 276 242 !omap_framebuffer_supports_rotation(new_plane_state->fb)) ··· 317 239 new_hw_overlay = true; 318 240 } 319 241 242 + /* 243 + * check if we need two overlays and only have 1 or 244 + * if we had 2 overlays but will only need 1 245 + */ 246 + if ((new_r_hw_overlay && !omap_state->r_overlay) || 247 + (!new_r_hw_overlay && omap_state->r_overlay)) 248 + new_hw_overlay = true; 249 + 320 250 if (new_hw_overlay) { 321 251 struct omap_hw_overlay *old_ovl = omap_state->overlay; 252 + struct omap_hw_overlay *old_r_ovl = omap_state->r_overlay; 322 253 struct omap_hw_overlay *new_ovl = NULL; 254 + struct omap_hw_overlay *new_r_ovl = NULL; 323 255 324 256 omap_overlay_release(state, old_ovl); 257 + omap_overlay_release(state, old_r_ovl); 325 258 326 - ret = omap_overlay_assign(state, plane, caps, fourcc, &new_ovl); 259 + ret = omap_overlay_assign(state, plane, caps, fourcc, &new_ovl, 260 + new_r_hw_overlay ? &new_r_ovl : NULL); 327 261 if (ret) { 328 262 DBG("%s: failed to assign hw_overlay", plane->name); 329 263 omap_state->overlay = NULL; 264 + omap_state->r_overlay = NULL; 330 265 return ret; 331 266 } 332 267 333 268 omap_state->overlay = new_ovl; 269 + if (new_r_hw_overlay) 270 + omap_state->r_overlay = new_r_ovl; 271 + else 272 + omap_state->r_overlay = NULL; 334 273 } 335 274 336 275 DBG("plane: %s overlay_id: %d", plane->name, omap_state->overlay->id); 276 + 277 + if (omap_state->r_overlay) 278 + DBG("plane: %s r_overlay_id: %d", plane->name, omap_state->r_overlay->id); 337 279 338 280 return 0; 339 281 } ··· 442 344 __drm_atomic_helper_plane_duplicate_state(plane, &state->base); 443 345 444 346 state->overlay = current_state->overlay; 347 + state->r_overlay = current_state->r_overlay; 445 348 446 349 return &state->base; 447 350 } ··· 458 359 omap_state->overlay->caps); 459 360 else 460 361 drm_printf(p, "\toverlay=None\n"); 362 + if (omap_state->r_overlay) 363 + drm_printf(p, "\tr_overlay=%s (caps=0x%x)\n", 364 + omap_state->r_overlay->name, 365 + omap_state->r_overlay->caps); 366 + else 367 + drm_printf(p, "\tr_overlay=None\n"); 461 368 } 462 369 463 370 static int omap_plane_atomic_set_property(struct drm_plane *plane,
+1
drivers/gpu/drm/omapdrm/omap_plane.h
··· 22 22 u32 possible_crtcs); 23 23 void omap_plane_install_properties(struct drm_plane *plane, 24 24 struct drm_mode_object *obj); 25 + bool is_omap_plane_dual_overlay(struct drm_plane_state *state); 25 26 26 27 #endif /* __OMAPDRM_PLANE_H__ */