From patchwork Mon May 29 17:14:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 100373 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1669034vqr; Mon, 29 May 2023 10:29:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4+ycwgld2mmw9gDC/zf0i0hzU3+OxC2+U1uxe0ikDq+RAMOkZa1SqQO0o+1BsdIcH9vFEA X-Received: by 2002:a17:90b:87:b0:256:831b:8f45 with SMTP id bb7-20020a17090b008700b00256831b8f45mr3445618pjb.16.1685381347267; Mon, 29 May 2023 10:29:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685381347; cv=none; d=google.com; s=arc-20160816; b=0LGVK4MW6MvH7trAIuuAU6EgyGdv1xn1XVaf4AF8AmVcTNaKai4wixCyxFuaQpuMf9 wxRuvhmy0sIcc6n2B5nOKjeGty9GlCZY0xfQ8sFi0PuLK1lBpTyuvJxWNx4RMmReUfLr mqUSpywIXZpEyh2IXahN7ev1DMJ/iDT4MM6qeFjTZ0cVDTU63fz27Z2oST4y8rYG6Ul1 vrGODuhms4JPg7CBR3Fx23rCRmGlh3v7uqoYPvHPm4HRtG2iiFJ41nqJBa/8kFbH5HpG Pb81C9yqcCda/++kHSHi4++vVtlaQjILer2/n+HwQKrwYJ3KfPzoFae4vuLBUZlcCnJO fORQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=g5GoVmte3jQk00l9vGqH6+GoCz0MdKE/5Y4kSzc27Ss=; b=1FbBwq+FCDguHrVTiDxdzbyQJhL8OpcaiISIbSwSYsW9Bwe4Fu/UxhCJSxEoI0p1gn 7mUkyzuag/qyjfppbSTmYYqYIuXy1pfU2heQhrE8Gy6072NvlA7AU4boHEdW9uLw9vZl iSLCm+DCoB4lM1XrdHFm4mHuS1YOi4MN1hYODSf+pOUYXj977anjLnwfa8Xb7OkRB18N 93Pk3Irk0q/27NCAnNqp+XG0SQdk3axdDFfmC9GXoOCF3GPhSRHKrai9LSWHvNi/fPo0 vwjzWN03IH1GKGWNbAkQrEA1Sr/8QfD0xcBVRfoJXMyziIWZSNXlLK2UUh/FnrFLGKZ0 zi8g== 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 bk13-20020a056a02028d00b00520e69b7439si4276824pgb.560.2023.05.29.10.28.52; Mon, 29 May 2023 10:29:07 -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 S229620AbjE2RO3 (ORCPT + 99 others); Mon, 29 May 2023 13:14:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229579AbjE2ROW (ORCPT ); Mon, 29 May 2023 13:14:22 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6FECEAB for ; Mon, 29 May 2023 10:14:19 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8AxxfBq3XRkkkkCAA--.915S3; Tue, 30 May 2023 01:14:18 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxD79p3XRkLUJ_AA--.10654S3; Tue, 30 May 2023 01:14:17 +0800 (CST) From: Sui Jingfeng To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Li Yi Subject: [PATCH v4 1/6] drm/etnaviv: add a dedicated function to register an irq handler Date: Tue, 30 May 2023 01:14:12 +0800 Message-Id: <20230529171417.2146323-2-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230529171417.2146323-1-suijingfeng@loongson.cn> References: <20230529171417.2146323-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxD79p3XRkLUJ_AA--.10654S3 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7AFWDWF4UKFyfArW3ZF47Jwb_yoW8Zr15pa 17Ja4Ykr18ua42g34fZF98ZF1akw1IqayIkwnrt3sak398Jrs8JryFkF1UJa4fAryrGay3 tF1jgFWUuF45u3DanT9S1TB71UUUUj7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bf8YFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwA2z4 x0Y4vEx4A2jsIE14v26r1j6r4UM28EF7xvwVC2z280aVCY1x0267AKxVWUJVW8JwAaw2AF wI0_JF0_Jw1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2jsIE 14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262kKe7 AKxVWUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C2 67AKxVWUAVWUtwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI 8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8 JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r 1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsG vfC2KfnxnUUI43ZEXa7IU8Gii3UUUUU== 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?1767250431413891086?= X-GMAIL-MSGID: =?utf-8?q?1767250431413891086?= Because getting IRQ from a device is platform-dependent, PCI devices have different methods for getting an IRQ. This patch is a preparation patch to extend support for the PCI device. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 34 ++++++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index de8c9894967c..636d3f39ddcb 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1817,6 +1817,29 @@ static const struct of_device_id etnaviv_gpu_match[] = { }; MODULE_DEVICE_TABLE(of, etnaviv_gpu_match); +static int etnaviv_gpu_register_irq(struct etnaviv_gpu *gpu, int irq) +{ + struct device *dev = gpu->dev; + int err; + + if (irq < 0) { + dev_err(dev, "failed to get irq: %d\n", irq); + return irq; + } + + err = devm_request_irq(dev, irq, irq_handler, 0, dev_name(dev), gpu); + if (err) { + dev_err(dev, "failed to request IRQ %u: %d\n", irq, err); + return err; + } + + gpu->irq = irq; + + dev_info(dev, "IRQ handler registered, irq = %d\n", irq); + + return 0; +} + static int etnaviv_gpu_platform_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1837,16 +1860,9 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) return PTR_ERR(gpu->mmio); /* Get Interrupt: */ - gpu->irq = platform_get_irq(pdev, 0); - if (gpu->irq < 0) - return gpu->irq; - - err = devm_request_irq(&pdev->dev, gpu->irq, irq_handler, 0, - dev_name(gpu->dev), gpu); - if (err) { - dev_err(dev, "failed to request IRQ%u: %d\n", gpu->irq, err); + err = etnaviv_gpu_register_irq(gpu, platform_get_irq(pdev, 0)); + if (err) return err; - } /* Get Clocks: */ gpu->clk_reg = devm_clk_get_optional(&pdev->dev, "reg"); From patchwork Mon May 29 17:14:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 100370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1662318vqr; Mon, 29 May 2023 10:15:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6PU3rD5BGvfMKIsGzWFW6xG8QxvNmZ0Lmkd5BxgJ83Ycw93IidVev7vB8T5NI5D4ygWu/q X-Received: by 2002:a17:902:e88f:b0:1b0:42fb:19e6 with SMTP id w15-20020a170902e88f00b001b042fb19e6mr3972002plg.6.1685380533727; Mon, 29 May 2023 10:15:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685380533; cv=none; d=google.com; s=arc-20160816; b=NQCaS0qyI1mHZNCxKXQ/TBWCF1bUqghi04agApNtDeAVgd1pAggH0KWFmjWLJ9IC8E TuUSV1O+6ADfRPCEFX58/AEgXhKexdeFuSPydfaX3zlm4J7tzSAfYXZ6DwUA+o3IizeU dVBQZnz3u1ygoSUlX0JRVVxBLnKShPZKg4d2RRzdZ1WyJSZ9S6jwYvDxlgGeBuBNtcui 25M0wvBa6UCYyfBhHBhM5BtlwJGYfXzs2u/BRAsLJx9diX+d3WIyOK5ixzrb1igLFk5J LUTCc5gdyBTMOhOf5zlxAt3IkuCAHKDLhdKHzfENA38S/U07jBRyPtabU1JVTcELDYxm MVYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=fepsGobuFg9aHpZsZqWq6X1c1R5Y3wG5ilGfUYb2rT8=; b=uO9es9fMwuwiHFy+w/dERaY6sJig58kBACox+5JmNMXvwR6JcjjpS4vePo25DckEjb GHBeyuxvnQD5yPov42eCd6g/ScM2sfpT+SVNRjHXpyNXJAlXSR5LGkTZ+ANlfldc8jPF kwg93+yKaGFQ7lYOj/8K04IrBG02mhHlaDIrvl9kmDluGM4FBkH+nh93KMdVgtQckRJb SdEDLBPk4lojSaWNnrYpmDMTOfTvlJA0F5BaPuUO345VR8loMD7r1uOWksJcQ3ePkAlR Skrc002YmRzWs43bZ7SGAYJrA4zsQAkF1LoSTs1sofsT2OMQl707rWH834a9W4QALJtE qPTw== 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 x15-20020a17090ab00f00b002509203c8b2si9428024pjq.47.2023.05.29.10.15.19; Mon, 29 May 2023 10:15:33 -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 S229580AbjE2ROW (ORCPT + 99 others); Mon, 29 May 2023 13:14:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbjE2ROV (ORCPT ); Mon, 29 May 2023 13:14:21 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 70DB6C7 for ; Mon, 29 May 2023 10:14:19 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8AxQ_Bq3XRknUkCAA--.5278S3; Tue, 30 May 2023 01:14:18 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxD79p3XRkLUJ_AA--.10654S4; Tue, 30 May 2023 01:14:17 +0800 (CST) From: Sui Jingfeng To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Li Yi Subject: [PATCH v4 2/6] drm/etnaviv: add a dedicated function to get various clocks Date: Tue, 30 May 2023 01:14:13 +0800 Message-Id: <20230529171417.2146323-3-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230529171417.2146323-1-suijingfeng@loongson.cn> References: <20230529171417.2146323-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxD79p3XRkLUJ_AA--.10654S4 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxGw45JrWrAFW5Gr4rKw47XFb_yoWrGw1xpa 1fJa4Ykr1UZryjg347AFn8trnIkw1xCa4xC3s0vwnavw45JF4Ut3yYkFZ8XFs8ZryrWFWf Kr15Kr4UCFyF9rDanT9S1TB71UUUUj7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bfkYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JFv_Jw1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8JVW8Jr1ln4kS 14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E87Iv 67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2 AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xF xVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWw C2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Xr0_ Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJV WUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIY CTnIWIevJa73UjIFyTuYvjxUFwIDUUUUU 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?1767249578557714760?= X-GMAIL-MSGID: =?utf-8?q?1767249578557714760?= Because it is also platform-dependent, there are environments where don't have CLK subsystem support, for example, discreted PCI gpu. So don't rage quit if there is no CLK subsystem. For the GPU in LS7a1000 and LS2k2000, the working frequency of the GPU is tuned by configuring the PLL register directly. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 62 ++++++++++++++++++--------- drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 1 + 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index 636d3f39ddcb..4937580551a5 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1565,10 +1565,45 @@ static irqreturn_t irq_handler(int irq, void *data) return ret; } +static int etnaviv_gpu_clk_get(struct etnaviv_gpu *gpu) +{ + struct device *dev = gpu->dev; + + if (gpu->no_clk) + return 0; + + gpu->clk_reg = devm_clk_get_optional(dev, "reg"); + DBG("clk_reg: %p", gpu->clk_reg); + if (IS_ERR(gpu->clk_reg)) + return PTR_ERR(gpu->clk_reg); + + gpu->clk_bus = devm_clk_get_optional(dev, "bus"); + DBG("clk_bus: %p", gpu->clk_bus); + if (IS_ERR(gpu->clk_bus)) + return PTR_ERR(gpu->clk_bus); + + gpu->clk_core = devm_clk_get(dev, "core"); + DBG("clk_core: %p", gpu->clk_core); + if (IS_ERR(gpu->clk_core)) + return PTR_ERR(gpu->clk_core); + gpu->base_rate_core = clk_get_rate(gpu->clk_core); + + gpu->clk_shader = devm_clk_get_optional(dev, "shader"); + DBG("clk_shader: %p", gpu->clk_shader); + if (IS_ERR(gpu->clk_shader)) + return PTR_ERR(gpu->clk_shader); + gpu->base_rate_shader = clk_get_rate(gpu->clk_shader); + + return 0; +} + static int etnaviv_gpu_clk_enable(struct etnaviv_gpu *gpu) { int ret; + if (gpu->no_clk) + return 0; + ret = clk_prepare_enable(gpu->clk_reg); if (ret) return ret; @@ -1599,6 +1634,9 @@ static int etnaviv_gpu_clk_enable(struct etnaviv_gpu *gpu) static int etnaviv_gpu_clk_disable(struct etnaviv_gpu *gpu) { + if (gpu->no_clk) + return 0; + clk_disable_unprepare(gpu->clk_shader); clk_disable_unprepare(gpu->clk_core); clk_disable_unprepare(gpu->clk_bus); @@ -1865,27 +1903,9 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) return err; /* Get Clocks: */ - gpu->clk_reg = devm_clk_get_optional(&pdev->dev, "reg"); - DBG("clk_reg: %p", gpu->clk_reg); - if (IS_ERR(gpu->clk_reg)) - return PTR_ERR(gpu->clk_reg); - - gpu->clk_bus = devm_clk_get_optional(&pdev->dev, "bus"); - DBG("clk_bus: %p", gpu->clk_bus); - if (IS_ERR(gpu->clk_bus)) - return PTR_ERR(gpu->clk_bus); - - gpu->clk_core = devm_clk_get(&pdev->dev, "core"); - DBG("clk_core: %p", gpu->clk_core); - if (IS_ERR(gpu->clk_core)) - return PTR_ERR(gpu->clk_core); - gpu->base_rate_core = clk_get_rate(gpu->clk_core); - - gpu->clk_shader = devm_clk_get_optional(&pdev->dev, "shader"); - DBG("clk_shader: %p", gpu->clk_shader); - if (IS_ERR(gpu->clk_shader)) - return PTR_ERR(gpu->clk_shader); - gpu->base_rate_shader = clk_get_rate(gpu->clk_shader); + err = etnaviv_gpu_clk_get(gpu); + if (err) + return err; /* TODO: figure out max mapped size */ dev_set_drvdata(dev, gpu); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h index 98c6f9c320fc..6da5209a7d64 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h @@ -148,6 +148,7 @@ struct etnaviv_gpu { struct clk *clk_reg; struct clk *clk_core; struct clk *clk_shader; + bool no_clk; unsigned int freq_scale; unsigned long base_rate_core; From patchwork Mon May 29 17:14:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 100376 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1669687vqr; Mon, 29 May 2023 10:30:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/VpiPGCUtP215NZ4dTZkjaxowm8btsyRF00UK+hxUHhauVVgMMTvohf+tNP3h04yook7h X-Received: by 2002:a17:902:f7c9:b0:1b0:31a8:2f74 with SMTP id h9-20020a170902f7c900b001b031a82f74mr5282823plw.68.1685381424554; Mon, 29 May 2023 10:30:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685381424; cv=none; d=google.com; s=arc-20160816; b=NwOkLK7wE5jWQiSBKl2Xuk0scqh+L3bFo0HqdunbiXXFodtZ0W/YAbp1BM5k3/Vwjs 4f1AacdStjQ2scrgxs6w1Sc7ilK13WfeG7P7zowRM9V+OWtEIq7zsi2/SVRReJfU89C1 Q/IkiXWSSP+e/4vin8CGAddVLpQFT5I1a4i7oK3BtPpkGKxoAaHBxBpgmO6AWfJ/7Y12 +ZLntSJBcttEgD4XOMpgoVIRt14bl0KLAsbzXXivuP1SjPAklKEtN8pRkTbRX8Eclqa1 kaFGVYG8k8+CSdVhToy9QM5VEafY1RZIDgmMALU6hk0wu/rXRKEQ9AiNbDgXti2cLAXF g8iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=q6caTcGh0X5Gh+bgcvS3STOCkrhXCuWqt7xr31+tKFQ=; b=K6Ozsj070dcdUCM/gLd7UE7Su1hNSPY8ymrAP8teEmdRASW7PTYuAVTfmTZ0q7RMP0 od/q0cnb3Pyij67D8v4B6ARKeSatFFwtRIPnGync8tPiE649cbpFoM0UaF7qdJ0tkTbo Hb8pkah+J9mjBzcISzQZ4Ox8pyUNaVTgXlVHiUrYklc+UpAs2jQYvPDQ/MuTsq1Um8n4 LXua/jtSUsfalv0nTi9N1POBxTyCekHGWir5L9oueKiUIcsIYJ9SI5c3Mr0QM384Q0H8 aQFPx8+cPIuy/1wuGqHc6TRzDcp4blsNpRVn+IM3zFx4AQZycM660xO7+ElTcvAu15cM 1a3g== 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 y23-20020a1709029b9700b001a2513b8e14si9300975plp.84.2023.05.29.10.30.10; Mon, 29 May 2023 10:30:24 -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 S229626AbjE2ROc (ORCPT + 99 others); Mon, 29 May 2023 13:14:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbjE2ROW (ORCPT ); Mon, 29 May 2023 13:14:22 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7DBEFCD for ; Mon, 29 May 2023 10:14:19 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8DxuPFq3XRkoUkCAA--.5299S3; Tue, 30 May 2023 01:14:18 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxD79p3XRkLUJ_AA--.10654S5; Tue, 30 May 2023 01:14:18 +0800 (CST) From: Sui Jingfeng To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Li Yi Subject: [PATCH v4 3/6] drm/etnaviv: add dedicated functions to create and destroy platform devices Date: Tue, 30 May 2023 01:14:14 +0800 Message-Id: <20230529171417.2146323-4-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230529171417.2146323-1-suijingfeng@loongson.cn> References: <20230529171417.2146323-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxD79p3XRkLUJ_AA--.10654S5 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxAr4ftrWxCr4xuFWkKFyxAFb_yoW5GF48pF 17GFWSyrW8uFW7Kw1xXwn8ZFW5C3WIg34F9rnFywnI9398AryDJF95GFyUAFnxJrWrG3W5 t39xtF4xuF45ZrJanT9S1TB71UUUUj7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bfkYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JFv_Jw1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8JVW8Jr1ln4kS 14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E87Iv 67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2 AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xF xVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWw C2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Xr0_ Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJV WUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIY CTnIWIevJa73UjIFyTuYvjxUFwIDUUUUU 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?1767250512316103674?= X-GMAIL-MSGID: =?utf-8?q?1767250512316103674?= Also rename the virtual master platform device as etnaviv_platform_device, for better reflection that it is a platform device, not a DRM device. Another benefit is that we no longer need to call of_node_put() for three different cases, Instead, we only need to call it once. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 56 +++++++++++++++++++-------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 31a7f59ccb49..0a9d90c18f2c 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -656,12 +656,44 @@ static struct platform_driver etnaviv_platform_driver = { }, }; -static struct platform_device *etnaviv_drm; +static struct platform_device *etnaviv_platform_device; -static int __init etnaviv_init(void) +static int etnaviv_create_platform_device(const char *name, + struct platform_device **ppdev) { struct platform_device *pdev; int ret; + + pdev = platform_device_alloc(name, PLATFORM_DEVID_NONE); + if (!pdev) + return -ENOMEM; + + ret = platform_device_add(pdev); + if (ret) { + platform_device_put(pdev); + return ret; + } + + *ppdev = pdev; + + return 0; +} + +static void etnaviv_destroy_platform_device(struct platform_device **ppdev) +{ + struct platform_device *pdev = *ppdev; + + if (!pdev) + return; + + *ppdev = NULL; + + platform_device_unregister(pdev); +} + +static int __init etnaviv_init(void) +{ + int ret; struct device_node *np; etnaviv_validate_init(); @@ -682,22 +714,12 @@ static int __init etnaviv_init(void) if (!of_device_is_available(np)) continue; - pdev = platform_device_alloc("etnaviv", PLATFORM_DEVID_NONE); - if (!pdev) { - ret = -ENOMEM; - of_node_put(np); - goto unregister_platform_driver; - } - - ret = platform_device_add(pdev); - if (ret) { - platform_device_put(pdev); - of_node_put(np); + ret = etnaviv_create_platform_device("etnaviv", + &etnaviv_platform_device); + of_node_put(np); + if (ret) goto unregister_platform_driver; - } - etnaviv_drm = pdev; - of_node_put(np); break; } @@ -713,7 +735,7 @@ module_init(etnaviv_init); static void __exit etnaviv_exit(void) { - platform_device_unregister(etnaviv_drm); + etnaviv_destroy_platform_device(&etnaviv_platform_device); platform_driver_unregister(&etnaviv_platform_driver); platform_driver_unregister(&etnaviv_gpu_driver); } From patchwork Mon May 29 17:14:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 100372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1667881vqr; Mon, 29 May 2023 10:26:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5YSL51alRn28xORxDdrZyr4uWkYx+aK9xLVL2odSUzLtDmLstF+6igGJ7kHZfRAyPBlsbH X-Received: by 2002:a17:902:ce82:b0:1af:e116:4b42 with SMTP id f2-20020a170902ce8200b001afe1164b42mr8464021plg.34.1685381197868; Mon, 29 May 2023 10:26:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685381197; cv=none; d=google.com; s=arc-20160816; b=bl4Zjxn71HIMWavEcDpoJ1geJbV5hfceZIpL8BcOoGlU6wusC98lCw+603drlwzkgd zY7bBByDsmUrFwZwdwaDaGFV3AI3kXIbyZZcmWcIoDnBQ3QRNQpHQr55J7g8xgAnXoG/ pFl20SsLSU4rKRjliOOSVDZskFUWh/oTk23F9Td+7YZqoLPu7QMGQGRAApS8/JudaHWJ gNsXgHsOs6AxIlc5+BUyJ+GJ8/HLKGwBjSsjSynFzPJyGH87HHk2XwE/ZC1raf9uZeMX fDvuht+rO4hAy+Kq8+mc4kq9Bhb+Ruv4SzRx5z26US9AuxlziTRs2y4dczuYkyrJHW6d 69Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hV666E4Kvnp6xtfEHPENgXUtKOT40MQjhx/HLYPbDgg=; b=g3KpQTrn2UR2wRr7yz1Zm3216H2KXhIU+MbW8mFGWuaIb8urGw9SaXOGw/IdNA8w/L FRIHo4xM0B624eOs+2kvf1SSWzEDsvjt6C9O9dJtTwOyoY2RF/eSuaPg7cImBax86Ne+ RntkPrJIObZf0jcfwEvJ9FVhgLf089Hb6xNtBRm75cVem5diQzhgIA5m3oaEG9rEC43/ Xo2QB+O5bYSt+ad2iz7ntzIHBIOFcxe8CuO4sHtvlo/YaPU2VdGT6O056nZF6lZePI57 IT0h6YhL3HCGQVuJpxtufdRKOFAZ8TOQFPqI97MNup535xucT144XvN8eFaactOnHitz QCmQ== 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 a12-20020a170902eccc00b001afe1d16369si9285775plh.420.2023.05.29.10.26.21; Mon, 29 May 2023 10:26:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229603AbjE2RO0 (ORCPT + 99 others); Mon, 29 May 2023 13:14:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbjE2ROW (ORCPT ); Mon, 29 May 2023 13:14:22 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4156CCF for ; Mon, 29 May 2023 10:14:19 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8BxfOtq3XRkqEkCAA--.2122S3; Tue, 30 May 2023 01:14:18 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxD79p3XRkLUJ_AA--.10654S6; Tue, 30 May 2023 01:14:18 +0800 (CST) From: Sui Jingfeng To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Li Yi Subject: [PATCH v4 4/6] drm/etnaviv: add helpers for private data construction and destruction Date: Tue, 30 May 2023 01:14:15 +0800 Message-Id: <20230529171417.2146323-5-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230529171417.2146323-1-suijingfeng@loongson.cn> References: <20230529171417.2146323-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxD79p3XRkLUJ_AA--.10654S6 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxCw4rWr47Gr17WF1kGF1rJFb_yoWrCFy8pF srJa40yrWvvF48K3sxJrs8Za43C3WxWa409asFqwn0qw4ayr1kWFn5tFyUAF9xJFyrCFy3 tw1Dtr1UXF40krJanT9S1TB71UUUUj7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bfkYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8JVW8Jr1ln4kS 14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E87Iv 67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2 AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xF xVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWw C2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Xr0_ Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJV WUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIY CTnIWIevJa73UjIFyTuYvjxU4Xo7DUUUU 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?1767250275104779029?= X-GMAIL-MSGID: =?utf-8?q?1767250275104779029?= struct etnaviv_drm_private contains a lot of common resources that are shared by all GPUs. This patch introduces two dedicated functions, which is for the construction and destruction of instances of this structure.      The idea is to avoid leaking its members outside. The error handling code can also be simplified. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 71 +++++++++++++++++---------- drivers/gpu/drm/etnaviv/etnaviv_drv.h | 4 ++ 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 0a9d90c18f2c..56c98711f8e1 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -498,28 +498,17 @@ static const struct drm_driver etnaviv_drm_driver = { .minor = 3, }; -/* - * Platform driver: - */ -static int etnaviv_bind(struct device *dev) +static int etnaviv_alloc_private(struct device *dev, + struct etnaviv_drm_private **ppriv) { struct etnaviv_drm_private *priv; - struct drm_device *drm; int ret; - drm = drm_dev_alloc(&etnaviv_drm_driver, dev); - if (IS_ERR(drm)) - return PTR_ERR(drm); - priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) { dev_err(dev, "failed to allocate private data\n"); - ret = -ENOMEM; - goto out_put; + return -ENOMEM; } - drm->dev_private = priv; - - dma_set_max_seg_size(dev, SZ_2G); xa_init_flags(&priv->active_contexts, XA_FLAGS_ALLOC); @@ -528,18 +517,55 @@ static int etnaviv_bind(struct device *dev) priv->num_gpus = 0; priv->shm_gfp_mask = GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN; - priv->cmdbuf_suballoc = etnaviv_cmdbuf_suballoc_new(drm->dev); + priv->cmdbuf_suballoc = etnaviv_cmdbuf_suballoc_new(dev); if (IS_ERR(priv->cmdbuf_suballoc)) { - dev_err(drm->dev, "Failed to create cmdbuf suballocator\n"); + dev_err(dev, "Failed to create cmdbuf suballocator\n"); ret = PTR_ERR(priv->cmdbuf_suballoc); - goto out_free_priv; + kfree(priv); + return ret; } + *ppriv = priv; + + return 0; +} + +static void etnaviv_free_private(struct etnaviv_drm_private *priv) +{ + etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); + + xa_destroy(&priv->active_contexts); + + kfree(priv); +} + +/* + * Platform driver: + */ +static int etnaviv_bind(struct device *dev) +{ + struct etnaviv_drm_private *priv; + struct drm_device *drm; + int ret; + + drm = drm_dev_alloc(&etnaviv_drm_driver, dev); + if (IS_ERR(drm)) + return PTR_ERR(drm); + + ret = etnaviv_alloc_private(dev, &priv); + if (ret) + goto out_put; + + priv->drm = drm; + drm->dev_private = priv; + + dma_set_max_seg_size(dev, SZ_2G); + dev_set_drvdata(dev, drm); ret = component_bind_all(dev, drm); if (ret < 0) - goto out_destroy_suballoc; + goto out_free_priv; load_gpu(drm); @@ -551,10 +577,8 @@ static int etnaviv_bind(struct device *dev) out_unbind: component_unbind_all(dev, drm); -out_destroy_suballoc: - etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); out_free_priv: - kfree(priv); + etnaviv_free_private(priv); out_put: drm_dev_put(drm); @@ -570,12 +594,9 @@ static void etnaviv_unbind(struct device *dev) component_unbind_all(dev, drm); - etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); - - xa_destroy(&priv->active_contexts); + etnaviv_free_private(priv); drm->dev_private = NULL; - kfree(priv); drm_dev_put(drm); } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h index b3eb1662e90c..87fb52c03c5e 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h @@ -35,6 +35,7 @@ struct etnaviv_file_private { }; struct etnaviv_drm_private { + struct drm_device *drm; int num_gpus; struct etnaviv_gpu *gpu[ETNA_MAX_PIPES]; gfp_t shm_gfp_mask; @@ -45,6 +46,9 @@ struct etnaviv_drm_private { struct xarray active_contexts; u32 next_context_id; + /* hint for platform support cached coherent caching mode */ + bool has_cached_coherent; + /* list of GEM objects: */ struct mutex gem_lock; struct list_head gem_list; From patchwork Mon May 29 17:14:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 100371 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1667578vqr; Mon, 29 May 2023 10:25:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7pfvqdIaR0ADfaF7IBOO5NNRxpWYOtCiQpfpplHRF/kwpy8SRkImkfqt3n3AUwO/bbqH+L X-Received: by 2002:a17:902:daca:b0:1ac:859a:5b5a with SMTP id q10-20020a170902daca00b001ac859a5b5amr12877417plx.0.1685381154484; Mon, 29 May 2023 10:25:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685381154; cv=none; d=google.com; s=arc-20160816; b=NDUgxBc0VgCqN6CW1kiMWCBwmJD3M6P7Z6qP1OeFx+NJyh2e/jfpY809JLIwBbkhVg rSqOSj0zicke/3NP7ACraqj1DNVA2VJVRVM9u1D0cZO/nQmjDxwumtNazl2atoaufg27 Ouu3w70JNp6K1ePC1LhSyMMSxXFINkmPToby9qpdLxKh5b2xNk1KepetU13urrO4WXs3 mNfJymPl392x8hgF3EIq0NqUrkP+T67KdP5MRLcsZKABF3X09drYEyvS6AxR9rB3z+TI ri/d3Kvp3bsexXOy8TG7jOd+z8a1YVNObcOPdYEcPtpHadzoAHsSHKUSuKvrqCmjH0BK koZA== 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=QRGu2OJh13TBggOa5FF3n5tJpz2I4FNAf2d6/oW0s90=; b=ujevuoLChVSaxPLHrGR1S8ZzfL/ArD7Fj4u50YDpW1YgoAKpEdLv+De/izf+cqpvqK yMpeICuMge7j+gwAZCpmwG7n/JVX7yiWLXXvhB01QDaf/b4+POk/kGCLia9CXim9kdj2 c1KFZsCtX25mfnpzKeNW25nu9mDfLYxcpVGx08PrtHNHd2ysNYyMY1MEZe7PVfuA4Ed7 2I0zAY+6mcYR+oeG8IOD1Gh7zlWBkFW/nx2Xn1/dpKC/rguYKkuOGktrU5j5Zjn41r2m iBE5pFTM2HTOBgT9Sj8OX49j6q7Z6Be+gKXFhfkwigWUwbWmUDTVgl/ftBCIlhxgLa3f MMeg== 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 x5-20020a1709028ec500b001a6ee332903si7635014plo.347.2023.05.29.10.25.38; Mon, 29 May 2023 10:25:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229631AbjE2ROf (ORCPT + 99 others); Mon, 29 May 2023 13:14:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbjE2ROX (ORCPT ); Mon, 29 May 2023 13:14:23 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D1015D2 for ; Mon, 29 May 2023 10:14:19 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8Bxq+pr3XRkr0kCAA--.916S3; Tue, 30 May 2023 01:14:19 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxD79p3XRkLUJ_AA--.10654S7; Tue, 30 May 2023 01:14:18 +0800 (CST) From: Sui Jingfeng To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, loongson-kernel@lists.loongnix.cn, Li Yi Subject: [PATCH v4 5/6] drm/etnaviv: expand driver support for the PCI devices Date: Tue, 30 May 2023 01:14:16 +0800 Message-Id: <20230529171417.2146323-6-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230529171417.2146323-1-suijingfeng@loongson.cn> References: <20230529171417.2146323-1-suijingfeng@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxD79p3XRkLUJ_AA--.10654S7 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvAXoWfGF1xGr4UZrW8tF4kZFW8JFb_yoW8Xw4xuo WxZrnxXa1rGFZ3t398AF12gFy3Zw4DC3s8C3Z8tws09ayvqF15tw13G3W3tF1Yvr1FgrWf Zw1Utw1rJF4xJFn5n29KB7ZKAUJUUUUx529EdanIXcx71UUUUU7KY7ZEXasCq-sGcSsGvf J3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnRJU UUB2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2IYs7xG6rWj6s 0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4j6r4UJwAa w2AFwI0_JF0_Jw1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44 I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Wrv_ZF1lYx0Ex4A2 jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262 kKe7AKxVWUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km 07C267AKxVWUAVWUtwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r 1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW5 JVW7JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rV WUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4U JbIYCTnIWIevJa73UjIFyTuYvjxUVWrXDUUUU 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?1767250229285372238?= X-GMAIL-MSGID: =?utf-8?q?1767250229285372238?= This patch adds PCI driver support on top of what already have. Take the GC1000 in LS7A1000/LS2K1000 as the first instance of the PCI device driver. There is only one GPU core for the GC1000 in the LS7A1000 and LS2K1000. Therefore, component frameworks can be avoided. Because we want to bind the DRM driver service to the PCI driver manually.      We avoid using the component framework because the virtual master device will not be used without a force override. X server and Mesa will try to find the PCI device to use by default. Creating a virtual master device for PCI GPUs cause unnecessary troubles.      Using the component framework with a PCI device is still possible; it is just that the solo PCI device should be the master. A platform with a single GPU core could also try the non-component code path. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/Makefile | 1 + drivers/gpu/drm/etnaviv/etnaviv_drv.c | 62 ++++++++++++--- drivers/gpu/drm/etnaviv/etnaviv_drv.h | 3 + drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 97 ++++++++++++++++------- drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 12 +++ drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c | 88 ++++++++++++++++++++ drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h | 10 +++ 7 files changed, 232 insertions(+), 41 deletions(-) create mode 100644 drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c create mode 100644 drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h diff --git a/drivers/gpu/drm/etnaviv/Makefile b/drivers/gpu/drm/etnaviv/Makefile index 46e5ffad69a6..3f8b99664a58 100644 --- a/drivers/gpu/drm/etnaviv/Makefile +++ b/drivers/gpu/drm/etnaviv/Makefile @@ -13,6 +13,7 @@ etnaviv-y := \ etnaviv_iommu_v2.o \ etnaviv_iommu.o \ etnaviv_mmu.o \ + etnaviv_pci_drv.o \ etnaviv_perfmon.o \ etnaviv_sched.o diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 56c98711f8e1..7ff795c5cc79 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -21,6 +22,7 @@ #include "etnaviv_gpu.h" #include "etnaviv_gem.h" #include "etnaviv_mmu.h" +#include "etnaviv_pci_drv.h" #include "etnaviv_perfmon.h" /* @@ -525,6 +527,16 @@ static int etnaviv_alloc_private(struct device *dev, return ret; } + /* + * Loongson Mips and LoongArch CPU(ls3a5000, ls3c5000, ls2k1000la) + * maintain cache coherency by hardware + */ + if (IS_ENABLED(CONFIG_CPU_LOONGSON64) || IS_ENABLED(CONFIG_LOONGARCH)) + priv->has_cached_coherent = true; + + dev_info(dev, "Cached coherent mode is %s\n", + priv->has_cached_coherent ? "support" : "not support"); + *ppriv = priv; return 0; @@ -539,10 +551,9 @@ static void etnaviv_free_private(struct etnaviv_drm_private *priv) kfree(priv); } -/* - * Platform driver: - */ -static int etnaviv_bind(struct device *dev) +static struct etnaviv_drm_private *etna_private_s; + +int etnaviv_drm_bind(struct device *dev, bool component) { struct etnaviv_drm_private *priv; struct drm_device *drm; @@ -558,12 +569,15 @@ static int etnaviv_bind(struct device *dev) priv->drm = drm; drm->dev_private = priv; + etna_private_s = priv; dma_set_max_seg_size(dev, SZ_2G); - dev_set_drvdata(dev, drm); + if (component) + ret = component_bind_all(dev, drm); + else + ret = etnaviv_gpu_bind(dev, NULL, drm); - ret = component_bind_all(dev, drm); if (ret < 0) goto out_free_priv; @@ -585,14 +599,17 @@ static int etnaviv_bind(struct device *dev) return ret; } -static void etnaviv_unbind(struct device *dev) +void etnaviv_drm_unbind(struct device *dev, bool component) { - struct drm_device *drm = dev_get_drvdata(dev); - struct etnaviv_drm_private *priv = drm->dev_private; + struct etnaviv_drm_private *priv = etna_private_s; + struct drm_device *drm = priv->drm; drm_dev_unregister(drm); - component_unbind_all(dev, drm); + if (component) + component_unbind_all(dev, drm); + else + etnaviv_gpu_unbind(dev, NULL, drm); etnaviv_free_private(priv); @@ -601,9 +618,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) @@ -723,10 +753,14 @@ static int __init etnaviv_init(void) if (ret != 0) return ret; - ret = platform_driver_register(&etnaviv_platform_driver); + ret = pci_register_driver(&etnaviv_pci_driver); if (ret != 0) goto unregister_gpu_driver; + ret = platform_driver_register(&etnaviv_platform_driver); + if (ret != 0) + goto unregister_pci_driver; + /* * If the DT contains at least one available GPU device, instantiate * the DRM platform device. @@ -748,6 +782,8 @@ static int __init etnaviv_init(void) unregister_platform_driver: platform_driver_unregister(&etnaviv_platform_driver); +unregister_pci_driver: + pci_unregister_driver(&etnaviv_pci_driver); unregister_gpu_driver: platform_driver_unregister(&etnaviv_gpu_driver); return ret; diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h index 87fb52c03c5e..934fc3744389 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h @@ -86,6 +86,9 @@ bool etnaviv_cmd_validate_one(struct etnaviv_gpu *gpu, u32 *stream, unsigned int size, struct drm_etnaviv_gem_submit_reloc *relocs, unsigned int reloc_size); +int etnaviv_drm_bind(struct device *dev, bool component); +void etnaviv_drm_unbind(struct device *dev, bool component); + #ifdef CONFIG_DEBUG_FS void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv, struct seq_file *m); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index 4937580551a5..700f2414b87d 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1565,10 +1565,11 @@ static irqreturn_t irq_handler(int irq, void *data) return ret; } -static int etnaviv_gpu_clk_get(struct etnaviv_gpu *gpu) +static int etnaviv_gpu_clk_get(struct etnaviv_gpu *gpu, bool no_clk) { struct device *dev = gpu->dev; + gpu->no_clk = no_clk; if (gpu->no_clk) return 0; @@ -1746,8 +1747,7 @@ static const struct thermal_cooling_device_ops cooling_ops = { .set_cur_state = etnaviv_gpu_cooling_set_cur_state, }; -static int etnaviv_gpu_bind(struct device *dev, struct device *master, - void *data) +int etnaviv_gpu_bind(struct device *dev, struct device *master, void *data) { struct drm_device *drm = data; struct etnaviv_drm_private *priv = drm->dev_private; @@ -1778,7 +1778,6 @@ static int etnaviv_gpu_bind(struct device *dev, struct device *master, if (ret < 0) goto out_sched; - gpu->drm = drm; gpu->fence_context = dma_fence_context_alloc(1); xa_init_flags(&gpu->user_fences, XA_FLAGS_ALLOC); @@ -1807,8 +1806,7 @@ static int etnaviv_gpu_bind(struct device *dev, struct device *master, return ret; } -static void etnaviv_gpu_unbind(struct device *dev, struct device *master, - void *data) +void etnaviv_gpu_unbind(struct device *dev, struct device *master, void *data) { struct etnaviv_gpu *gpu = dev_get_drvdata(dev); @@ -1878,9 +1876,37 @@ static int etnaviv_gpu_register_irq(struct etnaviv_gpu *gpu, int irq) return 0; } -static int etnaviv_gpu_platform_probe(struct platform_device *pdev) +static int etnaviv_gpu_plat_drv_init(struct etnaviv_gpu *gpu, bool component) +{ + struct device *dev = gpu->dev; + struct platform_device *pdev = to_platform_device(dev); + int err; + + /* Map registers: */ + gpu->mmio = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(gpu->mmio)) + return PTR_ERR(gpu->mmio); + + if (component) { + err = component_add(dev, &gpu_ops); + if (err < 0) { + dev_err(dev, "failed to register component: %d\n", err); + return err; + } + } + + return 0; +} + +static void etnaviv_gpu_plat_drv_fini(struct etnaviv_gpu *gpu, bool component) +{ + if (component) + component_del(gpu->dev, &gpu_ops); +} + +int etnaviv_gpu_driver_create(struct device *dev, int irq, bool component, + bool no_clk, pfn_gpu_init_t gpu_post_init) { - struct device *dev = &pdev->dev; struct etnaviv_gpu *gpu; int err; @@ -1888,22 +1914,16 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) if (!gpu) return -ENOMEM; - gpu->dev = &pdev->dev; + gpu->dev = dev; mutex_init(&gpu->lock); mutex_init(&gpu->sched_lock); - /* Map registers: */ - gpu->mmio = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(gpu->mmio)) - return PTR_ERR(gpu->mmio); - /* Get Interrupt: */ - err = etnaviv_gpu_register_irq(gpu, platform_get_irq(pdev, 0)); + err = etnaviv_gpu_register_irq(gpu, irq); if (err) return err; - /* Get Clocks: */ - err = etnaviv_gpu_clk_get(gpu); + err = etnaviv_gpu_clk_get(gpu, no_clk); if (err) return err; @@ -1915,23 +1935,44 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) * autosuspend delay is rather arbitary: no measurements have * yet been performed to determine an appropriate value. */ - pm_runtime_use_autosuspend(gpu->dev); - pm_runtime_set_autosuspend_delay(gpu->dev, 200); - pm_runtime_enable(gpu->dev); + pm_runtime_use_autosuspend(dev); + pm_runtime_set_autosuspend_delay(dev, 200); + pm_runtime_enable(dev); - err = component_add(&pdev->dev, &gpu_ops); - if (err < 0) { - dev_err(&pdev->dev, "failed to register component: %d\n", err); - return err; - } + gpu_post_init(gpu, component); return 0; } +void etnaviv_gpu_driver_destroy(struct device *dev, bool component, + pfn_gpu_fini_t gpu_early_fini) +{ + struct etnaviv_gpu *gpu = dev_get_drvdata(dev); + + if (!gpu) { + dev_err(dev, "device not initialized properly\n"); + return; + } + + gpu_early_fini(gpu, component); + + pm_runtime_disable(dev); +} + +static int etnaviv_gpu_platform_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + int irq = platform_get_irq(pdev, 0); + + return etnaviv_gpu_driver_create(dev, irq, true, false, etnaviv_gpu_plat_drv_init); +} + static int etnaviv_gpu_platform_remove(struct platform_device *pdev) { - component_del(&pdev->dev, &gpu_ops); - pm_runtime_disable(&pdev->dev); + struct device *dev = &pdev->dev; + + etnaviv_gpu_driver_destroy(dev, true, etnaviv_gpu_plat_drv_fini); + return 0; } @@ -1978,7 +2019,7 @@ static int etnaviv_gpu_rpm_resume(struct device *dev) return 0; } -static const struct dev_pm_ops etnaviv_gpu_pm_ops = { +const struct dev_pm_ops etnaviv_gpu_pm_ops = { RUNTIME_PM_OPS(etnaviv_gpu_rpm_suspend, etnaviv_gpu_rpm_resume, NULL) }; diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h index 6da5209a7d64..cfcdc5dde9d9 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h @@ -207,6 +207,18 @@ void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu); int etnaviv_gpu_wait_idle(struct etnaviv_gpu *gpu, unsigned int timeout_ms); void etnaviv_gpu_start_fe(struct etnaviv_gpu *gpu, u32 address, u16 prefetch); +typedef int (*pfn_gpu_init_t)(struct etnaviv_gpu *gpu, bool component); +typedef void (*pfn_gpu_fini_t)(struct etnaviv_gpu *gpu, bool component); + +int etnaviv_gpu_driver_create(struct device *dev, int irq, bool component, + bool no_clk, pfn_gpu_init_t post_init); +void etnaviv_gpu_driver_destroy(struct device *dev, bool component, + pfn_gpu_fini_t early_fini); + +int etnaviv_gpu_bind(struct device *dev, struct device *master, void *data); +void etnaviv_gpu_unbind(struct device *dev, struct device *master, void *data); + extern struct platform_driver etnaviv_gpu_driver; +extern const struct dev_pm_ops etnaviv_gpu_pm_ops; #endif /* __ETNAVIV_GPU_H__ */ diff --git a/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c new file mode 100644 index 000000000000..e64a03061d09 --- /dev/null +++ b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +#include "etnaviv_drv.h" +#include "etnaviv_gpu.h" +#include "etnaviv_pci_drv.h" + +enum etnaviv_pci_gpu_family { + GC1000_IN_LS7A1000 = 0, + GC1000_IN_LS2K1000 = 1, +}; + +static int etnaviv_gpu_pci_init(struct etnaviv_gpu *gpu, bool component) +{ + struct pci_dev *pdev = to_pci_dev(gpu->dev); + + /* Map registers, assume the PCI bar 0 contain the registers */ + gpu->mmio = pcim_iomap(pdev, 0, 0); + if (IS_ERR(gpu->mmio)) + return PTR_ERR(gpu->mmio); + + gpu->no_clk = true; + + return 0; +} + +static void etnaviv_gpu_pci_fini(struct etnaviv_gpu *gpu, bool component) +{ + struct pci_dev *pdev = to_pci_dev(gpu->dev); + + pci_clear_master(pdev); + + dev_dbg(gpu->dev, "component is %s\n", + component ? "enabled" : "disabled"); +} + +static int etnaviv_pci_probe(struct pci_dev *pdev, + const struct pci_device_id *ent) +{ + struct device *dev = &pdev->dev; + int ret; + + ret = pcim_enable_device(pdev); + if (ret) { + dev_err(&pdev->dev, "failed to enable\n"); + return ret; + } + + pci_set_master(pdev); + + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); + if (ret) + return ret; + + /* Create a GPU driver instance for the PCI device itself */ + ret = etnaviv_gpu_driver_create(dev, pdev->irq, false, true, + etnaviv_gpu_pci_init); + if (ret) + return ret; + + return etnaviv_drm_bind(dev, false); +} + +static void etnaviv_pci_remove(struct pci_dev *pdev) +{ + struct device *dev = &pdev->dev; + + etnaviv_drm_unbind(dev, false); + + etnaviv_gpu_driver_destroy(dev, false, etnaviv_gpu_pci_fini); +} + +static const struct pci_device_id etnaviv_pci_id_lists[] = { + {0x0014, 0x7a15, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GC1000_IN_LS7A1000}, + {0x0014, 0x7a05, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GC1000_IN_LS2K1000}, + {0, 0, 0, 0, 0, 0, 0} +}; + +struct pci_driver etnaviv_pci_driver = { + .name = "etnaviv", + .id_table = etnaviv_pci_id_lists, + .probe = etnaviv_pci_probe, + .remove = etnaviv_pci_remove, + .driver.pm = pm_ptr(&etnaviv_gpu_pm_ops), +}; + +MODULE_DEVICE_TABLE(pci, etnaviv_pci_id_lists); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h new file mode 100644 index 000000000000..6e50ec5f32b7 --- /dev/null +++ b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ETNAVIV_PCI_DRV_H__ +#define __ETNAVIV_PCI_DRV_H__ + +#include + +extern struct pci_driver etnaviv_pci_driver; + +#endif