From patchwork Wed Mar 29 20:51:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 76817 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp691165vqo; Wed, 29 Mar 2023 14:15:27 -0700 (PDT) X-Google-Smtp-Source: AKy350b3dnUYhEpp0f+5tUjHzeFza6V0TgHL+fSmbAcpbwVURTrxOCX1J1I5Cugqq0xHVcoyI8uK X-Received: by 2002:a17:903:6c5:b0:19d:778:ff5 with SMTP id kj5-20020a17090306c500b0019d07780ff5mr18839011plb.15.1680124527529; Wed, 29 Mar 2023 14:15:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680124527; cv=none; d=google.com; s=arc-20160816; b=DFhQxgvbv3Q97p4+wpJxRCL3NGnjDpQcquJwrMki3DAbp3koAR5GCgzgPXMY95e+ub ylUMjAbwJvAiMMceHr72qNvmS1EQByzFjGIPSHk4zR/FAY0dbfv4hBiBdbXbsLJC33sH ShpxJ9xMnsMyDMn2sYiGdfiTxTcArQO7KxLSwEgIfdLkMkO3AqUBYuJfmBWfhYutksxr v2mnJl1INJxZdI67jMXsMZmMJUr8gaySqeFQeq+rrqfSJemaheEr7fFy7VR51+Gk89qk cfyJULw6zDRAzL+VisvTuNnPHNS2V6rFujz+2c//3VtF9+hR+gO1RExtGTZskJsFp3ls 7/DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=dQ1D16H7SQKOll8LJFVpZZQml0HNUFjnyKmJ9Vp+LAA=; b=NrJdUXfar8vSjKfk2IPBVvXKluYNFcoDeDjLFOKgc8mpFvYeR4V0xFdjlWoSrMXZH0 vr8jAmHleo1fX5nez7Ca4T5b8QksvwEcakMIA4ydiMR2ItpJIuS/9JzsJFe8g2SHPmbP /Vd7N2jOC6/xQa6tYeD8O5YgCvRO3dxEymkFRU81kjl/AFovhwjIuXrr+fz+93E9Ae6j dn/YexcQUImo7ZkMpAGF0T39mpXyTi8rQoHXq7Fhg05ZJiv3MsKAFMbZQOTBhmWd/CJO 6xR5CWk5tDPLisyMCo9iN8xx6335C79NF4buoge7bsmMp5FoaT/ugg2fjVE/L1vjBstR avLQ== 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 38-20020a631766000000b005030a59a818si30827527pgx.402.2023.03.29.14.15.10; Wed, 29 Mar 2023 14:15:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229767AbjC2Uvr (ORCPT + 99 others); Wed, 29 Mar 2023 16:51:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbjC2Uvp (ORCPT ); Wed, 29 Mar 2023 16:51:45 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CAB3A469E for ; Wed, 29 Mar 2023 13:51:43 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.43:36106.2084148567 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.43]) by 189.cn (HERMES) with SMTP id AEC041002BB; Thu, 30 Mar 2023 04:51:42 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-7b48884fd-tj646 with ESMTP id 353b3cba185c4f20ae970cdfdfb1d751 for l.stach@pengutronix.de; Thu, 30 Mar 2023 04:51:42 CST X-Transaction-ID: 353b3cba185c4f20ae970cdfdfb1d751 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Li Yi Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng Subject: [PATCH v3 1/6] drm/etnaviv: add a dedicate function to register irq handler for the gpu Date: Thu, 30 Mar 2023 04:51:24 +0800 Message-Id: <20230329205129.1513734-2-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230329205129.1513734-1-15330273260@189.cn> References: <20230329205129.1513734-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=0.6 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,FROM_LOCAL_DIGITS,FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761738256386959602?= X-GMAIL-MSGID: =?utf-8?q?1761738256386959602?= From: Sui Jingfeng Because get irq from a device is platform dependent, pci device has different method to get irq. This patch is a preparation before we introduce 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 Wed Mar 29 20:51:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 76814 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp684147vqo; Wed, 29 Mar 2023 14:02:30 -0700 (PDT) X-Google-Smtp-Source: AKy350Y4QK69aQzRklazW14q/U8CFRrbiEeU3yZ8CqSVQCqwcuVFNHe6acSlsSEStXXusOou2RNP X-Received: by 2002:a17:907:8c0e:b0:930:bc07:3bf7 with SMTP id ta14-20020a1709078c0e00b00930bc073bf7mr23668332ejc.5.1680123750470; Wed, 29 Mar 2023 14:02:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680123750; cv=none; d=google.com; s=arc-20160816; b=Fyko+a1qpRxEFB9KFLjH2+RpX4IKFl9CPtUEcIZTgmK2axzk808tZ8OG2FxoRiVw2X Brvz8C0dNf8ojgN9kX+uyhRaGo7ibnYyQQ6M2zO34EkM+UAGTnm+i6VjuaGAn8X8M7Op gLnFfR7h3zDZu+xqxjz8HCWoQmzjHjDKzBroiYXSlOlqMw5fToYeS8YJ0gN5/oxF42Z0 A8OjqvlhmZYlzuNCv+HKnXzQbhGLGALRe1gBMeglGRISNIC7gKIvTbSj25iXOoPPh1k/ 8qa/9aLcPvnWFPOcQkzQX7kOBLn348hDhKC04Tk63HUrAw211eSEYgH8vkm8snB2tgyw 7Yog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=yqH0ILsc4kcWI5FhiPHvvoLOmwJ6Yb5/o8RSND1kjzo=; b=hS9SnysK+80HRFUCMhWTV3oMnZnEXkzw/EAHxEm7N9mramzrLvrp3jCQinTRoFwfoS 7P/cilBIV9iXwmjROED7jpPyuVbY3eSLPq+wKv1bcKf+X1cVeBLD6+m/nyRsGN/+GBM5 AmwzeHuG4nrgh25xMGZXCWp5v+oaOdaUCfUkK3JkPXD3KREgGjFxh4SE+YJuP99Y+Wnh kPoDBaA2bEbR9eLHdem2pIWTL4RoTbaJQLoswVNG8lWIyUm3m1rYl2nu08WrscRgHbMf aq+D8k1o+nB9N3ifWISi7N0oSToNdbZKoor/KNWUvt29L6HYtMBp/8KCWOroXsabCLa9 j4Ug== 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 tl3-20020a170907c30300b00939ad72ecacsi22354930ejc.225.2023.03.29.14.01.58; Wed, 29 Mar 2023 14:02:30 -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 S229934AbjC2Uvw (ORCPT + 99 others); Wed, 29 Mar 2023 16:51:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbjC2Uvq (ORCPT ); Wed, 29 Mar 2023 16:51:46 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1A0D744B8 for ; Wed, 29 Mar 2023 13:51:44 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.43:36106.2084148567 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.43]) by 189.cn (HERMES) with SMTP id 61DE81002BE; Thu, 30 Mar 2023 04:51:42 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-7b48884fd-tj646 with ESMTP id 70aca06a346644b4bc2ecbeae02d8063 for l.stach@pengutronix.de; Thu, 30 Mar 2023 04:51:43 CST X-Transaction-ID: 70aca06a346644b4bc2ecbeae02d8063 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Li Yi Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng Subject: [PATCH v3 2/6] drm/etnaviv: add a dedicate function to get clock Date: Thu, 30 Mar 2023 04:51:25 +0800 Message-Id: <20230329205129.1513734-3-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230329205129.1513734-1-15330273260@189.cn> References: <20230329205129.1513734-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=0.6 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,FROM_LOCAL_DIGITS,FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761737442068515733?= X-GMAIL-MSGID: =?utf-8?q?1761737442068515733?= From: Sui Jingfeng Because it is also platform dependent, there are environment which without clk subsystem support, we don't want the driver rage quit because of no clk subsystem driver support. There are discrete graphics card which integrate vivante gpu IP. For the GPU in ls7a1000 and lsak2000, working frequency of the gpu is changed 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 Wed Mar 29 20:51:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 76813 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp680014vqo; Wed, 29 Mar 2023 13:53:38 -0700 (PDT) X-Google-Smtp-Source: AKy350YoYlUn0seZ14dwcmA9+lgvD0KKdpZbt0Eoy8W3Nxm/Yp92IH0J1cGbsl0x2WXnbVMI2jWN X-Received: by 2002:a05:6402:712:b0:502:20f0:3ee1 with SMTP id w18-20020a056402071200b0050220f03ee1mr19756225edx.31.1680123217870; Wed, 29 Mar 2023 13:53:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680123217; cv=none; d=google.com; s=arc-20160816; b=hIVFr+a0hvCJMKgry3dGlbSLHSK1Wz8yL7Jp3XNANAiB1gNJedNSISHv4VsWLQyLTF Me/spBUh7NVfYwfpxNHMAQLcJ2i4nRJb6wpX+uBZyRjTPD3oNn9eAbxPiY36bygWVxvd XfeHXe3j7a6EKhYgA7IPiCRYWqexuSPS6LlVNVvpvjjVhFSfwlw+Pydq/0oWZBXVxggB /J+GBseNuxAsigPFzyNQKk7SPevlQTGmyDX3xPuhcFojo1efSuzzBz6JQ8stD1gzjYjg V6P0yG0Yx6sL8eTK9+Kxd+ZLs9gCDi8PfmIPyNmS0uEuDT0XrIMUOVgwLIswbuoUsCaa oKdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=1+WNe+CkowrnSULz7GNQKTUGdWlhhFBc1XTTAQhIEeQ=; b=zKY/JHfeNe/LxZEb7aXrg3Tyv6hSuwyHHujotil25EG2Qd7825CwPSRSBz/Thcomvm p2tpXaKbqpRr1yI3Bur0m9X1ehQcLHgmVr+rzp0+IXOlNmz8JE0gLtgnMjWN6o8Py7ja k3b0ofi7xEUgIX7KHnhnox7Veek6GI/jkc/6Lo77vEl37queNCqBKCGBPUuwQi/gm1GR Crj32JEhakXTaNRnFZJ1vDiSo70d2KOpFP03NcJkOejbknIyKhz/QBmTV9bwhX3MGWu8 XRjgAcEMNsqPDo4Rq4G0RtOHQTw1+yXFlFETTNcVgwyeqRcm1Mj3Jz1HPyt7nrE/ThBq ny2w== 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 g22-20020aa7d1d6000000b004bf976a1b56si32735630edp.627.2023.03.29.13.52.55; Wed, 29 Mar 2023 13:53: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 S229943AbjC2Uv7 (ORCPT + 99 others); Wed, 29 Mar 2023 16:51:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229618AbjC2Uvq (ORCPT ); Wed, 29 Mar 2023 16:51:46 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B0B094C20 for ; Wed, 29 Mar 2023 13:51:44 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.43:36106.2084148567 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.43]) by 189.cn (HERMES) with SMTP id 0D4F81002CE; Thu, 30 Mar 2023 04:51:43 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-7b48884fd-tj646 with ESMTP id 2cb5b1d07b6b49949d5f7ab88250ec0d for l.stach@pengutronix.de; Thu, 30 Mar 2023 04:51:44 CST X-Transaction-ID: 2cb5b1d07b6b49949d5f7ab88250ec0d X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Li Yi Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng Subject: [PATCH v3 3/6] drm/etnaviv: add dedicate functions to create and destroy platform device Date: Thu, 30 Mar 2023 04:51:26 +0800 Message-Id: <20230329205129.1513734-4-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230329205129.1513734-1-15330273260@189.cn> References: <20230329205129.1513734-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=0.6 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,FROM_LOCAL_DIGITS,FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761736883180513455?= X-GMAIL-MSGID: =?utf-8?q?1761736883180513455?= From: Sui Jingfeng Also rename the virtual master device as etnaviv_platform_device, for better reflection that it is a platform device, not the drm device control structure. Another benefit is that we no longer need to call of_node_put() for three different case. Instead, we only need 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 44ca803237a5..ce0537af80bd 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -697,12 +697,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(); @@ -723,22 +755,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; } @@ -754,7 +776,7 @@ module_init(etnaviv_init); static void __exit etnaviv_exit(void) { - platform_device_unregister(etnaviv_drm); + etnaviv_destroy_platform_device(&etnaviv_platform_device); platform_driver_unregister(&etnaviv_platform_driver); platform_driver_unregister(&etnaviv_gpu_driver); } From patchwork Wed Mar 29 20:51:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 76818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp691460vqo; Wed, 29 Mar 2023 14:15:57 -0700 (PDT) X-Google-Smtp-Source: AK7set8qvX3AFxKn+AxM2lBQreKqVtibYmlov9munWjfjW4JybYtsYRhyV6h/Ck6sX+jNMiYy/42 X-Received: by 2002:a05:6a20:c28a:b0:c7:770a:557f with SMTP id bs10-20020a056a20c28a00b000c7770a557fmr16762522pzb.50.1680124556784; Wed, 29 Mar 2023 14:15:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680124556; cv=none; d=google.com; s=arc-20160816; b=bJM2Rb2TyOWirASiLUXDAxMXa8JVVfzI6twXXqR91tpMfs5Q3kowvhvFmeTUxsYKKk hvvKamyRk9PNV6UwnQLCxh6EXBKqRBAg/ygVUvV2iSdE9wtOf+HzhlWbZO1OTMwEjk6f R0wEeiRDt24qwQ5SNG7QahEfD82av1o4fN87SZn0cH/xlQkvmgnPSTOnGIgviikRqxGf ifPlnvEiXomrxZV4049+cAP1CLidMtqsuRACDdg/IAmGPkYGhP8W1BNVLsvO/UtbsAlT MQtwte0NFj/Seu+xOTnW95vyJ012aM42FiR6+zvvNiILJHO20YFTFK3+XfsILx1QlFtR djdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=MxT0/nLkqFx2Za4zRQ483NpjHunl3bE/LM5EqR1WCw0=; b=GPJXmSGSVsVNlo72Ay6MaH883Fvt9so2zRV/vqI5+42wG8X+1Sjr0dQ6eCW8LXX5mp XTuZapQsggF24fgvc1FOE7gqWqagZk8Y5tX6ltOcyr0U9JmHwSra3cdmxhnaXIJ4W5JE rByzEgLPo1Ud65/edX6iEPr2jkJ0UDKYBd/Oq41QKrvO0WSk6MxWgo3cozayyjuNtgae enuMvbQAIX0Nzu1f+FS7M2AeVIrLifpek1Cz4gusMMJ2dNFISQjmVBM3hd/WFAalivo7 tLOnkbM//n0Q8oYg0brpC32zsR9pkYRjZZZ9axZRcZjvngAQ94Ubxg98XPD/wayGXNcJ C4lQ== 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 38-20020a631766000000b005030a59a818si30827527pgx.402.2023.03.29.14.15.42; Wed, 29 Mar 2023 14:15:56 -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 S230018AbjC2UwH (ORCPT + 99 others); Wed, 29 Mar 2023 16:52:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229574AbjC2Uvq (ORCPT ); Wed, 29 Mar 2023 16:51:46 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 550C75264 for ; Wed, 29 Mar 2023 13:51:45 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.43:36106.2084148567 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.43]) by 189.cn (HERMES) with SMTP id ACC9F1002C5; Thu, 30 Mar 2023 04:51:44 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-7b48884fd-tj646 with ESMTP id c1edc99e9a6b4656b719d8890ec08287 for l.stach@pengutronix.de; Thu, 30 Mar 2023 04:51:44 CST X-Transaction-ID: c1edc99e9a6b4656b719d8890ec08287 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Li Yi Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng Subject: [PATCH v3 4/6] drm/etnaviv: add helpers for private data construction and destruction Date: Thu, 30 Mar 2023 04:51:27 +0800 Message-Id: <20230329205129.1513734-5-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230329205129.1513734-1-15330273260@189.cn> References: <20230329205129.1513734-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=0.6 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,FROM_LOCAL_DIGITS,FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761738287048719973?= X-GMAIL-MSGID: =?utf-8?q?1761738287048719973?= From: Sui Jingfeng struct etnaviv_drm_private contains a lot of common resources that is shared by all GPUs, members of it is large enough. This patch introduce two dedicate functions which is for the construction and destruction of the instance of this structure. The idea is avoid to leak its members to outside, then the error handling code can 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 ce0537af80bd..93dfa4b1a38b 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -539,28 +539,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); @@ -569,18 +558,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); @@ -592,10 +618,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); @@ -611,12 +635,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 Wed Mar 29 20:51:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 76816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp688615vqo; Wed, 29 Mar 2023 14:10:37 -0700 (PDT) X-Google-Smtp-Source: AK7set8NV5LDbeeiTAcxHCCdo98hdglghTO9FasNA7zaQsFLeYN8APtdRa6Q9FoInmFX7+CKdBHj X-Received: by 2002:a05:6a20:bf18:b0:dc:43e8:54b7 with SMTP id gc24-20020a056a20bf1800b000dc43e854b7mr15882629pzb.43.1680124237419; Wed, 29 Mar 2023 14:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680124237; cv=none; d=google.com; s=arc-20160816; b=vPpETShS8IBZ1jwfttHvezJb8piAUlu6VEAHnWki6X9lgu1zE2lDjko+yBE/RkWIGe lMZDsfGbEm9WgAUPH33aQSVe0hn8rvC8RgitjU4MpoOvNwm0N/D86uiGfVQpSIwOggds 6O6w5lV1hGyAEeafduFogaa5/KtWyKPF6QP0VLsgwJ+5bh+MAMPxoAUDouOVMBZAf1QZ hvhwf+fxh0Rq3GNxlmFvKWspqSn3UaA8bXBSNP+9tNeDrzpmes+VXq+o7GNDlT1FZsAv GNe4sl+9fh1y2HCwwYmdEUSqtbqdc+fHIID38nXtMv/VwlMbp3ddPTzNvrcvubZDXKVR nH+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=2H6zbXE21PE86GxINZXxJVeh7yDXDYYZsmzWex19j4A=; b=kY18xZiga8jUr4y6MfbQ0evXZQuG2ZoGxSTktO6s+hFkAcISZ6GTTuemWnbctznQVS sSpqOVlqe0J12jkJjGRcY8EMQakY+47qm8GaG2n++TfFklX11ASB/30A8ctarjkPk+kV fr2LN2FytUBOwDFvc1p7tZvd7bT35YIKSZFkXfvJV4UN31zXDKpVarz5PoTO26dxRytC zvxNShtYglk5pXoNVt/apAf6jHlFUswxy0T+yLxLQJ9GUk41hzyzfEBscKNrEUtXATwW wCYR338a3M4yu04nHXxJKDLmkzId+rwwzY2o7QIT+NuitVOozw+XxxibXyo9XwzkUJUS p66g== 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 65-20020a630244000000b0051323b8a185si13446809pgc.811.2023.03.29.14.10.21; Wed, 29 Mar 2023 14:10: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 S230070AbjC2UwR (ORCPT + 99 others); Wed, 29 Mar 2023 16:52:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229822AbjC2Uvt (ORCPT ); Wed, 29 Mar 2023 16:51:49 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8C27C44B8 for ; Wed, 29 Mar 2023 13:51:46 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.43:36106.2084148567 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.43]) by 189.cn (HERMES) with SMTP id 7614D1002EB; Thu, 30 Mar 2023 04:51:44 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-7b48884fd-tj646 with ESMTP id 361ed639fbfd4736bfa6e60fe64116e5 for l.stach@pengutronix.de; Thu, 30 Mar 2023 04:51:45 CST X-Transaction-ID: 361ed639fbfd4736bfa6e60fe64116e5 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Li Yi Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng Subject: [PATCH v3 5/6] drm/etnaviv: expand driver support for the pci devices Date: Thu, 30 Mar 2023 04:51:28 +0800 Message-Id: <20230329205129.1513734-6-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230329205129.1513734-1-15330273260@189.cn> References: <20230329205129.1513734-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=0.6 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,FROM_LOCAL_DIGITS,FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761737952345975534?= X-GMAIL-MSGID: =?utf-8?q?1761737952345975534?= From: Sui Jingfeng This patch add pci driver support to etnaviv on the top of what already have, take the gc1000 in ls7a1000 and ls2k1000 as the first instance of the generic pci device driver. There is only one gpu core for the gc1000 in ls7a1000 and ls2k1000, component framework can be avoid on such a case. Because we want to bind the drm driver service to the pci gpu driver manually at a first. step. We avoid to using component framework, because userspace lib use libpciaccess to find available GPU in the system before initialization, the virtual drm master device will not be get used without a force override. X server is one of the examples, yet, mesa loader will do the similar thing, it will try to find the pci device to use in the system by default and then get a gallium driver name from the pci device id. The idea of create a virtual master for the system with pci gpu cause unnecessary troubles. I not saying that component framework is not impossible, it is just that the solo pci device should be the master. Creating a virtual platform device is still useful, as we can bind some software service to the real GPU master to control the dpendency or loading order. This is not only for pci devices, platform gpu with single core can also choose to try the non componment 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 93dfa4b1a38b..dbca3bf7fba2 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" #include "common.xml.h" @@ -566,6 +568,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; @@ -580,10 +592,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; @@ -599,12 +610,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; @@ -626,14 +640,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); @@ -642,9 +659,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) @@ -764,10 +794,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. @@ -789,6 +823,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 From patchwork Wed Mar 29 20:51:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng <15330273260@189.cn> X-Patchwork-Id: 76819 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp693334vqo; Wed, 29 Mar 2023 14:19:51 -0700 (PDT) X-Google-Smtp-Source: AKy350aYZ1yv3OPP7opXQ2++SblOX8MA4cJP9Bm/Spm4xicpuLAzmRJSNpPTZ10V1719DPEZuj/I X-Received: by 2002:a62:29c4:0:b0:627:fc3b:4ca9 with SMTP id p187-20020a6229c4000000b00627fc3b4ca9mr3610948pfp.0.1680124791431; Wed, 29 Mar 2023 14:19:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680124791; cv=none; d=google.com; s=arc-20160816; b=x6NANq1ZvXtu82yg4x37NZqlxo6LR7tGN8FGOmcdqjPlqvNvVtBGQS/eOH9HU9MUuf wKc6yyQx6n7+G7TRtidV0BXYsW6z7d9qCoryxa3CzGz0odw9QX4WPLi929hOD7Oj1pb8 Ht0DW8pbcmplo+H/9UTBrPMqXxTlJQV4tU/83WK7S37qqkbRStQIo3Tm8CTg/fiurwMZ sKIva4WTYcbQqrPbhDHIku5Uoz1aWht4O5hGv7Sq4S7+M2SreL2ZejRjBD1I0DDahVqt tm9CyjNgrP3W1H0Vl1ABrGk59F4tQTaapVIH0dF+BGT3xgP9FMyAh+9TLukgUjDzcYU3 yVqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :hmm_source_type:hmm_attache_num:hmm_source_ip; bh=JZM4nDs8JSEg4yc3+dOoURMdMbmkdC/Q3bHd1vHH0c4=; b=qgc6wc8WRtuiYDHUW19ddd4/YOAgxNCrnC94peu1j+exf/i7DslhDpwtvz3PoPCDT5 k1zPt+A6dlp8oaff5FU5V3wrK1xpShdF4uT1IifDyz21tOm+S4h7NPrIQ/cVPUtFbbwS lF0SC+21FoExx6uCR1qJHQZ1gbFeVmVyy/cVp1Zx1WwfCKLVCNpuq9wjqNTCWb0B9T52 R6fo2HxUqsxVuBH+aZPjBWzvNXFmqi1b42El49/rB/6bUvHmOh4gBe5E15d+KHXDGs5U +tumIabSPfr2m/Ws4pVRyA9iz9pJupnzkNOx+nBzxhhb57YBEXWvRINZTXEckKD24zz7 1Gtg== 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 x184-20020a6386c1000000b005135e8bc80bsi6990996pgd.6.2023.03.29.14.19.37; Wed, 29 Mar 2023 14:19:51 -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 S229997AbjC2UwN (ORCPT + 99 others); Wed, 29 Mar 2023 16:52:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbjC2Uvs (ORCPT ); Wed, 29 Mar 2023 16:51:48 -0400 Received: from 189.cn (ptr.189.cn [183.61.185.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BCCD4469E for ; Wed, 29 Mar 2023 13:51:46 -0700 (PDT) HMM_SOURCE_IP: 10.64.8.43:36106.2084148567 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-114.242.206.180 (unknown [10.64.8.43]) by 189.cn (HERMES) with SMTP id 29AA2100304; Thu, 30 Mar 2023 04:51:45 +0800 (CST) Received: from ([114.242.206.180]) by gateway-151646-dep-7b48884fd-tj646 with ESMTP id 1f901d09156e45989b64af738c892223 for l.stach@pengutronix.de; Thu, 30 Mar 2023 04:51:46 CST X-Transaction-ID: 1f901d09156e45989b64af738c892223 X-Real-From: 15330273260@189.cn X-Receive-IP: 114.242.206.180 X-MEDUSA-Status: 0 Sender: 15330273260@189.cn From: Sui Jingfeng <15330273260@189.cn> To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Li Yi Cc: linux-kernel@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Sui Jingfeng Subject: [PATCH v3 6/6] drm/etnaviv: allow usperspace create cached coherent bo Date: Thu, 30 Mar 2023 04:51:29 +0800 Message-Id: <20230329205129.1513734-7-15330273260@189.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230329205129.1513734-1-15330273260@189.cn> References: <20230329205129.1513734-1-15330273260@189.cn> MIME-Version: 1.0 X-Spam-Status: No, score=0.6 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,FROM_LOCAL_DIGITS,FROM_LOCAL_HEX,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761738533664214310?= X-GMAIL-MSGID: =?utf-8?q?1761738533664214310?= From: Sui Jingfeng As Lucas pointed, there should have some way to let mesa query the kernel about the host platform whether support cached coherent mode or not. This should touch the ioctl stuff I think, bad design may lead new mesa or libdrm crash old kernel. It need more instruction how to implement this, maybe another patch to do this. Making this driver works on loongson platform is far enough for me. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 22 +++++++++++++++++++-- drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 9 ++++++++- include/uapi/drm/etnaviv_drm.h | 11 ++++++----- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index dbca3bf7fba2..91aeedb837e9 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -276,7 +276,7 @@ static int etnaviv_ioctl_gem_new(struct drm_device *dev, void *data, struct drm_etnaviv_gem_new *args = data; if (args->flags & ~(ETNA_BO_CACHED | ETNA_BO_WC | ETNA_BO_UNCACHED | - ETNA_BO_FORCE_MMU)) + ETNA_BO_CACHED_COHERENT | ETNA_BO_FORCE_MMU)) return -EINVAL; return etnaviv_gem_new_handle(dev, file, args->size, diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c index b5f73502e3dd..d8b559bd33d3 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c @@ -343,6 +343,7 @@ void *etnaviv_gem_vmap(struct drm_gem_object *obj) static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) { struct page **pages; + pgprot_t prot; lockdep_assert_held(&obj->lock); @@ -350,8 +351,20 @@ static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) if (IS_ERR(pages)) return NULL; - return vmap(pages, obj->base.size >> PAGE_SHIFT, - VM_MAP, pgprot_writecombine(PAGE_KERNEL)); + switch (obj->flags) { + case ETNA_BO_CACHED_COHERENT: + case ETNA_BO_CACHED: + prot = PAGE_KERNEL; + break; + case ETNA_BO_UNCACHED: + prot = pgprot_noncached(PAGE_KERNEL); + break; + case ETNA_BO_WC: + default: + prot = pgprot_writecombine(PAGE_KERNEL); + } + + return vmap(pages, obj->base.size >> PAGE_SHIFT, VM_MAP, prot); } static inline enum dma_data_direction etnaviv_op_to_dma_dir(u32 op) @@ -545,6 +558,7 @@ static const struct drm_gem_object_funcs etnaviv_gem_object_funcs = { static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, const struct etnaviv_gem_ops *ops, struct drm_gem_object **obj) { + struct etnaviv_drm_private *priv = dev->dev_private; struct etnaviv_gem_object *etnaviv_obj; unsigned sz = sizeof(*etnaviv_obj); bool valid = true; @@ -555,6 +569,10 @@ static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags, case ETNA_BO_CACHED: case ETNA_BO_WC: break; + case ETNA_BO_CACHED_COHERENT: + if (priv->has_cached_coherent) + break; + fallthrough; default: valid = false; } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c index 7031db145a77..9364874918e3 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c @@ -104,11 +104,18 @@ static const struct etnaviv_gem_ops etnaviv_gem_prime_ops = { struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sgt) { + struct etnaviv_drm_private *priv = dev->dev_private; struct etnaviv_gem_object *etnaviv_obj; size_t size = PAGE_ALIGN(attach->dmabuf->size); + u32 cache_flags; int ret, npages; - ret = etnaviv_gem_new_private(dev, size, ETNA_BO_WC, + if (priv->has_cached_coherent) + cache_flags = ETNA_BO_CACHED_COHERENT; + else + cache_flags = ETNA_BO_WC; + + ret = etnaviv_gem_new_private(dev, size, cache_flags, &etnaviv_gem_prime_ops, &etnaviv_obj); if (ret < 0) return ERR_PTR(ret); diff --git a/include/uapi/drm/etnaviv_drm.h b/include/uapi/drm/etnaviv_drm.h index af024d90453d..474b0db286de 100644 --- a/include/uapi/drm/etnaviv_drm.h +++ b/include/uapi/drm/etnaviv_drm.h @@ -90,13 +90,14 @@ struct drm_etnaviv_param { * GEM buffers: */ -#define ETNA_BO_CACHE_MASK 0x000f0000 +#define ETNA_BO_CACHE_MASK 0x000f0000 /* cache modes */ -#define ETNA_BO_CACHED 0x00010000 -#define ETNA_BO_WC 0x00020000 -#define ETNA_BO_UNCACHED 0x00040000 +#define ETNA_BO_CACHED 0x00010000 +#define ETNA_BO_WC 0x00020000 +#define ETNA_BO_UNCACHED 0x00040000 +#define ETNA_BO_CACHED_COHERENT 0x00080000 /* map flags */ -#define ETNA_BO_FORCE_MMU 0x00100000 +#define ETNA_BO_FORCE_MMU 0x00100000 struct drm_etnaviv_gem_new { __u64 size; /* in */