[RFC][PATCH 8/8] ACPI / hotplug / PCI: Merge hotplug event handling functions

2013-07-08 Thread Rafael J. Wysocki
From: Rafael J. Wysocki 

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.

Signed-off-by: Rafael J. Wysocki 
---
 drivers/pci/hotplug/acpiphp_glue.c |  156 +++--
 1 file changed, 66 insertions(+), 90 deletions(-)

Index: linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===
--- linux-pm.orig/drivers/pci/hotplug/acpiphp_glue.c
+++ linux-pm/drivers/pci/hotplug/acpiphp_glue.c
@@ -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 notif
 
 
 static 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,
-   _dock_ops, newfunc,
+   _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_hand
acpiphp_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, );
 
@@ -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)
+   

[RFC][PATCH 8/8] ACPI / hotplug / PCI: Merge hotplug event handling functions

2013-07-08 Thread Rafael J. Wysocki
From: Rafael J. Wysocki rafael.j.wyso...@intel.com

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.

Signed-off-by: Rafael J. Wysocki rafael.j.wyso...@intel.com
---
 drivers/pci/hotplug/acpiphp_glue.c |  156 +++--
 1 file changed, 66 insertions(+), 90 deletions(-)

Index: linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===
--- linux-pm.orig/drivers/pci/hotplug/acpiphp_glue.c
+++ linux-pm/drivers/pci/hotplug/acpiphp_glue.c
@@ -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 notif
 
 
 static 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_hand
acpiphp_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