Skip to content

Commit 3ad5df2

Browse files
committed
ACPI: PNP: Drop PNP0C01 and PNP0C02 from acpi_pnp_device_ids[]
There is a long-standing problem with ACPI device enumeration that if the given device has a compatible ID which is one of the generic system resource device IDs (PNP0C01 and PNP0C02), it will be claimed by the PNP scan handler and it will not be represented as a platform device, so it cannot be handled by a platform driver. Drivers have been working around this issue by "manually" creating platform devices that they can bind to (see the Intel HID driver for one example) or adding their device IDs to acpi_nonpnp_device_ids[]. None of the above is particularly clean though and the only reason why the PNP0C01 and PNP0C02 device IDs are present in acpi_pnp_device_ids[] is to allow the legacy PNP system driver to bind to those devices and reserve their resources so they are not used going forward. Obviously, to address this problem PNP0C01 and PNP0C02 need to be dropped from acpi_pnp_device_ids[], but doing so without making any other changes would be problematic because the ACPI core would then create platform devices for the generic system resource device objects and that would not work on all systems for two reasons. First, the PNP system driver explicitly avoids reserving I/O resources below the "standard PC hardware" boundary, 0x100, to avoid conflicts in that range (one possible case when this may happen is when the CMOS RTC driver is involved), but the platform device creation code does not do that. Second, there may be resource conflicts between the "system" devices and the other devices in the system, possibly including conflicts with PCI BARs. Registering the PNP system driver via fs_initcall() helps to manage those conflicts, even though it does not make them go away. Resource conflicts during the registration of "motherboard resources" that occur after PCI has claimed BARs are harmless as a rule and do not need to be addressed in any specific way. To overcome the issues mentioned above, use the observation that it is not actually necessary to create any device objects in addition to struct acpi_device ones in order to reserve the "system" device resources because that can be done directly in the ACPI device enumeration code. Namely, modify acpi_default_enumeration() to add the given ACPI device object to a special "system devices" list if its _HID is either PNP0C01 or PNP0C02 without creating a platform device for it. Next, add a new special acpi_scan_claim_resources() function that will be run via fs_initcall() and will walk that list and reserve resources for each device in it along the lines of what the PNP system driver does. Having made the above changes, drop PNP0C01 and PNP0C02 from acpi_pnp_device_ids[] which will allow platform devices to be created for ACPI device objects whose _CID lists contain PNP0C01 or PNP0C02, but the _HID is not in acpi_pnp_device_ids[]. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org> [ rjw: Drop a leftover comment and add a new one elsewhere ] Link: https://patch.msgid.link/9550709.CDJkKcVGEf@rafael.j.wysocki Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 8f0b4cc commit 3ad5df2

2 files changed

Lines changed: 116 additions & 7 deletions

File tree

drivers/acpi/acpi_pnp.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
125125
{"PNP0401"}, /* ECP Printer Port */
126126
/* apple-gmux */
127127
{"APP000B"},
128-
/* system */
129-
{"PNP0c02"}, /* General ID for reserving resources */
130-
{"PNP0c01"}, /* memory controller */
131128
/* rtc_cmos */
132129
{"PNP0b00"},
133130
{"PNP0b01"},

drivers/acpi/scan.c

Lines changed: 116 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static LIST_HEAD(acpi_scan_handlers_list);
4242
DEFINE_MUTEX(acpi_device_lock);
4343
LIST_HEAD(acpi_wakeup_device_list);
4444
static DEFINE_MUTEX(acpi_hp_context_lock);
45+
static LIST_HEAD(acpi_scan_system_dev_list);
4546

4647
/*
4748
* The UART device described by the SPCR table is the only object which needs
@@ -2203,19 +2204,48 @@ static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used,
22032204
return acpi_bus_check_add(handle, false, (struct acpi_device **)ret_p);
22042205
}
22052206

2207+
struct acpi_scan_system_dev {
2208+
struct list_head node;
2209+
struct acpi_device *adev;
2210+
};
2211+
2212+
static const char * const acpi_system_dev_ids[] = {
2213+
"PNP0C01", /* Memory controller */
2214+
"PNP0C02", /* Motherboard resource */
2215+
NULL
2216+
};
2217+
22062218
static void acpi_default_enumeration(struct acpi_device *device)
22072219
{
22082220
/*
22092221
* Do not enumerate devices with enumeration_by_parent flag set as
22102222
* they will be enumerated by their respective parents.
22112223
*/
2212-
if (!device->flags.enumeration_by_parent) {
2213-
acpi_create_platform_device(device, NULL);
2214-
acpi_device_set_enumerated(device);
2215-
} else {
2224+
if (device->flags.enumeration_by_parent) {
22162225
blocking_notifier_call_chain(&acpi_reconfig_chain,
22172226
ACPI_RECONFIG_DEVICE_ADD, device);
2227+
return;
2228+
}
2229+
if (match_string(acpi_system_dev_ids, -1, acpi_device_hid(device)) >= 0) {
2230+
struct acpi_scan_system_dev *sd;
2231+
2232+
/*
2233+
* This is a generic system device, so there is no need to
2234+
* create a platform device for it, but its resources need to be
2235+
* reserved. However, that needs to be done after all of the
2236+
* other device objects have been processed and PCI has claimed
2237+
* BARs in case there are resource conflicts.
2238+
*/
2239+
sd = kmalloc(sizeof(*sd), GFP_KERNEL);
2240+
if (sd) {
2241+
sd->adev = device;
2242+
list_add_tail(&sd->node, &acpi_scan_system_dev_list);
2243+
}
2244+
} else {
2245+
/* For a regular device object, create a platform device. */
2246+
acpi_create_platform_device(device, NULL);
22182247
}
2248+
acpi_device_set_enumerated(device);
22192249
}
22202250

22212251
static const struct acpi_device_id generic_device_ids[] = {
@@ -2571,6 +2601,88 @@ static void acpi_scan_postponed(void)
25712601
mutex_unlock(&acpi_dep_list_lock);
25722602
}
25732603

2604+
static void acpi_scan_claim_resources(struct acpi_device *adev)
2605+
{
2606+
struct list_head resource_list = LIST_HEAD_INIT(resource_list);
2607+
struct resource_entry *rentry;
2608+
unsigned int count = 0;
2609+
const char *regionid;
2610+
2611+
if (acpi_dev_get_resources(adev, &resource_list, NULL, NULL) <= 0)
2612+
return;
2613+
2614+
regionid = kstrdup(dev_name(&adev->dev), GFP_KERNEL);
2615+
if (!regionid)
2616+
goto exit;
2617+
2618+
list_for_each_entry(rentry, &resource_list, node) {
2619+
struct resource *res = rentry->res;
2620+
struct resource *r;
2621+
2622+
/* Skip disabled and invalid resources. */
2623+
if ((res->flags & IORESOURCE_DISABLED) || res->end < res->start)
2624+
continue;
2625+
2626+
if (res->flags & IORESOURCE_IO) {
2627+
/*
2628+
* Follow the PNP system driver and on x86 skip I/O
2629+
* resources that start below 0x100 (the "standard PC
2630+
* hardware" boundary).
2631+
*/
2632+
if (IS_ENABLED(CONFIG_X86) && res->start < 0x100) {
2633+
dev_info(&adev->dev, "Skipped %pR\n", res);
2634+
continue;
2635+
}
2636+
r = request_region(res->start, resource_size(res), regionid);
2637+
} else if (res->flags & IORESOURCE_MEM) {
2638+
r = request_mem_region(res->start, resource_size(res), regionid);
2639+
} else {
2640+
continue;
2641+
}
2642+
2643+
if (r) {
2644+
r->flags &= ~IORESOURCE_BUSY;
2645+
dev_info(&adev->dev, "Reserved %pR\n", r);
2646+
count++;
2647+
} else {
2648+
/*
2649+
* Failures at this point are usually harmless. PCI
2650+
* quirks, for example, reserve resources they know
2651+
* about too, so there may well be double reservations.
2652+
*/
2653+
dev_info(&adev->dev, "Could not reserve %pR\n", res);
2654+
}
2655+
}
2656+
2657+
if (!count)
2658+
kfree(regionid);
2659+
2660+
exit:
2661+
acpi_dev_free_resource_list(&resource_list);
2662+
}
2663+
2664+
2665+
static int __init acpi_reserve_motherboard_resources(void)
2666+
{
2667+
struct acpi_scan_system_dev *sd, *tmp;
2668+
2669+
guard(mutex)(&acpi_scan_lock);
2670+
2671+
list_for_each_entry_safe(sd, tmp, &acpi_scan_system_dev_list, node) {
2672+
acpi_scan_claim_resources(sd->adev);
2673+
list_del(&sd->node);
2674+
kfree(sd);
2675+
}
2676+
2677+
return 0;
2678+
}
2679+
2680+
/*
2681+
* Reserve motherboard resources after PCI claims BARs, but before PCI assigns
2682+
* resources for uninitialized PCI devices.
2683+
*/
2684+
fs_initcall(acpi_reserve_motherboard_resources);
2685+
25742686
/**
25752687
* acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
25762688
* @handle: Root of the namespace scope to scan.

0 commit comments

Comments
 (0)