Commit 64c32b49 authored by Ville Syrjälä's avatar Ville Syrjälä

drm: Add local 'plane' variable for primary/cursor planes

Make the code a bit more readable by storing the plane pointer in a
local variable rather than having to do crtc->{primary,cursor} all the
time.
Signed-off-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180322152313.6561-6-ville.syrjala@linux.intel.comReviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
parent 5e78d01f
...@@ -402,6 +402,7 @@ int drm_mode_getcrtc(struct drm_device *dev, ...@@ -402,6 +402,7 @@ int drm_mode_getcrtc(struct drm_device *dev,
{ {
struct drm_mode_crtc *crtc_resp = data; struct drm_mode_crtc *crtc_resp = data;
struct drm_crtc *crtc; struct drm_crtc *crtc;
struct drm_plane *plane;
if (!drm_core_check_feature(dev, DRIVER_MODESET)) if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EINVAL; return -EINVAL;
...@@ -410,21 +411,23 @@ int drm_mode_getcrtc(struct drm_device *dev, ...@@ -410,21 +411,23 @@ int drm_mode_getcrtc(struct drm_device *dev,
if (!crtc) if (!crtc)
return -ENOENT; return -ENOENT;
plane = crtc->primary;
crtc_resp->gamma_size = crtc->gamma_size; crtc_resp->gamma_size = crtc->gamma_size;
drm_modeset_lock(&crtc->primary->mutex, NULL); drm_modeset_lock(&plane->mutex, NULL);
if (crtc->primary->state && crtc->primary->state->fb) if (plane->state && plane->state->fb)
crtc_resp->fb_id = crtc->primary->state->fb->base.id; crtc_resp->fb_id = plane->state->fb->base.id;
else if (!crtc->primary->state && crtc->primary->fb) else if (!plane->state && plane->fb)
crtc_resp->fb_id = crtc->primary->fb->base.id; crtc_resp->fb_id = plane->fb->base.id;
else else
crtc_resp->fb_id = 0; crtc_resp->fb_id = 0;
if (crtc->primary->state) { if (plane->state) {
crtc_resp->x = crtc->primary->state->src_x >> 16; crtc_resp->x = plane->state->src_x >> 16;
crtc_resp->y = crtc->primary->state->src_y >> 16; crtc_resp->y = plane->state->src_y >> 16;
} }
drm_modeset_unlock(&crtc->primary->mutex); drm_modeset_unlock(&plane->mutex);
drm_modeset_lock(&crtc->mutex, NULL); drm_modeset_lock(&crtc->mutex, NULL);
if (crtc->state) { if (crtc->state) {
...@@ -554,6 +557,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, ...@@ -554,6 +557,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
struct drm_mode_config *config = &dev->mode_config; struct drm_mode_config *config = &dev->mode_config;
struct drm_mode_crtc *crtc_req = data; struct drm_mode_crtc *crtc_req = data;
struct drm_crtc *crtc; struct drm_crtc *crtc;
struct drm_plane *plane;
struct drm_connector **connector_set = NULL, *connector; struct drm_connector **connector_set = NULL, *connector;
struct drm_framebuffer *fb = NULL; struct drm_framebuffer *fb = NULL;
struct drm_display_mode *mode = NULL; struct drm_display_mode *mode = NULL;
...@@ -580,6 +584,8 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, ...@@ -580,6 +584,8 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
} }
DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
plane = crtc->primary;
mutex_lock(&crtc->dev->mode_config.mutex); mutex_lock(&crtc->dev->mode_config.mutex);
drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE); drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
retry: retry:
...@@ -590,12 +596,12 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, ...@@ -590,12 +596,12 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
/* If we have a mode we need a framebuffer. */ /* If we have a mode we need a framebuffer. */
/* If we pass -1, set the mode with the currently bound fb */ /* If we pass -1, set the mode with the currently bound fb */
if (crtc_req->fb_id == -1) { if (crtc_req->fb_id == -1) {
if (!crtc->primary->fb) { if (!plane->fb) {
DRM_DEBUG_KMS("CRTC doesn't have current FB\n"); DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
fb = crtc->primary->fb; fb = plane->fb;
/* Make refcounting symmetric with the lookup path. */ /* Make refcounting symmetric with the lookup path. */
drm_framebuffer_get(fb); drm_framebuffer_get(fb);
} else { } else {
...@@ -627,8 +633,8 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, ...@@ -627,8 +633,8 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
* match real hardware capabilities. Skip the check in that * match real hardware capabilities. Skip the check in that
* case. * case.
*/ */
if (!crtc->primary->format_default) { if (!plane->format_default) {
ret = drm_plane_check_pixel_format(crtc->primary, ret = drm_plane_check_pixel_format(plane,
fb->format->format, fb->format->format,
fb->modifier); fb->modifier);
if (ret) { if (ret) {
......
...@@ -756,6 +756,7 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc, ...@@ -756,6 +756,7 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc,
struct drm_modeset_acquire_ctx *ctx) struct drm_modeset_acquire_ctx *ctx)
{ {
struct drm_device *dev = crtc->dev; struct drm_device *dev = crtc->dev;
struct drm_plane *plane = crtc->cursor;
struct drm_framebuffer *fb = NULL; struct drm_framebuffer *fb = NULL;
struct drm_mode_fb_cmd2 fbreq = { struct drm_mode_fb_cmd2 fbreq = {
.width = req->width, .width = req->width,
...@@ -769,8 +770,8 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc, ...@@ -769,8 +770,8 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc,
uint32_t src_w = 0, src_h = 0; uint32_t src_w = 0, src_h = 0;
int ret = 0; int ret = 0;
BUG_ON(!crtc->cursor); BUG_ON(!plane);
WARN_ON(crtc->cursor->crtc != crtc && crtc->cursor->crtc != NULL); WARN_ON(plane->crtc != crtc && plane->crtc != NULL);
/* /*
* Obtain fb we'll be using (either new or existing) and take an extra * Obtain fb we'll be using (either new or existing) and take an extra
...@@ -790,7 +791,7 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc, ...@@ -790,7 +791,7 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc,
fb = NULL; fb = NULL;
} }
} else { } else {
fb = crtc->cursor->fb; fb = plane->fb;
if (fb) if (fb)
drm_framebuffer_get(fb); drm_framebuffer_get(fb);
} }
...@@ -810,7 +811,7 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc, ...@@ -810,7 +811,7 @@ static int drm_mode_cursor_universal(struct drm_crtc *crtc,
src_h = fb->height << 16; src_h = fb->height << 16;
} }
ret = __setplane_internal(crtc->cursor, crtc, fb, ret = __setplane_internal(plane, crtc, fb,
crtc_x, crtc_y, crtc_w, crtc_h, crtc_x, crtc_y, crtc_w, crtc_h,
0, 0, src_w, src_h, ctx); 0, 0, src_w, src_h, ctx);
...@@ -931,6 +932,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, ...@@ -931,6 +932,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
{ {
struct drm_mode_crtc_page_flip_target *page_flip = data; struct drm_mode_crtc_page_flip_target *page_flip = data;
struct drm_crtc *crtc; struct drm_crtc *crtc;
struct drm_plane *plane;
struct drm_framebuffer *fb = NULL; struct drm_framebuffer *fb = NULL;
struct drm_pending_vblank_event *e = NULL; struct drm_pending_vblank_event *e = NULL;
u32 target_vblank = page_flip->sequence; u32 target_vblank = page_flip->sequence;
...@@ -959,6 +961,8 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, ...@@ -959,6 +961,8 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
if (!crtc) if (!crtc)
return -ENOENT; return -ENOENT;
plane = crtc->primary;
if (crtc->funcs->page_flip_target) { if (crtc->funcs->page_flip_target) {
u32 current_vblank; u32 current_vblank;
int r; int r;
...@@ -1003,11 +1007,11 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, ...@@ -1003,11 +1007,11 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
ret = drm_modeset_lock(&crtc->mutex, &ctx); ret = drm_modeset_lock(&crtc->mutex, &ctx);
if (ret) if (ret)
goto out; goto out;
ret = drm_modeset_lock(&crtc->primary->mutex, &ctx); ret = drm_modeset_lock(&plane->mutex, &ctx);
if (ret) if (ret)
goto out; goto out;
if (crtc->primary->fb == NULL) { if (plane->fb == NULL) {
/* The framebuffer is currently unbound, presumably /* The framebuffer is currently unbound, presumably
* due to a hotplug event, that userspace has not * due to a hotplug event, that userspace has not
* yet discovered. * yet discovered.
...@@ -1023,7 +1027,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, ...@@ -1023,7 +1027,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
} }
if (crtc->state) { if (crtc->state) {
const struct drm_plane_state *state = crtc->primary->state; const struct drm_plane_state *state = plane->state;
ret = drm_framebuffer_check_src_coords(state->src_x, ret = drm_framebuffer_check_src_coords(state->src_x,
state->src_y, state->src_y,
...@@ -1036,7 +1040,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, ...@@ -1036,7 +1040,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
if (ret) if (ret)
goto out; goto out;
if (crtc->primary->fb->format != fb->format) { if (plane->fb->format != fb->format) {
DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n"); DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n");
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
...@@ -1060,7 +1064,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, ...@@ -1060,7 +1064,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
} }
} }
crtc->primary->old_fb = crtc->primary->fb; plane->old_fb = plane->fb;
if (crtc->funcs->page_flip_target) if (crtc->funcs->page_flip_target)
ret = crtc->funcs->page_flip_target(crtc, fb, e, ret = crtc->funcs->page_flip_target(crtc, fb, e,
page_flip->flags, page_flip->flags,
...@@ -1073,9 +1077,9 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, ...@@ -1073,9 +1077,9 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT)
drm_event_cancel_free(dev, &e->base); drm_event_cancel_free(dev, &e->base);
/* Keep the old fb, don't unref it. */ /* Keep the old fb, don't unref it. */
crtc->primary->old_fb = NULL; plane->old_fb = NULL;
} else { } else {
crtc->primary->fb = fb; plane->fb = fb;
/* Unref only the old framebuffer. */ /* Unref only the old framebuffer. */
fb = NULL; fb = NULL;
} }
...@@ -1083,9 +1087,9 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, ...@@ -1083,9 +1087,9 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev,
out: out:
if (fb) if (fb)
drm_framebuffer_put(fb); drm_framebuffer_put(fb);
if (crtc->primary->old_fb) if (plane->old_fb)
drm_framebuffer_put(crtc->primary->old_fb); drm_framebuffer_put(plane->old_fb);
crtc->primary->old_fb = NULL; plane->old_fb = NULL;
if (ret == -EDEADLK) { if (ret == -EDEADLK) {
ret = drm_modeset_backoff(&ctx); ret = drm_modeset_backoff(&ctx);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment