From nobody Mon Feb 9 01:17:43 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 918BEEB64DA for ; Mon, 19 Jun 2023 12:42:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230381AbjFSMmP (ORCPT ); Mon, 19 Jun 2023 08:42:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbjFSMmK (ORCPT ); Mon, 19 Jun 2023 08:42:10 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B744EAB for ; Mon, 19 Jun 2023 05:42:08 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.41:49634.708654646 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id 06E4C100239; Mon, 19 Jun 2023 20:42:06 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xwndj with ESMTP id 2d93ac6bcbae4e088327129f15390ec1 for l.stach@pengutronix.de; Mon, 19 Jun 2023 20:42:08 CST X-Transaction-ID: 2d93ac6bcbae4e088327129f15390ec1 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng , Philipp Zabel , Bjorn Helgaas Subject: [PATCH v10 01/11] drm/etnaviv: Add a dedicated function to register an irq handler Date: Mon, 19 Jun 2023 20:41:51 +0800 Message-Id: <20230619124201.2215558-2-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230619124201.2215558-1-15330273260@189.cn> References: <20230619124201.2215558-1-15330273260@189.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sui Jingfeng Because getting IRQ from a device is platform-dependent, PCI devices have different methods for getting an IRQ. This patch is a preparation to extend this driver for supporting the PCI devices. Cc: Lucas Stach Cc: Christian Gmeiner Cc: Philipp Zabel Cc: Bjorn Helgaas Cc: Daniel Vetter Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 32 +++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnavi= v/etnaviv_gpu.c index de8c9894967c..a03e81337d8f 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1817,6 +1817,27 @@ static const struct of_device_id etnaviv_gpu_match[]= =3D { }; MODULE_DEVICE_TABLE(of, etnaviv_gpu_match); =20 +static int etnaviv_gpu_register_irq(struct etnaviv_gpu *gpu, int irq) +{ + struct device *dev =3D gpu->dev; + int err; + + if (irq < 0) + return irq; + + err =3D devm_request_irq(dev, irq, irq_handler, 0, dev_name(dev), gpu); + if (err) { + dev_err(dev, "failed to request irq %u: %d\n", irq, err); + return err; + } + + gpu->irq =3D irq; + + dev_info(dev, "irq(%d) handler registered\n", irq); + + return 0; +} + static int etnaviv_gpu_platform_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; @@ -1837,16 +1858,9 @@ static int etnaviv_gpu_platform_probe(struct platfor= m_device *pdev) return PTR_ERR(gpu->mmio); =20 /* Get Interrupt: */ - gpu->irq =3D platform_get_irq(pdev, 0); - if (gpu->irq < 0) - return gpu->irq; - - err =3D devm_request_irq(&pdev->dev, gpu->irq, irq_handler, 0, - dev_name(gpu->dev), gpu); - if (err) { - dev_err(dev, "failed to request IRQ%u: %d\n", gpu->irq, err); + err =3D etnaviv_gpu_register_irq(gpu, platform_get_irq(pdev, 0)); + if (err) return err; - } =20 /* Get Clocks: */ gpu->clk_reg =3D devm_clk_get_optional(&pdev->dev, "reg"); --=20 2.25.1 From nobody Mon Feb 9 01:17:43 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 ECCDBEB64DB for ; Mon, 19 Jun 2023 12:42:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230476AbjFSMmV (ORCPT ); Mon, 19 Jun 2023 08:42:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230253AbjFSMmM (ORCPT ); Mon, 19 Jun 2023 08:42:12 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E2637D7 for ; Mon, 19 Jun 2023 05:42:10 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.41:49634.708654646 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id 370FF100294; Mon, 19 Jun 2023 20:42:08 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xwndj with ESMTP id 335925be468247e09fde82d183bdd0ac for l.stach@pengutronix.de; Mon, 19 Jun 2023 20:42:10 CST X-Transaction-ID: 335925be468247e09fde82d183bdd0ac X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng , Philipp Zabel , Bjorn Helgaas Subject: [PATCH v10 02/11] drm/etnaviv: Add a dedicated function to get various clocks Date: Mon, 19 Jun 2023 20:41:52 +0800 Message-Id: <20230619124201.2215558-3-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230619124201.2215558-1-15330273260@189.cn> References: <20230619124201.2215558-1-15330273260@189.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sui Jingfeng Because it is also platform-dependent, there are systems where we don't have DT-based clock drivers supported. For example, discrete PCI GPUs. Therefire, don't quit if there is no clock subsystem support. =C2=A0 =C2=A0=C2=A0 For the GPU in LS7A1000 and LS2K1000, the working frequency of the GPU is rely on the GFX PLL to generate the clock. Typically, the GFX PLL is configured by the platform firmware. Cc: Lucas Stach Cc: Christian Gmeiner Cc: Philipp Zabel Cc: Bjorn Helgaas Cc: Daniel Vetter Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 53 ++++++++++++++++----------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnavi= v/etnaviv_gpu.c index a03e81337d8f..5e88fa95dac2 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1565,6 +1565,35 @@ static irqreturn_t irq_handler(int irq, void *data) return ret; } =20 +static int etnaviv_gpu_clk_get(struct etnaviv_gpu *gpu) +{ + struct device *dev =3D gpu->dev; + + gpu->clk_reg =3D devm_clk_get_optional(dev, "reg"); + DBG("clk_reg: %p", gpu->clk_reg); + if (IS_ERR(gpu->clk_reg)) + return PTR_ERR(gpu->clk_reg); + + gpu->clk_bus =3D devm_clk_get_optional(dev, "bus"); + DBG("clk_bus: %p", gpu->clk_bus); + if (IS_ERR(gpu->clk_bus)) + return PTR_ERR(gpu->clk_bus); + + gpu->clk_core =3D devm_clk_get(dev, "core"); + DBG("clk_core: %p", gpu->clk_core); + if (IS_ERR(gpu->clk_core)) + return PTR_ERR(gpu->clk_core); + gpu->base_rate_core =3D clk_get_rate(gpu->clk_core); + + gpu->clk_shader =3D devm_clk_get_optional(dev, "shader"); + DBG("clk_shader: %p", gpu->clk_shader); + if (IS_ERR(gpu->clk_shader)) + return PTR_ERR(gpu->clk_shader); + gpu->base_rate_shader =3D clk_get_rate(gpu->clk_shader); + + return 0; +} + static int etnaviv_gpu_clk_enable(struct etnaviv_gpu *gpu) { int ret; @@ -1863,27 +1892,9 @@ static int etnaviv_gpu_platform_probe(struct platfor= m_device *pdev) return err; =20 /* Get Clocks: */ - gpu->clk_reg =3D devm_clk_get_optional(&pdev->dev, "reg"); - DBG("clk_reg: %p", gpu->clk_reg); - if (IS_ERR(gpu->clk_reg)) - return PTR_ERR(gpu->clk_reg); - - gpu->clk_bus =3D devm_clk_get_optional(&pdev->dev, "bus"); - DBG("clk_bus: %p", gpu->clk_bus); - if (IS_ERR(gpu->clk_bus)) - return PTR_ERR(gpu->clk_bus); - - gpu->clk_core =3D devm_clk_get(&pdev->dev, "core"); - DBG("clk_core: %p", gpu->clk_core); - if (IS_ERR(gpu->clk_core)) - return PTR_ERR(gpu->clk_core); - gpu->base_rate_core =3D clk_get_rate(gpu->clk_core); - - gpu->clk_shader =3D devm_clk_get_optional(&pdev->dev, "shader"); - DBG("clk_shader: %p", gpu->clk_shader); - if (IS_ERR(gpu->clk_shader)) - return PTR_ERR(gpu->clk_shader); - gpu->base_rate_shader =3D clk_get_rate(gpu->clk_shader); + err =3D etnaviv_gpu_clk_get(gpu); + if (err) + return err; =20 /* TODO: figure out max mapped size */ dev_set_drvdata(dev, gpu); --=20 2.25.1 From nobody Mon Feb 9 01:17:43 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 154FBEB64D9 for ; Mon, 19 Jun 2023 12:42:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231156AbjFSMmZ (ORCPT ); Mon, 19 Jun 2023 08:42:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbjFSMmN (ORCPT ); Mon, 19 Jun 2023 08:42:13 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 47A7191 for ; Mon, 19 Jun 2023 05:42:12 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.41:49634.708654646 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id 947331001EB; Mon, 19 Jun 2023 20:42:10 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xwndj with ESMTP id cf32779ce696411688a85d1ebc14d26a for l.stach@pengutronix.de; Mon, 19 Jun 2023 20:42:11 CST X-Transaction-ID: cf32779ce696411688a85d1ebc14d26a X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng , Philipp Zabel , Bjorn Helgaas Subject: [PATCH v10 03/11] drm/etnaviv: Add dedicated functions to create and destroy platform device Date: Mon, 19 Jun 2023 20:41:53 +0800 Message-Id: <20230619124201.2215558-4-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230619124201.2215558-1-15330273260@189.cn> References: <20230619124201.2215558-1-15330273260@189.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sui Jingfeng Also rename the virtual master platform device as etnaviv_platform_device, for better reflection that it is a platform device, not a DRM device. Another benefit is that we no longer need to call of_node_put() for three different cases, Instead, we only need to call it once. Cc: Lucas Stach Cc: Christian Gmeiner Cc: Philipp Zabel Cc: Bjorn Helgaas Cc: Daniel Vetter Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 56 +++++++++++++++++++-------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnavi= v/etnaviv_drv.c index 31a7f59ccb49..cec005035d0e 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -656,12 +656,44 @@ static struct platform_driver etnaviv_platform_driver= =3D { }, }; =20 -static struct platform_device *etnaviv_drm; +static struct platform_device *etnaviv_platform_device; =20 -static int __init etnaviv_init(void) +static int etnaviv_create_platform_device(const char *name, + struct platform_device **ppdev) { struct platform_device *pdev; int ret; + + pdev =3D platform_device_alloc(name, PLATFORM_DEVID_NONE); + if (!pdev) + return -ENOMEM; + + ret =3D platform_device_add(pdev); + if (ret) { + platform_device_put(pdev); + return ret; + } + + *ppdev =3D pdev; + + return 0; +} + +static void etnaviv_destroy_platform_device(struct platform_device **ppdev) +{ + struct platform_device *pdev =3D *ppdev; + + if (!pdev) + return; + + platform_device_unregister(pdev); + + *ppdev =3D NULL; +} + +static int __init etnaviv_init(void) +{ + int ret; struct device_node *np; =20 etnaviv_validate_init(); @@ -681,23 +713,13 @@ static int __init etnaviv_init(void) for_each_compatible_node(np, NULL, "vivante,gc") { if (!of_device_is_available(np)) continue; + of_node_put(np); =20 - pdev =3D platform_device_alloc("etnaviv", PLATFORM_DEVID_NONE); - if (!pdev) { - ret =3D -ENOMEM; - of_node_put(np); - goto unregister_platform_driver; - } - - ret =3D platform_device_add(pdev); - if (ret) { - platform_device_put(pdev); - of_node_put(np); + ret =3D etnaviv_create_platform_device("etnaviv", + &etnaviv_platform_device); + if (ret) goto unregister_platform_driver; - } =20 - etnaviv_drm =3D pdev; - of_node_put(np); break; } =20 @@ -713,7 +735,7 @@ module_init(etnaviv_init); =20 static void __exit etnaviv_exit(void) { - platform_device_unregister(etnaviv_drm); + etnaviv_destroy_platform_device(&etnaviv_platform_device); platform_driver_unregister(&etnaviv_platform_driver); platform_driver_unregister(&etnaviv_gpu_driver); } --=20 2.25.1 From nobody Mon Feb 9 01:17:43 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 8B869EB64DA for ; Mon, 19 Jun 2023 12:42:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231163AbjFSMm3 (ORCPT ); Mon, 19 Jun 2023 08:42:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbjFSMmP (ORCPT ); Mon, 19 Jun 2023 08:42:15 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B3F3BAB for ; Mon, 19 Jun 2023 05:42:13 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.41:49634.708654646 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id A5FA6102961; Mon, 19 Jun 2023 20:42:11 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xwndj with ESMTP id ee75ca21548344d3bab114fc829fc0fe for l.stach@pengutronix.de; Mon, 19 Jun 2023 20:42:12 CST X-Transaction-ID: ee75ca21548344d3bab114fc829fc0fe X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng , Philipp Zabel , Bjorn Helgaas Subject: [PATCH v10 04/11] drm/etnaviv: Add helpers for private data construction and destruction Date: Mon, 19 Jun 2023 20:41:54 +0800 Message-Id: <20230619124201.2215558-5-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230619124201.2215558-1-15330273260@189.cn> References: <20230619124201.2215558-1-15330273260@189.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sui Jingfeng There are numerous members in the struct etnaviv_drm_private, which are shared by all GPU core. This patch introduces two dedicated functions for the construction and destruction of the instances of this structure. The goal is to keep its members from leaking to the outside. The code needed for error handling can also be simplified. Cc: Lucas Stach Cc: Christian Gmeiner Cc: Philipp Zabel Cc: Bjorn Helgaas Cc: Daniel Vetter Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 73 +++++++++++++++++---------- drivers/gpu/drm/etnaviv/etnaviv_drv.h | 1 + 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnavi= v/etnaviv_drv.c index cec005035d0e..6a048be02857 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -24,9 +24,47 @@ #include "etnaviv_perfmon.h" =20 /* - * DRM operations: + * etnaviv private data construction and destructions: */ +static struct etnaviv_drm_private * +etnaviv_alloc_private(struct device *dev, struct drm_device *drm) +{ + struct etnaviv_drm_private *priv; + + priv =3D kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) + return ERR_PTR(-ENOMEM); + + priv->drm =3D drm; + + xa_init_flags(&priv->active_contexts, XA_FLAGS_ALLOC); + + mutex_init(&priv->gem_lock); + INIT_LIST_HEAD(&priv->gem_list); + priv->num_gpus =3D 0; + priv->shm_gfp_mask =3D GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN; =20 + priv->cmdbuf_suballoc =3D etnaviv_cmdbuf_suballoc_new(dev); + if (IS_ERR(priv->cmdbuf_suballoc)) { + kfree(priv); + dev_err(dev, "Failed to create cmdbuf suballocator\n"); + return ERR_PTR(-ENOMEM); + } + + return priv; +} + +static void etnaviv_free_private(struct etnaviv_drm_private *priv) +{ + if (!priv) + return; + + etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); + + xa_destroy(&priv->active_contexts); + + kfree(priv); +} =20 static void load_gpu(struct drm_device *dev) { @@ -511,35 +549,21 @@ static int etnaviv_bind(struct device *dev) if (IS_ERR(drm)) return PTR_ERR(drm); =20 - priv =3D kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) { - dev_err(dev, "failed to allocate private data\n"); - ret =3D -ENOMEM; + priv =3D etnaviv_alloc_private(dev, drm); + if (IS_ERR(priv)) { + ret =3D PTR_ERR(priv); goto out_put; } + drm->dev_private =3D priv; =20 dma_set_max_seg_size(dev, SZ_2G); =20 - xa_init_flags(&priv->active_contexts, XA_FLAGS_ALLOC); - - mutex_init(&priv->gem_lock); - INIT_LIST_HEAD(&priv->gem_list); - priv->num_gpus =3D 0; - priv->shm_gfp_mask =3D GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN; - - priv->cmdbuf_suballoc =3D etnaviv_cmdbuf_suballoc_new(drm->dev); - if (IS_ERR(priv->cmdbuf_suballoc)) { - dev_err(drm->dev, "Failed to create cmdbuf suballocator\n"); - ret =3D PTR_ERR(priv->cmdbuf_suballoc); - goto out_free_priv; - } - dev_set_drvdata(dev, drm); =20 ret =3D component_bind_all(dev, drm); if (ret < 0) - goto out_destroy_suballoc; + goto out_free_priv; =20 load_gpu(drm); =20 @@ -551,10 +575,8 @@ static int etnaviv_bind(struct device *dev) =20 out_unbind: component_unbind_all(dev, drm); -out_destroy_suballoc: - etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); out_free_priv: - kfree(priv); + etnaviv_free_private(priv); out_put: drm_dev_put(drm); =20 @@ -570,12 +592,9 @@ static void etnaviv_unbind(struct device *dev) =20 component_unbind_all(dev, drm); =20 - etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); - - xa_destroy(&priv->active_contexts); + etnaviv_free_private(priv); =20 drm->dev_private =3D NULL; - kfree(priv); =20 drm_dev_put(drm); } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnavi= v/etnaviv_drv.h index b3eb1662e90c..e58f82e698de 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h @@ -35,6 +35,7 @@ struct etnaviv_file_private { }; =20 struct etnaviv_drm_private { + struct drm_device *drm; int num_gpus; struct etnaviv_gpu *gpu[ETNA_MAX_PIPES]; gfp_t shm_gfp_mask; --=20 2.25.1 From nobody Mon Feb 9 01:17:43 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 03EFCEB64D9 for ; Mon, 19 Jun 2023 12:42:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbjFSMmc (ORCPT ); Mon, 19 Jun 2023 08:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbjFSMmQ (ORCPT ); Mon, 19 Jun 2023 08:42:16 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DB53CE9 for ; Mon, 19 Jun 2023 05:42:14 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.41:49634.708654646 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id 367AF102980; Mon, 19 Jun 2023 20:42:12 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xwndj with ESMTP id 0598934f69a64bc18301d7ac0bf0de71 for l.stach@pengutronix.de; Mon, 19 Jun 2023 20:42:14 CST X-Transaction-ID: 0598934f69a64bc18301d7ac0bf0de71 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng , Philipp Zabel , Bjorn Helgaas Subject: [PATCH v10 05/11] drm/etnaviv: Allow bypass component framework Date: Mon, 19 Jun 2023 20:41:55 +0800 Message-Id: <20230619124201.2215558-6-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230619124201.2215558-1-15330273260@189.cn> References: <20230619124201.2215558-1-15330273260@189.cn> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sui Jingfeng Originally, component frameworks were used to bind multiple GPU cores to a virtual master. But there are chips that have only one GPU core integrated. The component framework can be avoided under some circumstances, Another reason is that=C2=A0usperspace programs=C2=A0such as X server and Mesa will= try to find the PCI device to use by default. Creating a virtual master device for PCI GPUs cause unnecessary troubles. This patch add additional code paths to allow bypassing the component frameworks, platforms with a single GPU core could probably try the non-component code path also. This patch is for code shaing between the PCI driver and the platform driver. Cc: Lucas Stach Cc: Christian Gmeiner Cc: Philipp Zabel Cc: Bjorn Helgaas Cc: Daniel Vetter Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 47 ++++++++++----- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 83 +++++++++++++++++---------- drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 3 + 3 files changed, 91 insertions(+), 42 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 5e88fa95dac2..059be8c89c5a 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 @@ -1867,9 +1864,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 @@ -1877,24 +1876,22 @@ 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); @@ -1904,24 +1901,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) @@ -1971,6 +1971,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 From nobody Mon Feb 9 01:17:43 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 24BC9EB64D9 for ; Mon, 19 Jun 2023 12:42:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231183AbjFSMme (ORCPT ); Mon, 19 Jun 2023 08:42:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230402AbjFSMmT (ORCPT ); Mon, 19 Jun 2023 08:42:19 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8DA4FF4 for ; Mon, 19 Jun 2023 05:42:15 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.41:49634.708654646 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id 43AA6102981; Mon, 19 Jun 2023 20:42:14 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xwndj with ESMTP id 5cd98150d09f47b08c486d9a7c538037 for l.stach@pengutronix.de; Mon, 19 Jun 2023 20:42:15 CST X-Transaction-ID: 5cd98150d09f47b08c486d9a7c538037 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng , Philipp Zabel , Bjorn Helgaas Subject: [PATCH v10 06/11] drm/etnaviv: Add driver support for the PCI devices Date: Mon, 19 Jun 2023 20:41:56 +0800 Message-Id: <20230619124201.2215558-7-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230619124201.2215558-1-15330273260@189.cn> References: <20230619124201.2215558-1-15330273260@189.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sui Jingfeng This patch adds PCI driver support on top of what we already have, take the GC1000 in LS7A1000/LS2K1000 as the first instance which enjoy the PCI device driver. There is only one GPU core for the GC1000 in the LS7A1000 and LS2K1000. Therefore, component frameworks can be avoided. Cc: Lucas Stach Cc: Christian Gmeiner Cc: Philipp Zabel Cc: Bjorn Helgaas Cc: Daniel Vetter Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/Kconfig | 10 +++ drivers/gpu/drm/etnaviv/Makefile | 2 + drivers/gpu/drm/etnaviv/etnaviv_drv.c | 13 +++- drivers/gpu/drm/etnaviv/etnaviv_drv.h | 3 + drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 8 +-- drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 6 ++ drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c | 75 +++++++++++++++++++++++ drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h | 18 ++++++ 8 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c create mode 100644 drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h diff --git a/drivers/gpu/drm/etnaviv/Kconfig b/drivers/gpu/drm/etnaviv/Kcon= fig index faa7fc68b009..1b5b162efb61 100644 --- a/drivers/gpu/drm/etnaviv/Kconfig +++ b/drivers/gpu/drm/etnaviv/Kconfig @@ -15,6 +15,16 @@ config DRM_ETNAVIV help DRM driver for Vivante GPUs. =20 +config DRM_ETNAVIV_PCI_DRIVER + bool "enable ETNAVIV PCI driver support" + depends on DRM_ETNAVIV + depends on PCI + default y + help + Compile in support for PCI GPUs of Vivante. + For example, the GC1000 in LS7A1000 and LS2K1000. + Say Y if you have such a hardware. + config DRM_ETNAVIV_THERMAL bool "enable ETNAVIV thermal throttling" depends on DRM_ETNAVIV diff --git a/drivers/gpu/drm/etnaviv/Makefile b/drivers/gpu/drm/etnaviv/Mak= efile index 46e5ffad69a6..6829e1ebf2db 100644 --- a/drivers/gpu/drm/etnaviv/Makefile +++ b/drivers/gpu/drm/etnaviv/Makefile @@ -16,4 +16,6 @@ etnaviv-y :=3D \ etnaviv_perfmon.o \ etnaviv_sched.o =20 +etnaviv-$(CONFIG_DRM_ETNAVIV_PCI_DRIVER) +=3D etnaviv_pci_drv.o + obj-$(CONFIG_DRM_ETNAVIV) +=3D etnaviv.o diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnavi= v/etnaviv_drv.c index 93ca240cd4c0..0a365e96d371 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -21,6 +21,7 @@ #include "etnaviv_gpu.h" #include "etnaviv_gem.h" #include "etnaviv_mmu.h" +#include "etnaviv_pci_drv.h" #include "etnaviv_perfmon.h" =20 /* @@ -538,7 +539,7 @@ static const struct drm_driver etnaviv_drm_driver =3D { =20 static struct etnaviv_drm_private *etna_private_ptr; =20 -static int etnaviv_drm_bind(struct device *dev, bool component) +int etnaviv_drm_bind(struct device *dev, bool component) { struct etnaviv_drm_private *priv; struct drm_device *drm; @@ -588,7 +589,7 @@ static int etnaviv_drm_bind(struct device *dev, bool co= mponent) return ret; } =20 -static void etnaviv_drm_unbind(struct device *dev, bool component) +void etnaviv_drm_unbind(struct device *dev, bool component) { struct etnaviv_drm_private *priv =3D etna_private_ptr; struct drm_device *drm =3D priv->drm; @@ -746,6 +747,10 @@ static int __init etnaviv_init(void) if (ret !=3D 0) goto unregister_gpu_driver; =20 + ret =3D etnaviv_register_pci_driver(); + if (ret !=3D 0) + goto unregister_platform_driver; + /* * If the DT contains at least one available GPU device, instantiate * the DRM platform device. @@ -763,7 +768,7 @@ static int __init etnaviv_init(void) break; } =20 - return 0; + return ret; =20 unregister_platform_driver: platform_driver_unregister(&etnaviv_platform_driver); @@ -778,6 +783,8 @@ static void __exit etnaviv_exit(void) etnaviv_destroy_platform_device(&etnaviv_platform_device); platform_driver_unregister(&etnaviv_platform_driver); platform_driver_unregister(&etnaviv_gpu_driver); + + etnaviv_unregister_pci_driver(); } module_exit(etnaviv_exit); =20 diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnavi= v/etnaviv_drv.h index e58f82e698de..9cd72948cfad 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h @@ -83,6 +83,9 @@ bool etnaviv_cmd_validate_one(struct etnaviv_gpu *gpu, u32 *stream, unsigned int size, struct drm_etnaviv_gem_submit_reloc *relocs, unsigned int reloc_size); =20 +int etnaviv_drm_bind(struct device *dev, bool component); +void etnaviv_drm_unbind(struct device *dev, bool component); + #ifdef CONFIG_DEBUG_FS void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv, struct seq_file *m); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnavi= v/etnaviv_gpu.c index 059be8c89c5a..d6a21e97feb1 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1866,8 +1866,8 @@ static int etnaviv_gpu_register_irq(struct etnaviv_gp= u *gpu, int irq) =20 /* platform independent */ =20 -static int etnaviv_gpu_driver_create(struct device *dev, void __iomem *mmi= o, - int irq, bool component, bool has_clk) +int etnaviv_gpu_driver_create(struct device *dev, void __iomem *mmio, + int irq, bool component, bool has_clk) { struct etnaviv_gpu *gpu; int err; @@ -1916,7 +1916,7 @@ static int etnaviv_gpu_driver_create(struct device *d= ev, void __iomem *mmio, return 0; } =20 -static void etnaviv_gpu_driver_destroy(struct device *dev, bool component) +void etnaviv_gpu_driver_destroy(struct device *dev, bool component) { if (component) component_del(dev, &gpu_ops); @@ -1967,7 +1967,7 @@ static int etnaviv_gpu_rpm_resume(struct device *dev) return 0; } =20 -static const struct dev_pm_ops etnaviv_gpu_pm_ops =3D { +const struct dev_pm_ops etnaviv_gpu_pm_ops =3D { RUNTIME_PM_OPS(etnaviv_gpu_rpm_suspend, etnaviv_gpu_rpm_resume, NULL) }; =20 diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h b/drivers/gpu/drm/etnavi= v/etnaviv_gpu.h index 1ec829a649b5..8d9833996ed7 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h @@ -209,6 +209,12 @@ void etnaviv_gpu_start_fe(struct etnaviv_gpu *gpu, u32= address, u16 prefetch); 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); =20 +int etnaviv_gpu_driver_create(struct device *dev, void __iomem *mmio, + int irq, bool component, bool has_clk); + +void etnaviv_gpu_driver_destroy(struct device *dev, bool component); + extern struct platform_driver etnaviv_gpu_driver; +extern const struct dev_pm_ops etnaviv_gpu_pm_ops; =20 #endif /* __ETNAVIV_GPU_H__ */ diff --git a/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c b/drivers/gpu/drm/et= naviv/etnaviv_pci_drv.c new file mode 100644 index 000000000000..78e44a28d30c --- /dev/null +++ b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +#include "etnaviv_drv.h" +#include "etnaviv_gpu.h" +#include "etnaviv_pci_drv.h" + +static int etnaviv_pci_probe(struct pci_dev *pdev, + const struct pci_device_id *ent) +{ + struct device *dev =3D &pdev->dev; + void __iomem *mmio; + int ret; + + ret =3D pcim_enable_device(pdev); + if (ret) { + dev_err(dev, "failed to enable\n"); + return ret; + } + + pci_set_master(pdev); + + ret =3D dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); + if (ret) + return ret; + + /* Map registers, assume the PCI bar 0 contain the registers */ + mmio =3D pcim_iomap(pdev, 0, 0); + if (IS_ERR(mmio)) + return PTR_ERR(mmio); + + ret =3D etnaviv_gpu_driver_create(dev, mmio, pdev->irq, false, false); + if (ret) + return ret; + + return etnaviv_drm_bind(dev, false); +} + +static void etnaviv_pci_remove(struct pci_dev *pdev) +{ + struct device *dev =3D &pdev->dev; + + etnaviv_drm_unbind(dev, false); + + etnaviv_gpu_driver_destroy(dev, false); + + pci_clear_master(pdev); +} + +static const struct pci_device_id etnaviv_pci_id_lists[] =3D { + {PCI_VDEVICE(LOONGSON, 0x7a15)}, + {PCI_VDEVICE(LOONGSON, 0x7a05)}, + { } +}; + +static struct pci_driver etnaviv_pci_driver =3D { + .name =3D "etnaviv", + .id_table =3D etnaviv_pci_id_lists, + .probe =3D etnaviv_pci_probe, + .remove =3D etnaviv_pci_remove, + .driver.pm =3D pm_ptr(&etnaviv_gpu_pm_ops), +}; + +int etnaviv_register_pci_driver(void) +{ + return pci_register_driver(&etnaviv_pci_driver); +} + +void etnaviv_unregister_pci_driver(void) +{ + pci_unregister_driver(&etnaviv_pci_driver); +} + +MODULE_DEVICE_TABLE(pci, etnaviv_pci_id_lists); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h b/drivers/gpu/drm/et= naviv/etnaviv_pci_drv.h new file mode 100644 index 000000000000..1db559ee5e9b --- /dev/null +++ b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ETNAVIV_PCI_DRV_H__ +#define __ETNAVIV_PCI_DRV_H__ + +#ifdef CONFIG_DRM_ETNAVIV_PCI_DRIVER + +int etnaviv_register_pci_driver(void); +void etnaviv_unregister_pci_driver(void); + +#else + +static inline int etnaviv_register_pci_driver(void) { return 0; } +static inline void etnaviv_unregister_pci_driver(void) { } + +#endif + +#endif --=20 2.25.1 From nobody Mon Feb 9 01:17:43 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 800C1EB64D9 for ; Mon, 19 Jun 2023 12:42:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230448AbjFSMmi (ORCPT ); Mon, 19 Jun 2023 08:42:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230452AbjFSMmU (ORCPT ); Mon, 19 Jun 2023 08:42:20 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D506711D for ; Mon, 19 Jun 2023 05:42:16 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.41:49634.708654646 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id 30CE610298B; Mon, 19 Jun 2023 20:42:15 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xwndj with ESMTP id 6faaa7ce1fed4496bb72097a1ec71896 for l.stach@pengutronix.de; Mon, 19 Jun 2023 20:42:16 CST X-Transaction-ID: 6faaa7ce1fed4496bb72097a1ec71896 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng , Philipp Zabel , Bjorn Helgaas Subject: [PATCH v10 07/11] drm/etnaviv: Add support for the dma coherent device Date: Mon, 19 Jun 2023 20:41:57 +0800 Message-Id: <20230619124201.2215558-8-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230619124201.2215558-1-15330273260@189.cn> References: <20230619124201.2215558-1-15330273260@189.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sui Jingfeng Loongson CPUs maintain cache coherency by hardware, which means that the data in the CPU cache is identical to the data in main system memory. As for the peripheral device, most of Loongson chips chose to define the peripherals as DMA coherent by default, device drivers do not need to maintain the coherency between a processor and an I/O device manually. There are exceptions, for LS2K1000 SoC, part of peripheral device can be configured as DMA non-coherent. But there is no released version of such firmware exist in the market. Peripherals of older LS2K1000 is also DMA non-coherent, but they are nearly outdated. So, those are trivial cases. Nevertheless, kernel space still need to do the probe work, because vivante GPU IP has been integrated into various platform. Hence, this patch add runtime detection code to probe if a specific GPU is DMA coherent, If the answer is yes, we are going to utilize such features. On Loongson platform, When a buffer is accessed by both the GPU and the CPU, the driver should prefer ETNA_BO_CACHED over ETNA_BO_WC. This patch also add a new parameter: etnaviv_param_gpu_coherent, which allow userspace to know if such a feature is available. Because write-combined BO is still preferred in some case, especially where don't need CPU read, for example, uploading compiled shader bin. Cc: Lucas Stach Cc: Christian Gmeiner Cc: Philipp Zabel Cc: Bjorn Helgaas Cc: Daniel Vetter Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 35 +++++++++++++++++++++ drivers/gpu/drm/etnaviv/etnaviv_drv.h | 6 ++++ drivers/gpu/drm/etnaviv/etnaviv_gem.c | 22 ++++++++++--- drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 7 ++++- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 4 +++ include/uapi/drm/etnaviv_drm.h | 1 + 6 files changed, 70 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnavi= v/etnaviv_drv.c index 0a365e96d371..d8e788aa16cb 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -5,7 +5,9 @@ =20 #include #include +#include #include +#include #include #include =20 @@ -24,6 +26,34 @@ #include "etnaviv_pci_drv.h" #include "etnaviv_perfmon.h" =20 +static struct device_node *etnaviv_of_first_available_node(void) +{ + struct device_node *core_node; + + for_each_compatible_node(core_node, NULL, "vivante,gc") { + if (of_device_is_available(core_node)) + return core_node; + } + + return NULL; +} + +static bool etnaviv_is_dma_coherent(struct device *dev) +{ + struct device_node *np; + bool coherent; + + np =3D etnaviv_of_first_available_node(); + if (np) { + coherent =3D of_dma_is_coherent(np); + of_node_put(np); + } else { + coherent =3D dev_is_dma_coherent(dev); + } + + return coherent; +} + /* * etnaviv private data construction and destructions: */ @@ -52,6 +82,11 @@ etnaviv_alloc_private(struct device *dev, struct drm_dev= ice *drm) return ERR_PTR(-ENOMEM); } =20 + priv->dma_coherent =3D etnaviv_is_dma_coherent(dev); + + if (priv->dma_coherent) + drm_info(drm, "%s is dma coherent\n", dev_name(dev)); + return priv; } =20 diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnavi= v/etnaviv_drv.h index 9cd72948cfad..644e5712c050 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h @@ -46,6 +46,12 @@ struct etnaviv_drm_private { struct xarray active_contexts; u32 next_context_id; =20 + /* + * If true, the GPU is capable of snooping cpu cache. Here, it + * also means that cache coherency is enforced by the hardware. + */ + bool dma_coherent; + /* list of GEM objects: */ struct mutex gem_lock; struct list_head gem_list; diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnavi= v/etnaviv_gem.c index b5f73502e3dd..39bdc3774f2d 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c @@ -343,6 +343,7 @@ void *etnaviv_gem_vmap(struct drm_gem_object *obj) static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) { struct page **pages; + pgprot_t prot; =20 lockdep_assert_held(&obj->lock); =20 @@ -350,8 +351,19 @@ static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_= object *obj) if (IS_ERR(pages)) return NULL; =20 - return vmap(pages, obj->base.size >> PAGE_SHIFT, - VM_MAP, pgprot_writecombine(PAGE_KERNEL)); + switch (obj->flags) { + case ETNA_BO_CACHED: + prot =3D PAGE_KERNEL; + break; + case ETNA_BO_UNCACHED: + prot =3D pgprot_noncached(PAGE_KERNEL); + break; + case ETNA_BO_WC: + default: + prot =3D pgprot_writecombine(PAGE_KERNEL); + } + + return vmap(pages, obj->base.size >> PAGE_SHIFT, VM_MAP, prot); } =20 static inline enum dma_data_direction etnaviv_op_to_dma_dir(u32 op) @@ -369,6 +381,7 @@ int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u3= 2 op, { struct etnaviv_gem_object *etnaviv_obj =3D to_etnaviv_bo(obj); struct drm_device *dev =3D obj->dev; + struct etnaviv_drm_private *priv =3D dev->dev_private; bool write =3D !!(op & ETNA_PREP_WRITE); int ret; =20 @@ -395,7 +408,7 @@ int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u3= 2 op, return ret =3D=3D 0 ? -ETIMEDOUT : ret; } =20 - if (etnaviv_obj->flags & ETNA_BO_CACHED) { + if (!priv->dma_coherent && etnaviv_obj->flags & ETNA_BO_CACHED) { dma_sync_sgtable_for_cpu(dev->dev, etnaviv_obj->sgt, etnaviv_op_to_dma_dir(op)); etnaviv_obj->last_cpu_prep_op =3D op; @@ -408,8 +421,9 @@ int etnaviv_gem_cpu_fini(struct drm_gem_object *obj) { struct drm_device *dev =3D obj->dev; struct etnaviv_gem_object *etnaviv_obj =3D to_etnaviv_bo(obj); + struct etnaviv_drm_private *priv =3D dev->dev_private; =20 - if (etnaviv_obj->flags & ETNA_BO_CACHED) { + if (!priv->dma_coherent && etnaviv_obj->flags & ETNA_BO_CACHED) { /* fini without a prep is almost certainly a userspace error */ WARN_ON(etnaviv_obj->last_cpu_prep_op =3D=3D 0); dma_sync_sgtable_for_device(dev->dev, etnaviv_obj->sgt, diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/= etnaviv/etnaviv_gem_prime.c index 3524b5811682..754126992264 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c @@ -112,11 +112,16 @@ static const struct etnaviv_gem_ops etnaviv_gem_prime= _ops =3D { struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device= *dev, struct dma_buf_attachment *attach, struct sg_table *sgt) { + struct etnaviv_drm_private *priv =3D dev->dev_private; struct etnaviv_gem_object *etnaviv_obj; size_t size =3D PAGE_ALIGN(attach->dmabuf->size); + u32 cache_flags =3D ETNA_BO_WC; int ret, npages; =20 - ret =3D etnaviv_gem_new_private(dev, size, ETNA_BO_WC, + if (priv->dma_coherent) + cache_flags =3D ETNA_BO_CACHED; + + ret =3D etnaviv_gem_new_private(dev, size, cache_flags, &etnaviv_gem_prime_ops, &etnaviv_obj); if (ret < 0) return ERR_PTR(ret); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnavi= v/etnaviv_gpu.c index d6a21e97feb1..d99ac675ce8b 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -164,6 +164,10 @@ int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32= param, u64 *value) *value =3D gpu->identity.eco_id; break; =20 + case ETNAVIV_PARAM_GPU_COHERENT: + *value =3D priv->dma_coherent; + break; + default: DBG("%s: invalid param: %u", dev_name(gpu->dev), param); return -EINVAL; diff --git a/include/uapi/drm/etnaviv_drm.h b/include/uapi/drm/etnaviv_drm.h index af024d90453d..76baf45d7158 100644 --- a/include/uapi/drm/etnaviv_drm.h +++ b/include/uapi/drm/etnaviv_drm.h @@ -77,6 +77,7 @@ struct drm_etnaviv_timespec { #define ETNAVIV_PARAM_GPU_PRODUCT_ID 0x1c #define ETNAVIV_PARAM_GPU_CUSTOMER_ID 0x1d #define ETNAVIV_PARAM_GPU_ECO_ID 0x1e +#define ETNAVIV_PARAM_GPU_COHERENT 0x1f =20 #define ETNA_MAX_PIPES 4 =20 --=20 2.25.1 From nobody Mon Feb 9 01:17:43 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 F139CEB64D9 for ; Mon, 19 Jun 2023 12:42:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230044AbjFSMmn (ORCPT ); Mon, 19 Jun 2023 08:42:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230253AbjFSMmW (ORCPT ); Mon, 19 Jun 2023 08:42:22 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6D695E66 for ; Mon, 19 Jun 2023 05:42:18 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.41:49634.708654646 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id 1F5C710298A; Mon, 19 Jun 2023 20:42:16 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xwndj with ESMTP id 8a8114871d834566bbad2466a63a610f for l.stach@pengutronix.de; Mon, 19 Jun 2023 20:42:18 CST X-Transaction-ID: 8a8114871d834566bbad2466a63a610f X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng , Philipp Zabel , Bjorn Helgaas Subject: [PATCH v10 08/11] drm/etnaviv: Add a dedicated function to create the virtual master Date: Mon, 19 Jun 2023 20:41:58 +0800 Message-Id: <20230619124201.2215558-9-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230619124201.2215558-1-15330273260@189.cn> References: <20230619124201.2215558-1-15330273260@189.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sui Jingfeng After introducing the etnaviv_of_first_available_node() helper, the creation of the virtual master platform device can also be simplified. So, switch to etnaviv_create_virtual_master() function. Cc: Lucas Stach Cc: Christian Gmeiner Cc: Philipp Zabel Cc: Bjorn Helgaas Cc: Daniel Vetter Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 43 ++++++++++++++++----------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnavi= v/etnaviv_drv.c index d8e788aa16cb..47b2cdbb53e2 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -767,10 +767,32 @@ static void etnaviv_destroy_platform_device(struct pl= atform_device **ppdev) *ppdev =3D NULL; } =20 +static int etnaviv_create_virtual_master(void) +{ + struct platform_device **master =3D &etnaviv_platform_device; + struct device_node *np; + + /* + * If the DT contains at least one available GPU device, instantiate + * the DRM platform device. + */ + np =3D etnaviv_of_first_available_node(); + if (np) { + int ret; + + of_node_put(np); + + ret =3D etnaviv_create_platform_device("etnaviv", master); + if (ret) + return ret; + } + + return 0; +} + static int __init etnaviv_init(void) { int ret; - struct device_node *np; =20 etnaviv_validate_init(); =20 @@ -786,22 +808,9 @@ static int __init etnaviv_init(void) if (ret !=3D 0) goto unregister_platform_driver; =20 - /* - * If the DT contains at least one available GPU device, instantiate - * the DRM platform device. - */ - for_each_compatible_node(np, NULL, "vivante,gc") { - if (!of_device_is_available(np)) - continue; - of_node_put(np); - - ret =3D etnaviv_create_platform_device("etnaviv", - &etnaviv_platform_device); - if (ret) - goto unregister_platform_driver; - - break; - } + ret =3D etnaviv_create_virtual_master(); + if (ret) + goto unregister_platform_driver; =20 return ret; =20 --=20 2.25.1 From nobody Mon Feb 9 01:17:43 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 B02FCEB64DA for ; Mon, 19 Jun 2023 12:43:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231207AbjFSMnD (ORCPT ); Mon, 19 Jun 2023 08:43:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbjFSMm0 (ORCPT ); Mon, 19 Jun 2023 08:42:26 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E5BBE10D3 for ; Mon, 19 Jun 2023 05:42:21 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.41:49634.708654646 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id E85ED102995; Mon, 19 Jun 2023 20:42:18 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xwndj with ESMTP id a4cbec9d97a5455a8cc00a4dbdebc0e3 for l.stach@pengutronix.de; Mon, 19 Jun 2023 20:42:18 CST X-Transaction-ID: a4cbec9d97a5455a8cc00a4dbdebc0e3 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng Subject: [PATCH v10 09/11] drm/etnaviv: Clean up etnaviv_pdev_probe() function Date: Mon, 19 Jun 2023 20:41:59 +0800 Message-Id: <20230619124201.2215558-10-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230619124201.2215558-1-15330273260@189.cn> References: <20230619124201.2215558-1-15330273260@189.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sui Jingfeng Add a dedicate function to do the DMA configuration to the virtual master. Also replace the &pdev->dev with dev. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 65 +++++++++++++++------------ 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnavi= v/etnaviv_drv.c index 47b2cdbb53e2..8907cdb8a1f8 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -54,6 +54,40 @@ static bool etnaviv_is_dma_coherent(struct device *dev) return coherent; } =20 +static int etnaviv_of_dma_configure(struct device *dev) +{ + struct device_node *first_node; + + /* + * PTA and MTLB can have 40 bit base addresses, but + * unfortunately, an entry in the MTLB can only point to a + * 32 bit base address of a STLB. Moreover, to initialize the + * MMU we need a command buffer with a 32 bit address because + * without an MMU there is only an indentity mapping between + * the internal 32 bit addresses and the bus addresses. + * + * To make things easy, we set the dma_coherent_mask to 32 + * bit to make sure we are allocating the command buffers and + * TLBs in the lower 4 GiB address space. + */ + if (dma_set_mask(dev, DMA_BIT_MASK(40)) || + dma_set_coherent_mask(dev, DMA_BIT_MASK(32))) { + dev_err(dev, "No suitable DMA available\n"); + return -ENODEV; + } + + /* + * Apply the same DMA configuration to the virtual etnaviv + * device as the GPU we found. This assumes that all Vivante + * GPUs in the system share the same DMA constraints. + */ + first_node =3D etnaviv_of_first_available_node(); + if (first_node) + of_dma_configure(dev, first_node, true); + + return 0; +} + /* * etnaviv private data construction and destructions: */ @@ -664,7 +698,6 @@ static const struct component_master_ops etnaviv_master= _ops =3D { static int etnaviv_pdev_probe(struct platform_device *pdev) { struct device *dev =3D &pdev->dev; - struct device_node *first_node =3D NULL; struct component_match *match =3D NULL; =20 if (!dev->platform_data) { @@ -674,10 +707,7 @@ static int etnaviv_pdev_probe(struct platform_device *= pdev) if (!of_device_is_available(core_node)) continue; =20 - if (!first_node) - first_node =3D core_node; - - drm_of_component_match_add(&pdev->dev, &match, + drm_of_component_match_add(dev, &match, component_compare_of, core_node); } } else { @@ -688,31 +718,8 @@ static int etnaviv_pdev_probe(struct platform_device *= pdev) component_match_add(dev, &match, component_compare_dev_name, names[i]); } =20 - /* - * PTA and MTLB can have 40 bit base addresses, but - * unfortunately, an entry in the MTLB can only point to a - * 32 bit base address of a STLB. Moreover, to initialize the - * MMU we need a command buffer with a 32 bit address because - * without an MMU there is only an indentity mapping between - * the internal 32 bit addresses and the bus addresses. - * - * To make things easy, we set the dma_coherent_mask to 32 - * bit to make sure we are allocating the command buffers and - * TLBs in the lower 4 GiB address space. - */ - if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(40)) || - dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32))) { - dev_dbg(&pdev->dev, "No suitable DMA available\n"); + if (etnaviv_of_dma_configure(dev)) return -ENODEV; - } - - /* - * Apply the same DMA configuration to the virtual etnaviv - * device as the GPU we found. This assumes that all Vivante - * GPUs in the system share the same DMA constraints. - */ - if (first_node) - of_dma_configure(&pdev->dev, first_node, true); =20 return component_master_add_with_match(dev, &etnaviv_master_ops, match); } --=20 2.25.1 From nobody Mon Feb 9 01:17:43 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 5F195EB64DA for ; Mon, 19 Jun 2023 12:42:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231146AbjFSMms (ORCPT ); Mon, 19 Jun 2023 08:42:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231151AbjFSMmZ (ORCPT ); Mon, 19 Jun 2023 08:42:25 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A68B9AB for ; Mon, 19 Jun 2023 05:42:20 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.41:49634.708654646 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id D93C3102997; Mon, 19 Jun 2023 20:42:18 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xwndj with ESMTP id c273b66ff6724ea4804090e8d235ef26 for l.stach@pengutronix.de; Mon, 19 Jun 2023 20:42:19 CST X-Transaction-ID: c273b66ff6724ea4804090e8d235ef26 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng Subject: [PATCH v10 10/11] drm/etnaviv: Keep the curly brace aligned Date: Mon, 19 Jun 2023 20:42:00 +0800 Message-Id: <20230619124201.2215558-11-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230619124201.2215558-1-15330273260@189.cn> References: <20230619124201.2215558-1-15330273260@189.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Sui Jingfeng No functional change. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnavi= v/etnaviv_drv.c index 8907cdb8a1f8..c9f502a89de6 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -185,7 +185,7 @@ static int etnaviv_open(struct drm_device *dev, struct = drm_file *file) drm_sched_entity_init(&ctx->sched_entity[i], DRM_SCHED_PRIORITY_NORMAL, &sched, 1, NULL); - } + } } =20 file->driver_priv =3D ctx; --=20 2.25.1 From nobody Mon Feb 9 01:17:43 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 961B3EB64D9 for ; Mon, 19 Jun 2023 12:43:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229709AbjFSMnG (ORCPT ); Mon, 19 Jun 2023 08:43:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230477AbjFSMm1 (ORCPT ); Mon, 19 Jun 2023 08:42:27 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0ABA7F9 for ; Mon, 19 Jun 2023 05:42:22 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.41:49634.708654646 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id D8EE010299B; Mon, 19 Jun 2023 20:42:19 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xwndj with ESMTP id 3963c01ed2f142e5934dee2e8a8f5cd0 for l.stach@pengutronix.de; Mon, 19 Jun 2023 20:42:20 CST X-Transaction-ID: 3963c01ed2f142e5934dee2e8a8f5cd0 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Rob Herring , Sui Jingfeng Subject: [PATCH v10 11/11] drm/etnaviv: Replace of_platform.h with explicit includes Date: Mon, 19 Jun 2023 20:42:01 +0800 Message-Id: <20230619124201.2215558-12-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230619124201.2215558-1-15330273260@189.cn> References: <20230619124201.2215558-1-15330273260@189.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Rob Herring Etnaviv doesn't use anything from of_platform.h, but depends on of.h, of_device.h, and platform_device.h which are all implicitly included, but that is going to be removed soon. Signed-off-by: Rob Herring Reviewed-by: Sui Jingfeng Tested-by: Sui Jingfeng Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnavi= v/etnaviv_drv.c index c9f502a89de6..ee47efff42a6 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -7,8 +7,10 @@ #include #include #include +#include #include -#include +#include +#include #include =20 #include --=20 2.25.1