Refactor pci_is_brdige() to simplify code
v2 cover Refactor pci_is_brdige() to simplify code
v1->v2: Add comments for new pci_is_bridge().
This patchset rename the current pci_is_bridge() to pci_has_subordinate(), and introduce a new pci_is_bridge() which determine pci bridge by check dev->hdr_type. The new one is more accurate. PCI Spec define the pci device is a bridge by the dev->hdr_type = 0x01 || 0x02.
There is no guarantee that a PCI bridge must attached a subordinate bus. When PCI bridge is created but before the scan child bus, it has no subordinate bus. Also users can remove the pci bus using interface pci_remove_bus() in remove.c.
So use new pci_is_bridge() check if the PCI device is bridge is better choice. If user want check PCI bridge whether has a subordinate bus, pci_has_subordinate() is a candidate.
Yijing Wang (13):
PCI: rename pci_is_bridge() to pci_has_subordinate()
PCI: Introduce new pci_is_bridge() helper function
PCI: Use new pci_is_bridge() to simplify code x86/PCI: Use new pci_is_bridge() to simplify code IA64/PCI: Use new pci_is_bridge() to simplify code powerpc/PCI: Use new pci_is_bridge() to simplify code sparc/PCI: Use new pci_is_bridge() to simplify code PCI, rpaphp: Use new pci_is_bridge() to simplify code PCI, shpchp: Use new pci_is_bridge() to simplify code PCI, cpcihp: Use new pci_is_bridge() to simplify code PCI, acpiphp: Use new pci_is_bridge() to simplify code PCI, pcmcia: Use new pci_is_bridge() to simplify code PCI, pciehp: Use new pci_is_bridge() to simplify code
arch/ia64/pci/fixup.c | 4 +--- arch/powerpc/kernel/pci-hotplug.c | 3 +-- arch/powerpc/kernel/pci_of_scan.c | 3 +-- arch/sparc/kernel/pci.c | 3 +-- arch/x86/pci/fixup.c | 4 +--- drivers/pci/hotplug/acpiphp_glue.c | 3 +-- drivers/pci/hotplug/cpci_hotplug_pci.c | 3 +-- drivers/pci/hotplug/pciehp_pci.c | 3 +-- drivers/pci/hotplug/rpadlpar_core.c | 3 +-- drivers/pci/hotplug/shpchp_pci.c | 3 +-- drivers/pci/pci-acpi.c | 8 +------- drivers/pci/pci-driver.c | 8 ++++---- drivers/pci/pci.h | 2 +- drivers/pci/probe.c | 3 +-- drivers/pci/setup-bus.c | 4 +--- drivers/pcmcia/cardbus.c | 3 +-- include/linux/pci.h | 13 +++++++++++++ 17 files changed, 32 insertions(+), 41 deletions(-)
PATCH v2 1/13 PCI: rename pci_is_bridge() to pci_has_subordinate()
pci_is_bridge() which seems to determine whether device is a bridge, returns true only when the subordinate bus exists. This confuses people. PCI device is a bridge means its header type(bit 0 through 6) is 0x1(PCI bridge) or 0x2(CardBus bridge). Rename the current pci_is_bridge() helper function to pci_has_subordinate().
--- drivers/pci/pci-driver.c | 8 ++++---- drivers/pci/pci.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/pci/pci-driver.c +4 -4
@@ -580,14 +580,14 @@ static void pci_pm_default_resume(struct pci_dev *pci_dev) {pci_fixup_device (pci_fixup_resume, pci_dev); -if (!pci_is_bridge (pci_dev)) +if (!pci_has_subordinate (pci_dev))pci_enable_wake (pci_dev,PCI_D0 , false); }static void pci_pm_default_suspend (struct pci_dev *pci_dev) {/* Disable non-bridge devices without PM support */ -if (!pci_is_bridge (pci_dev)) +if (!pci_has_subordinate (pci_dev))pci_disable_enabled_device (pci_dev); }
@@ -717,7 +717,7 @@ static int pci_pm_suspend_noirq(struct device *dev)if (!pci_dev->state_saved) {pci_save_state (pci_dev); -if (!pci_is_bridge (pci_dev)) +if (!pci_has_subordinate (pci_dev))pci_prepare_to_sleep (pci_dev); }
@@ -971,7 +971,7 @@ static int pci_pm_poweroff_noirq(struct device *dev)return error; } -if (!pci_dev->state_saved && !pci_is_bridge (pci_dev)) +if (!pci_dev->state_saved && !pci_has_subordinate (pci_dev))pci_prepare_to_sleep (pci_dev);/*
drivers/pci/pci.h +1 -1
@@ -77,7 +77,7 @@ static inline void pci_wakeup_event(struct pci_dev *dev)pm_wakeup_event (&dev->dev,100 ); } -static inline bool pci_is_bridge (struct pci_dev *pci_dev) +static inline bool pci_has_subordinate (struct pci_dev *pci_dev) {return !!(pci_dev->subordinate); }
Signature · 1 line
1.7.1
PATCH v2 2/13 PCI: Introduce new pci_is_bridge() helper function
In reply to Yijing WangPCIe Spec define the PCI bridge is the PCI device which header type(bit 0 through 6) is 0x1(PCI bridge) or 0x2(CardBus bridge).
--- include/linux/pci.h | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
include/linux/pci.h +13 -0
@@ -477,6 +477,19 @@ static inline bool pci_is_root_bus(struct pci_bus *pbus)return !(pbus->parent); } +/** +* pci_is_bridge - check if the PCI device is a bridge +* @dev: PCI device +* +* Return true if the PCI device is bridge whether it has subordinate +* or not. +*/ +static inline bool pci_is_bridge (struct pci_dev *dev) +{ +return dev->hdr_type =PCI_HEADER_TYPE_BRIDGE || + dev->hdr_type =PCI_HEADER_TYPE_CARDBUS ; +} +static inline struct pci_dev *pci_upstream_bridge (struct pci_dev *dev) { dev =pci_physfn (dev);
Signature · 1 line
1.7.1
PATCH v2 3/13 PCI: Use new pci_is_bridge() to simplify code
In reply to Yijing WangNow we can use new pci_is_bridge() helper function to simplify code.
--- drivers/pci/pci-acpi.c | 8 +------- drivers/pci/probe.c | 3 +-- drivers/pci/setup-bus.c | 4 +--- 3 files changed, 3 insertions(+), 12 deletions(-)
drivers/pci/pci-acpi.c +1 -7
@@ -309,13 +309,7 @@ static struct acpi_device *acpi_pci_find_companion(struct device *dev)bool check_children;u64 addr; -/* -* pci_is_bridge() is not suitable here, because pci_dev->subordinate -* is set only after acpi_pci_find_device() has been called for the -* given device. -*/ - check_children = pci_dev->hdr_type =PCI_HEADER_TYPE_BRIDGE - || pci_dev->hdr_type =PCI_HEADER_TYPE_CARDBUS ; + check_children =pci_is_bridge (pci_dev);/* Please ref to ACPI spec for the syntax of _ADR */ addr = (PCI_SLOT (pci_dev->devfn) <<16 ) |PCI_FUNC (pci_dev->devfn); return acpi_find_child_device(ACPI_COMPANION(dev->parent), addr,
drivers/pci/probe.c +1 -2
@@ -1670,8 +1670,7 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus)for (pass=0 ; pass <2 ; pass++)list_for_each_entry (dev, &bus->devices, bus_list) { -if (dev->hdr_type =PCI_HEADER_TYPE_BRIDGE || - dev->hdr_type =PCI_HEADER_TYPE_CARDBUS ) +if (pci_is_bridge (dev)) max =pci_scan_bridge (bus, dev, max, pass); }
drivers/pci/setup-bus.c +1 -3
@@ -1629,9 +1629,7 @@ void pci_assign_unassigned_bus_resources(struct pci_bus *bus)down_read (&pci_bus_sem);list_for_each_entry (dev, &bus->devices, bus_list) -if (dev->hdr_type =PCI_HEADER_TYPE_BRIDGE || - dev->hdr_type =PCI_HEADER_TYPE_CARDBUS ) -if (dev->subordinate) +if (pci_is_bridge (dev) &&pci_has_subordinate (dev))__pci_bus_size_bridges (dev->subordinate, &add_list);up_read (&pci_bus_sem);
Signature · 1 line
1.7.1
PATCH v2 4/13 x86/PCI: Use new pci_is_bridge() to simplify code
In reply to Yijing WangNow we can use new pci_is_bridge() helper function to simplify code.
--- arch/x86/pci/fixup.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
arch/x86/pci/fixup.c +1 -3
@@ -337,9 +337,7 @@ static void pci_fixup_video(struct pci_dev *pdev)* type BRIDGE, or CARDBUS. Host to PCI controllers use * PCI header type NORMAL. */ -if (bridge - && ((bridge->hdr_type =PCI_HEADER_TYPE_BRIDGE ) - || (bridge->hdr_type =PCI_HEADER_TYPE_CARDBUS ))) { +if (bridge && (pci_is_bridge (bridge))) {pci_read_config_word (bridge,PCI_BRIDGE_CONTROL , &config);if (!(config &PCI_BRIDGE_CTL_VGA ))
Signature · 1 line
1.7.1
PATCH v2 5/13 IA64/PCI: Use new pci_is_bridge() to simplify code
In reply to Yijing WangNow we can use new pci_is_bridge() helper function to simplify code.
--- arch/ia64/pci/fixup.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
arch/ia64/pci/fixup.c +1 -3
@@ -49,9 +49,7 @@ static void pci_fixup_video(struct pci_dev *pdev)* type BRIDGE, or CARDBUS. Host to PCI controllers use * PCI header type NORMAL. */ -if (bridge - &&((bridge->hdr_type =PCI_HEADER_TYPE_BRIDGE ) - ||(bridge->hdr_type =PCI_HEADER_TYPE_CARDBUS ))) { +if (bridge && (pci_is_bridge (bridge))) {pci_read_config_word (bridge,PCI_BRIDGE_CONTROL , &config);if (!(config &PCI_BRIDGE_CTL_VGA ))
Signature · 1 line
1.7.1
PATCH v2 6/13 powerpc/PCI: Use new pci_is_bridge() to simplify code
In reply to Yijing WangNow we can use new pci_is_bridge() helper function to simplify code.
--- arch/powerpc/kernel/pci-hotplug.c | 3 +-- arch/powerpc/kernel/pci_of_scan.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
arch/powerpc/kernel/pci-hotplug.c +1 -2
@@ -98,8 +98,7 @@ void pcibios_add_pci_devices(struct pci_bus * bus) max = bus->busn_res.start;for (pass =0 ; pass <2 ; pass++) {list_for_each_entry (dev, &bus->devices, bus_list) { -if (dev->hdr_type =PCI_HEADER_TYPE_BRIDGE || - dev->hdr_type =PCI_HEADER_TYPE_CARDBUS ) +if (pci_is_bridge (dev)) max =pci_scan_bridge (bus, dev, max, pass); }
arch/powerpc/kernel/pci_of_scan.c +1 -2
@@ -362,8 +362,7 @@ static void __of_scan_bus(struct device_node *node, struct pci_bus *bus,/* Now scan child busses */ list_for_each_entry (dev, &bus->devices, bus_list) { -if (dev->hdr_type =PCI_HEADER_TYPE_BRIDGE || - dev->hdr_type =PCI_HEADER_TYPE_CARDBUS ) { +if (pci_is_bridge (dev)) {of_scan_pci_bridge (dev); } }
Signature · 1 line
1.7.1
PATCH v2 7/13 sparc/PCI: Use new pci_is_bridge() to simplify code
In reply to Yijing WangNow we can use new pci_is_bridge() helper function to simplify code.
--- arch/sparc/kernel/pci.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
arch/sparc/kernel/pci.c +1 -2
@@ -543,8 +543,7 @@ static void pci_of_scan_bus(struct pci_pbm_info *pbm,printk ("PCI: dev header type: %x\n" , dev->hdr_type); -if (dev->hdr_type =PCI_HEADER_TYPE_BRIDGE || - dev->hdr_type =PCI_HEADER_TYPE_CARDBUS ) +if (pci_is_bridge (dev))of_scan_pci_bridge (pbm, child, dev); } }
Signature · 1 line
1.7.1
PATCH v2 8/13 PCI, rpaphp: Use new pci_is_bridge() to simplify code
In reply to Yijing WangNow we can use new pci_is_bridge() helper function to simplify code.
--- drivers/pci/hotplug/rpadlpar_core.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/pci/hotplug/rpadlpar_core.c +1 -2
@@ -157,8 +157,7 @@ static void dlpar_pci_add_bus(struct device_node *dn) }/* Scan below the new bridge */ -if (dev->hdr_type =PCI_HEADER_TYPE_BRIDGE || - dev->hdr_type =PCI_HEADER_TYPE_CARDBUS ) +if (pci_is_bridge (dev))of_scan_pci_bridge (dev);/* Map IO space for child bus, which may or may not succeed */
Signature · 1 line
1.7.1
PATCH v2 9/13 PCI, shpchp: Use new pci_is_bridge() to simplify code
In reply to Yijing WangNow we can use new pci_is_bridge() helper function to simplify code.
--- drivers/pci/hotplug/shpchp_pci.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/pci/hotplug/shpchp_pci.c +1 -2
@@ -64,8 +64,7 @@ int __ref shpchp_configure_device(struct slot *p_slot)list_for_each_entry (dev, &parent->devices, bus_list) {if (PCI_SLOT (dev->devfn) != p_slot->device)continue ; -if ((dev->hdr_type =PCI_HEADER_TYPE_BRIDGE ) || - (dev->hdr_type =PCI_HEADER_TYPE_CARDBUS )) +if (pci_is_bridge (dev))pci_hp_add_bridge (dev); }
Signature · 1 line
1.7.1
PATCH v2 10/13 PCI, cpcihp: Use new pci_is_bridge() to simplify code
In reply to Yijing WangNow we can use new pci_is_bridge() helper function to simplify code.
--- drivers/pci/hotplug/cpci_hotplug_pci.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/pci/hotplug/cpci_hotplug_pci.c +1 -2
@@ -289,8 +289,7 @@ int __ref cpci_configure_slot(struct slot *slot)list_for_each_entry (dev, &parent->devices, bus_list)if (PCI_SLOT (dev->devfn) !=PCI_SLOT (slot->devfn))continue ; -if ((dev->hdr_type =PCI_HEADER_TYPE_BRIDGE ) || - (dev->hdr_type =PCI_HEADER_TYPE_CARDBUS )) +if (pci_is_bridge (dev))pci_hp_add_bridge (dev);
Signature · 1 line
1.7.1
PATCH v2 11/13 PCI, acpiphp: Use new pci_is_bridge() to simplify code
In reply to Yijing WangNow we can use new pci_is_bridge() helper function to simplify code.
--- drivers/pci/hotplug/acpiphp_glue.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +1 -2
@@ -516,8 +516,7 @@ static void __ref enable_slot(struct acpiphp_slot *slot)if (PCI_SLOT (dev->devfn) != slot->device)continue ; -if (dev->hdr_type =PCI_HEADER_TYPE_BRIDGE || - dev->hdr_type =PCI_HEADER_TYPE_CARDBUS ) { +if (pci_is_bridge (dev)) { max =pci_scan_bridge (bus, dev, max, pass);if (pass && dev->subordinate) {check_hotplug_bridge (slot, dev);
Signature · 1 line
1.7.1
PATCH v2 12/13 PCI, pcmcia: Use new pci_is_bridge() to simplify code
In reply to Yijing WangNow we can use new pci_is_bridge() helper function to simplify code.
--- drivers/pcmcia/cardbus.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/pcmcia/cardbus.c +1 -2
@@ -78,8 +78,7 @@ int __ref cb_alloc(struct pcmcia_socket *s) max = bus->busn_res.start;for (pass =0 ; pass <2 ; pass++)list_for_each_entry (dev, &bus->devices, bus_list) -if (dev->hdr_type =PCI_HEADER_TYPE_BRIDGE || - dev->hdr_type =PCI_HEADER_TYPE_CARDBUS ) +if (pci_is_bridge (dev)) max =pci_scan_bridge (bus, dev, max, pass);/*
Signature · 1 line
1.7.1
PATCH v2 13/13 PCI, pciehp: Use new pci_is_bridge() to simplify code
In reply to Yijing WangNow we can use new pci_is_bridge() helper function to simplify code.
--- drivers/pci/hotplug/pciehp_pci.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/pci/hotplug/pciehp_pci.c +1 -2
@@ -62,8 +62,7 @@ int pciehp_configure_device(struct slot *p_slot) }list_for_each_entry (dev, &parent->devices, bus_list) -if ((dev->hdr_type =PCI_HEADER_TYPE_BRIDGE ) || - (dev->hdr_type =PCI_HEADER_TYPE_CARDBUS )) +if (pci_is_bridge (dev))pci_hp_add_bridge (dev);pci_assign_unassigned_bridge_resources (bridge);
Signature · 1 line
1.7.1
Quoted 42 lines · Yijing Wang
v1->v2: Add comments for newpci_is_bridge().This patchset rename the current
pci_is_bridge()topci_has_subordinate(), and introduce a newpci_is_bridge()which determine pci bridge by checkdev->hdr_type. The new one is more accurate. PCI Spec define the pci device is a bridge by thedev->hdr_type=0x01||0x02.There is no guarantee that a PCI bridge must attached a subordinate bus. When PCI bridge is created but before the scan child bus, it has no subordinate bus. Also users can remove the pci bus using interface
pci_remove_bus()inremove.c.So use new
pci_is_bridge()check if the PCI device is bridge is better choice. If user want check PCI bridge whether has a subordinate bus,pci_has_subordinate()is a candidate.Yijing Wang (13):
PCI: renamepci_is_bridge()topci_has_subordinate()
PCI: Introduce newpci_is_bridge()helper function
PCI: Use newpci_is_bridge()to simplify code x86/PCI: Use newpci_is_bridge()to simplify code IA64/PCI: Use newpci_is_bridge()to simplify code powerpc/PCI: Use newpci_is_bridge()to simplify code sparc/PCI: Use newpci_is_bridge()to simplify code PCI, rpaphp: Use newpci_is_bridge()to simplify code PCI, shpchp: Use newpci_is_bridge()to simplify code PCI, cpcihp: Use newpci_is_bridge()to simplify code PCI, acpiphp: Use newpci_is_bridge()to simplify code PCI, pcmcia: Use newpci_is_bridge()to simplify code PCI, pciehp: Use newpci_is_bridge()to simplify codearch/ia64/pci/fixup.c | 4 +--- arch/powerpc/kernel/pci-hotplug.c | 3 +-- arch/powerpc/kernel/pci_of_scan.c | 3 +-- arch/sparc/kernel/pci.c | 3 +-- arch/x86/pci/fixup.c | 4 +--- drivers/pci/hotplug/acpiphp_glue.c | 3 +-- drivers/pci/hotplug/cpci_hotplug_pci.c | 3 +-- drivers/pci/hotplug/pciehp_pci.c | 3 +-- drivers/pci/hotplug/rpadlpar_core.c | 3 +-- drivers/pci/hotplug/shpchp_pci.c | 3 +--
Quoted 8 lines
drivers/pci/pci-acpi.c | 8 +------- drivers/pci/pci-driver.c | 8 ++++---- drivers/pci/pci.h | 2 +- drivers/pci/probe.c | 3 +-- drivers/pci/setup-bus.c | 4 +--- drivers/pcmcia/cardbus.c | 3 +-- include/linux/pci.h | 13 +++++++++++++ 17 files changed, 32 insertions(+), 41 deletions(-)
Applied to pci/pci_is_bridge for v3.16, thanks,
Bjorn