Skip to contentSkip to conversation

acpi,pci: disentangle ACPI-related code and PCI-related code at hostbridge

RFC PATCH In review Taku Izumi 2 participants 7 messages Oct 30, 2012 – Nov 7, 2012

Subsystems (4)
lore
Share & tools
lore

Taku Izumi

author
#0 lore raw

cover acpi,pci: disentangle ACPI-related code and PCI-related code at hostbridge

addition/removal code
Message-Id: <[email protected]>
X-Mailer: Sylpheed 3.1.1 (GTK+ 2.10.14; i686-pc-mingw32)
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

Hi all,

This patchset is to disentangle ACPI-related code and PCI-related code at hostbridge addition/removal code.
This is based on the comment Bjorn suggested at
http://marc.info/?l=linux-pci&m=134825820111705&w=2

* [PATCH 1/5] ACPI: Pass segment/bus to _PRT add/del so they don't depend on pci_bus
* [PATCH 2/5] PCI,ACPI: Add _PRT interrupt routing info before enumerating devices
* [PATCH 3/5] PCI,ACPI: Remove _PRT info when removing a host bridge
* [PATCH 4/5] PCI: Change the signature of pci_ext_cfg_avail function
* [PATCH 5/5] PCI,ACPI: Requesting _OSC control before scanning pci tree in acpi_pci_root_add()

Signature · 2 lines
Best regards,
Taku Izumi <[email protected]>
author
#1 lore raw

PATCH 1/5 ACPI: Pass segment/bus to _PRT add/del so they don't depend on pci_bus

Author: Bjorn Helgaas <[email protected]>

ACPI: Pass segment/bus to _PRT add/del so they don't depend on pci_bus

This effectively reverts 859a3f86ca8 ("ACPI: simplify acpi_pci_irq_add_prt() API") and d9efae3688a ("ACPI: simplify acpi_pci_irq_del_prt() API").

The reason is to disentangle these routines from the struct pci_bus. We want to be able to add the _PRT before the struct pci_bus exists, and delete the _PRT after we've removed the pci_bus.

---
 drivers/acpi/pci_bind.c     |   10 +++++-----
 drivers/acpi/pci_irq.c      |   17 ++++++++---------
 drivers/acpi/pci_root.c     |    3 ++-
 include/acpi/acpi_drivers.h |    4 ++--
 4 files changed, 17 insertions(+), 17 deletions(-)
drivers/acpi/pci_bind.c +5 -5
Index: Bjorn-next-0925/drivers/acpi/pci_bind.c
===================================================================
@@ -49,7 +49,7 @@ static int acpi_pci_unbind(struct acpi_d
 	if (!dev->subordinate)
 		goto out;
 
-	acpi_pci_irq_del_prt(dev->subordinate);
+	acpi_pci_irq_del_prt(pci_domain_nr(dev->bus), dev->subordinate->number);
 
 	device->ops.bind = NULL;
 	device->ops.unbind = NULL;
@@ -63,7 +63,7 @@ static int acpi_pci_bind(struct acpi_dev
 {
 	acpi_status status;
 	acpi_handle handle;
-	struct pci_bus *bus;
+	unsigned char bus;
 	struct pci_dev *dev;
 
 	dev = acpi_get_pci_dev(device->handle);
@@ -100,11 +100,11 @@ static int acpi_pci_bind(struct acpi_dev
 		goto out;
 
 	if (dev->subordinate)
-		bus = dev->subordinate;
+		bus = dev->subordinate->number;
 	else
-		bus = dev->bus;
+		bus = dev->bus->number;
 
-	acpi_pci_irq_add_prt(device->handle, bus);
+	acpi_pci_irq_add_prt(device->handle, pci_domain_nr(dev->bus), bus);
 
 out:
 	pci_dev_put(dev);
drivers/acpi/pci_irq.c +8 -9
Index: Bjorn-next-0925/drivers/acpi/pci_irq.c
===================================================================
@@ -184,7 +184,7 @@ static void do_prt_fixups(struct acpi_pr
 	}
 }
 
-static int acpi_pci_irq_add_entry(acpi_handle handle, struct pci_bus *bus,
+static int acpi_pci_irq_add_entry(acpi_handle handle, int segment, int bus,
 				  struct acpi_pci_routing_table *prt)
 {
 	struct acpi_prt_entry *entry;
@@ -198,8 +198,8 @@ static int acpi_pci_irq_add_entry(acpi_h
 	 * 1=INTA, 2=INTB.  We use the PCI encoding throughout, so convert
 	 * it here.
 	 */
-	entry->id.segment = pci_domain_nr(bus);
-	entry->id.bus = bus->number;
+	entry->id.segment = segment;
+	entry->id.bus = bus;
 	entry->id.device = (prt->address >> 16) & 0xFFFF;
 	entry->pin = prt->pin + 1;
 
@@ -244,7 +244,7 @@ static int acpi_pci_irq_add_entry(acpi_h
 	return 0;
 }
 
-int acpi_pci_irq_add_prt(acpi_handle handle, struct pci_bus *bus)
+int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
 {
 	acpi_status status;
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
@@ -273,7 +273,7 @@ int acpi_pci_irq_add_prt(acpi_handle han
 
 	entry = buffer.pointer;
 	while (entry && (entry->length > 0)) {
-		acpi_pci_irq_add_entry(handle, bus, entry);
+		acpi_pci_irq_add_entry(handle, segment, bus, entry);
 		entry = (struct acpi_pci_routing_table *)
 		    ((unsigned long)entry + entry->length);
 	}
@@ -282,17 +282,16 @@ int acpi_pci_irq_add_prt(acpi_handle han
 	return 0;
 }
 
-void acpi_pci_irq_del_prt(struct pci_bus *bus)
+void acpi_pci_irq_del_prt(int segment, int bus)
 {
 	struct acpi_prt_entry *entry, *tmp;
 
 	printk(KERN_DEBUG
 	       "ACPI: Delete PCI Interrupt Routing Table for %04x:%02x\n",
-	       pci_domain_nr(bus), bus->number);
+	       segment, bus);
 	spin_lock(&acpi_prt_lock);
 	list_for_each_entry_safe(entry, tmp, &acpi_prt_list, list) {
-		if (pci_domain_nr(bus) == entry->id.segment
-			&& bus->number == entry->id.bus) {
+		if (segment == entry->id.segment && bus == entry->id.bus) {
 			list_del(&entry->list);
 			kfree(entry);
 		}
drivers/acpi/pci_root.c +2 -1
Index: Bjorn-next-0925/drivers/acpi/pci_root.c
===================================================================
@@ -554,7 +554,8 @@ static int __devinit acpi_pci_root_add(s
 	 */
 	status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
 	if (ACPI_SUCCESS(status))
-		result = acpi_pci_irq_add_prt(device->handle, root->bus);
+		result = acpi_pci_irq_add_prt(device->handle, root->segment,
+					      root->secondary.start);
 
 	/*
 	 * Scan and bind all _ADR-Based Devices
include/acpi/acpi_drivers.h +2 -2
Index: Bjorn-next-0925/include/acpi/acpi_drivers.h
===================================================================
@@ -92,8 +92,8 @@ int acpi_pci_link_free_irq(acpi_handle h
 
 /* ACPI PCI Interrupt Routing (pci_irq.c) */
 
-int acpi_pci_irq_add_prt(acpi_handle handle, struct pci_bus *bus);
-void acpi_pci_irq_del_prt(struct pci_bus *bus);
+int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus);
+void acpi_pci_irq_del_prt(int segment, int bus);
 
 /* ACPI PCI Device Binding (pci_bind.c) */
 
author
#2 lore raw

PATCH 2/5 PCI,ACPI: Add _PRT interrupt routing info before enumerating devices

In reply to Taku Izumi

Author: Bjorn Helgaas <[email protected]>

PCI/ACPI: Add _PRT interrupt routing info before enumerating devices

We used to add the _PRT after enumerating devices behind a new host bridge. This moves the _PRT addition *before* the enumeration, since it no longer depends on the struct pci_bus existing. This is one step towards consolidating the .add/.start methods.

[insert acpi_pci_irq_del_prt() on hostbridge addition failure]
---
 drivers/acpi/pci_root.c |   24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/acpi/pci_root.c +13 -11
Index: Bjorn-next-0925/drivers/acpi/pci_root.c
===================================================================
@@ -467,6 +467,7 @@ static int __devinit acpi_pci_root_add(s
 		result = -ENODEV;
 		goto end;
 	}
+	root->segment = segment & 0xFFFF;
 
 	/* Check _CRS first, then _BBN.  If no _BBN, default to zero. */
 	root->secondary.flags = IORESOURCE_BUS;
@@ -494,9 +495,18 @@ static int __devinit acpi_pci_root_add(s
 		}
 	}
 
+	/*
+	 * PCI Routing Table
+	 * -----------------
+	 * Evaluate and parse _PRT, if exists.
+	 */
+	status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
+	if (ACPI_SUCCESS(status))
+		result = acpi_pci_irq_add_prt(device->handle, root->segment,
+					      root->secondary.start);
+
 	INIT_LIST_HEAD(&root->node);
 	root->device = device;
-	root->segment = segment & 0xFFFF;
 	strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
 	strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
 	device->driver_data = root;
@@ -548,16 +558,6 @@ static int __devinit acpi_pci_root_add(s
 		goto out_del_root;
 
 	/*
-	 * PCI Routing Table
-	 * -----------------
-	 * Evaluate and parse _PRT, if exists.
-	 */
-	status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
-	if (ACPI_SUCCESS(status))
-		result = acpi_pci_irq_add_prt(device->handle, root->segment,
-					      root->secondary.start);
-
-	/*
 	 * Scan and bind all _ADR-Based Devices
 	 */
 	list_for_each_entry(child, &device->children, node)
@@ -635,6 +635,8 @@ out_del_root:
 	mutex_lock(&acpi_pci_root_lock);
 	list_del(&root->node);
 	mutex_unlock(&acpi_pci_root_lock);
+
+	acpi_pci_irq_del_prt(root->segment, root->secondary.start);
 end:
 	kfree(root);
 	return result;
author
#3 lore raw

PATCH 3/5 PCI,ACPI: Remove _PRT info when removing a host bridge

In reply to Taku Izumi

Author: Bjorn Helgaas <[email protected]>

PCI/ACPI: Remove _PRT info when removing a host bridge

---
 drivers/acpi/pci_root.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/pci_root.c +2 -0
Index: Bjorn-next-0925/drivers/acpi/pci_root.c
===================================================================
@@ -671,6 +671,8 @@ static int acpi_pci_root_remove(struct a
 	device_set_run_wake(root->bus->bridge, false);
 	pci_acpi_remove_bus_pm_notifier(device);
 
+	acpi_pci_irq_del_prt(root->segment, root->secondary.start);
+
 	list_del(&root->node);
 	mutex_unlock(&acpi_pci_root_lock);
 	kfree(root);
author
#4 lore raw

PATCH 4/5 PCI: Change the signature of pci_ext_cfg_avail function

In reply to Taku Izumi

PCI: change the signature of pci_ext_cfg_avail function

The default implementation of pci_ext_cfg_avail and its only overridden function for x86 architecture doesn't use passed *pci_dev. This patch ommits the parameter of pci_ext_cfg_avail function.

---
 arch/x86/pci/common.c   |    2 +-
 drivers/acpi/pci_root.c |    2 +-
 drivers/pci/pci.c       |    5 ++---
 include/linux/pci.h     |    2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)
arch/x86/pci/common.c +1 -1
Index: pci/arch/x86/pci/common.c
===================================================================
@@ -626,7 +626,7 @@ void pcibios_disable_device (struct pci_
 		pcibios_disable_irq(dev);
 }
 
-int pci_ext_cfg_avail(struct pci_dev *dev)
+int pci_ext_cfg_avail(void)
 {
 	if (raw_pci_ext_ops)
 		return 1;
drivers/acpi/pci_root.c +1 -1
Index: pci/drivers/acpi/pci_root.c
===================================================================
@@ -564,7 +564,7 @@ static int __devinit acpi_pci_root_add(s
 		acpi_pci_bridge_scan(child);
 
 	/* Indicate support for various _OSC capabilities. */
-	if (pci_ext_cfg_avail(root->bus->self))
+	if (pci_ext_cfg_avail())
 		flags |= OSC_EXT_PCI_CONFIG_SUPPORT;
 	if (pcie_aspm_support_enabled())
 		flags |= OSC_ACTIVE_STATE_PWR_SUPPORT |
drivers/pci/pci.c +2 -3
Index: pci/drivers/pci/pci.c
===================================================================
@@ -3833,14 +3833,13 @@ static void __devinit pci_no_domains(voi
 }
 
 /**
- * pci_ext_cfg_enabled - can we access extended PCI config space?
- * @dev: The PCI device of the root bridge.
+ * pci_ext_cfg_avail - can we access extended PCI config space?
  *
  * Returns 1 if we can access PCI extended config space (offsets
  * greater than 0xff). This is the default implementation. Architecture
  * implementations can override this.
  */
-int __weak pci_ext_cfg_avail(struct pci_dev *dev)
+int __weak pci_ext_cfg_avail(void)
 {
 	return 1;
 }
include/linux/pci.h +1 -1
Index: pci/include/linux/pci.h
===================================================================
@@ -1623,7 +1623,7 @@ static inline void pci_mmcfg_early_init(
 static inline void pci_mmcfg_late_init(void) { }
 #endif
 
-int pci_ext_cfg_avail(struct pci_dev *dev);
+int pci_ext_cfg_avail(void);
 
 void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar);
 
author
#5 lore raw

PATCH 5/5 PCI,ACPI: Requesting _OSC control before scanning pci tree in acpi_pci_root_add()

In reply to Taku Izumi

Requesting _OSC control before scanning pci tree in acpi_pci_root_add()

This patch moves up the code block to request _OSC control in order to separate ACPI work and PCI work in acpi_pci_root_add().

---
 drivers/acpi/pci_root.c |  121 ++++++++++++++++++++++++------------------------
 1 file changed, 62 insertions(+), 59 deletions(-)
drivers/acpi/pci_root.c +62 -59
Index: pci/drivers/acpi/pci_root.c
===================================================================
@@ -454,6 +454,7 @@ static int __devinit acpi_pci_root_add(s
 	acpi_handle handle;
 	struct acpi_device *child;
 	u32 flags, base_flags;
+	bool is_osc_granted = false;
 
 	root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
 	if (!root)
@@ -520,6 +521,60 @@ static int __devinit acpi_pci_root_add(s
 	flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
 	acpi_pci_osc_support(root, flags);
 
+	/* Indicate support for various _OSC capabilities. */
+	if (pci_ext_cfg_avail())
+		flags |= OSC_EXT_PCI_CONFIG_SUPPORT;
+	if (pcie_aspm_support_enabled()) {
+		flags |= OSC_ACTIVE_STATE_PWR_SUPPORT |
+		OSC_CLOCK_PWR_CAPABILITY_SUPPORT;
+	}
+	if (pci_msi_enabled())
+		flags |= OSC_MSI_SUPPORT;
+	if (flags != base_flags) {
+		status = acpi_pci_osc_support(root, flags);
+		if (ACPI_FAILURE(status)) {
+			dev_info(&device->dev, "ACPI _OSC support "
+				"notification failed, disabling PCIe ASPM\n");
+			pcie_no_aspm();
+			flags = base_flags;
+		}
+	}
+	if (!pcie_ports_disabled
+	    && (flags & ACPI_PCIE_REQ_SUPPORT) == ACPI_PCIE_REQ_SUPPORT) {
+		flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL
+			| OSC_PCI_EXPRESS_NATIVE_HP_CONTROL
+			| OSC_PCI_EXPRESS_PME_CONTROL;
+
+		if (pci_aer_available()) {
+			if (aer_acpi_firmware_first())
+				dev_dbg(&device->dev,
+					"PCIe errors handled by BIOS.\n");
+			else
+				flags |= OSC_PCI_EXPRESS_AER_CONTROL;
+		}
+
+		dev_info(&device->dev,
+			"Requesting ACPI _OSC control (0x%02x)\n", flags);
+
+		status = acpi_pci_osc_control_set(device->handle, &flags,
+				       OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
+		if (ACPI_SUCCESS(status)) {
+			is_osc_granted = true;
+			dev_info(&device->dev,
+				"ACPI _OSC control (0x%02x) granted\n", flags);
+		} else {
+			is_osc_granted = false;
+			dev_info(&device->dev,
+				"ACPI _OSC request failed (%s), "
+				"returned control mask: 0x%02x\n",
+				acpi_format_exception(status), flags);
+		}
+	} else {
+		dev_info(&device->dev,
+			"Unable to request _OSC control "
+			"(_OSC support mask: 0x%02x)\n", flags);
+	}
+
 	/*
 	 * TBD: Need PCI interface for enumeration/configuration of roots.
 	 */
@@ -563,66 +618,14 @@ static int __devinit acpi_pci_root_add(s
 	list_for_each_entry(child, &device->children, node)
 		acpi_pci_bridge_scan(child);
 
-	/* Indicate support for various _OSC capabilities. */
-	if (pci_ext_cfg_avail())
-		flags |= OSC_EXT_PCI_CONFIG_SUPPORT;
-	if (pcie_aspm_support_enabled())
-		flags |= OSC_ACTIVE_STATE_PWR_SUPPORT |
-			OSC_CLOCK_PWR_CAPABILITY_SUPPORT;
-	if (pci_msi_enabled())
-		flags |= OSC_MSI_SUPPORT;
-	if (flags != base_flags) {
-		status = acpi_pci_osc_support(root, flags);
-		if (ACPI_FAILURE(status)) {
-			dev_info(root->bus->bridge, "ACPI _OSC support "
-				"notification failed, disabling PCIe ASPM\n");
-			pcie_no_aspm();
-			flags = base_flags;
-		}
-	}
-
-	if (!pcie_ports_disabled
-	    && (flags & ACPI_PCIE_REQ_SUPPORT) == ACPI_PCIE_REQ_SUPPORT) {
-		flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL
-			| OSC_PCI_EXPRESS_NATIVE_HP_CONTROL
-			| OSC_PCI_EXPRESS_PME_CONTROL;
-
-		if (pci_aer_available()) {
-			if (aer_acpi_firmware_first())
-				dev_dbg(root->bus->bridge,
-					"PCIe errors handled by BIOS.\n");
-			else
-				flags |= OSC_PCI_EXPRESS_AER_CONTROL;
-		}
-
-		dev_info(root->bus->bridge,
-			"Requesting ACPI _OSC control (0x%02x)\n", flags);
-
-		status = acpi_pci_osc_control_set(device->handle, &flags,
-					OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
-		if (ACPI_SUCCESS(status)) {
-			dev_info(root->bus->bridge,
-				"ACPI _OSC control (0x%02x) granted\n", flags);
-			if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM) {
-				/*
-				 * We have ASPM control, but the FADT indicates
-				 * that it's unsupported. Clear it.
-				 */
-				pcie_clear_aspm(root->bus);
-			}
-		} else {
-			dev_info(root->bus->bridge,
-				"ACPI _OSC request failed (%s), "
-				"returned control mask: 0x%02x\n",
-				acpi_format_exception(status), flags);
-			pr_info("ACPI _OSC control for PCIe not granted, "
-				"disabling ASPM\n");
-			pcie_no_aspm();
-		}
+	/* ASPM setting */
+	if (is_osc_granted) {
+		if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM)
+			pcie_clear_aspm(root->bus);
 	} else {
-		dev_info(root->bus->bridge,
-			 "Unable to request _OSC control "
-			 "(_OSC support mask: 0x%02x)\n", flags);
+		pr_info("ACPI _OSC control for PCIe not granted, "
+			"disabling ASPM\n");
+		pcie_no_aspm();
 	}
 
 	pci_acpi_add_bus_pm_notifier(device, root->bus);
maintainer
#6 lore raw
In reply to Taku Izumi
Quoted 7 lines · Taku Izumi

Hi all,

This patchset is to disentangle ACPI-related code and PCI-related code at hostbridge addition/removal code.
This is based on the comment Bjorn suggested at
http://marc.info/?l=linux-pci&m=134825820111705&w=2

Quoted 5 lines

* [PATCH 1/5] ACPI: Pass segment/bus to _PRT add/del so they don't depend on pci_bus
* [PATCH 2/5] PCI,ACPI: Add _PRT interrupt routing info before enumerating devices
* [PATCH 3/5] PCI,ACPI: Remove _PRT info when removing a host bridge
* [PATCH 4/5] PCI: Change the signature of pci_ext_cfg_avail function
* [PATCH 5/5] PCI,ACPI: Requesting _OSC control before scanning pci tree in acpi_pci_root_add()

I applied these to my pci/taku-prt-cleanup branch (based on pci/yinghai-for-pci-root-bus-hotplug) as v3.8 material. Yinghai's patches already included 3/5, so that one was redundant.

Thanks!