Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1254838rdb; Mon, 2 Oct 2023 04:20:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZc51TtyOKiMQjTCb77t4ax12nVNcmpYnLkDaLtIJtAE7R5J06AI3fe0Xch3SuCMYG7fzt X-Received: by 2002:a05:6a00:8c7:b0:693:3cac:7897 with SMTP id s7-20020a056a0008c700b006933cac7897mr10922989pfu.9.1696245632830; Mon, 02 Oct 2023 04:20:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696245632; cv=none; d=google.com; s=arc-20160816; b=xhcvekCU4pP5fHAOd8LstJljhVn85wLP2JDghUtc7i98+r/e252Abs0BvuqzjwmNkE LTZAot/hztJDoaYnWbHP1I16yH30MCFgdNqh7FD31Gc3zU6RZUAMKqmu7D4F2jJNUfT7 9FzTTn3oVr9vcHlUtgtCxqacSLNesCAsToVnK2l1DLac1RJbL7vuEpDX6Jnh+Pg0J3xt Wam2datN4YKvW1qt0bAReStYOfY0CEEvXi2oHZj0/Gmm39dZfwps50vuln6orBZLi5wu Y/wPVD5oHdxruTW3ci0wMm+WnXNaumy3O/wcMpzEdgjhKJKgO4scLkewsLlWx4YoCu+Y p3Fw== 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=TbU2rzWQsKUaIW8aws46fyBWYdZA9hZzDer1cc5MXzg=; fh=zB/Le29j84eF2EWMM5mMCmgRJzHNI4kLocpkF47EhQo=; b=EVNrrLzd/sINNzK93KHI1vDbA7YQ7xcSH+IcqEwH0JXSN/Hjwuj2w+DZgm4NHX2HfO uMuLR3LWz2EDfQdmpBi20nLt1CX9KcWI03uVqYws1ed1sFnwA3UHEkEMmfrTCl9vxRD9 q3rn+NU60g1eiKyuB8cncKDT2o7mOgtdqSp5w0jYJvt2EBN9jFgRfPhxmlYwoMYBqvc4 0DsyN1K012uqTe9eCMiBqhnP2RaYfrsbCbo1LQtnXGF4b3pnJRvsqKkgyxkQT+bND824 5AAsZLW80gX0BIwYsjZmsk2EPkYdYwV2ov7u8q1RZEnd8KfGgE5kSudOiiZ/sKeYTFL6 bBqA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id z35-20020a056a001da300b00690f9e835d8si25943214pfw.132.2023.10.02.04.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 04:20:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id B12B4805A5CD; Mon, 2 Oct 2023 04:12:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236654AbjJBLMU (ORCPT + 99 others); Mon, 2 Oct 2023 07:12:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236633AbjJBLMN (ORCPT ); Mon, 2 Oct 2023 07:12:13 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3C081E8 for ; Mon, 2 Oct 2023 04:12:10 -0700 (PDT) Received: from loongson.cn (unknown [10.20.42.43]) by gateway (Coremail) with SMTP id _____8Dx_+uIpRplL5IuAA--.22517S3; Mon, 02 Oct 2023 19:12:08 +0800 (CST) Received: from openarena.loongson.cn (unknown [10.20.42.43]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxE+SHpRplEh4XAA--.50320S6; Mon, 02 Oct 2023 19:12:08 +0800 (CST) From: Sui Jingfeng To: Lucas Stach Cc: Christian Gmeiner , etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/5] drm/etnaviv: Add a helper to get the first available GPU device node Date: Mon, 2 Oct 2023 19:12:06 +0800 Message-Id: <20231002111207.513297-5-suijingfeng@loongson.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231002111207.513297-1-suijingfeng@loongson.cn> References: <20231002111207.513297-1-suijingfeng@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8BxE+SHpRplEh4XAA--.50320S6 X-CM-SenderInfo: xvxlyxpqjiv03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj93XoW7Zr4DGFyrWryfJF4UZryfZrc_yoW8KF1fpF 43GFyYyrykWFyUK34xXFW5ZFyYkw1Iq3yFy34IkwnY9ws5AryrJr1FgFyUAF9xJFWrJ3W3 tr18tr17uF48ZrXCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1a6r1DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4j6r4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI0UMc 02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWrXwAv7VC2z280aVAF wI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7V AKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCj r7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6x IIjxv20xvE14v26r4j6ryUMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x 0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IUbCzuJUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 02 Oct 2023 04:12:32 -0700 (PDT) This patch make the code in the etnaviv_pdev_probe() less twisted, and it also make it easier to drop the reference to device node after finished. Before apply this patch, there is no call to of_node_put() when done. We should call of_node_put() when done. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 28 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 8fe39e31d22d..a9a1659840ec 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -29,6 +29,17 @@ * DRM operations: */ +static struct device_node *etnaviv_of_first_available_node(void) +{ + struct device_node *np; + + for_each_compatible_node(np, NULL, "vivante,gc") { + if (of_device_is_available(np)) + return np; + } + + return NULL; +} static void load_gpu(struct drm_device *dev) { @@ -597,11 +608,10 @@ static int etnaviv_pdev_probe(struct platform_device *pdev) if (!of_device_is_available(core_node)) continue; - if (!first_node) - first_node = core_node; - drm_of_component_match_add(&pdev->dev, &match, component_compare_of, core_node); + + of_node_put(core_node); } } else { char **names = dev->platform_data; @@ -634,8 +644,11 @@ static int etnaviv_pdev_probe(struct platform_device *pdev) * device as the GPU we found. This assumes that all Vivante * GPUs in the system share the same DMA constraints. */ - if (first_node) + first_node = etnaviv_of_first_available_node(); + if (first_node) { of_dma_configure(&pdev->dev, first_node, true); + of_node_put(first_node); + } return component_master_add_with_match(dev, &etnaviv_master_ops, match); } @@ -709,16 +722,13 @@ static int __init etnaviv_init(void) * If the DT contains at least one available GPU device, instantiate * the DRM platform device. */ - for_each_compatible_node(np, NULL, "vivante,gc") { - if (!of_device_is_available(np)) - continue; + np = etnaviv_of_first_available_node(); + if (np) { of_node_put(np); ret = etnaviv_create_platform_device("etnaviv", &etnaviv_drm); if (ret) goto unregister_platform_driver; - - break; } return 0; -- 2.34.1