Skip to contentSkip to conversation

ACPI: Introduce acpi_get_physical_pci_device

PATCH In review Thomas Renninger 2 participants 2 messages Apr 16, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 4/7 ACPI: Introduce acpi_get_physical_pci_device

ACPI: Introduce acpi_get_physical_pci_device

This is the same as acpi_get_physical_pci_device, but checks whether the ACPI device's HID has a valid PCI value. This one should get enhanced (later or if accepted), so that the returned struct *device PCI device is further evaluated if it's a PCI bridge and the device behind that bridge should be returned then.
Sanity checks were taken over from Matthew Garrett.

---
 drivers/acpi/glue.c     |   35 +++++++++++++++++++++++++++++++++++
 drivers/acpi/video.c    |    7 ++++++-
 include/acpi/acpi_bus.h |    2 ++
 3 files changed, 43 insertions(+), 1 deletion(-)
drivers/acpi/glue.c +35 -0
Index: linux-acpi-2.6_video_native_vs_vendor/drivers/acpi/glue.c
===================================================================
@@ -140,6 +140,41 @@ struct device *acpi_get_physical_device(
 
 EXPORT_SYMBOL(acpi_get_physical_device);
 
+/* ToDo: When a PCI bridge is found, return the PCI device behind the bridge */
+/* Note: a success call will increase reference count by one */
+struct device *acpi_get_physical_pci_device(acpi_handle handle)
+{
+	struct device *dev;
+	long device_id;
+	acpi_status status;
+
+	status =
+		acpi_evaluate_integer(handle, "_ADR", NULL, &device_id);
+
+	if (ACPI_FAILURE(status))
+		return NULL;
+
+	/* We need to attempt to determine whether the _ADR refers to a
+	   PCI device or not. There's no terribly good way to do this,
+	   so the best we can hope for is to assume that there'll never
+	   be a video device in the host bridge */
+	if (device_id >= 0x10000) {
+		/* It looks like a PCI device. Does it exist? */
+		dev = acpi_get_physical_device(handle);
+	} else {
+		/* It doesn't look like a PCI device. Does its parent
+		   exist? */
+		acpi_handle phandle;
+		if (acpi_get_parent(handle, &phandle))
+			return NULL;
+		dev = acpi_get_physical_device(phandle);
+	}
+	if (!dev)
+		return NULL;
+	return dev;
+}
+EXPORT_SYMBOL(acpi_get_physical_pci_device);
+
 static int acpi_bind_one(struct device *dev, acpi_handle handle)
 {
 	acpi_status status;
drivers/acpi/video.c +6 -1
Index: linux-acpi-2.6_video_native_vs_vendor/drivers/acpi/video.c
===================================================================
@@ -805,11 +805,16 @@ static void acpi_video_bus_find_cap(stru
 static int acpi_video_bus_check(struct acpi_video_bus *video)
 {
 	acpi_status status = -ENOENT;
-
+	struct device *dev;
 
 	if (!video)
 		return -EINVAL;
 
+	dev = acpi_get_physical_pci_device(video->device->handle);
+	if (!dev)
+		return -ENODEV;
+	put_device(dev);
+
 	/* Since there is no HID, CID and so on for VGA driver, we have
 	 * to check well known required nodes.
 	 */
include/acpi/acpi_bus.h +2 -0
Index: linux-acpi-2.6_video_native_vs_vendor/include/acpi/acpi_bus.h
===================================================================
@@ -370,6 +370,8 @@ struct acpi_bus_type {
 int register_acpi_bus_type(struct acpi_bus_type *);
 int unregister_acpi_bus_type(struct acpi_bus_type *);
 struct device *acpi_get_physical_device(acpi_handle);
+struct device *acpi_get_physical_pci_device(acpi_handle);
+
 /* helper */
 acpi_handle acpi_get_child(acpi_handle, acpi_integer);
 acpi_handle acpi_get_pci_rootbridge_handle(unsigned int, unsigned int);
#1 lore raw
Quoted 8 lines · Thomas Renninger

ACPI: Introduce acpi_get_physical_pci_device

This is the same as acpi_get_physical_pci_device, but checks whether the ACPI device's HID has a valid PCI value. This one should get enhanced (later or if accepted), so that the returned struct *device PCI device is further evaluated if it's a PCI bridge and the device behind that bridge should be returned then.
Sanity checks were taken over from Matthew Garrett.

The comment isn't quite right. It checks whether the ADR is a likely PCI value, not a valid one.

Signature · 1 line
Matthew Garrett | [email protected]