From patchwork Tue May 30 16:06:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 100966 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2304803vqr; Tue, 30 May 2023 09:26:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Q0DYzv7U0JDsS85fvxNcN0AkEqwILZt5QZ/V8TQVlVKHFfg3vJShHn3QGjmlM8HwdFSS3 X-Received: by 2002:a05:6a00:1746:b0:648:ebb2:3d6 with SMTP id j6-20020a056a00174600b00648ebb203d6mr2953315pfc.26.1685463963914; Tue, 30 May 2023 09:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685463963; cv=none; d=google.com; s=arc-20160816; b=NqeCndbTroh/6x2RIQpYTfp36EpHO2JIOyFUmqZgUtzdOZwxZfCNJaG2BNQKOJ9bPb /VwexmklFqM8OTnw43YPwiY1Lb9VAdjHd//F/e02xZaBVfgp0MeKgCHAzlOHbqzcyqcQ R5PABnAZXjkYwmZylJut7QJlE/pQcJCWah4/ylz5Aj7nBZSldS7o34zj64Gnx1MQhbfy B+E1cjHWYnnI9CxAwdcXLguOlgrCr6pcIzUE+epQRWBb0015+/3ySJCRIfgS8CDX4k4/ VAF9R+bXJU422NWVVpiJlSbbLs7bggg4Ps8fegkC84Tzcvl4jNzJ7m/sKDfQvmqB2SOT uLHQ== 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; bh=g5GoVmte3jQk00l9vGqH6+GoCz0MdKE/5Y4kSzc27Ss=; b=FaB9I8gWgOZQoQ59449NMXcyHYLrm8aoKot/Trc6yiMnh+R4Vc65+uatNzGcHwYkaR Miq3vbojwgFIzHF2gH4y+wdZozt8Ggky7+KIVAAF7FWLX3d8NzCKVI98kdojprlvFmVC +z+JyEs3mwjiohropNA3F6JC7XvJl3gJ2Nui8f5QBJiO1II+U891l45bFMHgBVSY7KqZ WyjQDnMbj8ZeTs0Z9Jq7LJQZ0JG+pOuQgEAmFjdi9MCOgxINEmPLXJVaoIS0ro2PAC9O 7l1j8lqkcQyfh97eHqrq0OkKM3Y9CAyrFIvnri9g3ex4Z9R5+hfp6VuF7pVKIRzzA2jq XYjQ== 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 w67-20020a627b46000000b00626007418c3si218965pfc.289.2023.05.30.09.25.49; Tue, 30 May 2023 09:26:03 -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 S232977AbjE3QHF (ORCPT + 99 others); Tue, 30 May 2023 12:07:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231965AbjE3QGx (ORCPT ); Tue, 30 May 2023 12:06:53 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 89874114 for ; Tue, 30 May 2023 09:06:45 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8Bx7OoTH3ZkFqYCAA--.1548S3; Wed, 31 May 2023 00:06:43 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxqrYTH3Zket+AAA--.13773S3; Wed, 31 May 2023 00:06:43 +0800 (CST) From: Sui Jingfeng To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v6 1/6] drm/etnaviv: add a dedicated function to register an irq handler Date: Wed, 31 May 2023 00:06:38 +0800 Message-Id: <20230530160643.2344551-2-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230530160643.2344551-1-suijingfeng@loongson.cn> References: <20230530160643.2344551-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxqrYTH3Zket+AAA--.13773S3 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7AFWDWF4UKFyfArW3ZF47Jwb_yoW8Zr15pa 17Ja4Ykr18ua42g34fZF98ZF1akw1IqayIkwnrt3sak398Jrs8JryFkF1UJa4fAryrGay3 tF1jgFWUuF45u3DanT9S1TB71UUUU1UqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bSAYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84 ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4j6r4UJwAa w2AFwI0_Jw0_GFyle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44 I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Wrv_ZF1lYx0Ex4A2 jsIE14v26F4j6r4UJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxV Aaw2AFwI0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxY O2xFxVAFwI0_Jw0_GFylx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGV WUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_ Ar0_tr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj4 0_Jr0_JF4lIxAIcVC2z280aVAFwI0_Cr0_Gr1UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_ Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jh8n5UUUUU= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1767337061455351081?= X-GMAIL-MSGID: =?utf-8?q?1767337061455351081?= 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 support for the PCI device. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 34 ++++++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index de8c9894967c..636d3f39ddcb 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1817,6 +1817,29 @@ 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) { + dev_err(dev, "failed to get irq: %d\n", irq); + 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 handler registered, irq = %d\n", irq); + + return 0; +} + static int etnaviv_gpu_platform_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1837,16 +1860,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 Tue May 30 16:06:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 100973 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2305415vqr; Tue, 30 May 2023 09:27:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4QQn7fyOzXeeC5UjU/eEUI43onHBTCjnkWOCLkFNfY0cOn+IgcJGKnnOo7wolJGAXFkWCd X-Received: by 2002:a05:6a21:3a8e:b0:ec:d7cf:bcf7 with SMTP id zv14-20020a056a213a8e00b000ecd7cfbcf7mr2542948pzb.17.1685464023734; Tue, 30 May 2023 09:27:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685464023; cv=none; d=google.com; s=arc-20160816; b=mEuF9HB6my/PUFnq/cy2NmejJ1fM0Iv83vkqT910xHw478+k7bv3dwUop33TW21xRD LrLR0kqbLH9/ij6NvMHWaQOO9AemX67Fy1SRt3Fjwi7Lx4OEt/nFXjW8DXx3pdbDJSBH Hzx3QQq6gWX4yWQDNXQWFJKulMznxxtRE+ugNjBVWqE9RMp9kzLpOXW6CEpUSo0scpTN EDvkWvzmK/7Q6lWf8cWo8DfFUs8rxl36jzKuFP6eqa6dYVVK2P1J9OePRYFvmdHW+EE7 iqukDF/P66ngqRgFEPjW2Y3CF4QAc8mQ01KBeCAJ4iPPcTGY74KJ/Ksg/qAYeVhK4hPi Ryuw== 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; bh=fepsGobuFg9aHpZsZqWq6X1c1R5Y3wG5ilGfUYb2rT8=; b=yO/DsO/UT/tc/aCgzs+7MdrZOyYjTL6k7fxWpiHYlsRglrwgqtxTNWeZeN9PSjC5Iw 5iQoLWR8sbZ1E3vMyUTkFGnsbrtIYQzclanAsR2JuECdy8dZ96Go2fNI6UClbGuyEpXO NY2mmCBNywQXzkzjyP9VxQZRiilloUfGpAwhKUgUnzy9gHFq7lWN+MWwhzxxw5UMw/sU X0UfMJI2Tzx8Xl43UYUeYD6XkmxQZ9OlvkEbDJQ8vUysZ9pvcNYROQ40zxBTt41DAlow 0RMWqBKQjJQEPO1WMzXWTj2k8AiyvJS/ctKiStWBI6Y2jKadBiEzzJK38KEHChIZpXWV /utg== 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 k10-20020a637b4a000000b0053481e4c743si11959818pgn.171.2023.05.30.09.26.49; Tue, 30 May 2023 09:27:03 -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 S233165AbjE3QHB (ORCPT + 99 others); Tue, 30 May 2023 12:07:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230317AbjE3QGx (ORCPT ); Tue, 30 May 2023 12:06:53 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E0380109 for ; Tue, 30 May 2023 09:06:45 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8BxmPEUH3ZkIaYCAA--.5994S3; Wed, 31 May 2023 00:06:44 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxqrYTH3Zket+AAA--.13773S4; Wed, 31 May 2023 00:06:43 +0800 (CST) From: Sui Jingfeng To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v6 2/6] drm/etnaviv: add a dedicated function to get various clocks Date: Wed, 31 May 2023 00:06:39 +0800 Message-Id: <20230530160643.2344551-3-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230530160643.2344551-1-suijingfeng@loongson.cn> References: <20230530160643.2344551-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxqrYTH3Zket+AAA--.13773S4 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxGw45JrWrAFW5Gr4rKw47XFb_yoWrGw1xpa 1fJa4Ykr1UZryjg347AFn8trnIkw1xCa4xC3s0vwnavw45JF4Ut3yYkFZ8XFs8ZryrWFWf Kr15Kr4UCFyF9rDanT9S1TB71UUUU1UqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bh8YFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84 ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4j6r4UJwAa w2AFwI0_Jw0_GFyle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44 I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_ZF0_GryDMcIj6I8E 87Iv67AKxVWxJVW8Jr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I 0En4kS14v26r1q6r43MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCI bckI1I0E14v26r1q6r43MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_Jr I_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v2 6F1j6w1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7 xG6r1j6r1xMIIF0xvEx4A2jsIE14v26F4j6r4UJwCI42IY6I8E87Iv6xkF7I0E14v26r4j 6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUVsjjUUUUU X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1767337124453410908?= X-GMAIL-MSGID: =?utf-8?q?1767337124453410908?= Because it is also platform-dependent, there are environments where don't have CLK subsystem support, for example, discreted PCI gpu. So don't rage quit if there is no CLK subsystem. For the GPU in LS7a1000 and LS2k2000, the working frequency of the GPU is tuned by configuring the PLL register directly. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 62 ++++++++++++++++++--------- drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 1 + 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index 636d3f39ddcb..4937580551a5 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1565,10 +1565,45 @@ 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; + + if (gpu->no_clk) + return 0; + + 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; + if (gpu->no_clk) + return 0; + ret = clk_prepare_enable(gpu->clk_reg); if (ret) return ret; @@ -1599,6 +1634,9 @@ static int etnaviv_gpu_clk_enable(struct etnaviv_gpu *gpu) static int etnaviv_gpu_clk_disable(struct etnaviv_gpu *gpu) { + if (gpu->no_clk) + return 0; + clk_disable_unprepare(gpu->clk_shader); clk_disable_unprepare(gpu->clk_core); clk_disable_unprepare(gpu->clk_bus); @@ -1865,27 +1903,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); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h index 98c6f9c320fc..6da5209a7d64 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h @@ -148,6 +148,7 @@ struct etnaviv_gpu { struct clk *clk_reg; struct clk *clk_core; struct clk *clk_shader; + bool no_clk; unsigned int freq_scale; unsigned long base_rate_core; From patchwork Tue May 30 16:06:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 100967 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2305113vqr; Tue, 30 May 2023 09:26:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ40Mg7UVYHDwolsJzYg2IcZIhqh4Ah9yWmFX+30S2dNE1ikB42WIuVT4bAUs1yJU4G+Yerj X-Received: by 2002:a05:6a20:4288:b0:10c:5ff4:8bc6 with SMTP id o8-20020a056a20428800b0010c5ff48bc6mr3435482pzj.38.1685463994578; Tue, 30 May 2023 09:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685463994; cv=none; d=google.com; s=arc-20160816; b=pR6dxsJC9wgt1/96BOyrPpR+EVPdJUTEE1PY3s7aa3bj9rFI/v6YqVYq9IKqPAxxhb vkTHGllMtlzu5kVmojTntEEi10/MpqOGNPu8iuCZS5nsAfCNuy2PzwGOn1XygUTKTEOx dkPg3sr1TpdwHPV36uzd02/KPrxtkGmIkurMIeR5cN0d7OpT++6D7ZdI1UFba7kQjodb kvYUhWJ6iq1dPA0Vy92vZaQur1RPth2h0WBClPCfW+SZlczis7txVr0MlRlMWfPMC2O3 OzjFBhRrdocwq7k06OIQe7mz1qtBP76Cwf3P+kBWcWL/t/3zOgfmBzJA/am5b63fxm1o /4fA== 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; bh=q6caTcGh0X5Gh+bgcvS3STOCkrhXCuWqt7xr31+tKFQ=; b=AnGlYiugEwTl1r8sYDBG0D96qF5vToc5efCFMjXQC9tY9vvlq+GDj0yziMKNSKb8Ez JVVe3igiEqhis1mYAtiCDqrONwun/7anb8k/YkjEZrvI5dooV5F9bTBXAY2vmabrvTdS 6u71sKBp22kemZTlBLwvRZ9GoQaSYx3jB0adWN/EMHhziCaa6sY+fTO66zWbRJ0GEtfk 5DuKucsXLauyt/iwcn6lv4ua3OmH8krzYxayRZVaDGsbhLG9ecVNDiztljjJpQScrpNo semo5A7o63Na08fOfNsoE8cxgAmrtC7bL5J90JP/nhzgNesxeiPUWFbPLZhGOk58LKx8 FY8A== 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 d74-20020a621d4d000000b006434d66f94dsi1947820pfd.31.2023.05.30.09.26.20; Tue, 30 May 2023 09:26:34 -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 S232903AbjE3QGz (ORCPT + 99 others); Tue, 30 May 2023 12:06:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230174AbjE3QGx (ORCPT ); Tue, 30 May 2023 12:06:53 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DE5F2106 for ; Tue, 30 May 2023 09:06:45 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8AxhPAUH3ZkKKYCAA--.5872S3; Wed, 31 May 2023 00:06:44 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxqrYTH3Zket+AAA--.13773S5; Wed, 31 May 2023 00:06:43 +0800 (CST) From: Sui Jingfeng To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v6 3/6] drm/etnaviv: add dedicated functions to create and destroy platform devices Date: Wed, 31 May 2023 00:06:40 +0800 Message-Id: <20230530160643.2344551-4-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230530160643.2344551-1-suijingfeng@loongson.cn> References: <20230530160643.2344551-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxqrYTH3Zket+AAA--.13773S5 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxAr4ftrWxCr4xuFWkKFyxAFb_yoW5GF48pF 17GFWSyrW8uFW7Kw1xXwn8ZFW5C3WIg34F9rnFywnI9398AryDJF95GFyUAFnxJrWrG3W5 t39xtF4xuF45ZrJanT9S1TB71UUUU1UqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bh8YFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84 ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4j6r4UJwAa w2AFwI0_Jw0_GFyle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44 I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_ZF0_GryDMcIj6I8E 87Iv67AKxVWxJVW8Jr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I 0En4kS14v26r1q6r43MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCI bckI1I0E14v26r1q6r43MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_Jr I_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v2 6F1j6w1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7 xG6r1j6r1xMIIF0xvEx4A2jsIE14v26F4j6r4UJwCI42IY6I8E87Iv6xkF7I0E14v26r4j 6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUVsjjUUUUU X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1767337093880862850?= X-GMAIL-MSGID: =?utf-8?q?1767337093880862850?= 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. 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..0a9d90c18f2c 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; + + *ppdev = NULL; + + platform_device_unregister(pdev); +} + +static int __init etnaviv_init(void) +{ + int ret; struct device_node *np; etnaviv_validate_init(); @@ -682,22 +714,12 @@ static int __init etnaviv_init(void) if (!of_device_is_available(np)) continue; - 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); + of_node_put(np); + 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 Tue May 30 16:06:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 100963 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2304539vqr; Tue, 30 May 2023 09:25:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ65NY7mcHjJqyCdBISZFKeBer4XyEw1ZPzkJzDGx7CtKzZAlmviBMbgnjFnKaqIvbgQynVv X-Received: by 2002:a17:902:9002:b0:1a9:7ffb:5ed0 with SMTP id a2-20020a170902900200b001a97ffb5ed0mr2651167plp.59.1685463937498; Tue, 30 May 2023 09:25:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685463937; cv=none; d=google.com; s=arc-20160816; b=QLvayPEDIGaRplBLfXZHuun1QbGYVkKHyscF6nBX1zerqBTr5IIbweQwO1Z9pvz2e1 JLRNMj+Q1W4NBS5uYybDoj+MoYiZrwAP0jmewz3tvofCy8qQ15LYeqwii+AFQtJI9yEz uzJiDp6pLF3muqHUnh2Xu90DtoeqDpL3j0S7cNufNvRePMF0a+r5abJC3ol1DGMprZct vdu0OYWJocc6tJn+RTNm235rtUZF99yqmoJPaxNmXMSA+kefSvoVS9oh/QbOWMHwn4G1 tLOH2gXALoa7VgT+Owa45jOPz9J3jG0u2jswepQBWm6Km59QC/581IWbSOujA0UoebUO gIsg== 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; bh=hV666E4Kvnp6xtfEHPENgXUtKOT40MQjhx/HLYPbDgg=; b=E59SZ6wB2VrHA4de49FpSEAG4Yb1xBrBPlD26y5amanmJzDFQCPpD2YkA8kDIt6Orf 9fkugRySnJX43GEkhaQGH0ROnqcYS+LHXpuSgcZCSJdi6SYv3IR1Svj5qiAgsrB70W7Q gCYJFQ7q1bwu05SiUGoOvJW3ERW62Y5r5CbbfeAIZJnY9VdZtDdnCAYZcKFsP10N10Yb IUy7nJoRaDTeI1tO0NUhKMoZq+H6JqTxBWCgztVjPEefZPaNfJymDtY9kdZGCfFBGfpT sb0GET979uxfWyxfImjj5HP2oOpdyP2/7ReX4mHS8weJ6sNCstyRNNibQjyn7U0vFdEK KRyg== 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 bf6-20020a170902b90600b001adb600d4dcsi10870628plb.607.2023.05.30.09.25.23; Tue, 30 May 2023 09:25:37 -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 S233288AbjE3QHO (ORCPT + 99 others); Tue, 30 May 2023 12:07:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232714AbjE3QGz (ORCPT ); Tue, 30 May 2023 12:06:55 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 89E54116 for ; Tue, 30 May 2023 09:06:45 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8BxFvEUH3ZkLKYCAA--.6024S3; Wed, 31 May 2023 00:06:44 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxqrYTH3Zket+AAA--.13773S6; Wed, 31 May 2023 00:06:44 +0800 (CST) From: Sui Jingfeng To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v6 4/6] drm/etnaviv: add helpers for private data construction and destruction Date: Wed, 31 May 2023 00:06:41 +0800 Message-Id: <20230530160643.2344551-5-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230530160643.2344551-1-suijingfeng@loongson.cn> References: <20230530160643.2344551-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxqrYTH3Zket+AAA--.13773S6 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxCw4rWr47Gr17WF1kGF1rJFb_yoWrCFy8pF srJa40yrWvvF48K3sxJrs8Za43C3WxWa409asFqwn0qw4ayr1kWFn5tFyUAF9xJFyrCFy3 tw1Dtr1UXF40krJanT9S1TB71UUUU1UqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bh8YFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84 ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4j6r4UJwAa w2AFwI0_Jw0_GFyle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44 I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_ZF0_GryDMcIj6I8E 87Iv67AKxVWxJVW8Jr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I 0En4kS14v26r1q6r43MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCI bckI1I0E14v26r1q6r43MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_Jr I_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v2 6F1j6w1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7 xG6r1j6r1xMIIF0xvEx4A2jsIE14v26F4j6r4UJwCI42IY6I8E87Iv6xkF7I0E14v26r4j 6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU3U73UUUUU X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1767337033388719831?= X-GMAIL-MSGID: =?utf-8?q?1767337033388719831?= 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. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 71 +++++++++++++++++---------- drivers/gpu/drm/etnaviv/etnaviv_drv.h | 4 ++ 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 0a9d90c18f2c..56c98711f8e1 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -498,28 +498,17 @@ static const struct drm_driver etnaviv_drm_driver = { .minor = 3, }; -/* - * Platform driver: - */ -static int etnaviv_bind(struct device *dev) +static int etnaviv_alloc_private(struct device *dev, + struct etnaviv_drm_private **ppriv) { struct etnaviv_drm_private *priv; - struct drm_device *drm; int ret; - drm = drm_dev_alloc(&etnaviv_drm_driver, 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; - goto out_put; + return -ENOMEM; } - drm->dev_private = priv; - - dma_set_max_seg_size(dev, SZ_2G); xa_init_flags(&priv->active_contexts, XA_FLAGS_ALLOC); @@ -528,18 +517,55 @@ static int etnaviv_bind(struct device *dev) priv->num_gpus = 0; priv->shm_gfp_mask = GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN; - priv->cmdbuf_suballoc = etnaviv_cmdbuf_suballoc_new(drm->dev); + priv->cmdbuf_suballoc = etnaviv_cmdbuf_suballoc_new(dev); if (IS_ERR(priv->cmdbuf_suballoc)) { - dev_err(drm->dev, "Failed to create cmdbuf suballocator\n"); + dev_err(dev, "Failed to create cmdbuf suballocator\n"); ret = PTR_ERR(priv->cmdbuf_suballoc); - goto out_free_priv; + kfree(priv); + return ret; } + *ppriv = priv; + + return 0; +} + +static void etnaviv_free_private(struct etnaviv_drm_private *priv) +{ + etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); + + xa_destroy(&priv->active_contexts); + + kfree(priv); +} + +/* + * Platform driver: + */ +static int etnaviv_bind(struct device *dev) +{ + struct etnaviv_drm_private *priv; + struct drm_device *drm; + int ret; + + drm = drm_dev_alloc(&etnaviv_drm_driver, dev); + if (IS_ERR(drm)) + return PTR_ERR(drm); + + ret = etnaviv_alloc_private(dev, &priv); + if (ret) + goto out_put; + + priv->drm = drm; + drm->dev_private = priv; + + dma_set_max_seg_size(dev, SZ_2G); + 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 +577,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 +594,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..87fb52c03c5e 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; @@ -45,6 +46,9 @@ struct etnaviv_drm_private { struct xarray active_contexts; u32 next_context_id; + /* hint for platform support cached coherent caching mode */ + bool has_cached_coherent; + /* list of GEM objects: */ struct mutex gem_lock; struct list_head gem_list; From patchwork Tue May 30 16:06:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 100975 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2305447vqr; Tue, 30 May 2023 09:27:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5WVyq6/KRlZ0B766z/RSnD+gJYfr3sYPXJeP8qU7PbuxR0O/MjRUbWr/BSDstnv7HXqxbY X-Received: by 2002:a17:902:9898:b0:1ab:d89:5ef6 with SMTP id s24-20020a170902989800b001ab0d895ef6mr2241084plp.68.1685464026651; Tue, 30 May 2023 09:27:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685464026; cv=none; d=google.com; s=arc-20160816; b=xc22dbiZ9LbSnpAHsVK+76zBi4XsRVCZw0/aeJKWtxwEpcb+mv4JcNR8II1HtaNtC5 8MqDrn+P1iTUAIeYbi6KU6h6A4uSr0gqLM7AzTNQgH+vytOcEm/KnGx9qhMkXSzEcFww wgb6g8KBXISLUEiU99SROFB0wp2ZPK2r+oJ/8zy00imTG4DSBeSHftl4MNc5XYvn94y5 hqUahTc1Kiij9u6iqbZiuMbhSmUoGXrw8G3tABRQ6CbjQgYkBXa7cyfUxFhlTLPR4AwW QQxDOueIla/AHGXW7cMNVeYBHv8AF/NDGUu8eGh+mnPpQz2rKiL/kpBgKk5cfE2wu4bL 1b9A== 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; bh=7ve1gkPa/B+DfVhta+KAqVr7WLpp2xWmxJbnCTYujYk=; b=rRblPLEs8xljdxtroMI5WcDWyqwRkKIIKkJvNmiurftCsx4N+z9fr3xk24UyjYFgHP LrGcfBkslj44QgpyfBbuzPgSomU1HtiERTVyKKOvosqQCIIyfdmUQQ4LfYWhYRYKtHtu kR3MYRWGn91O7uycDb69q4vOXIFaZ/bdpFhk3e544SVo3ZpzqdAcg29ln8FT86WYYytg ZZwQ7Tejbgl6kYgPk6q/5v4nxnKUNWJg32TT3yA+FWXJcnhSY0iGVPjb2B0oqyedE0QK flDDDZQ7VWOpFF6tJxZo5ng2YOf1PNDDlM3qeQ0T5LVV4iv1H2B/44Mw/kz80OffjwO4 96+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 o10-20020a1709026b0a00b001ab0498403fsi11028437plk.169.2023.05.30.09.26.51; Tue, 30 May 2023 09:27:06 -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 S233216AbjE3QHL (ORCPT + 99 others); Tue, 30 May 2023 12:07:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232380AbjE3QGy (ORCPT ); Tue, 30 May 2023 12:06:54 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0E3DC10E for ; Tue, 30 May 2023 09:06:45 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8DxuPEUH3ZkNqYCAA--.5993S3; Wed, 31 May 2023 00:06:44 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxqrYTH3Zket+AAA--.13773S7; Wed, 31 May 2023 00:06:44 +0800 (CST) From: Sui Jingfeng To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v6 5/6] drm/etnaviv: add driver support for the PCI devices Date: Wed, 31 May 2023 00:06:42 +0800 Message-Id: <20230530160643.2344551-6-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230530160643.2344551-1-suijingfeng@loongson.cn> References: <20230530160643.2344551-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxqrYTH3Zket+AAA--.13773S7 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvAXoWfGF1xGr4DurW5JF15uryrtFb_yoW8WFW7Ko WxZrnxXa1rGFZ3t398AF12gFy3ZwsrCa45uan8trs09aykXF15tw13ta13tF1avr1FgrWf Zw1jqw15JFyxJFn5n29KB7ZKAUJUUUUJ529EdanIXcx71UUUUU7KY7ZEXasCq-sGcSsGvf J3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnRJU UUBGb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2IYs7xG6rWj6s 0DM7CIcVAFz4kK6r126r13M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26F4j6r4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4U JwAaw2AFwI0_Jw0_GFyle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4 CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_ZF0_GryDMcIj 6I8E87Iv67AKxVWxJVW8Jr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMx kF7I0En4kS14v26r1q6r43MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4U MxCIbckI1I0E14v26r1q6r43MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI 0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE 14v26w1j6s0DMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE42xK8VAvwI 8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWxJVW8Jr1lIxAIcVC2z280aVCY1x0267AK xVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07jS388UUUUU= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1767337127507221159?= X-GMAIL-MSGID: =?utf-8?q?1767337127507221159?= This patch adds PCI driver support on top of what 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. Because we want to bind the DRM driver service to the PCI driver manually.      We avoid using the component framework because the virtual master device will not be used without a force override. X server and Mesa will try to find the PCI device to use by default. Creating a virtual master device for PCI GPUs cause unnecessary troubles.      Using the component framework with a PCI device is still possible; it is just that the solo PCI device should be the master. A platform with a single GPU core could also try the non-component code path. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/Kconfig | 9 +++ drivers/gpu/drm/etnaviv/Makefile | 2 + drivers/gpu/drm/etnaviv/etnaviv_drv.c | 69 +++++++++++++--- drivers/gpu/drm/etnaviv/etnaviv_drv.h | 3 + drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 97 ++++++++++++++++------- drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 12 +++ drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c | 87 ++++++++++++++++++++ drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h | 12 +++ 8 files changed, 250 insertions(+), 41 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..dbf948f99976 100644 --- a/drivers/gpu/drm/etnaviv/Kconfig +++ b/drivers/gpu/drm/etnaviv/Kconfig @@ -15,6 +15,15 @@ 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. + 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 56c98711f8e1..052f745cecc0 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" /* @@ -525,6 +526,16 @@ static int etnaviv_alloc_private(struct device *dev, return ret; } + /* + * Loongson Mips and LoongArch CPU(ls3a5000, ls3a4000, ls2k1000la) + * maintain cache coherency by hardware + */ + if (IS_ENABLED(CONFIG_CPU_LOONGSON64) || IS_ENABLED(CONFIG_LOONGARCH)) + priv->has_cached_coherent = true; + + dev_info(dev, "Cached coherent mode is %s\n", + priv->has_cached_coherent ? "support" : "not support"); + *ppriv = priv; return 0; @@ -539,10 +550,9 @@ static void etnaviv_free_private(struct etnaviv_drm_private *priv) kfree(priv); } -/* - * Platform driver: - */ -static int etnaviv_bind(struct device *dev) +static struct etnaviv_drm_private *etna_private_s; + +int etnaviv_drm_bind(struct device *dev, bool component) { struct etnaviv_drm_private *priv; struct drm_device *drm; @@ -558,12 +568,15 @@ static int etnaviv_bind(struct device *dev) priv->drm = drm; drm->dev_private = priv; + etna_private_s = 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; @@ -585,14 +598,17 @@ static int etnaviv_bind(struct device *dev) return ret; } -static void etnaviv_unbind(struct device *dev) +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_s; + 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); @@ -601,9 +617,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) @@ -727,6 +756,12 @@ static int __init etnaviv_init(void) if (ret != 0) goto unregister_gpu_driver; +#ifdef CONFIG_DRM_ETNAVIV_PCI_DRIVER + ret = pci_register_driver(&etnaviv_pci_driver); +#endif + if (ret != 0) + goto unregister_platform_driver; + /* * If the DT contains at least one available GPU device, instantiate * the DRM platform device. @@ -739,13 +774,17 @@ static int __init etnaviv_init(void) &etnaviv_platform_device); of_node_put(np); if (ret) - goto unregister_platform_driver; + goto unregister_all_driver; break; } return 0; +unregister_all_driver: +#ifdef CONFIG_DRM_ETNAVIV_PCI_DRIVER + pci_unregister_driver(&etnaviv_pci_driver); +#endif unregister_platform_driver: platform_driver_unregister(&etnaviv_platform_driver); unregister_gpu_driver: @@ -759,6 +798,10 @@ 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); + +#ifdef CONFIG_DRM_ETNAVIV_PCI_DRIVER + pci_unregister_driver(&etnaviv_pci_driver); +#endif } module_exit(etnaviv_exit); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h index 87fb52c03c5e..934fc3744389 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h @@ -86,6 +86,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 4937580551a5..700f2414b87d 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1565,10 +1565,11 @@ static irqreturn_t irq_handler(int irq, void *data) return ret; } -static int etnaviv_gpu_clk_get(struct etnaviv_gpu *gpu) +static int etnaviv_gpu_clk_get(struct etnaviv_gpu *gpu, bool no_clk) { struct device *dev = gpu->dev; + gpu->no_clk = no_clk; if (gpu->no_clk) return 0; @@ -1746,8 +1747,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; @@ -1778,7 +1778,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); @@ -1807,8 +1806,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); @@ -1878,9 +1876,37 @@ static int etnaviv_gpu_register_irq(struct etnaviv_gpu *gpu, int irq) return 0; } -static int etnaviv_gpu_platform_probe(struct platform_device *pdev) +static int etnaviv_gpu_plat_drv_init(struct etnaviv_gpu *gpu, bool component) +{ + struct device *dev = gpu->dev; + struct platform_device *pdev = to_platform_device(dev); + int err; + + /* Map registers: */ + gpu->mmio = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(gpu->mmio)) + return PTR_ERR(gpu->mmio); + + 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 void etnaviv_gpu_plat_drv_fini(struct etnaviv_gpu *gpu, bool component) +{ + if (component) + component_del(gpu->dev, &gpu_ops); +} + +int etnaviv_gpu_driver_create(struct device *dev, int irq, bool component, + bool no_clk, pfn_gpu_init_t gpu_post_init) { - struct device *dev = &pdev->dev; struct etnaviv_gpu *gpu; int err; @@ -1888,22 +1914,16 @@ 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); - /* 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); + err = etnaviv_gpu_clk_get(gpu, no_clk); if (err) return err; @@ -1915,23 +1935,44 @@ 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); - if (err < 0) { - dev_err(&pdev->dev, "failed to register component: %d\n", err); - return err; - } + gpu_post_init(gpu, component); return 0; } +void etnaviv_gpu_driver_destroy(struct device *dev, bool component, + pfn_gpu_fini_t gpu_early_fini) +{ + struct etnaviv_gpu *gpu = dev_get_drvdata(dev); + + if (!gpu) { + dev_err(dev, "device not initialized properly\n"); + return; + } + + gpu_early_fini(gpu, component); + + pm_runtime_disable(dev); +} + +static int etnaviv_gpu_platform_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + int irq = platform_get_irq(pdev, 0); + + return etnaviv_gpu_driver_create(dev, irq, true, false, etnaviv_gpu_plat_drv_init); +} + static int etnaviv_gpu_platform_remove(struct platform_device *pdev) { - component_del(&pdev->dev, &gpu_ops); - pm_runtime_disable(&pdev->dev); + struct device *dev = &pdev->dev; + + etnaviv_gpu_driver_destroy(dev, true, etnaviv_gpu_plat_drv_fini); + return 0; } @@ -1978,7 +2019,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 6da5209a7d64..cfcdc5dde9d9 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h @@ -207,6 +207,18 @@ 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); +typedef int (*pfn_gpu_init_t)(struct etnaviv_gpu *gpu, bool component); +typedef void (*pfn_gpu_fini_t)(struct etnaviv_gpu *gpu, bool component); + +int etnaviv_gpu_driver_create(struct device *dev, int irq, bool component, + bool no_clk, pfn_gpu_init_t post_init); +void etnaviv_gpu_driver_destroy(struct device *dev, bool component, + pfn_gpu_fini_t early_fini); + +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; +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..d0bb6615c434 --- /dev/null +++ b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +#include "etnaviv_drv.h" +#include "etnaviv_gpu.h" +#include "etnaviv_pci_drv.h" + +enum etnaviv_pci_gpu_family { + GC1000_IN_LS7A1000 = 0, + GC1000_IN_LS2K1000 = 1, +}; + +static int etnaviv_gpu_pci_init(struct etnaviv_gpu *gpu, bool component) +{ + struct pci_dev *pdev = to_pci_dev(gpu->dev); + + /* Map registers, assume the PCI bar 0 contain the registers */ + gpu->mmio = pcim_iomap(pdev, 0, 0); + if (IS_ERR(gpu->mmio)) + return PTR_ERR(gpu->mmio); + + gpu->no_clk = true; + + return 0; +} + +static void etnaviv_gpu_pci_fini(struct etnaviv_gpu *gpu, bool component) +{ + struct pci_dev *pdev = to_pci_dev(gpu->dev); + + pci_clear_master(pdev); + + dev_dbg(gpu->dev, "component %s\n", component ? "enabled" : "disabled"); +} + +static int etnaviv_pci_probe(struct pci_dev *pdev, + const struct pci_device_id *ent) +{ + struct device *dev = &pdev->dev; + int ret; + + ret = pcim_enable_device(pdev); + if (ret) { + dev_err(&pdev->dev, "failed to enable\n"); + return ret; + } + + pci_set_master(pdev); + + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); + if (ret) + return ret; + + /* Create a GPU driver instance for the PCI device itself */ + ret = etnaviv_gpu_driver_create(dev, pdev->irq, false, true, + etnaviv_gpu_pci_init); + 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, etnaviv_gpu_pci_fini); +} + +static const struct pci_device_id etnaviv_pci_id_lists[] = { + {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}, + {0, 0, 0, 0, 0, 0, 0} +}; + +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), +}; + +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..e4f8183c5558 --- /dev/null +++ b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ETNAVIV_PCI_DRV_H__ +#define __ETNAVIV_PCI_DRV_H__ + +#include + +#ifdef CONFIG_DRM_ETNAVIV_PCI_DRIVER +extern struct pci_driver etnaviv_pci_driver; +#endif + +#endif From patchwork Tue May 30 16:06:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 100962 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2294636vqr; Tue, 30 May 2023 09:11:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ54xbdnIusuJ17WwezMpvCEjd33OjDZuRTI9nk3SnPsRJ7InBdt5Bq7msHyRlPHhmU/Y9k5 X-Received: by 2002:a17:902:e5d0:b0:1af:981b:eeff with SMTP id u16-20020a170902e5d000b001af981beeffmr3134212plf.64.1685463075131; Tue, 30 May 2023 09:11:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685463075; cv=none; d=google.com; s=arc-20160816; b=l/AF1R9/njcwJAuxgN0zwWDT4bvAZUL3VsWS7SGp33hGILwwsgkTmZ/WFEfn/H7ZDL QNV4AsU3TbXkVYPJ/h2b49A9cFmi1jCBOEGm5+Ke6dLKorj40AOeAG4ijYL8p9RP8OJd clpa9/cmTCZceaQKVKsTOQ4QjKknCGRtJq6vXzjWyWdRffTJwoV6PtrxIta3utztn4rO BFSLlAAnrcAhau9ZgfyTNPBX5KLhxxnGlQvfS6VHR90wfQzyWvuH62BUCSI2+BN5QRDY 9NqmMdN6aZwRTb2UEDYy732HrlqmYJfGAsp1eOHg4vvHuNIC7EaqPuliRudqDZXGv5we ND9w== 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; bh=gLpnV9R/pkjzQEOYgaXyEywX4NlQ5aEf7/ZwOHv7Xdc=; b=bN6x0YHxhTSTb7smHgzcH37Qiz2/Bv8ZKaYD4iVnm71vaoAuH5s2GHdDH5/bnsH2ly jHFZFZEJ/pfYSgkkDFpLtrx0FqjisgJCcYwL1k3de2Pib5hB1uV5VL4pDCWuoIpJkaPw wVdwWfv438J5rmbVJMtShng6mv+vUL94lAhlBt6tEJLjvEmTmF20TrIJCpjiBw01H37k SxG2DRrKWyensntEsl6tpZ6mqQ8ZeM/H+QcrJBb60e1IvAkUEFt014T85dvFeoqtppK8 4RgQURQmz6sOHU55y+TnPBc2lvdqu1HqloXa6wkuqimFJpzviWJ8OJyLvqZvUnT27Z5n aGpw== 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 m5-20020a170902768500b001ac6d4e1d72si11118625pll.149.2023.05.30.09.10.59; Tue, 30 May 2023 09:11:15 -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 S231256AbjE3QHI (ORCPT + 99 others); Tue, 30 May 2023 12:07:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232315AbjE3QGx (ORCPT ); Tue, 30 May 2023 12:06:53 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0EC66113 for ; Tue, 30 May 2023 09:06:45 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8Dxd_EUH3ZkOaYCAA--.6090S3; Wed, 31 May 2023 00:06:44 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxqrYTH3Zket+AAA--.13773S8; Wed, 31 May 2023 00:06:44 +0800 (CST) From: Sui Jingfeng To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v6 6/6] drm/etnaviv: allow usperspace create cached coherent bo Date: Wed, 31 May 2023 00:06:43 +0800 Message-Id: <20230530160643.2344551-7-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230530160643.2344551-1-suijingfeng@loongson.cn> References: <20230530160643.2344551-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxqrYTH3Zket+AAA--.13773S8 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxXF4fGryfAF4UZFyUZFykAFb_yoWrKFWUpF Z3AFyYkrW0v3yDK34xAFn8Za43Gw12gFZ2k3sxtwn09w45tF42qr95KFZ8Crn8Jr1fGry3 tw1Dtry5K3WjyrJanT9S1TB71UUUUj7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b68YFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr0_Cr1U M2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zV CFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVW3AVW8Xw1lYx0E x4A2jsIE14v26F4j6r4UJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7 CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l 4IxYO2xFxVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxV WUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAF wI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2 IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26F4j6r4UJwCI42IY6I8E87Iv6xkF7I0E14v2 6r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7IU01E_tUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1767336129288318650?= X-GMAIL-MSGID: =?utf-8?q?1767336129288318650?= cached system RAM is coherent on loongson CPUs, and the GPU and DC allways snoop the CPU's cache. write-combine caching property is not suitiable for us. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 22 +++++++++++++++++++-- drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 9 ++++++++- include/uapi/drm/etnaviv_drm.h | 11 ++++++----- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 052f745cecc0..2816c654c023 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -274,7 +274,7 @@ static int etnaviv_ioctl_gem_new(struct drm_device *dev, void *data, struct drm_etnaviv_gem_new *args = data; if (args->flags & ~(ETNA_BO_CACHED | ETNA_BO_WC | ETNA_BO_UNCACHED | - ETNA_BO_FORCE_MMU)) + ETNA_BO_CACHED_COHERENT | ETNA_BO_FORCE_MMU)) return -EINVAL; return etnaviv_gem_new_handle(dev, file, args->size, diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c index b5f73502e3dd..d8b559bd33d3 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,20 @@ 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_COHERENT: + 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) @@ -545,6 +558,7 @@ static const struct drm_gem_object_funcs etnaviv_gem_object_funcs = { static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, const struct etnaviv_gem_ops *ops, struct drm_gem_object **obj) { + struct etnaviv_drm_private *priv = dev->dev_private; struct etnaviv_gem_object *etnaviv_obj; unsigned sz = sizeof(*etnaviv_obj); bool valid = true; @@ -555,6 +569,10 @@ static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, case ETNA_BO_CACHED: case ETNA_BO_WC: break; + case ETNA_BO_CACHED_COHERENT: + if (priv->has_cached_coherent) + break; + fallthrough; default: valid = false; } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c index 3524b5811682..671d91d8f1c6 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c @@ -112,11 +112,18 @@ 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; int ret, npages; - ret = etnaviv_gem_new_private(dev, size, ETNA_BO_WC, + if (priv->has_cached_coherent) + cache_flags = ETNA_BO_CACHED_COHERENT; + else + cache_flags = ETNA_BO_WC; + + 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/include/uapi/drm/etnaviv_drm.h b/include/uapi/drm/etnaviv_drm.h index af024d90453d..474b0db286de 100644 --- a/include/uapi/drm/etnaviv_drm.h +++ b/include/uapi/drm/etnaviv_drm.h @@ -90,13 +90,14 @@ struct drm_etnaviv_param { * GEM buffers: */ -#define ETNA_BO_CACHE_MASK 0x000f0000 +#define ETNA_BO_CACHE_MASK 0x000f0000 /* cache modes */ -#define ETNA_BO_CACHED 0x00010000 -#define ETNA_BO_WC 0x00020000 -#define ETNA_BO_UNCACHED 0x00040000 +#define ETNA_BO_CACHED 0x00010000 +#define ETNA_BO_WC 0x00020000 +#define ETNA_BO_UNCACHED 0x00040000 +#define ETNA_BO_CACHED_COHERENT 0x00080000 /* map flags */ -#define ETNA_BO_FORCE_MMU 0x00100000 +#define ETNA_BO_FORCE_MMU 0x00100000 struct drm_etnaviv_gem_new { __u64 size; /* in */