ACPI/PCI: export acpi_pci_root to find pci_bus correctly
Subsystems (3)
v2 cover ACPI/PCI: export acpi_pci_root to find pci_bus correctly
This is v2 of a patch series that:
a) exports struct acpi_pci_root
b) fixes an assumption in acpiphp about finding struct pci_bus
It's a minimal fix that's aimed at -rc4, as (b) fixes an assumption introduced in -rc1.
I'll send the rest of the cleanups for linux-next later, after doing some more testing.
Original thread here:
http://thread.gmane.org/gmane.linux.kernel.pci/5080
v1 -> v2:
- fixed build error in acpi_pci_root
- reduced patch series in scope to be much smaller
---
Alex Chiang (2):
ACPI: export acpi_pci_root and friends
PCI Hotplug: acpiphp: get pci_bus from acpi handle correctly
drivers/acpi/pci_root.c | 17 ++--------------- drivers/pci/hotplug/acpiphp_glue.c | 27 ++++++++++++++++----------- include/acpi/acpi_bus.h | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 26 deletions(-)
PATCH v2 1/2 ACPI: export acpi_pci_root and friends
We can simplify ACPI drivers if we can tell whether a handle is an ACPI PCI root or not.
---
drivers/acpi/pci_root.c | 17 ++--------------- include/acpi/acpi_bus.h | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 15 deletions(-)
drivers/acpi/pci_root.c +2 -15
@@ -61,20 +61,6 @@ static struct acpi_driver acpi_pci_root_driver = { }, }; -struct acpi_pci_root { -struct list_head node; -struct acpi_device *device; -struct pci_bus *bus; -u16 segment; -u8 bus_nr; - -u32 osc_support_set;/* _OSC state of support bits */ -u32 osc_control_set;/* _OSC state of control bits */ -u32 osc_control_qry;/* the latest _OSC query result */ - -u32 osc_queried:1 ;/* has _OSC control been queried? */ -}; -static LIST_HEAD (acpi_pci_roots);static struct acpi_pci_driver *sub_driver;
@@ -317,7 +303,7 @@ static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags)return status; } -static struct acpi_pci_root *acpi_pci_find_root (acpi_handle handle) +struct acpi_pci_root *acpi_pci_find_root (acpi_handle handle) {struct acpi_pci_root *root;
@@ -327,6 +313,7 @@ static struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle) }return NULL ; } +EXPORT_SYMBOL_GPL (acpi_pci_find_root);struct acpi_handle_node {struct list_head node;
include/acpi/acpi_bus.h +16 -0
@@ -369,10 +369,26 @@ int register_acpi_bus_type(struct acpi_bus_type *);int unregister_acpi_bus_type (struct acpi_bus_type *);struct device *acpi_get_physical_device (acpi_handle ); +struct acpi_pci_root { +struct list_head node; +struct acpi_device * device; +struct acpi_pci_id id; +struct pci_bus *bus; +u16 segment; +u8 bus_nr; + +u32 osc_support_set;/* _OSC state of support bits */ +u32 osc_control_set;/* _OSC state of control bits */ +u32 osc_control_qry;/* the latest _OSC query result */ + +u32 osc_queried:1 ;/* has _OSC control been queried? */ +}; +/* helper */ acpi_handle acpi_get_child (acpi_handle ,acpi_integer );int acpi_is_root_bridge (acpi_handle );acpi_handle acpi_get_pci_rootbridge_handle (unsigned int ,unsigned int ); +struct acpi_pci_root *acpi_pci_find_root (acpi_handle handle);#define DEVICE_ACPI_HANDLE (dev) ((acpi_handle)((dev)->archdata.acpi_handle))#ifdef CONFIG_PM_SLEEP
PATCH v2 2/2 PCI Hotplug: acpiphp: get pci_bus from acpi handle correctly
In reply to Alex ChiangWe cannot simply call acpi_get_pci_dev() on any random ACPI handle and hope that it works, because a PCI root bridge may not have an associated struct pci_dev.
This is allowed per the PCI specification, and is referred to as a non-materialized bridge.
So, depending on the type of PCI bridge that the handle points to, use the appropriate interface to return the struct pci_bus correctly.
---
drivers/pci/hotplug/acpiphp_glue.c | 27 ++++++++++++++++----------- 1 files changed, 16 insertions(+), 11 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +16 -11
@@ -62,6 +62,21 @@ static void acpiphp_sanitize_bus(struct pci_bus *bus);static void acpiphp_set_hpp_values (acpi_handle handle,struct pci_bus *bus);static void handle_hotplug_event_func (acpi_handle handle,u32 type,void *context); +static struct pci_bus *pci_bus_from_handle (acpi_handle handle) +{ +struct pci_bus *pbus; + +if (acpi_is_root_bridge (handle)) { +struct acpi_pci_root *root =acpi_pci_find_root (handle); + pbus = root->bus; + }else { +struct pci_dev *pdev =acpi_get_pci_dev (handle); + pbus = pdev->subordinate; +pci_dev_put (pdev); + } +return pbus; +} +/* callback routine to check for the existence of a pci dock device */ static acpi_status is_pci_dock_device (acpi_handle handle,u32 lvl,void *context,void **rv)
@@ -1387,16 +1402,7 @@ static void acpiphp_sanitize_bus(struct pci_bus *bus)/* Program resources in newly inserted bridge */ static int acpiphp_configure_bridge (acpi_handle handle) { -struct pci_dev *dev; -struct pci_bus *bus; - - dev =acpi_get_pci_dev (handle); -if (!dev) { -err ("cannot get PCI domain and bus number for bridge\n" ); -return -EINVAL ; - } - - bus = dev->bus; +struct pci_bus *bus =pci_bus_from_handle (handle);pci_bus_size_bridges (bus);pci_bus_assign_resources (bus);
@@ -1404,7 +1410,6 @@ static int acpiphp_configure_bridge (acpi_handle handle)acpiphp_set_hpp_values (handle, bus);pci_enable_bridges (bus);acpiphp_configure_ioapics (handle); -pci_dev_put (dev);return 0 ; }
Re: [PATCH v2 2/2] PCI Hotplug: acpiphp: get pci_bus from acpi handle correctly
Quoted 27 lines · Alex Chiang
We cannot simply call
acpi_get_pci_dev()on any random ACPI handle and hope that it works, because a PCI root bridge may not have an associated structpci_dev.This is allowed per the PCI specification, and is referred to as a non-materialized bridge.
So, depending on the type of PCI bridge that the handle points to, use the appropriate interface to return the struct
pci_buscorrectly.Signed-off-by Alex Chiang <[email protected]>---
drivers/pci/hotplug/acpiphp_glue.c | 27 ++++++++++++++++----------- 1 files changed, 16 insertions(+), 11 deletions(-)drivers/pci/hotplug/acpiphp_glue.c +3
-0@@ -62,6 +62,21 @@ static void acpiphp_sanitize_bus(struct pci_bus *bus);static void acpiphp_set_hpp_values (acpi_handle handle,struct pci_bus *bus);static void handle_hotplug_event_func (acpi_handle handle,u32 type,void *context); +static struct pci_bus *pci_bus_from_handle (acpi_handle handle) +{ +struct pci_bus *pbus;
drivers/pci/hotplug/acpiphp_glue.c static void acpiphp_sanitize_bus(struct pci_bus *bus); · line 77
Quoted 10 lines
drivers/pci/hotplug/acpiphp_glue.c +10
-0+ +if (acpi_is_root_bridge (handle)) { +struct acpi_pci_root *root =acpi_pci_find_root (handle); + pbus = root->bus; + }else { +struct pci_dev *pdev =acpi_get_pci_dev (handle); + pbus = pdev->subordinate; +pci_dev_put (pdev); + } +return pbus;
I worry that acpi_is_root_bridge() merely checks the device IDs of "handle", which isn't quite the same as checking whether the pci_root driver has claimed "handle".
Are you confident that it's safe to move the pci_dev_put(), so it is released before configuring the bridge?
What do you think about something like this (even though the get/put is still a little clunky):
struct pci_dev *dev = NULL;
root = acpi_pci_find_root(handle);
if (root)
bus = root->bus;
else {
dev = acpi_get_pci_dev(handle);
if (dev)
bus = pdev->subordinate;
else {
err("cannot get PCI domain and bus number for bridge\n");
return -EINVAL;
}
}
pci_bus_size_bridges(bus);
...
if (dev)
pci_dev_put(dev);
return 0;Quoted 30 lines
drivers/pci/hotplug/acpiphp_glue.c +3
-11+} +/* callback routine to check for the existence of a pci dock device */ static acpi_status is_pci_dock_device (acpi_handle handle,u32 lvl,void *context,void **rv)@@ -1387,16 +1402,7 @@ static void acpiphp_sanitize_bus(struct pci_bus *bus)/* Program resources in newly inserted bridge */ static int acpiphp_configure_bridge (acpi_handle handle) { -struct pci_dev *dev; -struct pci_bus *bus; - - dev =acpi_get_pci_dev (handle); -if (!dev) { -err ("cannot get PCI domain and bus number for bridge\n" ); -return -EINVAL ; - } - - bus = dev->bus; +struct pci_bus *bus =pci_bus_from_handle (handle);pci_bus_size_bridges (bus);pci_bus_assign_resources (bus);@@ -1404,7 +1410,6 @@ static int acpiphp_configure_bridge (acpi_handle handle)acpiphp_set_hpp_values (handle, bus);pci_enable_bridges (bus);acpiphp_configure_ioapics (handle); -pci_dev_put (dev);return 0 ; }
Re: [PATCH v2 2/2] PCI Hotplug: acpiphp: get pci_bus from acpi handle correctly
* Bjorn Helgaas <[email protected]>:
Quoted 34 lines · Alex Chiang
Quoted 33 lines
We cannot simply call
acpi_get_pci_dev()on any random ACPI handle and hope that it works, because a PCI root bridge may not have an associated structpci_dev.This is allowed per the PCI specification, and is referred to as a non-materialized bridge.
So, depending on the type of PCI bridge that the handle points to, use the appropriate interface to return the struct
pci_buscorrectly.Signed-off-by Alex Chiang <[email protected]>---
drivers/pci/hotplug/acpiphp_glue.c | 27 ++++++++++++++++----------- 1 files changed, 16 insertions(+), 11 deletions(-)drivers/pci/hotplug/acpiphp_glue.c +9
-0@@ -62,6 +62,21 @@ static void acpiphp_sanitize_bus(struct pci_bus *bus);static void acpiphp_set_hpp_values (acpi_handle handle,struct pci_bus *bus);static void handle_hotplug_event_func (acpi_handle handle,u32 type,void *context); +static struct pci_bus *pci_bus_from_handle (acpi_handle handle) +{ +struct pci_bus *pbus; + +if (acpi_is_root_bridge (handle)) { +struct acpi_pci_root *root =acpi_pci_find_root (handle); + pbus = root->bus; + }else { +struct pci_dev *pdev =acpi_get_pci_dev (handle);
Quoted 8 lines
drivers/pci/hotplug/acpiphp_glue.c static void acpiphp_sanitize_bus(struct pci_bus *bus); · line 77
Quoted 4 lines
drivers/pci/hotplug/acpiphp_glue.c +4
-0+ pbus = pdev->subordinate; +pci_dev_put (pdev); + } +return pbus;I worry that
acpi_is_root_bridge()merely checks the device IDs of "handle", which isn't quite the same as checking whether thepci_rootdriver has claimed "handle".
Hm, I understand this concern in a theoretical sense, but could you explain more of what you're thinking about, and give me a concrete example of something that might go wrong here?
Quoted 2 lines
Are you confident that it's safe to move the
pci_dev_put(), so it is released before configuring the bridge?
I'm confident that I'm not changing the lifetime assumptions in acpiphp_configure_bridge(), as the old code didn't seem to care either.
Commit d6aa484c (acpiphp: convert to acpi_get_pci_dev) changed from pci_find_bus() to use acpi_get_pci_dev(), and pci_find_bus() does not elevate any reference counts.
What I'm trying to fix here is that acpi_get_pci_dev() /might/ not work all the time, namely on machines that have both:
a) hotpluggable root bridges
b) non-materialized root bridges
Quoted 15 lines
What do you think about something like this (even though the get/put is still a little clunky):
struct pci_dev *dev = NULL; root = acpi_pci_find_root(handle); if (root) bus = root->bus; else { dev = acpi_get_pci_dev(handle); if (dev) bus = pdev->subordinate; else { err("cannot get PCI domain and bus number for bridge\n"); return -EINVAL;
Quoted 8 lines
} } pci_bus_size_bridges(bus); ... if (dev) pci_dev_put(dev); return 0;
This seems like a good approach too, but I'd like to understand your concern about acpi_is_root_bridge() first.
Thanks for the review.
/ac
Re: [PATCH v2 2/2] PCI Hotplug: acpiphp: get pci_bus from acpi handle correctly
Quoted 44 lines · Alex Chiang
* Bjorn Helgaas <[email protected]>:
Quoted 34 lines · Alex Chiang
Quoted 33 lines
We cannot simply call
acpi_get_pci_dev()on any random ACPI handle and hope that it works, because a PCI root bridge may not have an associated structpci_dev.This is allowed per the PCI specification, and is referred to as a non-materialized bridge.
So, depending on the type of PCI bridge that the handle points to, use the appropriate interface to return the struct
pci_buscorrectly.Signed-off-by Alex Chiang <[email protected]>---
drivers/pci/hotplug/acpiphp_glue.c | 27 ++++++++++++++++----------- 1 files changed, 16 insertions(+), 11 deletions(-)drivers/pci/hotplug/acpiphp_glue.c +9
-0@@ -62,6 +62,21 @@ static void acpiphp_sanitize_bus(struct pci_bus *bus);static void acpiphp_set_hpp_values (acpi_handle handle,struct pci_bus *bus);static void handle_hotplug_event_func (acpi_handle handle,u32 type,void *context); +static struct pci_bus *pci_bus_from_handle (acpi_handle handle) +{ +struct pci_bus *pbus; + +if (acpi_is_root_bridge (handle)) { +struct acpi_pci_root *root =acpi_pci_find_root (handle); + pbus = root->bus; + }else { +struct pci_dev *pdev =acpi_get_pci_dev (handle);Quoted 8 lines
drivers/pci/hotplug/acpiphp_glue.c static void acpiphp_sanitize_bus(struct pci_bus *bus); · line 77
Quoted 4 lines
drivers/pci/hotplug/acpiphp_glue.c +4
-0+ pbus = pdev->subordinate; +pci_dev_put (pdev); + } +return pbus;I worry that
acpi_is_root_bridge()merely checks the device IDs of "handle", which isn't quite the same as checking whether thepci_rootdriver has claimed "handle".
Quoted 3 lines
Hm, I understand this concern in a theoretical sense, but could you explain more of what you're thinking about, and give me a concrete example of something that might go wrong here?
My concern is only theoretical -- I could imagine a PNP0A03 device in the namespace (so acpi_is_root_bridge() is true) that has not been claimed by the pci_root driver (so acpi_pci_find_root() returns NULL).
I don't think this will happen in practice because pci_root can't be a module, but it's easier to analyze with just one check, since you can learn everything you need from acpi_pci_find_root() without also depending on acpi_is_root_bridge().
Bjorn
Re: [PATCH v2 2/2] PCI Hotplug: acpiphp: get pci_bus from acpi handle correctly
* Bjorn Helgaas <[email protected]>:
Quoted 25 lines · Alex Chiang
Quoted 20 lines
* Bjorn Helgaas <[email protected]>:
Quoted 10 lines · Alex Chiang
Quoted 9 lines
drivers/pci/hotplug/acpiphp_glue.c +9
-0+static struct pci_bus *pci_bus_from_handle (acpi_handle handle) +{ +struct pci_bus *pbus; + +if (acpi_is_root_bridge (handle)) { +struct acpi_pci_root *root =acpi_pci_find_root (handle); + pbus = root->bus; + }else { +struct pci_dev *pdev =acpi_get_pci_dev (handle);Quoted 8 lines
drivers/pci/hotplug/acpiphp_glue.c static void acpiphp_sanitize_bus(struct pci_bus *bus); · line 77
Quoted 4 lines
drivers/pci/hotplug/acpiphp_glue.c +4
-0+ pbus = pdev->subordinate; +pci_dev_put (pdev); + } +return pbus;I worry that
acpi_is_root_bridge()merely checks the device IDs of "handle", which isn't quite the same as checking whether thepci_rootdriver has claimed "handle".Quoted 3 lines
Hm, I understand this concern in a theoretical sense, but could you explain more of what you're thinking about, and give me a concrete example of something that might go wrong here?
Quoted 8 lines
My concern is only theoretical -- I could imagine a PNP0A03 device in the namespace (so
acpi_is_root_bridge()is true) that has not been claimed by thepci_rootdriver (soacpi_pci_find_root()returns NULL).I don't think this will happen in practice because
pci_rootcan't be a module, but it's easier to analyze with just one check, since you can learn everything you need fromacpi_pci_find_root()without also depending onacpi_is_root_bridge().
Ah, that makes sense.
I can respin one more time using your suggestion (although I'll probably keep it factored out into a separate function).
Thanks.
/ac