Commit 134038b0 authored by Mario Limonciello's avatar Mario Limonciello Committed by Hans de Goede

platform/x86: wmi: Allow duplicate GUIDs for drivers that use struct wmi_driver

The WMI subsystem in the kernel currently tracks WMI devices by
a GUID string not by ACPI device.  The GUID used by the `wmi-bmof`
module however is available from many devices on nearly every machine.

This originally was thought to be a bug, but as it happens on most
machines it is a design mistake.  It has been fixed by tying an ACPI
device to the driver with struct wmi_driver. So drivers that have
moved over to struct wmi_driver can actually support multiple
instantiations of a GUID without any problem.

Add an allow list into wmi.c for GUIDs that the drivers that are known
to use struct wmi_driver.  The list is populated with `wmi-bmof` right
now. The additional instances of that in sysfs with be suffixed with -%d
Signed-off-by: default avatarMario Limonciello <mario.limonciello@amd.com>
Link: https://lore.kernel.org/r/20220829201500.6341-1-mario.limonciello@amd.comReviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent a2bdf10c
...@@ -105,6 +105,12 @@ static const struct acpi_device_id wmi_device_ids[] = { ...@@ -105,6 +105,12 @@ static const struct acpi_device_id wmi_device_ids[] = {
}; };
MODULE_DEVICE_TABLE(acpi, wmi_device_ids); MODULE_DEVICE_TABLE(acpi, wmi_device_ids);
/* allow duplicate GUIDs as these device drivers use struct wmi_driver */
static const char * const allow_duplicates[] = {
"05901221-D566-11D1-B2F0-00A0C9062910", /* wmi-bmof */
NULL
};
static struct platform_driver acpi_wmi_driver = { static struct platform_driver acpi_wmi_driver = {
.driver = { .driver = {
.name = "acpi-wmi", .name = "acpi-wmi",
...@@ -1073,6 +1079,23 @@ static const struct device_type wmi_type_data = { ...@@ -1073,6 +1079,23 @@ static const struct device_type wmi_type_data = {
.release = wmi_dev_release, .release = wmi_dev_release,
}; };
/*
* _WDG is a static list that is only parsed at startup,
* so it's safe to count entries without extra protection.
*/
static int guid_count(const guid_t *guid)
{
struct wmi_block *wblock;
int count = 0;
list_for_each_entry(wblock, &wmi_block_list, list) {
if (guid_equal(&wblock->gblock.guid, guid))
count++;
}
return count;
}
static int wmi_create_device(struct device *wmi_bus_dev, static int wmi_create_device(struct device *wmi_bus_dev,
struct wmi_block *wblock, struct wmi_block *wblock,
struct acpi_device *device) struct acpi_device *device)
...@@ -1080,6 +1103,7 @@ static int wmi_create_device(struct device *wmi_bus_dev, ...@@ -1080,6 +1103,7 @@ static int wmi_create_device(struct device *wmi_bus_dev,
struct acpi_device_info *info; struct acpi_device_info *info;
char method[WMI_ACPI_METHOD_NAME_SIZE]; char method[WMI_ACPI_METHOD_NAME_SIZE];
int result; int result;
uint count;
if (wblock->gblock.flags & ACPI_WMI_EVENT) { if (wblock->gblock.flags & ACPI_WMI_EVENT) {
wblock->dev.dev.type = &wmi_type_event; wblock->dev.dev.type = &wmi_type_event;
...@@ -1134,7 +1158,11 @@ static int wmi_create_device(struct device *wmi_bus_dev, ...@@ -1134,7 +1158,11 @@ static int wmi_create_device(struct device *wmi_bus_dev,
wblock->dev.dev.bus = &wmi_bus_type; wblock->dev.dev.bus = &wmi_bus_type;
wblock->dev.dev.parent = wmi_bus_dev; wblock->dev.dev.parent = wmi_bus_dev;
dev_set_name(&wblock->dev.dev, "%pUL", &wblock->gblock.guid); count = guid_count(&wblock->gblock.guid);
if (count)
dev_set_name(&wblock->dev.dev, "%pUL-%d", &wblock->gblock.guid, count);
else
dev_set_name(&wblock->dev.dev, "%pUL", &wblock->gblock.guid);
device_initialize(&wblock->dev.dev); device_initialize(&wblock->dev.dev);
...@@ -1154,11 +1182,20 @@ static void wmi_free_devices(struct acpi_device *device) ...@@ -1154,11 +1182,20 @@ static void wmi_free_devices(struct acpi_device *device)
} }
} }
static bool guid_already_parsed(struct acpi_device *device, const guid_t *guid) static bool guid_already_parsed_for_legacy(struct acpi_device *device, const guid_t *guid)
{ {
struct wmi_block *wblock; struct wmi_block *wblock;
list_for_each_entry(wblock, &wmi_block_list, list) { list_for_each_entry(wblock, &wmi_block_list, list) {
/* skip warning and register if we know the driver will use struct wmi_driver */
for (int i = 0; allow_duplicates[i] != NULL; i++) {
guid_t tmp;
if (guid_parse(allow_duplicates[i], &tmp))
continue;
if (guid_equal(&tmp, guid))
return false;
}
if (guid_equal(&wblock->gblock.guid, guid)) { if (guid_equal(&wblock->gblock.guid, guid)) {
/* /*
* Because we historically didn't track the relationship * Because we historically didn't track the relationship
...@@ -1208,13 +1245,7 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device) ...@@ -1208,13 +1245,7 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
if (debug_dump_wdg) if (debug_dump_wdg)
wmi_dump_wdg(&gblock[i]); wmi_dump_wdg(&gblock[i]);
/* if (guid_already_parsed_for_legacy(device, &gblock[i].guid))
* Some WMI devices, like those for nVidia hooks, have a
* duplicate GUID. It's not clear what we should do in this
* case yet, so for now, we'll just ignore the duplicate
* for device creation.
*/
if (guid_already_parsed(device, &gblock[i].guid))
continue; continue;
wblock = kzalloc(sizeof(*wblock), GFP_KERNEL); wblock = kzalloc(sizeof(*wblock), GFP_KERNEL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment