1/*- 2 * Copyright (c) 2009 Michael Gmelin <freebsd@grem.de> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 2009 Michael Gmelin <freebsd@grem.de> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h>
|
28__FBSDID("$FreeBSD: head/sys/dev/acpi_support/acpi_hp.c 195185 2009-06-30 09:51:41Z rpaulo $");
| 28__FBSDID("$FreeBSD: head/sys/dev/acpi_support/acpi_hp.c 195325 2009-07-03 21:12:37Z rpaulo $");
|
29 30/* 31 * Driver for extra ACPI-controlled features found on HP laptops 32 * that use a WMI enabled BIOS (e.g. HP Compaq 8510p and 6510p). 33 * Allows to control and read status of integrated hardware and read 34 * BIOS settings through CMI. 35 * Inspired by the hp-wmi driver, which implements a subset of these 36 * features (hotkeys) on Linux. 37 * 38 * HP CMI whitepaper: 39 * http://h20331.www2.hp.com/Hpsub/downloads/cmi_whitepaper.pdf 40 * wmi-hp for Linux: 41 * http://www.kernel.org 42 * WMI and ACPI: 43 * http://www.microsoft.com/whdc/system/pnppwr/wmi/wmi-acpi.mspx 44 */ 45 46#include "opt_acpi.h" 47#include <sys/param.h> 48#include <sys/conf.h> 49#include <sys/uio.h> 50#include <sys/proc.h> 51#include <sys/kernel.h> 52#include <sys/bus.h> 53#include <sys/sbuf.h> 54#include <sys/module.h> 55#include <sys/sysctl.h> 56 57#include <contrib/dev/acpica/include/acpi.h> 58#include <contrib/dev/acpica/include/accommon.h> 59#include <dev/acpica/acpivar.h> 60#include "acpi_wmi_if.h" 61 62#define _COMPONENT ACPI_OEM 63ACPI_MODULE_NAME("HP") 64 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" 68 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 74 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
| 29 30/* 31 * Driver for extra ACPI-controlled features found on HP laptops 32 * that use a WMI enabled BIOS (e.g. HP Compaq 8510p and 6510p). 33 * Allows to control and read status of integrated hardware and read 34 * BIOS settings through CMI. 35 * Inspired by the hp-wmi driver, which implements a subset of these 36 * features (hotkeys) on Linux. 37 * 38 * HP CMI whitepaper: 39 * http://h20331.www2.hp.com/Hpsub/downloads/cmi_whitepaper.pdf 40 * wmi-hp for Linux: 41 * http://www.kernel.org 42 * WMI and ACPI: 43 * http://www.microsoft.com/whdc/system/pnppwr/wmi/wmi-acpi.mspx 44 */ 45 46#include "opt_acpi.h" 47#include <sys/param.h> 48#include <sys/conf.h> 49#include <sys/uio.h> 50#include <sys/proc.h> 51#include <sys/kernel.h> 52#include <sys/bus.h> 53#include <sys/sbuf.h> 54#include <sys/module.h> 55#include <sys/sysctl.h> 56 57#include <contrib/dev/acpica/include/acpi.h> 58#include <contrib/dev/acpica/include/accommon.h> 59#include <dev/acpica/acpivar.h> 60#include "acpi_wmi_if.h" 61 62#define _COMPONENT ACPI_OEM 63ACPI_MODULE_NAME("HP") 64 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" 68 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 74 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
|
95 96#define HP_MASK_WWAN_ON_AIR 0x1000000 97#define HP_MASK_BLUETOOTH_ON_AIR 0x10000 98#define HP_MASK_WLAN_ON_AIR 0x100 99#define HP_MASK_WWAN_RADIO 0x8000000 100#define HP_MASK_BLUETOOTH_RADIO 0x80000 101#define HP_MASK_WLAN_RADIO 0x800 102#define HP_MASK_WWAN_ENABLED 0x2000000 103#define HP_MASK_BLUETOOTH_ENABLED 0x20000 104#define HP_MASK_WLAN_ENABLED 0x200 105 106#define ACPI_HP_CMI_DETAIL_PATHS 0x01 107#define ACPI_HP_CMI_DETAIL_ENUMS 0x02 108#define ACPI_HP_CMI_DETAIL_FLAGS 0x04 109#define ACPI_HP_CMI_DETAIL_SHOW_MAX_INSTANCE 0x08 110 111struct acpi_hp_inst_seq_pair { 112 UINT32 sequence; /* sequence number as suggested by cmi bios */ 113 UINT8 instance; /* object instance on guid */ 114}; 115 116struct acpi_hp_softc { 117 device_t dev; 118 ACPI_HANDLE handle; 119 device_t wmi_dev; 120 int has_notify; /* notification GUID found */ 121 int has_cmi; /* CMI GUID found */ 122 int cmi_detail; /* CMI detail level 123 (set by sysctl) */
| 96 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 106 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 111 112struct acpi_hp_inst_seq_pair { 113 UINT32 sequence; /* sequence number as suggested by cmi bios */ 114 UINT8 instance; /* object instance on guid */ 115}; 116 117struct acpi_hp_softc { 118 device_t dev; 119 ACPI_HANDLE handle; 120 device_t wmi_dev; 121 int has_notify; /* notification GUID found */ 122 int has_cmi; /* CMI GUID found */ 123 int cmi_detail; /* CMI detail level 124 (set by sysctl) */
|
| 125 int verbose; /* add debug output */
|
124 int wlan_enable_if_radio_on; /* set by sysctl */ 125 int wlan_disable_if_radio_off; /* set by sysctl */ 126 int bluetooth_enable_if_radio_on; /* set by sysctl */ 127 int bluetooth_disable_if_radio_off; /* set by sysctl */ 128 int wwan_enable_if_radio_on; /* set by sysctl */ 129 int wwan_disable_if_radio_off; /* set by sysctl */ 130 int was_wlan_on_air; /* last known WLAN 131 on air status */ 132 int was_bluetooth_on_air; /* last known BT 133 on air status */ 134 int was_wwan_on_air; /* last known WWAN 135 on air status */ 136 struct sysctl_ctx_list *sysctl_ctx; 137 struct sysctl_oid *sysctl_tree; 138 struct cdev *hpcmi_dev_t; /* hpcmi device handle */ 139 struct sbuf hpcmi_sbuf; /* /dev/hpcmi output sbuf */ 140 pid_t hpcmi_open_pid; /* pid operating on 141 /dev/hpcmi */ 142 int hpcmi_bufptr; /* current pointer position 143 in /dev/hpcmi output buffer 144 */ 145 int cmi_order_size; /* size of cmi_order list */ 146 struct acpi_hp_inst_seq_pair cmi_order[128]; /* list of CMI 147 instances ordered by BIOS suggested sequence */ 148}; 149 150static struct { 151 char *name; 152 int method; 153 char *description; 154 int access; 155} acpi_hp_sysctls[] = { 156 { 157 .name = "wlan_enabled", 158 .method = ACPI_HP_METHOD_WLAN_ENABLED, 159 .description = "Enable/Disable WLAN (WiFi)", 160 .access = CTLTYPE_INT | CTLFLAG_RW 161 }, 162 { 163 .name = "wlan_radio", 164 .method = ACPI_HP_METHOD_WLAN_RADIO, 165 .description = "WLAN radio status", 166 .access = CTLTYPE_INT | CTLFLAG_RD 167 }, 168 { 169 .name = "wlan_on_air", 170 .method = ACPI_HP_METHOD_WLAN_ON_AIR, 171 .description = "WLAN radio ready to use (enabled and radio)", 172 .access = CTLTYPE_INT | CTLFLAG_RD 173 }, 174 { 175 .name = "wlan_enable_if_radio_on", 176 .method = ACPI_HP_METHOD_WLAN_ENABLE_IF_RADIO_ON, 177 .description = "Enable WLAN if radio is turned on", 178 .access = CTLTYPE_INT | CTLFLAG_RW 179 }, 180 { 181 .name = "wlan_disable_if_radio_off", 182 .method = ACPI_HP_METHOD_WLAN_DISABLE_IF_RADIO_OFF, 183 .description = "Disable WLAN if radio is turned off", 184 .access = CTLTYPE_INT | CTLFLAG_RW 185 }, 186 { 187 .name = "bt_enabled", 188 .method = ACPI_HP_METHOD_BLUETOOTH_ENABLED, 189 .description = "Enable/Disable Bluetooth", 190 .access = CTLTYPE_INT | CTLFLAG_RW 191 }, 192 { 193 .name = "bt_radio", 194 .method = ACPI_HP_METHOD_BLUETOOTH_RADIO, 195 .description = "Bluetooth radio status", 196 .access = CTLTYPE_INT | CTLFLAG_RD 197 }, 198 { 199 .name = "bt_on_air", 200 .method = ACPI_HP_METHOD_BLUETOOTH_ON_AIR, 201 .description = "Bluetooth radio ready to use" 202 " (enabled and radio)", 203 .access = CTLTYPE_INT | CTLFLAG_RD 204 }, 205 { 206 .name = "bt_enable_if_radio_on", 207 .method = ACPI_HP_METHOD_BLUETOOTH_ENABLE_IF_RADIO_ON, 208 .description = "Enable bluetooth if radio is turned on", 209 .access = CTLTYPE_INT | CTLFLAG_RW 210 }, 211 { 212 .name = "bt_disable_if_radio_off", 213 .method = ACPI_HP_METHOD_BLUETOOTH_DISABLE_IF_RADIO_OFF, 214 .description = "Disable bluetooth if radio is turned off", 215 .access = CTLTYPE_INT | CTLFLAG_RW 216 }, 217 { 218 .name = "wwan_enabled", 219 .method = ACPI_HP_METHOD_WWAN_ENABLED, 220 .description = "Enable/Disable WWAN (UMTS)", 221 .access = CTLTYPE_INT | CTLFLAG_RW 222 }, 223 { 224 .name = "wwan_radio", 225 .method = ACPI_HP_METHOD_WWAN_RADIO, 226 .description = "WWAN radio status", 227 .access = CTLTYPE_INT | CTLFLAG_RD 228 }, 229 { 230 .name = "wwan_on_air", 231 .method = ACPI_HP_METHOD_WWAN_ON_AIR, 232 .description = "WWAN radio ready to use (enabled and radio)", 233 .access = CTLTYPE_INT | CTLFLAG_RD 234 }, 235 { 236 .name = "wwan_enable_if_radio_on", 237 .method = ACPI_HP_METHOD_WWAN_ENABLE_IF_RADIO_ON, 238 .description = "Enable WWAN if radio is turned on", 239 .access = CTLTYPE_INT | CTLFLAG_RW 240 }, 241 { 242 .name = "wwan_disable_if_radio_off", 243 .method = ACPI_HP_METHOD_WWAN_DISABLE_IF_RADIO_OFF, 244 .description = "Disable WWAN if radio is turned off", 245 .access = CTLTYPE_INT | CTLFLAG_RW 246 }, 247 { 248 .name = "als_enabled", 249 .method = ACPI_HP_METHOD_ALS, 250 .description = "Enable/Disable ALS (Ambient light sensor)", 251 .access = CTLTYPE_INT | CTLFLAG_RW 252 }, 253 { 254 .name = "display", 255 .method = ACPI_HP_METHOD_DISPLAY, 256 .description = "Display status", 257 .access = CTLTYPE_INT | CTLFLAG_RD 258 }, 259 { 260 .name = "hdd_temperature", 261 .method = ACPI_HP_METHOD_HDDTEMP, 262 .description = "HDD temperature", 263 .access = CTLTYPE_INT | CTLFLAG_RD 264 }, 265 { 266 .name = "is_docked", 267 .method = ACPI_HP_METHOD_DOCK, 268 .description = "Docking station status", 269 .access = CTLTYPE_INT | CTLFLAG_RD 270 }, 271 { 272 .name = "cmi_detail", 273 .method = ACPI_HP_METHOD_CMI_DETAIL, 274 .description = "Details shown in CMI output " 275 "(cat /dev/hpcmi)", 276 .access = CTLTYPE_INT | CTLFLAG_RW 277 },
| 126 int wlan_enable_if_radio_on; /* set by sysctl */ 127 int wlan_disable_if_radio_off; /* set by sysctl */ 128 int bluetooth_enable_if_radio_on; /* set by sysctl */ 129 int bluetooth_disable_if_radio_off; /* set by sysctl */ 130 int wwan_enable_if_radio_on; /* set by sysctl */ 131 int wwan_disable_if_radio_off; /* set by sysctl */ 132 int was_wlan_on_air; /* last known WLAN 133 on air status */ 134 int was_bluetooth_on_air; /* last known BT 135 on air status */ 136 int was_wwan_on_air; /* last known WWAN 137 on air status */ 138 struct sysctl_ctx_list *sysctl_ctx; 139 struct sysctl_oid *sysctl_tree; 140 struct cdev *hpcmi_dev_t; /* hpcmi device handle */ 141 struct sbuf hpcmi_sbuf; /* /dev/hpcmi output sbuf */ 142 pid_t hpcmi_open_pid; /* pid operating on 143 /dev/hpcmi */ 144 int hpcmi_bufptr; /* current pointer position 145 in /dev/hpcmi output buffer 146 */ 147 int cmi_order_size; /* size of cmi_order list */ 148 struct acpi_hp_inst_seq_pair cmi_order[128]; /* list of CMI 149 instances ordered by BIOS suggested sequence */ 150}; 151 152static struct { 153 char *name; 154 int method; 155 char *description; 156 int access; 157} acpi_hp_sysctls[] = { 158 { 159 .name = "wlan_enabled", 160 .method = ACPI_HP_METHOD_WLAN_ENABLED, 161 .description = "Enable/Disable WLAN (WiFi)", 162 .access = CTLTYPE_INT | CTLFLAG_RW 163 }, 164 { 165 .name = "wlan_radio", 166 .method = ACPI_HP_METHOD_WLAN_RADIO, 167 .description = "WLAN radio status", 168 .access = CTLTYPE_INT | CTLFLAG_RD 169 }, 170 { 171 .name = "wlan_on_air", 172 .method = ACPI_HP_METHOD_WLAN_ON_AIR, 173 .description = "WLAN radio ready to use (enabled and radio)", 174 .access = CTLTYPE_INT | CTLFLAG_RD 175 }, 176 { 177 .name = "wlan_enable_if_radio_on", 178 .method = ACPI_HP_METHOD_WLAN_ENABLE_IF_RADIO_ON, 179 .description = "Enable WLAN if radio is turned on", 180 .access = CTLTYPE_INT | CTLFLAG_RW 181 }, 182 { 183 .name = "wlan_disable_if_radio_off", 184 .method = ACPI_HP_METHOD_WLAN_DISABLE_IF_RADIO_OFF, 185 .description = "Disable WLAN if radio is turned off", 186 .access = CTLTYPE_INT | CTLFLAG_RW 187 }, 188 { 189 .name = "bt_enabled", 190 .method = ACPI_HP_METHOD_BLUETOOTH_ENABLED, 191 .description = "Enable/Disable Bluetooth", 192 .access = CTLTYPE_INT | CTLFLAG_RW 193 }, 194 { 195 .name = "bt_radio", 196 .method = ACPI_HP_METHOD_BLUETOOTH_RADIO, 197 .description = "Bluetooth radio status", 198 .access = CTLTYPE_INT | CTLFLAG_RD 199 }, 200 { 201 .name = "bt_on_air", 202 .method = ACPI_HP_METHOD_BLUETOOTH_ON_AIR, 203 .description = "Bluetooth radio ready to use" 204 " (enabled and radio)", 205 .access = CTLTYPE_INT | CTLFLAG_RD 206 }, 207 { 208 .name = "bt_enable_if_radio_on", 209 .method = ACPI_HP_METHOD_BLUETOOTH_ENABLE_IF_RADIO_ON, 210 .description = "Enable bluetooth if radio is turned on", 211 .access = CTLTYPE_INT | CTLFLAG_RW 212 }, 213 { 214 .name = "bt_disable_if_radio_off", 215 .method = ACPI_HP_METHOD_BLUETOOTH_DISABLE_IF_RADIO_OFF, 216 .description = "Disable bluetooth if radio is turned off", 217 .access = CTLTYPE_INT | CTLFLAG_RW 218 }, 219 { 220 .name = "wwan_enabled", 221 .method = ACPI_HP_METHOD_WWAN_ENABLED, 222 .description = "Enable/Disable WWAN (UMTS)", 223 .access = CTLTYPE_INT | CTLFLAG_RW 224 }, 225 { 226 .name = "wwan_radio", 227 .method = ACPI_HP_METHOD_WWAN_RADIO, 228 .description = "WWAN radio status", 229 .access = CTLTYPE_INT | CTLFLAG_RD 230 }, 231 { 232 .name = "wwan_on_air", 233 .method = ACPI_HP_METHOD_WWAN_ON_AIR, 234 .description = "WWAN radio ready to use (enabled and radio)", 235 .access = CTLTYPE_INT | CTLFLAG_RD 236 }, 237 { 238 .name = "wwan_enable_if_radio_on", 239 .method = ACPI_HP_METHOD_WWAN_ENABLE_IF_RADIO_ON, 240 .description = "Enable WWAN if radio is turned on", 241 .access = CTLTYPE_INT | CTLFLAG_RW 242 }, 243 { 244 .name = "wwan_disable_if_radio_off", 245 .method = ACPI_HP_METHOD_WWAN_DISABLE_IF_RADIO_OFF, 246 .description = "Disable WWAN if radio is turned off", 247 .access = CTLTYPE_INT | CTLFLAG_RW 248 }, 249 { 250 .name = "als_enabled", 251 .method = ACPI_HP_METHOD_ALS, 252 .description = "Enable/Disable ALS (Ambient light sensor)", 253 .access = CTLTYPE_INT | CTLFLAG_RW 254 }, 255 { 256 .name = "display", 257 .method = ACPI_HP_METHOD_DISPLAY, 258 .description = "Display status", 259 .access = CTLTYPE_INT | CTLFLAG_RD 260 }, 261 { 262 .name = "hdd_temperature", 263 .method = ACPI_HP_METHOD_HDDTEMP, 264 .description = "HDD temperature", 265 .access = CTLTYPE_INT | CTLFLAG_RD 266 }, 267 { 268 .name = "is_docked", 269 .method = ACPI_HP_METHOD_DOCK, 270 .description = "Docking station status", 271 .access = CTLTYPE_INT | CTLFLAG_RD 272 }, 273 { 274 .name = "cmi_detail", 275 .method = ACPI_HP_METHOD_CMI_DETAIL, 276 .description = "Details shown in CMI output " 277 "(cat /dev/hpcmi)", 278 .access = CTLTYPE_INT | CTLFLAG_RW 279 },
|
| 280 { 281 .name = "verbose", 282 .method = ACPI_HP_METHOD_VERBOSE, 283 .description = "Verbosity level", 284 .access = CTLTYPE_INT | CTLFLAG_RW 285 },
|
278 279 { NULL, 0, NULL, 0 } 280}; 281 282ACPI_SERIAL_DECL(hp, "HP ACPI-WMI Mapping"); 283 284static int acpi_hp_probe(device_t dev); 285static int acpi_hp_attach(device_t dev); 286static int acpi_hp_detach(device_t dev); 287 288static void acpi_hp_evaluate_auto_on_off(struct acpi_hp_softc* sc); 289static int acpi_hp_sysctl(SYSCTL_HANDLER_ARGS); 290static int acpi_hp_sysctl_set(struct acpi_hp_softc *sc, int method, 291 int arg, int oldarg); 292static int acpi_hp_sysctl_get(struct acpi_hp_softc *sc, int method); 293static int acpi_hp_exec_wmi_command(device_t wmi_dev, int command, 294 int is_write, int val); 295static void acpi_hp_notify(ACPI_HANDLE h, UINT32 notify, void *context); 296static int acpi_hp_get_cmi_block(device_t wmi_dev, const char* guid, 297 UINT8 instance, char* outbuf, size_t outsize, 298 UINT32* sequence, int detail); 299static void acpi_hp_hex_decode(char* buffer); 300 301static d_open_t acpi_hp_hpcmi_open; 302static d_close_t acpi_hp_hpcmi_close; 303static d_read_t acpi_hp_hpcmi_read; 304 305/* handler /dev/hpcmi device */ 306static struct cdevsw hpcmi_cdevsw = { 307 .d_version = D_VERSION, 308 .d_open = acpi_hp_hpcmi_open, 309 .d_close = acpi_hp_hpcmi_close, 310 .d_read = acpi_hp_hpcmi_read, 311 .d_name = "hpcmi", 312}; 313 314static device_method_t acpi_hp_methods[] = { 315 DEVMETHOD(device_probe, acpi_hp_probe), 316 DEVMETHOD(device_attach, acpi_hp_attach), 317 DEVMETHOD(device_detach, acpi_hp_detach), 318 {0, 0} 319}; 320 321static driver_t acpi_hp_driver = { 322 "acpi_hp", 323 acpi_hp_methods, 324 sizeof(struct acpi_hp_softc), 325}; 326 327static devclass_t acpi_hp_devclass; 328 329DRIVER_MODULE(acpi_hp, acpi, acpi_hp_driver, acpi_hp_devclass, 330 0, 0); 331MODULE_DEPEND(acpi_hp, acpi_wmi, 1, 1, 1); 332MODULE_DEPEND(acpi_hp, acpi, 1, 1, 1); 333 334static void 335acpi_hp_evaluate_auto_on_off(struct acpi_hp_softc *sc) 336{
| 286 287 { NULL, 0, NULL, 0 } 288}; 289 290ACPI_SERIAL_DECL(hp, "HP ACPI-WMI Mapping"); 291 292static int acpi_hp_probe(device_t dev); 293static int acpi_hp_attach(device_t dev); 294static int acpi_hp_detach(device_t dev); 295 296static void acpi_hp_evaluate_auto_on_off(struct acpi_hp_softc* sc); 297static int acpi_hp_sysctl(SYSCTL_HANDLER_ARGS); 298static int acpi_hp_sysctl_set(struct acpi_hp_softc *sc, int method, 299 int arg, int oldarg); 300static int acpi_hp_sysctl_get(struct acpi_hp_softc *sc, int method); 301static int acpi_hp_exec_wmi_command(device_t wmi_dev, int command, 302 int is_write, int val); 303static void acpi_hp_notify(ACPI_HANDLE h, UINT32 notify, void *context); 304static 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); 307static void acpi_hp_hex_decode(char* buffer); 308 309static d_open_t acpi_hp_hpcmi_open; 310static d_close_t acpi_hp_hpcmi_close; 311static d_read_t acpi_hp_hpcmi_read; 312 313/* handler /dev/hpcmi device */ 314static struct cdevsw hpcmi_cdevsw = { 315 .d_version = D_VERSION, 316 .d_open = acpi_hp_hpcmi_open, 317 .d_close = acpi_hp_hpcmi_close, 318 .d_read = acpi_hp_hpcmi_read, 319 .d_name = "hpcmi", 320}; 321 322static device_method_t acpi_hp_methods[] = { 323 DEVMETHOD(device_probe, acpi_hp_probe), 324 DEVMETHOD(device_attach, acpi_hp_attach), 325 DEVMETHOD(device_detach, acpi_hp_detach), 326 {0, 0} 327}; 328 329static driver_t acpi_hp_driver = { 330 "acpi_hp", 331 acpi_hp_methods, 332 sizeof(struct acpi_hp_softc), 333}; 334 335static devclass_t acpi_hp_devclass; 336 337DRIVER_MODULE(acpi_hp, acpi, acpi_hp_driver, acpi_hp_devclass, 338 0, 0); 339MODULE_DEPEND(acpi_hp, acpi_wmi, 1, 1, 1); 340MODULE_DEPEND(acpi_hp, acpi, 1, 1, 1); 341 342static void 343acpi_hp_evaluate_auto_on_off(struct acpi_hp_softc *sc) 344{
|
337 int wireless; 338 int new_wlan_status; 339 int new_bluetooth_status; 340 int new_wwan_status;
| 345 int wireless; 346 int new_wlan_status; 347 int new_bluetooth_status; 348 int new_wwan_status;
|
341 342 wireless = acpi_hp_exec_wmi_command(sc->wmi_dev, 343 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 344 new_wlan_status = -1; 345 new_bluetooth_status = -1; 346 new_wwan_status = -1; 347
| 349 350 wireless = acpi_hp_exec_wmi_command(sc->wmi_dev, 351 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 352 new_wlan_status = -1; 353 new_bluetooth_status = -1; 354 new_wwan_status = -1; 355
|
348 device_printf(sc->wmi_dev, "Wireless status is %x\n", wireless);
| 356 if (sc->verbose) 357 device_printf(sc->wmi_dev, "Wireless status is %x\n", wireless);
|
349 if (sc->wlan_disable_if_radio_off && !(wireless & HP_MASK_WLAN_RADIO) 350 && (wireless & HP_MASK_WLAN_ENABLED)) { 351 acpi_hp_exec_wmi_command(sc->wmi_dev, 352 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 0x100); 353 new_wlan_status = 0; 354 } 355 else if (sc->wlan_enable_if_radio_on && (wireless & HP_MASK_WLAN_RADIO) 356 && !(wireless & HP_MASK_WLAN_ENABLED)) { 357 acpi_hp_exec_wmi_command(sc->wmi_dev, 358 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 0x101); 359 new_wlan_status = 1; 360 } 361 if (sc->bluetooth_disable_if_radio_off && 362 !(wireless & HP_MASK_BLUETOOTH_RADIO) && 363 (wireless & HP_MASK_BLUETOOTH_ENABLED)) { 364 acpi_hp_exec_wmi_command(sc->wmi_dev, 365 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 0x200); 366 new_bluetooth_status = 0; 367 } 368 else if (sc->bluetooth_enable_if_radio_on && 369 (wireless & HP_MASK_BLUETOOTH_RADIO) && 370 !(wireless & HP_MASK_BLUETOOTH_ENABLED)) { 371 acpi_hp_exec_wmi_command(sc->wmi_dev, 372 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 0x202); 373 new_bluetooth_status = 1; 374 } 375 if (sc->wwan_disable_if_radio_off && 376 !(wireless & HP_MASK_WWAN_RADIO) && 377 (wireless & HP_MASK_WWAN_ENABLED)) { 378 acpi_hp_exec_wmi_command(sc->wmi_dev, 379 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 0x400); 380 new_wwan_status = 0; 381 } 382 else if (sc->wwan_enable_if_radio_on && 383 (wireless & HP_MASK_WWAN_RADIO) && 384 !(wireless & HP_MASK_WWAN_ENABLED)) { 385 acpi_hp_exec_wmi_command(sc->wmi_dev, 386 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 0x404); 387 new_wwan_status = 1; 388 } 389 390 if (new_wlan_status == -1) { 391 new_wlan_status = (wireless & HP_MASK_WLAN_ON_AIR); 392 if ((new_wlan_status?1:0) != sc->was_wlan_on_air) { 393 sc->was_wlan_on_air = sc->was_wlan_on_air?0:1;
| 358 if (sc->wlan_disable_if_radio_off && !(wireless & HP_MASK_WLAN_RADIO) 359 && (wireless & HP_MASK_WLAN_ENABLED)) { 360 acpi_hp_exec_wmi_command(sc->wmi_dev, 361 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 0x100); 362 new_wlan_status = 0; 363 } 364 else if (sc->wlan_enable_if_radio_on && (wireless & HP_MASK_WLAN_RADIO) 365 && !(wireless & HP_MASK_WLAN_ENABLED)) { 366 acpi_hp_exec_wmi_command(sc->wmi_dev, 367 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 0x101); 368 new_wlan_status = 1; 369 } 370 if (sc->bluetooth_disable_if_radio_off && 371 !(wireless & HP_MASK_BLUETOOTH_RADIO) && 372 (wireless & HP_MASK_BLUETOOTH_ENABLED)) { 373 acpi_hp_exec_wmi_command(sc->wmi_dev, 374 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 0x200); 375 new_bluetooth_status = 0; 376 } 377 else if (sc->bluetooth_enable_if_radio_on && 378 (wireless & HP_MASK_BLUETOOTH_RADIO) && 379 !(wireless & HP_MASK_BLUETOOTH_ENABLED)) { 380 acpi_hp_exec_wmi_command(sc->wmi_dev, 381 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 0x202); 382 new_bluetooth_status = 1; 383 } 384 if (sc->wwan_disable_if_radio_off && 385 !(wireless & HP_MASK_WWAN_RADIO) && 386 (wireless & HP_MASK_WWAN_ENABLED)) { 387 acpi_hp_exec_wmi_command(sc->wmi_dev, 388 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 0x400); 389 new_wwan_status = 0; 390 } 391 else if (sc->wwan_enable_if_radio_on && 392 (wireless & HP_MASK_WWAN_RADIO) && 393 !(wireless & HP_MASK_WWAN_ENABLED)) { 394 acpi_hp_exec_wmi_command(sc->wmi_dev, 395 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 0x404); 396 new_wwan_status = 1; 397 } 398 399 if (new_wlan_status == -1) { 400 new_wlan_status = (wireless & HP_MASK_WLAN_ON_AIR); 401 if ((new_wlan_status?1:0) != sc->was_wlan_on_air) { 402 sc->was_wlan_on_air = sc->was_wlan_on_air?0:1;
|
394 device_printf(sc->wmi_dev, 395 "WLAN on air changed to %i " 396 "(new_wlan_status is %i)\n", 397 sc->was_wlan_on_air, new_wlan_status);
| 403 if (sc->verbose) 404 device_printf(sc->wmi_dev, 405 "WLAN on air changed to %i " 406 "(new_wlan_status is %i)\n", 407 sc->was_wlan_on_air, new_wlan_status);
|
398 acpi_UserNotify("HP", sc->handle, 399 0xc0+sc->was_wlan_on_air); 400 } 401 } 402 if (new_bluetooth_status == -1) { 403 new_bluetooth_status = (wireless & HP_MASK_BLUETOOTH_ON_AIR); 404 if ((new_bluetooth_status?1:0) != sc->was_bluetooth_on_air) { 405 sc->was_bluetooth_on_air = sc->was_bluetooth_on_air? 406 0:1;
| 408 acpi_UserNotify("HP", sc->handle, 409 0xc0+sc->was_wlan_on_air); 410 } 411 } 412 if (new_bluetooth_status == -1) { 413 new_bluetooth_status = (wireless & HP_MASK_BLUETOOTH_ON_AIR); 414 if ((new_bluetooth_status?1:0) != sc->was_bluetooth_on_air) { 415 sc->was_bluetooth_on_air = sc->was_bluetooth_on_air? 416 0:1;
|
407 device_printf(sc->wmi_dev, "BLUETOOTH on air changed" 408 " to %i (new_bluetooth_status is %i)\n", 409 sc->was_bluetooth_on_air, new_bluetooth_status);
| 417 if (sc->verbose) 418 device_printf(sc->wmi_dev, 419 "BLUETOOTH on air changed" 420 " to %i (new_bluetooth_status is %i)\n", 421 sc->was_bluetooth_on_air, 422 new_bluetooth_status);
|
410 acpi_UserNotify("HP", sc->handle, 411 0xd0+sc->was_bluetooth_on_air); 412 } 413 } 414 if (new_wwan_status == -1) { 415 new_wwan_status = (wireless & HP_MASK_WWAN_ON_AIR); 416 if ((new_wwan_status?1:0) != sc->was_wwan_on_air) { 417 sc->was_wwan_on_air = sc->was_wwan_on_air?0:1;
| 423 acpi_UserNotify("HP", sc->handle, 424 0xd0+sc->was_bluetooth_on_air); 425 } 426 } 427 if (new_wwan_status == -1) { 428 new_wwan_status = (wireless & HP_MASK_WWAN_ON_AIR); 429 if ((new_wwan_status?1:0) != sc->was_wwan_on_air) { 430 sc->was_wwan_on_air = sc->was_wwan_on_air?0:1;
|
418 device_printf(sc->wmi_dev, "WWAN on air changed to %i" 419 " (new_wwan_status is %i)\n", 420 sc->was_wwan_on_air, new_wwan_status);
| 431 if (sc->verbose) 432 device_printf(sc->wmi_dev, 433 "WWAN on air changed to %i" 434 " (new_wwan_status is %i)\n", 435 sc->was_wwan_on_air, new_wwan_status);
|
421 acpi_UserNotify("HP", sc->handle, 422 0xe0+sc->was_wwan_on_air); 423 } 424 } 425} 426 427static int 428acpi_hp_probe(device_t dev) 429{ 430 if (acpi_disabled("hp") || device_get_unit(dev) != 0) 431 return (ENXIO); 432 device_set_desc(dev, "HP ACPI-WMI Mapping"); 433 434 return (0); 435} 436 437static int 438acpi_hp_attach(device_t dev) 439{ 440 struct acpi_hp_softc *sc; 441 struct acpi_softc *acpi_sc; 442 devclass_t wmi_devclass;
| 436 acpi_UserNotify("HP", sc->handle, 437 0xe0+sc->was_wwan_on_air); 438 } 439 } 440} 441 442static int 443acpi_hp_probe(device_t dev) 444{ 445 if (acpi_disabled("hp") || device_get_unit(dev) != 0) 446 return (ENXIO); 447 device_set_desc(dev, "HP ACPI-WMI Mapping"); 448 449 return (0); 450} 451 452static int 453acpi_hp_attach(device_t dev) 454{ 455 struct acpi_hp_softc *sc; 456 struct acpi_softc *acpi_sc; 457 devclass_t wmi_devclass;
|
443 int arg;
| 458 int arg;
|
444 445 ACPI_FUNCTION_TRACE((char *)(uintptr_t) __func__); 446 447 sc = device_get_softc(dev); 448 sc->dev = dev; 449 sc->handle = acpi_get_handle(dev); 450 sc->has_notify = 0; 451 sc->has_cmi = 0; 452 sc->bluetooth_enable_if_radio_on = 0; 453 sc->bluetooth_disable_if_radio_off = 0; 454 sc->wlan_enable_if_radio_on = 0; 455 sc->wlan_disable_if_radio_off = 0; 456 sc->wlan_enable_if_radio_on = 0; 457 sc->wlan_disable_if_radio_off = 0; 458 sc->was_wlan_on_air = 0; 459 sc->was_bluetooth_on_air = 0; 460 sc->was_wwan_on_air = 0; 461 sc->cmi_detail = 0; 462 sc->cmi_order_size = -1;
| 459 460 ACPI_FUNCTION_TRACE((char *)(uintptr_t) __func__); 461 462 sc = device_get_softc(dev); 463 sc->dev = dev; 464 sc->handle = acpi_get_handle(dev); 465 sc->has_notify = 0; 466 sc->has_cmi = 0; 467 sc->bluetooth_enable_if_radio_on = 0; 468 sc->bluetooth_disable_if_radio_off = 0; 469 sc->wlan_enable_if_radio_on = 0; 470 sc->wlan_disable_if_radio_off = 0; 471 sc->wlan_enable_if_radio_on = 0; 472 sc->wlan_disable_if_radio_off = 0; 473 sc->was_wlan_on_air = 0; 474 sc->was_bluetooth_on_air = 0; 475 sc->was_wwan_on_air = 0; 476 sc->cmi_detail = 0; 477 sc->cmi_order_size = -1;
|
| 478 sc->verbose = 0;
|
463 memset(sc->cmi_order, 0, sizeof(sc->cmi_order)); 464 acpi_sc = acpi_device_get_parent_softc(dev); 465 466 if (!(wmi_devclass = devclass_find ("acpi_wmi"))) { 467 device_printf(dev, "Couldn't find acpi_wmi devclass\n"); 468 return (EINVAL); 469 } 470 if (!(sc->wmi_dev = devclass_get_device(wmi_devclass, 0))) { 471 device_printf(dev, "Couldn't find acpi_wmi device\n"); 472 return (EINVAL); 473 } 474 if (!ACPI_WMI_PROVIDES_GUID_STRING(sc->wmi_dev, 475 ACPI_HP_WMI_BIOS_GUID)) { 476 device_printf(dev, 477 "WMI device does not provide the HP BIOS GUID\n"); 478 return (EINVAL); 479 } 480 if (ACPI_WMI_PROVIDES_GUID_STRING(sc->wmi_dev, 481 ACPI_HP_WMI_EVENT_GUID)) { 482 device_printf(dev, 483 "HP event GUID detected, installing event handler\n"); 484 if (ACPI_WMI_INSTALL_EVENT_HANDLER(sc->wmi_dev, 485 ACPI_HP_WMI_EVENT_GUID, acpi_hp_notify, dev)) { 486 device_printf(dev, 487 "Could not install notification handler!\n"); 488 } 489 else { 490 sc->has_notify = 1; 491 } 492 } 493 if ((sc->has_cmi = 494 ACPI_WMI_PROVIDES_GUID_STRING(sc->wmi_dev, ACPI_HP_WMI_CMI_GUID) 495 )) { 496 device_printf(dev, "HP CMI GUID detected\n"); 497 } 498 499 if (sc->has_cmi) { 500 sc->hpcmi_dev_t = make_dev(&hpcmi_cdevsw, 0, UID_ROOT, 501 GID_WHEEL, 0644, "hpcmi"); 502 sc->hpcmi_dev_t->si_drv1 = sc; 503 sc->hpcmi_open_pid = 0; 504 sc->hpcmi_bufptr = -1; 505 } 506 507 ACPI_SERIAL_BEGIN(hp); 508 509 sc->sysctl_ctx = device_get_sysctl_ctx(dev); 510 sc->sysctl_tree = device_get_sysctl_tree(dev); 511 for (int i = 0; acpi_hp_sysctls[i].name != NULL; ++i) { 512 arg = 0; 513 if ((!sc->has_notify && 514 (acpi_hp_sysctls[i].method == 515 ACPI_HP_METHOD_WLAN_ENABLE_IF_RADIO_ON || 516 acpi_hp_sysctls[i].method == 517 ACPI_HP_METHOD_WLAN_DISABLE_IF_RADIO_OFF || 518 acpi_hp_sysctls[i].method == 519 ACPI_HP_METHOD_BLUETOOTH_ENABLE_IF_RADIO_ON || 520 acpi_hp_sysctls[i].method == 521 ACPI_HP_METHOD_BLUETOOTH_DISABLE_IF_RADIO_OFF || 522 acpi_hp_sysctls[i].method == 523 ACPI_HP_METHOD_WWAN_ENABLE_IF_RADIO_ON || 524 acpi_hp_sysctls[i].method == 525 ACPI_HP_METHOD_WWAN_DISABLE_IF_RADIO_OFF)) || 526 (arg = acpi_hp_sysctl_get(sc, 527 acpi_hp_sysctls[i].method)) < 0) { 528 continue; 529 } 530 if (acpi_hp_sysctls[i].method == ACPI_HP_METHOD_WLAN_ON_AIR) { 531 sc->was_wlan_on_air = arg; 532 } 533 else if (acpi_hp_sysctls[i].method == 534 ACPI_HP_METHOD_BLUETOOTH_ON_AIR) { 535 sc->was_bluetooth_on_air = arg; 536 } 537 else if (acpi_hp_sysctls[i].method == 538 ACPI_HP_METHOD_WWAN_ON_AIR) { 539 sc->was_wwan_on_air = arg; 540 } 541 542 SYSCTL_ADD_PROC(sc->sysctl_ctx, 543 SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO, 544 acpi_hp_sysctls[i].name, acpi_hp_sysctls[i].access, 545 sc, i, acpi_hp_sysctl, "I", 546 acpi_hp_sysctls[i].description); 547 } 548 ACPI_SERIAL_END(hp); 549 550 return (0); 551} 552 553static int 554acpi_hp_detach(device_t dev) 555{
| 479 memset(sc->cmi_order, 0, sizeof(sc->cmi_order)); 480 acpi_sc = acpi_device_get_parent_softc(dev); 481 482 if (!(wmi_devclass = devclass_find ("acpi_wmi"))) { 483 device_printf(dev, "Couldn't find acpi_wmi devclass\n"); 484 return (EINVAL); 485 } 486 if (!(sc->wmi_dev = devclass_get_device(wmi_devclass, 0))) { 487 device_printf(dev, "Couldn't find acpi_wmi device\n"); 488 return (EINVAL); 489 } 490 if (!ACPI_WMI_PROVIDES_GUID_STRING(sc->wmi_dev, 491 ACPI_HP_WMI_BIOS_GUID)) { 492 device_printf(dev, 493 "WMI device does not provide the HP BIOS GUID\n"); 494 return (EINVAL); 495 } 496 if (ACPI_WMI_PROVIDES_GUID_STRING(sc->wmi_dev, 497 ACPI_HP_WMI_EVENT_GUID)) { 498 device_printf(dev, 499 "HP event GUID detected, installing event handler\n"); 500 if (ACPI_WMI_INSTALL_EVENT_HANDLER(sc->wmi_dev, 501 ACPI_HP_WMI_EVENT_GUID, acpi_hp_notify, dev)) { 502 device_printf(dev, 503 "Could not install notification handler!\n"); 504 } 505 else { 506 sc->has_notify = 1; 507 } 508 } 509 if ((sc->has_cmi = 510 ACPI_WMI_PROVIDES_GUID_STRING(sc->wmi_dev, ACPI_HP_WMI_CMI_GUID) 511 )) { 512 device_printf(dev, "HP CMI GUID detected\n"); 513 } 514 515 if (sc->has_cmi) { 516 sc->hpcmi_dev_t = make_dev(&hpcmi_cdevsw, 0, UID_ROOT, 517 GID_WHEEL, 0644, "hpcmi"); 518 sc->hpcmi_dev_t->si_drv1 = sc; 519 sc->hpcmi_open_pid = 0; 520 sc->hpcmi_bufptr = -1; 521 } 522 523 ACPI_SERIAL_BEGIN(hp); 524 525 sc->sysctl_ctx = device_get_sysctl_ctx(dev); 526 sc->sysctl_tree = device_get_sysctl_tree(dev); 527 for (int i = 0; acpi_hp_sysctls[i].name != NULL; ++i) { 528 arg = 0; 529 if ((!sc->has_notify && 530 (acpi_hp_sysctls[i].method == 531 ACPI_HP_METHOD_WLAN_ENABLE_IF_RADIO_ON || 532 acpi_hp_sysctls[i].method == 533 ACPI_HP_METHOD_WLAN_DISABLE_IF_RADIO_OFF || 534 acpi_hp_sysctls[i].method == 535 ACPI_HP_METHOD_BLUETOOTH_ENABLE_IF_RADIO_ON || 536 acpi_hp_sysctls[i].method == 537 ACPI_HP_METHOD_BLUETOOTH_DISABLE_IF_RADIO_OFF || 538 acpi_hp_sysctls[i].method == 539 ACPI_HP_METHOD_WWAN_ENABLE_IF_RADIO_ON || 540 acpi_hp_sysctls[i].method == 541 ACPI_HP_METHOD_WWAN_DISABLE_IF_RADIO_OFF)) || 542 (arg = acpi_hp_sysctl_get(sc, 543 acpi_hp_sysctls[i].method)) < 0) { 544 continue; 545 } 546 if (acpi_hp_sysctls[i].method == ACPI_HP_METHOD_WLAN_ON_AIR) { 547 sc->was_wlan_on_air = arg; 548 } 549 else if (acpi_hp_sysctls[i].method == 550 ACPI_HP_METHOD_BLUETOOTH_ON_AIR) { 551 sc->was_bluetooth_on_air = arg; 552 } 553 else if (acpi_hp_sysctls[i].method == 554 ACPI_HP_METHOD_WWAN_ON_AIR) { 555 sc->was_wwan_on_air = arg; 556 } 557 558 SYSCTL_ADD_PROC(sc->sysctl_ctx, 559 SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO, 560 acpi_hp_sysctls[i].name, acpi_hp_sysctls[i].access, 561 sc, i, acpi_hp_sysctl, "I", 562 acpi_hp_sysctls[i].description); 563 } 564 ACPI_SERIAL_END(hp); 565 566 return (0); 567} 568 569static int 570acpi_hp_detach(device_t dev) 571{
|
556 int ret;
| 572 int ret;
|
557 558 ACPI_FUNCTION_TRACE((char *)(uintptr_t) __func__); 559 struct acpi_hp_softc *sc = device_get_softc(dev); 560 if (sc->has_cmi && sc->hpcmi_open_pid != 0) { 561 ret = EBUSY; 562 } 563 else { 564 if (sc->has_notify) { 565 ACPI_WMI_REMOVE_EVENT_HANDLER(dev, 566 ACPI_HP_WMI_EVENT_GUID); 567 } 568 if (sc->hpcmi_bufptr != -1) { 569 sbuf_delete(&sc->hpcmi_sbuf); 570 sc->hpcmi_bufptr = -1; 571 } 572 sc->hpcmi_open_pid = 0; 573 destroy_dev(sc->hpcmi_dev_t); 574 ret = 0; 575 } 576 577 return (ret); 578} 579 580static int 581acpi_hp_sysctl(SYSCTL_HANDLER_ARGS) 582{
| 573 574 ACPI_FUNCTION_TRACE((char *)(uintptr_t) __func__); 575 struct acpi_hp_softc *sc = device_get_softc(dev); 576 if (sc->has_cmi && sc->hpcmi_open_pid != 0) { 577 ret = EBUSY; 578 } 579 else { 580 if (sc->has_notify) { 581 ACPI_WMI_REMOVE_EVENT_HANDLER(dev, 582 ACPI_HP_WMI_EVENT_GUID); 583 } 584 if (sc->hpcmi_bufptr != -1) { 585 sbuf_delete(&sc->hpcmi_sbuf); 586 sc->hpcmi_bufptr = -1; 587 } 588 sc->hpcmi_open_pid = 0; 589 destroy_dev(sc->hpcmi_dev_t); 590 ret = 0; 591 } 592 593 return (ret); 594} 595 596static int 597acpi_hp_sysctl(SYSCTL_HANDLER_ARGS) 598{
|
583 struct acpi_hp_softc *sc; 584 int arg; 585 int oldarg; 586 int error = 0; 587 int function; 588 int method;
| 599 struct acpi_hp_softc *sc; 600 int arg; 601 int oldarg; 602 int error = 0; 603 int function; 604 int method;
|
589 590 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); 591 592 sc = (struct acpi_hp_softc *)oidp->oid_arg1; 593 function = oidp->oid_arg2; 594 method = acpi_hp_sysctls[function].method; 595 596 ACPI_SERIAL_BEGIN(hp); 597 arg = acpi_hp_sysctl_get(sc, method); 598 oldarg = arg; 599 error = sysctl_handle_int(oidp, &arg, 0, req); 600 if (!error && req->newptr != NULL) { 601 error = acpi_hp_sysctl_set(sc, method, arg, oldarg); 602 } 603 ACPI_SERIAL_END(hp); 604 605 return (error); 606} 607 608static int 609acpi_hp_sysctl_get(struct acpi_hp_softc *sc, int method) 610{
| 605 606 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); 607 608 sc = (struct acpi_hp_softc *)oidp->oid_arg1; 609 function = oidp->oid_arg2; 610 method = acpi_hp_sysctls[function].method; 611 612 ACPI_SERIAL_BEGIN(hp); 613 arg = acpi_hp_sysctl_get(sc, method); 614 oldarg = arg; 615 error = sysctl_handle_int(oidp, &arg, 0, req); 616 if (!error && req->newptr != NULL) { 617 error = acpi_hp_sysctl_set(sc, method, arg, oldarg); 618 } 619 ACPI_SERIAL_END(hp); 620 621 return (error); 622} 623 624static int 625acpi_hp_sysctl_get(struct acpi_hp_softc *sc, int method) 626{
|
611 int val = 0;
| 627 int val = 0;
|
612 613 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); 614 ACPI_SERIAL_ASSERT(hp); 615 616 switch (method) { 617 case ACPI_HP_METHOD_WLAN_ENABLED: 618 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 619 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 620 val = ((val & HP_MASK_WLAN_ENABLED) != 0); 621 break; 622 case ACPI_HP_METHOD_WLAN_RADIO: 623 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 624 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 625 val = ((val & HP_MASK_WLAN_RADIO) != 0); 626 break; 627 case ACPI_HP_METHOD_WLAN_ON_AIR: 628 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 629 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 630 val = ((val & HP_MASK_WLAN_ON_AIR) != 0); 631 break; 632 case ACPI_HP_METHOD_WLAN_ENABLE_IF_RADIO_ON: 633 val = sc->wlan_enable_if_radio_on; 634 break; 635 case ACPI_HP_METHOD_WLAN_DISABLE_IF_RADIO_OFF: 636 val = sc->wlan_disable_if_radio_off; 637 break; 638 case ACPI_HP_METHOD_BLUETOOTH_ENABLED: 639 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 640 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 641 val = ((val & HP_MASK_BLUETOOTH_ENABLED) != 0); 642 break; 643 case ACPI_HP_METHOD_BLUETOOTH_RADIO: 644 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 645 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 646 val = ((val & HP_MASK_BLUETOOTH_RADIO) != 0); 647 break; 648 case ACPI_HP_METHOD_BLUETOOTH_ON_AIR: 649 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 650 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 651 val = ((val & HP_MASK_BLUETOOTH_ON_AIR) != 0); 652 break; 653 case ACPI_HP_METHOD_BLUETOOTH_ENABLE_IF_RADIO_ON: 654 val = sc->bluetooth_enable_if_radio_on; 655 break; 656 case ACPI_HP_METHOD_BLUETOOTH_DISABLE_IF_RADIO_OFF: 657 val = sc->bluetooth_disable_if_radio_off; 658 break; 659 case ACPI_HP_METHOD_WWAN_ENABLED: 660 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 661 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 662 val = ((val & HP_MASK_WWAN_ENABLED) != 0); 663 break; 664 case ACPI_HP_METHOD_WWAN_RADIO: 665 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 666 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 667 val = ((val & HP_MASK_WWAN_RADIO) != 0); 668 break; 669 case ACPI_HP_METHOD_WWAN_ON_AIR: 670 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 671 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 672 val = ((val & HP_MASK_WWAN_ON_AIR) != 0); 673 break; 674 case ACPI_HP_METHOD_WWAN_ENABLE_IF_RADIO_ON: 675 val = sc->wwan_enable_if_radio_on; 676 break; 677 case ACPI_HP_METHOD_WWAN_DISABLE_IF_RADIO_OFF: 678 val = sc->wwan_disable_if_radio_off; 679 break; 680 case ACPI_HP_METHOD_ALS: 681 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 682 ACPI_HP_WMI_ALS_COMMAND, 0, 0); 683 break; 684 case ACPI_HP_METHOD_DISPLAY: 685 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 686 ACPI_HP_WMI_DISPLAY_COMMAND, 0, 0); 687 break; 688 case ACPI_HP_METHOD_HDDTEMP: 689 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 690 ACPI_HP_WMI_HDDTEMP_COMMAND, 0, 0); 691 break; 692 case ACPI_HP_METHOD_DOCK: 693 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 694 ACPI_HP_WMI_DOCK_COMMAND, 0, 0); 695 break; 696 case ACPI_HP_METHOD_CMI_DETAIL: 697 val = sc->cmi_detail; 698 break;
| 628 629 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); 630 ACPI_SERIAL_ASSERT(hp); 631 632 switch (method) { 633 case ACPI_HP_METHOD_WLAN_ENABLED: 634 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 635 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 636 val = ((val & HP_MASK_WLAN_ENABLED) != 0); 637 break; 638 case ACPI_HP_METHOD_WLAN_RADIO: 639 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 640 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 641 val = ((val & HP_MASK_WLAN_RADIO) != 0); 642 break; 643 case ACPI_HP_METHOD_WLAN_ON_AIR: 644 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 645 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 646 val = ((val & HP_MASK_WLAN_ON_AIR) != 0); 647 break; 648 case ACPI_HP_METHOD_WLAN_ENABLE_IF_RADIO_ON: 649 val = sc->wlan_enable_if_radio_on; 650 break; 651 case ACPI_HP_METHOD_WLAN_DISABLE_IF_RADIO_OFF: 652 val = sc->wlan_disable_if_radio_off; 653 break; 654 case ACPI_HP_METHOD_BLUETOOTH_ENABLED: 655 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 656 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 657 val = ((val & HP_MASK_BLUETOOTH_ENABLED) != 0); 658 break; 659 case ACPI_HP_METHOD_BLUETOOTH_RADIO: 660 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 661 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 662 val = ((val & HP_MASK_BLUETOOTH_RADIO) != 0); 663 break; 664 case ACPI_HP_METHOD_BLUETOOTH_ON_AIR: 665 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 666 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 667 val = ((val & HP_MASK_BLUETOOTH_ON_AIR) != 0); 668 break; 669 case ACPI_HP_METHOD_BLUETOOTH_ENABLE_IF_RADIO_ON: 670 val = sc->bluetooth_enable_if_radio_on; 671 break; 672 case ACPI_HP_METHOD_BLUETOOTH_DISABLE_IF_RADIO_OFF: 673 val = sc->bluetooth_disable_if_radio_off; 674 break; 675 case ACPI_HP_METHOD_WWAN_ENABLED: 676 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 677 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 678 val = ((val & HP_MASK_WWAN_ENABLED) != 0); 679 break; 680 case ACPI_HP_METHOD_WWAN_RADIO: 681 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 682 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 683 val = ((val & HP_MASK_WWAN_RADIO) != 0); 684 break; 685 case ACPI_HP_METHOD_WWAN_ON_AIR: 686 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 687 ACPI_HP_WMI_WIRELESS_COMMAND, 0, 0); 688 val = ((val & HP_MASK_WWAN_ON_AIR) != 0); 689 break; 690 case ACPI_HP_METHOD_WWAN_ENABLE_IF_RADIO_ON: 691 val = sc->wwan_enable_if_radio_on; 692 break; 693 case ACPI_HP_METHOD_WWAN_DISABLE_IF_RADIO_OFF: 694 val = sc->wwan_disable_if_radio_off; 695 break; 696 case ACPI_HP_METHOD_ALS: 697 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 698 ACPI_HP_WMI_ALS_COMMAND, 0, 0); 699 break; 700 case ACPI_HP_METHOD_DISPLAY: 701 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 702 ACPI_HP_WMI_DISPLAY_COMMAND, 0, 0); 703 break; 704 case ACPI_HP_METHOD_HDDTEMP: 705 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 706 ACPI_HP_WMI_HDDTEMP_COMMAND, 0, 0); 707 break; 708 case ACPI_HP_METHOD_DOCK: 709 val = acpi_hp_exec_wmi_command(sc->wmi_dev, 710 ACPI_HP_WMI_DOCK_COMMAND, 0, 0); 711 break; 712 case ACPI_HP_METHOD_CMI_DETAIL: 713 val = sc->cmi_detail; 714 break;
|
| 715 case ACPI_HP_METHOD_VERBOSE: 716 val = sc->verbose; 717 break;
|
699 } 700 701 return (val); 702} 703 704static int 705acpi_hp_sysctl_set(struct acpi_hp_softc *sc, int method, int arg, int oldarg) 706{ 707 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); 708 ACPI_SERIAL_ASSERT(hp); 709
| 718 } 719 720 return (val); 721} 722 723static int 724acpi_hp_sysctl_set(struct acpi_hp_softc *sc, int method, int arg, int oldarg) 725{ 726 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); 727 ACPI_SERIAL_ASSERT(hp); 728
|
710 if (method != ACPI_HP_METHOD_CMI_DETAIL)
| 729 if (method != ACPI_HP_METHOD_CMI_DETAIL && 730 method != ACPI_HP_METHOD_VERBOSE)
|
711 arg = arg?1:0; 712 713 if (arg != oldarg) { 714 switch (method) { 715 case ACPI_HP_METHOD_WLAN_ENABLED: 716 return (acpi_hp_exec_wmi_command(sc->wmi_dev, 717 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 718 arg?0x101:0x100)); 719 case ACPI_HP_METHOD_WLAN_ENABLE_IF_RADIO_ON: 720 sc->wlan_enable_if_radio_on = arg; 721 acpi_hp_evaluate_auto_on_off(sc); 722 break; 723 case ACPI_HP_METHOD_WLAN_DISABLE_IF_RADIO_OFF: 724 sc->wlan_disable_if_radio_off = arg; 725 acpi_hp_evaluate_auto_on_off(sc); 726 break; 727 case ACPI_HP_METHOD_BLUETOOTH_ENABLED: 728 return (acpi_hp_exec_wmi_command(sc->wmi_dev, 729 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 730 arg?0x202:0x200)); 731 case ACPI_HP_METHOD_BLUETOOTH_ENABLE_IF_RADIO_ON: 732 sc->bluetooth_enable_if_radio_on = arg; 733 acpi_hp_evaluate_auto_on_off(sc); 734 break; 735 case ACPI_HP_METHOD_BLUETOOTH_DISABLE_IF_RADIO_OFF: 736 sc->bluetooth_disable_if_radio_off = arg?1:0; 737 acpi_hp_evaluate_auto_on_off(sc); 738 break; 739 case ACPI_HP_METHOD_WWAN_ENABLED: 740 return (acpi_hp_exec_wmi_command(sc->wmi_dev, 741 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 742 arg?0x404:0x400)); 743 case ACPI_HP_METHOD_WWAN_ENABLE_IF_RADIO_ON: 744 sc->wwan_enable_if_radio_on = arg?1:0; 745 acpi_hp_evaluate_auto_on_off(sc); 746 break; 747 case ACPI_HP_METHOD_WWAN_DISABLE_IF_RADIO_OFF: 748 sc->wwan_disable_if_radio_off = arg?1:0; 749 acpi_hp_evaluate_auto_on_off(sc); 750 break; 751 case ACPI_HP_METHOD_ALS: 752 return (acpi_hp_exec_wmi_command(sc->wmi_dev, 753 ACPI_HP_WMI_ALS_COMMAND, 1, 754 arg?1:0)); 755 case ACPI_HP_METHOD_CMI_DETAIL: 756 sc->cmi_detail = arg; 757 if ((arg & ACPI_HP_CMI_DETAIL_SHOW_MAX_INSTANCE) != 758 (oldarg & ACPI_HP_CMI_DETAIL_SHOW_MAX_INSTANCE)) { 759 sc->cmi_order_size = -1; 760 } 761 break;
| 731 arg = arg?1:0; 732 733 if (arg != oldarg) { 734 switch (method) { 735 case ACPI_HP_METHOD_WLAN_ENABLED: 736 return (acpi_hp_exec_wmi_command(sc->wmi_dev, 737 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 738 arg?0x101:0x100)); 739 case ACPI_HP_METHOD_WLAN_ENABLE_IF_RADIO_ON: 740 sc->wlan_enable_if_radio_on = arg; 741 acpi_hp_evaluate_auto_on_off(sc); 742 break; 743 case ACPI_HP_METHOD_WLAN_DISABLE_IF_RADIO_OFF: 744 sc->wlan_disable_if_radio_off = arg; 745 acpi_hp_evaluate_auto_on_off(sc); 746 break; 747 case ACPI_HP_METHOD_BLUETOOTH_ENABLED: 748 return (acpi_hp_exec_wmi_command(sc->wmi_dev, 749 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 750 arg?0x202:0x200)); 751 case ACPI_HP_METHOD_BLUETOOTH_ENABLE_IF_RADIO_ON: 752 sc->bluetooth_enable_if_radio_on = arg; 753 acpi_hp_evaluate_auto_on_off(sc); 754 break; 755 case ACPI_HP_METHOD_BLUETOOTH_DISABLE_IF_RADIO_OFF: 756 sc->bluetooth_disable_if_radio_off = arg?1:0; 757 acpi_hp_evaluate_auto_on_off(sc); 758 break; 759 case ACPI_HP_METHOD_WWAN_ENABLED: 760 return (acpi_hp_exec_wmi_command(sc->wmi_dev, 761 ACPI_HP_WMI_WIRELESS_COMMAND, 1, 762 arg?0x404:0x400)); 763 case ACPI_HP_METHOD_WWAN_ENABLE_IF_RADIO_ON: 764 sc->wwan_enable_if_radio_on = arg?1:0; 765 acpi_hp_evaluate_auto_on_off(sc); 766 break; 767 case ACPI_HP_METHOD_WWAN_DISABLE_IF_RADIO_OFF: 768 sc->wwan_disable_if_radio_off = arg?1:0; 769 acpi_hp_evaluate_auto_on_off(sc); 770 break; 771 case ACPI_HP_METHOD_ALS: 772 return (acpi_hp_exec_wmi_command(sc->wmi_dev, 773 ACPI_HP_WMI_ALS_COMMAND, 1, 774 arg?1:0)); 775 case ACPI_HP_METHOD_CMI_DETAIL: 776 sc->cmi_detail = arg; 777 if ((arg & ACPI_HP_CMI_DETAIL_SHOW_MAX_INSTANCE) != 778 (oldarg & ACPI_HP_CMI_DETAIL_SHOW_MAX_INSTANCE)) { 779 sc->cmi_order_size = -1; 780 } 781 break;
|
| 782 case ACPI_HP_METHOD_VERBOSE: 783 sc->verbose = arg; 784 break;
|
762 } 763 } 764 765 return (0); 766} 767 768static __inline void 769acpi_hp_free_buffer(ACPI_BUFFER* buf) { 770 if (buf && buf->Pointer) { 771 AcpiOsFree(buf->Pointer); 772 } 773} 774 775static void 776acpi_hp_notify(ACPI_HANDLE h, UINT32 notify, void *context) 777{ 778 device_t dev = context; 779 ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, notify); 780 781 struct acpi_hp_softc *sc = device_get_softc(dev); 782 ACPI_BUFFER response = { ACPI_ALLOCATE_BUFFER, NULL }; 783 ACPI_OBJECT *obj; 784 ACPI_WMI_GET_EVENT_DATA(sc->wmi_dev, notify, &response); 785 obj = (ACPI_OBJECT*) response.Pointer; 786 if (obj && obj->Type == ACPI_TYPE_BUFFER && obj->Buffer.Length == 8) { 787 if (*((UINT8 *) obj->Buffer.Pointer) == 0x5) { 788 acpi_hp_evaluate_auto_on_off(sc); 789 } 790 } 791 acpi_hp_free_buffer(&response); 792} 793 794static int 795acpi_hp_exec_wmi_command(device_t wmi_dev, int command, int is_write, int val) 796{
| 785 } 786 } 787 788 return (0); 789} 790 791static __inline void 792acpi_hp_free_buffer(ACPI_BUFFER* buf) { 793 if (buf && buf->Pointer) { 794 AcpiOsFree(buf->Pointer); 795 } 796} 797 798static void 799acpi_hp_notify(ACPI_HANDLE h, UINT32 notify, void *context) 800{ 801 device_t dev = context; 802 ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, notify); 803 804 struct acpi_hp_softc *sc = device_get_softc(dev); 805 ACPI_BUFFER response = { ACPI_ALLOCATE_BUFFER, NULL }; 806 ACPI_OBJECT *obj; 807 ACPI_WMI_GET_EVENT_DATA(sc->wmi_dev, notify, &response); 808 obj = (ACPI_OBJECT*) response.Pointer; 809 if (obj && obj->Type == ACPI_TYPE_BUFFER && obj->Buffer.Length == 8) { 810 if (*((UINT8 *) obj->Buffer.Pointer) == 0x5) { 811 acpi_hp_evaluate_auto_on_off(sc); 812 } 813 } 814 acpi_hp_free_buffer(&response); 815} 816 817static int 818acpi_hp_exec_wmi_command(device_t wmi_dev, int command, int is_write, int val) 819{
|
797 UINT32 params[5] = { 0x55434553, 798 is_write?2:1, 799 command, 800 is_write?4:0, 801 val}; 802 UINT32* result; 803 ACPI_OBJECT *obj; 804 ACPI_BUFFER in = { sizeof(params), ¶ms }; 805 ACPI_BUFFER out = { ACPI_ALLOCATE_BUFFER, NULL };
| 820 UINT32 params[5] = { 0x55434553, 821 is_write?2:1, 822 command, 823 is_write?4:0, 824 val}; 825 UINT32* result; 826 ACPI_OBJECT *obj; 827 ACPI_BUFFER in = { sizeof(params), ¶ms }; 828 ACPI_BUFFER out = { ACPI_ALLOCATE_BUFFER, NULL };
|
806 int retval; 807 808 if (ACPI_FAILURE(ACPI_WMI_EVALUATE_CALL(wmi_dev, ACPI_HP_WMI_BIOS_GUID, 809 0, 0x3, &in, &out))) { 810 acpi_hp_free_buffer(&out); 811 return (-EINVAL); 812 } 813 obj = out.Pointer; 814 if (!obj || obj->Type != ACPI_TYPE_BUFFER) { 815 acpi_hp_free_buffer(&out); 816 return (-EINVAL); 817 } 818 result = (UINT32*) obj->Buffer.Pointer; 819 retval = result[2]; 820 if (result[1] > 0) { 821 retval = result[1]; 822 } 823 acpi_hp_free_buffer(&out); 824 825 return (retval); 826} 827 828static __inline char* 829acpi_hp_get_string_from_object(ACPI_OBJECT* obj, char* dst, size_t size) {
| 829 int retval; 830 831 if (ACPI_FAILURE(ACPI_WMI_EVALUATE_CALL(wmi_dev, ACPI_HP_WMI_BIOS_GUID, 832 0, 0x3, &in, &out))) { 833 acpi_hp_free_buffer(&out); 834 return (-EINVAL); 835 } 836 obj = out.Pointer; 837 if (!obj || obj->Type != ACPI_TYPE_BUFFER) { 838 acpi_hp_free_buffer(&out); 839 return (-EINVAL); 840 } 841 result = (UINT32*) obj->Buffer.Pointer; 842 retval = result[2]; 843 if (result[1] > 0) { 844 retval = result[1]; 845 } 846 acpi_hp_free_buffer(&out); 847 848 return (retval); 849} 850 851static __inline char* 852acpi_hp_get_string_from_object(ACPI_OBJECT* obj, char* dst, size_t size) {
|
830 int length;
| 853 int length; 854
|
831 dst[0] = 0; 832 if (obj->Type == ACPI_TYPE_STRING) { 833 length = obj->String.Length+1; 834 if (length > size) { 835 length = size - 1; 836 } 837 strlcpy(dst, obj->String.Pointer, length); 838 acpi_hp_hex_decode(dst); 839 } 840 841 return (dst); 842} 843 844 845/* 846 * Read BIOS Setting block in instance "instance". 847 * The block returned is ACPI_TYPE_PACKAGE which should contain the following 848 * elements: 849 * Index Meaning
| 855 dst[0] = 0; 856 if (obj->Type == ACPI_TYPE_STRING) { 857 length = obj->String.Length+1; 858 if (length > size) { 859 length = size - 1; 860 } 861 strlcpy(dst, obj->String.Pointer, length); 862 acpi_hp_hex_decode(dst); 863 } 864 865 return (dst); 866} 867 868 869/* 870 * Read BIOS Setting block in instance "instance". 871 * The block returned is ACPI_TYPE_PACKAGE which should contain the following 872 * elements: 873 * Index Meaning
|
850 * 0 Setting Name [string] 851 * 1 Value (comma separated, asterisk marks the current value) [string] 852 * 2 Path within the bios hierarchy [string] 853 * 3 IsReadOnly [int] 854 * 4 DisplayInUI [int] 855 * 5 RequiresPhysicalPresence [int] 856 * 6 Sequence for ordering within the bios settings (absolute) [int] 857 * 7 Length of prerequisites array [int] 858 * 8 Prerequisite1 [string] 859 * 9 Prerequisite2 [string] 860 * 10 Prerequisite3 [string] 861 * 11 Current value (in case of enum) [string] / Array length [int] 862 * 12 Enum length [int] / Array values 863 * 13ff Enum value at index x [string]
| 874 * 0 Setting Name [string] 875 * 1 Value (comma separated, asterisk marks the current value) [string] 876 * 2 Path within the bios hierarchy [string] 877 * 3 IsReadOnly [int] 878 * 4 DisplayInUI [int] 879 * 5 RequiresPhysicalPresence [int] 880 * 6 Sequence for ordering within the bios settings (absolute) [int] 881 * 7 Length of prerequisites array [int] 882 * 8..8+[7] PrerequisiteN [string] 883 * 9+[7] Current value (in case of enum) [string] / Array length [int] 884 * 10+[7] Enum length [int] / Array values 885 * 11+[7]ff Enum value at index x [string]
|
864 */ 865static int 866acpi_hp_get_cmi_block(device_t wmi_dev, const char* guid, UINT8 instance, 867 char* outbuf, size_t outsize, UINT32* sequence, int detail) 868{
| 886 */ 887static int 888acpi_hp_get_cmi_block(device_t wmi_dev, const char* guid, UINT8 instance, 889 char* outbuf, size_t outsize, UINT32* sequence, int detail) 890{
|
869 ACPI_OBJECT *obj; 870 ACPI_BUFFER out = { ACPI_ALLOCATE_BUFFER, NULL }; 871 int i; 872 int outlen; 873 int size = 255; 874 int has_enums = 0; 875 char string_buffer[size]; 876 int enumbase;
| 891 ACPI_OBJECT *obj; 892 ACPI_BUFFER out = { ACPI_ALLOCATE_BUFFER, NULL }; 893 int i; 894 int outlen; 895 int size = 255; 896 int has_enums = 0; 897 int valuebase = 0; 898 char string_buffer[size]; 899 int enumbase;
|
877 878 outlen = 0; 879 outbuf[0] = 0; 880 if (ACPI_FAILURE(ACPI_WMI_GET_BLOCK(wmi_dev, guid, instance, &out))) { 881 acpi_hp_free_buffer(&out); 882 return (-EINVAL); 883 } 884 obj = out.Pointer; 885 if (!obj && obj->Type != ACPI_TYPE_PACKAGE) { 886 acpi_hp_free_buffer(&out); 887 return (-EINVAL); 888 } 889
| 900 901 outlen = 0; 902 outbuf[0] = 0; 903 if (ACPI_FAILURE(ACPI_WMI_GET_BLOCK(wmi_dev, guid, instance, &out))) { 904 acpi_hp_free_buffer(&out); 905 return (-EINVAL); 906 } 907 obj = out.Pointer; 908 if (!obj && obj->Type != ACPI_TYPE_PACKAGE) { 909 acpi_hp_free_buffer(&out); 910 return (-EINVAL); 911 } 912
|
| 913 if (obj->Package.Count >= 8 && 914 obj->Package.Elements[7].Type == ACPI_TYPE_INTEGER) { 915 valuebase = 8 + obj->Package.Elements[7].Integer.Value; 916 } 917
|
890 /* check if this matches our expectations based on limited knowledge */
| 918 /* check if this matches our expectations based on limited knowledge */
|
891 if (obj->Package.Count >= 13 &&
| 919 if (valuebase > 7 && obj->Package.Count > valuebase + 1 &&
|
892 obj->Package.Elements[0].Type == ACPI_TYPE_STRING && 893 obj->Package.Elements[1].Type == ACPI_TYPE_STRING && 894 obj->Package.Elements[2].Type == ACPI_TYPE_STRING && 895 obj->Package.Elements[3].Type == ACPI_TYPE_INTEGER && 896 obj->Package.Elements[4].Type == ACPI_TYPE_INTEGER && 897 obj->Package.Elements[5].Type == ACPI_TYPE_INTEGER && 898 obj->Package.Elements[6].Type == ACPI_TYPE_INTEGER &&
| 920 obj->Package.Elements[0].Type == ACPI_TYPE_STRING && 921 obj->Package.Elements[1].Type == ACPI_TYPE_STRING && 922 obj->Package.Elements[2].Type == ACPI_TYPE_STRING && 923 obj->Package.Elements[3].Type == ACPI_TYPE_INTEGER && 924 obj->Package.Elements[4].Type == ACPI_TYPE_INTEGER && 925 obj->Package.Elements[5].Type == ACPI_TYPE_INTEGER && 926 obj->Package.Elements[6].Type == ACPI_TYPE_INTEGER &&
|
899 obj->Package.Elements[7].Type == ACPI_TYPE_INTEGER && 900 obj->Package.Elements[8].Type == ACPI_TYPE_STRING && 901 obj->Package.Elements[9].Type == ACPI_TYPE_STRING && 902 obj->Package.Elements[10].Type == ACPI_TYPE_STRING && 903 ((obj->Package.Elements[11].Type == ACPI_TYPE_STRING && 904 obj->Package.Elements[12].Type == ACPI_TYPE_INTEGER && 905 obj->Package.Count >= 906 13+obj->Package.Elements[12].Integer.Value) || 907 (obj->Package.Elements[11].Type == ACPI_TYPE_INTEGER && 908 obj->Package.Count >= 909 12+obj->Package.Elements[11].Integer.Value)) 910 ) { 911 enumbase = obj->Package.Elements[11].Type == ACPI_TYPE_STRING? 912 12:11;
| 927 obj->Package.Elements[valuebase].Type == ACPI_TYPE_STRING && 928 obj->Package.Elements[valuebase+1].Type == ACPI_TYPE_INTEGER && 929 obj->Package.Count > valuebase + 930 obj->Package.Elements[valuebase+1].Integer.Value 931 ) { 932 enumbase = valuebase + 1;
|
913 if (detail & ACPI_HP_CMI_DETAIL_PATHS) { 914 strlcat(outbuf, acpi_hp_get_string_from_object( 915 &obj->Package.Elements[2], string_buffer, size), 916 outsize); 917 outlen += 48; 918 while (strlen(outbuf) < outlen) 919 strlcat(outbuf, " ", outsize); 920 } 921 strlcat(outbuf, acpi_hp_get_string_from_object( 922 &obj->Package.Elements[0], string_buffer, size), 923 outsize); 924 outlen += 43; 925 while (strlen(outbuf) < outlen) 926 strlcat(outbuf, " ", outsize);
| 933 if (detail & ACPI_HP_CMI_DETAIL_PATHS) { 934 strlcat(outbuf, acpi_hp_get_string_from_object( 935 &obj->Package.Elements[2], string_buffer, size), 936 outsize); 937 outlen += 48; 938 while (strlen(outbuf) < outlen) 939 strlcat(outbuf, " ", outsize); 940 } 941 strlcat(outbuf, acpi_hp_get_string_from_object( 942 &obj->Package.Elements[0], string_buffer, size), 943 outsize); 944 outlen += 43; 945 while (strlen(outbuf) < outlen) 946 strlcat(outbuf, " ", outsize);
|
927 if (enumbase == 12) 928 strlcat(outbuf, acpi_hp_get_string_from_object( 929 &obj->Package.Elements[11], 930 string_buffer, size), 931 outsize);
| 947 strlcat(outbuf, acpi_hp_get_string_from_object( 948 &obj->Package.Elements[valuebase], string_buffer, 949 size), 950 outsize);
|
932 outlen += 21; 933 while (strlen(outbuf) < outlen) 934 strlcat(outbuf, " ", outsize); 935 for (i = 0; i < strlen(outbuf); ++i) 936 if (outbuf[i] == '\\') 937 outbuf[i] = '/'; 938 if (detail & ACPI_HP_CMI_DETAIL_ENUMS) {
| 951 outlen += 21; 952 while (strlen(outbuf) < outlen) 953 strlcat(outbuf, " ", outsize); 954 for (i = 0; i < strlen(outbuf); ++i) 955 if (outbuf[i] == '\\') 956 outbuf[i] = '/'; 957 if (detail & ACPI_HP_CMI_DETAIL_ENUMS) {
|
939 for (i = enumbase+1; i < enumbase + 1 +
| 958 for (i = enumbase + 1; i < enumbase + 1 +
|
940 obj->Package.Elements[enumbase].Integer.Value; 941 ++i) { 942 acpi_hp_get_string_from_object( 943 &obj->Package.Elements[i], string_buffer, 944 size); 945 if (strlen(string_buffer) > 1 || 946 (strlen(string_buffer) == 1 && 947 string_buffer[0] != ' ')) { 948 if (has_enums) 949 strlcat(outbuf, "/", outsize); 950 else 951 strlcat(outbuf, " (", outsize); 952 strlcat(outbuf, string_buffer, outsize); 953 has_enums = 1; 954 } 955 } 956 } 957 if (has_enums) 958 strlcat(outbuf, ")", outsize); 959 if (detail & ACPI_HP_CMI_DETAIL_FLAGS) { 960 strlcat(outbuf, obj->Package.Elements[3].Integer.Value? 961 " [ReadOnly]":"", outsize); 962 strlcat(outbuf, obj->Package.Elements[4].Integer.Value? 963 "":" [NOUI]", outsize); 964 strlcat(outbuf, obj->Package.Elements[5].Integer.Value? 965 " [RPP]":"", outsize); 966 } 967 *sequence = (UINT32) obj->Package.Elements[6].Integer.Value; 968 } 969 acpi_hp_free_buffer(&out); 970 971 return (0); 972} 973 974 975 976/* 977 * Convert given two digit hex string (hexin) to an UINT8 referenced 978 * by byteout. 979 * Return != 0 if the was a problem (invalid input) 980 */ 981static __inline int acpi_hp_hex_to_int(const UINT8 *hexin, UINT8 *byteout) 982{
| 959 obj->Package.Elements[enumbase].Integer.Value; 960 ++i) { 961 acpi_hp_get_string_from_object( 962 &obj->Package.Elements[i], string_buffer, 963 size); 964 if (strlen(string_buffer) > 1 || 965 (strlen(string_buffer) == 1 && 966 string_buffer[0] != ' ')) { 967 if (has_enums) 968 strlcat(outbuf, "/", outsize); 969 else 970 strlcat(outbuf, " (", outsize); 971 strlcat(outbuf, string_buffer, outsize); 972 has_enums = 1; 973 } 974 } 975 } 976 if (has_enums) 977 strlcat(outbuf, ")", outsize); 978 if (detail & ACPI_HP_CMI_DETAIL_FLAGS) { 979 strlcat(outbuf, obj->Package.Elements[3].Integer.Value? 980 " [ReadOnly]":"", outsize); 981 strlcat(outbuf, obj->Package.Elements[4].Integer.Value? 982 "":" [NOUI]", outsize); 983 strlcat(outbuf, obj->Package.Elements[5].Integer.Value? 984 " [RPP]":"", outsize); 985 } 986 *sequence = (UINT32) obj->Package.Elements[6].Integer.Value; 987 } 988 acpi_hp_free_buffer(&out); 989 990 return (0); 991} 992 993 994 995/* 996 * Convert given two digit hex string (hexin) to an UINT8 referenced 997 * by byteout. 998 * Return != 0 if the was a problem (invalid input) 999 */ 1000static __inline int acpi_hp_hex_to_int(const UINT8 *hexin, UINT8 *byteout) 1001{
|
983 unsigned int hi; 984 unsigned int lo;
| 1002 unsigned int hi; 1003 unsigned int lo;
|
985 986 hi = hexin[0]; 987 lo = hexin[1]; 988 if ('0' <= hi && hi <= '9') 989 hi -= '0'; 990 else if ('A' <= hi && hi <= 'F') 991 hi -= ('A' - 10); 992 else if ('a' <= hi && hi <= 'f') 993 hi -= ('a' - 10); 994 else 995 return (1); 996 if ('0' <= lo && lo <= '9') 997 lo -= '0'; 998 else if ('A' <= lo && lo <= 'F') 999 lo -= ('A' - 10); 1000 else if ('a' <= lo && lo <= 'f') 1001 lo -= ('a' - 10); 1002 else 1003 return (1); 1004 *byteout = (hi << 4) + lo; 1005 1006 return (0); 1007} 1008 1009 1010static void 1011acpi_hp_hex_decode(char* buffer) 1012{
| 1004 1005 hi = hexin[0]; 1006 lo = hexin[1]; 1007 if ('0' <= hi && hi <= '9') 1008 hi -= '0'; 1009 else if ('A' <= hi && hi <= 'F') 1010 hi -= ('A' - 10); 1011 else if ('a' <= hi && hi <= 'f') 1012 hi -= ('a' - 10); 1013 else 1014 return (1); 1015 if ('0' <= lo && lo <= '9') 1016 lo -= '0'; 1017 else if ('A' <= lo && lo <= 'F') 1018 lo -= ('A' - 10); 1019 else if ('a' <= lo && lo <= 'f') 1020 lo -= ('a' - 10); 1021 else 1022 return (1); 1023 *byteout = (hi << 4) + lo; 1024 1025 return (0); 1026} 1027 1028 1029static void 1030acpi_hp_hex_decode(char* buffer) 1031{
|
1013 int i; 1014 int length = strlen(buffer); 1015 UINT8 *uin; 1016 UINT8 uout;
| 1032 int i; 1033 int length = strlen(buffer); 1034 UINT8 *uin; 1035 UINT8 uout;
|
1017 1018 if (((int)length/2)*2 == length || length < 10) return; 1019 1020 for (i = 0; i<length; ++i) { 1021 if (!((i+1)%3)) { 1022 if (buffer[i] != ' ') 1023 return; 1024 } 1025 else 1026 if (!((buffer[i] >= '0' && buffer[i] <= '9') || 1027 (buffer[i] >= 'A' && buffer[i] <= 'F'))) 1028 return; 1029 } 1030 1031 for (i = 0; i<length; i += 3) { 1032 uin = &buffer[i]; 1033 uout = 0; 1034 acpi_hp_hex_to_int(uin, &uout); 1035 buffer[i/3] = (char) uout; 1036 } 1037 buffer[(length+1)/3] = 0; 1038} 1039 1040 1041/* 1042 * open hpcmi device 1043 */ 1044static int 1045acpi_hp_hpcmi_open(struct cdev* dev, int flags, int mode, struct thread *td) 1046{
| 1036 1037 if (((int)length/2)*2 == length || length < 10) return; 1038 1039 for (i = 0; i<length; ++i) { 1040 if (!((i+1)%3)) { 1041 if (buffer[i] != ' ') 1042 return; 1043 } 1044 else 1045 if (!((buffer[i] >= '0' && buffer[i] <= '9') || 1046 (buffer[i] >= 'A' && buffer[i] <= 'F'))) 1047 return; 1048 } 1049 1050 for (i = 0; i<length; i += 3) { 1051 uin = &buffer[i]; 1052 uout = 0; 1053 acpi_hp_hex_to_int(uin, &uout); 1054 buffer[i/3] = (char) uout; 1055 } 1056 buffer[(length+1)/3] = 0; 1057} 1058 1059 1060/* 1061 * open hpcmi device 1062 */ 1063static int 1064acpi_hp_hpcmi_open(struct cdev* dev, int flags, int mode, struct thread *td) 1065{
|
1047 struct acpi_hp_softc *sc; 1048 int ret;
| 1066 struct acpi_hp_softc *sc; 1067 int ret;
|
1049 1050 if (dev == NULL || dev->si_drv1 == NULL) 1051 return (EBADF); 1052 sc = dev->si_drv1; 1053 1054 ACPI_SERIAL_BEGIN(hp); 1055 if (sc->hpcmi_open_pid != 0) { 1056 ret = EBUSY; 1057 } 1058 else { 1059 if (sbuf_new(&sc->hpcmi_sbuf, NULL, 4096, SBUF_AUTOEXTEND) 1060 == NULL) { 1061 ret = ENXIO; 1062 } else { 1063 sc->hpcmi_open_pid = td->td_proc->p_pid; 1064 sc->hpcmi_bufptr = 0; 1065 ret = 0; 1066 } 1067 } 1068 ACPI_SERIAL_END(hp); 1069 1070 return (ret); 1071} 1072 1073/* 1074 * close hpcmi device 1075 */ 1076static int 1077acpi_hp_hpcmi_close(struct cdev* dev, int flags, int mode, struct thread *td) 1078{
| 1068 1069 if (dev == NULL || dev->si_drv1 == NULL) 1070 return (EBADF); 1071 sc = dev->si_drv1; 1072 1073 ACPI_SERIAL_BEGIN(hp); 1074 if (sc->hpcmi_open_pid != 0) { 1075 ret = EBUSY; 1076 } 1077 else { 1078 if (sbuf_new(&sc->hpcmi_sbuf, NULL, 4096, SBUF_AUTOEXTEND) 1079 == NULL) { 1080 ret = ENXIO; 1081 } else { 1082 sc->hpcmi_open_pid = td->td_proc->p_pid; 1083 sc->hpcmi_bufptr = 0; 1084 ret = 0; 1085 } 1086 } 1087 ACPI_SERIAL_END(hp); 1088 1089 return (ret); 1090} 1091 1092/* 1093 * close hpcmi device 1094 */ 1095static int 1096acpi_hp_hpcmi_close(struct cdev* dev, int flags, int mode, struct thread *td) 1097{
|
1079 struct acpi_hp_softc *sc; 1080 int ret;
| 1098 struct acpi_hp_softc *sc; 1099 int ret;
|
1081 1082 if (dev == NULL || dev->si_drv1 == NULL) 1083 return (EBADF); 1084 sc = dev->si_drv1; 1085 1086 ACPI_SERIAL_BEGIN(hp); 1087 if (sc->hpcmi_open_pid == 0) { 1088 ret = EBADF; 1089 } 1090 else { 1091 if (sc->hpcmi_bufptr != -1) { 1092 sbuf_delete(&sc->hpcmi_sbuf); 1093 sc->hpcmi_bufptr = -1; 1094 } 1095 sc->hpcmi_open_pid = 0; 1096 ret = 0; 1097 } 1098 ACPI_SERIAL_END(hp); 1099 1100 return (ret); 1101} 1102 1103/* 1104 * Read from hpcmi bios information 1105 */ 1106static int 1107acpi_hp_hpcmi_read(struct cdev *dev, struct uio *buf, int flag) 1108{
| 1100 1101 if (dev == NULL || dev->si_drv1 == NULL) 1102 return (EBADF); 1103 sc = dev->si_drv1; 1104 1105 ACPI_SERIAL_BEGIN(hp); 1106 if (sc->hpcmi_open_pid == 0) { 1107 ret = EBADF; 1108 } 1109 else { 1110 if (sc->hpcmi_bufptr != -1) { 1111 sbuf_delete(&sc->hpcmi_sbuf); 1112 sc->hpcmi_bufptr = -1; 1113 } 1114 sc->hpcmi_open_pid = 0; 1115 ret = 0; 1116 } 1117 ACPI_SERIAL_END(hp); 1118 1119 return (ret); 1120} 1121 1122/* 1123 * Read from hpcmi bios information 1124 */ 1125static int 1126acpi_hp_hpcmi_read(struct cdev *dev, struct uio *buf, int flag) 1127{
|
1109 struct acpi_hp_softc *sc; 1110 int pos, i, l, ret; 1111 UINT8 instance; 1112 UINT8 maxInstance; 1113 UINT32 sequence; 1114 int linesize = 1025; 1115 char line[linesize];
| 1128 struct acpi_hp_softc *sc; 1129 int pos, i, l, ret; 1130 UINT8 instance; 1131 UINT8 maxInstance; 1132 UINT32 sequence; 1133 int linesize = 1025; 1134 char line[linesize];
|
1116 1117 if (dev == NULL || dev->si_drv1 == NULL) 1118 return (EBADF); 1119 sc = dev->si_drv1; 1120 1121 ACPI_SERIAL_BEGIN(hp); 1122 if (sc->hpcmi_open_pid != buf->uio_td->td_proc->p_pid 1123 || sc->hpcmi_bufptr == -1) { 1124 ret = EBADF; 1125 } 1126 else { 1127 if (!sbuf_done(&sc->hpcmi_sbuf)) { 1128 if (sc->cmi_order_size < 0) { 1129 maxInstance = sc->has_cmi; 1130 if (!(sc->cmi_detail & 1131 ACPI_HP_CMI_DETAIL_SHOW_MAX_INSTANCE) && 1132 maxInstance > 0) { 1133 maxInstance--; 1134 } 1135 sc->cmi_order_size = 0; 1136 for (instance = 0; instance < maxInstance; 1137 ++instance) { 1138 if (acpi_hp_get_cmi_block(sc->wmi_dev, 1139 ACPI_HP_WMI_CMI_GUID, instance, 1140 line, linesize, &sequence, 1141 sc->cmi_detail)) { 1142 instance = maxInstance; 1143 } 1144 else { 1145 pos = sc->cmi_order_size; 1146 for (i=0; 1147 i<sc->cmi_order_size && i<127; 1148 ++i) { 1149 if (sc->cmi_order[i].sequence > sequence) { 1150 pos = i; 1151 break; 1152 } 1153 } 1154 for (i=sc->cmi_order_size; 1155 i>pos; 1156 --i) { 1157 sc->cmi_order[i].sequence = 1158 sc->cmi_order[i-1].sequence; 1159 sc->cmi_order[i].instance = 1160 sc->cmi_order[i-1].instance; 1161 } 1162 sc->cmi_order[pos].sequence = 1163 sequence; 1164 sc->cmi_order[pos].instance = 1165 instance; 1166 sc->cmi_order_size++; 1167 } 1168 } 1169 } 1170 for (i=0; i<sc->cmi_order_size; ++i) { 1171 if (!acpi_hp_get_cmi_block(sc->wmi_dev, 1172 ACPI_HP_WMI_CMI_GUID, 1173 sc->cmi_order[i].instance, line, linesize, 1174 &sequence, sc->cmi_detail)) { 1175 sbuf_printf(&sc->hpcmi_sbuf, "%s\n", line); 1176 } 1177 } 1178 sbuf_finish(&sc->hpcmi_sbuf); 1179 } 1180 if (sbuf_len(&sc->hpcmi_sbuf) <= 0) { 1181 sbuf_delete(&sc->hpcmi_sbuf); 1182 sc->hpcmi_bufptr = -1; 1183 sc->hpcmi_open_pid = 0; 1184 ret = ENOMEM; 1185 } else { 1186 l = min(buf->uio_resid, sbuf_len(&sc->hpcmi_sbuf) - 1187 sc->hpcmi_bufptr); 1188 ret = (l > 0)?uiomove(sbuf_data(&sc->hpcmi_sbuf) + 1189 sc->hpcmi_bufptr, l, buf) : 0; 1190 sc->hpcmi_bufptr += l; 1191 } 1192 } 1193 ACPI_SERIAL_END(hp); 1194 1195 return (ret); 1196}
| 1135 1136 if (dev == NULL || dev->si_drv1 == NULL) 1137 return (EBADF); 1138 sc = dev->si_drv1; 1139 1140 ACPI_SERIAL_BEGIN(hp); 1141 if (sc->hpcmi_open_pid != buf->uio_td->td_proc->p_pid 1142 || sc->hpcmi_bufptr == -1) { 1143 ret = EBADF; 1144 } 1145 else { 1146 if (!sbuf_done(&sc->hpcmi_sbuf)) { 1147 if (sc->cmi_order_size < 0) { 1148 maxInstance = sc->has_cmi; 1149 if (!(sc->cmi_detail & 1150 ACPI_HP_CMI_DETAIL_SHOW_MAX_INSTANCE) && 1151 maxInstance > 0) { 1152 maxInstance--; 1153 } 1154 sc->cmi_order_size = 0; 1155 for (instance = 0; instance < maxInstance; 1156 ++instance) { 1157 if (acpi_hp_get_cmi_block(sc->wmi_dev, 1158 ACPI_HP_WMI_CMI_GUID, instance, 1159 line, linesize, &sequence, 1160 sc->cmi_detail)) { 1161 instance = maxInstance; 1162 } 1163 else { 1164 pos = sc->cmi_order_size; 1165 for (i=0; 1166 i<sc->cmi_order_size && i<127; 1167 ++i) { 1168 if (sc->cmi_order[i].sequence > sequence) { 1169 pos = i; 1170 break; 1171 } 1172 } 1173 for (i=sc->cmi_order_size; 1174 i>pos; 1175 --i) { 1176 sc->cmi_order[i].sequence = 1177 sc->cmi_order[i-1].sequence; 1178 sc->cmi_order[i].instance = 1179 sc->cmi_order[i-1].instance; 1180 } 1181 sc->cmi_order[pos].sequence = 1182 sequence; 1183 sc->cmi_order[pos].instance = 1184 instance; 1185 sc->cmi_order_size++; 1186 } 1187 } 1188 } 1189 for (i=0; i<sc->cmi_order_size; ++i) { 1190 if (!acpi_hp_get_cmi_block(sc->wmi_dev, 1191 ACPI_HP_WMI_CMI_GUID, 1192 sc->cmi_order[i].instance, line, linesize, 1193 &sequence, sc->cmi_detail)) { 1194 sbuf_printf(&sc->hpcmi_sbuf, "%s\n", line); 1195 } 1196 } 1197 sbuf_finish(&sc->hpcmi_sbuf); 1198 } 1199 if (sbuf_len(&sc->hpcmi_sbuf) <= 0) { 1200 sbuf_delete(&sc->hpcmi_sbuf); 1201 sc->hpcmi_bufptr = -1; 1202 sc->hpcmi_open_pid = 0; 1203 ret = ENOMEM; 1204 } else { 1205 l = min(buf->uio_resid, sbuf_len(&sc->hpcmi_sbuf) - 1206 sc->hpcmi_bufptr); 1207 ret = (l > 0)?uiomove(sbuf_data(&sc->hpcmi_sbuf) + 1208 sc->hpcmi_bufptr, l, buf) : 0; 1209 sc->hpcmi_bufptr += l; 1210 } 1211 } 1212 ACPI_SERIAL_END(hp); 1213 1214 return (ret); 1215}
|