Skip to content

Commit dd86dc2

Browse files
committed
drm/sti: implement atomic_check for the planes
Atomic update should never fail. Thus all checks must be done in the atomic_check function for each plane (gdp, hqvdp and cursor). Signed-off-by: Vincent Abriou <[email protected]> Reviewed-by: Benjamin Gaignard <[email protected]>
1 parent 0b9d041 commit dd86dc2

File tree

3 files changed

+270
-168
lines changed

3 files changed

+270
-168
lines changed

drivers/gpu/drm/sti/sti_cursor.c

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
* for STMicroelectronics.
66
* License terms: GNU General Public License (GPL), version 2
77
*/
8-
#include <drm/drmP.h>
98

10-
#include <drm/drm_atomic_helper.h>
9+
#include <drm/drm_atomic.h>
1110
#include <drm/drm_fb_cma_helper.h>
1211
#include <drm/drm_gem_cma_helper.h>
13-
#include <drm/drm_plane_helper.h>
1412

1513
#include "sti_compositor.h"
1614
#include "sti_cursor.h"
@@ -110,42 +108,39 @@ static void sti_cursor_init(struct sti_cursor *cursor)
110108
(b * 5);
111109
}
112110

113-
static void sti_cursor_atomic_update(struct drm_plane *drm_plane,
114-
struct drm_plane_state *oldstate)
111+
static int sti_cursor_atomic_check(struct drm_plane *drm_plane,
112+
struct drm_plane_state *state)
115113
{
116-
struct drm_plane_state *state = drm_plane->state;
117114
struct sti_plane *plane = to_sti_plane(drm_plane);
118115
struct sti_cursor *cursor = to_sti_cursor(plane);
119116
struct drm_crtc *crtc = state->crtc;
120-
struct sti_mixer *mixer = to_sti_mixer(crtc);
121117
struct drm_framebuffer *fb = state->fb;
122-
struct drm_display_mode *mode = &crtc->mode;
123-
int dst_x = state->crtc_x;
124-
int dst_y = state->crtc_y;
125-
int dst_w = clamp_val(state->crtc_w, 0, mode->crtc_hdisplay - dst_x);
126-
int dst_h = clamp_val(state->crtc_h, 0, mode->crtc_vdisplay - dst_y);
118+
struct drm_crtc_state *crtc_state;
119+
struct drm_display_mode *mode;
120+
int dst_x, dst_y, dst_w, dst_h;
121+
int src_w, src_h;
122+
123+
/* no need for further checks if the plane is being disabled */
124+
if (!crtc || !fb)
125+
return 0;
126+
127+
crtc_state = drm_atomic_get_crtc_state(state->state, crtc);
128+
mode = &crtc_state->mode;
129+
dst_x = state->crtc_x;
130+
dst_y = state->crtc_y;
131+
dst_w = clamp_val(state->crtc_w, 0, mode->crtc_hdisplay - dst_x);
132+
dst_h = clamp_val(state->crtc_h, 0, mode->crtc_vdisplay - dst_y);
127133
/* src_x are in 16.16 format */
128-
int src_w = state->src_w >> 16;
129-
int src_h = state->src_h >> 16;
130-
struct drm_gem_cma_object *cma_obj;
131-
u32 y, x;
132-
u32 val;
133-
134-
DRM_DEBUG_KMS("CRTC:%d (%s) drm plane:%d (%s)\n",
135-
crtc->base.id, sti_mixer_to_str(mixer),
136-
drm_plane->base.id, sti_plane_to_str(plane));
137-
DRM_DEBUG_KMS("(%dx%d)@(%d,%d)\n", dst_w, dst_h, dst_x, dst_y);
138-
139-
dev_dbg(cursor->dev, "%s %s\n", __func__,
140-
sti_plane_to_str(plane));
134+
src_w = state->src_w >> 16;
135+
src_h = state->src_h >> 16;
141136

142137
if (src_w < STI_CURS_MIN_SIZE ||
143138
src_h < STI_CURS_MIN_SIZE ||
144139
src_w > STI_CURS_MAX_SIZE ||
145140
src_h > STI_CURS_MAX_SIZE) {
146141
DRM_ERROR("Invalid cursor size (%dx%d)\n",
147142
src_w, src_h);
148-
return;
143+
return -EINVAL;
149144
}
150145

151146
/* If the cursor size has changed, re-allocated the pixmap */
@@ -169,16 +164,46 @@ static void sti_cursor_atomic_update(struct drm_plane *drm_plane,
169164
GFP_KERNEL | GFP_DMA);
170165
if (!cursor->pixmap.base) {
171166
DRM_ERROR("Failed to allocate memory for pixmap\n");
172-
return;
167+
return -EINVAL;
173168
}
174169
}
175170

176-
cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
177-
if (!cma_obj) {
171+
if (!drm_fb_cma_get_gem_obj(fb, 0)) {
178172
DRM_ERROR("Can't get CMA GEM object for fb\n");
179-
return;
173+
return -EINVAL;
180174
}
181175

176+
DRM_DEBUG_KMS("CRTC:%d (%s) drm plane:%d (%s)\n",
177+
crtc->base.id, sti_mixer_to_str(to_sti_mixer(crtc)),
178+
drm_plane->base.id, sti_plane_to_str(plane));
179+
DRM_DEBUG_KMS("(%dx%d)@(%d,%d)\n", dst_w, dst_h, dst_x, dst_y);
180+
181+
return 0;
182+
}
183+
184+
static void sti_cursor_atomic_update(struct drm_plane *drm_plane,
185+
struct drm_plane_state *oldstate)
186+
{
187+
struct drm_plane_state *state = drm_plane->state;
188+
struct sti_plane *plane = to_sti_plane(drm_plane);
189+
struct sti_cursor *cursor = to_sti_cursor(plane);
190+
struct drm_crtc *crtc = state->crtc;
191+
struct drm_framebuffer *fb = state->fb;
192+
struct drm_display_mode *mode;
193+
int dst_x, dst_y;
194+
struct drm_gem_cma_object *cma_obj;
195+
u32 y, x;
196+
u32 val;
197+
198+
if (!crtc || !fb)
199+
return;
200+
201+
mode = &crtc->mode;
202+
dst_x = state->crtc_x;
203+
dst_y = state->crtc_y;
204+
205+
cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
206+
182207
/* Convert ARGB8888 to CLUT8 */
183208
sti_cursor_argb8888_to_clut8(cursor, (u32 *)cma_obj->vaddr);
184209

@@ -212,7 +237,6 @@ static void sti_cursor_atomic_disable(struct drm_plane *drm_plane,
212237
struct drm_plane_state *oldstate)
213238
{
214239
struct sti_plane *plane = to_sti_plane(drm_plane);
215-
struct sti_mixer *mixer = to_sti_mixer(drm_plane->crtc);
216240

217241
if (!drm_plane->crtc) {
218242
DRM_DEBUG_DRIVER("drm plane:%d not enabled\n",
@@ -221,13 +245,15 @@ static void sti_cursor_atomic_disable(struct drm_plane *drm_plane,
221245
}
222246

223247
DRM_DEBUG_DRIVER("CRTC:%d (%s) drm plane:%d (%s)\n",
224-
drm_plane->crtc->base.id, sti_mixer_to_str(mixer),
248+
drm_plane->crtc->base.id,
249+
sti_mixer_to_str(to_sti_mixer(drm_plane->crtc)),
225250
drm_plane->base.id, sti_plane_to_str(plane));
226251

227252
plane->status = STI_PLANE_DISABLING;
228253
}
229254

230255
static const struct drm_plane_helper_funcs sti_cursor_helpers_funcs = {
256+
.atomic_check = sti_cursor_atomic_check,
231257
.atomic_update = sti_cursor_atomic_update,
232258
.atomic_disable = sti_cursor_atomic_disable,
233259
};

0 commit comments

Comments
 (0)