From patchwork Mon Dec 24 09:15:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Qian Wang X-Patchwork-Id: 10742121 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7598214DE for ; Mon, 24 Dec 2018 09:15:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6413C28F9E for ; Mon, 24 Dec 2018 09:15:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5743028FA6; Mon, 24 Dec 2018 09:15:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 58F9E28F9E for ; Mon, 24 Dec 2018 09:15:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7969E6E545; Mon, 24 Dec 2018 09:15:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10082.outbound.protection.outlook.com [40.107.1.82]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2BEB46E545 for ; Mon, 24 Dec 2018 09:15:52 +0000 (UTC) Received: from AM3PR08MB0611.eurprd08.prod.outlook.com (10.163.188.149) by AM3PR08MB0183.eurprd08.prod.outlook.com (10.161.35.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1446.19; Mon, 24 Dec 2018 09:15:49 +0000 Received: from AM3PR08MB0611.eurprd08.prod.outlook.com ([fe80::3c73:534c:9c6e:352d]) by AM3PR08MB0611.eurprd08.prod.outlook.com ([fe80::3c73:534c:9c6e:352d%2]) with mapi id 15.20.1446.026; Mon, 24 Dec 2018 09:15:49 +0000 From: "james qian wang (Arm Technology China)" To: Liviu Dudau Subject: [PATCH 2/5] drm/komeda: Add komeda_pipeline/component_get_state_and_set_user Thread-Topic: [PATCH 2/5] drm/komeda: Add komeda_pipeline/component_get_state_and_set_user Thread-Index: AQHUm2lCeELNQHzQ80OmA4uEgAdeNA== Date: Mon, 24 Dec 2018 09:15:48 +0000 Message-ID: <20181224091450.2643-3-james.qian.wang@arm.com> References: <20181224091450.2643-1-james.qian.wang@arm.com> In-Reply-To: <20181224091450.2643-1-james.qian.wang@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [113.29.88.7] x-clientproxiedby: SY2PR01CA0039.ausprd01.prod.outlook.com (2603:10c6:1:15::27) To AM3PR08MB0611.eurprd08.prod.outlook.com (2a01:111:e400:c408::21) x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM3PR08MB0183; 6:B1PyX/cUXQ+u9SCdqU7dGWvewFzV2jYpVnX2cBgxT1nZqTvlhzPU9JiV/YAcBlO7I9Utmr6bP4mgHgymEijv/QX+6uxWyyZHIl1U488coys4neM/jNcJqkEnZ5fICuTzZbLNym6PiRww3XRmJt6xJn3KS4fQX8r2LZxogBGs7nmSAwUTSNRXsTXhksQXCF1SkEFlluAw+bvyN8SrNeDpcUOLmYbj9NBedT8H48XWx83l4vTNpr4gRIMtsLb4dZ28YrNDsQz3FEijP1U1HBx2fMnegSBdDYTn7a3jOFrtFEJKnHhGSqI6TtIjcUlg/B5dfCGuulwmToyHz5fK9e9XHuiTzr4XU3GWSyym3p4iA5zQCmYLKuxxuwNGQPzAVT4z8lMifdslTQc5BxsDWfysFd3hKbsAHIM/wbAqYKvvf2LtXahNEeSI/rqCMuoDJD7XAm8LQfPKAHZcLp2ysWCz8w==; 5:QqmynkiYPv8UGPKs+rY3hvUlWZ3wxR507hrs9F3nMEPHe+3ltDWOojtTZF98vXtYa6dWuH28mF80+Ysbux0iqqcY2AlTh/IZnaY0FPTmIdTgwHBIrZj3SHfNW6U2u+WjJvdhjM96F6oaUHaRLXIZM2uBzT73vWcz1n3eAF43Sd8=; 7:c9fz/T9ttil4BC9gRDTCOx5EEAlE6scZZZeH/eP+rbBPAkUMBb/JueeCXQUASfba4XTpay1x1l6KlGbqEybSkYXBkMm6JRQjUX0lrnMtIoFvCvBZPSlHbF0Kkl/n1VCfCXVLTKtF6rNfXCs3eytpeQ== x-ms-office365-filtering-correlation-id: 821e39d3-9aaa-4bd9-505e-08d6698064a6 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM3PR08MB0183; x-ms-traffictypediagnostic: AM3PR08MB0183: nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(908002)(999002)(5005026)(6040522)(2401047)(8121501046)(10201501046)(93006095)(93001095)(3231475)(944501520)(52105112)(3002001)(6055026)(6041310)(20161123560045)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:AM3PR08MB0183; BCL:0; PCL:0; RULEID:; SRVR:AM3PR08MB0183; x-forefront-prvs: 0896BFCE6C x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(396003)(366004)(39850400004)(346002)(376002)(189003)(199004)(5660300001)(575784001)(54906003)(7736002)(37006003)(256004)(14444005)(6862004)(4326008)(316002)(55236004)(386003)(86362001)(106356001)(14454004)(6506007)(186003)(99286004)(2906002)(105586002)(8936002)(97736004)(76176011)(36756003)(476003)(2616005)(71200400001)(478600001)(1076003)(6486002)(486006)(81156014)(71190400001)(3846002)(26005)(52116002)(68736007)(6116002)(6436002)(11346002)(8676002)(446003)(25786009)(305945005)(102836004)(103116003)(6636002)(81166006)(53936002)(6512007)(66066001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM3PR08MB0183; H:AM3PR08MB0611.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: IfPBLmFiHOxaIJYyIN3fzuDsTgqiO0OWui1HGaXNMk+1BFJ4VqutYOclekLo/PdtobUx5EBDj8euSNd+HKDM3hG5F/W13uAsfzF4wrGz4mPekTftyjYuK9jvQO4x4ippS9TbHIKL4HcN+//Rbqfc8w7KWnwPuJwXdztgYVCxqjdBNYM1jiglA+4FEGPk4YTMKqP7Tc80fABGsoFhB3/SzcIOIiJqsLSm3tAE2rfekuBYmmY7GCE9zJG1agImILMTBbpUL25GJU/ZXC1YRGy/I/33umwmuuMrczid8b64FI4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 821e39d3-9aaa-4bd9-505e-08d6698064a6 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Dec 2018 09:15:48.8808 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR08MB0183 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nd , Ayan Halder , "Tiannan Zhu \(Arm Technology China\)" , "airlied@linux.ie" , "Jonathan Chai \(Arm Technology China\)" , Alexandru-Cosmin Gheorghe , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "Julien Yin \(Arm Technology China\)" , "yamada.masahiro@socionext.com" , "james qian wang \(Arm Technology China\)" , "malidp@foss.arm.com" , "Yiqi Kang \(Arm Technology China\)" , "maxime.ripard@bootlin.com" , "thomas Sun \(Arm Technology China\)" , "Jin Gao \(Arm Technology China\)" , "Lowry Li \(Arm Technology China\)" , "sean@poorly.run" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP get_state_and_set_user packed get_state and set_user into one function, which get pipeline/component state for a specific pipeline/component, if success set the user to it. Signed-off-by: James (Qian) Wang --- drivers/gpu/drm/arm/display/komeda/Makefile | 1 + .../drm/arm/display/komeda/komeda_pipeline.c | 2 + .../drm/arm/display/komeda/komeda_pipeline.h | 7 + .../display/komeda/komeda_pipeline_state.c | 148 ++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c diff --git a/drivers/gpu/drm/arm/display/komeda/Makefile b/drivers/gpu/drm/arm/display/komeda/Makefile index d593125236ae..62bd1bff66a3 100644 --- a/drivers/gpu/drm/arm/display/komeda/Makefile +++ b/drivers/gpu/drm/arm/display/komeda/Makefile @@ -9,6 +9,7 @@ komeda-y := \ komeda_dev.o \ komeda_format_caps.o \ komeda_pipeline.o \ + komeda_pipeline_state.o \ komeda_framebuffer.o \ komeda_kms.o \ komeda_crtc.o \ diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.c b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.c index 611e8c53e248..1c9205d0e61b 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.c @@ -34,6 +34,8 @@ komeda_pipeline_add(struct komeda_dev *mdev, size_t size, pipe->id = mdev->n_pipelines; pipe->funcs = funcs; + drm_modeset_lock_init(&pipe->mutex); + mdev->pipelines[mdev->n_pipelines] = pipe; mdev->n_pipelines++; diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h index 4f98fdb21557..201fcf074fa1 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h +++ b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h @@ -295,6 +295,13 @@ struct komeda_pipeline_funcs { struct komeda_pipeline { /** @obj: link pipeline as private obj of drm_atomic_state */ struct drm_private_obj obj; + + /** + * @mutex: + * + * protects pipeline_state, since pipeline can be shared between crtcs + */ + struct drm_modeset_lock mutex; /** @mdev: the parent komeda_dev */ struct komeda_dev *mdev; /** @pxlclk: pixel clock */ diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c new file mode 100644 index 000000000000..7ce006b9e5f7 --- /dev/null +++ b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c @@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * (C) COPYRIGHT 2018 ARM Limited. All rights reserved. + * Author: James.Qian.Wang + * + */ +#include +#include "komeda_dev.h" +#include "komeda_kms.h" +#include "komeda_pipeline.h" + +static inline bool is_switching_user(void *old, void *new) +{ + if (!old || !new) + return false; + + return old != new; +} + +struct komeda_pipeline_state * +komeda_pipeline_get_state(struct komeda_pipeline *pipe, + struct drm_atomic_state *state) +{ + struct drm_private_state *priv_st; + int err; + + WARN_ON(!state->acquire_ctx); + + priv_st = drm_atomic_get_new_private_obj_state(state, &pipe->obj); + if (priv_st) + return priv_to_pipe_st(priv_st); + + err = drm_modeset_lock(&pipe->mutex, state->acquire_ctx); + if (err) + return ERR_PTR(err); + + priv_st = drm_atomic_get_private_obj_state(state, &pipe->obj); + if (IS_ERR(priv_st)) + return ERR_CAST(priv_st); + + return priv_to_pipe_st(priv_st); +} + +/* Assign a pipeline crtc */ +struct komeda_pipeline_state * +komeda_pipeline_get_state_and_set_crtc(struct komeda_pipeline *pipe, + struct drm_atomic_state *state, + struct drm_crtc *crtc) +{ + struct komeda_pipeline_state *st; + + st = komeda_pipeline_get_state(pipe, state); + if (IS_ERR(st)) + return st; + + if (is_switching_user(crtc, st->crtc)) { + DRM_DEBUG_ATOMIC("CRTC%d required pipeline%d is busy.\n", + drm_crtc_index(crtc), pipe->id); + return ERR_PTR(-EBUSY); + } + + /* pipeline only can be disabled when the it is free or unused */ + if (!crtc && st->active_comps) { + DRM_DEBUG_ATOMIC("Disabling a busy pipeline:%d.\n", pipe->id); + return ERR_PTR(-EBUSY); + } + + st->crtc = crtc; + + if (crtc) { + struct komeda_crtc_state *kcrtc_st; + + kcrtc_st = to_kcrtc_st(drm_atomic_get_new_crtc_state(state, + crtc)); + + kcrtc_st->active_pipes |= BIT(pipe->id); + kcrtc_st->affected_pipes |= BIT(pipe->id); + } + return st; +} + +static struct komeda_component_state * +komeda_component_get_state(struct komeda_component *c, + struct drm_atomic_state *state) +{ + WARN_ON(!drm_modeset_is_locked(&c->pipeline->mutex)); + + return priv_to_comp_st(drm_atomic_get_private_obj_state(state, + &c->obj)); +} + +/** + * komeda_component_get_state_and_set_user() + * + * @c: component to get state and set user + * @state: global atomic state + * @user: direct user, the binding user + * @crtc: the CRTC user, the big boss :) + * + * This function accepts two users: + * - The direct user: can be plane/crtc/wb_connector depends on component + * - The big boss (CRTC) + * CRTC is the big boss (the final user), because all component resources + * eventually will be assigned to CRTC, like the layer will be binding to + * kms_plane, but kms plane will be binding to a CRTC eventually. + * + * The big boss (CRTC) is for pipeline assignment, since &komeda_component isn't + * independent and can be assigned to CRTC freely, but belongs to a specific + * pipeline, only pipeline can be shared between crtc, and pipeline as a whole + * (include all the internal components) assigned to a specific CRTC. + * + * So when set a user to komeda_component, need first to check the status of + * component->pipeline to see if the pipeline is available on this specific + * CRTC. if the pipeline is busy (assigned to another CRTC), even the required + * component is free, the component still cannot be assigned to the direct user. + */ +static struct komeda_component_state * +komeda_component_get_state_and_set_user(struct komeda_component *c, + struct drm_atomic_state *state, + void *user, + struct drm_crtc *crtc) +{ + struct komeda_pipeline_state *pipe_st; + struct komeda_component_state *st; + + /* First check if the pipeline is available */ + pipe_st = komeda_pipeline_get_state_and_set_crtc(c->pipeline, + state, crtc); + if (IS_ERR(pipe_st)) + return ERR_CAST(pipe_st); + + st = komeda_component_get_state(c, state); + if (IS_ERR(st)) + return st; + + /* check if the component has been occupied */ + if (is_switching_user(user, st->binding_user)) { + DRM_DEBUG_ATOMIC("required %s is busy.\n", c->name); + return ERR_PTR(-EBUSY); + } + + st->binding_user = user; + /* mark the component as active if user is valid */ + if (st->binding_user) + pipe_st->active_comps |= BIT(c->id); + + return st; +}