From patchwork Sun Apr 21 19:09:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 13637501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E90B4C4345F for ; Sun, 21 Apr 2024 19:09:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sxV8zaScESNTOeHDnfeTodD3xJtRagFIlBpbUVaDELs=; b=bYCPAA9ir/7Yub xNz+KwBcl6+8BgM8yz4TduTbr8udwyWDIMy2n1KuCVGyzbSSRwHEPWEuxlYxscvCNWnBdVn8A6gL5 zPkfW5g/wMTplFRdiXJgPASP4x3RbY1B5Rsm+PpQvaxg+1jbtnRViOYItGNTIm7pQ6PJz2Rg3uhiF 8QwE9lkiFUIHdrFnjDiSJV4jauyYrwQRkeAwvO4/MFkXBObQRi+XbxDCCoygOz4tA6Z7USPxU9xwK S39W8+7B1U9bP0VVxyNnToAkUB1ByBOp24vC7sh6pEIPvZIz54mn7m+i8CCC2UnJ6Aiw2tmQvP7/J +uhtEGZxJPuHL+g3b2Wg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rycZE-0000000B8Xn-3OGc; Sun, 21 Apr 2024 19:09:36 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rycZA-0000000B8Wl-0H27 for linux-arm-kernel@lists.infradead.org; Sun, 21 Apr 2024 19:09:35 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7203060B99; Sun, 21 Apr 2024 19:09:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3909C2BD11; Sun, 21 Apr 2024 19:09:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713726571; bh=5b1Rd+c4FpyVTxmhZ/c+aS1Qqo8vTZijXYkHUU+mNds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l2uCX7zaTXjwYyn/HQscx0eZQElgdBDcegVeBMyoFW6Ni+fmor0aF/r+A6FlfHyxC Fnmd5OCyvRhDoMHR4NLJ3kEta8jWq+Duf9CwA/1CyA3XQc2npDjsgNP57BdfTPaqZo JL+yNZfOjIarLusj0UH4zrZu/beCz4R+iY+xchmh/nBT+oRSmlDoRWkrIZeZOa9eb0 K6cOgaqfPOKf1JE/accZjoJzhYGXFbbyFNAgjQ27n99xtjkO/N/kPmEscxthzbcPFL 6RJ4wrkv/pt+LogV3bvcwh63J4n+trLMGcepdbhk/LZowaVdA9k2SrYSMVEk0sr8iC Pc/POnBWBz0ug== From: Bjorn Helgaas To: Vidya Sagar Cc: "Rafael J . Wysocki" , Len Brown , Will Deacon , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Rob Herring , Frank Rowand , Thierry Reding , Jonathan Hunter , Krishna Thota , Manikanta Maddireddy , Vidya Sagar , linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Bjorn Helgaas Subject: [PATCH v7-incomplete 2/3] PCI: of: Add of_pci_preserve_config() for per-host bridge support Date: Sun, 21 Apr 2024 14:09:13 -0500 Message-Id: <20240421190914.374399-3-helgaas@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240421190914.374399-1-helgaas@kernel.org> References: <20240418174043.3750240-1-vidyas@nvidia.com> <20240421190914.374399-1-helgaas@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240421_120932_219970_A0F443E6 X-CRM114-Status: GOOD ( 16.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bjorn Helgaas Add of_pci_preserve_config() to look for the "linux,pci-probe-only" property under a specified node. If it's not found there, look under "of_chosen" in addition. If the caller didn't specify a node, look under "of_chosen". With a future patch, this will support "linux,pci-probe-only" on a per host bridge basis based on the presence of the property in the respective PCI host bridge DT node. Implement of_pci_check_probe_only() using of_pci_preserve_config(). --- drivers/pci/of.c | 60 +++++++++++++++++++++++++++++++++++++---------- drivers/pci/pci.h | 7 ++++++ 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/drivers/pci/of.c b/drivers/pci/of.c index 51e3dd0ea5ab..d21c0bed36f3 100644 --- a/drivers/pci/of.c +++ b/drivers/pci/of.c @@ -233,28 +233,62 @@ int of_get_pci_domain_nr(struct device_node *node) } EXPORT_SYMBOL_GPL(of_get_pci_domain_nr); +/** + * of_pci_preserve_config - Return true if the boot configuration needs to + * be preserved + * @node: Device tree node. + * + * This function looks for "linux,pci-probe-only" property for a given + * PCI controller's node and returns true if found. It will also look in the + * chosen node if the property is not found in the given controller's node. + * Having this property ensures that the kernel doesn't reconfigure the + * BARs and bridge windows that are already done by the platform firmware. + * + * Return: true if the property exists false otherwise. + */ +bool of_pci_preserve_config(struct device_node *node) +{ + u32 val = 0; + int ret; + + if (!node) { + pr_warn("device node is NULL, trying with of_chosen\n"); + node = of_chosen; + } + +retry: + ret = of_property_read_u32(node, "linux,pci-probe-only", &val); + if (ret) { + if (ret == -ENODATA || ret == -EOVERFLOW) { + pr_warn("Incorrect value for linux,pci-probe-only in %pOF, ignoring\n", + node); + return false; + } + if (ret == -EINVAL) { + if (node == of_chosen) + return false; + + node = of_chosen; + goto retry; + } + } + + if (val) + return true; + else + return false; +} + /** * of_pci_check_probe_only - Setup probe only mode if linux,pci-probe-only * is present and valid */ void of_pci_check_probe_only(void) { - u32 val; - int ret; - - ret = of_property_read_u32(of_chosen, "linux,pci-probe-only", &val); - if (ret) { - if (ret == -ENODATA || ret == -EOVERFLOW) - pr_warn("linux,pci-probe-only without valid value, ignoring\n"); - return; - } - - if (val) + if (of_pci_preserve_config(of_chosen)) pci_add_flags(PCI_PROBE_ONLY); else pci_clear_flags(PCI_PROBE_ONLY); - - pr_info("PROBE_ONLY %s\n", val ? "enabled" : "disabled"); } EXPORT_SYMBOL_GPL(of_pci_check_probe_only); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 180d3907b543..feedbedd65df 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -650,6 +650,7 @@ int of_pci_get_max_link_speed(struct device_node *node); u32 of_pci_get_slot_power_limit(struct device_node *node, u8 *slot_power_limit_value, u8 *slot_power_limit_scale); +bool of_pci_preserve_config(struct device_node *node); int pci_set_of_node(struct pci_dev *dev); void pci_release_of_node(struct pci_dev *dev); void pci_set_bus_of_node(struct pci_bus *bus); @@ -688,6 +689,12 @@ of_pci_get_slot_power_limit(struct device_node *node, return 0; } +static inline bool +of_pci_preserve_config(struct device_node *node) +{ + return false; +} + static inline int pci_set_of_node(struct pci_dev *dev) { return 0; } static inline void pci_release_of_node(struct pci_dev *dev) { } static inline void pci_set_bus_of_node(struct pci_bus *bus) { }