Skip to content

Commit e02b5cc

Browse files
bparrottomba
authored andcommitted
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 <[email protected]> Signed-off-by: Neil Armstrong <[email protected]> Reviewed-by: Tomi Valkeinen <[email protected]> Signed-off-by: Tomi Valkeinen <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 19e2d26 commit e02b5cc

File tree

7 files changed

+267
-12
lines changed

7 files changed

+267
-12
lines changed

drivers/gpu/drm/omapdrm/omap_drv.c

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,110 @@ static void omap_atomic_commit_tail(struct drm_atomic_state *old_state)
117117
dispc_runtime_put(priv->dispc);
118118
}
119119

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+
120216
static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs = {
121217
.atomic_commit_tail = omap_atomic_commit_tail,
122218
};
123219

124220
static const struct drm_mode_config_funcs omap_mode_config_funcs = {
125221
.fb_create = omap_framebuffer_create,
126222
.output_poll_changed = drm_fb_helper_output_poll_changed,
127-
.atomic_check = drm_atomic_helper_check,
223+
.atomic_check = omap_atomic_check,
128224
.atomic_commit = drm_atomic_helper_commit,
129225
};
130226

drivers/gpu/drm/omapdrm/omap_fb.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ static u32 drm_rotation_to_tiler(unsigned int drm_rot)
131131
/* update ovl info for scanout, handles cases of multi-planar fb's, etc.
132132
*/
133133
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)
135137
{
136138
struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb);
137139
const struct drm_format_info *format = omap_fb->format;
@@ -218,6 +220,35 @@ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb,
218220
} else {
219221
info->p_uv_addr = 0;
220222
}
223+
224+
if (r_info) {
225+
info->width /= 2;
226+
info->out_width /= 2;
227+
228+
*r_info = *info;
229+
230+
if (fb->format->is_yuv) {
231+
if (info->width & 1) {
232+
info->width++;
233+
r_info->width--;
234+
}
235+
236+
if (info->out_width & 1) {
237+
info->out_width++;
238+
r_info->out_width--;
239+
}
240+
}
241+
242+
r_info->pos_x = info->pos_x + info->out_width;
243+
244+
r_info->paddr = get_linear_addr(fb, format, 0,
245+
x + info->width, y);
246+
if (fb->format->format == DRM_FORMAT_NV12) {
247+
r_info->p_uv_addr =
248+
get_linear_addr(fb, format, 1,
249+
x + info->width, y);
250+
}
251+
}
221252
}
222253

223254
/* pin, prepare for scanout: */

drivers/gpu/drm/omapdrm/omap_fb.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev,
2626
int omap_framebuffer_pin(struct drm_framebuffer *fb);
2727
void omap_framebuffer_unpin(struct drm_framebuffer *fb);
2828
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);
3032
bool omap_framebuffer_supports_rotation(struct drm_framebuffer *fb);
3133
void omap_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m);
3234

drivers/gpu/drm/omapdrm/omap_overlay.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ omap_plane_find_free_overlay(struct drm_device *dev, struct drm_plane *hwoverlay
6767
* next global overlay_map to be enabled when atomic transaction is valid.
6868
*/
6969
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)
7172
{
7273
/* Get the global state of the current atomic transaction */
7374
struct omap_global_state *state = omap_get_global_state(s);
7475
struct drm_plane **overlay_map = state->hwoverlay_to_plane;
75-
struct omap_hw_overlay *ovl;
76+
struct omap_hw_overlay *ovl, *r_ovl;
7677

7778
ovl = omap_plane_find_free_overlay(s->dev, overlay_map, caps, fourcc);
7879
if (!ovl)
@@ -81,8 +82,26 @@ int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane,
8182
overlay_map[ovl->idx] = plane;
8283
*overlay = ovl;
8384

85+
if (r_overlay) {
86+
r_ovl = omap_plane_find_free_overlay(s->dev, overlay_map,
87+
caps, fourcc);
88+
if (!r_ovl) {
89+
overlay_map[r_ovl->idx] = NULL;
90+
*overlay = NULL;
91+
return -ENOMEM;
92+
}
93+
94+
overlay_map[r_ovl->idx] = plane;
95+
*r_overlay = r_ovl;
96+
}
97+
8498
DBG("%s: assign to plane %s caps %x", ovl->name, plane->name, caps);
8599

100+
if (r_overlay) {
101+
DBG("%s: assign to right of plane %s caps %x",
102+
r_ovl->name, plane->name, caps);
103+
}
104+
86105
return 0;
87106
}
88107

drivers/gpu/drm/omapdrm/omap_overlay.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ struct omap_hw_overlay {
2828
int omap_hwoverlays_init(struct omap_drm_private *priv);
2929
void omap_hwoverlays_destroy(struct omap_drm_private *priv);
3030
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);
3233
void omap_overlay_release(struct drm_atomic_state *s, struct omap_hw_overlay *overlay);
3334
void omap_overlay_update_state(struct omap_drm_private *priv, struct omap_hw_overlay *overlay);
3435
#endif /* __OMAPDRM_OVERLAY_H__ */

0 commit comments

Comments
 (0)