1 // SPDX-License-Identifier: GPL-2.0-only
3 * Dell WMI descriptor driver
5 * Copyright (C) 2017 Dell Inc. All Rights Reserved.
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/acpi.h>
11 #include <linux/list.h>
12 #include <linux/module.h>
13 #include <linux/wmi.h>
14 #include "dell-wmi-descriptor.h"
16 #define DELL_WMI_DESCRIPTOR_GUID "8D9DDCBC-A997-11DA-B012-B622A1EF5492"
18 struct descriptor_priv {
19 struct list_head list;
20 u32 interface_version;
24 static int descriptor_valid = -EPROBE_DEFER;
25 static LIST_HEAD(wmi_list);
26 static DEFINE_MUTEX(list_mutex);
28 int dell_wmi_get_descriptor_valid(void)
30 if (!wmi_has_guid(DELL_WMI_DESCRIPTOR_GUID))
33 return descriptor_valid;
35 EXPORT_SYMBOL_GPL(dell_wmi_get_descriptor_valid);
37 bool dell_wmi_get_interface_version(u32 *version)
39 struct descriptor_priv *priv;
42 mutex_lock(&list_mutex);
43 priv = list_first_entry_or_null(&wmi_list,
44 struct descriptor_priv,
47 *version = priv->interface_version;
50 mutex_unlock(&list_mutex);
53 EXPORT_SYMBOL_GPL(dell_wmi_get_interface_version);
55 bool dell_wmi_get_size(u32 *size)
57 struct descriptor_priv *priv;
60 mutex_lock(&list_mutex);
61 priv = list_first_entry_or_null(&wmi_list,
62 struct descriptor_priv,
68 mutex_unlock(&list_mutex);
71 EXPORT_SYMBOL_GPL(dell_wmi_get_size);
73 bool dell_wmi_get_hotfix(u32 *hotfix)
75 struct descriptor_priv *priv;
78 mutex_lock(&list_mutex);
79 priv = list_first_entry_or_null(&wmi_list,
80 struct descriptor_priv,
83 *hotfix = priv->hotfix;
86 mutex_unlock(&list_mutex);
89 EXPORT_SYMBOL_GPL(dell_wmi_get_hotfix);
92 * Descriptor buffer is 128 byte long and contains:
94 * Name Offset Length Value
95 * Vendor Signature 0 4 "DELL"
96 * Object Signature 4 4 " WMI"
97 * WMI Interface Version 8 4 <version>
98 * WMI buffer length 12 4 <length>
99 * WMI hotfix number 16 4 <hotfix>
101 static int dell_wmi_descriptor_probe(struct wmi_device *wdev,
104 union acpi_object *obj = NULL;
105 struct descriptor_priv *priv;
109 obj = wmidev_block_query(wdev, 0);
111 dev_err(&wdev->dev, "failed to read Dell WMI descriptor\n");
116 if (obj->type != ACPI_TYPE_BUFFER) {
117 dev_err(&wdev->dev, "Dell descriptor has wrong type\n");
119 descriptor_valid = ret;
123 /* Although it's not technically a failure, this would lead to
124 * unexpected behavior
126 if (obj->buffer.length != 128) {
128 "Dell descriptor buffer has unexpected length (%d)\n",
131 descriptor_valid = ret;
135 buffer = (u32 *)obj->buffer.pointer;
137 if (strncmp(obj->string.pointer, "DELL WMI", 8) != 0) {
138 dev_err(&wdev->dev, "Dell descriptor buffer has invalid signature (%8ph)\n",
141 descriptor_valid = ret;
144 descriptor_valid = 0;
146 if (buffer[2] != 0 && buffer[2] != 1)
147 dev_warn(&wdev->dev, "Dell descriptor buffer has unknown version (%lu)\n",
148 (unsigned long) buffer[2]);
150 priv = devm_kzalloc(&wdev->dev, sizeof(struct descriptor_priv),
158 priv->interface_version = buffer[2];
159 priv->size = buffer[3];
160 priv->hotfix = buffer[4];
162 dev_set_drvdata(&wdev->dev, priv);
163 mutex_lock(&list_mutex);
164 list_add_tail(&priv->list, &wmi_list);
165 mutex_unlock(&list_mutex);
167 dev_dbg(&wdev->dev, "Detected Dell WMI interface version %lu, buffer size %lu, hotfix %lu\n",
168 (unsigned long) priv->interface_version,
169 (unsigned long) priv->size,
170 (unsigned long) priv->hotfix);
177 static void dell_wmi_descriptor_remove(struct wmi_device *wdev)
179 struct descriptor_priv *priv = dev_get_drvdata(&wdev->dev);
181 mutex_lock(&list_mutex);
182 list_del(&priv->list);
183 mutex_unlock(&list_mutex);
186 static const struct wmi_device_id dell_wmi_descriptor_id_table[] = {
187 { .guid_string = DELL_WMI_DESCRIPTOR_GUID },
191 static struct wmi_driver dell_wmi_descriptor_driver = {
193 .name = "dell-wmi-descriptor",
195 .probe = dell_wmi_descriptor_probe,
196 .remove = dell_wmi_descriptor_remove,
197 .id_table = dell_wmi_descriptor_id_table,
200 module_wmi_driver(dell_wmi_descriptor_driver);
202 MODULE_DEVICE_TABLE(wmi, dell_wmi_descriptor_id_table);
203 MODULE_AUTHOR("Mario Limonciello <mario.limonciello@outlook.com>");
204 MODULE_DESCRIPTION("Dell WMI descriptor driver");
205 MODULE_LICENSE("GPL");