From patchwork Sat Jun 3 10:56:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 102833 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1597804vqr; Sat, 3 Jun 2023 04:21:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ614j/CozlCtEHn8G9iz1ZUy+eDcded+56BhO4SkQ9p3sE6UXTLtYM7ntxRLE863JFPF/l5 X-Received: by 2002:a17:90a:dc02:b0:253:8a50:1bcb with SMTP id i2-20020a17090adc0200b002538a501bcbmr1080343pjv.25.1685791265003; Sat, 03 Jun 2023 04:21:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685791264; cv=none; d=google.com; s=arc-20160816; b=kK10ZSGXYBRqGAP4C/XqG+uBaG0P7KqiznkweoG7e1B4fReA/rqUlXb4bhXWVKH/9I NgHaJ97XBuCnOuoSRvisr2YWHhcl/VIfLU+rlpi/kSSM5bSazxuHWA5XjI9bL7E7kr96 qyv2D7JVKKiGAJd/T+EmuES6F06WefM4j6++2Zlfem5fflyWxC3t27hE536zmvHvRDHs gEPunOIfBm44o65mZqb+3KFeHDLmPZano1EH7r2aabCO+whWHHui/EBnHFpZrkGazAQK wyY1m6Ho46czhSz1ouW0q05PUblRl4Cf58cNpXo735t+mZxuIFVS/02pBsK6kzKYkQFX /HjA== 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=CFw37BRvxzwXvJfBLPklKC4fTViv/PphYdlB6vApJReOOZT2mafdpoZocg9jVP7RaQ 4i6cRtUNwdmKYxErR7SG25Jm7YhjWckOt+5wo4Yq/p/RfVTHefQhlz2MskoK/CoY+iei f5aXViDatd+PVPYtO5ahcJp9ghaSenEwMxul9XJdl3A0zyjdpUHXyUtgvTehi5F9Jzyx HuEpiqv8XS5wAXr50ZDnlzeFh4njtD3Mq9L2aqx0HHYRj9A7YQgwqy6tJnfXEUJ22Aeq M8tLK8LSwuDT6GUZwXmFEgAjlaFNDp5iYZFEKjCRbdUWUIlEtOS1LDVUrYPjdpUq9S8H CUAg== 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 i1-20020a17090a64c100b002569554346esi2596717pjm.168.2023.06.03.04.20.51; Sat, 03 Jun 2023 04:21:04 -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 S234672AbjFCK4y (ORCPT + 99 others); Sat, 3 Jun 2023 06:56:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229620AbjFCK4w (ORCPT ); Sat, 3 Jun 2023 06:56:52 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 263BD9E for ; Sat, 3 Jun 2023 03:56:49 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8DxNvFxHHtkZesDAA--.8376S3; Sat, 03 Jun 2023 18:56:49 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx_7NwHHtkdTWHAA--.22115S3; Sat, 03 Jun 2023 18:56:48 +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:56:42 +0800 Message-Id: <20230603105648.3042645-2-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603105648.3042645-1-suijingfeng@loongson.cn> References: <20230603105648.3042645-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx_7NwHHtkdTWHAA--.22115S3 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7AFWDWF4UGFykJr1DKF17ZFb_yoW8Zr48pF 47Ja4Ykr18Ca42g34fZF98ZF1akw1IqayIkwnrt3sak398Jrs8JryFkF1UXa4fAryrGay3 tF1YgFWUuF45urJanT9S1TB71UUUUe7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bkAYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84 ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr0_Cr1U M2kKe7AKxVW8ZVWrXwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zV CFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVW3AVW8Xw1lYx0E x4A2jsIE14v26r4UJVWxJr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4 x0Y40E4IxF1VCIxcxG6Fyj6r4UJwCY1x0262kKe7AKxVWrXVW3AwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVW8ZVWrXwC20s026c02F40E14 v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkG c2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW7JVWDJwCI42IY6xIIjxv20xvEc7CjxVAFwI 0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_ Cr1UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUQs 2-UUUUU 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?1767680261453308461?= X-GMAIL-MSGID: =?utf-8?q?1767680261453308461?= 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:56: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: 102836 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1599108vqr; Sat, 3 Jun 2023 04:24:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5rEM7yaeHKoqm41UnBF2qsMYp8cb9vqdTi0pPFaNilRI7UdAkFSy8jQwKmn8sIdzRB2Gfh X-Received: by 2002:a05:6830:20d7:b0:6b1:5899:42b2 with SMTP id z23-20020a05683020d700b006b1589942b2mr670216otq.19.1685791458661; Sat, 03 Jun 2023 04:24:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685791458; cv=none; d=google.com; s=arc-20160816; b=watJIYwdfZYalrhGT8BttcggHNT7Zc5nRGXBZRfVx0jj7/j9voJ+bCnkbf4+fxbt4C 6PAVazT6sV5n83is09dHKqjUxOGT14PfZgj5sHigDS3TV+OyOLZSeSBuzdNQKJMZBS+M sWod60UA53F5mxN+EQ3EhWB5UotkRJHmD/4V6Wj6ox53Tj4vdAPtCxQ1g/AqQuvXJfJz EqH1I26L+HvJ6HcVfnjJOAbdm6cP6lmfbRabP3wtEHdYuPl0bPsZbfmcZclMt1CC9que D/cYLrPhgGyfdlyWs0yWfdWvrwwtsyvwuaAyCw+oGmXcoP1t1xJcOXDd4w6eD+A/JAef RBAA== 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=xdQxmppl8O8Y5KzcYJpVF06GaJvL/xXzaZRFbd0Z8nvC/cE8Uo09hX/l6HkOt5keA1 xgTdmd7hoyfuT8NJsG61x848xNQWuqasrr/ZR4pmO40uUHjvTl5VmD+8tF7/VWDuzrCX q/U0thDtEvJXSX+rlRE3O/PVqJQaPKrOtQO74FCl9D26z/LsPKAQDbWx0Hbq2/PwLlCI n6/2hkf6kUgL8SzKCv4B15HwhZhvghHsgXBnFbfi2tj5RjR9N6PsHMyk01IAt/YF9qg4 6Jc5iiDuHDdVi8x4cH4ej32UJEDBzwl6WlYJWURqNhLH75mtO/SwDHteWOHMLVHcXA9R DiSA== 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 a5-20020a637045000000b0053fb1d02b00si2612780pgn.383.2023.06.03.04.24.04; Sat, 03 Jun 2023 04:24:18 -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 S236828AbjFCK5B (ORCPT + 99 others); Sat, 3 Jun 2023 06:57:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbjFCK4w (ORCPT ); Sat, 3 Jun 2023 06:56:52 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 34096A6 for ; Sat, 3 Jun 2023 03:56:50 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8Cx7+txHHtkbOsDAA--.8108S3; Sat, 03 Jun 2023 18:56:49 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx_7NwHHtkdTWHAA--.22115S4; Sat, 03 Jun 2023 18:56:48 +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:56:43 +0800 Message-Id: <20230603105648.3042645-3-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603105648.3042645-1-suijingfeng@loongson.cn> References: <20230603105648.3042645-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx_7NwHHtkdTWHAA--.22115S4 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxWrWfZryxArW3GFyDtF4fZrb_yoW5Ar48pa 1fJ3W5Kr1UCry7K3yxAF15tr1akr1xAayxuwnYvrn3Zw45GF4Utw4YkryYqF45uryrXFWS kw15GF4UCFyF9rUanT9S1TB71UUUUe7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bkAYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84 ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr0_Cr1U M2kKe7AKxVW8ZVWrXwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zV CFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVW3AVW8Xw1lYx0E x4A2jsIE14v26r4UJVWxJr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4 x0Y40E4IxF1VCIxcxG6Fyj6r4UJwCY1x0262kKe7AKxVWrXVW3AwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVW8ZVWrXwC20s026c02F40E14 v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkG c2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW7JVWDJwCI42IY6xIIjxv20xvEc7CjxVAFwI 0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_ Cr1UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUQs 2-UUUUU 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?1767680464526746865?= X-GMAIL-MSGID: =?utf-8?q?1767680464526746865?= 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:56: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: 102835 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1598231vqr; Sat, 3 Jun 2023 04:22:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5SYJXaJYDzstgyzyBQK+gB+Wb3PKxozFQZ8Zw5BxWw8y4I5nldSjBqtenaS0/84/ChnFKt X-Received: by 2002:a05:6808:298f:b0:398:ad87:2dab with SMTP id ex15-20020a056808298f00b00398ad872dabmr3083761oib.5.1685791326421; Sat, 03 Jun 2023 04:22:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685791326; cv=none; d=google.com; s=arc-20160816; b=dIicLGjqGKPi1V2Eyf1YTas4AiQ5ospPSLre5+EVQYZjDCme3/SgP9WGDKxp6Ef9VQ 7i8KEQZT81I/TkV6gr2cUuGNa9pkZjYLrfTu4Nwp5uvbTCCovnuWy6lKDuykOV2DYlpd 7JFLliiX0f/XuNJDtg2k3aUcI7wXOqLLcCJOn0JRZ73iJI2EowSJ60QN7ojvr/uZ/+21 Ng8J6o6rH3Je1tTenvnZ1Bj7GFu82zqchZZVXlmqj79YZsHneawLq3writVO4KNrQQIP O8SstUsbpj/J0zynQJSbPcNkvkYgYmdUlp/Yjr1vYmL/q6r8O3NUNil6+wFOWfnMLHYh h6lw== 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=1JUKmsfn4zpZt1IPtWVWQu2SyDUlECkjUhg6K4VBbzRNGXWABvggW5bOewOuFdvudi e0dvuVbBIoMz1NrDnwRHE5vp4enrf5xFBBje7+VlR8uxjYw+bj6wC8cLe0u2EfWQ1dc0 xccGr3XCf+e5je1qSnpwFwMO5NX9ORYJYE1KMwySDzENVSFVj3X2LvOsU29U29IOl6Ku 0/eP4Ko30wxnkv+woddNiivx+MKvWl/XgcKTW3UddtjrAVRAj3yIw/X6VNDO9j0P2XN6 o3L0fApWkftPClYW2hn7KAarWjyU6HDL5TeXCRiIuYe/vu83o3UjNTrd3bVYzzppqJn7 IGfw== 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 p2-20020a17090a680200b002535d0a89f8si4167049pjj.186.2023.06.03.04.21.52; Sat, 03 Jun 2023 04:22: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 S237174AbjFCK5J (ORCPT + 99 others); Sat, 3 Jun 2023 06:57:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229807AbjFCK4w (ORCPT ); Sat, 3 Jun 2023 06:56:52 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A337CC3 for ; Sat, 3 Jun 2023 03:56:50 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8Cx_OpxHHtkdusDAA--.3975S3; Sat, 03 Jun 2023 18:56:49 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx_7NwHHtkdTWHAA--.22115S5; Sat, 03 Jun 2023 18:56:49 +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:56:44 +0800 Message-Id: <20230603105648.3042645-4-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603105648.3042645-1-suijingfeng@loongson.cn> References: <20230603105648.3042645-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx_7NwHHtkdTWHAA--.22115S5 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxAr4ftrWxCr4xuFWkKFyxAFb_yoW5Gw4DpF 17GFWSyrW8uFW7Kw1xXwn8ZFW5C3WIg34F9rnFywnI9398Ar98XF95GFyUAFnxJrWrGa45 t39xtF48uF45ZrJanT9S1TB71UUUUeDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bkAYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84 ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr0_Cr1U M2kKe7AKxVW8ZVWrXwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zV CFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVW3AVW8Xw1lYx0E x4A2jsIE14v26r4UJVWxJr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4 x0Y40E4IxF1VCIxcxG6Fyj6r4UJwCY1x0262kKe7AKxVWrXVW3AwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVW8ZVWrXwC20s026c02F40E14 v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkG c2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWDJVCq3wCI42IY6xIIjxv20xvEc7CjxVAFwI 0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_ Cr1UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUQj YLDUUUU 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?1767680325860312183?= X-GMAIL-MSGID: =?utf-8?q?1767680325860312183?= 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:56:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 102828 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1596774vqr; Sat, 3 Jun 2023 04:18:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Ty9lqfiUBpIoFStVp4lDPckWifTWzip0EfR3uT4zIe/IkA65idMofJMev0K3g84tjWmfA X-Received: by 2002:a05:6358:720d:b0:123:30f2:a07f with SMTP id h13-20020a056358720d00b0012330f2a07fmr18504404rwa.26.1685791103022; Sat, 03 Jun 2023 04:18:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685791102; cv=none; d=google.com; s=arc-20160816; b=cFfP9uBoeznqpMdDDuhS8lxaqFCGcAEFQy9vGBGCL/BuQq0rUvLEuYiFiPLGVpOUSG gmQFqREZTv2sskI5BZfLI9neHjKr+AwCApq+YJT93BId7lSIYoX3V2I28nL/f9hsU48Z U2NBD+dA4/SLBpRuF+85MuJUz735xhnaIhB/W1EOYPI9C8xa9ZKp9mk9xbVvRzhUFj9t h+cwt7lHoSJnjNm4/9r+3XfnbZs7iUQYcHsPD7RDwzpOjHQKjr54o8X2kei7N4AasQq0 EMJZY5PGotPSA0BTU3g0a7Ohdqfoi/7J5IL2XPMSVdzIE1sxmMwXg/7/04qaYTAghhba Sd5A== 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=xIB2JilUm0myyVehaanNtK2a9Rl7dCAfBXqhvdwTxxQfIQamgHZgLA+JcBTh2x0NTO YjbdFymJQ+Qb6YwmpwartBfllLLiCEosOUy5SEWm8aPHXtvrN6ybvTTBU41E09dLqXuL X1LKcGlMXZ5MoL0wDiIg2amue0LolTcNgCzJpUxepCzDB859T0YeLkaz9GZFEgNtW2wp g5auXUDQl/U+iRtgmGDGD/fUJxcpr9NJ18SVkJw1uMfcAZz0Byyw+IuEpTRoi2z7/Pem rAyCUs7YulwLjeT1vy682M6y+2tKlzYT+o/AQN+VcqGGNCcCDCSvxaCiWAzbdgrNnSmm QN9w== 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 k137-20020a633d8f000000b0053fee168aabsi2573118pga.742.2023.06.03.04.18.09; Sat, 03 Jun 2023 04:18: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 S235567AbjFCK45 (ORCPT + 99 others); Sat, 3 Jun 2023 06:56:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbjFCK4w (ORCPT ); Sat, 3 Jun 2023 06:56:52 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8A0E7BD for ; Sat, 3 Jun 2023 03:56:50 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8BxFvFxHHtkeusDAA--.8485S3; Sat, 03 Jun 2023 18:56:49 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx_7NwHHtkdTWHAA--.22115S6; Sat, 03 Jun 2023 18:56:49 +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:56:45 +0800 Message-Id: <20230603105648.3042645-5-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603105648.3042645-1-suijingfeng@loongson.cn> References: <20230603105648.3042645-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx_7NwHHtkdTWHAA--.22115S6 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxCw4rWr1fXr4fXr48AFWkJFb_yoWrAr4Dpa n7AFy0yrWkZF18Ka9xJrn5Za43C3WxWay09asFgwn0qw4ayr1vgFn5tFyUAF9xJFyrCr13 tw1Utr1UXF40krJanT9S1TB71UUUUe7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bkAYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84 ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr0_Cr1U M2kKe7AKxVW8ZVWrXwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zV CFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVW3AVW8Xw1lYx0E x4A2jsIE14v26r4UJVWxJr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4 x0Y40E4IxF1VCIxcxG6Fyj6r4UJwCY1x0262kKe7AKxVWrXVW3AwCF04k20xvY0x0EwIxG rwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVW8ZVWrXwC20s026c02F40E14 v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkG c2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWDJVCq3wCI42IY6xIIjxv20xvEc7CjxVAFwI 0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_ Cr1UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUQj YLDUUUU 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?1767680091999830236?= X-GMAIL-MSGID: =?utf-8?q?1767680091999830236?= 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:56: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: 102832 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1597761vqr; Sat, 3 Jun 2023 04:21:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4DVmBQJxRmZmpG0z/inWemzsGRV9o2M/HW+yS5aM7Gr+2BIXSMz9WoHGR3ltjx274cXZPs X-Received: by 2002:a05:6a21:32a2:b0:10b:cf0a:f82a with SMTP id yt34-20020a056a2132a200b0010bcf0af82amr1524849pzb.45.1685791260213; Sat, 03 Jun 2023 04:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685791260; cv=none; d=google.com; s=arc-20160816; b=xvYcU0zY7/pQt7CDaS+LduSnWwoBymkfMLemLKN0rk1ACSagAxhWbt+dEXBmY31QX0 IimKZEasO7PZJU2L2WhBGX/KlYOG1Yg69Ll4iS8o5sI5MGopZH6KrwsHrlOyMgwGOlP1 ZDi3wI02689M+yfQ2Q7gPfIzIW5AzYEbneudg81WPqLBkV5JrD4AqITBTBMPsKoT7wYi 6lC7ydJUpApJxufDfyjVrBXLnS1v4qDX5aKsEDVzfYUXpU5qnIFzxcerOUu20clFo3el GGMoJVep60YGjLUSB/FE4MPZOXZIznjbfZ3Brif3RpC5n1ByUfr4HID2whNTxbMNSyS/ E0pw== 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=VY0WMB0+S5Laxuq0mZVpn9W6Ys9QHQ8knWvcQ5o8au8Y8a5U3QUAeugJpJJZ2uc4WY FAhvdgX90FNjCbGK731Act9ZTgmviYjNuso4FppwuKsbujYJkm5TN4gnmYg2s0YsP825 AZZq/v2j1Ai769FmnfND1Er6ZJPaaTVQTacls3BSftvQDRxP/g3t7PUOgnY9eboqfaud NRZZnUBpoUIWDRtbKLFAUE9bz7strrNyYZyi6dcEANlN+oulCgDYn8WRHHT7bTeYOy/K Cux6zyJ6c1qGODFSI/daFzQnDQnRKBDTSCHryoLEsisWCHSxGcH1KCuOZaTqgRk5VD9V ICjQ== 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 p2-20020a17090a680200b002535d0a89f8si4167049pjj.186.2023.06.03.04.20.45; Sat, 03 Jun 2023 04:21:00 -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 S237191AbjFCK5N (ORCPT + 99 others); Sat, 3 Jun 2023 06:57:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230225AbjFCK4x (ORCPT ); Sat, 3 Jun 2023 06:56:53 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0D0E512E for ; Sat, 3 Jun 2023 03:56:50 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8Bx1fByHHtkgesDAA--.8485S3; Sat, 03 Jun 2023 18:56:50 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx_7NwHHtkdTWHAA--.22115S7; Sat, 03 Jun 2023 18:56:49 +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:56:46 +0800 Message-Id: <20230603105648.3042645-6-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230603105648.3042645-1-suijingfeng@loongson.cn> References: <20230603105648.3042645-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx_7NwHHtkdTWHAA--.22115S7 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW3Gr4UCr4UWryUKw1kCF1fCrg_yoW3tr13pF 4xJayYkrW8uayqg34UArn5ZF13Cw1Sq34Iy34kK3sakw45JryktF1YyFyjyFnxJrZ5WFW3 tr1DtrWUAF40y3DanT9S1TB71UUUUe7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bvxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4U JwAaw2AFwI0_GFv_Wryle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4 CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_ZF0_GryDMcIj 6I8E87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrw ACjcxG6xCI17CEII8vrVW3JVW8Jr1lc7CjxVAaw2AFwI0_Wrv_ZF1l42xK82IYc2Ij64vI r41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_GFv_Wrylx2IqxVAqx4xG67 AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIY rxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14 v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4U JVWxJr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07 bma0PUUUUU= 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?1767680256862845190?= X-GMAIL-MSGID: =?utf-8?q?1767680256862845190?= 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__ */