2004-03-01 08:12:56 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002-2003 Taku YAMAMOTO <taku@cent.saitama-u.ac.jp>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $Id: acpi_vid.c,v 1.4 2003/10/13 10:07:36 taku Exp $
|
|
|
|
*/
|
|
|
|
|
2005-03-02 09:22:34 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2004-03-01 08:12:56 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.h>
|
2004-03-01 08:12:56 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/power.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
2009-06-05 18:44:36 +00:00
|
|
|
#include <contrib/dev/acpica/include/acpi.h>
|
|
|
|
|
2004-03-01 08:12:56 +00:00
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
|
|
|
|
/* ACPI video extension driver. */
|
|
|
|
struct acpi_video_output {
|
|
|
|
ACPI_HANDLE handle;
|
|
|
|
UINT32 adr;
|
|
|
|
STAILQ_ENTRY(acpi_video_output) vo_next;
|
|
|
|
struct {
|
|
|
|
int num;
|
|
|
|
STAILQ_ENTRY(acpi_video_output) next;
|
|
|
|
} vo_unit;
|
|
|
|
int vo_brightness;
|
|
|
|
int vo_fullpower;
|
|
|
|
int vo_economy;
|
|
|
|
int vo_numlevels;
|
|
|
|
int *vo_levels;
|
|
|
|
struct sysctl_ctx_list vo_sysctl_ctx;
|
|
|
|
struct sysctl_oid *vo_sysctl_tree;
|
|
|
|
};
|
|
|
|
|
|
|
|
STAILQ_HEAD(acpi_video_output_queue, acpi_video_output);
|
|
|
|
|
|
|
|
struct acpi_video_softc {
|
|
|
|
device_t device;
|
|
|
|
ACPI_HANDLE handle;
|
2004-07-22 05:18:05 +00:00
|
|
|
struct acpi_video_output_queue vid_outputs;
|
2004-03-01 08:12:56 +00:00
|
|
|
eventhandler_tag vid_pwr_evh;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* interfaces */
|
|
|
|
static int acpi_video_modevent(struct module*, int, void *);
|
2005-12-20 22:42:16 +00:00
|
|
|
static void acpi_video_identify(driver_t *driver, device_t parent);
|
2004-03-01 08:12:56 +00:00
|
|
|
static int acpi_video_probe(device_t);
|
|
|
|
static int acpi_video_attach(device_t);
|
|
|
|
static int acpi_video_detach(device_t);
|
2012-06-17 16:19:09 +00:00
|
|
|
static int acpi_video_resume(device_t);
|
2004-03-01 08:12:56 +00:00
|
|
|
static int acpi_video_shutdown(device_t);
|
|
|
|
static void acpi_video_notify_handler(ACPI_HANDLE, UINT32, void *);
|
|
|
|
static void acpi_video_power_profile(void *);
|
|
|
|
static void acpi_video_bind_outputs(struct acpi_video_softc *);
|
2004-07-22 05:18:05 +00:00
|
|
|
static struct acpi_video_output *acpi_video_vo_init(UINT32);
|
2004-03-01 08:12:56 +00:00
|
|
|
static void acpi_video_vo_bind(struct acpi_video_output *, ACPI_HANDLE);
|
|
|
|
static void acpi_video_vo_destroy(struct acpi_video_output *);
|
|
|
|
static int acpi_video_vo_check_level(struct acpi_video_output *, int);
|
2010-02-13 02:24:23 +00:00
|
|
|
static void acpi_video_vo_notify_handler(ACPI_HANDLE, UINT32, void *);
|
2004-03-01 08:12:56 +00:00
|
|
|
static int acpi_video_vo_active_sysctl(SYSCTL_HANDLER_ARGS);
|
|
|
|
static int acpi_video_vo_bright_sysctl(SYSCTL_HANDLER_ARGS);
|
|
|
|
static int acpi_video_vo_presets_sysctl(SYSCTL_HANDLER_ARGS);
|
|
|
|
static int acpi_video_vo_levels_sysctl(SYSCTL_HANDLER_ARGS);
|
|
|
|
|
|
|
|
/* operations */
|
|
|
|
static void vid_set_switch_policy(ACPI_HANDLE, UINT32);
|
|
|
|
static int vid_enum_outputs(ACPI_HANDLE,
|
2004-07-22 05:18:05 +00:00
|
|
|
void(*)(ACPI_HANDLE, UINT32, void *), void *);
|
2004-08-13 06:22:20 +00:00
|
|
|
static int vo_get_brightness_levels(ACPI_HANDLE, int **);
|
2010-02-13 02:24:23 +00:00
|
|
|
static int vo_get_brightness(ACPI_HANDLE);
|
2004-03-01 08:12:56 +00:00
|
|
|
static void vo_set_brightness(ACPI_HANDLE, int);
|
|
|
|
static UINT32 vo_get_device_status(ACPI_HANDLE);
|
2004-08-13 06:22:20 +00:00
|
|
|
static UINT32 vo_get_graphics_state(ACPI_HANDLE);
|
2004-03-01 08:12:56 +00:00
|
|
|
static void vo_set_device_state(ACPI_HANDLE, UINT32);
|
|
|
|
|
|
|
|
/* events */
|
2010-02-15 20:46:01 +00:00
|
|
|
#define VID_NOTIFY_SWITCHED 0x80
|
|
|
|
#define VID_NOTIFY_REPROBE 0x81
|
|
|
|
#define VID_NOTIFY_CYCLE_BRN 0x85
|
2010-02-13 02:24:23 +00:00
|
|
|
#define VID_NOTIFY_INC_BRN 0x86
|
|
|
|
#define VID_NOTIFY_DEC_BRN 0x87
|
2010-02-15 20:46:01 +00:00
|
|
|
#define VID_NOTIFY_ZERO_BRN 0x88
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
/* _DOS (Enable/Disable Output Switching) argument bits */
|
2010-02-15 20:46:01 +00:00
|
|
|
#define DOS_SWITCH_MASK 3
|
|
|
|
#define DOS_SWITCH_BY_OSPM 0
|
|
|
|
#define DOS_SWITCH_BY_BIOS 1
|
|
|
|
#define DOS_SWITCH_LOCKED 2
|
|
|
|
#define DOS_BRIGHTNESS_BY_OSPM (1 << 2)
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
/* _DOD and subdev's _ADR */
|
2010-02-15 20:46:01 +00:00
|
|
|
#define DOD_DEVID_MASK 0x0f00
|
|
|
|
#define DOD_DEVID_MASK_FULL 0xffff
|
|
|
|
#define DOD_DEVID_MASK_DISPIDX 0x000f
|
|
|
|
#define DOD_DEVID_MASK_DISPPORT 0x00f0
|
|
|
|
#define DOD_DEVID_MONITOR 0x0100
|
|
|
|
#define DOD_DEVID_LCD 0x0110
|
|
|
|
#define DOD_DEVID_TV 0x0200
|
|
|
|
#define DOD_DEVID_EXT 0x0300
|
|
|
|
#define DOD_DEVID_INTDFP 0x0400
|
|
|
|
#define DOD_BIOS (1 << 16)
|
|
|
|
#define DOD_NONVGA (1 << 17)
|
|
|
|
#define DOD_HEAD_ID_SHIFT 18
|
|
|
|
#define DOD_HEAD_ID_BITS 3
|
|
|
|
#define DOD_HEAD_ID_MASK \
|
2004-07-22 05:18:05 +00:00
|
|
|
(((1 << DOD_HEAD_ID_BITS) - 1) << DOD_HEAD_ID_SHIFT)
|
2010-02-15 20:46:01 +00:00
|
|
|
#define DOD_DEVID_SCHEME_STD (1 << 31)
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
/* _BCL related constants */
|
2010-02-15 20:46:01 +00:00
|
|
|
#define BCL_FULLPOWER 0
|
|
|
|
#define BCL_ECONOMY 1
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
/* _DCS (Device Currrent Status) value bits and masks. */
|
2010-02-15 20:46:01 +00:00
|
|
|
#define DCS_EXISTS (1 << 0)
|
|
|
|
#define DCS_ACTIVE (1 << 1)
|
|
|
|
#define DCS_READY (1 << 2)
|
|
|
|
#define DCS_FUNCTIONAL (1 << 3)
|
|
|
|
#define DCS_ATTACHED (1 << 4)
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
/* _DSS (Device Set Status) argument bits and masks. */
|
2010-02-15 20:46:01 +00:00
|
|
|
#define DSS_INACTIVE 0
|
|
|
|
#define DSS_ACTIVE (1 << 0)
|
|
|
|
#define DSS_SETNEXT (1 << 30)
|
|
|
|
#define DSS_COMMIT (1 << 31)
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
static device_method_t acpi_video_methods[] = {
|
2005-12-20 22:42:16 +00:00
|
|
|
DEVMETHOD(device_identify, acpi_video_identify),
|
2004-03-01 08:12:56 +00:00
|
|
|
DEVMETHOD(device_probe, acpi_video_probe),
|
|
|
|
DEVMETHOD(device_attach, acpi_video_attach),
|
|
|
|
DEVMETHOD(device_detach, acpi_video_detach),
|
2012-06-17 16:19:09 +00:00
|
|
|
DEVMETHOD(device_resume, acpi_video_resume),
|
2004-03-01 08:12:56 +00:00
|
|
|
DEVMETHOD(device_shutdown, acpi_video_shutdown),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t acpi_video_driver = {
|
|
|
|
"acpi_video",
|
|
|
|
acpi_video_methods,
|
|
|
|
sizeof(struct acpi_video_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t acpi_video_devclass;
|
|
|
|
|
2005-12-20 22:42:16 +00:00
|
|
|
DRIVER_MODULE(acpi_video, vgapci, acpi_video_driver, acpi_video_devclass,
|
2004-03-01 08:12:56 +00:00
|
|
|
acpi_video_modevent, NULL);
|
2004-04-08 16:45:12 +00:00
|
|
|
MODULE_DEPEND(acpi_video, acpi, 1, 1, 1);
|
2004-03-01 08:12:56 +00:00
|
|
|
|
2004-07-22 05:18:05 +00:00
|
|
|
static struct sysctl_ctx_list acpi_video_sysctl_ctx;
|
|
|
|
static struct sysctl_oid *acpi_video_sysctl_tree;
|
2006-08-10 13:18:02 +00:00
|
|
|
static struct acpi_video_output_queue crt_units, tv_units,
|
|
|
|
ext_units, lcd_units, other_units;
|
2004-03-01 08:12:56 +00:00
|
|
|
|
2009-09-30 17:05:26 +00:00
|
|
|
/*
|
|
|
|
* The 'video' lock protects the hierarchy of video output devices
|
|
|
|
* (the video "bus"). The 'video_output' lock protects per-output
|
|
|
|
* data is equivalent to a softc lock for each video output.
|
|
|
|
*/
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_DECL(video, "ACPI video");
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_DECL(video_output, "ACPI video output");
|
2011-11-07 06:44:47 +00:00
|
|
|
static MALLOC_DEFINE(M_ACPIVIDEO, "acpivideo", "ACPI video extension");
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_video_modevent(struct module *mod __unused, int evt, void *cookie __unused)
|
|
|
|
{
|
2004-11-09 04:41:30 +00:00
|
|
|
int err;
|
2004-03-01 08:12:56 +00:00
|
|
|
|
2004-11-09 04:41:30 +00:00
|
|
|
err = 0;
|
2004-03-01 08:12:56 +00:00
|
|
|
switch (evt) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
sysctl_ctx_init(&acpi_video_sysctl_ctx);
|
|
|
|
STAILQ_INIT(&crt_units);
|
|
|
|
STAILQ_INIT(&tv_units);
|
2006-08-10 13:18:02 +00:00
|
|
|
STAILQ_INIT(&ext_units);
|
|
|
|
STAILQ_INIT(&lcd_units);
|
2004-03-01 08:12:56 +00:00
|
|
|
STAILQ_INIT(&other_units);
|
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
sysctl_ctx_free(&acpi_video_sysctl_ctx);
|
2004-07-16 16:59:32 +00:00
|
|
|
acpi_video_sysctl_tree = NULL;
|
2004-03-01 08:12:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2005-12-20 22:42:16 +00:00
|
|
|
static void
|
|
|
|
acpi_video_identify(driver_t *driver, device_t parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (device_find_child(parent, "acpi_video", -1) == NULL)
|
|
|
|
device_add_child(parent, "acpi_video", -1);
|
|
|
|
}
|
|
|
|
|
2004-03-01 08:12:56 +00:00
|
|
|
static int
|
|
|
|
acpi_video_probe(device_t dev)
|
|
|
|
{
|
2004-07-22 05:18:05 +00:00
|
|
|
ACPI_HANDLE devh, h;
|
|
|
|
ACPI_OBJECT_TYPE t_dos;
|
2004-03-01 08:12:56 +00:00
|
|
|
|
2004-07-22 05:18:05 +00:00
|
|
|
devh = acpi_get_handle(dev);
|
|
|
|
if (acpi_disabled("video") ||
|
|
|
|
ACPI_FAILURE(AcpiGetHandle(devh, "_DOD", &h)) ||
|
|
|
|
ACPI_FAILURE(AcpiGetHandle(devh, "_DOS", &h)) ||
|
|
|
|
ACPI_FAILURE(AcpiGetType(h, &t_dos)) ||
|
|
|
|
t_dos != ACPI_TYPE_METHOD)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
device_set_desc(dev, "ACPI video extension");
|
|
|
|
return (0);
|
2004-03-01 08:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_video_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_softc *acpi_sc;
|
|
|
|
struct acpi_video_softc *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
2004-07-16 16:59:32 +00:00
|
|
|
acpi_sc = devclass_get_softc(devclass_find("acpi"), 0);
|
2004-07-24 17:51:22 +00:00
|
|
|
if (acpi_sc == NULL)
|
|
|
|
return (ENXIO);
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_BEGIN(video);
|
2004-07-24 17:51:22 +00:00
|
|
|
if (acpi_video_sysctl_tree == NULL) {
|
2004-03-01 08:12:56 +00:00
|
|
|
acpi_video_sysctl_tree = SYSCTL_ADD_NODE(&acpi_video_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
|
|
|
|
OID_AUTO, "video", CTLFLAG_RD, 0,
|
|
|
|
"video extension control");
|
|
|
|
}
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_END(video);
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
sc->device = dev;
|
|
|
|
sc->handle = acpi_get_handle(dev);
|
|
|
|
STAILQ_INIT(&sc->vid_outputs);
|
|
|
|
|
|
|
|
AcpiInstallNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
|
|
|
|
acpi_video_notify_handler, sc);
|
|
|
|
sc->vid_pwr_evh = EVENTHANDLER_REGISTER(power_profile_change,
|
|
|
|
acpi_video_power_profile, sc, 0);
|
|
|
|
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_BEGIN(video);
|
2004-03-01 08:12:56 +00:00
|
|
|
acpi_video_bind_outputs(sc);
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_END(video);
|
2004-11-09 04:41:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Notify the BIOS that we want to switch both active outputs and
|
|
|
|
* brightness levels.
|
|
|
|
*/
|
|
|
|
vid_set_switch_policy(sc->handle, DOS_SWITCH_BY_OSPM |
|
2010-02-15 20:46:01 +00:00
|
|
|
DOS_BRIGHTNESS_BY_OSPM);
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
acpi_video_power_profile(sc);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_video_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_video_softc *sc;
|
|
|
|
struct acpi_video_output *vo, *vn;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
vid_set_switch_policy(sc->handle, DOS_SWITCH_BY_BIOS);
|
|
|
|
EVENTHANDLER_DEREGISTER(power_profile_change, sc->vid_pwr_evh);
|
|
|
|
AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
|
|
|
|
acpi_video_notify_handler);
|
|
|
|
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_BEGIN(video);
|
2009-09-23 15:39:54 +00:00
|
|
|
STAILQ_FOREACH_SAFE(vo, &sc->vid_outputs, vo_next, vn) {
|
2004-03-01 08:12:56 +00:00
|
|
|
acpi_video_vo_destroy(vo);
|
|
|
|
}
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_END(video);
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-06-17 16:19:09 +00:00
|
|
|
static int
|
|
|
|
acpi_video_resume(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_video_softc *sc;
|
|
|
|
struct acpi_video_output *vo, *vn;
|
|
|
|
int level;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
/* Restore brightness level */
|
|
|
|
ACPI_SERIAL_BEGIN(video);
|
|
|
|
ACPI_SERIAL_BEGIN(video_output);
|
|
|
|
STAILQ_FOREACH_SAFE(vo, &sc->vid_outputs, vo_next, vn) {
|
|
|
|
if ((vo->adr & DOD_DEVID_MASK_FULL) != DOD_DEVID_LCD &&
|
|
|
|
(vo->adr & DOD_DEVID_MASK) != DOD_DEVID_INTDFP)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((vo_get_device_status(vo->handle) & DCS_ACTIVE) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
level = vo_get_brightness(vo->handle);
|
|
|
|
if (level != -1)
|
|
|
|
vo_set_brightness(vo->handle, level);
|
|
|
|
}
|
|
|
|
ACPI_SERIAL_END(video_output);
|
|
|
|
ACPI_SERIAL_END(video);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-03-01 08:12:56 +00:00
|
|
|
static int
|
|
|
|
acpi_video_shutdown(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_video_softc *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
vid_set_switch_policy(sc->handle, DOS_SWITCH_BY_BIOS);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-11-09 04:41:30 +00:00
|
|
|
acpi_video_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
|
2004-03-01 08:12:56 +00:00
|
|
|
{
|
|
|
|
struct acpi_video_softc *sc;
|
2004-07-24 17:51:22 +00:00
|
|
|
struct acpi_video_output *vo, *vo_tmp;
|
2004-11-09 04:41:30 +00:00
|
|
|
ACPI_HANDLE lasthand;
|
|
|
|
UINT32 dcs, dss, dss_p;
|
2004-03-01 08:12:56 +00:00
|
|
|
|
2004-11-09 04:41:30 +00:00
|
|
|
sc = (struct acpi_video_softc *)context;
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
switch (notify) {
|
|
|
|
case VID_NOTIFY_SWITCHED:
|
2004-11-09 04:41:30 +00:00
|
|
|
dss_p = 0;
|
|
|
|
lasthand = NULL;
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_BEGIN(video);
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_BEGIN(video_output);
|
2004-03-01 08:12:56 +00:00
|
|
|
STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next) {
|
2004-08-13 06:22:20 +00:00
|
|
|
dss = vo_get_graphics_state(vo->handle);
|
2004-03-01 08:12:56 +00:00
|
|
|
dcs = vo_get_device_status(vo->handle);
|
|
|
|
if (!(dcs & DCS_READY))
|
|
|
|
dss = DSS_INACTIVE;
|
|
|
|
if (((dcs & DCS_ACTIVE) && dss == DSS_INACTIVE) ||
|
|
|
|
(!(dcs & DCS_ACTIVE) && dss == DSS_ACTIVE)) {
|
|
|
|
if (lasthand != NULL)
|
|
|
|
vo_set_device_state(lasthand, dss_p);
|
|
|
|
dss_p = dss;
|
|
|
|
lasthand = vo->handle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lasthand != NULL)
|
|
|
|
vo_set_device_state(lasthand, dss_p|DSS_COMMIT);
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_END(video_output);
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_END(video);
|
2004-03-01 08:12:56 +00:00
|
|
|
break;
|
|
|
|
case VID_NOTIFY_REPROBE:
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_BEGIN(video);
|
2004-03-01 08:12:56 +00:00
|
|
|
STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next)
|
|
|
|
vo->handle = NULL;
|
|
|
|
acpi_video_bind_outputs(sc);
|
2004-07-24 17:51:22 +00:00
|
|
|
STAILQ_FOREACH_SAFE(vo, &sc->vid_outputs, vo_next, vo_tmp) {
|
2004-03-01 08:12:56 +00:00
|
|
|
if (vo->handle == NULL) {
|
|
|
|
STAILQ_REMOVE(&sc->vid_outputs, vo,
|
2004-11-09 04:41:30 +00:00
|
|
|
acpi_video_output, vo_next);
|
2004-03-01 08:12:56 +00:00
|
|
|
acpi_video_vo_destroy(vo);
|
|
|
|
}
|
|
|
|
}
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_END(video);
|
2004-03-01 08:12:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-11-09 04:41:30 +00:00
|
|
|
device_printf(sc->device, "unknown notify event 0x%x\n",
|
|
|
|
notify);
|
2004-03-01 08:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_video_power_profile(void *context)
|
|
|
|
{
|
|
|
|
int state;
|
|
|
|
struct acpi_video_softc *sc;
|
|
|
|
struct acpi_video_output *vo;
|
|
|
|
|
|
|
|
sc = context;
|
|
|
|
state = power_profile_get_state();
|
|
|
|
if (state != POWER_PROFILE_PERFORMANCE &&
|
|
|
|
state != POWER_PROFILE_ECONOMY)
|
|
|
|
return;
|
|
|
|
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_BEGIN(video);
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_BEGIN(video_output);
|
2004-03-01 08:12:56 +00:00
|
|
|
STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next) {
|
|
|
|
if (vo->vo_levels != NULL && vo->vo_brightness == -1)
|
|
|
|
vo_set_brightness(vo->handle,
|
2004-11-09 04:41:30 +00:00
|
|
|
state == POWER_PROFILE_ECONOMY ?
|
|
|
|
vo->vo_economy : vo->vo_fullpower);
|
2004-03-01 08:12:56 +00:00
|
|
|
}
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_END(video_output);
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_END(video);
|
2004-03-01 08:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_video_bind_outputs_subr(ACPI_HANDLE handle, UINT32 adr, void *context)
|
|
|
|
{
|
|
|
|
struct acpi_video_softc *sc;
|
|
|
|
struct acpi_video_output *vo;
|
|
|
|
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_ASSERT(video);
|
2004-03-01 08:12:56 +00:00
|
|
|
sc = context;
|
|
|
|
|
|
|
|
STAILQ_FOREACH(vo, &sc->vid_outputs, vo_next) {
|
|
|
|
if (vo->adr == adr) {
|
|
|
|
acpi_video_vo_bind(vo, handle);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vo = acpi_video_vo_init(adr);
|
|
|
|
if (vo != NULL) {
|
|
|
|
acpi_video_vo_bind(vo, handle);
|
|
|
|
STAILQ_INSERT_TAIL(&sc->vid_outputs, vo, vo_next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_video_bind_outputs(struct acpi_video_softc *sc)
|
|
|
|
{
|
|
|
|
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_ASSERT(video);
|
2004-03-01 08:12:56 +00:00
|
|
|
vid_enum_outputs(sc->handle, acpi_video_bind_outputs_subr, sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct acpi_video_output *
|
|
|
|
acpi_video_vo_init(UINT32 adr)
|
|
|
|
{
|
|
|
|
struct acpi_video_output *vn, *vo, *vp;
|
|
|
|
int n, x;
|
2004-11-09 04:41:30 +00:00
|
|
|
char name[8], env[32];
|
2004-03-01 08:12:56 +00:00
|
|
|
const char *type, *desc;
|
|
|
|
struct acpi_video_output_queue *voqh;
|
|
|
|
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_ASSERT(video);
|
2006-08-10 13:18:02 +00:00
|
|
|
|
2004-03-01 08:12:56 +00:00
|
|
|
switch (adr & DOD_DEVID_MASK) {
|
|
|
|
case DOD_DEVID_MONITOR:
|
2006-08-10 13:18:02 +00:00
|
|
|
if ((adr & DOD_DEVID_MASK_FULL) == DOD_DEVID_LCD) {
|
|
|
|
/* DOD_DEVID_LCD is a common, backward compatible ID */
|
|
|
|
desc = "Internal/Integrated Digital Flat Panel";
|
|
|
|
type = "lcd";
|
|
|
|
voqh = &lcd_units;
|
|
|
|
} else {
|
|
|
|
desc = "VGA CRT or VESA Compatible Analog Monitor";
|
|
|
|
type = "crt";
|
|
|
|
voqh = &crt_units;
|
|
|
|
}
|
2004-03-01 08:12:56 +00:00
|
|
|
break;
|
|
|
|
case DOD_DEVID_TV:
|
2006-08-10 13:18:02 +00:00
|
|
|
desc = "TV/HDTV or Analog-Video Monitor";
|
2004-03-01 08:12:56 +00:00
|
|
|
type = "tv";
|
|
|
|
voqh = &tv_units;
|
|
|
|
break;
|
2006-08-10 13:18:02 +00:00
|
|
|
case DOD_DEVID_EXT:
|
|
|
|
desc = "External Digital Monitor";
|
|
|
|
type = "ext";
|
|
|
|
voqh = &ext_units;
|
|
|
|
break;
|
|
|
|
case DOD_DEVID_INTDFP:
|
|
|
|
desc = "Internal/Integrated Digital Flat Panel";
|
|
|
|
type = "lcd";
|
|
|
|
voqh = &lcd_units;
|
|
|
|
break;
|
2004-03-01 08:12:56 +00:00
|
|
|
default:
|
|
|
|
desc = "unknown output";
|
|
|
|
type = "out";
|
|
|
|
voqh = &other_units;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = 0;
|
2010-06-11 19:53:42 +00:00
|
|
|
vp = NULL;
|
2004-03-01 08:12:56 +00:00
|
|
|
STAILQ_FOREACH(vn, voqh, vo_unit.next) {
|
|
|
|
if (vn->vo_unit.num != n)
|
|
|
|
break;
|
|
|
|
vp = vn;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2004-07-22 05:18:05 +00:00
|
|
|
snprintf(name, sizeof(name), "%s%d", type, n);
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
vo = malloc(sizeof(*vo), M_ACPIVIDEO, M_NOWAIT);
|
|
|
|
if (vo != NULL) {
|
|
|
|
vo->handle = NULL;
|
|
|
|
vo->adr = adr;
|
|
|
|
vo->vo_unit.num = n;
|
|
|
|
vo->vo_brightness = -1;
|
|
|
|
vo->vo_fullpower = -1; /* TODO: override with tunables */
|
|
|
|
vo->vo_economy = -1;
|
|
|
|
vo->vo_numlevels = 0;
|
|
|
|
vo->vo_levels = NULL;
|
2004-11-09 04:41:30 +00:00
|
|
|
snprintf(env, sizeof(env), "hw.acpi.video.%s.fullpower", name);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (getenv_int(env, &x))
|
|
|
|
vo->vo_fullpower = x;
|
2004-11-09 04:41:30 +00:00
|
|
|
snprintf(env, sizeof(env), "hw.acpi.video.%s.economy", name);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (getenv_int(env, &x))
|
|
|
|
vo->vo_economy = x;
|
|
|
|
|
|
|
|
sysctl_ctx_init(&vo->vo_sysctl_ctx);
|
|
|
|
if (vp != NULL)
|
|
|
|
STAILQ_INSERT_AFTER(voqh, vp, vo, vo_unit.next);
|
|
|
|
else
|
|
|
|
STAILQ_INSERT_TAIL(voqh, vo, vo_unit.next);
|
|
|
|
if (acpi_video_sysctl_tree != NULL)
|
|
|
|
vo->vo_sysctl_tree =
|
|
|
|
SYSCTL_ADD_NODE(&vo->vo_sysctl_ctx,
|
2004-07-22 05:18:05 +00:00
|
|
|
SYSCTL_CHILDREN(acpi_video_sysctl_tree),
|
|
|
|
OID_AUTO, name, CTLFLAG_RD, 0, desc);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (vo->vo_sysctl_tree != NULL) {
|
|
|
|
SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
|
2004-07-22 05:18:05 +00:00
|
|
|
SYSCTL_CHILDREN(vo->vo_sysctl_tree),
|
|
|
|
OID_AUTO, "active",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RW, vo, 0,
|
|
|
|
acpi_video_vo_active_sysctl, "I",
|
|
|
|
"current activity of this device");
|
2004-03-01 08:12:56 +00:00
|
|
|
SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
|
2004-07-22 05:18:05 +00:00
|
|
|
SYSCTL_CHILDREN(vo->vo_sysctl_tree),
|
|
|
|
OID_AUTO, "brightness",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RW, vo, 0,
|
|
|
|
acpi_video_vo_bright_sysctl, "I",
|
|
|
|
"current brightness level");
|
2004-03-01 08:12:56 +00:00
|
|
|
SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
|
2004-07-22 05:18:05 +00:00
|
|
|
SYSCTL_CHILDREN(vo->vo_sysctl_tree),
|
|
|
|
OID_AUTO, "fullpower",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RW, vo,
|
|
|
|
POWER_PROFILE_PERFORMANCE,
|
|
|
|
acpi_video_vo_presets_sysctl, "I",
|
|
|
|
"preset level for full power mode");
|
2004-03-01 08:12:56 +00:00
|
|
|
SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
|
2004-07-22 05:18:05 +00:00
|
|
|
SYSCTL_CHILDREN(vo->vo_sysctl_tree),
|
|
|
|
OID_AUTO, "economy",
|
|
|
|
CTLTYPE_INT|CTLFLAG_RW, vo,
|
|
|
|
POWER_PROFILE_ECONOMY,
|
|
|
|
acpi_video_vo_presets_sysctl, "I",
|
|
|
|
"preset level for economy mode");
|
2004-03-01 08:12:56 +00:00
|
|
|
SYSCTL_ADD_PROC(&vo->vo_sysctl_ctx,
|
2004-07-22 05:18:05 +00:00
|
|
|
SYSCTL_CHILDREN(vo->vo_sysctl_tree),
|
|
|
|
OID_AUTO, "levels",
|
2011-01-19 00:57:58 +00:00
|
|
|
CTLTYPE_INT | CTLFLAG_RD, vo, 0,
|
2004-07-22 05:18:05 +00:00
|
|
|
acpi_video_vo_levels_sysctl, "I",
|
|
|
|
"supported brightness levels");
|
2004-03-01 08:12:56 +00:00
|
|
|
} else
|
|
|
|
printf("%s: sysctl node creation failed\n", type);
|
|
|
|
} else
|
|
|
|
printf("%s: softc allocation failed\n", type);
|
|
|
|
|
|
|
|
if (bootverbose) {
|
2006-08-10 13:18:02 +00:00
|
|
|
printf("found %s(%x)", desc, adr & DOD_DEVID_MASK_FULL);
|
|
|
|
printf(", idx#%x", adr & DOD_DEVID_MASK_DISPIDX);
|
|
|
|
printf(", port#%x", (adr & DOD_DEVID_MASK_DISPPORT) >> 4);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (adr & DOD_BIOS)
|
|
|
|
printf(", detectable by BIOS");
|
|
|
|
if (adr & DOD_NONVGA)
|
2006-08-10 13:18:02 +00:00
|
|
|
printf(" (Non-VGA output device whose power "
|
|
|
|
"is related to the VGA device)");
|
2004-03-01 08:12:56 +00:00
|
|
|
printf(", head #%d\n",
|
2006-08-10 13:18:02 +00:00
|
|
|
(adr & DOD_HEAD_ID_MASK) >> DOD_HEAD_ID_SHIFT);
|
2004-03-01 08:12:56 +00:00
|
|
|
}
|
2004-07-22 05:18:05 +00:00
|
|
|
return (vo);
|
2004-03-01 08:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_video_vo_bind(struct acpi_video_output *vo, ACPI_HANDLE handle)
|
|
|
|
{
|
|
|
|
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_BEGIN(video_output);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (vo->vo_levels != NULL)
|
|
|
|
AcpiOsFree(vo->vo_levels);
|
|
|
|
vo->handle = handle;
|
2004-08-13 06:22:20 +00:00
|
|
|
vo->vo_numlevels = vo_get_brightness_levels(handle, &vo->vo_levels);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (vo->vo_numlevels >= 2) {
|
|
|
|
if (vo->vo_fullpower == -1
|
|
|
|
|| acpi_video_vo_check_level(vo, vo->vo_fullpower) != 0)
|
|
|
|
/* XXX - can't deal with rebinding... */
|
|
|
|
vo->vo_fullpower = vo->vo_levels[BCL_FULLPOWER];
|
|
|
|
if (vo->vo_economy == -1
|
|
|
|
|| acpi_video_vo_check_level(vo, vo->vo_economy) != 0)
|
|
|
|
/* XXX - see above. */
|
|
|
|
vo->vo_economy = vo->vo_levels[BCL_ECONOMY];
|
|
|
|
}
|
2010-02-13 02:24:23 +00:00
|
|
|
if (vo->vo_levels != NULL)
|
2010-03-10 18:30:55 +00:00
|
|
|
AcpiInstallNotifyHandler(handle, ACPI_DEVICE_NOTIFY,
|
|
|
|
acpi_video_vo_notify_handler, vo);
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_END(video_output);
|
2004-03-01 08:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_video_vo_destroy(struct acpi_video_output *vo)
|
|
|
|
{
|
|
|
|
struct acpi_video_output_queue *voqh;
|
|
|
|
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_ASSERT(video);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (vo->vo_sysctl_tree != NULL) {
|
|
|
|
vo->vo_sysctl_tree = NULL;
|
|
|
|
sysctl_ctx_free(&vo->vo_sysctl_ctx);
|
|
|
|
}
|
2010-02-13 02:24:23 +00:00
|
|
|
if (vo->vo_levels != NULL) {
|
|
|
|
AcpiRemoveNotifyHandler(vo->handle, ACPI_DEVICE_NOTIFY,
|
|
|
|
acpi_video_vo_notify_handler);
|
2004-03-01 08:12:56 +00:00
|
|
|
AcpiOsFree(vo->vo_levels);
|
2010-02-13 02:24:23 +00:00
|
|
|
}
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
switch (vo->adr & DOD_DEVID_MASK) {
|
|
|
|
case DOD_DEVID_MONITOR:
|
|
|
|
voqh = &crt_units;
|
|
|
|
break;
|
|
|
|
case DOD_DEVID_TV:
|
|
|
|
voqh = &tv_units;
|
|
|
|
break;
|
2006-08-10 13:18:02 +00:00
|
|
|
case DOD_DEVID_EXT:
|
|
|
|
voqh = &ext_units;
|
|
|
|
break;
|
|
|
|
case DOD_DEVID_INTDFP:
|
|
|
|
voqh = &lcd_units;
|
|
|
|
break;
|
2004-03-01 08:12:56 +00:00
|
|
|
default:
|
|
|
|
voqh = &other_units;
|
|
|
|
}
|
|
|
|
STAILQ_REMOVE(voqh, vo, acpi_video_output, vo_unit.next);
|
|
|
|
free(vo, M_ACPIVIDEO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_video_vo_check_level(struct acpi_video_output *vo, int level)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_ASSERT(video_output);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (vo->vo_levels == NULL)
|
|
|
|
return (ENODEV);
|
|
|
|
for (i = 0; i < vo->vo_numlevels; i++)
|
|
|
|
if (vo->vo_levels[i] == level)
|
|
|
|
return (0);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
2010-02-13 02:24:23 +00:00
|
|
|
static void
|
|
|
|
acpi_video_vo_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
|
|
|
|
{
|
|
|
|
struct acpi_video_output *vo;
|
|
|
|
int i, j, level, new_level;
|
|
|
|
|
|
|
|
vo = context;
|
|
|
|
ACPI_SERIAL_BEGIN(video_output);
|
2010-02-15 19:30:28 +00:00
|
|
|
if (vo->handle != handle)
|
|
|
|
goto out;
|
2010-02-13 02:24:23 +00:00
|
|
|
|
|
|
|
switch (notify) {
|
2010-02-15 20:46:01 +00:00
|
|
|
case VID_NOTIFY_CYCLE_BRN:
|
2010-02-15 19:30:28 +00:00
|
|
|
if (vo->vo_numlevels <= 3)
|
|
|
|
goto out;
|
|
|
|
/* FALLTHROUGH */
|
2010-02-13 02:24:23 +00:00
|
|
|
case VID_NOTIFY_INC_BRN:
|
|
|
|
case VID_NOTIFY_DEC_BRN:
|
2010-02-15 20:46:01 +00:00
|
|
|
case VID_NOTIFY_ZERO_BRN:
|
2010-02-13 02:24:23 +00:00
|
|
|
if (vo->vo_levels == NULL)
|
2010-02-15 19:30:28 +00:00
|
|
|
goto out;
|
2010-02-13 05:38:21 +00:00
|
|
|
level = vo_get_brightness(handle);
|
2010-02-13 02:24:23 +00:00
|
|
|
if (level < 0)
|
2010-02-15 19:30:28 +00:00
|
|
|
goto out;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("unknown notify event 0x%x from %s\n",
|
|
|
|
notify, acpi_name(handle));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_level = level;
|
|
|
|
switch (notify) {
|
2010-02-15 20:46:01 +00:00
|
|
|
case VID_NOTIFY_CYCLE_BRN:
|
2010-02-15 19:30:28 +00:00
|
|
|
for (i = 2; i < vo->vo_numlevels; i++)
|
|
|
|
if (vo->vo_levels[i] == level) {
|
|
|
|
new_level = vo->vo_numlevels > i + 1 ?
|
|
|
|
vo->vo_levels[i + 1] : vo->vo_levels[2];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VID_NOTIFY_INC_BRN:
|
|
|
|
case VID_NOTIFY_DEC_BRN:
|
2010-02-13 02:24:23 +00:00
|
|
|
for (i = 0; i < vo->vo_numlevels; i++) {
|
|
|
|
j = vo->vo_levels[i];
|
|
|
|
if (notify == VID_NOTIFY_INC_BRN) {
|
|
|
|
if (j > level &&
|
|
|
|
(j < new_level || level == new_level))
|
|
|
|
new_level = j;
|
|
|
|
} else {
|
|
|
|
if (j < level &&
|
|
|
|
(j > new_level || level == new_level))
|
|
|
|
new_level = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-02-15 20:46:01 +00:00
|
|
|
case VID_NOTIFY_ZERO_BRN:
|
2010-02-15 19:30:28 +00:00
|
|
|
for (i = 0; i < vo->vo_numlevels; i++)
|
|
|
|
if (vo->vo_levels[i] == 0) {
|
|
|
|
new_level = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2010-02-13 02:24:23 +00:00
|
|
|
}
|
2010-02-15 19:30:28 +00:00
|
|
|
if (new_level != level) {
|
|
|
|
vo_set_brightness(handle, new_level);
|
|
|
|
vo->vo_brightness = new_level;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2010-02-13 02:24:23 +00:00
|
|
|
ACPI_SERIAL_END(video_output);
|
|
|
|
}
|
|
|
|
|
2004-03-01 08:12:56 +00:00
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
acpi_video_vo_active_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct acpi_video_output *vo;
|
|
|
|
int state, err;
|
|
|
|
|
|
|
|
vo = (struct acpi_video_output *)arg1;
|
2004-08-13 06:22:20 +00:00
|
|
|
if (vo->handle == NULL)
|
|
|
|
return (ENXIO);
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_BEGIN(video_output);
|
2004-08-13 06:22:20 +00:00
|
|
|
state = (vo_get_device_status(vo->handle) & DCS_ACTIVE) ? 1 : 0;
|
2004-03-01 08:12:56 +00:00
|
|
|
err = sysctl_handle_int(oidp, &state, 0, req);
|
|
|
|
if (err != 0 || req->newptr == NULL)
|
|
|
|
goto out;
|
|
|
|
vo_set_device_state(vo->handle,
|
2004-11-09 04:41:30 +00:00
|
|
|
DSS_COMMIT | (state ? DSS_ACTIVE : DSS_INACTIVE));
|
2004-03-01 08:12:56 +00:00
|
|
|
out:
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_END(video_output);
|
2004-03-01 08:12:56 +00:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
acpi_video_vo_bright_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct acpi_video_output *vo;
|
|
|
|
int level, preset, err;
|
|
|
|
|
|
|
|
vo = (struct acpi_video_output *)arg1;
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_BEGIN(video_output);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (vo->handle == NULL) {
|
|
|
|
err = ENXIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (vo->vo_levels == NULL) {
|
|
|
|
err = ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2004-07-22 05:18:05 +00:00
|
|
|
preset = (power_profile_get_state() == POWER_PROFILE_ECONOMY) ?
|
|
|
|
vo->vo_economy : vo->vo_fullpower;
|
2004-03-01 08:12:56 +00:00
|
|
|
level = vo->vo_brightness;
|
|
|
|
if (level == -1)
|
|
|
|
level = preset;
|
|
|
|
|
|
|
|
err = sysctl_handle_int(oidp, &level, 0, req);
|
|
|
|
if (err != 0 || req->newptr == NULL)
|
|
|
|
goto out;
|
|
|
|
if (level < -1 || level > 100) {
|
|
|
|
err = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level != -1 && (err = acpi_video_vo_check_level(vo, level)))
|
|
|
|
goto out;
|
|
|
|
vo->vo_brightness = level;
|
2004-08-13 06:22:20 +00:00
|
|
|
vo_set_brightness(vo->handle, (level == -1) ? preset : level);
|
|
|
|
|
2004-03-01 08:12:56 +00:00
|
|
|
out:
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_END(video_output);
|
2004-03-01 08:12:56 +00:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_video_vo_presets_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct acpi_video_output *vo;
|
2004-11-09 04:41:30 +00:00
|
|
|
int i, level, *preset, err;
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
vo = (struct acpi_video_output *)arg1;
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_BEGIN(video_output);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (vo->handle == NULL) {
|
|
|
|
err = ENXIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (vo->vo_levels == NULL) {
|
|
|
|
err = ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
2004-07-22 05:18:05 +00:00
|
|
|
preset = (arg2 == POWER_PROFILE_ECONOMY) ?
|
|
|
|
&vo->vo_economy : &vo->vo_fullpower;
|
2004-03-01 08:12:56 +00:00
|
|
|
level = *preset;
|
|
|
|
err = sysctl_handle_int(oidp, &level, 0, req);
|
|
|
|
if (err != 0 || req->newptr == NULL)
|
|
|
|
goto out;
|
|
|
|
if (level < -1 || level > 100) {
|
|
|
|
err = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2004-08-13 06:22:20 +00:00
|
|
|
if (level == -1) {
|
|
|
|
i = (arg2 == POWER_PROFILE_ECONOMY) ?
|
|
|
|
BCL_ECONOMY : BCL_FULLPOWER;
|
|
|
|
level = vo->vo_levels[i];
|
2004-11-09 04:41:30 +00:00
|
|
|
} else if ((err = acpi_video_vo_check_level(vo, level)) != 0)
|
2004-03-01 08:12:56 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (vo->vo_brightness == -1 && (power_profile_get_state() == arg2))
|
|
|
|
vo_set_brightness(vo->handle, level);
|
|
|
|
*preset = level;
|
2004-08-13 06:22:20 +00:00
|
|
|
|
2004-03-01 08:12:56 +00:00
|
|
|
out:
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_END(video_output);
|
2004-03-01 08:12:56 +00:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
acpi_video_vo_levels_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct acpi_video_output *vo;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
vo = (struct acpi_video_output *)arg1;
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_BEGIN(video_output);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (vo->vo_levels == NULL) {
|
|
|
|
err = ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (req->newptr != NULL) {
|
|
|
|
err = EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
err = sysctl_handle_opaque(oidp, vo->vo_levels,
|
2004-08-13 06:22:20 +00:00
|
|
|
vo->vo_numlevels * sizeof(*vo->vo_levels), req);
|
|
|
|
|
2004-03-01 08:12:56 +00:00
|
|
|
out:
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_END(video_output);
|
2004-03-01 08:12:56 +00:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vid_set_switch_policy(ACPI_HANDLE handle, UINT32 policy)
|
|
|
|
{
|
|
|
|
ACPI_STATUS status;
|
|
|
|
|
2004-03-03 18:34:42 +00:00
|
|
|
status = acpi_SetInteger(handle, "_DOS", policy);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
printf("can't evaluate %s._DOS - %s\n",
|
|
|
|
acpi_name(handle), AcpiFormatException(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct enum_callback_arg {
|
|
|
|
void (*callback)(ACPI_HANDLE, UINT32, void *);
|
|
|
|
void *context;
|
|
|
|
ACPI_OBJECT *dod_pkg;
|
2004-07-24 17:51:22 +00:00
|
|
|
int count;
|
2004-03-01 08:12:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static ACPI_STATUS
|
|
|
|
vid_enum_outputs_subr(ACPI_HANDLE handle, UINT32 level __unused,
|
2004-07-24 17:51:22 +00:00
|
|
|
void *context, void **retp __unused)
|
2004-03-01 08:12:56 +00:00
|
|
|
{
|
|
|
|
ACPI_STATUS status;
|
2004-07-24 17:51:22 +00:00
|
|
|
UINT32 adr, val;
|
2004-03-01 08:12:56 +00:00
|
|
|
struct enum_callback_arg *argset;
|
|
|
|
size_t i;
|
|
|
|
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_ASSERT(video);
|
2004-03-01 08:12:56 +00:00
|
|
|
argset = context;
|
2004-03-03 18:34:42 +00:00
|
|
|
status = acpi_GetInteger(handle, "_ADR", &adr);
|
2004-07-24 17:51:22 +00:00
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
return (AE_OK);
|
|
|
|
|
|
|
|
for (i = 0; i < argset->dod_pkg->Package.Count; i++) {
|
|
|
|
if (acpi_PkgInt32(argset->dod_pkg, i, &val) == 0 &&
|
2012-10-19 19:17:43 +00:00
|
|
|
(val & DOD_DEVID_MASK_FULL) ==
|
|
|
|
(adr & DOD_DEVID_MASK_FULL)) {
|
2004-07-24 17:51:22 +00:00
|
|
|
argset->callback(handle, val, argset->context);
|
|
|
|
argset->count++;
|
2004-03-01 08:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (AE_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
vid_enum_outputs(ACPI_HANDLE handle,
|
|
|
|
void (*callback)(ACPI_HANDLE, UINT32, void *), void *context)
|
|
|
|
{
|
|
|
|
ACPI_STATUS status;
|
|
|
|
ACPI_BUFFER dod_buf;
|
|
|
|
ACPI_OBJECT *res;
|
|
|
|
struct enum_callback_arg argset;
|
|
|
|
|
2004-08-13 06:22:20 +00:00
|
|
|
ACPI_SERIAL_ASSERT(video);
|
2004-03-01 08:12:56 +00:00
|
|
|
dod_buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
dod_buf.Pointer = NULL;
|
|
|
|
status = AcpiEvaluateObject(handle, "_DOD", NULL, &dod_buf);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
if (status != AE_NOT_FOUND)
|
|
|
|
printf("can't evaluate %s._DOD - %s\n",
|
|
|
|
acpi_name(handle), AcpiFormatException(status));
|
2004-07-24 17:51:22 +00:00
|
|
|
argset.count = -1;
|
2004-03-01 08:12:56 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
res = (ACPI_OBJECT *)dod_buf.Pointer;
|
2004-07-24 17:51:22 +00:00
|
|
|
if (!ACPI_PKG_VALID(res, 1)) {
|
2004-03-01 08:12:56 +00:00
|
|
|
printf("evaluation of %s._DOD makes no sense\n",
|
|
|
|
acpi_name(handle));
|
2004-07-24 17:51:22 +00:00
|
|
|
argset.count = -1;
|
2004-03-01 08:12:56 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (callback == NULL) {
|
2004-07-24 17:51:22 +00:00
|
|
|
argset.count = res->Package.Count;
|
2004-03-01 08:12:56 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
argset.callback = callback;
|
|
|
|
argset.context = context;
|
|
|
|
argset.dod_pkg = res;
|
2004-07-24 17:51:22 +00:00
|
|
|
argset.count = 0;
|
2004-03-01 08:12:56 +00:00
|
|
|
status = AcpiWalkNamespace(ACPI_TYPE_DEVICE, handle, 1,
|
2009-11-16 21:47:12 +00:00
|
|
|
vid_enum_outputs_subr, NULL, &argset, NULL);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
printf("failed walking down %s - %s\n",
|
|
|
|
acpi_name(handle), AcpiFormatException(status));
|
|
|
|
out:
|
|
|
|
if (dod_buf.Pointer != NULL)
|
|
|
|
AcpiOsFree(dod_buf.Pointer);
|
2004-07-24 17:51:22 +00:00
|
|
|
return (argset.count);
|
2004-03-01 08:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-08-13 06:22:20 +00:00
|
|
|
vo_get_brightness_levels(ACPI_HANDLE handle, int **levelp)
|
2004-03-01 08:12:56 +00:00
|
|
|
{
|
|
|
|
ACPI_STATUS status;
|
|
|
|
ACPI_BUFFER bcl_buf;
|
2004-07-24 17:51:22 +00:00
|
|
|
ACPI_OBJECT *res;
|
2004-11-09 04:41:30 +00:00
|
|
|
int num, i, n, *levels;
|
2004-03-01 08:12:56 +00:00
|
|
|
|
|
|
|
bcl_buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
bcl_buf.Pointer = NULL;
|
|
|
|
status = AcpiEvaluateObject(handle, "_BCL", NULL, &bcl_buf);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
if (status != AE_NOT_FOUND)
|
|
|
|
printf("can't evaluate %s._BCL - %s\n",
|
|
|
|
acpi_name(handle), AcpiFormatException(status));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
res = (ACPI_OBJECT *)bcl_buf.Pointer;
|
2004-07-24 17:51:22 +00:00
|
|
|
if (!ACPI_PKG_VALID(res, 2)) {
|
2004-03-01 08:12:56 +00:00
|
|
|
printf("evaluation of %s._BCL makes no sense\n",
|
|
|
|
acpi_name(handle));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
num = res->Package.Count;
|
2010-06-11 19:58:41 +00:00
|
|
|
if (num < 2 || levelp == NULL)
|
2004-03-01 08:12:56 +00:00
|
|
|
goto out;
|
2004-07-24 17:51:22 +00:00
|
|
|
levels = AcpiOsAllocate(num * sizeof(*levels));
|
2010-06-11 19:58:41 +00:00
|
|
|
if (levels == NULL)
|
2004-03-01 08:12:56 +00:00
|
|
|
goto out;
|
2004-07-24 17:51:22 +00:00
|
|
|
for (i = 0, n = 0; i < num; i++)
|
|
|
|
if (acpi_PkgInt32(res, i, &levels[n]) == 0)
|
|
|
|
n++;
|
2004-03-01 08:12:56 +00:00
|
|
|
if (n < 2) {
|
|
|
|
AcpiOsFree(levels);
|
2010-06-11 19:58:41 +00:00
|
|
|
goto out;
|
2004-03-01 08:12:56 +00:00
|
|
|
}
|
2010-06-11 19:58:41 +00:00
|
|
|
*levelp = levels;
|
|
|
|
return (n);
|
|
|
|
|
2004-03-01 08:12:56 +00:00
|
|
|
out:
|
|
|
|
if (bcl_buf.Pointer != NULL)
|
|
|
|
AcpiOsFree(bcl_buf.Pointer);
|
2010-06-11 19:58:41 +00:00
|
|
|
return (0);
|
2004-03-01 08:12:56 +00:00
|
|
|
}
|
|
|
|
|
2010-02-13 02:24:23 +00:00
|
|
|
static int
|
|
|
|
vo_get_brightness(ACPI_HANDLE handle)
|
|
|
|
{
|
|
|
|
UINT32 level;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
|
|
|
|
ACPI_SERIAL_ASSERT(video_output);
|
|
|
|
status = acpi_GetInteger(handle, "_BQC", &level);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
printf("can't evaluate %s._BQC - %s\n", acpi_name(handle),
|
|
|
|
AcpiFormatException(status));
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (level > 100)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
return (level);
|
|
|
|
}
|
|
|
|
|
2004-03-01 08:12:56 +00:00
|
|
|
static void
|
|
|
|
vo_set_brightness(ACPI_HANDLE handle, int level)
|
|
|
|
{
|
|
|
|
ACPI_STATUS status;
|
|
|
|
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_ASSERT(video_output);
|
2004-03-03 18:34:42 +00:00
|
|
|
status = acpi_SetInteger(handle, "_BCM", level);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
printf("can't evaluate %s._BCM - %s\n",
|
|
|
|
acpi_name(handle), AcpiFormatException(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT32
|
|
|
|
vo_get_device_status(ACPI_HANDLE handle)
|
|
|
|
{
|
2004-11-09 04:41:30 +00:00
|
|
|
UINT32 dcs;
|
2004-03-01 08:12:56 +00:00
|
|
|
ACPI_STATUS status;
|
|
|
|
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_ASSERT(video_output);
|
2004-11-09 04:41:30 +00:00
|
|
|
dcs = 0;
|
2004-03-03 18:34:42 +00:00
|
|
|
status = acpi_GetInteger(handle, "_DCS", &dcs);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
printf("can't evaluate %s._DCS - %s\n",
|
|
|
|
acpi_name(handle), AcpiFormatException(status));
|
|
|
|
|
|
|
|
return (dcs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT32
|
2004-08-13 06:22:20 +00:00
|
|
|
vo_get_graphics_state(ACPI_HANDLE handle)
|
2004-03-01 08:12:56 +00:00
|
|
|
{
|
2004-11-09 04:41:30 +00:00
|
|
|
UINT32 dgs;
|
2004-03-01 08:12:56 +00:00
|
|
|
ACPI_STATUS status;
|
|
|
|
|
2004-11-09 04:41:30 +00:00
|
|
|
dgs = 0;
|
2004-03-03 18:34:42 +00:00
|
|
|
status = acpi_GetInteger(handle, "_DGS", &dgs);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
printf("can't evaluate %s._DGS - %s\n",
|
|
|
|
acpi_name(handle), AcpiFormatException(status));
|
|
|
|
|
|
|
|
return (dgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vo_set_device_state(ACPI_HANDLE handle, UINT32 state)
|
|
|
|
{
|
|
|
|
ACPI_STATUS status;
|
|
|
|
|
2009-09-30 17:05:26 +00:00
|
|
|
ACPI_SERIAL_ASSERT(video_output);
|
2004-03-03 18:34:42 +00:00
|
|
|
status = acpi_SetInteger(handle, "_DSS", state);
|
2004-03-01 08:12:56 +00:00
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
printf("can't evaluate %s._DSS - %s\n",
|
|
|
|
acpi_name(handle), AcpiFormatException(status));
|
|
|
|
}
|