Skip to contentSkip to conversation

PCI: acpi_pcihp, run _OSC on a root bridge

PATCH In review Jiri Slaby 3 participants 8 messages Aug 11, 2008 – Aug 18, 2008

Subsystems (2)
lore
Share & tools
lore

Jiri Slaby

author
#0 lore raw

PATCH 1/1 PCI: acpi_pcihp, run _OSC on a root bridge

_OSC should be ran on a root bridge instead of the device itself. Do this before touching OSHP since PCI fw specs states that _OSC should be preferred over OSHP (however if the device has OSHP but not _OSC -- not a root bridge -- it's not).

---
 drivers/pci/hotplug/acpi_pcihp.c |   41 ++++++++++++++++++++++++++-----------
 1 files changed, 29 insertions(+), 12 deletions(-)
drivers/pci/hotplug/acpi_pcihp.c +29 -12
index 93e37f0..bd83197 100644
@@ -382,7 +382,7 @@ EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware);
 int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags)
 {
 	acpi_status status;
-	acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
+	acpi_handle chandle, handle;
 	struct pci_dev *pdev = dev;
 	struct pci_bus *parent;
 	struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
@@ -399,10 +399,28 @@ int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags)
 	 * Per PCI firmware specification, we should run the ACPI _OSC
 	 * method to get control of hotplug hardware before using it. If
 	 * an _OSC is missing, we look for an OSHP to do the same thing.
-	 * To handle different BIOS behavior, we look for _OSC and OSHP
-	 * within the scope of the hotplug controller and its parents,
+	 * To handle different BIOS behavior, we look for _OSC on a root
+	 * bridge preferentially (according to PCI fw spec). Later for
+	 * OSHP within the scope of the hotplug controller and its parents,
 	 * upto the host bridge under which this controller exists.
 	 */
+	while (pdev->bus->self)
+		pdev = pdev->bus->self;
+	handle = acpi_get_pci_rootbridge_handle(pci_domain_nr(pdev->bus),
+			pdev->bus->number);
+	if (handle) {
+		acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
+		dbg("Trying to get hotplug control for %s\n",
+				(char *)string.pointer);
+		status = pci_osc_control_set(handle, flags);
+		if (ACPI_SUCCESS(status))
+			goto got_one;
+		kfree(string.pointer);
+		string = (struct acpi_buffer){ ACPI_ALLOCATE_BUFFER, NULL };
+	}
+
+	pdev = dev;
+	handle = DEVICE_ACPI_HANDLE(&dev->dev);
 	while (!handle) {
 		/*
 		 * This hotplug controller was not listed in the ACPI name
@@ -427,15 +445,9 @@ int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags)
 		acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
 		dbg("Trying to get hotplug control for %s \n",
 		    (char *)string.pointer);
-		status = pci_osc_control_set(handle, flags);
-		if (status == AE_NOT_FOUND)
-			status = acpi_run_oshp(handle);
-		if (ACPI_SUCCESS(status)) {
-			dbg("Gained control for hotplug HW for pci %s (%s)\n",
-			    pci_name(dev), (char *)string.pointer);
-			kfree(string.pointer);
-			return 0;
-		}
+		status = acpi_run_oshp(handle);
+		if (ACPI_SUCCESS(status))
+			goto got_one;
 		if (acpi_root_bridge(handle))
 			break;
 		chandle = handle;
@@ -449,6 +461,11 @@ int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags)
 
 	kfree(string.pointer);
 	return -ENODEV;
+got_one:
+	dbg("Gained control for hotplug HW for pci %s (%s)\n", pci_name(dev),
+			(char *)string.pointer);
+	kfree(string.pointer);
+	return 0;
 }
 EXPORT_SYMBOL(acpi_get_hp_hw_control_from_firmware);
 
Signature · 1 line
1.5.6.5
#1 lore raw

[Cc'ing Alex & Kenji-san for their comments on this fix.]

Quoted 90 lines · Jiri Slaby

_OSC should be ran on a root bridge instead of the device itself. Do this before touching OSHP since PCI fw specs states that _OSC should be preferred over OSHP (however if the device has OSHP but not _OSC -- not a root bridge -- it's not).

---
 drivers/pci/hotplug/acpi_pcihp.c |   41

++++++++++++++++++++++++++----------- 1 files changed, 29 insertions(+), 12 deletions(-)

(quoted diff) +0 -0

b/drivers/pci/hotplug/acpi_pcihp.c index 93e37f0..bd83197 100644

drivers/pci/hotplug/acpi_pcihp.c +1 -1
@@ -382,7 +382,7 @@ EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware);
 int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags)
 {
 	acpi_status status;
-	acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
+	acpi_handle chandle, handle;
 	struct pci_dev *pdev = dev;
 	struct pci_bus *parent;
 	struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
@@ -399,10 +399,28 @@ int acpi_get_hp_hw_control_from_firmware(struct

pci_dev *dev, u32 flags) * Per PCI firmware specification, we should run the ACPI _OSC

drivers/pci/hotplug/acpi_pcihp.c +23 -11
 	 * method to get control of hotplug hardware before using it. If
 	 * an _OSC is missing, we look for an OSHP to do the same thing.
-	 * To handle different BIOS behavior, we look for _OSC and OSHP
-	 * within the scope of the hotplug controller and its parents,
+	 * To handle different BIOS behavior, we look for _OSC on a root
+	 * bridge preferentially (according to PCI fw spec). Later for
+	 * OSHP within the scope of the hotplug controller and its parents,
 	 * upto the host bridge under which this controller exists.
 	 */
+	while (pdev->bus->self)
+		pdev = pdev->bus->self;
+	handle = acpi_get_pci_rootbridge_handle(pci_domain_nr(pdev->bus),
+			pdev->bus->number);
+	if (handle) {
+		acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
+		dbg("Trying to get hotplug control for %s\n",
+				(char *)string.pointer);
+		status = pci_osc_control_set(handle, flags);
+		if (ACPI_SUCCESS(status))
+			goto got_one;
+		kfree(string.pointer);
+		string = (struct acpi_buffer){ ACPI_ALLOCATE_BUFFER, NULL };
+	}
+
+	pdev = dev;
+	handle = DEVICE_ACPI_HANDLE(&dev->dev);
 	while (!handle) {
 		/*
 		 * This hotplug controller was not listed in the ACPI name
@@ -427,15 +445,9 @@ int acpi_get_hp_hw_control_from_firmware(struct
 pci_dev *dev, u32 flags) acpi_get_name(handle, ACPI_FULL_PATHNAME,
 &string);
 		dbg("Trying to get hotplug control for %s \n",
 		    (char *)string.pointer);
-		status = pci_osc_control_set(handle, flags);
-		if (status == AE_NOT_FOUND)
-			status = acpi_run_oshp(handle);
-		if (ACPI_SUCCESS(status)) {
-			dbg("Gained control for hotplug HW for pci %s (%s)\n",
-			    pci_name(dev), (char *)string.pointer);
-			kfree(string.pointer);
-			return 0;
-		}
+		status = acpi_run_oshp(handle);
+		if (ACPI_SUCCESS(status))
+			goto got_one;
 		if (acpi_root_bridge(handle))
 			break;
drivers/pci/hotplug/acpi_pcihp.c +5 -0
 		chandle = handle;
@@ -449,6 +461,11 @@ int acpi_get_hp_hw_control_from_firmware(struct
 pci_dev *dev, u32 flags)
 
 	kfree(string.pointer);
 	return -ENODEV;
+got_one:
+	dbg("Gained control for hotplug HW for pci %s (%s)\n", pci_name(dev),
+			(char *)string.pointer);
+	kfree(string.pointer);
+	return 0;
 }
 EXPORT_SYMBOL(acpi_get_hp_hw_control_from_firmware);
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Acked-by
#2 lore raw

* Jesse Barnes <[email protected]>:

Quoted 7 lines

[Cc'ing Alex & Kenji-san for their comments on this fix.]

Quoted 4 lines · Jiri Slaby

_OSC should be ran on a root bridge instead of the device itself. Do this before touching OSHP since PCI fw specs states that _OSC should be preferred over OSHP (however if the device has OSHP but not _OSC -- not a root bridge -- it's not).

Reviewed the PCI fw spec (v3.0) and this code, and Jiri's change seems sane to me.

One minor nit below.

Quoted 30 lines
Quoted 30 lines
---
 drivers/pci/hotplug/acpi_pcihp.c |   41

++++++++++++++++++++++++++----------- 1 files changed, 29 insertions(+), 12 deletions(-)

(quoted diff) +0 -0

b/drivers/pci/hotplug/acpi_pcihp.c index 93e37f0..bd83197 100644

drivers/pci/hotplug/acpi_pcihp.c +1 -1
@@ -382,7 +382,7 @@ EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware);
 int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags)
 {
 	acpi_status status;
-	acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
+	acpi_handle chandle, handle;
 	struct pci_dev *pdev = dev;
 	struct pci_bus *parent;
 	struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
@@ -399,10 +399,28 @@ int acpi_get_hp_hw_control_from_firmware(struct

pci_dev *dev, u32 flags) * Per PCI firmware specification, we should run the ACPI _OSC

drivers/pci/hotplug/acpi_pcihp.c +1 -2
 	 * method to get control of hotplug hardware before using it. If
 	 * an _OSC is missing, we look for an OSHP to do the same thing.
-	 * To handle different BIOS behavior, we look for _OSC and OSHP
-	 * within the scope of the hotplug controller and its parents,
+	 * To handle different BIOS behavior, we look for _OSC on a root
Quoted 8 lines

drivers/pci/hotplug/acpi_pcihp.c int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags) · line 410

Quoted 8 lines
drivers/pci/hotplug/acpi_pcihp.c +6 -0
+	 * bridge preferentially (according to PCI fw spec). Later for
+	 * OSHP within the scope of the hotplug controller and its parents,
 	 * upto the host bridge under which this controller exists.
 	 */
+	while (pdev->bus->self)
+		pdev = pdev->bus->self;
+	handle = acpi_get_pci_rootbridge_handle(pci_domain_nr(pdev->bus),
+			pdev->bus->number);

This looks an awful lot like the first few lines of aer_osc_setup(). Any chance you could factor those lines out into a common inline?

static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)

{
	while (pdev->bus->self)
		pdev = pdev->bus->self;

	return acpi_get_pci_rootbridge_handle(pci_domain_nr(pdev->bus),
					      pdev->bus->number);
}

<linux/pci-acpi.h> might be a good place for that.

Just a thought.

But otherwise,

Thanks.

/ac

Quoted 54 lines
Quoted 48 lines
drivers/pci/hotplug/acpi_pcihp.c +16 -9
+	if (handle) {
+		acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
+		dbg("Trying to get hotplug control for %s\n",
+				(char *)string.pointer);
+		status = pci_osc_control_set(handle, flags);
+		if (ACPI_SUCCESS(status))
+			goto got_one;
+		kfree(string.pointer);
+		string = (struct acpi_buffer){ ACPI_ALLOCATE_BUFFER, NULL };
+	}
+
+	pdev = dev;
+	handle = DEVICE_ACPI_HANDLE(&dev->dev);
 	while (!handle) {
 		/*
 		 * This hotplug controller was not listed in the ACPI name
@@ -427,15 +445,9 @@ int acpi_get_hp_hw_control_from_firmware(struct
 pci_dev *dev, u32 flags) acpi_get_name(handle, ACPI_FULL_PATHNAME,
 &string);
 		dbg("Trying to get hotplug control for %s \n",
 		    (char *)string.pointer);
-		status = pci_osc_control_set(handle, flags);
-		if (status == AE_NOT_FOUND)
-			status = acpi_run_oshp(handle);
-		if (ACPI_SUCCESS(status)) {
-			dbg("Gained control for hotplug HW for pci %s (%s)\n",
-			    pci_name(dev), (char *)string.pointer);
-			kfree(string.pointer);
-			return 0;
-		}
+		status = acpi_run_oshp(handle);
+		if (ACPI_SUCCESS(status))
+			goto got_one;
 		if (acpi_root_bridge(handle))
 			break;
drivers/pci/hotplug/acpi_pcihp.c +5 -0
 		chandle = handle;
@@ -449,6 +461,11 @@ int acpi_get_hp_hw_control_from_firmware(struct
 pci_dev *dev, u32 flags)
 
 	kfree(string.pointer);
 	return -ENODEV;
+got_one:
+	dbg("Gained control for hotplug HW for pci %s (%s)\n", pci_name(dev),
+			(char *)string.pointer);
+	kfree(string.pointer);
+	return 0;
 }
 EXPORT_SYMBOL(acpi_get_hp_hw_control_from_firmware);
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
author
#3 lore raw

PATCH 1/1 PCI: add acpi_find_root_bridge_handle

Hi,

I'm sending an update proposed by Alex. Consider it and drop or merge :). --

Consolidate finding of a root bridge and getting its handle to the one inline function. It's cut&pasted on multiple places. Use this new inline in those.

Cc Jesse Barnes <[email protected]>
Cc Alex Chiang <[email protected]>
Cc Kenji Kaneshige <[email protected]>
---
 drivers/pci/hotplug/acpi_pcihp.c   |    5 +----
 drivers/pci/pcie/aer/aerdrv_acpi.c |    7 +------
 include/linux/pci-acpi.h           |   10 ++++++++++
 3 files changed, 12 insertions(+), 10 deletions(-)
drivers/pci/hotplug/acpi_pcihp.c +1 -4
index bd83197..e17ef54 100644
@@ -404,10 +404,7 @@ int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags)
 	 * OSHP within the scope of the hotplug controller and its parents,
 	 * upto the host bridge under which this controller exists.
 	 */
-	while (pdev->bus->self)
-		pdev = pdev->bus->self;
-	handle = acpi_get_pci_rootbridge_handle(pci_domain_nr(pdev->bus),
-			pdev->bus->number);
+	handle = acpi_find_root_bridge_handle(pdev);
 	if (handle) {
 		acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
 		dbg("Trying to get hotplug control for %s\n",
drivers/pci/pcie/aer/aerdrv_acpi.c +1 -6
index 30f581b..6dd7b13 100644
@@ -36,12 +36,7 @@ int aer_osc_setup(struct pcie_device *pciedev)
 	if (acpi_pci_disabled)
 		return -1;
 
-	/* Find root host bridge */
-	while (pdev->bus->self)
-		pdev = pdev->bus->self;
-	handle = acpi_get_pci_rootbridge_handle(
-		pci_domain_nr(pdev->bus), pdev->bus->number);
-
+	handle = acpi_find_root_bridge_handle(pdev);
 	if (handle) {
 		pcie_osc_support_set(OSC_EXT_PCI_CONFIG_SUPPORT);
 		status = pci_osc_control_set(handle,
include/linux/pci-acpi.h +10 -0
index 3ba2506..807847a 100644
@@ -57,6 +57,14 @@ static inline acpi_status pcie_osc_support_set(u32 flags)
 {
 	return __pci_osc_support_set(flags, PCI_EXPRESS_ROOT_HID_STRING);
 }
+static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
+{
+	while (pdev->bus->self)
+		pdev = pdev->bus->self;
+
+	return acpi_get_pci_rootbridge_handle(pci_domain_nr(pdev->bus),
+			pdev->bus->number);
+}
 #else
 #if !defined(AE_ERROR)
 typedef u32 		acpi_status;
@@ -66,6 +74,8 @@ static inline acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
 {return AE_ERROR;}
 static inline acpi_status pci_osc_support_set(u32 flags) {return AE_ERROR;} 
 static inline acpi_status pcie_osc_support_set(u32 flags) {return AE_ERROR;}
+static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
+{ return NULL; }
 #endif
 
 #endif	/* _PCI_ACPI_H_ */
Signature · 1 line
1.6.0
#4 lore raw

Re: [PATCH 1/1] PCI: add acpi_find_root_bridge_handle

* Jiri Slaby <[email protected]>:

Quoted 41 lines

Hi,

I'm sending an update proposed by Alex. Consider it and drop or merge :). --

Consolidate finding of a root bridge and getting its handle to the one inline function. It's cut&pasted on multiple places. Use this new inline in those.

Cc Jesse Barnes <[email protected]>
Cc Alex Chiang <[email protected]>
Cc Kenji Kaneshige <[email protected]>
---
 drivers/pci/hotplug/acpi_pcihp.c   |    5 +----
 drivers/pci/pcie/aer/aerdrv_acpi.c |    7 +------
 include/linux/pci-acpi.h           |   10 ++++++++++
 3 files changed, 12 insertions(+), 10 deletions(-)
drivers/pci/hotplug/acpi_pcihp.c +1 -4
index bd83197..e17ef54 100644
@@ -404,10 +404,7 @@ int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags)
 	 * OSHP within the scope of the hotplug controller and its parents,
 	 * upto the host bridge under which this controller exists.
 	 */
-	while (pdev->bus->self)
-		pdev = pdev->bus->self;
-	handle = acpi_get_pci_rootbridge_handle(pci_domain_nr(pdev->bus),
-			pdev->bus->number);
+	handle = acpi_find_root_bridge_handle(pdev);
 	if (handle) {
 		acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
 		dbg("Trying to get hotplug control for %s\n",
drivers/pci/pcie/aer/aerdrv_acpi.c +0 -0
index 30f581b..6dd7b13 100644

drivers/pci/pcie/aer/aerdrv_acpi.c int aer_osc_setup(struct pcie_device *pciedev) · line 38

Quoted 3 lines
drivers/pci/pcie/aer/aerdrv_acpi.c +0 -0
@@ -36,12 +36,7 @@ int aer_osc_setup(struct pcie_device *pciedev)
 	if (acpi_pci_disabled)
 		return -1;
 

The reason I even knew about aer_osc_setup() was because I found the while (pdev->bus->self) idiom a bit confusing, so I did a git grep to see if it was used anywhere else in the kernel. Luckily, the below comment was there, and I found it helpful.

drivers/pci/pcie/aer/aerdrv_acpi.c int aer_osc_setup(struct pcie_device *pciedev) · line 39

Quoted 1 line
drivers/pci/pcie/aer/aerdrv_acpi.c +0 -1
-	/* Find root host bridge */

So can we move this coment ^^ into your new inline below?

Thanks!

/ac

Quoted 46 lines
drivers/pci/pcie/aer/aerdrv_acpi.c +1 -5
-	while (pdev->bus->self)
-		pdev = pdev->bus->self;
-	handle = acpi_get_pci_rootbridge_handle(
-		pci_domain_nr(pdev->bus), pdev->bus->number);
-
+	handle = acpi_find_root_bridge_handle(pdev);
 	if (handle) {
 		pcie_osc_support_set(OSC_EXT_PCI_CONFIG_SUPPORT);
 		status = pci_osc_control_set(handle,
include/linux/pci-acpi.h +10 -0
index 3ba2506..807847a 100644
@@ -57,6 +57,14 @@ static inline acpi_status pcie_osc_support_set(u32 flags)
 {
 	return __pci_osc_support_set(flags, PCI_EXPRESS_ROOT_HID_STRING);
 }
+static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
+{
+	while (pdev->bus->self)
+		pdev = pdev->bus->self;
+
+	return acpi_get_pci_rootbridge_handle(pci_domain_nr(pdev->bus),
+			pdev->bus->number);
+}
 #else
 #if !defined(AE_ERROR)
 typedef u32 		acpi_status;
@@ -66,6 +74,8 @@ static inline acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
 {return AE_ERROR;}
 static inline acpi_status pci_osc_support_set(u32 flags) {return AE_ERROR;} 
 static inline acpi_status pcie_osc_support_set(u32 flags) {return AE_ERROR;}
+static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
+{ return NULL; }
 #endif
 
 #endif	/* _PCI_ACPI_H_ */
Signature · 7 lines
1.6.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
author
#5 lore raw

PATCH 1/1 PCI: add acpi_find_root_bridge_handle

Consolidate finding of a root bridge and getting its handle to the one inline function. It's cut&pasted on multiple places. Use this new inline in those.

Updates:
- added a comment to the acpi_find_root_bridge_handle

Cc Jesse Barnes <[email protected]>
Cc Alex Chiang <[email protected]>
Cc Kenji Kaneshige <[email protected]>
---
 drivers/pci/hotplug/acpi_pcihp.c   |    5 +----
 drivers/pci/pcie/aer/aerdrv_acpi.c |    7 +------
 include/linux/pci-acpi.h           |   11 +++++++++++
 3 files changed, 13 insertions(+), 10 deletions(-)
drivers/pci/hotplug/acpi_pcihp.c +1 -4
index bd83197..e17ef54 100644
@@ -404,10 +404,7 @@ int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags)
 	 * OSHP within the scope of the hotplug controller and its parents,
 	 * upto the host bridge under which this controller exists.
 	 */
-	while (pdev->bus->self)
-		pdev = pdev->bus->self;
-	handle = acpi_get_pci_rootbridge_handle(pci_domain_nr(pdev->bus),
-			pdev->bus->number);
+	handle = acpi_find_root_bridge_handle(pdev);
 	if (handle) {
 		acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
 		dbg("Trying to get hotplug control for %s\n",
drivers/pci/pcie/aer/aerdrv_acpi.c +1 -6
index 30f581b..6dd7b13 100644
@@ -36,12 +36,7 @@ int aer_osc_setup(struct pcie_device *pciedev)
 	if (acpi_pci_disabled)
 		return -1;
 
-	/* Find root host bridge */
-	while (pdev->bus->self)
-		pdev = pdev->bus->self;
-	handle = acpi_get_pci_rootbridge_handle(
-		pci_domain_nr(pdev->bus), pdev->bus->number);
-
+	handle = acpi_find_root_bridge_handle(pdev);
 	if (handle) {
 		pcie_osc_support_set(OSC_EXT_PCI_CONFIG_SUPPORT);
 		status = pci_osc_control_set(handle,
include/linux/pci-acpi.h +11 -0
index 3ba2506..8837928 100644
@@ -57,6 +57,15 @@ static inline acpi_status pcie_osc_support_set(u32 flags)
 {
 	return __pci_osc_support_set(flags, PCI_EXPRESS_ROOT_HID_STRING);
 }
+static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
+{
+	/* Find root host bridge */
+	while (pdev->bus->self)
+		pdev = pdev->bus->self;
+
+	return acpi_get_pci_rootbridge_handle(pci_domain_nr(pdev->bus),
+			pdev->bus->number);
+}
 #else
 #if !defined(AE_ERROR)
 typedef u32 		acpi_status;
@@ -66,6 +75,8 @@ static inline acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
 {return AE_ERROR;}
 static inline acpi_status pci_osc_support_set(u32 flags) {return AE_ERROR;} 
 static inline acpi_status pcie_osc_support_set(u32 flags) {return AE_ERROR;}
+static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
+{ return NULL; }
 #endif
 
 #endif	/* _PCI_ACPI_H_ */
Signature · 1 line
1.5.6.5
Acked-by on v1 1/1
#6 lore raw

Re: [PATCH 1/1 #2] PCI: add acpi_find_root_bridge_handle

* Jiri Slaby <[email protected]>:

Quoted 6 lines

Consolidate finding of a root bridge and getting its handle to the one inline function. It's cut&pasted on multiple places. Use this new inline in those.

Updates:
- added a comment to the acpi_find_root_bridge_handle

Thanks.

/ac

Quoted 83 lines
Cc Jesse Barnes <[email protected]>
Cc Alex Chiang <[email protected]>
Cc Kenji Kaneshige <[email protected]>
---
 drivers/pci/hotplug/acpi_pcihp.c   |    5 +----
 drivers/pci/pcie/aer/aerdrv_acpi.c |    7 +------
 include/linux/pci-acpi.h           |   11 +++++++++++
 3 files changed, 13 insertions(+), 10 deletions(-)
drivers/pci/hotplug/acpi_pcihp.c +1 -4
index bd83197..e17ef54 100644
@@ -404,10 +404,7 @@ int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags)
 	 * OSHP within the scope of the hotplug controller and its parents,
 	 * upto the host bridge under which this controller exists.
 	 */
-	while (pdev->bus->self)
-		pdev = pdev->bus->self;
-	handle = acpi_get_pci_rootbridge_handle(pci_domain_nr(pdev->bus),
-			pdev->bus->number);
+	handle = acpi_find_root_bridge_handle(pdev);
 	if (handle) {
 		acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
 		dbg("Trying to get hotplug control for %s\n",
drivers/pci/pcie/aer/aerdrv_acpi.c +1 -6
index 30f581b..6dd7b13 100644
@@ -36,12 +36,7 @@ int aer_osc_setup(struct pcie_device *pciedev)
 	if (acpi_pci_disabled)
 		return -1;
 
-	/* Find root host bridge */
-	while (pdev->bus->self)
-		pdev = pdev->bus->self;
-	handle = acpi_get_pci_rootbridge_handle(
-		pci_domain_nr(pdev->bus), pdev->bus->number);
-
+	handle = acpi_find_root_bridge_handle(pdev);
 	if (handle) {
 		pcie_osc_support_set(OSC_EXT_PCI_CONFIG_SUPPORT);
 		status = pci_osc_control_set(handle,
include/linux/pci-acpi.h +11 -0
index 3ba2506..8837928 100644
@@ -57,6 +57,15 @@ static inline acpi_status pcie_osc_support_set(u32 flags)
 {
 	return __pci_osc_support_set(flags, PCI_EXPRESS_ROOT_HID_STRING);
 }
+static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
+{
+	/* Find root host bridge */
+	while (pdev->bus->self)
+		pdev = pdev->bus->self;
+
+	return acpi_get_pci_rootbridge_handle(pci_domain_nr(pdev->bus),
+			pdev->bus->number);
+}
 #else
 #if !defined(AE_ERROR)
 typedef u32 		acpi_status;
@@ -66,6 +75,8 @@ static inline acpi_status pci_osc_control_set(acpi_handle handle, u32 flags)
 {return AE_ERROR;}
 static inline acpi_status pci_osc_support_set(u32 flags) {return AE_ERROR;} 
 static inline acpi_status pcie_osc_support_set(u32 flags) {return AE_ERROR;}
+static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
+{ return NULL; }
 #endif
 
 #endif	/* _PCI_ACPI_H_ */
Signature · 6 lines
1.5.6.5

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw
In reply to Jiri Slaby
Quoted 8 lines · Jiri Slaby

_OSC should be ran on a root bridge instead of the device itself. Do this before touching OSHP since PCI fw specs states that _OSC should be preferred over OSHP (however if the device has OSHP but not _OSC -- not a root bridge -- it's not).

Thanks Jiri, I applied both of these to my for-linus branch.

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center