Skip to contentSkip to conversation

ACPI / scan: Allow ACPI drivers to bind to PNP device objects

PATCH In review Rafael J. Wysocki 3 participants 11 messages Aug 21, 2014 – Sep 8, 2014

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

PATCH 1/1 ACPI / scan: Allow ACPI drivers to bind to PNP device objects

From: Rafael J. Wysocki <[email protected]>

We generally don't allow ACPI drivers to bind to ACPI device objects that companion "physical" device objects are created for to avoid situations in which two different drivers may attempt to handle one device at the same time. Recent ACPI device enumeration rework extended that approach to ACPI PNP devices by starting to use a scan handler for enumerating them. However, we previously allowed ACPI drivers to bind to ACPI device objects with existing PNP device companions and changing that led to functional regressions on some systems.

For this reason, add a special check for PNP devices in acpi_device_probe() so that ACPI drivers can bind to ACPI device objects having existing PNP device companions as before.

Fixes eec15edbb0e1 (ACPI / PNP: use device ID list for PNPACPI device enumeration)
---
 drivers/acpi/acpi_pnp.c |    5 +++++
 drivers/acpi/internal.h |    1 +
 drivers/acpi/scan.c     |    2 +-
 3 files changed, 7 insertions(+), 1 deletion(-)
drivers/acpi/acpi_pnp.c +5 -0
Index: linux-pm/drivers/acpi/acpi_pnp.c
===================================================================
@@ -396,3 +396,8 @@ void __init acpi_pnp_init(void)
 {
 	acpi_scan_add_handler(&acpi_pnp_handler);
 }
+
+bool is_acpi_pnp_device(struct acpi_device *adev)
+{
+	return adev->handler == &acpi_pnp_handler;
+}
drivers/acpi/internal.h +1 -0
Index: linux-pm/drivers/acpi/internal.h
===================================================================
@@ -86,6 +86,7 @@ void acpi_device_add_finalize(struct acp
 void acpi_free_pnp_ids(struct acpi_device_pnp *pnp);
 bool acpi_device_is_present(struct acpi_device *adev);
 bool acpi_device_is_battery(struct acpi_device *adev);
+bool is_acpi_pnp_device(struct acpi_device *adev);
 
 /* --------------------------------------------------------------------------
                                   Power Resource
drivers/acpi/scan.c +1 -1
Index: linux-pm/drivers/acpi/scan.c
===================================================================
@@ -975,7 +975,7 @@ static int acpi_device_probe(struct devi
 	struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
 	int ret;
 
-	if (acpi_dev->handler)
+	if (acpi_dev->handler && !is_acpi_pnp_device(acpi_dev))
 		return -EINVAL;
 
 	if (!acpi_drv->ops.add)
#1 lore raw

Hi, Rafael,

Quoted 6 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

We generally don't allow ACPI drivers to bind to ACPI device objects that companion "physical" device objects are created for to avoid situations in which two different drivers may attempt to handle one device at the same time.

Yes, and I think we should not break this rule.

Quoted 7 lines

Recent ACPI device enumeration rework
extended that approach to ACPI PNP devices by starting to use a scan handler for enumerating them. However, we previously allowed ACPI drivers to bind to ACPI device objects with existing PNP device companions and changing that led to functional regressions on some systems.

Question: except the PNP0C01/PNP0C02 case, if we have an device have two ids that matches two different drivers, should we allow both drivers probe successfully?
I think the answer is no.
In the PNP0C01/PNP0C02 case, I think we can fix the issue by the following patch instead.

Note that I've just tested on my machine and it works well.
I still need the bug reporter to check if the patch fixes bug 81511 or not.

Quoted 1 line

From c6c388728d08a6368f21dab61d6f0a940e0ea13a Mon Sep 17 00:00:00 2001

From: Zhang Rui <[email protected]>
Date: Thu, 21 Aug 2014 13:39:47 +0800
Subject: [RFC PATCH] ACPI: introduce motherboard resource management

ACPI Devices with _HID/_CID PNP0C01/PNP0C02 represents that they have some motherboard resources that needs to be reserved.

We used to enumerated those devices to PNP bus and rely on PNP system driver to do resource reservation.
But this mechanism does not work well nowadays as many devices not only represent motherboard resources, but also represent physical devices that need native drivers other than PNP system driver for the device to work. For example,
1) https://bugzilla.kernel.org/show_bug.cgi?id=46741,

    Device (NIPM)
    {
        Name (_HID, EisaId ("IPI0001"))  // _HID: Hardware ID
        Name (_CID, EisaId ("PNP0C01"))  // _CID: Compatible ID
   the NIPM device has _CID PNP0C01 but it is an IPMI device.
   PNP system driver blocks the PNP IPMI driver to probe.
2) https://bugzilla.kernel.org/show_bug.cgi?id=81511
        Device (IFFS)
        {
            Name (_HID, EisaId ("INT3392"))  // _HID: Hardware ID
            Name (_CID, EisaId ("PNP0C02"))  // _CID: Compatible ID

the IFFS device has _CID PNP0C02, but it is an intel rapid start device, which already has an ACPI driver at drivers/platform/x86/intel-rst.c
3) a couple of machines, including the on in
https://bugzilla.kernel.org/show_bug.cgi?id=81511, has the AML code like following

        Device (PTID)
        {
            Name (_HID, EisaId ("INT340E"))  // _HID: Hardware ID
            Name (_CID, EisaId ("PNP0C02"))  // _CID: Compatible ID

the PTID device has _CID PNP0C02, but it is also represents an INT340E device, there is a platform bus driver for this device which will be introduced by myself soon.

In any of the above cases, the current code for managing PNP0C01/PNP0C02 resources in Linux kernel is broken, because it either blocks the physical device driver on the same bus, or results in multiple drivers loaded for the same ACPI device node, which may also has some potential risks.

Thus, IMO, we need a clean way to handle those motherboard resources. Given that PNP0C01/PNP0C02 is more like an indicator for reserving the resources, this patch
1. does the resource reservation in ACPI code directly, with the same logic and time point in drivers/pnp/quirks.c and drivers/pnp/system.c.
2. makes PNP0C01/PNP0C02 PNP id transparent to Linux devices and drivers, thus PNP system driver becomes a no-op for ACPI enumerated devices.

This is just a draft patch, and I'd like to see if this is the right direction to go. Any comments are welcome.

---
 drivers/acpi/acpi_pnp.c |   3 -
 drivers/acpi/scan.c     | 208 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 204 insertions(+), 7 deletions(-)
drivers/acpi/acpi_pnp.c +0 -3
index 1f8b204..a7deae5 100644
@@ -134,9 +134,6 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	{"FUJ02bf"},
 	{"FUJ02B1"},
 	{"FUJ02E3"},
-	/* system */
-	{"PNP0c02"},		/* General ID for reserving resources */
-	{"PNP0c01"},		/* memory controller */
 	/* rtc_cmos */
 	{"PNP0b00"},
 	{"PNP0b01"},
drivers/acpi/scan.c +204 -4

241 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#2 lore raw
Quoted 11 lines · Zhang Rui

Hi, Rafael,

Quoted 6 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

We generally don't allow ACPI drivers to bind to ACPI device objects that companion "physical" device objects are created for to avoid situations in which two different drivers may attempt to handle one device at the same time.

Yes, and I think we should not break this rule.

No, we broke the way the code worked previously. We need to restore it first and *then* try to fix it up, not the other way around.

Quoted 10 lines
Quoted 7 lines

Recent ACPI device enumeration rework
extended that approach to ACPI PNP devices by starting to use a scan handler for enumerating them. However, we previously allowed ACPI drivers to bind to ACPI device objects with existing PNP device companions and changing that led to functional regressions on some systems.

Question: except the PNP0C01/PNP0C02 case, if we have an device have two ids that matches two different drivers, should we allow both drivers probe successfully?

No, we shouldn't, but in the cases in question we have only one driver (an ACPI one).

Quoted 3 lines

I think the answer is no.
In the PNP0C01/PNP0C02 case, I think we can fix the issue by the following patch instead.

The right answer to me is to get rid of ACPI drviers entirely.

The thing below adds complexity to the resources management which I'm not sure is necessary.

In any case, please let's do that on top of the $subject patch not instead of it, because there are more cases we need to cover. And we need a fix for -stable.

Rafael

#3 lore raw
In reply to Zhang Rui
Quoted 4 lines · Zhang Rui

Hi, Rafael,

Quoted 1 line · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

[cut]

Quoted 2 lines

Note that I've just tested on my machine and it works well.
I still need the bug reporter to check if the patch fixes bug 81511 or not.

The FUJ02B1 and FUJ02E3 devices in bug 81971 have the same problem and they aren't motherboard devices. Yes, we need to convert that driver to use a PNP driver structure or a platform device, but (1) we need a -stable fix *first* and (2) the cases we already know about may not be the only broken ones.

Quoted 15 lines

From c6c388728d08a6368f21dab61d6f0a940e0ea13a Mon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Thu, 21 Aug 2014 13:39:47 +0800
Subject: [RFC PATCH] ACPI: introduce motherboard resource management

ACPI Devices with _HID/_CID PNP0C01/PNP0C02 represents that they have some motherboard resources that needs to be reserved.

We used to enumerated those devices to PNP bus and rely on PNP system driver to do resource reservation.
But this mechanism does not work well nowadays as many devices not only represent motherboard resources, but also represent physical devices that need native drivers other than PNP system driver for the device to work. For example,
1) https://bugzilla.kernel.org/show_bug.cgi?id=46741,

Quoted 6 lines
    Device (NIPM)
    {
        Name (_HID, EisaId ("IPI0001"))  // _HID: Hardware ID
        Name (_CID, EisaId ("PNP0C01"))  // _CID: Compatible ID

the NIPM device has _CID PNP0C01 but it is an IPMI device. PNP system driver blocks the PNP IPMI driver to probe.

That is a good reason for PNP0C01 to be dropped from acpi_pnp_device_ids[].

Quoted 8 lines

2) https://bugzilla.kernel.org/show_bug.cgi?id=81511

        Device (IFFS)
        {
            Name (_HID, EisaId ("INT3392"))  // _HID: Hardware ID
            Name (_CID, EisaId ("PNP0C02"))  // _CID: Compatible ID

the IFFS device has _CID PNP0C02, but it is an intel rapid start device, which already has an ACPI driver at drivers/platform/x86/intel-rst.c

And which should be a platform driver really.

Quoted 10 lines

3) a couple of machines, including the on in
https://bugzilla.kernel.org/show_bug.cgi?id=81511, has the AML code like following

        Device (PTID)
        {
            Name (_HID, EisaId ("INT340E"))  // _HID: Hardware ID
            Name (_CID, EisaId ("PNP0C02"))  // _CID: Compatible ID

the PTID device has _CID PNP0C02, but it is also represents an INT340E device, there is a platform bus driver for this device which will be introduced by myself soon.

Again, that's a good reason for dropping PNP0C02 from acpi_pnp_device_ids[].

Quoted 49 lines

In any of the above cases, the current code for managing PNP0C01/PNP0C02 resources in Linux kernel is broken, because it either blocks the physical device driver on the same bus, or results in multiple drivers loaded for the same ACPI device node, which may also has some potential risks.

Thus, IMO, we need a clean way to handle those motherboard resources. Given that PNP0C01/PNP0C02 is more like an indicator for reserving the resources, this patch
1. does the resource reservation in ACPI code directly, with the same logic and time point in drivers/pnp/quirks.c and drivers/pnp/system.c.
2. makes PNP0C01/PNP0C02 PNP id transparent to Linux devices and drivers, thus PNP system driver becomes a no-op for ACPI enumerated devices.

This is just a draft patch, and I'd like to see if this is the right direction to go. Any comments are welcome.

---
 drivers/acpi/acpi_pnp.c |   3 -
 drivers/acpi/scan.c     | 208 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 204 insertions(+), 7 deletions(-)
drivers/acpi/acpi_pnp.c +0 -3
index 1f8b204..a7deae5 100644
@@ -134,9 +134,6 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	{"FUJ02bf"},
 	{"FUJ02B1"},
 	{"FUJ02E3"},
-	/* system */
-	{"PNP0c02"},		/* General ID for reserving resources */
-	{"PNP0c01"},		/* memory controller */
 	/* rtc_cmos */
 	{"PNP0b00"},
 	{"PNP0b01"},
drivers/acpi/scan.c +1 -0
index 0a817ad..674518b 100644
@@ -11,6 +11,7 @@
 #include <linux/kthread.h>
 #include <linux/dmi.h>
 #include <linux/nls.h>
+#include <linux/pci.h>
 
 #include <asm/pgtable.h>
 

drivers/acpi/scan.c static bool acpi_object_is_system_bus(acpi_handle handle) · line 1789

Quoted 8 lines
drivers/acpi/scan.c +5 -0
@@ -1781,12 +1782,201 @@ static bool acpi_object_is_system_bus(acpi_handle handle)
 	return false;
 }
 
+static bool acpi_is_motherboard_resource(char *id)
+{
+	return !(strncmp(id, "PNP0C01", sizeof("PNP0C01")) &&
+		 strncmp(id, "PNP0C02", sizeof("PNP0C02")));
+}

Can we use __acpi_match_device() for that?

Quoted 35 lines
drivers/acpi/scan.c +35 -0
+
+static LIST_HEAD(acpi_motherboard_resource_list);
+
+struct acpi_motherboard_resource {
+	acpi_handle handle;
+	struct list_head node;
+};
+
+static void acpi_record_motherboard_resource(acpi_handle handle)
+{
+	struct acpi_motherboard_resource *res;
+
+	res = kzalloc(sizeof(struct acpi_motherboard_resource), GFP_KERNEL);
+	if (!res)
+		return;
+	res->handle = handle;
+	list_add(&res->node, &acpi_motherboard_resource_list);
+}
+
+static void reserve_range(struct acpi_device *device, struct resource *r, int port)
+{
+	char *regionid;
+	resource_size_t start = r->start, end = r->end;
+	struct resource *res;
+	int result;
+
+	regionid = kmalloc(20, GFP_KERNEL);
+	if (!regionid)
+		return;
+
+	snprintf(regionid, 20, "ACPI %s", dev_name(&device->dev));
+		
+	if (port)
+		res = request_region(start, end - start + 1, regionid);
+	else

drivers/acpi/scan.c static bool acpi_object_is_system_bus(acpi_handle handle) · line 1834

Quoted 10 lines
drivers/acpi/scan.c +10 -0
+		res = request_mem_region(start, end - start + 1, regionid);
+	if (res)
+		res->flags &= ~IORESOURCE_BUSY;
+	else
+		kfree(regionid);
+
+	dev_info(&device->dev, "%pR %s reserved\n", r,
+			res ? "has been" : "could not be");
+}
+

The routine below should go into the PCI core.

Quoted 48 lines
drivers/acpi/scan.c +48 -0
+static int is_pci_reserved(struct resource *res)
+{
+	struct pci_dev *pdev = NULL;
+	resource_size_t acpi_start, acpi_end, pci_start, pci_end;
+	int i;
+
+	/*
+	 * Some BIOSes have motherboard devices with resources that
+	 * partially overlap PCI BARs.
+	 * Those resources should not be reserved, or else, it will
+	 * prevent the normal PCI driver from requesting them later.
+	 */
+	for_each_pci_dev(pdev) {
+		for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
+			unsigned long type;
+
+			type = pci_resource_flags(pdev, i) & res->flags
+			       & (IORESOURCE_IO | IORESOURCE_MEM);
+			if (!type || pci_resource_len(pdev, i) == 0)
+				continue;
+
+			pci_start = pci_resource_start(pdev, i);
+			pci_end = pci_resource_end(pdev, i);
+
+			if (res->start == 0 && res->end == 0)
+				continue;
+
+			acpi_start = res->start;
+			acpi_end = res->end;
+
+			/*
+			 * If the ACPI region doesn't overlap the PCI
+			 * region at all, there's no problem.
+			 */
+			if (acpi_end < pci_start || acpi_start > pci_end)
+				continue;
+
+			/*
+			 * If the PNP region completely encloses (or is
+			 * at least as large as) the PCI region, that's
+			 * also OK.  For example, this happens when the
+			 * PNP device describes a bridge with PCI
+			 * behind it.
+			 */
+			if (acpi_start <= pci_start && acpi_end >= pci_end)
+				continue;
+
+			/*

drivers/acpi/scan.c static bool acpi_object_is_system_bus(acpi_handle handle) · line 1892

Quoted 10 lines
drivers/acpi/scan.c +10 -0
+			 * Otherwise, the ACPI region overlaps *part* of
+			 * the PCI region, and that might prevent a PCI
+			 * driver from requesting its resources.
+			 */
+			return true;
+		}
+	}
+	return false;
+}
+

The routine below should go into resource.c.

Quoted 69 lines
drivers/acpi/scan.c +69 -0
+static acpi_status __init __acpi_reserve_motherboard_resource(struct acpi_resource *res,
+							void *data)
+{
+	struct resource r = {0};
+	acpi_handle handle = data;
+	struct acpi_device *device;
+	int result;
+
+	result = acpi_bus_get_device(handle, &device);
+	if (result)
+		return AE_OK;
+
+	if (!device->status.present)
+		return AE_OK;
+
+	switch (res->type) {
+	case ACPI_RESOURCE_TYPE_MEMORY24:
+	case ACPI_RESOURCE_TYPE_MEMORY32:
+	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
+		if (!acpi_dev_resource_memory(res, &r))
+			return AE_OK;
+		break;
+	case ACPI_RESOURCE_TYPE_IO:
+	case ACPI_RESOURCE_TYPE_FIXED_IO:
+		if (!acpi_dev_resource_io(res, &r))
+			return AE_OK;
+		break;
+	case ACPI_RESOURCE_TYPE_ADDRESS16:
+	case ACPI_RESOURCE_TYPE_ADDRESS32:
+	case ACPI_RESOURCE_TYPE_ADDRESS64:
+		if (!acpi_dev_resource_address_space(res, &r))
+			return AE_OK;
+		break;
+	case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
+		if (!acpi_dev_resource_ext_address_space(res, &r))
+			return AE_OK;
+		break;
+	default:
+		return AE_OK;
+	}
+
+	if (r.flags & IORESOURCE_DISABLED)
+		return AE_OK;
+
+	if (is_pci_reserved(&r))
+		return AE_OK;
+
+	if (r.flags & IORESOURCE_IO) {
+		if (r.start < 0x100)
+		/*
+		 * Below 0x100 is only standard PC hardware
+		 * (pics, kbd, timer, dma, ...)
+		 * We should not get resource conflicts there,
+		 * and the kernel reserves these anyway
+		 * (see arch/i386/kernel/setup.c).
+		 * So, do nothing
+		 */
+			return AE_OK;
+		if (r.end < r.start)
+			return AE_OK;       /* invalid */
+                reserve_range(device, &r, 1);
+        } else if (r.flags & IORESOURCE_MEM) {
+                reserve_range(device, &r, 0);
+        }
+
+	return AE_OK;
+}
+
+static int __init acpi_reserve_motherboard_resource(void)

drivers/acpi/scan.c static bool acpi_object_is_system_bus(acpi_handle handle) · line 1971

Quoted 10 lines
drivers/acpi/scan.c +10 -0
+{
+	struct acpi_motherboard_resource *res;
+
+	list_for_each_entry(res, &acpi_motherboard_resource_list, node)
+		acpi_walk_resources(res->handle, METHOD_NAME__CRS,
+			__acpi_reserve_motherboard_resource, res->handle);
+
+	return 0;
+}
+fs_initcall(acpi_reserve_motherboard_resource);

Why don't we call that directly from acpi_scan_init() and do we need the acpi_motherboard_resource_list list to be present any more after calling this function?

Quoted 12 lines
drivers/acpi/scan.c +2 -0
+
 static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
 				int device_type)
 {
 	acpi_status status;
 	struct acpi_device_info *info;
 	struct acpi_pnp_device_id_list *cid_list;
+	int is_mb_resource = 0;
 	int i;
 
 	switch (device_type) {

drivers/acpi/scan.c static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp, · line 1997

Quoted 6 lines
drivers/acpi/scan.c +1 -2
@@ -1804,13 +1994,20 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
 		}
 
 		if (info->valid & ACPI_VALID_HID) {
-			acpi_add_id(pnp, info->hardware_id.string);
-			pnp->type.platform_id = 1;
+			if (!acpi_is_motherboard_resource(info->hardware_id.string)) {

I would reverse the check. That is, do

			if (!acpi_is_motherboard_resource(info->hardware_id.string)) {
				is_mb_resource = 1;
			} else { ...

Also, don't we really want to create platform devices for the ACPI device objects in question?

Quoted 20 lines
drivers/acpi/scan.c +10 -2
+				acpi_add_id(pnp, info->hardware_id.string);
+				pnp->type.platform_id = 1;
+			} else
+				is_mb_resource = 1;
 		}
 		if (info->valid & ACPI_VALID_CID) {
 			cid_list = &info->compatible_id_list;
-			for (i = 0; i < cid_list->count; i++)
-				acpi_add_id(pnp, cid_list->ids[i].string);
+			for (i = 0; i < cid_list->count; i++) {
+				if (!acpi_is_motherboard_resource(cid_list->ids[i].string))
+					acpi_add_id(pnp, cid_list->ids[i].string);
+				else
+					is_mb_resource = 1;
+			}
 		}
 		if (info->valid & ACPI_VALID_ADR) {
 			pnp->bus_address = info->address;

drivers/acpi/scan.c static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp, · line 2027

Quoted 9 lines
drivers/acpi/scan.c +3 -0
@@ -1822,6 +2019,9 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
 
 		kfree(info);
 
+		if (is_mb_resource)
+			acpi_record_motherboard_resource(handle);
+
 		/*
 		 * Some devices don't reliably have _HIDs & _CIDs, so add
 		 * synthetic HIDs to make sure drivers can find them.

Overall, it looks reasonable, but it can't be a replacement for the $subject patch.

I also should mention that I don't want the special case for PNP devices to stay there forever, but in my opinion we do need it at the moment for a couple of reasons.

Rafael

#4 lore raw
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Zhang Rui

Hi, Rafael,

Quoted 1 line · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Quoted 7 lines

[cut]

Quoted 2 lines

Note that I've just tested on my machine and it works well.
I still need the bug reporter to check if the patch fixes bug 81511 or not.

The FUJ02B1 and FUJ02E3 devices in bug 81971 have the same problem and they aren't motherboard devices.

Right, but IMO, the rootcause of that bug is that
1. the PNP id table in fujitsu-laptop driver was introduced for some reason, probably it is used as an indicator for module auto-loading, and nowadays, this is redundant because fujitsu-laptop driver probes ACPI device only, and the driver will be loaded if the ACPI device objects for FUJ02B1 and FUJ02E3 is created.
2. This "redundant" PNP id table results in that those IDs are added to PNP ID list unnecessarily, and results in PNP device nodes for those devices are created unnecessarily.

Quoted 3 lines

Yes, we need to convert that driver
to use a PNP driver structure or a platform device, but (1) we need a -stable fix *first*

I agree.

Quoted 2 lines

and (2) the cases we already know about may not be
the only broken ones.

Agree.
But the issue addressed in your patch is that PNP scan handler blocks ACPI driver from being probed, right?
So my question would be,
1. If the id in PNP scan handler does not have a PNP driver, like the FUJ02B1/FUJ02E3 issue, what do we need the id in PNP scan handler? In fact, I think this is a good chance for us to cleanup the ACPI PNP id list, as long as we can fix them in time.
2. If the id in PNP scan handler has a PNP driver, should we allow both PNP driver and ACPI driver loaded? I think PNP system driver is the only case that makes us have to say yes, and what I'm trying to do is to fix this in the following patch.

Plus, IMO, your patch only fixes the PNP bus vs. ACPI bus issue. We still may get bug report complaining some *PLATFORM* driver stops to functional if the ACPI node has _CID PNP0C01/PNP0C02, sooner or later. right?

thanks,
rui

Quoted 369 lines
Quoted 16 lines

From c6c388728d08a6368f21dab61d6f0a940e0ea13a Mon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Thu, 21 Aug 2014 13:39:47 +0800
Subject: [RFC PATCH] ACPI: introduce motherboard resource management

ACPI Devices with _HID/_CID PNP0C01/PNP0C02 represents that they have some motherboard resources that needs to be reserved.

We used to enumerated those devices to PNP bus and rely on PNP system driver to do resource reservation.
But this mechanism does not work well nowadays as many devices not only represent motherboard resources, but also represent physical devices that need native drivers other than PNP system driver for the device to work. For example,
1) https://bugzilla.kernel.org/show_bug.cgi?id=46741,

Quoted 6 lines
    Device (NIPM)
    {
        Name (_HID, EisaId ("IPI0001"))  // _HID: Hardware ID
        Name (_CID, EisaId ("PNP0C01"))  // _CID: Compatible ID

the NIPM device has _CID PNP0C01 but it is an IPMI device. PNP system driver blocks the PNP IPMI driver to probe.

That is a good reason for PNP0C01 to be dropped from acpi_pnp_device_ids[].

Quoted 8 lines

2) https://bugzilla.kernel.org/show_bug.cgi?id=81511

        Device (IFFS)
        {
            Name (_HID, EisaId ("INT3392"))  // _HID: Hardware ID
            Name (_CID, EisaId ("PNP0C02"))  // _CID: Compatible ID

the IFFS device has _CID PNP0C02, but it is an intel rapid start device, which already has an ACPI driver at drivers/platform/x86/intel-rst.c

And which should be a platform driver really.

Quoted 10 lines

3) a couple of machines, including the on in
https://bugzilla.kernel.org/show_bug.cgi?id=81511, has the AML code like following

        Device (PTID)
        {
            Name (_HID, EisaId ("INT340E"))  // _HID: Hardware ID
            Name (_CID, EisaId ("PNP0C02"))  // _CID: Compatible ID

the PTID device has _CID PNP0C02, but it is also represents an INT340E device, there is a platform bus driver for this device which will be introduced by myself soon.

Again, that's a good reason for dropping PNP0C02 from acpi_pnp_device_ids[].

Quoted 49 lines

In any of the above cases, the current code for managing PNP0C01/PNP0C02 resources in Linux kernel is broken, because it either blocks the physical device driver on the same bus, or results in multiple drivers loaded for the same ACPI device node, which may also has some potential risks.

Thus, IMO, we need a clean way to handle those motherboard resources. Given that PNP0C01/PNP0C02 is more like an indicator for reserving the resources, this patch
1. does the resource reservation in ACPI code directly, with the same logic and time point in drivers/pnp/quirks.c and drivers/pnp/system.c.
2. makes PNP0C01/PNP0C02 PNP id transparent to Linux devices and drivers, thus PNP system driver becomes a no-op for ACPI enumerated devices.

This is just a draft patch, and I'd like to see if this is the right direction to go. Any comments are welcome.

---
 drivers/acpi/acpi_pnp.c |   3 -
 drivers/acpi/scan.c     | 208 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 204 insertions(+), 7 deletions(-)
drivers/acpi/acpi_pnp.c +0 -3
index 1f8b204..a7deae5 100644
@@ -134,9 +134,6 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	{"FUJ02bf"},
 	{"FUJ02B1"},
 	{"FUJ02E3"},
-	/* system */
-	{"PNP0c02"},		/* General ID for reserving resources */
-	{"PNP0c01"},		/* memory controller */
 	/* rtc_cmos */
 	{"PNP0b00"},
 	{"PNP0b01"},
drivers/acpi/scan.c +1 -0
index 0a817ad..674518b 100644
@@ -11,6 +11,7 @@
 #include <linux/kthread.h>
 #include <linux/dmi.h>
 #include <linux/nls.h>
+#include <linux/pci.h>
 
 #include <asm/pgtable.h>
 

drivers/acpi/scan.c static bool acpi_object_is_system_bus(acpi_handle handle) · line 1789

Quoted 8 lines
drivers/acpi/scan.c +5 -0
@@ -1781,12 +1782,201 @@ static bool acpi_object_is_system_bus(acpi_handle handle)
 	return false;
 }
 
+static bool acpi_is_motherboard_resource(char *id)
+{
+	return !(strncmp(id, "PNP0C01", sizeof("PNP0C01")) &&
+		 strncmp(id, "PNP0C02", sizeof("PNP0C02")));
+}

Can we use __acpi_match_device() for that?

Quoted 35 lines
drivers/acpi/scan.c +35 -0
+
+static LIST_HEAD(acpi_motherboard_resource_list);
+
+struct acpi_motherboard_resource {
+	acpi_handle handle;
+	struct list_head node;
+};
+
+static void acpi_record_motherboard_resource(acpi_handle handle)
+{
+	struct acpi_motherboard_resource *res;
+
+	res = kzalloc(sizeof(struct acpi_motherboard_resource), GFP_KERNEL);
+	if (!res)
+		return;
+	res->handle = handle;
+	list_add(&res->node, &acpi_motherboard_resource_list);
+}
+
+static void reserve_range(struct acpi_device *device, struct resource *r, int port)
+{
+	char *regionid;
+	resource_size_t start = r->start, end = r->end;
+	struct resource *res;
+	int result;
+
+	regionid = kmalloc(20, GFP_KERNEL);
+	if (!regionid)
+		return;
+
+	snprintf(regionid, 20, "ACPI %s", dev_name(&device->dev));
+		
+	if (port)
+		res = request_region(start, end - start + 1, regionid);
+	else

drivers/acpi/scan.c static bool acpi_object_is_system_bus(acpi_handle handle) · line 1834

Quoted 10 lines
drivers/acpi/scan.c +10 -0
+		res = request_mem_region(start, end - start + 1, regionid);
+	if (res)
+		res->flags &= ~IORESOURCE_BUSY;
+	else
+		kfree(regionid);
+
+	dev_info(&device->dev, "%pR %s reserved\n", r,
+			res ? "has been" : "could not be");
+}
+

The routine below should go into the PCI core.

Quoted 48 lines
drivers/acpi/scan.c +48 -0
+static int is_pci_reserved(struct resource *res)
+{
+	struct pci_dev *pdev = NULL;
+	resource_size_t acpi_start, acpi_end, pci_start, pci_end;
+	int i;
+
+	/*
+	 * Some BIOSes have motherboard devices with resources that
+	 * partially overlap PCI BARs.
+	 * Those resources should not be reserved, or else, it will
+	 * prevent the normal PCI driver from requesting them later.
+	 */
+	for_each_pci_dev(pdev) {
+		for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
+			unsigned long type;
+
+			type = pci_resource_flags(pdev, i) & res->flags
+			       & (IORESOURCE_IO | IORESOURCE_MEM);
+			if (!type || pci_resource_len(pdev, i) == 0)
+				continue;
+
+			pci_start = pci_resource_start(pdev, i);
+			pci_end = pci_resource_end(pdev, i);
+
+			if (res->start == 0 && res->end == 0)
+				continue;
+
+			acpi_start = res->start;
+			acpi_end = res->end;
+
+			/*
+			 * If the ACPI region doesn't overlap the PCI
+			 * region at all, there's no problem.
+			 */
+			if (acpi_end < pci_start || acpi_start > pci_end)
+				continue;
+
+			/*
+			 * If the PNP region completely encloses (or is
+			 * at least as large as) the PCI region, that's
+			 * also OK.  For example, this happens when the
+			 * PNP device describes a bridge with PCI
+			 * behind it.
+			 */
+			if (acpi_start <= pci_start && acpi_end >= pci_end)
+				continue;
+
+			/*

drivers/acpi/scan.c static bool acpi_object_is_system_bus(acpi_handle handle) · line 1892

Quoted 10 lines
drivers/acpi/scan.c +10 -0
+			 * Otherwise, the ACPI region overlaps *part* of
+			 * the PCI region, and that might prevent a PCI
+			 * driver from requesting its resources.
+			 */
+			return true;
+		}
+	}
+	return false;
+}
+

The routine below should go into resource.c.

Quoted 69 lines
drivers/acpi/scan.c +69 -0
+static acpi_status __init __acpi_reserve_motherboard_resource(struct acpi_resource *res,
+							void *data)
+{
+	struct resource r = {0};
+	acpi_handle handle = data;
+	struct acpi_device *device;
+	int result;
+
+	result = acpi_bus_get_device(handle, &device);
+	if (result)
+		return AE_OK;
+
+	if (!device->status.present)
+		return AE_OK;
+
+	switch (res->type) {
+	case ACPI_RESOURCE_TYPE_MEMORY24:
+	case ACPI_RESOURCE_TYPE_MEMORY32:
+	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
+		if (!acpi_dev_resource_memory(res, &r))
+			return AE_OK;
+		break;
+	case ACPI_RESOURCE_TYPE_IO:
+	case ACPI_RESOURCE_TYPE_FIXED_IO:
+		if (!acpi_dev_resource_io(res, &r))
+			return AE_OK;
+		break;
+	case ACPI_RESOURCE_TYPE_ADDRESS16:
+	case ACPI_RESOURCE_TYPE_ADDRESS32:
+	case ACPI_RESOURCE_TYPE_ADDRESS64:
+		if (!acpi_dev_resource_address_space(res, &r))
+			return AE_OK;
+		break;
+	case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
+		if (!acpi_dev_resource_ext_address_space(res, &r))
+			return AE_OK;
+		break;
+	default:
+		return AE_OK;
+	}
+
+	if (r.flags & IORESOURCE_DISABLED)
+		return AE_OK;
+
+	if (is_pci_reserved(&r))
+		return AE_OK;
+
+	if (r.flags & IORESOURCE_IO) {
+		if (r.start < 0x100)
+		/*
+		 * Below 0x100 is only standard PC hardware
+		 * (pics, kbd, timer, dma, ...)
+		 * We should not get resource conflicts there,
+		 * and the kernel reserves these anyway
+		 * (see arch/i386/kernel/setup.c).
+		 * So, do nothing
+		 */
+			return AE_OK;
+		if (r.end < r.start)
+			return AE_OK;       /* invalid */
+                reserve_range(device, &r, 1);
+        } else if (r.flags & IORESOURCE_MEM) {
+                reserve_range(device, &r, 0);
+        }
+
+	return AE_OK;
+}
+
+static int __init acpi_reserve_motherboard_resource(void)

drivers/acpi/scan.c static bool acpi_object_is_system_bus(acpi_handle handle) · line 1971

Quoted 10 lines
drivers/acpi/scan.c +10 -0
+{
+	struct acpi_motherboard_resource *res;
+
+	list_for_each_entry(res, &acpi_motherboard_resource_list, node)
+		acpi_walk_resources(res->handle, METHOD_NAME__CRS,
+			__acpi_reserve_motherboard_resource, res->handle);
+
+	return 0;
+}
+fs_initcall(acpi_reserve_motherboard_resource);

Why don't we call that directly from acpi_scan_init() and do we need the acpi_motherboard_resource_list list to be present any more after calling this function?

Quoted 12 lines
drivers/acpi/scan.c +2 -0
+
 static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
 				int device_type)
 {
 	acpi_status status;
 	struct acpi_device_info *info;
 	struct acpi_pnp_device_id_list *cid_list;
+	int is_mb_resource = 0;
 	int i;
 
 	switch (device_type) {

drivers/acpi/scan.c static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp, · line 1997

Quoted 6 lines
drivers/acpi/scan.c +1 -2
@@ -1804,13 +1994,20 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
 		}
 
 		if (info->valid & ACPI_VALID_HID) {
-			acpi_add_id(pnp, info->hardware_id.string);
-			pnp->type.platform_id = 1;
+			if (!acpi_is_motherboard_resource(info->hardware_id.string)) {

I would reverse the check. That is, do

			if (!acpi_is_motherboard_resource(info->hardware_id.string)) {
				is_mb_resource = 1;
			} else { ...

Also, don't we really want to create platform devices for the ACPI device objects in question?

Quoted 20 lines
drivers/acpi/scan.c +10 -2
+				acpi_add_id(pnp, info->hardware_id.string);
+				pnp->type.platform_id = 1;
+			} else
+				is_mb_resource = 1;
 		}
 		if (info->valid & ACPI_VALID_CID) {
 			cid_list = &info->compatible_id_list;
-			for (i = 0; i < cid_list->count; i++)
-				acpi_add_id(pnp, cid_list->ids[i].string);
+			for (i = 0; i < cid_list->count; i++) {
+				if (!acpi_is_motherboard_resource(cid_list->ids[i].string))
+					acpi_add_id(pnp, cid_list->ids[i].string);
+				else
+					is_mb_resource = 1;
+			}
 		}
 		if (info->valid & ACPI_VALID_ADR) {
 			pnp->bus_address = info->address;

drivers/acpi/scan.c static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp, · line 2027

Quoted 9 lines
drivers/acpi/scan.c +3 -0
@@ -1822,6 +2019,9 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
 
 		kfree(info);
 
+		if (is_mb_resource)
+			acpi_record_motherboard_resource(handle);
+
 		/*
 		 * Some devices don't reliably have _HIDs & _CIDs, so add
 		 * synthetic HIDs to make sure drivers can find them.

Overall, it looks reasonable, but it can't be a replacement for the $subject patch.

I also should mention that I don't want the special case for PNP devices to stay there forever, but in my opinion we do need it at the moment for a couple of reasons.

Rafael

#5 lore raw
Quoted 15 lines · Zhang Rui
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Zhang Rui

Hi, Rafael,

Quoted 1 line · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Quoted 7 lines

[cut]

Quoted 2 lines

Note that I've just tested on my machine and it works well.
I still need the bug reporter to check if the patch fixes bug 81511 or not.

The FUJ02B1 and FUJ02E3 devices in bug 81971 have the same problem and they aren't motherboard devices.

Quoted 6 lines

Right, but IMO, the rootcause of that bug is that
1. the PNP id table in fujitsu-laptop driver was introduced for some reason, probably it is used as an indicator for module auto-loading, and nowadays, this is redundant because fujitsu-laptop driver probes ACPI device only, and the driver will be loaded if the ACPI device objects for FUJ02B1 and FUJ02E3 is created.

We may be able to drop the Fujitsu devices from the ACPI PNP list and all may work. Still, does that fix all of the potential problems?

Quoted 3 lines

2. This "redundant" PNP id table results in that those IDs are added to PNP ID list unnecessarily, and results in PNP device nodes for those devices are created unnecessarily.

Yes, that may be the case, but the way to deal with that is not to break thing and then see what's broken and fix it, but to get rid of ACPI drivers one by one in which case we can control what's been changed and why.

Quoted 4 lines
Quoted 3 lines

Yes, we need to convert that driver
to use a PNP driver structure or a platform device, but (1) we need a -stable fix *first*

Quoted 8 lines

I agree.

Quoted 2 lines

and (2) the cases we already know about may not be
the only broken ones.

Agree.
But the issue addressed in your patch is that PNP scan handler blocks ACPI driver from being probed, right?

Yes.

Quoted 5 lines

So my question would be,
1. If the id in PNP scan handler does not have a PNP driver, like the FUJ02B1/FUJ02E3 issue, what do we need the id in PNP scan handler? In fact, I think this is a good chance for us to cleanup the ACPI PNP id list, as long as we can fix them in time.

No.

We need -stable to work and there's no way I will mark the motherboard resource changes for -stable. Second, if we deal with it as I said (that is, get rid of ACPI drivers gradually), we will clean up that list in the process without breaking things for people in random ways.

Quoted 9 lines

2. If the id in PNP scan handler has a PNP driver, should we allow both PNP driver and ACPI driver loaded? I think PNP system driver is the only case that makes us have to say yes, and what I'm trying to do is to fix this in the following patch.

Plus, IMO, your patch only fixes the PNP bus vs. ACPI bus issue. We still may get bug report complaining some *PLATFORM* driver stops to functional if the ACPI node has _CID PNP0C01/PNP0C02, sooner or later. right?

No.

We never allowed ACPI drivers to bind to ACPI device objects having platform device companions, wherease we *did* allow that for ACPI device objects having PNP device companions. We simply need to go back to what we were doing and fix things *on* *top* of that.

Any other approach pretty much guarantees leaving breakage in random places.

So I'm fine with cleaning up the PNP list *if* you convert the drivers in question from ACPI drivers to something else (platform drivers preferably) at the same time.

Rafael

Tested-by Dirk Griesbach
#6 lore raw
Quoted 55 lines · Rafael J. Wysocki
Quoted 15 lines · Zhang Rui
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Zhang Rui

Hi, Rafael,

Quoted 1 line · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Quoted 7 lines

[cut]

Quoted 2 lines

Note that I've just tested on my machine and it works well.
I still need the bug reporter to check if the patch fixes bug 81511 or not.

The FUJ02B1 and FUJ02E3 devices in bug 81971 have the same problem and they aren't motherboard devices.

Quoted 6 lines

Right, but IMO, the rootcause of that bug is that
1. the PNP id table in fujitsu-laptop driver was introduced for some reason, probably it is used as an indicator for module auto-loading, and nowadays, this is redundant because fujitsu-laptop driver probes ACPI device only, and the driver will be loaded if the ACPI device objects for FUJ02B1 and FUJ02E3 is created.

We may be able to drop the Fujitsu devices from the ACPI PNP list and all may work. Still, does that fix all of the potential problems?

Quoted 3 lines

2. This "redundant" PNP id table results in that those IDs are added to PNP ID list unnecessarily, and results in PNP device nodes for those devices are created unnecessarily.

Yes, that may be the case, but the way to deal with that is not to break thing and then see what's broken and fix it, but to get rid of ACPI drivers one by one in which case we can control what's been changed and why.

Quoted 4 lines
Quoted 3 lines

Yes, we need to convert that driver
to use a PNP driver structure or a platform device, but (1) we need a -stable fix *first*

Quoted 8 lines

I agree.

Quoted 2 lines

and (2) the cases we already know about may not be
the only broken ones.

Agree.
But the issue addressed in your patch is that PNP scan handler blocks ACPI driver from being probed, right?

Yes.

Quoted 5 lines

So my question would be,
1. If the id in PNP scan handler does not have a PNP driver, like the FUJ02B1/FUJ02E3 issue, what do we need the id in PNP scan handler? In fact, I think this is a good chance for us to cleanup the ACPI PNP id list, as long as we can fix them in time.

Quoted 4 lines

No.

We need -stable to work and there's no way I will mark the motherboard resource changes for -stable.

I agree. And I would rather consider my patch as the start point of a long term solution.

Quoted 3 lines

Second, if we deal with it as I said (that is,
get rid of ACPI drivers gradually), we will clean up that list in the process without breaking things for people in random ways.

Agree.

Quoted 11 lines
Quoted 10 lines

2. If the id in PNP scan handler has a PNP driver, should we allow both PNP driver and ACPI driver loaded? I think PNP system driver is the only case that makes us have to say yes, and what I'm trying to do is to fix this in the following patch.

Plus, IMO, your patch only fixes the PNP bus vs. ACPI bus issue. We still may get bug report complaining some *PLATFORM* driver stops to functional if the ACPI node has _CID PNP0C01/PNP0C02, sooner or later. right?

Quoted 4 lines

No.

We never allowed ACPI drivers to bind to ACPI device objects having platform device companions,

No, I mean, a platform device is used to be created as the ACPI device object _HID was in the previous acpi_platform scan handler list, but if this device has _CID PNP0C01/PNP0C02, the platform device will not be created any more after the ACPI enumeration re-work patches.

Quoted 10 lines

wherease we *did* allow that for ACPI device objects having
PNP device companions. We simply need to go back to what we were doing and fix things *on* *top* of that.

Any other approach pretty much guarantees leaving breakage in random places.

So I'm fine with cleaning up the PNP list *if* you convert the drivers in question from ACPI drivers to something else (platform drivers preferably) at the same time.

yes, I see.

So I guess the following patch can be upstream candidate, right?

Quoted 1 line

From e32c2de37750d622dae6ef9d2f5c448a528a7edb Mon Sep 17 00:00:00 2001

From: Zhang Rui <[email protected]>
Date: Fri, 22 Aug 2014 09:06:10 +0800
Subject: [PATCH] ACPI: remove Fujitsu backlight and hotkey device ID from ACPI
PNP id list

Fujitsu backlight and hotkey devices have ACPI drivers.
The PNP MODULE_DEVICE_TABLE in fujitsu-laptop driver is just used as an indicator for module autoloading. But this is wrong because what we need is ACPI module device table instead because the driver is probing ACPI devices.

Thus remove those ids from ACPI PNP scan handler list as we don't have PNP driver for them, and convert the fujitsu-laptop PNP MODULE_DEVICE_TABLE to ACPI MODULE_DEVICE_TABLE.

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=81971

---
 drivers/acpi/acpi_pnp.c               |  4 ----
 drivers/platform/x86/fujitsu-laptop.c | 16 +++++++---------
 2 files changed, 7 insertions(+), 13 deletions(-)
drivers/acpi/acpi_pnp.c +0 -4
index 1f8b204..b193f84 100644
@@ -130,10 +130,6 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	{"PNP0401"},		/* ECP Printer Port */
 	/* apple-gmux */
 	{"APP000B"},
-	/* fujitsu-laptop.c */
-	{"FUJ02bf"},
-	{"FUJ02B1"},
-	{"FUJ02E3"},
 	/* system */
 	{"PNP0c02"},		/* General ID for reserving resources */
 	{"PNP0c01"},		/* memory controller */
drivers/platform/x86/fujitsu-laptop.c +7 -9
index 87aa28c..2655d4a 100644
@@ -1050,6 +1050,13 @@ static struct acpi_driver acpi_fujitsu_hotkey_driver = {
 		},
 };
 
+static const struct acpi_device_id fujitsu_ids[] __used = {
+	{ACPI_FUJITSU_HID, 0},
+	{ACPI_FUJITSU_HOTKEY_HID, 0},
+	{"", 0}
+};
+MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
+
 static int __init fujitsu_init(void)
 {
 	int ret, result, max_brightness;
@@ -1208,12 +1215,3 @@ MODULE_LICENSE("GPL");
 MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*");
 MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1E6:*:cvrS6420:*");
 MODULE_ALIAS("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*");
-
-static struct pnp_device_id pnp_ids[] __used = {
-	{.id = "FUJ02bf"},
-	{.id = "FUJ02B1"},
-	{.id = "FUJ02E3"},
-	{.id = ""}
-};
-
-MODULE_DEVICE_TABLE(pnp, pnp_ids);
Signature · 1 line
1.8.3.2
#7 lore raw

On Saturday, August 23, 2014 11:21:17 PM Zhang Rui wrote:

[cut]

Darren, would there be any problems if I took the patch below from Rui for 3.18?

Quoted 73 lines

So I guess the following patch can be upstream candidate, right?

From e32c2de37750d622dae6ef9d2f5c448a528a7edb Mon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Fri, 22 Aug 2014 09:06:10 +0800
Subject: [PATCH] ACPI: remove Fujitsu backlight and hotkey device ID from ACPI
PNP id list

Fujitsu backlight and hotkey devices have ACPI drivers.
The PNP MODULE_DEVICE_TABLE in fujitsu-laptop driver is just used as an indicator for module autoloading. But this is wrong because what we need is ACPI module device table instead because the driver is probing ACPI devices.

Thus remove those ids from ACPI PNP scan handler list as we don't have PNP driver for them, and convert the fujitsu-laptop PNP MODULE_DEVICE_TABLE to ACPI MODULE_DEVICE_TABLE.

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=81971

---
 drivers/acpi/acpi_pnp.c               |  4 ----
 drivers/platform/x86/fujitsu-laptop.c | 16 +++++++---------
 2 files changed, 7 insertions(+), 13 deletions(-)
drivers/acpi/acpi_pnp.c +0 -4
index 1f8b204..b193f84 100644
@@ -130,10 +130,6 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	{"PNP0401"},		/* ECP Printer Port */
 	/* apple-gmux */
 	{"APP000B"},
-	/* fujitsu-laptop.c */
-	{"FUJ02bf"},
-	{"FUJ02B1"},
-	{"FUJ02E3"},
 	/* system */
 	{"PNP0c02"},		/* General ID for reserving resources */
 	{"PNP0c01"},		/* memory controller */
drivers/platform/x86/fujitsu-laptop.c +7 -9
index 87aa28c..2655d4a 100644
@@ -1050,6 +1050,13 @@ static struct acpi_driver acpi_fujitsu_hotkey_driver = {
 		},
 };
 
+static const struct acpi_device_id fujitsu_ids[] __used = {
+	{ACPI_FUJITSU_HID, 0},
+	{ACPI_FUJITSU_HOTKEY_HID, 0},
+	{"", 0}
+};
+MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
+
 static int __init fujitsu_init(void)
 {
 	int ret, result, max_brightness;
@@ -1208,12 +1215,3 @@ MODULE_LICENSE("GPL");
 MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*");
 MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1E6:*:cvrS6420:*");
 MODULE_ALIAS("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*");
-
-static struct pnp_device_id pnp_ids[] __used = {
-	{.id = "FUJ02bf"},
-	{.id = "FUJ02B1"},
-	{.id = "FUJ02E3"},
-	{.id = ""}
-};
-
-MODULE_DEVICE_TABLE(pnp, pnp_ids);
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
Acked-by
#8 lore raw
Quoted 6 lines · Rafael J. Wysocki

On Saturday, August 23, 2014 11:21:17 PM Zhang Rui wrote:

[cut]

Darren, would there be any problems if I took the patch below from Rui for 3.18?

No objection.

Quoted 83 lines
Quoted 73 lines

So I guess the following patch can be upstream candidate, right?

From e32c2de37750d622dae6ef9d2f5c448a528a7edb Mon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Fri, 22 Aug 2014 09:06:10 +0800
Subject: [PATCH] ACPI: remove Fujitsu backlight and hotkey device ID from ACPI
PNP id list

Fujitsu backlight and hotkey devices have ACPI drivers.
The PNP MODULE_DEVICE_TABLE in fujitsu-laptop driver is just used as an indicator for module autoloading. But this is wrong because what we need is ACPI module device table instead because the driver is probing ACPI devices.

Thus remove those ids from ACPI PNP scan handler list as we don't have PNP driver for them, and convert the fujitsu-laptop PNP MODULE_DEVICE_TABLE to ACPI MODULE_DEVICE_TABLE.

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=81971

---
 drivers/acpi/acpi_pnp.c               |  4 ----
 drivers/platform/x86/fujitsu-laptop.c | 16 +++++++---------
 2 files changed, 7 insertions(+), 13 deletions(-)
drivers/acpi/acpi_pnp.c +0 -4
index 1f8b204..b193f84 100644
@@ -130,10 +130,6 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	{"PNP0401"},		/* ECP Printer Port */
 	/* apple-gmux */
 	{"APP000B"},
-	/* fujitsu-laptop.c */
-	{"FUJ02bf"},
-	{"FUJ02B1"},
-	{"FUJ02E3"},
 	/* system */
 	{"PNP0c02"},		/* General ID for reserving resources */
 	{"PNP0c01"},		/* memory controller */
drivers/platform/x86/fujitsu-laptop.c +7 -9
index 87aa28c..2655d4a 100644
@@ -1050,6 +1050,13 @@ static struct acpi_driver acpi_fujitsu_hotkey_driver = {
 		},
 };
 
+static const struct acpi_device_id fujitsu_ids[] __used = {
+	{ACPI_FUJITSU_HID, 0},
+	{ACPI_FUJITSU_HOTKEY_HID, 0},
+	{"", 0}
+};
+MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
+
 static int __init fujitsu_init(void)
 {
 	int ret, result, max_brightness;
@@ -1208,12 +1215,3 @@ MODULE_LICENSE("GPL");
 MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*");
 MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1E6:*:cvrS6420:*");
 MODULE_ALIAS("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*");
-
-static struct pnp_device_id pnp_ids[] __used = {
-	{.id = "FUJ02bf"},
-	{.id = "FUJ02B1"},
-	{.id = "FUJ02E3"},
-	{.id = ""}
-};
-
-MODULE_DEVICE_TABLE(pnp, pnp_ids);
Signature · 7 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
#9 lore raw
In reply to Rafael J. Wysocki
Quoted 33 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

We generally don't allow ACPI drivers to bind to ACPI device objects that companion "physical" device objects are created for to avoid situations in which two different drivers may attempt to handle one device at the same time. Recent ACPI device enumeration rework extended that approach to ACPI PNP devices by starting to use a scan handler for enumerating them. However, we previously allowed ACPI drivers to bind to ACPI device objects with existing PNP device companions and changing that led to functional regressions on some systems.

For this reason, add a special check for PNP devices in acpi_device_probe() so that ACPI drivers can bind to ACPI device objects having existing PNP device companions as before.

Fixes eec15edbb0e1 (ACPI / PNP: use device ID list for PNPACPI device enumeration)
---
 drivers/acpi/acpi_pnp.c |    5 +++++
 drivers/acpi/internal.h |    1 +
 drivers/acpi/scan.c     |    2 +-
 3 files changed, 7 insertions(+), 1 deletion(-)

Index: linux-pm/drivers/acpi/acpi_pnp.c
===================================================================

drivers/acpi/acpi_pnp.c void __init acpi_pnp_init(void) · line 403

Quoted 8 lines
drivers/acpi/acpi_pnp.c +5 -0
@@ -396,3 +396,8 @@ void __init acpi_pnp_init(void)
 {
 	acpi_scan_add_handler(&acpi_pnp_handler);
 }
+
+bool is_acpi_pnp_device(struct acpi_device *adev)
+{
+	return adev->handler == &acpi_pnp_handler;
+}

can we reuse acpi_is_pnp_device()?
The only difference is that acpi_is_pnp_device() returns true for RTC_CMOS devices, which is not a problem IMO because RTC CMOS devices have PNP driver only.

thanks,
rui

Quoted 25 lines

Index: linux-pm/drivers/acpi/internal.h
===================================================================

drivers/acpi/internal.h +1 -0
@@ -86,6 +86,7 @@ void acpi_device_add_finalize(struct acp
 void acpi_free_pnp_ids(struct acpi_device_pnp *pnp);
 bool acpi_device_is_present(struct acpi_device *adev);
 bool acpi_device_is_battery(struct acpi_device *adev);
+bool is_acpi_pnp_device(struct acpi_device *adev);
 
 /* --------------------------------------------------------------------------
                                   Power Resource

Index: linux-pm/drivers/acpi/scan.c
===================================================================

drivers/acpi/scan.c +1 -1
@@ -975,7 +975,7 @@ static int acpi_device_probe(struct devi
 	struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
 	int ret;
 
-	if (acpi_dev->handler)
+	if (acpi_dev->handler && !is_acpi_pnp_device(acpi_dev))
 		return -EINVAL;
 
 	if (!acpi_drv->ops.add)
#10 lore raw
Quoted 2 lines · Zhang Rui
Quoted 1 line · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

[cut]

Quoted 12 lines
Quoted 12 lines
 3 files changed, 7 insertions(+), 1 deletion(-)

Index: linux-pm/drivers/acpi/acpi_pnp.c
===================================================================

drivers/acpi/acpi_pnp.c +2 -0
@@ -396,3 +396,8 @@ void __init acpi_pnp_init(void)
 {
 	acpi_scan_add_handler(&acpi_pnp_handler);
 }
+
+bool is_acpi_pnp_device(struct acpi_device *adev)
Quoted 8 lines

drivers/acpi/acpi_pnp.c void __init acpi_pnp_init(void) · line 403

Quoted 3 lines
drivers/acpi/acpi_pnp.c +3 -0
+{
+	return adev->handler == &acpi_pnp_handler;
+}

can we reuse acpi_is_pnp_device()?
The only difference is that acpi_is_pnp_device() returns true for RTC_CMOS devices, which is not a problem IMO because RTC CMOS devices have PNP driver only.

Yes, we can. Overlooked that.

Updated patch is appended.

Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: [PATCH] ACPI / scan: Allow ACPI drivers to bind to PNP device objects

We generally don't allow ACPI drivers to bind to ACPI device objects that companion "physical" device objects are created for to avoid situations in which two different drivers may attempt to handle one device at the same time. Recent ACPI device enumeration rework extended that approach to ACPI PNP devices by starting to use a scan handler for enumerating them. However, we previously allowed ACPI drivers to bind to ACPI device objects with existing PNP device companions and changing that led to functional regressions on some systems.

For this reason, add a special check for PNP devices in acpi_device_probe() so that ACPI drivers can bind to ACPI device objects having existing PNP device companions as before.

---
 drivers/acpi/scan.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/scan.c +1 -1
Index: linux-pm/drivers/acpi/scan.c
===================================================================
@@ -975,7 +975,7 @@ static int acpi_device_probe(struct devi
 	struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
 	int ret;
 
-	if (acpi_dev->handler)
+	if (acpi_dev->handler && !acpi_is_pnp_device(acpi_dev))
 		return -EINVAL;
 
 	if (!acpi_drv->ops.add)