Sun Dec 3 23:43:00 2017 UTC ()
make this compile again and:
- remove extra space
- use alternate form %x printing
- use aprint_debug_dev instead of printf


(christos)
diff -r1.10 -r1.11 src/sys/dev/acpi/wmi/wmi_dell.c

cvs diff -r1.10 -r1.11 src/sys/dev/acpi/wmi/wmi_dell.c (expand / switch to unified diff)

--- src/sys/dev/acpi/wmi/wmi_dell.c 2017/12/03 17:40:48 1.10
+++ src/sys/dev/acpi/wmi/wmi_dell.c 2017/12/03 23:43:00 1.11
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wmi_dell.c,v 1.10 2017/12/03 17:40:48 bouyer Exp $ */ 1/* $NetBSD: wmi_dell.c,v 1.11 2017/12/03 23:43:00 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jukka Ruohonen. 8 * by Jukka Ruohonen.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 13 *
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE. 30 * SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: wmi_dell.c,v 1.10 2017/12/03 17:40:48 bouyer Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: wmi_dell.c,v 1.11 2017/12/03 23:43:00 christos Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/device.h> 37#include <sys/device.h>
38#include <sys/module.h> 38#include <sys/module.h>
39 39
40#include <dev/acpi/acpireg.h> 40#include <dev/acpi/acpireg.h>
41#include <dev/acpi/acpivar.h> 41#include <dev/acpi/acpivar.h>
42#include <dev/acpi/wmi/wmi_acpivar.h> 42#include <dev/acpi/wmi/wmi_acpivar.h>
43 43
44#include <dev/sysmon/sysmonvar.h> 44#include <dev/sysmon/sysmonvar.h>
45 45
46#ifdef WMI_DEBUG 46#ifdef WMI_DEBUG
47#define DPRINTF(x) printf x 47#define DPRINTF(x) printf x
@@ -154,28 +154,30 @@ wmi_dell_attach(device_t parent, device_ @@ -154,28 +154,30 @@ wmi_dell_attach(device_t parent, device_
154 if (obj->Type != ACPI_TYPE_BUFFER) { 154 if (obj->Type != ACPI_TYPE_BUFFER) {
155 aprint_error(": wrong type %d for WMI descriptor\n", obj->Type); 155 aprint_error(": wrong type %d for WMI descriptor\n", obj->Type);
156 return; 156 return;
157 } 157 }
158 if (obj->Buffer.Length != 128) { 158 if (obj->Buffer.Length != 128) {
159 aprint_error(": wrong len %d for WMI descriptor", 159 aprint_error(": wrong len %d for WMI descriptor",
160 obj->Buffer.Length); 160 obj->Buffer.Length);
161 if (obj->Buffer.Length < 16) { 161 if (obj->Buffer.Length < 16) {
162 aprint_error("\n"); 162 aprint_error("\n");
163 return; 163 return;
164 } 164 }
165 } 165 }
166 data = (uint32_t *)obj->Buffer.Pointer; 166 data = (uint32_t *)obj->Buffer.Pointer;
167 if (data[0] != 0x4C4C4544 || data[1] != 0x494D5720) { 167#define WMI_LLED 0x4C4C4544
168 aprint_error(": wrong WMI descriptor signature 0x%x 0x%x", 168#define WMI_IMWsp 0x494D5720
 169 if (data[0] != WMI_LLED || data[1] != WMI_IMWsp) {
 170 aprint_error(": wrong WMI descriptor signature %#x %#x",
169 data[0], data[1]); 171 data[0], data[1]);
170 } 172 }
171 sc->sc_version = data[2]; 173 sc->sc_version = data[2];
172 aprint_naive("\n"); 174 aprint_naive("\n");
173 aprint_normal(": Dell WMI mappings version %d\n", sc->sc_version); 175 aprint_normal(": Dell WMI mappings version %d\n", sc->sc_version);
174 176
175 sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE].smpsw_name = 177 sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE].smpsw_name =
176 PSWITCH_HK_DISPLAY_CYCLE; 178 PSWITCH_HK_DISPLAY_CYCLE;
177 179
178 sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE].smpsw_type = 180 sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE].smpsw_type =
179 PSWITCH_TYPE_HOTKEY; 181 PSWITCH_TYPE_HOTKEY;
180 182
181 e = sysmon_pswitch_register(&sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE]); 183 e = sysmon_pswitch_register(&sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE]);
@@ -220,57 +222,55 @@ static bool @@ -220,57 +222,55 @@ static bool
220wmi_dell_resume(device_t self, const pmf_qual_t *qual) 222wmi_dell_resume(device_t self, const pmf_qual_t *qual)
221{ 223{
222 struct wmi_dell_softc *sc = device_private(self); 224 struct wmi_dell_softc *sc = device_private(self);
223 device_t parent = sc->sc_parent; 225 device_t parent = sc->sc_parent;
224 226
225 (void)acpi_wmi_event_register(parent, wmi_dell_notify_handler); 227 (void)acpi_wmi_event_register(parent, wmi_dell_notify_handler);
226 228
227 return true; 229 return true;
228} 230}
229 231
230static void 232static void
231wmi_dell_action(struct wmi_dell_softc *sc, uint16_t *data, int len) 233wmi_dell_action(struct wmi_dell_softc *sc, uint16_t *data, int len)
232{ 234{
233 int i; 235 size_t i;
234 for (i = 0; i < __arraycount(wmi_dell_actions); i++) { 236 for (i = 0; i < __arraycount(wmi_dell_actions); i++) {
235 const struct wmi_dell_actions *wda = &wmi_dell_actions[i]; 237 const struct wmi_dell_actions *wda = &wmi_dell_actions[i];
236 if (wda->wda_type == data[0] && 238 if (wda->wda_type == data[0] &&
237 wda->wda_subtype == data[1]) { 239 wda->wda_subtype == data[1]) {
238 switch(wda->wda_action) { 240 switch(wda->wda_action) {
239 case WMI_DELLA_IGN: 241 case WMI_DELLA_IGN:
240 DPRINTF((" ignored")); 242 DPRINTF((" ignored"));
241 return; 243 return;
242 case WMI_DELLA_PMF: 244 case WMI_DELLA_PMF:
243 DPRINTF((" pmf %d", 245 DPRINTF((" pmf %d", wda->wda_data));
244 wda->wda_data)); 246 pmf_event_inject(NULL, wda->wda_data);
245 pmf_event_inject(NULL, 
246 wda->wda_data); 
247 return; 247 return;
248 case WMI_DELLA_PSW: 248 case WMI_DELLA_PSW:
249 DPRINTF((" psw %d", 249 DPRINTF((" psw %d", wda->wda_data));
250 wda->wda_data)); 
251 sysmon_pswitch_event( 250 sysmon_pswitch_event(
252 &sc->sc_smpsw[wda->wda_data], 251 &sc->sc_smpsw[wda->wda_data],
253 PSWITCH_EVENT_PRESSED); 252 PSWITCH_EVENT_PRESSED);
254 return; 253 return;
255 default: 254 default:
256 printf("unknown dell wmi action %d\n", 255 aprint_debug_dev(sc->sc_dev,
 256 "unknown dell wmi action %d\n",
257 wda->wda_action); 257 wda->wda_action);
258 return; 258 return;
259 } 259 }
260 260
261 } 261 }
262 } 262 }
263 aprint_debug_dev(sc->sc_dev, "unkown event 0x%4X 0x%4X\n", 263 aprint_debug_dev(sc->sc_dev, "unknown event %#4X %#4X\n",
264 data[0], data[1]); 264 data[0], data[1]);
265} 265}
266 266
267static void 267static void
268wmi_dell_notify_handler(ACPI_HANDLE hdl, uint32_t evt, void *aux) 268wmi_dell_notify_handler(ACPI_HANDLE hdl, uint32_t evt, void *aux)
269{ 269{
270 struct wmi_dell_softc *sc; 270 struct wmi_dell_softc *sc;
271 device_t self = aux; 271 device_t self = aux;
272 ACPI_OBJECT *obj; 272 ACPI_OBJECT *obj;
273 ACPI_BUFFER buf; 273 ACPI_BUFFER buf;
274 ACPI_STATUS rv; 274 ACPI_STATUS rv;
275 uint16_t *data, *end; 275 uint16_t *data, *end;
276 int i, len; 276 int i, len;
@@ -302,71 +302,68 @@ wmi_dell_notify_handler(ACPI_HANDLE hdl, @@ -302,71 +302,68 @@ wmi_dell_notify_handler(ACPI_HANDLE hdl,
302 break; 302 break;
303 } 303 }
304 len = data[0] + 1; 304 len = data[0] + 1;
305 305
306 if (&data[len] >= end) { 306 if (&data[len] >= end) {
307 DPRINTF(("\n")); 307 DPRINTF(("\n"));
308 break; 308 break;
309 } 309 }
310 if (len < 2) { 310 if (len < 2) {
311 DPRINTF(("\n")); 311 DPRINTF(("\n"));
312 continue; 312 continue;
313 } 313 }
314 for (i = 1; i < len; i++) 314 for (i = 1; i < len; i++)
315 DPRINTF((" 0x%04X", data[i])); 315 DPRINTF((" %#04X", data[i]));
316 wmi_dell_action(sc, &data[1], len - 1); 316 wmi_dell_action(sc, &data[1], len - 1);
317 DPRINTF(("\n")); 317 DPRINTF(("\n"));
318 data = &data[len]; 318 data = &data[len];
319 /*  319 /*
320 * WMI interface version 0 don't clear the buffer from previous 320 * WMI interface version 0 don't clear the buffer from previous
321 * event, so if the current event is smaller than the previous 321 * event, so if the current event is smaller than the previous
322 * one there will be garbage after the current event. 322 * one there will be garbage after the current event.
323 * workaround by processing only the first event 323 * workaround by processing only the first event
324 */ 324 */
325 if (sc->sc_version == 0) 325 if (sc->sc_version == 0)
326 break; 326 break;
327 } 327 }
328 328
329out: 329out:
330 if (buf.Pointer != NULL) 330 if (buf.Pointer != NULL)
331 ACPI_FREE(buf.Pointer); 331 ACPI_FREE(buf.Pointer);
332 332
333 if (ACPI_FAILURE(rv)) 333 if (ACPI_FAILURE(rv))
334 aprint_error_dev(sc->sc_dev, "failed to get data for " 334 aprint_error_dev(sc->sc_dev, "failed to get data for "
335 "event 0x%02X: %s\n", evt, AcpiFormatException(rv)); 335 "event %#02X: %s\n", evt, AcpiFormatException(rv));
336} 336}
337 337
338MODULE(MODULE_CLASS_DRIVER, wmidell, "acpiwmi,sysmon_power"); 338MODULE(MODULE_CLASS_DRIVER, wmidell, "acpiwmi,sysmon_power");
339 339
340#ifdef _MODULE 340#ifdef _MODULE
341#include "ioconf.c" 341#include "ioconf.c"
342#endif 342#endif
343 343
344static int 344static int
345wmidell_modcmd(modcmd_t cmd, void *aux) 345wmidell_modcmd(modcmd_t cmd, void *aux)
346{ 346{
347 int rv = 0; 347 int rv = 0;
348 348
349 switch (cmd) { 349 switch (cmd) {
350 
351 case MODULE_CMD_INIT: 350 case MODULE_CMD_INIT:
352 
353#ifdef _MODULE 351#ifdef _MODULE
354 rv = config_init_component(cfdriver_ioconf_wmidell, 352 rv = config_init_component(cfdriver_ioconf_wmidell,
355 cfattach_ioconf_wmidell, cfdata_ioconf_wmidell); 353 cfattach_ioconf_wmidell, cfdata_ioconf_wmidell);
356#endif 354#endif
357 break; 355 break;
358 356
359 case MODULE_CMD_FINI: 357 case MODULE_CMD_FINI:
360 
361#ifdef _MODULE 358#ifdef _MODULE
362 rv = config_fini_component(cfdriver_ioconf_wmidell, 359 rv = config_fini_component(cfdriver_ioconf_wmidell,
363 cfattach_ioconf_wmidell, cfdata_ioconf_wmidell); 360 cfattach_ioconf_wmidell, cfdata_ioconf_wmidell);
364#endif 361#endif
365 break; 362 break;
366 363
367 default: 364 default:
368 rv = ENOTTY; 365 rv = ENOTTY;
369 } 366 }
370 367
371 return rv; 368 return rv;
372} 369}