From nobody Tue Feb 10 08:27:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9809C7EE24 for ; Sat, 3 Jun 2023 10:38:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232236AbjFCKiJ (ORCPT ); Sat, 3 Jun 2023 06:38:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbjFCKhr (ORCPT ); Sat, 3 Jun 2023 06:37:47 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0F3CFE1 for ; Sat, 3 Jun 2023 03:37:44 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8Dxiur3F3tkIeoDAA--.4044S3; Sat, 03 Jun 2023 18:37:43 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxJLH2F3tkkzCHAA--.22741S7; Sat, 03 Jun 2023 18:37:43 +0800 (CST) From: Sui Jingfeng To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Bjorn Helgaas , Li Yi Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v7 5/7] drm/etnaviv: allow bypass component framework Date: Sat, 3 Jun 2023 18:37:40 +0800 Message-Id: <20230603103742.3041649-6-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603103742.3041649-1-suijingfeng@loongson.cn> References: <20230603103742.3041649-1-suijingfeng@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8CxJLH2F3tkkzCHAA--.22741S7 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW3Gr4UCr4UWryUKw1kCF1fCrg_yoW3tr13pF 4xJayYkrW8uayqg34UArn5ZF13Cw1Sq34Iy34kK3sakw45JryktF1YyFyjyFnxJrZ5WFW3 tr1DtrWUAF40y3DanT9S1TB71UUUUjDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bhxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84 ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr0_Cr1U M2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zV CFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWrXVW3AwAv7VC2 z280aVAFwI0_Cr0_Gr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x 0262kKe7AKxVWUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCF I7km07C267AKxVWUAVWUtwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r 106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AK xVW7JVWDJwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcI k0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWxJVW8Jr1lIxAIcVC2z280aVCY1x0267AKxVW8 JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU022NJUUUUU== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Adds another code path to allow bypass component frameworks, A platform with a single GPU core could probably try the non-component code path. This patch is for code sharing, no functional change. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 47 ++++++++++----- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 84 +++++++++++++++++---------- drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 3 + 3 files changed, 91 insertions(+), 43 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnavi= v/etnaviv_drv.c index 6a048be02857..93ca240cd4c0 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -536,10 +536,9 @@ static const struct drm_driver etnaviv_drm_driver =3D { .minor =3D 3, }; =20 -/* - * Platform driver: - */ -static int etnaviv_bind(struct device *dev) +static struct etnaviv_drm_private *etna_private_ptr; + +static int etnaviv_drm_bind(struct device *dev, bool component) { struct etnaviv_drm_private *priv; struct drm_device *drm; @@ -556,12 +555,15 @@ static int etnaviv_bind(struct device *dev) } =20 drm->dev_private =3D priv; + etna_private_ptr =3D priv; =20 dma_set_max_seg_size(dev, SZ_2G); =20 - dev_set_drvdata(dev, drm); + if (component) + ret =3D component_bind_all(dev, drm); + else + ret =3D etnaviv_gpu_bind(dev, NULL, drm); =20 - ret =3D component_bind_all(dev, drm); if (ret < 0) goto out_free_priv; =20 @@ -574,7 +576,10 @@ static int etnaviv_bind(struct device *dev) return 0; =20 out_unbind: - component_unbind_all(dev, drm); + if (component) + component_unbind_all(dev, drm); + else + etnaviv_gpu_unbind(dev, NULL, drm); out_free_priv: etnaviv_free_private(priv); out_put: @@ -583,14 +588,17 @@ static int etnaviv_bind(struct device *dev) return ret; } =20 -static void etnaviv_unbind(struct device *dev) +static void etnaviv_drm_unbind(struct device *dev, bool component) { - struct drm_device *drm =3D dev_get_drvdata(dev); - struct etnaviv_drm_private *priv =3D drm->dev_private; + struct etnaviv_drm_private *priv =3D etna_private_ptr; + struct drm_device *drm =3D priv->drm; =20 drm_dev_unregister(drm); =20 - component_unbind_all(dev, drm); + if (component) + component_unbind_all(dev, drm); + else + etnaviv_gpu_unbind(dev, NULL, drm); =20 etnaviv_free_private(priv); =20 @@ -599,9 +607,22 @@ static void etnaviv_unbind(struct device *dev) drm_dev_put(drm); } =20 +/* + * Platform driver: + */ +static int etnaviv_master_bind(struct device *dev) +{ + return etnaviv_drm_bind(dev, true); +} + +static void etnaviv_master_unbind(struct device *dev) +{ + return etnaviv_drm_unbind(dev, true); +} + static const struct component_master_ops etnaviv_master_ops =3D { - .bind =3D etnaviv_bind, - .unbind =3D etnaviv_unbind, + .bind =3D etnaviv_master_bind, + .unbind =3D etnaviv_master_unbind, }; =20 static int etnaviv_pdev_probe(struct platform_device *pdev) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnavi= v/etnaviv_gpu.c index 6c7aa9322468..126f0409aaed 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1737,8 +1737,7 @@ static const struct thermal_cooling_device_ops coolin= g_ops =3D { .set_cur_state =3D etnaviv_gpu_cooling_set_cur_state, }; =20 -static int etnaviv_gpu_bind(struct device *dev, struct device *master, - void *data) +int etnaviv_gpu_bind(struct device *dev, struct device *master, void *data) { struct drm_device *drm =3D data; struct etnaviv_drm_private *priv =3D drm->dev_private; @@ -1769,7 +1768,6 @@ static int etnaviv_gpu_bind(struct device *dev, struc= t device *master, if (ret < 0) goto out_sched; =20 - gpu->drm =3D drm; gpu->fence_context =3D dma_fence_context_alloc(1); xa_init_flags(&gpu->user_fences, XA_FLAGS_ALLOC); @@ -1798,8 +1796,7 @@ static int etnaviv_gpu_bind(struct device *dev, struc= t device *master, return ret; } =20 -static void etnaviv_gpu_unbind(struct device *dev, struct device *master, - void *data) +void etnaviv_gpu_unbind(struct device *dev, struct device *master, void *d= ata) { struct etnaviv_gpu *gpu =3D dev_get_drvdata(dev); =20 @@ -1869,9 +1866,11 @@ static int etnaviv_gpu_register_irq(struct etnaviv_g= pu *gpu, int irq) return 0; } =20 -static int etnaviv_gpu_platform_probe(struct platform_device *pdev) +/* platform independent */ + +static int etnaviv_gpu_driver_create(struct device *dev, void __iomem *mmi= o, + int irq, bool component, bool has_clk) { - struct device *dev =3D &pdev->dev; struct etnaviv_gpu *gpu; int err; =20 @@ -1879,24 +1878,21 @@ static int etnaviv_gpu_platform_probe(struct platfo= rm_device *pdev) if (!gpu) return -ENOMEM; =20 - gpu->dev =3D &pdev->dev; + gpu->dev =3D dev; + gpu->mmio =3D mmio; mutex_init(&gpu->lock); mutex_init(&gpu->sched_lock); =20 - /* Map registers: */ - gpu->mmio =3D devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(gpu->mmio)) - return PTR_ERR(gpu->mmio); - /* Get Interrupt: */ - err =3D etnaviv_gpu_register_irq(gpu, platform_get_irq(pdev, 0)); + err =3D etnaviv_gpu_register_irq(gpu, irq); if (err) return err; =20 - /* Get Clocks: */ - err =3D etnaviv_gpu_clk_get(gpu); - if (err) - return err; + if (has_clk) { + err =3D etnaviv_gpu_clk_get(gpu); + if (err) + return err; + } =20 /* TODO: figure out max mapped size */ dev_set_drvdata(dev, gpu); @@ -1906,24 +1902,27 @@ static int etnaviv_gpu_platform_probe(struct platfo= rm_device *pdev) * autosuspend delay is rather arbitary: no measurements have * yet been performed to determine an appropriate value. */ - pm_runtime_use_autosuspend(gpu->dev); - pm_runtime_set_autosuspend_delay(gpu->dev, 200); - pm_runtime_enable(gpu->dev); - - err =3D component_add(&pdev->dev, &gpu_ops); - if (err < 0) { - dev_err(&pdev->dev, "failed to register component: %d\n", err); - return err; + pm_runtime_use_autosuspend(dev); + pm_runtime_set_autosuspend_delay(dev, 200); + pm_runtime_enable(dev); + + if (component) { + err =3D component_add(dev, &gpu_ops); + if (err < 0) { + dev_err(dev, "failed to register component: %d\n", err); + return err; + } } =20 return 0; } =20 -static int etnaviv_gpu_platform_remove(struct platform_device *pdev) +static void etnaviv_gpu_driver_destroy(struct device *dev, bool component) { - component_del(&pdev->dev, &gpu_ops); - pm_runtime_disable(&pdev->dev); - return 0; + if (component) + component_del(dev, &gpu_ops); + + pm_runtime_disable(dev); } =20 static int etnaviv_gpu_rpm_suspend(struct device *dev) @@ -1973,6 +1972,31 @@ static const struct dev_pm_ops etnaviv_gpu_pm_ops = =3D { RUNTIME_PM_OPS(etnaviv_gpu_rpm_suspend, etnaviv_gpu_rpm_resume, NULL) }; =20 +static int etnaviv_gpu_platform_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + void __iomem *mmio; + int irq; + + /* Map registers: */ + mmio =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(mmio)) + return PTR_ERR(mmio); + + irq =3D platform_get_irq(pdev, 0); + + return etnaviv_gpu_driver_create(dev, mmio, irq, true, true); +} + +static int etnaviv_gpu_platform_remove(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + + etnaviv_gpu_driver_destroy(dev, true); + + return 0; +} + struct platform_driver etnaviv_gpu_driver =3D { .driver =3D { .name =3D "etnaviv-gpu", diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h b/drivers/gpu/drm/etnavi= v/etnaviv_gpu.h index 98c6f9c320fc..1ec829a649b5 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h @@ -206,6 +206,9 @@ void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu); int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms= ); void etnaviv_gpu_start_fe(struct etnaviv_gpu *gpu, u32 address, u16 prefet= ch); =20 +int etnaviv_gpu_bind(struct device *dev, struct device *master, void *data= ); +void etnaviv_gpu_unbind(struct device *dev, struct device *master, void *d= ata); + extern struct platform_driver etnaviv_gpu_driver; =20 #endif /* __ETNAVIV_GPU_H__ */ --=20 2.25.1