[PATCH v2 2/6] ACPI / hotplug / PCI: Define hotplug context lock in the core

2014-02-01 Thread Rafael J. Wysocki
From: Rafael J. Wysocki 

Subsequent changes will require the ACPI core to acquire the lock
protecting the ACPIPHP hotplug contexts, so move the definition of
the lock to the core and change its name to be more generic.

Signed-off-by: Rafael J. Wysocki 
---
 drivers/acpi/scan.c|   11 +
 drivers/pci/hotplug/acpiphp_glue.c |   41 ++---
 include/acpi/acpi_bus.h|2 +
 3 files changed, 33 insertions(+), 21 deletions(-)

Index: linux-pm/drivers/acpi/scan.c
===
--- linux-pm.orig/drivers/acpi/scan.c
+++ linux-pm/drivers/acpi/scan.c
@@ -43,6 +43,7 @@ DEFINE_MUTEX(acpi_device_lock);
 LIST_HEAD(acpi_wakeup_device_list);
 static LIST_HEAD(acpi_device_del_list);
 static DEFINE_MUTEX(acpi_device_del_lock);
+static DEFINE_MUTEX(acpi_hp_context_lock);
 
 struct acpi_device_bus_id{
char bus_id[15];
@@ -62,6 +63,16 @@ void acpi_scan_lock_release(void)
 }
 EXPORT_SYMBOL_GPL(acpi_scan_lock_release);
 
+void acpi_lock_hp_context(void)
+{
+   mutex_lock(_hp_context_lock);
+}
+
+void acpi_unlock_hp_context(void)
+{
+   mutex_unlock(_hp_context_lock);
+}
+
 int acpi_scan_add_handler(struct acpi_scan_handler *handler)
 {
if (!handler || !handler->attach)
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
@@ -58,7 +58,6 @@
 
 static LIST_HEAD(bridge_list);
 static DEFINE_MUTEX(bridge_mutex);
-static DEFINE_MUTEX(acpiphp_context_lock);
 
 static void handle_hotplug_event(acpi_handle handle, u32 type, void *data);
 static void acpiphp_sanitize_bus(struct pci_bus *bus);
@@ -75,7 +74,7 @@ static void acpiphp_context_handler(acpi
  * acpiphp_init_context - Create hotplug context and grab a reference to it.
  * @adev: ACPI device object to create the context for.
  *
- * Call under acpiphp_context_lock.
+ * Call under acpi_hp_context_lock.
  */
 static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev)
 {
@@ -100,7 +99,7 @@ static struct acpiphp_context *acpiphp_i
  * 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.
+ * Call under acpi_hp_context_lock.
  */
 static struct acpiphp_context *acpiphp_get_context(acpi_handle handle)
 {
@@ -122,7 +121,7 @@ static struct acpiphp_context *acpiphp_g
  *
  * The context object is removed if there are no more references to it.
  *
- * Call under acpiphp_context_lock.
+ * Call under acpi_hp_context_lock.
  */
 static void acpiphp_put_context(struct acpiphp_context *context)
 {
@@ -151,7 +150,7 @@ static void free_bridge(struct kref *kre
struct acpiphp_slot *slot, *next;
struct acpiphp_func *func, *tmp;
 
-   mutex_lock(_context_lock);
+   acpi_lock_hp_context();
 
bridge = container_of(kref, struct acpiphp_bridge, ref);
 
@@ -175,7 +174,7 @@ static void free_bridge(struct kref *kre
pci_dev_put(bridge->pci_dev);
kfree(bridge);
 
-   mutex_unlock(_context_lock);
+   acpi_unlock_hp_context();
 }
 
 /*
@@ -291,17 +290,17 @@ static acpi_status register_slot(acpi_ha
device = (adr >> 16) & 0x;
function = adr & 0x;
 
-   mutex_lock(_context_lock);
+   acpi_lock_hp_context();
context = acpiphp_init_context(adev);
if (!context) {
-   mutex_unlock(_context_lock);
+   acpi_unlock_hp_context();
acpi_handle_err(handle, "No hotplug context\n");
return AE_NOT_EXIST;
}
newfunc = >func;
newfunc->function = function;
newfunc->parent = bridge;
-   mutex_unlock(_context_lock);
+   acpi_unlock_hp_context();
 
if (acpi_has_method(handle, "_EJ0"))
newfunc->flags = FUNC_HAS_EJ0;
@@ -319,9 +318,9 @@ static acpi_status register_slot(acpi_ha
 
slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
if (!slot) {
-   mutex_lock(_context_lock);
+   acpi_lock_hp_context();
acpiphp_put_context(context);
-   mutex_unlock(_context_lock);
+   acpi_unlock_hp_context();
return AE_NO_MEMORY;
}
 
@@ -396,7 +395,7 @@ static struct acpiphp_bridge *acpiphp_ha
struct acpiphp_context *context;
struct acpiphp_bridge *bridge = NULL;
 
-   mutex_lock(_context_lock);
+   acpi_lock_hp_context();
context = acpiphp_get_context(handle);
if (context) {
bridge = context->bridge;
@@ -405,7 +404,7 @@ static struct acpiphp_bridge *acpiphp_ha
 
acpiphp_put_context(context);
}
-   mutex_unlock(_context_lock);
+   acpi_unlock_hp_context();
return bridge;
 }
 
@@ -796,12 +795,12 @@ 

[PATCH v2 2/6] ACPI / hotplug / PCI: Define hotplug context lock in the core

2014-02-01 Thread Rafael J. Wysocki
From: Rafael J. Wysocki rafael.j.wyso...@intel.com

Subsequent changes will require the ACPI core to acquire the lock
protecting the ACPIPHP hotplug contexts, so move the definition of
the lock to the core and change its name to be more generic.

Signed-off-by: Rafael J. Wysocki rafael.j.wyso...@intel.com
---
 drivers/acpi/scan.c|   11 +
 drivers/pci/hotplug/acpiphp_glue.c |   41 ++---
 include/acpi/acpi_bus.h|2 +
 3 files changed, 33 insertions(+), 21 deletions(-)

Index: linux-pm/drivers/acpi/scan.c
===
--- linux-pm.orig/drivers/acpi/scan.c
+++ linux-pm/drivers/acpi/scan.c
@@ -43,6 +43,7 @@ DEFINE_MUTEX(acpi_device_lock);
 LIST_HEAD(acpi_wakeup_device_list);
 static LIST_HEAD(acpi_device_del_list);
 static DEFINE_MUTEX(acpi_device_del_lock);
+static DEFINE_MUTEX(acpi_hp_context_lock);
 
 struct acpi_device_bus_id{
char bus_id[15];
@@ -62,6 +63,16 @@ void acpi_scan_lock_release(void)
 }
 EXPORT_SYMBOL_GPL(acpi_scan_lock_release);
 
+void acpi_lock_hp_context(void)
+{
+   mutex_lock(acpi_hp_context_lock);
+}
+
+void acpi_unlock_hp_context(void)
+{
+   mutex_unlock(acpi_hp_context_lock);
+}
+
 int acpi_scan_add_handler(struct acpi_scan_handler *handler)
 {
if (!handler || !handler-attach)
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
@@ -58,7 +58,6 @@
 
 static LIST_HEAD(bridge_list);
 static DEFINE_MUTEX(bridge_mutex);
-static DEFINE_MUTEX(acpiphp_context_lock);
 
 static void handle_hotplug_event(acpi_handle handle, u32 type, void *data);
 static void acpiphp_sanitize_bus(struct pci_bus *bus);
@@ -75,7 +74,7 @@ static void acpiphp_context_handler(acpi
  * acpiphp_init_context - Create hotplug context and grab a reference to it.
  * @adev: ACPI device object to create the context for.
  *
- * Call under acpiphp_context_lock.
+ * Call under acpi_hp_context_lock.
  */
 static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev)
 {
@@ -100,7 +99,7 @@ static struct acpiphp_context *acpiphp_i
  * 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.
+ * Call under acpi_hp_context_lock.
  */
 static struct acpiphp_context *acpiphp_get_context(acpi_handle handle)
 {
@@ -122,7 +121,7 @@ static struct acpiphp_context *acpiphp_g
  *
  * The context object is removed if there are no more references to it.
  *
- * Call under acpiphp_context_lock.
+ * Call under acpi_hp_context_lock.
  */
 static void acpiphp_put_context(struct acpiphp_context *context)
 {
@@ -151,7 +150,7 @@ static void free_bridge(struct kref *kre
struct acpiphp_slot *slot, *next;
struct acpiphp_func *func, *tmp;
 
-   mutex_lock(acpiphp_context_lock);
+   acpi_lock_hp_context();
 
bridge = container_of(kref, struct acpiphp_bridge, ref);
 
@@ -175,7 +174,7 @@ static void free_bridge(struct kref *kre
pci_dev_put(bridge-pci_dev);
kfree(bridge);
 
-   mutex_unlock(acpiphp_context_lock);
+   acpi_unlock_hp_context();
 }
 
 /*
@@ -291,17 +290,17 @@ static acpi_status register_slot(acpi_ha
device = (adr  16)  0x;
function = adr  0x;
 
-   mutex_lock(acpiphp_context_lock);
+   acpi_lock_hp_context();
context = acpiphp_init_context(adev);
if (!context) {
-   mutex_unlock(acpiphp_context_lock);
+   acpi_unlock_hp_context();
acpi_handle_err(handle, No hotplug context\n);
return AE_NOT_EXIST;
}
newfunc = context-func;
newfunc-function = function;
newfunc-parent = bridge;
-   mutex_unlock(acpiphp_context_lock);
+   acpi_unlock_hp_context();
 
if (acpi_has_method(handle, _EJ0))
newfunc-flags = FUNC_HAS_EJ0;
@@ -319,9 +318,9 @@ static acpi_status register_slot(acpi_ha
 
slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
if (!slot) {
-   mutex_lock(acpiphp_context_lock);
+   acpi_lock_hp_context();
acpiphp_put_context(context);
-   mutex_unlock(acpiphp_context_lock);
+   acpi_unlock_hp_context();
return AE_NO_MEMORY;
}
 
@@ -396,7 +395,7 @@ static struct acpiphp_bridge *acpiphp_ha
struct acpiphp_context *context;
struct acpiphp_bridge *bridge = NULL;
 
-   mutex_lock(acpiphp_context_lock);
+   acpi_lock_hp_context();
context = acpiphp_get_context(handle);
if (context) {
bridge = context-bridge;
@@ -405,7 +404,7 @@ static struct acpiphp_bridge *acpiphp_ha
 
acpiphp_put_context(context);
}
-