linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiang Liu <liuj97@gmail.com>
To: Yinghai Lu <yinghai@kernel.org>
Cc: Jiang Liu <jiang.liu@huawei.com>,
	Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>,
	Jiang Liu <liuj97@gmail.com>, Keping Chen <chenkeping@huawei.com>,
	linux-pci@vger.kernel.org
Subject: [PATCH] PCI: correctly detect ACPI PCI host bridge objects
Date: Thu, 12 Apr 2012 00:27:03 +0800	[thread overview]
Message-ID: <1334161623-4834-1-git-send-email-jiang.liu@huawei.com> (raw)

The code in pci_root_hp.c depends on function acpi_is_root_bridge()
to check whether an ACPI object is a PCI host bridge or not.
If an ACPI device hasn't been created for the ACPI object yet,
function acpi_is_root_bridge() will return false even if the object
is a PCI host bridge object. That behavior will cause two issues:
1) No ACPI notification handler installed for PCI host bridges absent
   at startup, so hotplug events for those bridges won't be handled.
2) rescan_root_bridge() can't reenumerate offlined PCI host bridges
   because the ACPI devices have been already destroyed.

So introduce acpi_match_object_ids() to correctly detect PCI host bridges.

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
---
It applies to Yinghai's tree at
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-root-bus-hotplug
---
 drivers/acpi/pci_root_hp.c |   15 +++++++++++++--
 drivers/acpi/scan.c        |   28 ++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h    |    2 ++
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/pci_root_hp.c b/drivers/acpi/pci_root_hp.c
index e16b53d..34cf1b7 100644
--- a/drivers/acpi/pci_root_hp.c
+++ b/drivers/acpi/pci_root_hp.c
@@ -19,6 +19,12 @@ struct acpi_root_bridge {
 	u32 flags;
 };
 
+static const struct acpi_device_id root_device_ids[] = {
+	{"PNP0A03", 0},
+	{"PNP0A08", 0},
+	{"", 0},
+};
+
 /* bridge flags */
 #define ROOT_BRIDGE_HAS_EJ0	(0x00000002)
 #define ROOT_BRIDGE_HAS_PS3	(0x00000080)
@@ -232,6 +238,11 @@ static void handle_hotplug_event_root(acpi_handle handle, u32 type,
 				_handle_hotplug_event_root);
 }
 
+static bool acpi_is_root_bridge_object(acpi_handle handle)
+{
+	return !!acpi_match_object_ids(handle, root_device_ids);
+}
+
 static acpi_status __init
 find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
 {
@@ -240,7 +251,7 @@ find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
 				      .pointer = objname };
 	int *count = (int *)context;
 
-	if (!acpi_is_root_bridge(handle))
+	if (!acpi_is_root_bridge_object(handle))
 		return AE_OK;
 
 	(*count)++;
@@ -273,7 +284,7 @@ subsys_initcall(acpi_pci_root_hp_init);
 static acpi_status
 rescan_root_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
 {
-	if (!acpi_is_root_bridge(handle))
+	if (!acpi_is_root_bridge_object(handle))
 		return AE_OK;
 
 	handle_root_bridge_insertion(handle);
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 767e2dc..53e95f5 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -272,6 +272,34 @@ int acpi_match_device_ids(struct acpi_device *device,
 }
 EXPORT_SYMBOL(acpi_match_device_ids);
 
+int acpi_match_object_ids(acpi_handle handle, const struct acpi_device_id *ids)
+{
+	int i, count;
+	acpi_status status;
+	struct acpica_device_id *hids;
+	const struct acpi_device_id *id;
+	struct acpi_device_info *info = NULL;
+
+	status = acpi_get_object_info(handle, &info);
+	if (ACPI_FAILURE(status))
+		return 0;
+
+	hids = info->compatible_id_list.ids;
+	count = info->compatible_id_list.count;
+	for (id = ids; id->id[0]; id++)
+		for (i = 0; i < count; i++)
+			if (!strncmp((char *)id->id, hids[i].string,
+				     ACPI_ID_LEN)) {
+				kfree(info);
+				return 1;
+			}
+
+	kfree(info);
+
+	return 0;
+}
+EXPORT_SYMBOL(acpi_match_object_ids);
+
 static void acpi_free_ids(struct acpi_device *device)
 {
 	struct acpi_hardware_id *id, *tmp;
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index cb4f402..0d990b7 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -342,6 +342,8 @@ int acpi_bus_start(struct acpi_device *device);
 acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);
 int acpi_match_device_ids(struct acpi_device *device,
 			  const struct acpi_device_id *ids);
+int acpi_match_object_ids(acpi_handle handle,
+			  const struct acpi_device_id *ids);
 int acpi_create_dir(struct acpi_device *);
 void acpi_remove_dir(struct acpi_device *);
 
-- 
1.7.5.4


                 reply	other threads:[~2012-04-11 16:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1334161623-4834-1-git-send-email-jiang.liu@huawei.com \
    --to=liuj97@gmail.com \
    --cc=chenkeping@huawei.com \
    --cc=jiang.liu@huawei.com \
    --cc=kaneshige.kenji@jp.fujitsu.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=yinghai@kernel.org \
    /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).