From patchwork Wed Jun 14 02:47:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 107672 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp959655vqr; Tue, 13 Jun 2023 19:49:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5WkrrSpZu+EtcZuvn6w0IsIz/At2hylRgSFM9cF01v1fKVleqlXmJC+qLAUAc/iUTtPIFe X-Received: by 2002:a17:907:3f0d:b0:976:6824:ec76 with SMTP id hq13-20020a1709073f0d00b009766824ec76mr294662ejc.11.1686710959736; Tue, 13 Jun 2023 19:49:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686710959; cv=none; d=google.com; s=arc-20160816; b=bHY63h11jBS4E7BZF6L8vYFWuiEA6XEPYckbmav2SgafSbnrF9WUEo7tsnW+2MUH3L kUGz/U3N2Dnf2KbhyMx5DOMjpAycURqh7XFsdqkeU1ZqZWVwIMEnh+20rnll6CyWuYSY 0gTd6qsnrS411ud7Rbmoj5BaMZBylGhMqKFNzfPbDbKdBg/VW76B3/eNGi6+A3vzmuzt 1VNE4oP3akYLM4tmvHIoUTmWTsYj4t9+Np7/waC/GFJ3cLzd65Tp2zV8RzPCUplUUoz3 oV85F+bw7bkFQ9Zm12ibUysLje2iB15hfUsHq9JVYod2gYpfhbtbNSMG0yzt5H93fW0B PsaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=43h8VtkSu9HfsQwYJNXwUUXmV4KrnxmLoGYDKcVA+tg=; b=iPl+upC9+hfXJjL4MErmOiub870xJI6pUqNTch2zNJaci4l6Xl1r1136P44I/xm61v RaCGvg5O+PMBSggVPrWorzRy7rrt/0xMKa4qJhYoOwfuLGAA53aZQUaB1Vjp8TzIUcmf qtG2iDCTaXeVXrSXBMK3TFWQuRTIcJHwwgnaQUyKRUXZBEsz9vkxi+uRZdObO9nkaXbe dw2ExZR+qtb22MgWEaiqp7OCRydH/ZgVlrnNNiZxyrlnKYwiYBIH45hfsLWCmV4UCH+L nUjBum/Y+Dn7CKN3CqBg60GPKcfm+Z23mzs5Tky+/p94hUAnlMSq2OQA3vA/CKxL+vqO PL7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i8-20020a1709061e4800b00977e6c403f6si7321304ejj.78.2023.06.13.19.48.55; Tue, 13 Jun 2023 19:49:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241554AbjFNCrz (ORCPT + 99 others); Tue, 13 Jun 2023 22:47:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230231AbjFNCrv (ORCPT ); Tue, 13 Jun 2023 22:47:51 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 83E7DEA for ; Tue, 13 Jun 2023 19:47:50 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.31:39796.1729481184 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id D3D6E1002EA; Wed, 14 Jun 2023 10:47:48 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xp9j7 with ESMTP id 50ed557d58b148f0baa58f2f2858138b for l.stach@pengutronix.de; Wed, 14 Jun 2023 10:47:49 CST X-Transaction-ID: 50ed557d58b148f0baa58f2f2858138b 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 , Christian Gmeiner , Daniel Vetter , Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Sui Jingfeng , Philipp Zabel Subject: [PATCH v9 1/9] drm/etnaviv: Add a dedicated function to register an irq handler Date: Wed, 14 Jun 2023 10:47:37 +0800 Message-Id: <20230614024745.865129-2-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230614024745.865129-1-15330273260@189.cn> References: <20230614024745.865129-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768644631220580932?= X-GMAIL-MSGID: =?utf-8?q?1768644631220580932?= 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 patch to extend the driver for the PCI device support. 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/etnaviv/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[] = { }; MODULE_DEVICE_TABLE(of, etnaviv_gpu_match); +static int etnaviv_gpu_register_irq(struct etnaviv_gpu *gpu, int irq) +{ + struct device *dev = gpu->dev; + int err; + + if (irq < 0) + return irq; + + err = 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 = 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 = &pdev->dev; @@ -1837,16 +1858,9 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) return PTR_ERR(gpu->mmio); /* Get Interrupt: */ - gpu->irq = platform_get_irq(pdev, 0); - if (gpu->irq < 0) - return gpu->irq; - - err = 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 = etnaviv_gpu_register_irq(gpu, platform_get_irq(pdev, 0)); + if (err) return err; - } /* Get Clocks: */ gpu->clk_reg = devm_clk_get_optional(&pdev->dev, "reg"); From patchwork Wed Jun 14 02:47:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 107684 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp970617vqr; Tue, 13 Jun 2023 20:20:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ74QHfyeYVjeasJF50shBFh4b3XjEd+K1RfuJemqK8PGdHNzXp6oL9XUtblgOoZd1CUT60n X-Received: by 2002:a17:902:864b:b0:1b0:6544:1d4 with SMTP id y11-20020a170902864b00b001b0654401d4mr10045475plt.27.1686712822746; Tue, 13 Jun 2023 20:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686712822; cv=none; d=google.com; s=arc-20160816; b=z0rAdZRz9U/YhYPdeV89rAQvdtbPFMxmO/nSuTqObSHZm3APbZ4H6cuzNYmYyllWVo LESnvW5uqI2vxy4PhXgnnxFejOuyX6U9cQXZuTYlQRECeXAeB2yYJOj/F9oS2iPYgmBA WWskydtPn23MC7g07QOX60PrQ1rftda+ztDrkzQs7gb3LZXWAOF/sYapzp0ZrDiC2ilk 5KXaZ777A5IyAFIAo+yTDlMzmTJZK9F7fkCa/wsf//sYAuYypRICVPGQ7AhROM5vO7yy k1hvbBdZ2/tukHHwCCs2WUfN6cRpcd4qetiMnlg+xb6ZVs2/EnLauO7tr3knMJpAjEky LKaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=uqQxtS1ZOuYcXXnvPysjSFa3MtB/3k9tIHv5P9CBcxI=; b=n+TGBs5w8ZccvKvCXZ1CuYCd6YCHXF978TwNHMfEMHm/Yqj+CHRzpjspKPzGRROtVp 1f0mTjD6mODWC3vavVCY2/0Gs9gQY3+tGqRrdl7GphZLnYztg2kZhB2m3ZUp0BdzzH/m AdoOhp39F5iMgjXALTttt8E+Thz3j/f5/0zR0FZrCaV7DWdbep3Ni75s/MUEkgSjrnAh zQWq2k++xvp29lr2omhxR5C7KHB3b1a3qc8jvbLwZes4crI7QWCv/EJkz/6dBMXnVA7s YzJ1GSy1ixZ/sj5ujo2Vnq4iBhQ99ZfVwhcM9VIhRBBpLQrNiles0n+liIszPT5wq37m gwrw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a170902d2c600b001aae1eefc9bsi8141071plc.238.2023.06.13.20.20.10; Tue, 13 Jun 2023 20:20:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240748AbjFNCr6 (ORCPT + 99 others); Tue, 13 Jun 2023 22:47:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233669AbjFNCrx (ORCPT ); Tue, 13 Jun 2023 22:47:53 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 73DC8119 for ; Tue, 13 Jun 2023 19:47:51 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.31:39796.1729481184 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id C0E1F102A12; Wed, 14 Jun 2023 10:47:49 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xp9j7 with ESMTP id 89268092dad54a25b067776cddf25f68 for l.stach@pengutronix.de; Wed, 14 Jun 2023 10:47:50 CST X-Transaction-ID: 89268092dad54a25b067776cddf25f68 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 , Christian Gmeiner , Daniel Vetter , Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Sui Jingfeng , Philipp Zabel Subject: [PATCH v9 2/9] drm/etnaviv: Add a dedicated function to get various clocks Date: Wed, 14 Jun 2023 10:47:38 +0800 Message-Id: <20230614024745.865129-3-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230614024745.865129-1-15330273260@189.cn> References: <20230614024745.865129-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768646584725052011?= X-GMAIL-MSGID: =?utf-8?q?1768646584725052011?= From: Sui Jingfeng Because it is also platform-dependent, there are environments where don't have CLK subsystem support, for example, discreted PCI GPUs. So don't rage quit if there is no CLK subsystem support. For the GPU in LS7A1000 and LS2K1000, the working frequency of the GPU is tuned by configuring the PLL registers. 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/etnaviv/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; } +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; @@ -1863,27 +1892,9 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) return err; /* 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 Wed Jun 14 02:47:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 107680 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp965370vqr; Tue, 13 Jun 2023 20:05:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4doNPG+q0jV/ny3DdhY2qqd94TVt6RF+jMjQrR82POwpAectp/aNyEJ7MG/IyxIM/YmgN8 X-Received: by 2002:a17:907:daa:b0:982:6bba:79ce with SMTP id go42-20020a1709070daa00b009826bba79cemr375226ejc.12.1686711942186; Tue, 13 Jun 2023 20:05:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686711942; cv=none; d=google.com; s=arc-20160816; b=ZU0M30m8ysEinbXGK6nEWV+4G0OPZ0+ucz7/S2rE9IJT9IusaXSjdoGJ1jx5NDc8+K fEAS13SxrRoD47l67aJLPgAIOSb8V1jBxVWcMz+TxH0dq9bG9VZJPv4UQXPYE+uNDaNR RWx/OvFLsir+k5hMHFUK2wNmfjzBVq9h0yvgo5xDmDPrAfz+1zp3I/w2+dlJeN5NpJRP AVwU1qb1XM8vE6Owr1nt/IU+fHvyEgAVvTF5AKaAlMu9yuDFweZDxSaliVBZIfBQ67NI 6mbYPZT65Nl2gWgSwsJLfMzZ+Yj6mxae0kbODvOotb20TcVwrM7zotXu8cicoUZ5Eaut iXew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=I036IOlE47YU/zkCBkHIDjqcQBQLJoAnED19i/4kJrc=; b=i+TEpWWoNinLlZCYUG75jeFQOGrAKshxzrs8nhHIHrHulpeod4wzOyTT5Ptli4D8oZ ZYYMlLshRG7jFf3TiC5YPVfusZ60+DlwbKBu8LB3xbTaP0/3Ik8BrbClbnXgPJgspwsU U2Mmg7c8cwwNlDByq2di0VIJNLkAHcGldIoPcMGPJFvb6YXiaratC8kzKfG4OZb7a/0N 01Nj+gJNV1nf0FjgMXTB34mVrvl9LFOKZmn7I5aUuoA8flPRI37a8CMrQAfTSWQjGUSB bG/MqxMiUAPvrEirK6yfwhciNhdQaDeSSEyHZE58sbJIE5w8IK+ULwJAwZ/8A+nV/fcy N/cw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xo17-20020a170907bb9100b00977e0fde811si7228598ejc.507.2023.06.13.20.05.16; Tue, 13 Jun 2023 20:05:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241575AbjFNCsB (ORCPT + 99 others); Tue, 13 Jun 2023 22:48:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241345AbjFNCrx (ORCPT ); Tue, 13 Jun 2023 22:47:53 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7193BCE for ; Tue, 13 Jun 2023 19:47:52 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.31:39796.1729481184 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id C950B102A13; Wed, 14 Jun 2023 10:47:50 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xp9j7 with ESMTP id 8e1f28f3194d4dbf9a65f0a0c08edfa6 for l.stach@pengutronix.de; Wed, 14 Jun 2023 10:47:51 CST X-Transaction-ID: 8e1f28f3194d4dbf9a65f0a0c08edfa6 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 , Christian Gmeiner , Daniel Vetter , Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Sui Jingfeng , Philipp Zabel Subject: [PATCH v9 3/9] drm/etnaviv: Add dedicated functions to create and destroy platform device Date: Wed, 14 Jun 2023 10:47:39 +0800 Message-Id: <20230614024745.865129-4-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230614024745.865129-1-15330273260@189.cn> References: <20230614024745.865129-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768645661893066539?= X-GMAIL-MSGID: =?utf-8?q?1768645661893066539?= 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/etnaviv/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 = { }, }; -static struct platform_device *etnaviv_drm; +static struct platform_device *etnaviv_platform_device; -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 = platform_device_alloc(name, PLATFORM_DEVID_NONE); + if (!pdev) + return -ENOMEM; + + ret = platform_device_add(pdev); + if (ret) { + platform_device_put(pdev); + return ret; + } + + *ppdev = pdev; + + return 0; +} + +static void etnaviv_destroy_platform_device(struct platform_device **ppdev) +{ + struct platform_device *pdev = *ppdev; + + if (!pdev) + return; + + platform_device_unregister(pdev); + + *ppdev = NULL; +} + +static int __init etnaviv_init(void) +{ + int ret; struct device_node *np; 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); - pdev = platform_device_alloc("etnaviv", PLATFORM_DEVID_NONE); - if (!pdev) { - ret = -ENOMEM; - of_node_put(np); - goto unregister_platform_driver; - } - - ret = platform_device_add(pdev); - if (ret) { - platform_device_put(pdev); - of_node_put(np); + ret = etnaviv_create_platform_device("etnaviv", + &etnaviv_platform_device); + if (ret) goto unregister_platform_driver; - } - etnaviv_drm = pdev; - of_node_put(np); break; } @@ -713,7 +735,7 @@ module_init(etnaviv_init); 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); } From patchwork Wed Jun 14 02:47:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 107679 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp964177vqr; Tue, 13 Jun 2023 20:02:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5CtMnCP8dFgtuwIZuiYaHbQ/H13d4x6RESPHluLqn3oGfc20pcZs3rjADm/BkxKIMb/rVL X-Received: by 2002:a05:6a00:1706:b0:651:cd9d:7dd7 with SMTP id h6-20020a056a00170600b00651cd9d7dd7mr970294pfc.15.1686711769178; Tue, 13 Jun 2023 20:02:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686711769; cv=none; d=google.com; s=arc-20160816; b=tbus6f+WcSlBRgX227rsHOyMqTafbUSoG1zZ+jX/asN6E8iAXY+MXwu6g+Ycu77M72 Hn07NALFbQrm3Z/Ym1aSTrlN5C+rcXJzMNnN37yJ9BbtTDSg9d+UJQP3E+vwYhFF84EJ 7obTG6X/9iZ/GfnlPclY/u7NWXO1ab0250xOBtlNt32MN/QfMEQuRgbYXYH2tXQcBaZS V9w4bmcdMM/c5jsCp20sKd3Jqv2ayruQqP46vTQRXd0hBitpG2tj13aVRERnJ/aKNQ+l LhwYGREJ8P97B9elQZBViYw/ZmlGjMFoOVQg5dbykgwvUZxp7uPRSWyk6i8aoXzxKgkl prqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=GCgAytbkMElGTfLXDm0UPNO+9Aw9ddnP5qMxXO+ahaw=; b=jBCa/rZEBuEgiPjlVIkks/H1QrlqiKRTRXuQbGutgl5yPOZzhAgtzqsN5EYFiCJ3De HFfR4EPImZLWpLxUPcD1S/EuR7BI/244NsDZXCi9oKziH4Ij2Mw34vtH41PHJdz4GImI NFz9c1oDDLPbmTXAvhkneKQO+3NOIehv7hW3G7LyxwcQ5yc9p8qMWDnq5ewm3Ia8QQZf x+5psKiqoQpEC7leU1kCG7xbsIY1qnz/aTI2fcp2jIBNiKYjX9f0RR78H7624DbXhmR2 4MOi68vZ/emLAC6l6UhhshAJawJ5wRP9UPHwUdOyyt9TlOx+6Z5k1rMbSUYd8qx2qw3u gM/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f25-20020a633819000000b00542d72d19f6si9860053pga.404.2023.06.13.20.02.35; Tue, 13 Jun 2023 20:02:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242159AbjFNCsF (ORCPT + 99 others); Tue, 13 Jun 2023 22:48:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241706AbjFNCr4 (ORCPT ); Tue, 13 Jun 2023 22:47:56 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C1515CE for ; Tue, 13 Jun 2023 19:47:54 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.31:39796.1729481184 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id 496FF102A2A; Wed, 14 Jun 2023 10:47:51 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xp9j7 with ESMTP id a77d2c7ea8a2449fb6a4b6ccc2e5aab2 for l.stach@pengutronix.de; Wed, 14 Jun 2023 10:47:53 CST X-Transaction-ID: a77d2c7ea8a2449fb6a4b6ccc2e5aab2 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 , Christian Gmeiner , Daniel Vetter , Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Sui Jingfeng , Philipp Zabel Subject: [PATCH v9 4/9] drm/etnaviv: Add helpers for private data construction and destruction Date: Wed, 14 Jun 2023 10:47:40 +0800 Message-Id: <20230614024745.865129-5-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230614024745.865129-1-15330273260@189.cn> References: <20230614024745.865129-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768645480403054377?= X-GMAIL-MSGID: =?utf-8?q?1768645480403054377?= From: Sui Jingfeng struct etnaviv_drm_private contains a lot of common resources that are shared by all GPUs. This patch introduces two dedicated functions, which is for the construction and destruction of instances of this structure.      The idea is to avoid leaking its members outside. The error handling code 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/etnaviv/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" /* - * 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 = kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) + return ERR_PTR(-ENOMEM); + + priv->drm = drm; + + 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) { @@ -511,35 +549,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, drm); + 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); @@ -551,10 +575,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); @@ -570,12 +592,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); } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/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 { }; struct etnaviv_drm_private { + struct drm_device *drm; int num_gpus; struct etnaviv_gpu *gpu[ETNA_MAX_PIPES]; gfp_t shm_gfp_mask; From patchwork Wed Jun 14 02:47:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 107686 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp971567vqr; Tue, 13 Jun 2023 20:23:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6/TuyjL38QC2s8J8KZl8JeDoNO3wqktFkstImfs5szDeqpUrnqqs3Wfx4cigdwi8NYv08u X-Received: by 2002:a05:6808:158f:b0:39c:90ba:c6c with SMTP id t15-20020a056808158f00b0039c90ba0c6cmr10247928oiw.22.1686712993593; Tue, 13 Jun 2023 20:23:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686712993; cv=none; d=google.com; s=arc-20160816; b=giFBcoKZppqICGhZiCGHU7dGP1TYRcGViqf5UlWTdMSpCcL7kkcIWas0OtPIdG7eRb LwnVcafQkh05PJYHm989wXmqi2krOyVgzp0rRpmeUrAPF7nZbJBCtq58FFFEyuEncGjW aCxbcHV0gWv89ceYC/jxGLziBZ1nfZj5GZn6p4jI2XFen3nqdKWmQ39yoX15OodMCexf dXrySeKA0qcd4YqytXYP6jYoD58t/Q1zumjUrls6y21sYY2ejs1cq+Fv5pw2pBjwG7dR icJ2Ab1+bunb4cxjfmoqvk1pGtbp4Qpwys0VftUa0+CFBojPi6JzobEWw5uRcbANG0LT Ccmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=pq4sUPUAoFb4j7pH3JJEylcIiusTPXeYW6nkbdjNHb0=; b=gFMEeoH8Y5lSZnD+0oHcGvpHZ79XyoCFrXSOjzmqjh6dVLmeHAx+6Qyn8ZyKXy0rD5 HqayVnHocPcZxq4DZZQAsOz9vPHTnSpSlP9rpfnlGjyZFKU1OIpTe1+J/vTuzt2zyA+U MDzEnJrBhRHHJAEVyyAhIgHLiWDSmAjRIHFbO8FuM2woDeFbwrEw6p85LrYliY3Sh7xM pKVaJh6Fpn4eqJx2IArGLfd0pTgA0Vgi/gE3wJGHQ/OkbVjwLj3nvSRmjlFUtmWTpyZI 48VTfUmgKaI3JGfjZjLZNzoUWWdlgSkhHSHAd0tOzmmuPE/2Ub9guSh8nAfVrLaKvKI1 fh/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o9-20020a639209000000b0054294720d55si10032304pgd.262.2023.06.13.20.23.00; Tue, 13 Jun 2023 20:23:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242235AbjFNCsI (ORCPT + 99 others); Tue, 13 Jun 2023 22:48:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240237AbjFNCr4 (ORCPT ); Tue, 13 Jun 2023 22:47:56 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5B448EA for ; Tue, 13 Jun 2023 19:47:55 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.31:39796.1729481184 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id ACBCC102A32; Wed, 14 Jun 2023 10:47:53 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xp9j7 with ESMTP id 219991398cda459e80fe347b88e2327e for l.stach@pengutronix.de; Wed, 14 Jun 2023 10:47:54 CST X-Transaction-ID: 219991398cda459e80fe347b88e2327e 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 , Christian Gmeiner , Daniel Vetter , Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Sui Jingfeng , Philipp Zabel Subject: [PATCH v9 5/9] drm/etnaviv: Allow bypass component framework Date: Wed, 14 Jun 2023 10:47:41 +0800 Message-Id: <20230614024745.865129-6-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230614024745.865129-1-15330273260@189.cn> References: <20230614024745.865129-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768646764170080146?= X-GMAIL-MSGID: =?utf-8?q?1768646764170080146?= From: Sui Jingfeng Adding additional code path to allow bypass component frameworks, A platform with a single GPU core could probably try the non-component code path. This patch is for code sharing, no functional change. 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/etnaviv/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 = { .minor = 3, }; -/* - * 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) } drm->dev_private = priv; + etna_private_ptr = priv; dma_set_max_seg_size(dev, SZ_2G); - dev_set_drvdata(dev, drm); + if (component) + ret = component_bind_all(dev, drm); + else + ret = etnaviv_gpu_bind(dev, NULL, drm); - ret = component_bind_all(dev, drm); if (ret < 0) goto out_free_priv; @@ -574,7 +576,10 @@ static int etnaviv_bind(struct device *dev) return 0; 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; } -static void etnaviv_unbind(struct device *dev) +static void etnaviv_drm_unbind(struct device *dev, bool component) { - struct drm_device *drm = dev_get_drvdata(dev); - struct etnaviv_drm_private *priv = drm->dev_private; + struct etnaviv_drm_private *priv = etna_private_ptr; + struct drm_device *drm = priv->drm; drm_dev_unregister(drm); - component_unbind_all(dev, drm); + if (component) + component_unbind_all(dev, drm); + else + etnaviv_gpu_unbind(dev, NULL, drm); etnaviv_free_private(priv); @@ -599,9 +607,22 @@ static void etnaviv_unbind(struct device *dev) drm_dev_put(drm); } +/* + * 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 = { - .bind = etnaviv_bind, - .unbind = etnaviv_unbind, + .bind = etnaviv_master_bind, + .unbind = etnaviv_master_unbind, }; static int etnaviv_pdev_probe(struct platform_device *pdev) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/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 cooling_ops = { .set_cur_state = etnaviv_gpu_cooling_set_cur_state, }; -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 = data; struct etnaviv_drm_private *priv = drm->dev_private; @@ -1769,7 +1768,6 @@ static int etnaviv_gpu_bind(struct device *dev, struct device *master, if (ret < 0) goto out_sched; - gpu->drm = drm; gpu->fence_context = 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, struct device *master, return ret; } -static void etnaviv_gpu_unbind(struct device *dev, struct device *master, - void *data) +void etnaviv_gpu_unbind(struct device *dev, struct device *master, void *data) { struct etnaviv_gpu *gpu = dev_get_drvdata(dev); @@ -1867,9 +1864,11 @@ static int etnaviv_gpu_register_irq(struct etnaviv_gpu *gpu, int irq) return 0; } -static int etnaviv_gpu_platform_probe(struct platform_device *pdev) +/* platform independent */ + +static int etnaviv_gpu_driver_create(struct device *dev, void __iomem *mmio, + int irq, bool component, bool has_clk) { - struct device *dev = &pdev->dev; struct etnaviv_gpu *gpu; int err; @@ -1877,24 +1876,22 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) if (!gpu) return -ENOMEM; - gpu->dev = &pdev->dev; + gpu->dev = dev; + gpu->mmio = mmio; mutex_init(&gpu->lock); mutex_init(&gpu->sched_lock); - /* Map registers: */ - gpu->mmio = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(gpu->mmio)) - return PTR_ERR(gpu->mmio); - /* Get Interrupt: */ - err = etnaviv_gpu_register_irq(gpu, platform_get_irq(pdev, 0)); + err = etnaviv_gpu_register_irq(gpu, irq); if (err) return err; /* Get Clocks: */ - err = etnaviv_gpu_clk_get(gpu); - if (err) - return err; + if (has_clk) { + err = etnaviv_gpu_clk_get(gpu); + if (err) + return err; + } /* TODO: figure out max mapped size */ dev_set_drvdata(dev, gpu); @@ -1904,24 +1901,27 @@ 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); - - err = 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 = component_add(dev, &gpu_ops); + if (err < 0) { + dev_err(dev, "failed to register component: %d\n", err); + return err; + } } return 0; } -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); } static int etnaviv_gpu_rpm_suspend(struct device *dev) @@ -1971,6 +1971,31 @@ static const struct dev_pm_ops etnaviv_gpu_pm_ops = { RUNTIME_PM_OPS(etnaviv_gpu_rpm_suspend, etnaviv_gpu_rpm_resume, NULL) }; +static int etnaviv_gpu_platform_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + void __iomem *mmio; + int irq; + + /* Map registers: */ + mmio = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(mmio)) + return PTR_ERR(mmio); + + irq = 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 = &pdev->dev; + + etnaviv_gpu_driver_destroy(dev, true); + + return 0; +} + struct platform_driver etnaviv_gpu_driver = { .driver = { .name = "etnaviv-gpu", diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h b/drivers/gpu/drm/etnaviv/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 prefetch); +int etnaviv_gpu_bind(struct device *dev, struct device *master, void *data); +void etnaviv_gpu_unbind(struct device *dev, struct device *master, void *data); + extern struct platform_driver etnaviv_gpu_driver; #endif /* __ETNAVIV_GPU_H__ */ From patchwork Wed Jun 14 02:47:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 107677 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp963192vqr; Tue, 13 Jun 2023 20:00:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ABfVuNxxvOq1NIzDZLl3H2fuPXGw+wXCcH436hOJ/EPxPTYvI/isWfVN4MOcDfePKTj4o X-Received: by 2002:a17:907:707:b0:96a:b12d:2fdf with SMTP id xb7-20020a170907070700b0096ab12d2fdfmr14228574ejb.12.1686711648630; Tue, 13 Jun 2023 20:00:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686711648; cv=none; d=google.com; s=arc-20160816; b=eJn6B2ZRoV0VxPrmyBN1tFtPio03Wkqu8i7pCZZf+odiFIRW8ukyUzjLbLSyuwzMjT q9HvBjxxYsjggPA28DcrQ96ol6/AE63nRBbYqfu8o6Pl7CLoIPAMtiu2LVxbB5mTe6OU U9aP6sfWxrSEJr7cQPB29BuIz4tP5GExhqN7VR7DNbOcxo9UOjiaxDae7hT54rb5Sw9q FjhP8hX0XgJMnB1FNjGAQQWREne5bLQLTTwhRaAkYt0D9S7RdVUW2OpSsFreaL7BeBLZ y7gl0plIMB64sxdZB7IQOEMP1qTYTVk11vNgfoO98FC5cY2Ebtg94/yWUd8fUe6OAJK5 QWCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=Yq5S2nrdejmBlQ7pkgIXn1FgCCslyASMaLOnQpbtF9A=; b=uQhTXtEy7qtDxGhVfTS5Rdivrk31JgKjk3BhndixA7vVyQ5WpkxVXMYBBJrKmdfoD8 xY77hI8QR6yrf/gG9qd330OE8K0jamMono4r3wRnGpukLGcUTeKWvyLTO86AHGXB0r5i cfHkDpXQigutVu0WgxMleAq+BtrnOnjxyz5ay7DZEQPeim/JjBaWycsWNsk8+PgH1oI9 kjJGN1PuQEzkGd0gQZrZLyGo9zg4IBt1b+laCZiwL8orYSbN+TN0l8K74t7dKORyx6O0 UO92Y0C+O1RRYuFki/vyXVTffWVBpwvCm2qBV2XQ3IVFYYzNBnMWkzQfpdoFRk6QV0bm 0s4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a1709063c4e00b009788ec72d2fsi8161978ejg.620.2023.06.13.20.00.24; Tue, 13 Jun 2023 20:00:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242197AbjFNCsM (ORCPT + 99 others); Tue, 13 Jun 2023 22:48:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241871AbjFNCr5 (ORCPT ); Tue, 13 Jun 2023 22:47:57 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 438B71BDB for ; Tue, 13 Jun 2023 19:47:56 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.31:39796.1729481184 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id 9B1B6102A30; Wed, 14 Jun 2023 10:47:54 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xp9j7 with ESMTP id 09dde29204064a9fbd4069940ae6f7cb for l.stach@pengutronix.de; Wed, 14 Jun 2023 10:47:55 CST X-Transaction-ID: 09dde29204064a9fbd4069940ae6f7cb 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 , Christian Gmeiner , Daniel Vetter , Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Sui Jingfeng , Philipp Zabel Subject: [PATCH v9 6/9] drm/etnaviv: Add driver support for the PCI devices Date: Wed, 14 Jun 2023 10:47:42 +0800 Message-Id: <20230614024745.865129-7-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230614024745.865129-1-15330273260@189.cn> References: <20230614024745.865129-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768645353807102410?= X-GMAIL-MSGID: =?utf-8?q?1768645353807102410?= 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 of 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/Kconfig 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. +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/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 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" /* @@ -538,7 +539,7 @@ static const struct drm_driver etnaviv_drm_driver = { static struct etnaviv_drm_private *etna_private_ptr; -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 component) return ret; } -static void etnaviv_drm_unbind(struct device *dev, bool component) +void etnaviv_drm_unbind(struct device *dev, bool component) { struct etnaviv_drm_private *priv = etna_private_ptr; struct drm_device *drm = priv->drm; @@ -746,6 +747,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. @@ -763,7 +768,7 @@ static int __init etnaviv_init(void) break; } - return 0; + return ret; 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); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/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); +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/etnaviv/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_gpu *gpu, int irq) /* platform independent */ -static int etnaviv_gpu_driver_create(struct device *dev, void __iomem *mmio, - 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 *dev, void __iomem *mmio, return 0; } -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; } -static const struct dev_pm_ops etnaviv_gpu_pm_ops = { +const struct dev_pm_ops etnaviv_gpu_pm_ops = { RUNTIME_PM_OPS(etnaviv_gpu_rpm_suspend, etnaviv_gpu_rpm_resume, NULL) }; diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h b/drivers/gpu/drm/etnaviv/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 *data); +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; #endif /* __ETNAVIV_GPU_H__ */ 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..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 = &pdev->dev; + void __iomem *mmio; + 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; + + /* Map registers, assume the PCI bar 0 contain the registers */ + mmio = pcim_iomap(pdev, 0, 0); + if (IS_ERR(mmio)) + return PTR_ERR(mmio); + + ret = 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 = &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[] = { + {PCI_VDEVICE(LOONGSON, 0x7a15)}, + {PCI_VDEVICE(LOONGSON, 0x7a05)}, + { } +}; + +static struct pci_driver etnaviv_pci_driver = { + .name = "etnaviv", + .id_table = etnaviv_pci_id_lists, + .probe = etnaviv_pci_probe, + .remove = etnaviv_pci_remove, + .driver.pm = 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/etnaviv/etnaviv_pci_drv.h new file mode 100644 index 000000000000..46dffa27f8c5 --- /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 + +int etnaviv_register_pci_driver(void) { return 0; } +void etnaviv_unregister_pci_driver(void) { } + +#endif + +#endif From patchwork Wed Jun 14 02:47:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 107676 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp963189vqr; Tue, 13 Jun 2023 20:00:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7uacEvi/ZM3uqZQVYKP1yVXh5B47gsPZO3p/u6nY4LGvtkJI3qmcCcWypmF5Zuo/qU3Jt7 X-Received: by 2002:a17:906:eec5:b0:969:bac4:8e22 with SMTP id wu5-20020a170906eec500b00969bac48e22mr14425788ejb.26.1686711648101; Tue, 13 Jun 2023 20:00:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686711648; cv=none; d=google.com; s=arc-20160816; b=p0L6sG5Ysy+7KTrIZSmF0Aa275yw0gWXUDY3zXiV3xmOAD2hX0kF+ouvkGWJM/do7A /thH2M2P1l/NZIynGGfcicA2BTk8YaY8Lg+U8mj8miHGeu0XYzR48E46ymKL8L+EHEO/ 58++KpFU1JztIqtSb4hGSXr6omVqfv8v/OOY3m8tuGmwxW5kQ61cr46j3dO8ZZ9iOyRF +eZse+aGe39RhSUX7ouikAHKFE6vEUnF2kqJvLTNGlz+2udu5i1WPUerrnnkaEuiO24a EJCbrKUqsljGCJcyEfoBhtI4s0J4TaEi03TJsFLO4qiaNZ26Qi6upXFWwwztxIbHbb76 6bRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=MgTOEA8uKitHKoBrcbxTxoZwguwN0RLy0m6nRPfDbCo=; b=fJn7FKAVMRkttI+/c4Q4JEoa6QNM2tFyaBJ7uX93yeG7Lbd8op2RnI/bz4//3gQwnf GPdMdzpaUQzaenOfz+9wJC4KiMujV5IEm8NmU7rpyUMPgkvbjEWLWQUy6jop4ATpJE/a Qgop9cmZHMh50WlF1IqszkfzvXVhHk0+VaMTUJNQjAtLCV270QFz1GLBr1l8CyhxE1Ne 8744gav8+C7bOiqSvjiSt397e6YiVQZVyN2RYFConc7gK0b3U1kQRVSWNEq9Bq//+Ux4 XvtE615c7Ola9rgxh96rZbzEWrhG8gx5T3//ifMV7x8rhRhS6D8KEuczFafTZJNs67b4 xhlA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c10-20020a170906170a00b0096f8fc8e668si7289127eje.673.2023.06.13.20.00.22; Tue, 13 Jun 2023 20:00:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233639AbjFNCsW (ORCPT + 99 others); Tue, 13 Jun 2023 22:48:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242019AbjFNCr6 (ORCPT ); Tue, 13 Jun 2023 22:47:58 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 159281BE5 for ; Tue, 13 Jun 2023 19:47:56 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.31:39796.1729481184 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id 8D423102A3B; Wed, 14 Jun 2023 10:47:55 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xp9j7 with ESMTP id 9fee7db26a3b4738992b705ddeb35013 for l.stach@pengutronix.de; Wed, 14 Jun 2023 10:47:56 CST X-Transaction-ID: 9fee7db26a3b4738992b705ddeb35013 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 , Christian Gmeiner , Daniel Vetter , Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Sui Jingfeng , Philipp Zabel Subject: [PATCH v9 7/9] drm/etnaviv: Add support for the dma coherent device Date: Wed, 14 Jun 2023 10:47:43 +0800 Message-Id: <20230614024745.865129-8-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230614024745.865129-1-15330273260@189.cn> References: <20230614024745.865129-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768645353070939554?= X-GMAIL-MSGID: =?utf-8?q?1768645353070939554?= 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 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 | 34 +++++++++++++++++++++ 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, 69 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 0a365e96d371..1c9386e5a1b0 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -5,7 +5,9 @@ #include #include +#include #include +#include #include #include @@ -24,6 +26,34 @@ #include "etnaviv_pci_drv.h" #include "etnaviv_perfmon.h" +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 = etnaviv_of_first_available_node(); + if (np) { + coherent = of_dma_is_coherent(np); + of_node_put(np); + } else { + coherent = dev_is_dma_coherent(dev); + } + + return coherent; +} + /* * etnaviv private data construction and destructions: */ @@ -52,6 +82,10 @@ etnaviv_alloc_private(struct device *dev, struct drm_device *drm) return ERR_PTR(-ENOMEM); } + priv->dma_coherent = etnaviv_is_dma_coherent(dev); + + drm_info(drm, "%s is dma coherent\n", dev_name(dev)); + return priv; } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/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; + /* + * 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/etnaviv/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; lockdep_assert_held(&obj->lock); @@ -350,8 +351,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) @@ -369,6 +381,7 @@ int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op, { struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj); struct drm_device *dev = obj->dev; + struct etnaviv_drm_private *priv = dev->dev_private; bool write = !!(op & ETNA_PREP_WRITE); int ret; @@ -395,7 +408,7 @@ int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op, return ret == 0 ? -ETIMEDOUT : ret; } - 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 = op; @@ -408,8 +421,9 @@ int etnaviv_gem_cpu_fini(struct drm_gem_object *obj) { struct drm_device *dev = obj->dev; struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj); + struct etnaviv_drm_private *priv = dev->dev_private; - 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 == 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 = { 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 = dev->dev_private; struct etnaviv_gem_object *etnaviv_obj; size_t size = PAGE_ALIGN(attach->dmabuf->size); + u32 cache_flags = ETNA_BO_WC; int ret, npages; - ret = etnaviv_gem_new_private(dev, size, ETNA_BO_WC, + if (priv->dma_coherent) + cache_flags = ETNA_BO_CACHED; + + ret = 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/etnaviv/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 = gpu->identity.eco_id; break; + case ETNAVIV_PARAM_GPU_COHERENT: + *value = 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 #define ETNA_MAX_PIPES 4 From patchwork Wed Jun 14 02:47:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 107673 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp959887vqr; Tue, 13 Jun 2023 19:50:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ537mgqNmiT5kJfENJ6JOQEbNAtkp+1+HXD0N+fGGOXA3yhi9EPnj0G3JsZMFg1mPOi1poJ X-Received: by 2002:a17:906:fe43:b0:978:9b09:ccaf with SMTP id wz3-20020a170906fe4300b009789b09ccafmr15750485ejb.14.1686711005068; Tue, 13 Jun 2023 19:50:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686711005; cv=none; d=google.com; s=arc-20160816; b=BjuTiZhBpSkgV2IkFmrw4mbAzDE3ZzyI9ZistFt+O7tuoWYDUZl/zp1/sTgshQc/XD FVbKV2shE7dJB1XmGVNR6JUn7gTRcNsRJY2mwIjtoBNSXEsQGo6ZQk6dKULOIZH2PczX a+R1Rbiz9jhC9rerSGN0E6RcRaKILuwvALnL7bvJuXMYWrZT8aeNjc0q2obwFzfqZHnn S3YoLysAS9i8QICCdX99zz2AHp/LJH1Alhat9AM4bx195kU9BFnkONbF22ec6SYgkO0P v98/xvo+vwBnCg7sIgQ/aHDIY3DiN7p546pAoOEcJsn45neUsU2JiZp+iZWfio753AAR /8fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=VGySUCk7HatD+QYkz0NlLMZ1axXsvLqFptXLEpTn0oE=; b=hYwwtlUWRKVFyqTrm42YfUS5gKmA05Lv6yi/pKUXqn2Q3Zjk5Uqgepw0qxtLQpfFrh rOEvS6EP5joh8E8HgH3MNx80FbpKjkZ8s47j/G9DlYw6sllrYg04f3U7dgSHW8hosqvy yGaRIVs/VTBm8rJyFduHX0IhVbbRf4SdhOhK5ylzi2VSI0Tz5E0N659o3OXYuLEYkRy6 +BTVzIhu8OIB1Iib2lmjDZIxxU1m0wYKCtsWuywjMxTPUAsz6U/KLBvxppIrmUJteHeR t4foS8sK38rcqXyVPlHhD//k0tuxHdGhS6ohlDUwy/m/8fac6Kuj1aYvo4Jk/OnSYyTm QMwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gl16-20020a170906e0d000b0096f8b640d66si3868594ejb.104.2023.06.13.19.49.40; Tue, 13 Jun 2023 19:50:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233436AbjFNCsQ (ORCPT + 99 others); Tue, 13 Jun 2023 22:48:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242052AbjFNCr6 (ORCPT ); Tue, 13 Jun 2023 22:47:58 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E61C8CE for ; Tue, 13 Jun 2023 19:47:57 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.31:39796.1729481184 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id 819B5102A42; Wed, 14 Jun 2023 10:47:56 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xp9j7 with ESMTP id 39b79d1d098c4910a97066329ad02cb9 for l.stach@pengutronix.de; Wed, 14 Jun 2023 10:47:57 CST X-Transaction-ID: 39b79d1d098c4910a97066329ad02cb9 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 , Christian Gmeiner , Daniel Vetter , Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Sui Jingfeng , Philipp Zabel Subject: [PATCH v9 8/9] drm/etnaviv: Add a dedicated function to create the virtual master Date: Wed, 14 Jun 2023 10:47:44 +0800 Message-Id: <20230614024745.865129-9-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230614024745.865129-1-15330273260@189.cn> References: <20230614024745.865129-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768644678622736668?= X-GMAIL-MSGID: =?utf-8?q?1768644678622736668?= 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/etnaviv/etnaviv_drv.c index 1c9386e5a1b0..0ee7f641cee3 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -766,10 +766,32 @@ static void etnaviv_destroy_platform_device(struct platform_device **ppdev) *ppdev = NULL; } +static int etnaviv_create_virtual_master(void) +{ + struct platform_device **master = &etnaviv_platform_device; + struct device_node *np; + + /* + * If the DT contains at least one available GPU device, instantiate + * the DRM platform device. + */ + np = etnaviv_of_first_available_node(); + if (np) { + int ret; + + of_node_put(np); + + ret = etnaviv_create_platform_device("etnaviv", master); + if (ret) + return ret; + } + + return 0; +} + static int __init etnaviv_init(void) { int ret; - struct device_node *np; etnaviv_validate_init(); @@ -785,22 +807,9 @@ static int __init etnaviv_init(void) if (ret != 0) goto unregister_platform_driver; - /* - * 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 = etnaviv_create_platform_device("etnaviv", - &etnaviv_platform_device); - if (ret) - goto unregister_platform_driver; - - break; - } + ret = etnaviv_create_virtual_master(); + if (ret) + goto unregister_platform_driver; return ret; From patchwork Wed Jun 14 02:47:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 107682 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp966868vqr; Tue, 13 Jun 2023 20:09:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7e2N8cVHDImn7IHbAgFMTtA60C6y0A535IXOV2So4g61Dc6LdWzAqfOt8wEmQbSTZwK9FT X-Received: by 2002:a17:907:a414:b0:965:b087:8002 with SMTP id sg20-20020a170907a41400b00965b0878002mr15413545ejc.0.1686712194189; Tue, 13 Jun 2023 20:09:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686712194; cv=none; d=google.com; s=arc-20160816; b=QffMKcz+4bYkY0dqU3qmrUAix6PFZit7eC3Y+fFkkLD6mfSiWvfscuS1NIAws3nVcT Nuvg1eXbg4RHQhdBkppAe+4xUeIfnpvcAKCvIwKsRpZw+1qgzEy55LqKRTJc20vh6M/I Cj8qExBWIdQf8gGkgcHMIAkLYpwtNMxNfMcmBrkkvdDt/ST4qS3z+jmBCRb5kCzcAoGW 8Qko3tUaMF2sIprPqoukpoHQZmUpC7amfCojMNhHkJh4shBoPJszP0NGBou1LkUgDuKV 9a/BygVVGvPKBKd5cvfcizLGDC2RMejZStLHlF85VvuVUbFNHolniBQU3B4gVFr9PAdX jKrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=ryQxEOEn5nxGeynRYQSiZwrj9tClDnH39O24gmV1Ywk=; b=ymDLv4Kh9M5r6eu/O6mx5oi3zYp8VoYK6HVlOr7DCUgJhIeYZC8ZMfiQIdtD/gg4/I NgBytlibRj4qZnuJaG4R/giRsH1nl+O89rxSGl3GVZr8g5jFa1AJNAZnMqnVxsp3WxDw I2uVubz2z8yVXu0twfOrMJU5cxlT79Hu4FlHxTriDMfVQYihnu76+8ICbtPHUZoZ/hfH 0VMwEHcUXV8YmQcniEt0fFlnU3kRmgwer/36p8l7FuFKlf/vv2YyocVSheGr5MN74fS6 ISMzsEgobtfZbl1TSzoczeHVXavfO1nk06ItfeMnjshSJuxWum5iYcUVtEbHZQLyzXf1 KuPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n4-20020a1709061d0400b00977c72ac5d2si7320636ejh.468.2023.06.13.20.09.30; Tue, 13 Jun 2023 20:09:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242141AbjFNCs2 (ORCPT + 99 others); Tue, 13 Jun 2023 22:48:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242198AbjFNCsG (ORCPT ); Tue, 13 Jun 2023 22:48:06 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 12D661BE9 for ; Tue, 13 Jun 2023 19:47:59 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.31:39796.1729481184 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.31]) by 189.cn (HERMES) with SMTP id 56F9A102A0A; Wed, 14 Jun 2023 10:47:57 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-75648544bd-xp9j7 with ESMTP id 9bcf566c75864b53860340869d884dc2 for l.stach@pengutronix.de; Wed, 14 Jun 2023 10:47:59 CST X-Transaction-ID: 9bcf566c75864b53860340869d884dc2 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 , Christian Gmeiner , Daniel Vetter , Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Sui Jingfeng Subject: [PATCH v9 9/9] drm/etnaviv: Clean up etnaviv_pdev_probe() function Date: Wed, 14 Jun 2023 10:47:45 +0800 Message-Id: <20230614024745.865129-10-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230614024745.865129-1-15330273260@189.cn> References: <20230614024745.865129-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FROM_LOCAL_DIGITS, FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768645926025958096?= X-GMAIL-MSGID: =?utf-8?q?1768645926025958096?= 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/etnaviv/etnaviv_drv.c index 0ee7f641cee3..df4c21a17d9d 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; } +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 = etnaviv_of_first_available_node(); + if (first_node) + of_dma_configure(dev, first_node, true); + + return 0; +} + /* * etnaviv private data construction and destructions: */ @@ -663,7 +697,6 @@ static const struct component_master_ops etnaviv_master_ops = { static int etnaviv_pdev_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct device_node *first_node = NULL; struct component_match *match = NULL; if (!dev->platform_data) { @@ -673,10 +706,7 @@ static int etnaviv_pdev_probe(struct platform_device *pdev) if (!of_device_is_available(core_node)) continue; - if (!first_node) - first_node = core_node; - - drm_of_component_match_add(&pdev->dev, &match, + drm_of_component_match_add(dev, &match, component_compare_of, core_node); } } else { @@ -687,31 +717,8 @@ static int etnaviv_pdev_probe(struct platform_device *pdev) component_match_add(dev, &match, component_compare_dev_name, names[i]); } - /* - * 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); return component_master_add_with_match(dev, &etnaviv_master_ops, match); }