2 * Copyright (c) 2002-2003 Taku YAMAMOTO <taku@cent.saitama-u.ac.jp>
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/acpica/acpi_video.c,v 1.13 2006/08/10 13:18:02 bruno Exp $
27 * $DragonFly: src/sys/dev/acpica5/acpi_video/acpi_video.c,v 1.2 2008/08/28 11:05:34 sephe Exp $
30 #include <sys/param.h>
31 #include <sys/kernel.h>
33 #include <sys/malloc.h>
34 #include <sys/module.h>
36 #include <sys/power.h>
37 #include <sys/queue.h>
38 #include <sys/sysctl.h>
43 /* ACPI video extension driver. */
44 struct acpi_video_output {
47 STAILQ_ENTRY(acpi_video_output) vo_next;
50 STAILQ_ENTRY(acpi_video_output) next;
57 struct sysctl_ctx_list vo_sysctl_ctx;
58 struct sysctl_oid *vo_sysctl_tree;
61 STAILQ_HEAD(acpi_video_output_queue, acpi_video_output);
63 struct acpi_video_softc {
66 struct acpi_video_output_queue vid_outputs;
67 eventhandler_tag vid_pwr_evh;
71 static int acpi_video_modevent(struct module*, int, void *);
72 static int acpi_video_probe(device_t);
73 static int acpi_video_attach(device_t);
74 static int acpi_video_detach(device_t);
75 static int acpi_video_shutdown(device_t);
76 static void acpi_video_notify_handler(ACPI_HANDLE, UINT32, void *);
77 static void acpi_video_power_profile(void *);
78 static void acpi_video_bind_outputs(struct acpi_video_softc *);
79 static struct acpi_video_output *acpi_video_vo_init(UINT32);
80 static void acpi_video_vo_bind(struct acpi_video_output *, ACPI_HANDLE);
81 static void acpi_video_vo_destroy(struct acpi_video_output *);
82 static int acpi_video_vo_check_level(struct acpi_video_output *, int);
83 static int acpi_video_vo_active_sysctl(SYSCTL_HANDLER_ARGS);
84 static int acpi_video_vo_bright_sysctl(SYSCTL_HANDLER_ARGS);
85 static int acpi_video_vo_presets_sysctl(SYSCTL_HANDLER_ARGS);
86 static int acpi_video_vo_levels_sysctl(SYSCTL_HANDLER_ARGS);
89 static void vid_set_switch_policy(ACPI_HANDLE, UINT32);
90 static int vid_enum_outputs(ACPI_HANDLE,
91 void(*)(ACPI_HANDLE, UINT32, void *), void *);
92 static int vo_get_brightness_levels(ACPI_HANDLE, int **);
93 static void vo_set_brightness(ACPI_HANDLE, int);
94 static UINT32 vo_get_device_status(ACPI_HANDLE);
95 static UINT32 vo_get_graphics_state(ACPI_HANDLE);
96 static void vo_set_device_state(ACPI_HANDLE, UINT32);
99 #define VID_NOTIFY_SWITCHED 0x80
100 #define VID_NOTIFY_REPROBE 0x81
102 /* _DOS (Enable/Disable Output Switching) argument bits */
103 #define DOS_SWITCH_MASK 3
104 #define DOS_SWITCH_BY_OSPM 0
105 #define DOS_SWITCH_BY_BIOS 1
106 #define DOS_SWITCH_LOCKED 2
107 #define DOS_BRIGHTNESS_BY_BIOS (1 << 2)
109 /* _DOD and subdev's _ADR */
110 #define DOD_DEVID_MASK 0x0f00
111 #define DOD_DEVID_MASK_FULL 0xffff
112 #define DOD_DEVID_MASK_DISPIDX 0x000f
113 #define DOD_DEVID_MASK_DISPPORT 0x00f0
114 #define DOD_DEVID_MONITOR 0x0100
115 #define DOD_DEVID_LCD 0x0110
116 #define DOD_DEVID_TV 0x0200
117 #define DOD_DEVID_EXT 0x0300
118 #define DOD_DEVID_INTDFP 0x0400
119 #define DOD_BIOS (1 << 16)
120 #define DOD_NONVGA (1 << 17)
121 #define DOD_HEAD_ID_SHIFT 18
122 #define DOD_HEAD_ID_BITS 3
123 #define DOD_HEAD_ID_MASK \
124 (((1 << DOD_HEAD_ID_BITS) - 1) << DOD_HEAD_ID_SHIFT)
125 #define DOD_DEVID_SCHEME_STD (1 << 31)
127 /* _BCL related constants */
128 #define BCL_FULLPOWER 0
129 #define BCL_ECONOMY 1
131 /* _DCS (Device Currrent Status) value bits and masks. */
132 #define DCS_EXISTS (1 << 0)
133 #define DCS_ACTIVE (1 << 1)
134 #define DCS_READY (1 << 2)
135 #define DCS_FUNCTIONAL (1 << 3)
136 #define DCS_ATTACHED (1 << 4)
138 /* _DSS (Device Set Status) argument bits and masks. */
139 #define DSS_INACTIVE 0
140 #define DSS_ACTIVE (1 << 0)
141 #define DSS_SETNEXT (1 << 30)
142 #define DSS_COMMIT (1 << 31)
144 static device_method_t acpi_video_methods[] = {
145 DEVMETHOD(device_probe, acpi_video_probe),
146 DEVMETHOD(device_attach, acpi_video_attach),
147 DEVMETHOD(device_detach, acpi_video_detach),
148 DEVMETHOD(device_shutdown, acpi_video_shutdown),
152 static driver_t acpi_video_driver = {
155 sizeof(struct acpi_video_softc),
158 static devclass_t acpi_video_devclass;
160 DRIVER_MODULE(acpi_video, acpi, acpi_video_driver, acpi_video_devclass,
161 acpi_video_modevent, NULL);
162 MODULE_DEPEND(acpi_video, acpi, 1, 1, 1);
164 static struct sysctl_ctx_list acpi_video_sysctl_ctx;
165 static struct sysctl_oid *acpi_video_sysctl_tree;
166 static struct acpi_video_output_queue crt_units, tv_units,
167 ext_units, lcd_units, other_units;
168 static struct lock avlock;
170 MALLOC_DEFINE(M_ACPIVIDEO, "acpivideo", "ACPI video extension");
173 acpi_video_modevent(struct module *mod __unused, int evt, void *cookie __unused)
180 sysctl_ctx_init(&acpi_video_sysctl_ctx);
181 STAILQ_INIT(&crt_units);
182 STAILQ_INIT(&tv_units);
183 STAILQ_INIT(&ext_units);
184 STAILQ_INIT(&lcd_units);
185 STAILQ_INIT(&other_units);
188 sysctl_ctx_free(&acpi_video_sysctl_ctx);
189 acpi_video_sysctl_tree = NULL;
199 acpi_video_probe(device_t dev)
202 ACPI_OBJECT_TYPE t_dos;
204 devh = acpi_get_handle(dev);
205 if (acpi_disabled("video") ||
206 ACPI_FAILURE(AcpiGetHandle(devh, "_DOD", &h)) ||
207 ACPI_FAILURE(AcpiGetHandle(devh, "_DOS", &h)) ||
208 ACPI_FAILURE(AcpiGetType(h, &t_dos)) ||
209 t_dos != ACPI_TYPE_METHOD)
212 device_set_desc(dev, "ACPI video extension");
217 acpi_video_attach(device_t dev)
219 struct acpi_softc *acpi_sc;
220 struct acpi_video_softc *sc;
222 sc = device_get_softc(dev);
224 acpi_sc = devclass_get_softc(devclass_find("acpi"), 0);
227 if (acpi_video_sysctl_tree == NULL) {
228 acpi_video_sysctl_tree = SYSCTL_ADD_NODE(&acpi_video_sysctl_ctx,
229 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
230 OID_AUTO, "video", CTLFLAG_RD, 0,
231 "video extension control");
235 sc->handle = acpi_get_handle(dev);
236 STAILQ_INIT(&sc->vid_outputs);
238 AcpiInstallNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
239 acpi_video_notify_handler, sc);
240 sc->vid_pwr_evh = EVENTHANDLER_REGISTER(power_profile_change,
241 acpi_video_power_profile, sc, 0);
243 lockinit(&avlock, "acpi_video", 0, 0);
244 lockmgr(&avlock, LK_EXCLUSIVE);
245 acpi_video_bind_outputs(sc);
246 lockmgr(&avlock, LK_RELEASE);
249 * Notify the BIOS that we want to switch both active outputs and
252 vid_set_switch_policy(sc->handle, DOS_SWITCH_BY_OSPM |
253 DOS_BRIGHTNESS_BY_BIOS);
255 acpi_video_power_profile(sc);
261 acpi_video_detach(device_t dev)
263 struct acpi_video_softc *sc;
264 struct acpi_video_output *vo, *vn;
266 sc = device_get_softc(dev);
268 vid_set_switch_policy(sc->handle, DOS_SWITCH_BY_BIOS);
269 EVENTHANDLER_DEREGISTER(power_profile_change, sc->vid_pwr_evh);
270 AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
271 acpi_video_notify_handler);
273 lockmgr(&avlock, LK_EXCLUSIVE);
274 for (vo = STAILQ_FIRST(&sc->vid_outputs); vo != NULL; vo = vn) {
275 vn = STAILQ_NEXT(vo, vo_next);
276 acpi_video_vo_destroy(vo);
278 lockmgr(&avlock, LK_RELEASE);
284 acpi_video_shutdown(device_t dev)
286 struct acpi_video_softc *sc;
288 sc = device_get_softc(dev);
289 vid_set_switch_policy(sc->handle, DOS_SWITCH_BY_BIOS);
295 acpi_video_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
297 struct acpi_video_softc *sc;
298 struct acpi_video_output *vo, *vo_tmp;
299 ACPI_HANDLE lasthand;
300 UINT32 dcs, dss, dss_p;
302 sc = (struct acpi_video_softc *)context;
305 case VID_NOTIFY_SWITCHED:
308 lockmgr(&avlock, LK_EXCLUSIVE);
309 STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next) {
310 dss = vo_get_graphics_state(vo->handle);
311 dcs = vo_get_device_status(vo->handle);
312 if (!(dcs & DCS_READY))
314 if (((dcs & DCS_ACTIVE) && dss == DSS_INACTIVE) ||
315 (!(dcs & DCS_ACTIVE) && dss == DSS_ACTIVE)) {
316 if (lasthand != NULL)
317 vo_set_device_state(lasthand, dss_p);
319 lasthand = vo->handle;
322 if (lasthand != NULL)
323 vo_set_device_state(lasthand, dss_p|DSS_COMMIT);
324 lockmgr(&avlock, LK_RELEASE);
326 case VID_NOTIFY_REPROBE:
327 lockmgr(&avlock, LK_EXCLUSIVE);
328 STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next)
330 acpi_video_bind_outputs(sc);
331 STAILQ_FOREACH_MUTABLE(vo, &sc->vid_outputs, vo_next, vo_tmp) {
332 if (vo->handle == NULL) {
333 STAILQ_REMOVE(&sc->vid_outputs, vo,
334 acpi_video_output, vo_next);
335 acpi_video_vo_destroy(vo);
338 lockmgr(&avlock, LK_RELEASE);
341 device_printf(sc->device, "unknown notify event 0x%x\n",
347 acpi_video_power_profile(void *context)
350 struct acpi_video_softc *sc;
351 struct acpi_video_output *vo;
354 state = power_profile_get_state();
355 if (state != POWER_PROFILE_PERFORMANCE &&
356 state != POWER_PROFILE_ECONOMY)
359 lockmgr(&avlock, LK_EXCLUSIVE);
360 STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next) {
361 if (vo->vo_levels != NULL && vo->vo_brightness == -1)
362 vo_set_brightness(vo->handle,
363 state == POWER_PROFILE_ECONOMY ?
364 vo->vo_economy : vo->vo_fullpower);
366 lockmgr(&avlock, LK_RELEASE);
370 acpi_video_bind_outputs_subr(ACPI_HANDLE handle, UINT32 adr, void *context)
372 struct acpi_video_softc *sc;
373 struct acpi_video_output *vo;
377 STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next) {
378 if (vo->adr == adr) {
379 acpi_video_vo_bind(vo, handle);
383 vo = acpi_video_vo_init(adr);
385 acpi_video_vo_bind(vo, handle);
386 STAILQ_INSERT_TAIL(&sc->vid_outputs, vo, vo_next);
391 acpi_video_bind_outputs(struct acpi_video_softc *sc)
394 vid_enum_outputs(sc->handle, acpi_video_bind_outputs_subr, sc);
397 static struct acpi_video_output *
398 acpi_video_vo_init(UINT32 adr)
400 struct acpi_video_output *vn, *vo, *vp;
404 char name[8], env[32];
405 const char *type, *desc;
406 struct acpi_video_output_queue *voqh;
408 display_index = adr & DOD_DEVID_MASK_DISPIDX;
409 display_port = (adr & DOD_DEVID_MASK_DISPPORT) >> 4;
411 switch (adr & DOD_DEVID_MASK) {
412 case DOD_DEVID_MONITOR:
413 if ((adr & DOD_DEVID_MASK_FULL) == DOD_DEVID_LCD) {
414 /* DOD_DEVID_LCD is a common, backward compatible ID */
415 desc = "Internal/Integrated Digital Flat Panel";
419 desc = "VGA CRT or VESA Compatible Analog Monitor";
425 desc = "TV/HDTV or Analog-Video Monitor";
430 desc = "External Digital Monitor";
434 case DOD_DEVID_INTDFP:
435 desc = "Internal/Integrated Digital Flat Panel";
440 desc = "unknown output";
447 STAILQ_FOREACH(vn, voqh, vo_unit.next) {
448 if (vn->vo_unit.num != n)
454 ksnprintf(name, sizeof(name), "%s%d", type, n);
456 vo = kmalloc(sizeof(*vo), M_ACPIVIDEO, M_NOWAIT);
461 vo->vo_brightness = -1;
462 vo->vo_fullpower = -1; /* TODO: override with tunables */
464 vo->vo_numlevels = 0;
465 vo->vo_levels = NULL;
466 ksnprintf(env, sizeof(env), "hw.acpi.video.%s.fullpower", name);
467 if (kgetenv_int(env, &x))
468 vo->vo_fullpower = x;
469 ksnprintf(env, sizeof(env), "hw.acpi.video.%s.economy", name);
470 if (kgetenv_int(env, &x))
473 sysctl_ctx_init(&vo->vo_sysctl_ctx);
475 STAILQ_INSERT_AFTER(voqh, vp, vo, vo_unit.next);
477 STAILQ_INSERT_TAIL(voqh, vo, vo_unit.next);
478 if (acpi_video_sysctl_tree != NULL)
480 SYSCTL_ADD_NODE(&vo->vo_sysctl_ctx,
481 SYSCTL_CHILDREN(acpi_video_sysctl_tree),
482 OID_AUTO, name, CTLFLAG_RD, 0, desc);
483 if (vo->vo_sysctl_tree != NULL) {
484 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
485 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
487 CTLTYPE_INT|CTLFLAG_RW, vo, 0,
488 acpi_video_vo_active_sysctl, "I",
489 "current activity of this device");
490 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
491 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
492 OID_AUTO, "brightness",
493 CTLTYPE_INT|CTLFLAG_RW, vo, 0,
494 acpi_video_vo_bright_sysctl, "I",
495 "current brightness level");
496 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
497 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
498 OID_AUTO, "fullpower",
499 CTLTYPE_INT|CTLFLAG_RW, vo,
500 POWER_PROFILE_PERFORMANCE,
501 acpi_video_vo_presets_sysctl, "I",
502 "preset level for full power mode");
503 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
504 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
506 CTLTYPE_INT|CTLFLAG_RW, vo,
507 POWER_PROFILE_ECONOMY,
508 acpi_video_vo_presets_sysctl, "I",
509 "preset level for economy mode");
510 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
511 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
513 CTLTYPE_OPAQUE|CTLFLAG_RD, vo, 0,
514 acpi_video_vo_levels_sysctl, "I",
515 "supported brightness levels");
517 kprintf("%s: sysctl node creation failed\n", type);
519 kprintf("%s: softc allocation failed\n", type);
522 kprintf("found %s(%x)", desc, adr & DOD_DEVID_MASK_FULL);
523 kprintf(", idx#%x", adr & DOD_DEVID_MASK_DISPIDX);
524 kprintf(", port#%x", (adr & DOD_DEVID_MASK_DISPPORT) >> 4);
526 kprintf(", detectable by BIOS");
527 if (adr & DOD_NONVGA)
528 kprintf(" (Non-VGA output device whose power "
529 "is related to the VGA device)");
530 kprintf(", head #%d\n",
531 (adr & DOD_HEAD_ID_MASK) >> DOD_HEAD_ID_SHIFT);
537 acpi_video_vo_bind(struct acpi_video_output *vo, ACPI_HANDLE handle)
539 if (vo->vo_levels != NULL)
540 AcpiOsFree(vo->vo_levels);
542 vo->vo_numlevels = vo_get_brightness_levels(handle, &vo->vo_levels);
543 if (vo->vo_numlevels >= 2) {
544 if (vo->vo_fullpower == -1
545 || acpi_video_vo_check_level(vo, vo->vo_fullpower) != 0)
546 /* XXX - can't deal with rebinding... */
547 vo->vo_fullpower = vo->vo_levels[BCL_FULLPOWER];
548 if (vo->vo_economy == -1
549 || acpi_video_vo_check_level(vo, vo->vo_economy) != 0)
550 /* XXX - see above. */
551 vo->vo_economy = vo->vo_levels[BCL_ECONOMY];
556 acpi_video_vo_destroy(struct acpi_video_output *vo)
558 struct acpi_video_output_queue *voqh;
560 if (vo->vo_sysctl_tree != NULL) {
561 vo->vo_sysctl_tree = NULL;
562 sysctl_ctx_free(&vo->vo_sysctl_ctx);
564 if (vo->vo_levels != NULL)
565 AcpiOsFree(vo->vo_levels);
567 switch (vo->adr & DOD_DEVID_MASK) {
568 case DOD_DEVID_MONITOR:
577 case DOD_DEVID_INTDFP:
583 STAILQ_REMOVE(voqh, vo, acpi_video_output, vo_unit.next);
584 kfree(vo, M_ACPIVIDEO);
588 acpi_video_vo_check_level(struct acpi_video_output *vo, int level)
592 if (vo->vo_levels == NULL)
594 for (i = 0; i < vo->vo_numlevels; i++)
595 if (vo->vo_levels[i] == level)
602 acpi_video_vo_active_sysctl(SYSCTL_HANDLER_ARGS)
604 struct acpi_video_output *vo;
607 vo = (struct acpi_video_output *)arg1;
608 if (vo->handle == NULL)
610 lockmgr(&avlock, LK_EXCLUSIVE);
611 state = (vo_get_device_status(vo->handle) & DCS_ACTIVE) ? 1 : 0;
612 err = sysctl_handle_int(oidp, &state, 0, req);
613 if (err != 0 || req->newptr == NULL)
615 vo_set_device_state(vo->handle,
616 DSS_COMMIT | (state ? DSS_ACTIVE : DSS_INACTIVE));
618 lockmgr(&avlock, LK_RELEASE);
624 acpi_video_vo_bright_sysctl(SYSCTL_HANDLER_ARGS)
626 struct acpi_video_output *vo;
627 int level, preset, err;
629 vo = (struct acpi_video_output *)arg1;
630 lockmgr(&avlock, LK_EXCLUSIVE);
631 if (vo->handle == NULL) {
635 if (vo->vo_levels == NULL) {
640 preset = (power_profile_get_state() == POWER_PROFILE_ECONOMY) ?
641 vo->vo_economy : vo->vo_fullpower;
642 level = vo->vo_brightness;
646 err = sysctl_handle_int(oidp, &level, 0, req);
647 if (err != 0 || req->newptr == NULL)
649 if (level < -1 || level > 100) {
654 if (level != -1 && (err = acpi_video_vo_check_level(vo, level)))
656 vo->vo_brightness = level;
657 vo_set_brightness(vo->handle, (level == -1) ? preset : level);
660 lockmgr(&avlock, LK_RELEASE);
665 acpi_video_vo_presets_sysctl(SYSCTL_HANDLER_ARGS)
667 struct acpi_video_output *vo;
668 int i, level, *preset, err;
671 vo = (struct acpi_video_output *)arg1;
672 lockmgr(&avlock, LK_EXCLUSIVE);
673 if (vo->handle == NULL) {
677 if (vo->vo_levels == NULL) {
681 preset = (arg2 == POWER_PROFILE_ECONOMY) ?
682 &vo->vo_economy : &vo->vo_fullpower;
684 err = sysctl_handle_int(oidp, &level, 0, req);
685 if (err != 0 || req->newptr == NULL)
687 if (level < -1 || level > 100) {
692 i = (arg2 == POWER_PROFILE_ECONOMY) ?
693 BCL_ECONOMY : BCL_FULLPOWER;
694 level = vo->vo_levels[i];
695 } else if ((err = acpi_video_vo_check_level(vo, level)) != 0)
698 if (vo->vo_brightness == -1 && (power_profile_get_state() == arg2))
699 vo_set_brightness(vo->handle, level);
703 lockmgr(&avlock, LK_RELEASE);
709 acpi_video_vo_levels_sysctl(SYSCTL_HANDLER_ARGS)
711 struct acpi_video_output *vo;
714 vo = (struct acpi_video_output *)arg1;
715 lockmgr(&avlock, LK_EXCLUSIVE);
716 if (vo->vo_levels == NULL) {
720 if (req->newptr != NULL) {
724 err = sysctl_handle_opaque(oidp, vo->vo_levels,
725 vo->vo_numlevels * sizeof(*vo->vo_levels), req);
728 lockmgr(&avlock, LK_RELEASE);
733 vid_set_switch_policy(ACPI_HANDLE handle, UINT32 policy)
737 status = acpi_SetInteger(handle, "_DOS", policy);
738 if (ACPI_FAILURE(status))
739 kprintf("can't evaluate %s._DOS - %s\n",
740 acpi_name(handle), AcpiFormatException(status));
743 struct enum_callback_arg {
744 void (*callback)(ACPI_HANDLE, UINT32, void *);
746 ACPI_OBJECT *dod_pkg;
751 vid_enum_outputs_subr(ACPI_HANDLE handle, UINT32 level __unused,
752 void *context, void **retp __unused)
756 struct enum_callback_arg *argset;
760 status = acpi_GetInteger(handle, "_ADR", &adr);
761 if (ACPI_FAILURE(status))
764 for (i = 0; i < argset->dod_pkg->Package.Count; i++) {
765 if (acpi_PkgInt32(argset->dod_pkg, i, &val) == 0 &&
766 (val & DOD_DEVID_MASK_FULL) == adr) {
767 argset->callback(handle, val, argset->context);
776 vid_enum_outputs(ACPI_HANDLE handle,
777 void (*callback)(ACPI_HANDLE, UINT32, void *), void *context)
782 struct enum_callback_arg argset;
784 dod_buf.Length = ACPI_ALLOCATE_BUFFER;
785 dod_buf.Pointer = NULL;
786 status = AcpiEvaluateObject(handle, "_DOD", NULL, &dod_buf);
787 if (ACPI_FAILURE(status)) {
788 if (status != AE_NOT_FOUND)
789 kprintf("can't evaluate %s._DOD - %s\n",
790 acpi_name(handle), AcpiFormatException(status));
794 res = (ACPI_OBJECT *)dod_buf.Pointer;
795 if (!ACPI_PKG_VALID(res, 1)) {
796 kprintf("evaluation of %s._DOD makes no sense\n",
801 if (callback == NULL) {
802 argset.count = res->Package.Count;
805 argset.callback = callback;
806 argset.context = context;
807 argset.dod_pkg = res;
809 status = AcpiWalkNamespace(ACPI_TYPE_DEVICE, handle, 1,
810 vid_enum_outputs_subr, NULL, &argset, NULL);
811 if (ACPI_FAILURE(status))
812 kprintf("failed walking down %s - %s\n",
813 acpi_name(handle), AcpiFormatException(status));
815 if (dod_buf.Pointer != NULL)
816 AcpiOsFree(dod_buf.Pointer);
817 return (argset.count);
821 vo_get_brightness_levels(ACPI_HANDLE handle, int **levelp)
826 int num, i, n, *levels;
829 bcl_buf.Length = ACPI_ALLOCATE_BUFFER;
830 bcl_buf.Pointer = NULL;
831 status = AcpiEvaluateObject(handle, "_BCL", NULL, &bcl_buf);
832 if (ACPI_FAILURE(status)) {
833 if (status != AE_NOT_FOUND)
834 kprintf("can't evaluate %s._BCL - %s\n",
835 acpi_name(handle), AcpiFormatException(status));
839 res = (ACPI_OBJECT *)bcl_buf.Pointer;
840 if (!ACPI_PKG_VALID(res, 2)) {
841 kprintf("evaluation of %s._BCL makes no sense\n",
846 num = res->Package.Count;
849 levels = AcpiOsAllocate(num * sizeof(*levels));
850 if (levels == NULL) {
854 for (i = 0, n = 0; i < num; i++)
855 if (acpi_PkgInt32(res, i, &levels[n]) == 0)
865 if (bcl_buf.Pointer != NULL)
866 AcpiOsFree(bcl_buf.Pointer);
872 vo_set_brightness(ACPI_HANDLE handle, int level)
876 status = acpi_SetInteger(handle, "_BCM", level);
877 if (ACPI_FAILURE(status))
878 kprintf("can't evaluate %s._BCM - %s\n",
879 acpi_name(handle), AcpiFormatException(status));
883 vo_get_device_status(ACPI_HANDLE handle)
889 status = acpi_GetInteger(handle, "_DCS", &dcs);
890 if (ACPI_FAILURE(status))
891 kprintf("can't evaluate %s._DCS - %s\n",
892 acpi_name(handle), AcpiFormatException(status));
898 vo_get_graphics_state(ACPI_HANDLE handle)
904 status = acpi_GetInteger(handle, "_DGS", &dgs);
905 if (ACPI_FAILURE(status))
906 kprintf("can't evaluate %s._DGS - %s\n",
907 acpi_name(handle), AcpiFormatException(status));
913 vo_set_device_state(ACPI_HANDLE handle, UINT32 state)
917 status = acpi_SetInteger(handle, "_DSS", state);
918 if (ACPI_FAILURE(status))
919 kprintf("can't evaluate %s._DSS - %s\n",
920 acpi_name(handle), AcpiFormatException(status));