| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: wmi_acpi.c,v 1.15 2017/06/01 02:45:09 chs Exp $ */ | | 1 | /* $NetBSD: wmi_acpi.c,v 1.16 2017/12/03 17:34:50 bouyer Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2009, 2010 Jukka Ruohonen <jruohonen@iki.fi> | | 4 | * Copyright (c) 2009, 2010 Jukka Ruohonen <jruohonen@iki.fi> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * | | 10 | * |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | | 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | | 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
27 | * SUCH DAMAGE. | | 27 | * SUCH DAMAGE. |
28 | */ | | 28 | */ |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: wmi_acpi.c,v 1.15 2017/06/01 02:45:09 chs Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: wmi_acpi.c,v 1.16 2017/12/03 17:34:50 bouyer Exp $"); |
31 | | | 31 | |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/device.h> | | 33 | #include <sys/device.h> |
34 | #include <sys/endian.h> | | 34 | #include <sys/endian.h> |
35 | #include <sys/kmem.h> | | 35 | #include <sys/kmem.h> |
36 | #include <sys/systm.h> | | 36 | #include <sys/systm.h> |
37 | #include <sys/module.h> | | 37 | #include <sys/module.h> |
38 | | | 38 | |
39 | #include <dev/acpi/acpireg.h> | | 39 | #include <dev/acpi/acpireg.h> |
40 | #include <dev/acpi/acpivar.h> | | 40 | #include <dev/acpi/acpivar.h> |
41 | #include <dev/acpi/acpi_ecvar.h> | | 41 | #include <dev/acpi/acpi_ecvar.h> |
42 | #include <dev/acpi/wmi/wmi_acpivar.h> | | 42 | #include <dev/acpi/wmi/wmi_acpivar.h> |
43 | | | 43 | |
| @@ -313,39 +313,40 @@ acpi_wmi_init_ec(struct acpi_wmi_softc * | | | @@ -313,39 +313,40 @@ acpi_wmi_init_ec(struct acpi_wmi_softc * |
313 | ACPI_ADR_SPACE_EC, acpi_wmi_ec_handler, NULL, sc); | | 313 | ACPI_ADR_SPACE_EC, acpi_wmi_ec_handler, NULL, sc); |
314 | | | 314 | |
315 | if (ACPI_FAILURE(rv)) | | 315 | if (ACPI_FAILURE(rv)) |
316 | sc->sc_ecdev = NULL; | | 316 | sc->sc_ecdev = NULL; |
317 | } | | 317 | } |
318 | | | 318 | |
319 | static ACPI_STATUS | | 319 | static ACPI_STATUS |
320 | acpi_wmi_guid_get(struct acpi_wmi_softc *sc, | | 320 | acpi_wmi_guid_get(struct acpi_wmi_softc *sc, |
321 | const char *src, struct wmi_t **out) | | 321 | const char *src, struct wmi_t **out) |
322 | { | | 322 | { |
323 | struct wmi_t *wmi; | | 323 | struct wmi_t *wmi; |
324 | struct guid_t *guid; | | 324 | struct guid_t *guid; |
325 | char bin[16]; | | 325 | char bin[16]; |
326 | char hex[2]; | | 326 | char hex[3]; |
327 | const char *ptr; | | 327 | const char *ptr; |
328 | uint8_t i; | | 328 | uint8_t i; |
329 | | | 329 | |
330 | if (sc == NULL || src == NULL || strlen(src) != 36) | | 330 | if (sc == NULL || src == NULL || strlen(src) != 36) |
331 | return AE_BAD_PARAMETER; | | 331 | return AE_BAD_PARAMETER; |
332 | | | 332 | |
333 | for (ptr = src, i = 0; i < 16; i++) { | | 333 | for (ptr = src, i = 0; i < 16; i++) { |
334 | | | 334 | |
335 | if (*ptr == '-') | | 335 | if (*ptr == '-') |
336 | ptr++; | | 336 | ptr++; |
337 | | | 337 | |
338 | (void)memcpy(hex, ptr, 2); | | 338 | (void)memcpy(hex, ptr, 2); |
| | | 339 | hex[2] = '\0'; |
339 | | | 340 | |
340 | if (HEXCHAR(hex[0]) == 0 || HEXCHAR(hex[1]) == 0) | | 341 | if (HEXCHAR(hex[0]) == 0 || HEXCHAR(hex[1]) == 0) |
341 | return AE_BAD_HEX_CONSTANT; | | 342 | return AE_BAD_HEX_CONSTANT; |
342 | | | 343 | |
343 | bin[i] = strtoul(hex, NULL, 16) & 0xFF; | | 344 | bin[i] = strtoul(hex, NULL, 16) & 0xFF; |
344 | | | 345 | |
345 | ptr++; | | 346 | ptr++; |
346 | ptr++; | | 347 | ptr++; |
347 | } | | 348 | } |
348 | | | 349 | |
349 | guid = (struct guid_t *)bin; | | 350 | guid = (struct guid_t *)bin; |
350 | guid->data1 = be32toh(guid->data1); | | 351 | guid->data1 = be32toh(guid->data1); |
351 | guid->data2 = be16toh(guid->data2); | | 352 | guid->data2 = be16toh(guid->data2); |
| @@ -603,28 +604,30 @@ static ACPI_STATUS | | | @@ -603,28 +604,30 @@ static ACPI_STATUS |
603 | acpi_wmi_enable_collection(ACPI_HANDLE hdl, const char *oid, bool flag) | | 604 | acpi_wmi_enable_collection(ACPI_HANDLE hdl, const char *oid, bool flag) |
604 | { | | 605 | { |
605 | char path[5]; | | 606 | char path[5]; |
606 | | | 607 | |
607 | strlcpy(path, "WC", sizeof(path)); | | 608 | strlcpy(path, "WC", sizeof(path)); |
608 | strlcat(path, oid, sizeof(path)); | | 609 | strlcat(path, oid, sizeof(path)); |
609 | | | 610 | |
610 | return acpi_eval_set_integer(hdl, path, (flag != false) ? 0x01 : 0x00); | | 611 | return acpi_eval_set_integer(hdl, path, (flag != false) ? 0x01 : 0x00); |
611 | } | | 612 | } |
612 | | | 613 | |
613 | static bool | | 614 | static bool |
614 | acpi_wmi_input(struct wmi_t *wmi, uint8_t flag, uint8_t idx) | | 615 | acpi_wmi_input(struct wmi_t *wmi, uint8_t flag, uint8_t idx) |
615 | { | | 616 | { |
616 | | | 617 | /* A data block may have no flags at all */ |
617 | if ((wmi->guid.flags & flag) == 0) | | 618 | if ((wmi->guid.flags & flag) == 0 && |
| | | 619 | (flag == ACPI_WMI_FLAG_DATA && |
| | | 620 | (wmi->guid.flags & ~ACPI_WMI_FLAG_EXPENSIVE) != 0)) |
618 | return false; | | 621 | return false; |
619 | | | 622 | |
620 | if (wmi->guid.count == 0x00) | | 623 | if (wmi->guid.count == 0x00) |
621 | return false; | | 624 | return false; |
622 | | | 625 | |
623 | if (wmi->guid.count < idx) | | 626 | if (wmi->guid.count < idx) |
624 | return false; | | 627 | return false; |
625 | | | 628 | |
626 | return true; | | 629 | return true; |
627 | } | | 630 | } |
628 | | | 631 | |
629 | /* | | 632 | /* |
630 | * Makes a WMI data block query (WQxx). The corresponding control | | 633 | * Makes a WMI data block query (WQxx). The corresponding control |