2 * Dell WMI descriptor driver
4 * Copyright (C) 2017 Dell Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/acpi.h>
19 #include <linux/list.h>
20 #include <linux/module.h>
21 #include <linux/wmi.h>
22 #include "dell-wmi-descriptor.h"
24 #define DELL_WMI_DESCRIPTOR_GUID "8D9DDCBC-A997-11DA-B012-B622A1EF5492"
26 struct descriptor_priv
{
27 struct list_head list
;
28 u32 interface_version
;
31 static int descriptor_valid
= -EPROBE_DEFER
;
32 static LIST_HEAD(wmi_list
);
33 static DEFINE_MUTEX(list_mutex
);
35 int dell_wmi_get_descriptor_valid(void)
37 if (!wmi_has_guid(DELL_WMI_DESCRIPTOR_GUID
))
40 return descriptor_valid
;
42 EXPORT_SYMBOL_GPL(dell_wmi_get_descriptor_valid
);
44 bool dell_wmi_get_interface_version(u32
*version
)
46 struct descriptor_priv
*priv
;
49 mutex_lock(&list_mutex
);
50 priv
= list_first_entry_or_null(&wmi_list
,
51 struct descriptor_priv
,
54 *version
= priv
->interface_version
;
57 mutex_unlock(&list_mutex
);
60 EXPORT_SYMBOL_GPL(dell_wmi_get_interface_version
);
62 bool dell_wmi_get_size(u32
*size
)
64 struct descriptor_priv
*priv
;
67 mutex_lock(&list_mutex
);
68 priv
= list_first_entry_or_null(&wmi_list
,
69 struct descriptor_priv
,
75 mutex_unlock(&list_mutex
);
78 EXPORT_SYMBOL_GPL(dell_wmi_get_size
);
81 * Descriptor buffer is 128 byte long and contains:
83 * Name Offset Length Value
84 * Vendor Signature 0 4 "DELL"
85 * Object Signature 4 4 " WMI"
86 * WMI Interface Version 8 4 <version>
87 * WMI buffer length 12 4 <length>
89 static int dell_wmi_descriptor_probe(struct wmi_device
*wdev
)
91 union acpi_object
*obj
= NULL
;
92 struct descriptor_priv
*priv
;
96 obj
= wmidev_block_query(wdev
, 0);
98 dev_err(&wdev
->dev
, "failed to read Dell WMI descriptor\n");
103 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
104 dev_err(&wdev
->dev
, "Dell descriptor has wrong type\n");
106 descriptor_valid
= ret
;
110 /* Although it's not technically a failure, this would lead to
111 * unexpected behavior
113 if (obj
->buffer
.length
!= 128) {
115 "Dell descriptor buffer has unexpected length (%d)\n",
118 descriptor_valid
= ret
;
122 buffer
= (u32
*)obj
->buffer
.pointer
;
124 if (strncmp(obj
->string
.pointer
, "DELL WMI", 8) != 0) {
125 dev_err(&wdev
->dev
, "Dell descriptor buffer has invalid signature (%8ph)\n",
128 descriptor_valid
= ret
;
131 descriptor_valid
= 0;
133 if (buffer
[2] != 0 && buffer
[2] != 1)
134 dev_warn(&wdev
->dev
, "Dell descriptor buffer has unknown version (%lu)\n",
135 (unsigned long) buffer
[2]);
137 priv
= devm_kzalloc(&wdev
->dev
, sizeof(struct descriptor_priv
),
145 priv
->interface_version
= buffer
[2];
146 priv
->size
= buffer
[3];
148 dev_set_drvdata(&wdev
->dev
, priv
);
149 mutex_lock(&list_mutex
);
150 list_add_tail(&priv
->list
, &wmi_list
);
151 mutex_unlock(&list_mutex
);
153 dev_dbg(&wdev
->dev
, "Detected Dell WMI interface version %lu and buffer size %lu\n",
154 (unsigned long) priv
->interface_version
,
155 (unsigned long) priv
->size
);
162 static int dell_wmi_descriptor_remove(struct wmi_device
*wdev
)
164 struct descriptor_priv
*priv
= dev_get_drvdata(&wdev
->dev
);
166 mutex_lock(&list_mutex
);
167 list_del(&priv
->list
);
168 mutex_unlock(&list_mutex
);
172 static const struct wmi_device_id dell_wmi_descriptor_id_table
[] = {
173 { .guid_string
= DELL_WMI_DESCRIPTOR_GUID
},
177 static struct wmi_driver dell_wmi_descriptor_driver
= {
179 .name
= "dell-wmi-descriptor",
181 .probe
= dell_wmi_descriptor_probe
,
182 .remove
= dell_wmi_descriptor_remove
,
183 .id_table
= dell_wmi_descriptor_id_table
,
186 module_wmi_driver(dell_wmi_descriptor_driver
);
188 MODULE_ALIAS("wmi:" DELL_WMI_DESCRIPTOR_GUID
);
189 MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
190 MODULE_DESCRIPTION("Dell WMI descriptor driver");
191 MODULE_LICENSE("GPL");