From patchwork Tue Feb 6 17:27:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13547642 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35FEEC4828D for ; Tue, 6 Feb 2024 17:28:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1AAF8112CFF; Tue, 6 Feb 2024 17:28:31 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="i0jM8bBH"; dkim-atps=neutral Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0BA23112CFC for ; Tue, 6 Feb 2024 17:28:18 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707240496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BJeg+jbAcpnrVW6uuGDu8kXydhp7MfSBefIfBQvVhDk=; b=i0jM8bBHnaZzGn07/ZaR92j+Iu1f4A+Cgb8phFRhlfoT8PgwxmsUTchLLn6lKUrr19AHY5 JdBUHc6dtAMo0LCObrJqRS4qFFuPhU1C69xvB4mmudD5s0YrJCAlbGN5/6pJwye5WVPsQY P9m2JwQ3BrypIAMlYED2dzpX4SUOX8g= From: Sui Jingfeng To: Lucas Stach Cc: Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Maxime Ripard , Thomas Zimmermann , dri-devel@lists.freedesktop.org, etnaviv@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [etnaviv-next v13 1/7] drm/etnaviv: Add a helper function to get clocks Date: Wed, 7 Feb 2024 01:27:53 +0800 Message-Id: <20240206172759.421737-2-sui.jingfeng@linux.dev> In-Reply-To: <20240206172759.421737-1-sui.jingfeng@linux.dev> References: <20240206172759.421737-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Because the current implementation is DT-based, this only works when the host platform has the DT support. The problem is that some host platforms does not provide DT-based clocks drivers, as a result, the driver rage quit. For example, the X86-64 and LoongArch desktop platform. Typically, PLL hardware is provided by the host platform, which is part of the entire clock tree, the PLL hardware provide clock pulse to the GPU core, but it's not belong to the GPU core. PLL registers can be manipulated directly by the device driver. Hence, add a dedicated helper function to get the various clocks, which make it possible to call this function only on the platform where DT support is available. 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/etnaviv/etnaviv_gpu.c index ce1e970f0209..654bf2631755 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1617,6 +1617,35 @@ static irqreturn_t irq_handler(int irq, void *data) return ret; } +static int etnaviv_gpu_clk_get(struct etnaviv_gpu *gpu) +{ + struct device *dev = gpu->dev; + + gpu->clk_reg = 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 = 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 = 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 = clk_get_rate(gpu->clk_core); + + gpu->clk_shader = 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 = clk_get_rate(gpu->clk_shader); + + return 0; +} + static int etnaviv_gpu_clk_enable(struct etnaviv_gpu *gpu) { int ret; @@ -1892,27 +1921,9 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) } /* Get Clocks: */ - gpu->clk_reg = 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 = 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 = 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 = clk_get_rate(gpu->clk_core); - - gpu->clk_shader = 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 = clk_get_rate(gpu->clk_shader); + err = etnaviv_gpu_clk_get(gpu); + if (err) + return err; /* TODO: figure out max mapped size */ dev_set_drvdata(dev, gpu); From patchwork Tue Feb 6 17:27:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13547641 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B49C7C4828D for ; Tue, 6 Feb 2024 17:28:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 00F0410F201; Tue, 6 Feb 2024 17:28:29 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="AXkiw7Lk"; dkim-atps=neutral Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) by gabe.freedesktop.org (Postfix) with ESMTPS id 592A6112CFF for ; Tue, 6 Feb 2024 17:28:22 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707240500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pOl+WgTjKJZRKMCx8JnZTX+9XX5z/UJw+mIPtTzvouc=; b=AXkiw7LknosjTimkeNik72XnkwvC61hx6D3LsGKh3kTI1I/TDMAln3jApZGBBVprJdtDwC QsXjZBfSBItjfO6qMXzR79qZHUpy2A/PWqu8f5rPQEeqKpuMG4QVhiec/ApWQgyhYc0IXP J6r5xZy2gtdavK8l5wuefY9tDUrPxco= From: Sui Jingfeng To: Lucas Stach Cc: Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Maxime Ripard , Thomas Zimmermann , dri-devel@lists.freedesktop.org, etnaviv@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [etnaviv-next v13 2/7] drm/etnaviv: Add constructor and destructor for the etnaviv_drm_private struct Date: Wed, 7 Feb 2024 01:27:54 +0800 Message-Id: <20240206172759.421737-3-sui.jingfeng@linux.dev> In-Reply-To: <20240206172759.421737-1-sui.jingfeng@linux.dev> References: <20240206172759.421737-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" There are a lot of data members in the struct etnaviv_drm_private, which are intended to be shared by all GPU cores. Introduces two dedicated helper functions for the purpose of construction and destruction. After applied this patch, the error handling of the etnaviv_bind() gets simplified a lot. Another potential benefit is that we can also put the struct drm_device into struct etnaviv_drm_private in the future, as the instance of struct drm_device is also unique across all GPU cores. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 70 +++++++++++++++++---------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 4bdfb1c81eff..035ac0c6884f 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -41,6 +41,43 @@ static struct device_node *etnaviv_of_first_available_node(void) return NULL; } +static struct etnaviv_drm_private *etnaviv_alloc_private(struct device *dev) +{ + struct etnaviv_drm_private *priv; + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) + return ERR_PTR(-ENOMEM); + + xa_init_flags(&priv->active_contexts, XA_FLAGS_ALLOC); + + mutex_init(&priv->gem_lock); + INIT_LIST_HEAD(&priv->gem_list); + priv->num_gpus = 0; + priv->shm_gfp_mask = GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN; + + priv->cmdbuf_suballoc = 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); +} + static void load_gpu(struct drm_device *dev) { struct etnaviv_drm_private *priv = dev->dev_private; @@ -521,35 +558,21 @@ static int etnaviv_bind(struct device *dev) if (IS_ERR(drm)) return PTR_ERR(drm); - priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) { - dev_err(dev, "failed to allocate private data\n"); - ret = -ENOMEM; + priv = etnaviv_alloc_private(dev); + if (IS_ERR(priv)) { + ret = PTR_ERR(priv); goto out_put; } + drm->dev_private = priv; dma_set_max_seg_size(dev, SZ_2G); - xa_init_flags(&priv->active_contexts, XA_FLAGS_ALLOC); - - mutex_init(&priv->gem_lock); - INIT_LIST_HEAD(&priv->gem_list); - priv->num_gpus = 0; - priv->shm_gfp_mask = GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN; - - priv->cmdbuf_suballoc = etnaviv_cmdbuf_suballoc_new(drm->dev); - if (IS_ERR(priv->cmdbuf_suballoc)) { - dev_err(drm->dev, "Failed to create cmdbuf suballocator\n"); - ret = PTR_ERR(priv->cmdbuf_suballoc); - goto out_free_priv; - } - dev_set_drvdata(dev, drm); ret = component_bind_all(dev, drm); if (ret < 0) - goto out_destroy_suballoc; + goto out_free_priv; load_gpu(drm); @@ -561,10 +584,8 @@ static int etnaviv_bind(struct device *dev) 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); @@ -580,12 +601,9 @@ static void etnaviv_unbind(struct device *dev) component_unbind_all(dev, drm); - etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); - - xa_destroy(&priv->active_contexts); + etnaviv_free_private(priv); drm->dev_private = NULL; - kfree(priv); drm_dev_put(drm); } From patchwork Tue Feb 6 17:27:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13547645 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1AF1C48297 for ; Tue, 6 Feb 2024 17:28:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5E67B112CFD; Tue, 6 Feb 2024 17:28:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="LKEFZU8/"; dkim-atps=neutral Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) by gabe.freedesktop.org (Postfix) with ESMTPS id D97AF10EE4F for ; Tue, 6 Feb 2024 17:28:25 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707240504; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8HAy2xAuPJeCpNnNishsphDqlFIPREAv9Gabwc+YWgA=; b=LKEFZU8/pHxDeB1+ZDDRHLp5JzF2MK73NhgWQzq5uiL9OlgqJN8Z6iG6QCZXR8q+sMXDcO E0Cc2OzMBnyaOicvvupO4LwLDe8RWRnTySRNhjIhobJUS8CXg8Sf/LULxmYY1Ipyj9mo/H l9mf7hud5VYfhzkShdKgg1s+vkDczBs= From: Sui Jingfeng To: Lucas Stach Cc: Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Maxime Ripard , Thomas Zimmermann , dri-devel@lists.freedesktop.org, etnaviv@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [etnaviv-next v13 3/7] drm/etnaviv: Embed struct drm_device in struct etnaviv_drm_private Date: Wed, 7 Feb 2024 01:27:55 +0800 Message-Id: <20240206172759.421737-4-sui.jingfeng@linux.dev> In-Reply-To: <20240206172759.421737-1-sui.jingfeng@linux.dev> References: <20240206172759.421737-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Both the instance of struct drm_device and the instance of struct etnaviv_drm_private are intended to be shared by all GPU cores. They both have only one instance across drm/etnaviv, therefore, embed struct drm_device into struct etnaviv_drm_private, and use container_of() to retrieve pointer for the containing structure. The benifit is that the DRM device can be initialized with devm_drm_dev_alloc() and the DRM device created is automatically put on driver detach, so don't need us to call drm_dev_put() explicitly on driver teardown. It's also eliminate the need to use the .dev_private member, which is deprecated according to the drm document. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 65 ++++++++------------ drivers/gpu/drm/etnaviv/etnaviv_drv.h | 7 +++ drivers/gpu/drm/etnaviv/etnaviv_gem.c | 6 +- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 6 +- drivers/gpu/drm/etnaviv/etnaviv_mmu.c | 4 +- 6 files changed, 40 insertions(+), 50 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 035ac0c6884f..5ba2b3a386b3 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -41,14 +41,9 @@ static struct device_node *etnaviv_of_first_available_node(void) return NULL; } -static struct etnaviv_drm_private *etnaviv_alloc_private(struct device *dev) +static int etnaviv_private_init(struct device *dev, + struct etnaviv_drm_private *priv) { - struct etnaviv_drm_private *priv; - - priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) - return ERR_PTR(-ENOMEM); - xa_init_flags(&priv->active_contexts, XA_FLAGS_ALLOC); mutex_init(&priv->gem_lock); @@ -58,15 +53,14 @@ static struct etnaviv_drm_private *etnaviv_alloc_private(struct device *dev) priv->cmdbuf_suballoc = 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 -ENOMEM; } - return priv; + return 0; } -static void etnaviv_free_private(struct etnaviv_drm_private *priv) +static void etnaviv_private_fini(struct etnaviv_drm_private *priv) { if (!priv) return; @@ -74,13 +68,11 @@ static void etnaviv_free_private(struct etnaviv_drm_private *priv) etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); xa_destroy(&priv->active_contexts); - - kfree(priv); } static void load_gpu(struct drm_device *dev) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); unsigned int i; for (i = 0; i < ETNA_MAX_PIPES; i++) { @@ -98,7 +90,7 @@ static void load_gpu(struct drm_device *dev) static int etnaviv_open(struct drm_device *dev, struct drm_file *file) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct etnaviv_file_private *ctx; int ret, i; @@ -141,7 +133,7 @@ static int etnaviv_open(struct drm_device *dev, struct drm_file *file) static void etnaviv_postclose(struct drm_device *dev, struct drm_file *file) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct etnaviv_file_private *ctx = file->driver_priv; unsigned int i; @@ -166,7 +158,7 @@ static void etnaviv_postclose(struct drm_device *dev, struct drm_file *file) #ifdef CONFIG_DEBUG_FS static int etnaviv_gem_show(struct drm_device *dev, struct seq_file *m) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); etnaviv_gem_describe_objects(priv, m); @@ -260,7 +252,7 @@ static int show_each_gpu(struct seq_file *m, void *arg) { struct drm_info_node *node = (struct drm_info_node *) m->private; struct drm_device *dev = node->minor->dev; - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct etnaviv_gpu *gpu; int (*show)(struct etnaviv_gpu *gpu, struct seq_file *m) = node->info_ent->data; @@ -303,7 +295,7 @@ static void etnaviv_debugfs_init(struct drm_minor *minor) static int etnaviv_ioctl_get_param(struct drm_device *dev, void *data, struct drm_file *file) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_etnaviv_param *args = data; struct etnaviv_gpu *gpu; @@ -396,7 +388,7 @@ static int etnaviv_ioctl_wait_fence(struct drm_device *dev, void *data, struct drm_file *file) { struct drm_etnaviv_wait_fence *args = data; - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_etnaviv_timespec *timeout = &args->timeout; struct etnaviv_gpu *gpu; @@ -444,7 +436,7 @@ static int etnaviv_ioctl_gem_userptr(struct drm_device *dev, void *data, static int etnaviv_ioctl_gem_wait(struct drm_device *dev, void *data, struct drm_file *file) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_etnaviv_gem_wait *args = data; struct drm_etnaviv_timespec *timeout = &args->timeout; struct drm_gem_object *obj; @@ -478,7 +470,7 @@ static int etnaviv_ioctl_gem_wait(struct drm_device *dev, void *data, static int etnaviv_ioctl_pm_query_dom(struct drm_device *dev, void *data, struct drm_file *file) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_etnaviv_pm_domain *args = data; struct etnaviv_gpu *gpu; @@ -495,7 +487,7 @@ static int etnaviv_ioctl_pm_query_dom(struct drm_device *dev, void *data, static int etnaviv_ioctl_pm_query_sig(struct drm_device *dev, void *data, struct drm_file *file) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_etnaviv_pm_signal *args = data; struct etnaviv_gpu *gpu; @@ -554,17 +546,14 @@ static int etnaviv_bind(struct device *dev) struct drm_device *drm; int ret; - drm = drm_dev_alloc(&etnaviv_drm_driver, dev); - if (IS_ERR(drm)) - return PTR_ERR(drm); + priv = devm_drm_dev_alloc(dev, &etnaviv_drm_driver, + struct etnaviv_drm_private, drm); + if (IS_ERR(priv)) + return PTR_ERR(priv); - priv = etnaviv_alloc_private(dev); - if (IS_ERR(priv)) { - ret = PTR_ERR(priv); - goto out_put; - } + etnaviv_private_init(dev, priv); - drm->dev_private = priv; + drm = &priv->drm; dma_set_max_seg_size(dev, SZ_2G); @@ -585,9 +574,7 @@ static int etnaviv_bind(struct device *dev) out_unbind: component_unbind_all(dev, drm); out_free_priv: - etnaviv_free_private(priv); -out_put: - drm_dev_put(drm); + etnaviv_private_fini(priv); return ret; } @@ -595,17 +582,13 @@ static int etnaviv_bind(struct device *dev) static void etnaviv_unbind(struct device *dev) { struct drm_device *drm = dev_get_drvdata(dev); - struct etnaviv_drm_private *priv = drm->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(drm); drm_dev_unregister(drm); component_unbind_all(dev, drm); - etnaviv_free_private(priv); - - drm->dev_private = NULL; - - drm_dev_put(drm); + etnaviv_private_fini(priv); } static const struct component_master_ops etnaviv_master_ops = { diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h index b3eb1662e90c..1f9b50b5a6aa 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 { }; struct etnaviv_drm_private { + struct drm_device drm; int num_gpus; struct etnaviv_gpu *gpu[ETNA_MAX_PIPES]; gfp_t shm_gfp_mask; @@ -50,6 +51,12 @@ struct etnaviv_drm_private { struct list_head gem_list; }; +static inline struct etnaviv_drm_private * +to_etnaviv_priv(struct drm_device *ddev) +{ + return container_of(ddev, struct etnaviv_drm_private, drm); +} + int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_file *file); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c index 71a6d2b1c80f..aa95a5e98374 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c @@ -486,7 +486,7 @@ static const struct etnaviv_gem_ops etnaviv_gem_shmem_ops = { void etnaviv_gem_free_object(struct drm_gem_object *obj) { struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj); - struct etnaviv_drm_private *priv = obj->dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(obj->dev); struct etnaviv_vram_mapping *mapping, *tmp; /* object should not be active */ @@ -517,7 +517,7 @@ void etnaviv_gem_free_object(struct drm_gem_object *obj) void etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj); mutex_lock(&priv->gem_lock); @@ -584,7 +584,7 @@ static int etnaviv_gem_new_impl(struct drm_device *dev, u32 flags, int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file, u32 size, u32 flags, u32 *handle) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_gem_object *obj = NULL; int ret; diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c index 3d0f8d182506..6b40a39fb8cd 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c @@ -413,7 +413,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_file *file) { struct etnaviv_file_private *ctx = file->driver_priv; - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_etnaviv_gem_submit *args = data; struct drm_etnaviv_gem_submit_reloc *relocs; struct drm_etnaviv_gem_submit_pmr *pmrs; diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index 654bf2631755..a407c2c9e140 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -38,7 +38,7 @@ static const struct platform_device_id gpu_ids[] = { int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value) { - struct etnaviv_drm_private *priv = gpu->drm->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(gpu->drm); switch (param) { case ETNAVIV_PARAM_GPU_MODEL: @@ -801,7 +801,7 @@ static void etnaviv_gpu_hw_init(struct etnaviv_gpu *gpu) int etnaviv_gpu_init(struct etnaviv_gpu *gpu) { - struct etnaviv_drm_private *priv = gpu->drm->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(gpu->drm); dma_addr_t cmdbuf_paddr; int ret, i; @@ -1791,7 +1791,7 @@ static int etnaviv_gpu_bind(struct device *dev, struct device *master, void *data) { struct drm_device *drm = data; - struct etnaviv_drm_private *priv = drm->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(drm); struct etnaviv_gpu *gpu = dev_get_drvdata(dev); int ret; diff --git a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c index 1661d589bf3e..c38272868328 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c @@ -490,7 +490,7 @@ void etnaviv_iommu_dump(struct etnaviv_iommu_context *context, void *buf) int etnaviv_iommu_global_init(struct etnaviv_gpu *gpu) { enum etnaviv_iommu_version version = ETNAVIV_IOMMU_V1; - struct etnaviv_drm_private *priv = gpu->drm->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(gpu->drm); struct etnaviv_iommu_global *global; struct device *dev = gpu->drm->dev; @@ -550,7 +550,7 @@ int etnaviv_iommu_global_init(struct etnaviv_gpu *gpu) void etnaviv_iommu_global_fini(struct etnaviv_gpu *gpu) { - struct etnaviv_drm_private *priv = gpu->drm->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(gpu->drm); struct etnaviv_iommu_global *global = priv->mmu_global; if (!global) From patchwork Tue Feb 6 17:27:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13547644 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E0DB2C4829C for ; Tue, 6 Feb 2024 17:28:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0D09C112CFC; Tue, 6 Feb 2024 17:28:34 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="CBSJ6Qu0"; dkim-atps=neutral Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) by gabe.freedesktop.org (Postfix) with ESMTPS id AB831112CFC for ; Tue, 6 Feb 2024 17:28:29 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707240508; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dVVAqRzMJsdMeT1oOUAb65qyjBdxIyQ/VJBw576jp8g=; b=CBSJ6Qu0yJEpGwXujNr8pa0XwekuOg2d0/VV3w1I289ams5E59ep2xR/nyVFM6UYx0qUO8 /Uf+1eNfcC4j1cK+E16/5jvKTM2f3vxIZ2CBkJBpC95681X9ifZpg2pr+13T8kQQ4Xg1Us AL6jNDSBBuP4gDk4MPYOc2p1Mfmc7uQ= From: Sui Jingfeng To: Lucas Stach Cc: Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Maxime Ripard , Thomas Zimmermann , dri-devel@lists.freedesktop.org, etnaviv@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [etnaviv-next v13 4/7] drm/etnaviv: Add support for cached coherent caching mode Date: Wed, 7 Feb 2024 01:27:56 +0800 Message-Id: <20240206172759.421737-5-sui.jingfeng@linux.dev> In-Reply-To: <20240206172759.421737-1-sui.jingfeng@linux.dev> References: <20240206172759.421737-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In the etnaviv_gem_vmap_impl(), update the page property from writecombine to PAGE_KERNEL on cached mapping. Previously, it use writecombine page property to vmap cached buffer unconditionally. Many modern CPUs choose to define the peripheral devices as DMA coherent by default, to be specific, the peripheral devices are capable of snooping CPU's cache. Therefore, cached buffers should be accessed with cached mapping. While at it, probe cached coherent support at the host platform with the dev_is_dma_coherent() function. This allows userspace to query on the runtime, which avoid compile-time macros (#ifdefs). Modern CPUs choose to define the peripheral devices as DMA coherent by default, In other words, the peripheral devices are capable of snooping CPU's cache. This means that device drivers do not need to maintain the coherency issue between a processor and an peripheral I/O for the cached mapping buffers. Such a hardware feature is implementation-defined by host CPU platform, not the vivante GPU IP core itself. X86-64, LoongArch and Loongson Mips CPU and some ARM64 CPU has the hardware maintain cache coherency, but ARM CPU is not. So provide mechanism to let userspace know. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 3 +++ drivers/gpu/drm/etnaviv/etnaviv_drv.h | 8 ++++++++ drivers/gpu/drm/etnaviv/etnaviv_gem.c | 16 ++++++++++++++-- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 4 ++++ include/uapi/drm/etnaviv_drm.h | 1 + 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 5ba2b3a386b3..e3a05b8b9330 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -57,6 +58,8 @@ static int etnaviv_private_init(struct device *dev, return -ENOMEM; } + priv->cached_coherent = dev_is_dma_coherent(dev); + return 0; } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h index 1f9b50b5a6aa..9c05f503747a 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h @@ -46,6 +46,14 @@ struct etnaviv_drm_private { struct xarray active_contexts; u32 next_context_id; + /* + * If true, the cached mapping is consistent for all CPU cores and + * peripheral bus masters in the system. It means that vboth of the + * CPU and GPU will see the same data if the buffer being access is + * cached. And coherency is guaranteed by the arch specific hardware. + */ + bool cached_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/etnaviv/etnaviv_gem.c index aa95a5e98374..eed98bb9e446 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c @@ -342,6 +342,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; lockdep_assert_held(&obj->lock); @@ -349,8 +350,19 @@ static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) if (IS_ERR(pages)) return NULL; - return vmap(pages, obj->base.size >> PAGE_SHIFT, - VM_MAP, pgprot_writecombine(PAGE_KERNEL)); + switch (obj->flags) { + case ETNA_BO_CACHED: + prot = PAGE_KERNEL; + break; + case ETNA_BO_UNCACHED: + prot = pgprot_noncached(PAGE_KERNEL); + break; + case ETNA_BO_WC: + default: + prot = pgprot_writecombine(PAGE_KERNEL); + } + + return vmap(pages, obj->base.size >> PAGE_SHIFT, VM_MAP, prot); } static inline enum dma_data_direction etnaviv_op_to_dma_dir(u32 op) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index a407c2c9e140..306973660653 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -184,6 +184,10 @@ int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value) *value = gpu->identity.axi_sram_size; break; + case ETNAVIV_PARAM_CACHED_COHERENT: + *value = priv->cached_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 d87410a8443a..7c5d988a5b9f 100644 --- a/include/uapi/drm/etnaviv_drm.h +++ b/include/uapi/drm/etnaviv_drm.h @@ -82,6 +82,7 @@ struct drm_etnaviv_timespec { #define ETNAVIV_PARAM_GPU_TP_CORE_COUNT 0x21 #define ETNAVIV_PARAM_GPU_ON_CHIP_SRAM_SIZE 0x22 #define ETNAVIV_PARAM_GPU_AXI_SRAM_SIZE 0x23 +#define ETNAVIV_PARAM_CACHED_COHERENT 0x24 #define ETNA_MAX_PIPES 4 From patchwork Tue Feb 6 17:27:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13547646 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 33059C4829C for ; Tue, 6 Feb 2024 17:28:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 90F6D112D00; Tue, 6 Feb 2024 17:28:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="dvCnJRTV"; dkim-atps=neutral Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) by gabe.freedesktop.org (Postfix) with ESMTPS id 35386112CFC for ; Tue, 6 Feb 2024 17:28:33 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707240511; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y0hdY76agQrzY+9gtVZaFHqY84LfFC9/R41cfmLOlh8=; b=dvCnJRTVEODFXuwOO7YyVPHVEEu1sDKKoH+z9Dc8yc7y0A+nMKTi+8arxlg+5p3Lnj+S29 GpgdG3j7ZriNqqmz6xWa9RjvifOP2uLBlme0lZNYhINy9OcR/9VEfG2JrBHLxqt2u5taEb tXE6/8DzvG4NxsC3XmeerKEgsM0Y5ZU= From: Sui Jingfeng To: Lucas Stach Cc: Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Maxime Ripard , Thomas Zimmermann , dri-devel@lists.freedesktop.org, etnaviv@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [etnaviv-next v13 5/7] drm/etnaviv: Replace the '&pdev->dev' with 'dev' Date: Wed, 7 Feb 2024 01:27:57 +0800 Message-Id: <20240206172759.421737-6-sui.jingfeng@linux.dev> In-Reply-To: <20240206172759.421737-1-sui.jingfeng@linux.dev> References: <20240206172759.421737-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In the etnaviv_pdev_probe() and the etnaviv_gpu_platform_probe() function, the value of '&pdev->dev' has been cached to a local auto variable (which is named as 'dev'), but part of caller functions use 'dev' as argument, but the rest use '&pdev->dev'. To keep it consistent, use 'dev' uniformly. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 10 +++++----- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index e3a05b8b9330..d5a5fcc30341 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -612,7 +612,7 @@ static int etnaviv_pdev_probe(struct platform_device *pdev) if (!of_device_is_available(core_node)) continue; - drm_of_component_match_add(&pdev->dev, &match, + drm_of_component_match_add(dev, &match, component_compare_of, core_node); } } else { @@ -635,9 +635,9 @@ static int etnaviv_pdev_probe(struct platform_device *pdev) * 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 (dma_set_mask(dev, DMA_BIT_MASK(40)) || + dma_set_coherent_mask(dev, DMA_BIT_MASK(32))) { + dev_dbg(dev, "No suitable DMA available\n"); return -ENODEV; } @@ -648,7 +648,7 @@ static int etnaviv_pdev_probe(struct platform_device *pdev) */ first_node = etnaviv_of_first_available_node(); if (first_node) { - of_dma_configure(&pdev->dev, first_node, true); + of_dma_configure(dev, first_node, true); of_node_put(first_node); } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index 306973660653..3fd637c17797 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1903,7 +1903,7 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) if (!gpu) return -ENOMEM; - gpu->dev = &pdev->dev; + gpu->dev = dev; mutex_init(&gpu->lock); mutex_init(&gpu->sched_lock); @@ -1917,8 +1917,8 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) if (gpu->irq < 0) return gpu->irq; - err = devm_request_irq(&pdev->dev, gpu->irq, irq_handler, 0, - dev_name(gpu->dev), gpu); + err = devm_request_irq(dev, gpu->irq, irq_handler, 0, + dev_name(dev), gpu); if (err) { dev_err(dev, "failed to request IRQ%u: %d\n", gpu->irq, err); return err; @@ -1937,13 +1937,13 @@ static int etnaviv_gpu_platform_probe(struct platform_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); + pm_runtime_use_autosuspend(dev); + pm_runtime_set_autosuspend_delay(dev, 200); + pm_runtime_enable(dev); - err = component_add(&pdev->dev, &gpu_ops); + err = component_add(dev, &gpu_ops); if (err < 0) { - dev_err(&pdev->dev, "failed to register component: %d\n", err); + dev_err(dev, "failed to register component: %d\n", err); return err; } From patchwork Tue Feb 6 17:27:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13547647 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B8053C48297 for ; Tue, 6 Feb 2024 17:28:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 04252112D04; Tue, 6 Feb 2024 17:28:39 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="bj9f6nPN"; dkim-atps=neutral Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by gabe.freedesktop.org (Postfix) with ESMTPS id 79357112D03 for ; Tue, 6 Feb 2024 17:28:37 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707240516; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jmVPFCNKCEoxyfP5fWPRoMeSPbEbmBVNboqHaLmwopU=; b=bj9f6nPNUnvNreGxSEJL4GRanUU7epVcP9jtGuoNULXnMXPcYRC8wNMLn1F/9NdkMVaYxx rsABrTZTT8ee69ohJDd7pIwPlD9xmEuQnkNVKaOW4GFfph5FtQCL9dcx2Rc6ilrBkL+lc7 W6tnQifptQj4MMRWcdDpGe/xKyH8moI= From: Sui Jingfeng To: Lucas Stach Cc: Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Maxime Ripard , Thomas Zimmermann , dri-devel@lists.freedesktop.org, etnaviv@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [etnaviv-next v13 6/7] drm/etnaviv: Update the implement of etnaviv_create_platform_device() Date: Wed, 7 Feb 2024 01:27:58 +0800 Message-Id: <20240206172759.421737-7-sui.jingfeng@linux.dev> In-Reply-To: <20240206172759.421737-1-sui.jingfeng@linux.dev> References: <20240206172759.421737-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Because we need this function to create virtial child. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 33 +++++++++++++++++++++++---- drivers/gpu/drm/etnaviv/etnaviv_drv.h | 9 ++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index d5a5fcc30341..5f65f2dead44 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -670,16 +670,36 @@ static struct platform_driver etnaviv_platform_driver = { }, }; -static int etnaviv_create_platform_device(const char *name, - struct platform_device **ppdev) +int etnaviv_create_platform_device(struct device *parent, + const char *name, int id, + struct resource *pres, + void *data, + struct platform_device **ppdev) { struct platform_device *pdev; int ret; - pdev = platform_device_alloc(name, PLATFORM_DEVID_NONE); + pdev = platform_device_alloc(name, id); if (!pdev) return -ENOMEM; + pdev->dev.parent = parent; + + if (pres) { + ret = platform_device_add_resources(pdev, pres, 1); + if (ret) { + platform_device_put(pdev); + return ret; + } + } + + if (data) { + void *pdata = kmalloc(sizeof(void *), GFP_KERNEL); + + *(void **)pdata = data; + pdev->dev.platform_data = pdata; + } + ret = platform_device_add(pdev); if (ret) { platform_device_put(pdev); @@ -691,7 +711,7 @@ static int etnaviv_create_platform_device(const char *name, return 0; } -static void etnaviv_destroy_platform_device(struct platform_device **ppdev) +void etnaviv_destroy_platform_device(struct platform_device **ppdev) { struct platform_device *pdev = *ppdev; @@ -728,7 +748,10 @@ static int __init etnaviv_init(void) if (np) { of_node_put(np); - ret = etnaviv_create_platform_device("etnaviv", &etnaviv_drm); + ret = etnaviv_create_platform_device(NULL, "etnaviv", + PLATFORM_DEVID_NONE, + NULL, NULL, + &etnaviv_drm); if (ret) goto unregister_platform_driver; } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h index 9c05f503747a..bd8ac64dbaf3 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -97,6 +98,14 @@ 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); +int etnaviv_create_platform_device(struct device *parent, + const char *name, int id, + struct resource *pres, + void *data, + struct platform_device **ppdev); + +void etnaviv_destroy_platform_device(struct platform_device **ppdev); + #ifdef CONFIG_DEBUG_FS void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv, struct seq_file *m); From patchwork Tue Feb 6 17:27:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 13547648 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31CAFC4829C for ; Tue, 6 Feb 2024 17:28:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6D50B10EE4F; Tue, 6 Feb 2024 17:28:43 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.b="N0V6+Fi0"; dkim-atps=neutral Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by gabe.freedesktop.org (Postfix) with ESMTPS id 26529112D03 for ; Tue, 6 Feb 2024 17:28:41 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707240519; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IuDNXHrtfsKiiCQUnd7vhGhnPyKVBJ6ejLgzQPnQqMM=; b=N0V6+Fi0RXnwW3dJ4Ogl6JoBR1dfoPD69CvJuAXnCmi2BDy5JBAQQAgh2/PYYk1r/bN1EI cqXzKgVUMld365VCGyYlVUt0mWI6geHRc8QIDSAlBox1Aqa+CTeTj58RsMUo1vKw7FsA3f p0UeLuGV+nWcZ7KvDoEp9gEYIKRinNc= From: Sui Jingfeng To: Lucas Stach Cc: Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Maxime Ripard , Thomas Zimmermann , dri-devel@lists.freedesktop.org, etnaviv@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [etnaviv-next v13 7/7] drm/etnaviv: Add support for vivante GPU cores attached via PCI(e) Date: Wed, 7 Feb 2024 01:27:59 +0800 Message-Id: <20240206172759.421737-8-sui.jingfeng@linux.dev> In-Reply-To: <20240206172759.421737-1-sui.jingfeng@linux.dev> References: <20240206172759.421737-1-sui.jingfeng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The component helper functions are the glue, which is used to bind multiple GPU cores to a virtual master platform device. Which is fine and works well for the SoCs who contains multiple GPU cores. The problem is that usperspace programs (such as X server and Mesa) will search the PCIe device to use if it is exist. In other words, usperspace programs open the PCIe device with higher priority. Creating a virtual master platform device for PCI(e) GPUs is unnecessary, as the PCI device has been created by the time drm/etnaviv is loaded. we create virtual platform devices as a representation for the vivante GPU ip core. As all of subcomponent are attached via the PCIe master device, we reflect this hardware layout by binding all of the virtual child to the the real master. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/Kconfig | 8 + drivers/gpu/drm/etnaviv/Makefile | 2 + drivers/gpu/drm/etnaviv/etnaviv_drv.c | 12 +- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 75 ++++++-- drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 4 + drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c | 224 ++++++++++++++++++++++ drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h | 18 ++ 7 files changed, 327 insertions(+), 16 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/Kconfig index faa7fc68b009..38c251585ec1 100644 --- a/drivers/gpu/drm/etnaviv/Kconfig +++ b/drivers/gpu/drm/etnaviv/Kconfig @@ -15,6 +15,14 @@ config DRM_ETNAVIV help DRM driver for Vivante GPUs. +config DRM_ETNAVIV_PCI_DRIVER + bool "enable ETNAVIV PCI driver support" + depends on DRM_ETNAVIV + depends on PCI + help + Compile in support for Vivante GPUs attached via PCI(e). + Say Y if you have such hardwares. + 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/Makefile index 46e5ffad69a6..6829e1ebf2db 100644 --- a/drivers/gpu/drm/etnaviv/Makefile +++ b/drivers/gpu/drm/etnaviv/Makefile @@ -16,4 +16,6 @@ etnaviv-y := \ etnaviv_perfmon.o \ etnaviv_sched.o +etnaviv-$(CONFIG_DRM_ETNAVIV_PCI_DRIVER) += etnaviv_pci_drv.o + obj-$(CONFIG_DRM_ETNAVIV) += etnaviv.o diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 5f65f2dead44..48e2402adbe3 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -24,6 +24,7 @@ #include "etnaviv_gpu.h" #include "etnaviv_gem.h" #include "etnaviv_mmu.h" +#include "etnaviv_pci_drv.h" #include "etnaviv_perfmon.h" /* @@ -566,6 +567,10 @@ static int etnaviv_bind(struct device *dev) if (ret < 0) goto out_free_priv; + ret = etnaviv_register_irq_handler(dev, priv); + if (ret) + goto out_unbind; + load_gpu(drm); ret = drm_dev_register(drm, 0); @@ -594,7 +599,7 @@ static void etnaviv_unbind(struct device *dev) etnaviv_private_fini(priv); } -static const struct component_master_ops etnaviv_master_ops = { +const struct component_master_ops etnaviv_master_ops = { .bind = etnaviv_bind, .unbind = etnaviv_unbind, }; @@ -740,6 +745,10 @@ static int __init etnaviv_init(void) if (ret != 0) goto unregister_gpu_driver; + ret = etnaviv_register_pci_driver(); + if (ret != 0) + goto unregister_platform_driver; + /* * If the DT contains at least one available GPU device, instantiate * the DRM platform device. @@ -769,6 +778,7 @@ module_init(etnaviv_init); static void __exit etnaviv_exit(void) { etnaviv_destroy_platform_device(&etnaviv_drm); + etnaviv_unregister_pci_driver(); platform_driver_unregister(&etnaviv_platform_driver); platform_driver_unregister(&etnaviv_gpu_driver); } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index 3fd637c17797..221020e98900 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,7 @@ static const struct platform_device_id gpu_ids[] = { { .name = "etnaviv-gpu,2d" }, + { .name = "etnaviv-gpu,3d" }, { }, }; @@ -1555,14 +1557,22 @@ static void dump_mmu_fault(struct etnaviv_gpu *gpu) static irqreturn_t irq_handler(int irq, void *data) { - struct etnaviv_gpu *gpu = data; + struct etnaviv_drm_private *priv = data; irqreturn_t ret = IRQ_NONE; + int i; - u32 intr = gpu_read(gpu, VIVS_HI_INTR_ACKNOWLEDGE); - - if (intr != 0) { + for (i = 0; i < priv->num_gpus; i++) { + struct etnaviv_gpu *gpu = priv->gpu[i]; + u32 intr; int event; + if (!gpu) + continue; + + intr = gpu_read(gpu, VIVS_HI_INTR_ACKNOWLEDGE); + if (!intr) + continue; + pm_runtime_mark_last_busy(gpu->dev); dev_dbg(gpu->dev, "intr 0x%08x\n", intr); @@ -1893,10 +1903,44 @@ static const struct of_device_id etnaviv_gpu_match[] = { }; MODULE_DEVICE_TABLE(of, etnaviv_gpu_match); +/* + * dev point to the master. For platform device, it is virtual. + * For PCI(e) device, it is real. + */ +int etnaviv_register_irq_handler(struct device *dev, + struct etnaviv_drm_private *priv) +{ + bool is_pci = dev_is_pci(dev); + int ret = 0; + + if (is_pci) { + struct pci_dev *pdev = to_pci_dev(dev); + + ret = request_irq(pdev->irq, irq_handler, IRQF_SHARED, + dev_name(dev), priv); + } else { + int i; + + for (i = 0; i < priv->num_gpus; i++) { + struct etnaviv_gpu *gpu = priv->gpu[i]; + + ret = devm_request_irq(gpu->dev, gpu->irq, irq_handler, + 0, dev_name(dev), priv); + if (ret) { + dev_err(dev, "failed to request IRQ handler: %d\n", ret); + break; + } + } + } + + return ret; +} + static int etnaviv_gpu_platform_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct etnaviv_gpu *gpu; + bool is_pci; int err; gpu = devm_kzalloc(dev, sizeof(*gpu), GFP_KERNEL); @@ -1912,22 +1956,23 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) if (IS_ERR(gpu->mmio)) return PTR_ERR(gpu->mmio); + is_pci = dev->parent ? dev_is_pci(dev->parent) : false; + /* Get Interrupt: */ - gpu->irq = platform_get_irq(pdev, 0); + if (is_pci) + gpu->irq = to_pci_dev(dev->parent)->irq; + else + gpu->irq = platform_get_irq(pdev, 0); + if (gpu->irq < 0) return gpu->irq; - err = devm_request_irq(dev, gpu->irq, irq_handler, 0, - dev_name(dev), gpu); - if (err) { - dev_err(dev, "failed to request IRQ%u: %d\n", gpu->irq, err); - return err; - } - /* Get Clocks: */ - err = etnaviv_gpu_clk_get(gpu); - if (err) - return err; + if (!is_pci) { + err = etnaviv_gpu_clk_get(gpu); + if (err) + return err; + } /* TODO: figure out max mapped size */ dev_set_drvdata(dev, gpu); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h index 7d5e9158e13c..d354e096652c 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h @@ -208,6 +208,10 @@ static inline u32 gpu_read_power(struct etnaviv_gpu *gpu, u32 reg) int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value); int etnaviv_gpu_init(struct etnaviv_gpu *gpu); + +int etnaviv_register_irq_handler(struct device *dev, + struct etnaviv_drm_private *priv); + bool etnaviv_fill_identity_from_hwdb(struct etnaviv_gpu *gpu); #ifdef CONFIG_DEBUG_FS diff --git a/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c new file mode 100644 index 000000000000..ec5039866eda --- /dev/null +++ b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c @@ -0,0 +1,224 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +#include "etnaviv_drv.h" +#include "etnaviv_pci_drv.h" + +enum etnaviv_pci_gpu_chip_id { + GC_CORE_UNKNOWN = 0, + JM9100 = 1, + JD9230P = 2, + GP102 = 3, + GC1000_IN_LS7A1000 = 4, + GC1000_IN_LS2K1000 = 5, + GC_CORE_PCI_LAST, +}; + +struct etnaviv_pci_gpu_data { + enum etnaviv_pci_gpu_chip_id chip_id; + u32 num_core; + u32 num_vram; + u32 vram_bars[2]; + u32 mmio_bar; + struct { + u32 id; + u32 offset; + u32 size; + char compatible[20]; + } cores[ETNA_MAX_PIPES]; + + bool has_dedicated_vram; + char market_name[24]; +}; + +static const struct etnaviv_pci_gpu_data +gc_core_plaform_data[GC_CORE_PCI_LAST] = { + { + .chip_id = GC_CORE_UNKNOWN, + }, + { + .chip_id = JM9100, + .num_core = 1, + .num_vram = 2, + .vram_bars = {0, 2}, + .mmio_bar = 1, + .cores = {{0, 0x00900000, 0x00010000, "etnaviv-gpu,3d"},}, + .has_dedicated_vram = true, + .market_name = "JingJia Micro JM9100", + }, + { + .chip_id = JD9230P, + .num_core = 2, + .num_vram = 2, + .vram_bars = {0, 2}, + .mmio_bar = 1, + .cores = {{0, 0x00900000, 0x00010000, "etnaviv-gpu,3d"}, + {1, 0x00910000, 0x00010000, "etnaviv-gpu,3d"},}, + .has_dedicated_vram = true, + .market_name = "JingJia Micro JD9230P", + }, + { + .chip_id = GP102, + .num_core = 2, + .num_vram = 1, + .vram_bars = {0,}, + .mmio_bar = 2, + .cores = {{0, 0x00040000, 0x00010000, "etnaviv-gpu,3d"}, + {0, 0x000C0000, 0x00010000, "etnaviv-gpu,2d"},}, + .has_dedicated_vram = true, + .market_name = "LingJiu GP102", + }, + { + .chip_id = GC1000_IN_LS7A1000, + .num_core = 1, + .num_vram = 1, + .vram_bars = {2,}, + .mmio_bar = 0, + .cores = {{0, 0, 0x00010000, "etnaviv-gpu,3d"}, {}, {}, {}}, + .has_dedicated_vram = true, + .market_name = "GC1000 in LS7A1000", + }, + { + .chip_id = GC1000_IN_LS2K1000, + .num_core = 1, + .num_vram = 0, + .mmio_bar = 0, + .cores = {{0, 0, 0x00010000, "etnaviv-gpu,3d"}, {}, {}, {}}, + .has_dedicated_vram = false, + .market_name = "GC1000 in LS2K1000", + }, +}; + +static const struct etnaviv_pci_gpu_data * +etnaviv_pci_get_platform_data(const struct pci_device_id *entity) +{ + enum etnaviv_pci_gpu_chip_id chip_id = entity->driver_data; + static const struct etnaviv_pci_gpu_data *pdata; + + pdata = &gc_core_plaform_data[chip_id]; + if (!pdata || pdata->chip_id == GC_CORE_UNKNOWN) + return NULL; + + return pdata; +} + +extern const struct component_master_ops etnaviv_master_ops; + +static int etnaviv_pci_probe(struct pci_dev *pdev, + const struct pci_device_id *ent) +{ + const struct etnaviv_pci_gpu_data *pdata; + struct device *dev = &pdev->dev; + struct component_match *matches = NULL; + unsigned int i; + unsigned int num_core; + int ret; + + ret = pcim_enable_device(pdev); + if (ret) { + dev_err(dev, "failed to enable\n"); + return ret; + } + + pci_set_master(pdev); + + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); + if (ret) + return ret; + + pdata = etnaviv_pci_get_platform_data(ent); + if (!pdata) + return -ENODEV; + + num_core = pdata->num_core; + + dev_info(dev, "%s has %u GPU cores\n", pdata->market_name, num_core); + + /* + * Create a virtual platform device for the sub-component, + * a sub-component is refer to a single vivante GPU core. + * But it can also be extended to stand for a display controller + * or any other IP core attached via the same PCIe master. + */ + for (i = 0; i < num_core; i++) { + struct platform_device *virtual_child; + resource_size_t start, offset, size; + struct resource res; + + start = pci_resource_start(pdev, pdata->mmio_bar); + offset = pdata->cores[i].offset; + size = pdata->cores[i].size; + + memset(&res, 0, sizeof(res)); + res.flags = IORESOURCE_MEM; + res.name = "reg"; + res.start = start + offset; + res.end = start + offset + size - 1; + + ret = etnaviv_create_platform_device(dev, + pdata->cores[i].compatible, + pdata->cores[i].id, + &res, + (void *)pdata, + &virtual_child); + if (ret) + return ret; + + component_match_add(dev, &matches, component_compare_dev, + &virtual_child->dev); + } + + ret = component_master_add_with_match(dev, &etnaviv_master_ops, matches); + + return ret; +} + +static int platform_device_remove_callback(struct device *dev, void *data) +{ + struct platform_device *pdev = to_platform_device(dev); + + etnaviv_destroy_platform_device(&pdev); + + return 0; +} + +static void etnaviv_pci_remove(struct pci_dev *pdev) +{ + struct device *dev = &pdev->dev; + + component_master_del(dev, &etnaviv_master_ops); + + device_for_each_child(dev, NULL, platform_device_remove_callback); + + pci_clear_master(pdev); +} + +static const struct pci_device_id etnaviv_pci_id_lists[] = { + {0x0731, 0x9100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, JM9100}, + {0x0731, 0x9230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, JD9230P}, + {0x0709, 0x0001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GP102}, + {0x0014, 0x7A15, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GC1000_IN_LS7A1000}, + {0x0014, 0x7A05, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GC1000_IN_LS2K1000}, + { } +}; + +static struct pci_driver etnaviv_pci_driver = { + .name = "etnaviv", + .id_table = etnaviv_pci_id_lists, + .probe = etnaviv_pci_probe, + .remove = etnaviv_pci_remove, +}; + +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/etnaviv/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