export acpi_pci_root to find pci_bus correctly
Subsystems (3)
v3 cover export acpi_pci_root to find pci_bus correctly
This is v3 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 -rc5, 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
v2 -> v3:
- don't depend on acpi_is_root_bridge (Bjorn Helgaas)
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 | 28 +++++++++++++++++----------- include/acpi/acpi_bus.h | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 26 deletions(-)
PATCH v3 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
Re: [PATCH v3 1/2] ACPI: export acpi_pci_root and friends
Quoted 5 lines · Alex Chiang
We can simplify ACPI drivers if we can tell whether a handle is an ACPI PCI root or not.
Cc Bjorn Helgaas <[email protected]>Signed-off-by Alex Chiang <[email protected]>
Quoted 85 lines
---
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
-1@@ -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 --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
PATCH v3 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 | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +17 -11
@@ -62,6 +62,22 @@ 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; +struct acpi_pci_root *root; + + root =acpi_pci_find_root (handle); +if (root) + 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 +1403,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 +1411,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 v3 2/2] PCI Hotplug: acpiphp: get pci_bus from acpi handle correctly
Quoted 11 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]>
Quoted 64 lines
---
drivers/pci/hotplug/acpiphp_glue.c | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-)drivers/pci/hotplug/acpiphp_glue.c +17
-12@@ -62,6 +62,22 @@ 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; +struct acpi_pci_root *root; + + root =acpi_pci_find_root (handle); +if (root) + 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 +1403,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 +1411,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 ; } --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
Re: [PATCH v3 2/2] PCI Hotplug: acpiphp: get pci_bus from acpi handle correctly
In reply to Alex ChiangQuoted 4 lines · On Thu, 23 Jul 2009 17:03:05 -0600 Alex Chiang <[email protected]> wrote:
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.
Quoted 8 lines
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]>---
I put these in my linux-next branch, just because I'm really conservative about the current release.
If we hear of boxes in the wild getting bitten by the non-materialized bit, we can push this set back to stable.
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Re: [PATCH v3 2/2] PCI Hotplug: acpiphp: get pci_bus from acpi handle correctly
* Jesse Barnes <[email protected]>:
Quoted 13 lines
Quoted 10 lines · On Thu, 23 Jul 2009 17:03:05 -0600 Alex Chiang <[email protected]> wrote:
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.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Alex Chiang <[email protected]>---
I put these in my linux-next branch, just because I'm really conservative about the current release.
If we hear of boxes in the wild getting bitten by the non-materialized bit, we can push this set back to stable.
Sounds good, thanks Jesse.
/ac