ACPI / hotplug / PCI: Consolidation of handling notifications (in progress)
cover ACPI / hotplug / PCI: Consolidation of handling notifications (in progress)
Hi,
Following is the current set of acpiphp updates targeted at the consolidation of device notifications handling and removal of suprefluous infrastructure. Still on top of 3.10 with ACPI+PM 3.11 material merged on top (I'll rebase it on top of linux-pm.git/bleeding-edge eventually).
[1/8] Make bus registration and unregistration symmetric. [Resend] [2/8] Consolidate acpiphp_enumerate_slots(). [Resend]
[3/8] Fix error code path in register_slot(). [Resend]
[4/8] Introduce hotplug context objects for ACPI device objects corresponding
to PCI hotplug devices. [Update]
[5/8] Unified notify handler for hotplug events. [Resend]
[6/8] Drop acpiphp_handle_to_bridge() and use context objects instead of it. [7/8] Pass entire hotplug context objects (instead of their fields
individually) to event handling work functions.
[8/8] Merge hotplug event handling functions.
Comments welcome.
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
RFC PATCH 1/8 ACPI / PCI: Make bus registration and unregistration symmetric
From: Rafael J. Wysocki <[email protected]>
Since acpi_pci_slot_enumerate() and acpiphp_enumerate_slots() can get the ACPI device handle they need from bus->bridge, it is not necessary to pass that handle to them as an argument.
Drop the second argument of acpi_pci_slot_enumerate() and acpiphp_enumerate_slots(), rework them to obtain the ACPI handle from bus->bridge and make acpi_pci_add_bus() and acpi_pci_remove_bus() entirely symmetrical.
--- drivers/acpi/pci_slot.c | 14 +++++++++----- drivers/pci/hotplug/acpiphp_glue.c | 7 ++++--- drivers/pci/pci-acpi.c | 16 ++++------------ include/linux/pci-acpi.h | 10 ++++------ 4 files changed, 21 insertions(+), 26 deletions(-)
drivers/acpi/pci_slot.c +9 -5
@@ -159,12 +159,16 @@ register_slot(acpi_handle handle, u32 lvreturn AE_OK ; } -void acpi_pci_slot_enumerate (struct pci_bus *bus,acpi_handle handle) +void acpi_pci_slot_enumerate (struct pci_bus *bus) { -mutex_lock (&slot_list_lock); -acpi_walk_namespace (ACPI_TYPE_DEVICE , handle,1 , - register_slot,NULL , bus,NULL ); -mutex_unlock (&slot_list_lock); +acpi_handle handle =ACPI_HANDLE (bus->bridge); + +if (handle) { +mutex_lock (&slot_list_lock); +acpi_walk_namespace (ACPI_TYPE_DEVICE , handle,1 , + register_slot,NULL , bus,NULL ); +mutex_unlock (&slot_list_lock); + } }void acpi_pci_slot_remove (struct pci_bus *bus)
drivers/pci/hotplug/acpiphp_glue.c +4 -3
@@ -1169,15 +1169,16 @@ static void handle_hotplug_event_func(ac* Create hotplug slots for the PCI bus. * It should always return 0 to avoid skipping following notifiers. */ -void acpiphp_enumerate_slots (struct pci_bus *bus,acpi_handle handle) +void acpiphp_enumerate_slots (struct pci_bus *bus) { -acpi_handle dummy_handle; +acpi_handle handle, dummy_handle;struct acpiphp_bridge *bridge;if (acpiphp_disabled)return ; -if (detect_ejectable_slots (handle) <=0 ) + handle =ACPI_HANDLE (bus->bridge); +if (!handle ||detect_ejectable_slots (handle) <=0 )return ; bridge =kzalloc (sizeof (struct acpiphp_bridge ),GFP_KERNEL );
drivers/pci/pci-acpi.c +4 -12
@@ -290,24 +290,16 @@ static struct pci_platform_pm_ops acpi_pvoid acpi_pci_add_bus (struct pci_bus *bus) { -acpi_handle handle =NULL ; - -if (bus->bridge) - handle =ACPI_HANDLE (bus->bridge); -if (acpi_pci_disabled || handle ==NULL ) +if (acpi_pci_disabled || !bus->bridge)return ; -acpi_pci_slot_enumerate (bus, handle); -acpiphp_enumerate_slots (bus, handle); +acpi_pci_slot_enumerate (bus); +acpiphp_enumerate_slots (bus); }void acpi_pci_remove_bus (struct pci_bus *bus) { -/* -* bus->bridge->acpi_node.handle has already been reset to NULL -* when acpi_pci_remove_bus() is called, so don't check ACPI handle. -*/ -if (acpi_pci_disabled) +if (acpi_pci_disabled || !bus->bridge)return ;acpiphp_remove_slots (bus);
include/linux/pci-acpi.h +4 -6
@@ -47,24 +47,22 @@ void acpi_pci_remove_bus(struct pci_bus#ifdef CONFIG_ACPI_PCI_SLOT void acpi_pci_slot_init (void ); -void acpi_pci_slot_enumerate (struct pci_bus *bus,acpi_handle handle); +void acpi_pci_slot_enumerate (struct pci_bus *bus);void acpi_pci_slot_remove (struct pci_bus *bus);#else static inline void acpi_pci_slot_init (void ) { } -static inline void acpi_pci_slot_enumerate (struct pci_bus *bus, -acpi_handle handle) { } +static inline void acpi_pci_slot_enumerate (struct pci_bus *bus) { }static inline void acpi_pci_slot_remove (struct pci_bus *bus) { }#endif #ifdef CONFIG_HOTPLUG_PCI_ACPI void acpiphp_init (void ); -void acpiphp_enumerate_slots (struct pci_bus *bus,acpi_handle handle); +void acpiphp_enumerate_slots (struct pci_bus *bus);void acpiphp_remove_slots (struct pci_bus *bus);void acpiphp_check_host_bridge (acpi_handle handle);#else static inline void acpiphp_init (void ) { } -static inline void acpiphp_enumerate_slots (struct pci_bus *bus, -acpi_handle handle) { } +static inline void acpiphp_enumerate_slots (struct pci_bus *bus) { }static inline void acpiphp_remove_slots (struct pci_bus *bus) { }static inline void acpiphp_check_host_bridge (acpi_handle handle) { }#endif
RFC PATCH 2/8 ACPI / hotplug / PCI: Consolidate acpiphp_enumerate_slots()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The acpiphp_enumerate_slots() function is now split into two parts, acpiphp_enumerate_slots() proper and init_bridge_misc() which is only called by the former. If these functions are combined, it is possible to make the code easier to follow and to clean up the error handling (to prevent memory leaks on error from happening in particular), so do that.
--- drivers/pci/hotplug/acpiphp_glue.c | 94 ++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 48 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +46 -48
@@ -363,46 +363,6 @@ static int detect_ejectable_slots(acpi_hreturn found; } -/* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */ -static void init_bridge_misc (struct acpiphp_bridge *bridge) -{ -acpi_status status; - -/* must be added to the list prior to calling register_slot */ -mutex_lock (&bridge_mutex); -list_add (&bridge->list, &bridge_list); -mutex_unlock (&bridge_mutex); - -/* register all slot objects under this bridge */ - status =acpi_walk_namespace (ACPI_TYPE_DEVICE , bridge->handle, (u32 )1 , - register_slot,NULL , bridge,NULL ); -if (ACPI_FAILURE (status)) { -mutex_lock (&bridge_mutex); -list_del (&bridge->list); -mutex_unlock (&bridge_mutex); -return ; - } - -/* install notify handler for P2P bridges */ -if (!pci_is_root_bus (bridge->pci_bus)) { -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) { - status =acpi_remove_notify_handler (bridge->func->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func); -if (ACPI_FAILURE (status)) -err ("failed to remove notify handler\n" ); - } - status =acpi_install_notify_handler (bridge->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_bridge, - bridge); - -if (ACPI_FAILURE (status)) { -err ("failed to register interrupt notify handler\n" ); - } - } -} -/* find acpiphp_func from acpiphp_bridge */ static struct acpiphp_func *acpiphp_bridge_handle_to_function (acpi_handle handle)
@@ -1171,8 +1131,9 @@ static void handle_hotplug_event_func(ac*/ void acpiphp_enumerate_slots (struct pci_bus *bus) { -acpi_handle handle, dummy_handle;struct acpiphp_bridge *bridge; +acpi_handle handle; +acpi_status status;if (acpiphp_disabled)return ;
@@ -1200,15 +1161,52 @@ void acpiphp_enumerate_slots(struct pci_*/ get_device (&bus->dev); -if (!pci_is_root_bus (bridge->pci_bus) && -ACPI_SUCCESS (acpi_get_handle (bridge->handle, -"_EJ0" , &dummy_handle))) { -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; - bridge->func =acpiphp_bridge_handle_to_function (handle); +/* must be added to the list prior to calling register_slot */ +mutex_lock (&bridge_mutex); +list_add (&bridge->list, &bridge_list); +mutex_unlock (&bridge_mutex); + +/* register all slot objects under this bridge */ + status =acpi_walk_namespace (ACPI_TYPE_DEVICE , bridge->handle,1 , + register_slot,NULL , bridge,NULL ); +if (ACPI_FAILURE (status)) { +acpi_handle_err (bridge->handle,"failed to register slots\n" ); + goto err; } -init_bridge_misc (bridge); +if (pci_is_root_bus (bridge->pci_bus)) +return ; + +/* install notify handler for P2P bridges */ + status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , + handle_hotplug_event_bridge, + bridge); +if (ACPI_FAILURE (status)) { +acpi_handle_err (bridge->handle, +"failed to register notify handler\n" ); + goto err; + } + + status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); +if (ACPI_FAILURE (status)) +return ; + +dbg ("found ejectable p2p bridge\n" ); + bridge->flags |=BRIDGE_HAS_EJ0 ; + bridge->func =acpiphp_bridge_handle_to_function (bridge->handle); +if (bridge->func) { + status =acpi_remove_notify_handler (bridge->func->handle, +ACPI_SYSTEM_NOTIFY , + handle_hotplug_event_func); +if (ACPI_FAILURE (status)) +acpi_handle_err (bridge->func->handle, +"failed to remove notify handler\n" ); + } +return ; + + err: +cleanup_bridge (bridge); +put_bridge (bridge); }/* Destroy hotplug slots associated with the PCI bus */
RFC PATCH 3/8 ACPI / hotplug / PCI: Always return success after adding a function
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
When a new ACPIPHP function is added by register_slot() and the notify handler cannot be installed for it, register_slot() returns an error status without cleaning up, which causes the entire namespace walk in acpiphp_enumerate_slots() to be aborted, although it still may be possible to successfully install the function notify handler for other device objects under the given brigde.
To address this issue make register_slot() return success after a new function has been added, even if the addition of the notify handler for it has failed.
--- drivers/pci/hotplug/acpiphp_glue.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +2 -3
@@ -335,10 +335,9 @@ register_slot(acpi_handle handle, u32 lvif (ACPI_FAILURE (status))err ("failed to register interrupt notify handler\n" ); - }else - status =AE_OK ; + } -return status; +return AE_OK ; err_exit: bridge->nr_slots--;
RFC PATCH 4/8 ACPI / hotplug / PCI: Hotplug context objects for bridges and functions
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
When either a new hotplug brigde or a new hotplug function is added by the ACPI-based PCI hotplug (acpiphp) code, attach a context object to its ACPI handle to store hotplug-related information in it. To start with, put the handle's bridge and function pointers into that object. Count references to the context objects and drop them when they are not needed any more.
First of all, this makes it possible to find out if the given bridge has been registered as a function already in a much more straightforward way and acpiphp_bridge_handle_to_function() can be dropped (Yay!).
This also will allow some more simplifications to be made going forward.
--- drivers/pci/hotplug/acpiphp.h | 10 ++ drivers/pci/hotplug/acpiphp_glue.c | 154 ++++++++++++++++++++++++++----------- 2 files changed, 121 insertions(+), 43 deletions(-)
drivers/pci/hotplug/acpiphp.h +10 -0
@@ -49,6 +49,7 @@ #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) +struct acpiphp_context ;struct acpiphp_bridge ;struct acpiphp_slot ;
@@ -77,6 +78,7 @@ struct acpiphp_bridge {struct kref ref;acpi_handle handle; +struct acpiphp_context *context;/* Ejectable PCI-to-PCI bridge (PCI bridge and PCI function) */ struct acpiphp_func *func;
@@ -119,6 +121,7 @@ struct acpiphp_slot {* typically 8 objects per slot (i.e. for each PCI function) */ struct acpiphp_func { +struct acpiphp_context *context;struct acpiphp_slot *slot;/* parent */ struct list_head sibling;
@@ -129,6 +132,13 @@ struct acpiphp_func {u32 flags;/* see below */ }; +struct acpiphp_context { +struct kref kref; +acpi_handle handle; +struct acpiphp_func *func; +struct acpiphp_bridge *bridge; +}; +/* * struct acpiphp_attention_info - device specific attention registration *
drivers/pci/hotplug/acpiphp_glue.c +111 -43
261 lines not on this page · raw message
Re: [RFC][PATCH 4/8] ACPI / hotplug / PCI: Hotplug context objects for bridges and functions
Quoted 3 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
When either a new hotplug brigde or a new hotplug function is added
^^^^^^
typoQuoted 178 lines
by the ACPI-based PCI hotplug (acpiphp) code, attach a context object to its ACPI handle to store hotplug-related information in it. To start with, put the handle's bridge and function pointers into that object. Count references to the context objects and drop them when they are not needed any more.
First of all, this makes it possible to find out if the given bridge has been registered as a function already in a much more straightforward way and
acpiphp_bridge_handle_to_function()can be dropped (Yay!).This also will allow some more simplifications to be made going forward.
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/pci/hotplug/acpiphp.h | 10 ++ drivers/pci/hotplug/acpiphp_glue.c | 154 ++++++++++++++++++++++++++----------- 2 files changed, 121 insertions(+), 43 deletions(-)Index:
linux-pm/drivers/pci/hotplug/acpiphp.h
===================================================================drivers/pci/hotplug/acpiphp.h +10
-0@@ -49,6 +49,7 @@ #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) +struct acpiphp_context ;struct acpiphp_bridge ;struct acpiphp_slot ;@@ -77,6 +78,7 @@ struct acpiphp_bridge {struct kref ref;acpi_handle handle; +struct acpiphp_context *context;/* Ejectable PCI-to-PCI bridge (PCI bridge and PCI function) */ struct acpiphp_func *func;@@ -119,6 +121,7 @@ struct acpiphp_slot {* typically 8 objects per slot (i.e. for each PCI function) */ struct acpiphp_func { +struct acpiphp_context *context;struct acpiphp_slot *slot;/* parent */ struct list_head sibling;@@ -129,6 +132,13 @@ struct acpiphp_func {u32 flags;/* see below */ }; +struct acpiphp_context { +struct kref kref; +acpi_handle handle; +struct acpiphp_func *func; +struct acpiphp_bridge *bridge; +}; +/* * struct acpiphp_attention_info - device specific attention registration * Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c +68
-4@@ -79,6 +79,61 @@ is_pci_dock_device(acpi_handle handle, u } } +static void acpiphp_context_handler (acpi_handle handle,void *context) +{ +/* Intentionally empty. */ +} + +static struct acpiphp_context *acpiphp_init_context (acpi_handle handle) +{ +struct acpiphp_context *context; +acpi_status status; + + context =kzalloc (sizeof (*context),GFP_KERNEL ); +if (!context) +return NULL ; + + context->handle = handle; +kref_init (&context->kref); + status =acpi_attach_data (handle, acpiphp_context_handler, context); +if (ACPI_FAILURE (status)) { +kfree (context); +return NULL ; + } +return context; +} + +static struct acpiphp_context *acpiphp_get_context (acpi_handle handle) +{ +struct acpiphp_context *context =NULL ; +acpi_status status; +void *data; + + status =acpi_get_data (handle, acpiphp_context_handler, &data); +if (ACPI_SUCCESS (status)) { + context = data; +kref_get (&context->kref); + }else if (status ==AE_NOT_FOUND ) { + context =acpiphp_init_context (handle); + } +return context; +} + +static void acpiphp_release_context (struct kref *kref) +{ +struct acpiphp_context *context; + + context = container_of(kref, struct acpiphp_context, kref); +WARN_ON (context->func || context->bridge); +acpi_detach_data (context->handle, acpiphp_context_handler); +kfree (context); +} + +static void acpiphp_put_context (struct acpiphp_context *context) +{ +kref_put (&context->kref, acpiphp_release_context); +} +static inline void get_bridge (struct acpiphp_bridge *bridge) {kref_get (&bridge->ref);@@ -91,6 +146,7 @@ static inline void put_bridge(struct acpstatic void free_bridge (struct kref *kref) { +struct acpiphp_context *context;struct acpiphp_bridge *bridge;struct acpiphp_slot *slot, *next;struct acpiphp_func *func, *tmp;@@ -99,17 +155,24 @@ static void free_bridge(struct kref *krelist_for_each_entry_safe (slot, next, &bridge->slots, node) {list_for_each_entry_safe (func, tmp, &slot->funcs, sibling) { + context = func->context; + context->func =NULL ;kfree (func); +acpiphp_put_context (context); }kfree (slot); } -/* Release reference acquired by acpiphp_bridge_handle_to_function() */ +/* Release reference acquired by acpiphp_enumerate_slots(). */ if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func)put_bridge (bridge->func->slot->bridge); +put_device (&bridge->pci_bus->dev);pci_dev_put (bridge->pci_dev); + context = bridge->context; + context->bridge =NULL ;kfree (bridge); +acpiphp_put_context (context); }/* @@ -195,10 +258,11 @@ static void acpiphp_dock_release(void *d }/* callback routine to register each ACPI PCI slot object */ -static acpi_status -register_slot (acpi_handle handle,u32 lvl,void *context,void **rv) +static acpi_status register_slot (acpi_handle handle,u32 lvl,void *data, +void **rv) { -struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context; +struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)data; +struct acpiphp_context *context;struct acpiphp_slot *slot;struct acpiphp_func *newfunc;acpi_handle tmp;
drivers/pci/hotplug/acpiphp_glue.c register_slot(acpi_handle handle, u32 lv · line 298
Quoted 6 lines
drivers/pci/hotplug/acpiphp_glue.c +3
-0@@ -229,8 +293,20 @@ register_slot(acpi_handle handle, u32 lvif (!newfunc)return AE_NO_MEMORY ; + context =acpiphp_get_context (handle); +if (!context) { + context =acpiphp_init_context (handle);
Since acpiphp_get_context() already does acpiphp_init_context() is the above really necessary?
Quoted 99 lines
drivers/pci/hotplug/acpiphp_glue.c +20
-32+if (!context) { +acpi_handle_err (handle,"No hotplug context\n" ); +kfree (newfunc); +return AE_NOT_EXIST ; + } + } + newfunc->handle = handle; newfunc->function = function; + newfunc->context = context; + context->func = newfunc;if (ACPI_SUCCESS (acpi_get_handle (handle,"_EJ0" , &tmp))) newfunc->flags =FUNC_HAS_EJ0 ;@@ -268,8 +344,8 @@ register_slot(acpi_handle handle, u32 lvif (!found) { slot =kzalloc (sizeof (struct acpiphp_slot ),GFP_KERNEL );if (!slot) { -kfree (newfunc); -return AE_NO_MEMORY ; + status =AE_NO_MEMORY ; + goto err_out; } slot->bridge = bridge;@@ -293,7 +369,9 @@ register_slot(acpi_handle handle, u32 lvelse warn ("acpiphp_register_hotplug_slot failed " "(err code = 0x%x)\n" , retval); - goto err_exit; + + status =AE_OK ; + goto err; } }@@ -339,15 +417,17 @@ register_slot(acpi_handle handle, u32 lvreturn AE_OK ; - err_exit: + err: bridge->nr_slots--;mutex_lock (&bridge_mutex);list_del (&slot->node);mutex_unlock (&bridge_mutex);kfree (slot); + err_out: + context->func =NULL ;kfree (newfunc); - -return AE_OK ; +acpiphp_put_context (context); +return status; }@@ -362,32 +442,6 @@ static int detect_ejectable_slots(acpi_hreturn found; } - -/* find acpiphp_func from acpiphp_bridge */ -static struct acpiphp_func *acpiphp_bridge_handle_to_function (acpi_handle handle) -{ -struct acpiphp_bridge *bridge; -struct acpiphp_slot *slot; -struct acpiphp_func *func =NULL ; - -mutex_lock (&bridge_mutex); -list_for_each_entry (bridge, &bridge_list, list) { -list_for_each_entry (slot, &bridge->slots, node) { -list_for_each_entry (func, &slot->funcs, sibling) { -if (func->handle == handle) { -get_bridge (func->slot->bridge); -mutex_unlock (&bridge_mutex); -return func; - } - } - } - } -mutex_unlock (&bridge_mutex); - -return NULL ; -} - -static struct acpiphp_bridge *acpiphp_handle_to_bridge (acpi_handle handle) {struct acpiphp_bridge *bridge;@@ -1130,6 +1184,7 @@ static void handle_hotplug_event_func(ac*/ void acpiphp_enumerate_slots (struct pci_bus *bus) { +struct acpiphp_context *context;struct acpiphp_bridge *bridge;acpi_handle handle;acpi_status status;
drivers/pci/hotplug/acpiphp_glue.c void acpiphp_enumerate_slots(struct pci_ · line 1201
Quoted 6 lines
drivers/pci/hotplug/acpiphp_glue.c +3
-0@@ -1141,9 +1196,19 @@ void acpiphp_enumerate_slots(struct pci_if (!handle ||detect_ejectable_slots (handle) <=0 )return ; + context =acpiphp_get_context (handle); +if (!context) { + context =acpiphp_init_context (handle);
Ditto.
Quoted 13 lines
drivers/pci/hotplug/acpiphp_glue.c +8
-1+if (!context) { +acpi_handle_err (handle,"No hotplug context\n" ); +return ; + } + } + bridge =kzalloc (sizeof (struct acpiphp_bridge ),GFP_KERNEL );if (bridge ==NULL ) { -err ("out of memory\n" ); +acpi_handle_err (handle,"No memory for bridge object\n" ); +acpiphp_put_context (context);return ; }
RFC PATCH 4/8 ACPI / hotplug / PCI: Hotplug context objects for bridges and functions
Quoted 7 lines · Mika Westerberg
Quoted 3 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
When either a new hotplug brigde or a new hotplug function is added
^^^^^^ typo
Yup, thanks!
Quoted 16 lines
Quoted 16 lines
by the ACPI-based PCI hotplug (acpiphp) code, attach a context object to its ACPI handle to store hotplug-related information in it. To start with, put the handle's bridge and function pointers into that object. Count references to the context objects and drop them when they are not needed any more.
First of all, this makes it possible to find out if the given bridge has been registered as a function already in a much more straightforward way and
acpiphp_bridge_handle_to_function()can be dropped (Yay!).This also will allow some more simplifications to be made going forward.
Signed-off-by Rafael J. Wysocki <[email protected]>---
[...]
Quoted 16 lines
Quoted 16 lines
/* callback routine to register each ACPI PCI slot object */
(quoted diff) +4
-3-static acpi_status -register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) +static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, + void **rv) { - struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context; + struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)data; + struct acpiphp_context *context; struct acpiphp_slot *slot; struct acpiphp_func *newfunc; acpi_handle tmp;@@ -229,8 +293,20 @@ register_slot(acpi_handle handle, u32 lv if (!newfunc) return AE_NO_MEMORY;
Quoted 6 lines
Review register_slot(acpi_handle handle, u32 lv · line 298
Quoted 3 lines
(quoted diff) +3
-0+ context = acpiphp_get_context(handle); + if (!context) { + context = acpiphp_init_context(handle);Since
acpiphp_get_context()already doesacpiphp_init_context()is the above really necessary?
Hmm, acpiphp_get_context() wasn't supposed to be doing that.
Well, I guess I just forgot to remove that part. Updated patch is appended.
Thanks,
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: ACPI / hotplug / PCI: Hotplug context objects for bridges and functions
When either a new hotplug bridge or a new hotplug function is added by the ACPI-based PCI hotplug (acpiphp) code, attach a context object to its ACPI handle to store hotplug-related information in it. To start with, put the handle's bridge and function pointers into that object. Count references to the context objects and drop them when they are not needed any more.
First of all, this makes it possible to find out if the given bridge has been registered as a function already in a much more straightforward way and acpiphp_bridge_handle_to_function() can be dropped (Yay!).
This also will allow some more simplifications to be made going forward.
--- drivers/pci/hotplug/acpiphp.h | 10 ++ drivers/pci/hotplug/acpiphp_glue.c | 152 ++++++++++++++++++++++++++----------- 2 files changed, 119 insertions(+), 43 deletions(-)
drivers/pci/hotplug/acpiphp.h +10 -0
@@ -49,6 +49,7 @@ #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) +struct acpiphp_context ;struct acpiphp_bridge ;struct acpiphp_slot ;
@@ -77,6 +78,7 @@ struct acpiphp_bridge {struct kref ref;acpi_handle handle; +struct acpiphp_context *context;/* Ejectable PCI-to-PCI bridge (PCI bridge and PCI function) */ struct acpiphp_func *func;
@@ -119,6 +121,7 @@ struct acpiphp_slot {* typically 8 objects per slot (i.e. for each PCI function) */ struct acpiphp_func { +struct acpiphp_context *context;struct acpiphp_slot *slot;/* parent */ struct list_head sibling;
@@ -129,6 +132,13 @@ struct acpiphp_func {u32 flags;/* see below */ }; +struct acpiphp_context { +struct kref kref; +acpi_handle handle; +struct acpiphp_func *func; +struct acpiphp_bridge *bridge; +}; +/* * struct acpiphp_attention_info - device specific attention registration *
drivers/pci/hotplug/acpiphp_glue.c +109 -43
259 lines not on this page · raw message
RFC PATCH 5/8 ACPI / hotplug / PCI: Unified notify handler for hotplug events
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Using the hotplug context objects introduced previously rework the ACPI-based PCI hotplug (acpiphp) core code so that all notifications for ACPI device objects corresponding to the hotplug PCI devices are handled by one function, handle_hotplug_event(), which recognizes whether it has to handle a bridge or a function.
In addition to code size reduction it allows some ugly pieces of code where notify handlers have to be uninstalled and installed again to go away.
--- drivers/pci/hotplug/acpiphp.h | 1 drivers/pci/hotplug/acpiphp_glue.c | 127 +++++++++++++------------------------ 2 files changed, 48 insertions(+), 80 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +47 -80
@@ -58,11 +58,10 @@ static DEFINE_MUTEX(bridge_mutex);#define MY_NAME "acpiphp_glue" -static void handle_hotplug_event_bridge (acpi_handle ,u32 ,void *); +static void handle_hotplug_event (acpi_handle handle,u32 type,void *data);static void acpiphp_sanitize_bus (struct pci_bus *bus);static void acpiphp_set_hpp_values (struct pci_bus *bus);static void hotplug_event_func (acpi_handle handle,u32 type,void *context); -static void handle_hotplug_event_func (acpi_handle handle,u32 type,void *context);static void free_bridge (struct kref *kref);/* callback routine to check for the existence of a pci dock device */
@@ -163,13 +162,13 @@ static void free_bridge(struct kref *krekfree (slot); } + context = bridge->context;/* Release reference acquired by acpiphp_enumerate_slots(). */ -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) +if (context->handler_for_func)put_bridge (bridge->func->slot->bridge);put_device (&bridge->pci_bus->dev);pci_dev_put (bridge->pci_dev); - context = bridge->context; context->bridge =NULL ;kfree (bridge);acpiphp_put_context (context);
@@ -406,12 +405,12 @@ static acpi_status register_slot(acpi_ha/* install notify handler */ if (!(newfunc->flags &FUNC_HAS_DCK )) { - status =acpi_install_notify_handler (handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func, - newfunc); - -if (ACPI_FAILURE (status)) + status =acpi_install_notify_handler (handle,ACPI_SYSTEM_NOTIFY , + handle_hotplug_event, + context); +if (ACPI_SUCCESS (status)) + context->handler_for_func = true; +else err ("failed to register interrupt notify handler\n" ); }
@@ -465,23 +464,13 @@ static void cleanup_bridge(struct acpiphacpi_status status;acpi_handle handle = bridge->handle; -if (!pci_is_root_bus (bridge->pci_bus)) { - status =acpi_remove_notify_handler (handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_bridge); +if (!bridge->context->handler_for_func) { + status =acpi_remove_notify_handler (handle,ACPI_SYSTEM_NOTIFY , + handle_hotplug_event);if (ACPI_FAILURE (status))err ("failed to remove notify handler\n" ); } -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) { - status =acpi_install_notify_handler (bridge->func->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func, - bridge->func); -if (ACPI_FAILURE (status)) -err ("failed to install interrupt notify handler\n" ); - } -list_for_each_entry (slot, &bridge->slots, node) {list_for_each_entry (func, &slot->funcs, sibling) {if (is_dock_device (func->handle)) {
@@ -489,9 +478,10 @@ static void cleanup_bridge(struct acpiphunregister_dock_notifier (&func->nb); }if (!(func->flags &FUNC_HAS_DCK )) { + func->context->handler_for_func = false; status =acpi_remove_notify_handler (func->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func); +ACPI_SYSTEM_NOTIFY , + handle_hotplug_event);if (ACPI_FAILURE (status))err ("failed to remove notify handler\n" ); }
@@ -1072,31 +1062,6 @@ static void _handle_hotplug_event_bridgeput_bridge (bridge); } -/** -* handle_hotplug_event_bridge - handle ACPI event on bridges -* @handle: Notify()'ed acpi_handle -* @type: Notify code -* @context: pointer to acpiphp_bridge structure -* -* Handles ACPI event notification on {host,p2p} bridges. -*/ -static void handle_hotplug_event_bridge (acpi_handle handle,u32 type, -void *context) -{ -struct acpiphp_bridge *bridge = context; - -/* -* Currently the code adds all hotplug events to the kacpid_wq -* queue when it should add hotplug events to the kacpi_hotplug_wq. -* The proper way to fix this is to reorganize the code so that -* drivers (dock, etc.) do not call acpi_os_execute(), etc. -* For now just re-add this work to the kacpi_hotplug_wq so we -* don't deadlock on hotplug actions. -*/ -get_bridge (bridge); -alloc_acpi_hp_work (handle, type, context, _handle_hotplug_event_bridge); -} -static void hotplug_event_func (acpi_handle handle,u32 type,void *context) {struct acpiphp_func *func = context;
@@ -1154,18 +1119,29 @@ static void _handle_hotplug_event_func(s }/** -* handle_hotplug_event_func - handle ACPI event on functions (i.e. slots) +* handle_hotplug_event - handle ACPI hotplug event * @handle: Notify()'ed acpi_handle * @type: Notify code -* @context: pointer to acpiphp_func structure +* @data: pointer to acpiphp_context structure * * Handles ACPI event notification on slots. */ -static void handle_hotplug_event_func (acpi_handle handle,u32 type, -void *context) +static void handle_hotplug_event (acpi_handle handle,u32 type,void *data) { -struct acpiphp_func *func = context; +struct acpiphp_context *context = data; +void (*work_func)(struct work_struct *work); +if (context->bridge) { +get_bridge (context->bridge); + data = context->bridge; + work_func = _handle_hotplug_event_bridge; + }else if (context->func) { +get_bridge (context->func->slot->bridge); + data = context->func; + work_func = _handle_hotplug_event_func; + }else { +return ; + }/* * Currently the code adds all hotplug events to the kacpid_wq * queue when it should add hotplug events to the kacpi_hotplug_wq.
@@ -1174,8 +1150,7 @@ static void handle_hotplug_event_func(ac* For now just re-add this work to the kacpi_hotplug_wq so we * don't deadlock on hotplug actions. */ -get_bridge (func->slot->bridge); -alloc_acpi_hp_work (handle, type, context, _handle_hotplug_event_func); +alloc_acpi_hp_work (handle, type, data, work_func); }/*
@@ -1243,33 +1218,25 @@ void acpiphp_enumerate_slots(struct pci_if (pci_is_root_bus (bridge->pci_bus))return ; + status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); +if (ACPI_SUCCESS (status)) { +dbg ("found ejectable p2p bridge\n" ); + bridge->flags |=BRIDGE_HAS_EJ0 ; + } +if (context->handler_for_func) { +/* Notify handler already installed. */ + bridge->func = context->func; +get_bridge (context->func->slot->bridge); +return ; + } +/* install notify handler for P2P bridges */ status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_bridge, - bridge); -if (ACPI_FAILURE (status)) { -acpi_handle_err (bridge->handle, -"failed to register notify handler\n" ); - goto err; - } - status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); -if (ACPI_FAILURE (status)) + handle_hotplug_event, context); +if (ACPI_SUCCESS (status))return ; -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; -if (context->func) { -get_bridge (context->func->slot->bridge); - bridge->func = context->func; - handle = context->handle; -WARN_ON (bridge->handle != handle); - status =acpi_remove_notify_handler (handle,ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func); -if (ACPI_FAILURE (status)) -acpi_handle_err (handle, -"failed to remove notify handler\n" ); - } -return ; +acpi_handle_err (bridge->handle,"failed to register notify handler\n" ); err:cleanup_bridge (bridge);
drivers/pci/hotplug/acpiphp.h +1 -0
@@ -137,6 +137,7 @@ struct acpiphp_context {acpi_handle handle;struct acpiphp_func *func;struct acpiphp_bridge *bridge; + bool handler_for_func:1; };/*
Re: [RFC][PATCH 5/8] ACPI / hotplug / PCI: Unified notify handler for hotplug events
drivers/pci/hotplug/acpiphp.h struct acpiphp_context { · line 140
Quoted 9 lines · Rafael J. Wysocki
Index:
linux-pm/drivers/pci/hotplug/acpiphp.h
===================================================================drivers/pci/hotplug/acpiphp.h +1
-0@@ -137,6 +137,7 @@ struct acpiphp_context {acpi_handle handle;struct acpiphp_func *func;struct acpiphp_bridge *bridge; + bool handler_for_func:1;
Hmm, should it be just plain:
bool handler_for_func;
? What's the reason using bitfields for bool?
Quoted 1 line
drivers/pci/hotplug/acpiphp.h +0
-0};
Re: [RFC][PATCH 5/8] ACPI / hotplug / PCI: Unified notify handler for hotplug events
Quoted 13 lines · Mika Westerberg
drivers/pci/hotplug/acpiphp.h struct acpiphp_context { · line 140
Quoted 9 lines · Rafael J. Wysocki
Index:
linux-pm/drivers/pci/hotplug/acpiphp.h
===================================================================drivers/pci/hotplug/acpiphp.h +1
-0@@ -137,6 +137,7 @@ struct acpiphp_context {acpi_handle handle;struct acpiphp_func *func;struct acpiphp_bridge *bridge; + bool handler_for_func:1;Hmm, should it be just plain:
Quoted 3 lines
bool handler_for_func;? What's the reason using bitfields for bool?
If there are more of them, they can be stored together in one int (they are unsigned int under the hood).
I this particular case it doesn't matter and one of subsequent patches will remove that field anyway. :-)
Quoted 1 line
Quoted 1 line
drivers/pci/hotplug/acpiphp.h +0
-0};
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
RFC PATCH 6/8 ACPI / hotplug / PCI: Drop acpiphp_handle_to_bridge()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Using the hotplug context objects introduced previously rework the ACPI-based PCI hotplug (acpiphp) core code to get to acpiphp_bridge objects associated with hotplug bridges from those context objects rather than from the global list of hotplug bridges.
After that the acpiphp_handle_to_bridge() is not necessary any more, so drop it.
--- drivers/pci/hotplug/acpiphp_glue.c | 54 +++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 29 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +25 -29
@@ -441,22 +441,6 @@ static int detect_ejectable_slots(acpi_hreturn found; } -static struct acpiphp_bridge *acpiphp_handle_to_bridge (acpi_handle handle) -{ -struct acpiphp_bridge *bridge; - -mutex_lock (&bridge_mutex); -list_for_each_entry (bridge, &bridge_list, list) -if (bridge->handle == handle) { -get_bridge (bridge); -mutex_unlock (&bridge_mutex); -return bridge; - } -mutex_unlock (&bridge_mutex); - -return NULL ; -} -static void cleanup_bridge (struct acpiphp_bridge *bridge) {struct acpiphp_slot *slot;
@@ -953,37 +937,49 @@ static void acpiphp_sanitize_bus(struct* ACPI event handlers */ -static acpi_status -check_sub_bridges (acpi_handle handle,u32 lvl,void *context,void **rv) +static acpi_status check_sub_bridges (acpi_handle handle,u32 lvl,void *data, +void **rv) { -struct acpiphp_bridge *bridge; -char objname[64 ]; -struct acpi_buffer buffer = { .length =sizeof (objname), - .pointer = objname }; +struct acpiphp_context *context =acpiphp_get_context (handle); + +if (!context) +return AE_OK ; - bridge =acpiphp_handle_to_bridge (handle); -if (bridge) { +if (context->bridge) { +struct acpiphp_bridge *bridge = context->bridge; +char objname[64 ]; +struct acpi_buffer buffer = { .length =sizeof (objname), + .pointer = objname }; + +get_bridge (bridge);acpi_get_name (handle,ACPI_FULL_PATHNAME , &buffer); -dbg ("%s: re-enumerating slots under %s\n" , - __func__, objname); +dbg ("%s: re-enumerating slots under %s\n" , __func__, objname);acpiphp_check_bridge (bridge);put_bridge (bridge); } +acpiphp_put_context (context);return AE_OK ; }void acpiphp_check_host_bridge (acpi_handle handle) { -struct acpiphp_bridge *bridge; +struct acpiphp_context *context =acpiphp_get_context (handle); - bridge =acpiphp_handle_to_bridge (handle); -if (bridge) { +if (!context) +return ; + +if (context->bridge) { +struct acpiphp_bridge *bridge = context->bridge; + +get_bridge (bridge);acpiphp_check_bridge (bridge);put_bridge (bridge); }acpi_walk_namespace (ACPI_TYPE_DEVICE , handle,ACPI_UINT32_MAX , check_sub_bridges,NULL ,NULL ,NULL ); + +acpiphp_put_context (context); }static void _handle_hotplug_event_bridge (struct work_struct *work)
Re: [RFC][PATCH 6/8] ACPI / hotplug / PCI: Drop acpiphp_handle_to_bridge()
Quoted 21 lines · Rafael J. Wysocki
drivers/pci/hotplug/acpiphp_glue.c +7
-8@@ -953,37 +937,49 @@ static void acpiphp_sanitize_bus(struct* ACPI event handlers */ -static acpi_status -check_sub_bridges (acpi_handle handle,u32 lvl,void *context,void **rv) +static acpi_status check_sub_bridges (acpi_handle handle,u32 lvl,void *data, +void **rv) { -struct acpiphp_bridge *bridge; -char objname[64 ]; -struct acpi_buffer buffer = { .length =sizeof (objname), - .pointer = objname }; +struct acpiphp_context *context =acpiphp_get_context (handle); + +if (!context) +return AE_OK ; - bridge =acpiphp_handle_to_bridge (handle); -if (bridge) { +if (context->bridge) {
drivers/pci/hotplug/acpiphp_glue.c static void acpiphp_sanitize_bus(struct · line 956
Quoted 10 lines
drivers/pci/hotplug/acpiphp_glue.c +7
-2+struct acpiphp_bridge *bridge = context->bridge; +char objname[64 ]; +struct acpi_buffer buffer = { .length =sizeof (objname), + .pointer = objname }; + +get_bridge (bridge);acpi_get_name (handle,ACPI_FULL_PATHNAME , &buffer); -dbg ("%s: re-enumerating slots under %s\n" , - __func__, objname); +dbg ("%s: re-enumerating slots under %s\n" , __func__, objname);
Although not related to this patch directly, how about using acpi_handle_debug() or similar here?
Quoted 6 lines
drivers/pci/hotplug/acpiphp_glue.c +1
-0acpiphp_check_bridge (bridge);put_bridge (bridge); } +acpiphp_put_context (context);return AE_OK ; }
Re: [RFC][PATCH 6/8] ACPI / hotplug / PCI: Drop acpiphp_handle_to_bridge()
Quoted 19 lines · Mika Westerberg
Quoted 18 lines · Rafael J. Wysocki
drivers/pci/hotplug/acpiphp_glue.c +6
-6@@ -953,37 +937,49 @@ static void acpiphp_sanitize_bus(struct* ACPI event handlers */ -static acpi_status -check_sub_bridges (acpi_handle handle,u32 lvl,void *context,void **rv) +static acpi_status check_sub_bridges (acpi_handle handle,u32 lvl,void *data, +void **rv) { -struct acpiphp_bridge *bridge; -char objname[64 ]; -struct acpi_buffer buffer = { .length =sizeof (objname), - .pointer = objname }; +struct acpiphp_context *context =acpiphp_get_context (handle); + +if (!context) +return AE_OK ;
Quoted 16 lines
drivers/pci/hotplug/acpiphp_glue.c static void acpiphp_sanitize_bus(struct · line 956
Quoted 13 lines
drivers/pci/hotplug/acpiphp_glue.c +8
-4- bridge =acpiphp_handle_to_bridge (handle); -if (bridge) { +if (context->bridge) { +struct acpiphp_bridge *bridge = context->bridge; +char objname[64 ]; +struct acpi_buffer buffer = { .length =sizeof (objname), + .pointer = objname }; + +get_bridge (bridge);acpi_get_name (handle,ACPI_FULL_PATHNAME , &buffer); -dbg ("%s: re-enumerating slots under %s\n" , - __func__, objname); +dbg ("%s: re-enumerating slots under %s\n" , __func__, objname);Although not related to this patch directly, how about using
acpi_handle_debug()or similar here?
Well, we don't have acpi_handle_debug() and I remember there was a reason why, but I can't recall what the reason was at the moment. :-)
Quoted 6 lines
Quoted 6 lines
drivers/pci/hotplug/acpiphp_glue.c +1
-0acpiphp_check_bridge (bridge);put_bridge (bridge); } +acpiphp_put_context (context);return AE_OK ; }
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
RFC PATCH 7/8 ACPI / hotplug / PCI: Pass hotplug context object to event handlers
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Modify handle_hotplug_event() to pass the entire context object (instead of its fields individually) to work functions started by it.
This change makes the subsequent consolidation of the event handling work functions a bit more straightforward.
--- drivers/pci/hotplug/acpiphp_glue.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +8 -8
@@ -984,6 +984,7 @@ void acpiphp_check_host_bridge(acpi_handstatic void _handle_hotplug_event_bridge (struct work_struct *work) { +struct acpiphp_context *context;struct acpiphp_bridge *bridge;char objname[64 ];struct acpi_buffer buffer = { .length =sizeof (objname),
@@ -995,7 +996,8 @@ static void _handle_hotplug_event_bridge hp_work = container_of(work, struct acpi_hp_work, work); handle = hp_work->handle; type = hp_work->type; - bridge = (struct acpiphp_bridge *)hp_work->context; + context = hp_work->context; + bridge = context->bridge;acpi_scan_lock_acquire ();
@@ -1100,18 +1102,18 @@ static void hotplug_event_func(acpi_handstatic void _handle_hotplug_event_func (struct work_struct *work) { +struct acpiphp_context *context;struct acpi_hp_work *hp_work; -struct acpiphp_func *func; hp_work = container_of(work, struct acpi_hp_work, work); - func = hp_work->context; + context = hp_work->context;acpi_scan_lock_acquire (); -hotplug_event_func (hp_work->handle, hp_work->type, func); +hotplug_event_func (hp_work->handle, hp_work->type, context->func);acpi_scan_lock_release ();kfree (hp_work);/* allocated in handle_hotplug_event_func */ -put_bridge (func->slot->bridge); +put_bridge (context->func->slot->bridge); }/**
@@ -1129,11 +1131,9 @@ static void handle_hotplug_event(acpi_haif (context->bridge) {get_bridge (context->bridge); - data = context->bridge; work_func = _handle_hotplug_event_bridge; }else if (context->func) {get_bridge (context->func->slot->bridge); - data = context->func; work_func = _handle_hotplug_event_func; }else {return ;
@@ -1146,7 +1146,7 @@ static void handle_hotplug_event(acpi_ha* For now just re-add this work to the kacpi_hotplug_wq so we * don't deadlock on hotplug actions. */ -alloc_acpi_hp_work (handle, type, data, work_func); +alloc_acpi_hp_work (handle, type, context, work_func); }/*
RFC PATCH 8/8 ACPI / hotplug / PCI: Merge hotplug event handling functions
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
There are separate handling event functions for hotplug bridges and for hotplug functions, but they may be combined into one common hotplug event handling function which simplifies the code slightly.
That also allows a theoretical bug to be dealt with which in principle may occur if a hotplug bridge is a docking station device, because in that case the bridge-specific notification should be used instead of the device-specific one.
--- drivers/pci/hotplug/acpiphp_glue.c | 156 +++++++++++++++---------------------- 1 file changed, 66 insertions(+), 90 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +66 -90
@@ -61,7 +61,7 @@ static DEFINE_MUTEX(bridge_mutex);static void handle_hotplug_event (acpi_handle handle,u32 type,void *data);static void acpiphp_sanitize_bus (struct pci_bus *bus);static void acpiphp_set_hpp_values (struct pci_bus *bus); -static void hotplug_event_func (acpi_handle handle,u32 type,void *context); +static void hotplug_event (acpi_handle handle,u32 type,void *data);static void free_bridge (struct kref *kref);/* callback routine to check for the existence of a pci dock device */
@@ -210,7 +210,7 @@ static int post_dock_fixups(struct notifstatic const struct acpi_dock_ops acpiphp_dock_ops = { - .handler = hotplug_event_func, + .handler = hotplug_event, };/* Check whether the PCI device is managed by native PCIe hotplug driver */
@@ -244,16 +244,24 @@ static bool device_is_managed_by_native_static void acpiphp_dock_init (void *data) { -struct acpiphp_func *func = data; +struct acpiphp_context *context = data; + +if (context->func) +get_bridge (context->func->slot->bridge); -get_bridge (func->slot->bridge); +if (context->bridge) +get_bridge (context->bridge); }static void acpiphp_dock_release (void *data) { -struct acpiphp_func *func = data; +struct acpiphp_context *context = data; + +if (context->bridge) +put_bridge (context->bridge); -put_bridge (func->slot->bridge); +if (context->func) +put_bridge (context->func->slot->bridge); }/* callback routine to register each ACPI PCI slot object */
@@ -390,7 +398,7 @@ static acpi_status register_slot(acpi_ha*/ newfunc->flags &= ~FUNC_HAS_EJ0 ;if (register_hotplug_dock_device (handle, - &acpiphp_dock_ops, newfunc, + &acpiphp_dock_ops, context, acpiphp_dock_init, acpiphp_dock_release))dbg ("failed to register dock device\n" );
@@ -982,24 +990,14 @@ void acpiphp_check_host_bridge(acpi_handacpiphp_put_context (context); } -static void _handle_hotplug_event_bridge (struct work_struct *work) +static void hotplug_event (acpi_handle handle,u32 type,void *data) { -struct acpiphp_context *context; -struct acpiphp_bridge *bridge; +struct acpiphp_context *context = data; +struct acpiphp_bridge *bridge = context->bridge; +struct acpiphp_func *func = context->func;char objname[64 ];struct acpi_buffer buffer = { .length =sizeof (objname), .pointer = objname }; -struct acpi_hp_work *hp_work; -acpi_handle handle; -u32 type; - - hp_work = container_of(work, struct acpi_hp_work, work); - handle = hp_work->handle; - type = hp_work->type; - context = hp_work->context; - bridge = context->bridge; - -acpi_scan_lock_acquire ();acpi_get_name (handle,ACPI_FULL_PATHNAME , &buffer);
@@ -1008,15 +1006,24 @@ static void _handle_hotplug_event_bridge/* bus re-enumerate */ dbg ("%s: Bus check notify on %s\n" , __func__, objname);dbg ("%s: re-enumerating slots under %s\n" , __func__, objname); -acpiphp_check_bridge (bridge); -acpi_walk_namespace (ACPI_TYPE_DEVICE , handle, -ACPI_UINT32_MAX , check_sub_bridges,NULL ,NULL ,NULL ); +if (bridge) { +acpiphp_check_bridge (bridge); +acpi_walk_namespace (ACPI_TYPE_DEVICE , handle, +ACPI_UINT32_MAX , check_sub_bridges, +NULL ,NULL ,NULL ); + }else { +acpiphp_enable_slot (func->slot); + }break ;case ACPI_NOTIFY_DEVICE_CHECK :/* device check */ dbg ("%s: Device check notify on %s\n" , __func__, objname); -acpiphp_check_bridge (bridge); +if (bridge) +acpiphp_check_bridge (bridge); +else +acpiphp_check_bridge (func->slot->bridge); +break ;case ACPI_NOTIFY_DEVICE_WAKE :
@@ -1027,12 +1034,15 @@ static void _handle_hotplug_event_bridgecase ACPI_NOTIFY_EJECT_REQUEST :/* request device eject */ dbg ("%s: Device eject notify on %s\n" , __func__, objname); -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) { -struct acpiphp_slot *slot; - slot = bridge->func->slot; -if (!acpiphp_disable_slot (slot)) -acpiphp_eject_slot (slot); - } +if (!func) +break ; + +if (bridge && !(bridge->flags &BRIDGE_HAS_EJ0 )) +break ; + +if (!(acpiphp_disable_slot (func->slot))) +acpiphp_eject_slot (func->slot); +break ;case ACPI_NOTIFY_FREQUENCY_MISMATCH :
@@ -1051,56 +1061,13 @@ static void _handle_hotplug_event_bridgebreak ;default : -warn ("notify_handler: unknown event type 0x%x for %s\n" , type, objname); +warn ("notify_handler: unknown event type 0x%x for %s\n" , type, + objname);break ; } - -acpi_scan_lock_release (); -kfree (hp_work);/* allocated in handle_hotplug_event_bridge */ -put_bridge (bridge); } -static void hotplug_event_func (acpi_handle handle,u32 type,void *context) -{ -struct acpiphp_func *func = context; -char objname[64 ]; -struct acpi_buffer buffer = { .length =sizeof (objname), - .pointer = objname }; - -acpi_get_name (handle,ACPI_FULL_PATHNAME , &buffer); - -switch (type) { -case ACPI_NOTIFY_BUS_CHECK : -/* bus re-enumerate */ -dbg ("%s: Bus check notify on %s\n" , __func__, objname); -acpiphp_enable_slot (func->slot); -break ; - -case ACPI_NOTIFY_DEVICE_CHECK : -/* device check : re-enumerate from parent bus */ -dbg ("%s: Device check notify on %s\n" , __func__, objname); -acpiphp_check_bridge (func->slot->bridge); -break ; - -case ACPI_NOTIFY_DEVICE_WAKE : -/* wake event */ -dbg ("%s: Device wake notify on %s\n" , __func__, objname); -break ; - -case ACPI_NOTIFY_EJECT_REQUEST : -/* request device eject */ -dbg ("%s: Device eject notify on %s\n" , __func__, objname); -if (!(acpiphp_disable_slot (func->slot))) -acpiphp_eject_slot (func->slot); -break ; - -default : -warn ("notify_handler: unknown event type 0x%x for %s\n" , type, objname); -break ; - } -} - -static void _handle_hotplug_event_func (struct work_struct *work) +static void handle_hotplug_event_work_fn (struct work_struct *work) {struct acpiphp_context *context;struct acpi_hp_work *hp_work;
@@ -1109,11 +1076,16 @@ static void _handle_hotplug_event_func(s context = hp_work->context;acpi_scan_lock_acquire (); -hotplug_event_func (hp_work->handle, hp_work->type, context->func); +hotplug_event (hp_work->handle, hp_work->type, context);acpi_scan_lock_release (); -kfree (hp_work);/* allocated in handle_hotplug_event_func */ -put_bridge (context->func->slot->bridge); +kfree (hp_work);/* allocated in handle_hotplug_event() */ +if (context->bridge) +put_bridge (context->bridge); + +if (context->func) +put_bridge (context->func->slot->bridge); + }/**
@@ -1127,17 +1099,16 @@ static void _handle_hotplug_event_func(sstatic void handle_hotplug_event (acpi_handle handle,u32 type,void *data) {struct acpiphp_context *context = data; -void (*work_func)(struct work_struct *work); -if (context->bridge) { -get_bridge (context->bridge); - work_func = _handle_hotplug_event_bridge; - }else if (context->func) { -get_bridge (context->func->slot->bridge); - work_func = _handle_hotplug_event_func; - }else { +if (WARN_ON (!context->bridge && !context->func))return ; - } + +if (context->func) +get_bridge (context->func->slot->bridge); + +if (context->bridge) +get_bridge (context->bridge); +/* * Currently the code adds all hotplug events to the kacpid_wq * queue when it should add hotplug events to the kacpi_hotplug_wq.
@@ -1146,7 +1117,7 @@ static void handle_hotplug_event(acpi_ha* For now just re-add this work to the kacpi_hotplug_wq so we * don't deadlock on hotplug actions. */ -alloc_acpi_hp_work (handle, type, context, work_func); +alloc_acpi_hp_work (handle, type, context, handle_hotplug_event_work_fn); }/*
@@ -1226,6 +1197,11 @@ void acpiphp_enumerate_slots(struct pci_return ; } +/* If it has _DCK, there is a notify handler for it already. */ + status =acpi_get_handle (bridge->handle,"_DCK" , &handle); +if (ACPI_SUCCESS (status)) +return ; +/* install notify handler for P2P bridges */ status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , handle_hotplug_event, context);
cover ACPI / hotplug / PCI: Major rework + Thunderbolt workarounds
In reply to Rafael J. WysockiHi,
I've made some progress with my ACPIPHP rework since I posted the series last time and here goes an update.
First off, the previous series was somewhat racy, which should be fixed now. Apart from this there's quite some new material on top of the patches I posted last time (or rather on top of their new versions) and I integrated the Thunderbolt series from Mika with that. As a result,
https://patchwork.kernel.org/patch/2817341/
is required to be applied.
Still untested, still based on 3.10 with ACPI+PM 3.11 material merged on top, but this time I don't have any plans to add more patches to the series for the time being. Also 3.11-rc1 should be out in a couple of days, so I'll be able to integrate this work with the previous cleanups series from Gerry and myself on top of it.
I did my best not to change too much at a time and some steps add stuff that is removed by the subsequent ones, so hopefully it is bisectable.
If anyone finds something questionable or outright bogus in these patches, please let me know before it's too late. ;-)
[ 1/30] Make bus registration and unregistration symmetric. [Resend]
[ 2/30] Consolidate acpiphp_enumerate_slots(). [Resend]
[ 3/30] Fix error code path in register_slot(). [Resend]
[ 4/30] Introduce hotplug context objects for ACPI device objects corresponding
to PCI hotplug devices. [Update]
[ 5/30] Unified notify handler for hotplug events. [Update]
[ 6/30] Drop acpiphp_handle_to_bridge() and use context objects instead of it. [Update] [ 7/30] Pass entire hotplug context objects (instead of their fields
individually) to event handling work functions. [Update]
[ 8/30] Merge hotplug event handling functions. [Update]
[ 9/30] Drop func field from struct acpiphp_bridge.
[10/30] Refactor slot allocation code in register_slot().
[11/30] Make acpiphp_enumerate_slots() to register all devices on the given bus
and install the notification handler for all of them.
[12/30] Drop sun field from struct acpiphp_slot.
[13/30] Use common slot count variable in register_slot().
[14/30] Drop flags field from struct acpiphp_bridge.
[15/30] Embed function structure into struct acpiphp_context.
[16/30] Drop handle field from struct acpiphp_func.
[17/30] Drop handle field from struct acpiphp_bridge.
[18/30] Store parent bridge pointer in function objects and bus pointer in slot
objects.
[19/30] Rework ACPI namespace scanning and trimming routines.
[20/30] Drop redundant checks from check_hotplug_bridge().
[21/30] Consolidate slot disabling and ejecting
[22/30] Do not queue up event handling work items for non-hotplug events. [23/30] Do not execute _PS0 and _PS3 directly.
[24/30] Do not check SLOT_ENABLED in enable_device(). [Thunderbolt series] [25/30] Allow slots without new devices to be rescanned. [Thunderbolt series] [26/30] Check for new devices on enabled slots. [Thunderbolt series, TBD] [27/30] Get rid of unused constands in acpiphp.h. [Thunderbolt series] [28/30] Sanitize acpiphp_get_(latch)|(adapter)_status(). [Thunderbolt series] [29/30] Redefine enable_device() and disable_device() (rename and change to void). [30/30] Clean up the usage of bridge_mutex.
Patch [26/30] seems to go over the top with dropping the non-responsive devices and it probaby needs some more thought. Also the algorithm of bus checks and device checks may need to be improved in the future, but for the time being I think it is good enough.
Comments welcome!
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
RFC PATCH 1/30 ACPI / PCI: Make bus registration and unregistration symmetric
From: Rafael J. Wysocki <[email protected]>
Since acpi_pci_slot_enumerate() and acpiphp_enumerate_slots() can get the ACPI device handle they need from bus->bridge, it is not necessary to pass that handle to them as an argument.
Drop the second argument of acpi_pci_slot_enumerate() and acpiphp_enumerate_slots(), rework them to obtain the ACPI handle from bus->bridge and make acpi_pci_add_bus() and acpi_pci_remove_bus() entirely symmetrical.
--- drivers/acpi/pci_slot.c | 14 +++++++++----- drivers/pci/hotplug/acpiphp_glue.c | 7 ++++--- drivers/pci/pci-acpi.c | 16 ++++------------ include/linux/pci-acpi.h | 10 ++++------ 4 files changed, 21 insertions(+), 26 deletions(-)
drivers/acpi/pci_slot.c +9 -5
@@ -159,12 +159,16 @@ register_slot(acpi_handle handle, u32 lvreturn AE_OK ; } -void acpi_pci_slot_enumerate (struct pci_bus *bus,acpi_handle handle) +void acpi_pci_slot_enumerate (struct pci_bus *bus) { -mutex_lock (&slot_list_lock); -acpi_walk_namespace (ACPI_TYPE_DEVICE , handle,1 , - register_slot,NULL , bus,NULL ); -mutex_unlock (&slot_list_lock); +acpi_handle handle =ACPI_HANDLE (bus->bridge); + +if (handle) { +mutex_lock (&slot_list_lock); +acpi_walk_namespace (ACPI_TYPE_DEVICE , handle,1 , + register_slot,NULL , bus,NULL ); +mutex_unlock (&slot_list_lock); + } }void acpi_pci_slot_remove (struct pci_bus *bus)
drivers/pci/hotplug/acpiphp_glue.c +4 -3
@@ -1169,15 +1169,16 @@ static void handle_hotplug_event_func(ac* Create hotplug slots for the PCI bus. * It should always return 0 to avoid skipping following notifiers. */ -void acpiphp_enumerate_slots (struct pci_bus *bus,acpi_handle handle) +void acpiphp_enumerate_slots (struct pci_bus *bus) { -acpi_handle dummy_handle; +acpi_handle handle, dummy_handle;struct acpiphp_bridge *bridge;if (acpiphp_disabled)return ; -if (detect_ejectable_slots (handle) <=0 ) + handle =ACPI_HANDLE (bus->bridge); +if (!handle ||detect_ejectable_slots (handle) <=0 )return ; bridge =kzalloc (sizeof (struct acpiphp_bridge ),GFP_KERNEL );
drivers/pci/pci-acpi.c +4 -12
@@ -290,24 +290,16 @@ static struct pci_platform_pm_ops acpi_pvoid acpi_pci_add_bus (struct pci_bus *bus) { -acpi_handle handle =NULL ; - -if (bus->bridge) - handle =ACPI_HANDLE (bus->bridge); -if (acpi_pci_disabled || handle ==NULL ) +if (acpi_pci_disabled || !bus->bridge)return ; -acpi_pci_slot_enumerate (bus, handle); -acpiphp_enumerate_slots (bus, handle); +acpi_pci_slot_enumerate (bus); +acpiphp_enumerate_slots (bus); }void acpi_pci_remove_bus (struct pci_bus *bus) { -/* -* bus->bridge->acpi_node.handle has already been reset to NULL -* when acpi_pci_remove_bus() is called, so don't check ACPI handle. -*/ -if (acpi_pci_disabled) +if (acpi_pci_disabled || !bus->bridge)return ;acpiphp_remove_slots (bus);
include/linux/pci-acpi.h +4 -6
@@ -47,24 +47,22 @@ void acpi_pci_remove_bus(struct pci_bus#ifdef CONFIG_ACPI_PCI_SLOT void acpi_pci_slot_init (void ); -void acpi_pci_slot_enumerate (struct pci_bus *bus,acpi_handle handle); +void acpi_pci_slot_enumerate (struct pci_bus *bus);void acpi_pci_slot_remove (struct pci_bus *bus);#else static inline void acpi_pci_slot_init (void ) { } -static inline void acpi_pci_slot_enumerate (struct pci_bus *bus, -acpi_handle handle) { } +static inline void acpi_pci_slot_enumerate (struct pci_bus *bus) { }static inline void acpi_pci_slot_remove (struct pci_bus *bus) { }#endif #ifdef CONFIG_HOTPLUG_PCI_ACPI void acpiphp_init (void ); -void acpiphp_enumerate_slots (struct pci_bus *bus,acpi_handle handle); +void acpiphp_enumerate_slots (struct pci_bus *bus);void acpiphp_remove_slots (struct pci_bus *bus);void acpiphp_check_host_bridge (acpi_handle handle);#else static inline void acpiphp_init (void ) { } -static inline void acpiphp_enumerate_slots (struct pci_bus *bus, -acpi_handle handle) { } +static inline void acpiphp_enumerate_slots (struct pci_bus *bus) { }static inline void acpiphp_remove_slots (struct pci_bus *bus) { }static inline void acpiphp_check_host_bridge (acpi_handle handle) { }#endif
RFC PATCH 2/30 ACPI / hotplug / PCI: Consolidate acpiphp_enumerate_slots()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The acpiphp_enumerate_slots() function is now split into two parts, acpiphp_enumerate_slots() proper and init_bridge_misc() which is only called by the former. If these functions are combined, it is possible to make the code easier to follow and to clean up the error handling (to prevent memory leaks on error from happening in particular), so do that.
--- drivers/pci/hotplug/acpiphp_glue.c | 94 ++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 48 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +46 -48
@@ -363,46 +363,6 @@ static int detect_ejectable_slots(acpi_hreturn found; } -/* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */ -static void init_bridge_misc (struct acpiphp_bridge *bridge) -{ -acpi_status status; - -/* must be added to the list prior to calling register_slot */ -mutex_lock (&bridge_mutex); -list_add (&bridge->list, &bridge_list); -mutex_unlock (&bridge_mutex); - -/* register all slot objects under this bridge */ - status =acpi_walk_namespace (ACPI_TYPE_DEVICE , bridge->handle, (u32 )1 , - register_slot,NULL , bridge,NULL ); -if (ACPI_FAILURE (status)) { -mutex_lock (&bridge_mutex); -list_del (&bridge->list); -mutex_unlock (&bridge_mutex); -return ; - } - -/* install notify handler for P2P bridges */ -if (!pci_is_root_bus (bridge->pci_bus)) { -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) { - status =acpi_remove_notify_handler (bridge->func->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func); -if (ACPI_FAILURE (status)) -err ("failed to remove notify handler\n" ); - } - status =acpi_install_notify_handler (bridge->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_bridge, - bridge); - -if (ACPI_FAILURE (status)) { -err ("failed to register interrupt notify handler\n" ); - } - } -} -/* find acpiphp_func from acpiphp_bridge */ static struct acpiphp_func *acpiphp_bridge_handle_to_function (acpi_handle handle)
@@ -1171,8 +1131,9 @@ static void handle_hotplug_event_func(ac*/ void acpiphp_enumerate_slots (struct pci_bus *bus) { -acpi_handle handle, dummy_handle;struct acpiphp_bridge *bridge; +acpi_handle handle; +acpi_status status;if (acpiphp_disabled)return ;
@@ -1200,15 +1161,52 @@ void acpiphp_enumerate_slots(struct pci_*/ get_device (&bus->dev); -if (!pci_is_root_bus (bridge->pci_bus) && -ACPI_SUCCESS (acpi_get_handle (bridge->handle, -"_EJ0" , &dummy_handle))) { -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; - bridge->func =acpiphp_bridge_handle_to_function (handle); +/* must be added to the list prior to calling register_slot */ +mutex_lock (&bridge_mutex); +list_add (&bridge->list, &bridge_list); +mutex_unlock (&bridge_mutex); + +/* register all slot objects under this bridge */ + status =acpi_walk_namespace (ACPI_TYPE_DEVICE , bridge->handle,1 , + register_slot,NULL , bridge,NULL ); +if (ACPI_FAILURE (status)) { +acpi_handle_err (bridge->handle,"failed to register slots\n" ); + goto err; } -init_bridge_misc (bridge); +if (pci_is_root_bus (bridge->pci_bus)) +return ; + +/* install notify handler for P2P bridges */ + status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , + handle_hotplug_event_bridge, + bridge); +if (ACPI_FAILURE (status)) { +acpi_handle_err (bridge->handle, +"failed to register notify handler\n" ); + goto err; + } + + status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); +if (ACPI_FAILURE (status)) +return ; + +dbg ("found ejectable p2p bridge\n" ); + bridge->flags |=BRIDGE_HAS_EJ0 ; + bridge->func =acpiphp_bridge_handle_to_function (bridge->handle); +if (bridge->func) { + status =acpi_remove_notify_handler (bridge->func->handle, +ACPI_SYSTEM_NOTIFY , + handle_hotplug_event_func); +if (ACPI_FAILURE (status)) +acpi_handle_err (bridge->func->handle, +"failed to remove notify handler\n" ); + } +return ; + + err: +cleanup_bridge (bridge); +put_bridge (bridge); }/* Destroy hotplug slots associated with the PCI bus */
RFC PATCH 3/30 ACPI / hotplug / PCI: Always return success after adding a function
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
When a new ACPIPHP function is added by register_slot() and the notify handler cannot be installed for it, register_slot() returns an error status without cleaning up, which causes the entire namespace walk in acpiphp_enumerate_slots() to be aborted, although it still may be possible to successfully install the function notify handler for other device objects under the given brigde.
To address this issue make register_slot() return success after a new function has been added, even if the addition of the notify handler for it has failed.
--- drivers/pci/hotplug/acpiphp_glue.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +2 -3
@@ -335,10 +335,9 @@ register_slot(acpi_handle handle, u32 lvif (ACPI_FAILURE (status))err ("failed to register interrupt notify handler\n" ); - }else - status =AE_OK ; + } -return status; +return AE_OK ; err_exit: bridge->nr_slots--;
RFC PATCH 4/30 ACPI / hotplug / PCI: Hotplug context objects for bridges and functions
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
When either a new hotplug bridge or a new hotplug function is added by the ACPI-based PCI hotplug (ACPIPHP) code, attach a context object to its ACPI handle to store hotplug-related information in it. To start with, put the handle's bridge and function pointers into that object. Count references to the context objects and drop them when they are not needed any more.
First of all, this makes it possible to find out if the given bridge has been registered as a function already in a much more straightforward way and acpiphp_bridge_handle_to_function() can be dropped (Yay!).
This also will allow some more simplifications to be made going forward.
--- drivers/pci/hotplug/acpiphp.h | 10 ++ drivers/pci/hotplug/acpiphp_glue.c | 180 +++++++++++++++++++++++++++---------- 2 files changed, 146 insertions(+), 44 deletions(-)
drivers/pci/hotplug/acpiphp.h +10 -0
@@ -49,6 +49,7 @@ #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) +struct acpiphp_context ;struct acpiphp_bridge ;struct acpiphp_slot ;
@@ -77,6 +78,7 @@ struct acpiphp_bridge {struct kref ref;acpi_handle handle; +struct acpiphp_context *context;/* Ejectable PCI-to-PCI bridge (PCI bridge and PCI function) */ struct acpiphp_func *func;
@@ -119,6 +121,7 @@ struct acpiphp_slot {* typically 8 objects per slot (i.e. for each PCI function) */ struct acpiphp_func { +struct acpiphp_context *context;struct acpiphp_slot *slot;/* parent */ struct list_head sibling;
@@ -129,6 +132,13 @@ struct acpiphp_func {u32 flags;/* see below */ }; +struct acpiphp_context { +acpi_handle handle; +struct acpiphp_func *func; +struct acpiphp_bridge *bridge; +unsigned int refcount; +}; +/* * struct acpiphp_attention_info - device specific attention registration *
drivers/pci/hotplug/acpiphp_glue.c +136 -44
291 lines not on this page · raw message
RFC PATCH 5/30 ACPI / hotplug / PCI: Unified notify handler for hotplug events
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Using the hotplug context objects introduced previously rework the ACPI-based PCI hotplug (ACPIPHP) core code so that all notifications for ACPI device objects corresponding to the hotplug PCI devices are handled by one function, handle_hotplug_event(), which recognizes whether it has to handle a bridge or a function.
In addition to code size reduction it allows some ugly pieces of code where notify handlers have to be uninstalled and installed again to go away. Moreover, it fixes a theoretically possible race between handle_hotplug_event() and free_bridge() tearing down data structures for the same handle.
--- drivers/pci/hotplug/acpiphp.h | 1 drivers/pci/hotplug/acpiphp_glue.c | 133 ++++++++++++++----------------------- 2 files changed, 54 insertions(+), 80 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +53 -80
@@ -59,11 +59,10 @@ static DEFINE_MUTEX(acpiphp_context_lock#define MY_NAME "acpiphp_glue" -static void handle_hotplug_event_bridge (acpi_handle ,u32 ,void *); +static void handle_hotplug_event (acpi_handle handle,u32 type,void *data);static void acpiphp_sanitize_bus (struct pci_bus *bus);static void acpiphp_set_hpp_values (struct pci_bus *bus);static void hotplug_event_func (acpi_handle handle,u32 type,void *context); -static void handle_hotplug_event_func (acpi_handle handle,u32 type,void *context);static void free_bridge (struct kref *kref);/* callback routine to check for the existence of a pci dock device */
@@ -179,13 +178,13 @@ static void free_bridge(struct kref *krekfree (slot); } + context = bridge->context;/* Release the reference acquired by acpiphp_enumerate_slots(). */ -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) +if (context->handler_for_func)put_bridge (bridge->func->slot->bridge);put_device (&bridge->pci_bus->dev);pci_dev_put (bridge->pci_dev); - context = bridge->context; context->bridge =NULL ;acpiphp_put_context (context);kfree (bridge);
@@ -424,12 +423,12 @@ static acpi_status register_slot(acpi_ha/* install notify handler */ if (!(newfunc->flags &FUNC_HAS_DCK )) { - status =acpi_install_notify_handler (handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func, - newfunc); - -if (ACPI_FAILURE (status)) + status =acpi_install_notify_handler (handle,ACPI_SYSTEM_NOTIFY , + handle_hotplug_event, + context); +if (ACPI_SUCCESS (status)) + context->handler_for_func = true; +else err ("failed to register interrupt notify handler\n" ); }
@@ -486,23 +485,13 @@ static void cleanup_bridge(struct acpiphacpi_status status;acpi_handle handle = bridge->handle; -if (!pci_is_root_bus (bridge->pci_bus)) { - status =acpi_remove_notify_handler (handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_bridge); +if (!bridge->context->handler_for_func) { + status =acpi_remove_notify_handler (handle,ACPI_SYSTEM_NOTIFY , + handle_hotplug_event);if (ACPI_FAILURE (status))err ("failed to remove notify handler\n" ); } -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) { - status =acpi_install_notify_handler (bridge->func->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func, - bridge->func); -if (ACPI_FAILURE (status)) -err ("failed to install interrupt notify handler\n" ); - } -list_for_each_entry (slot, &bridge->slots, node) {list_for_each_entry (func, &slot->funcs, sibling) {if (is_dock_device (func->handle)) {
@@ -510,9 +499,10 @@ static void cleanup_bridge(struct acpiphunregister_dock_notifier (&func->nb); }if (!(func->flags &FUNC_HAS_DCK )) { + func->context->handler_for_func = false; status =acpi_remove_notify_handler (func->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func); +ACPI_SYSTEM_NOTIFY , + handle_hotplug_event);if (ACPI_FAILURE (status))err ("failed to remove notify handler\n" ); }
@@ -1093,31 +1083,6 @@ static void _handle_hotplug_event_bridgeput_bridge (bridge); } -/** -* handle_hotplug_event_bridge - handle ACPI event on bridges -* @handle: Notify()'ed acpi_handle -* @type: Notify code -* @context: pointer to acpiphp_bridge structure -* -* Handles ACPI event notification on {host,p2p} bridges. -*/ -static void handle_hotplug_event_bridge (acpi_handle handle,u32 type, -void *context) -{ -struct acpiphp_bridge *bridge = context; - -/* -* Currently the code adds all hotplug events to the kacpid_wq -* queue when it should add hotplug events to the kacpi_hotplug_wq. -* The proper way to fix this is to reorganize the code so that -* drivers (dock, etc.) do not call acpi_os_execute(), etc. -* For now just re-add this work to the kacpi_hotplug_wq so we -* don't deadlock on hotplug actions. -*/ -get_bridge (bridge); -alloc_acpi_hp_work (handle, type, context, _handle_hotplug_event_bridge); -} -static void hotplug_event_func (acpi_handle handle,u32 type,void *context) {struct acpiphp_func *func = context;
@@ -1175,17 +1140,33 @@ static void _handle_hotplug_event_func(s }/** -* handle_hotplug_event_func - handle ACPI event on functions (i.e. slots) +* handle_hotplug_event - handle ACPI hotplug event * @handle: Notify()'ed acpi_handle * @type: Notify code -* @context: pointer to acpiphp_func structure +* @data: pointer to acpiphp_context structure * * Handles ACPI event notification on slots. */ -static void handle_hotplug_event_func (acpi_handle handle,u32 type, -void *context) +static void handle_hotplug_event (acpi_handle handle,u32 type,void *data) { -struct acpiphp_func *func = context; +struct acpiphp_context *context; +void (*work_func)(struct work_struct *work) =NULL ; + +mutex_lock (&acpiphp_context_lock); + context =acpiphp_get_context (handle); +if (context) { +if (context->bridge) { +get_bridge (context->bridge); + data = context->bridge; + work_func = _handle_hotplug_event_bridge; + }else if (context->func) { +get_bridge (context->func->slot->bridge); + data = context->func; + work_func = _handle_hotplug_event_func; + } +acpiphp_put_context (context); + } +mutex_unlock (&acpiphp_context_lock);/* * Currently the code adds all hotplug events to the kacpid_wq
@@ -1195,8 +1176,8 @@ static void handle_hotplug_event_func(ac* For now just re-add this work to the kacpi_hotplug_wq so we * don't deadlock on hotplug actions. */ -get_bridge (func->slot->bridge); -alloc_acpi_hp_work (handle, type, context, _handle_hotplug_event_func); +if (work_func) +alloc_acpi_hp_work (handle, type, data, work_func); }/*
@@ -1267,33 +1248,25 @@ void acpiphp_enumerate_slots(struct pci_if (pci_is_root_bus (bridge->pci_bus))return ; + status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); +if (ACPI_SUCCESS (status)) { +dbg ("found ejectable p2p bridge\n" ); + bridge->flags |=BRIDGE_HAS_EJ0 ; + } +if (context->handler_for_func) { +/* Notify handler already installed. */ + bridge->func = context->func; +get_bridge (context->func->slot->bridge); +return ; + } +/* install notify handler for P2P bridges */ status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_bridge, - bridge); -if (ACPI_FAILURE (status)) { -acpi_handle_err (bridge->handle, -"failed to register notify handler\n" ); - goto err; - } - status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); -if (ACPI_FAILURE (status)) + handle_hotplug_event,NULL ); +if (ACPI_SUCCESS (status))return ; -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; -if (context->func) { -get_bridge (context->func->slot->bridge); - bridge->func = context->func; - handle = context->handle; -WARN_ON (bridge->handle != handle); - status =acpi_remove_notify_handler (handle,ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func); -if (ACPI_FAILURE (status)) -acpi_handle_err (handle, -"failed to remove notify handler\n" ); - } -return ; +acpi_handle_err (bridge->handle,"failed to register notify handler\n" ); err:cleanup_bridge (bridge);
drivers/pci/hotplug/acpiphp.h +1 -0
@@ -137,6 +137,7 @@ struct acpiphp_context {struct acpiphp_func *func;struct acpiphp_bridge *bridge;unsigned int refcount; +bool handler_for_func; };/*
RFC PATCH 6/30 ACPI / hotplug / PCI: Rework acpiphp_handle_to_bridge()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]> Subject:
Using the hotplug context objects introduced previously rework the ACPI-based PCI hotplug (ACPIPHP) core code to get to acpiphp_bridge objects associated with hotplug bridges from those context objects rather than from the global list of hotplug bridges.
--- drivers/pci/hotplug/acpiphp_glue.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +11 -9
@@ -464,18 +464,20 @@ static int detect_ejectable_slots(acpi_hstatic struct acpiphp_bridge *acpiphp_handle_to_bridge (acpi_handle handle) { -struct acpiphp_bridge *bridge; +struct acpiphp_context *context; +struct acpiphp_bridge *bridge =NULL ; -mutex_lock (&bridge_mutex); -list_for_each_entry (bridge, &bridge_list, list) -if (bridge->handle == handle) { +mutex_lock (&acpiphp_context_lock); + context =acpiphp_get_context (handle); +if (context) { + bridge = context->bridge; +if (bridge)get_bridge (bridge); -mutex_unlock (&bridge_mutex); -return bridge; - } -mutex_unlock (&bridge_mutex); -return NULL ; +acpiphp_put_context (context); + } +mutex_unlock (&acpiphp_context_lock); +return bridge; }static void cleanup_bridge (struct acpiphp_bridge *bridge)
RFC PATCH 7/30 ACPI / hotplug / PCI: Pass hotplug context objects to event handlers
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Modify handle_hotplug_event() to pass the entire context object (instead of its fields individually) to work functions started by it.
This change makes the subsequent consolidation of the event handling work functions a bit more straightforward.
--- drivers/pci/hotplug/acpiphp_glue.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +8 -8
@@ -1011,6 +1011,7 @@ void acpiphp_check_host_bridge(acpi_handstatic void _handle_hotplug_event_bridge (struct work_struct *work) { +struct acpiphp_context *context;struct acpiphp_bridge *bridge;char objname[64 ];struct acpi_buffer buffer = { .length =sizeof (objname),
@@ -1022,7 +1023,8 @@ static void _handle_hotplug_event_bridge hp_work = container_of(work, struct acpi_hp_work, work); handle = hp_work->handle; type = hp_work->type; - bridge = (struct acpiphp_bridge *)hp_work->context; + context = hp_work->context; + bridge = context->bridge;acpi_scan_lock_acquire ();
@@ -1127,18 +1129,18 @@ static void hotplug_event_func(acpi_handstatic void _handle_hotplug_event_func (struct work_struct *work) { +struct acpiphp_context *context;struct acpi_hp_work *hp_work; -struct acpiphp_func *func; hp_work = container_of(work, struct acpi_hp_work, work); - func = hp_work->context; + context = hp_work->context;acpi_scan_lock_acquire (); -hotplug_event_func (hp_work->handle, hp_work->type, func); +hotplug_event_func (hp_work->handle, hp_work->type, context->func);acpi_scan_lock_release ();kfree (hp_work);/* allocated in handle_hotplug_event_func */ -put_bridge (func->slot->bridge); +put_bridge (context->func->slot->bridge); }/**
@@ -1159,11 +1161,9 @@ static void handle_hotplug_event(acpi_haif (context) {if (context->bridge) {get_bridge (context->bridge); - data = context->bridge; work_func = _handle_hotplug_event_bridge; }else if (context->func) {get_bridge (context->func->slot->bridge); - data = context->func; work_func = _handle_hotplug_event_func; }acpiphp_put_context (context);
@@ -1179,7 +1179,7 @@ static void handle_hotplug_event(acpi_ha* don't deadlock on hotplug actions. */ if (work_func) -alloc_acpi_hp_work (handle, type, data, work_func); +alloc_acpi_hp_work (handle, type, context, work_func); }/*
RFC PATCH 8/30 ACPI / hotplug / PCI: Merge hotplug event handling functions
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
There are separate handling event functions for hotplug bridges and for hotplug functions, but they may be combined into one common hotplug event handling function which simplifies the code slightly.
That also allows a theoretical bug to be dealt with which in principle may occur if a hotplug bridge is on a dock station, because in that case the bridge-specific notification should be used instead of the function-specific one, but the dock station always uses the latter.
--- drivers/pci/hotplug/acpiphp_glue.c | 148 +++++++++++++++---------------------- 1 file changed, 63 insertions(+), 85 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +63 -85
@@ -62,7 +62,7 @@ static DEFINE_MUTEX(acpiphp_context_lockstatic void handle_hotplug_event (acpi_handle handle,u32 type,void *data);static void acpiphp_sanitize_bus (struct pci_bus *bus);static void acpiphp_set_hpp_values (struct pci_bus *bus); -static void hotplug_event_func (acpi_handle handle,u32 type,void *context); +static void hotplug_event (acpi_handle handle,u32 type,void *data);static void free_bridge (struct kref *kref);/* callback routine to check for the existence of a pci dock device */
@@ -228,7 +228,7 @@ static int post_dock_fixups(struct notifstatic const struct acpi_dock_ops acpiphp_dock_ops = { - .handler = hotplug_event_func, + .handler = hotplug_event, };/* Check whether the PCI device is managed by native PCIe hotplug driver */
@@ -262,16 +262,16 @@ static bool device_is_managed_by_native_static void acpiphp_dock_init (void *data) { -struct acpiphp_func *func = data; +struct acpiphp_context *context = data; -get_bridge (func->slot->bridge); +get_bridge (context->func->slot->bridge); }static void acpiphp_dock_release (void *data) { -struct acpiphp_func *func = data; +struct acpiphp_context *context = data; -put_bridge (func->slot->bridge); +put_bridge (context->func->slot->bridge); }/* callback routine to register each ACPI PCI slot object */
@@ -408,7 +408,7 @@ static acpi_status register_slot(acpi_ha*/ newfunc->flags &= ~FUNC_HAS_EJ0 ;if (register_hotplug_dock_device (handle, - &acpiphp_dock_ops, newfunc, + &acpiphp_dock_ops, context, acpiphp_dock_init, acpiphp_dock_release))dbg ("failed to register dock device\n" );
@@ -1009,24 +1009,26 @@ void acpiphp_check_host_bridge(acpi_hand ACPI_UINT32_MAX, check_sub_bridges, NULL, NULL, NULL); } -static void _handle_hotplug_event_bridge (struct work_struct *work) +static void hotplug_event (acpi_handle handle,u32 type,void *data) { -struct acpiphp_context *context; +struct acpiphp_context *context = data;struct acpiphp_bridge *bridge; +struct acpiphp_func *func;char objname[64 ];struct acpi_buffer buffer = { .length =sizeof (objname), .pointer = objname }; -struct acpi_hp_work *hp_work; -acpi_handle handle; -u32 type; - hp_work = container_of(work, struct acpi_hp_work, work); - handle = hp_work->handle; - type = hp_work->type; - context = hp_work->context; +mutex_lock (&acpiphp_context_lock); bridge = context->bridge; +if (bridge) +get_bridge (bridge); -acpi_scan_lock_acquire (); +/* +* If context->func is not NULL, we are holding a reference to its +* parent bridge, so it won't go away until we drop that reference. +*/ + func = context->func; +mutex_unlock (&acpiphp_context_lock);acpi_get_name (handle,ACPI_FULL_PATHNAME , &buffer);
@@ -1035,15 +1037,24 @@ static void _handle_hotplug_event_bridge/* bus re-enumerate */ dbg ("%s: Bus check notify on %s\n" , __func__, objname);dbg ("%s: re-enumerating slots under %s\n" , __func__, objname); -acpiphp_check_bridge (bridge); -acpi_walk_namespace (ACPI_TYPE_DEVICE , handle, -ACPI_UINT32_MAX , check_sub_bridges,NULL ,NULL ,NULL ); +if (bridge) { +acpiphp_check_bridge (bridge); +acpi_walk_namespace (ACPI_TYPE_DEVICE , handle, +ACPI_UINT32_MAX , check_sub_bridges, +NULL ,NULL ,NULL ); + }else { +acpiphp_enable_slot (func->slot); + }break ;case ACPI_NOTIFY_DEVICE_CHECK :/* device check */ dbg ("%s: Device check notify on %s\n" , __func__, objname); -acpiphp_check_bridge (bridge); +if (bridge) +acpiphp_check_bridge (bridge); +else +acpiphp_check_bridge (func->slot->bridge); +break ;case ACPI_NOTIFY_DEVICE_WAKE :
@@ -1054,12 +1065,15 @@ static void _handle_hotplug_event_bridgecase ACPI_NOTIFY_EJECT_REQUEST :/* request device eject */ dbg ("%s: Device eject notify on %s\n" , __func__, objname); -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) { -struct acpiphp_slot *slot; - slot = bridge->func->slot; -if (!acpiphp_disable_slot (slot)) -acpiphp_eject_slot (slot); - } +if (!func) +break ; + +if (bridge && !(bridge->flags &BRIDGE_HAS_EJ0 )) +break ; + +if (!(acpiphp_disable_slot (func->slot))) +acpiphp_eject_slot (func->slot); +break ;case ACPI_NOTIFY_FREQUENCY_MISMATCH :
@@ -1078,56 +1092,16 @@ static void _handle_hotplug_event_bridgebreak ;default : -warn ("notify_handler: unknown event type 0x%x for %s\n" , type, objname); +warn ("notify_handler: unknown event type 0x%x for %s\n" , type, + objname);break ; } -acpi_scan_lock_release (); -kfree (hp_work);/* allocated in handle_hotplug_event_bridge */ -put_bridge (bridge); -} - -static void hotplug_event_func (acpi_handle handle,u32 type,void *context) -{ -struct acpiphp_func *func = context; -char objname[64 ]; -struct acpi_buffer buffer = { .length =sizeof (objname), - .pointer = objname }; - -acpi_get_name (handle,ACPI_FULL_PATHNAME , &buffer); - -switch (type) { -case ACPI_NOTIFY_BUS_CHECK : -/* bus re-enumerate */ -dbg ("%s: Bus check notify on %s\n" , __func__, objname); -acpiphp_enable_slot (func->slot); -break ; - -case ACPI_NOTIFY_DEVICE_CHECK : -/* device check : re-enumerate from parent bus */ -dbg ("%s: Device check notify on %s\n" , __func__, objname); -acpiphp_check_bridge (func->slot->bridge); -break ; - -case ACPI_NOTIFY_DEVICE_WAKE : -/* wake event */ -dbg ("%s: Device wake notify on %s\n" , __func__, objname); -break ; - -case ACPI_NOTIFY_EJECT_REQUEST : -/* request device eject */ -dbg ("%s: Device eject notify on %s\n" , __func__, objname); -if (!(acpiphp_disable_slot (func->slot))) -acpiphp_eject_slot (func->slot); -break ; - -default : -warn ("notify_handler: unknown event type 0x%x for %s\n" , type, objname); -break ; - } +if (bridge) +put_bridge (bridge); } -static void _handle_hotplug_event_func (struct work_struct *work) +static void hotplug_event_work (struct work_struct *work) {struct acpiphp_context *context;struct acpi_hp_work *hp_work;
@@ -1136,11 +1110,18 @@ static void _handle_hotplug_event_func(s context = hp_work->context;acpi_scan_lock_acquire (); -hotplug_event_func (hp_work->handle, hp_work->type, context->func); +hotplug_event (hp_work->handle, hp_work->type, context);acpi_scan_lock_release (); -kfree (hp_work);/* allocated in handle_hotplug_event_func */ -put_bridge (context->func->slot->bridge); +kfree (hp_work);/* allocated in handle_hotplug_event() */ + +mutex_lock (&acpiphp_context_lock); +if (context->func) +put_bridge (context->func->slot->bridge); +else +acpiphp_put_context (context); + +mutex_unlock (&acpiphp_context_lock); }/**
@@ -1154,22 +1135,19 @@ static void _handle_hotplug_event_func(sstatic void handle_hotplug_event (acpi_handle handle,u32 type,void *data) {struct acpiphp_context *context; -void (*work_func)(struct work_struct *work) =NULL ;mutex_lock (&acpiphp_context_lock); context =acpiphp_get_context (handle);if (context) { -if (context->bridge) { -get_bridge (context->bridge); - work_func = _handle_hotplug_event_bridge; - }else if (context->func) { +if (context->func) {get_bridge (context->func->slot->bridge); - work_func = _handle_hotplug_event_func; +acpiphp_put_context (context); + }else if (!context->bridge) { +acpiphp_put_context (context); + context =NULL ; } -acpiphp_put_context (context); }mutex_unlock (&acpiphp_context_lock); -/* * Currently the code adds all hotplug events to the kacpid_wq * queue when it should add hotplug events to the kacpi_hotplug_wq.
@@ -1178,8 +1156,8 @@ static void handle_hotplug_event(acpi_ha* For now just re-add this work to the kacpi_hotplug_wq so we * don't deadlock on hotplug actions. */ -if (work_func) -alloc_acpi_hp_work (handle, type, context, work_func); +if (context) +alloc_acpi_hp_work (handle, type, context, hotplug_event_work); }/*
RFC PATCH 9/30 ACPI / hotplug / PCI: Drop func field from struct acpiphp_bridge
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since the func pointer in struct acpiphp_context can always be used instead of the func pointer in struct acpiphp_bridge, drop the latter.
--- drivers/pci/hotplug/acpiphp.h | 2 -- drivers/pci/hotplug/acpiphp_glue.c | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/pci/hotplug/acpiphp.h +0 -2
@@ -79,8 +79,6 @@ struct acpiphp_bridge {acpi_handle handle;struct acpiphp_context *context; -/* Ejectable PCI-to-PCI bridge (PCI bridge and PCI function) */ -struct acpiphp_func *func;int nr_slots;
drivers/pci/hotplug/acpiphp_glue.c +1 -2
@@ -181,7 +181,7 @@ static void free_bridge(struct kref *kre context = bridge->context;/* Release the reference acquired by acpiphp_enumerate_slots(). */ if (context->handler_for_func) -put_bridge (bridge->func->slot->bridge); +put_bridge (context->func->slot->bridge);put_device (&bridge->pci_bus->dev);pci_dev_put (bridge->pci_dev);
@@ -1235,7 +1235,6 @@ void acpiphp_enumerate_slots(struct pci_ }if (context->handler_for_func) {/* Notify handler already installed. */ - bridge->func = context->func;get_bridge (context->func->slot->bridge);return ; }
RFC PATCH 10/30 ACPI / hotplug / PCI: Refactor slot allocation code in register_slot()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
To make the code in register_slot() a bit easier to follow, change the way the slot allocation part is organized. Drop one local variable that's not used any more after that modification.
This code change should not lead to any changes in behavior.
--- drivers/pci/hotplug/acpiphp_glue.c | 74 ++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 38 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +36 -38
@@ -285,7 +285,7 @@ static acpi_status register_slot(acpi_haacpi_handle tmp;acpi_status status =AE_OK ;unsigned long long adr, sun; -int device, function, retval, found =0 ; +int device, function, retval;struct pci_bus *pbus = bridge->pci_bus;struct pci_dev *pdev;u32 val;
@@ -354,44 +354,49 @@ static acpi_status register_slot(acpi_haif (slot->device == device) {if (slot->sun != sun)warn ("sibling found, but _SUN doesn't match!\n" ); - found =1 ; -break ; - } -if (!found) { - slot =kzalloc (sizeof (struct acpiphp_slot ),GFP_KERNEL ); -if (!slot) { - status =AE_NO_MEMORY ; - goto err_out; + goto slot_found; } - slot->bridge = bridge; - slot->device = device; - slot->sun = sun; -INIT_LIST_HEAD (&slot->funcs); -mutex_init (&slot->crit_sect); + slot =kzalloc (sizeof (struct acpiphp_slot ),GFP_KERNEL ); +if (!slot) { + status =AE_NO_MEMORY ; + goto err; + } -mutex_lock (&bridge_mutex); -list_add_tail (&slot->node, &bridge->slots); -mutex_unlock (&bridge_mutex); - bridge->nr_slots++; + slot->bridge = bridge; + slot->device = device; + slot->sun = sun; +INIT_LIST_HEAD (&slot->funcs); +mutex_init (&slot->crit_sect); -dbg ("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n" , - slot->sun,pci_domain_nr (pbus), pbus->number, device); - retval =acpiphp_register_hotplug_slot (slot); -if (retval) { -if (retval == -EBUSY ) -warn ("Slot %llu already registered by another " -"hotplug driver\n" , slot->sun); -else -warn ("acpiphp_register_hotplug_slot failed " -"(err code = 0x%x)\n" , retval); +mutex_lock (&bridge_mutex); +list_add_tail (&slot->node, &bridge->slots); +mutex_unlock (&bridge_mutex); + bridge->nr_slots++; - status =AE_OK ; - goto err; - } +dbg ("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n" , + slot->sun,pci_domain_nr (pbus), pbus->number, device); + + retval =acpiphp_register_hotplug_slot (slot); +if (retval) { +if (retval == -EBUSY ) +warn ("Slot %llu already registered by another " +"hotplug driver\n" , slot->sun); +else +warn ("acpiphp_register_hotplug_slot failed " +"(err code = 0x%x)\n" , retval); + + bridge->nr_slots--; +mutex_lock (&bridge_mutex); +list_del (&slot->node); +mutex_unlock (&bridge_mutex); +kfree (slot); + status =AE_OK ; + goto err; } + slot_found: newfunc->slot = slot;mutex_lock (&bridge_mutex);list_add_tail (&newfunc->sibling, &slot->funcs);
@@ -435,13 +440,6 @@ static acpi_status register_slot(acpi_hareturn AE_OK ; err: - bridge->nr_slots--; -mutex_lock (&bridge_mutex); -list_del (&slot->node); -mutex_unlock (&bridge_mutex); -kfree (slot); - - err_out:mutex_lock (&acpiphp_context_lock); context->func =NULL ;acpiphp_put_context (context);
RFC PATCH 11/30 ACPI / hotplug / PCI: Register all devices under the given bridge
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Rework register_slot() to create a struct acpiphp_func object for every function it is called for and to create acpiphp slots for all of them. Although acpiphp_register_hotplug_slot() is only called for the slots whose functions are identified as "ejectable", so that user space can manipulate them, the ACPIPHP notify handler, handle_hotplug_event(), is now installed for all of the registered functions (that aren't dock stations) and hotplug events may be handled for all of them.
As a result, essentially, all PCI bridges represented by objects in the ACPI namespace are now going to be "hotplug" bridges and that may affect resources allocation in general, although it shouldn't lead to problems.
This allows the code to be simplified substantially and addresses the problem where bus check or device check notifications for some PCI bridges or devices are not handled, because those devices are not recognized as "ejectable" or there appear to be no "ejectable" devices under those bridges.
--- drivers/pci/hotplug/acpiphp.h | 1 drivers/pci/hotplug/acpiphp_glue.c | 231 ++++++++++++------------------------- 2 files changed, 75 insertions(+), 157 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +75 -156
@@ -65,20 +65,6 @@ static void acpiphp_set_hpp_values(strucstatic void hotplug_event (acpi_handle handle,u32 type,void *data);static void free_bridge (struct kref *kref); -/* 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) -{ -int *count = (int *)context; - -if (is_dock_device (handle)) { - (*count)++; -return AE_CTRL_TERMINATE ; - }else { -return AE_OK ; - } -} -static void acpiphp_context_handler (acpi_handle handle,void *context) {/* Intentionally empty. */
@@ -179,14 +165,16 @@ static void free_bridge(struct kref *kre } context = bridge->context; -/* Release the reference acquired by acpiphp_enumerate_slots(). */ -if (context->handler_for_func) +/* Root bridges will not have hotplug context. */ +if (context) { +/* Release the reference taken by acpiphp_enumerate_slots(). */ put_bridge (context->func->slot->bridge); + context->bridge =NULL ; +acpiphp_put_context (context); + }put_device (&bridge->pci_bus->dev);pci_dev_put (bridge->pci_dev); - context->bridge =NULL ; -acpiphp_put_context (context);kfree (bridge);mutex_unlock (&acpiphp_context_lock);
@@ -284,28 +272,24 @@ static acpi_status register_slot(acpi_hastruct acpiphp_func *newfunc;acpi_handle tmp;acpi_status status =AE_OK ; -unsigned long long adr, sun; -int device, function, retval; +unsigned long long adr; +int device, function;struct pci_bus *pbus = bridge->pci_bus; -struct pci_dev *pdev; +struct pci_dev *pdev = bridge->pci_dev;u32 val; -if (!acpi_pci_check_ejectable (pbus, handle) && !is_dock_device (handle)) +if (pdev &&device_is_managed_by_native_pciehp (pdev))return AE_OK ; status =acpi_evaluate_integer (handle,"_ADR" ,NULL , &adr);if (ACPI_FAILURE (status)) { -warn ("can't evaluate _ADR (%#x)\n" , status); +acpi_handle_warn (handle,"can't evaluate _ADR (%#x)\n" , status);return AE_OK ; } device = (adr >>16 ) &0xffff ; function = adr &0xffff ; - pdev = bridge->pci_dev; -if (pdev &&device_is_managed_by_native_pciehp (pdev)) -return AE_OK ; - newfunc =kzalloc (sizeof (struct acpiphp_func ),GFP_KERNEL );if (!newfunc)return AE_NO_MEMORY ;
@@ -340,23 +324,10 @@ static acpi_status register_slot(acpi_haif (ACPI_SUCCESS (acpi_get_handle (handle,"_DCK" , &tmp))) newfunc->flags |=FUNC_HAS_DCK ; - status =acpi_evaluate_integer (handle,"_SUN" ,NULL , &sun); -if (ACPI_FAILURE (status)) { -/* -* use the count of the number of slots we've found -* for the number of the slot -*/ - sun = bridge->nr_slots+1 ; - } -/* search for objects that share the same slot */ list_for_each_entry (slot, &bridge->slots, node) -if (slot->device == device) { -if (slot->sun != sun) -warn ("sibling found, but _SUN doesn't match!\n" ); - +if (slot->device == device) goto slot_found; - } slot =kzalloc (sizeof (struct acpiphp_slot ),GFP_KERNEL );if (!slot) {
@@ -366,34 +337,38 @@ static acpi_status register_slot(acpi_ha slot->bridge = bridge; slot->device = device; - slot->sun = sun;INIT_LIST_HEAD (&slot->funcs);mutex_init (&slot->crit_sect);mutex_lock (&bridge_mutex);list_add_tail (&slot->node, &bridge->slots);mutex_unlock (&bridge_mutex); - bridge->nr_slots++; -dbg ("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n" , - slot->sun,pci_domain_nr (pbus), pbus->number, device); +/* Register slots for ejectable funtions only. */ +if (acpi_pci_check_ejectable (pbus, handle) ||is_dock_device (handle)) { +unsigned long long sun; +int retval; - retval =acpiphp_register_hotplug_slot (slot); -if (retval) { -if (retval == -EBUSY ) -warn ("Slot %llu already registered by another " -"hotplug driver\n" , slot->sun); -else -warn ("acpiphp_register_hotplug_slot failed " -"(err code = 0x%x)\n" , retval); + bridge->nr_slots++; + status =acpi_evaluate_integer (handle,"_SUN" ,NULL , &sun); +if (ACPI_FAILURE (status)) + sun = bridge->nr_slots; - bridge->nr_slots--; -mutex_lock (&bridge_mutex); -list_del (&slot->node); -mutex_unlock (&bridge_mutex); -kfree (slot); - status =AE_OK ; - goto err; + slot->sun = sun; +dbg ("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n" , + slot->sun,pci_domain_nr (pbus), pbus->number, device); + + retval =acpiphp_register_hotplug_slot (slot); +if (retval) { + bridge->nr_slots--; +if (retval == -EBUSY ) +warn ("Slot %llu already registered by another " +"hotplug driver\n" , slot->sun); +else +warn ("acpiphp_register_hotplug_slot failed " +"(err code = 0x%x)\n" , retval); + } +/* Even if the slot registration fails, we can still use it. */ } slot_found:
@@ -431,10 +406,9 @@ static acpi_status register_slot(acpi_ha status =acpi_install_notify_handler (handle,ACPI_SYSTEM_NOTIFY , handle_hotplug_event, context); -if (ACPI_SUCCESS (status)) - context->handler_for_func = true; -else -err ("failed to register interrupt notify handler\n" ); +if (ACPI_FAILURE (status)) +acpi_handle_err (handle, +"failed to install notify handler\n" ); }return AE_OK ;
@@ -448,18 +422,6 @@ static acpi_status register_slot(acpi_hareturn status; } - -/* see if it's worth looking at this bridge */ -static int detect_ejectable_slots (acpi_handle handle) -{ -int found =acpi_pci_detect_ejectable (handle); -if (!found) { -acpi_walk_namespace (ACPI_TYPE_DEVICE , handle, (u32 )1 , - is_pci_dock_device,NULL , (void *)&found,NULL ); - } -return found; -} -static struct acpiphp_bridge *acpiphp_handle_to_bridge (acpi_handle handle) {struct acpiphp_context *context;
@@ -483,14 +445,6 @@ static void cleanup_bridge(struct acpiphstruct acpiphp_slot *slot;struct acpiphp_func *func;acpi_status status; -acpi_handle handle = bridge->handle; - -if (!bridge->context->handler_for_func) { - status =acpi_remove_notify_handler (handle,ACPI_SYSTEM_NOTIFY , - handle_hotplug_event); -if (ACPI_FAILURE (status)) -err ("failed to remove notify handler\n" ); - }list_for_each_entry (slot, &bridge->slots, node) {list_for_each_entry (func, &slot->funcs, sibling) {
@@ -499,7 +453,6 @@ static void cleanup_bridge(struct acpiphunregister_dock_notifier (&func->nb); }if (!(func->flags &FUNC_HAS_DCK )) { - func->context->handler_for_func = false; status =acpi_remove_notify_handler (func->handle,ACPI_SYSTEM_NOTIFY , handle_hotplug_event);
@@ -689,9 +642,7 @@ static void check_hotplug_bridge(structlist_for_each_entry (func, &slot->funcs, sibling) {if (PCI_FUNC (dev->devfn) == func->function) { -/* check if this bridge has ejectable slots */ -if ((detect_ejectable_slots (func->handle) >0 )) - dev->is_hotplug_bridge =1 ; + dev->is_hotplug_bridge =1 ;break ; } }
@@ -1010,8 +961,8 @@ void acpiphp_check_host_bridge(acpi_handstatic void hotplug_event (acpi_handle handle,u32 type,void *data) {struct acpiphp_context *context = data; +struct acpiphp_func *func = context->func;struct acpiphp_bridge *bridge; -struct acpiphp_func *func;char objname[64 ];struct acpi_buffer buffer = { .length =sizeof (objname), .pointer = objname };
@@ -1021,11 +972,6 @@ static void hotplug_event(acpi_handle haif (bridge)get_bridge (bridge); -/* -* If context->func is not NULL, we are holding a reference to its -* parent bridge, so it won't go away until we drop that reference. -*/ - func = context->func;mutex_unlock (&acpiphp_context_lock);acpi_get_name (handle,ACPI_FULL_PATHNAME , &buffer);
@@ -1063,9 +1009,6 @@ static void hotplug_event(acpi_handle hacase ACPI_NOTIFY_EJECT_REQUEST :/* request device eject */ dbg ("%s: Device eject notify on %s\n" , __func__, objname); -if (!func) -break ; -if (bridge && !(bridge->flags &BRIDGE_HAS_EJ0 ))break ;
@@ -1112,14 +1055,7 @@ static void hotplug_event_work(struct woacpi_scan_lock_release ();kfree (hp_work);/* allocated in handle_hotplug_event() */ - -mutex_lock (&acpiphp_context_lock); -if (context->func) -put_bridge (context->func->slot->bridge); -else -acpiphp_put_context (context); - -mutex_unlock (&acpiphp_context_lock); +put_bridge (context->func->slot->bridge); }/**
@@ -1137,13 +1073,8 @@ static void handle_hotplug_event(acpi_hamutex_lock (&acpiphp_context_lock); context =acpiphp_get_context (handle);if (context) { -if (context->func) { -get_bridge (context->func->slot->bridge); -acpiphp_put_context (context); - }else if (!context->bridge) { -acpiphp_put_context (context); - context =NULL ; - } +get_bridge (context->func->slot->bridge); +acpiphp_put_context (context); }mutex_unlock (&acpiphp_context_lock);/*
@@ -1164,7 +1095,6 @@ static void handle_hotplug_event(acpi_ha*/ void acpiphp_enumerate_slots (struct pci_bus *bus) { -struct acpiphp_context *context;struct acpiphp_bridge *bridge;acpi_handle handle;acpi_status status;
@@ -1173,7 +1103,7 @@ void acpiphp_enumerate_slots(struct pci_return ; handle =ACPI_HANDLE (bus->bridge); -if (!handle ||detect_ejectable_slots (handle) <=0 ) +if (!handle)return ; bridge =kzalloc (sizeof (struct acpiphp_bridge ),GFP_KERNEL );
@@ -1188,21 +1118,6 @@ void acpiphp_enumerate_slots(struct pci_ bridge->pci_dev =pci_dev_get (bus->self); bridge->pci_bus = bus; -mutex_lock (&acpiphp_context_lock); - context =acpiphp_get_context (handle); -if (!context) { - context =acpiphp_init_context (handle); -if (!context) { -mutex_unlock (&acpiphp_context_lock); -acpi_handle_err (handle,"No hotplug context\n" ); -kfree (bridge); -return ; - } - } - bridge->context = context; - context->bridge = bridge; -mutex_unlock (&acpiphp_context_lock); -/* * Grab a ref to the subordinate PCI bus in case the bus is * removed via PCI core logical hotplug. The ref pins the bus
@@ -1210,6 +1125,35 @@ void acpiphp_enumerate_slots(struct pci_*/ get_device (&bus->dev); +if (!pci_is_root_bus (bridge->pci_bus)) { +struct acpiphp_context *context; + +/* +* This bridge should have been registered as a hotplug function +* under its parent, so the context has to be there. If not, we +* are in deep goo. +*/ +mutex_lock (&acpiphp_context_lock); + context =acpiphp_get_context (handle); +if (WARN_ON (!context || !context->func)) { +mutex_unlock (&acpiphp_context_lock); +put_device (&bus->dev); +kfree (bridge); +return ; + } + bridge->context = context; + context->bridge = bridge; +/* Get a reference to the parent bridge. */ +get_bridge (context->func->slot->bridge); +mutex_unlock (&acpiphp_context_lock); + } + + status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); +if (ACPI_SUCCESS (status)) { +dbg ("found ejectable p2p bridge\n" ); + bridge->flags |=BRIDGE_HAS_EJ0 ; + } +/* must be added to the list prior to calling register_slot */ mutex_lock (&bridge_mutex);list_add (&bridge->list, &bridge_list);
@@ -1220,34 +1164,9 @@ void acpiphp_enumerate_slots(struct pci_ register_slot, NULL, bridge, NULL);if (ACPI_FAILURE (status)) {acpi_handle_err (bridge->handle,"failed to register slots\n" ); - goto err; - } - -if (pci_is_root_bus (bridge->pci_bus)) -return ; - - status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); -if (ACPI_SUCCESS (status)) { -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; - } -if (context->handler_for_func) { -/* Notify handler already installed. */ -get_bridge (context->func->slot->bridge); -return ; +cleanup_bridge (bridge); +put_bridge (bridge); } - -/* install notify handler for P2P bridges */ - status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , - handle_hotplug_event,NULL ); -if (ACPI_SUCCESS (status)) -return ; - -acpi_handle_err (bridge->handle,"failed to register notify handler\n" ); - - err: -cleanup_bridge (bridge); -put_bridge (bridge); }/* Destroy hotplug slots associated with the PCI bus */
drivers/pci/hotplug/acpiphp.h +0 -1
@@ -135,7 +135,6 @@ struct acpiphp_context {struct acpiphp_func *func;struct acpiphp_bridge *bridge;unsigned int refcount; -bool handler_for_func; };/*
Re: [RFC][PATCH 11/30] ACPI / hotplug / PCI: Register all devices under the given bridge
Quoted 52 lines · Rafael J. Wysocki
drivers/pci/hotplug/acpiphp_glue.c +29
-12@@ -1210,6 +1125,35 @@ void acpiphp_enumerate_slots(struct pci_*/ get_device (&bus->dev); +if (!pci_is_root_bus (bridge->pci_bus)) { +struct acpiphp_context *context; + +/* +* This bridge should have been registered as a hotplug function +* under its parent, so the context has to be there. If not, we +* are in deep goo. +*/ +mutex_lock (&acpiphp_context_lock); + context =acpiphp_get_context (handle); +if (WARN_ON (!context || !context->func)) { +mutex_unlock (&acpiphp_context_lock); +put_device (&bus->dev); +kfree (bridge); +return ; + } + bridge->context = context; + context->bridge = bridge; +/* Get a reference to the parent bridge. */ +get_bridge (context->func->slot->bridge); +mutex_unlock (&acpiphp_context_lock); + } + + status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); +if (ACPI_SUCCESS (status)) { +dbg ("found ejectable p2p bridge\n" ); + bridge->flags |=BRIDGE_HAS_EJ0 ; + } +/* must be added to the list prior to calling register_slot */ mutex_lock (&bridge_mutex);list_add (&bridge->list, &bridge_list);@@ -1220,34 +1164,9 @@ void acpiphp_enumerate_slots(struct pci_ register_slot, NULL, bridge, NULL);if (ACPI_FAILURE (status)) {acpi_handle_err (bridge->handle,"failed to register slots\n" ); - goto err; - } - -if (pci_is_root_bus (bridge->pci_bus)) -return ; - - status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); -if (ACPI_SUCCESS (status)) { -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; - } -if (context->handler_for_func) {
drivers/pci/hotplug/acpiphp_glue.c void acpiphp_enumerate_slots(struct pci_ · line 1242
Quoted 10 lines
drivers/pci/hotplug/acpiphp_glue.c +2
-7-/* Notify handler already installed. */ -get_bridge (context->func->slot->bridge); -return ; +cleanup_bridge (bridge); +put_bridge (bridge); } - -/* install notify handler for P2P bridges */ - status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , - handle_hotplug_event,NULL );
With this removed we now install notify handlers for the slot objects under this bridge but not for the bridge itself.
In case of Thunderbolt the BIOS will send the event for the root port ACPI device \_SB_.PCI0.RP05 and with the above change we don't handle it anymore.
Quoted 9 lines
drivers/pci/hotplug/acpiphp_glue.c +0
-8-if (ACPI_SUCCESS (status)) -return ; - -acpi_handle_err (bridge->handle,"failed to register notify handler\n" ); - - err: -cleanup_bridge (bridge); -put_bridge (bridge); }
Re: [RFC][PATCH 11/30] ACPI / hotplug / PCI: Register all devices under the given bridge
Quoted 67 lines · Mika Westerberg
Quoted 52 lines · Rafael J. Wysocki
drivers/pci/hotplug/acpiphp_glue.c +29
-12@@ -1210,6 +1125,35 @@ void acpiphp_enumerate_slots(struct pci_*/ get_device (&bus->dev); +if (!pci_is_root_bus (bridge->pci_bus)) { +struct acpiphp_context *context; + +/* +* This bridge should have been registered as a hotplug function +* under its parent, so the context has to be there. If not, we +* are in deep goo. +*/ +mutex_lock (&acpiphp_context_lock); + context =acpiphp_get_context (handle); +if (WARN_ON (!context || !context->func)) { +mutex_unlock (&acpiphp_context_lock); +put_device (&bus->dev); +kfree (bridge); +return ; + } + bridge->context = context; + context->bridge = bridge; +/* Get a reference to the parent bridge. */ +get_bridge (context->func->slot->bridge); +mutex_unlock (&acpiphp_context_lock); + } + + status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); +if (ACPI_SUCCESS (status)) { +dbg ("found ejectable p2p bridge\n" ); + bridge->flags |=BRIDGE_HAS_EJ0 ; + } +/* must be added to the list prior to calling register_slot */ mutex_lock (&bridge_mutex);list_add (&bridge->list, &bridge_list);@@ -1220,34 +1164,9 @@ void acpiphp_enumerate_slots(struct pci_ register_slot, NULL, bridge, NULL);if (ACPI_FAILURE (status)) {acpi_handle_err (bridge->handle,"failed to register slots\n" ); - goto err; - } - -if (pci_is_root_bus (bridge->pci_bus)) -return ; - - status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); -if (ACPI_SUCCESS (status)) { -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; - } -if (context->handler_for_func) {drivers/pci/hotplug/acpiphp_glue.c void acpiphp_enumerate_slots(struct pci_ · line 1242
Quoted 10 lines
drivers/pci/hotplug/acpiphp_glue.c +2
-7-/* Notify handler already installed. */ -get_bridge (context->func->slot->bridge); -return ; +cleanup_bridge (bridge); +put_bridge (bridge); } - -/* install notify handler for P2P bridges */ - status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , - handle_hotplug_event,NULL );With this removed we now install notify handlers for the slot objects under this bridge but not for the bridge itself.
Quoted 3 lines
In case of Thunderbolt the BIOS will send the event for the root port ACPI device \_SB_.PCI0.RP05 and with the above change we don't handle it anymore.
Actually there was a bug in patch [23/30] that caused this. Once that is fixed I can see that the notify handlers get correctly installed. I'll comment on that patch.
RFC PATCH 12/30 ACPI / hotplug / PCI: Drop sun field from struct acpiphp_slot
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
If the slot unique number is passed as an additional argument to acpiphp_register_hotplug_slot(), the slot field in struct acpiphp_slot is not necessary and may be dropped, so make that happen.
--- drivers/pci/hotplug/acpiphp.h | 4 +--- drivers/pci/hotplug/acpiphp_core.c | 5 +++-- drivers/pci/hotplug/acpiphp_glue.c | 7 +++---- 3 files changed, 7 insertions(+), 9 deletions(-)
drivers/pci/hotplug/acpiphp.h +1 -3
@@ -106,8 +106,6 @@ struct acpiphp_slot {struct mutex crit_sect;u8 device;/* pci device# */ - -unsigned long long sun;/* ACPI _SUN (slot unique number) */ u32 flags;/* see below */ };
@@ -180,7 +178,7 @@ struct acpiphp_attention_info/* acpiphp_core.c */ int acpiphp_register_attention (struct acpiphp_attention_info *info);int acpiphp_unregister_attention (struct acpiphp_attention_info *info); -int acpiphp_register_hotplug_slot (struct acpiphp_slot *slot); +int acpiphp_register_hotplug_slot (struct acpiphp_slot *slot,unsigned int sun);void acpiphp_unregister_hotplug_slot (struct acpiphp_slot *slot);/* acpiphp_glue.c */
drivers/pci/hotplug/acpiphp_core.c +3 -2
@@ -290,7 +290,8 @@ static void release_slot(struct hotplug_ }/* callback routine to initialize 'struct slot' for each slot */ -int acpiphp_register_hotplug_slot (struct acpiphp_slot *acpiphp_slot) +int acpiphp_register_hotplug_slot (struct acpiphp_slot *acpiphp_slot, +unsigned int sun) {struct slot *slot;int retval = -ENOMEM ;
@@ -317,7 +318,7 @@ int acpiphp_register_hotplug_slot(struct slot->hotplug_slot->info->adapter_status =acpiphp_get_adapter_status (slot->acpi_slot); acpiphp_slot->slot = slot; -snprintf (name,SLOT_NAME_SIZE ,"%llu" , slot->acpi_slot->sun); +snprintf (name,SLOT_NAME_SIZE ,"%u" , sun); retval = pci_hp_register(slot->hotplug_slot, acpiphp_slot->bridge->pci_bus,
drivers/pci/hotplug/acpiphp_glue.c +3 -4
@@ -354,16 +354,15 @@ static acpi_status register_slot(acpi_haif (ACPI_FAILURE (status)) sun = bridge->nr_slots; - slot->sun = sun;dbg ("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n" , - slot->sun,pci_domain_nr (pbus), pbus->number, device); + sun,pci_domain_nr (pbus), pbus->number, device); - retval =acpiphp_register_hotplug_slot (slot); + retval =acpiphp_register_hotplug_slot (slot, sun);if (retval) { bridge->nr_slots--;if (retval == -EBUSY )warn ("Slot %llu already registered by another " -"hotplug driver\n" , slot->sun); +"hotplug driver\n" , sun);else warn ("acpiphp_register_hotplug_slot failed " "(err code = 0x%x)\n" , retval);
RFC PATCH 13/30 ACPI / hotplug / PCI: Use common slot count variable in register_slot()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
It is not necessary to use per-bridge slot count fields just in order to label slots for devices without _SUN, so use a common static slot_count variable for this purpose and drop the nr_slots field from struct acpiphp_bridge.
--- drivers/pci/hotplug/acpiphp.h | 2 -- drivers/pci/hotplug/acpiphp_glue.c | 7 ++++--- 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/pci/hotplug/acpiphp.h +0 -2
@@ -80,8 +80,6 @@ struct acpiphp_bridge {struct acpiphp_context *context; -int nr_slots; -u32 flags;/* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */
drivers/pci/hotplug/acpiphp_glue.c +4 -3
@@ -346,20 +346,21 @@ static acpi_status register_slot(acpi_ha/* Register slots for ejectable funtions only. */ if (acpi_pci_check_ejectable (pbus, handle) ||is_dock_device (handle)) { +static unsigned int slot_count;unsigned long long sun;int retval; - bridge->nr_slots++; + slot_count++; status =acpi_evaluate_integer (handle,"_SUN" ,NULL , &sun);if (ACPI_FAILURE (status)) - sun = bridge->nr_slots; + sun = slot_count;dbg ("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n" , sun,pci_domain_nr (pbus), pbus->number, device); retval =acpiphp_register_hotplug_slot (slot, sun);if (retval) { - bridge->nr_slots--; + slot_count--;if (retval == -EBUSY )warn ("Slot %llu already registered by another " "hotplug driver\n" , sun);
RFC PATCH 14/30 ACPI / hotplug / PCI: Drop flags field from struct acpiphp_bridge
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The only bridge flag used by the ACPI-based PCI hotplug (ACPIPHP) code is BRIDGE_HAS_EJ0, but it is only used by the event handling function hotplug_event() and if that flag is set, the corresponding function flag FUNC_HAS_EJ0 is set as well, so that bridge flag is redundant.
For this reason, drop BRIDGE_HAS_EJ0 and all code referring to it and since it is the only bridge flag defined, drop the flags field from struct acpiphp_bridge entirely.
--- drivers/pci/hotplug/acpiphp.h | 5 ----- drivers/pci/hotplug/acpiphp_glue.c | 9 --------- 2 files changed, 14 deletions(-)
drivers/pci/hotplug/acpiphp.h +0 -5
@@ -80,8 +80,6 @@ struct acpiphp_bridge {struct acpiphp_context *context; -u32 flags; -/* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */ struct pci_bus *pci_bus;
@@ -152,9 +150,6 @@ struct acpiphp_attention_info/* ACPI _STA method value (ignore bit 4; battery present) */ #define ACPI_STA_ALL (0x0000000f) -/* bridge flags */ -#define BRIDGE_HAS_EJ0 (0x00000001) -/* slot flags */ #define SLOT_POWEREDON (0x00000001)
drivers/pci/hotplug/acpiphp_glue.c +0 -9
@@ -1009,9 +1009,6 @@ static void hotplug_event(acpi_handle hacase ACPI_NOTIFY_EJECT_REQUEST :/* request device eject */ dbg ("%s: Device eject notify on %s\n" , __func__, objname); -if (bridge && !(bridge->flags &BRIDGE_HAS_EJ0 )) -break ; -if (!(acpiphp_disable_slot (func->slot)))acpiphp_eject_slot (func->slot);
@@ -1148,12 +1145,6 @@ void acpiphp_enumerate_slots(struct pci_mutex_unlock (&acpiphp_context_lock); } - status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); -if (ACPI_SUCCESS (status)) { -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; - } -/* must be added to the list prior to calling register_slot */ mutex_lock (&bridge_mutex);list_add (&bridge->list, &bridge_list);
RFC PATCH 15/30 ACPI / hotplug / PCI: Embed function struct into struct acpiphp_context
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since there has to be a struct acpiphp_func object for every struct acpiphp_context created by register_slot(), the struct acpiphp_func one can be embedded into the struct acpiphp_context one, which allows some code simplifications to be made.
--- drivers/pci/hotplug/acpiphp.h | 8 +++++-- drivers/pci/hotplug/acpiphp_glue.c | 42 +++++++++++++------------------------ 2 files changed, 21 insertions(+), 29 deletions(-)
drivers/pci/hotplug/acpiphp.h +6 -2
@@ -113,7 +113,6 @@ struct acpiphp_slot {* typically 8 objects per slot (i.e. for each PCI function) */ struct acpiphp_func { -struct acpiphp_context *context;struct acpiphp_slot *slot;/* parent */ struct list_head sibling;
@@ -126,11 +125,16 @@ struct acpiphp_func {struct acpiphp_context {acpi_handle handle; -struct acpiphp_func *func; +struct acpiphp_func func;struct acpiphp_bridge *bridge;unsigned int refcount; }; +static inline struct acpiphp_context *func_to_context (struct acpiphp_func *func) +{ + return container_of(func, struct acpiphp_context, func); +} +/* * struct acpiphp_attention_info - device specific attention registration *
drivers/pci/hotplug/acpiphp_glue.c +15 -27
123 lines not on this page · raw message
RFC PATCH 16/30 ACPI / hotplug / PCI: Drop handle field from struct acpiphp_func
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The ACPI handle stored in struct acpiphp_func is also stored in the struct acpiphp_context object containing it and it is trivial to get from a struct acpiphp_func pointer to the handle field of the outer struct acpiphp_context.
Hence, the handle field of struct acpiphp_func is redundant, so drop it and provide a helper function, func_to_handle(), allowing it users to get the ACPI handle for the given struct acpiphp_func pointer.
--- drivers/pci/hotplug/acpiphp.h | 6 ++++- drivers/pci/hotplug/acpiphp_glue.c | 42 ++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 18 deletions(-)
drivers/pci/hotplug/acpiphp.h +5 -1
@@ -117,7 +117,6 @@ struct acpiphp_func {struct list_head sibling;struct notifier_block nb; -acpi_handle handle;u8 function;/* pci function# */ u32 flags;/* see below */
@@ -135,6 +134,11 @@ static inline struct acpiphp_context *fu return container_of(func, struct acpiphp_context, func); } +static inline acpi_handle func_to_handle (struct acpiphp_func *func) +{ +return func_to_context (func)->handle; +} +/* * struct acpiphp_attention_info - device specific attention registration *
drivers/pci/hotplug/acpiphp_glue.c +25 -17
117 lines not on this page · raw message
RFC PATCH 17/30 ACPI / hotplug / PCI: Drop handle field from struct acpiphp_bridge
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The handle field in struct acpiphp_bridge is only used by acpiphp_enumerate_slots(), but in that function the local handle variable can be used instead, so make that happen and drop handle from struct acpiphp_bridge.
--- drivers/pci/hotplug/acpiphp.h | 1 - drivers/pci/hotplug/acpiphp_glue.c | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/pci/hotplug/acpiphp.h +0 -1
@@ -76,7 +76,6 @@ struct acpiphp_bridge {struct list_head list;struct list_head slots;struct kref ref; -acpi_handle handle;struct acpiphp_context *context;
drivers/pci/hotplug/acpiphp_glue.c +2 -3
@@ -1107,7 +1107,6 @@ void acpiphp_enumerate_slots(struct pci_INIT_LIST_HEAD (&bridge->slots);kref_init (&bridge->ref); - bridge->handle = handle; bridge->pci_dev =pci_dev_get (bus->self); bridge->pci_bus = bus;
@@ -1147,10 +1146,10 @@ void acpiphp_enumerate_slots(struct pci_mutex_unlock (&bridge_mutex);/* register all slot objects under this bridge */ - status =acpi_walk_namespace (ACPI_TYPE_DEVICE , bridge->handle,1 , + status =acpi_walk_namespace (ACPI_TYPE_DEVICE , handle,1 , register_slot,NULL , bridge,NULL );if (ACPI_FAILURE (status)) { -acpi_handle_err (bridge->handle,"failed to register slots\n" ); +acpi_handle_err (handle,"failed to register slots\n" );cleanup_bridge (bridge);put_bridge (bridge); }
RFC PATCH 18/30 ACPI / hotplug / PCI: Store parent in functions and bus in slots
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
To avoid chasing more pointers than necessary in some situations, move the bridge pointer from struct acpiphp_slot to struct acpiphp_func (and call it 'parent') and add a bus pointer to struct acpiphp_slot.
--- drivers/pci/hotplug/acpiphp.h | 5 +++-- drivers/pci/hotplug/acpiphp_core.c | 6 ++---- drivers/pci/hotplug/acpiphp_glue.c | 25 +++++++++++++------------ 3 files changed, 18 insertions(+), 18 deletions(-)
drivers/pci/hotplug/acpiphp.h +3 -2
@@ -94,7 +94,7 @@ struct acpiphp_bridge {*/ struct acpiphp_slot {struct list_head node; -struct acpiphp_bridge *bridge;/* parent */ +struct pci_bus *bus;struct list_head funcs;/* one slot may have different objects (i.e. for each function) */ struct slot *slot;
@@ -112,7 +112,8 @@ struct acpiphp_slot {* typically 8 objects per slot (i.e. for each PCI function) */ struct acpiphp_func { -struct acpiphp_slot *slot;/* parent */ +struct acpiphp_bridge *parent; +struct acpiphp_slot *slot;struct list_head sibling;struct notifier_block nb;
drivers/pci/hotplug/acpiphp_glue.c +13 -12
@@ -165,7 +165,7 @@ static void free_bridge(struct kref *kre/* Root bridges will not have hotplug context. */ if (context) {/* Release the reference taken by acpiphp_enumerate_slots(). */ -put_bridge (context->func.slot->bridge); +put_bridge (context->func.parent); context->bridge =NULL ;acpiphp_put_context (context); }
@@ -188,7 +188,7 @@ static int post_dock_fixups(struct notif void *v) { struct acpiphp_func *func = container_of(nb, struct acpiphp_func, nb); -struct pci_bus *bus = func->slot->bridge->pci_bus; +struct pci_bus *bus = func->slot->bus;u32 buses;if (!bus->self)
@@ -249,14 +249,14 @@ static void acpiphp_dock_init(void *data {struct acpiphp_context *context = data; -get_bridge (context->func.slot->bridge); +get_bridge (context->func.parent); }static void acpiphp_dock_release (void *data) {struct acpiphp_context *context = data; -put_bridge (context->func.slot->bridge); +put_bridge (context->func.parent); }/* callback routine to register each ACPI PCI slot object */
@@ -296,6 +296,7 @@ static acpi_status register_slot(acpi_ha } newfunc = &context->func; newfunc->function = function; + newfunc->parent = bridge;mutex_unlock (&acpiphp_context_lock);if (ACPI_SUCCESS (acpi_get_handle (handle,"_EJ0" , &tmp)))
@@ -324,7 +325,7 @@ static acpi_status register_slot(acpi_ha goto err; } - slot->bridge = bridge; + slot->bus = bridge->pci_bus; slot->device = device;INIT_LIST_HEAD (&slot->funcs);mutex_init (&slot->crit_sect);
@@ -651,7 +652,7 @@ static void check_hotplug_bridge(structstatic int __ref enable_device (struct acpiphp_slot *slot) {struct pci_dev *dev; -struct pci_bus *bus = slot->bridge->pci_bus; +struct pci_bus *bus = slot->bus;struct acpiphp_func *func;int num, max, pass;LIST_HEAD (add_list);
@@ -721,7 +722,7 @@ static int __ref enable_device(struct ac/* return first device in slot, acquiring a reference on it */ static struct pci_dev *dev_in_slot (struct acpiphp_slot *slot) { -struct pci_bus *bus = slot->bridge->pci_bus; +struct pci_bus *bus = slot->bus;struct pci_dev *dev;struct pci_dev *ret =NULL ;
@@ -793,7 +794,7 @@ static unsigned int get_slot_status(stru }else {u32 dvid; -pci_bus_read_config_dword (slot->bridge->pci_bus, +pci_bus_read_config_dword (slot->bus,PCI_DEVFN (slot->device, func->function),PCI_VENDOR_ID , &dvid);
@@ -993,7 +994,7 @@ static void hotplug_event(acpi_handle haif (bridge)acpiphp_check_bridge (bridge);else -acpiphp_check_bridge (func->slot->bridge); +acpiphp_check_bridge (func->parent);break ;
@@ -1048,7 +1049,7 @@ static void hotplug_event_work(struct woacpi_scan_lock_release ();kfree (hp_work);/* allocated in handle_hotplug_event() */ -put_bridge (context->func.slot->bridge); +put_bridge (context->func.parent); }/**
@@ -1066,7 +1067,7 @@ static void handle_hotplug_event(acpi_hamutex_lock (&acpiphp_context_lock); context =acpiphp_get_context (handle);if (context) { -get_bridge (context->func.slot->bridge); +get_bridge (context->func.parent);acpiphp_put_context (context); }mutex_unlock (&acpiphp_context_lock);
@@ -1136,7 +1137,7 @@ void acpiphp_enumerate_slots(struct pci_ bridge->context = context; context->bridge = bridge;/* Get a reference to the parent bridge. */ -get_bridge (context->func.slot->bridge); +get_bridge (context->func.parent);mutex_unlock (&acpiphp_context_lock); }
drivers/pci/hotplug/acpiphp_core.c +2 -4
@@ -320,10 +320,8 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot->slot = slot;snprintf (name,SLOT_NAME_SIZE ,"%u" , sun); - retval =pci_hp_register (slot->hotplug_slot, - acpiphp_slot->bridge->pci_bus, - acpiphp_slot->device, - name); + retval =pci_hp_register (slot->hotplug_slot, acpiphp_slot->bus, + acpiphp_slot->device, name);if (retval == -EBUSY ) goto error_hpslot;if (retval) {
RFC PATCH 19/30 ACPI / hotplug / PCI: Rework namespace scanning and trimming routines
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The acpiphp_bus_trim() and acpiphp_bus_add() functions need not return error codes that are never checked, so redefine them and simplify them a bit.
--- drivers/pci/hotplug/acpiphp_glue.c | 52 +++++++++---------------------------- 1 file changed, 13 insertions(+), 39 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +13 -39
@@ -552,53 +552,27 @@ static unsigned char acpiphp_max_busnr(sreturn max; } -/** -* acpiphp_bus_add - add a new bus to acpi subsystem -* @func: acpiphp_func of the bridge +* acpiphp_bus_trim - Trim device objects in an ACPI namespace subtree. +* @handle: ACPI device object handle to start from. */ -static int acpiphp_bus_add (struct acpiphp_func *func) +static void acpiphp_bus_trim (acpi_handle handle) { -acpi_handle handle =func_to_handle (func); -struct acpi_device *device; -int ret_val; - -if (!acpi_bus_get_device (handle, &device)) { -dbg ("bus exists... trim\n" ); -/* this shouldn't be in here, so remove -* the bus then re-add it... -*/ -acpi_bus_trim (device); - } - - ret_val =acpi_bus_scan (handle); -if (!ret_val) - ret_val =acpi_bus_get_device (handle, &device); - -if (ret_val) -dbg ("error adding bus, %x\n" , -ret_val); +struct acpi_device *adev =NULL ; -return ret_val; +acpi_bus_get_device (handle, &adev); +if (adev) +acpi_bus_trim (adev); } -/** -* acpiphp_bus_trim - trim a bus from acpi subsystem -* @handle: handle to acpi namespace +* acpiphp_bus_add - Scan ACPI namespace subtree. +* @handle: ACPI object handle to start the scan from. */ -static int acpiphp_bus_trim (acpi_handle handle) +static void acpiphp_bus_add (acpi_handle handle) { -struct acpi_device *device; -int retval; - - retval =acpi_bus_get_device (handle, &device); -if (retval) { -dbg ("acpi_device not found\n" ); -return retval; - } - -acpi_bus_trim (device); -return 0 ; +acpiphp_bus_trim (handle); +acpi_bus_scan (handle); }static void acpiphp_set_acpi_region (struct acpiphp_slot *slot)
@@ -661,7 +635,7 @@ static int __ref enable_device(struct ac goto err_exit;list_for_each_entry (func, &slot->funcs, sibling) -acpiphp_bus_add (func); +acpiphp_bus_add (func_to_handle (func)); num =pci_scan_slot (bus,PCI_DEVFN (slot->device,0 ));if (num ==0 ) {
RFC PATCH 20/30 ACPI / hotplug / PCI: Drop redundant checks from check_hotplug_bridge()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Two checks in check_hotplug_bridge() are redundant (they have been done by the caller already), so drop them.
--- drivers/pci/hotplug/acpiphp_glue.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +0 -6
@@ -598,16 +598,10 @@ static void check_hotplug_bridge(struct {struct acpiphp_func *func; -if (!dev->subordinate) -return ; -/* quirk, or pcie could set it already */ if (dev->is_hotplug_bridge)return ; -if (PCI_SLOT (dev->devfn) != slot->device) -return ; -list_for_each_entry (func, &slot->funcs, sibling) {if (PCI_FUNC (dev->devfn) == func->function) { dev->is_hotplug_bridge =1 ;
RFC PATCH 21/30 ACPI / hotplug / PCI: Consolidate slot disabling and ejecting
In reply to Rafael J. WysockiFrom: Mika Westerberg <[email protected]>
Both acpiphp_disable_slot() and acpiphp_eject_slot() are always called together so instead of calling each separately we can consolidate them into one function acpiphp_disable_and_eject_slot() that does both (but it will return success on _EJ0 failures that were ignored in the majority of call sites anyway).
--- drivers/pci/hotplug/acpiphp.h | 3 - drivers/pci/hotplug/acpiphp_core.c | 6 --- drivers/pci/hotplug/acpiphp_glue.c | 74 +++++++++++++++---------------------- 3 files changed, 33 insertions(+), 50 deletions(-)
drivers/pci/hotplug/acpiphp.h +1 -2
@@ -186,8 +186,7 @@ void acpiphp_unregister_hotplug_slot(strtypedef int (*acpiphp_callback )(struct acpiphp_slot *slot,void *data);int acpiphp_enable_slot (struct acpiphp_slot *slot); -int acpiphp_disable_slot (struct acpiphp_slot *slot); -int acpiphp_eject_slot (struct acpiphp_slot *slot); +int acpiphp_disable_and_eject_slot (struct acpiphp_slot *slot);u8 acpiphp_get_power_status (struct acpiphp_slot *slot);u8 acpiphp_get_attention_status (struct acpiphp_slot *slot);u8 acpiphp_get_latch_status (struct acpiphp_slot *slot);
drivers/pci/hotplug/acpiphp_core.c +1 -5
@@ -155,15 +155,11 @@ static int enable_slot(struct hotplug_slstatic int disable_slot (struct hotplug_slot *hotplug_slot) {struct slot *slot = hotplug_slot->private; -int retval;dbg ("%s - physical_slot = %s\n" , __func__,slot_name (slot));/* disable the specified slot */ - retval =acpiphp_disable_slot (slot->acpi_slot); -if (!retval) - retval =acpiphp_eject_slot (slot->acpi_slot); -return retval; +return acpiphp_disable_and_eject_slot (slot->acpi_slot); }
drivers/pci/hotplug/acpiphp_glue.c +31 -43
108 lines not on this page · raw message
RFC PATCH 22/30 ACPI / hotplug / PCI: Do not queue up event handling work items in vain
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Modify handle_hotplug_event() to avoid queing up the execution of handle_hotplug_event_work_fn() as a work item on kacpi_hotplug_wq for non-hotplug events, such as ACPI_NOTIFY_DEVICE_WAKE. Move the code printing diagnostic messages for those events into handle_hotplug_event().
In addition to that, remove the bogus comment about how the core should distinguish between hotplug and non-hotplug events and queue them up on different workqueues. The core clearly cannot know in advance what events will be interesting to the given caller of acpi_install_notify_handler().
--- drivers/pci/hotplug/acpiphp_glue.c | 64 ++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 35 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +29 -35
@@ -932,36 +932,11 @@ static void hotplug_event(acpi_handle habreak ; -case ACPI_NOTIFY_DEVICE_WAKE : -/* wake event */ -dbg ("%s: Device wake notify on %s\n" , __func__, objname); -break ; -case ACPI_NOTIFY_EJECT_REQUEST :/* request device eject */ dbg ("%s: Device eject notify on %s\n" , __func__, objname);acpiphp_disable_and_eject_slot (func->slot);break ; - -case ACPI_NOTIFY_FREQUENCY_MISMATCH : -printk (KERN_ERR "Device %s cannot be configured due" -" to a frequency mismatch\n" , objname); -break ; - -case ACPI_NOTIFY_BUS_MODE_MISMATCH : -printk (KERN_ERR "Device %s cannot be configured due" -" to a bus mode mismatch\n" , objname); -break ; - -case ACPI_NOTIFY_POWER_FAULT : -printk (KERN_ERR "Device %s has suffered a power fault\n" , - objname); -break ; - -default : -warn ("notify_handler: unknown event type 0x%x for %s\n" , type, - objname); -break ; }if (bridge)
@@ -996,23 +971,42 @@ static void handle_hotplug_event(acpi_ha {struct acpiphp_context *context; +switch (type) { +case ACPI_NOTIFY_BUS_CHECK : +case ACPI_NOTIFY_DEVICE_CHECK : +case ACPI_NOTIFY_EJECT_REQUEST : +break ; + +case ACPI_NOTIFY_DEVICE_WAKE : +return ; + +case ACPI_NOTIFY_FREQUENCY_MISMATCH : +acpi_handle_err (handle,"Device cannot be configured due " +"to a frequency mismatch\n" ); +return ; + +case ACPI_NOTIFY_BUS_MODE_MISMATCH : +acpi_handle_err (handle,"Device cannot be configured due " +"to a bus mode mismatch\n" ); +return ; + +case ACPI_NOTIFY_POWER_FAULT : +acpi_handle_err (handle,"Device has suffered a power fault\n" ); +return ; + +default : +acpi_handle_warn (handle,"Unsupported event type 0x%x\n" , type); +return ; + } +mutex_lock (&acpiphp_context_lock); context =acpiphp_get_context (handle);if (context) {get_bridge (context->func.parent);acpiphp_put_context (context); +alloc_acpi_hp_work (handle, type, context, hotplug_event_work); }mutex_unlock (&acpiphp_context_lock); -/* -* Currently the code adds all hotplug events to the kacpid_wq -* queue when it should add hotplug events to the kacpi_hotplug_wq. -* The proper way to fix this is to reorganize the code so that -* drivers (dock, etc.) do not call acpi_os_execute(), etc. -* For now just re-add this work to the kacpi_hotplug_wq so we -* don't deadlock on hotplug actions. -*/ -if (context) -alloc_acpi_hp_work (handle, type, context, hotplug_event_work); }/*
RFC PATCH 23/30 ACPI / hotplug / PCI: Do not exectute _PS0 and _PS3 directly
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The ACPI-based PCI hotplug (acpiphp) core code need not and really should not execute _PS0 and _PS3 directly for devices it handles.
First of all, it is not necessary to put devices into D3 after acpi_bus_trim() has walked through them, because acpi_device_unregister() invoked by it puts each device into D3cold before returning. Thus after disable_device() the slot should be powered down already.
Second, calling _PS0 directly on ACPI device objects may not be appropriate, because it may require power resources to be set up in a specific way in advance and that must be taken care of by the ACPI core. Thus modify acpiphp_bus_add() to power up the device using the appropriate interface after it has run acpi_bus_scan() on its handle.
After that, the functions executing _PS0 and _PS3, power_on_slot() and power_off_slot(), are not necessary any more, so drop them and update the code calling them accordingly. Also drop the function flags related to device power states, since they aren't useful any more too.
--- drivers/pci/hotplug/acpiphp.h | 7 -- drivers/pci/hotplug/acpiphp_glue.c | 106 +++---------------------------------- 2 files changed, 10 insertions(+), 103 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +9 -97
@@ -305,12 +305,6 @@ static acpi_status register_slot(acpi_haif (ACPI_SUCCESS (acpi_get_handle (handle,"_STA" , &tmp))) newfunc->flags |=FUNC_HAS_STA ; -if (ACPI_SUCCESS (acpi_get_handle (handle,"_PS0" , &tmp))) - newfunc->flags |=FUNC_HAS_PS0 ; - -if (ACPI_SUCCESS (acpi_get_handle (handle,"_PS3" , &tmp))) - newfunc->flags |=FUNC_HAS_PS3 ; -if (ACPI_SUCCESS (acpi_get_handle (handle,"_DCK" , &tmp))) newfunc->flags |=FUNC_HAS_DCK ;
@@ -369,7 +363,7 @@ static acpi_status register_slot(acpi_haif (pci_bus_read_dev_vendor_id (pbus,PCI_DEVFN (device, function), &val,60 *1000 )) - slot->flags |= (SLOT_ENABLED |SLOT_POWEREDON ); + slot->flags |=SLOT_ENABLED ;if (is_dock_device (handle)) {/* we don't want to call this device's _EJ0
@@ -458,73 +452,6 @@ static void cleanup_bridge(struct acpiphmutex_unlock (&bridge_mutex); } -static int power_on_slot (struct acpiphp_slot *slot) -{ -acpi_status status; -struct acpiphp_func *func; -int retval =0 ; - -/* if already enabled, just skip */ -if (slot->flags &SLOT_POWEREDON ) - goto err_exit; - -list_for_each_entry (func, &slot->funcs, sibling) { -if (func->flags &FUNC_HAS_PS0 ) { -dbg ("%s: executing _PS0\n" , __func__); - status =acpi_evaluate_object (func_to_handle (func), -"_PS0" ,NULL ,NULL ); -if (ACPI_FAILURE (status)) { -warn ("%s: _PS0 failed\n" , __func__); - retval =-1 ; - goto err_exit; - }else -break ; - } - } - -/* TBD: evaluate _STA to check if the slot is enabled */ - - slot->flags |=SLOT_POWEREDON ; - - err_exit: -return retval; -} - - -static int power_off_slot (struct acpiphp_slot *slot) -{ -acpi_status status; -struct acpiphp_func *func; - -int retval =0 ; - -/* if already disabled, just skip */ -if ((slot->flags &SLOT_POWEREDON ) ==0 ) - goto err_exit; - -list_for_each_entry (func, &slot->funcs, sibling) { -if (func->flags &FUNC_HAS_PS3 ) { - status =acpi_evaluate_object (func_to_handle (func), -"_PS3" ,NULL ,NULL ); -if (ACPI_FAILURE (status)) { -warn ("%s: _PS3 failed\n" , __func__); - retval =-1 ; - goto err_exit; - }else -break ; - } - } - -/* TBD: evaluate _STA to check if the slot is disabled */ - - slot->flags &= (~SLOT_POWEREDON ); - - err_exit: -return retval; -} - - -/** * acpiphp_max_busnr - return the highest reserved bus number under the given bus. * @bus: bus to start search with
@@ -571,8 +498,13 @@ static void acpiphp_bus_trim(acpi_handle*/ static void acpiphp_bus_add (acpi_handle handle) { +struct acpi_device *adev =NULL ; +acpiphp_bus_trim (handle);acpi_bus_scan (handle); +acpi_bus_get_device (handle, &adev); +if (adev) +acpi_device_set_power (adev,ACPI_STATE_D0 ); }static void acpiphp_set_acpi_region (struct acpiphp_slot *slot)
@@ -1107,23 +1039,8 @@ int acpiphp_enable_slot(struct acpiphp_sint retval;mutex_lock (&slot->crit_sect); - -/* wake up all functions */ - retval =power_on_slot (slot); -if (retval) - goto err_exit; - -if (get_slot_status (slot) ==ACPI_STA_ALL ) { -/* configure all functions */ - retval =enable_device (slot); -if (retval) -power_off_slot (slot); - }else { -dbg ("%s: Slot status is not ACPI_STA_ALL\n" , __func__); -power_off_slot (slot); - } - - err_exit: +/* configure all functions */ + retval =enable_device (slot);mutex_unlock (&slot->crit_sect);return retval; }
@@ -1146,11 +1063,6 @@ int acpiphp_disable_and_eject_slot(strucif (retval) goto err_exit; -/* power off all functions */ - retval =power_off_slot (slot); -if (retval) - goto err_exit; -list_for_each_entry (func, &slot->funcs, sibling) {/* We don't want to call _EJ0 on non-existing functions. */ if (func->flags &FUNC_HAS_EJ0 ) {
@@ -1184,7 +1096,7 @@ int acpiphp_disable_and_eject_slot(struc*/ u8 acpiphp_get_power_status (struct acpiphp_slot *slot) { -return (slot->flags &SLOT_POWEREDON ); +return (slot->flags &SLOT_ENABLED ); }
drivers/pci/hotplug/acpiphp.h +1 -6
@@ -160,7 +160,6 @@ struct acpiphp_attention_info/* slot flags */ -#define SLOT_POWEREDON (0x00000001)#define SLOT_ENABLED (0x00000002)#define SLOT_MULTIFUNCTION (0x00000004)
@@ -168,11 +167,7 @@ struct acpiphp_attention_info#define FUNC_HAS_STA (0x00000001)#define FUNC_HAS_EJ0 (0x00000002) -#define FUNC_HAS_PS0 (0x00000010) -#define FUNC_HAS_PS1 (0x00000020) -#define FUNC_HAS_PS2 (0x00000040) -#define FUNC_HAS_PS3 (0x00000080) -#define FUNC_HAS_DCK (0x00000100) +#define FUNC_HAS_DCK (0x00000003)/* function prototypes */
Re: [RFC][PATCH 23/30] ACPI / hotplug / PCI: Do not exectute _PS0 and _PS3 directly
Quoted 13 lines · Rafael J. Wysocki
Index:
linux-pm/drivers/pci/hotplug/acpiphp.h
===================================================================drivers/pci/hotplug/acpiphp.h +0
-1@@ -160,7 +160,6 @@ struct acpiphp_attention_info/* slot flags */ -#define SLOT_POWEREDON (0x00000001)#define SLOT_ENABLED (0x00000002)#define SLOT_MULTIFUNCTION (0x00000004)
drivers/pci/hotplug/acpiphp.h struct acpiphp_attention_info · line 170
Quoted 9 lines
drivers/pci/hotplug/acpiphp.h +1
-5@@ -168,11 +167,7 @@ struct acpiphp_attention_info#define FUNC_HAS_STA (0x00000001)#define FUNC_HAS_EJ0 (0x00000002) -#define FUNC_HAS_PS0 (0x00000010) -#define FUNC_HAS_PS1 (0x00000020) -#define FUNC_HAS_PS2 (0x00000040) -#define FUNC_HAS_PS3 (0x00000080) -#define FUNC_HAS_DCK (0x00000100) +#define FUNC_HAS_DCK (0x00000003)
These are flags not enum so the above wants to be
#define FUNC_HAS_DCK (0x00000004)
otherwise we accidentally match checks like:
/* install notify handler */
if (!(newfunc->flags & FUNC_HAS_DCK)) {
...Re: [RFC][PATCH 23/30] ACPI / hotplug / PCI: Do not exectute _PS0 and _PS3 directly
Quoted 26 lines · Mika Westerberg
Quoted 13 lines · Rafael J. Wysocki
Index:
linux-pm/drivers/pci/hotplug/acpiphp.h
===================================================================drivers/pci/hotplug/acpiphp.h +0
-1@@ -160,7 +160,6 @@ struct acpiphp_attention_info/* slot flags */ -#define SLOT_POWEREDON (0x00000001)#define SLOT_ENABLED (0x00000002)#define SLOT_MULTIFUNCTION (0x00000004)drivers/pci/hotplug/acpiphp.h struct acpiphp_attention_info · line 170
Quoted 9 lines
drivers/pci/hotplug/acpiphp.h +1
-5@@ -168,11 +167,7 @@ struct acpiphp_attention_info#define FUNC_HAS_STA (0x00000001)#define FUNC_HAS_EJ0 (0x00000002) -#define FUNC_HAS_PS0 (0x00000010) -#define FUNC_HAS_PS1 (0x00000020) -#define FUNC_HAS_PS2 (0x00000040) -#define FUNC_HAS_PS3 (0x00000080) -#define FUNC_HAS_DCK (0x00000100) +#define FUNC_HAS_DCK (0x00000003)These are flags not enum so the above wants to be
Quoted 1 line
#define FUNC_HAS_DCK (0x00000004)
Yeah, obviously.
I guess it goes against the natural tendency to assign numbers to things sequentially, so I generally prefer the (1U << n) notation. :-)
Quoted 5 lines
otherwise we accidentally match checks like:
/* install notify handler */ if (!(newfunc->flags & FUNC_HAS_DCK)) { ...
Yup. Thanks for spotting that!
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
RFC PATCH 24/30 ACPI / hotplug / PCI: Do not check SLOT_ENABLED in enable_device()
In reply to Rafael J. WysockiFrom: Kirill A. Shutemov <[email protected]>
With Thunderbolt you can daisy chain devices: connect new devices to an already plugged one. In that case the "hotplug slot" is already enabled, but we still want to look for new PCI devices behind it.
Reuse enable_device() to scan for new PCI devices on enabled slots and push the SLOT_ENABLED check up into acpiphp_enable_slot().
---drivers/pci/hotplug/acpiphp_glue.c | 5 ++---
drivers/pci/hotplug/acpiphp_glue.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +5 -5
@@ -557,9 +557,6 @@ static int __ref enable_device(struct acint num, max, pass;LIST_HEAD (add_list); -if (slot->flags &SLOT_ENABLED ) - goto err_exit; -list_for_each_entry (func, &slot->funcs, sibling)acpiphp_bus_add (func_to_handle (func));
@@ -1036,11 +1033,14 @@ void acpiphp_remove_slots(struct pci_bus*/ int acpiphp_enable_slot (struct acpiphp_slot *slot) { -int retval; +int retval =0 ;mutex_lock (&slot->crit_sect); +/* configure all functions */ - retval =enable_device (slot); +if (!(slot->flags &SLOT_ENABLED )) + retval =enable_device (slot); +mutex_unlock (&slot->crit_sect);return retval; }
RFC PATCH 25/30 ACPI / hotplug / PCI: Allow slots without new devices to be rescanned
In reply to Rafael J. WysockiFrom: Kirill A. Shutemov <[email protected]>
Currently, enable_device() checks the return value of pci_scan_slot() and returns immediately if that's 0 (meaning that no new functions have been found in the slot). However, if one of the functions in the slot is a bridge, some new devices may appear below it even if the bridge itself is present continuously, so it generally is necessary to do the rescan anyway just in case. [In particular, that's necessary with the Thunderbolt daisy chaining in which case new devices may be connected to the existing ones down the chain.]
The correctness of this change relies on the ability of pcibios_resource_survey_bus() to detect if it has already been called for the given bus and to skip it if so. Failure to do that will lead to resource allocation conflicts.
---drivers/pci/hotplug/acpiphp_glue.c | 11 ++---------
drivers/pci/hotplug/acpiphp_glue.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +2 -9
@@ -554,18 +554,13 @@ static int __ref enable_device(struct acstruct pci_dev *dev;struct pci_bus *bus = slot->bus;struct acpiphp_func *func; -int num, max, pass; +int max, pass;LIST_HEAD (add_list);list_for_each_entry (func, &slot->funcs, sibling)acpiphp_bus_add (func_to_handle (func)); - num =pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); -if (num ==0 ) { -/* Maybe only part of funcs are added. */ -dbg ("No new device found\n" ); - goto err_exit; - } +pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); max =acpiphp_max_busnr (bus);for (pass =0 ; pass <2 ; pass++) {
@@ -611,8 +606,6 @@ static int __ref enable_device(struct ac } } - - err_exit:return 0 ; }
RFC PATCH 26/30 ACPI / hotplug / PCI: Check for new devices on enabled slots
In reply to Rafael J. WysockiFrom: Kirill A. Shutemov <[email protected]> Subject:
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy chaining case properly, however, because in that case the bus behind the already enabled slot needs to be rescanned for new devices.
For this reason, modify acpiphp_check_bridge() so that slots are disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state devices that don't respond are trimmed using a new function, pci_trim_stale_devices(), introduced specifically for this purpose. That function walks the given bus and checks each device on it. If the device doesn't respond, it is assumed to be gone and removed.
Once all of the stale device objects on the bus have been removed, we start looking for new devices that might have appeared on that bus. We do that even if the slot is already enabled (SLOT_ENABLED).
Moreover, make the bus check notification ignore SLOT_ENABLED and go for enable_device() directly if bridge is NULL, so that devices behind the slot are re-enumerated in that case too.
Rafael J. Wysocki <[email protected]>
--- drivers/pci/hotplug/acpiphp_glue.c | 49 +++++++++++++++---------------------- drivers/pci/remove.c | 20 +++++++++++++++ include/linux/pci.h | 1 3 files changed, 42 insertions(+), 28 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +21 -28
@@ -705,41 +705,30 @@ static unsigned int get_slot_status(stru* Iterate over all slots under this bridge and make sure that if a * card is present they are enabled, and if not they are disabled. */ -static int acpiphp_check_bridge (struct acpiphp_bridge *bridge) +static void acpiphp_check_bridge (struct acpiphp_bridge *bridge) {struct acpiphp_slot *slot; -int retval =0 ; -int enabled, disabled; - - enabled = disabled =0 ;list_for_each_entry (slot, &bridge->slots, node) { -unsigned int status =get_slot_status (slot); -if (slot->flags &SLOT_ENABLED ) { -if (status ==ACPI_STA_ALL ) -continue ; - - retval =acpiphp_disable_and_eject_slot (slot); -if (retval) - goto err_exit; +struct pci_bus *bus = slot->bus; +struct pci_dev *dev, *tmp; + +mutex_lock (&slot->crit_sect); +/* wake up all functions */ +if (get_slot_status (slot) ==ACPI_STA_ALL ) { +/* remove stale devices if any */ +list_for_each_entry_safe (dev, tmp, &bus->devices, + bus_list) +if (PCI_SLOT (dev->devfn) == slot->device) +pci_trim_stale_devices (dev); - disabled++; +/* configure all functions */ +enable_device (slot); }else { -if (status !=ACPI_STA_ALL ) -continue ; - retval =acpiphp_enable_slot (slot); -if (retval) { -err ("Error occurred in enabling\n" ); - goto err_exit; - } - enabled++; +disable_device (slot); } +mutex_unlock (&slot->crit_sect); } - -dbg ("%s: %d enabled, %d disabled\n" , __func__, enabled, disabled); - - err_exit: -return retval; }static void acpiphp_set_hpp_values (struct pci_bus *bus)
@@ -840,7 +829,11 @@ static void hotplug_event(acpi_handle haACPI_UINT32_MAX , check_sub_bridges, NULL, NULL, NULL); }else { -acpiphp_enable_slot (func->slot); +struct acpiphp_slot *slot = func->slot; + +mutex_lock (&slot->crit_sect); +enable_device (slot); +mutex_unlock (&slot->crit_sect); }break ;
drivers/pci/remove.c +20 -0
@@ -112,6 +112,26 @@ void pci_stop_and_remove_bus_device(stru }EXPORT_SYMBOL (pci_stop_and_remove_bus_device); +/** +* pci_trim_stale_devices - remove stale device or any stale child +*/ +void pci_trim_stale_devices (struct pci_dev *dev) +{ +struct pci_bus *bus = dev->subordinate; +struct pci_dev *child, *tmp; +bool alive; +u32 l; + +/* check if the device responds */ + alive =pci_bus_read_dev_vendor_id (dev->bus, dev->devfn, &l,0 ); +if (!alive) +pci_stop_and_remove_bus_device (dev); + +if (alive && bus) +list_for_each_entry_safe (child, tmp, &bus->devices, bus_list) +pci_trim_stale_devices (child); +} +void pci_stop_root_bus (struct pci_bus *bus) {struct pci_dev *child, *tmp;
include/linux/pci.h +1 -0
@@ -754,6 +754,7 @@ struct pci_dev *pci_dev_get(struct pci_dvoid pci_dev_put (struct pci_dev *dev);void pci_remove_bus (struct pci_bus *b);void pci_stop_and_remove_bus_device (struct pci_dev *dev); +void pci_trim_stale_devices (struct pci_dev *dev);void pci_stop_root_bus (struct pci_bus *bus);void pci_remove_root_bus (struct pci_bus *bus);void pci_setup_cardbus (struct pci_bus *bus);
RFC PATCH 27/30 ACPI / hotplug / PCI: Get rid of unused constants in acpiphp.h
In reply to Rafael J. WysockiFrom: Mika Westerberg <[email protected]>
Drop some unused symbols from acpiphp.h and redefine SLOT_ENABLED (which is the only slot flag now) as 1.
---drivers/pci/hotplug/acpiphp.h | 4 ----
drivers/pci/hotplug/acpiphp.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/pci/hotplug/acpiphp.h +1 -5
@@ -152,16 +152,12 @@ struct acpiphp_attention_infostruct module *owner; }; -/* PCI bus bridge HID */ -#define ACPI_PCI_HOST_HID "PNP0A03" -/* ACPI _STA method value (ignore bit 4; battery present) */ #define ACPI_STA_ALL (0x0000000f)/* slot flags */ -#define SLOT_ENABLED (0x00000002) -#define SLOT_MULTIFUNCTION (0x00000004) +#define SLOT_ENABLED (0x00000001)/* function flags */
RFC PATCH 28/30 ACPI / hotplug / PCI: Sanitize acpiphp_get_(latch)|(adapter)_status()
In reply to Rafael J. WysockiFrom: Mika Westerberg <[email protected]>
There is no need for a temporary variable and all the tricks with ternary operators in acpiphp_get_(latch)|(adapter)_status(). Change those functions to be a bit more straightforward.
---drivers/pci/hotplug/acpiphp_glue.c | 12 ++----------
drivers/pci/hotplug/acpiphp_glue.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +2 -10
@@ -1092,11 +1092,7 @@ u8 acpiphp_get_power_status(struct acpip*/ u8 acpiphp_get_latch_status (struct acpiphp_slot *slot) { -unsigned int sta; - - sta =get_slot_status (slot); - -return (sta &ACPI_STA_DEVICE_UI ) ?0 :1 ; +return !(get_slot_status (slot) &ACPI_STA_DEVICE_UI ); }
@@ -1106,9 +1102,5 @@ u8 acpiphp_get_latch_status(struct acpip*/ u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot) { -unsigned int sta; - - sta =get_slot_status (slot); - -return (sta ==0 ) ?0 :1 ; +return !!get_slot_status (slot); }
RFC PATCH 29/30 ACPI / hotplug / PCI: Redefine enable_device() and disable_device()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Notice that functions enable_device() and disable_device() cannot fail and their return values are ignored in the majority of places, so redefine them as void and use the opportunity to change their names to enable_slot() and disable_slot(), respectively, which much better reflects what they do.
--- drivers/pci/hotplug/acpiphp_glue.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +12 -21
@@ -543,13 +543,13 @@ static void check_hotplug_bridge(struct }/** -* enable_device - enable, configure a slot +* enable_slot - enable, configure a slot * @slot: slot to be enabled * * This function should be called per *physical slot*, * not per each slot object in ACPI namespace. */ -static int __ref enable_device (struct acpiphp_slot *slot) +static void __ref enable_slot (struct acpiphp_slot *slot) {struct pci_dev *dev;struct pci_bus *bus = slot->bus;
@@ -567,6 +567,7 @@ static int __ref enable_device(struct aclist_for_each_entry (dev, &bus->devices, bus_list) {if (PCI_SLOT (dev->devfn) != slot->device)continue ; +if (dev->hdr_type ==PCI_HEADER_TYPE_BRIDGE || dev->hdr_type ==PCI_HEADER_TYPE_CARDBUS ) { max =pci_scan_bridge (bus, dev, max, pass);
@@ -605,8 +606,6 @@ static int __ref enable_device(struct accontinue ; } } - -return 0 ; }/* return first device in slot, acquiring a reference on it */
@@ -628,16 +627,16 @@ static struct pci_dev *dev_in_slot(struc }/** -* disable_device - disable a slot +* disable_slot - disable a slot * @slot: ACPI PHP slot */ -static int disable_device (struct acpiphp_slot *slot) +static void disable_slot (struct acpiphp_slot *slot) {struct acpiphp_func *func;struct pci_dev *pdev;/* -* enable_device() enumerates all functions in this device via +* enable_slot() enumerates all functions in this device via * pci_scan_slot(), whether they have associated ACPI hotplug * methods (_EJ0, etc.) or not. Therefore, we remove all functions * here.
@@ -651,8 +650,6 @@ static int disable_device(struct acpiphpacpiphp_bus_trim (func_to_handle (func)); slot->flags &= (~SLOT_ENABLED ); - -return 0 ; }
@@ -723,9 +720,9 @@ static void acpiphp_check_bridge(structpci_trim_stale_devices (dev);/* configure all functions */ -enable_device (slot); +enable_slot (slot); }else { -disable_device (slot); +disable_slot (slot); }mutex_unlock (&slot->crit_sect); }
@@ -832,7 +829,7 @@ static void hotplug_event(acpi_handle hastruct acpiphp_slot *slot = func->slot;mutex_lock (&slot->crit_sect); -enable_device (slot); +enable_slot (slot);mutex_unlock (&slot->crit_sect); }break ;
@@ -1019,16 +1016,13 @@ void acpiphp_remove_slots(struct pci_bus*/ int acpiphp_enable_slot (struct acpiphp_slot *slot) { -int retval =0 ; -mutex_lock (&slot->crit_sect); -/* configure all functions */ if (!(slot->flags &SLOT_ENABLED )) - retval =enable_device (slot); +enable_slot (slot);mutex_unlock (&slot->crit_sect); -return retval; +return 0 ; }/**
@@ -1045,9 +1039,7 @@ int acpiphp_disable_and_eject_slot(strucmutex_lock (&slot->crit_sect);/* unconfigure all functions */ - retval =disable_device (slot); -if (retval) - goto err_exit; +disable_slot (slot);list_for_each_entry (func, &slot->funcs, sibling) {/* We don't want to call _EJ0 on non-existing functions. */
@@ -1070,7 +1062,6 @@ int acpiphp_disable_and_eject_slot(struc } } - err_exit:mutex_unlock (&slot->crit_sect);return retval; }
RFC PATCH 30/30 ACPI / hotplug / PCI: Clean up bridge_mutex usage
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Do not acquire bridge_mutex around the addition of a slot to its bridge's list of slots and arount the addition of a function to its slot's list of functions, because that doesn't help anything right now (those lists are walked without any locking anyway).
However, acquire bridge_mutex around the list walk in acpiphp_remove_slots() and use list_for_each_entry() there, because we terminate the walk as soon as we find the first matching entry. This prevents that list walk from colliding with bridge addition and removal.
--- drivers/pci/hotplug/acpiphp_glue.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +7 -7
@@ -324,9 +324,7 @@ static acpi_status register_slot(acpi_haINIT_LIST_HEAD (&slot->funcs);mutex_init (&slot->crit_sect); -mutex_lock (&bridge_mutex);list_add_tail (&slot->node, &bridge->slots); -mutex_unlock (&bridge_mutex);/* Register slots for ejectable funtions only. */ if (acpi_pci_check_ejectable (pbus, handle) ||is_dock_device (handle)) {
@@ -357,9 +355,7 @@ static acpi_status register_slot(acpi_ha slot_found: newfunc->slot = slot; -mutex_lock (&bridge_mutex);list_add_tail (&newfunc->sibling, &slot->funcs); -mutex_unlock (&bridge_mutex);if (pci_bus_read_dev_vendor_id (pbus,PCI_DEVFN (device, function), &val,60 *1000 ))
@@ -997,17 +993,21 @@ void acpiphp_enumerate_slots(struct pci_/* Destroy hotplug slots associated with the PCI bus */ void acpiphp_remove_slots (struct pci_bus *bus) { -struct acpiphp_bridge *bridge, *tmp; +struct acpiphp_bridge *bridge;if (acpiphp_disabled)return ; -list_for_each_entry_safe (bridge, tmp, &bridge_list, list) +mutex_lock (&bridge_mutex); +list_for_each_entry (bridge, &bridge_list, list)if (bridge->pci_bus == bus) { +mutex_unlock (&bridge_mutex);cleanup_bridge (bridge);put_bridge (bridge); -break ; +return ; } + +mutex_unlock (&bridge_mutex); }/**
Re: [RFC][PATCH 0/30] ACPI / hotplug / PCI: Major rework + Thunderbolt workarounds
In reply to Rafael J. WysockiQuoted 5 lines · Rafael J. Wysocki
Hi,
I've made some progress with my ACPIPHP rework since I posted the series last time and here goes an update.
Quoted 8 lines
First off, the previous series was somewhat racy, which should be fixed now. Apart from this there's quite some new material on top of the patches I posted last time (or rather on top of their new versions) and I integrated the Thunderbolt series from Mika with that. As a result,
https://patchwork.kernel.org/patch/2817341/
is required to be applied.
With the above mentioned patch applied + fix for patch [23/30], I tested this series on Acer Aspire S5 and Intel DZ77RE-75K desktop and Thunderbolt works just fine :-)
You can add
to the series.
Nice cleanup!
Re: [RFC][PATCH 0/30] ACPI / hotplug / PCI: Major rework + Thunderbolt workarounds
Quoted 19 lines · Mika Westerberg
Quoted 5 lines · Rafael J. Wysocki
Hi,
I've made some progress with my ACPIPHP rework since I posted the series last time and here goes an update.
Quoted 8 lines
First off, the previous series was somewhat racy, which should be fixed now. Apart from this there's quite some new material on top of the patches I posted last time (or rather on top of their new versions) and I integrated the Thunderbolt series from Mika with that. As a result,
https://patchwork.kernel.org/patch/2817341/
is required to be applied.
With the above mentioned patch applied + fix for patch [23/30], I tested this series on Acer Aspire S5 and Intel DZ77RE-75K desktop and Thunderbolt works just fine :-)
Quoted 5 lines
You can add
Tested-by Mika Westerberg <[email protected]>to the series.
Thanks a lot, that's really helpful!
Now I can rebase it on the previous cleanups and we'll see how that all together works on top of the Linus' current. :-)
Quoted 1 line
Nice cleanup!
Thanks!
cover ACPI / hotplug / PCI: Major rework + Thunderbolt workarounds
In reply to Rafael J. WysockiHi All,
Now the series has been rebased on top of current linux-pm.git/linux-next and tested on two systems with Thunderbolt. Some changes have been made too. ->
Quoted 26 lines · Rafael J. Wysocki
Hi,
I've made some progress with my ACPIPHP rework since I posted the series last time and here goes an update.
First off, the previous series was somewhat racy, which should be fixed now. Apart from this there's quite some new material on top of the patches I posted last time (or rather on top of their new versions) and I integrated the Thunderbolt series from Mika with that. As a result,
https://patchwork.kernel.org/patch/2817341/
is required to be applied.
Still untested, still based on 3.10 with ACPI+PM 3.11 material merged on top, but this time I don't have any plans to add more patches to the series for the time being. Also 3.11-rc1 should be out in a couple of days, so I'll be able to integrate this work with the previous cleanups series from Gerry and myself on top of it.
I did my best not to change too much at a time and some steps add stuff that is removed by the subsequent ones, so hopefully it is bisectable.
If anyone finds something questionable or outright bogus in these patches, please let me know before it's too late. ;-)
Quoted 16 lines
[ 1/30] Make bus registration and unregistration symmetric. [Resend]
[ 2/30] Consolidateacpiphp_enumerate_slots(). [Resend]
[ 3/30] Fix error code path inregister_slot(). [Resend]
[ 4/30] Introduce hotplug context objects for ACPI device objects corresponding
to PCI hotplug devices. [Update]
[ 5/30] Unified notify handler for hotplug events. [Update]
[ 6/30] Dropacpiphp_handle_to_bridge()and use context objects instead of it. [Update] [ 7/30] Pass entire hotplug context objects (instead of their fields
individually) to event handling work functions. [Update]
[ 8/30] Merge hotplug event handling functions. [Update]
[ 9/30] Drop func field from structacpiphp_bridge.
[10/30] Refactor slot allocation code inregister_slot().
[11/30] Makeacpiphp_enumerate_slots()to register all devices on the given bus
and install the notification handler for all of them.
[12/30] Drop sun field from structacpiphp_slot.
[13/30] Use common slot count variable inregister_slot().
-> The one above has been dropped, because it might cause regressions to appear on some systems, but that's not a big deal.
The numbering of the patches below has changed as a result, so the next one is [13/30] now and so on.
Quoted 11 lines
[14/30] Drop flags field from struct
acpiphp_bridge.
[15/30] Embed function structure into structacpiphp_context. [16/30] Drop handle field from structacpiphp_func.
[17/30] Drop handle field from structacpiphp_bridge.
[18/30] Store parent bridge pointer in function objects and bus pointer in slot
objects.
[19/30] Rework ACPI namespace scanning and trimming routines. [20/30] Drop redundant checks fromcheck_hotplug_bridge().
[21/30] Consolidate slot disabling and ejecting
[22/30] Do not queue up event handling work items for non-hotplug events. [23/30] Do not execute_PS0and_PS3directly.
This one was fixed after Mika had reported a problem with it.
Quoted 3 lines
[24/30] Do not check
SLOT_ENABLEDinenable_device(). [Thunderbolt series] [25/30] Allow slots without new devices to be rescanned. [Thunderbolt series] [26/30] Check for new devices on enabled slots. [Thunderbolt series, TBD]
This one was reworked to use acpi_bus_trim() on ACPI device objects corresponding to PCI devices being removed (it also uses _STA to check the status of those devices if available).
Quoted 4 lines
[27/30] Get rid of unused constands in
acpiphp.h. [Thunderbolt series] [28/30] Sanitize acpiphp_get_(latch)|(adapter)_status(). [Thunderbolt series] [29/30] Redefineenable_device()anddisable_device()(rename and change to void). [30/30] Clean up the usage ofbridge_mutex.
The one above is [29/30] now and we have added one more patch:
[30/30] Drop check_sub_bridges() which isn't necessary any more.
The updated patches follow.
If you don't hate this stuff, I'll put it into linux-next over the weekend for further testing.
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
PATCH 1/30 ACPI / PCI: Make bus registration and unregistration symmetric
From: Rafael J. Wysocki <[email protected]>
Since acpi_pci_slot_enumerate() and acpiphp_enumerate_slots() can get the ACPI device handle they need from bus->bridge, it is not necessary to pass that handle to them as an argument.
Drop the second argument of acpi_pci_slot_enumerate() and acpiphp_enumerate_slots(), rework them to obtain the ACPI handle from bus->bridge and make acpi_pci_add_bus() and acpi_pci_remove_bus() entirely symmetrical.
--- drivers/acpi/pci_slot.c | 14 +++++++++----- drivers/pci/hotplug/acpiphp_glue.c | 6 ++++-- drivers/pci/pci-acpi.c | 16 ++++------------ include/linux/pci-acpi.h | 10 ++++------ 4 files changed, 21 insertions(+), 25 deletions(-)
drivers/acpi/pci_slot.c +9 -5
@@ -159,12 +159,16 @@ register_slot(acpi_handle handle, u32 lvreturn AE_OK ; } -void acpi_pci_slot_enumerate (struct pci_bus *bus,acpi_handle handle) +void acpi_pci_slot_enumerate (struct pci_bus *bus) { -mutex_lock (&slot_list_lock); -acpi_walk_namespace (ACPI_TYPE_DEVICE , handle,1 , - register_slot,NULL , bus,NULL ); -mutex_unlock (&slot_list_lock); +acpi_handle handle =ACPI_HANDLE (bus->bridge); + +if (handle) { +mutex_lock (&slot_list_lock); +acpi_walk_namespace (ACPI_TYPE_DEVICE , handle,1 , + register_slot,NULL , bus,NULL ); +mutex_unlock (&slot_list_lock); + } }void acpi_pci_slot_remove (struct pci_bus *bus)
drivers/pci/hotplug/acpiphp_glue.c +4 -2
@@ -1147,14 +1147,16 @@ static void handle_hotplug_event_func(ac* Create hotplug slots for the PCI bus. * It should always return 0 to avoid skipping following notifiers. */ -void acpiphp_enumerate_slots (struct pci_bus *bus,acpi_handle handle) +void acpiphp_enumerate_slots (struct pci_bus *bus) { +acpi_handle handle;struct acpiphp_bridge *bridge;if (acpiphp_disabled)return ; -if (detect_ejectable_slots (handle) <=0 ) + handle =ACPI_HANDLE (bus->bridge); +if (!handle ||detect_ejectable_slots (handle) <=0 )return ; bridge =kzalloc (sizeof (struct acpiphp_bridge ),GFP_KERNEL );
drivers/pci/pci-acpi.c +4 -12
@@ -290,24 +290,16 @@ static struct pci_platform_pm_ops acpi_pvoid acpi_pci_add_bus (struct pci_bus *bus) { -acpi_handle handle =NULL ; - -if (bus->bridge) - handle =ACPI_HANDLE (bus->bridge); -if (acpi_pci_disabled || handle ==NULL ) +if (acpi_pci_disabled || !bus->bridge)return ; -acpi_pci_slot_enumerate (bus, handle); -acpiphp_enumerate_slots (bus, handle); +acpi_pci_slot_enumerate (bus); +acpiphp_enumerate_slots (bus); }void acpi_pci_remove_bus (struct pci_bus *bus) { -/* -* bus->bridge->acpi_node.handle has already been reset to NULL -* when acpi_pci_remove_bus() is called, so don't check ACPI handle. -*/ -if (acpi_pci_disabled) +if (acpi_pci_disabled || !bus->bridge)return ;acpiphp_remove_slots (bus);
include/linux/pci-acpi.h +4 -6
@@ -47,24 +47,22 @@ void acpi_pci_remove_bus(struct pci_bus#ifdef CONFIG_ACPI_PCI_SLOT void acpi_pci_slot_init (void ); -void acpi_pci_slot_enumerate (struct pci_bus *bus,acpi_handle handle); +void acpi_pci_slot_enumerate (struct pci_bus *bus);void acpi_pci_slot_remove (struct pci_bus *bus);#else static inline void acpi_pci_slot_init (void ) { } -static inline void acpi_pci_slot_enumerate (struct pci_bus *bus, -acpi_handle handle) { } +static inline void acpi_pci_slot_enumerate (struct pci_bus *bus) { }static inline void acpi_pci_slot_remove (struct pci_bus *bus) { }#endif #ifdef CONFIG_HOTPLUG_PCI_ACPI void acpiphp_init (void ); -void acpiphp_enumerate_slots (struct pci_bus *bus,acpi_handle handle); +void acpiphp_enumerate_slots (struct pci_bus *bus);void acpiphp_remove_slots (struct pci_bus *bus);void acpiphp_check_host_bridge (acpi_handle handle);#else static inline void acpiphp_init (void ) { } -static inline void acpiphp_enumerate_slots (struct pci_bus *bus, -acpi_handle handle) { } +static inline void acpiphp_enumerate_slots (struct pci_bus *bus) { }static inline void acpiphp_remove_slots (struct pci_bus *bus) { }static inline void acpiphp_check_host_bridge (acpi_handle handle) { }#endif
Re: [PATCH 1/30] ACPI / PCI: Make bus registration and unregistration symmetric
Quoted 89 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Since
acpi_pci_slot_enumerate()andacpiphp_enumerate_slots()can get the ACPI device handle they need frombus->bridge, it is not necessary to pass that handle to them as an argument.Drop the second argument of
acpi_pci_slot_enumerate()andacpiphp_enumerate_slots(), rework them to obtain the ACPI handle frombus->bridgeand makeacpi_pci_add_bus()andacpi_pci_remove_bus()entirely symmetrical.Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/acpi/pci_slot.c | 14 +++++++++----- drivers/pci/hotplug/acpiphp_glue.c | 6 ++++-- drivers/pci/pci-acpi.c | 16 ++++------------ include/linux/pci-acpi.h | 10 ++++------ 4 files changed, 21 insertions(+), 25 deletions(-)Index:
linux-pm/drivers/acpi/pci_slot.c
===================================================================drivers/acpi/pci_slot.c +9
-5@@ -159,12 +159,16 @@ register_slot(acpi_handle handle, u32 lvreturn AE_OK ; } -void acpi_pci_slot_enumerate (struct pci_bus *bus,acpi_handle handle) +void acpi_pci_slot_enumerate (struct pci_bus *bus) { -mutex_lock (&slot_list_lock); -acpi_walk_namespace (ACPI_TYPE_DEVICE , handle,1 , - register_slot,NULL , bus,NULL ); -mutex_unlock (&slot_list_lock); +acpi_handle handle =ACPI_HANDLE (bus->bridge); + +if (handle) { +mutex_lock (&slot_list_lock); +acpi_walk_namespace (ACPI_TYPE_DEVICE , handle,1 , + register_slot,NULL , bus,NULL ); +mutex_unlock (&slot_list_lock); + } }void acpi_pci_slot_remove (struct pci_bus *bus)Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c +4
-2@@ -1147,14 +1147,16 @@ static void handle_hotplug_event_func(ac* Create hotplug slots for the PCI bus. * It should always return 0 to avoid skipping following notifiers. */ -void acpiphp_enumerate_slots (struct pci_bus *bus,acpi_handle handle) +void acpiphp_enumerate_slots (struct pci_bus *bus) { +acpi_handle handle;struct acpiphp_bridge *bridge;if (acpiphp_disabled)return ; -if (detect_ejectable_slots (handle) <=0 ) + handle =ACPI_HANDLE (bus->bridge); +if (!handle ||detect_ejectable_slots (handle) <=0 )return ; bridge =kzalloc (sizeof (struct acpiphp_bridge ),GFP_KERNEL );Index:
linux-pm/drivers/pci/pci-acpi.c
===================================================================drivers/pci/pci-acpi.c +3
-7@@ -290,24 +290,16 @@ static struct pci_platform_pm_ops acpi_pvoid acpi_pci_add_bus (struct pci_bus *bus) { -acpi_handle handle =NULL ; - -if (bus->bridge) - handle =ACPI_HANDLE (bus->bridge); -if (acpi_pci_disabled || handle ==NULL ) +if (acpi_pci_disabled || !bus->bridge)return ; -acpi_pci_slot_enumerate (bus, handle); -acpiphp_enumerate_slots (bus, handle); +acpi_pci_slot_enumerate (bus); +acpiphp_enumerate_slots (bus); }
drivers/pci/pci-acpi.c static struct pci_platform_pm_ops acpi_p · line 303
Quoted 10 lines
drivers/pci/pci-acpi.c +1
-5void acpi_pci_remove_bus (struct pci_bus *bus) { -/* -* bus->bridge->acpi_node.handle has already been reset to NULL -* when acpi_pci_remove_bus() is called, so don't check ACPI handle. -*/ -if (acpi_pci_disabled) +if (acpi_pci_disabled || !bus->bridge)return ;
Quoted 36 lines
drivers/pci/pci-acpi.c +0
-0acpiphp_remove_slots (bus);Index:
linux-pm/include/linux/pci-acpi.h
===================================================================include/linux/pci-acpi.h +4
-6@@ -47,24 +47,22 @@ void acpi_pci_remove_bus(struct pci_bus#ifdef CONFIG_ACPI_PCI_SLOT void acpi_pci_slot_init (void ); -void acpi_pci_slot_enumerate (struct pci_bus *bus,acpi_handle handle); +void acpi_pci_slot_enumerate (struct pci_bus *bus);void acpi_pci_slot_remove (struct pci_bus *bus);#else static inline void acpi_pci_slot_init (void ) { } -static inline void acpi_pci_slot_enumerate (struct pci_bus *bus, -acpi_handle handle) { } +static inline void acpi_pci_slot_enumerate (struct pci_bus *bus) { }static inline void acpi_pci_slot_remove (struct pci_bus *bus) { }#endif #ifdef CONFIG_HOTPLUG_PCI_ACPI void acpiphp_init (void ); -void acpiphp_enumerate_slots (struct pci_bus *bus,acpi_handle handle); +void acpiphp_enumerate_slots (struct pci_bus *bus);void acpiphp_remove_slots (struct pci_bus *bus);void acpiphp_check_host_bridge (acpi_handle handle);#else static inline void acpiphp_init (void ) { } -static inline void acpiphp_enumerate_slots (struct pci_bus *bus, -acpi_handle handle) { } +static inline void acpiphp_enumerate_slots (struct pci_bus *bus) { }static inline void acpiphp_remove_slots (struct pci_bus *bus) { }static inline void acpiphp_check_host_bridge (acpi_handle handle) { }#endif
PATCH 2/30 ACPI / hotplug / PCI: Consolidate acpiphp_enumerate_slots()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The acpiphp_enumerate_slots() function is now split into two parts, acpiphp_enumerate_slots() proper and init_bridge_misc() which is only called by the former. If these functions are combined, it is possible to make the code easier to follow and to clean up the error handling (to prevent memory leaks on error from happening in particular), so do that.
--- drivers/pci/hotplug/acpiphp_glue.c | 92 ++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 47 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +45 -47
@@ -353,46 +353,6 @@ static int detect_ejectable_slots(acpi_hreturn found; } -/* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */ -static void init_bridge_misc (struct acpiphp_bridge *bridge) -{ -acpi_status status; - -/* must be added to the list prior to calling register_slot */ -mutex_lock (&bridge_mutex); -list_add (&bridge->list, &bridge_list); -mutex_unlock (&bridge_mutex); - -/* register all slot objects under this bridge */ - status =acpi_walk_namespace (ACPI_TYPE_DEVICE , bridge->handle, (u32 )1 , - register_slot,NULL , bridge,NULL ); -if (ACPI_FAILURE (status)) { -mutex_lock (&bridge_mutex); -list_del (&bridge->list); -mutex_unlock (&bridge_mutex); -return ; - } - -/* install notify handler for P2P bridges */ -if (!pci_is_root_bus (bridge->pci_bus)) { -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) { - status =acpi_remove_notify_handler (bridge->func->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func); -if (ACPI_FAILURE (status)) -err ("failed to remove notify handler\n" ); - } - status =acpi_install_notify_handler (bridge->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_bridge, - bridge); - -if (ACPI_FAILURE (status)) { -err ("failed to register interrupt notify handler\n" ); - } - } -} -/* find acpiphp_func from acpiphp_bridge */ static struct acpiphp_func *acpiphp_bridge_handle_to_function (acpi_handle handle)
@@ -1149,8 +1109,9 @@ static void handle_hotplug_event_func(ac*/ void acpiphp_enumerate_slots (struct pci_bus *bus) { -acpi_handle handle;struct acpiphp_bridge *bridge; +acpi_handle handle; +acpi_status status;if (acpiphp_disabled)return ;
@@ -1178,14 +1139,51 @@ void acpiphp_enumerate_slots(struct pci_*/ get_device (&bus->dev); -if (!pci_is_root_bus (bridge->pci_bus) && -acpi_has_method (bridge->handle,"_EJ0" )) { -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; - bridge->func =acpiphp_bridge_handle_to_function (handle); +/* must be added to the list prior to calling register_slot */ +mutex_lock (&bridge_mutex); +list_add (&bridge->list, &bridge_list); +mutex_unlock (&bridge_mutex); + +/* register all slot objects under this bridge */ + status =acpi_walk_namespace (ACPI_TYPE_DEVICE , bridge->handle,1 , + register_slot,NULL , bridge,NULL ); +if (ACPI_FAILURE (status)) { +acpi_handle_err (bridge->handle,"failed to register slots\n" ); + goto err; + } + +if (pci_is_root_bus (bridge->pci_bus)) +return ; + +/* install notify handler for P2P bridges */ + status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , + handle_hotplug_event_bridge, + bridge); +if (ACPI_FAILURE (status)) { +acpi_handle_err (bridge->handle, +"failed to register notify handler\n" ); + goto err; } -init_bridge_misc (bridge); +if (!acpi_has_method (bridge->handle,"_EJ0" )) +return ; + +dbg ("found ejectable p2p bridge\n" ); + bridge->flags |=BRIDGE_HAS_EJ0 ; + bridge->func =acpiphp_bridge_handle_to_function (bridge->handle); +if (bridge->func) { + status =acpi_remove_notify_handler (bridge->func->handle, +ACPI_SYSTEM_NOTIFY , + handle_hotplug_event_func); +if (ACPI_FAILURE (status)) +acpi_handle_err (bridge->func->handle, +"failed to remove notify handler\n" ); + } +return ; + + err: +cleanup_bridge (bridge); +put_bridge (bridge); }/* Destroy hotplug slots associated with the PCI bus */
Re: [PATCH 2/30] ACPI / hotplug / PCI: Consolidate acpiphp_enumerate_slots()
Quoted 116 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The
acpiphp_enumerate_slots()function is now split into two parts,acpiphp_enumerate_slots()proper andinit_bridge_misc()which is only called by the former. If these functions are combined, it is possible to make the code easier to follow and to clean up the error handling (to prevent memory leaks on error from happening in particular), so do that.Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/pci/hotplug/acpiphp_glue.c | 92 ++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 47 deletions(-)Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c +30
-47@@ -353,46 +353,6 @@ static int detect_ejectable_slots(acpi_hreturn found; } -/* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */ -static void init_bridge_misc (struct acpiphp_bridge *bridge) -{ -acpi_status status; - -/* must be added to the list prior to calling register_slot */ -mutex_lock (&bridge_mutex); -list_add (&bridge->list, &bridge_list); -mutex_unlock (&bridge_mutex); - -/* register all slot objects under this bridge */ - status =acpi_walk_namespace (ACPI_TYPE_DEVICE , bridge->handle, (u32 )1 , - register_slot,NULL , bridge,NULL ); -if (ACPI_FAILURE (status)) { -mutex_lock (&bridge_mutex); -list_del (&bridge->list); -mutex_unlock (&bridge_mutex); -return ; - } - -/* install notify handler for P2P bridges */ -if (!pci_is_root_bus (bridge->pci_bus)) { -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) { - status =acpi_remove_notify_handler (bridge->func->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func); -if (ACPI_FAILURE (status)) -err ("failed to remove notify handler\n" ); - } - status =acpi_install_notify_handler (bridge->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_bridge, - bridge); - -if (ACPI_FAILURE (status)) { -err ("failed to register interrupt notify handler\n" ); - } - } -} -/* find acpiphp_func from acpiphp_bridge */ static struct acpiphp_func *acpiphp_bridge_handle_to_function (acpi_handle handle)@@ -1149,8 +1109,9 @@ static void handle_hotplug_event_func(ac*/ void acpiphp_enumerate_slots (struct pci_bus *bus) { -acpi_handle handle;struct acpiphp_bridge *bridge; +acpi_handle handle; +acpi_status status;if (acpiphp_disabled)return ;@@ -1178,14 +1139,51 @@ void acpiphp_enumerate_slots(struct pci_*/ get_device (&bus->dev); -if (!pci_is_root_bus (bridge->pci_bus) && -acpi_has_method (bridge->handle,"_EJ0" )) { -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; - bridge->func =acpiphp_bridge_handle_to_function (handle); +/* must be added to the list prior to calling register_slot */ +mutex_lock (&bridge_mutex); +list_add (&bridge->list, &bridge_list); +mutex_unlock (&bridge_mutex); + +/* register all slot objects under this bridge */ + status =acpi_walk_namespace (ACPI_TYPE_DEVICE , bridge->handle,1 , + register_slot,NULL , bridge,NULL ); +if (ACPI_FAILURE (status)) { +acpi_handle_err (bridge->handle,"failed to register slots\n" ); + goto err; + } + +if (pci_is_root_bus (bridge->pci_bus)) +return ; + +/* install notify handler for P2P bridges */ + status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , + handle_hotplug_event_bridge, + bridge); +if (ACPI_FAILURE (status)) { +acpi_handle_err (bridge->handle, +"failed to register notify handler\n" ); + goto err; } -init_bridge_misc (bridge); +if (!acpi_has_method (bridge->handle,"_EJ0" )) +return ; + +dbg ("found ejectable p2p bridge\n" );
drivers/pci/hotplug/acpiphp_glue.c void acpiphp_enumerate_slots(struct pci_ · line 1181
Quoted 10 lines
drivers/pci/hotplug/acpiphp_glue.c +10
-0+ bridge->flags |=BRIDGE_HAS_EJ0 ; + bridge->func =acpiphp_bridge_handle_to_function (bridge->handle); +if (bridge->func) { + status =acpi_remove_notify_handler (bridge->func->handle, +ACPI_SYSTEM_NOTIFY , + handle_hotplug_event_func); +if (ACPI_FAILURE (status)) +acpi_handle_err (bridge->func->handle, +"failed to remove notify handler\n" ); + }
looks little weird that you change to install bridge notifier handler and remove bridge func notifier handler.
actually these two handles is the same one.
I would prefer to keeping the old sequence.
Yinghai
Re: [PATCH 2/30] ACPI / hotplug / PCI: Consolidate acpiphp_enumerate_slots()
Quoted 132 lines · Yinghai Lu
Quoted 116 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The
acpiphp_enumerate_slots()function is now split into two parts,acpiphp_enumerate_slots()proper andinit_bridge_misc()which is only called by the former. If these functions are combined, it is possible to make the code easier to follow and to clean up the error handling (to prevent memory leaks on error from happening in particular), so do that.Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/pci/hotplug/acpiphp_glue.c | 92 ++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 47 deletions(-)Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c +30
-47@@ -353,46 +353,6 @@ static int detect_ejectable_slots(acpi_hreturn found; } -/* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */ -static void init_bridge_misc (struct acpiphp_bridge *bridge) -{ -acpi_status status; - -/* must be added to the list prior to calling register_slot */ -mutex_lock (&bridge_mutex); -list_add (&bridge->list, &bridge_list); -mutex_unlock (&bridge_mutex); - -/* register all slot objects under this bridge */ - status =acpi_walk_namespace (ACPI_TYPE_DEVICE , bridge->handle, (u32 )1 , - register_slot,NULL , bridge,NULL ); -if (ACPI_FAILURE (status)) { -mutex_lock (&bridge_mutex); -list_del (&bridge->list); -mutex_unlock (&bridge_mutex); -return ; - } - -/* install notify handler for P2P bridges */ -if (!pci_is_root_bus (bridge->pci_bus)) { -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) { - status =acpi_remove_notify_handler (bridge->func->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func); -if (ACPI_FAILURE (status)) -err ("failed to remove notify handler\n" ); - } - status =acpi_install_notify_handler (bridge->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_bridge, - bridge); - -if (ACPI_FAILURE (status)) { -err ("failed to register interrupt notify handler\n" ); - } - } -} -/* find acpiphp_func from acpiphp_bridge */ static struct acpiphp_func *acpiphp_bridge_handle_to_function (acpi_handle handle)@@ -1149,8 +1109,9 @@ static void handle_hotplug_event_func(ac*/ void acpiphp_enumerate_slots (struct pci_bus *bus) { -acpi_handle handle;struct acpiphp_bridge *bridge; +acpi_handle handle; +acpi_status status;if (acpiphp_disabled)return ;@@ -1178,14 +1139,51 @@ void acpiphp_enumerate_slots(struct pci_*/ get_device (&bus->dev); -if (!pci_is_root_bus (bridge->pci_bus) && -acpi_has_method (bridge->handle,"_EJ0" )) { -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; - bridge->func =acpiphp_bridge_handle_to_function (handle); +/* must be added to the list prior to calling register_slot */ +mutex_lock (&bridge_mutex); +list_add (&bridge->list, &bridge_list); +mutex_unlock (&bridge_mutex); + +/* register all slot objects under this bridge */ + status =acpi_walk_namespace (ACPI_TYPE_DEVICE , bridge->handle,1 , + register_slot,NULL , bridge,NULL ); +if (ACPI_FAILURE (status)) { +acpi_handle_err (bridge->handle,"failed to register slots\n" ); + goto err; + } + +if (pci_is_root_bus (bridge->pci_bus)) +return ; + +/* install notify handler for P2P bridges */ + status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , + handle_hotplug_event_bridge, + bridge); +if (ACPI_FAILURE (status)) { +acpi_handle_err (bridge->handle, +"failed to register notify handler\n" ); + goto err; } -init_bridge_misc (bridge); +if (!acpi_has_method (bridge->handle,"_EJ0" )) +return ; + +dbg ("found ejectable p2p bridge\n" );drivers/pci/hotplug/acpiphp_glue.c void acpiphp_enumerate_slots(struct pci_ · line 1181
Quoted 10 lines
drivers/pci/hotplug/acpiphp_glue.c +10
-0+ bridge->flags |=BRIDGE_HAS_EJ0 ; + bridge->func =acpiphp_bridge_handle_to_function (bridge->handle); +if (bridge->func) { + status =acpi_remove_notify_handler (bridge->func->handle, +ACPI_SYSTEM_NOTIFY , + handle_hotplug_event_func); +if (ACPI_FAILURE (status)) +acpi_handle_err (bridge->func->handle, +"failed to remove notify handler\n" ); + }looks little weird that you change to install bridge notifier handler and remove bridge func notifier handler.
actually these two handles is the same one.
Quoted 1 line
I would prefer to keeping the old sequence.
First, it doesn't matter because one of the notifiers goes away in the subsequent patches and it would complicate those patches without any real reason if I did that.
Second, it doesn't matter because there can be multiple notify handlers for the same handle and if one of the above two triggers, the second one won't really do anything.
So no, I'm not going to do that, sorry.
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
PATCH 3/30 ACPI / hotplug / PCI: Always return success after adding a function
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
When a new ACPIPHP function is added by register_slot() and the notify handler cannot be installed for it, register_slot() returns an error status without cleaning up, which causes the entire namespace walk in acpiphp_enumerate_slots() to be aborted, although it still may be possible to successfully install the function notify handler for other device objects under the given brigde.
To address this issue make register_slot() return success after a new function has been added, even if the addition of the notify handler for it has failed.
--- drivers/pci/hotplug/acpiphp_glue.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +2 -3
@@ -325,10 +325,9 @@ register_slot(acpi_handle handle, u32 lvif (ACPI_FAILURE (status))err ("failed to register interrupt notify handler\n" ); - }else - status =AE_OK ; + } -return status; +return AE_OK ; err_exit: bridge->nr_slots--;
PATCH 4/30 ACPI / hotplug / PCI: Hotplug context objects for bridges and functions
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
When either a new hotplug bridge or a new hotplug function is added by the ACPI-based PCI hotplug (ACPIPHP) code, attach a context object to its ACPI handle to store hotplug-related information in it. To start with, put the handle's bridge and function pointers into that object. Count references to the context objects and drop them when they are not needed any more.
First of all, this makes it possible to find out if the given bridge has been registered as a function already in a much more straightforward way and acpiphp_bridge_handle_to_function() can be dropped (Yay!).
This also will allow some more simplifications to be made going forward.
--- drivers/pci/hotplug/acpiphp.h | 10 ++ drivers/pci/hotplug/acpiphp_glue.c | 179 ++++++++++++++++++++++++++++--------- 2 files changed, 146 insertions(+), 43 deletions(-)
drivers/pci/hotplug/acpiphp.h +10 -0
@@ -49,6 +49,7 @@ #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) +struct acpiphp_context ;struct acpiphp_bridge ;struct acpiphp_slot ;
@@ -77,6 +78,7 @@ struct acpiphp_bridge {struct kref ref;acpi_handle handle; +struct acpiphp_context *context;/* Ejectable PCI-to-PCI bridge (PCI bridge and PCI function) */ struct acpiphp_func *func;
@@ -119,6 +121,7 @@ struct acpiphp_slot {* typically 8 objects per slot (i.e. for each PCI function) */ struct acpiphp_func { +struct acpiphp_context *context;struct acpiphp_slot *slot;/* parent */ struct list_head sibling;
@@ -128,6 +131,13 @@ struct acpiphp_func {u32 flags;/* see below */ }; +struct acpiphp_context { +acpi_handle handle; +struct acpiphp_func *func; +struct acpiphp_bridge *bridge; +unsigned int refcount; +}; +/* * struct acpiphp_attention_info - device specific attention registration *
drivers/pci/hotplug/acpiphp_glue.c +136 -43
284 lines not on this page · raw message
Re: [PATCH 4/30] ACPI / hotplug / PCI: Hotplug context objects for bridges and functions
Quoted 14 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
When either a new hotplug bridge or a new hotplug function is added by the ACPI-based PCI hotplug (ACPIPHP) code, attach a context object to its ACPI handle to store hotplug-related information in it. To start with, put the handle's bridge and function pointers into that object. Count references to the context objects and drop them when they are not needed any more.
First of all, this makes it possible to find out if the given bridge has been registered as a function already in a much more straightforward way and
acpiphp_bridge_handle_to_function()can be dropped (Yay!).
Quoted 8 lines
This also will allow some more simplifications to be made going forward.
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/pci/hotplug/acpiphp.h | 10 ++ drivers/pci/hotplug/acpiphp_glue.c | 179 ++++++++++++++++++++++++++++--------- 2 files changed, 146 insertions(+), 43 deletions(-)
no, more lines are added.
Quoted 291 lines
Index:
linux-pm/drivers/pci/hotplug/acpiphp.h
===================================================================drivers/pci/hotplug/acpiphp.h +10
-0@@ -49,6 +49,7 @@ #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) +struct acpiphp_context ;struct acpiphp_bridge ;struct acpiphp_slot ;@@ -77,6 +78,7 @@ struct acpiphp_bridge {struct kref ref;acpi_handle handle; +struct acpiphp_context *context;/* Ejectable PCI-to-PCI bridge (PCI bridge and PCI function) */ struct acpiphp_func *func;@@ -119,6 +121,7 @@ struct acpiphp_slot {* typically 8 objects per slot (i.e. for each PCI function) */ struct acpiphp_func { +struct acpiphp_context *context;struct acpiphp_slot *slot;/* parent */ struct list_head sibling;@@ -128,6 +131,13 @@ struct acpiphp_func {u32 flags;/* see below */ }; +struct acpiphp_context { +acpi_handle handle; +struct acpiphp_func *func; +struct acpiphp_bridge *bridge; +unsigned int refcount; +}; +/* * struct acpiphp_attention_info - device specific attention registration * Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c +112
-36@@ -55,6 +55,7 @@static LIST_HEAD (bridge_list);static DEFINE_MUTEX (bridge_mutex); +static DEFINE_MUTEX (acpiphp_context_lock);#define MY_NAME "acpiphp_glue"@@ -79,6 +80,74 @@ is_pci_dock_device(acpi_handle handle, u } } +static void acpiphp_context_handler (acpi_handle handle,void *context) +{ +/* Intentionally empty. */ +} + +/** +* acpiphp_init_context - Create hotplug context and grab a reference to it. +* @handle: ACPI object handle to create the context for. +* +* Call under acpiphp_context_lock. +*/ +static struct acpiphp_context *acpiphp_init_context (acpi_handle handle) +{ +struct acpiphp_context *context; +acpi_status status; + + context =kzalloc (sizeof (*context),GFP_KERNEL ); +if (!context) +return NULL ; + + context->handle = handle; + context->refcount =1 ; + status =acpi_attach_data (handle, acpiphp_context_handler, context); +if (ACPI_FAILURE (status)) { +kfree (context); +return NULL ; + } +return context; +} + +/** +* acpiphp_get_context - Get hotplug context and grab a reference to it. +* @handle: ACPI object handle to get the context for. +* +* Call under acpiphp_context_lock. +*/ +static struct acpiphp_context *acpiphp_get_context (acpi_handle handle) +{ +struct acpiphp_context *context =NULL ; +acpi_status status; +void *data; + + status =acpi_get_data (handle, acpiphp_context_handler, &data); +if (ACPI_SUCCESS (status)) { + context = data; + context->refcount++; + } +return context; +} + +/** +* acpiphp_put_context - Drop a reference to ACPI hotplug context. +* @handle: ACPI object handle to put the context for. +* +* The context object is removed if there are no more references to it. +* +* Call under acpiphp_context_lock. +*/ +static void acpiphp_put_context (struct acpiphp_context *context) +{ +if (--context->refcount) +return ; + +WARN_ON (context->func || context->bridge); +acpi_detach_data (context->handle, acpiphp_context_handler); +kfree (context); +} +static inline void get_bridge (struct acpiphp_bridge *bridge) {kref_get (&bridge->ref);@@ -91,25 +160,37 @@ static inline void put_bridge(struct acpstatic void free_bridge (struct kref *kref) { +struct acpiphp_context *context;struct acpiphp_bridge *bridge;struct acpiphp_slot *slot, *next;struct acpiphp_func *func, *tmp; +mutex_lock (&acpiphp_context_lock); + bridge = container_of(kref, struct acpiphp_bridge, ref);list_for_each_entry_safe (slot, next, &bridge->slots, node) {list_for_each_entry_safe (func, tmp, &slot->funcs, sibling) { + context = func->context; + context->func =NULL ; +acpiphp_put_context (context);kfree (func); }kfree (slot); } -/* Release reference acquired by acpiphp_bridge_handle_to_function() */ +/* Release the reference acquired by acpiphp_enumerate_slots(). */ if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func)put_bridge (bridge->func->slot->bridge); +put_device (&bridge->pci_bus->dev);pci_dev_put (bridge->pci_dev); + context = bridge->context; + context->bridge =NULL ; +acpiphp_put_context (context);kfree (bridge); + +mutex_unlock (&acpiphp_context_lock); }/* @@ -194,10 +275,11 @@ static void acpiphp_dock_release(void *d }/* callback routine to register each ACPI PCI slot object */ -static acpi_status -register_slot (acpi_handle handle,u32 lvl,void *context,void **rv) +static acpi_status register_slot (acpi_handle handle,u32 lvl,void *data, +void **rv) { -struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context; +struct acpiphp_bridge *bridge = data; +struct acpiphp_context *context;struct acpiphp_slot *slot;struct acpiphp_func *newfunc;acpi_status status =AE_OK ;@@ -230,6 +312,18 @@ register_slot(acpi_handle handle, u32 lv newfunc->handle = handle; newfunc->function = function; +mutex_lock (&acpiphp_context_lock); + context =acpiphp_init_context (handle); +if (!context) { +mutex_unlock (&acpiphp_context_lock); +acpi_handle_err (handle,"No hotplug context\n" ); +kfree (newfunc); +return AE_NOT_EXIST ; + } + newfunc->context = context; + context->func = newfunc; +mutex_unlock (&acpiphp_context_lock); +if (acpi_has_method (handle,"_EJ0" )) newfunc->flags =FUNC_HAS_EJ0 ;@@ -266,8 +360,8 @@ register_slot(acpi_handle handle, u32 lvif (!found) { slot =kzalloc (sizeof (struct acpiphp_slot ),GFP_KERNEL );if (!slot) { -kfree (newfunc); -return AE_NO_MEMORY ; + status =AE_NO_MEMORY ; + goto err_out; } slot->bridge = bridge;@@ -291,7 +385,9 @@ register_slot(acpi_handle handle, u32 lvelse warn ("acpiphp_register_hotplug_slot failed " "(err code = 0x%x)\n" , retval); - goto err_exit; + + status =AE_OK ; + goto err; } }@@ -329,15 +425,20 @@ register_slot(acpi_handle handle, u32 lvreturn AE_OK ; - err_exit: + err: bridge->nr_slots--;mutex_lock (&bridge_mutex);list_del (&slot->node);mutex_unlock (&bridge_mutex);kfree (slot); -kfree (newfunc); -return AE_OK ; + err_out: +mutex_lock (&acpiphp_context_lock); + context->func =NULL ; +acpiphp_put_context (context); +mutex_unlock (&acpiphp_context_lock); +kfree (newfunc); +return status; }@@ -352,32 +453,6 @@ static int detect_ejectable_slots(acpi_hreturn found; } - -/* find acpiphp_func from acpiphp_bridge */ -static struct acpiphp_func *acpiphp_bridge_handle_to_function (acpi_handle handle) -{ -struct acpiphp_bridge *bridge; -struct acpiphp_slot *slot; -struct acpiphp_func *func =NULL ; - -mutex_lock (&bridge_mutex); -list_for_each_entry (bridge, &bridge_list, list) { -list_for_each_entry (slot, &bridge->slots, node) { -list_for_each_entry (func, &slot->funcs, sibling) { -if (func->handle == handle) { -get_bridge (func->slot->bridge); -mutex_unlock (&bridge_mutex); -return func; - } - } - } - } -mutex_unlock (&bridge_mutex); - -return NULL ; -} - -static struct acpiphp_bridge *acpiphp_handle_to_bridge (acpi_handle handle) {struct acpiphp_bridge *bridge;@@ -1108,6 +1183,7 @@ static void handle_hotplug_event_func(ac*/ void acpiphp_enumerate_slots (struct pci_bus *bus) { +struct acpiphp_context *context;struct acpiphp_bridge *bridge;acpi_handle handle;acpi_status status;
drivers/pci/hotplug/acpiphp_glue.c void acpiphp_enumerate_slots(struct pci_ · line 1203
Quoted 10 lines
drivers/pci/hotplug/acpiphp_glue.c +2
-2@@ -1120,8 +1196,8 @@ void acpiphp_enumerate_slots(struct pci_return ; bridge =kzalloc (sizeof (struct acpiphp_bridge ),GFP_KERNEL ); -if (bridge ==NULL ) { -err ("out of memory\n" ); +if (!bridge) { +acpi_handle_err (handle,"No memory for bridge object\n" );return ; }
can you put this change in another patch?
Quoted 44 lines
drivers/pci/hotplug/acpiphp_glue.c +22
-5@@ -1131,6 +1207,21 @@ void acpiphp_enumerate_slots(struct pci_ bridge->pci_dev =pci_dev_get (bus->self); bridge->pci_bus = bus; +mutex_lock (&acpiphp_context_lock); + context =acpiphp_get_context (handle); +if (!context) { + context =acpiphp_init_context (handle); +if (!context) { +mutex_unlock (&acpiphp_context_lock); +acpi_handle_err (handle,"No hotplug context\n" ); +kfree (bridge); +return ; + } + } + bridge->context = context; + context->bridge = bridge; +mutex_unlock (&acpiphp_context_lock); +/* * Grab a ref to the subordinate PCI bus in case the bus is * removed via PCI core logical hotplug. The ref pins the bus @@ -1169,13 +1260,15 @@ void acpiphp_enumerate_slots(struct pci_dbg ("found ejectable p2p bridge\n" ); bridge->flags |=BRIDGE_HAS_EJ0 ; - bridge->func =acpiphp_bridge_handle_to_function (bridge->handle); -if (bridge->func) { - status =acpi_remove_notify_handler (bridge->func->handle, -ACPI_SYSTEM_NOTIFY , +if (context->func) { +get_bridge (context->func->slot->bridge); + bridge->func = context->func; + handle = context->handle; +WARN_ON (bridge->handle != handle); + status =acpi_remove_notify_handler (handle,ACPI_SYSTEM_NOTIFY , handle_hotplug_event_func);if (ACPI_FAILURE (status)) -acpi_handle_err (bridge->func->handle, +acpi_handle_err (handle,"failed to remove notify handler\n" ); }return ;
Re: [PATCH 4/30] ACPI / hotplug / PCI: Hotplug context objects for bridges and functions
Quoted 18 lines · Yinghai Lu
Quoted 17 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
When either a new hotplug bridge or a new hotplug function is added by the ACPI-based PCI hotplug (ACPIPHP) code, attach a context object to its ACPI handle to store hotplug-related information in it. To start with, put the handle's bridge and function pointers into that object. Count references to the context objects and drop them when they are not needed any more.
First of all, this makes it possible to find out if the given bridge has been registered as a function already in a much more straightforward way and
acpiphp_bridge_handle_to_function()can be dropped (Yay!).This also will allow some more simplifications to be made going forward.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/pci/hotplug/acpiphp.h | 10 ++ drivers/pci/hotplug/acpiphp_glue.c | 179 ++++++++++++++++++++++++++++--------- 2 files changed, 146 insertions(+), 43 deletions(-)no, more lines are added.
Well, that's what 'quilt refresh --diffstat' tells me, quite consistently.
Have you actually counted them?
Quoted 292 lines
Quoted 292 lines
Index:
linux-pm/drivers/pci/hotplug/acpiphp.h
===================================================================drivers/pci/hotplug/acpiphp.h +10
-0@@ -49,6 +49,7 @@ #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) +struct acpiphp_context ;struct acpiphp_bridge ;struct acpiphp_slot ;@@ -77,6 +78,7 @@ struct acpiphp_bridge {struct kref ref;acpi_handle handle; +struct acpiphp_context *context;/* Ejectable PCI-to-PCI bridge (PCI bridge and PCI function) */ struct acpiphp_func *func;@@ -119,6 +121,7 @@ struct acpiphp_slot {* typically 8 objects per slot (i.e. for each PCI function) */ struct acpiphp_func { +struct acpiphp_context *context;struct acpiphp_slot *slot;/* parent */ struct list_head sibling;@@ -128,6 +131,13 @@ struct acpiphp_func {u32 flags;/* see below */ }; +struct acpiphp_context { +acpi_handle handle; +struct acpiphp_func *func; +struct acpiphp_bridge *bridge; +unsigned int refcount; +}; +/* * struct acpiphp_attention_info - device specific attention registration * Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c +112
-36@@ -55,6 +55,7 @@static LIST_HEAD (bridge_list);static DEFINE_MUTEX (bridge_mutex); +static DEFINE_MUTEX (acpiphp_context_lock);#define MY_NAME "acpiphp_glue"@@ -79,6 +80,74 @@ is_pci_dock_device(acpi_handle handle, u } } +static void acpiphp_context_handler (acpi_handle handle,void *context) +{ +/* Intentionally empty. */ +} + +/** +* acpiphp_init_context - Create hotplug context and grab a reference to it. +* @handle: ACPI object handle to create the context for. +* +* Call under acpiphp_context_lock. +*/ +static struct acpiphp_context *acpiphp_init_context (acpi_handle handle) +{ +struct acpiphp_context *context; +acpi_status status; + + context =kzalloc (sizeof (*context),GFP_KERNEL ); +if (!context) +return NULL ; + + context->handle = handle; + context->refcount =1 ; + status =acpi_attach_data (handle, acpiphp_context_handler, context); +if (ACPI_FAILURE (status)) { +kfree (context); +return NULL ; + } +return context; +} + +/** +* acpiphp_get_context - Get hotplug context and grab a reference to it. +* @handle: ACPI object handle to get the context for. +* +* Call under acpiphp_context_lock. +*/ +static struct acpiphp_context *acpiphp_get_context (acpi_handle handle) +{ +struct acpiphp_context *context =NULL ; +acpi_status status; +void *data; + + status =acpi_get_data (handle, acpiphp_context_handler, &data); +if (ACPI_SUCCESS (status)) { + context = data; + context->refcount++; + } +return context; +} + +/** +* acpiphp_put_context - Drop a reference to ACPI hotplug context. +* @handle: ACPI object handle to put the context for. +* +* The context object is removed if there are no more references to it. +* +* Call under acpiphp_context_lock. +*/ +static void acpiphp_put_context (struct acpiphp_context *context) +{ +if (--context->refcount) +return ; + +WARN_ON (context->func || context->bridge); +acpi_detach_data (context->handle, acpiphp_context_handler); +kfree (context); +} +static inline void get_bridge (struct acpiphp_bridge *bridge) {kref_get (&bridge->ref);@@ -91,25 +160,37 @@ static inline void put_bridge(struct acpstatic void free_bridge (struct kref *kref) { +struct acpiphp_context *context;struct acpiphp_bridge *bridge;struct acpiphp_slot *slot, *next;struct acpiphp_func *func, *tmp; +mutex_lock (&acpiphp_context_lock); + bridge = container_of(kref, struct acpiphp_bridge, ref);list_for_each_entry_safe (slot, next, &bridge->slots, node) {list_for_each_entry_safe (func, tmp, &slot->funcs, sibling) { + context = func->context; + context->func =NULL ; +acpiphp_put_context (context);kfree (func); }kfree (slot); } -/* Release reference acquired by acpiphp_bridge_handle_to_function() */ +/* Release the reference acquired by acpiphp_enumerate_slots(). */ if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func)put_bridge (bridge->func->slot->bridge); +put_device (&bridge->pci_bus->dev);pci_dev_put (bridge->pci_dev); + context = bridge->context; + context->bridge =NULL ; +acpiphp_put_context (context);kfree (bridge); + +mutex_unlock (&acpiphp_context_lock); }/* @@ -194,10 +275,11 @@ static void acpiphp_dock_release(void *d }/* callback routine to register each ACPI PCI slot object */ -static acpi_status -register_slot (acpi_handle handle,u32 lvl,void *context,void **rv) +static acpi_status register_slot (acpi_handle handle,u32 lvl,void *data, +void **rv) { -struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context; +struct acpiphp_bridge *bridge = data; +struct acpiphp_context *context;struct acpiphp_slot *slot;struct acpiphp_func *newfunc;acpi_status status =AE_OK ;@@ -230,6 +312,18 @@ register_slot(acpi_handle handle, u32 lv newfunc->handle = handle; newfunc->function = function; +mutex_lock (&acpiphp_context_lock); + context =acpiphp_init_context (handle); +if (!context) { +mutex_unlock (&acpiphp_context_lock); +acpi_handle_err (handle,"No hotplug context\n" ); +kfree (newfunc); +return AE_NOT_EXIST ; + } + newfunc->context = context; + context->func = newfunc; +mutex_unlock (&acpiphp_context_lock); +if (acpi_has_method (handle,"_EJ0" )) newfunc->flags =FUNC_HAS_EJ0 ;@@ -266,8 +360,8 @@ register_slot(acpi_handle handle, u32 lvif (!found) { slot =kzalloc (sizeof (struct acpiphp_slot ),GFP_KERNEL );if (!slot) { -kfree (newfunc); -return AE_NO_MEMORY ; + status =AE_NO_MEMORY ; + goto err_out; } slot->bridge = bridge;@@ -291,7 +385,9 @@ register_slot(acpi_handle handle, u32 lvelse warn ("acpiphp_register_hotplug_slot failed " "(err code = 0x%x)\n" , retval); - goto err_exit; + + status =AE_OK ; + goto err; } }@@ -329,15 +425,20 @@ register_slot(acpi_handle handle, u32 lvreturn AE_OK ; - err_exit: + err: bridge->nr_slots--;mutex_lock (&bridge_mutex);list_del (&slot->node);mutex_unlock (&bridge_mutex);kfree (slot); -kfree (newfunc); -return AE_OK ; + err_out: +mutex_lock (&acpiphp_context_lock); + context->func =NULL ; +acpiphp_put_context (context); +mutex_unlock (&acpiphp_context_lock); +kfree (newfunc); +return status; }@@ -352,32 +453,6 @@ static int detect_ejectable_slots(acpi_hreturn found; } - -/* find acpiphp_func from acpiphp_bridge */ -static struct acpiphp_func *acpiphp_bridge_handle_to_function (acpi_handle handle) -{ -struct acpiphp_bridge *bridge; -struct acpiphp_slot *slot; -struct acpiphp_func *func =NULL ; - -mutex_lock (&bridge_mutex); -list_for_each_entry (bridge, &bridge_list, list) { -list_for_each_entry (slot, &bridge->slots, node) { -list_for_each_entry (func, &slot->funcs, sibling) { -if (func->handle == handle) { -get_bridge (func->slot->bridge); -mutex_unlock (&bridge_mutex); -return func; - } - } - } - } -mutex_unlock (&bridge_mutex); - -return NULL ; -} - -static struct acpiphp_bridge *acpiphp_handle_to_bridge (acpi_handle handle) {struct acpiphp_bridge *bridge;@@ -1108,6 +1183,7 @@ static void handle_hotplug_event_func(ac*/ void acpiphp_enumerate_slots (struct pci_bus *bus) { +struct acpiphp_context *context;struct acpiphp_bridge *bridge;acpi_handle handle;acpi_status status;@@ -1120,8 +1196,8 @@ void acpiphp_enumerate_slots(struct pci_return ;
Quoted 10 lines
drivers/pci/hotplug/acpiphp_glue.c void acpiphp_enumerate_slots(struct pci_ · line 1203
Quoted 8 lines
drivers/pci/hotplug/acpiphp_glue.c +2
-2bridge =kzalloc (sizeof (struct acpiphp_bridge ),GFP_KERNEL ); -if (bridge ==NULL ) { -err ("out of memory\n" ); +if (!bridge) { +acpi_handle_err (handle,"No memory for bridge object\n" );return ; }can you put this change in another patch?
Yes, I can, but is it worth it?
Quoted 44 lines
Quoted 44 lines
drivers/pci/hotplug/acpiphp_glue.c +22
-5@@ -1131,6 +1207,21 @@ void acpiphp_enumerate_slots(struct pci_ bridge->pci_dev =pci_dev_get (bus->self); bridge->pci_bus = bus; +mutex_lock (&acpiphp_context_lock); + context =acpiphp_get_context (handle); +if (!context) { + context =acpiphp_init_context (handle); +if (!context) { +mutex_unlock (&acpiphp_context_lock); +acpi_handle_err (handle,"No hotplug context\n" ); +kfree (bridge); +return ; + } + } + bridge->context = context; + context->bridge = bridge; +mutex_unlock (&acpiphp_context_lock); +/* * Grab a ref to the subordinate PCI bus in case the bus is * removed via PCI core logical hotplug. The ref pins the bus @@ -1169,13 +1260,15 @@ void acpiphp_enumerate_slots(struct pci_dbg ("found ejectable p2p bridge\n" ); bridge->flags |=BRIDGE_HAS_EJ0 ; - bridge->func =acpiphp_bridge_handle_to_function (bridge->handle); -if (bridge->func) { - status =acpi_remove_notify_handler (bridge->func->handle, -ACPI_SYSTEM_NOTIFY , +if (context->func) { +get_bridge (context->func->slot->bridge); + bridge->func = context->func; + handle = context->handle; +WARN_ON (bridge->handle != handle); + status =acpi_remove_notify_handler (handle,ACPI_SYSTEM_NOTIFY , handle_hotplug_event_func);if (ACPI_FAILURE (status)) -acpi_handle_err (bridge->func->handle, +acpi_handle_err (handle,"failed to remove notify handler\n" ); }return ;
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: [PATCH 4/30] ACPI / hotplug / PCI: Hotplug context objects for bridges and functions
Quoted 25 lines · Rafael J. Wysocki
Quoted 24 lines · Yinghai Lu
Quoted 22 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
When either a new hotplug bridge or a new hotplug function is added by the ACPI-based PCI hotplug (ACPIPHP) code, attach a context object to its ACPI handle to store hotplug-related information in it. To start with, put the handle's bridge and function pointers into that object. Count references to the context objects and drop them when they are not needed any more.
First of all, this makes it possible to find out if the given bridge has been registered as a function already in a much more straightforward way and
acpiphp_bridge_handle_to_function()can be dropped (Yay!).This also will allow some more simplifications to be made going forward.
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/pci/hotplug/acpiphp.h | 10 ++ drivers/pci/hotplug/acpiphp_glue.c | 179 ++++++++++++++++++++++++++++--------- 2 files changed, 146 insertions(+), 43 deletions(-)
Quoted 5 lines
Quoted 1 line
no, more lines are added.
Well, that's what 'quilt refresh --diffstat' tells me, quite consistently.
Have you actually counted them?
Now I have done that (using "grep '^+' | wc -l") and that indeed turns out ot the right number.
What gives?
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
PATCH 5/30 ACPI / hotplug / PCI: Unified notify handler for hotplug events
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Using the hotplug context objects introduced previously rework the ACPI-based PCI hotplug (ACPIPHP) core code so that all notifications for ACPI device objects corresponding to the hotplug PCI devices are handled by one function, handle_hotplug_event(), which recognizes whether it has to handle a bridge or a function.
In addition to code size reduction it allows some ugly pieces of code where notify handlers have to be uninstalled and installed again to go away. Moreover, it fixes a theoretically possible race between handle_hotplug_event() and free_bridge() tearing down data structures for the same handle.
--- drivers/pci/hotplug/acpiphp.h | 1 drivers/pci/hotplug/acpiphp_glue.c | 132 ++++++++++++++----------------------- 2 files changed, 53 insertions(+), 80 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +52 -80
@@ -59,11 +59,10 @@ static DEFINE_MUTEX(acpiphp_context_lock#define MY_NAME "acpiphp_glue" -static void handle_hotplug_event_bridge (acpi_handle ,u32 ,void *); +static void handle_hotplug_event (acpi_handle handle,u32 type,void *data);static void acpiphp_sanitize_bus (struct pci_bus *bus);static void acpiphp_set_hpp_values (struct pci_bus *bus);static void hotplug_event_func (acpi_handle handle,u32 type,void *context); -static void handle_hotplug_event_func (acpi_handle handle,u32 type,void *context);static void free_bridge (struct kref *kref);/* callback routine to check for the existence of a pci dock device */
@@ -179,13 +178,13 @@ static void free_bridge(struct kref *krekfree (slot); } + context = bridge->context;/* Release the reference acquired by acpiphp_enumerate_slots(). */ -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) +if (context->handler_for_func)put_bridge (bridge->func->slot->bridge);put_device (&bridge->pci_bus->dev);pci_dev_put (bridge->pci_dev); - context = bridge->context; context->bridge =NULL ;acpiphp_put_context (context);kfree (bridge);
@@ -414,12 +413,12 @@ static acpi_status register_slot(acpi_ha/* install notify handler */ if (!(newfunc->flags &FUNC_HAS_DCK )) { - status =acpi_install_notify_handler (handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func, - newfunc); - -if (ACPI_FAILURE (status)) + status =acpi_install_notify_handler (handle,ACPI_SYSTEM_NOTIFY , + handle_hotplug_event, + context); +if (ACPI_SUCCESS (status)) + context->handler_for_func = true; +else err ("failed to register interrupt notify handler\n" ); }
@@ -476,32 +475,23 @@ static void cleanup_bridge(struct acpiphacpi_status status;acpi_handle handle = bridge->handle; -if (!pci_is_root_bus (bridge->pci_bus)) { - status =acpi_remove_notify_handler (handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_bridge); +if (!bridge->context->handler_for_func) { + status =acpi_remove_notify_handler (handle,ACPI_SYSTEM_NOTIFY , + handle_hotplug_event);if (ACPI_FAILURE (status))err ("failed to remove notify handler\n" ); } -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) { - status =acpi_install_notify_handler (bridge->func->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func, - bridge->func); -if (ACPI_FAILURE (status)) -err ("failed to install interrupt notify handler\n" ); - } -list_for_each_entry (slot, &bridge->slots, node) {list_for_each_entry (func, &slot->funcs, sibling) {if (is_dock_device (func->handle)) {unregister_hotplug_dock_device (func->handle); }if (!(func->flags &FUNC_HAS_DCK )) { + func->context->handler_for_func = false; status =acpi_remove_notify_handler (func->handle, -ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func); +ACPI_SYSTEM_NOTIFY , + handle_hotplug_event);if (ACPI_FAILURE (status))err ("failed to remove notify handler\n" ); }
@@ -1071,31 +1061,6 @@ static void _handle_hotplug_event_bridgeput_bridge (bridge); } -/** -* handle_hotplug_event_bridge - handle ACPI event on bridges -* @handle: Notify()'ed acpi_handle -* @type: Notify code -* @context: pointer to acpiphp_bridge structure -* -* Handles ACPI event notification on {host,p2p} bridges. -*/ -static void handle_hotplug_event_bridge (acpi_handle handle,u32 type, -void *context) -{ -struct acpiphp_bridge *bridge = context; - -/* -* Currently the code adds all hotplug events to the kacpid_wq -* queue when it should add hotplug events to the kacpi_hotplug_wq. -* The proper way to fix this is to reorganize the code so that -* drivers (dock, etc.) do not call acpi_os_execute(), etc. -* For now just re-add this work to the kacpi_hotplug_wq so we -* don't deadlock on hotplug actions. -*/ -get_bridge (bridge); -alloc_acpi_hp_work (handle, type, context, _handle_hotplug_event_bridge); -} -static void hotplug_event_func (acpi_handle handle,u32 type,void *context) {struct acpiphp_func *func = context;
@@ -1153,17 +1118,33 @@ static void _handle_hotplug_event_func(s }/** -* handle_hotplug_event_func - handle ACPI event on functions (i.e. slots) +* handle_hotplug_event - handle ACPI hotplug event * @handle: Notify()'ed acpi_handle * @type: Notify code -* @context: pointer to acpiphp_func structure +* @data: pointer to acpiphp_context structure * * Handles ACPI event notification on slots. */ -static void handle_hotplug_event_func (acpi_handle handle,u32 type, -void *context) +static void handle_hotplug_event (acpi_handle handle,u32 type,void *data) { -struct acpiphp_func *func = context; +struct acpiphp_context *context; +void (*work_func)(struct work_struct *work) =NULL ; + +mutex_lock (&acpiphp_context_lock); + context =acpiphp_get_context (handle); +if (context) { +if (context->bridge) { +get_bridge (context->bridge); + data = context->bridge; + work_func = _handle_hotplug_event_bridge; + }else if (context->func) { +get_bridge (context->func->slot->bridge); + data = context->func; + work_func = _handle_hotplug_event_func; + } +acpiphp_put_context (context); + } +mutex_unlock (&acpiphp_context_lock);/* * Currently the code adds all hotplug events to the kacpid_wq
@@ -1173,8 +1154,8 @@ static void handle_hotplug_event_func(ac* For now just re-add this work to the kacpi_hotplug_wq so we * don't deadlock on hotplug actions. */ -get_bridge (func->slot->bridge); -alloc_acpi_hp_work (handle, type, context, _handle_hotplug_event_func); +if (work_func) +alloc_acpi_hp_work (handle, type, data, work_func); }/*
@@ -1245,33 +1226,24 @@ void acpiphp_enumerate_slots(struct pci_if (pci_is_root_bus (bridge->pci_bus))return ; -/* install notify handler for P2P bridges */ - status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_bridge, - bridge); -if (ACPI_FAILURE (status)) { -acpi_handle_err (bridge->handle, -"failed to register notify handler\n" ); - goto err; +if (acpi_has_method (bridge->handle,"_EJ0" )) { +dbg ("found ejectable p2p bridge\n" ); + bridge->flags |=BRIDGE_HAS_EJ0 ; + } +if (context->handler_for_func) { +/* Notify handler already installed. */ + bridge->func = context->func; +get_bridge (context->func->slot->bridge); +return ; } -if (!acpi_has_method (bridge->handle,"_EJ0" )) +/* install notify handler for P2P bridges */ + status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , + handle_hotplug_event,NULL ); +if (ACPI_SUCCESS (status))return ; -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; -if (context->func) { -get_bridge (context->func->slot->bridge); - bridge->func = context->func; - handle = context->handle; -WARN_ON (bridge->handle != handle); - status =acpi_remove_notify_handler (handle,ACPI_SYSTEM_NOTIFY , - handle_hotplug_event_func); -if (ACPI_FAILURE (status)) -acpi_handle_err (handle, -"failed to remove notify handler\n" ); - } -return ; +acpi_handle_err (bridge->handle,"failed to register notify handler\n" ); err:cleanup_bridge (bridge);
drivers/pci/hotplug/acpiphp.h +1 -0
@@ -136,6 +136,7 @@ struct acpiphp_context {struct acpiphp_func *func;struct acpiphp_bridge *bridge;unsigned int refcount; +bool handler_for_func; };/*
Re: [PATCH 5/30] ACPI / hotplug / PCI: Unified notify handler for hotplug events
Quoted 14 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Using the hotplug context objects introduced previously rework the ACPI-based PCI hotplug (ACPIPHP) core code so that all notifications for ACPI device objects corresponding to the hotplug PCI devices are handled by one function,
handle_hotplug_event(), which recognizes whether it has to handle a bridge or a function.In addition to code size reduction it allows some ugly pieces of code where notify handlers have to be uninstalled and installed again to go away. Moreover, it fixes a theoretically possible race between
handle_hotplug_event()andfree_bridge()tearing down data structures for the same handle.
Quoted 5 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/pci/hotplug/acpiphp.h | 1 drivers/pci/hotplug/acpiphp_glue.c | 132 ++++++++++++++----------------------- 2 files changed, 53 insertions(+), 80 deletions(-)
Can you put this patches in one temp branch ?
Like to check final bits.
Thanks
Yinghai
Re: [PATCH 5/30] ACPI / hotplug / PCI: Unified notify handler for hotplug events
Quoted 15 lines · Yinghai Lu
Quoted 14 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Using the hotplug context objects introduced previously rework the ACPI-based PCI hotplug (ACPIPHP) core code so that all notifications for ACPI device objects corresponding to the hotplug PCI devices are handled by one function,
handle_hotplug_event(), which recognizes whether it has to handle a bridge or a function.In addition to code size reduction it allows some ugly pieces of code where notify handlers have to be uninstalled and installed again to go away. Moreover, it fixes a theoretically possible race between
handle_hotplug_event()andfree_bridge()tearing down data structures for the same handle.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/pci/hotplug/acpiphp.h | 1 drivers/pci/hotplug/acpiphp_glue.c | 132 ++++++++++++++----------------------- 2 files changed, 53 insertions(+), 80 deletions(-)Can you put this patches in one temp branch ?
They are in linux-pm.git/bleeding-edge.
Quoted 2 lines
Like to check final bits.
Sure.
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
PATCH 6/30 ACPI / hotplug / PCI: Rework acpiphp_handle_to_bridge()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Using the hotplug context objects introduced previously rework the ACPI-based PCI hotplug (ACPIPHP) core code to get to acpiphp_bridge objects associated with hotplug bridges from those context objects rather than from the global list of hotplug bridges.
--- drivers/pci/hotplug/acpiphp_glue.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +11 -9
@@ -454,18 +454,20 @@ static int detect_ejectable_slots(acpi_hstatic struct acpiphp_bridge *acpiphp_handle_to_bridge (acpi_handle handle) { -struct acpiphp_bridge *bridge; +struct acpiphp_context *context; +struct acpiphp_bridge *bridge =NULL ; -mutex_lock (&bridge_mutex); -list_for_each_entry (bridge, &bridge_list, list) -if (bridge->handle == handle) { +mutex_lock (&acpiphp_context_lock); + context =acpiphp_get_context (handle); +if (context) { + bridge = context->bridge; +if (bridge)get_bridge (bridge); -mutex_unlock (&bridge_mutex); -return bridge; - } -mutex_unlock (&bridge_mutex); -return NULL ; +acpiphp_put_context (context); + } +mutex_unlock (&acpiphp_context_lock); +return bridge; }static void cleanup_bridge (struct acpiphp_bridge *bridge)
PATCH 7/30 ACPI / hotplug / PCI: Pass hotplug context objects to event handlers
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Modify handle_hotplug_event() to pass the entire context object (instead of its fields individually) to work functions started by it.
This change makes the subsequent consolidation of the event handling work functions a bit more straightforward.
--- drivers/pci/hotplug/acpiphp_glue.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +8 -8
@@ -989,6 +989,7 @@ void acpiphp_check_host_bridge(acpi_handstatic void _handle_hotplug_event_bridge (struct work_struct *work) { +struct acpiphp_context *context;struct acpiphp_bridge *bridge;char objname[64 ];struct acpi_buffer buffer = { .length =sizeof (objname),
@@ -1000,7 +1001,8 @@ static void _handle_hotplug_event_bridge hp_work = container_of(work, struct acpi_hp_work, work); handle = hp_work->handle; type = hp_work->type; - bridge = (struct acpiphp_bridge *)hp_work->context; + context = hp_work->context; + bridge = context->bridge;acpi_scan_lock_acquire ();
@@ -1105,18 +1107,18 @@ static void hotplug_event_func(acpi_handstatic void _handle_hotplug_event_func (struct work_struct *work) { +struct acpiphp_context *context;struct acpi_hp_work *hp_work; -struct acpiphp_func *func; hp_work = container_of(work, struct acpi_hp_work, work); - func = hp_work->context; + context = hp_work->context;acpi_scan_lock_acquire (); -hotplug_event_func (hp_work->handle, hp_work->type, func); +hotplug_event_func (hp_work->handle, hp_work->type, context->func);acpi_scan_lock_release ();kfree (hp_work);/* allocated in handle_hotplug_event_func */ -put_bridge (func->slot->bridge); +put_bridge (context->func->slot->bridge); }/**
@@ -1137,11 +1139,9 @@ static void handle_hotplug_event(acpi_haif (context) {if (context->bridge) {get_bridge (context->bridge); - data = context->bridge; work_func = _handle_hotplug_event_bridge; }else if (context->func) {get_bridge (context->func->slot->bridge); - data = context->func; work_func = _handle_hotplug_event_func; }acpiphp_put_context (context);
@@ -1157,7 +1157,7 @@ static void handle_hotplug_event(acpi_ha* don't deadlock on hotplug actions. */ if (work_func) -alloc_acpi_hp_work (handle, type, data, work_func); +alloc_acpi_hp_work (handle, type, context, work_func); }/*
PATCH 8/30 ACPI / hotplug / PCI: Merge hotplug event handling functions
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
There are separate handling event functions for hotplug bridges and for hotplug functions, but they may be combined into one common hotplug event handling function which simplifies the code slightly.
That also allows a theoretical bug to be dealt with which in principle may occur if a hotplug bridge is on a dock station, because in that case the bridge-specific notification should be used instead of the function-specific one, but the dock station always uses the latter.
--- drivers/pci/hotplug/acpiphp_glue.c | 152 +++++++++++++++---------------------- 1 file changed, 65 insertions(+), 87 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +65 -87
@@ -62,7 +62,7 @@ static DEFINE_MUTEX(acpiphp_context_lockstatic void handle_hotplug_event (acpi_handle handle,u32 type,void *data);static void acpiphp_sanitize_bus (struct pci_bus *bus);static void acpiphp_set_hpp_values (struct pci_bus *bus); -static void hotplug_event_func (acpi_handle handle,u32 type,void *context); +static void hotplug_event (acpi_handle handle,u32 type,void *data);static void free_bridge (struct kref *kref);/* callback routine to check for the existence of a pci dock device */
@@ -201,8 +201,8 @@ static void free_bridge(struct kref *kre*/ static void post_dock_fixups (acpi_handle not_used,u32 event,void *data) { -struct acpiphp_func *func = data; -struct pci_bus *bus = func->slot->bridge->pci_bus; +struct acpiphp_context *context = data; +struct pci_bus *bus = context->func->slot->bridge->pci_bus;u32 buses;if (!bus->self)
@@ -227,7 +227,7 @@ static void post_dock_fixups(acpi_handlestatic const struct acpi_dock_ops acpiphp_dock_ops = { .fixup = post_dock_fixups, - .handler = hotplug_event_func, + .handler = hotplug_event, };/* Check whether the PCI device is managed by native PCIe hotplug driver */
@@ -261,16 +261,16 @@ static bool device_is_managed_by_native_static void acpiphp_dock_init (void *data) { -struct acpiphp_func *func = data; +struct acpiphp_context *context = data; -get_bridge (func->slot->bridge); +get_bridge (context->func->slot->bridge); }static void acpiphp_dock_release (void *data) { -struct acpiphp_func *func = data; +struct acpiphp_context *context = data; -put_bridge (func->slot->bridge); +put_bridge (context->func->slot->bridge); }/* callback routine to register each ACPI PCI slot object */
@@ -406,7 +406,7 @@ static acpi_status register_slot(acpi_ha*/ newfunc->flags &= ~FUNC_HAS_EJ0 ;if (register_hotplug_dock_device (handle, - &acpiphp_dock_ops, newfunc, + &acpiphp_dock_ops, context, acpiphp_dock_init, acpiphp_dock_release))dbg ("failed to register dock device\n" ); }
@@ -987,24 +987,26 @@ void acpiphp_check_host_bridge(acpi_hand ACPI_UINT32_MAX, check_sub_bridges, NULL, NULL, NULL); } -static void _handle_hotplug_event_bridge (struct work_struct *work) +static void hotplug_event (acpi_handle handle,u32 type,void *data) { -struct acpiphp_context *context; +struct acpiphp_context *context = data;struct acpiphp_bridge *bridge; +struct acpiphp_func *func;char objname[64 ];struct acpi_buffer buffer = { .length =sizeof (objname), .pointer = objname }; -struct acpi_hp_work *hp_work; -acpi_handle handle; -u32 type; - hp_work = container_of(work, struct acpi_hp_work, work); - handle = hp_work->handle; - type = hp_work->type; - context = hp_work->context; +mutex_lock (&acpiphp_context_lock); bridge = context->bridge; +if (bridge) +get_bridge (bridge); -acpi_scan_lock_acquire (); +/* +* If context->func is not NULL, we are holding a reference to its +* parent bridge, so it won't go away until we drop that reference. +*/ + func = context->func; +mutex_unlock (&acpiphp_context_lock);acpi_get_name (handle,ACPI_FULL_PATHNAME , &buffer);
@@ -1013,15 +1015,24 @@ static void _handle_hotplug_event_bridge/* bus re-enumerate */ dbg ("%s: Bus check notify on %s\n" , __func__, objname);dbg ("%s: re-enumerating slots under %s\n" , __func__, objname); -acpiphp_check_bridge (bridge); -acpi_walk_namespace (ACPI_TYPE_DEVICE , handle, -ACPI_UINT32_MAX , check_sub_bridges,NULL ,NULL ,NULL ); +if (bridge) { +acpiphp_check_bridge (bridge); +acpi_walk_namespace (ACPI_TYPE_DEVICE , handle, +ACPI_UINT32_MAX , check_sub_bridges, +NULL ,NULL ,NULL ); + }else { +acpiphp_enable_slot (func->slot); + }break ;case ACPI_NOTIFY_DEVICE_CHECK :/* device check */ dbg ("%s: Device check notify on %s\n" , __func__, objname); -acpiphp_check_bridge (bridge); +if (bridge) +acpiphp_check_bridge (bridge); +else +acpiphp_check_bridge (func->slot->bridge); +break ;case ACPI_NOTIFY_DEVICE_WAKE :
@@ -1032,12 +1043,15 @@ static void _handle_hotplug_event_bridgecase ACPI_NOTIFY_EJECT_REQUEST :/* request device eject */ dbg ("%s: Device eject notify on %s\n" , __func__, objname); -if ((bridge->flags &BRIDGE_HAS_EJ0 ) && bridge->func) { -struct acpiphp_slot *slot; - slot = bridge->func->slot; -if (!acpiphp_disable_slot (slot)) -acpiphp_eject_slot (slot); - } +if (!func) +break ; + +if (bridge && !(bridge->flags &BRIDGE_HAS_EJ0 )) +break ; + +if (!(acpiphp_disable_slot (func->slot))) +acpiphp_eject_slot (func->slot); +break ;case ACPI_NOTIFY_FREQUENCY_MISMATCH :
@@ -1056,56 +1070,16 @@ static void _handle_hotplug_event_bridgebreak ;default : -warn ("notify_handler: unknown event type 0x%x for %s\n" , type, objname); +warn ("notify_handler: unknown event type 0x%x for %s\n" , type, + objname);break ; } -acpi_scan_lock_release (); -kfree (hp_work);/* allocated in handle_hotplug_event_bridge */ -put_bridge (bridge); -} - -static void hotplug_event_func (acpi_handle handle,u32 type,void *context) -{ -struct acpiphp_func *func = context; -char objname[64 ]; -struct acpi_buffer buffer = { .length =sizeof (objname), - .pointer = objname }; - -acpi_get_name (handle,ACPI_FULL_PATHNAME , &buffer); - -switch (type) { -case ACPI_NOTIFY_BUS_CHECK : -/* bus re-enumerate */ -dbg ("%s: Bus check notify on %s\n" , __func__, objname); -acpiphp_enable_slot (func->slot); -break ; - -case ACPI_NOTIFY_DEVICE_CHECK : -/* device check : re-enumerate from parent bus */ -dbg ("%s: Device check notify on %s\n" , __func__, objname); -acpiphp_check_bridge (func->slot->bridge); -break ; - -case ACPI_NOTIFY_DEVICE_WAKE : -/* wake event */ -dbg ("%s: Device wake notify on %s\n" , __func__, objname); -break ; - -case ACPI_NOTIFY_EJECT_REQUEST : -/* request device eject */ -dbg ("%s: Device eject notify on %s\n" , __func__, objname); -if (!(acpiphp_disable_slot (func->slot))) -acpiphp_eject_slot (func->slot); -break ; - -default : -warn ("notify_handler: unknown event type 0x%x for %s\n" , type, objname); -break ; - } +if (bridge) +put_bridge (bridge); } -static void _handle_hotplug_event_func (struct work_struct *work) +static void hotplug_event_work (struct work_struct *work) {struct acpiphp_context *context;struct acpi_hp_work *hp_work;
@@ -1114,11 +1088,18 @@ static void _handle_hotplug_event_func(s context = hp_work->context;acpi_scan_lock_acquire (); -hotplug_event_func (hp_work->handle, hp_work->type, context->func); +hotplug_event (hp_work->handle, hp_work->type, context);acpi_scan_lock_release (); -kfree (hp_work);/* allocated in handle_hotplug_event_func */ -put_bridge (context->func->slot->bridge); +kfree (hp_work);/* allocated in handle_hotplug_event() */ + +mutex_lock (&acpiphp_context_lock); +if (context->func) +put_bridge (context->func->slot->bridge); +else +acpiphp_put_context (context); + +mutex_unlock (&acpiphp_context_lock); }/**
@@ -1132,22 +1113,19 @@ static void _handle_hotplug_event_func(sstatic void handle_hotplug_event (acpi_handle handle,u32 type,void *data) {struct acpiphp_context *context; -void (*work_func)(struct work_struct *work) =NULL ;mutex_lock (&acpiphp_context_lock); context =acpiphp_get_context (handle);if (context) { -if (context->bridge) { -get_bridge (context->bridge); - work_func = _handle_hotplug_event_bridge; - }else if (context->func) { +if (context->func) {get_bridge (context->func->slot->bridge); - work_func = _handle_hotplug_event_func; +acpiphp_put_context (context); + }else if (!context->bridge) { +acpiphp_put_context (context); + context =NULL ; } -acpiphp_put_context (context); }mutex_unlock (&acpiphp_context_lock); -/* * Currently the code adds all hotplug events to the kacpid_wq * queue when it should add hotplug events to the kacpi_hotplug_wq.
@@ -1156,8 +1134,8 @@ static void handle_hotplug_event(acpi_ha* For now just re-add this work to the kacpi_hotplug_wq so we * don't deadlock on hotplug actions. */ -if (work_func) -alloc_acpi_hp_work (handle, type, context, work_func); +if (context) +alloc_acpi_hp_work (handle, type, context, hotplug_event_work); }/*
PATCH 9/30 ACPI / hotplug / PCI: Drop func field from struct acpiphp_bridge
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since the func pointer in struct acpiphp_context can always be used instead of the func pointer in struct acpiphp_bridge, drop the latter.
--- drivers/pci/hotplug/acpiphp.h | 2 -- drivers/pci/hotplug/acpiphp_glue.c | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/pci/hotplug/acpiphp.h +0 -2
@@ -79,8 +79,6 @@ struct acpiphp_bridge {acpi_handle handle;struct acpiphp_context *context; -/* Ejectable PCI-to-PCI bridge (PCI bridge and PCI function) */ -struct acpiphp_func *func;int nr_slots;
drivers/pci/hotplug/acpiphp_glue.c +1 -2
@@ -181,7 +181,7 @@ static void free_bridge(struct kref *kre context = bridge->context;/* Release the reference acquired by acpiphp_enumerate_slots(). */ if (context->handler_for_func) -put_bridge (bridge->func->slot->bridge); +put_bridge (context->func->slot->bridge);put_device (&bridge->pci_bus->dev);pci_dev_put (bridge->pci_dev);
@@ -1212,7 +1212,6 @@ void acpiphp_enumerate_slots(struct pci_ }if (context->handler_for_func) {/* Notify handler already installed. */ - bridge->func = context->func;get_bridge (context->func->slot->bridge);return ; }
PATCH 10/30 ACPI / hotplug / PCI: Refactor slot allocation code in register_slot()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
To make the code in register_slot() a bit easier to follow, change the way the slot allocation part is organized. Drop one local variable that's not used any more after that modification.
This code change should not lead to any changes in behavior.
--- drivers/pci/hotplug/acpiphp_glue.c | 74 ++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 38 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +36 -38
@@ -283,7 +283,7 @@ static acpi_status register_slot(acpi_hastruct acpiphp_func *newfunc;acpi_status status =AE_OK ;unsigned long long adr, sun; -int device, function, retval, found =0 ; +int device, function, retval;struct pci_bus *pbus = bridge->pci_bus;struct pci_dev *pdev;u32 val;
@@ -352,44 +352,49 @@ static acpi_status register_slot(acpi_haif (slot->device == device) {if (slot->sun != sun)warn ("sibling found, but _SUN doesn't match!\n" ); - found =1 ; -break ; - } -if (!found) { - slot =kzalloc (sizeof (struct acpiphp_slot ),GFP_KERNEL ); -if (!slot) { - status =AE_NO_MEMORY ; - goto err_out; + goto slot_found; } - slot->bridge = bridge; - slot->device = device; - slot->sun = sun; -INIT_LIST_HEAD (&slot->funcs); -mutex_init (&slot->crit_sect); + slot =kzalloc (sizeof (struct acpiphp_slot ),GFP_KERNEL ); +if (!slot) { + status =AE_NO_MEMORY ; + goto err; + } -mutex_lock (&bridge_mutex); -list_add_tail (&slot->node, &bridge->slots); -mutex_unlock (&bridge_mutex); - bridge->nr_slots++; + slot->bridge = bridge; + slot->device = device; + slot->sun = sun; +INIT_LIST_HEAD (&slot->funcs); +mutex_init (&slot->crit_sect); -dbg ("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n" , - slot->sun,pci_domain_nr (pbus), pbus->number, device); - retval =acpiphp_register_hotplug_slot (slot); -if (retval) { -if (retval == -EBUSY ) -warn ("Slot %llu already registered by another " -"hotplug driver\n" , slot->sun); -else -warn ("acpiphp_register_hotplug_slot failed " -"(err code = 0x%x)\n" , retval); +mutex_lock (&bridge_mutex); +list_add_tail (&slot->node, &bridge->slots); +mutex_unlock (&bridge_mutex); + bridge->nr_slots++; - status =AE_OK ; - goto err; - } +dbg ("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n" , + slot->sun,pci_domain_nr (pbus), pbus->number, device); + + retval =acpiphp_register_hotplug_slot (slot); +if (retval) { +if (retval == -EBUSY ) +warn ("Slot %llu already registered by another " +"hotplug driver\n" , slot->sun); +else +warn ("acpiphp_register_hotplug_slot failed " +"(err code = 0x%x)\n" , retval); + + bridge->nr_slots--; +mutex_lock (&bridge_mutex); +list_del (&slot->node); +mutex_unlock (&bridge_mutex); +kfree (slot); + status =AE_OK ; + goto err; } + slot_found: newfunc->slot = slot;mutex_lock (&bridge_mutex);list_add_tail (&newfunc->sibling, &slot->funcs);
@@ -425,13 +430,6 @@ static acpi_status register_slot(acpi_hareturn AE_OK ; err: - bridge->nr_slots--; -mutex_lock (&bridge_mutex); -list_del (&slot->node); -mutex_unlock (&bridge_mutex); -kfree (slot); - - err_out:mutex_lock (&acpiphp_context_lock); context->func =NULL ;acpiphp_put_context (context);
PATCH 11/30 ACPI / hotplug / PCI: Register all devices under the given bridge
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Rework register_slot() to create a struct acpiphp_func object for every function it is called for and to create acpiphp slots for all of them. Although acpiphp_register_hotplug_slot() is only called for the slots whose functions are identified as "ejectable", so that user space can manipulate them, the ACPIPHP notify handler, handle_hotplug_event(), is now installed for all of the registered functions (that aren't dock stations) and hotplug events may be handled for all of them.
As a result, essentially, all PCI bridges represented by objects in the ACPI namespace are now going to be "hotplug" bridges and that may affect resources allocation in general, although it shouldn't lead to problems.
This allows the code to be simplified substantially and addresses the problem where bus check or device check notifications for some PCI bridges or devices are not handled, because those devices are not recognized as "ejectable" or there appear to be no "ejectable" devices under those bridges.
--- drivers/pci/hotplug/acpiphp.h | 1 drivers/pci/hotplug/acpiphp_glue.c | 230 ++++++++++++------------------------- 2 files changed, 75 insertions(+), 156 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +75 -155
@@ -65,20 +65,6 @@ static void acpiphp_set_hpp_values(strucstatic void hotplug_event (acpi_handle handle,u32 type,void *data);static void free_bridge (struct kref *kref); -/* 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) -{ -int *count = (int *)context; - -if (is_dock_device (handle)) { - (*count)++; -return AE_CTRL_TERMINATE ; - }else { -return AE_OK ; - } -} -static void acpiphp_context_handler (acpi_handle handle,void *context) {/* Intentionally empty. */
@@ -179,14 +165,16 @@ static void free_bridge(struct kref *kre } context = bridge->context; -/* Release the reference acquired by acpiphp_enumerate_slots(). */ -if (context->handler_for_func) +/* Root bridges will not have hotplug context. */ +if (context) { +/* Release the reference taken by acpiphp_enumerate_slots(). */ put_bridge (context->func->slot->bridge); + context->bridge =NULL ; +acpiphp_put_context (context); + }put_device (&bridge->pci_bus->dev);pci_dev_put (bridge->pci_dev); - context->bridge =NULL ; -acpiphp_put_context (context);kfree (bridge);mutex_unlock (&acpiphp_context_lock);
@@ -282,28 +270,24 @@ static acpi_status register_slot(acpi_hastruct acpiphp_slot *slot;struct acpiphp_func *newfunc;acpi_status status =AE_OK ; -unsigned long long adr, sun; -int device, function, retval; +unsigned long long adr; +int device, function;struct pci_bus *pbus = bridge->pci_bus; -struct pci_dev *pdev; +struct pci_dev *pdev = bridge->pci_dev;u32 val; -if (!acpi_pci_check_ejectable (pbus, handle) && !is_dock_device (handle)) +if (pdev &&device_is_managed_by_native_pciehp (pdev))return AE_OK ; status =acpi_evaluate_integer (handle,"_ADR" ,NULL , &adr);if (ACPI_FAILURE (status)) { -warn ("can't evaluate _ADR (%#x)\n" , status); +acpi_handle_warn (handle,"can't evaluate _ADR (%#x)\n" , status);return AE_OK ; } device = (adr >>16 ) &0xffff ; function = adr &0xffff ; - pdev = bridge->pci_dev; -if (pdev &&device_is_managed_by_native_pciehp (pdev)) -return AE_OK ; - newfunc =kzalloc (sizeof (struct acpiphp_func ),GFP_KERNEL );if (!newfunc)return AE_NO_MEMORY ;
@@ -338,23 +322,10 @@ static acpi_status register_slot(acpi_haif (acpi_has_method (handle,"_DCK" )) newfunc->flags |=FUNC_HAS_DCK ; - status =acpi_evaluate_integer (handle,"_SUN" ,NULL , &sun); -if (ACPI_FAILURE (status)) { -/* -* use the count of the number of slots we've found -* for the number of the slot -*/ - sun = bridge->nr_slots+1 ; - } -/* search for objects that share the same slot */ list_for_each_entry (slot, &bridge->slots, node) -if (slot->device == device) { -if (slot->sun != sun) -warn ("sibling found, but _SUN doesn't match!\n" ); - +if (slot->device == device) goto slot_found; - } slot =kzalloc (sizeof (struct acpiphp_slot ),GFP_KERNEL );if (!slot) {
@@ -364,34 +335,38 @@ static acpi_status register_slot(acpi_ha slot->bridge = bridge; slot->device = device; - slot->sun = sun;INIT_LIST_HEAD (&slot->funcs);mutex_init (&slot->crit_sect);mutex_lock (&bridge_mutex);list_add_tail (&slot->node, &bridge->slots);mutex_unlock (&bridge_mutex); - bridge->nr_slots++; -dbg ("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n" , - slot->sun,pci_domain_nr (pbus), pbus->number, device); +/* Register slots for ejectable funtions only. */ +if (acpi_pci_check_ejectable (pbus, handle) ||is_dock_device (handle)) { +unsigned long long sun; +int retval; - retval =acpiphp_register_hotplug_slot (slot); -if (retval) { -if (retval == -EBUSY ) -warn ("Slot %llu already registered by another " -"hotplug driver\n" , slot->sun); -else -warn ("acpiphp_register_hotplug_slot failed " -"(err code = 0x%x)\n" , retval); + bridge->nr_slots++; + status =acpi_evaluate_integer (handle,"_SUN" ,NULL , &sun); +if (ACPI_FAILURE (status)) + sun = bridge->nr_slots; - bridge->nr_slots--; -mutex_lock (&bridge_mutex); -list_del (&slot->node); -mutex_unlock (&bridge_mutex); -kfree (slot); - status =AE_OK ; - goto err; + slot->sun = sun; +dbg ("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n" , + slot->sun,pci_domain_nr (pbus), pbus->number, device); + + retval =acpiphp_register_hotplug_slot (slot); +if (retval) { + bridge->nr_slots--; +if (retval == -EBUSY ) +warn ("Slot %llu already registered by another " +"hotplug driver\n" , slot->sun); +else +warn ("acpiphp_register_hotplug_slot failed " +"(err code = 0x%x)\n" , retval); + } +/* Even if the slot registration fails, we can still use it. */ } slot_found:
@@ -421,10 +396,9 @@ static acpi_status register_slot(acpi_ha status =acpi_install_notify_handler (handle,ACPI_SYSTEM_NOTIFY , handle_hotplug_event, context); -if (ACPI_SUCCESS (status)) - context->handler_for_func = true; -else -err ("failed to register interrupt notify handler\n" ); +if (ACPI_FAILURE (status)) +acpi_handle_err (handle, +"failed to install notify handler\n" ); }return AE_OK ;
@@ -438,18 +412,6 @@ static acpi_status register_slot(acpi_hareturn status; } - -/* see if it's worth looking at this bridge */ -static int detect_ejectable_slots (acpi_handle handle) -{ -int found =acpi_pci_detect_ejectable (handle); -if (!found) { -acpi_walk_namespace (ACPI_TYPE_DEVICE , handle, (u32 )1 , - is_pci_dock_device,NULL , (void *)&found,NULL ); - } -return found; -} -static struct acpiphp_bridge *acpiphp_handle_to_bridge (acpi_handle handle) {struct acpiphp_context *context;
@@ -473,14 +435,6 @@ static void cleanup_bridge(struct acpiphstruct acpiphp_slot *slot;struct acpiphp_func *func;acpi_status status; -acpi_handle handle = bridge->handle; - -if (!bridge->context->handler_for_func) { - status =acpi_remove_notify_handler (handle,ACPI_SYSTEM_NOTIFY , - handle_hotplug_event); -if (ACPI_FAILURE (status)) -err ("failed to remove notify handler\n" ); - }list_for_each_entry (slot, &bridge->slots, node) {list_for_each_entry (func, &slot->funcs, sibling) {
@@ -488,7 +442,6 @@ static void cleanup_bridge(struct acpiphunregister_hotplug_dock_device (func->handle); }if (!(func->flags &FUNC_HAS_DCK )) { - func->context->handler_for_func = false; status =acpi_remove_notify_handler (func->handle,ACPI_SYSTEM_NOTIFY , handle_hotplug_event);
@@ -678,9 +631,7 @@ static void check_hotplug_bridge(structlist_for_each_entry (func, &slot->funcs, sibling) {if (PCI_FUNC (dev->devfn) == func->function) { -/* check if this bridge has ejectable slots */ -if ((detect_ejectable_slots (func->handle) >0 )) - dev->is_hotplug_bridge =1 ; + dev->is_hotplug_bridge =1 ;break ; } }
@@ -988,8 +939,8 @@ void acpiphp_check_host_bridge(acpi_handstatic void hotplug_event (acpi_handle handle,u32 type,void *data) {struct acpiphp_context *context = data; +struct acpiphp_func *func = context->func;struct acpiphp_bridge *bridge; -struct acpiphp_func *func;char objname[64 ];struct acpi_buffer buffer = { .length =sizeof (objname), .pointer = objname };
@@ -999,11 +950,6 @@ static void hotplug_event(acpi_handle haif (bridge)get_bridge (bridge); -/* -* If context->func is not NULL, we are holding a reference to its -* parent bridge, so it won't go away until we drop that reference. -*/ - func = context->func;mutex_unlock (&acpiphp_context_lock);acpi_get_name (handle,ACPI_FULL_PATHNAME , &buffer);
@@ -1041,9 +987,6 @@ static void hotplug_event(acpi_handle hacase ACPI_NOTIFY_EJECT_REQUEST :/* request device eject */ dbg ("%s: Device eject notify on %s\n" , __func__, objname); -if (!func) -break ; -if (bridge && !(bridge->flags &BRIDGE_HAS_EJ0 ))break ;
@@ -1090,14 +1033,7 @@ static void hotplug_event_work(struct woacpi_scan_lock_release ();kfree (hp_work);/* allocated in handle_hotplug_event() */ - -mutex_lock (&acpiphp_context_lock); -if (context->func) -put_bridge (context->func->slot->bridge); -else -acpiphp_put_context (context); - -mutex_unlock (&acpiphp_context_lock); +put_bridge (context->func->slot->bridge); }/**
@@ -1115,13 +1051,8 @@ static void handle_hotplug_event(acpi_hamutex_lock (&acpiphp_context_lock); context =acpiphp_get_context (handle);if (context) { -if (context->func) { -get_bridge (context->func->slot->bridge); -acpiphp_put_context (context); - }else if (!context->bridge) { -acpiphp_put_context (context); - context =NULL ; - } +get_bridge (context->func->slot->bridge); +acpiphp_put_context (context); }mutex_unlock (&acpiphp_context_lock);/*
@@ -1142,7 +1073,6 @@ static void handle_hotplug_event(acpi_ha*/ void acpiphp_enumerate_slots (struct pci_bus *bus) { -struct acpiphp_context *context;struct acpiphp_bridge *bridge;acpi_handle handle;acpi_status status;
@@ -1151,7 +1081,7 @@ void acpiphp_enumerate_slots(struct pci_return ; handle =ACPI_HANDLE (bus->bridge); -if (!handle ||detect_ejectable_slots (handle) <=0 ) +if (!handle)return ; bridge =kzalloc (sizeof (struct acpiphp_bridge ),GFP_KERNEL );
@@ -1166,21 +1096,6 @@ void acpiphp_enumerate_slots(struct pci_ bridge->pci_dev =pci_dev_get (bus->self); bridge->pci_bus = bus; -mutex_lock (&acpiphp_context_lock); - context =acpiphp_get_context (handle); -if (!context) { - context =acpiphp_init_context (handle); -if (!context) { -mutex_unlock (&acpiphp_context_lock); -acpi_handle_err (handle,"No hotplug context\n" ); -kfree (bridge); -return ; - } - } - bridge->context = context; - context->bridge = bridge; -mutex_unlock (&acpiphp_context_lock); -/* * Grab a ref to the subordinate PCI bus in case the bus is * removed via PCI core logical hotplug. The ref pins the bus
@@ -1188,6 +1103,35 @@ void acpiphp_enumerate_slots(struct pci_*/ get_device (&bus->dev); +if (!pci_is_root_bus (bridge->pci_bus)) { +struct acpiphp_context *context; + +/* +* This bridge should have been registered as a hotplug function +* under its parent, so the context has to be there. If not, we +* are in deep goo. +*/ +mutex_lock (&acpiphp_context_lock); + context =acpiphp_get_context (handle); +if (WARN_ON (!context || !context->func)) { +mutex_unlock (&acpiphp_context_lock); +put_device (&bus->dev); +kfree (bridge); +return ; + } + bridge->context = context; + context->bridge = bridge; +/* Get a reference to the parent bridge. */ +get_bridge (context->func->slot->bridge); +mutex_unlock (&acpiphp_context_lock); + } + + status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); +if (ACPI_SUCCESS (status)) { +dbg ("found ejectable p2p bridge\n" ); + bridge->flags |=BRIDGE_HAS_EJ0 ; + } +/* must be added to the list prior to calling register_slot */ mutex_lock (&bridge_mutex);list_add (&bridge->list, &bridge_list);
@@ -1198,33 +1142,9 @@ void acpiphp_enumerate_slots(struct pci_ register_slot, NULL, bridge, NULL);if (ACPI_FAILURE (status)) {acpi_handle_err (bridge->handle,"failed to register slots\n" ); - goto err; - } - -if (pci_is_root_bus (bridge->pci_bus)) -return ; - -if (acpi_has_method (bridge->handle,"_EJ0" )) { -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; - } -if (context->handler_for_func) { -/* Notify handler already installed. */ -get_bridge (context->func->slot->bridge); -return ; +cleanup_bridge (bridge); +put_bridge (bridge); } - -/* install notify handler for P2P bridges */ - status =acpi_install_notify_handler (bridge->handle,ACPI_SYSTEM_NOTIFY , - handle_hotplug_event,NULL ); -if (ACPI_SUCCESS (status)) -return ; - -acpi_handle_err (bridge->handle,"failed to register notify handler\n" ); - - err: -cleanup_bridge (bridge); -put_bridge (bridge); }/* Destroy hotplug slots associated with the PCI bus */
drivers/pci/hotplug/acpiphp.h +0 -1
@@ -134,7 +134,6 @@ struct acpiphp_context {struct acpiphp_func *func;struct acpiphp_bridge *bridge;unsigned int refcount; -bool handler_for_func; };/*
PATCH 12/30 ACPI / hotplug / PCI: Drop sun field from struct acpiphp_slot
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
If the slot unique number is passed as an additional argument to acpiphp_register_hotplug_slot(), the 'sun' field in struct acpiphp_slot is only used by ibm_[s|g]et_attention_status(), but then it's more efficient to store it in struct slot.
Thus move the 'sun' field from struct acpiphp_slot to struct slot changing its data type to unsigned int in the process, and redefine acpiphp_register_hotplug_slot() to take the slot number as separate argument.
--- drivers/pci/hotplug/acpiphp.h | 5 ++--- drivers/pci/hotplug/acpiphp_core.c | 6 ++++-- drivers/pci/hotplug/acpiphp_glue.c | 7 +++---- drivers/pci/hotplug/acpiphp_ibm.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-)
drivers/pci/hotplug/acpiphp.h +2 -3
@@ -60,6 +60,7 @@ struct slot {struct hotplug_slot *hotplug_slot;struct acpiphp_slot *acpi_slot;struct hotplug_slot_info info; +unsigned int sun;/* ACPI _SUN (Slot User Number) value */ };static inline const char *slot_name (struct slot *slot)
@@ -106,8 +107,6 @@ struct acpiphp_slot {struct mutex crit_sect;u8 device;/* pci device# */ - -unsigned long long sun;/* ACPI _SUN (slot unique number) */ u32 flags;/* see below */ };
@@ -179,7 +178,7 @@ struct acpiphp_attention_info/* acpiphp_core.c */ int acpiphp_register_attention (struct acpiphp_attention_info *info);int acpiphp_unregister_attention (struct acpiphp_attention_info *info); -int acpiphp_register_hotplug_slot (struct acpiphp_slot *slot); +int acpiphp_register_hotplug_slot (struct acpiphp_slot *slot,unsigned int sun);void acpiphp_unregister_hotplug_slot (struct acpiphp_slot *slot);/* acpiphp_glue.c */
drivers/pci/hotplug/acpiphp_core.c +4 -2
@@ -290,7 +290,8 @@ static void release_slot(struct hotplug_ }/* callback routine to initialize 'struct slot' for each slot */ -int acpiphp_register_hotplug_slot (struct acpiphp_slot *acpiphp_slot) +int acpiphp_register_hotplug_slot (struct acpiphp_slot *acpiphp_slot, +unsigned int sun) {struct slot *slot;int retval = -ENOMEM ;
@@ -317,7 +318,8 @@ int acpiphp_register_hotplug_slot(struct slot->hotplug_slot->info->adapter_status =acpiphp_get_adapter_status (slot->acpi_slot); acpiphp_slot->slot = slot; -snprintf (name,SLOT_NAME_SIZE ,"%llu" , slot->acpi_slot->sun); + slot->sun = sun; +snprintf (name,SLOT_NAME_SIZE ,"%u" , sun); retval = pci_hp_register(slot->hotplug_slot, acpiphp_slot->bridge->pci_bus,
drivers/pci/hotplug/acpiphp_glue.c +3 -4
@@ -352,16 +352,15 @@ static acpi_status register_slot(acpi_haif (ACPI_FAILURE (status)) sun = bridge->nr_slots; - slot->sun = sun;dbg ("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n" , - slot->sun,pci_domain_nr (pbus), pbus->number, device); + sun,pci_domain_nr (pbus), pbus->number, device); - retval =acpiphp_register_hotplug_slot (slot); + retval =acpiphp_register_hotplug_slot (slot, sun);if (retval) { bridge->nr_slots--;if (retval == -EBUSY )warn ("Slot %llu already registered by another " -"hotplug driver\n" , slot->sun); +"hotplug driver\n" , sun);else warn ("acpiphp_register_hotplug_slot failed " "(err code = 0x%x)\n" , retval);
drivers/pci/hotplug/acpiphp_ibm.c +1 -1
@@ -66,7 +66,7 @@ do { \#define IBM_HARDWARE_ID1 "IBM37D0"#define IBM_HARDWARE_ID2 "IBM37D4" -#define hpslot_to_sun (A ) (((struct slot *)((A)->private))->acpi_slot->sun) +#define hpslot_to_sun (A ) (((struct slot *)((A)->private))->sun)/* union apci_descriptor - allows access to the * various device descriptors that are embedded in the
PATCH 13/30 ACPI / hotplug / PCI: Drop flags field from struct acpiphp_bridge
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The only bridge flag used by the ACPI-based PCI hotplug (ACPIPHP) code is BRIDGE_HAS_EJ0, but it is only used by the event handling function hotplug_event() and if that flag is set, the corresponding function flag FUNC_HAS_EJ0 is set as well, so that bridge flag is redundant.
For this reason, drop BRIDGE_HAS_EJ0 and all code referring to it and since it is the only bridge flag defined, drop the flags field from struct acpiphp_bridge entirely.
--- drivers/pci/hotplug/acpiphp.h | 5 ----- drivers/pci/hotplug/acpiphp_glue.c | 9 --------- 2 files changed, 14 deletions(-)
drivers/pci/hotplug/acpiphp.h +0 -5
@@ -83,8 +83,6 @@ struct acpiphp_bridge {int nr_slots; -u32 flags; -/* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */ struct pci_bus *pci_bus;
@@ -154,9 +152,6 @@ struct acpiphp_attention_info/* ACPI _STA method value (ignore bit 4; battery present) */ #define ACPI_STA_ALL (0x0000000f) -/* bridge flags */ -#define BRIDGE_HAS_EJ0 (0x00000001) -/* slot flags */ #define SLOT_POWEREDON (0x00000001)
drivers/pci/hotplug/acpiphp_glue.c +0 -9
@@ -986,9 +986,6 @@ static void hotplug_event(acpi_handle hacase ACPI_NOTIFY_EJECT_REQUEST :/* request device eject */ dbg ("%s: Device eject notify on %s\n" , __func__, objname); -if (bridge && !(bridge->flags &BRIDGE_HAS_EJ0 )) -break ; -if (!(acpiphp_disable_slot (func->slot)))acpiphp_eject_slot (func->slot);
@@ -1125,12 +1122,6 @@ void acpiphp_enumerate_slots(struct pci_mutex_unlock (&acpiphp_context_lock); } - status =acpi_get_handle (bridge->handle,"_EJ0" , &handle); -if (ACPI_SUCCESS (status)) { -dbg ("found ejectable p2p bridge\n" ); - bridge->flags |=BRIDGE_HAS_EJ0 ; - } -/* must be added to the list prior to calling register_slot */ mutex_lock (&bridge_mutex);list_add (&bridge->list, &bridge_list);
PATCH 14/30 ACPI / hotplug / PCI: Embed function struct into struct acpiphp_context
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Since there has to be a struct acpiphp_func object for every struct acpiphp_context created by register_slot(), the struct acpiphp_func one can be embedded into the struct acpiphp_context one, which allows some code simplifications to be made.
--- drivers/pci/hotplug/acpiphp.h | 8 +++++- drivers/pci/hotplug/acpiphp_glue.c | 44 +++++++++++++------------------------ 2 files changed, 22 insertions(+), 30 deletions(-)
drivers/pci/hotplug/acpiphp.h +6 -2
@@ -116,7 +116,6 @@ struct acpiphp_slot {* typically 8 objects per slot (i.e. for each PCI function) */ struct acpiphp_func { -struct acpiphp_context *context;struct acpiphp_slot *slot;/* parent */ struct list_head sibling;
@@ -128,11 +127,16 @@ struct acpiphp_func {struct acpiphp_context {acpi_handle handle; -struct acpiphp_func *func; +struct acpiphp_func func;struct acpiphp_bridge *bridge;unsigned int refcount; }; +static inline struct acpiphp_context *func_to_context (struct acpiphp_func *func) +{ + return container_of(func, struct acpiphp_context, func); +} +/* * struct acpiphp_attention_info - device specific attention registration *
drivers/pci/hotplug/acpiphp_glue.c +16 -28
131 lines not on this page · raw message
PATCH 15/30 ACPI / hotplug / PCI: Drop handle field from struct acpiphp_func
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The ACPI handle stored in struct acpiphp_func is also stored in the struct acpiphp_context object containing it and it is trivial to get from a struct acpiphp_func pointer to the handle field of the outer struct acpiphp_context.
Hence, the handle field of struct acpiphp_func is redundant, so drop it and provide a helper function, func_to_handle(), allowing it users to get the ACPI handle for the given struct acpiphp_func pointer.
--- drivers/pci/hotplug/acpiphp.h | 6 +++- drivers/pci/hotplug/acpiphp_glue.c | 54 +++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 24 deletions(-)
drivers/pci/hotplug/acpiphp.h +5 -1
@@ -119,7 +119,6 @@ struct acpiphp_func {struct acpiphp_slot *slot;/* parent */ struct list_head sibling; -acpi_handle handle;u8 function;/* pci function# */ u32 flags;/* see below */
@@ -137,6 +136,11 @@ static inline struct acpiphp_context *fu return container_of(func, struct acpiphp_context, func); } +static inline acpi_handle func_to_handle (struct acpiphp_func *func) +{ +return func_to_context (func)->handle; +} +/* * struct acpiphp_attention_info - device specific attention registration *
drivers/pci/hotplug/acpiphp_glue.c +31 -23
127 lines not on this page · raw message
PATCH 16/30 ACPI / hotplug / PCI: Drop handle field from struct acpiphp_bridge
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The handle field in struct acpiphp_bridge is only used by acpiphp_enumerate_slots(), but in that function the local handle variable can be used instead, so make that happen and drop handle from struct acpiphp_bridge.
--- drivers/pci/hotplug/acpiphp.h | 1 - drivers/pci/hotplug/acpiphp_glue.c | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/pci/hotplug/acpiphp.h +0 -1
@@ -77,7 +77,6 @@ struct acpiphp_bridge {struct list_head list;struct list_head slots;struct kref ref; -acpi_handle handle;struct acpiphp_context *context;
drivers/pci/hotplug/acpiphp_glue.c +2 -3
@@ -1084,7 +1084,6 @@ void acpiphp_enumerate_slots(struct pci_INIT_LIST_HEAD (&bridge->slots);kref_init (&bridge->ref); - bridge->handle = handle; bridge->pci_dev =pci_dev_get (bus->self); bridge->pci_bus = bus;
@@ -1124,10 +1123,10 @@ void acpiphp_enumerate_slots(struct pci_mutex_unlock (&bridge_mutex);/* register all slot objects under this bridge */ - status =acpi_walk_namespace (ACPI_TYPE_DEVICE , bridge->handle,1 , + status =acpi_walk_namespace (ACPI_TYPE_DEVICE , handle,1 , register_slot,NULL , bridge,NULL );if (ACPI_FAILURE (status)) { -acpi_handle_err (bridge->handle,"failed to register slots\n" ); +acpi_handle_err (handle,"failed to register slots\n" );cleanup_bridge (bridge);put_bridge (bridge); }
PATCH 17/30 ACPI / hotplug / PCI: Store parent in functions and bus in slots
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
To avoid chasing more pointers than necessary in some situations, move the bridge pointer from struct acpiphp_slot to struct acpiphp_func (and call it 'parent') and add a bus pointer to struct acpiphp_slot.
--- drivers/pci/hotplug/acpiphp.h | 5 +++-- drivers/pci/hotplug/acpiphp_core.c | 6 ++---- drivers/pci/hotplug/acpiphp_glue.c | 25 +++++++++++++------------ 3 files changed, 18 insertions(+), 18 deletions(-)
drivers/pci/hotplug/acpiphp.h +3 -2
@@ -97,7 +97,7 @@ struct acpiphp_bridge {*/ struct acpiphp_slot {struct list_head node; -struct acpiphp_bridge *bridge;/* parent */ +struct pci_bus *bus;struct list_head funcs;/* one slot may have different objects (i.e. for each function) */ struct slot *slot;
@@ -115,7 +115,8 @@ struct acpiphp_slot {* typically 8 objects per slot (i.e. for each PCI function) */ struct acpiphp_func { -struct acpiphp_slot *slot;/* parent */ +struct acpiphp_bridge *parent; +struct acpiphp_slot *slot;struct list_head sibling;
drivers/pci/hotplug/acpiphp_glue.c +13 -12
@@ -165,7 +165,7 @@ static void free_bridge(struct kref *kre/* Root bridges will not have hotplug context. */ if (context) {/* Release the reference taken by acpiphp_enumerate_slots(). */ -put_bridge (context->func.slot->bridge); +put_bridge (context->func.parent); context->bridge =NULL ;acpiphp_put_context (context); }
@@ -187,7 +187,7 @@ static void free_bridge(struct kref *krestatic void post_dock_fixups (acpi_handle not_used,u32 event,void *data) {struct acpiphp_context *context = data; -struct pci_bus *bus = context->func.slot->bridge->pci_bus; +struct pci_bus *bus = context->func.slot->bus;u32 buses;if (!bus->self)
@@ -248,14 +248,14 @@ static void acpiphp_dock_init(void *data {struct acpiphp_context *context = data; -get_bridge (context->func.slot->bridge); +get_bridge (context->func.parent); }static void acpiphp_dock_release (void *data) {struct acpiphp_context *context = data; -put_bridge (context->func.slot->bridge); +put_bridge (context->func.parent); }/* callback routine to register each ACPI PCI slot object */
@@ -294,6 +294,7 @@ static acpi_status register_slot(acpi_ha } newfunc = &context->func; newfunc->function = function; + newfunc->parent = bridge;mutex_unlock (&acpiphp_context_lock);if (acpi_has_method (handle,"_EJ0" ))
@@ -322,7 +323,7 @@ static acpi_status register_slot(acpi_ha goto err; } - slot->bridge = bridge; + slot->bus = bridge->pci_bus; slot->device = device;INIT_LIST_HEAD (&slot->funcs);mutex_init (&slot->crit_sect);
@@ -639,7 +640,7 @@ static void check_hotplug_bridge(structstatic int __ref enable_device (struct acpiphp_slot *slot) {struct pci_dev *dev; -struct pci_bus *bus = slot->bridge->pci_bus; +struct pci_bus *bus = slot->bus;struct acpiphp_func *func;int num, max, pass;LIST_HEAD (add_list);
@@ -709,7 +710,7 @@ static int __ref enable_device(struct ac/* return first device in slot, acquiring a reference on it */ static struct pci_dev *dev_in_slot (struct acpiphp_slot *slot) { -struct pci_bus *bus = slot->bridge->pci_bus; +struct pci_bus *bus = slot->bus;struct pci_dev *dev;struct pci_dev *ret =NULL ;
@@ -781,7 +782,7 @@ static unsigned int get_slot_status(stru }else {u32 dvid; -pci_bus_read_config_dword (slot->bridge->pci_bus, +pci_bus_read_config_dword (slot->bus,PCI_DEVFN (slot->device, func->function),PCI_VENDOR_ID , &dvid);
@@ -970,7 +971,7 @@ static void hotplug_event(acpi_handle haif (bridge)acpiphp_check_bridge (bridge);else -acpiphp_check_bridge (func->slot->bridge); +acpiphp_check_bridge (func->parent);break ;
@@ -1025,7 +1026,7 @@ static void hotplug_event_work(struct woacpi_scan_lock_release ();kfree (hp_work);/* allocated in handle_hotplug_event() */ -put_bridge (context->func.slot->bridge); +put_bridge (context->func.parent); }/**
@@ -1043,7 +1044,7 @@ static void handle_hotplug_event(acpi_hamutex_lock (&acpiphp_context_lock); context =acpiphp_get_context (handle);if (context) { -get_bridge (context->func.slot->bridge); +get_bridge (context->func.parent);acpiphp_put_context (context); }mutex_unlock (&acpiphp_context_lock);
@@ -1113,7 +1114,7 @@ void acpiphp_enumerate_slots(struct pci_ bridge->context = context; context->bridge = bridge;/* Get a reference to the parent bridge. */ -get_bridge (context->func.slot->bridge); +get_bridge (context->func.parent);mutex_unlock (&acpiphp_context_lock); }
drivers/pci/hotplug/acpiphp_core.c +2 -4
@@ -321,10 +321,8 @@ int acpiphp_register_hotplug_slot(struct slot->sun = sun;snprintf (name,SLOT_NAME_SIZE ,"%u" , sun); - retval =pci_hp_register (slot->hotplug_slot, - acpiphp_slot->bridge->pci_bus, - acpiphp_slot->device, - name); + retval =pci_hp_register (slot->hotplug_slot, acpiphp_slot->bus, + acpiphp_slot->device, name);if (retval == -EBUSY ) goto error_hpslot;if (retval) {
PATCH 18/30 ACPI / hotplug / PCI: Rework namespace scanning and trimming routines
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The acpiphp_bus_trim() and acpiphp_bus_add() functions need not return error codes that are never checked, so redefine them and simplify them a bit.
--- drivers/pci/hotplug/acpiphp_glue.c | 52 +++++++++---------------------------- 1 file changed, 13 insertions(+), 39 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +13 -39
@@ -540,53 +540,27 @@ static unsigned char acpiphp_max_busnr(sreturn max; } -/** -* acpiphp_bus_add - add a new bus to acpi subsystem -* @func: acpiphp_func of the bridge +* acpiphp_bus_trim - Trim device objects in an ACPI namespace subtree. +* @handle: ACPI device object handle to start from. */ -static int acpiphp_bus_add (struct acpiphp_func *func) +static void acpiphp_bus_trim (acpi_handle handle) { -acpi_handle handle =func_to_handle (func); -struct acpi_device *device; -int ret_val; - -if (!acpi_bus_get_device (handle, &device)) { -dbg ("bus exists... trim\n" ); -/* this shouldn't be in here, so remove -* the bus then re-add it... -*/ -acpi_bus_trim (device); - } - - ret_val =acpi_bus_scan (handle); -if (!ret_val) - ret_val =acpi_bus_get_device (handle, &device); - -if (ret_val) -dbg ("error adding bus, %x\n" , -ret_val); +struct acpi_device *adev =NULL ; -return ret_val; +acpi_bus_get_device (handle, &adev); +if (adev) +acpi_bus_trim (adev); } -/** -* acpiphp_bus_trim - trim a bus from acpi subsystem -* @handle: handle to acpi namespace +* acpiphp_bus_add - Scan ACPI namespace subtree. +* @handle: ACPI object handle to start the scan from. */ -static int acpiphp_bus_trim (acpi_handle handle) +static void acpiphp_bus_add (acpi_handle handle) { -struct acpi_device *device; -int retval; - - retval =acpi_bus_get_device (handle, &device); -if (retval) { -dbg ("acpi_device not found\n" ); -return retval; - } - -acpi_bus_trim (device); -return 0 ; +acpiphp_bus_trim (handle); +acpi_bus_scan (handle); }static void acpiphp_set_acpi_region (struct acpiphp_slot *slot)
@@ -649,7 +623,7 @@ static int __ref enable_device(struct ac goto err_exit;list_for_each_entry (func, &slot->funcs, sibling) -acpiphp_bus_add (func); +acpiphp_bus_add (func_to_handle (func)); num =pci_scan_slot (bus,PCI_DEVFN (slot->device,0 ));if (num ==0 ) {
PATCH 19/30 ACPI / hotplug / PCI: Drop redundant checks from check_hotplug_bridge()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Two checks in check_hotplug_bridge() are redundant (they have been done by the caller already), so drop them.
--- drivers/pci/hotplug/acpiphp_glue.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +0 -6
@@ -586,16 +586,10 @@ static void check_hotplug_bridge(struct {struct acpiphp_func *func; -if (!dev->subordinate) -return ; -/* quirk, or pcie could set it already */ if (dev->is_hotplug_bridge)return ; -if (PCI_SLOT (dev->devfn) != slot->device) -return ; -list_for_each_entry (func, &slot->funcs, sibling) {if (PCI_FUNC (dev->devfn) == func->function) { dev->is_hotplug_bridge =1 ;
PATCH 20/30 ACPI / hotplug / PCI: Consolidate slot disabling and ejecting
In reply to Rafael J. WysockiFrom: Mika Westerberg <[email protected]>
Both acpiphp_disable_slot() and acpiphp_eject_slot() are always called together so instead of calling each separately we can consolidate them into one function acpiphp_disable_and_eject_slot() that does both (but it will return success on _EJ0 failures that were ignored in the majority of call sites anyway).
--- drivers/pci/hotplug/acpiphp.h | 3 -- drivers/pci/hotplug/acpiphp_core.c | 6 ---- drivers/pci/hotplug/acpiphp_glue.c | 50 +++++++++++++------------------------ 3 files changed, 20 insertions(+), 39 deletions(-)
drivers/pci/hotplug/acpiphp.h +1 -2
@@ -188,8 +188,7 @@ void acpiphp_unregister_hotplug_slot(strtypedef int (*acpiphp_callback )(struct acpiphp_slot *slot,void *data);int acpiphp_enable_slot (struct acpiphp_slot *slot); -int acpiphp_disable_slot (struct acpiphp_slot *slot); -int acpiphp_eject_slot (struct acpiphp_slot *slot); +int acpiphp_disable_and_eject_slot (struct acpiphp_slot *slot);u8 acpiphp_get_power_status (struct acpiphp_slot *slot);u8 acpiphp_get_attention_status (struct acpiphp_slot *slot);u8 acpiphp_get_latch_status (struct acpiphp_slot *slot);
drivers/pci/hotplug/acpiphp_core.c +1 -5
@@ -155,15 +155,11 @@ static int enable_slot(struct hotplug_slstatic int disable_slot (struct hotplug_slot *hotplug_slot) {struct slot *slot = hotplug_slot->private; -int retval;dbg ("%s - physical_slot = %s\n" , __func__,slot_name (slot));/* disable the specified slot */ - retval =acpiphp_disable_slot (slot->acpi_slot); -if (!retval) - retval =acpiphp_eject_slot (slot->acpi_slot); -return retval; +return acpiphp_disable_and_eject_slot (slot->acpi_slot); }
drivers/pci/hotplug/acpiphp_glue.c +18 -32
84 lines not on this page · raw message
PATCH 21/30 ACPI / hotplug / PCI: Do not queue up event handling work items in vain
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Modify handle_hotplug_event() to avoid queing up the execution of handle_hotplug_event_work_fn() as a work item on kacpi_hotplug_wq for non-hotplug events, such as ACPI_NOTIFY_DEVICE_WAKE. Move the code printing diagnostic messages for those events into handle_hotplug_event().
In addition to that, remove the bogus comment about how the core should distinguish between hotplug and non-hotplug events and queue them up on different workqueues. The core clearly cannot know in advance what events will be interesting to the given caller of acpi_install_notify_handler().
--- drivers/pci/hotplug/acpiphp_glue.c | 64 ++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 35 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +29 -35
@@ -920,36 +920,11 @@ static void hotplug_event(acpi_handle habreak ; -case ACPI_NOTIFY_DEVICE_WAKE : -/* wake event */ -dbg ("%s: Device wake notify on %s\n" , __func__, objname); -break ; -case ACPI_NOTIFY_EJECT_REQUEST :/* request device eject */ dbg ("%s: Device eject notify on %s\n" , __func__, objname);acpiphp_disable_and_eject_slot (func->slot);break ; - -case ACPI_NOTIFY_FREQUENCY_MISMATCH : -printk (KERN_ERR "Device %s cannot be configured due" -" to a frequency mismatch\n" , objname); -break ; - -case ACPI_NOTIFY_BUS_MODE_MISMATCH : -printk (KERN_ERR "Device %s cannot be configured due" -" to a bus mode mismatch\n" , objname); -break ; - -case ACPI_NOTIFY_POWER_FAULT : -printk (KERN_ERR "Device %s has suffered a power fault\n" , - objname); -break ; - -default : -warn ("notify_handler: unknown event type 0x%x for %s\n" , type, - objname); -break ; }if (bridge)
@@ -984,23 +959,42 @@ static void handle_hotplug_event(acpi_ha {struct acpiphp_context *context; +switch (type) { +case ACPI_NOTIFY_BUS_CHECK : +case ACPI_NOTIFY_DEVICE_CHECK : +case ACPI_NOTIFY_EJECT_REQUEST : +break ; + +case ACPI_NOTIFY_DEVICE_WAKE : +return ; + +case ACPI_NOTIFY_FREQUENCY_MISMATCH : +acpi_handle_err (handle,"Device cannot be configured due " +"to a frequency mismatch\n" ); +return ; + +case ACPI_NOTIFY_BUS_MODE_MISMATCH : +acpi_handle_err (handle,"Device cannot be configured due " +"to a bus mode mismatch\n" ); +return ; + +case ACPI_NOTIFY_POWER_FAULT : +acpi_handle_err (handle,"Device has suffered a power fault\n" ); +return ; + +default : +acpi_handle_warn (handle,"Unsupported event type 0x%x\n" , type); +return ; + } +mutex_lock (&acpiphp_context_lock); context =acpiphp_get_context (handle);if (context) {get_bridge (context->func.parent);acpiphp_put_context (context); +alloc_acpi_hp_work (handle, type, context, hotplug_event_work); }mutex_unlock (&acpiphp_context_lock); -/* -* Currently the code adds all hotplug events to the kacpid_wq -* queue when it should add hotplug events to the kacpi_hotplug_wq. -* The proper way to fix this is to reorganize the code so that -* drivers (dock, etc.) do not call acpi_os_execute(), etc. -* For now just re-add this work to the kacpi_hotplug_wq so we -* don't deadlock on hotplug actions. -*/ -if (context) -alloc_acpi_hp_work (handle, type, context, hotplug_event_work); }/*
PATCH 22/30 ACPI / hotplug / PCI: Do not exectute _PS0 and _PS3 directly
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The ACPI-based PCI hotplug (acpiphp) core code need not and really should not execute _PS0 and _PS3 directly for devices it handles.
First of all, it is not necessary to put devices into D3 after acpi_bus_trim() has walked through them, because acpi_device_unregister() invoked by it puts each device into D3cold before returning. Thus after disable_device() the slot should be powered down already.
Second, calling _PS0 directly on ACPI device objects may not be appropriate, because it may require power resources to be set up in a specific way in advance and that must be taken care of by the ACPI core. Thus modify acpiphp_bus_add() to power up the device using the appropriate interface after it has run acpi_bus_scan() on its handle.
After that, the functions executing _PS0 and _PS3, power_on_slot() and power_off_slot(), are not necessary any more, so drop them and update the code calling them accordingly. Also drop the function flags related to device power states, since they aren't useful any more too.
--- drivers/pci/hotplug/acpiphp.h | 7 -- drivers/pci/hotplug/acpiphp_glue.c | 106 +++---------------------------------- 2 files changed, 10 insertions(+), 103 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +9 -97
@@ -303,12 +303,6 @@ static acpi_status register_slot(acpi_haif (acpi_has_method (handle,"_STA" )) newfunc->flags |=FUNC_HAS_STA ; -if (acpi_has_method (handle,"_PS0" )) - newfunc->flags |=FUNC_HAS_PS0 ; - -if (acpi_has_method (handle,"_PS3" )) - newfunc->flags |=FUNC_HAS_PS3 ; -if (acpi_has_method (handle,"_DCK" )) newfunc->flags |=FUNC_HAS_DCK ;
@@ -366,7 +360,7 @@ static acpi_status register_slot(acpi_haif (pci_bus_read_dev_vendor_id (pbus,PCI_DEVFN (device, function), &val,60 *1000 )) - slot->flags |= (SLOT_ENABLED |SLOT_POWEREDON ); + slot->flags |=SLOT_ENABLED ;if (is_dock_device (handle)) {/* we don't want to call this device's _EJ0
@@ -446,73 +440,6 @@ static void cleanup_bridge(struct acpiphmutex_unlock (&bridge_mutex); } -static int power_on_slot (struct acpiphp_slot *slot) -{ -acpi_status status; -struct acpiphp_func *func; -int retval =0 ; - -/* if already enabled, just skip */ -if (slot->flags &SLOT_POWEREDON ) - goto err_exit; - -list_for_each_entry (func, &slot->funcs, sibling) { -if (func->flags &FUNC_HAS_PS0 ) { -dbg ("%s: executing _PS0\n" , __func__); - status =acpi_evaluate_object (func_to_handle (func), -"_PS0" ,NULL ,NULL ); -if (ACPI_FAILURE (status)) { -warn ("%s: _PS0 failed\n" , __func__); - retval =-1 ; - goto err_exit; - }else -break ; - } - } - -/* TBD: evaluate _STA to check if the slot is enabled */ - - slot->flags |=SLOT_POWEREDON ; - - err_exit: -return retval; -} - - -static int power_off_slot (struct acpiphp_slot *slot) -{ -acpi_status status; -struct acpiphp_func *func; - -int retval =0 ; - -/* if already disabled, just skip */ -if ((slot->flags &SLOT_POWEREDON ) ==0 ) - goto err_exit; - -list_for_each_entry (func, &slot->funcs, sibling) { -if (func->flags &FUNC_HAS_PS3 ) { - status =acpi_evaluate_object (func_to_handle (func), -"_PS3" ,NULL ,NULL ); -if (ACPI_FAILURE (status)) { -warn ("%s: _PS3 failed\n" , __func__); - retval =-1 ; - goto err_exit; - }else -break ; - } - } - -/* TBD: evaluate _STA to check if the slot is disabled */ - - slot->flags &= (~SLOT_POWEREDON ); - - err_exit: -return retval; -} - - -/** * acpiphp_max_busnr - return the highest reserved bus number under the given bus. * @bus: bus to start search with
@@ -559,8 +486,13 @@ static void acpiphp_bus_trim(acpi_handle*/ static void acpiphp_bus_add (acpi_handle handle) { +struct acpi_device *adev =NULL ; +acpiphp_bus_trim (handle);acpi_bus_scan (handle); +acpi_bus_get_device (handle, &adev); +if (adev) +acpi_device_set_power (adev,ACPI_STATE_D0 ); }static void acpiphp_set_acpi_region (struct acpiphp_slot *slot)
@@ -1095,23 +1027,8 @@ int acpiphp_enable_slot(struct acpiphp_sint retval;mutex_lock (&slot->crit_sect); - -/* wake up all functions */ - retval =power_on_slot (slot); -if (retval) - goto err_exit; - -if (get_slot_status (slot) ==ACPI_STA_ALL ) { -/* configure all functions */ - retval =enable_device (slot); -if (retval) -power_off_slot (slot); - }else { -dbg ("%s: Slot status is not ACPI_STA_ALL\n" , __func__); -power_off_slot (slot); - } - - err_exit: +/* configure all functions */ + retval =enable_device (slot);mutex_unlock (&slot->crit_sect);return retval; }
@@ -1132,11 +1049,6 @@ int acpiphp_disable_and_eject_slot(strucif (retval) goto err_exit; -/* power off all functions */ - retval =power_off_slot (slot); -if (retval) - goto err_exit; -list_for_each_entry (func, &slot->funcs, sibling)if (func->flags &FUNC_HAS_EJ0 ) {acpi_handle handle =func_to_handle (func);
@@ -1159,7 +1071,7 @@ int acpiphp_disable_and_eject_slot(struc*/ u8 acpiphp_get_power_status (struct acpiphp_slot *slot) { -return (slot->flags &SLOT_POWEREDON ); +return (slot->flags &SLOT_ENABLED ); }
drivers/pci/hotplug/acpiphp.h +1 -6
@@ -162,7 +162,6 @@ struct acpiphp_attention_info/* slot flags */ -#define SLOT_POWEREDON (0x00000001)#define SLOT_ENABLED (0x00000002)#define SLOT_MULTIFUNCTION (0x00000004)
@@ -170,11 +169,7 @@ struct acpiphp_attention_info#define FUNC_HAS_STA (0x00000001)#define FUNC_HAS_EJ0 (0x00000002) -#define FUNC_HAS_PS0 (0x00000010) -#define FUNC_HAS_PS1 (0x00000020) -#define FUNC_HAS_PS2 (0x00000040) -#define FUNC_HAS_PS3 (0x00000080) -#define FUNC_HAS_DCK (0x00000100) +#define FUNC_HAS_DCK (0x00000004)/* function prototypes */
PATCH 23/30 ACPI / hotplug / PCI: Do not check SLOT_ENABLED in enable_device()
In reply to Rafael J. WysockiFrom: Kirill A. Shutemov <[email protected]>
With Thunderbolt you can daisy chain devices: connect new devices to an already plugged one. In that case the "hotplug slot" is already enabled, but we still want to look for new PCI devices behind it.
Reuse enable_device() to scan for new PCI devices on enabled slots and push the SLOT_ENABLED check up into acpiphp_enable_slot().
---drivers/pci/hotplug/acpiphp_glue.c | 5 ++---
drivers/pci/hotplug/acpiphp_glue.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +5 -5
@@ -545,9 +545,6 @@ static int __ref enable_device(struct acint num, max, pass;LIST_HEAD (add_list); -if (slot->flags &SLOT_ENABLED ) - goto err_exit; -list_for_each_entry (func, &slot->funcs, sibling)acpiphp_bus_add (func_to_handle (func));
@@ -1024,11 +1021,14 @@ void acpiphp_remove_slots(struct pci_bus*/ int acpiphp_enable_slot (struct acpiphp_slot *slot) { -int retval; +int retval =0 ;mutex_lock (&slot->crit_sect); +/* configure all functions */ - retval =enable_device (slot); +if (!(slot->flags &SLOT_ENABLED )) + retval =enable_device (slot); +mutex_unlock (&slot->crit_sect);return retval; }
PATCH 24/30 ACPI / hotplug / PCI: Allow slots without new devices to be rescanned
In reply to Rafael J. WysockiFrom: Kirill A. Shutemov <[email protected]>
Currently, enable_device() checks the return value of pci_scan_slot() and returns immediately if that's 0 (meaning that no new functions have been found in the slot). However, if one of the functions in the slot is a bridge, some new devices may appear below it even if the bridge itself is present continuously, so it generally is necessary to do the rescan anyway just in case. [In particular, that's necessary with the Thunderbolt daisy chaining in which case new devices may be connected to the existing ones down the chain.]
The correctness of this change relies on the ability of pcibios_resource_survey_bus() to detect if it has already been called for the given bus and to skip it if so. Failure to do that will lead to resource allocation conflicts.
---drivers/pci/hotplug/acpiphp_glue.c | 11 ++---------
drivers/pci/hotplug/acpiphp_glue.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +2 -9
@@ -542,18 +542,13 @@ static int __ref enable_device(struct acstruct pci_dev *dev;struct pci_bus *bus = slot->bus;struct acpiphp_func *func; -int num, max, pass; +int max, pass;LIST_HEAD (add_list);list_for_each_entry (func, &slot->funcs, sibling)acpiphp_bus_add (func_to_handle (func)); - num =pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); -if (num ==0 ) { -/* Maybe only part of funcs are added. */ -dbg ("No new device found\n" ); - goto err_exit; - } +pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); max =acpiphp_max_busnr (bus);for (pass =0 ; pass <2 ; pass++) {
@@ -599,8 +594,6 @@ static int __ref enable_device(struct ac } } - - err_exit:return 0 ; }
PATCH 25/30 ACPI / hotplug / PCI: Check for new devices on enabled slots
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The current implementation of acpiphp_check_bridge() is pretty dumb:
- It enables a slot if it's not enabled and the slot status is ACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is not ACPI_STA_ALL.
This behavior is not sufficient to handle the Thunderbolt daisy chaining case properly, however, because in that case the bus behind the already enabled slot needs to be rescanned for new devices.
For this reason, modify acpiphp_check_bridge() so that slots are disabled and stopped if they are not in the ACPI_STA_ALL state.
For slots in the ACPI_STA_ALL state, devices behind them that don't respond are trimmed using a new function, trim_stale_devices(), introduced specifically for this purpose. That function walks the given bus and checks each device on it. If the device doesn't respond, it is assumed to be gone and is removed.
Once all of the stale devices directy behind the slot have been removed, acpiphp_check_bridge() will start looking for new devices that might have appeared on the given bus. It will do that even if the slot is already enabled (SLOT_ENABLED is set for it).
In addition to that, make the bus check notification ignore SLOT_ENABLED and go for enable_device() directly if bridge is NULL, so that devices behind the slot are re-enumerated in that case too.
This change is based on earlier patches from Kirill A Shutemov and Mika Westerberg.
--- drivers/pci/hotplug/acpiphp_glue.c | 87 +++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 27 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +60 -27
@@ -46,6 +46,7 @@#include <linux/pci.h> #include <linux/pci_hotplug.h> #include <linux/pci-acpi.h> +#include <linux/pm_runtime.h> #include <linux/mutex.h> #include <linux/slab.h> #include <linux/acpi.h>
@@ -687,47 +688,75 @@ static unsigned int get_slot_status(stru }/** +* trim_stale_devices - remove PCI devices that are not responding. +* @dev: PCI device to start walking the hierarchy from. +*/ +static void trim_stale_devices (struct pci_dev *dev) +{ +acpi_handle handle =ACPI_HANDLE (&dev->dev); +struct pci_bus *bus = dev->subordinate; +bool alive = false; + +if (handle) { +acpi_status status; +unsigned long long sta; + + status =acpi_evaluate_integer (handle,"_STA" ,NULL , &sta); + alive =ACPI_SUCCESS (status) && sta ==ACPI_STA_ALL ; + } +if (!alive) { +u32 v; + +/* Check if the device responds. */ + alive =pci_bus_read_dev_vendor_id (dev->bus, dev->devfn, &v,0 ); + } +if (!alive) { +pci_stop_and_remove_bus_device (dev); +if (handle) +acpiphp_bus_trim (handle); + }else if (bus) { +struct pci_dev *child, *tmp; + +/* The device is a bridge. so check the bus below it. */ +pm_runtime_get_sync (&dev->dev); +list_for_each_entry_safe (child, tmp, &bus->devices, bus_list) +trim_stale_devices (child); + +pm_runtime_put (&dev->dev); + } +} + +/** * acpiphp_check_bridge - re-enumerate devices * @bridge: where to begin re-enumeration * * Iterate over all slots under this bridge and make sure that if a * card is present they are enabled, and if not they are disabled. */ -static int acpiphp_check_bridge (struct acpiphp_bridge *bridge) +static void acpiphp_check_bridge (struct acpiphp_bridge *bridge) {struct acpiphp_slot *slot; -int retval =0 ; -int enabled, disabled; - - enabled = disabled =0 ;list_for_each_entry (slot, &bridge->slots, node) { -unsigned int status =get_slot_status (slot); -if (slot->flags &SLOT_ENABLED ) { -if (status ==ACPI_STA_ALL ) -continue ; +struct pci_bus *bus = slot->bus; +struct pci_dev *dev, *tmp; - retval =acpiphp_disable_and_eject_slot (slot); -if (retval) - goto err_exit; +mutex_lock (&slot->crit_sect); +/* wake up all functions */ +if (get_slot_status (slot) ==ACPI_STA_ALL ) { +/* remove stale devices if any */ +list_for_each_entry_safe (dev, tmp, &bus->devices, + bus_list) +if (PCI_SLOT (dev->devfn) == slot->device) +trim_stale_devices (dev); - disabled++; +/* configure all functions */ +enable_device (slot); }else { -if (status !=ACPI_STA_ALL ) -continue ; - retval =acpiphp_enable_slot (slot); -if (retval) { -err ("Error occurred in enabling\n" ); - goto err_exit; - } - enabled++; +disable_device (slot); } +mutex_unlock (&slot->crit_sect); } - -dbg ("%s: %d enabled, %d disabled\n" , __func__, enabled, disabled); - - err_exit: -return retval; }static void acpiphp_set_hpp_values (struct pci_bus *bus)
@@ -828,7 +857,11 @@ static void hotplug_event(acpi_handle haACPI_UINT32_MAX , check_sub_bridges, NULL, NULL, NULL); }else { -acpiphp_enable_slot (func->slot); +struct acpiphp_slot *slot = func->slot; + +mutex_lock (&slot->crit_sect); +enable_device (slot); +mutex_unlock (&slot->crit_sect); }break ;
Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots
Quoted 31 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The current implementation of
acpiphp_check_bridge()is pretty dumb:
- It enables a slot if it's not enabled and the slot status isACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is notACPI_STA_ALL.This behavior is not sufficient to handle the Thunderbolt daisy chaining case properly, however, because in that case the bus behind the already enabled slot needs to be rescanned for new devices.
For this reason, modify
acpiphp_check_bridge()so that slots are disabled and stopped if they are not in theACPI_STA_ALLstate.For slots in the
ACPI_STA_ALLstate, devices behind them that don't respond are trimmed using a new function,trim_stale_devices(), introduced specifically for this purpose. That function walks the given bus and checks each device on it. If the device doesn't respond, it is assumed to be gone and is removed.Once all of the stale devices directy behind the slot have been removed,
acpiphp_check_bridge()will start looking for new devices that might have appeared on the given bus. It will do that even if the slot is already enabled (SLOT_ENABLEDis set for it).In addition to that, make the bus check notification ignore
SLOT_ENABLEDand go forenable_device()directly if bridge is NULL, so that devices behind the slot are re-enumerated in that case too.
Quoted 6 lines
This change is based on earlier patches from Kirill A Shutemov and Mika Westerberg.
Signed-off-by Rafael J. Wysocki <[email protected]>Tested-by Mika Westerberg <[email protected]>---
FYI, git bisect landed on this patch as the cause of my serial console dying on current upstream. Further debugging to come... Thanks,
Alex
Quoted 135 lines
drivers/pci/hotplug/acpiphp_glue.c | 87 +++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 27 deletions(-)Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c +60
-28@@ -46,6 +46,7 @@#include <linux/pci.h> #include <linux/pci_hotplug.h> #include <linux/pci-acpi.h> +#include <linux/pm_runtime.h> #include <linux/mutex.h> #include <linux/slab.h> #include <linux/acpi.h> @@ -687,47 +688,75 @@ static unsigned int get_slot_status(stru }/** +* trim_stale_devices - remove PCI devices that are not responding. +* @dev: PCI device to start walking the hierarchy from. +*/ +static void trim_stale_devices (struct pci_dev *dev) +{ +acpi_handle handle =ACPI_HANDLE (&dev->dev); +struct pci_bus *bus = dev->subordinate; +bool alive = false; + +if (handle) { +acpi_status status; +unsigned long long sta; + + status =acpi_evaluate_integer (handle,"_STA" ,NULL , &sta); + alive =ACPI_SUCCESS (status) && sta ==ACPI_STA_ALL ; + } +if (!alive) { +u32 v; + +/* Check if the device responds. */ + alive =pci_bus_read_dev_vendor_id (dev->bus, dev->devfn, &v,0 ); + } +if (!alive) { +pci_stop_and_remove_bus_device (dev); +if (handle) +acpiphp_bus_trim (handle); + }else if (bus) { +struct pci_dev *child, *tmp; + +/* The device is a bridge. so check the bus below it. */ +pm_runtime_get_sync (&dev->dev); +list_for_each_entry_safe (child, tmp, &bus->devices, bus_list) +trim_stale_devices (child); + +pm_runtime_put (&dev->dev); + } +} + +/** * acpiphp_check_bridge - re-enumerate devices * @bridge: where to begin re-enumeration * * Iterate over all slots under this bridge and make sure that if a * card is present they are enabled, and if not they are disabled. */ -static int acpiphp_check_bridge (struct acpiphp_bridge *bridge) +static void acpiphp_check_bridge (struct acpiphp_bridge *bridge) {struct acpiphp_slot *slot; -int retval =0 ; -int enabled, disabled; - - enabled = disabled =0 ;list_for_each_entry (slot, &bridge->slots, node) { -unsigned int status =get_slot_status (slot); -if (slot->flags &SLOT_ENABLED ) { -if (status ==ACPI_STA_ALL ) -continue ; +struct pci_bus *bus = slot->bus; +struct pci_dev *dev, *tmp; - retval =acpiphp_disable_and_eject_slot (slot); -if (retval) - goto err_exit; +mutex_lock (&slot->crit_sect); +/* wake up all functions */ +if (get_slot_status (slot) ==ACPI_STA_ALL ) { +/* remove stale devices if any */ +list_for_each_entry_safe (dev, tmp, &bus->devices, + bus_list) +if (PCI_SLOT (dev->devfn) == slot->device) +trim_stale_devices (dev); - disabled++; +/* configure all functions */ +enable_device (slot); }else { -if (status !=ACPI_STA_ALL ) -continue ; - retval =acpiphp_enable_slot (slot); -if (retval) { -err ("Error occurred in enabling\n" ); - goto err_exit; - } - enabled++; +disable_device (slot); } +mutex_unlock (&slot->crit_sect); } - -dbg ("%s: %d enabled, %d disabled\n" , __func__, enabled, disabled); - - err_exit: -return retval; }static void acpiphp_set_hpp_values (struct pci_bus *bus)@@ -828,7 +857,11 @@ static void hotplug_event(acpi_handle haACPI_UINT32_MAX , check_sub_bridges, NULL, NULL, NULL); }else { -acpiphp_enable_slot (func->slot); +struct acpiphp_slot *slot = func->slot; + +mutex_lock (&slot->crit_sect); +enable_device (slot); +mutex_unlock (&slot->crit_sect); }break ; --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 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots
Quoted 35 lines · Alex Williamson
Quoted 34 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The current implementation of
acpiphp_check_bridge()is pretty dumb:
- It enables a slot if it's not enabled and the slot status isACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is notACPI_STA_ALL.This behavior is not sufficient to handle the Thunderbolt daisy chaining case properly, however, because in that case the bus behind the already enabled slot needs to be rescanned for new devices.
For this reason, modify
acpiphp_check_bridge()so that slots are disabled and stopped if they are not in theACPI_STA_ALLstate.For slots in the
ACPI_STA_ALLstate, devices behind them that don't respond are trimmed using a new function,trim_stale_devices(), introduced specifically for this purpose. That function walks the given bus and checks each device on it. If the device doesn't respond, it is assumed to be gone and is removed.Once all of the stale devices directy behind the slot have been removed,
acpiphp_check_bridge()will start looking for new devices that might have appeared on the given bus. It will do that even if the slot is already enabled (SLOT_ENABLEDis set for it).In addition to that, make the bus check notification ignore
SLOT_ENABLEDand go forenable_device()directly if bridge is NULL, so that devices behind the slot are re-enumerated in that case too.This change is based on earlier patches from Kirill A Shutemov and Mika Westerberg.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Rafael J. Wysocki <[email protected]>Tested-by Mika Westerberg <[email protected]>---
FYI, git bisect landed on this patch as the cause of my serial console dying on current upstream. Further debugging to come... Thanks,
Well, sorry about that.
What exactly do you mean by "dying"?
Rafael
Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots
Quoted 40 lines · Rafael J. Wysocki
Quoted 39 lines · Alex Williamson
Quoted 37 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The current implementation of
acpiphp_check_bridge()is pretty dumb:
- It enables a slot if it's not enabled and the slot status isACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is notACPI_STA_ALL.This behavior is not sufficient to handle the Thunderbolt daisy chaining case properly, however, because in that case the bus behind the already enabled slot needs to be rescanned for new devices.
For this reason, modify
acpiphp_check_bridge()so that slots are disabled and stopped if they are not in theACPI_STA_ALLstate.For slots in the
ACPI_STA_ALLstate, devices behind them that don't respond are trimmed using a new function,trim_stale_devices(), introduced specifically for this purpose. That function walks the given bus and checks each device on it. If the device doesn't respond, it is assumed to be gone and is removed.Once all of the stale devices directy behind the slot have been removed,
acpiphp_check_bridge()will start looking for new devices that might have appeared on the given bus. It will do that even if the slot is already enabled (SLOT_ENABLEDis set for it).In addition to that, make the bus check notification ignore
SLOT_ENABLEDand go forenable_device()directly if bridge is NULL, so that devices behind the slot are re-enumerated in that case too.This change is based on earlier patches from Kirill A Shutemov and Mika Westerberg.
Signed-off-by Rafael J. Wysocki <[email protected]>Tested-by Mika Westerberg <[email protected]>---
Quoted 6 lines
Quoted 2 lines
FYI, git bisect landed on this patch as the cause of my serial console dying on current upstream. Further debugging to come... Thanks,
Well, sorry about that.
What exactly do you mean by "dying"?
Sorry, I was hoping to have more details quickly, but it's been a pain to debug. By dying I mean serial console output suddenly stops during kernel boot and nothing more comes out of it until after the system is rebooted. The problem happens when acpiphp_check_bridge() calls enable_slot(). The serial console dies somewhere down in acpiphp_bus_trim(). I think this is happening on the 00:1f ISA bridge, so there's a good chance the serial ports are described as somewhere under there. Thanks,
Alex
Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots
Quoted 48 lines · Alex Williamson
Quoted 40 lines · Rafael J. Wysocki
Quoted 39 lines · Alex Williamson
Quoted 37 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The current implementation of
acpiphp_check_bridge()is pretty dumb:
- It enables a slot if it's not enabled and the slot status isACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is notACPI_STA_ALL.This behavior is not sufficient to handle the Thunderbolt daisy chaining case properly, however, because in that case the bus behind the already enabled slot needs to be rescanned for new devices.
For this reason, modify
acpiphp_check_bridge()so that slots are disabled and stopped if they are not in theACPI_STA_ALLstate.For slots in the
ACPI_STA_ALLstate, devices behind them that don't respond are trimmed using a new function,trim_stale_devices(), introduced specifically for this purpose. That function walks the given bus and checks each device on it. If the device doesn't respond, it is assumed to be gone and is removed.Once all of the stale devices directy behind the slot have been removed,
acpiphp_check_bridge()will start looking for new devices that might have appeared on the given bus. It will do that even if the slot is already enabled (SLOT_ENABLEDis set for it).In addition to that, make the bus check notification ignore
SLOT_ENABLEDand go forenable_device()directly if bridge is NULL, so that devices behind the slot are re-enumerated in that case too.This change is based on earlier patches from Kirill A Shutemov and Mika Westerberg.
Signed-off-by Rafael J. Wysocki <[email protected]>Tested-by Mika Westerberg <[email protected]>---
Quoted 6 lines
Quoted 2 lines
FYI, git bisect landed on this patch as the cause of my serial console dying on current upstream. Further debugging to come... Thanks,
Well, sorry about that.
What exactly do you mean by "dying"?
Quoted 8 lines
Sorry, I was hoping to have more details quickly, but it's been a pain to debug. By dying I mean serial console output suddenly stops during kernel boot and nothing more comes out of it until after the system is rebooted. The problem happens when
acpiphp_check_bridge()callsenable_slot(). The serial console dies somewhere down inacpiphp_bus_trim(). I think this is happening on the 00:1f ISA bridge, so there's a good chance the serial ports are described as somewhere under there.
Can you please check if that is the acpiphp_bus_trim() called by acpiphp_bus_add() or the other one called from trim_stale_devices()?
Just add a dump_stack() or WARN_ON(1) to trim_stale_devices() next to the acpiphp_bus_trim() call and see if that triggers. I *think* it's the one in acpiphp_bus_add(), but it won't hurt to verify that.
Thanks,
Rafael
Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots
Quoted 58 lines · Rafael J. Wysocki
Quoted 48 lines · Alex Williamson
Quoted 40 lines · Rafael J. Wysocki
Quoted 39 lines · Alex Williamson
Quoted 37 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The current implementation of
acpiphp_check_bridge()is pretty dumb:
- It enables a slot if it's not enabled and the slot status isACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is notACPI_STA_ALL.This behavior is not sufficient to handle the Thunderbolt daisy chaining case properly, however, because in that case the bus behind the already enabled slot needs to be rescanned for new devices.
For this reason, modify
acpiphp_check_bridge()so that slots are disabled and stopped if they are not in theACPI_STA_ALLstate.For slots in the
ACPI_STA_ALLstate, devices behind them that don't respond are trimmed using a new function,trim_stale_devices(), introduced specifically for this purpose. That function walks the given bus and checks each device on it. If the device doesn't respond, it is assumed to be gone and is removed.Once all of the stale devices directy behind the slot have been removed,
acpiphp_check_bridge()will start looking for new devices that might have appeared on the given bus. It will do that even if the slot is already enabled (SLOT_ENABLEDis set for it).In addition to that, make the bus check notification ignore
SLOT_ENABLEDand go forenable_device()directly if bridge is NULL, so that devices behind the slot are re-enumerated in that case too.This change is based on earlier patches from Kirill A Shutemov and Mika Westerberg.
Signed-off-by Rafael J. Wysocki <[email protected]>Tested-by Mika Westerberg <[email protected]>---
Quoted 6 lines
Quoted 2 lines
FYI, git bisect landed on this patch as the cause of my serial console dying on current upstream. Further debugging to come... Thanks,
Well, sorry about that.
What exactly do you mean by "dying"?
Quoted 8 lines
Sorry, I was hoping to have more details quickly, but it's been a pain to debug. By dying I mean serial console output suddenly stops during kernel boot and nothing more comes out of it until after the system is rebooted. The problem happens when
acpiphp_check_bridge()callsenable_slot(). The serial console dies somewhere down inacpiphp_bus_trim(). I think this is happening on the 00:1f ISA bridge, so there's a good chance the serial ports are described as somewhere under there.
Quoted 6 lines
Can you please check if that is the
acpiphp_bus_trim()called byacpiphp_bus_add()or the other one called fromtrim_stale_devices()?Just add a
dump_stack()orWARN_ON(1)totrim_stale_devices()next to theacpiphp_bus_trim()call and see if that triggers. I *think* it's the one inacpiphp_bus_add(), but it won't hurt to verify that.
Here's the call path:
[ 16.120824] [<ffffffff81627e6c>] dump_stack+0x55/0x76 [ 16.125979] [<ffffffff8162132e>] enable_slot+0x4ee/0x5e0 [ 16.131396] [<ffffffff813418fb>] ? trim_stale_devices+0x5b/0xf0 [ 16.137420] [<ffffffff81341b35>] acpiphp_check_bridge+0xd5/0x110 [ 16.143531] [<ffffffff81342acb>] hotplug_event+0x16b/0x260 [ 16.149115] [<ffffffff81072cd9>] ? process_one_work+0x189/0x540 [ 16.155136] [<ffffffff81342bf0>] hotplug_event_work+0x30/0x70 [ 16.160978] [<ffffffff81072d3b>] process_one_work+0x1eb/0x540 [ 16.166819] [<ffffffff81072cd9>] ? process_one_work+0x189/0x540 [ 16.172836] [<ffffffff8107353c>] worker_thread+0x11c/0x370 [ 16.178426] [<ffffffff81073420>] ? rescuer_thread+0x350/0x350 [ 16.184276] [<ffffffff8107b0ea>] kthread+0xea/0xf0 [ 16.189165] [<ffffffff8107b000>] ? kthread_create_on_node+0x160/0x160 [ 16.195700] [<ffffffff816395dc>] ret_from_fork+0x7c/0xb0 [ 16.201109] [<ffffffff8107b000>] ? kthread_create_on_node+0x160/0x160
The actual death of the serial console occurs in acpi_device_set_power() called from:
enable_slot()
acpiphp_bus_add()
acpiphp_bus_trim()
acpi_bus_trim()
acpi_walk_namespace()
acpi_bus_remove()
acpi_device_unregister()
acpi_device_set_power()
I can't seem to get a path from the acpi devices in question there, so I have no idea what's getting trimmed here. It worries me quite a bit by introducing this trimming that apparently wasn't happening before though. Thanks,
Alex
Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots
Quoted 96 lines · Alex Williamson
Quoted 58 lines · Rafael J. Wysocki
Quoted 48 lines · Alex Williamson
Quoted 40 lines · Rafael J. Wysocki
Quoted 39 lines · Alex Williamson
Quoted 37 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The current implementation of
acpiphp_check_bridge()is pretty dumb:
- It enables a slot if it's not enabled and the slot status isACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is notACPI_STA_ALL.This behavior is not sufficient to handle the Thunderbolt daisy chaining case properly, however, because in that case the bus behind the already enabled slot needs to be rescanned for new devices.
For this reason, modify
acpiphp_check_bridge()so that slots are disabled and stopped if they are not in theACPI_STA_ALLstate.For slots in the
ACPI_STA_ALLstate, devices behind them that don't respond are trimmed using a new function,trim_stale_devices(), introduced specifically for this purpose. That function walks the given bus and checks each device on it. If the device doesn't respond, it is assumed to be gone and is removed.Once all of the stale devices directy behind the slot have been removed,
acpiphp_check_bridge()will start looking for new devices that might have appeared on the given bus. It will do that even if the slot is already enabled (SLOT_ENABLEDis set for it).In addition to that, make the bus check notification ignore
SLOT_ENABLEDand go forenable_device()directly if bridge is NULL, so that devices behind the slot are re-enumerated in that case too.This change is based on earlier patches from Kirill A Shutemov and Mika Westerberg.
Signed-off-by Rafael J. Wysocki <[email protected]>Tested-by Mika Westerberg <[email protected]>---
Quoted 6 lines
Quoted 2 lines
FYI, git bisect landed on this patch as the cause of my serial console dying on current upstream. Further debugging to come... Thanks,
Well, sorry about that.
What exactly do you mean by "dying"?
Quoted 8 lines
Sorry, I was hoping to have more details quickly, but it's been a pain to debug. By dying I mean serial console output suddenly stops during kernel boot and nothing more comes out of it until after the system is rebooted. The problem happens when
acpiphp_check_bridge()callsenable_slot(). The serial console dies somewhere down inacpiphp_bus_trim(). I think this is happening on the 00:1f ISA bridge, so there's a good chance the serial ports are described as somewhere under there.Quoted 6 lines
Can you please check if that is the
acpiphp_bus_trim()called byacpiphp_bus_add()or the other one called fromtrim_stale_devices()?Just add a
dump_stack()orWARN_ON(1)totrim_stale_devices()next to theacpiphp_bus_trim()call and see if that triggers. I *think* it's the one inacpiphp_bus_add(), but it won't hurt to verify that.Here's the call path:
[ 16.120824] [<ffffffff81627e6c>] dump_stack+0x55/0x76 [ 16.125979] [<ffffffff8162132e>] enable_slot+0x4ee/0x5e0 [ 16.131396] [<ffffffff813418fb>] ? trim_stale_devices+0x5b/0xf0 [ 16.137420] [<ffffffff81341b35>] acpiphp_check_bridge+0xd5/0x110 [ 16.143531] [<ffffffff81342acb>] hotplug_event+0x16b/0x260 [ 16.149115] [<ffffffff81072cd9>] ? process_one_work+0x189/0x540 [ 16.155136] [<ffffffff81342bf0>] hotplug_event_work+0x30/0x70 [ 16.160978] [<ffffffff81072d3b>] process_one_work+0x1eb/0x540 [ 16.166819] [<ffffffff81072cd9>] ? process_one_work+0x189/0x540 [ 16.172836] [<ffffffff8107353c>] worker_thread+0x11c/0x370 [ 16.178426] [<ffffffff81073420>] ? rescuer_thread+0x350/0x350 [ 16.184276] [<ffffffff8107b0ea>] kthread+0xea/0xf0 [ 16.189165] [<ffffffff8107b000>] ? kthread_create_on_node+0x160/0x160 [ 16.195700] [<ffffffff816395dc>] ret_from_fork+0x7c/0xb0 [ 16.201109] [<ffffffff8107b000>] ? kthread_create_on_node+0x160/0x160The actual death of the serial console occurs in
acpi_device_set_power()called from:
enable_slot()
acpiphp_bus_add()
acpiphp_bus_trim()
acpi_bus_trim()
acpi_walk_namespace()
acpi_bus_remove()
acpi_device_unregister()
acpi_device_set_power()
Quoted 4 lines
I can't seem to get a path from the acpi devices in question there, so I have no idea what's getting trimmed here. It worries me quite a bit by introducing this trimming that apparently wasn't happening before though. Thanks,
As suspected, the pnp.bus_id/id of the last device before the serial console dies is COM1/PNP0501. I also see all of these being trimmed out:
MBRD/PNP0C02
DMAC/PNP0200
MATH/PNP0C04
PIC/PNP0000
HPET/PNP0103
RTC/PNP0B00
SPKR/PNP0800
TIME/PNP0100
LNK{A-H}/PNP0C0F
This seems like a bad idea. I forgot to mention, the original hotplug_event is called with a device check on \_SB_.PCI0.PEX2. The box where I'm seeing this is a pretty generic X58 based Nehalem workstation (Lenovo S20). Thanks,
Alex
Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots
Quoted 116 lines · Alex Williamson
Quoted 96 lines · Alex Williamson
Quoted 58 lines · Rafael J. Wysocki
Quoted 48 lines · Alex Williamson
Quoted 40 lines · Rafael J. Wysocki
Quoted 39 lines · Alex Williamson
Quoted 37 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The current implementation of
acpiphp_check_bridge()is pretty dumb:
- It enables a slot if it's not enabled and the slot status isACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is notACPI_STA_ALL.This behavior is not sufficient to handle the Thunderbolt daisy chaining case properly, however, because in that case the bus behind the already enabled slot needs to be rescanned for new devices.
For this reason, modify
acpiphp_check_bridge()so that slots are disabled and stopped if they are not in theACPI_STA_ALLstate.For slots in the
ACPI_STA_ALLstate, devices behind them that don't respond are trimmed using a new function,trim_stale_devices(), introduced specifically for this purpose. That function walks the given bus and checks each device on it. If the device doesn't respond, it is assumed to be gone and is removed.Once all of the stale devices directy behind the slot have been removed,
acpiphp_check_bridge()will start looking for new devices that might have appeared on the given bus. It will do that even if the slot is already enabled (SLOT_ENABLEDis set for it).In addition to that, make the bus check notification ignore
SLOT_ENABLEDand go forenable_device()directly if bridge is NULL, so that devices behind the slot are re-enumerated in that case too.This change is based on earlier patches from Kirill A Shutemov and Mika Westerberg.
Signed-off-by Rafael J. Wysocki <[email protected]>Tested-by Mika Westerberg <[email protected]>---
Quoted 6 lines
Quoted 2 lines
FYI, git bisect landed on this patch as the cause of my serial console dying on current upstream. Further debugging to come... Thanks,
Well, sorry about that.
What exactly do you mean by "dying"?
Quoted 8 lines
Sorry, I was hoping to have more details quickly, but it's been a pain to debug. By dying I mean serial console output suddenly stops during kernel boot and nothing more comes out of it until after the system is rebooted. The problem happens when
acpiphp_check_bridge()callsenable_slot(). The serial console dies somewhere down inacpiphp_bus_trim(). I think this is happening on the 00:1f ISA bridge, so there's a good chance the serial ports are described as somewhere under there.Quoted 6 lines
Can you please check if that is the
acpiphp_bus_trim()called byacpiphp_bus_add()or the other one called fromtrim_stale_devices()?Just add a
dump_stack()orWARN_ON(1)totrim_stale_devices()next to theacpiphp_bus_trim()call and see if that triggers. I *think* it's the one inacpiphp_bus_add(), but it won't hurt to verify that.Here's the call path:
[ 16.120824] [<ffffffff81627e6c>] dump_stack+0x55/0x76 [ 16.125979] [<ffffffff8162132e>] enable_slot+0x4ee/0x5e0 [ 16.131396] [<ffffffff813418fb>] ? trim_stale_devices+0x5b/0xf0 [ 16.137420] [<ffffffff81341b35>] acpiphp_check_bridge+0xd5/0x110 [ 16.143531] [<ffffffff81342acb>] hotplug_event+0x16b/0x260 [ 16.149115] [<ffffffff81072cd9>] ? process_one_work+0x189/0x540 [ 16.155136] [<ffffffff81342bf0>] hotplug_event_work+0x30/0x70 [ 16.160978] [<ffffffff81072d3b>] process_one_work+0x1eb/0x540 [ 16.166819] [<ffffffff81072cd9>] ? process_one_work+0x189/0x540 [ 16.172836] [<ffffffff8107353c>] worker_thread+0x11c/0x370 [ 16.178426] [<ffffffff81073420>] ? rescuer_thread+0x350/0x350 [ 16.184276] [<ffffffff8107b0ea>] kthread+0xea/0xf0 [ 16.189165] [<ffffffff8107b000>] ? kthread_create_on_node+0x160/0x160 [ 16.195700] [<ffffffff816395dc>] ret_from_fork+0x7c/0xb0 [ 16.201109] [<ffffffff8107b000>] ? kthread_create_on_node+0x160/0x160The actual death of the serial console occurs in
acpi_device_set_power()called from:
enable_slot()
acpiphp_bus_add()
acpiphp_bus_trim()
acpi_bus_trim()
acpi_walk_namespace()
acpi_bus_remove()
acpi_device_unregister()
acpi_device_set_power()Quoted 4 lines
I can't seem to get a path from the acpi devices in question there, so I have no idea what's getting trimmed here. It worries me quite a bit by introducing this trimming that apparently wasn't happening before though. Thanks,
As suspected, the pnp.bus_id/id of the last device before the serial console dies is COM1/PNP0501. I also see all of these being trimmed out:
MBRD/PNP0C02
DMAC/PNP0200
MATH/PNP0C04
PIC/PNP0000
HPET/PNP0103
RTC/PNP0B00
SPKR/PNP0800
TIME/PNP0100
LNK{A-H}/PNP0C0F
Quoted 4 lines
This seems like a bad idea. I forgot to mention, the original
hotplug_eventis called with a device check on \_SB_.PCI0.PEX2. The box where I'm seeing this is a pretty generic X58 based Nehalem workstation (Lenovo S20).
Thanks for the info!
The acpiphp_bus_trim() in acpiphp_bus_add() is a leftover and a bad one. I don't think it's actually necessary, at least Thunderbolt works without it just fine on my Aspire S5.
The patch below should help, can you please test it?
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: ACPI / hotplug / PCI: Don't trim devices before scanning the namespace
In acpiphp_bus_add() we first remove device objects corresponding to the given handle and the ACPI namespace branch below it which are then re-created by acpi_bus_scan(). This used to be done to clean up after surprise removals, but now we do the cleanup through trim_stale_devices() which checks if the devices in question are actually gone before removing them, so the device hierarchy trimming in acpiphp_bus_add() is not necessary any more and, moreover, it may lead to problems if it removes device objects corresponding to devices that are actually present.
--- drivers/pci/hotplug/acpiphp_glue.c | 1 - 1 file changed, 1 deletion(-)
drivers/pci/hotplug/acpiphp_glue.c +0 -1
@@ -487,7 +487,6 @@ static void acpiphp_bus_add(acpi_handle {struct acpi_device *adev =NULL ; -acpiphp_bus_trim (handle);acpi_bus_scan (handle);acpi_bus_get_device (handle, &adev);if (adev)
Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots
Quoted 159 lines · Rafael J. Wysocki
Quoted 116 lines · Alex Williamson
Quoted 96 lines · Alex Williamson
Quoted 58 lines · Rafael J. Wysocki
Quoted 48 lines · Alex Williamson
Quoted 40 lines · Rafael J. Wysocki
Quoted 39 lines · Alex Williamson
Quoted 37 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The current implementation of
acpiphp_check_bridge()is pretty dumb:
- It enables a slot if it's not enabled and the slot status isACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is notACPI_STA_ALL.This behavior is not sufficient to handle the Thunderbolt daisy chaining case properly, however, because in that case the bus behind the already enabled slot needs to be rescanned for new devices.
For this reason, modify
acpiphp_check_bridge()so that slots are disabled and stopped if they are not in theACPI_STA_ALLstate.For slots in the
ACPI_STA_ALLstate, devices behind them that don't respond are trimmed using a new function,trim_stale_devices(), introduced specifically for this purpose. That function walks the given bus and checks each device on it. If the device doesn't respond, it is assumed to be gone and is removed.Once all of the stale devices directy behind the slot have been removed,
acpiphp_check_bridge()will start looking for new devices that might have appeared on the given bus. It will do that even if the slot is already enabled (SLOT_ENABLEDis set for it).In addition to that, make the bus check notification ignore
SLOT_ENABLEDand go forenable_device()directly if bridge is NULL, so that devices behind the slot are re-enumerated in that case too.This change is based on earlier patches from Kirill A Shutemov and Mika Westerberg.
Signed-off-by Rafael J. Wysocki <[email protected]>Tested-by Mika Westerberg <[email protected]>---
Quoted 6 lines
Quoted 2 lines
FYI, git bisect landed on this patch as the cause of my serial console dying on current upstream. Further debugging to come... Thanks,
Well, sorry about that.
What exactly do you mean by "dying"?
Quoted 8 lines
Sorry, I was hoping to have more details quickly, but it's been a pain to debug. By dying I mean serial console output suddenly stops during kernel boot and nothing more comes out of it until after the system is rebooted. The problem happens when
acpiphp_check_bridge()callsenable_slot(). The serial console dies somewhere down inacpiphp_bus_trim(). I think this is happening on the 00:1f ISA bridge, so there's a good chance the serial ports are described as somewhere under there.Quoted 6 lines
Can you please check if that is the
acpiphp_bus_trim()called byacpiphp_bus_add()or the other one called fromtrim_stale_devices()?Just add a
dump_stack()orWARN_ON(1)totrim_stale_devices()next to theacpiphp_bus_trim()call and see if that triggers. I *think* it's the one inacpiphp_bus_add(), but it won't hurt to verify that.Here's the call path:
[ 16.120824] [<ffffffff81627e6c>] dump_stack+0x55/0x76 [ 16.125979] [<ffffffff8162132e>] enable_slot+0x4ee/0x5e0 [ 16.131396] [<ffffffff813418fb>] ? trim_stale_devices+0x5b/0xf0 [ 16.137420] [<ffffffff81341b35>] acpiphp_check_bridge+0xd5/0x110 [ 16.143531] [<ffffffff81342acb>] hotplug_event+0x16b/0x260 [ 16.149115] [<ffffffff81072cd9>] ? process_one_work+0x189/0x540 [ 16.155136] [<ffffffff81342bf0>] hotplug_event_work+0x30/0x70 [ 16.160978] [<ffffffff81072d3b>] process_one_work+0x1eb/0x540 [ 16.166819] [<ffffffff81072cd9>] ? process_one_work+0x189/0x540 [ 16.172836] [<ffffffff8107353c>] worker_thread+0x11c/0x370 [ 16.178426] [<ffffffff81073420>] ? rescuer_thread+0x350/0x350 [ 16.184276] [<ffffffff8107b0ea>] kthread+0xea/0xf0 [ 16.189165] [<ffffffff8107b000>] ? kthread_create_on_node+0x160/0x160 [ 16.195700] [<ffffffff816395dc>] ret_from_fork+0x7c/0xb0 [ 16.201109] [<ffffffff8107b000>] ? kthread_create_on_node+0x160/0x160The actual death of the serial console occurs in
acpi_device_set_power()called from:
enable_slot()
acpiphp_bus_add()
acpiphp_bus_trim()
acpi_bus_trim()
acpi_walk_namespace()
acpi_bus_remove()
acpi_device_unregister()
acpi_device_set_power()Quoted 4 lines
I can't seem to get a path from the acpi devices in question there, so I have no idea what's getting trimmed here. It worries me quite a bit by introducing this trimming that apparently wasn't happening before though. Thanks,
As suspected, the pnp.bus_id/id of the last device before the serial console dies is COM1/PNP0501. I also see all of these being trimmed out:
MBRD/PNP0C02
DMAC/PNP0200
MATH/PNP0C04
PIC/PNP0000
HPET/PNP0103
RTC/PNP0B00
SPKR/PNP0800
TIME/PNP0100
LNK{A-H}/PNP0C0FQuoted 4 lines
This seems like a bad idea. I forgot to mention, the original
hotplug_eventis called with a device check on \_SB_.PCI0.PEX2. The box where I'm seeing this is a pretty generic X58 based Nehalem workstation (Lenovo S20).Thanks for the info!
The
acpiphp_bus_trim()inacpiphp_bus_add()is a leftover and a bad one. I don't think it's actually necessary, at least Thunderbolt works without it just fine on my Aspire S5.The patch below should help, can you please test it?
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: ACPI / hotplug / PCI: Don't trim devices before scanning the namespaceIn
acpiphp_bus_add()we first remove device objects corresponding to the given handle and the ACPI namespace branch below it which are then re-created byacpi_bus_scan(). This used to be done to clean up after surprise removals, but now we do the cleanup throughtrim_stale_devices()which checks if the devices in question are actually gone before removing them, so the device hierarchy trimming inacpiphp_bus_add()is not necessary any more and, moreover, it may lead to problems if it removes device objects corresponding to devices that are actually present.Reported-by Alex Williamson <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/pci/hotplug/acpiphp_glue.c | 1 - 1 file changed, 1 deletion(-)Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================
drivers/pci/hotplug/acpiphp_glue.c static void acpiphp_bus_add(acpi_handle · line 492
Quoted 7 lines
drivers/pci/hotplug/acpiphp_glue.c +0
-1@@ -487,7 +487,6 @@ static void acpiphp_bus_add(acpi_handle {struct acpi_device *adev =NULL ; -acpiphp_bus_trim (handle);acpi_bus_scan (handle);acpi_bus_get_device (handle, &adev);if (adev)
It boots again and the console works, but I see screens and screens of messages like this:
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settings
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation? Thanks,
Alex
Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots
Quoted 211 lines · Alex Williamson
Quoted 159 lines · Rafael J. Wysocki
Quoted 116 lines · Alex Williamson
Quoted 96 lines · Alex Williamson
Quoted 58 lines · Rafael J. Wysocki
Quoted 48 lines · Alex Williamson
Quoted 40 lines · Rafael J. Wysocki
Quoted 39 lines · Alex Williamson
Quoted 37 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The current implementation of
acpiphp_check_bridge()is pretty dumb:
- It enables a slot if it's not enabled and the slot status isACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is notACPI_STA_ALL.This behavior is not sufficient to handle the Thunderbolt daisy chaining case properly, however, because in that case the bus behind the already enabled slot needs to be rescanned for new devices.
For this reason, modify
acpiphp_check_bridge()so that slots are disabled and stopped if they are not in theACPI_STA_ALLstate.For slots in the
ACPI_STA_ALLstate, devices behind them that don't respond are trimmed using a new function,trim_stale_devices(), introduced specifically for this purpose. That function walks the given bus and checks each device on it. If the device doesn't respond, it is assumed to be gone and is removed.Once all of the stale devices directy behind the slot have been removed,
acpiphp_check_bridge()will start looking for new devices that might have appeared on the given bus. It will do that even if the slot is already enabled (SLOT_ENABLEDis set for it).In addition to that, make the bus check notification ignore
SLOT_ENABLEDand go forenable_device()directly if bridge is NULL, so that devices behind the slot are re-enumerated in that case too.This change is based on earlier patches from Kirill A Shutemov and Mika Westerberg.
Signed-off-by Rafael J. Wysocki <[email protected]>Tested-by Mika Westerberg <[email protected]>---
Quoted 6 lines
Quoted 2 lines
FYI, git bisect landed on this patch as the cause of my serial console dying on current upstream. Further debugging to come... Thanks,
Well, sorry about that.
What exactly do you mean by "dying"?
Quoted 8 lines
Sorry, I was hoping to have more details quickly, but it's been a pain to debug. By dying I mean serial console output suddenly stops during kernel boot and nothing more comes out of it until after the system is rebooted. The problem happens when
acpiphp_check_bridge()callsenable_slot(). The serial console dies somewhere down inacpiphp_bus_trim(). I think this is happening on the 00:1f ISA bridge, so there's a good chance the serial ports are described as somewhere under there.Quoted 6 lines
Can you please check if that is the
acpiphp_bus_trim()called byacpiphp_bus_add()or the other one called fromtrim_stale_devices()?Just add a
dump_stack()orWARN_ON(1)totrim_stale_devices()next to theacpiphp_bus_trim()call and see if that triggers. I *think* it's the one inacpiphp_bus_add(), but it won't hurt to verify that.Here's the call path:
[ 16.120824] [<ffffffff81627e6c>] dump_stack+0x55/0x76 [ 16.125979] [<ffffffff8162132e>] enable_slot+0x4ee/0x5e0 [ 16.131396] [<ffffffff813418fb>] ? trim_stale_devices+0x5b/0xf0 [ 16.137420] [<ffffffff81341b35>] acpiphp_check_bridge+0xd5/0x110 [ 16.143531] [<ffffffff81342acb>] hotplug_event+0x16b/0x260 [ 16.149115] [<ffffffff81072cd9>] ? process_one_work+0x189/0x540 [ 16.155136] [<ffffffff81342bf0>] hotplug_event_work+0x30/0x70 [ 16.160978] [<ffffffff81072d3b>] process_one_work+0x1eb/0x540 [ 16.166819] [<ffffffff81072cd9>] ? process_one_work+0x189/0x540 [ 16.172836] [<ffffffff8107353c>] worker_thread+0x11c/0x370 [ 16.178426] [<ffffffff81073420>] ? rescuer_thread+0x350/0x350 [ 16.184276] [<ffffffff8107b0ea>] kthread+0xea/0xf0 [ 16.189165] [<ffffffff8107b000>] ? kthread_create_on_node+0x160/0x160 [ 16.195700] [<ffffffff816395dc>] ret_from_fork+0x7c/0xb0 [ 16.201109] [<ffffffff8107b000>] ? kthread_create_on_node+0x160/0x160The actual death of the serial console occurs in
acpi_device_set_power()called from:
enable_slot()
acpiphp_bus_add()
acpiphp_bus_trim()
acpi_bus_trim()
acpi_walk_namespace()
acpi_bus_remove()
acpi_device_unregister()
acpi_device_set_power()Quoted 4 lines
I can't seem to get a path from the acpi devices in question there, so I have no idea what's getting trimmed here. It worries me quite a bit by introducing this trimming that apparently wasn't happening before though. Thanks,
As suspected, the pnp.bus_id/id of the last device before the serial console dies is COM1/PNP0501. I also see all of these being trimmed out:
MBRD/PNP0C02
DMAC/PNP0200
MATH/PNP0C04
PIC/PNP0000
HPET/PNP0103
RTC/PNP0B00
SPKR/PNP0800
TIME/PNP0100
LNK{A-H}/PNP0C0FQuoted 4 lines
This seems like a bad idea. I forgot to mention, the original
hotplug_eventis called with a device check on \_SB_.PCI0.PEX2. The box where I'm seeing this is a pretty generic X58 based Nehalem workstation (Lenovo S20).Thanks for the info!
The
acpiphp_bus_trim()inacpiphp_bus_add()is a leftover and a bad one. I don't think it's actually necessary, at least Thunderbolt works without it just fine on my Aspire S5.The patch below should help, can you please test it?
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: ACPI / hotplug / PCI: Don't trim devices before scanning the namespaceIn
acpiphp_bus_add()we first remove device objects corresponding to the given handle and the ACPI namespace branch below it which are then re-created byacpi_bus_scan(). This used to be done to clean up after surprise removals, but now we do the cleanup throughtrim_stale_devices()which checks if the devices in question are actually gone before removing them, so the device hierarchy trimming inacpiphp_bus_add()is not necessary any more and, moreover, it may lead to problems if it removes device objects corresponding to devices that are actually present.Reported-by Alex Williamson <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/pci/hotplug/acpiphp_glue.c | 1 - 1 file changed, 1 deletion(-)Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c static void acpiphp_bus_add(acpi_handle · line 492
Quoted 7 lines
drivers/pci/hotplug/acpiphp_glue.c +0
-1@@ -487,7 +487,6 @@ static void acpiphp_bus_add(acpi_handle {struct acpi_device *adev =NULL ; -acpiphp_bus_trim (handle);acpi_bus_scan (handle);acpi_bus_get_device (handle, &adev);if (adev)It boots again and the console works, but I see screens and screens of messages like this:
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settings
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y
$ dmesg | wc 5697 49935 384368
$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered
-- vs --
# CONFIG_HOTPLUG_PCI_ACPI is not set
$ dmesg | wc 1053 9176 71652
$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registered
So it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good. Thanks,
Alex
Excess dmesg output from ACPIPHP on boot (was: Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots)
Quoted 162 lines · Alex Williamson
Quoted 161 lines · Alex Williamson
Quoted 160 lines · Rafael J. Wysocki
Quoted 116 lines · Alex Williamson
Quoted 96 lines · Alex Williamson
Quoted 58 lines · Rafael J. Wysocki
Quoted 48 lines · Alex Williamson
Quoted 40 lines · Rafael J. Wysocki
Quoted 39 lines · Alex Williamson
Quoted 37 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The current implementation of
acpiphp_check_bridge()is pretty dumb:
- It enables a slot if it's not enabled and the slot status isACPI_STA_ALL.
- It disables a slot if it's enabled and the slot status is notACPI_STA_ALL.This behavior is not sufficient to handle the Thunderbolt daisy chaining case properly, however, because in that case the bus behind the already enabled slot needs to be rescanned for new devices.
For this reason, modify
acpiphp_check_bridge()so that slots are disabled and stopped if they are not in theACPI_STA_ALLstate.For slots in the
ACPI_STA_ALLstate, devices behind them that don't respond are trimmed using a new function,trim_stale_devices(), introduced specifically for this purpose. That function walks the given bus and checks each device on it. If the device doesn't respond, it is assumed to be gone and is removed.Once all of the stale devices directy behind the slot have been removed,
acpiphp_check_bridge()will start looking for new devices that might have appeared on the given bus. It will do that even if the slot is already enabled (SLOT_ENABLEDis set for it).In addition to that, make the bus check notification ignore
SLOT_ENABLEDand go forenable_device()directly if bridge is NULL, so that devices behind the slot are re-enumerated in that case too.This change is based on earlier patches from Kirill A Shutemov and Mika Westerberg.
Signed-off-by Rafael J. Wysocki <[email protected]>Tested-by Mika Westerberg <[email protected]>---
Quoted 6 lines
Quoted 2 lines
FYI, git bisect landed on this patch as the cause of my serial console dying on current upstream. Further debugging to come... Thanks,
Well, sorry about that.
What exactly do you mean by "dying"?
Quoted 8 lines
Sorry, I was hoping to have more details quickly, but it's been a pain to debug. By dying I mean serial console output suddenly stops during kernel boot and nothing more comes out of it until after the system is rebooted. The problem happens when
acpiphp_check_bridge()callsenable_slot(). The serial console dies somewhere down inacpiphp_bus_trim(). I think this is happening on the 00:1f ISA bridge, so there's a good chance the serial ports are described as somewhere under there.Quoted 6 lines
Can you please check if that is the
acpiphp_bus_trim()called byacpiphp_bus_add()or the other one called fromtrim_stale_devices()?Just add a
dump_stack()orWARN_ON(1)totrim_stale_devices()next to theacpiphp_bus_trim()call and see if that triggers. I *think* it's the one inacpiphp_bus_add(), but it won't hurt to verify that.Here's the call path:
[ 16.120824] [<ffffffff81627e6c>] dump_stack+0x55/0x76 [ 16.125979] [<ffffffff8162132e>] enable_slot+0x4ee/0x5e0 [ 16.131396] [<ffffffff813418fb>] ? trim_stale_devices+0x5b/0xf0 [ 16.137420] [<ffffffff81341b35>] acpiphp_check_bridge+0xd5/0x110 [ 16.143531] [<ffffffff81342acb>] hotplug_event+0x16b/0x260 [ 16.149115] [<ffffffff81072cd9>] ? process_one_work+0x189/0x540 [ 16.155136] [<ffffffff81342bf0>] hotplug_event_work+0x30/0x70 [ 16.160978] [<ffffffff81072d3b>] process_one_work+0x1eb/0x540 [ 16.166819] [<ffffffff81072cd9>] ? process_one_work+0x189/0x540 [ 16.172836] [<ffffffff8107353c>] worker_thread+0x11c/0x370 [ 16.178426] [<ffffffff81073420>] ? rescuer_thread+0x350/0x350 [ 16.184276] [<ffffffff8107b0ea>] kthread+0xea/0xf0 [ 16.189165] [<ffffffff8107b000>] ? kthread_create_on_node+0x160/0x160 [ 16.195700] [<ffffffff816395dc>] ret_from_fork+0x7c/0xb0 [ 16.201109] [<ffffffff8107b000>] ? kthread_create_on_node+0x160/0x160The actual death of the serial console occurs in
acpi_device_set_power()called from:
enable_slot()
acpiphp_bus_add()
acpiphp_bus_trim()
acpi_bus_trim()
acpi_walk_namespace()
acpi_bus_remove()
acpi_device_unregister()
acpi_device_set_power()Quoted 4 lines
I can't seem to get a path from the acpi devices in question there, so I have no idea what's getting trimmed here. It worries me quite a bit by introducing this trimming that apparently wasn't happening before though. Thanks,
As suspected, the pnp.bus_id/id of the last device before the serial console dies is COM1/PNP0501. I also see all of these being trimmed out:
MBRD/PNP0C02
DMAC/PNP0200
MATH/PNP0C04
PIC/PNP0000
HPET/PNP0103
RTC/PNP0B00
SPKR/PNP0800
TIME/PNP0100
LNK{A-H}/PNP0C0FQuoted 4 lines
This seems like a bad idea. I forgot to mention, the original
hotplug_eventis called with a device check on \_SB_.PCI0.PEX2. The box where I'm seeing this is a pretty generic X58 based Nehalem workstation (Lenovo S20).Thanks for the info!
The
acpiphp_bus_trim()inacpiphp_bus_add()is a leftover and a bad one. I don't think it's actually necessary, at least Thunderbolt works without it just fine on my Aspire S5.The patch below should help, can you please test it?
Rafael
---
From: Rafael J. Wysocki <[email protected]>
Subject: ACPI / hotplug / PCI: Don't trim devices before scanning the namespaceIn
acpiphp_bus_add()we first remove device objects corresponding to the given handle and the ACPI namespace branch below it which are then re-created byacpi_bus_scan(). This used to be done to clean up after surprise removals, but now we do the cleanup throughtrim_stale_devices()which checks if the devices in question are actually gone before removing them, so the device hierarchy trimming inacpiphp_bus_add()is not necessary any more and, moreover, it may lead to problems if it removes device objects corresponding to devices that are actually present.Reported-by Alex Williamson <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/pci/hotplug/acpiphp_glue.c | 1 - 1 file changed, 1 deletion(-)Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c +0
-0@@ -487,7 +487,6 @@ static void acpiphp_bus_add(acpi_handle {struct acpi_device *adev =NULL ;
Quoted 8 lines
Quoted 8 lines
drivers/pci/hotplug/acpiphp_glue.c static void acpiphp_bus_add(acpi_handle · line 492
Quoted 6 lines
drivers/pci/hotplug/acpiphp_glue.c +0
-1-acpiphp_bus_trim (handle);acpi_bus_scan (handle);acpi_bus_get_device (handle, &adev);if (adev)It boots again and the console works,
OK, so I'll queue up the patch above as a 3.12 fix and let's regard the dying serial console problem as fixed.
Now ->
Quoted 1 line
Quoted 1 line
but I see screens and screens of messages like this:
-> this is a separate issue that we need to take care of (so I've changed the subject to reflect that).
Quoted 41 lines
Quoted 41 lines
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settings
Quoted 2 lines
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
That depends on how many bus check/device check events they generate on boot.
My test machines don't generate them during boot at all (even the one with a Thunderbolt connector), so I don't see the messages in question during boot on any of them. Mika doesn't see them either I suppose, or he would have told me about that before.
And let's just make it clear that it is not usual or even OK to generate bus checks or device checks during boot like this. And since the changes in question have been in linux-next since right after the 3.11 merge window, I think that someone would have complained already had that been a common issue.
Of course, we need to deal with that somehow nevertheless. :-)
Quoted 14 lines
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y$ dmesg | wc 5697 49935 384368$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered-- vs --
#
CONFIG_HOTPLUG_PCI_ACPIis not set
Quoted 8 lines
$ dmesg | wc 1053 9176 71652$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registeredSo it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good.
The "no hotplug settings from platform" message is from pci_configure_slot(). I think the messages you're seeing are from the call to it in acpiphp_set_hpp_values() which is called by enable_slot().
There, I think, we can simply check the return value of pci_scan_slot() and if that is 0 (no new devices), we can just skip everything under the call to __pci_bus_assign_resources().
However, we can't skip the scanning of bridges, if any, because there may be new devices below them and I guess that's what takes so much time on your machine.
Thanks,
Rafael
Re: Excess dmesg output from ACPIPHP on boot (was: Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots)
Quoted 1 line · Rafael J. Wysocki
On Thursday, September 05, 2013 08:21:41 AM Alex Williamson wrote:
[...]
Quoted 85 lines
Quoted 41 lines
Quoted 41 lines
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settingsQuoted 2 lines
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
That depends on how many bus check/device check events they generate on boot.
My test machines don't generate them during boot at all (even the one with a Thunderbolt connector), so I don't see the messages in question during boot on any of them. Mika doesn't see them either I suppose, or he would have told me about that before.
And let's just make it clear that it is not usual or even OK to generate bus checks or device checks during boot like this. And since the changes in question have been in linux-next since right after the 3.11 merge window, I think that someone would have complained already had that been a common issue.
Of course, we need to deal with that somehow nevertheless. :-)
Quoted 14 lines
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y$ dmesg | wc 5697 49935 384368$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered-- vs --
#
CONFIG_HOTPLUG_PCI_ACPIis not setQuoted 8 lines
$ dmesg | wc 1053 9176 71652$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registeredSo it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good.
The "no hotplug settings from platform" message is from
pci_configure_slot(). I think the messages you're seeing are from the call to it inacpiphp_set_hpp_values()which is called byenable_slot().
Quoted 7 lines
There, I think, we can simply check the return value of
pci_scan_slot()and if that is 0 (no new devices), we can just skip everything under the call to__pci_bus_assign_resources().However, we can't skip the scanning of bridges, if any, because there may be new devices below them and I guess that's what takes so much time on your machine.
OK, one piece is missing. We may need to evaluate _OSC after handling each event to let the platform know the status.
Can you please check if the appended patch makes any difference (with the previous fix applied, of course)?
If fact, it is two patches combined. One of them optimizes enable_slot() slightly and the other adds the missing _OSC evaluation.
Thanks,
Rafael
--- drivers/pci/hotplug/acpiphp_glue.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +27 -8
@@ -542,12 +542,12 @@ static void __ref enable_slot(struct acpstruct acpiphp_func *func;int max, pass;LIST_HEAD (add_list); +int nr_found;list_for_each_entry (func, &slot->funcs, sibling)acpiphp_bus_add (func_to_handle (func)); -pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); - + nr_found =pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); max =acpiphp_max_busnr (bus);for (pass =0 ; pass <2 ; pass++) {list_for_each_entry (dev, &bus->devices, bus_list) {
@@ -566,8 +566,11 @@ static void __ref enable_slot(struct acp } } } -__pci_bus_assign_resources (bus, &add_list,NULL ); +/* Nothing more to do here if there are no new devices on this bus. */ +if (!nr_found && (slot->flags &SLOT_ENABLED )) +return ; +acpiphp_sanitize_bus (bus);acpiphp_set_hpp_values (bus);acpiphp_set_acpi_region (slot);
@@ -867,6 +870,8 @@ static void hotplug_event_work(struct wohotplug_event (hp_work->handle, hp_work->type, context);acpi_scan_lock_release (); +acpi_evaluate_hotplug_ost (hp_work->handle, hp_work->type, +ACPI_OST_SC_SUCCESS ,NULL );kfree (hp_work);/* allocated in handle_hotplug_event() */ put_bridge (context->func.parent); }
@@ -882,12 +887,16 @@ static void hotplug_event_work(struct wostatic void handle_hotplug_event (acpi_handle handle,u32 type,void *data) {struct acpiphp_context *context; +u32 ost_code;switch (type) {case ACPI_NOTIFY_BUS_CHECK :case ACPI_NOTIFY_DEVICE_CHECK : + ost_code =ACPI_OST_SC_INSERT_IN_PROGRESS ; + goto work;case ACPI_NOTIFY_EJECT_REQUEST : -break ; + ost_code =ACPI_OST_SC_EJECT_IN_PROGRESS ; + goto work;case ACPI_NOTIFY_DEVICE_WAKE :return ;
@@ -895,30 +904,40 @@ static void handle_hotplug_event(acpi_hacase ACPI_NOTIFY_FREQUENCY_MISMATCH :acpi_handle_err (handle,"Device cannot be configured due " "to a frequency mismatch\n" ); -return ; +break ;case ACPI_NOTIFY_BUS_MODE_MISMATCH :acpi_handle_err (handle,"Device cannot be configured due " "to a bus mode mismatch\n" ); -return ; +break ;case ACPI_NOTIFY_POWER_FAULT :acpi_handle_err (handle,"Device has suffered a power fault\n" ); -return ; +break ;default :acpi_handle_warn (handle,"Unsupported event type 0x%x\n" , type); -return ; +break ; } + err: + ost_code =ACPI_OST_SC_NON_SPECIFIC_FAILURE ; +acpi_evaluate_hotplug_ost (handle, type, ost_code,NULL ); +return ; + + work:mutex_lock (&acpiphp_context_lock); context =acpiphp_get_context (handle);if (context) {get_bridge (context->func.parent);acpiphp_put_context (context); +acpi_evaluate_hotplug_ost (handle, type, ost_code,NULL );alloc_acpi_hp_work (handle, type, context, hotplug_event_work); +mutex_unlock (&acpiphp_context_lock); +return ; }mutex_unlock (&acpiphp_context_lock); + goto err; }/*
Re: Excess dmesg output from ACPIPHP on boot (was: Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots)
Quoted 94 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Thursday, September 05, 2013 08:21:41 AM Alex Williamson wrote:
[...]
Quoted 89 lines
Quoted 41 lines
Quoted 41 lines
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settingsQuoted 2 lines
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
That depends on how many bus check/device check events they generate on boot.
My test machines don't generate them during boot at all (even the one with a Thunderbolt connector), so I don't see the messages in question during boot on any of them. Mika doesn't see them either I suppose, or he would have told me about that before.
And let's just make it clear that it is not usual or even OK to generate bus checks or device checks during boot like this. And since the changes in question have been in linux-next since right after the 3.11 merge window, I think that someone would have complained already had that been a common issue.
Of course, we need to deal with that somehow nevertheless. :-)
Quoted 14 lines
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y$ dmesg | wc 5697 49935 384368$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered-- vs --
#
CONFIG_HOTPLUG_PCI_ACPIis not setQuoted 8 lines
$ dmesg | wc 1053 9176 71652$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registeredSo it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good.
The "no hotplug settings from platform" message is from
pci_configure_slot(). I think the messages you're seeing are from the call to it inacpiphp_set_hpp_values()which is called byenable_slot().There, I think, we can simply check the return value of
pci_scan_slot()and if that is 0 (no new devices), we can just skip everything under the call to__pci_bus_assign_resources().
Quoted 6 lines
Quoted 3 lines
However, we can't skip the scanning of bridges, if any, because there may be new devices below them and I guess that's what takes so much time on your machine.
OK, one piece is missing. We may need to evaluate
_OSCafter handling each event to let the platform know the status.
s/_OSC/_OST/
Quoted 5 lines
Can you please check if the appended patch makes any difference (with the previous fix applied, of course)?
If fact, it is two patches combined. One of them optimizes
enable_slot()slightly and the other adds the missing_OSCevaluation.
s/_OSC/_OST/ (What the heck?)
But the patch should be OK. :-)
Thanks,
Rafael
Quoted 113 lines
--- drivers/pci/hotplug/acpiphp_glue.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c +27
-9@@ -542,12 +542,12 @@ static void __ref enable_slot(struct acpstruct acpiphp_func *func;int max, pass;LIST_HEAD (add_list); +int nr_found;list_for_each_entry (func, &slot->funcs, sibling)acpiphp_bus_add (func_to_handle (func)); -pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); - + nr_found =pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); max =acpiphp_max_busnr (bus);for (pass =0 ; pass <2 ; pass++) {list_for_each_entry (dev, &bus->devices, bus_list) {@@ -566,8 +566,11 @@ static void __ref enable_slot(struct acp } } } -__pci_bus_assign_resources (bus, &add_list,NULL ); +/* Nothing more to do here if there are no new devices on this bus. */ +if (!nr_found && (slot->flags &SLOT_ENABLED )) +return ; +acpiphp_sanitize_bus (bus);acpiphp_set_hpp_values (bus);acpiphp_set_acpi_region (slot);@@ -867,6 +870,8 @@ static void hotplug_event_work(struct wohotplug_event (hp_work->handle, hp_work->type, context);acpi_scan_lock_release (); +acpi_evaluate_hotplug_ost (hp_work->handle, hp_work->type, +ACPI_OST_SC_SUCCESS ,NULL );kfree (hp_work);/* allocated in handle_hotplug_event() */ put_bridge (context->func.parent); }@@ -882,12 +887,16 @@ static void hotplug_event_work(struct wostatic void handle_hotplug_event (acpi_handle handle,u32 type,void *data) {struct acpiphp_context *context; +u32 ost_code;switch (type) {case ACPI_NOTIFY_BUS_CHECK :case ACPI_NOTIFY_DEVICE_CHECK : + ost_code =ACPI_OST_SC_INSERT_IN_PROGRESS ; + goto work;case ACPI_NOTIFY_EJECT_REQUEST : -break ; + ost_code =ACPI_OST_SC_EJECT_IN_PROGRESS ; + goto work;case ACPI_NOTIFY_DEVICE_WAKE :return ;@@ -895,30 +904,40 @@ static void handle_hotplug_event(acpi_hacase ACPI_NOTIFY_FREQUENCY_MISMATCH :acpi_handle_err (handle,"Device cannot be configured due " "to a frequency mismatch\n" ); -return ; +break ;case ACPI_NOTIFY_BUS_MODE_MISMATCH :acpi_handle_err (handle,"Device cannot be configured due " "to a bus mode mismatch\n" ); -return ; +break ;case ACPI_NOTIFY_POWER_FAULT :acpi_handle_err (handle,"Device has suffered a power fault\n" ); -return ; +break ;default :acpi_handle_warn (handle,"Unsupported event type 0x%x\n" , type); -return ; +break ; } + err: + ost_code =ACPI_OST_SC_NON_SPECIFIC_FAILURE ; +acpi_evaluate_hotplug_ost (handle, type, ost_code,NULL ); +return ; + + work:mutex_lock (&acpiphp_context_lock); context =acpiphp_get_context (handle);if (context) {get_bridge (context->func.parent);acpiphp_put_context (context); +acpi_evaluate_hotplug_ost (handle, type, ost_code,NULL );alloc_acpi_hp_work (handle, type, context, hotplug_event_work); +mutex_unlock (&acpiphp_context_lock); +return ; }mutex_unlock (&acpiphp_context_lock); + goto err; }/* -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: Excess dmesg output from ACPIPHP on boot (was: Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots)
In reply to Rafael J. WysockiQuoted 98 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Thursday, September 05, 2013 08:21:41 AM Alex Williamson wrote:
[...]
Quoted 85 lines
Quoted 41 lines
Quoted 41 lines
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settingsQuoted 2 lines
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
That depends on how many bus check/device check events they generate on boot.
My test machines don't generate them during boot at all (even the one with a Thunderbolt connector), so I don't see the messages in question during boot on any of them. Mika doesn't see them either I suppose, or he would have told me about that before.
And let's just make it clear that it is not usual or even OK to generate bus checks or device checks during boot like this. And since the changes in question have been in linux-next since right after the 3.11 merge window, I think that someone would have complained already had that been a common issue.
Of course, we need to deal with that somehow nevertheless. :-)
Quoted 14 lines
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y$ dmesg | wc 5697 49935 384368$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered-- vs --
#
CONFIG_HOTPLUG_PCI_ACPIis not setQuoted 8 lines
$ dmesg | wc 1053 9176 71652$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registeredSo it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good.
The "no hotplug settings from platform" message is from
pci_configure_slot(). I think the messages you're seeing are from the call to it inacpiphp_set_hpp_values()which is called byenable_slot().Quoted 7 lines
There, I think, we can simply check the return value of
pci_scan_slot()and if that is 0 (no new devices), we can just skip everything under the call to__pci_bus_assign_resources().However, we can't skip the scanning of bridges, if any, because there may be new devices below them and I guess that's what takes so much time on your machine.
Quoted 8 lines
OK, one piece is missing. We may need to evaluate
_OSCafter handling each event to let the platform know the status.Can you please check if the appended patch makes any difference (with the previous fix applied, of course)?
If fact, it is two patches combined. One of them optimizes
enable_slot()slightly and the other adds the missing_OSCevaluation.
Better, still double the output:
$ dmesg | wc 2169 19047 152710
$ dmesg | tail --lines=1 [ 39.980918] Ebtables v2.0 registered
Here's another interesting stat:
$ dmesg | colrm 1 15 | sort | uniq -c | sort -nr | head --lines=25
73 pci 0000:00:1f.0: BAR 13: [io 0x1000-0x107f] has bogus alignment
73 pci 0000:00:1e.0: PCI bridge to [bus 06]
64 pci 0000:00:1e.0: bridge window [mem 0x81100000-0x812fffff 64bit pref]
64 pci 0000:00:1e.0: bridge window [mem 0x80f00000-0x810fffff]
64 pci 0000:00:1e.0: bridge window [io 0x7000-0x7fff]
38 pci 0000:00:1c.4: PCI bridge to [bus 05]
38 pci 0000:00:1c.4: bridge window [mem 0xf4f00000-0xf4ffffff]
38 pci 0000:00:1c.0: PCI bridge to [bus 04]
38 pci 0000:00:07.0: PCI bridge to [bus 03]
38 pci 0000:00:07.0: bridge window [mem 0xf2000000-0xf40fffff]
38 pci 0000:00:07.0: bridge window [mem 0xe0000000-0xf1ffffff 64bit pref]
38 pci 0000:00:07.0: bridge window [io 0x4000-0x4fff]
38 pci 0000:00:03.0: PCI bridge to [bus 02]
38 pci 0000:00:03.0: bridge window [mem 0xf4e00000-0xf4efffff]
38 pci 0000:00:03.0: bridge window [mem 0xd0000000-0xdfffffff 64bit pref]
38 pci 0000:00:03.0: bridge window [io 0x3000-0x3fff]
38 pci 0000:00:01.0: PCI bridge to [bus 01]
38 pci 0000:00:01.0: bridge window [mem 0xf4100000-0xf4bfffff]
38 pci 0000:00:01.0: bridge window [io 0x2000-0x2fff]
37 pci 0000:00:1c.4: bridge window [mem 0x80c00000-0x80dfffff 64bit pref]
37 pci 0000:00:1c.4: bridge window [io 0x6000-0x6fff]
37 pci 0000:00:1c.0: bridge window [mem 0x80a00000-0x80bfffff 64bit pref]
37 pci 0000:00:1c.0: bridge window [mem 0x80800000-0x809fffff]
37 pci 0000:00:1c.0: bridge window [io 0x5000-0x5fff]
36 pci 0000:00:01.0: bridge window [mem 0x80000000-0x807fffff 64bit pref]This is nearly the entire difference, just 25 lines repeated over and over. Thanks,
Alex
Re: Excess dmesg output from ACPIPHP on boot (was: Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots)
Quoted 105 lines · Alex Williamson
Quoted 104 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Thursday, September 05, 2013 08:21:41 AM Alex Williamson wrote:
[...]
Quoted 85 lines
Quoted 41 lines
Quoted 41 lines
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settingsQuoted 2 lines
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
That depends on how many bus check/device check events they generate on boot.
My test machines don't generate them during boot at all (even the one with a Thunderbolt connector), so I don't see the messages in question during boot on any of them. Mika doesn't see them either I suppose, or he would have told me about that before.
And let's just make it clear that it is not usual or even OK to generate bus checks or device checks during boot like this. And since the changes in question have been in linux-next since right after the 3.11 merge window, I think that someone would have complained already had that been a common issue.
Of course, we need to deal with that somehow nevertheless. :-)
Quoted 14 lines
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y$ dmesg | wc 5697 49935 384368$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered-- vs --
#
CONFIG_HOTPLUG_PCI_ACPIis not setQuoted 8 lines
$ dmesg | wc 1053 9176 71652$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registeredSo it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good.
The "no hotplug settings from platform" message is from
pci_configure_slot(). I think the messages you're seeing are from the call to it inacpiphp_set_hpp_values()which is called byenable_slot().Quoted 7 lines
There, I think, we can simply check the return value of
pci_scan_slot()and if that is 0 (no new devices), we can just skip everything under the call to__pci_bus_assign_resources().However, we can't skip the scanning of bridges, if any, because there may be new devices below them and I guess that's what takes so much time on your machine.
OK, one piece is missing. We may need to evaluate
_OSCafter handling each event to let the platform know the status.Can you please check if the appended patch makes any difference (with the previous fix applied, of course)?
Quoted 7 lines
Quoted 2 lines
If fact, it is two patches combined. One of them optimizes
enable_slot()slightly and the other adds the missing_OSCevaluation.Better, still double the output:
$ dmesg | wc 2169 19047 152710
I see.
What about the timing?
Quoted 32 lines
$ dmesg | tail --lines=1 [ 39.980918] Ebtables v2.0 registeredHere's another interesting stat:
$ dmesg | colrm 1 15 | sort | uniq -c | sort -nr | head --lines=25 73 pci 0000:00:1f.0: BAR 13: [io 0x1000-0x107f] has bogus alignment 73 pci 0000:00:1e.0: PCI bridge to [bus 06] 64 pci 0000:00:1e.0: bridge window [mem 0x81100000-0x812fffff 64bit pref] 64 pci 0000:00:1e.0: bridge window [mem 0x80f00000-0x810fffff] 64 pci 0000:00:1e.0: bridge window [io 0x7000-0x7fff] 38 pci 0000:00:1c.4: PCI bridge to [bus 05] 38 pci 0000:00:1c.4: bridge window [mem 0xf4f00000-0xf4ffffff] 38 pci 0000:00:1c.0: PCI bridge to [bus 04] 38 pci 0000:00:07.0: PCI bridge to [bus 03] 38 pci 0000:00:07.0: bridge window [mem 0xf2000000-0xf40fffff] 38 pci 0000:00:07.0: bridge window [mem 0xe0000000-0xf1ffffff 64bit pref] 38 pci 0000:00:07.0: bridge window [io 0x4000-0x4fff] 38 pci 0000:00:03.0: PCI bridge to [bus 02] 38 pci 0000:00:03.0: bridge window [mem 0xf4e00000-0xf4efffff] 38 pci 0000:00:03.0: bridge window [mem 0xd0000000-0xdfffffff 64bit pref] 38 pci 0000:00:03.0: bridge window [io 0x3000-0x3fff] 38 pci 0000:00:01.0: PCI bridge to [bus 01] 38 pci 0000:00:01.0: bridge window [mem 0xf4100000-0xf4bfffff] 38 pci 0000:00:01.0: bridge window [io 0x2000-0x2fff] 37 pci 0000:00:1c.4: bridge window [mem 0x80c00000-0x80dfffff 64bit pref] 37 pci 0000:00:1c.4: bridge window [io 0x6000-0x6fff] 37 pci 0000:00:1c.0: bridge window [mem 0x80a00000-0x80bfffff 64bit pref] 37 pci 0000:00:1c.0: bridge window [mem 0x80800000-0x809fffff] 37 pci 0000:00:1c.0: bridge window [io 0x5000-0x5fff] 36 pci 0000:00:01.0: bridge window [mem 0x80000000-0x807fffff 64bit pref]
Quoted 2 lines
This is nearly the entire difference, just 25 lines repeated over and over.
Well, this is the bridge sizing I talked about previously. We still get apparently spurious bus check/device check events and they trigger bridge scans.
I'm not sure what to do about that and I wonder whether or not this is reproducible on any other machines you can test.
Can you please change dbg() to pr_info() under ACPI_NOTIFY_BUS_CHECK and ACPI_NOTIFY_DEVICE_CHECK in hotplug_event() (acpiphp_glue.c), grep the boot dmesg log for "check notify" and send the result? I'm wondering what's going on there.
Thanks,
Rafael
Re: Excess dmesg output from ACPIPHP on boot (was: Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots)
Quoted 109 lines · Rafael J. Wysocki
Quoted 108 lines · Alex Williamson
Quoted 106 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Thursday, September 05, 2013 08:21:41 AM Alex Williamson wrote:
[...]
Quoted 85 lines
Quoted 41 lines
Quoted 41 lines
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settingsQuoted 2 lines
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
That depends on how many bus check/device check events they generate on boot.
My test machines don't generate them during boot at all (even the one with a Thunderbolt connector), so I don't see the messages in question during boot on any of them. Mika doesn't see them either I suppose, or he would have told me about that before.
And let's just make it clear that it is not usual or even OK to generate bus checks or device checks during boot like this. And since the changes in question have been in linux-next since right after the 3.11 merge window, I think that someone would have complained already had that been a common issue.
Of course, we need to deal with that somehow nevertheless. :-)
Quoted 14 lines
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y$ dmesg | wc 5697 49935 384368$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered-- vs --
#
CONFIG_HOTPLUG_PCI_ACPIis not setQuoted 8 lines
$ dmesg | wc 1053 9176 71652$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registeredSo it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good.
The "no hotplug settings from platform" message is from
pci_configure_slot(). I think the messages you're seeing are from the call to it inacpiphp_set_hpp_values()which is called byenable_slot().Quoted 7 lines
There, I think, we can simply check the return value of
pci_scan_slot()and if that is 0 (no new devices), we can just skip everything under the call to__pci_bus_assign_resources().However, we can't skip the scanning of bridges, if any, because there may be new devices below them and I guess that's what takes so much time on your machine.
OK, one piece is missing. We may need to evaluate
_OSCafter handling each event to let the platform know the status.Can you please check if the appended patch makes any difference (with the previous fix applied, of course)?
If fact, it is two patches combined. One of them optimizes
enable_slot()slightly and the other adds the missing_OSCevaluation.
Quoted 8 lines
Quoted 4 lines
Better, still double the output:
$ dmesg | wc 2169 19047 152710I see.
What about the timing?
~40s below vs ~29s for acpiphp config'd out above.
Quoted 35 lines
Quoted 32 lines
$ dmesg | tail --lines=1 [ 39.980918] Ebtables v2.0 registeredHere's another interesting stat:
$ dmesg | colrm 1 15 | sort | uniq -c | sort -nr | head --lines=25 73 pci 0000:00:1f.0: BAR 13: [io 0x1000-0x107f] has bogus alignment 73 pci 0000:00:1e.0: PCI bridge to [bus 06] 64 pci 0000:00:1e.0: bridge window [mem 0x81100000-0x812fffff 64bit pref] 64 pci 0000:00:1e.0: bridge window [mem 0x80f00000-0x810fffff] 64 pci 0000:00:1e.0: bridge window [io 0x7000-0x7fff] 38 pci 0000:00:1c.4: PCI bridge to [bus 05] 38 pci 0000:00:1c.4: bridge window [mem 0xf4f00000-0xf4ffffff] 38 pci 0000:00:1c.0: PCI bridge to [bus 04] 38 pci 0000:00:07.0: PCI bridge to [bus 03] 38 pci 0000:00:07.0: bridge window [mem 0xf2000000-0xf40fffff] 38 pci 0000:00:07.0: bridge window [mem 0xe0000000-0xf1ffffff 64bit pref] 38 pci 0000:00:07.0: bridge window [io 0x4000-0x4fff] 38 pci 0000:00:03.0: PCI bridge to [bus 02] 38 pci 0000:00:03.0: bridge window [mem 0xf4e00000-0xf4efffff] 38 pci 0000:00:03.0: bridge window [mem 0xd0000000-0xdfffffff 64bit pref] 38 pci 0000:00:03.0: bridge window [io 0x3000-0x3fff] 38 pci 0000:00:01.0: PCI bridge to [bus 01] 38 pci 0000:00:01.0: bridge window [mem 0xf4100000-0xf4bfffff] 38 pci 0000:00:01.0: bridge window [io 0x2000-0x2fff] 37 pci 0000:00:1c.4: bridge window [mem 0x80c00000-0x80dfffff 64bit pref] 37 pci 0000:00:1c.4: bridge window [io 0x6000-0x6fff] 37 pci 0000:00:1c.0: bridge window [mem 0x80a00000-0x80bfffff 64bit pref] 37 pci 0000:00:1c.0: bridge window [mem 0x80800000-0x809fffff] 37 pci 0000:00:1c.0: bridge window [io 0x5000-0x5fff] 36 pci 0000:00:01.0: bridge window [mem 0x80000000-0x807fffff 64bit pref]Quoted 2 lines
This is nearly the entire difference, just 25 lines repeated over and over.
Quoted 6 lines
Well, this is the bridge sizing I talked about previously. We still get apparently spurious bus check/device check events and they trigger bridge scans.
I'm not sure what to do about that and I wonder whether or not this is reproducible on any other machines you can test.
I can try it on a couple other systems, but probably not until tomorrow.
Quoted 4 lines
Can you please change
dbg()topr_info()underACPI_NOTIFY_BUS_CHECKandACPI_NOTIFY_DEVICE_CHECKinhotplug_event()(acpiphp_glue.c), grep the boot dmesg log for "check notify" and send the result? I'm wondering what's going on there.
$ dmesg | grep "check notify" [ 1.633228] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 2.472004] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 2.477288] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 2.482571] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 2.482579] hotplug_event: Device check notify on \_SB_.PCI0.PEX6 [ 8.204953] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 8.209632] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 8.214272] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 8.218894] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 8.218901] hotplug_event: Device check notify on \_SB_.PCI0.PEX6
Thanks,
Alex
Re: Excess dmesg output from ACPIPHP on boot (was: Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots)
Quoted 112 lines · Alex Williamson
Quoted 111 lines · Rafael J. Wysocki
Quoted 110 lines · Alex Williamson
Quoted 98 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Thursday, September 05, 2013 08:21:41 AM Alex Williamson wrote:
[...]
Quoted 85 lines
Quoted 41 lines
Quoted 41 lines
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settingsQuoted 2 lines
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
That depends on how many bus check/device check events they generate on boot.
My test machines don't generate them during boot at all (even the one with a Thunderbolt connector), so I don't see the messages in question during boot on any of them. Mika doesn't see them either I suppose, or he would have told me about that before.
And let's just make it clear that it is not usual or even OK to generate bus checks or device checks during boot like this. And since the changes in question have been in linux-next since right after the 3.11 merge window, I think that someone would have complained already had that been a common issue.
Of course, we need to deal with that somehow nevertheless. :-)
Quoted 14 lines
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y$ dmesg | wc 5697 49935 384368$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered-- vs --
#
CONFIG_HOTPLUG_PCI_ACPIis not setQuoted 8 lines
$ dmesg | wc 1053 9176 71652$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registeredSo it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good.
The "no hotplug settings from platform" message is from
pci_configure_slot(). I think the messages you're seeing are from the call to it inacpiphp_set_hpp_values()which is called byenable_slot().Quoted 7 lines
There, I think, we can simply check the return value of
pci_scan_slot()and if that is 0 (no new devices), we can just skip everything under the call to__pci_bus_assign_resources().However, we can't skip the scanning of bridges, if any, because there may be new devices below them and I guess that's what takes so much time on your machine.
Quoted 8 lines
OK, one piece is missing. We may need to evaluate
_OSCafter handling each event to let the platform know the status.Can you please check if the appended patch makes any difference (with the previous fix applied, of course)?
If fact, it is two patches combined. One of them optimizes
enable_slot()slightly and the other adds the missing_OSCevaluation.Better, still double the output:
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
$ dmesg | wc 2169 19047 152710I see.
What about the timing?
~40s below vs ~29s for acpiphp config'd out above.
Well, that's better than before.
I'll prepare "official" patches with the last changes then too.
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
$ dmesg | tail --lines=1 [ 39.980918] Ebtables v2.0 registeredHere's another interesting stat:
$ dmesg | colrm 1 15 | sort | uniq -c | sort -nr | head --lines=25 73 pci 0000:00:1f.0: BAR 13: [io 0x1000-0x107f] has bogus alignment 73 pci 0000:00:1e.0: PCI bridge to [bus 06] 64 pci 0000:00:1e.0: bridge window [mem 0x81100000-0x812fffff 64bit pref] 64 pci 0000:00:1e.0: bridge window [mem 0x80f00000-0x810fffff] 64 pci 0000:00:1e.0: bridge window [io 0x7000-0x7fff] 38 pci 0000:00:1c.4: PCI bridge to [bus 05] 38 pci 0000:00:1c.4: bridge window [mem 0xf4f00000-0xf4ffffff] 38 pci 0000:00:1c.0: PCI bridge to [bus 04] 38 pci 0000:00:07.0: PCI bridge to [bus 03] 38 pci 0000:00:07.0: bridge window [mem 0xf2000000-0xf40fffff] 38 pci 0000:00:07.0: bridge window [mem 0xe0000000-0xf1ffffff 64bit pref] 38 pci 0000:00:07.0: bridge window [io 0x4000-0x4fff] 38 pci 0000:00:03.0: PCI bridge to [bus 02] 38 pci 0000:00:03.0: bridge window [mem 0xf4e00000-0xf4efffff] 38 pci 0000:00:03.0: bridge window [mem 0xd0000000-0xdfffffff 64bit pref] 38 pci 0000:00:03.0: bridge window [io 0x3000-0x3fff] 38 pci 0000:00:01.0: PCI bridge to [bus 01] 38 pci 0000:00:01.0: bridge window [mem 0xf4100000-0xf4bfffff] 38 pci 0000:00:01.0: bridge window [io 0x2000-0x2fff] 37 pci 0000:00:1c.4: bridge window [mem 0x80c00000-0x80dfffff 64bit pref] 37 pci 0000:00:1c.4: bridge window [io 0x6000-0x6fff] 37 pci 0000:00:1c.0: bridge window [mem 0x80a00000-0x80bfffff 64bit pref] 37 pci 0000:00:1c.0: bridge window [mem 0x80800000-0x809fffff] 37 pci 0000:00:1c.0: bridge window [io 0x5000-0x5fff] 36 pci 0000:00:01.0: bridge window [mem 0x80000000-0x807fffff 64bit pref]
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This is nearly the entire difference, just 25 lines repeated over and over.
Can you check how many times the lines above are repeated?
Quoted 9 lines
Quoted 7 lines
Well, this is the bridge sizing I talked about previously. We still get apparently spurious bus check/device check events and they trigger bridge scans.
I'm not sure what to do about that and I wonder whether or not this is reproducible on any other machines you can test.
I can try it on a couple other systems, but probably not until tomorrow.
Tomorrow (or even later) works just fine for me. :-)
Quoted 5 lines
Quoted 4 lines
Can you please change
dbg()topr_info()underACPI_NOTIFY_BUS_CHECKandACPI_NOTIFY_DEVICE_CHECKinhotplug_event()(acpiphp_glue.c), grep the boot dmesg log for "check notify" and send the result? I'm wondering what's going on there.
Quoted 11 lines
$ dmesg | grep "check notify" [ 1.633228] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 2.472004] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 2.477288] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 2.482571] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 2.482579] hotplug_event: Device check notify on \_SB_.PCI0.PEX6 [ 8.204953] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 8.209632] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 8.214272] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 8.218894] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 8.218901] hotplug_event: Device check notify on \_SB_.PCI0.PEX6
So I guess the PEXn things are PCIe ports and we get two notifications for each of them, so everything below them gets rescanned.
I've just talked to Bjorn about that and we don't seem to have a good idea how to handle this. The notifies shouldn't be there, but we kind of have to handle them.
I guess we could suppress the output from repeated bridge scans. Alternatively, we could just blacklist this particular system somehow if the problem is specific to it.
Thanks,
Rafael
Re: Excess dmesg output from ACPIPHP on boot (was: Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots)
Quoted 158 lines · Rafael J. Wysocki
Quoted 112 lines · Alex Williamson
Quoted 111 lines · Rafael J. Wysocki
Quoted 110 lines · Alex Williamson
Quoted 98 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Thursday, September 05, 2013 08:21:41 AM Alex Williamson wrote:
[...]
Quoted 85 lines
Quoted 41 lines
Quoted 41 lines
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settingsQuoted 2 lines
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
That depends on how many bus check/device check events they generate on boot.
My test machines don't generate them during boot at all (even the one with a Thunderbolt connector), so I don't see the messages in question during boot on any of them. Mika doesn't see them either I suppose, or he would have told me about that before.
And let's just make it clear that it is not usual or even OK to generate bus checks or device checks during boot like this. And since the changes in question have been in linux-next since right after the 3.11 merge window, I think that someone would have complained already had that been a common issue.
Of course, we need to deal with that somehow nevertheless. :-)
Quoted 14 lines
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y$ dmesg | wc 5697 49935 384368$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered-- vs --
#
CONFIG_HOTPLUG_PCI_ACPIis not setQuoted 8 lines
$ dmesg | wc 1053 9176 71652$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registeredSo it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good.
The "no hotplug settings from platform" message is from
pci_configure_slot(). I think the messages you're seeing are from the call to it inacpiphp_set_hpp_values()which is called byenable_slot().Quoted 7 lines
There, I think, we can simply check the return value of
pci_scan_slot()and if that is 0 (no new devices), we can just skip everything under the call to__pci_bus_assign_resources().However, we can't skip the scanning of bridges, if any, because there may be new devices below them and I guess that's what takes so much time on your machine.
Quoted 8 lines
OK, one piece is missing. We may need to evaluate
_OSCafter handling each event to let the platform know the status.Can you please check if the appended patch makes any difference (with the previous fix applied, of course)?
If fact, it is two patches combined. One of them optimizes
enable_slot()slightly and the other adds the missing_OSCevaluation.Better, still double the output:
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
$ dmesg | wc 2169 19047 152710I see.
What about the timing?
~40s below vs ~29s for acpiphp config'd out above.
Well, that's better than before.
I'll prepare "official" patches with the last changes then too.
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
$ dmesg | tail --lines=1 [ 39.980918] Ebtables v2.0 registeredHere's another interesting stat:
$ dmesg | colrm 1 15 | sort | uniq -c | sort -nr | head --lines=25 73 pci 0000:00:1f.0: BAR 13: [io 0x1000-0x107f] has bogus alignment 73 pci 0000:00:1e.0: PCI bridge to [bus 06] 64 pci 0000:00:1e.0: bridge window [mem 0x81100000-0x812fffff 64bit pref] 64 pci 0000:00:1e.0: bridge window [mem 0x80f00000-0x810fffff] 64 pci 0000:00:1e.0: bridge window [io 0x7000-0x7fff] 38 pci 0000:00:1c.4: PCI bridge to [bus 05] 38 pci 0000:00:1c.4: bridge window [mem 0xf4f00000-0xf4ffffff] 38 pci 0000:00:1c.0: PCI bridge to [bus 04] 38 pci 0000:00:07.0: PCI bridge to [bus 03] 38 pci 0000:00:07.0: bridge window [mem 0xf2000000-0xf40fffff] 38 pci 0000:00:07.0: bridge window [mem 0xe0000000-0xf1ffffff 64bit pref] 38 pci 0000:00:07.0: bridge window [io 0x4000-0x4fff] 38 pci 0000:00:03.0: PCI bridge to [bus 02] 38 pci 0000:00:03.0: bridge window [mem 0xf4e00000-0xf4efffff] 38 pci 0000:00:03.0: bridge window [mem 0xd0000000-0xdfffffff 64bit pref] 38 pci 0000:00:03.0: bridge window [io 0x3000-0x3fff] 38 pci 0000:00:01.0: PCI bridge to [bus 01] 38 pci 0000:00:01.0: bridge window [mem 0xf4100000-0xf4bfffff] 38 pci 0000:00:01.0: bridge window [io 0x2000-0x2fff] 37 pci 0000:00:1c.4: bridge window [mem 0x80c00000-0x80dfffff 64bit pref] 37 pci 0000:00:1c.4: bridge window [io 0x6000-0x6fff] 37 pci 0000:00:1c.0: bridge window [mem 0x80a00000-0x80bfffff 64bit pref] 37 pci 0000:00:1c.0: bridge window [mem 0x80800000-0x809fffff] 37 pci 0000:00:1c.0: bridge window [io 0x5000-0x5fff] 36 pci 0000:00:01.0: bridge window [mem 0x80000000-0x807fffff 64bit pref]
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This is nearly the entire difference, just 25 lines repeated over and over.
Can you check how many times the lines above are repeated?
The line count is pre-pended to each line. 73 times for the first two line, etc.
Quoted 32 lines
Quoted 9 lines
Quoted 7 lines
Well, this is the bridge sizing I talked about previously. We still get apparently spurious bus check/device check events and they trigger bridge scans.
I'm not sure what to do about that and I wonder whether or not this is reproducible on any other machines you can test.
I can try it on a couple other systems, but probably not until tomorrow.
Tomorrow (or even later) works just fine for me. :-)
Quoted 5 lines
Quoted 4 lines
Can you please change
dbg()topr_info()underACPI_NOTIFY_BUS_CHECKandACPI_NOTIFY_DEVICE_CHECKinhotplug_event()(acpiphp_glue.c), grep the boot dmesg log for "check notify" and send the result? I'm wondering what's going on there.Quoted 11 lines
$ dmesg | grep "check notify" [ 1.633228] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 2.472004] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 2.477288] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 2.482571] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 2.482579] hotplug_event: Device check notify on \_SB_.PCI0.PEX6 [ 8.204953] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 8.209632] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 8.214272] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 8.218894] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 8.218901] hotplug_event: Device check notify on \_SB_.PCI0.PEX6So I guess the PEXn things are PCIe ports and we get two notifications for each of them, so everything below them gets rescanned.
Quoted 7 lines
I've just talked to Bjorn about that and we don't seem to have a good idea how to handle this. The notifies shouldn't be there, but we kind of have to handle them.
I guess we could suppress the output from repeated bridge scans. Alternatively, we could just blacklist this particular system somehow if the problem is specific to it.
Can't we determine that nothing has changed and avoid re-printing? I have a hard time believing this system is all that unique. Thanks,
Alex
Re: Excess dmesg output from ACPIPHP on boot (was: Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots)
Quoted 159 lines · Alex Williamson
Quoted 158 lines · Rafael J. Wysocki
Quoted 112 lines · Alex Williamson
Quoted 111 lines · Rafael J. Wysocki
Quoted 110 lines · Alex Williamson
Quoted 98 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Thursday, September 05, 2013 08:21:41 AM Alex Williamson wrote:
[...]
Quoted 85 lines
Quoted 41 lines
Quoted 41 lines
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settingsQuoted 2 lines
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
That depends on how many bus check/device check events they generate on boot.
My test machines don't generate them during boot at all (even the one with a Thunderbolt connector), so I don't see the messages in question during boot on any of them. Mika doesn't see them either I suppose, or he would have told me about that before.
And let's just make it clear that it is not usual or even OK to generate bus checks or device checks during boot like this. And since the changes in question have been in linux-next since right after the 3.11 merge window, I think that someone would have complained already had that been a common issue.
Of course, we need to deal with that somehow nevertheless. :-)
Quoted 14 lines
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y$ dmesg | wc 5697 49935 384368$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered-- vs --
#
CONFIG_HOTPLUG_PCI_ACPIis not setQuoted 8 lines
$ dmesg | wc 1053 9176 71652$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registeredSo it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good.
The "no hotplug settings from platform" message is from
pci_configure_slot(). I think the messages you're seeing are from the call to it inacpiphp_set_hpp_values()which is called byenable_slot().Quoted 7 lines
There, I think, we can simply check the return value of
pci_scan_slot()and if that is 0 (no new devices), we can just skip everything under the call to__pci_bus_assign_resources().However, we can't skip the scanning of bridges, if any, because there may be new devices below them and I guess that's what takes so much time on your machine.
Quoted 8 lines
OK, one piece is missing. We may need to evaluate
_OSCafter handling each event to let the platform know the status.Can you please check if the appended patch makes any difference (with the previous fix applied, of course)?
If fact, it is two patches combined. One of them optimizes
enable_slot()slightly and the other adds the missing_OSCevaluation.Better, still double the output:
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
$ dmesg | wc 2169 19047 152710I see.
What about the timing?
~40s below vs ~29s for acpiphp config'd out above.
Well, that's better than before.
I'll prepare "official" patches with the last changes then too.
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
$ dmesg | tail --lines=1 [ 39.980918] Ebtables v2.0 registeredHere's another interesting stat:
$ dmesg | colrm 1 15 | sort | uniq -c | sort -nr | head --lines=25 73 pci 0000:00:1f.0: BAR 13: [io 0x1000-0x107f] has bogus alignment 73 pci 0000:00:1e.0: PCI bridge to [bus 06] 64 pci 0000:00:1e.0: bridge window [mem 0x81100000-0x812fffff 64bit pref] 64 pci 0000:00:1e.0: bridge window [mem 0x80f00000-0x810fffff] 64 pci 0000:00:1e.0: bridge window [io 0x7000-0x7fff] 38 pci 0000:00:1c.4: PCI bridge to [bus 05] 38 pci 0000:00:1c.4: bridge window [mem 0xf4f00000-0xf4ffffff] 38 pci 0000:00:1c.0: PCI bridge to [bus 04] 38 pci 0000:00:07.0: PCI bridge to [bus 03] 38 pci 0000:00:07.0: bridge window [mem 0xf2000000-0xf40fffff] 38 pci 0000:00:07.0: bridge window [mem 0xe0000000-0xf1ffffff 64bit pref] 38 pci 0000:00:07.0: bridge window [io 0x4000-0x4fff] 38 pci 0000:00:03.0: PCI bridge to [bus 02] 38 pci 0000:00:03.0: bridge window [mem 0xf4e00000-0xf4efffff] 38 pci 0000:00:03.0: bridge window [mem 0xd0000000-0xdfffffff 64bit pref] 38 pci 0000:00:03.0: bridge window [io 0x3000-0x3fff] 38 pci 0000:00:01.0: PCI bridge to [bus 01] 38 pci 0000:00:01.0: bridge window [mem 0xf4100000-0xf4bfffff] 38 pci 0000:00:01.0: bridge window [io 0x2000-0x2fff] 37 pci 0000:00:1c.4: bridge window [mem 0x80c00000-0x80dfffff 64bit pref] 37 pci 0000:00:1c.4: bridge window [io 0x6000-0x6fff] 37 pci 0000:00:1c.0: bridge window [mem 0x80a00000-0x80bfffff 64bit pref] 37 pci 0000:00:1c.0: bridge window [mem 0x80800000-0x809fffff] 37 pci 0000:00:1c.0: bridge window [io 0x5000-0x5fff] 36 pci 0000:00:01.0: bridge window [mem 0x80000000-0x807fffff 64bit pref]
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This is nearly the entire difference, just 25 lines repeated over and over.
Can you check how many times the lines above are repeated?
The line count is pre-pended to each line. 73 times for the first two line, etc.
Too late, too tired. Sorry.
Hmm, there's kind of too many of them given the number of notifications. Interesting.
OK, I'll look deeper into things tomorrow, maybe I'll find some clues.
Quoted 36 lines
Quoted 36 lines
Quoted 9 lines
Quoted 7 lines
Well, this is the bridge sizing I talked about previously. We still get apparently spurious bus check/device check events and they trigger bridge scans.
I'm not sure what to do about that and I wonder whether or not this is reproducible on any other machines you can test.
I can try it on a couple other systems, but probably not until tomorrow.
Tomorrow (or even later) works just fine for me. :-)
Quoted 5 lines
Quoted 4 lines
Can you please change
dbg()topr_info()underACPI_NOTIFY_BUS_CHECKandACPI_NOTIFY_DEVICE_CHECKinhotplug_event()(acpiphp_glue.c), grep the boot dmesg log for "check notify" and send the result? I'm wondering what's going on there.Quoted 11 lines
$ dmesg | grep "check notify" [ 1.633228] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 2.472004] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 2.477288] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 2.482571] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 2.482579] hotplug_event: Device check notify on \_SB_.PCI0.PEX6 [ 8.204953] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 8.209632] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 8.214272] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 8.218894] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 8.218901] hotplug_event: Device check notify on \_SB_.PCI0.PEX6So I guess the PEXn things are PCIe ports and we get two notifications for each of them, so everything below them gets rescanned.
I've just talked to Bjorn about that and we don't seem to have a good idea how to handle this. The notifies shouldn't be there, but we kind of have to handle them.
Quoted 5 lines
Quoted 3 lines
I guess we could suppress the output from repeated bridge scans. Alternatively, we could just blacklist this particular system somehow if the problem is specific to it.
Can't we determine that nothing has changed and avoid re-printing?
I suppose so, but that's not going to be a simple modification, because the output is from somewhat deep in the stack.
Quoted 1 line
I have a hard time believing this system is all that unique.
Yes, it is quite likely that there are more systems like that.
Thanks,
Rafael
Bjorn Helgaas
maintainerRe: Excess dmesg output from ACPIPHP on boot (was: Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots)
In reply to Rafael J. WysockiQuoted 192 lines · Rafael J. Wysocki
Quoted 112 lines · Alex Williamson
Quoted 111 lines · Rafael J. Wysocki
Quoted 110 lines · Alex Williamson
Quoted 98 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Thursday, September 05, 2013 08:21:41 AM Alex Williamson wrote:
[...]
Quoted 85 lines
Quoted 41 lines
Quoted 41 lines
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settingsQuoted 2 lines
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
That depends on how many bus check/device check events they generate on boot.
My test machines don't generate them during boot at all (even the one with a Thunderbolt connector), so I don't see the messages in question during boot on any of them. Mika doesn't see them either I suppose, or he would have told me about that before.
And let's just make it clear that it is not usual or even OK to generate bus checks or device checks during boot like this. And since the changes in question have been in linux-next since right after the 3.11 merge window, I think that someone would have complained already had that been a common issue.
Of course, we need to deal with that somehow nevertheless. :-)
Quoted 14 lines
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y$ dmesg | wc 5697 49935 384368$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered-- vs --
#
CONFIG_HOTPLUG_PCI_ACPIis not setQuoted 8 lines
$ dmesg | wc 1053 9176 71652$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registeredSo it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good.
The "no hotplug settings from platform" message is from
pci_configure_slot(). I think the messages you're seeing are from the call to it inacpiphp_set_hpp_values()which is called byenable_slot().Quoted 7 lines
There, I think, we can simply check the return value of
pci_scan_slot()and if that is 0 (no new devices), we can just skip everything under the call to__pci_bus_assign_resources().However, we can't skip the scanning of bridges, if any, because there may be new devices below them and I guess that's what takes so much time on your machine.
Quoted 8 lines
OK, one piece is missing. We may need to evaluate
_OSCafter handling each event to let the platform know the status.Can you please check if the appended patch makes any difference (with the previous fix applied, of course)?
If fact, it is two patches combined. One of them optimizes
enable_slot()slightly and the other adds the missing_OSCevaluation.Better, still double the output:
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
$ dmesg | wc 2169 19047 152710I see.
What about the timing?
~40s below vs ~29s for acpiphp config'd out above.
Well, that's better than before.
I'll prepare "official" patches with the last changes then too.
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
$ dmesg | tail --lines=1 [ 39.980918] Ebtables v2.0 registeredHere's another interesting stat:
$ dmesg | colrm 1 15 | sort | uniq -c | sort -nr | head --lines=25 73 pci 0000:00:1f.0: BAR 13: [io 0x1000-0x107f] has bogus alignment 73 pci 0000:00:1e.0: PCI bridge to [bus 06] 64 pci 0000:00:1e.0: bridge window [mem 0x81100000-0x812fffff 64bit pref] 64 pci 0000:00:1e.0: bridge window [mem 0x80f00000-0x810fffff] 64 pci 0000:00:1e.0: bridge window [io 0x7000-0x7fff] 38 pci 0000:00:1c.4: PCI bridge to [bus 05] 38 pci 0000:00:1c.4: bridge window [mem 0xf4f00000-0xf4ffffff] 38 pci 0000:00:1c.0: PCI bridge to [bus 04] 38 pci 0000:00:07.0: PCI bridge to [bus 03] 38 pci 0000:00:07.0: bridge window [mem 0xf2000000-0xf40fffff] 38 pci 0000:00:07.0: bridge window [mem 0xe0000000-0xf1ffffff 64bit pref] 38 pci 0000:00:07.0: bridge window [io 0x4000-0x4fff] 38 pci 0000:00:03.0: PCI bridge to [bus 02] 38 pci 0000:00:03.0: bridge window [mem 0xf4e00000-0xf4efffff] 38 pci 0000:00:03.0: bridge window [mem 0xd0000000-0xdfffffff 64bit pref] 38 pci 0000:00:03.0: bridge window [io 0x3000-0x3fff] 38 pci 0000:00:01.0: PCI bridge to [bus 01] 38 pci 0000:00:01.0: bridge window [mem 0xf4100000-0xf4bfffff] 38 pci 0000:00:01.0: bridge window [io 0x2000-0x2fff] 37 pci 0000:00:1c.4: bridge window [mem 0x80c00000-0x80dfffff 64bit pref] 37 pci 0000:00:1c.4: bridge window [io 0x6000-0x6fff] 37 pci 0000:00:1c.0: bridge window [mem 0x80a00000-0x80bfffff 64bit pref] 37 pci 0000:00:1c.0: bridge window [mem 0x80800000-0x809fffff] 37 pci 0000:00:1c.0: bridge window [io 0x5000-0x5fff] 36 pci 0000:00:01.0: bridge window [mem 0x80000000-0x807fffff 64bit pref]Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This is nearly the entire difference, just 25 lines repeated over and over.
Can you check how many times the lines above are repeated?
Quoted 9 lines
Quoted 7 lines
Well, this is the bridge sizing I talked about previously. We still get apparently spurious bus check/device check events and they trigger bridge scans.
I'm not sure what to do about that and I wonder whether or not this is reproducible on any other machines you can test.
I can try it on a couple other systems, but probably not until tomorrow.
Tomorrow (or even later) works just fine for me. :-)
Quoted 5 lines
Quoted 4 lines
Can you please change
dbg()topr_info()underACPI_NOTIFY_BUS_CHECKandACPI_NOTIFY_DEVICE_CHECKinhotplug_event()(acpiphp_glue.c), grep the boot dmesg log for "check notify" and send the result? I'm wondering what's going on there.Quoted 11 lines
$ dmesg | grep "check notify" [ 1.633228] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 2.472004] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 2.477288] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 2.482571] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 2.482579] hotplug_event: Device check notify on \_SB_.PCI0.PEX6 [ 8.204953] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 8.209632] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 8.214272] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 8.218894] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 8.218901] hotplug_event: Device check notify on \_SB_.PCI0.PEX6
Quoted 6 lines
So I guess the PEXn things are PCIe ports and we get two notifications for each of them, so everything below them gets rescanned.
I've just talked to Bjorn about that and we don't seem to have a good idea how to handle this. The notifies shouldn't be there, but we kind of have to handle them.
What I said was "We aren't going to be able to get rid of the notifications, but we can probably figure out how to clean up some of the output." I don't think there's anything *wrong* with the notifications themselves, and as far as I know, there's nothing in the spec that limits how many notifications the platform can send.
Quoted 3 lines
I guess we could suppress the output from repeated bridge scans. Alternatively, we could just blacklist this particular system somehow if the problem is specific to it.
I'm opposed to blacklisting in principle because this doesn't sound like a platform defect. And I think we pretty much have to re-enumerate for each Device Check, because that's what the spec tells us to do.
My goal is for PCI to print stuff only for significant events, when we discover something new, or when we change something (BAR, bridge window, etc.) A hot-plug event, e.g., a Device Check, is arguably significant all by itself, but that's in ACPI, and it sounds like we only have a dbg() there now. The repeated PCI bridge info seems like it's useless. I've looked at cleaning up some of that in the past, but it wasn't trivial and it wasn't urgent enough at the time. But it sure sounds urgent now.
Alex, would you mind collecting the full dmesg or console log (with "debug ignore_loglevel") and "lspci -vv" output and attaching them to a bugzilla? Keep the hotplug_event() pr_info() change so we have more clues about what triggers things. This seems like an interesting situation, and there might be other things we can learn from it. It looks like the "hotplug settings" output is probably more than is necessary also.
Bjorn
Re: Excess dmesg output from ACPIPHP on boot (was: Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots)
Quoted 200 lines · Bjorn Helgaas
Quoted 192 lines · Rafael J. Wysocki
Quoted 112 lines · Alex Williamson
Quoted 111 lines · Rafael J. Wysocki
Quoted 110 lines · Alex Williamson
Quoted 98 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Thursday, September 05, 2013 08:21:41 AM Alex Williamson wrote:
[...]
Quoted 85 lines
Quoted 41 lines
Quoted 41 lines
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settingsQuoted 2 lines
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
That depends on how many bus check/device check events they generate on boot.
My test machines don't generate them during boot at all (even the one with a Thunderbolt connector), so I don't see the messages in question during boot on any of them. Mika doesn't see them either I suppose, or he would have told me about that before.
And let's just make it clear that it is not usual or even OK to generate bus checks or device checks during boot like this. And since the changes in question have been in linux-next since right after the 3.11 merge window, I think that someone would have complained already had that been a common issue.
Of course, we need to deal with that somehow nevertheless. :-)
Quoted 14 lines
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y$ dmesg | wc 5697 49935 384368$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered-- vs --
#
CONFIG_HOTPLUG_PCI_ACPIis not setQuoted 8 lines
$ dmesg | wc 1053 9176 71652$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registeredSo it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good.
The "no hotplug settings from platform" message is from
pci_configure_slot(). I think the messages you're seeing are from the call to it inacpiphp_set_hpp_values()which is called byenable_slot().Quoted 7 lines
There, I think, we can simply check the return value of
pci_scan_slot()and if that is 0 (no new devices), we can just skip everything under the call to__pci_bus_assign_resources().However, we can't skip the scanning of bridges, if any, because there may be new devices below them and I guess that's what takes so much time on your machine.
Quoted 8 lines
OK, one piece is missing. We may need to evaluate
_OSCafter handling each event to let the platform know the status.Can you please check if the appended patch makes any difference (with the previous fix applied, of course)?
If fact, it is two patches combined. One of them optimizes
enable_slot()slightly and the other adds the missing_OSCevaluation.Better, still double the output:
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
$ dmesg | wc 2169 19047 152710I see.
What about the timing?
~40s below vs ~29s for acpiphp config'd out above.
Well, that's better than before.
I'll prepare "official" patches with the last changes then too.
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
$ dmesg | tail --lines=1 [ 39.980918] Ebtables v2.0 registeredHere's another interesting stat:
$ dmesg | colrm 1 15 | sort | uniq -c | sort -nr | head --lines=25 73 pci 0000:00:1f.0: BAR 13: [io 0x1000-0x107f] has bogus alignment 73 pci 0000:00:1e.0: PCI bridge to [bus 06] 64 pci 0000:00:1e.0: bridge window [mem 0x81100000-0x812fffff 64bit pref] 64 pci 0000:00:1e.0: bridge window [mem 0x80f00000-0x810fffff] 64 pci 0000:00:1e.0: bridge window [io 0x7000-0x7fff] 38 pci 0000:00:1c.4: PCI bridge to [bus 05] 38 pci 0000:00:1c.4: bridge window [mem 0xf4f00000-0xf4ffffff] 38 pci 0000:00:1c.0: PCI bridge to [bus 04] 38 pci 0000:00:07.0: PCI bridge to [bus 03] 38 pci 0000:00:07.0: bridge window [mem 0xf2000000-0xf40fffff] 38 pci 0000:00:07.0: bridge window [mem 0xe0000000-0xf1ffffff 64bit pref] 38 pci 0000:00:07.0: bridge window [io 0x4000-0x4fff] 38 pci 0000:00:03.0: PCI bridge to [bus 02] 38 pci 0000:00:03.0: bridge window [mem 0xf4e00000-0xf4efffff] 38 pci 0000:00:03.0: bridge window [mem 0xd0000000-0xdfffffff 64bit pref] 38 pci 0000:00:03.0: bridge window [io 0x3000-0x3fff] 38 pci 0000:00:01.0: PCI bridge to [bus 01] 38 pci 0000:00:01.0: bridge window [mem 0xf4100000-0xf4bfffff] 38 pci 0000:00:01.0: bridge window [io 0x2000-0x2fff] 37 pci 0000:00:1c.4: bridge window [mem 0x80c00000-0x80dfffff 64bit pref] 37 pci 0000:00:1c.4: bridge window [io 0x6000-0x6fff] 37 pci 0000:00:1c.0: bridge window [mem 0x80a00000-0x80bfffff 64bit pref] 37 pci 0000:00:1c.0: bridge window [mem 0x80800000-0x809fffff] 37 pci 0000:00:1c.0: bridge window [io 0x5000-0x5fff] 36 pci 0000:00:01.0: bridge window [mem 0x80000000-0x807fffff 64bit pref]Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This is nearly the entire difference, just 25 lines repeated over and over.
Can you check how many times the lines above are repeated?
Quoted 9 lines
Quoted 7 lines
Well, this is the bridge sizing I talked about previously. We still get apparently spurious bus check/device check events and they trigger bridge scans.
I'm not sure what to do about that and I wonder whether or not this is reproducible on any other machines you can test.
I can try it on a couple other systems, but probably not until tomorrow.
Tomorrow (or even later) works just fine for me. :-)
Quoted 5 lines
Quoted 4 lines
Can you please change
dbg()topr_info()underACPI_NOTIFY_BUS_CHECKandACPI_NOTIFY_DEVICE_CHECKinhotplug_event()(acpiphp_glue.c), grep the boot dmesg log for "check notify" and send the result? I'm wondering what's going on there.Quoted 11 lines
$ dmesg | grep "check notify" [ 1.633228] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 2.472004] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 2.477288] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 2.482571] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 2.482579] hotplug_event: Device check notify on \_SB_.PCI0.PEX6 [ 8.204953] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 8.209632] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 8.214272] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 8.218894] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 8.218901] hotplug_event: Device check notify on \_SB_.PCI0.PEX6Quoted 6 lines
So I guess the PEXn things are PCIe ports and we get two notifications for each of them, so everything below them gets rescanned.
I've just talked to Bjorn about that and we don't seem to have a good idea how to handle this. The notifies shouldn't be there, but we kind of have to handle them.
Quoted 5 lines
What I said was "We aren't going to be able to get rid of the notifications, but we can probably figure out how to clean up some of the output." I don't think there's anything *wrong* with the notifications themselves, and as far as I know, there's nothing in the spec that limits how many notifications the platform can send.
One would think that it wouldn't send notifications if nothing changed, however.
Quoted 6 lines
Quoted 3 lines
I guess we could suppress the output from repeated bridge scans. Alternatively, we could just blacklist this particular system somehow if the problem is specific to it.
I'm opposed to blacklisting in principle because this doesn't sound like a platform defect.
I'm not sure about that. Sending notifications without a reason is not a good practice at least, even if the spec does't forbid it directly.
There are many things for which there are no "don't do that" statements in the spec which nevertheless may be regarded as incorrect behavior. Therefore I'm opposed to the "the spec doesn't forbid that openly, so it has to be OK to do it" way of thinking. Sorry.
Quoted 3 lines
And I think we pretty much have to
re-enumerate for each Device Check, because that's what the spec tells us to do.
Yes, it is.
Quoted 9 lines
My goal is for PCI to print stuff only for significant events, when we discover something new, or when we change something (BAR, bridge window, etc.) A hot-plug event, e.g., a Device Check, is arguably significant all by itself, but that's in ACPI, and it sounds like we only have a
dbg()there now. The repeated PCI bridge info seems like it's useless. I've looked at cleaning up some of that in the past, but it wasn't trivial and it wasn't urgent enough at the time. But it sure sounds urgent now.
Quoted 7 lines
Alex, would you mind collecting the full dmesg or console log (with "debug
ignore_loglevel") and "lspci -vv" output and attaching them to a bugzilla? Keep thehotplug_event()pr_info()change so we have more clues about what triggers things. This seems like an interesting situation, and there might be other things we can learn from it. It looks like the "hotplug settings" output is probably more than is necessary also.
That can be changed to dev_dbg() I think and no one will really miss it. :-)
Thanks,
Rafael
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Re: Excess dmesg output from ACPIPHP on boot (was: Re: [PATCH 25/30] ACPI / hotplug / PCI: Check for new devices on enabled slots)
In reply to Bjorn HelgaasQuoted 224 lines · Bjorn Helgaas
Quoted 192 lines · Rafael J. Wysocki
Quoted 112 lines · Alex Williamson
Quoted 111 lines · Rafael J. Wysocki
Quoted 110 lines · Alex Williamson
Quoted 98 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Thursday, September 05, 2013 08:21:41 AM Alex Williamson wrote:
[...]
Quoted 85 lines
Quoted 41 lines
Quoted 41 lines
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settingsQuoted 2 lines
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
That depends on how many bus check/device check events they generate on boot.
My test machines don't generate them during boot at all (even the one with a Thunderbolt connector), so I don't see the messages in question during boot on any of them. Mika doesn't see them either I suppose, or he would have told me about that before.
And let's just make it clear that it is not usual or even OK to generate bus checks or device checks during boot like this. And since the changes in question have been in linux-next since right after the 3.11 merge window, I think that someone would have complained already had that been a common issue.
Of course, we need to deal with that somehow nevertheless. :-)
Quoted 14 lines
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y$ dmesg | wc 5697 49935 384368$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered-- vs --
#
CONFIG_HOTPLUG_PCI_ACPIis not setQuoted 8 lines
$ dmesg | wc 1053 9176 71652$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registeredSo it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good.
The "no hotplug settings from platform" message is from
pci_configure_slot(). I think the messages you're seeing are from the call to it inacpiphp_set_hpp_values()which is called byenable_slot().Quoted 7 lines
There, I think, we can simply check the return value of
pci_scan_slot()and if that is 0 (no new devices), we can just skip everything under the call to__pci_bus_assign_resources().However, we can't skip the scanning of bridges, if any, because there may be new devices below them and I guess that's what takes so much time on your machine.
Quoted 8 lines
OK, one piece is missing. We may need to evaluate
_OSCafter handling each event to let the platform know the status.Can you please check if the appended patch makes any difference (with the previous fix applied, of course)?
If fact, it is two patches combined. One of them optimizes
enable_slot()slightly and the other adds the missing_OSCevaluation.Better, still double the output:
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
$ dmesg | wc 2169 19047 152710I see.
What about the timing?
~40s below vs ~29s for acpiphp config'd out above.
Well, that's better than before.
I'll prepare "official" patches with the last changes then too.
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
$ dmesg | tail --lines=1 [ 39.980918] Ebtables v2.0 registeredHere's another interesting stat:
$ dmesg | colrm 1 15 | sort | uniq -c | sort -nr | head --lines=25 73 pci 0000:00:1f.0: BAR 13: [io 0x1000-0x107f] has bogus alignment 73 pci 0000:00:1e.0: PCI bridge to [bus 06] 64 pci 0000:00:1e.0: bridge window [mem 0x81100000-0x812fffff 64bit pref] 64 pci 0000:00:1e.0: bridge window [mem 0x80f00000-0x810fffff] 64 pci 0000:00:1e.0: bridge window [io 0x7000-0x7fff] 38 pci 0000:00:1c.4: PCI bridge to [bus 05] 38 pci 0000:00:1c.4: bridge window [mem 0xf4f00000-0xf4ffffff] 38 pci 0000:00:1c.0: PCI bridge to [bus 04] 38 pci 0000:00:07.0: PCI bridge to [bus 03] 38 pci 0000:00:07.0: bridge window [mem 0xf2000000-0xf40fffff] 38 pci 0000:00:07.0: bridge window [mem 0xe0000000-0xf1ffffff 64bit pref] 38 pci 0000:00:07.0: bridge window [io 0x4000-0x4fff] 38 pci 0000:00:03.0: PCI bridge to [bus 02] 38 pci 0000:00:03.0: bridge window [mem 0xf4e00000-0xf4efffff] 38 pci 0000:00:03.0: bridge window [mem 0xd0000000-0xdfffffff 64bit pref] 38 pci 0000:00:03.0: bridge window [io 0x3000-0x3fff] 38 pci 0000:00:01.0: PCI bridge to [bus 01] 38 pci 0000:00:01.0: bridge window [mem 0xf4100000-0xf4bfffff] 38 pci 0000:00:01.0: bridge window [io 0x2000-0x2fff] 37 pci 0000:00:1c.4: bridge window [mem 0x80c00000-0x80dfffff 64bit pref] 37 pci 0000:00:1c.4: bridge window [io 0x6000-0x6fff] 37 pci 0000:00:1c.0: bridge window [mem 0x80a00000-0x80bfffff 64bit pref] 37 pci 0000:00:1c.0: bridge window [mem 0x80800000-0x809fffff] 37 pci 0000:00:1c.0: bridge window [io 0x5000-0x5fff] 36 pci 0000:00:01.0: bridge window [mem 0x80000000-0x807fffff 64bit pref]Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
This is nearly the entire difference, just 25 lines repeated over and over.
Can you check how many times the lines above are repeated?
Quoted 9 lines
Quoted 7 lines
Well, this is the bridge sizing I talked about previously. We still get apparently spurious bus check/device check events and they trigger bridge scans.
I'm not sure what to do about that and I wonder whether or not this is reproducible on any other machines you can test.
I can try it on a couple other systems, but probably not until tomorrow.
Tomorrow (or even later) works just fine for me. :-)
Quoted 5 lines
Quoted 4 lines
Can you please change
dbg()topr_info()underACPI_NOTIFY_BUS_CHECKandACPI_NOTIFY_DEVICE_CHECKinhotplug_event()(acpiphp_glue.c), grep the boot dmesg log for "check notify" and send the result? I'm wondering what's going on there.Quoted 11 lines
$ dmesg | grep "check notify" [ 1.633228] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 2.472004] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 2.477288] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 2.482571] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 2.482579] hotplug_event: Device check notify on \_SB_.PCI0.PEX6 [ 8.204953] hotplug_event: Device check notify on \_SB_.PCI0.PEX2 [ 8.209632] hotplug_event: Device check notify on \_SB_.PCI0.PEX3 [ 8.214272] hotplug_event: Device check notify on \_SB_.PCI0.PEX4 [ 8.218894] hotplug_event: Device check notify on \_SB_.PCI0.PEX5 [ 8.218901] hotplug_event: Device check notify on \_SB_.PCI0.PEX6Quoted 6 lines
So I guess the PEXn things are PCIe ports and we get two notifications for each of them, so everything below them gets rescanned.
I've just talked to Bjorn about that and we don't seem to have a good idea how to handle this. The notifies shouldn't be there, but we kind of have to handle them.
What I said was "We aren't going to be able to get rid of the notifications, but we can probably figure out how to clean up some of the output." I don't think there's anything *wrong* with the notifications themselves, and as far as I know, there's nothing in the spec that limits how many notifications the platform can send.
Quoted 3 lines
I guess we could suppress the output from repeated bridge scans. Alternatively, we could just blacklist this particular system somehow if the problem is specific to it.
I'm opposed to blacklisting in principle because this doesn't sound like a platform defect. And I think we pretty much have to re-enumerate for each Device Check, because that's what the spec tells us to do.
My goal is for PCI to print stuff only for significant events, when we discover something new, or when we change something (BAR, bridge window, etc.) A hot-plug event, e.g., a Device Check, is arguably significant all by itself, but that's in ACPI, and it sounds like we only have a
dbg()there now. The repeated PCI bridge info seems like it's useless. I've looked at cleaning up some of that in the past, but it wasn't trivial and it wasn't urgent enough at the time. But it sure sounds urgent now.
Quoted 7 lines
Alex, would you mind collecting the full dmesg or console log (with "debug
ignore_loglevel") and "lspci -vv" output and attaching them to a bugzilla? Keep thehotplug_event()pr_info()change so we have more clues about what triggers things. This seems like an interesting situation, and there might be other things we can learn from it. It looks like the "hotplug settings" output is probably more than is necessary also.
bz here:
https://bugzilla.kernel.org/show_bug.cgi?id=60865
Thanks,
Alex
PATCH 1/1 ACPI / hotplug / PCI: Avoid parent bus rescans on spurious device checks
From: Rafael J. Wysocki <[email protected]>
In the current ACPIPHP notify handler we always go directly for a rescan of the parent bus if we get a device check notification for a device that is not a bridge. However, this obviously is overzealous if nothing really changes, because this way we may rescan the whole PCI hierarchy pretty much in vain.
That happens on Alex Williamson's machine whose ACPI tables contain device objects that are supposed to coresspond to PCIe root ports, but those ports aren't physically present (or at least they aren't visible in the PCI config space to us). The BIOS generates multiple device check notifies for those objects during boot and for each of them we go straight for the parent bus rescan, but the parent bus is the root bus in this particular case. In consequence, we rescan the whole PCI bus from the top several times in a row, which is completely unnecessary, increases boot time by 50% (after previous fixes) and generates excess dmesg output from the PCI subsystem.
Fix the problem by checking if we can find anything new in the slot corresponding to the device we've got a device check notify for and doing nothig if that's not the case.
The spec (ACPI 5.0, Section 5.6.6) appears to mandate this behavior, as it says:
Device Check. Used to notify OSPM that the device either appeared or disappeared. If the device has appeared, OSPM will re-enumerate from the parent. If the device has disappeared, OSPM will invalidate the state of the device. OSPM may optimize out re-enumeration.
Therefore, according to the spec, we are free to do nothing if nothing changes.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60865
---
On top of linux-pm.git/linux-next.
Thanks,
Rafael
--- drivers/pci/hotplug/acpiphp_glue.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +25 -7
@@ -528,6 +528,16 @@ static void check_hotplug_bridge(struct } } +static int acpiphp_rescan_slot (struct acpiphp_slot *slot) +{ +struct acpiphp_func *func; + +list_for_each_entry (func, &slot->funcs, sibling) +acpiphp_bus_add (func_to_handle (func)); + +return pci_scan_slot (slot->bus,PCI_DEVFN (slot->device,0 )); +} +/** * enable_slot - enable, configure a slot * @slot: slot to be enabled
@@ -544,10 +554,7 @@ static void __ref enable_slot(struct acpLIST_HEAD (add_list);int nr_found; -list_for_each_entry (func, &slot->funcs, sibling) -acpiphp_bus_add (func_to_handle (func)); - - nr_found =pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); + nr_found =acpiphp_rescan_slot (slot); max =acpiphp_max_busnr (bus);for (pass =0 ; pass <2 ; pass++) {list_for_each_entry (dev, &bus->devices, bus_list) {
@@ -840,11 +847,22 @@ static void hotplug_event(acpi_handle hacase ACPI_NOTIFY_DEVICE_CHECK :/* device check */ dbg ("%s: Device check notify on %s\n" , __func__, objname); -if (bridge) +if (bridge) {acpiphp_check_bridge (bridge); -else -acpiphp_check_bridge (func->parent); + }else { +struct acpiphp_slot *slot = func->slot; +int ret; +/* +* Check if anything has changed in the slot and rescan +* from the parent if that's the case. +*/ +mutex_lock (&slot->crit_sect); + ret =acpiphp_rescan_slot (slot); +mutex_unlock (&slot->crit_sect); +if (ret) +acpiphp_check_bridge (func->parent); + }break ;case ACPI_NOTIFY_EJECT_REQUEST :
Re: [PATCH] ACPI / hotplug / PCI: Avoid parent bus rescans on spurious device checks
Quoted 32 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
In the current ACPIPHP notify handler we always go directly for a rescan of the parent bus if we get a device check notification for a device that is not a bridge. However, this obviously is overzealous if nothing really changes, because this way we may rescan the whole PCI hierarchy pretty much in vain.
That happens on Alex Williamson's machine whose ACPI tables contain device objects that are supposed to coresspond to PCIe root ports, but those ports aren't physically present (or at least they aren't visible in the PCI config space to us). The BIOS generates multiple device check notifies for those objects during boot and for each of them we go straight for the parent bus rescan, but the parent bus is the root bus in this particular case. In consequence, we rescan the whole PCI bus from the top several times in a row, which is completely unnecessary, increases boot time by 50% (after previous fixes) and generates excess dmesg output from the PCI subsystem.
Fix the problem by checking if we can find anything new in the slot corresponding to the device we've got a device check notify for and doing nothig if that's not the case.
The spec (ACPI 5.0, Section 5.6.6) appears to mandate this behavior, as it says:
Device Check. Used to notify OSPM that the device either appeared or disappeared. If the device has appeared, OSPM will re-enumerate from the parent. If the device has disappeared, OSPM will invalidate the state of the device. OSPM may optimize out re-enumeration.
Quoted 7 lines
Therefore, according to the spec, we are free to do nothing if nothing changes.
References: https://bugzilla.kernel.org/show_bug.cgi?id=60865
Reported-by Alex Williamson <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>---
Works for me. Thanks!
Quoted 68 lines
On top of linux-pm.git/linux-next.
Thanks,
Rafael--- drivers/pci/hotplug/acpiphp_glue.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-)Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c +25
-7@@ -528,6 +528,16 @@ static void check_hotplug_bridge(struct } } +static int acpiphp_rescan_slot (struct acpiphp_slot *slot) +{ +struct acpiphp_func *func; + +list_for_each_entry (func, &slot->funcs, sibling) +acpiphp_bus_add (func_to_handle (func)); + +return pci_scan_slot (slot->bus,PCI_DEVFN (slot->device,0 )); +} +/** * enable_slot - enable, configure a slot * @slot: slot to be enabled @@ -544,10 +554,7 @@ static void __ref enable_slot(struct acpLIST_HEAD (add_list);int nr_found; -list_for_each_entry (func, &slot->funcs, sibling) -acpiphp_bus_add (func_to_handle (func)); - - nr_found =pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); + nr_found =acpiphp_rescan_slot (slot); max =acpiphp_max_busnr (bus);for (pass =0 ; pass <2 ; pass++) {list_for_each_entry (dev, &bus->devices, bus_list) {@@ -840,11 +847,22 @@ static void hotplug_event(acpi_handle hacase ACPI_NOTIFY_DEVICE_CHECK :/* device check */ dbg ("%s: Device check notify on %s\n" , __func__, objname); -if (bridge) +if (bridge) {acpiphp_check_bridge (bridge); -else -acpiphp_check_bridge (func->parent); + }else { +struct acpiphp_slot *slot = func->slot; +int ret; +/* +* Check if anything has changed in the slot and rescan +* from the parent if that's the case. +*/ +mutex_lock (&slot->crit_sect); + ret =acpiphp_rescan_slot (slot); +mutex_unlock (&slot->crit_sect); +if (ret) +acpiphp_check_bridge (func->parent); + }break ;case ACPI_NOTIFY_EJECT_REQUEST :
Re: [PATCH] ACPI / hotplug / PCI: Avoid parent bus rescans on spurious device checks
Quoted 36 lines · Alex Williamson
Quoted 35 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
In the current ACPIPHP notify handler we always go directly for a rescan of the parent bus if we get a device check notification for a device that is not a bridge. However, this obviously is overzealous if nothing really changes, because this way we may rescan the whole PCI hierarchy pretty much in vain.
That happens on Alex Williamson's machine whose ACPI tables contain device objects that are supposed to coresspond to PCIe root ports, but those ports aren't physically present (or at least they aren't visible in the PCI config space to us). The BIOS generates multiple device check notifies for those objects during boot and for each of them we go straight for the parent bus rescan, but the parent bus is the root bus in this particular case. In consequence, we rescan the whole PCI bus from the top several times in a row, which is completely unnecessary, increases boot time by 50% (after previous fixes) and generates excess dmesg output from the PCI subsystem.
Fix the problem by checking if we can find anything new in the slot corresponding to the device we've got a device check notify for and doing nothig if that's not the case.
The spec (ACPI 5.0, Section 5.6.6) appears to mandate this behavior, as it says:
Device Check. Used to notify OSPM that the device either appeared or disappeared. If the device has appeared, OSPM will re-enumerate from the parent. If the device has disappeared, OSPM will invalidate the state of the device. OSPM may optimize out re-enumeration.
Therefore, according to the spec, we are free to do nothing if nothing changes.
Quoted 8 lines
Quoted 4 lines
References: https://bugzilla.kernel.org/show_bug.cgi?id=60865
Reported-by Alex Williamson <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>---
Works for me. Thanks!
Tested-by Alex Williamson <[email protected]>
Great, thanks for testing.
Quoted 65 lines
Quoted 63 lines
--- drivers/pci/hotplug/acpiphp_glue.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-)Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c +25
-7@@ -528,6 +528,16 @@ static void check_hotplug_bridge(struct } } +static int acpiphp_rescan_slot (struct acpiphp_slot *slot) +{ +struct acpiphp_func *func; + +list_for_each_entry (func, &slot->funcs, sibling) +acpiphp_bus_add (func_to_handle (func)); + +return pci_scan_slot (slot->bus,PCI_DEVFN (slot->device,0 )); +} +/** * enable_slot - enable, configure a slot * @slot: slot to be enabled @@ -544,10 +554,7 @@ static void __ref enable_slot(struct acpLIST_HEAD (add_list);int nr_found; -list_for_each_entry (func, &slot->funcs, sibling) -acpiphp_bus_add (func_to_handle (func)); - - nr_found =pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); + nr_found =acpiphp_rescan_slot (slot); max =acpiphp_max_busnr (bus);for (pass =0 ; pass <2 ; pass++) {list_for_each_entry (dev, &bus->devices, bus_list) {@@ -840,11 +847,22 @@ static void hotplug_event(acpi_handle hacase ACPI_NOTIFY_DEVICE_CHECK :/* device check */ dbg ("%s: Device check notify on %s\n" , __func__, objname); -if (bridge) +if (bridge) {acpiphp_check_bridge (bridge); -else -acpiphp_check_bridge (func->parent); + }else { +struct acpiphp_slot *slot = func->slot; +int ret; +/* +* Check if anything has changed in the slot and rescan +* from the parent if that's the case. +*/ +mutex_lock (&slot->crit_sect); + ret =acpiphp_rescan_slot (slot); +mutex_unlock (&slot->crit_sect); +if (ret) +acpiphp_check_bridge (func->parent); + }break ;case ACPI_NOTIFY_EJECT_REQUEST :
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
[PATCH 0/2] Re: Excess dmesg output from ACPIPHP on boot
In reply to Rafael J. WysockiQuoted 118 lines · Rafael J. Wysocki
Quoted 117 lines · Alex Williamson
Quoted 116 lines · Rafael J. Wysocki
Quoted 105 lines · Alex Williamson
Quoted 104 lines · Rafael J. Wysocki
Quoted 1 line · Rafael J. Wysocki
On Thursday, September 05, 2013 08:21:41 AM Alex Williamson wrote:
[...]
Quoted 85 lines
Quoted 41 lines
Quoted 41 lines
[ 18.288122] pci 0000:00:00.0: no hotplug settings from platform [ 18.288127] pcieport 0000:00:01.0: no hotplug settings from platform [ 18.288142] pci 0000:01:00.0: no hotplug settings from platform [ 18.288157] pci 0000:01:00.1: no hotplug settings from platform [ 18.288162] pcieport 0000:00:03.0: no hotplug settings from platform [ 18.288176] pci 0000:02:00.0: no hotplug settings from platform [ 18.288190] pci 0000:02:00.1: no hotplug settings from platform [ 18.288195] pcieport 0000:00:07.0: no hotplug settings from platform [ 18.288209] pci 0000:03:00.0: no hotplug settings from platform [ 18.288224] pci 0000:03:00.1: no hotplug settings from platform [ 18.288228] pci 0000:00:14.0: no hotplug settings from platform [ 18.288233] pci 0000:00:14.1: no hotplug settings from platform [ 18.288237] pci 0000:00:14.2: no hotplug settings from platform [ 18.288242] pci 0000:00:16.0: no hotplug settings from platform [ 18.288247] pci 0000:00:16.1: no hotplug settings from platform [ 18.288251] pci 0000:00:16.2: no hotplug settings from platform [ 18.288256] pci 0000:00:16.3: no hotplug settings from platform [ 18.288260] pci 0000:00:16.4: no hotplug settings from platform [ 18.288265] pci 0000:00:16.5: no hotplug settings from platform [ 18.288269] pci 0000:00:16.6: no hotplug settings from platform [ 18.288274] pci 0000:00:16.7: no hotplug settings from platform [ 18.288278] pci 0000:00:1a.0: no hotplug settings from platform [ 18.288279] pci 0000:00:1a.0: using default PCI settings [ 18.288292] pci 0000:00:1a.1: no hotplug settings from platform [ 18.288293] pci 0000:00:1a.1: using default PCI settings [ 18.288307] ehci-pci 0000:00:1a.7: no hotplug settings from platform [ 18.288308] ehci-pci 0000:00:1a.7: using default PCI settings [ 18.288322] pci 0000:00:1b.0: no hotplug settings from platform [ 18.288327] pcieport 0000:00:1c.0: no hotplug settings from platform [ 18.288332] pcieport 0000:00:1c.4: no hotplug settings from platform [ 18.288344] pci 0000:05:00.0: no hotplug settings from platform [ 18.288349] pci 0000:00:1d.0: no hotplug settings from platform [ 18.288350] pci 0000:00:1d.0: using default PCI settings [ 18.288360] pci 0000:00:1d.1: no hotplug settings from platform [ 18.288361] pci 0000:00:1d.1: using default PCI settings [ 18.288374] pci 0000:00:1d.2: no hotplug settings from platform [ 18.288374] pci 0000:00:1d.2: using default PCI settings [ 18.288387] pci 0000:00:1d.3: no hotplug settings from platform [ 18.288387] pci 0000:00:1d.3: using default PCI settingsQuoted 2 lines
Quoted 2 lines
The boot is noticeably slower. What's going to happen on systems that actually have a significant I/O topology vs my little workstation?
That depends on how many bus check/device check events they generate on boot.
My test machines don't generate them during boot at all (even the one with a Thunderbolt connector), so I don't see the messages in question during boot on any of them. Mika doesn't see them either I suppose, or he would have told me about that before.
And let's just make it clear that it is not usual or even OK to generate bus checks or device checks during boot like this. And since the changes in question have been in linux-next since right after the 3.11 merge window, I think that someone would have complained already had that been a common issue.
Of course, we need to deal with that somehow nevertheless. :-)
Quoted 14 lines
Just to give you an idea:
CONFIG_HOTPLUG_PCI_ACPI=y$ dmesg | wc 5697 49935 384368$ dmesg | tail --lines=1 [ 53.137123] Ebtables v2.0 registered-- vs --
#
CONFIG_HOTPLUG_PCI_ACPIis not setQuoted 8 lines
$ dmesg | wc 1053 9176 71652$dmesg | tail --lines=1
[ 28.917220] Ebtables v2.0 registeredSo it spews out 5x more output with acpiphp enabled and takes and extra 24s to boot (nearly 2x). Not good.
The "no hotplug settings from platform" message is from
pci_configure_slot(). I think the messages you're seeing are from the call to it inacpiphp_set_hpp_values()which is called byenable_slot().Quoted 7 lines
There, I think, we can simply check the return value of
pci_scan_slot()and if that is 0 (no new devices), we can just skip everything under the call to__pci_bus_assign_resources().However, we can't skip the scanning of bridges, if any, because there may be new devices below them and I guess that's what takes so much time on your machine.
OK, one piece is missing. We may need to evaluate
_OSCafter handling each event to let the platform know the status.Can you please check if the appended patch makes any difference (with the previous fix applied, of course)?
Quoted 7 lines
Quoted 2 lines
If fact, it is two patches combined. One of them optimizes
enable_slot()slightly and the other adds the missing_OSCevaluation.Better, still double the output:
$ dmesg | wc 2169 19047 152710I see.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
What about the timing?
~40s below vs ~29s for acpiphp config'd out above.
Well, that's better than before.
I'll prepare "official" patches with the last changes then too.
The patches follow as [1/2] and [2/2]. The change in enable_slot() is literally the same, but the _OST patch is somewhat different, although the changes mostly affect the eject code path and the notifies that we don't actually handle, so they should not matter on your machine.
Thanks,
Rafael
PATCH 1/2 ACPI / hotplug / PCI: Avoid doing too much for spurious notifies
From: Rafael J. Wysocki <[email protected]>
Sometimes we may get a spurious device check or bus check notify for a hotplug device and in those cases we should avoid doing all of the configuration work needed when something actually changes. To that end, check the return value of pci_scan_slot() in enable_slot() and bail out early if it is 0.
This turns out to help reduce the amount of diagnostic output from the ACPIPHP subsystem and speed up boot on at least one system that generates multiple device check notifies for PCIe ports during boot.
--- drivers/pci/hotplug/acpiphp_glue.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +6 -3
@@ -542,12 +542,12 @@ static void __ref enable_slot(struct acpstruct acpiphp_func *func;int max, pass;LIST_HEAD (add_list); +int nr_found;list_for_each_entry (func, &slot->funcs, sibling)acpiphp_bus_add (func_to_handle (func)); -pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); - + nr_found =pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); max =acpiphp_max_busnr (bus);for (pass =0 ; pass <2 ; pass++) {list_for_each_entry (dev, &bus->devices, bus_list) {
@@ -566,8 +566,11 @@ static void __ref enable_slot(struct acp } } } -__pci_bus_assign_resources (bus, &add_list,NULL ); +/* Nothing more to do here if there are no new devices on this bus. */ +if (!nr_found && (slot->flags &SLOT_ENABLED )) +return ; +acpiphp_sanitize_bus (bus);acpiphp_set_hpp_values (bus);acpiphp_set_acpi_region (slot);
Re: [PATCH 1/2] ACPI / hotplug / PCI: Avoid doing too much for spurious notifies
Quoted 42 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Sometimes we may get a spurious device check or bus check notify for a hotplug device and in those cases we should avoid doing all of the configuration work needed when something actually changes. To that end, check the return value of
pci_scan_slot()inenable_slot()and bail out early if it is 0.This turns out to help reduce the amount of diagnostic output from the ACPIPHP subsystem and speed up boot on at least one system that generates multiple device check notifies for PCIe ports during boot.
Reported-by Alex Williamson <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/pci/hotplug/acpiphp_glue.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c +2
-2@@ -542,12 +542,12 @@ static void __ref enable_slot(struct acpstruct acpiphp_func *func;int max, pass;LIST_HEAD (add_list); +int nr_found;list_for_each_entry (func, &slot->funcs, sibling)acpiphp_bus_add (func_to_handle (func)); -pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); - + nr_found =pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); max =acpiphp_max_busnr (bus);for (pass =0 ; pass <2 ; pass++) {list_for_each_entry (dev, &bus->devices, bus_list) {@@ -566,8 +566,11 @@ static void __ref enable_slot(struct acp } }
drivers/pci/hotplug/acpiphp_glue.c static void __ref enable_slot(struct acp · line 576
Quoted 10 lines
drivers/pci/hotplug/acpiphp_glue.c +4
-1} -__pci_bus_assign_resources (bus, &add_list,NULL ); +/* Nothing more to do here if there are no new devices on this bus. */ +if (!nr_found && (slot->flags &SLOT_ENABLED )) +return ; +acpiphp_sanitize_bus (bus);acpiphp_set_hpp_values (bus);acpiphp_set_acpi_region (slot);
why not just returning early before size bridges and assign unassign resources?
Yinghai
Re: [PATCH 1/2] ACPI / hotplug / PCI: Avoid doing too much for spurious notifies
Quoted 47 lines · Yinghai Lu
Quoted 46 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Sometimes we may get a spurious device check or bus check notify for a hotplug device and in those cases we should avoid doing all of the configuration work needed when something actually changes. To that end, check the return value of
pci_scan_slot()inenable_slot()and bail out early if it is 0.This turns out to help reduce the amount of diagnostic output from the ACPIPHP subsystem and speed up boot on at least one system that generates multiple device check notifies for PCIe ports during boot.
Reported-by Alex Williamson <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/pci/hotplug/acpiphp_glue.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-)Index:
linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================drivers/pci/hotplug/acpiphp_glue.c +4
-3@@ -542,12 +542,12 @@ static void __ref enable_slot(struct acpstruct acpiphp_func *func;int max, pass;LIST_HEAD (add_list); +int nr_found;list_for_each_entry (func, &slot->funcs, sibling)acpiphp_bus_add (func_to_handle (func)); -pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); - + nr_found =pci_scan_slot (bus,PCI_DEVFN (slot->device,0 )); max =acpiphp_max_busnr (bus);for (pass =0 ; pass <2 ; pass++) {list_for_each_entry (dev, &bus->devices, bus_list) {@@ -566,8 +566,11 @@ static void __ref enable_slot(struct acp } } } -__pci_bus_assign_resources (bus, &add_list,NULL ); +/* Nothing more to do here if there are no new devices on this bus. */ +if (!nr_found && (slot->flags &SLOT_ENABLED ))
Quoted 8 lines
drivers/pci/hotplug/acpiphp_glue.c static void __ref enable_slot(struct acp · line 576
Quoted 6 lines
drivers/pci/hotplug/acpiphp_glue.c +2
-0+return ; +acpiphp_sanitize_bus (bus);acpiphp_set_hpp_values (bus);acpiphp_set_acpi_region (slot);why not just returning early before size bridges and assign unassign resources?
Because we still need to do that even if pci_scan_slot() returns 0.
There may be new devices down in the hierarchy and we need to look for them.
Thanks,
Rafael
PATCH 2/2 ACPI / hotplug / PCI: Use _OST to notify firmware about notify status
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
The spec suggests that we should use _OST to inform the platform of the status of notifications it sends us, for example so that it doesn't repeate a notification that has been handled already.
For this reason, add _OST evaluation to the ACPIPHP subsystem.
This turns out to help reduce the amount of diagnostic output from the ACPIPHP subsystem and speed up boot on at least one system that generates multiple device check notifies for PCIe ports during boot.
--- drivers/pci/hotplug/acpiphp_glue.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +17 -4
@@ -870,6 +870,8 @@ static void hotplug_event_work(struct wohotplug_event (hp_work->handle, hp_work->type, context);acpi_scan_lock_release (); +acpi_evaluate_hotplug_ost (hp_work->handle, hp_work->type, +ACPI_OST_SC_SUCCESS ,NULL );kfree (hp_work);/* allocated in handle_hotplug_event() */ put_bridge (context->func.parent); }
@@ -885,11 +887,15 @@ static void hotplug_event_work(struct wostatic void handle_hotplug_event (acpi_handle handle,u32 type,void *data) {struct acpiphp_context *context; +u32 ost_code =ACPI_OST_SC_SUCCESS ;switch (type) {case ACPI_NOTIFY_BUS_CHECK :case ACPI_NOTIFY_DEVICE_CHECK : +break ;case ACPI_NOTIFY_EJECT_REQUEST : + ost_code =ACPI_OST_SC_EJECT_IN_PROGRESS ; +acpi_evaluate_hotplug_ost (handle, type, ost_code,NULL );break ;case ACPI_NOTIFY_DEVICE_WAKE :
@@ -898,20 +904,21 @@ static void handle_hotplug_event(acpi_hacase ACPI_NOTIFY_FREQUENCY_MISMATCH :acpi_handle_err (handle,"Device cannot be configured due " "to a frequency mismatch\n" ); -return ; + goto out;case ACPI_NOTIFY_BUS_MODE_MISMATCH :acpi_handle_err (handle,"Device cannot be configured due " "to a bus mode mismatch\n" ); -return ; + goto out;case ACPI_NOTIFY_POWER_FAULT :acpi_handle_err (handle,"Device has suffered a power fault\n" ); -return ; + goto out;default :acpi_handle_warn (handle,"Unsupported event type 0x%x\n" , type); -return ; + ost_code =ACPI_OST_SC_UNRECOGNIZED_NOTIFY ; + goto out; }mutex_lock (&acpiphp_context_lock);
@@ -920,8 +927,14 @@ static void handle_hotplug_event(acpi_haget_bridge (context->func.parent);acpiphp_put_context (context);alloc_acpi_hp_work (handle, type, context, hotplug_event_work); +mutex_unlock (&acpiphp_context_lock); +return ; }mutex_unlock (&acpiphp_context_lock); + ost_code =ACPI_OST_SC_NON_SPECIFIC_FAILURE ; + + out: +acpi_evaluate_hotplug_ost (handle, type, ost_code,NULL ); }/*