From patchwork Sat Jun 3 10:48:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 102818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1583961vqr; Sat, 3 Jun 2023 03:50:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ZOdq7GzxQ8V0MUrmPAPZrvN1r7nYONiVtV2622paaelrdee6S5TvpslYocXn8bl5XX5gU X-Received: by 2002:a81:8311:0:b0:565:c750:c5c6 with SMTP id t17-20020a818311000000b00565c750c5c6mr4021441ywf.6.1685789445774; Sat, 03 Jun 2023 03:50:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685789445; cv=none; d=google.com; s=arc-20160816; b=ypbEVk6xGxhcrlx9I8mZ446bJx+pPOxpZOn8AYKM3babIcSQzU87zsGTLYc+7g5vLV sX/dCatQw1FRPbl5jGTd49OtGatgZTmAio+DQt9uOPjQkrg/tO+22w3zUrRo0Jt3JNOd p0Y661Ke/eEK3jwCQd+YUOfjplfKFFv2xkGVN/aMJgtQSfCzO6f9m+Kw4P/pUdU9P4al 09mDE3w6YPgwjSWfoF1reDm79eV/ibFn30BPH4PFSLh0q9YHVMBrRNxTiy+G3o8ybQmY HpF4JP/pB8lTupaJ2DnzPJGc6EE6rND8+txftNPVIepzEBlKjQZDo3+bHG9K+BeHLVRv NXBQ== 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=7IBmtMqxEZwTCDlHz1coltEiy94XtJ3WZTC8w3cTahg=; b=SYF2jmdM9VvdZydBqFX9BzVlckd3EcWixQp/JvRB0XQuSwIpKWlK/RiFfa9eFvAVrS MkWWfkYsespKKCVEV64OvU0Qgz4sXM3NeTCmncFaZgvtZQiaWfNVa9E1AhxwEjRjyHgz iLMnuhp0Z/QLKKOIzusUK01y7Gh6cSRNJCRKq42YEybB02k4bJ+DHZdeV2YiTpboGCJb Msa3Ffu5DNzzL9/bxGX4MeSDDzIFQNJucvqpSOmIYSJIZ0oqRpoes4KpimQASe3HLwhe hS6Pwzl5JEUsA3uIKRyGo7I+Co5KaAdOo1LKsdrWUulDJ7Gy7KLBiTYGB64IMYLqVj2f jxPA== 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 s16-20020aa78bd0000000b00655079704afsi707149pfd.119.2023.06.03.03.50.31; Sat, 03 Jun 2023 03:50:45 -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 S236828AbjFCKs4 (ORCPT + 99 others); Sat, 3 Jun 2023 06:48:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236904AbjFCKsx (ORCPT ); Sat, 3 Jun 2023 06:48:53 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0EFA4F5 for ; Sat, 3 Jun 2023 03:48:51 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8AxiPGTGntk2+oDAA--.8556S3; Sat, 03 Jun 2023 18:48:51 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx87SSGntkOjOHAA--.20866S3; Sat, 03 Jun 2023 18:48:50 +0800 (CST) From: Sui Jingfeng 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 Subject: [PATCH v7 1/7] drm/etnaviv: add a dedicated function to register an irq handler Date: Sat, 3 Jun 2023 18:48:44 +0800 Message-Id: <20230603104850.3042011-2-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603104850.3042011-1-suijingfeng@loongson.cn> References: <20230603104850.3042011-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx87SSGntkOjOHAA--.20866S3 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7AFWDWF4UGFykJr1DKF17ZFb_yoW8Zr48pF 47Ja4Ykr18Ca42g34fZF98ZF1akw1IqayIkwnrt3sak398Jrs8JryFkF1UXa4fAryrGay3 tF1YgFWUuF45urJanT9S1TB71UUUU0DqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bvxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4U JwAaw2AFwI0_GFv_Wryle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4 CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_ZF0_GryDMcIj 6I8E87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrw ACjcxG6xCI17CEII8vrVW3JVW8Jr1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vI r41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_GFv_Wrylx2IqxVAqx4xG67 AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIY rxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4U JVWxJr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07 bgXdbUUUUU= 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?1767678353809057661?= X-GMAIL-MSGID: =?utf-8?q?1767678353809057661?= 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. 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 Sat Jun 3 10:48:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 102822 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1586686vqr; Sat, 3 Jun 2023 03:58:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Nc6h94uSxQUqEmjhrcz7CwfEEee7eKs3CUStfoecGipudGR31moy40vBkIHtQhmzQA0bu X-Received: by 2002:a25:2fce:0:b0:ba2:ca56:7206 with SMTP id v197-20020a252fce000000b00ba2ca567206mr4865625ybv.17.1685789902761; Sat, 03 Jun 2023 03:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685789902; cv=none; d=google.com; s=arc-20160816; b=0F2f/Y47oQ21qLro8uol5KJGmTfTnSWiRs/3GoIcDvr1oUmWeTV4mmcinM2dyn9qI0 LrVSxjldbIMMHdVuoj/DaQSrdZubhl7BHtXHYal9luKYWZx5i64aWlbis22nh7G93bqf QyCLJBq7om3k5T7dMKD+7hrT0iVmHEjmjowEDAz6SfVD0tq83xzJfdDuZR8DE+2RMuI1 AneQ/uLlUyNiOc4J+/jn5KFV0N40oKhiVvHCN61GQtjIcQfxr89E/pR6orXmIOYVuPBV 9Mlk/Lk0PCkqtlENWvIoOlhDJC6HLr3hcKb3OHKXdL7TVVTmj5N5qk1aCmoXjGFK25cu 6hmA== 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=+hbTDDKi82/Q2MQmS1gmKRuAMdTHk0qKAa5aNLOZW3A=; b=0N7YNn+d1qvUTGJkWVQRWDO16k1x7Xh5f3Fb1ZbzXL3am8qkTQeqCscn1k9oatpoHO OH9unDjBVJWBefRkUSk0zvX1PasY6lFTzbbNBvsjFMOaHeQ1hhuIuJN7D7ZpTbH1nyYo 80z3YJOklxYRLsGGmQicLS21xg6BroEiHO2Pj72pbrFEhwTc2cjDNy0jy+pjnbL/B/oE Cdl15PFxjkoqz+OQDkS0gXH05r/fHpYra62PyvZg0o5XN7yCnEN4sJK+qevwIW6Qt52P bCPJOYXdEHtdB2cITWrDUfKb4jFJ9MEYA67HraH492YUqVNA0iDNyqznXYv/I54UKjXt Dy0Q== 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 s196-20020a632ccd000000b005360d7da569si2467869pgs.634.2023.06.03.03.58.09; Sat, 03 Jun 2023 03:58: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 S235673AbjFCKtL (ORCPT + 99 others); Sat, 3 Jun 2023 06:49:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236976AbjFCKsy (ORCPT ); Sat, 3 Jun 2023 06:48:54 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 64EBD1B7 for ; Sat, 3 Jun 2023 03:48:52 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8CxPeuTGntk5eoDAA--.4008S3; Sat, 03 Jun 2023 18:48:51 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx87SSGntkOjOHAA--.20866S4; Sat, 03 Jun 2023 18:48:51 +0800 (CST) From: Sui Jingfeng 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 Subject: [PATCH v7 2/7] drm/etnaviv: add a dedicated function to get various clocks Date: Sat, 3 Jun 2023 18:48:45 +0800 Message-Id: <20230603104850.3042011-3-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603104850.3042011-1-suijingfeng@loongson.cn> References: <20230603104850.3042011-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx87SSGntkOjOHAA--.20866S4 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxWrWfZryxArW3GFyDtF4fZrb_yoW5Ar48pa 1fJ3W5Kr1UCry7K3yxAF15tr1akr1xAayxuwnYvrn3Zw45GF4Utw4YkryYqF45uryrXFWS kw15GF4UCFyF9rUanT9S1TB71UUUU0DqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bvxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4U JwAaw2AFwI0_GFv_Wryle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4 CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_ZF0_GryDMcIj 6I8E87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrw ACjcxG6xCI17CEII8vrVW3JVW8Jr1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vI r41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_GFv_Wrylx2IqxVAqx4xG67 AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIY rxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4U JVWxJr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07 bgXdbUUUUU= 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?1767678833070237557?= X-GMAIL-MSGID: =?utf-8?q?1767678833070237557?= 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. For the GPU in LS7A1000 and LS2K1000, 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 | 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 636d3f39ddcb..6c7aa9322468 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; @@ -1865,27 +1894,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 Sat Jun 3 10:48:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 102820 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1586413vqr; Sat, 3 Jun 2023 03:57:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ErVa6NyCPnOQZc09o/4rpfLihNfMizAT7PrGSZaCqo3Z1kLtFoW2lHGxd1dRQ9GTORVbs X-Received: by 2002:a05:6a00:17a0:b0:64d:60f8:cb35 with SMTP id s32-20020a056a0017a000b0064d60f8cb35mr9313242pfg.7.1685789847874; Sat, 03 Jun 2023 03:57:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685789847; cv=none; d=google.com; s=arc-20160816; b=Q9TARKNyzLsrpxkVcP8Y3PoNQzmv824HO30lSCK+Y+debFeb03i+cBa2c4NcrhPn9q k01k7otAC3reWYRjkHqc6VZSzKL/dAQPO5WHy+H8Vf189otk09nWuHPttlVDnFnol+jB FvQ5D/gBccdvT5v1fRD2Iu5tWbkty9Pv2ma1/OCDqWbHR46ppZMcVZYrB4oK9OJ6iunU DbRT1cVH9RL4mRb2tY3Bjw08Lw7qM+f1izNqTB8qx6G6hxdwglps6WDGH8VJSuzauH/k 2YSftJJlbF/FxheWn/EH1m7kftf/4iWhO3Qa71Z/6/eaRh4sQiou2SlCT98rRS0ySs/X OxqQ== 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=4j/71Z9OtbYjhzqbU7IeJdafy215Lb7b3MEEkA3Bruk=; b=DPCyv3QqUlPmbA5ExhYT532R0bCNtXoriuVCVJ80pwomZXHc+Nn9PswfI5W/mX4JWY KPwCWtVqeOEHeLIbi2OKlGKePYWveXoJmpkboSZqkgFxanRRtIX943tFm7b7of6wLLWa mQw4bYq05NYbEoula0UCyclRmg855FBLjqY7kowHyieinLuIa00VIRJTNlvvt7twJKrl 4fk+pDPXHyebAoqOq0Juh5ADj6O0neNBG7ALhU2bS3WCpq0Lp8ovLCM8f/hajJXOHNsZ vgfiikXueK3S8/480rYap/99snfNV9d5Uy/vceNSALO01gD0tD2psYMxP2m+txVyX1tm weKg== 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 63-20020a630242000000b0052c3f0ae398si2547166pgc.158.2023.06.03.03.57.14; Sat, 03 Jun 2023 03:57:27 -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 S232870AbjFCKtH (ORCPT + 99 others); Sat, 3 Jun 2023 06:49:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237010AbjFCKsy (ORCPT ); Sat, 3 Jun 2023 06:48:54 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 649291B3 for ; Sat, 3 Jun 2023 03:48:52 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8BxmPGTGntk6eoDAA--.8420S3; Sat, 03 Jun 2023 18:48:51 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx87SSGntkOjOHAA--.20866S5; Sat, 03 Jun 2023 18:48:51 +0800 (CST) From: Sui Jingfeng 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 Subject: [PATCH v7 3/7] drm/etnaviv: add dedicated functions to create and destroy platform devices Date: Sat, 3 Jun 2023 18:48:46 +0800 Message-Id: <20230603104850.3042011-4-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603104850.3042011-1-suijingfeng@loongson.cn> References: <20230603104850.3042011-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx87SSGntkOjOHAA--.20866S5 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxAr4ftrWxCr4xuFWkKFyxAFb_yoW5Gw4DpF 17GFWSyrW8uFW7Kw1xXwn8ZFW5C3WIg34F9rnFywnI9398Ar98XF95GFyUAFnxJrWrGa45 t39xtF48uF45ZrJanT9S1TB71UUUU07qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bvxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4U JwAaw2AFwI0_GFv_Wryle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4 CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Gryq6s0DMcIj 6I8E87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrw ACjcxG6xCI17CEII8vrVW3JVW8Jr1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vI r41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_GFv_Wrylx2IqxVAqx4xG67 AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIY rxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4U JVWxJr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07 bGxRDUUUUU= 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?1767678775716240541?= X-GMAIL-MSGID: =?utf-8?q?1767678775716240541?= 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..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 Sat Jun 3 10:48:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 102819 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1584117vqr; Sat, 3 Jun 2023 03:51:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ktzNhgTQfPV/c+q+LiK6oHz7JGsM+UZqXe2YEim8/DVxNkqlaW5uvKlraGauBjlzJS+RE X-Received: by 2002:a9d:4f12:0:b0:6af:813c:990b with SMTP id d18-20020a9d4f12000000b006af813c990bmr5243303otl.14.1685789471658; Sat, 03 Jun 2023 03:51:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685789471; cv=none; d=google.com; s=arc-20160816; b=xfYUNJvkC1+E1moK5Lkt2pk+ON0oHEUMaYXEchwD+S8W+4bzNYpj/N9nfWeDsGGoSR eitIvv3mF98RfRHNwFzRZkO+nVprPalQ6sBTN/ir6rLYXcqS92EuWAJHMBa/ES/JKaKa +OkbK9PJy+fL/qDRoVEZ8GH2ZraV+nS5PVZz05nVoS4O4rOUmNKYoUQwyBOfDgNrKhxD P6ty9XWWlimAVh+dPQTt5THtJmFUyhA+HqakcLlM+m92ebDI/2yz3WuYQ69DXcKOX+BL CHHQ8w1L0yZDbKKeqkbpK9JSSJBjWDFRHSzqizxSCF1GhweipLvey6ty7OARXYjZ/4+P o5+g== 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=I0ONVoiECuLFHbCEtEuFGXKlEN+GeLJnYOD+WhCZx3Q=; b=gpMHpkvyx3Ov1yWhaokHdh1QQ5DueZwAMPtDCM0OXlllZVCBHM30D5H4yj1D8BhVG6 PU5i87zw60N/QthpYtyoJNbER5JazJ6IpY8TPOuZyd9r5h/ciC+SS7nfvnJ/TTR+FnE4 gA5ollVEtBmgLoVNWFyz73Kf4/25eXd5Q4HxZLmIRGcUeM5SEic4MuVH4Q6Gc1RXgX6i xTZkJIi6tiJqUVK/mKpxesEaHGXDgNXBIcJu80Xhadbfhpp//cajTgqOxeaxaZgeCDR/ Ue+qBNjacag0R8xRaN0RgN8H8+Lioob39dvGU4y66AUcrhxwNm1yUPMaXpMrgoQPkyrd 1Gtw== 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 q83-20020a632a56000000b0053051c56825si2468810pgq.777.2023.06.03.03.50.57; Sat, 03 Jun 2023 03:51:11 -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 S234505AbjFCKtP (ORCPT + 99 others); Sat, 3 Jun 2023 06:49:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236978AbjFCKsy (ORCPT ); Sat, 3 Jun 2023 06:48:54 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C6F9C1BB for ; Sat, 3 Jun 2023 03:48:52 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8AxQ_CTGntk8OoDAA--.8474S3; Sat, 03 Jun 2023 18:48:51 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx87SSGntkOjOHAA--.20866S6; Sat, 03 Jun 2023 18:48:51 +0800 (CST) From: Sui Jingfeng 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 Subject: [PATCH v7 4/7] drm/etnaviv: add helpers for private data construction and destruction Date: Sat, 3 Jun 2023 18:48:47 +0800 Message-Id: <20230603104850.3042011-5-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603104850.3042011-1-suijingfeng@loongson.cn> References: <20230603104850.3042011-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx87SSGntkOjOHAA--.20866S6 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxCw4rWr1fXr4fXr48AFWkJFb_yoWrAr4Dpa n7AFy0yrWkZF18Ka9xJrn5Za43C3WxWay09asFgwn0qw4ayr1vgFn5tFyUAF9xJFyrCr13 tw1Utr1UXF40krJanT9S1TB71UUUU0DqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bvxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4U JwAaw2AFwI0_GFv_Wryle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4 CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Gryq6s0DMcIj 6I8E87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrw ACjcxG6xCI17CEII8vrVW3JVW8Jr1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vI r41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_GFv_Wrylx2IqxVAqx4xG67 AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIY rxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4U JVWxJr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07 bXmhwUUUUU= 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?1767678380938758323?= X-GMAIL-MSGID: =?utf-8?q?1767678380938758323?= 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 | 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 Sat Jun 3 10:48:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 102823 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1586844vqr; Sat, 3 Jun 2023 03:58:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7SiaEhYTuGwmRUvf1XZ4QL/CNvDnwYQ3sGCc2gDdMuO5OVIwIy8Lx3FBMGFTcuP6RtW2re X-Received: by 2002:a17:902:7284:b0:1a6:6fe3:df8d with SMTP id d4-20020a170902728400b001a66fe3df8dmr2755938pll.8.1685789928636; Sat, 03 Jun 2023 03:58:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685789928; cv=none; d=google.com; s=arc-20160816; b=Yfijmot3GFVOSEfIaMcZHG0R9BfdmH9HF2stzqdKs/SViBBhTcpFSIv8r3Bwu6bCWc en7WXOFndwwHWtmXTG5ZrXxoeZeKBZjtgKpllda5etxxnYN9Kz80uNB+alT07PScchC4 oufPotje5Wo7rNaR0jRSVNLl/jOPO0txWEUj6+k/rS6Q7z4H+GsGNf9cOpr2LXJy1YRK iGQBRQffr7tpH4lPYoIW7fB866DtMIen/eQq0vm29a4KvFoRkJ54/HIGUOSIAkv4jr2h bA8xEnx+QTxJbHUliz1jUs4IpIT06oTMf7QsvIctv+MSKMgi4u52pGEkHZ+4dBYKbTE8 HOJQ== 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=+QhSsDT3d8/OwPx5tRs+TbLUHY5DUnYjay8xOFP4FsE=; b=yuTuqfTi0AYsRgKq3DIB3EEIfLgSP7aOAJNmNpzfwBMCNMuDuv+C+o3f+j3P/zCqAm 2A9p7m++YEmfO+tOWUK8FeILJSOyxPs+eOGtCgTmgkPuJGWYxDOXPRNKBERoAhMvxbTc rH9H3GfIIEi1dkQBc/rnoVMStAYYrKt8qEjUQtNFwRcLizhFNdmjz8UkLWYKVh+V+0I/ OZTI8aG878pw35zXZdQwqzNtnhVFlPep3YgVpZZ6kwP/XFmGA8nd7ymU/sL/sIhPJTLD L2h+n0Y30SPdWPcIfZrd3gsZ8DZFHtgB/P3wkgKWKag1x2Az1GRNz0C6yUwkZUP/z70F 5W5g== 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 i2-20020a17090332c200b001a643dfb884si2448996plr.451.2023.06.03.03.58.34; Sat, 03 Jun 2023 03:58: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 S235570AbjFCKtT (ORCPT + 99 others); Sat, 3 Jun 2023 06:49:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237019AbjFCKsy (ORCPT ); Sat, 3 Jun 2023 06:48:54 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1905219A for ; Sat, 3 Jun 2023 03:48:52 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8DxiuqUGntk9+oDAA--.4055S3; Sat, 03 Jun 2023 18:48:52 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx87SSGntkOjOHAA--.20866S7; Sat, 03 Jun 2023 18:48:51 +0800 (CST) From: Sui Jingfeng 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 Subject: [PATCH v7 5/7] drm/etnaviv: allow bypass component framework Date: Sat, 3 Jun 2023 18:48:48 +0800 Message-Id: <20230603104850.3042011-6-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603104850.3042011-1-suijingfeng@loongson.cn> References: <20230603104850.3042011-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx87SSGntkOjOHAA--.20866S7 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW3Gr4UCr4UWryUKw1kCF1fCrg_yoW3tr13pF 4xJayYkrW8uayqg34UArn5ZF13Cw1Sq34Iy34kK3sakw45JryktF1YyFyjyFnxJrZ5WFW3 tr1DtrWUAF40y3DanT9S1TB71UUUU0DqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bvxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4U JwAaw2AFwI0_GFv_Wryle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4 CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Gryq6s0DMcIj 6I8E87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrw ACjcxG6xCI17CEII8vrVW3JVW8Jr1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vI r41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_GFv_Wrylx2IqxVAqx4xG67 AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIY rxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4U JVWxJr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07 bXmhwUUUUU= 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?1767678860444227135?= X-GMAIL-MSGID: =?utf-8?q?1767678860444227135?= Adds another code path to allow bypass component frameworks, A platform with a single GPU core could probably try the non-component code path. This patch is for code sharing, no functional change. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 47 ++++++++++----- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 84 +++++++++++++++++---------- drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 3 + 3 files changed, 91 insertions(+), 43 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/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 6c7aa9322468..126f0409aaed 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1737,8 +1737,7 @@ static const struct thermal_cooling_device_ops 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); @@ -1869,9 +1866,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; @@ -1879,24 +1878,21 @@ 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); @@ -1906,24 +1902,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) @@ -1973,6 +1972,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 Sat Jun 3 10:48:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 102821 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1586643vqr; Sat, 3 Jun 2023 03:58:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ZqqGqnU7ipT22L7s+mJESw1QMmpLvMvOEGGFp2H0vrINWC6XNx/bSMco+M3Mdsnw0ZoNB X-Received: by 2002:a25:5095:0:b0:b9e:85a1:9a34 with SMTP id e143-20020a255095000000b00b9e85a19a34mr6924717ybb.35.1685789895528; Sat, 03 Jun 2023 03:58:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685789895; cv=none; d=google.com; s=arc-20160816; b=jYs0OBarUgj3dBWEwh7KGGSpPnjchqI60IE5fnas7at2MRDo4p6npV58GMylCHAoX7 T/UYHu9FFmWySwkdSGj73t3KwRQlkEsFCMvWGxE/gGbE8T54WNqaIYst0aLW3EFVP5W2 6tcz4Z4U7T9F4d7l+5JkWy9FlabvYei9IzffRJeO0jHIi9clfqHv4NoGxjyhL+b65Twp evFJsUVEOS5N1QDJ/hOQoLPceDy23SYE6SpCBmxItkyjQtBYZAu7W3SEtuAnc/t3FEMU AfM61jcbftQ7X4vgow8lgQlCqWU7yoIX9NywSyOFr8cY7EAEoFFMf18KTFHblhogWux0 8bKw== 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=A6DGLi8pqLlfA3UgqpgaEIU7Zw8XpJP8Z5PNgvz55eE=; b=gx0OUBiskMRtFZRa/DeDEkWebhyEuBkO04SVnk9/62tl3D53ABy03NUxpXehNQQs6w /k1iX2PnXmSXWkD1hyXy+LchlNSVOmRKwBpHKANHBt+95Xv+F2RHJC3dLGQwDi30OGwD QjCwJJqPCpuPhgpTVxcJACg06d4hOR2E1mBpneflhqO2xMDTr+JKWvFTZBUKMWYRS203 ORYwvqgojPYZ6SHDdsJnxYcCLk6X6DLNpsrsRsV4BmjcCmVOY9nrJEI1xyVEbR9HhHma To25SDdFVHKFfabkdVyZNQgxU+VJiQnSkgYrEBLcPIpy4QEQEtuyIGzkf+FgJaiQtGFh C+jw== 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 lr2-20020a17090b4b8200b0024ef1d1151bsi2727670pjb.17.2023.06.03.03.58.01; Sat, 03 Jun 2023 03:58: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 S237148AbjFCKtX (ORCPT + 99 others); Sat, 3 Jun 2023 06:49:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236526AbjFCKsz (ORCPT ); Sat, 3 Jun 2023 06:48:55 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6D569E40 for ; Sat, 3 Jun 2023 03:48:53 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8Dx_+uUGntk_uoDAA--.8341S3; Sat, 03 Jun 2023 18:48:52 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx87SSGntkOjOHAA--.20866S8; Sat, 03 Jun 2023 18:48:51 +0800 (CST) From: Sui Jingfeng 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 Subject: [PATCH v7 6/7] drm/etnaviv: add driver support for the PCI devices Date: Sat, 3 Jun 2023 18:48:49 +0800 Message-Id: <20230603104850.3042011-7-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603104850.3042011-1-suijingfeng@loongson.cn> References: <20230603104850.3042011-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx87SSGntkOjOHAA--.20866S8 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxtw1furyxZry7GF4xAw1kXwb_yoWfuw1DpF 43JFyjkrW8Za1jg347JFs5ZFy3K3WIgFyS934DK3sIvw45AFyUJryqkFyDAr9xJrZxGr9x trn8Kry7ZF4UA3DanT9S1TB71UUUUjDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bvxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4U JwAaw2AFwI0_JF0_Jw1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4 CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Gryq6s0DMcIj 6I8E87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrw ACjcxG6xCI17CEII8vrVW3JVW8Jr1lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vI r41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_JF0_Jw1lx2IqxVAqx4xG67 AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIY rxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4U JVWxJr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07 b3iihUUUUU= 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?1767678825317776947?= X-GMAIL-MSGID: =?utf-8?q?1767678825317776947?= 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. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/Kconfig | 9 +++ drivers/gpu/drm/etnaviv/Makefile | 2 + drivers/gpu/drm/etnaviv/etnaviv_drv.c | 20 +++++- 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 | 9 +++ 8 files changed, 125 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..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 93ca240cd4c0..033afe542a3a 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -23,6 +23,10 @@ #include "etnaviv_mmu.h" #include "etnaviv_perfmon.h" +#ifdef CONFIG_DRM_ETNAVIV_PCI_DRIVER +#include "etnaviv_pci_drv.h" +#endif + /* * etnaviv private data construction and destructions: */ @@ -538,7 +542,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 +592,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 +750,12 @@ static int __init etnaviv_init(void) if (ret != 0) goto unregister_gpu_driver; +#ifdef CONFIG_DRM_ETNAVIV_PCI_DRIVER + ret = etnaviv_register_pci_driver(); + if (ret != 0) + goto unregister_platform_driver; +#endif + /* * If the DT contains at least one available GPU device, instantiate * the DRM platform device. @@ -763,7 +773,7 @@ static int __init etnaviv_init(void) break; } - return 0; + return ret; unregister_platform_driver: platform_driver_unregister(&etnaviv_platform_driver); @@ -778,6 +788,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 + etnaviv_unregister_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 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 126f0409aaed..f0eb808496e2 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1868,8 +1868,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; @@ -1917,7 +1917,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); @@ -1968,7 +1968,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..5de3e218274a --- /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(&pdev->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_VENDOR_ID_LOONGSON, 0x7a15, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + {PCI_VENDOR_ID_LOONGSON, 0x7a05, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, + { } +}; + +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..25d07bdd2ea0 --- /dev/null +++ b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ETNAVIV_PCI_DRV_H__ +#define __ETNAVIV_PCI_DRV_H__ + +int etnaviv_register_pci_driver(void); +void etnaviv_unregister_pci_driver(void); + +#endif