From patchwork Mon Apr 16 12:16:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 898610 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fdH/BS0z"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40PnTm6w5kz9s1R for ; Mon, 16 Apr 2018 22:18:20 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755220AbeDPMRj (ORCPT ); Mon, 16 Apr 2018 08:17:39 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:41300 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755178AbeDPMRh (ORCPT ); Mon, 16 Apr 2018 08:17:37 -0400 Received: by mail-pg0-f67.google.com with SMTP id e2so3736440pgv.8; Mon, 16 Apr 2018 05:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=QnFwCekthXQLdK7Lgx+X47IIc+E3cLltWVZn6shT9sc=; b=fdH/BS0zDmirPNKc79IkihSGs+pks9+czk19+eI9QRgIGft3G9u3ksYggxxm9Hyjzy 0rsplerNWz2LyTMUPuexu+wEZdgn/HgsByoPjgoRALJKvpp9GxKcD4BE4/uKZEdqOnB+ 3hk+rqD3kbr1IIaO6iPaO+8iV72V2wDMujG8rSerGG1LYz0rL/rffixjK8SFpuX7ISSz 0JMwjF/5cstxuV5eHGJpgGrO8vmvT7QGiBR4NHxRKgZKWU60NP0Y8CoKffwFZ5htMDkx DaQMjc8wPZIIXHX6v7+JCTln0sUodWpQDyXGXUoem8ijpy5fZci2z6IuwuaJR7SuOTbp jmuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=QnFwCekthXQLdK7Lgx+X47IIc+E3cLltWVZn6shT9sc=; b=R80yjHx5OzdnsLH3HM7LahogZNTzKfhmcMV8ClHxAcd2ocqdZa3BFZI6xUPihVk/pb A6Y8Kvh81k4sgENpiURUgMsVO+3BYplLUORKs5CJDwPYhuPMTZKCuqZBghRJ6fUTOhBa XbppOs82FNXN5l8hravUmGSZTqho/1oCUpb1Pk1yylaY0M6mZNeGnElrm9tHtHThlICN PaFNYUmciBdqryvSbe25+O6EW0rnSLMaiwpQqbxv4UAU6EETKzpXTy0YAQh71QcKpuRV zy9UxUrt3zBr/+3lOdwVy9dAkQnVmo1NVwSTBzz+fzmfDz03E6i3D3Au63qJpvs1N3IG MTmw== X-Gm-Message-State: ALQs6tApzB+BTg7dr+10R6WyTP3VGSNy96ySaFWE+UnhhR9yd4PgFbUO FMjRdB7k+UcDh3R5VCEhZK0= X-Google-Smtp-Source: AIpwx49IY+rwcWDZtOPk1VBsVWm7ECPJWq5TAvDWomSApTlQ7TggEeXlsYhk5nNPGqK0ZKbueZJf7g== X-Received: by 10.98.51.69 with SMTP id z66mr2034809pfz.0.1523881056827; Mon, 16 Apr 2018 05:17:36 -0700 (PDT) Received: from localhost.localdomain (ppp109-252-91-201.pppoe.spdop.ru. [109.252.91.201]) by smtp.gmail.com with ESMTPSA id p1sm23524153pfp.48.2018.04.16.05.17.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Apr 2018 05:17:36 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding Cc: dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/4] drm/tegra: plane: Add custom colorkey properties for older Tegra's Date: Mon, 16 Apr 2018 15:16:27 +0300 Message-Id: X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org Colorkey'ing allows to draw on top of overlapping planes, like for example on top of a video plane. Older Tegra's have a limited colorkey'ing capability such that blending features are reduced when colorkey'ing is enabled. In particular dependent weighting isn't possible, meaning that cursors plane can't be displayed properly. In most cases it is more useful to display content on top of video overlay, sacrificing mouse cursor in the area of three planes intersection with colorkey mismatch. This patch adds a custom colorkey properties to primary plane and CRTC's of older Tegra's, allowing userspace like Opentegra Xorg driver to implement colorkey support for XVideo extension. Signed-off-by: Dmitry Osipenko --- drivers/gpu/drm/tegra/dc.c | 166 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/tegra/dc.h | 18 +++- drivers/gpu/drm/tegra/plane.c | 40 ++++++++ drivers/gpu/drm/tegra/plane.h | 9 +- 4 files changed, 231 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c index a54eefea2513..b19e954a223f 100644 --- a/drivers/gpu/drm/tegra/dc.c +++ b/drivers/gpu/drm/tegra/dc.c @@ -172,6 +172,24 @@ static void tegra_plane_setup_blending_legacy(struct tegra_plane *plane) state = to_tegra_plane_state(plane->base.state); + /* + * Assuming default zPos window order, enable color keying for cases + * of overlapping with topping windows, excluding overlap with + * window B. Due to limited HW capabilities, this allows to draw + * primary plane on top of video overlay in areas where key isn't + * matching. Though window C will be completely transparent in a + * region of three windows intersection + key mismatch. + */ + if (state->ckey0_enabled) { + background[0] |= BLEND_COLOR_KEY_0; + background[2] |= BLEND_COLOR_KEY_0; + } + + if (state->ckey1_enabled) { + background[0] |= BLEND_COLOR_KEY_1; + background[2] |= BLEND_COLOR_KEY_1; + } + if (state->opaque) { /* * Since custom fix-weight blending isn't utilized and weight @@ -729,6 +747,35 @@ static unsigned long tegra_plane_get_possible_crtcs(struct drm_device *drm) return 1 << drm->mode_config.num_crtc; } +static void tegra_plane_create_legacy_properties(struct tegra_plane *plane, + struct drm_device *drm) +{ + plane->props.color_key0 = drm_property_create_bool( + drm, 0, "color key 0"); + plane->props.color_key1 = drm_property_create_bool( + drm, 0, "color key 1"); + + if (!plane->props.color_key0 || + !plane->props.color_key1) + goto err_cleanup; + + drm_object_attach_property(&plane->base.base, plane->props.color_key0, + false); + drm_object_attach_property(&plane->base.base, plane->props.color_key1, + false); + + return; + +err_cleanup: + if (plane->props.color_key0) + drm_property_destroy(drm, plane->props.color_key0); + + if (plane->props.color_key1) + drm_property_destroy(drm, plane->props.color_key1); + + dev_err(plane->dc->dev, "failed to create legacy plane properties\n"); +} + static struct drm_plane *tegra_primary_plane_create(struct drm_device *drm, struct tegra_dc *dc) { @@ -764,6 +811,9 @@ static struct drm_plane *tegra_primary_plane_create(struct drm_device *drm, drm_plane_helper_add(&plane->base, &tegra_plane_helper_funcs); drm_plane_create_zpos_property(&plane->base, plane->index, 0, 255); + if (dc->soc->legacy_blending) + tegra_plane_create_legacy_properties(plane, drm); + return &plane->base; } @@ -1153,6 +1203,8 @@ tegra_crtc_atomic_duplicate_state(struct drm_crtc *crtc) copy->pclk = state->pclk; copy->div = state->div; copy->planes = state->planes; + copy->ckey0 = state->ckey0; + copy->ckey1 = state->ckey1; return ©->base; } @@ -1537,6 +1589,50 @@ static void tegra_dc_disable_vblank(struct drm_crtc *crtc) tegra_dc_writel(dc, value, DC_CMD_INT_MASK); } +static int tegra_crtc_atomic_set_property(struct drm_crtc *crtc, + struct drm_crtc_state *state, + struct drm_property *property, + uint64_t value) +{ + struct tegra_dc_state *tegra_state = to_dc_state(state); + struct tegra_dc *dc = to_tegra_dc(crtc); + + if (property == dc->props.ckey0_lower) + tegra_state->ckey0.lower = value; + else if (property == dc->props.ckey0_upper) + tegra_state->ckey0.upper = value; + else if (property == dc->props.ckey1_lower) + tegra_state->ckey1.lower = value; + else if (property == dc->props.ckey1_upper) + tegra_state->ckey1.upper = value; + else + return -EINVAL; + + return 0; +} + +static int tegra_crtc_atomic_get_property(struct drm_crtc *crtc, + const struct drm_crtc_state *state, + struct drm_property *property, + uint64_t *value) +{ + struct tegra_dc_state *tegra_state = to_dc_state(state); + struct tegra_dc *dc = to_tegra_dc(crtc); + + if (property == dc->props.ckey0_lower) + *value = tegra_state->ckey0.lower; + else if (property == dc->props.ckey0_upper) + *value = tegra_state->ckey0.upper; + else if (property == dc->props.ckey1_lower) + *value = tegra_state->ckey1.lower; + else if (property == dc->props.ckey1_upper) + *value = tegra_state->ckey1.upper; + else + return -EINVAL; + + return 0; +} + static const struct drm_crtc_funcs tegra_crtc_funcs = { .page_flip = drm_atomic_helper_page_flip, .set_config = drm_atomic_helper_set_config, @@ -1549,6 +1645,8 @@ static const struct drm_crtc_funcs tegra_crtc_funcs = { .get_vblank_counter = tegra_dc_get_vblank_counter, .enable_vblank = tegra_dc_enable_vblank, .disable_vblank = tegra_dc_disable_vblank, + .atomic_set_property = tegra_crtc_atomic_set_property, + .atomic_get_property = tegra_crtc_atomic_get_property, }; static int tegra_dc_set_timings(struct tegra_dc *dc, @@ -1883,6 +1981,18 @@ static void tegra_crtc_atomic_flush(struct drm_crtc *crtc, struct tegra_dc *dc = to_tegra_dc(crtc); u32 value; + if (dc->soc->legacy_blending) { + tegra_dc_writel(dc, state->ckey0.lower, + DC_DISP_COLOR_KEY0_LOWER); + tegra_dc_writel(dc, state->ckey0.upper, + DC_DISP_COLOR_KEY0_UPPER); + + tegra_dc_writel(dc, state->ckey1.lower, + DC_DISP_COLOR_KEY1_LOWER); + tegra_dc_writel(dc, state->ckey1.upper, + DC_DISP_COLOR_KEY1_UPPER); + } + value = state->planes << 8 | GENERAL_UPDATE; tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL); value = tegra_dc_readl(dc, DC_CMD_STATE_CONTROL); @@ -1944,6 +2054,56 @@ static irqreturn_t tegra_dc_irq(int irq, void *data) return IRQ_HANDLED; } +static int tegra_dc_create_legacy_properties(struct tegra_dc *dc, + struct drm_device *drm) +{ + /* + * Each color key value is represented in RGB888 format. + * All planes share the same color key values and free to choose + * among the ckey0 and ckey1. + */ + dc->props.ckey0_lower = drm_property_create_range( + drm, 0, "color key 0 lower margin", 0, 0xffffff); + dc->props.ckey0_upper = drm_property_create_range( + drm, 0, "color key 0 upper margin", 0, 0xffffff); + dc->props.ckey1_lower = drm_property_create_range( + drm, 0, "color key 1 lower margin", 0, 0xffffff); + dc->props.ckey1_upper = drm_property_create_range( + drm, 0, "color key 1 upper margin", 0, 0xffffff); + + if (!dc->props.ckey0_lower || + !dc->props.ckey0_upper || + !dc->props.ckey1_lower || + !dc->props.ckey1_upper) + goto err_cleanup; + + drm_object_attach_property(&dc->base.base, dc->props.ckey0_lower, + 0x000000); + drm_object_attach_property(&dc->base.base, dc->props.ckey0_upper, + 0x000000); + drm_object_attach_property(&dc->base.base, dc->props.ckey1_lower, + 0x000000); + drm_object_attach_property(&dc->base.base, dc->props.ckey1_upper, + 0x000000); + + return 0; + +err_cleanup: + if (dc->props.ckey0_lower) + drm_property_destroy(drm, dc->props.ckey0_lower); + + if (dc->props.ckey0_upper) + drm_property_destroy(drm, dc->props.ckey0_upper); + + if (dc->props.ckey1_lower) + drm_property_destroy(drm, dc->props.ckey1_lower); + + if (dc->props.ckey1_upper) + drm_property_destroy(drm, dc->props.ckey1_upper); + + return -ENOMEM; +} + static int tegra_dc_init(struct host1x_client *client) { struct drm_device *drm = dev_get_drvdata(client->parent); @@ -2031,6 +2191,12 @@ static int tegra_dc_init(struct host1x_client *client) goto cleanup; } + if (dc->soc->legacy_blending) { + err = tegra_dc_create_legacy_properties(dc, drm); + if (err < 0) + dev_err(dc->dev, "failed to create CRTC properties\n"); + } + return 0; cleanup: diff --git a/drivers/gpu/drm/tegra/dc.h b/drivers/gpu/drm/tegra/dc.h index 3156006e75c6..3913d047abac 100644 --- a/drivers/gpu/drm/tegra/dc.h +++ b/drivers/gpu/drm/tegra/dc.h @@ -18,6 +18,11 @@ struct tegra_output; +struct tegra_dc_color_key_state { + u32 lower; + u32 upper; +}; + struct tegra_dc_state { struct drm_crtc_state base; @@ -26,9 +31,13 @@ struct tegra_dc_state { unsigned int div; u32 planes; + + struct tegra_dc_color_key_state ckey0; + struct tegra_dc_color_key_state ckey1; }; -static inline struct tegra_dc_state *to_dc_state(struct drm_crtc_state *state) +static inline struct tegra_dc_state * +to_dc_state(const struct drm_crtc_state *state) { if (state) return container_of(state, struct tegra_dc_state, base); @@ -94,6 +103,13 @@ struct tegra_dc { const struct tegra_dc_soc_info *soc; struct iommu_domain *domain; + + struct { + struct drm_property *ckey0_lower; + struct drm_property *ckey0_upper; + struct drm_property *ckey1_lower; + struct drm_property *ckey1_upper; + } props; }; static inline struct tegra_dc * diff --git a/drivers/gpu/drm/tegra/plane.c b/drivers/gpu/drm/tegra/plane.c index 0406c2ef432c..4d794f2b44df 100644 --- a/drivers/gpu/drm/tegra/plane.c +++ b/drivers/gpu/drm/tegra/plane.c @@ -57,6 +57,8 @@ tegra_plane_atomic_duplicate_state(struct drm_plane *plane) copy->format = state->format; copy->swap = state->swap; copy->opaque = state->opaque; + copy->ckey0_enabled = state->ckey0_enabled; + copy->ckey1_enabled = state->ckey1_enabled; for (i = 0; i < 2; i++) copy->blending[i] = state->blending[i]; @@ -86,6 +88,42 @@ static bool tegra_plane_format_mod_supported(struct drm_plane *plane, return false; } +static int tegra_plane_set_property(struct drm_plane *plane, + struct drm_plane_state *state, + struct drm_property *property, + uint64_t value) +{ + struct tegra_plane_state *tegra_state = to_tegra_plane_state(state); + struct tegra_plane *tegra = to_tegra_plane(plane); + + if (property == tegra->props.color_key0) + tegra_state->ckey0_enabled = value; + else if (property == tegra->props.color_key1) + tegra_state->ckey1_enabled = value; + else + return -EINVAL; + + return 0; +} + +static int tegra_plane_get_property(struct drm_plane *plane, + const struct drm_plane_state *state, + struct drm_property *property, + uint64_t *value) +{ + struct tegra_plane_state *tegra_state = to_tegra_plane_state(state); + struct tegra_plane *tegra = to_tegra_plane(plane); + + if (property == tegra->props.color_key0) + *value = tegra_state->ckey0_enabled; + else if (property == tegra->props.color_key1) + *value = tegra_state->ckey1_enabled; + else + return -EINVAL; + + return 0; +} + const struct drm_plane_funcs tegra_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane, @@ -94,6 +132,8 @@ const struct drm_plane_funcs tegra_plane_funcs = { .atomic_duplicate_state = tegra_plane_atomic_duplicate_state, .atomic_destroy_state = tegra_plane_atomic_destroy_state, .format_mod_supported = tegra_plane_format_mod_supported, + .atomic_set_property = tegra_plane_set_property, + .atomic_get_property = tegra_plane_get_property, }; int tegra_plane_state_add(struct tegra_plane *plane, diff --git a/drivers/gpu/drm/tegra/plane.h b/drivers/gpu/drm/tegra/plane.h index 7360ddfafee8..dafecea73b29 100644 --- a/drivers/gpu/drm/tegra/plane.h +++ b/drivers/gpu/drm/tegra/plane.h @@ -19,6 +19,11 @@ struct tegra_plane { struct tegra_dc *dc; unsigned int offset; unsigned int index; + + struct { + struct drm_property *color_key0; + struct drm_property *color_key1; + } props; }; struct tegra_cursor { @@ -49,10 +54,12 @@ struct tegra_plane_state { /* used for legacy blending support only */ struct tegra_plane_legacy_blending_state blending[2]; bool opaque; + bool ckey0_enabled; + bool ckey1_enabled; }; static inline struct tegra_plane_state * -to_tegra_plane_state(struct drm_plane_state *state) +to_tegra_plane_state(const struct drm_plane_state *state) { if (state) return container_of(state, struct tegra_plane_state, base);