2 * Copyright (c) 2009 Michael Gmelin <freebsd@grem.de>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/sys/dev/acpi_support/acpi_hp.c,v 1.7 2010/09/11 08:09:14 avg Exp $
30 * Driver for extra ACPI-controlled features found on HP laptops
31 * that use a WMI enabled BIOS (e.g. HP Compaq 8510p and 6510p).
32 * Allows to control and read status of integrated hardware and read
33 * BIOS settings through CMI.
34 * Inspired by the hp-wmi driver, which implements a subset of these
35 * features (hotkeys) on Linux.
38 * http://h20331.www2.hp.com/Hpsub/downloads/cmi_whitepaper.pdf
40 * http://www.kernel.org
42 * http://www.microsoft.com/whdc/system/pnppwr/wmi/wmi-acpi.mspx
46 #include <sys/param.h>
50 #include <sys/kernel.h>
53 #include <sys/module.h>
54 #include <sys/sysctl.h>
55 #include <sys/device.h>
59 #include <dev/acpica/acpivar.h>
60 #include "acpi_wmi_if.h"
62 #define _COMPONENT ACPI_OEM
63 ACPI_MODULE_NAME("HP")
65 #define ACPI_HP_WMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C"
66 #define ACPI_HP_WMI_BIOS_GUID "5FB7F034-2C63-45E9-BE91-3D44E2C707E4"
67 #define ACPI_HP_WMI_CMI_GUID "2D114B49-2DFB-4130-B8FE-4A3C09E75133"
69 #define ACPI_HP_WMI_DISPLAY_COMMAND 0x1
70 #define ACPI_HP_WMI_HDDTEMP_COMMAND 0x2
71 #define ACPI_HP_WMI_ALS_COMMAND 0x3
72 #define ACPI_HP_WMI_DOCK_COMMAND 0x4
73 #define ACPI_HP_WMI_WIRELESS_COMMAND 0x5
75 #define ACPI_HP_METHOD_WLAN_ENABLED 1
76 #define ACPI_HP_METHOD_WLAN_RADIO 2
77 #define ACPI_HP_METHOD_WLAN_ON_AIR 3
78 #define ACPI_HP_METHOD_WLAN_ENABLE_IF_RADIO_ON 4
79 #define ACPI_HP_METHOD_WLAN_DISABLE_IF_RADIO_OFF 5
80 #define ACPI_HP_METHOD_BLUETOOTH_ENABLED 6
81 #define ACPI_HP_METHOD_BLUETOOTH_RADIO 7
82 #define ACPI_HP_METHOD_BLUETOOTH_ON_AIR 8
83 #define ACPI_HP_METHOD_BLUETOOTH_ENABLE_IF_RADIO_ON 9
84 #define ACPI_HP_METHOD_BLUETOOTH_DISABLE_IF_RADIO_OFF 10
85 #define ACPI_HP_METHOD_WWAN_ENABLED 11
86 #define ACPI_HP_METHOD_WWAN_RADIO 12
87 #define ACPI_HP_METHOD_WWAN_ON_AIR 13
88 #define ACPI_HP_METHOD_WWAN_ENABLE_IF_RADIO_ON 14
89 #define ACPI_HP_METHOD_WWAN_DISABLE_IF_RADIO_OFF 15
90 #define ACPI_HP_METHOD_ALS 16
91 #define ACPI_HP_METHOD_DISPLAY 17
92 #define ACPI_HP_METHOD_HDDTEMP 18
93 #define ACPI_HP_METHOD_DOCK 19
94 #define ACPI_HP_METHOD_CMI_DETAIL 20
95 #define ACPI_HP_METHOD_VERBOSE 21
97 #define HP_MASK_WWAN_ON_AIR 0x1000000
98 #define HP_MASK_BLUETOOTH_ON_AIR 0x10000
99 #define HP_MASK_WLAN_ON_AIR 0x100
100 #define HP_MASK_WWAN_RADIO 0x8000000
101 #define HP_MASK_BLUETOOTH_RADIO 0x80000
102 #define HP_MASK_WLAN_RADIO 0x800
103 #define HP_MASK_WWAN_ENABLED 0x2000000
104 #define HP_MASK_BLUETOOTH_ENABLED 0x20000
105 #define HP_MASK_WLAN_ENABLED 0x200
107 #define ACPI_HP_CMI_DETAIL_PATHS 0x01
108 #define ACPI_HP_CMI_DETAIL_ENUMS 0x02
109 #define ACPI_HP_CMI_DETAIL_FLAGS 0x04
110 #define ACPI_HP_CMI_DETAIL_SHOW_MAX_INSTANCE 0x08
112 struct acpi_hp_inst_seq_pair
{
113 UINT32 sequence
; /* sequence number as suggested by cmi bios */
114 UINT8 instance
; /* object instance on guid */
117 struct acpi_hp_softc
{
120 int has_notify
; /* notification GUID found */
121 int has_cmi
; /* CMI GUID found */
122 int cmi_detail
; /* CMI detail level
124 int verbose
; /* add debug output */
125 int wlan_enable_if_radio_on
; /* set by sysctl */
126 int wlan_disable_if_radio_off
; /* set by sysctl */
127 int bluetooth_enable_if_radio_on
; /* set by sysctl */
128 int bluetooth_disable_if_radio_off
; /* set by sysctl */
129 int wwan_enable_if_radio_on
; /* set by sysctl */
130 int wwan_disable_if_radio_off
; /* set by sysctl */
131 int was_wlan_on_air
; /* last known WLAN
133 int was_bluetooth_on_air
; /* last known BT
135 int was_wwan_on_air
; /* last known WWAN
137 struct sysctl_ctx_list sysctl_ctx
;
138 struct sysctl_oid
*sysctl_tree
;
139 struct cdev
*hpcmi_dev_t
; /* hpcmi device handle */
140 struct sbuf hpcmi_sbuf
; /* /dev/hpcmi output sbuf */
141 pid_t hpcmi_open_pid
; /* pid operating on
143 int hpcmi_bufptr
; /* current pointer position
144 in /dev/hpcmi output buffer
146 int cmi_order_size
; /* size of cmi_order list */
147 struct acpi_hp_inst_seq_pair cmi_order
[128]; /* list of CMI
148 instances ordered by BIOS suggested sequence */
156 } acpi_hp_sysctls
[] = {
158 .name
= "wlan_enabled",
159 .method
= ACPI_HP_METHOD_WLAN_ENABLED
,
160 .description
= "Enable/Disable WLAN (WiFi)",
161 .access
= CTLTYPE_INT
| CTLFLAG_RW
164 .name
= "wlan_radio",
165 .method
= ACPI_HP_METHOD_WLAN_RADIO
,
166 .description
= "WLAN radio status",
167 .access
= CTLTYPE_INT
| CTLFLAG_RD
170 .name
= "wlan_on_air",
171 .method
= ACPI_HP_METHOD_WLAN_ON_AIR
,
172 .description
= "WLAN radio ready to use (enabled and radio)",
173 .access
= CTLTYPE_INT
| CTLFLAG_RD
176 .name
= "wlan_enable_if_radio_on",
177 .method
= ACPI_HP_METHOD_WLAN_ENABLE_IF_RADIO_ON
,
178 .description
= "Enable WLAN if radio is turned on",
179 .access
= CTLTYPE_INT
| CTLFLAG_RW
182 .name
= "wlan_disable_if_radio_off",
183 .method
= ACPI_HP_METHOD_WLAN_DISABLE_IF_RADIO_OFF
,
184 .description
= "Disable WLAN if radio is turned off",
185 .access
= CTLTYPE_INT
| CTLFLAG_RW
188 .name
= "bt_enabled",
189 .method
= ACPI_HP_METHOD_BLUETOOTH_ENABLED
,
190 .description
= "Enable/Disable Bluetooth",
191 .access
= CTLTYPE_INT
| CTLFLAG_RW
195 .method
= ACPI_HP_METHOD_BLUETOOTH_RADIO
,
196 .description
= "Bluetooth radio status",
197 .access
= CTLTYPE_INT
| CTLFLAG_RD
201 .method
= ACPI_HP_METHOD_BLUETOOTH_ON_AIR
,
202 .description
= "Bluetooth radio ready to use"
203 " (enabled and radio)",
204 .access
= CTLTYPE_INT
| CTLFLAG_RD
207 .name
= "bt_enable_if_radio_on",
208 .method
= ACPI_HP_METHOD_BLUETOOTH_ENABLE_IF_RADIO_ON
,
209 .description
= "Enable bluetooth if radio is turned on",
210 .access
= CTLTYPE_INT
| CTLFLAG_RW
213 .name
= "bt_disable_if_radio_off",
214 .method
= ACPI_HP_METHOD_BLUETOOTH_DISABLE_IF_RADIO_OFF
,
215 .description
= "Disable bluetooth if radio is turned off",
216 .access
= CTLTYPE_INT
| CTLFLAG_RW
219 .name
= "wwan_enabled",
220 .method
= ACPI_HP_METHOD_WWAN_ENABLED
,
221 .description
= "Enable/Disable WWAN (UMTS)",
222 .access
= CTLTYPE_INT
| CTLFLAG_RW
225 .name
= "wwan_radio",
226 .method
= ACPI_HP_METHOD_WWAN_RADIO
,
227 .description
= "WWAN radio status",
228 .access
= CTLTYPE_INT
| CTLFLAG_RD
231 .name
= "wwan_on_air",
232 .method
= ACPI_HP_METHOD_WWAN_ON_AIR
,
233 .description
= "WWAN radio ready to use (enabled and radio)",
234 .access
= CTLTYPE_INT
| CTLFLAG_RD
237 .name
= "wwan_enable_if_radio_on",
238 .method
= ACPI_HP_METHOD_WWAN_ENABLE_IF_RADIO_ON
,
239 .description
= "Enable WWAN if radio is turned on",
240 .access
= CTLTYPE_INT
| CTLFLAG_RW
243 .name
= "wwan_disable_if_radio_off",
244 .method
= ACPI_HP_METHOD_WWAN_DISABLE_IF_RADIO_OFF
,
245 .description
= "Disable WWAN if radio is turned off",
246 .access
= CTLTYPE_INT
| CTLFLAG_RW
249 .name
= "als_enabled",
250 .method
= ACPI_HP_METHOD_ALS
,
251 .description
= "Enable/Disable ALS (Ambient light sensor)",
252 .access
= CTLTYPE_INT
| CTLFLAG_RW
256 .method
= ACPI_HP_METHOD_DISPLAY
,
257 .description
= "Display status",
258 .access
= CTLTYPE_INT
| CTLFLAG_RD
261 .name
= "hdd_temperature",
262 .method
= ACPI_HP_METHOD_HDDTEMP
,
263 .description
= "HDD temperature",
264 .access
= CTLTYPE_INT
| CTLFLAG_RD
268 .method
= ACPI_HP_METHOD_DOCK
,
269 .description
= "Docking station status",
270 .access
= CTLTYPE_INT
| CTLFLAG_RD
273 .name
= "cmi_detail",
274 .method
= ACPI_HP_METHOD_CMI_DETAIL
,
275 .description
= "Details shown in CMI output "
277 .access
= CTLTYPE_INT
| CTLFLAG_RW
281 .method
= ACPI_HP_METHOD_VERBOSE
,
282 .description
= "Verbosity level",
283 .access
= CTLTYPE_INT
| CTLFLAG_RW
289 ACPI_SERIAL_DECL(hp
, "HP ACPI-WMI Mapping");
291 static void acpi_hp_identify(driver_t
*driver
, device_t parent
);
292 static int acpi_hp_probe(device_t dev
);
293 static int acpi_hp_attach(device_t dev
);
294 static int acpi_hp_detach(device_t dev
);
296 static void acpi_hp_evaluate_auto_on_off(struct acpi_hp_softc
* sc
);
297 static int acpi_hp_sysctl(SYSCTL_HANDLER_ARGS
);
298 static int acpi_hp_sysctl_set(struct acpi_hp_softc
*sc
, int method
,
299 int arg
, int oldarg
);
300 static int acpi_hp_sysctl_get(struct acpi_hp_softc
*sc
, int method
);
301 static int acpi_hp_exec_wmi_command(device_t wmi_dev
, int command
,
302 int is_write
, int val
);
303 static void acpi_hp_notify(ACPI_HANDLE h
, UINT32 notify
, void *context
);
304 static int acpi_hp_get_cmi_block(device_t wmi_dev
, const char* guid
,
305 UINT8 instance
, char* outbuf
, size_t outsize
,
306 UINT32
* sequence
, int detail
);
307 static void acpi_hp_hex_decode(char* buffer
);
309 static d_open_t acpi_hp_hpcmi_open
;
310 static d_close_t acpi_hp_hpcmi_close
;
311 static d_read_t acpi_hp_hpcmi_read
;
313 /* handler /dev/hpcmi device */
314 static struct dev_ops hpcmi_ops
= {
315 { "hpcmi", 0, D_MPSAFE
},
316 .d_open
= acpi_hp_hpcmi_open
,
317 .d_close
= acpi_hp_hpcmi_close
,
318 .d_read
= acpi_hp_hpcmi_read
,
321 static device_method_t acpi_hp_methods
[] = {
322 DEVMETHOD(device_identify
, acpi_hp_identify
),
323 DEVMETHOD(device_probe
, acpi_hp_probe
),
324 DEVMETHOD(device_attach
, acpi_hp_attach
),
325 DEVMETHOD(device_detach
, acpi_hp_detach
),
329 static driver_t acpi_hp_driver
= {
332 sizeof(struct acpi_hp_softc
),
335 static devclass_t acpi_hp_devclass
;
337 DRIVER_MODULE(acpi_hp
, acpi_wmi
, acpi_hp_driver
, acpi_hp_devclass
,
339 MODULE_VERSION(acpi_hp
, 1);
340 MODULE_DEPEND(acpi_hp
, acpi_wmi
, 1, 1, 1);
341 MODULE_DEPEND(acpi_hp
, acpi
, 1, 1, 1);
344 acpi_hp_evaluate_auto_on_off(struct acpi_hp_softc
*sc
)
348 int new_bluetooth_status
;
351 wireless
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
352 ACPI_HP_WMI_WIRELESS_COMMAND
, 0, 0);
353 new_wlan_status
= -1;
354 new_bluetooth_status
= -1;
355 new_wwan_status
= -1;
358 device_printf(sc
->wmi_dev
, "Wireless status is %x\n", wireless
);
359 if (sc
->wlan_disable_if_radio_off
&& !(wireless
& HP_MASK_WLAN_RADIO
)
360 && (wireless
& HP_MASK_WLAN_ENABLED
)) {
361 acpi_hp_exec_wmi_command(sc
->wmi_dev
,
362 ACPI_HP_WMI_WIRELESS_COMMAND
, 1, 0x100);
365 else if (sc
->wlan_enable_if_radio_on
&& (wireless
& HP_MASK_WLAN_RADIO
)
366 && !(wireless
& HP_MASK_WLAN_ENABLED
)) {
367 acpi_hp_exec_wmi_command(sc
->wmi_dev
,
368 ACPI_HP_WMI_WIRELESS_COMMAND
, 1, 0x101);
371 if (sc
->bluetooth_disable_if_radio_off
&&
372 !(wireless
& HP_MASK_BLUETOOTH_RADIO
) &&
373 (wireless
& HP_MASK_BLUETOOTH_ENABLED
)) {
374 acpi_hp_exec_wmi_command(sc
->wmi_dev
,
375 ACPI_HP_WMI_WIRELESS_COMMAND
, 1, 0x200);
376 new_bluetooth_status
= 0;
378 else if (sc
->bluetooth_enable_if_radio_on
&&
379 (wireless
& HP_MASK_BLUETOOTH_RADIO
) &&
380 !(wireless
& HP_MASK_BLUETOOTH_ENABLED
)) {
381 acpi_hp_exec_wmi_command(sc
->wmi_dev
,
382 ACPI_HP_WMI_WIRELESS_COMMAND
, 1, 0x202);
383 new_bluetooth_status
= 1;
385 if (sc
->wwan_disable_if_radio_off
&&
386 !(wireless
& HP_MASK_WWAN_RADIO
) &&
387 (wireless
& HP_MASK_WWAN_ENABLED
)) {
388 acpi_hp_exec_wmi_command(sc
->wmi_dev
,
389 ACPI_HP_WMI_WIRELESS_COMMAND
, 1, 0x400);
392 else if (sc
->wwan_enable_if_radio_on
&&
393 (wireless
& HP_MASK_WWAN_RADIO
) &&
394 !(wireless
& HP_MASK_WWAN_ENABLED
)) {
395 acpi_hp_exec_wmi_command(sc
->wmi_dev
,
396 ACPI_HP_WMI_WIRELESS_COMMAND
, 1, 0x404);
400 if (new_wlan_status
== -1) {
401 new_wlan_status
= (wireless
& HP_MASK_WLAN_ON_AIR
);
402 if ((new_wlan_status
?1:0) != sc
->was_wlan_on_air
) {
403 sc
->was_wlan_on_air
= sc
->was_wlan_on_air
?0:1;
405 device_printf(sc
->wmi_dev
,
406 "WLAN on air changed to %i "
407 "(new_wlan_status is %i)\n",
408 sc
->was_wlan_on_air
, new_wlan_status
);
409 acpi_UserNotify("HP", ACPI_ROOT_OBJECT
,
410 0xc0+sc
->was_wlan_on_air
);
413 if (new_bluetooth_status
== -1) {
414 new_bluetooth_status
= (wireless
& HP_MASK_BLUETOOTH_ON_AIR
);
415 if ((new_bluetooth_status
?1:0) != sc
->was_bluetooth_on_air
) {
416 sc
->was_bluetooth_on_air
= sc
->was_bluetooth_on_air
?
419 device_printf(sc
->wmi_dev
,
420 "BLUETOOTH on air changed"
421 " to %i (new_bluetooth_status is %i)\n",
422 sc
->was_bluetooth_on_air
,
423 new_bluetooth_status
);
424 acpi_UserNotify("HP", ACPI_ROOT_OBJECT
,
425 0xd0+sc
->was_bluetooth_on_air
);
428 if (new_wwan_status
== -1) {
429 new_wwan_status
= (wireless
& HP_MASK_WWAN_ON_AIR
);
430 if ((new_wwan_status
?1:0) != sc
->was_wwan_on_air
) {
431 sc
->was_wwan_on_air
= sc
->was_wwan_on_air
?0:1;
433 device_printf(sc
->wmi_dev
,
434 "WWAN on air changed to %i"
435 " (new_wwan_status is %i)\n",
436 sc
->was_wwan_on_air
, new_wwan_status
);
437 acpi_UserNotify("HP", ACPI_ROOT_OBJECT
,
438 0xe0+sc
->was_wwan_on_air
);
444 acpi_hp_identify(driver_t
*driver
, device_t parent
)
447 /* Don't do anything if driver is disabled. */
448 if (acpi_disabled("hp"))
451 /* Add only a single device instance. */
452 if (device_find_child(parent
, "acpi_hp", -1) != NULL
)
455 if (BUS_ADD_CHILD(parent
, parent
, 0, "acpi_hp", -1) == NULL
)
456 device_printf(parent
, "add acpi_hp child failed\n");
460 acpi_hp_probe(device_t dev
)
463 device_set_desc(dev
, "HP ACPI-WMI Mapping");
468 acpi_hp_attach(device_t dev
)
470 struct acpi_hp_softc
*sc
;
471 struct acpi_softc
*acpi_sc
;
474 ACPI_SERIAL_INIT(hp
);
475 ACPI_FUNCTION_TRACE((char *)(uintptr_t) __func__
);
477 sc
= device_get_softc(dev
);
481 sc
->bluetooth_enable_if_radio_on
= 0;
482 sc
->bluetooth_disable_if_radio_off
= 0;
483 sc
->wlan_enable_if_radio_on
= 0;
484 sc
->wlan_disable_if_radio_off
= 0;
485 sc
->wlan_enable_if_radio_on
= 0;
486 sc
->wlan_disable_if_radio_off
= 0;
487 sc
->was_wlan_on_air
= 0;
488 sc
->was_bluetooth_on_air
= 0;
489 sc
->was_wwan_on_air
= 0;
491 sc
->cmi_order_size
= -1;
493 memset(sc
->cmi_order
, 0, sizeof(sc
->cmi_order
));
494 sc
->wmi_dev
= device_get_parent(dev
);
495 acpi_sc
= acpi_device_get_parent_softc(sc
->wmi_dev
);
497 if (!ACPI_WMI_PROVIDES_GUID_STRING(sc
->wmi_dev
,
498 ACPI_HP_WMI_BIOS_GUID
)) {
500 "WMI device does not provide the HP BIOS GUID\n");
503 if (ACPI_WMI_PROVIDES_GUID_STRING(sc
->wmi_dev
,
504 ACPI_HP_WMI_EVENT_GUID
)) {
506 "HP event GUID detected, installing event handler\n");
507 if (ACPI_WMI_INSTALL_EVENT_HANDLER(sc
->wmi_dev
,
508 ACPI_HP_WMI_EVENT_GUID
, acpi_hp_notify
, dev
)) {
510 "Could not install notification handler!\n");
517 ACPI_WMI_PROVIDES_GUID_STRING(sc
->wmi_dev
, ACPI_HP_WMI_CMI_GUID
)
519 device_printf(dev
, "HP CMI GUID detected\n");
523 sc
->hpcmi_dev_t
= make_dev(&hpcmi_ops
, 0, UID_ROOT
,
524 GID_WHEEL
, 0644, "hpcmi");
525 sc
->hpcmi_dev_t
->si_drv1
= sc
;
526 sc
->hpcmi_open_pid
= 0;
527 sc
->hpcmi_bufptr
= -1;
530 ACPI_SERIAL_BEGIN(hp
);
532 sysctl_ctx_init(&sc
->sysctl_ctx
);
533 sc
->sysctl_tree
= SYSCTL_ADD_NODE(&sc
->sysctl_ctx
,
534 SYSCTL_CHILDREN(acpi_sc
->acpi_sysctl_tree
), OID_AUTO
,
535 "hp", CTLFLAG_RD
, 0, "");
537 for (int i
= 0; acpi_hp_sysctls
[i
].name
!= NULL
; ++i
) {
539 if ((!sc
->has_notify
&&
540 (acpi_hp_sysctls
[i
].method
==
541 ACPI_HP_METHOD_WLAN_ENABLE_IF_RADIO_ON
||
542 acpi_hp_sysctls
[i
].method
==
543 ACPI_HP_METHOD_WLAN_DISABLE_IF_RADIO_OFF
||
544 acpi_hp_sysctls
[i
].method
==
545 ACPI_HP_METHOD_BLUETOOTH_ENABLE_IF_RADIO_ON
||
546 acpi_hp_sysctls
[i
].method
==
547 ACPI_HP_METHOD_BLUETOOTH_DISABLE_IF_RADIO_OFF
||
548 acpi_hp_sysctls
[i
].method
==
549 ACPI_HP_METHOD_WWAN_ENABLE_IF_RADIO_ON
||
550 acpi_hp_sysctls
[i
].method
==
551 ACPI_HP_METHOD_WWAN_DISABLE_IF_RADIO_OFF
)) ||
552 (arg
= acpi_hp_sysctl_get(sc
,
553 acpi_hp_sysctls
[i
].method
)) < 0) {
556 if (acpi_hp_sysctls
[i
].method
== ACPI_HP_METHOD_WLAN_ON_AIR
) {
557 sc
->was_wlan_on_air
= arg
;
559 else if (acpi_hp_sysctls
[i
].method
==
560 ACPI_HP_METHOD_BLUETOOTH_ON_AIR
) {
561 sc
->was_bluetooth_on_air
= arg
;
563 else if (acpi_hp_sysctls
[i
].method
==
564 ACPI_HP_METHOD_WWAN_ON_AIR
) {
565 sc
->was_wwan_on_air
= arg
;
568 SYSCTL_ADD_PROC(&sc
->sysctl_ctx
,
569 SYSCTL_CHILDREN(sc
->sysctl_tree
), OID_AUTO
,
570 acpi_hp_sysctls
[i
].name
, acpi_hp_sysctls
[i
].access
,
571 sc
, i
, acpi_hp_sysctl
, "I",
572 acpi_hp_sysctls
[i
].description
);
580 acpi_hp_detach(device_t dev
)
584 ACPI_FUNCTION_TRACE((char *)(uintptr_t) __func__
);
585 struct acpi_hp_softc
*sc
= device_get_softc(dev
);
586 if (sc
->has_cmi
&& sc
->hpcmi_open_pid
!= 0) {
590 if (sc
->has_notify
) {
591 ACPI_WMI_REMOVE_EVENT_HANDLER(dev
,
592 ACPI_HP_WMI_EVENT_GUID
);
594 sysctl_ctx_free(&sc
->sysctl_ctx
);
595 if (sc
->hpcmi_bufptr
!= -1) {
596 sbuf_delete(&sc
->hpcmi_sbuf
);
597 sc
->hpcmi_bufptr
= -1;
599 sc
->hpcmi_open_pid
= 0;
600 destroy_dev(sc
->hpcmi_dev_t
);
608 acpi_hp_sysctl(SYSCTL_HANDLER_ARGS
)
610 struct acpi_hp_softc
*sc
;
617 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__
);
619 sc
= (struct acpi_hp_softc
*)oidp
->oid_arg1
;
620 function
= oidp
->oid_arg2
;
621 method
= acpi_hp_sysctls
[function
].method
;
623 ACPI_SERIAL_BEGIN(hp
);
624 arg
= acpi_hp_sysctl_get(sc
, method
);
626 error
= sysctl_handle_int(oidp
, &arg
, 0, req
);
627 if (!error
&& req
->newptr
!= NULL
) {
628 error
= acpi_hp_sysctl_set(sc
, method
, arg
, oldarg
);
636 acpi_hp_sysctl_get(struct acpi_hp_softc
*sc
, int method
)
640 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__
);
641 ACPI_SERIAL_ASSERT(hp
);
644 case ACPI_HP_METHOD_WLAN_ENABLED
:
645 val
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
646 ACPI_HP_WMI_WIRELESS_COMMAND
, 0, 0);
647 val
= ((val
& HP_MASK_WLAN_ENABLED
) != 0);
649 case ACPI_HP_METHOD_WLAN_RADIO
:
650 val
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
651 ACPI_HP_WMI_WIRELESS_COMMAND
, 0, 0);
652 val
= ((val
& HP_MASK_WLAN_RADIO
) != 0);
654 case ACPI_HP_METHOD_WLAN_ON_AIR
:
655 val
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
656 ACPI_HP_WMI_WIRELESS_COMMAND
, 0, 0);
657 val
= ((val
& HP_MASK_WLAN_ON_AIR
) != 0);
659 case ACPI_HP_METHOD_WLAN_ENABLE_IF_RADIO_ON
:
660 val
= sc
->wlan_enable_if_radio_on
;
662 case ACPI_HP_METHOD_WLAN_DISABLE_IF_RADIO_OFF
:
663 val
= sc
->wlan_disable_if_radio_off
;
665 case ACPI_HP_METHOD_BLUETOOTH_ENABLED
:
666 val
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
667 ACPI_HP_WMI_WIRELESS_COMMAND
, 0, 0);
668 val
= ((val
& HP_MASK_BLUETOOTH_ENABLED
) != 0);
670 case ACPI_HP_METHOD_BLUETOOTH_RADIO
:
671 val
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
672 ACPI_HP_WMI_WIRELESS_COMMAND
, 0, 0);
673 val
= ((val
& HP_MASK_BLUETOOTH_RADIO
) != 0);
675 case ACPI_HP_METHOD_BLUETOOTH_ON_AIR
:
676 val
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
677 ACPI_HP_WMI_WIRELESS_COMMAND
, 0, 0);
678 val
= ((val
& HP_MASK_BLUETOOTH_ON_AIR
) != 0);
680 case ACPI_HP_METHOD_BLUETOOTH_ENABLE_IF_RADIO_ON
:
681 val
= sc
->bluetooth_enable_if_radio_on
;
683 case ACPI_HP_METHOD_BLUETOOTH_DISABLE_IF_RADIO_OFF
:
684 val
= sc
->bluetooth_disable_if_radio_off
;
686 case ACPI_HP_METHOD_WWAN_ENABLED
:
687 val
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
688 ACPI_HP_WMI_WIRELESS_COMMAND
, 0, 0);
689 val
= ((val
& HP_MASK_WWAN_ENABLED
) != 0);
691 case ACPI_HP_METHOD_WWAN_RADIO
:
692 val
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
693 ACPI_HP_WMI_WIRELESS_COMMAND
, 0, 0);
694 val
= ((val
& HP_MASK_WWAN_RADIO
) != 0);
696 case ACPI_HP_METHOD_WWAN_ON_AIR
:
697 val
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
698 ACPI_HP_WMI_WIRELESS_COMMAND
, 0, 0);
699 val
= ((val
& HP_MASK_WWAN_ON_AIR
) != 0);
701 case ACPI_HP_METHOD_WWAN_ENABLE_IF_RADIO_ON
:
702 val
= sc
->wwan_enable_if_radio_on
;
704 case ACPI_HP_METHOD_WWAN_DISABLE_IF_RADIO_OFF
:
705 val
= sc
->wwan_disable_if_radio_off
;
707 case ACPI_HP_METHOD_ALS
:
708 val
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
709 ACPI_HP_WMI_ALS_COMMAND
, 0, 0);
711 case ACPI_HP_METHOD_DISPLAY
:
712 val
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
713 ACPI_HP_WMI_DISPLAY_COMMAND
, 0, 0);
715 case ACPI_HP_METHOD_HDDTEMP
:
716 val
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
717 ACPI_HP_WMI_HDDTEMP_COMMAND
, 0, 0);
719 case ACPI_HP_METHOD_DOCK
:
720 val
= acpi_hp_exec_wmi_command(sc
->wmi_dev
,
721 ACPI_HP_WMI_DOCK_COMMAND
, 0, 0);
723 case ACPI_HP_METHOD_CMI_DETAIL
:
724 val
= sc
->cmi_detail
;
726 case ACPI_HP_METHOD_VERBOSE
:
735 acpi_hp_sysctl_set(struct acpi_hp_softc
*sc
, int method
, int arg
, int oldarg
)
737 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__
);
738 ACPI_SERIAL_ASSERT(hp
);
740 if (method
!= ACPI_HP_METHOD_CMI_DETAIL
&&
741 method
!= ACPI_HP_METHOD_VERBOSE
)
746 case ACPI_HP_METHOD_WLAN_ENABLED
:
747 return (acpi_hp_exec_wmi_command(sc
->wmi_dev
,
748 ACPI_HP_WMI_WIRELESS_COMMAND
, 1,
750 case ACPI_HP_METHOD_WLAN_ENABLE_IF_RADIO_ON
:
751 sc
->wlan_enable_if_radio_on
= arg
;
752 acpi_hp_evaluate_auto_on_off(sc
);
754 case ACPI_HP_METHOD_WLAN_DISABLE_IF_RADIO_OFF
:
755 sc
->wlan_disable_if_radio_off
= arg
;
756 acpi_hp_evaluate_auto_on_off(sc
);
758 case ACPI_HP_METHOD_BLUETOOTH_ENABLED
:
759 return (acpi_hp_exec_wmi_command(sc
->wmi_dev
,
760 ACPI_HP_WMI_WIRELESS_COMMAND
, 1,
762 case ACPI_HP_METHOD_BLUETOOTH_ENABLE_IF_RADIO_ON
:
763 sc
->bluetooth_enable_if_radio_on
= arg
;
764 acpi_hp_evaluate_auto_on_off(sc
);
766 case ACPI_HP_METHOD_BLUETOOTH_DISABLE_IF_RADIO_OFF
:
767 sc
->bluetooth_disable_if_radio_off
= arg
?1:0;
768 acpi_hp_evaluate_auto_on_off(sc
);
770 case ACPI_HP_METHOD_WWAN_ENABLED
:
771 return (acpi_hp_exec_wmi_command(sc
->wmi_dev
,
772 ACPI_HP_WMI_WIRELESS_COMMAND
, 1,
774 case ACPI_HP_METHOD_WWAN_ENABLE_IF_RADIO_ON
:
775 sc
->wwan_enable_if_radio_on
= arg
?1:0;
776 acpi_hp_evaluate_auto_on_off(sc
);
778 case ACPI_HP_METHOD_WWAN_DISABLE_IF_RADIO_OFF
:
779 sc
->wwan_disable_if_radio_off
= arg
?1:0;
780 acpi_hp_evaluate_auto_on_off(sc
);
782 case ACPI_HP_METHOD_ALS
:
783 return (acpi_hp_exec_wmi_command(sc
->wmi_dev
,
784 ACPI_HP_WMI_ALS_COMMAND
, 1,
786 case ACPI_HP_METHOD_CMI_DETAIL
:
787 sc
->cmi_detail
= arg
;
788 if ((arg
& ACPI_HP_CMI_DETAIL_SHOW_MAX_INSTANCE
) !=
789 (oldarg
& ACPI_HP_CMI_DETAIL_SHOW_MAX_INSTANCE
)) {
790 sc
->cmi_order_size
= -1;
793 case ACPI_HP_METHOD_VERBOSE
:
803 acpi_hp_free_buffer(ACPI_BUFFER
* buf
) {
804 if (buf
&& buf
->Pointer
) {
805 AcpiOsFree(buf
->Pointer
);
810 acpi_hp_notify(ACPI_HANDLE h
, UINT32 notify
, void *context
)
812 device_t dev
= context
;
813 ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__
, notify
);
815 struct acpi_hp_softc
*sc
= device_get_softc(dev
);
816 ACPI_BUFFER response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
818 ACPI_WMI_GET_EVENT_DATA(sc
->wmi_dev
, notify
, &response
);
819 obj
= (ACPI_OBJECT
*) response
.Pointer
;
820 if (obj
&& obj
->Type
== ACPI_TYPE_BUFFER
&& obj
->Buffer
.Length
== 8) {
821 if (*((UINT8
*) obj
->Buffer
.Pointer
) == 0x5) {
822 acpi_hp_evaluate_auto_on_off(sc
);
825 acpi_hp_free_buffer(&response
);
829 acpi_hp_exec_wmi_command(device_t wmi_dev
, int command
, int is_write
, int val
)
831 UINT32 params
[5] = { 0x55434553,
838 ACPI_BUFFER in
= { sizeof(params
), ¶ms
};
839 ACPI_BUFFER out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
842 if (ACPI_FAILURE(ACPI_WMI_EVALUATE_CALL(wmi_dev
, ACPI_HP_WMI_BIOS_GUID
,
843 0, 0x3, &in
, &out
))) {
844 acpi_hp_free_buffer(&out
);
848 if (!obj
|| obj
->Type
!= ACPI_TYPE_BUFFER
) {
849 acpi_hp_free_buffer(&out
);
852 result
= (UINT32
*) obj
->Buffer
.Pointer
;
857 acpi_hp_free_buffer(&out
);
862 static __inline
char*
863 acpi_hp_get_string_from_object(ACPI_OBJECT
* obj
, char* dst
, size_t size
) {
867 if (obj
->Type
== ACPI_TYPE_STRING
) {
868 length
= obj
->String
.Length
+1;
872 strlcpy(dst
, obj
->String
.Pointer
, length
);
873 acpi_hp_hex_decode(dst
);
881 * Read BIOS Setting block in instance "instance".
882 * The block returned is ACPI_TYPE_PACKAGE which should contain the following
885 * 0 Setting Name [string]
886 * 1 Value (comma separated, asterisk marks the current value) [string]
887 * 2 Path within the bios hierarchy [string]
889 * 4 DisplayInUI [int]
890 * 5 RequiresPhysicalPresence [int]
891 * 6 Sequence for ordering within the bios settings (absolute) [int]
892 * 7 Length of prerequisites array [int]
893 * 8..8+[7] PrerequisiteN [string]
894 * 9+[7] Current value (in case of enum) [string] / Array length [int]
895 * 10+[7] Enum length [int] / Array values
896 * 11+[7]ff Enum value at index x [string]
899 acpi_hp_get_cmi_block(device_t wmi_dev
, const char* guid
, UINT8 instance
,
900 char* outbuf
, size_t outsize
, UINT32
* sequence
, int detail
)
903 ACPI_BUFFER out
= { ACPI_ALLOCATE_BUFFER
, NULL
};
909 char string_buffer
[size
];
912 *sequence
= 0; /* whack gcc warning */
915 if (ACPI_FAILURE(ACPI_WMI_GET_BLOCK(wmi_dev
, guid
, instance
, &out
))) {
916 acpi_hp_free_buffer(&out
);
920 if (!obj
|| obj
->Type
!= ACPI_TYPE_PACKAGE
) {
921 acpi_hp_free_buffer(&out
);
925 if (obj
->Package
.Count
>= 8 &&
926 obj
->Package
.Elements
[7].Type
== ACPI_TYPE_INTEGER
) {
927 valuebase
= 8 + obj
->Package
.Elements
[7].Integer
.Value
;
930 /* check if this matches our expectations based on limited knowledge */
931 if (valuebase
> 7 && obj
->Package
.Count
> valuebase
+ 1 &&
932 obj
->Package
.Elements
[0].Type
== ACPI_TYPE_STRING
&&
933 obj
->Package
.Elements
[1].Type
== ACPI_TYPE_STRING
&&
934 obj
->Package
.Elements
[2].Type
== ACPI_TYPE_STRING
&&
935 obj
->Package
.Elements
[3].Type
== ACPI_TYPE_INTEGER
&&
936 obj
->Package
.Elements
[4].Type
== ACPI_TYPE_INTEGER
&&
937 obj
->Package
.Elements
[5].Type
== ACPI_TYPE_INTEGER
&&
938 obj
->Package
.Elements
[6].Type
== ACPI_TYPE_INTEGER
&&
939 obj
->Package
.Elements
[valuebase
].Type
== ACPI_TYPE_STRING
&&
940 obj
->Package
.Elements
[valuebase
+1].Type
== ACPI_TYPE_INTEGER
&&
941 obj
->Package
.Count
> valuebase
+
942 obj
->Package
.Elements
[valuebase
+1].Integer
.Value
944 enumbase
= valuebase
+ 1;
945 if (detail
& ACPI_HP_CMI_DETAIL_PATHS
) {
946 strlcat(outbuf
, acpi_hp_get_string_from_object(
947 &obj
->Package
.Elements
[2], string_buffer
, size
),
950 while (strlen(outbuf
) < outlen
)
951 strlcat(outbuf
, " ", outsize
);
953 strlcat(outbuf
, acpi_hp_get_string_from_object(
954 &obj
->Package
.Elements
[0], string_buffer
, size
),
957 while (strlen(outbuf
) < outlen
)
958 strlcat(outbuf
, " ", outsize
);
959 strlcat(outbuf
, acpi_hp_get_string_from_object(
960 &obj
->Package
.Elements
[valuebase
], string_buffer
,
964 while (strlen(outbuf
) < outlen
)
965 strlcat(outbuf
, " ", outsize
);
966 for (i
= 0; i
< strlen(outbuf
); ++i
)
967 if (outbuf
[i
] == '\\')
969 if (detail
& ACPI_HP_CMI_DETAIL_ENUMS
) {
970 for (i
= enumbase
+ 1; i
< enumbase
+ 1 +
971 obj
->Package
.Elements
[enumbase
].Integer
.Value
;
973 acpi_hp_get_string_from_object(
974 &obj
->Package
.Elements
[i
], string_buffer
,
976 if (strlen(string_buffer
) > 1 ||
977 (strlen(string_buffer
) == 1 &&
978 string_buffer
[0] != ' ')) {
980 strlcat(outbuf
, "/", outsize
);
982 strlcat(outbuf
, " (", outsize
);
983 strlcat(outbuf
, string_buffer
, outsize
);
989 strlcat(outbuf
, ")", outsize
);
990 if (detail
& ACPI_HP_CMI_DETAIL_FLAGS
) {
991 strlcat(outbuf
, obj
->Package
.Elements
[3].Integer
.Value
?
992 " [ReadOnly]":"", outsize
);
993 strlcat(outbuf
, obj
->Package
.Elements
[4].Integer
.Value
?
994 "":" [NOUI]", outsize
);
995 strlcat(outbuf
, obj
->Package
.Elements
[5].Integer
.Value
?
996 " [RPP]":"", outsize
);
998 *sequence
= (UINT32
) obj
->Package
.Elements
[6].Integer
.Value
;
1000 acpi_hp_free_buffer(&out
);
1008 * Convert given two digit hex string (hexin) to an UINT8 referenced
1010 * Return != 0 if the was a problem (invalid input)
1012 static __inline
int acpi_hp_hex_to_int(const UINT8
*hexin
, UINT8
*byteout
)
1019 if ('0' <= hi
&& hi
<= '9')
1021 else if ('A' <= hi
&& hi
<= 'F')
1023 else if ('a' <= hi
&& hi
<= 'f')
1027 if ('0' <= lo
&& lo
<= '9')
1029 else if ('A' <= lo
&& lo
<= 'F')
1031 else if ('a' <= lo
&& lo
<= 'f')
1035 *byteout
= (hi
<< 4) + lo
;
1042 acpi_hp_hex_decode(char* buffer
)
1045 int length
= strlen(buffer
);
1049 if (((int)length
/2)*2 == length
|| length
< 10) return;
1051 for (i
= 0; i
<length
; ++i
) {
1053 if (buffer
[i
] != ' ')
1057 if (!((buffer
[i
] >= '0' && buffer
[i
] <= '9') ||
1058 (buffer
[i
] >= 'A' && buffer
[i
] <= 'F')))
1062 for (i
= 0; i
<length
; i
+= 3) {
1065 acpi_hp_hex_to_int(uin
, &uout
);
1066 buffer
[i
/3] = (char) uout
;
1068 buffer
[(length
+1)/3] = 0;
1076 acpi_hp_hpcmi_open(struct dev_open_args
*ap
)
1078 struct acpi_hp_softc
*sc
;
1080 struct cdev
*dev
= ap
->a_head
.a_dev
;
1081 struct thread
*td
= curthread
;
1083 if (dev
== NULL
|| dev
->si_drv1
== NULL
)
1087 ACPI_SERIAL_BEGIN(hp
);
1088 if (sc
->hpcmi_open_pid
!= 0) {
1092 if (sbuf_new(&sc
->hpcmi_sbuf
, NULL
, 4096, SBUF_AUTOEXTEND
)
1096 sc
->hpcmi_open_pid
= td
->td_proc
->p_pid
;
1097 sc
->hpcmi_bufptr
= 0;
1101 ACPI_SERIAL_END(hp
);
1107 * close hpcmi device
1110 acpi_hp_hpcmi_close(struct dev_close_args
*ap
)
1112 struct acpi_hp_softc
*sc
;
1114 struct cdev
*dev
= ap
->a_head
.a_dev
;
1116 if (dev
== NULL
|| dev
->si_drv1
== NULL
)
1120 ACPI_SERIAL_BEGIN(hp
);
1121 if (sc
->hpcmi_open_pid
== 0) {
1125 if (sc
->hpcmi_bufptr
!= -1) {
1126 sbuf_delete(&sc
->hpcmi_sbuf
);
1127 sc
->hpcmi_bufptr
= -1;
1129 sc
->hpcmi_open_pid
= 0;
1132 ACPI_SERIAL_END(hp
);
1138 * Read from hpcmi bios information
1141 acpi_hp_hpcmi_read(struct dev_read_args
*ap
)
1143 struct acpi_hp_softc
*sc
;
1148 int linesize
= 1025;
1149 char line
[linesize
];
1150 struct cdev
*dev
= ap
->a_head
.a_dev
;
1151 struct uio
*buf
= ap
->a_uio
;
1153 if (dev
== NULL
|| dev
->si_drv1
== NULL
)
1157 ACPI_SERIAL_BEGIN(hp
);
1158 if (sc
->hpcmi_open_pid
!= buf
->uio_td
->td_proc
->p_pid
1159 || sc
->hpcmi_bufptr
== -1) {
1163 if (!sbuf_done(&sc
->hpcmi_sbuf
)) {
1164 if (sc
->cmi_order_size
< 0) {
1165 maxInstance
= sc
->has_cmi
;
1166 if (!(sc
->cmi_detail
&
1167 ACPI_HP_CMI_DETAIL_SHOW_MAX_INSTANCE
) &&
1171 sc
->cmi_order_size
= 0;
1172 for (instance
= 0; instance
< maxInstance
;
1174 if (acpi_hp_get_cmi_block(sc
->wmi_dev
,
1175 ACPI_HP_WMI_CMI_GUID
, instance
,
1176 line
, linesize
, &sequence
,
1178 instance
= maxInstance
;
1181 pos
= sc
->cmi_order_size
;
1183 i
<sc
->cmi_order_size
&& i
<127;
1185 if (sc
->cmi_order
[i
].sequence
> sequence
) {
1190 for (i
=sc
->cmi_order_size
;
1193 sc
->cmi_order
[i
].sequence
=
1194 sc
->cmi_order
[i
-1].sequence
;
1195 sc
->cmi_order
[i
].instance
=
1196 sc
->cmi_order
[i
-1].instance
;
1198 sc
->cmi_order
[pos
].sequence
=
1200 sc
->cmi_order
[pos
].instance
=
1202 sc
->cmi_order_size
++;
1206 for (i
=0; i
<sc
->cmi_order_size
; ++i
) {
1207 if (!acpi_hp_get_cmi_block(sc
->wmi_dev
,
1208 ACPI_HP_WMI_CMI_GUID
,
1209 sc
->cmi_order
[i
].instance
, line
, linesize
,
1210 &sequence
, sc
->cmi_detail
)) {
1211 sbuf_printf(&sc
->hpcmi_sbuf
, "%s\n", line
);
1214 sbuf_finish(&sc
->hpcmi_sbuf
);
1216 if (sbuf_len(&sc
->hpcmi_sbuf
) <= 0) {
1217 sbuf_delete(&sc
->hpcmi_sbuf
);
1218 sc
->hpcmi_bufptr
= -1;
1219 sc
->hpcmi_open_pid
= 0;
1222 l
= min(buf
->uio_resid
, sbuf_len(&sc
->hpcmi_sbuf
) -
1224 ret
= (l
> 0)?uiomove(sbuf_data(&sc
->hpcmi_sbuf
) +
1225 sc
->hpcmi_bufptr
, l
, buf
) : 0;
1226 sc
->hpcmi_bufptr
+= l
;
1229 ACPI_SERIAL_END(hp
);