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 $
29 #include <sys/param.h>
30 #include <sys/kernel.h>
32 #include <sys/malloc.h>
33 #include <sys/module.h>
35 #include <sys/power.h>
36 #include <sys/queue.h>
37 #include <sys/sysctl.h>
42 /* ACPI video extension driver. */
43 struct acpi_video_output {
46 STAILQ_ENTRY(acpi_video_output) vo_next;
49 STAILQ_ENTRY(acpi_video_output) next;
56 struct sysctl_ctx_list vo_sysctl_ctx;
57 struct sysctl_oid *vo_sysctl_tree;
60 STAILQ_HEAD(acpi_video_output_queue, acpi_video_output);
62 struct acpi_video_softc {
65 struct acpi_video_output_queue vid_outputs;
66 eventhandler_tag vid_pwr_evh;
70 static int acpi_video_modevent(struct module*, int, void *);
71 static int acpi_video_probe(device_t);
72 static int acpi_video_attach(device_t);
73 static int acpi_video_detach(device_t);
74 static int acpi_video_shutdown(device_t);
75 static void acpi_video_notify_handler(ACPI_HANDLE, UINT32, void *);
76 static void acpi_video_power_profile(void *);
77 static void acpi_video_bind_outputs(struct acpi_video_softc *);
78 static struct acpi_video_output *acpi_video_vo_init(UINT32);
79 static void acpi_video_vo_bind(struct acpi_video_output *, ACPI_HANDLE);
80 static void acpi_video_vo_destroy(struct acpi_video_output *);
81 static int acpi_video_vo_check_level(struct acpi_video_output *, int);
82 static int acpi_video_vo_active_sysctl(SYSCTL_HANDLER_ARGS);
83 static int acpi_video_vo_bright_sysctl(SYSCTL_HANDLER_ARGS);
84 static int acpi_video_vo_presets_sysctl(SYSCTL_HANDLER_ARGS);
85 static int acpi_video_vo_levels_sysctl(SYSCTL_HANDLER_ARGS);
88 static void vid_set_switch_policy(ACPI_HANDLE, UINT32);
89 static int vid_enum_outputs(ACPI_HANDLE,
90 void(*)(ACPI_HANDLE, UINT32, void *), void *);
91 static int vo_get_brightness_levels(ACPI_HANDLE, int **);
92 static void vo_set_brightness(ACPI_HANDLE, int);
93 static UINT32 vo_get_device_status(ACPI_HANDLE);
94 static UINT32 vo_get_graphics_state(ACPI_HANDLE);
95 static void vo_set_device_state(ACPI_HANDLE, UINT32);
98 #define VID_NOTIFY_SWITCHED 0x80
99 #define VID_NOTIFY_REPROBE 0x81
101 /* _DOS (Enable/Disable Output Switching) argument bits */
102 #define DOS_SWITCH_MASK 3
103 #define DOS_SWITCH_BY_OSPM 0
104 #define DOS_SWITCH_BY_BIOS 1
105 #define DOS_SWITCH_LOCKED 2
106 #define DOS_BRIGHTNESS_BY_BIOS (1 << 2)
108 /* _DOD and subdev's _ADR */
109 #define DOD_DEVID_MASK 0x0f00
110 #define DOD_DEVID_MASK_FULL 0xffff
111 #define DOD_DEVID_MASK_DISPIDX 0x000f
112 #define DOD_DEVID_MASK_DISPPORT 0x00f0
113 #define DOD_DEVID_MONITOR 0x0100
114 #define DOD_DEVID_LCD 0x0110
115 #define DOD_DEVID_TV 0x0200
116 #define DOD_DEVID_EXT 0x0300
117 #define DOD_DEVID_INTDFP 0x0400
118 #define DOD_BIOS (1 << 16)
119 #define DOD_NONVGA (1 << 17)
120 #define DOD_HEAD_ID_SHIFT 18
121 #define DOD_HEAD_ID_BITS 3
122 #define DOD_HEAD_ID_MASK \
123 (((1 << DOD_HEAD_ID_BITS) - 1) << DOD_HEAD_ID_SHIFT)
124 #define DOD_DEVID_SCHEME_STD (1 << 31)
126 /* _BCL related constants */
127 #define BCL_FULLPOWER 0
128 #define BCL_ECONOMY 1
130 /* _DCS (Device Currrent Status) value bits and masks. */
131 #define DCS_EXISTS (1 << 0)
132 #define DCS_ACTIVE (1 << 1)
133 #define DCS_READY (1 << 2)
134 #define DCS_FUNCTIONAL (1 << 3)
135 #define DCS_ATTACHED (1 << 4)
137 /* _DSS (Device Set Status) argument bits and masks. */
138 #define DSS_INACTIVE 0
139 #define DSS_ACTIVE (1 << 0)
140 #define DSS_SETNEXT (1 << 30)
141 #define DSS_COMMIT (1 << 31)
143 static device_method_t acpi_video_methods[] = {
144 DEVMETHOD(device_probe, acpi_video_probe),
145 DEVMETHOD(device_attach, acpi_video_attach),
146 DEVMETHOD(device_detach, acpi_video_detach),
147 DEVMETHOD(device_shutdown, acpi_video_shutdown),
151 static driver_t acpi_video_driver = {
154 sizeof(struct acpi_video_softc),
157 static devclass_t acpi_video_devclass;
159 DRIVER_MODULE(acpi_video, acpi, acpi_video_driver, acpi_video_devclass,
160 acpi_video_modevent, NULL);
161 MODULE_DEPEND(acpi_video, acpi, 1, 1, 1);
163 static struct sysctl_ctx_list acpi_video_sysctl_ctx;
164 static struct sysctl_oid *acpi_video_sysctl_tree;
165 static struct acpi_video_output_queue crt_units, tv_units,
166 ext_units, lcd_units, other_units;
167 static struct lock avlock;
169 MALLOC_DEFINE(M_ACPIVIDEO, "acpivideo", "ACPI video extension");
172 acpi_video_modevent(struct module *mod __unused, int evt, void *cookie __unused)
179 sysctl_ctx_init(&acpi_video_sysctl_ctx);
180 STAILQ_INIT(&crt_units);
181 STAILQ_INIT(&tv_units);
182 STAILQ_INIT(&ext_units);
183 STAILQ_INIT(&lcd_units);
184 STAILQ_INIT(&other_units);
187 sysctl_ctx_free(&acpi_video_sysctl_ctx);
188 acpi_video_sysctl_tree = NULL;
198 acpi_video_probe(device_t dev)
201 ACPI_OBJECT_TYPE t_dos;
203 devh = acpi_get_handle(dev);
204 if (acpi_disabled("video") ||
205 ACPI_FAILURE(AcpiGetHandle(devh, "_DOD", &h)) ||
206 ACPI_FAILURE(AcpiGetHandle(devh, "_DOS", &h)) ||
207 ACPI_FAILURE(AcpiGetType(h, &t_dos)) ||
208 t_dos != ACPI_TYPE_METHOD)
211 device_set_desc(dev, "ACPI video extension");
216 acpi_video_attach(device_t dev)
218 struct acpi_softc *acpi_sc;
219 struct acpi_video_softc *sc;
221 sc = device_get_softc(dev);
223 acpi_sc = devclass_get_softc(devclass_find("acpi"), 0);
226 if (acpi_video_sysctl_tree == NULL) {
227 acpi_video_sysctl_tree = SYSCTL_ADD_NODE(&acpi_video_sysctl_ctx,
228 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
229 OID_AUTO, "video", CTLFLAG_RD, 0,
230 "video extension control");
234 sc->handle = acpi_get_handle(dev);
235 STAILQ_INIT(&sc->vid_outputs);
237 AcpiInstallNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
238 acpi_video_notify_handler, sc);
239 sc->vid_pwr_evh = EVENTHANDLER_REGISTER(power_profile_change,
240 acpi_video_power_profile, sc, 0);
242 lockinit(&avlock, "acpi_video", 0, 0);
243 lockmgr(&avlock, LK_EXCLUSIVE);
244 acpi_video_bind_outputs(sc);
245 lockmgr(&avlock, LK_RELEASE);
248 * Notify the BIOS that we want to switch both active outputs and
251 vid_set_switch_policy(sc->handle, DOS_SWITCH_BY_OSPM |
252 DOS_BRIGHTNESS_BY_BIOS);
254 acpi_video_power_profile(sc);
260 acpi_video_detach(device_t dev)
262 struct acpi_video_softc *sc;
263 struct acpi_video_output *vo, *vn;
265 sc = device_get_softc(dev);
267 vid_set_switch_policy(sc->handle, DOS_SWITCH_BY_BIOS);
268 EVENTHANDLER_DEREGISTER(power_profile_change, sc->vid_pwr_evh);
269 AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
270 acpi_video_notify_handler);
272 lockmgr(&avlock, LK_EXCLUSIVE);
273 for (vo = STAILQ_FIRST(&sc->vid_outputs); vo != NULL; vo = vn) {
274 vn = STAILQ_NEXT(vo, vo_next);
275 acpi_video_vo_destroy(vo);
277 lockmgr(&avlock, LK_RELEASE);
283 acpi_video_shutdown(device_t dev)
285 struct acpi_video_softc *sc;
287 sc = device_get_softc(dev);
288 vid_set_switch_policy(sc->handle, DOS_SWITCH_BY_BIOS);
294 acpi_video_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
296 struct acpi_video_softc *sc;
297 struct acpi_video_output *vo, *vo_tmp;
298 ACPI_HANDLE lasthand;
299 UINT32 dcs, dss, dss_p;
301 sc = (struct acpi_video_softc *)context;
304 case VID_NOTIFY_SWITCHED:
307 lockmgr(&avlock, LK_EXCLUSIVE);
308 STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next) {
309 dss = vo_get_graphics_state(vo->handle);
310 dcs = vo_get_device_status(vo->handle);
311 if (!(dcs & DCS_READY))
313 if (((dcs & DCS_ACTIVE) && dss == DSS_INACTIVE) ||
314 (!(dcs & DCS_ACTIVE) && dss == DSS_ACTIVE)) {
315 if (lasthand != NULL)
316 vo_set_device_state(lasthand, dss_p);
318 lasthand = vo->handle;
321 if (lasthand != NULL)
322 vo_set_device_state(lasthand, dss_p|DSS_COMMIT);
323 lockmgr(&avlock, LK_RELEASE);
325 case VID_NOTIFY_REPROBE:
326 lockmgr(&avlock, LK_EXCLUSIVE);
327 STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next)
329 acpi_video_bind_outputs(sc);
330 STAILQ_FOREACH_MUTABLE(vo, &sc->vid_outputs, vo_next, vo_tmp) {
331 if (vo->handle == NULL) {
332 STAILQ_REMOVE(&sc->vid_outputs, vo,
333 acpi_video_output, vo_next);
334 acpi_video_vo_destroy(vo);
337 lockmgr(&avlock, LK_RELEASE);
340 device_printf(sc->device, "unknown notify event 0x%x\n",
346 acpi_video_power_profile(void *context)
349 struct acpi_video_softc *sc;
350 struct acpi_video_output *vo;
353 state = power_profile_get_state();
354 if (state != POWER_PROFILE_PERFORMANCE &&
355 state != POWER_PROFILE_ECONOMY)
358 lockmgr(&avlock, LK_EXCLUSIVE);
359 STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next) {
360 if (vo->vo_levels != NULL && vo->vo_brightness == -1)
361 vo_set_brightness(vo->handle,
362 state == POWER_PROFILE_ECONOMY ?
363 vo->vo_economy : vo->vo_fullpower);
365 lockmgr(&avlock, LK_RELEASE);
369 acpi_video_bind_outputs_subr(ACPI_HANDLE handle, UINT32 adr, void *context)
371 struct acpi_video_softc *sc;
372 struct acpi_video_output *vo;
376 STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next) {
377 if (vo->adr == adr) {
378 acpi_video_vo_bind(vo, handle);
382 vo = acpi_video_vo_init(adr);
384 acpi_video_vo_bind(vo, handle);
385 STAILQ_INSERT_TAIL(&sc->vid_outputs, vo, vo_next);
390 acpi_video_bind_outputs(struct acpi_video_softc *sc)
393 vid_enum_outputs(sc->handle, acpi_video_bind_outputs_subr, sc);
396 static struct acpi_video_output *
397 acpi_video_vo_init(UINT32 adr)
399 struct acpi_video_output *vn, *vo, *vp;
401 char name[8], env[32];
402 const char *type, *desc;
403 struct acpi_video_output_queue *voqh;
405 switch (adr & DOD_DEVID_MASK) {
406 case DOD_DEVID_MONITOR:
407 if ((adr & DOD_DEVID_MASK_FULL) == DOD_DEVID_LCD) {
408 /* DOD_DEVID_LCD is a common, backward compatible ID */
409 desc = "Internal/Integrated Digital Flat Panel";
413 desc = "VGA CRT or VESA Compatible Analog Monitor";
419 desc = "TV/HDTV or Analog-Video Monitor";
424 desc = "External Digital Monitor";
428 case DOD_DEVID_INTDFP:
429 desc = "Internal/Integrated Digital Flat Panel";
434 desc = "unknown output";
441 STAILQ_FOREACH(vn, voqh, vo_unit.next) {
442 if (vn->vo_unit.num != n)
448 ksnprintf(name, sizeof(name), "%s%d", type, n);
450 vo = kmalloc(sizeof(*vo), M_ACPIVIDEO, M_NOWAIT);
455 vo->vo_brightness = -1;
456 vo->vo_fullpower = -1; /* TODO: override with tunables */
458 vo->vo_numlevels = 0;
459 vo->vo_levels = NULL;
460 ksnprintf(env, sizeof(env), "hw.acpi.video.%s.fullpower", name);
461 if (kgetenv_int(env, &x))
462 vo->vo_fullpower = x;
463 ksnprintf(env, sizeof(env), "hw.acpi.video.%s.economy", name);
464 if (kgetenv_int(env, &x))
467 sysctl_ctx_init(&vo->vo_sysctl_ctx);
469 STAILQ_INSERT_AFTER(voqh, vp, vo, vo_unit.next);
471 STAILQ_INSERT_TAIL(voqh, vo, vo_unit.next);
472 if (acpi_video_sysctl_tree != NULL)
474 SYSCTL_ADD_NODE(&vo->vo_sysctl_ctx,
475 SYSCTL_CHILDREN(acpi_video_sysctl_tree),
476 OID_AUTO, name, CTLFLAG_RD, 0, desc);
477 if (vo->vo_sysctl_tree != NULL) {
478 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
479 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
481 CTLTYPE_INT|CTLFLAG_RW, vo, 0,
482 acpi_video_vo_active_sysctl, "I",
483 "current activity of this device");
484 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
485 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
486 OID_AUTO, "brightness",
487 CTLTYPE_INT|CTLFLAG_RW, vo, 0,
488 acpi_video_vo_bright_sysctl, "I",
489 "current brightness level");
490 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
491 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
492 OID_AUTO, "fullpower",
493 CTLTYPE_INT|CTLFLAG_RW, vo,
494 POWER_PROFILE_PERFORMANCE,
495 acpi_video_vo_presets_sysctl, "I",
496 "preset level for full power mode");
497 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
498 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
500 CTLTYPE_INT|CTLFLAG_RW, vo,
501 POWER_PROFILE_ECONOMY,
502 acpi_video_vo_presets_sysctl, "I",
503 "preset level for economy mode");
504 SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
505 SYSCTL_CHILDREN(vo->vo_sysctl_tree),
507 CTLTYPE_OPAQUE|CTLFLAG_RD, vo, 0,
508 acpi_video_vo_levels_sysctl, "I",
509 "supported brightness levels");
511 kprintf("%s: sysctl node creation failed\n", type);
513 kprintf("%s: softc allocation failed\n", type);
516 kprintf("found %s(%x)", desc, adr & DOD_DEVID_MASK_FULL);
517 kprintf(", idx#%x", adr & DOD_DEVID_MASK_DISPIDX);
518 kprintf(", port#%x", (adr & DOD_DEVID_MASK_DISPPORT) >> 4);
520 kprintf(", detectable by BIOS");
521 if (adr & DOD_NONVGA)
522 kprintf(" (Non-VGA output device whose power "
523 "is related to the VGA device)");
524 kprintf(", head #%d\n",
525 (adr & DOD_HEAD_ID_MASK) >> DOD_HEAD_ID_SHIFT);
531 acpi_video_vo_bind(struct acpi_video_output *vo, ACPI_HANDLE handle)
533 if (vo->vo_levels != NULL)
534 AcpiOsFree(vo->vo_levels);
536 vo->vo_numlevels = vo_get_brightness_levels(handle, &vo->vo_levels);
537 if (vo->vo_numlevels >= 2) {
538 if (vo->vo_fullpower == -1
539 || acpi_video_vo_check_level(vo, vo->vo_fullpower) != 0)
540 /* XXX - can't deal with rebinding... */
541 vo->vo_fullpower = vo->vo_levels[BCL_FULLPOWER];
542 if (vo->vo_economy == -1
543 || acpi_video_vo_check_level(vo, vo->vo_economy) != 0)
544 /* XXX - see above. */
545 vo->vo_economy = vo->vo_levels[BCL_ECONOMY];
550 acpi_video_vo_destroy(struct acpi_video_output *vo)
552 struct acpi_video_output_queue *voqh;
554 if (vo->vo_sysctl_tree != NULL) {
555 vo->vo_sysctl_tree = NULL;
556 sysctl_ctx_free(&vo->vo_sysctl_ctx);
558 if (vo->vo_levels != NULL)
559 AcpiOsFree(vo->vo_levels);
561 switch (vo->adr & DOD_DEVID_MASK) {
562 case DOD_DEVID_MONITOR:
571 case DOD_DEVID_INTDFP:
577 STAILQ_REMOVE(voqh, vo, acpi_video_output, vo_unit.next);
578 kfree(vo, M_ACPIVIDEO);
582 acpi_video_vo_check_level(struct acpi_video_output *vo, int level)
586 if (vo->vo_levels == NULL)
588 for (i = 0; i < vo->vo_numlevels; i++)
589 if (vo->vo_levels[i] == level)
596 acpi_video_vo_active_sysctl(SYSCTL_HANDLER_ARGS)
598 struct acpi_video_output *vo;
601 vo = (struct acpi_video_output *)arg1;
602 if (vo->handle == NULL)
604 lockmgr(&avlock, LK_EXCLUSIVE);
605 state = (vo_get_device_status(vo->handle) & DCS_ACTIVE) ? 1 : 0;
606 err = sysctl_handle_int(oidp, &state, 0, req);
607 if (err != 0 || req->newptr == NULL)
609 vo_set_device_state(vo->handle,
610 DSS_COMMIT | (state ? DSS_ACTIVE : DSS_INACTIVE));
612 lockmgr(&avlock, LK_RELEASE);
618 acpi_video_vo_bright_sysctl(SYSCTL_HANDLER_ARGS)
620 struct acpi_video_output *vo;
621 int level, preset, err;
623 vo = (struct acpi_video_output *)arg1;
624 lockmgr(&avlock, LK_EXCLUSIVE);
625 if (vo->handle == NULL) {
629 if (vo->vo_levels == NULL) {
634 preset = (power_profile_get_state() == POWER_PROFILE_ECONOMY) ?
635 vo->vo_economy : vo->vo_fullpower;
636 level = vo->vo_brightness;
640 err = sysctl_handle_int(oidp, &level, 0, req);
641 if (err != 0 || req->newptr == NULL)
643 if (level < -1 || level > 100) {
648 if (level != -1 && (err = acpi_video_vo_check_level(vo, level)))
650 vo->vo_brightness = level;
651 vo_set_brightness(vo->handle, (level == -1) ? preset : level);
654 lockmgr(&avlock, LK_RELEASE);
659 acpi_video_vo_presets_sysctl(SYSCTL_HANDLER_ARGS)
661 struct acpi_video_output *vo;
662 int i, level, *preset, err;
665 vo = (struct acpi_video_output *)arg1;
666 lockmgr(&avlock, LK_EXCLUSIVE);
667 if (vo->handle == NULL) {
671 if (vo->vo_levels == NULL) {
675 preset = (arg2 == POWER_PROFILE_ECONOMY) ?
676 &vo->vo_economy : &vo->vo_fullpower;
678 err = sysctl_handle_int(oidp, &level, 0, req);
679 if (err != 0 || req->newptr == NULL)
681 if (level < -1 || level > 100) {
686 i = (arg2 == POWER_PROFILE_ECONOMY) ?
687 BCL_ECONOMY : BCL_FULLPOWER;
688 level = vo->vo_levels[i];
689 } else if ((err = acpi_video_vo_check_level(vo, level)) != 0)
692 if (vo->vo_brightness == -1 && (power_profile_get_state() == arg2))
693 vo_set_brightness(vo->handle, level);
697 lockmgr(&avlock, LK_RELEASE);
703 acpi_video_vo_levels_sysctl(SYSCTL_HANDLER_ARGS)
705 struct acpi_video_output *vo;
708 vo = (struct acpi_video_output *)arg1;
709 lockmgr(&avlock, LK_EXCLUSIVE);
710 if (vo->vo_levels == NULL) {
714 if (req->newptr != NULL) {
718 err = sysctl_handle_opaque(oidp, vo->vo_levels,
719 vo->vo_numlevels * sizeof(*vo->vo_levels), req);
722 lockmgr(&avlock, LK_RELEASE);
727 vid_set_switch_policy(ACPI_HANDLE handle, UINT32 policy)
731 status = acpi_SetInteger(handle, "_DOS", policy);
732 if (ACPI_FAILURE(status))
733 kprintf("can't evaluate %s._DOS - %s\n",
734 acpi_name(handle), AcpiFormatException(status));
737 struct enum_callback_arg {
738 void (*callback)(ACPI_HANDLE, UINT32, void *);
740 ACPI_OBJECT *dod_pkg;
745 vid_enum_outputs_subr(ACPI_HANDLE handle, UINT32 level __unused,
746 void *context, void **retp __unused)
750 struct enum_callback_arg *argset;
754 status = acpi_GetInteger(handle, "_ADR", &adr);
755 if (ACPI_FAILURE(status))
758 for (i = 0; i < argset->dod_pkg->Package.Count; i++) {
759 if (acpi_PkgInt32(argset->dod_pkg, i, &val) == 0 &&
760 (val & DOD_DEVID_MASK_FULL) == adr) {
761 argset->callback(handle, val, argset->context);
770 vid_enum_outputs(ACPI_HANDLE handle,
771 void (*callback)(ACPI_HANDLE, UINT32, void *), void *context)
776 struct enum_callback_arg argset;
778 dod_buf.Length = ACPI_ALLOCATE_BUFFER;
779 dod_buf.Pointer = NULL;
780 status = AcpiEvaluateObject(handle, "_DOD", NULL, &dod_buf);
781 if (ACPI_FAILURE(status)) {
782 if (status != AE_NOT_FOUND)
783 kprintf("can't evaluate %s._DOD - %s\n",
784 acpi_name(handle), AcpiFormatException(status));
788 res = (ACPI_OBJECT *)dod_buf.Pointer;
789 if (!ACPI_PKG_VALID(res, 1)) {
790 kprintf("evaluation of %s._DOD makes no sense\n",
795 if (callback == NULL) {
796 argset.count = res->Package.Count;
799 argset.callback = callback;
800 argset.context = context;
801 argset.dod_pkg = res;
803 status = AcpiWalkNamespace(ACPI_TYPE_DEVICE, handle, 1,
804 vid_enum_outputs_subr, NULL, &argset, NULL);
805 if (ACPI_FAILURE(status))
806 kprintf("failed walking down %s - %s\n",
807 acpi_name(handle), AcpiFormatException(status));
809 if (dod_buf.Pointer != NULL)
810 AcpiOsFree(dod_buf.Pointer);
811 return (argset.count);
815 vo_get_brightness_levels(ACPI_HANDLE handle, int **levelp)
820 int num, i, n, *levels;
823 bcl_buf.Length = ACPI_ALLOCATE_BUFFER;
824 bcl_buf.Pointer = NULL;
825 status = AcpiEvaluateObject(handle, "_BCL", NULL, &bcl_buf);
826 if (ACPI_FAILURE(status)) {
827 if (status != AE_NOT_FOUND)
828 kprintf("can't evaluate %s._BCL - %s\n",
829 acpi_name(handle), AcpiFormatException(status));
833 res = (ACPI_OBJECT *)bcl_buf.Pointer;
834 if (!ACPI_PKG_VALID(res, 2)) {
835 kprintf("evaluation of %s._BCL makes no sense\n",
840 num = res->Package.Count;
843 levels = AcpiOsAllocate(num * sizeof(*levels));
844 if (levels == NULL) {
848 for (i = 0, n = 0; i < num; i++)
849 if (acpi_PkgInt32(res, i, &levels[n]) == 0)
859 if (bcl_buf.Pointer != NULL)
860 AcpiOsFree(bcl_buf.Pointer);
866 vo_set_brightness(ACPI_HANDLE handle, int level)
870 status = acpi_SetInteger(handle, "_BCM", level);
871 if (ACPI_FAILURE(status))
872 kprintf("can't evaluate %s._BCM - %s\n",
873 acpi_name(handle), AcpiFormatException(status));
877 vo_get_device_status(ACPI_HANDLE handle)
883 status = acpi_GetInteger(handle, "_DCS", &dcs);
884 if (ACPI_FAILURE(status))
885 kprintf("can't evaluate %s._DCS - %s\n",
886 acpi_name(handle), AcpiFormatException(status));
892 vo_get_graphics_state(ACPI_HANDLE handle)
898 status = acpi_GetInteger(handle, "_DGS", &dgs);
899 if (ACPI_FAILURE(status))
900 kprintf("can't evaluate %s._DGS - %s\n",
901 acpi_name(handle), AcpiFormatException(status));
907 vo_set_device_state(ACPI_HANDLE handle, UINT32 state)
911 status = acpi_SetInteger(handle, "_DSS", state);
912 if (ACPI_FAILURE(status))
913 kprintf("can't evaluate %s._DSS - %s\n",
914 acpi_name(handle), AcpiFormatException(status));