From patchwork Mon Sep 10 03:03:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11262 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 1376623E00 for ; Mon, 10 Sep 2012 03:05:20 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 9D0BBA183FA for ; Mon, 10 Sep 2012 03:05:19 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id k11so2235201iea.11 for ; Sun, 09 Sep 2012 20:05:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :dkim-signature:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=N4ei0NW5PLomgLnpeKsy7/GduvdEpf86vmno3DFtMM8=; b=ed/mKf08+MMIU5/R5J9flaL02bMyW+CUuz9V4pD/tSkM+VGGHqOpUHjlSJGoKPuhjT 76gZqAT04yGiA65/n37tN/th6y5skCBouSyhG1Vkd88umH5mHkgf3svTGTsv4iNg9Xj4 zn+w/h4tA/nVdaScWJIBNgoeob8G8WVU5Ac+ZEHevQ7ywPw5zOFJ85bW1q45QOXGmpNw vSAIINpJGpNHlbt1wRV2S+bxeoMOOSPjq85p/iyCgd/ll4SCgjBr6CB8xPad6PHHtPJu q1nKOuVapsJYXz7h0QXtK91JKQbRn8W399ry0MLAeeo/bKU/7WG9SAyycLi88Avx2TzW DDaQ== Received: by 10.50.191.227 with SMTP id hb3mr733399igc.43.1347246319413; Sun, 09 Sep 2012 20:05:19 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp70795igc; Sun, 9 Sep 2012 20:05:19 -0700 (PDT) Received: by 10.60.13.41 with SMTP id e9mr8388413oec.15.1347246318970; Sun, 09 Sep 2012 20:05:18 -0700 (PDT) Received: from mail-ob0-f178.google.com (mail-ob0-f178.google.com [209.85.214.178]) by mx.google.com with ESMTPS id is1si7284901obc.87.2012.09.09.20.05.18 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 09 Sep 2012 20:05:18 -0700 (PDT) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.214.178 as permitted sender) client-ip=209.85.214.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.214.178 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by mail-ob0-f178.google.com with SMTP id wd20so2865791obb.37 for ; Sun, 09 Sep 2012 20:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=N4ei0NW5PLomgLnpeKsy7/GduvdEpf86vmno3DFtMM8=; b=CRz/z0RczGJjdg8cJycMqer2+h8vavPQ26Tsy15Bv+PuIdRHr/z1GZQhieHUjv73VV PT4iuYvRuC85IPH5jfVTKXM/i/I1UZ3hwaQ6KFy78uMVcLvSOcV3X0dppcSHNk6tnljS T08zYaWtYg4gxhPeoCdxsFcFJeiqJdXEQzibhj9mT13HC3nT10eRU4patW/mbvfTCJEa 9zAL4KvMD8SiHwtnVqSwjn7xtiv+FpmOMbVgc3Z3QaqpfGZ4Yd10tpMuBPmjB76+vKTA OBQGmiJu86Q/ohAQfNtlV7vjwyGo1Qtn5PT7/OYlEqS2O/3kOB/IJEt09whdTspkJy+T y08A== Received: by 10.60.19.168 with SMTP id g8mr12910677oee.134.1347246318841; Sun, 09 Sep 2012 20:05:18 -0700 (PDT) Received: from localhost (ppp-70-129-131-42.dsl.rcsntx.swbell.net. [70.129.131.42]) by mx.google.com with ESMTPS id j10sm9648580oej.10.2012.09.09.20.05.17 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 09 Sep 2012 20:05:18 -0700 (PDT) Sender: Rob Clark From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: patches@linaro.org, ville.syrjala@linux.intel.com, jbarnes@virtuousgeek.org, daniel.vetter@ffwll.ch, Rob Clark Subject: [RFC 5/9] drm: add drm_plane_state Date: Sun, 9 Sep 2012 22:03:18 -0500 Message-Id: <1347246202-24249-6-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1347246202-24249-1-git-send-email-rob.clark@linaro.org> References: <1347246202-24249-1-git-send-email-rob.clark@linaro.org> X-Gm-Message-State: ALoCoQmq4xlRRegkfv19bgQL7N9e25EgCNHx2s4hBrSX3Zlt6POstmSqbcRStbW8b2DZoxAYE3jX From: Rob Clark Break the mutable state of a plane out into a separate structure. This makes it easier to have some helpers for plane->set_property() and for checking for invalid params. The idea is that individual drivers can wrap the state struct in their own struct which adds driver specific parameters, for easy build-up of state across multiple set_property() calls and for easy atomic commit or roll- back. The same should be done for CRTC, encoder, and connector, but this patch only includes the first part (plane). --- drivers/gpu/drm/drm_crtc.c | 97 +++++++++++++++++++++++++++++++++++++++++--- include/drm/drm_crtc.h | 38 +++++++++++++---- 2 files changed, 123 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index e680fbe..ce6fa6a 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -411,7 +411,7 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb) } list_for_each_entry(plane, &dev->mode_config.plane_list, head) { - if (plane->fb == fb) { + if (plane->state->fb == fb) { /* should turn off the crtc */ drm_mode_plane_set_obj_prop(plane, state, config->prop_crtc_id, 0); drm_mode_plane_set_obj_prop(plane, state, config->prop_fb_id, 0); @@ -747,6 +747,93 @@ void drm_plane_cleanup(struct drm_plane *plane) } EXPORT_SYMBOL(drm_plane_cleanup); +int drm_plane_check_state(struct drm_plane *plane, + struct drm_plane_state *state) +{ + unsigned int fb_width, fb_height; + struct drm_framebuffer *fb = state->fb; + int i; + + fb_width = fb->width << 16; + fb_height = fb->height << 16; + + /* Check whether this plane supports the fb pixel format. */ + for (i = 0; i < plane->format_count; i++) + if (fb->pixel_format == plane->format_types[i]) + break; + if (i == plane->format_count) { + DRM_DEBUG_KMS("Invalid pixel format 0x%08x\n", fb->pixel_format); + return -EINVAL; + } + + /* Make sure source coordinates are inside the fb. */ + if (state->src_w > fb_width || + state->src_x > fb_width - state->src_w || + state->src_h > fb_height || + state->src_y > fb_height - state->src_h) { + DRM_DEBUG_KMS("Invalid source coordinates " + "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n", + state->src_w >> 16, + ((state->src_w & 0xffff) * 15625) >> 10, + state->src_h >> 16, + ((state->src_h & 0xffff) * 15625) >> 10, + state->src_x >> 16, + ((state->src_x & 0xffff) * 15625) >> 10, + state->src_y >> 16, + ((state->src_y & 0xffff) * 15625) >> 10); + return -ENOSPC; + } + + /* Give drivers some help against integer overflows */ + if (state->crtc_w > INT_MAX || + state->crtc_x > INT_MAX - (int32_t) state->crtc_w || + state->crtc_h > INT_MAX || + state->crtc_y > INT_MAX - (int32_t) state->crtc_h) { + DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n", + state->crtc_w, state->crtc_h, + state->crtc_x, state->crtc_y); + return -ERANGE; + } + + return 0; +} +EXPORT_SYMBOL(drm_plane_check_state); + +int drm_plane_set_property(struct drm_plane *plane, + struct drm_plane_state *state, + struct drm_property *property, uint64_t value) +{ + struct drm_device *dev = plane->dev; + struct drm_mode_config *config = &dev->mode_config; + + if (property == config->prop_fb_id) { + state->fb = U642VOID(value); + } else if (property == config->prop_crtc_id) { + state->crtc = U642VOID(value); + } else if (property == config->prop_crtc_x) { + state->crtc_x = *(int32_t *)&value; + } else if (property == config->prop_crtc_y) { + state->crtc_y = *(int32_t *)&value; + } else if (property == config->prop_crtc_w) { + state->crtc_w = value; + } else if (property == config->prop_crtc_h) { + state->crtc_h = value; + } else if (property == config->prop_src_x) { + state->src_x = value; + } else if (property == config->prop_src_y) { + state->src_y = value; + } else if (property == config->prop_src_w) { + state->src_w = value; + } else if (property == config->prop_src_h) { + state->src_h = value; + } else { + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL(drm_plane_set_property); + /** * drm_mode_create - create a new display mode * @dev: DRM device @@ -1790,13 +1877,13 @@ int drm_mode_getplane(struct drm_device *dev, void *data, } plane = obj_to_plane(obj); - if (plane->crtc) - plane_resp->crtc_id = plane->crtc->base.id; + if (plane->state->crtc) + plane_resp->crtc_id = plane->state->crtc->base.id; else plane_resp->crtc_id = 0; - if (plane->fb) - plane_resp->fb_id = plane->fb->base.id; + if (plane->state->fb) + plane_resp->fb_id = plane->state->fb->base.id; else plane_resp->fb_id = 0; diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 546026c..a2ba164 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -628,6 +628,26 @@ struct drm_plane_funcs { }; /** + * drm_plane_state - mutable plane state + * @crtc: currently bound CRTC + * @fb: currently bound fb + * @enabled: enabled flag + */ +struct drm_plane_state { + struct drm_crtc *crtc; + struct drm_framebuffer *fb; + bool enabled; + + /* Signed dest location allows it to be partially off screen */ + int32_t crtc_x, crtc_y; + uint32_t crtc_w, crtc_h; + + /* Source values are 16.16 fixed point */ + uint32_t src_x, src_y; + uint32_t src_h, src_w; +}; + +/** * drm_plane - central DRM plane control structure * @dev: DRM device this plane belongs to * @head: for list management @@ -635,11 +655,9 @@ struct drm_plane_funcs { * @possible_crtcs: pipes this plane can be bound to * @format_types: array of formats supported by this plane * @format_count: number of formats supported - * @crtc: currently bound CRTC - * @fb: currently bound fb + * @state: the mutable state * @gamma_size: size of gamma table * @gamma_store: gamma correction table - * @enabled: enabled flag * @funcs: helper functions * @helper_private: storage for drver layer * @properties: property tracking for this plane @@ -654,15 +672,16 @@ struct drm_plane { uint32_t *format_types; uint32_t format_count; - struct drm_crtc *crtc; - struct drm_framebuffer *fb; + /* + * State that can be updated from userspace, and atomically + * commited or rolled back: + */ + struct drm_plane_state *state; /* CRTC gamma size for reporting to userspace */ uint32_t gamma_size; uint16_t *gamma_store; - bool enabled; - const struct drm_plane_funcs *funcs; void *helper_private; @@ -874,6 +893,11 @@ extern int drm_plane_init(struct drm_device *dev, const uint32_t *formats, uint32_t format_count, bool priv); extern void drm_plane_cleanup(struct drm_plane *plane); +extern int drm_plane_check_state(struct drm_plane *plane, + struct drm_plane_state *state); +extern int drm_plane_set_property(struct drm_plane *plane, + struct drm_plane_state *state, + struct drm_property *property, uint64_t value); extern void drm_encoder_cleanup(struct drm_encoder *encoder);