From patchwork Thu Dec 14 10:31:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 178634 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8445551dys; Thu, 14 Dec 2023 02:32:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeJYtAdLx0lRWerjm9LHZp21mLCtRRE/rah7okZgQLe/OH5LJeZ1K8xGjDawccoLwGOD9Q X-Received: by 2002:a05:6a20:748f:b0:18f:ce60:ceeb with SMTP id p15-20020a056a20748f00b0018fce60ceebmr11829742pzd.23.1702549945628; Thu, 14 Dec 2023 02:32:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702549945; cv=none; d=google.com; s=arc-20160816; b=e0XlUQBUWZ+ror3+9bGIgY96NynzSm0ZP7SVb2w2h/tSdyFkTwA6AGdj7oO62DrRUH yPW7WI/QnSkOw2nqO2MXhyiRQL29Doa140VDLnCGfgOfJWbqpdpbOp2WZQhHlgYoEWvA LOt6eVHoB7j5FAXxj8AJ3v0jRPuXa6HmzvO5JrDqdKEsCHIEV3fXprKdzdHgvQo7l8Fd tRTe2KRpj736zKSXbHV55o+Zr2CKjTheoGd5hM2NcEutQHu5Vd8gKStcOJ08y5HZ/Gy9 3yCEAxg1tJ+FLAZ69X3DHG/UQKWPL4NK31O0vfVaLz0Xb54FD/T3DUCCU8U+v90tcsd8 F8eQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=GGeeLl7/lvdKSOj2aFz5JQVMA3Kqw3o0H/s73FfePTY=; fh=6z+ElFTra147heHAzZZJ57t98ehK0pbxyWNV5p0IBGo=; b=n0+/GoFOQcrKA7Y9YtPnowAAmFIpv7mi/LqxgBDJtYPOHIHWg89fefzodcO11EIdAH kFqBwzH+mCmThORS3GW3OLrLyPt+Xbh8G/bIvqIZyzm16gcJF4UGY0v/z+muvLygr/HW pN9LnyhDhj+vIUzA5iFe8DO+vWl4RuNTeiDAKPhfziWA667T42FpQ9dOGhAQeVLnl7ws gkwdfTUiwuPRZuIQtnIWkFAvMnAp4vfAdR5Z5G1YqcBacFn0lWKv/jzwexQ7PWijlLuQ 93lOkimXR7Gsv/v8u6gMAGpzV0PPugD6HPMkX+KnnPtDjWh1B+wGj3qZYdBgvNtXprw+ 7sDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=B2pWi838; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id e8-20020a056a001a8800b006c8d6276344si11305681pfv.339.2023.12.14.02.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 02:32:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=B2pWi838; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 1D3868313D24; Thu, 14 Dec 2023 02:32:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443661AbjLNKcJ (ORCPT + 99 others); Thu, 14 Dec 2023 05:32:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443647AbjLNKcF (ORCPT ); Thu, 14 Dec 2023 05:32:05 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81ECE126 for ; Thu, 14 Dec 2023 02:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1702549925; bh=GGeeLl7/lvdKSOj2aFz5JQVMA3Kqw3o0H/s73FfePTY=; h=From:To:Cc:Subject:Date:From; b=B2pWi838wrtLIVhJS7mPEbgCabqUp6TppXiowwvt8mhy+oj0T9gHzIG8OxETfWNsY ssDE9o9sOnCrm//48vnGkWynayIk3Fc0lokMXIDTDKMn3V2zLB9+rWR9zRu2cO/WKq gqkTrzeDlekFCW5/FWmkIoleruWQuLZYTGaRhilQSrwn5Rx2pM7kuLfR7kaSH+J9N+ FJdCpBQfTOAIZFfneFDSttaPapgCSDNKx3vn4QmU4KTTyT6C/sRRzHDGKB/lJ/Sc8a Rrtxl2L0LHrr30/7UVDb91ps9rsJTJ9kEfLzadwevJ6mf2Yr5Xwwr+aJoHXzl5sTI8 d9cQdLGmht2lw== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4SrTDj5X98z4xPL; Thu, 14 Dec 2023 21:32:05 +1100 (AEDT) From: Michael Ellerman To: Cc: , , Subject: [PATCH v2 1/5] of: Add of_machine_compatible_match() Date: Thu, 14 Dec 2023 21:31:48 +1100 Message-ID: <20231214103152.12269-1-mpe@ellerman.id.au> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Thu, 14 Dec 2023 02:32:22 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785253011613242437 X-GMAIL-MSGID: 1785253011613242437 We have of_machine_is_compatible() to check if a machine is compatible with a single compatible string. However some code is able to support multiple compatible boards, and so wants to check for one of many compatible strings. So add of_machine_compatible_match() which takes a NULL terminated array of compatible strings to check against the root node's compatible property. Compared to an open coded match this is slightly more self documenting, and also avoids the caller needing to juggle the root node either directly or via of_find_node_by_path(). Signed-off-by: Christophe Leroy Reviewed-by: Rob Herring Signed-off-by: Michael Ellerman --- drivers/of/base.c | 21 +++++++++++++++++++++ include/linux/of.h | 6 ++++++ 2 files changed, 27 insertions(+) v2: Unchanged. diff --git a/drivers/of/base.c b/drivers/of/base.c index 8d93cb6ea9cd..9020be2eb4d5 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -394,6 +394,27 @@ int of_device_compatible_match(const struct device_node *device, } EXPORT_SYMBOL_GPL(of_device_compatible_match); +/** + * of_machine_compatible_match - Test root of device tree against a compatible array + * @compats: NULL terminated array of compatible strings to look for in root node's compatible property. + * + * Returns true if the root node has any of the given compatible values in its + * compatible property. + */ +bool of_machine_compatible_match(const char *const *compats) +{ + struct device_node *root; + int rc = 0; + + root = of_find_node_by_path("/"); + if (root) { + rc = of_device_compatible_match(root, compats); + of_node_put(root); + } + + return rc != 0; +} + /** * of_machine_is_compatible - Test root of device tree for a given compatible value * @compat: compatible string to look for in root node's compatible property. diff --git a/include/linux/of.h b/include/linux/of.h index 6a9ddf20e79a..e3418babc203 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -403,6 +403,7 @@ extern int of_alias_get_id(struct device_node *np, const char *stem); extern int of_alias_get_highest_id(const char *stem); extern int of_machine_is_compatible(const char *compat); +bool of_machine_compatible_match(const char *const *compats); extern int of_add_property(struct device_node *np, struct property *prop); extern int of_remove_property(struct device_node *np, struct property *prop); @@ -808,6 +809,11 @@ static inline int of_remove_property(struct device_node *np, struct property *pr return 0; } +static inline bool of_machine_compatible_match(const char *const *compats) +{ + return false; +} + static inline bool of_console_check(const struct device_node *dn, const char *name, int index) { return false; From patchwork Thu Dec 14 10:31:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 178632 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8445490dys; Thu, 14 Dec 2023 02:32:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpEuYK3t5qDwGwNpd97dq9rpKVOViHF7irvEdUC79X63PXG7h9i1BaDDcVVQNZ3lmTKKcw X-Received: by 2002:a9d:7758:0:b0:6d9:dd14:3a75 with SMTP id t24-20020a9d7758000000b006d9dd143a75mr9387075otl.70.1702549938962; Thu, 14 Dec 2023 02:32:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702549938; cv=none; d=google.com; s=arc-20160816; b=mQyKribYSXGjZQtutyGsqMcmuyUrWa2rNVUPuV9QF6c2LtgmlpcRyls4sfe6nKinYF hBsC5BtFjGxstsO0gtuRnu8kc2iY+UgIzCM+TWSW6mL1nSeGRZFjWI2nAT76OwbK3maR CAJIK+Vk4VepB8Z+mpr/ZjMZVYJIN7JtfwceDqS6TiODgYxau0o90bov/fUWyubNtWXj adSuZqB6XM4Pwc4CH3xNy7Nxl5kCjBS9t784jTRS/HPz012+ogVHt90GRt/kgUb8HqYM eFeQ8mGpZSTsBBpwdIE1t+WZWm+s5kqhqTf8O5LgJmihSRb7eqI7GPAB0L9SFzRAtrmW wegA== 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 :dkim-signature; bh=RoCUu1mXewEDtm43Qq0pBWgiYLguorwyr3zE9+lEq2w=; fh=6z+ElFTra147heHAzZZJ57t98ehK0pbxyWNV5p0IBGo=; b=p/yg+1PnXOLMkCwyACy5KZsg8JwrW4f/vxsN6VqepqAI+1hZk3CiXXRSMmdyLmHDlz 9I/cd8OQjfQ8YNItZdtfOCtCdLtMRvYPD56EDDuoKwdp2tjwCtsl3rjp+lkzfdWdMEDO 8LzV9xg3hOXFySX2jkSzCBeTnvgZZeAsD+UeL183i9DRmn9uuqgHvUQTU+UDl863bS+j GT0pEvRCIxYXccNtoF+UV7s+93Jufx+0fol5oVGL6Ssu8d3tczx7CJaFFlQ4eBV52Ejz rBVZBJhpcUjLFe6DDIn0seuIEuSKyOmrt6Tg8d5+TYScftLbg2Ybtg9zlg/EsFCsXWBM hYaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=TCEU2AUr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id 17-20020a631651000000b005c668a5a90esi10586746pgw.596.2023.12.14.02.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 02:32:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=TCEU2AUr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 3C3038313D24; Thu, 14 Dec 2023 02:32:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443652AbjLNKcF (ORCPT + 99 others); Thu, 14 Dec 2023 05:32:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443630AbjLNKcE (ORCPT ); Thu, 14 Dec 2023 05:32:04 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8138A11A for ; Thu, 14 Dec 2023 02:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1702549926; bh=RoCUu1mXewEDtm43Qq0pBWgiYLguorwyr3zE9+lEq2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TCEU2AUr0ZA04uTWvKS/i3ZVnJa0VyDib+4PiyGCQg7iYXZ0YGOJGDur97P5pyzAJ ZDtG+cH7Qm4T+X/9B8J01Tj1odsNEBX7Zv7jVYv2UGg/igHIajr64YmluEtiDAktbJ FYNzi99K+px1npcA6NnqaXreto/JcbyQnFH3ZgWLhJhkphXGPb0d8FRzCMmA5OYoTE mi2ltw6Peioc0GwLpqNoOvumthQnpVxfsByUQS6ELu2c/csI87q8kODmX4phBHrPBG geRxOfCFC/OBotVhANnyzFeit42L1QHw+6Blf+5bqiU+1uuONyJ2OrSuNgPt6FhPFz cMuyAa7oMqijg== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4SrTDk1lzGz4xPQ; Thu, 14 Dec 2023 21:32:06 +1100 (AEDT) From: Michael Ellerman To: Cc: , , Subject: [PATCH v2 2/5] of: Change of_machine_is_compatible() to return bool Date: Thu, 14 Dec 2023 21:31:49 +1100 Message-ID: <20231214103152.12269-2-mpe@ellerman.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231214103152.12269-1-mpe@ellerman.id.au> References: <20231214103152.12269-1-mpe@ellerman.id.au> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Thu, 14 Dec 2023 02:32:14 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785253004596408167 X-GMAIL-MSGID: 1785253004596408167 of_machine_is_compatible() currently returns a positive integer if it finds a match. However none of the callers ever check the value, they all treat it as a true/false. So change of_machine_is_compatible() to return bool, which will allow the implementation to be changed in a subsequent patch. Suggested-by: Rob Herring Signed-off-by: Michael Ellerman --- drivers/of/base.c | 5 ++--- include/linux/of.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) v2: New. diff --git a/drivers/of/base.c b/drivers/of/base.c index 9020be2eb4d5..c82c8b77badc 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -419,10 +419,9 @@ bool of_machine_compatible_match(const char *const *compats) * of_machine_is_compatible - Test root of device tree for a given compatible value * @compat: compatible string to look for in root node's compatible property. * - * Return: A positive integer if the root node has the given value in its - * compatible property. + * Return: true if the root node has the given value in its compatible property. */ -int of_machine_is_compatible(const char *compat) +bool of_machine_is_compatible(const char *compat) { struct device_node *root; int rc = 0; diff --git a/include/linux/of.h b/include/linux/of.h index e3418babc203..c5c663a7fb77 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -402,7 +402,7 @@ extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); extern int of_alias_get_id(struct device_node *np, const char *stem); extern int of_alias_get_highest_id(const char *stem); -extern int of_machine_is_compatible(const char *compat); +extern bool of_machine_is_compatible(const char *compat); bool of_machine_compatible_match(const char *const *compats); extern int of_add_property(struct device_node *np, struct property *prop); From patchwork Thu Dec 14 10:31:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 178633 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8445530dys; Thu, 14 Dec 2023 02:32:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7fM32d9Nxow1iMtTm8PvFrgkOUsWoQwTjlJWcqJ6HG+7k2BV1vjcLFn738bSBCLVBDXY9 X-Received: by 2002:a05:6808:3207:b0:3b2:eab1:918 with SMTP id cb7-20020a056808320700b003b2eab10918mr10393656oib.29.1702549943918; Thu, 14 Dec 2023 02:32:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702549943; cv=none; d=google.com; s=arc-20160816; b=s2DfHSYutfS6q/2ypZAbRp3+A0NNJYHcOn19Xjzr3bfZ83qb+E4jj2aYkjXiCi3yZo bLB/fDwKZl9Ui1THD6VFcpCdlkIZRDZW4kSXu6ZJpt5gqGKeTgJ9+nk867mBD1pwZu6j M4HTKcBJmLvAzPweEIvN3RohgosHEqn9jrxG2qeJEeVB99LI5Pv8ro4loNlFiNA0kgX6 +IKwgdKd3locN8VUGrMILVxRrw+3UqSLiuUImSPO2Eez0gzmCKzuzNCZubVdwdQ1yIBd ZogEdAVlGWzOmp8gpuDJ+ux96uvQQBt2Agq+UQkFL6KTeJ+te4YtFtrcq6qz+ZFr8/Qt r0bg== 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 :dkim-signature; bh=O/o9QbjKiENBQBWvJbXtJwhr2ssAm9bGM38u9QD4iZ0=; fh=6z+ElFTra147heHAzZZJ57t98ehK0pbxyWNV5p0IBGo=; b=Vz+oW6P1adsuU/2k+lYPWbhf0cCgM4+Mo0NaOs12rooSmdIsQHWS/rgGocSjaRY1R/ tZkry3QGKgS8hgU0XrkSDz7HIEEkbZvvvDRrCDUyiSYpxM1bjFIJQ5GE/L4i0mABmM9l OVD9fqZRC0ylIYtapA5CYtQHCbGf0XppoovORWMy6R75aNlE6NigH6GaDgWWaETqg2hX qnz8aIixU3wKYYimEv5GIPg1YhcEVZXLXke09umnlz2g146TKSEB/kd0xzwbolL5I4Ax hKvvpBnFTzo3fGi8FYF1PrvTWM6Ur+OqSUQA+IlMVyNKakdqQqjX4L7WoG9Kre73iY/U b0Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b="O/6bDQV2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id q12-20020a056a00088c00b006cddc343ceesi11283990pfj.181.2023.12.14.02.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 02:32:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b="O/6bDQV2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 2CE168026AC0; Thu, 14 Dec 2023 02:32:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443640AbjLNKcH (ORCPT + 99 others); Thu, 14 Dec 2023 05:32:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443649AbjLNKcF (ORCPT ); Thu, 14 Dec 2023 05:32:05 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6C11118 for ; Thu, 14 Dec 2023 02:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1702549926; bh=O/o9QbjKiENBQBWvJbXtJwhr2ssAm9bGM38u9QD4iZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O/6bDQV2iPr1GiUNCyIXnzRtSQNhDbG3/OGhfzVpYJSmwu9Gt7Fl5ZhHhScJU0OiB iSaHVPVIpvHig+sjQZkfmpi1tyTBsCWtmXiJUel68hCraxyYL/vF9JYomdHKPMB5BQ culcMruEy52Pxsd+RzfqVS3v44hc6NVfsrPSuK97RJwTt8sz0t6VuDeUyFGwd53xAJ LKRLjjsK8PJUBhgNXMH0eWLqmHNC8D2jNGx5NwQqIsEkWSJhuspMzQKPWvG25DFyAh 6wbTzOuJV5jIV7z6BBR98S1BPaOIpfaXyOoWRnHoC6eGAhJm6Oos0+w37BXnH27GOE FpW5QjuSt2r3g== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4SrTDk4sV7z4xPY; Thu, 14 Dec 2023 21:32:06 +1100 (AEDT) From: Michael Ellerman To: Cc: , , Subject: [PATCH v2 3/5] of: Reimplement of_machine_is_compatible() using of_machine_compatible_match() Date: Thu, 14 Dec 2023 21:31:50 +1100 Message-ID: <20231214103152.12269-3-mpe@ellerman.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231214103152.12269-1-mpe@ellerman.id.au> References: <20231214103152.12269-1-mpe@ellerman.id.au> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Thu, 14 Dec 2023 02:32:19 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785253010004437114 X-GMAIL-MSGID: 1785253010004437114 From: Christophe Leroy of_machine_compatible_match() works with a table of strings. of_machine_is_compatible() is a simplier version with only one string. Re-implement of_machine_is_compatible() by setting a table of strings with a single string then using of_machine_compatible_match(). Suggested-by: Rob Herring Signed-off-by: Christophe Leroy Reviewed-by: Rob Herring Signed-off-by: Michael Ellerman --- drivers/of/base.c | 21 +-------------------- include/linux/of.h | 14 +++++++++++++- 2 files changed, 14 insertions(+), 21 deletions(-) v2: Unchanged. diff --git a/drivers/of/base.c b/drivers/of/base.c index c82c8b77badc..73c3a754bad1 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -414,26 +414,7 @@ bool of_machine_compatible_match(const char *const *compats) return rc != 0; } - -/** - * of_machine_is_compatible - Test root of device tree for a given compatible value - * @compat: compatible string to look for in root node's compatible property. - * - * Return: true if the root node has the given value in its compatible property. - */ -bool of_machine_is_compatible(const char *compat) -{ - struct device_node *root; - int rc = 0; - - root = of_find_node_by_path("/"); - if (root) { - rc = of_device_is_compatible(root, compat); - of_node_put(root); - } - return rc; -} -EXPORT_SYMBOL(of_machine_is_compatible); +EXPORT_SYMBOL(of_machine_compatible_match); /** * __of_device_is_available - check if a device is available for use diff --git a/include/linux/of.h b/include/linux/of.h index c5c663a7fb77..03ed4e37ca57 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -402,9 +402,21 @@ extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); extern int of_alias_get_id(struct device_node *np, const char *stem); extern int of_alias_get_highest_id(const char *stem); -extern bool of_machine_is_compatible(const char *compat); bool of_machine_compatible_match(const char *const *compats); +/** + * of_machine_is_compatible - Test root of device tree for a given compatible value + * @compat: compatible string to look for in root node's compatible property. + * + * Return: true if the root node has the given value in its compatible property. + */ +static inline bool of_machine_is_compatible(const char *compat) +{ + const char *compats[] = { compat, NULL }; + + return of_machine_compatible_match(compats); +} + extern int of_add_property(struct device_node *np, struct property *prop); extern int of_remove_property(struct device_node *np, struct property *prop); extern int of_update_property(struct device_node *np, struct property *newprop); From patchwork Thu Dec 14 10:31:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 178635 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8445570dys; Thu, 14 Dec 2023 02:32:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmRdPdbQAQ4PlRn4x1/LSb5PWZB5B34ASiaPY1hOQ5pKWY3ZyT7Q1njGdXUTWrzfVUvU5A X-Received: by 2002:a05:6359:6b84:b0:170:406b:7ba9 with SMTP id ta4-20020a0563596b8400b00170406b7ba9mr8270468rwb.18.1702549948692; Thu, 14 Dec 2023 02:32:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702549948; cv=none; d=google.com; s=arc-20160816; b=F2SK1VqCjUjli4jeYiwgE2CQTZL67Uh49wnPwiqbxAwcMb/xBExzzXf5uQFEQkld2g 0VwgTPgtCms/4btntou61qbRFYZD2GoCxzZj+cQXCSLJcNv/RFzv1InLnxoG3dzHEeL7 QwzAOcq20bMUX8jH+4wJa+MvvxZngC4EcEQDTAHj7nXmI7wvZ7HfPmZ++rMBR4ivefSJ lDp0J2lfg+HMdQmHttuXjih/3AS0HWMmY8M6YoKv0/9rCIoJs8QX5JqgXwGNx+C2p8Ds KzPoHEoL4X1w/X8D0m+rTq4eazWMRAb+3EOn3i6zJv7SSo3R2o1CEgfh8ihtVjojcTQB +GUw== 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 :dkim-signature; bh=NlF0fP+4ZhmPGamGwDlLFY8ZIOwzXJyGh1FdhfSJsUQ=; fh=6z+ElFTra147heHAzZZJ57t98ehK0pbxyWNV5p0IBGo=; b=No6ruHe5SOG6JE57OyKqkNdH3EPyzlOT0KQ/KLumByb79LtnmlXS9u9i0jp5jChgwu DJ9jM32V9LuHqPcTDv+qiMThxjgI83zRz1ssEbuPApRzfZiPElHpTm0chFnlTSmDUkkR OAZ9JS2ldtCbnuKoY/IRy41FtevPPCyI3sUxssgjtAE2rz+s1q0P4HbleGcZJMeQ37ib IDt3FsE8eR1J54ABbJ+BMc0/lTNzLUQAeCezpDQhrxkh5qucZkGY3J8+obbZtRYMSghh PnDHSZSEb3GWZVzXxjgRCI6QLpGiwVOT7NyOno6ERhc5IdF6hN0lX3xJscctxmCUBFS1 i/cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=E25BrxdS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id q3-20020a17090a68c300b0028b0d0c8b2esi621657pjj.14.2023.12.14.02.32.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 02:32:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=E25BrxdS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id E812281FD280; Thu, 14 Dec 2023 02:32:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443677AbjLNKcN (ORCPT + 99 others); Thu, 14 Dec 2023 05:32:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443641AbjLNKcG (ORCPT ); Thu, 14 Dec 2023 05:32:06 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81D7D124 for ; Thu, 14 Dec 2023 02:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1702549927; bh=NlF0fP+4ZhmPGamGwDlLFY8ZIOwzXJyGh1FdhfSJsUQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E25BrxdSpDZr+Z9D3h9QALguzNoK1GKyYdWl1YP6Sh99o7o6B08mVXkZsR2c79na2 UU45cYaT4MD7nZJuaSIhQHE2iCsI+Fz7lyFdboKvSZFomdVTjEDF3B/p6tAicJhbdV MoBKv+5rWvbtmkadldUSbS9/+JXmHtIabcdsDZT97J1HdlTwU3FlKU77dI0YGBbm0+ OtU0cKt3Pin1A+250VzgaI+g6Jri26HBYFOEJPgCnr5BW6PEIhP8E1t5fbBtKnVnCO YPuEmVfH7XXoxn5YC95EZjAk7DlKBRxern4YaadcL6w6RQYgRS+/6Gr9lYxDg5Ov+/ b6g5wH/m0ZG7A== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4SrTDl199yz4xQj; Thu, 14 Dec 2023 21:32:07 +1100 (AEDT) From: Michael Ellerman To: Cc: , , Subject: [PATCH v2 4/5] powerpc/machdep: Define 'compatibles' property in ppc_md and use it Date: Thu, 14 Dec 2023 21:31:51 +1100 Message-ID: <20231214103152.12269-4-mpe@ellerman.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231214103152.12269-1-mpe@ellerman.id.au> References: <20231214103152.12269-1-mpe@ellerman.id.au> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 pete.vger.email 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 (pete.vger.email [0.0.0.0]); Thu, 14 Dec 2023 02:32:23 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785253015099777952 X-GMAIL-MSGID: 1785253015099777952 From: Christophe Leroy Most probe functions that do not use the 'compatible' string do nothing else than checking whether the machine is compatible with one of the strings in a NULL terminated table of strings. Define that table of strings in ppc_md structure and check it directly from probe_machine() instead of using ppc_md.probe() for that. Keep checking in ppc_md.probe() only for more complex probing. All .compatible could be replaced with a single element NULL terminated list but that's not worth the churn. Can be do incrementaly in follow-up patches. Signed-off-by: Christophe Leroy Reviewed-by: Rob Herring Signed-off-by: Michael Ellerman --- arch/powerpc/include/asm/machdep.h | 1 + arch/powerpc/kernel/setup-common.c | 2 ++ arch/powerpc/platforms/40x/ppc40x_simple.c | 9 +++------ arch/powerpc/platforms/512x/mpc512x_generic.c | 4 +--- arch/powerpc/platforms/52xx/lite5200.c | 10 +--------- arch/powerpc/platforms/52xx/mpc5200_simple.c | 10 +--------- arch/powerpc/platforms/83xx/mpc830x_rdb.c | 10 +--------- arch/powerpc/platforms/83xx/mpc831x_rdb.c | 10 +--------- arch/powerpc/platforms/83xx/mpc837x_rdb.c | 10 +--------- arch/powerpc/platforms/85xx/corenet_generic.c | 2 +- arch/powerpc/platforms/85xx/tqm85xx.c | 10 +--------- 11 files changed, 14 insertions(+), 64 deletions(-) v2: Unchanged. diff --git a/arch/powerpc/include/asm/machdep.h b/arch/powerpc/include/asm/machdep.h index d31a5ec1550d..1862f94335ee 100644 --- a/arch/powerpc/include/asm/machdep.h +++ b/arch/powerpc/include/asm/machdep.h @@ -22,6 +22,7 @@ struct pci_host_bridge; struct machdep_calls { const char *name; const char *compatible; + const char * const *compatibles; #ifdef CONFIG_PPC64 #ifdef CONFIG_PM void (*iommu_restore)(void); diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c index 9b142b9d5187..ec02f9d8f55d 100644 --- a/arch/powerpc/kernel/setup-common.c +++ b/arch/powerpc/kernel/setup-common.c @@ -616,6 +616,8 @@ static __init void probe_machine(void) DBG(" %s ...\n", machine_id->name); if (machine_id->compatible && !of_machine_is_compatible(machine_id->compatible)) continue; + if (machine_id->compatibles && !of_machine_compatible_match(machine_id->compatibles)) + continue; memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls)); if (ppc_md.probe && !ppc_md.probe()) continue; diff --git a/arch/powerpc/platforms/40x/ppc40x_simple.c b/arch/powerpc/platforms/40x/ppc40x_simple.c index e454e9d2eff1..294ab2728588 100644 --- a/arch/powerpc/platforms/40x/ppc40x_simple.c +++ b/arch/powerpc/platforms/40x/ppc40x_simple.c @@ -59,16 +59,13 @@ static const char * const board[] __initconst = { static int __init ppc40x_probe(void) { - if (of_device_compatible_match(of_root, board)) { - pci_set_flags(PCI_REASSIGN_ALL_RSRC); - return 1; - } - - return 0; + pci_set_flags(PCI_REASSIGN_ALL_RSRC); + return 1; } define_machine(ppc40x_simple) { .name = "PowerPC 40x Platform", + .compatibles = board, .probe = ppc40x_probe, .progress = udbg_progress, .init_IRQ = uic_init_tree, diff --git a/arch/powerpc/platforms/512x/mpc512x_generic.c b/arch/powerpc/platforms/512x/mpc512x_generic.c index 0d58ab257cd9..d4fa6c302ccf 100644 --- a/arch/powerpc/platforms/512x/mpc512x_generic.c +++ b/arch/powerpc/platforms/512x/mpc512x_generic.c @@ -32,9 +32,6 @@ static const char * const board[] __initconst = { */ static int __init mpc512x_generic_probe(void) { - if (!of_device_compatible_match(of_root, board)) - return 0; - mpc512x_init_early(); return 1; @@ -42,6 +39,7 @@ static int __init mpc512x_generic_probe(void) define_machine(mpc512x_generic) { .name = "MPC512x generic", + .compatibles = board, .probe = mpc512x_generic_probe, .init = mpc512x_init, .setup_arch = mpc512x_setup_arch, diff --git a/arch/powerpc/platforms/52xx/lite5200.c b/arch/powerpc/platforms/52xx/lite5200.c index 0fd67b3ffc3e..0a161d82a3a8 100644 --- a/arch/powerpc/platforms/52xx/lite5200.c +++ b/arch/powerpc/platforms/52xx/lite5200.c @@ -172,17 +172,9 @@ static const char * const board[] __initconst = { NULL, }; -/* - * Called very early, MMU is off, device-tree isn't unflattened - */ -static int __init lite5200_probe(void) -{ - return of_device_compatible_match(of_root, board); -} - define_machine(lite5200) { .name = "lite5200", - .probe = lite5200_probe, + .compatibles = board, .setup_arch = lite5200_setup_arch, .discover_phbs = mpc52xx_setup_pci, .init = mpc52xx_declare_of_platform_devices, diff --git a/arch/powerpc/platforms/52xx/mpc5200_simple.c b/arch/powerpc/platforms/52xx/mpc5200_simple.c index f1e85e86f5e5..7e0e4c34a40b 100644 --- a/arch/powerpc/platforms/52xx/mpc5200_simple.c +++ b/arch/powerpc/platforms/52xx/mpc5200_simple.c @@ -59,17 +59,9 @@ static const char *board[] __initdata = { NULL }; -/* - * Called very early, MMU is off, device-tree isn't unflattened - */ -static int __init mpc5200_simple_probe(void) -{ - return of_device_compatible_match(of_root, board); -} - define_machine(mpc5200_simple_platform) { .name = "mpc5200-simple-platform", - .probe = mpc5200_simple_probe, + .compatibles = board, .setup_arch = mpc5200_simple_setup_arch, .discover_phbs = mpc52xx_setup_pci, .init = mpc52xx_declare_of_platform_devices, diff --git a/arch/powerpc/platforms/83xx/mpc830x_rdb.c b/arch/powerpc/platforms/83xx/mpc830x_rdb.c index 534bb227480d..63b6d213726a 100644 --- a/arch/powerpc/platforms/83xx/mpc830x_rdb.c +++ b/arch/powerpc/platforms/83xx/mpc830x_rdb.c @@ -34,19 +34,11 @@ static const char *board[] __initdata = { NULL }; -/* - * Called very early, MMU is off, device-tree isn't unflattened - */ -static int __init mpc830x_rdb_probe(void) -{ - return of_device_compatible_match(of_root, board); -} - machine_device_initcall(mpc830x_rdb, mpc83xx_declare_of_platform_devices); define_machine(mpc830x_rdb) { .name = "MPC830x RDB", - .probe = mpc830x_rdb_probe, + .compatibles = board, .setup_arch = mpc830x_rdb_setup_arch, .discover_phbs = mpc83xx_setup_pci, .init_IRQ = mpc83xx_ipic_init_IRQ, diff --git a/arch/powerpc/platforms/83xx/mpc831x_rdb.c b/arch/powerpc/platforms/83xx/mpc831x_rdb.c index 7b901ab3b864..5c39966762e4 100644 --- a/arch/powerpc/platforms/83xx/mpc831x_rdb.c +++ b/arch/powerpc/platforms/83xx/mpc831x_rdb.c @@ -34,19 +34,11 @@ static const char *board[] __initdata = { NULL }; -/* - * Called very early, MMU is off, device-tree isn't unflattened - */ -static int __init mpc831x_rdb_probe(void) -{ - return of_device_compatible_match(of_root, board); -} - machine_device_initcall(mpc831x_rdb, mpc83xx_declare_of_platform_devices); define_machine(mpc831x_rdb) { .name = "MPC831x RDB", - .probe = mpc831x_rdb_probe, + .compatibles = board, .setup_arch = mpc831x_rdb_setup_arch, .discover_phbs = mpc83xx_setup_pci, .init_IRQ = mpc83xx_ipic_init_IRQ, diff --git a/arch/powerpc/platforms/83xx/mpc837x_rdb.c b/arch/powerpc/platforms/83xx/mpc837x_rdb.c index 39e78018dd0b..45823e147933 100644 --- a/arch/powerpc/platforms/83xx/mpc837x_rdb.c +++ b/arch/powerpc/platforms/83xx/mpc837x_rdb.c @@ -61,17 +61,9 @@ static const char * const board[] __initconst = { NULL }; -/* - * Called very early, MMU is off, device-tree isn't unflattened - */ -static int __init mpc837x_rdb_probe(void) -{ - return of_device_compatible_match(of_root, board); -} - define_machine(mpc837x_rdb) { .name = "MPC837x RDB/WLAN", - .probe = mpc837x_rdb_probe, + .compatibles = board, .setup_arch = mpc837x_rdb_setup_arch, .discover_phbs = mpc83xx_setup_pci, .init_IRQ = mpc83xx_ipic_init_IRQ, diff --git a/arch/powerpc/platforms/85xx/corenet_generic.c b/arch/powerpc/platforms/85xx/corenet_generic.c index 645fcca77cde..c44400e95f55 100644 --- a/arch/powerpc/platforms/85xx/corenet_generic.c +++ b/arch/powerpc/platforms/85xx/corenet_generic.c @@ -149,7 +149,7 @@ static int __init corenet_generic_probe(void) extern struct smp_ops_t smp_85xx_ops; #endif - if (of_device_compatible_match(of_root, boards)) + if (of_machine_compatible_match(boards)) return 1; /* Check if we're running under the Freescale hypervisor */ diff --git a/arch/powerpc/platforms/85xx/tqm85xx.c b/arch/powerpc/platforms/85xx/tqm85xx.c index 6be1b9809db6..f74d446c53f0 100644 --- a/arch/powerpc/platforms/85xx/tqm85xx.c +++ b/arch/powerpc/platforms/85xx/tqm85xx.c @@ -112,17 +112,9 @@ static const char * const board[] __initconst = { NULL }; -/* - * Called very early, device-tree isn't unflattened - */ -static int __init tqm85xx_probe(void) -{ - return of_device_compatible_match(of_root, board); -} - define_machine(tqm85xx) { .name = "TQM85xx", - .probe = tqm85xx_probe, + .compatibles = board, .setup_arch = tqm85xx_setup_arch, .init_IRQ = tqm85xx_pic_init, .show_cpuinfo = tqm85xx_show_cpuinfo, From patchwork Thu Dec 14 10:31:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 178636 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8445579dys; Thu, 14 Dec 2023 02:32:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvtVJ1zwAdFBgSmYp66EzAmhO3Lwnz6UskH2yHLLBQPdBNjsSKoYe0sv7cDlCKtIiog6qJ X-Received: by 2002:a05:6a20:3d1e:b0:191:bd3b:78b5 with SMTP id y30-20020a056a203d1e00b00191bd3b78b5mr2799917pzi.78.1702549949916; Thu, 14 Dec 2023 02:32:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702549949; cv=none; d=google.com; s=arc-20160816; b=ef21dStj+VULg2gM05s3DLSOYH9K70eFKzpam/ZOkrrzm+xUSFwQBZK/GpCDn8bCXQ gb553NAFo6HYmrhKDZHHWQN/OM8KB7q6xvVKawAhM05yFbu1aI5VryxEThMcdbfXdYJl rhUpsEX5JdpUlAxl1G0lo9xT8J451ZnK8NpBifZSVFTtxelLi3XPJCmJDMsnjc54/5C3 HhrsklYx18wGBj1gKcAMf9PorZ9sLAAvlaDds+/YnhYzuKTC6/Ev1fUugw5Phb5i1atB 9mSeP0p2IVQx4eFiubup5PzA11DSLO2ZEMWzxtyw3TEMLVsxPZp1FgiPWxx/dTde25jI kJ7A== 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 :dkim-signature; bh=wq25GBJsbyghd55GhhhgbPyxN8BeAnr9gNBYTVIUpPs=; fh=6z+ElFTra147heHAzZZJ57t98ehK0pbxyWNV5p0IBGo=; b=NLuqNptMjPy8vzVKLphp8IRcDlYp4Gra1prytADT9HIebaF2rxoqPFWfERcGUC4/nk 19Skq7HczTXlc9PfOQG0O8fGd45F9jVbwNmHBrS8qU7+9g7Sre23rGfIcLvlBb0YM/Vz 7s0kfxHSAJL9x6XoGCAd2Tn1gpG9fmDIPb8x86L6ja3Za77dDNMB5vdERLliL9wIBS2U 2Q1fmnqD3nJSI4u4p71/NiAri0CrahGM+DBqItw5OLmt/SAGWcrb5UjktjzV4cwDuTSM +ybC8mR88qsUzFgr8fTk8U3aG4D8suA7BsO7UXdcu4Wcfm55Seryk0FxXrlCz03GTQ0+ RXaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=OzCRiAsf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id o9-20020a655209000000b005b8ee1c0c67si10776889pgp.594.2023.12.14.02.32.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 02:32:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=OzCRiAsf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 0775C810F6F6; Thu, 14 Dec 2023 02:32:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443695AbjLNKcP (ORCPT + 99 others); Thu, 14 Dec 2023 05:32:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443656AbjLNKcG (ORCPT ); Thu, 14 Dec 2023 05:32:06 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81E1D125 for ; Thu, 14 Dec 2023 02:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1702549927; bh=wq25GBJsbyghd55GhhhgbPyxN8BeAnr9gNBYTVIUpPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OzCRiAsfvE/MJiS5OPusWIC2gJQhPD09SHuFxXokr64wyYQrZialQTGpNYmkqBA2j 66UMyYAW7tdn20EOajWVbv8Fl+dnYz8URxGFLoCAuVxH3949xRhkes/6gF0TVeLcwT 4KoMFWw3cqGdMT9K/wxlyduoSwqROYlggR7dRay7RybY+Mw5NsUu0KdbTia+yXyZYw +oscrfxUhR2gODqFFbD5C3ceZ6DsQtKdU7/4Ku6jHfIsQMAOI62qP2ey7rRYwntI+r pT2vDS08k4EFuW4ZXvua/HhmtdOd+jXZIgVh5Of8aQiJTyFIlxSBO7PR3DB52HAlxQ eLX2dzWM+Q9wA== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4SrTDl4rgGz4xRn; Thu, 14 Dec 2023 21:32:07 +1100 (AEDT) From: Michael Ellerman To: Cc: , , Subject: [PATCH v2 5/5] powerpc: Stop using of_root Date: Thu, 14 Dec 2023 21:31:52 +1100 Message-ID: <20231214103152.12269-5-mpe@ellerman.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231214103152.12269-1-mpe@ellerman.id.au> References: <20231214103152.12269-1-mpe@ellerman.id.au> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Thu, 14 Dec 2023 02:32:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785253016039879437 X-GMAIL-MSGID: 1785253016039879437 From: Christophe Leroy Replace all usages of of_root by of_find_node_by_path("/") Signed-off-by: Christophe Leroy Reviewed-by: Rob Herring Signed-off-by: Michael Ellerman --- arch/powerpc/kernel/secure_boot.c | 8 ++++++-- arch/powerpc/kexec/ranges.c | 8 +++++--- arch/powerpc/mm/drmem.c | 10 +++++----- arch/powerpc/mm/numa.c | 6 ++++-- arch/powerpc/platforms/52xx/efika.c | 4 +++- arch/powerpc/platforms/pasemi/pci.c | 4 +++- arch/powerpc/platforms/pseries/lparcfg.c | 6 +++++- arch/powerpc/platforms/pseries/setup.c | 12 +++++++++--- 8 files changed, 40 insertions(+), 18 deletions(-) v2: Unchanged. diff --git a/arch/powerpc/kernel/secure_boot.c b/arch/powerpc/kernel/secure_boot.c index f9af305d9579..9e0efb657f39 100644 --- a/arch/powerpc/kernel/secure_boot.c +++ b/arch/powerpc/kernel/secure_boot.c @@ -32,8 +32,10 @@ bool is_ppc_secureboot_enabled(void) if (enabled) goto out; - if (!of_property_read_u32(of_root, "ibm,secure-boot", &secureboot)) + node = of_find_node_by_path("/"); + if (!of_property_read_u32(node, "ibm,secure-boot", &secureboot)) enabled = (secureboot > 1); + of_node_put(node); out: pr_info("Secure boot mode %s\n", enabled ? "enabled" : "disabled"); @@ -54,8 +56,10 @@ bool is_ppc_trustedboot_enabled(void) if (enabled) goto out; - if (!of_property_read_u32(of_root, "ibm,trusted-boot", &trustedboot)) + node = of_find_node_by_path("/"); + if (!of_property_read_u32(node, "ibm,trusted-boot", &trustedboot)) enabled = (trustedboot > 0); + of_node_put(node); out: pr_info("Trusted boot mode %s\n", enabled ? "enabled" : "disabled"); diff --git a/arch/powerpc/kexec/ranges.c b/arch/powerpc/kexec/ranges.c index fb3e12f15214..33b780049aaf 100644 --- a/arch/powerpc/kexec/ranges.c +++ b/arch/powerpc/kexec/ranges.c @@ -385,14 +385,16 @@ int add_opal_mem_range(struct crash_mem **mem_ranges) int add_reserved_mem_ranges(struct crash_mem **mem_ranges) { int n_mem_addr_cells, n_mem_size_cells, i, len, cells, ret = 0; + struct device_node *root = of_find_node_by_path("/"); const __be32 *prop; - prop = of_get_property(of_root, "reserved-ranges", &len); + prop = of_get_property(root, "reserved-ranges", &len); + n_mem_addr_cells = of_n_addr_cells(root); + n_mem_size_cells = of_n_size_cells(root); + of_node_put(root); if (!prop) return 0; - n_mem_addr_cells = of_n_addr_cells(of_root); - n_mem_size_cells = of_n_size_cells(of_root); cells = n_mem_addr_cells + n_mem_size_cells; /* Each reserved range is an (address,size) pair */ diff --git a/arch/powerpc/mm/drmem.c b/arch/powerpc/mm/drmem.c index fde7790277f7..c110ab8fa8a3 100644 --- a/arch/powerpc/mm/drmem.c +++ b/arch/powerpc/mm/drmem.c @@ -393,17 +393,17 @@ static const __be32 *of_get_usable_memory(struct device_node *dn) int walk_drmem_lmbs(struct device_node *dn, void *data, int (*func)(struct drmem_lmb *, const __be32 **, void *)) { + struct device_node *root = of_find_node_by_path("/"); const __be32 *prop, *usm; int ret = -ENODEV; - if (!of_root) + if (!root) return ret; /* Get the address & size cells */ - of_node_get(of_root); - n_root_addr_cells = of_n_addr_cells(of_root); - n_root_size_cells = of_n_size_cells(of_root); - of_node_put(of_root); + n_root_addr_cells = of_n_addr_cells(root); + n_root_size_cells = of_n_size_cells(root); + of_node_put(root); if (init_drmem_lmb_size(dn)) return ret; diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c index f6c4ace3b221..a490724e84ad 100644 --- a/arch/powerpc/mm/numa.c +++ b/arch/powerpc/mm/numa.c @@ -1111,7 +1111,7 @@ static void __init setup_node_data(int nid, u64 start_pfn, u64 end_pfn) static void __init find_possible_nodes(void) { - struct device_node *rtas; + struct device_node *rtas, *root; const __be32 *domains = NULL; int prop_length, max_nodes; u32 i; @@ -1132,10 +1132,12 @@ static void __init find_possible_nodes(void) * If the LPAR is migratable, new nodes might be activated after a LPM, * so we should consider the max number in that case. */ - if (!of_get_property(of_root, "ibm,migratable-partition", NULL)) + root = of_find_node_by_path("/"); + if (!of_get_property(root, "ibm,migratable-partition", NULL)) domains = of_get_property(rtas, "ibm,current-associativity-domains", &prop_length); + of_node_put(root); if (!domains) { domains = of_get_property(rtas, "ibm,max-associativity-domains", &prop_length); diff --git a/arch/powerpc/platforms/52xx/efika.c b/arch/powerpc/platforms/52xx/efika.c index aa82e6b437f3..37a67120f257 100644 --- a/arch/powerpc/platforms/52xx/efika.c +++ b/arch/powerpc/platforms/52xx/efika.c @@ -195,8 +195,10 @@ static void __init efika_setup_arch(void) static int __init efika_probe(void) { - const char *model = of_get_property(of_root, "model", NULL); + struct device_node *root = of_find_node_by_path("/"); + const char *model = of_get_property(root, "model", NULL); + of_node_put(root); if (model == NULL) return 0; if (strcmp(model, "EFIKA5K2")) diff --git a/arch/powerpc/platforms/pasemi/pci.c b/arch/powerpc/platforms/pasemi/pci.c index f27d31414737..60f990a336c4 100644 --- a/arch/powerpc/platforms/pasemi/pci.c +++ b/arch/powerpc/platforms/pasemi/pci.c @@ -270,16 +270,18 @@ static int __init pas_add_bridge(struct device_node *dev) void __init pas_pci_init(void) { + struct device_node *root = of_find_node_by_path("/"); struct device_node *np; int res; pci_set_flags(PCI_SCAN_ALL_PCIE_DEVS); - np = of_find_compatible_node(of_root, NULL, "pasemi,rootbus"); + np = of_find_compatible_node(root, NULL, "pasemi,rootbus"); if (np) { res = pas_add_bridge(np); of_node_put(np); } + of_node_put(root); } void __iomem *__init pasemi_pci_getcfgaddr(struct pci_dev *dev, int offset) diff --git a/arch/powerpc/platforms/pseries/lparcfg.c b/arch/powerpc/platforms/pseries/lparcfg.c index 1c151d77e74b..f73c4d1c26af 100644 --- a/arch/powerpc/platforms/pseries/lparcfg.c +++ b/arch/powerpc/platforms/pseries/lparcfg.c @@ -346,9 +346,13 @@ static int read_rtas_lpar_name(struct seq_file *m) */ static int read_dt_lpar_name(struct seq_file *m) { + struct device_node *root = of_find_node_by_path("/"); const char *name; + int ret; - if (of_property_read_string(of_root, "ibm,partition-name", &name)) + ret = of_property_read_string(root, "ibm,partition-name", &name); + of_node_put(root); + if (ret) return -ENOENT; seq_printf(m, "partition_name=%s\n", name); diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c index ecea85c74c43..284a6fa04b0c 100644 --- a/arch/powerpc/platforms/pseries/setup.c +++ b/arch/powerpc/platforms/pseries/setup.c @@ -1029,9 +1029,11 @@ static void __init pseries_add_hw_description(void) return; } - if (of_property_read_bool(of_root, "ibm,powervm-partition") || - of_property_read_bool(of_root, "ibm,fw-net-version")) + dn = of_find_node_by_path("/"); + if (of_property_read_bool(dn, "ibm,powervm-partition") || + of_property_read_bool(dn, "ibm,fw-net-version")) seq_buf_printf(&ppc_hw_desc, "hv:phyp "); + of_node_put(dn); } /* @@ -1091,7 +1093,11 @@ static void pseries_power_off(void) static int __init pSeries_probe(void) { - if (!of_node_is_type(of_root, "chrp")) + struct device_node *root = of_find_node_by_path("/"); + bool ret = of_node_is_type(root, "chrp"); + + of_node_put(root); + if (!ret) return 0; /* Cell blades firmware claims to be chrp while it's not. Until this