hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/platform/x86/wmi.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * ACPI-WMI mapping driver
34 *
....@@ -11,24 +12,6 @@
1112 * WMI bus infrastructure by Andrew Lutomirski and Darren Hart:
1213 * Copyright (C) 2015 Andrew Lutomirski
1314 * Copyright (C) 2017 VMware, Inc. All Rights Reserved.
14
- *
15
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16
- *
17
- * This program is free software; you can redistribute it and/or modify
18
- * it under the terms of the GNU General Public License as published by
19
- * the Free Software Foundation; either version 2 of the License, or (at
20
- * your option) any later version.
21
- *
22
- * This program is distributed in the hope that it will be useful, but
23
- * WITHOUT ANY WARRANTY; without even the implied warranty of
24
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
- * General Public License for more details.
26
- *
27
- * You should have received a copy of the GNU General Public License along
28
- * with this program; if not, write to the Free Software Foundation, Inc.,
29
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
30
- *
31
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3215 */
3316
3417 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -46,6 +29,7 @@
4629 #include <linux/uaccess.h>
4730 #include <linux/uuid.h>
4831 #include <linux/wmi.h>
32
+#include <linux/fs.h>
4933 #include <uapi/linux/wmi.h>
5034
5135 ACPI_MODULE_NAME("wmi");
....@@ -127,11 +111,11 @@
127111
128112 static bool find_guid(const char *guid_string, struct wmi_block **out)
129113 {
130
- uuid_le guid_input;
114
+ guid_t guid_input;
131115 struct wmi_block *wblock;
132116 struct guid_block *block;
133117
134
- if (uuid_le_to_bin(guid_string, &guid_input))
118
+ if (guid_parse(guid_string, &guid_input))
135119 return false;
136120
137121 list_for_each_entry(wblock, &wmi_block_list, list) {
....@@ -144,6 +128,28 @@
144128 }
145129 }
146130 return false;
131
+}
132
+
133
+static const void *find_guid_context(struct wmi_block *wblock,
134
+ struct wmi_driver *wdriver)
135
+{
136
+ const struct wmi_device_id *id;
137
+ guid_t guid_input;
138
+
139
+ if (wblock == NULL || wdriver == NULL)
140
+ return NULL;
141
+ if (wdriver->id_table == NULL)
142
+ return NULL;
143
+
144
+ id = wdriver->id_table;
145
+ while (*id->guid_string) {
146
+ if (guid_parse(id->guid_string, &guid_input))
147
+ continue;
148
+ if (!memcmp(wblock->gblock.guid, &guid_input, 16))
149
+ return id->context;
150
+ id++;
151
+ }
152
+ return NULL;
147153 }
148154
149155 static int get_subobj_info(acpi_handle handle, const char *pathname,
....@@ -196,7 +202,7 @@
196202 /**
197203 * set_required_buffer_size - Sets the buffer size needed for performing IOCTL
198204 * @wdev: A wmi bus device from a driver
199
- * @instance: Instance index
205
+ * @length: Required buffer size
200206 *
201207 * Allocates memory needed for buffer, stores the buffer size in that memory
202208 */
....@@ -216,8 +222,8 @@
216222 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
217223 * @instance: Instance index
218224 * @method_id: Method ID to call
219
- * &in: Buffer containing input for the method call
220
- * &out: Empty buffer to return the method results
225
+ * @in: Buffer containing input for the method call
226
+ * @out: Empty buffer to return the method results
221227 *
222228 * Call an ACPI-WMI method
223229 */
....@@ -238,8 +244,8 @@
238244 * @wdev: A wmi bus device from a driver
239245 * @instance: Instance index
240246 * @method_id: Method ID to call
241
- * &in: Buffer containing input for the method call
242
- * &out: Empty buffer to return the method results
247
+ * @in: Buffer containing input for the method call
248
+ * @out: Empty buffer to return the method results
243249 *
244250 * Call an ACPI-WMI method
245251 */
....@@ -335,9 +341,7 @@
335341 * expensive, but have no corresponding WCxx method. So we
336342 * should not fail if this happens.
337343 */
338
- if (acpi_has_method(handle, wc_method))
339
- wc_status = acpi_execute_simple_method(handle,
340
- wc_method, 1);
344
+ wc_status = acpi_execute_simple_method(handle, wc_method, 1);
341345 }
342346
343347 strcpy(method, "WQ");
....@@ -367,7 +371,7 @@
367371 * wmi_query_block - Return contents of a WMI block (deprecated)
368372 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
369373 * @instance: Instance index
370
- * &out: Empty buffer to return the contents of the data block to
374
+ * @out: Empty buffer to return the contents of the data block to
371375 *
372376 * Return the contents of an ACPI-WMI data block to a buffer
373377 */
....@@ -402,7 +406,7 @@
402406 * wmi_set_block - Write to a WMI block
403407 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
404408 * @instance: Instance index
405
- * &in: Buffer containing new values for the data block
409
+ * @in: Buffer containing new values for the data block
406410 *
407411 * Write the contents of the input buffer to an ACPI-WMI data block
408412 */
....@@ -513,6 +517,7 @@
513517
514518 /**
515519 * wmi_install_notify_handler - Register handler for WMI events
520
+ * @guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
516521 * @handler: Function to handle notifications
517522 * @data: Data to be returned to handler when event is fired
518523 *
....@@ -523,12 +528,12 @@
523528 {
524529 struct wmi_block *block;
525530 acpi_status status = AE_NOT_EXIST;
526
- uuid_le guid_input;
531
+ guid_t guid_input;
527532
528533 if (!guid || !handler)
529534 return AE_BAD_PARAMETER;
530535
531
- if (uuid_le_to_bin(guid, &guid_input))
536
+ if (guid_parse(guid, &guid_input))
532537 return AE_BAD_PARAMETER;
533538
534539 list_for_each_entry(block, &wmi_block_list, list) {
....@@ -555,6 +560,7 @@
555560
556561 /**
557562 * wmi_uninstall_notify_handler - Unregister handler for WMI events
563
+ * @guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
558564 *
559565 * Unregister handler for events sent to the ACPI-WMI mapper device.
560566 */
....@@ -562,12 +568,12 @@
562568 {
563569 struct wmi_block *block;
564570 acpi_status status = AE_NOT_EXIST;
565
- uuid_le guid_input;
571
+ guid_t guid_input;
566572
567573 if (!guid)
568574 return AE_BAD_PARAMETER;
569575
570
- if (uuid_le_to_bin(guid, &guid_input))
576
+ if (guid_parse(guid, &guid_input))
571577 return AE_BAD_PARAMETER;
572578
573579 list_for_each_entry(block, &wmi_block_list, list) {
....@@ -641,6 +647,25 @@
641647 return find_guid(guid_string, NULL);
642648 }
643649 EXPORT_SYMBOL_GPL(wmi_has_guid);
650
+
651
+/**
652
+ * wmi_get_acpi_device_uid() - Get _UID name of ACPI device that defines GUID
653
+ * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
654
+ *
655
+ * Find the _UID of ACPI device associated with this WMI GUID.
656
+ *
657
+ * Return: The ACPI _UID field value or NULL if the WMI GUID was not found
658
+ */
659
+char *wmi_get_acpi_device_uid(const char *guid_string)
660
+{
661
+ struct wmi_block *wblock = NULL;
662
+
663
+ if (!find_guid(guid_string, &wblock))
664
+ return NULL;
665
+
666
+ return acpi_device_uid(wblock->acpi_device);
667
+}
668
+EXPORT_SYMBOL_GPL(wmi_get_acpi_device_uid);
644669
645670 static struct wmi_block *dev_to_wblock(struct device *dev)
646671 {
....@@ -778,10 +803,10 @@
778803 if (id == NULL)
779804 return 0;
780805
781
- while (id->guid_string) {
782
- uuid_le driver_guid;
806
+ while (*id->guid_string) {
807
+ guid_t driver_guid;
783808
784
- if (WARN_ON(uuid_le_to_bin(id->guid_string, &driver_guid)))
809
+ if (WARN_ON(guid_parse(id->guid_string, &driver_guid)))
785810 continue;
786811 if (!memcmp(&driver_guid, wblock->gblock.guid, 16))
787812 return 1;
....@@ -896,7 +921,7 @@
896921 .read = wmi_char_read,
897922 .open = wmi_char_open,
898923 .unlocked_ioctl = wmi_ioctl,
899
- .compat_ioctl = wmi_ioctl,
924
+ .compat_ioctl = compat_ptr_ioctl,
900925 };
901926
902927 static int wmi_dev_probe(struct device *dev)
....@@ -911,7 +936,8 @@
911936 dev_warn(dev, "failed to enable device -- probing anyway\n");
912937
913938 if (wdriver->probe) {
914
- ret = wdriver->probe(dev_to_wdev(dev));
939
+ ret = wdriver->probe(dev_to_wdev(dev),
940
+ find_guid_context(wblock, wdriver));
915941 if (ret != 0)
916942 goto probe_failure;
917943 }
....@@ -997,19 +1023,19 @@
9971023 .remove = wmi_dev_remove,
9981024 };
9991025
1000
-static struct device_type wmi_type_event = {
1026
+static const struct device_type wmi_type_event = {
10011027 .name = "event",
10021028 .groups = wmi_event_groups,
10031029 .release = wmi_dev_release,
10041030 };
10051031
1006
-static struct device_type wmi_type_method = {
1032
+static const struct device_type wmi_type_method = {
10071033 .name = "method",
10081034 .groups = wmi_method_groups,
10091035 .release = wmi_dev_release,
10101036 };
10111037
1012
-static struct device_type wmi_type_data = {
1038
+static const struct device_type wmi_type_data = {
10131039 .name = "data",
10141040 .groups = wmi_data_groups,
10151041 .release = wmi_dev_release,
....@@ -1099,8 +1125,7 @@
10991125 }
11001126 }
11011127
1102
-static bool guid_already_parsed(struct acpi_device *device,
1103
- const u8 *guid)
1128
+static bool guid_already_parsed(struct acpi_device *device, const u8 *guid)
11041129 {
11051130 struct wmi_block *wblock;
11061131
....@@ -1310,10 +1335,8 @@
13101335 wblock->handler(event, wblock->handler_data);
13111336 }
13121337
1313
- if (debug_event) {
1314
- pr_info("DEBUG Event GUID: %pUL\n",
1315
- wblock->gblock.guid);
1316
- }
1338
+ if (debug_event)
1339
+ pr_info("DEBUG Event GUID: %pUL\n", wblock->gblock.guid);
13171340
13181341 acpi_bus_generate_netlink_event(
13191342 wblock->acpi_device->pnp.device_class,