linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: ACPI Devel Maling List <linux-acpi@vger.kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	Aaron Lu <aaron.lu@intel.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux PCI <linux-pci@vger.kernel.org>,
	Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [PATCH 5/11] ACPI / hotplug / PCI: Store acpi_device pointer in acpiphp_context
Date: Mon, 27 Jan 2014 01:41:17 +0100	[thread overview]
Message-ID: <2392255.TACRzd2AD0@vostro.rjw.lan> (raw)
In-Reply-To: <2217793.001RY6hKlo@vostro.rjw.lan>

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

After recent modifications of the ACPI core making it create a struct
acpi_device object for every namespace node representing a device
regardless of the current status of that device the ACPIPHP code
can store a struct acpi_device pointer instead of an ACPI handle
in struct acpiphp_context.  This immediately makes it possible to
avoid making potentially costly calls to acpi_bus_get_device() in
two places and allows some more simplifications to be made going
forward.

The reason why that is correct is because ACPIPHP only installs
hotify handlers for namespace nodes that exist when
acpiphp_enumerate_slots() is called for their parent bridge.
That only happens if the parent bridge has an ACPI companion
associated with it, which means that the ACPI namespace scope
in question has been scanned already at that point.  That, in
turn, means that struct acpi_device objects have been created
for all namespace nodes in that scope and pointers to those
objects can be stored directly instead of their ACPI handles.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/pci/hotplug/acpiphp.h      |    9 +++++--
 drivers/pci/hotplug/acpiphp_glue.c |   44 +++++++++++++++++--------------------
 2 files changed, 28 insertions(+), 25 deletions(-)

Index: linux-pm/drivers/pci/hotplug/acpiphp.h
===================================================================
--- linux-pm.orig/drivers/pci/hotplug/acpiphp.h
+++ linux-pm/drivers/pci/hotplug/acpiphp.h
@@ -117,8 +117,8 @@ struct acpiphp_func {
 };
 
 struct acpiphp_context {
-	acpi_handle handle;
 	struct acpiphp_func func;
+	struct acpi_device *adev;
 	struct acpiphp_bridge *bridge;
 	unsigned int refcount;
 };
@@ -128,9 +128,14 @@ static inline struct acpiphp_context *fu
 	return container_of(func, struct acpiphp_context, func);
 }
 
+static inline struct acpi_device *func_to_acpi_device(struct acpiphp_func *func)
+{
+	return func_to_context(func)->adev;
+}
+
 static inline acpi_handle func_to_handle(struct acpiphp_func *func)
 {
-	return func_to_context(func)->handle;
+	return func_to_acpi_device(func)->handle;
 }
 
 /*
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
@@ -73,11 +73,11 @@ static void acpiphp_context_handler(acpi
 
 /**
  * acpiphp_init_context - Create hotplug context and grab a reference to it.
- * @handle: ACPI object handle to create the context for.
+ * @adev: ACPI device object to create the context for.
  *
  * Call under acpiphp_context_lock.
  */
-static struct acpiphp_context *acpiphp_init_context(acpi_handle handle)
+static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev)
 {
 	struct acpiphp_context *context;
 	acpi_status status;
@@ -86,9 +86,9 @@ static struct acpiphp_context *acpiphp_i
 	if (!context)
 		return NULL;
 
-	context->handle = handle;
+	context->adev = adev;
 	context->refcount = 1;
-	status = acpi_attach_data(handle, acpiphp_context_handler, context);
+	status = acpi_attach_data(adev->handle, acpiphp_context_handler, context);
 	if (ACPI_FAILURE(status)) {
 		kfree(context);
 		return NULL;
@@ -118,7 +118,7 @@ static struct acpiphp_context *acpiphp_g
 
 /**
  * acpiphp_put_context - Drop a reference to ACPI hotplug context.
- * @handle: ACPI object handle to put the context for.
+ * @context: ACPI hotplug context to drop a reference to.
  *
  * The context object is removed if there are no more references to it.
  *
@@ -130,7 +130,7 @@ static void acpiphp_put_context(struct a
 		return;
 
 	WARN_ON(context->bridge);
-	acpi_detach_data(context->handle, acpiphp_context_handler);
+	acpi_detach_data(context->adev->handle, acpiphp_context_handler);
 	kfree(context);
 }
 
@@ -265,6 +265,7 @@ static acpi_status register_slot(acpi_ha
 {
 	struct acpiphp_bridge *bridge = data;
 	struct acpiphp_context *context;
+	struct acpi_device *adev;
 	struct acpiphp_slot *slot;
 	struct acpiphp_func *newfunc;
 	acpi_status status = AE_OK;
@@ -284,12 +285,14 @@ static acpi_status register_slot(acpi_ha
 				"can't evaluate _ADR (%#x)\n", status);
 		return AE_OK;
 	}
+	if (acpi_bus_get_device(handle, &adev))
+		return AE_OK;
 
 	device = (adr >> 16) & 0xffff;
 	function = adr & 0xffff;
 
 	mutex_lock(&acpiphp_context_lock);
-	context = acpiphp_init_context(handle);
+	context = acpiphp_init_context(adev);
 	if (!context) {
 		mutex_unlock(&acpiphp_context_lock);
 		acpi_handle_err(handle, "No hotplug context\n");
@@ -625,12 +628,8 @@ static void disable_slot(struct acpiphp_
 		pci_dev_put(pdev);
 	}
 
-	list_for_each_entry(func, &slot->funcs, sibling) {
-		struct acpi_device *adev;
-
-		if (!acpi_bus_get_device(func_to_handle(func), &adev))
-			acpi_bus_trim(adev);
-	}
+	list_for_each_entry(func, &slot->funcs, sibling)
+		acpi_bus_trim(func_to_acpi_device(func));
 
 	slot->flags &= (~SLOT_ENABLED);
 }
@@ -644,13 +643,10 @@ static bool slot_no_hotplug(struct acpip
 {
 	struct acpiphp_func *func;
 
-	list_for_each_entry(func, &slot->funcs, sibling) {
-		struct acpi_device *adev = NULL;
-
-		acpi_bus_get_device(func_to_handle(func), &adev);
-		if (acpiphp_no_hotplug(adev))
+	list_for_each_entry(func, &slot->funcs, sibling)
+		if (acpiphp_no_hotplug(func_to_acpi_device(func)))
 			return true;
-	}
+
 	return false;
 }
 
@@ -899,7 +895,7 @@ static void hotplug_event(acpi_handle ha
 static void hotplug_event_work(void *data, u32 type)
 {
 	struct acpiphp_context *context = data;
-	acpi_handle handle = context->handle;
+	acpi_handle handle = context->adev->handle;
 
 	acpi_scan_lock_acquire();
 	pci_lock_rescan_remove();
@@ -959,7 +955,7 @@ static void handle_hotplug_event(acpi_ha
 
 	mutex_lock(&acpiphp_context_lock);
 	context = acpiphp_get_context(handle);
-	if (context && !WARN_ON(context->handle != handle)) {
+	if (context && !WARN_ON(context->adev->handle != handle)) {
 		get_bridge(context->func.parent);
 		acpiphp_put_context(context);
 		acpi_hotplug_execute(hotplug_event_work, context, type);
@@ -983,16 +979,18 @@ static void handle_hotplug_event(acpi_ha
 void acpiphp_enumerate_slots(struct pci_bus *bus)
 {
 	struct acpiphp_bridge *bridge;
+	struct acpi_device *adev;
 	acpi_handle handle;
 	acpi_status status;
 
 	if (acpiphp_disabled)
 		return;
 
-	handle = ACPI_HANDLE(bus->bridge);
-	if (!handle)
+	adev = ACPI_COMPANION(bus->bridge);
+	if (!adev)
 		return;
 
+	handle = adev->handle;
 	bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
 	if (!bridge) {
 		acpi_handle_err(handle, "No memory for bridge object\n");


  parent reply	other threads:[~2014-01-27  0:32 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-27  0:37 [PATCH 0/11] ACPI / hotplug / PCI: Updates on top of changes merged recently Rafael J. Wysocki
2014-01-27  0:38 ` [PATCH 1/11] ACPI / hotplug / PCI: Proper kerneldoc comments for enumeration/removal Rafael J. Wysocki
2014-01-27  0:38 ` [PATCH 2/11] ACPI / hotplug / PCI: Simplify register_slot() Rafael J. Wysocki
2014-01-27  0:39 ` [PATCH 3/11] ACPI / hotplug / PCI: Drop acpiphp_bus_trim() Rafael J. Wysocki
2014-01-27  0:40 ` [PATCH 4/11] ACPI / hotplug / PCI: Rework acpiphp_no_hotplug() Rafael J. Wysocki
2014-01-27  0:41 ` Rafael J. Wysocki [this message]
2014-01-27  0:41 ` [PATCH 6/11] ACPI / hotplug / PCI: Drop acpiphp_bus_add() Rafael J. Wysocki
2014-01-27  0:42 ` [PATCH 7/11] ACPI / hotplug / PCI: Drop crit_sect locking Rafael J. Wysocki
2014-01-27  0:43 ` [PATCH 8/11] ACPI / hotplug / PCI: Simplify hotplug_event() Rafael J. Wysocki
2014-01-27  0:44 ` [PATCH 9/11] ACPI / hotplug / PCI: Simplify disable_slot() Rafael J. Wysocki
2014-01-27  0:45 ` [PATCH 10/11] ACPI / hotplug / PCI: Use acpi_handle_debug() in hotplug_event() Rafael J. Wysocki
2014-01-27  0:46 ` [PATCH 11/11] ACPI / hotplug: Do not pass ACPI handles to ACPI dock operations Rafael J. Wysocki
2014-01-28 22:10 ` [PATCH 0/5][RFT] ACPI / hotplug / PCI: Consolidation of ACPIPHP with ACPI core device hotplug Rafael J. Wysocki
2014-01-28 22:12   ` [PATCH 1/5][RFT] ACPI / hotplug / PCI: Attach hotplug contexts to struct acpi_device Rafael J. Wysocki
2014-01-28 22:13   ` [PATCH 2/5][RFT] ACPI / hotplug: Introduce acpi_install_hotplug_notify_handler() Rafael J. Wysocki
2014-01-28 22:14   ` [PATCH 3/5][RFT] ACPI / hotplug / PCI: Consolidate ACPIPHP with ACPI core hotplug Rafael J. Wysocki
2014-01-28 22:14   ` [PATCH 4/5][RFT] ACPI / hotplug / PCI: Simplify acpi_install_hotplug_notify_handler() Rafael J. Wysocki
2014-01-28 22:16   ` [PATCH 5/5][RFT] ACPI / hotplug: Dispach hotplug notifications from acpi_bus_notify() Rafael J. Wysocki
2014-01-28 23:57   ` [PATCH 0/5][RFT] ACPI / hotplug / PCI: Consolidation of ACPIPHP with ACPI core device hotplug Rafael J. Wysocki
2014-01-28 23:58     ` [Resend][PATCH 1/5][RFT] ACPI / hotplug / PCI: Attach hotplug contexts to struct acpi_device Rafael J. Wysocki
2014-01-28 23:59     ` [Resend][PATCH 2/5][RFT] ACPI / hotplug: Introduce acpi_install_hotplug_notify_handler() Rafael J. Wysocki
2014-01-28 23:59     ` [Update][PATCH 3/5][RFT] ACPI / hotplug / PCI: Consolidate ACPIPHP with ACPI core hotplug Rafael J. Wysocki
2014-01-29  0:00     ` [Update][PATCH 4/5][RFT] ACPI / hotplug / PCI: Simplify acpi_install_hotplug_notify_handler() Rafael J. Wysocki
2014-01-31 15:28       ` Mika Westerberg
2014-01-31 15:42         ` Rafael J. Wysocki
2014-01-31 15:40           ` Mika Westerberg
2014-01-31 16:01             ` Mika Westerberg
2014-01-31 16:16               ` Rafael J. Wysocki
2014-01-31 17:09                 ` Mika Westerberg
2014-01-31 17:34                   ` Rafael J. Wysocki
2014-02-02  0:12                     ` Rafael J. Wysocki
2014-01-29  0:02     ` [Update][PATCH 5/5][RFT] ACPI / hotplug / PCI: Hotplug notifications from acpi_bus_notify() Rafael J. Wysocki
2014-01-30 15:28       ` [Update 2x][PATCH " Rafael J. Wysocki
2014-02-02  0:52     ` [PATCH v2 0/6] ACPI / hotplug / PCI: Consolidation of ACPIPHP with ACPI core device hotplug Rafael J. Wysocki
2014-02-02  0:54       ` [PATCH v2 1/6] ACPI / hotplug: Fix theoretical race in acpi_hotplug_notify_cb() Rafael J. Wysocki
2014-02-02 17:01         ` Rafael J. Wysocki
2014-02-02  0:55       ` [PATCH v2 2/6] ACPI / hotplug / PCI: Define hotplug context lock in the core Rafael J. Wysocki
2014-02-02  0:56       ` [PATCH v2 3/6] ACPI / hotplug / PCI: Consolidate ACPIPHP with ACPI core hotplug Rafael J. Wysocki
2014-02-02  0:57       ` [PATCH v2 4/6] ACPI / hotplug / PCI: Rework the handling of eject requests Rafael J. Wysocki
2014-02-02  0:58       ` [PATCH v2 5/6] ACPI / hotplug / PCI: Simplify acpi_install_hotplug_notify_handler() Rafael J. Wysocki
2014-02-02  0:58       ` [PATCH v2 6/6] ACPI / hotplug / PCI: Hotplug notifications from acpi_bus_notify() Rafael J. Wysocki
2014-02-02 17:11       ` [PATCH v3 0/7] ACPI / hotplug / PCI: Consolidation of ACPIPHP with ACPI core device hotplug Rafael J. Wysocki
2014-02-02 17:12         ` [PATCH v3 1/7] ACPICA: Introduce acpi_get_data_full() and rework acpi_get_data() Rafael J. Wysocki
2014-02-02 17:15         ` [PATCH v3 2/7] ACPI / hotplug: Fix potential races in notify handlers Rafael J. Wysocki
2014-02-02 17:16         ` [PATCH v3 3/7] ACPI / hotplug / PCI: Define hotplug context lock in the core Rafael J. Wysocki
2014-02-02 17:17         ` [PATCH v3 4/7] ACPI / hotplug / PCI: Consolidate ACPIPHP with ACPI core hotplug Rafael J. Wysocki
2014-02-02 17:18         ` [PATCH v3 5/7] ACPI / hotplug / PCI: Rework the handling of eject requests Rafael J. Wysocki
2014-02-02 17:19         ` [PATCH v3 6/7] ACPI / hotplug / PCI: Simplify acpi_install_hotplug_notify_handler() Rafael J. Wysocki
2014-02-02 17:20         ` [PATCH v3 7/7] ACPI / hotplug / PCI: Hotplug notifications from acpi_bus_notify() Rafael J. Wysocki
2014-02-03 10:45         ` [PATCH v3 0/7] ACPI / hotplug / PCI: Consolidation of ACPIPHP with ACPI core device hotplug Mika Westerberg
2014-02-03 21:51           ` Rafael J. Wysocki
2014-02-02  0:19 ` [PATCH v2 0/13] ACPI / hotplug / PCI: Updates on top of changes merged recently Rafael J. Wysocki
2014-02-02  0:21   ` [PATCH v2 1/13] ACPI / hotplug / PCI: Remove entries from bus->devices in reverse order Rafael J. Wysocki
2014-02-02  0:22   ` [PATCH v2 2/13] ACPI / hotplug / PCI: Move PCI rescan-remove locking to hotplug_event() Rafael J. Wysocki
2014-02-02  0:23   ` [PATCH v2 3/13] ACPI / hotplug / PCI: Simplify disable_slot() Rafael J. Wysocki
2014-02-02  0:24   ` [PATCH v2 4/13] ACPI / hotplug / PCI: Proper kerneldoc comments for enumeration/removal Rafael J. Wysocki
2014-02-02  0:25   ` [PATCH v2 5/13] ACPI / hotplug / PCI: Simplify register_slot() Rafael J. Wysocki
2014-02-02  0:26   ` [PATCH v2 6/13] ACPI / hotplug / PCI: Drop acpiphp_bus_trim() Rafael J. Wysocki
2014-02-02  0:27   ` [PATCH v2 7/13] ACPI / hotplug / PCI: Rework acpiphp_no_hotplug() Rafael J. Wysocki
2014-02-02  0:27   ` [PATCH v2 8/13] ACPI / hotplug / PCI: Store acpi_device pointer in acpiphp_context Rafael J. Wysocki
2014-02-02  0:28   ` [PATCH v2 9/13] ACPI / hotplug / PCI: Drop acpiphp_bus_add() Rafael J. Wysocki
2014-02-02  0:29   ` [PATCH v2 10/13] ACPI / hotplug / PCI: Drop crit_sect locking Rafael J. Wysocki
2014-02-02  0:30   ` [PATCH v2 11/13] ACPI / hotplug / PCI: Simplify hotplug_event() Rafael J. Wysocki
2014-02-02  0:31   ` [PATCH v2 12/13] ACPI / hotplug / PCI: Use acpi_handle_debug() in hotplug_event() Rafael J. Wysocki
2014-02-02  0:31   ` [PATCH v2 13/13] ACPI / hotplug: Do not pass ACPI handles to ACPI dock operations Rafael J. Wysocki
2014-02-03  1:47   ` [PATCH] ACPI / hotplug / PCI: Scan root bus under the PCI rescan-remove lock Rafael J. Wysocki
2014-02-03 10:44   ` [PATCH v2 0/13] ACPI / hotplug / PCI: Updates on top of changes merged recently Mika Westerberg
2014-02-03 23:12     ` [PATCH v2 0/24] ACPI / hotplug / PCI: ACPIPHP updates and consolidation with ACPI core Rafael J. Wysocki
2014-02-03 23:14       ` [PATCH 1/24][Resend] ACPI / hotplug / PCI: Remove entries from bus->devices in reverse order Rafael J. Wysocki
2014-02-03 23:15       ` [PATCH 2/24][Resend] ACPI / hotplug / PCI: Move PCI rescan-remove locking to hotplug_event() Rafael J. Wysocki
2014-02-03 23:16       ` [PATCH 3/24][Resend] ACPI / hotplug / PCI: Scan root bus under the PCI rescan-remove lock Rafael J. Wysocki
2014-02-03 23:18       ` [PATCH 4/24][New] ACPI / hotplug / PCI: Fix bridge removal race in handle_hotplug_event() Rafael J. Wysocki
2014-02-03 23:18       ` [PATCH 5/24][New] ACPI / hotplug / PCI: Fix bridge removal race vs dock events Rafael J. Wysocki
2014-02-03 23:20       ` [PATCH 6/24][Resend] ACPI / hotplug / PCI: Simplify disable_slot() Rafael J. Wysocki
2014-02-03 23:21       ` [PATCH 7/24][Resend] ACPI / hotplug / PCI: Proper kerneldoc comments for enumeration/removal Rafael J. Wysocki
2014-02-03 23:22       ` [PATCH 8/24][Resend] ACPI / hotplug / PCI: Simplify register_slot() Rafael J. Wysocki
2014-02-03 23:23       ` [PATCH 9/24][Resend] ACPI / hotplug / PCI: Drop acpiphp_bus_trim() Rafael J. Wysocki
2014-02-03 23:24       ` [PATCH 10/24][Resend] ACPI / hotplug / PCI: Rework acpiphp_no_hotplug() Rafael J. Wysocki
2014-02-03 23:25       ` [PATCH 11/24][Update] ACPI / hotplug / PCI: Store acpi_device pointer in acpiphp_context Rafael J. Wysocki
2014-02-03 23:26       ` [PATCH 12/24][Resend] ACPI / hotplug / PCI: Drop acpiphp_bus_add() Rafael J. Wysocki
2014-02-03 23:27       ` [PATCH 13/24][Resend] ACPI / hotplug / PCI: Drop crit_sect locking Rafael J. Wysocki
2014-02-03 23:33       ` [PATCH 14/24][Update] ACPI / hotplug / PCI: Simplify hotplug_event() Rafael J. Wysocki
2014-02-03 23:33       ` [PATCH 15/24][Resend] ACPI / hotplug / PCI: Use acpi_handle_debug() in hotplug_event() Rafael J. Wysocki
2014-02-03 23:34       ` [PATCH 16/24][New] ACPI / hotplug / PCI: Do not pass ACPI handle to hotplug_event() Rafael J. Wysocki
2014-02-03 23:34       ` [PATCH 17/24][Resend] ACPICA: Introduce acpi_get_data_full() and rework acpi_get_data() Rafael J. Wysocki
2014-02-03 23:36       ` [PATCH 18/24][Update] ACPI / hotplug: Fix potential race in acpi_bus_notify() Rafael J. Wysocki
2014-02-03 23:36       ` [PATCH 19/24][Update] ACPI / hotplug / PCI: Define hotplug context lock in the core Rafael J. Wysocki
2014-02-03 23:37       ` [PATCH 20/24][Update] ACPI / hotplug / PCI: Consolidate ACPIPHP with ACPI core hotplug Rafael J. Wysocki
2014-02-06 13:07         ` [Update][PATCH 20/24] " Rafael J. Wysocki
2014-02-06 23:35           ` [Update 2x][PATCH " Rafael J. Wysocki
2014-02-03 23:38       ` [PATCH 21/24][Resend] ACPI / hotplug / PCI: Rework the handling of eject requests Rafael J. Wysocki
2014-02-03 23:39       ` [PATCH 22/24][Resend] ACPI / hotplug / PCI: Simplify acpi_install_hotplug_notify_handler() Rafael J. Wysocki
2014-02-06 13:09         ` [Update][PATCH 22/24] " Rafael J. Wysocki
2014-02-03 23:40       ` [PATCH 23/24][Update] ACPI / hotplug / PCI: Hotplug notifications from acpi_bus_notify() Rafael J. Wysocki
2014-02-06 13:10         ` [Update][PATCH 23/24] " Rafael J. Wysocki
2014-02-03 23:41       ` [PATCH 24/24][New] ACPI / hotplug / PCI: Rework acpiphp_check_host_bridge() Rafael J. Wysocki
2014-02-05 10:14       ` [PATCH v2 0/24] ACPI / hotplug / PCI: ACPIPHP updates and consolidation with ACPI core Mika Westerberg
2014-02-05 10:59         ` Rafael J. Wysocki
2014-02-11  0:19 ` [PATCH 0/11] ACPI / hotplug / PCI: Updates on top of changes merged recently Bjorn Helgaas
2014-02-11 12:53   ` Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2392255.TACRzd2AD0@vostro.rjw.lan \
    --to=rjw@rjwysocki.net \
    --cc=aaron.lu@intel.com \
    --cc=bhelgaas@google.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).