Skip to contentSkip to conversation

PCI: Add support for preserving boot configuration

PATCH Applied Vidya Sagar 2 participants 8 messages May 8, 2024 – Jun 3, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v7 cover PCI: Add support for preserving boot configuration

Add support for preserving the boot configuration done by the platform firmware per host bridge basis, based on the presence of 'linux,pci-probe-only' property in the respective PCI host bridge device-tree node. It also unifies the ACPI and DT based boot flows in this regard.

This patch series is a complete version of the incomplete series
( https://lore.kernel.org/linux-pci/[email protected]/ ) posted by Bjorn which in turn was an attempted split work of the single V6 patch ( https://lore.kernel.org/linux-pci/[email protected]/ ) posted by me.

Vidya Sagar (4):
PCI: Move PRESERVE_BOOT_CONFIG _DSM evaluation to
pci_register_host_bridge()
PCI: of: Add of_pci_preserve_config() for per-host bridge support
PCI: Unify ACPI and DT 'preserve config' support
PCI: Use preserve_config in place of pci_flags

 drivers/acpi/pci_root.c                  | 12 ------
 drivers/pci/controller/pci-host-common.c |  4 --
 drivers/pci/of.c                         | 54 +++++++++++++++++++-----
 drivers/pci/pci-acpi.c                   | 22 ++++++++++
 drivers/pci/pci.h                        | 12 ++++++
 drivers/pci/probe.c                      | 34 ++++++++++-----
 6 files changed, 101 insertions(+), 37 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v7 1/4 PCI: Move PRESERVE_BOOT_CONFIG _DSM evaluation to pci_register_host_bridge()

Move the PRESERVE_BOOT_CONFIG _DSM evaluation from acpi_pci_root_create() to pci_register_host_bridge().

This will help unify the ACPI _DSM path and the DT-based "linux,pci-probe-only" paths.

This should be safe because it happens earlier than it used to:

acpi_pci_root_create
pci_create_root_bus
pci_register_host_bridge
+ bridge->preserve_config = pci_preserve_config(bridge)
pci_acpi_preserve_config
+ acpi_evaluate_dsm_typed(DSM_PCI_PRESERVE_BOOT_CONFIG)
- acpi_evaluate_dsm_typed(DSM_PCI_PRESERVE_BOOT_CONFIG)

No functional change intended.

---
 drivers/acpi/pci_root.c | 12 ------------
 drivers/pci/pci-acpi.c  | 22 ++++++++++++++++++++++
 drivers/pci/pci.h       |  5 +++++
 drivers/pci/probe.c     | 11 +++++++++++
 4 files changed, 38 insertions(+), 12 deletions(-)
drivers/acpi/pci_root.c +0 -12
index 58b89b8d950e..ddc2b3e89111 100644
@@ -1008,7 +1008,6 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root,
 	int node = acpi_get_node(device->handle);
 	struct pci_bus *bus;
 	struct pci_host_bridge *host_bridge;
-	union acpi_object *obj;
 
 	info->root = root;
 	info->bridge = device;
@@ -1050,17 +1049,6 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root,
 	if (!(root->osc_ext_control_set & OSC_CXL_ERROR_REPORTING_CONTROL))
 		host_bridge->native_cxl_error = 0;
 
-	/*
-	 * Evaluate the "PCI Boot Configuration" _DSM Function.  If it
-	 * exists and returns 0, we must preserve any PCI resource
-	 * assignments made by firmware for this host bridge.
-	 */
-	obj = acpi_evaluate_dsm_typed(ACPI_HANDLE(bus->bridge), &pci_acpi_dsm_guid, 1,
-				      DSM_PCI_PRESERVE_BOOT_CONFIG, NULL, ACPI_TYPE_INTEGER);
-	if (obj && obj->integer.value == 0)
-		host_bridge->preserve_config = 1;
-	ACPI_FREE(obj);
-
 	acpi_dev_power_up_children_with_adr(device);
 
 	pci_scan_child_bus(bus);
drivers/pci/pci-acpi.c +22 -0
index 004575091596..9cc447da9475 100644
@@ -119,6 +119,28 @@ phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle)
 	return (phys_addr_t)mcfg_addr;
 }
 
+bool pci_acpi_preserve_config(struct pci_host_bridge *host_bridge)
+{
+	if (ACPI_HANDLE(&host_bridge->dev)) {
+		union acpi_object *obj;
+
+		/*
+		 * Evaluate the "PCI Boot Configuration" _DSM Function.  If it
+		 * exists and returns 0, we must preserve any PCI resource
+		 * assignments made by firmware for this host bridge.
+		 */
+		obj = acpi_evaluate_dsm_typed(ACPI_HANDLE(&host_bridge->dev),
+					      &pci_acpi_dsm_guid,
+					      1, DSM_PCI_PRESERVE_BOOT_CONFIG,
+					      NULL, ACPI_TYPE_INTEGER);
+		if (obj && obj->integer.value == 0)
+			return true;
+		ACPI_FREE(obj);
+	}
+
+	return false;
+}
+
 /* _HPX PCI Setting Record (Type 0); same as _HPP */
 struct hpx_type0 {
 	u32 revision;		/* Not present in _HPP */
drivers/pci/pci.h +5 -0
index 17fed1846847..180d3907b543 100644
@@ -734,6 +734,7 @@ static inline void pci_restore_aer_state(struct pci_dev *dev) { }
 #endif
 
 #ifdef CONFIG_ACPI
+bool pci_acpi_preserve_config(struct pci_host_bridge *bridge);
 int pci_acpi_program_hp_params(struct pci_dev *dev);
 extern const struct attribute_group pci_dev_acpi_attr_group;
 void pci_set_acpi_fwnode(struct pci_dev *dev);
@@ -747,6 +748,10 @@ int acpi_pci_wakeup(struct pci_dev *dev, bool enable);
 bool acpi_pci_need_resume(struct pci_dev *dev);
 pci_power_t acpi_pci_choose_state(struct pci_dev *pdev);
 #else
+static inline bool pci_acpi_preserve_config(struct pci_host_bridge *bridge)
+{
+	return false;
+}
 static inline int pci_dev_acpi_reset(struct pci_dev *dev, bool probe)
 {
 	return -ENOTTY;
drivers/pci/probe.c +11 -0
index 1325fbae2f28..ee086d029450 100644
@@ -889,6 +889,14 @@ static void pci_set_bus_msi_domain(struct pci_bus *bus)
 	dev_set_msi_domain(&bus->dev, d);
 }
 
+static bool pci_preserve_config(struct pci_host_bridge *host_bridge)
+{
+	if (pci_acpi_preserve_config(host_bridge))
+		return true;
+
+	return false;
+}
+
 static int pci_register_host_bridge(struct pci_host_bridge *bridge)
 {
 	struct device *parent = bridge->dev.parent;
@@ -983,6 +991,9 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge)
 	if (nr_node_ids > 1 && pcibus_to_node(bus) == NUMA_NO_NODE)
 		dev_warn(&bus->dev, "Unknown NUMA node; performance will be reduced\n");
 
+	/* Check if the boot configuration by FW needs to be preserved */
+	bridge->preserve_config = pci_preserve_config(bridge);
+
 	/* Coalesce contiguous windows */
 	resource_list_for_each_entry_safe(window, n, &resources) {
 		if (list_is_last(&window->node, &resources))
Signature · 1 line
2.25.1
#2 lore raw

PATCH v7 2/4 PCI: of: Add of_pci_preserve_config() for per-host bridge support

In reply to Vidya Sagar

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  | 54 ++++++++++++++++++++++++++++++++++++++---------
 drivers/pci/pci.h |  7 ++++++
 2 files changed, 51 insertions(+), 10 deletions(-)
drivers/pci/of.c +44 -10
index 51e3dd0ea5ab..d21c0bed36f3 100644
@@ -234,27 +234,61 @@ int of_get_pci_domain_nr(struct device_node *node)
 EXPORT_SYMBOL_GPL(of_get_pci_domain_nr);
 
 /**
- * of_pci_check_probe_only - Setup probe only mode if linux,pci-probe-only
- *                           is present and valid
+ * 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.
  */
-void of_pci_check_probe_only(void)
+bool of_pci_preserve_config(struct device_node *node)
 {
-	u32 val;
+	u32 val = 0;
 	int ret;
 
-	ret = of_property_read_u32(of_chosen, "linux,pci-probe-only", &val);
+	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("linux,pci-probe-only without valid value, ignoring\n");
-		return;
+		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)
+{
+	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);
 
drivers/pci/pci.h +7 -0
index 180d3907b543..feedbedd65df 100644
@@ -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) { }
Signature · 1 line
2.25.1
#3 lore raw

PATCH v7 3/4 PCI: Unify ACPI and DT 'preserve config' support

In reply to Vidya Sagar

Unify the 'preserve config' support across ACPI and device-tree boot flows.

---
 drivers/pci/probe.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/probe.c +3 -0
index ee086d029450..2c232c22d6af 100644
@@ -894,6 +894,9 @@ static bool pci_preserve_config(struct pci_host_bridge *host_bridge)
 	if (pci_acpi_preserve_config(host_bridge))
 		return true;
 
+	if (host_bridge->dev.parent && host_bridge->dev.parent->of_node)
+		return of_pci_preserve_config(host_bridge->dev.parent->of_node);
+
 	return false;
 }
 
Signature · 1 line
2.25.1
#4 lore raw

PATCH v7 4/4 PCI: Use preserve_config in place of pci_flags

In reply to Vidya Sagar

Use preserve_config in place of checking for PCI_PROBE_ONLY flag to enable support for "linux,pci-probe-only" on a per host bridge basis.

This patch also obviates the use of adding PCI_REASSIGN_ALL_BUS flag if !PCI_PROBE_ONLY, as pci_assign_unassigned_root_bus_resources() takes care of reassigning the resources that are not already claimed.

---
 drivers/pci/controller/pci-host-common.c |  4 ----
 drivers/pci/probe.c                      | 20 +++++++++-----------
 2 files changed, 9 insertions(+), 15 deletions(-)
drivers/pci/controller/pci-host-common.c +0 -4
index 45b71806182d..c96b2de163b5 100644
@@ -73,10 +73,6 @@ int pci_host_common_probe(struct platform_device *pdev)
 	if (IS_ERR(cfg))
 		return PTR_ERR(cfg);
 
-	/* Do not reassign resources if probe only */
-	if (!pci_has_flag(PCI_PROBE_ONLY))
-		pci_add_flags(PCI_REASSIGN_ALL_BUS);
-
 	bridge->sysdata = cfg;
 	bridge->ops = (struct pci_ops *)&ops->pci_ops;
 	bridge->msi_domain = true;
drivers/pci/probe.c +9 -11
index 2c232c22d6af..b4adc33f88cf 100644
@@ -3088,20 +3088,18 @@ int pci_host_probe(struct pci_host_bridge *bridge)
 
 	bus = bridge->bus;
 
+	/* If we must preserve the resource configuration, claim now */
+	if (bridge->preserve_config)
+		pci_bus_claim_resources(bus);
+
 	/*
-	 * We insert PCI resources into the iomem_resource and
-	 * ioport_resource trees in either pci_bus_claim_resources()
-	 * or pci_bus_assign_resources().
+	 * Assign whatever was left unassigned. If we didn't claim above,
+	 * this will reassign everything.
 	 */
-	if (pci_has_flag(PCI_PROBE_ONLY)) {
-		pci_bus_claim_resources(bus);
-	} else {
-		pci_bus_size_bridges(bus);
-		pci_bus_assign_resources(bus);
+	pci_assign_unassigned_root_bus_resources(bus);
 
-		list_for_each_entry(child, &bus->children, node)
-			pcie_bus_configure_settings(child);
-	}
+	list_for_each_entry(child, &bus->children, node)
+		pcie_bus_configure_settings(child);
 
 	pci_bus_add_devices(bus);
 	return 0;
Signature · 1 line
2.25.1
#5 lore raw
In reply to Vidya Sagar

Hi Bjorn,
Thanks for reviewing and refactoring V6 patch.
Could you please review this V7 series as well?

Thanks,
Vidya Sagar

Quoted 41 lines

-----Original Message-----
From: Vidya Sagar <[email protected]>
Sent: Wednesday, May 8, 2024 11:12 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Thierry Reding <[email protected]>; Jon Hunter <[email protected]>; Krishna Thota <[email protected]>; Manikanta Maddireddy <[email protected]>; Vidya Sagar <[email protected]>; [email protected]
Subject: [PATCH V7 0/4] PCI: Add support for preserving boot configuration

Add support for preserving the boot configuration done by the platform firmware per host bridge basis, based on the presence of 'linux,pci-probe-only' property in the respective PCI host bridge device-tree node. It also unifies the ACPI and DT based boot flows in this regard.

This patch series is a complete version of the incomplete series (
https://lore.kernel.org/linux-pci/20240421190914.374399-1-
[email protected]/ ) posted by Bjorn which in turn was an attempted split work of the single V6 patch ( https://lore.kernel.org/linux-
pci/[email protected]/ ) posted by me.

Vidya Sagar (4):
PCI: Move PRESERVE_BOOT_CONFIG _DSM evaluation to
pci_register_host_bridge()
PCI: of: Add of_pci_preserve_config() for per-host bridge support
PCI: Unify ACPI and DT 'preserve config' support
PCI: Use preserve_config in place of pci_flags

 drivers/acpi/pci_root.c                  | 12 ------
 drivers/pci/controller/pci-host-common.c |  4 --
 drivers/pci/of.c                         | 54 +++++++++++++++++++-----
 drivers/pci/pci-acpi.c                   | 22 ++++++++++
 drivers/pci/pci.h                        | 12 ++++++
 drivers/pci/probe.c                      | 34 ++++++++++-----
 6 files changed, 101 insertions(+), 37 deletions(-)

--
2.25.1

#6 lore raw

Hi Bjorn,
Sorry to bug you.
Please let me know if you need more information for this series.

Thanks,
Vidya Sagar

Quoted 66 lines

-----Original Message-----
From: Vidya Sagar <[email protected]>
Sent: Friday, May 17, 2024 11:05 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Thierry Reding <[email protected]>; Jon Hunter <[email protected]>; Krishna Thota <[email protected]>; Manikanta Maddireddy <[email protected]>; [email protected]
Subject: RE: [PATCH V7 0/4] PCI: Add support for preserving boot configuration

External email: Use caution opening links or attachments

Hi Bjorn,
Thanks for reviewing and refactoring V6 patch.
Could you please review this V7 series as well?

Thanks,
Vidya Sagar

Quoted 43 lines

-----Original Message-----
From: Vidya Sagar <[email protected]>
Sent: Wednesday, May 8, 2024 11:12 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Thierry Reding <[email protected]>; Jon Hunter <[email protected]>; Krishna Thota <[email protected]>; Manikanta Maddireddy <[email protected]>; Vidya Sagar <[email protected]>; [email protected]
Subject: [PATCH V7 0/4] PCI: Add support for preserving boot configuration

Add support for preserving the boot configuration done by the platform firmware per host bridge basis, based on the presence of 'linux,pci-probe-only' property in the respective PCI host bridge device-tree node. It also unifies the ACPI and DT based boot flows in this regard.

This patch series is a complete version of the incomplete series (
https://lore.kernel.org/linux-pci/20240421190914.374399-1-
[email protected]/ ) posted by Bjorn which in turn was an attempted split work of the single V6 patch ( https://lore.kernel.org/linux-
pci/[email protected]/ ) posted by me.

Vidya Sagar (4):
PCI: Move PRESERVE_BOOT_CONFIG _DSM evaluation to
pci_register_host_bridge()
PCI: of: Add of_pci_preserve_config() for per-host bridge support
PCI: Unify ACPI and DT 'preserve config' support
PCI: Use preserve_config in place of pci_flags

 drivers/acpi/pci_root.c                  | 12 ------
 drivers/pci/controller/pci-host-common.c |  4 --
 drivers/pci/of.c                         | 54 +++++++++++++++++++-----
 drivers/pci/pci-acpi.c                   | 22 ++++++++++
 drivers/pci/pci.h                        | 12 ++++++
 drivers/pci/probe.c                      | 34 ++++++++++-----
 6 files changed, 101 insertions(+), 37 deletions(-)

--
2.25.1

#7 lore raw
In reply to Vidya Sagar
Quoted 19 lines · Vidya Sagar

Add support for preserving the boot configuration done by the platform firmware per host bridge basis, based on the presence of 'linux,pci-probe-only' property in the respective PCI host bridge device-tree node. It also unifies the ACPI and DT based boot flows in this regard.

This patch series is a complete version of the incomplete series
( https://lore.kernel.org/linux-pci/[email protected]/ ) posted by Bjorn which in turn was an attempted split work of the single V6 patch ( https://lore.kernel.org/linux-pci/[email protected]/ ) posted by me.

Vidya Sagar (4):
PCI: Move PRESERVE_BOOT_CONFIG _DSM evaluation to
pci_register_host_bridge()
PCI: of: Add of_pci_preserve_config() for per-host bridge support
PCI: Unify ACPI and DT 'preserve config' support
PCI: Use preserve_config in place of pci_flags

Quoted 7 lines
 drivers/acpi/pci_root.c                  | 12 ------
 drivers/pci/controller/pci-host-common.c |  4 --
 drivers/pci/of.c                         | 54 +++++++++++++++++++-----
 drivers/pci/pci-acpi.c                   | 22 ++++++++++
 drivers/pci/pci.h                        | 12 ++++++
 drivers/pci/probe.c                      | 34 ++++++++++-----
 6 files changed, 101 insertions(+), 37 deletions(-)

Applied to pci/enumeration for v6.11, thanks!