Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1852117lqt; Sun, 21 Apr 2024 12:10:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWsberOc9U5/8GNkyHw9xZkmNHZXx1qNXwbGyvKsGk0FEnT1pUoCrxHuCj7hH479GFZHNcZSkOi+SsnAraiCS9bdSBNsuEM5THLkceERw== X-Google-Smtp-Source: AGHT+IF+LSGR8ra08sg6sm4yw/kTxv0oZlArim6p1R5KrbzOpgNSoSBJvTTrfIHwkaDxQ5SDYvJE X-Received: by 2002:ac2:4e92:0:b0:518:f4c6:5bb3 with SMTP id o18-20020ac24e92000000b00518f4c65bb3mr6015093lfr.25.1713726619670; Sun, 21 Apr 2024 12:10:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713726619; cv=pass; d=google.com; s=arc-20160816; b=dIiHni3pwACcAyd0FgVxGet67MNKA+3f2MZMhxAKSz9JGxMBZxQD30onRuh4ktBAgQ TLF1VmwBsmYsj5BFd8ohNolF+PoXVO1QYBMIEFgr3Ch9Nakt3WpQGy7dUwoimX6ijTay VgnMJvgR/HXjOe/riAKrbisy7fwKWHzrC65sNptxFtVmBzeeBBMg2ZG/bXLQkRPWcmJO MDxT49LpMiKc7CgKmdBsZyhca35oZ7riOhd1RnxMJZbNhMUh0fUze8fgLClVoILqV1Sc guaUQ1h2X6IvFlqLuEDaEKnm9AjfBz6wRp3zJU7fWDcSECxWGwzC6YTjvRbztULcFVVQ 6qDg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=2TVnCQj2NIjIEqFAmdLzrXirb9YiFwfbNg0QtiCbxtA=; fh=SjyyLJaug74WeH+YBfITVzrTrUuKP2sS83jRs9MsakU=; b=m5bXZiEdt++NhGQYRU5FMrG1XWgiXrtkZH9VsQO/j59ScVljLcdEK2BY/DclEXENab 6DkeZMnurJG2XyDILwHwaonQUhAOW/7uVXwyHuAa786iXjcuVVH/xT1/ht1HTB5A+vUh 7DWFyDT9AVYmOaWaylfUBPAHz79ZRQI8qZ4VUPjznCyZjFifv9i+qQyGn8rvo+PAyUoN ZekNyzB60q78My4MzfV3ubaXpR2HCHvycMRfWUD31P/6VZ7efRnuquymny/aa5lYWASb tAr25JcEc+zSpUT2kkjaztahQ7WzN+M/qhrcNyhvruyxPsYzBZCw6CKsNnO2JhsIbyeR cDMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=l2uCX7za; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-152591-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152591-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id t16-20020a17090605d000b00a51931af824si4837675ejt.560.2024.04.21.12.10.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 12:10:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152591-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=l2uCX7za; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-152591-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152591-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 55A0F1F213E1 for ; Sun, 21 Apr 2024 19:10:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BEFE74436E; Sun, 21 Apr 2024 19:09:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="l2uCX7za" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD2A142ABE; Sun, 21 Apr 2024 19:09:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713726571; cv=none; b=FuHbj7LCtHJNdqsqUq4iODGRPJriCEJBfh/mh6jYorloQFKAwdQP9LukZ8k0z5NXJc4hyYC0pZ5PdictsZ9PvGvGiLQZ44kVqvAEC1wEml7wfvSeCnwlA8nMqK/ipTR287NhAFiyvS/dZGEQggu/nObC5lCyACq1YAcSmp4UK04= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713726571; c=relaxed/simple; bh=5b1Rd+c4FpyVTxmhZ/c+aS1Qqo8vTZijXYkHUU+mNds=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZC/fz7AG8DP8vWGEjKVYBRnd1OKyumFOZ80kUumu6rXQhjZpGyAJ1l577gsiiSzFaO5IBcFXM8vYQrLZcFaTK9X/yH3HYG6CL4WQRhx1Wx3Ba8T9btlW6ifO4kXkbbg8CgN6b62omAyKBDhMH/FBaqCijqddCU9DXWfdM8AGRYA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l2uCX7za; arc=none smtp.client-ip=10.30.226.201 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=20Wilczy=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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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) { } -- 2.34.1