From patchwork Thu Feb 11 02:32:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 8276211 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0348ABEEE5 for ; Thu, 11 Feb 2016 02:33:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B7AC420376 for ; Thu, 11 Feb 2016 02:33:51 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5D18D2037E for ; Thu, 11 Feb 2016 02:33:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9B316720BF; Wed, 10 Feb 2016 18:33:47 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id 690527206B; Wed, 10 Feb 2016 18:33:46 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP; 10 Feb 2016 18:33:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,428,1449561600"; d="scan'208";a="45968772" Received: from mdroper-hswdev.fm.intel.com (HELO mdroper-hswdev) ([10.1.134.207]) by fmsmga004.fm.intel.com with ESMTP; 10 Feb 2016 18:33:46 -0800 Received: from mattrope by mdroper-hswdev with local (Exim 4.84) (envelope-from ) id 1aTh4k-0001vr-3L; Wed, 10 Feb 2016 18:33:46 -0800 From: Matt Roper To: intel-gfx@lists.freedesktop.org Subject: [PATCH v2 1/2] drm: Add infrastructure for CRTC background color property (v2) Date: Wed, 10 Feb 2016 18:32:58 -0800 Message-Id: <1455157979-7341-2-git-send-email-matthew.d.roper@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455157979-7341-1-git-send-email-matthew.d.roper@intel.com> References: <1455157979-7341-1-git-send-email-matthew.d.roper@intel.com> Cc: dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To support CRTC background color, we need a way of communicating RGB color values to the DRM. However there is often a mismatch between how userspace wants to represent the color value vs how it must be programmed into the hardware; this mismatch can easily lead to non-obvious bugs. Let's create a kernel-side property type that standardizes the user<->kernel format and add some macros that allow drivers to extract the bits they care about without having to worry about the internal representation. This RGBA property type may also be useful for future properties like color keys. These properties are still exposed to userspace as range properties, so the only userspace change we need are some helpers to build RGBA values appropriately. v2: - Just use 'struct rgba' rather than a typedef as our opaque RGBA datatype. (Emil) - Actually use drm_property_create_rgba() to create the background color property. (Bob) - Add helper to build 64-bit RGBA internal value in appropriate format (e.g., for the initial value when attaching a property). (Bob) Cc: dri-devel@lists.freedesktop.org Signed-off-by: Matt Roper --- drivers/gpu/drm/drm_atomic.c | 4 ++ drivers/gpu/drm/drm_crtc.c | 39 +++++++++++++++++++ include/drm/drm_crtc.h | 92 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 8fb469c..e47c250 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -413,6 +413,8 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc, if (property == config->prop_active) state->active = val; + else if (property == config->prop_background_color) + state->background_color.v = val; else if (property == config->prop_mode_id) { struct drm_property_blob *mode = drm_property_lookup_blob(dev, val); @@ -456,6 +458,8 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc, *val = state->active; else if (property == config->prop_mode_id) *val = (state->mode_blob) ? state->mode_blob->base.id : 0; + else if (property == config->prop_background_color) + *val = state->background_color.v; else if (crtc->funcs->atomic_get_property) return crtc->funcs->atomic_get_property(crtc, state, property, val); else diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 65258ac..f86fd2d 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -3933,6 +3933,30 @@ struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags, EXPORT_SYMBOL(drm_property_create_bool); /** + * drm_property_create_rgba - create a new RGBA property type + * @dev: drm device + * @flags: flags specifying the property type + * @name: name of the property + * + * This creates a new generic drm property which can then be attached to a drm + * object with drm_object_attach_property. The returned property object must be + * freed with drm_property_destroy. + * + * Userspace should use the DRM_RGBA() macro to build values with the proper + * bit layout. + * + * Returns: + * A pointer to the newly created property on success, NULL on failure. + */ +struct drm_property *drm_property_create_rgba(struct drm_device *dev, int flags, + const char *name) +{ + return drm_property_create_range(dev, flags, name, + 0, GENMASK_ULL(63, 0)); +} +EXPORT_SYMBOL(drm_property_create_rgba); + +/** * drm_property_add_enum - add a possible value to an enumeration property * @property: enumeration property to change * @index: index of the new enumeration @@ -5943,6 +5967,21 @@ struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev, EXPORT_SYMBOL(drm_mode_create_rotation_property); /** + * drm_mode_create_background_color_property - create CRTC color property + * @dev: DRM device + * + * Creates a property to represent CRTC background/canvas color. Called by a + * driver the first time it's needed, must be attached to desired CRTC's. + */ +struct drm_property * +drm_mode_create_background_color_property(struct drm_device *dev) +{ + return drm_property_create_rgba(dev, DRM_MODE_PROP_ATOMIC, + "background_color"); +} +EXPORT_SYMBOL(drm_mode_create_background_color_property); + +/** * DOC: Tile group * * Tile groups are used to represent tiled monitors with a unique diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 8c7fb3d..e59dace 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -297,6 +297,90 @@ struct drm_connector_helper_funcs; struct drm_plane_helper_funcs; /** + * struct drm_rgba - RGBA property value type + * @v: Internal representation of RGBA, stored in 16bpc format + * + * Structure to abstract away the representation of RGBA values with precision + * up to 16 bits per color component. This is primarily intended for use with + * DRM properties that need to take a color value since we don't want userspace + * to have to worry about the bit layout expected by the underlying hardware. + * + * We wrap the value in a structure here so that the compiler will flag any + * accidental attempts by driver code to directly attempt bitwise operations + * that could potentially misinterpret the value. Drivers should instead use + * the DRM_RGBA_{RED,GREEN,BLUE,ALPHA}BITS() macros to obtain the component + * bits and then build values in the format their hardware expects. + */ +struct drm_rgba { + uint64_t v; +}; + +/** + * drm_rgba - Build RGBA property values + * @bpc: Bits per component value for @red, @green, @blue, and @alpha parameters + * @red: Red component value + * @green: Green component value + * @blue: Blue component value + * @alpha: Alpha component value + * + * Helper to build RGBA 16bpc color values with the bits laid out in the format + * expected by DRM RGBA properties. + * + * Returns: + * An RGBA structure encapsulating the requested RGBA value. + */ +static inline struct drm_rgba +drm_rgba(unsigned bpc, + uint16_t red, + uint16_t green, + uint16_t blue, + uint16_t alpha) +{ + int shift; + struct drm_rgba val; + + if (WARN_ON(bpc > 16)) + bpc = 16; + + /* + * If we were provided with fewer than 16 bpc, shift the value we + * received into the most significant bits. + */ + shift = 16 - bpc; + + val.v = red << shift; + val.v <<= 16; + val.v |= green << shift; + val.v <<= 16; + val.v |= blue << shift; + val.v <<= 16; + val.v |= alpha << shift; + + return val; +} + +static inline uint16_t +drm_rgba_bits(struct drm_rgba c, unsigned compshift, unsigned bits) { + uint64_t val; + + if (WARN_ON(bits > 16)) + bits = 16; + + val = c.v & GENMASK_ULL(compshift + 15, compshift); + return val >> (compshift + 16 - bits); +} + +/* + * Macros to access the individual color components of an RGBA property value. + * If the requested number of bits is less than 16, only the most significant + * bits of the color component will be returned. + */ +#define DRM_RGBA_REDBITS(c, bits) drm_rgba_bits(c, 48, bits) +#define DRM_RGBA_GREENBITS(c, bits) drm_rgba_bits(c, 32, bits) +#define DRM_RGBA_BLUEBITS(c, bits) drm_rgba_bits(c, 16, bits) +#define DRM_RGBA_ALPHABITS(c, bits) drm_rgba_bits(c, 0, bits) + +/** * struct drm_crtc_state - mutable CRTC state * @crtc: backpointer to the CRTC * @enable: whether the CRTC should be enabled, gates all other state @@ -312,6 +396,7 @@ struct drm_plane_helper_funcs; * update to ensure framebuffer cleanup isn't done too early * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings * @mode: current mode timings + * @background_color: background/canvas color of regions not covered by planes * @event: optional pointer to a DRM event to signal upon completion of the * state update * @state: backpointer to global drm_atomic_state @@ -355,6 +440,9 @@ struct drm_crtc_state { /* blob property to expose current mode to atomic userspace */ struct drm_property_blob *mode_blob; + /* CRTC background color */ + struct drm_rgba background_color; + struct drm_pending_vblank_event *event; struct drm_atomic_state *state; @@ -2101,6 +2189,7 @@ struct drm_mode_config { struct drm_property *prop_crtc_id; struct drm_property *prop_active; struct drm_property *prop_mode_id; + struct drm_property *prop_background_color; /* DVI-I properties */ struct drm_property *dvi_i_subconnector_property; @@ -2371,6 +2460,8 @@ struct drm_property *drm_property_create_object(struct drm_device *dev, int flags, const char *name, uint32_t type); struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags, const char *name); +struct drm_property *drm_property_create_rgba(struct drm_device *dev, + int flags, const char *name); struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, size_t length, const void *data); @@ -2503,6 +2594,7 @@ extern int drm_format_plane_height(int height, uint32_t format, int plane); extern const char *drm_get_format_name(uint32_t format); extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev, unsigned int supported_rotations); +extern struct drm_property *drm_mode_create_background_color_property(struct drm_device *dev); extern unsigned int drm_rotation_simplify(unsigned int rotation, unsigned int supported_rotations);