2001-10-26 17:43:05 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001 Mitsuru IWASAKI
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-06-02 06:16:45 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2001-10-26 17:43:05 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/bus.h>
|
2007-03-31 23:23:42 +00:00
|
|
|
#include <sys/condvar.h>
|
2001-10-26 17:43:05 +00:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/fcntl.h>
|
2003-10-30 16:14:55 +00:00
|
|
|
#include <sys/kernel.h>
|
2007-06-21 22:50:37 +00:00
|
|
|
#include <sys/malloc.h>
|
2008-03-13 20:39:04 +00:00
|
|
|
#include <sys/module.h>
|
2007-06-21 22:50:37 +00:00
|
|
|
#include <sys/poll.h>
|
2003-10-30 16:14:55 +00:00
|
|
|
#include <sys/sysctl.h>
|
2001-10-26 17:43:05 +00:00
|
|
|
#include <sys/uio.h>
|
2004-06-30 04:42:29 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/pmap.h>
|
2001-10-26 17:43:05 +00:00
|
|
|
|
2005-09-11 18:39:03 +00:00
|
|
|
#include <contrib/dev/acpica/acpi.h>
|
2001-10-26 17:43:05 +00:00
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
#include <dev/acpica/acpiio.h>
|
|
|
|
|
2008-03-13 20:39:04 +00:00
|
|
|
#include <machine/nexusvar.h>
|
|
|
|
|
2001-10-26 17:43:05 +00:00
|
|
|
/*
|
|
|
|
* APM driver emulation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <machine/apm_bios.h>
|
|
|
|
#include <machine/pc/bios.h>
|
|
|
|
|
2003-03-24 19:14:46 +00:00
|
|
|
#include <i386/bios/apm.h>
|
2001-10-26 17:43:05 +00:00
|
|
|
|
2006-06-10 08:06:16 +00:00
|
|
|
SYSCTL_DECL(_debug_acpi);
|
|
|
|
|
2006-06-08 17:54:10 +00:00
|
|
|
uint32_t acpi_resume_beep;
|
2006-06-10 08:06:16 +00:00
|
|
|
TUNABLE_INT("debug.acpi.resume_beep", &acpi_resume_beep);
|
|
|
|
SYSCTL_UINT(_debug_acpi, OID_AUTO, resume_beep, CTLFLAG_RW, &acpi_resume_beep,
|
|
|
|
0, "Beep the PC speaker when resuming");
|
2006-06-08 17:54:10 +00:00
|
|
|
uint32_t acpi_reset_video;
|
2003-11-01 00:18:29 +00:00
|
|
|
TUNABLE_INT("hw.acpi.reset_video", &acpi_reset_video);
|
2003-10-30 16:14:55 +00:00
|
|
|
|
2004-05-05 19:51:15 +00:00
|
|
|
static int intr_model = ACPI_INTR_PIC;
|
2004-07-24 22:41:30 +00:00
|
|
|
static int apm_active;
|
2007-06-21 22:50:37 +00:00
|
|
|
static struct clonedevs *apm_clones;
|
|
|
|
|
|
|
|
MALLOC_DEFINE(M_APMDEV, "apmdev", "APM device emulation");
|
2001-10-26 17:43:05 +00:00
|
|
|
|
2007-06-21 22:50:37 +00:00
|
|
|
static d_open_t apmopen;
|
|
|
|
static d_close_t apmclose;
|
|
|
|
static d_write_t apmwrite;
|
|
|
|
static d_ioctl_t apmioctl;
|
|
|
|
static d_poll_t apmpoll;
|
|
|
|
static d_kqfilter_t apmkqfilter;
|
|
|
|
static void apmreadfiltdetach(struct knote *kn);
|
|
|
|
static int apmreadfilt(struct knote *kn, long hint);
|
|
|
|
static struct filterops apm_readfiltops =
|
|
|
|
{ 1, NULL, apmreadfiltdetach, apmreadfilt };
|
2001-10-26 17:43:05 +00:00
|
|
|
|
|
|
|
static struct cdevsw apm_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
2007-06-21 22:50:37 +00:00
|
|
|
.d_flags = D_TRACKCLOSE,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = apmopen,
|
|
|
|
.d_close = apmclose,
|
|
|
|
.d_write = apmwrite,
|
|
|
|
.d_ioctl = apmioctl,
|
|
|
|
.d_poll = apmpoll,
|
|
|
|
.d_name = "apm",
|
2007-06-21 22:50:37 +00:00
|
|
|
.d_kqfilter = apmkqfilter
|
2001-10-26 17:43:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_capm_convert_battstate(struct acpi_battinfo *battp)
|
|
|
|
{
|
|
|
|
int state;
|
|
|
|
|
2004-06-28 02:38:20 +00:00
|
|
|
state = APM_UNKNOWN;
|
2001-10-26 17:43:05 +00:00
|
|
|
|
|
|
|
if (battp->state & ACPI_BATT_STAT_DISCHARG) {
|
2003-08-28 16:26:24 +00:00
|
|
|
if (battp->cap >= 50)
|
2001-10-26 17:43:05 +00:00
|
|
|
state = 0; /* high */
|
2003-08-28 16:26:24 +00:00
|
|
|
else
|
2001-10-26 17:43:05 +00:00
|
|
|
state = 1; /* low */
|
|
|
|
}
|
2003-08-28 16:26:24 +00:00
|
|
|
if (battp->state & ACPI_BATT_STAT_CRITICAL)
|
2001-10-26 17:43:05 +00:00
|
|
|
state = 2; /* critical */
|
2003-08-28 16:26:24 +00:00
|
|
|
if (battp->state & ACPI_BATT_STAT_CHARGING)
|
2001-10-26 17:43:05 +00:00
|
|
|
state = 3; /* charging */
|
2003-08-28 16:26:24 +00:00
|
|
|
|
2003-09-17 08:47:39 +00:00
|
|
|
/* If still unknown, determine it based on the battery capacity. */
|
2004-06-28 02:38:20 +00:00
|
|
|
if (state == APM_UNKNOWN) {
|
2004-05-05 19:51:15 +00:00
|
|
|
if (battp->cap >= 50)
|
2003-09-17 08:47:39 +00:00
|
|
|
state = 0; /* high */
|
2004-05-05 19:51:15 +00:00
|
|
|
else
|
2003-09-17 08:47:39 +00:00
|
|
|
state = 1; /* low */
|
|
|
|
}
|
|
|
|
|
2001-10-26 17:43:05 +00:00
|
|
|
return (state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_capm_convert_battflags(struct acpi_battinfo *battp)
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
|
2004-05-05 19:51:15 +00:00
|
|
|
if (battp->cap >= 50)
|
2001-10-26 17:43:05 +00:00
|
|
|
flags |= APM_BATT_HIGH;
|
2004-05-05 19:51:15 +00:00
|
|
|
else {
|
2003-08-28 16:26:24 +00:00
|
|
|
if (battp->state & ACPI_BATT_STAT_CRITICAL)
|
2001-10-26 17:43:05 +00:00
|
|
|
flags |= APM_BATT_CRITICAL;
|
2003-08-28 16:26:24 +00:00
|
|
|
else
|
2001-10-26 17:43:05 +00:00
|
|
|
flags |= APM_BATT_LOW;
|
|
|
|
}
|
2003-08-28 16:26:24 +00:00
|
|
|
if (battp->state & ACPI_BATT_STAT_CHARGING)
|
2001-10-26 17:43:05 +00:00
|
|
|
flags |= APM_BATT_CHARGING;
|
2003-08-28 16:26:24 +00:00
|
|
|
if (battp->state == ACPI_BATT_STAT_NOT_PRESENT)
|
2001-10-26 17:43:05 +00:00
|
|
|
flags = APM_BATT_NOT_PRESENT;
|
|
|
|
|
|
|
|
return (flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_capm_get_info(apm_info_t aip)
|
|
|
|
{
|
|
|
|
int acline;
|
|
|
|
struct acpi_battinfo batt;
|
|
|
|
|
|
|
|
aip->ai_infoversion = 1;
|
|
|
|
aip->ai_major = 1;
|
|
|
|
aip->ai_minor = 2;
|
2004-07-24 22:41:30 +00:00
|
|
|
aip->ai_status = apm_active;
|
2004-06-28 02:38:20 +00:00
|
|
|
aip->ai_capabilities= 0xff00; /* unknown */
|
2001-10-26 17:43:05 +00:00
|
|
|
|
2003-08-28 16:26:24 +00:00
|
|
|
if (acpi_acad_get_acline(&acline))
|
2004-06-28 02:38:20 +00:00
|
|
|
aip->ai_acline = APM_UNKNOWN; /* unknown */
|
2003-08-28 16:26:24 +00:00
|
|
|
else
|
2001-10-26 17:43:05 +00:00
|
|
|
aip->ai_acline = acline; /* on/off */
|
|
|
|
|
2005-07-23 19:36:00 +00:00
|
|
|
if (acpi_battery_get_battinfo(NULL, &batt) != 0) {
|
2004-06-28 02:38:20 +00:00
|
|
|
aip->ai_batt_stat = APM_UNKNOWN;
|
|
|
|
aip->ai_batt_life = APM_UNKNOWN;
|
|
|
|
aip->ai_batt_time = -1; /* unknown */
|
|
|
|
aip->ai_batteries = ~0U; /* unknown */
|
2001-10-26 17:43:05 +00:00
|
|
|
} else {
|
|
|
|
aip->ai_batt_stat = acpi_capm_convert_battstate(&batt);
|
|
|
|
aip->ai_batt_life = batt.cap;
|
|
|
|
aip->ai_batt_time = (batt.min == -1) ? -1 : batt.min * 60;
|
|
|
|
aip->ai_batteries = acpi_battery_get_units();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_capm_get_pwstatus(apm_pwstatus_t app)
|
|
|
|
{
|
2005-07-23 19:36:00 +00:00
|
|
|
device_t dev;
|
|
|
|
int acline, unit, error;
|
2001-10-26 17:43:05 +00:00
|
|
|
struct acpi_battinfo batt;
|
|
|
|
|
|
|
|
if (app->ap_device != PMDV_ALLDEV &&
|
2004-05-05 19:51:15 +00:00
|
|
|
(app->ap_device < PMDV_BATT0 || app->ap_device > PMDV_BATT_ALL))
|
2001-10-26 17:43:05 +00:00
|
|
|
return (1);
|
|
|
|
|
2003-08-28 16:26:24 +00:00
|
|
|
if (app->ap_device == PMDV_ALLDEV)
|
2005-07-23 19:36:00 +00:00
|
|
|
error = acpi_battery_get_battinfo(NULL, &batt);
|
|
|
|
else {
|
|
|
|
unit = app->ap_device - PMDV_BATT0;
|
|
|
|
dev = devclass_get_device(devclass_find("battery"), unit);
|
|
|
|
if (dev != NULL)
|
|
|
|
error = acpi_battery_get_battinfo(dev, &batt);
|
|
|
|
else
|
|
|
|
error = ENXIO;
|
|
|
|
}
|
|
|
|
if (error)
|
2001-10-26 17:43:05 +00:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
app->ap_batt_stat = acpi_capm_convert_battstate(&batt);
|
|
|
|
app->ap_batt_flag = acpi_capm_convert_battflags(&batt);
|
|
|
|
app->ap_batt_life = batt.cap;
|
|
|
|
app->ap_batt_time = (batt.min == -1) ? -1 : batt.min * 60;
|
|
|
|
|
2003-08-28 16:26:24 +00:00
|
|
|
if (acpi_acad_get_acline(&acline))
|
2004-06-28 02:38:20 +00:00
|
|
|
app->ap_acline = APM_UNKNOWN;
|
2003-08-28 16:26:24 +00:00
|
|
|
else
|
2001-10-26 17:43:05 +00:00
|
|
|
app->ap_acline = acline; /* on/off */
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2007-06-21 22:50:37 +00:00
|
|
|
/* Create single-use devices for /dev/apm and /dev/apmctl. */
|
|
|
|
static void
|
|
|
|
apm_clone(void *arg, struct ucred *cred, char *name, int namelen,
|
|
|
|
struct cdev **dev)
|
|
|
|
{
|
|
|
|
int ctl_dev, unit;
|
|
|
|
|
|
|
|
if (*dev != NULL)
|
|
|
|
return;
|
|
|
|
if (strcmp(name, "apmctl") == 0)
|
|
|
|
ctl_dev = TRUE;
|
|
|
|
else if (strcmp(name, "apm") == 0)
|
|
|
|
ctl_dev = FALSE;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Always create a new device and unit number. */
|
|
|
|
unit = -1;
|
|
|
|
if (clone_create(&apm_clones, &apm_cdevsw, &unit, dev, 0)) {
|
|
|
|
if (ctl_dev) {
|
|
|
|
*dev = make_dev(&apm_cdevsw, unit2minor(unit),
|
|
|
|
UID_ROOT, GID_OPERATOR, 0660, "apmctl%d", unit);
|
|
|
|
} else {
|
|
|
|
*dev = make_dev(&apm_cdevsw, unit2minor(unit),
|
|
|
|
UID_ROOT, GID_OPERATOR, 0664, "apm%d", unit);
|
|
|
|
}
|
|
|
|
if (*dev != NULL) {
|
|
|
|
dev_ref(*dev);
|
|
|
|
(*dev)->si_flags |= SI_CHEAPCLONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a struct for tracking per-device suspend notification. */
|
|
|
|
static struct apm_clone_data *
|
|
|
|
apm_create_clone(struct cdev *dev, struct acpi_softc *acpi_sc)
|
|
|
|
{
|
|
|
|
struct apm_clone_data *clone;
|
|
|
|
|
|
|
|
clone = malloc(sizeof(*clone), M_APMDEV, M_WAITOK);
|
|
|
|
clone->cdev = dev;
|
|
|
|
clone->acpi_sc = acpi_sc;
|
|
|
|
clone->notify_status = APM_EV_NONE;
|
|
|
|
bzero(&clone->sel_read, sizeof(clone->sel_read));
|
|
|
|
knlist_init(&clone->sel_read.si_note, &acpi_mutex, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The acpi device is always managed by devd(8) and is considered
|
|
|
|
* writable (i.e., ack is required to allow suspend to proceed.)
|
|
|
|
*/
|
|
|
|
if (strcmp("acpi", devtoname(dev)) == 0)
|
|
|
|
clone->flags = ACPI_EVF_DEVD | ACPI_EVF_WRITE;
|
|
|
|
else
|
|
|
|
clone->flags = ACPI_EVF_NONE;
|
|
|
|
|
|
|
|
ACPI_LOCK(acpi);
|
|
|
|
STAILQ_INSERT_TAIL(&acpi_sc->apm_cdevs, clone, entries);
|
|
|
|
ACPI_UNLOCK(acpi);
|
|
|
|
return (clone);
|
|
|
|
}
|
|
|
|
|
2001-10-26 17:43:05 +00:00
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
apmopen(struct cdev *dev, int flag, int fmt, d_thread_t *td)
|
2001-10-26 17:43:05 +00:00
|
|
|
{
|
2007-06-21 22:50:37 +00:00
|
|
|
struct acpi_softc *acpi_sc;
|
|
|
|
struct apm_clone_data *clone;
|
|
|
|
|
|
|
|
acpi_sc = devclass_get_softc(devclass_find("acpi"), 0);
|
|
|
|
clone = apm_create_clone(dev, acpi_sc);
|
|
|
|
dev->si_drv1 = clone;
|
|
|
|
|
|
|
|
/* If the device is opened for write, record that. */
|
|
|
|
if ((flag & FWRITE) != 0)
|
|
|
|
clone->flags |= ACPI_EVF_WRITE;
|
|
|
|
|
2001-10-26 17:43:05 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
apmclose(struct cdev *dev, int flag, int fmt, d_thread_t *td)
|
2001-10-26 17:43:05 +00:00
|
|
|
{
|
2007-06-21 22:50:37 +00:00
|
|
|
struct apm_clone_data *clone;
|
|
|
|
struct acpi_softc *acpi_sc;
|
|
|
|
|
|
|
|
clone = dev->si_drv1;
|
|
|
|
acpi_sc = clone->acpi_sc;
|
|
|
|
|
|
|
|
/* We are about to lose a reference so check if suspend should occur */
|
|
|
|
if (acpi_sc->acpi_next_sstate != 0 &&
|
|
|
|
clone->notify_status != APM_EV_ACKED)
|
|
|
|
acpi_AckSleepState(clone, 0);
|
|
|
|
|
|
|
|
/* Remove this clone's data from the list and free it. */
|
|
|
|
ACPI_LOCK(acpi);
|
|
|
|
STAILQ_REMOVE(&acpi_sc->apm_cdevs, clone, apm_clone_data, entries);
|
|
|
|
knlist_destroy(&clone->sel_read.si_note);
|
|
|
|
ACPI_UNLOCK(acpi);
|
|
|
|
free(clone, M_APMDEV);
|
2007-07-07 17:54:33 +00:00
|
|
|
destroy_dev_sched(dev);
|
2001-10-26 17:43:05 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
apmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, d_thread_t *td)
|
2001-10-26 17:43:05 +00:00
|
|
|
{
|
2007-06-21 22:50:37 +00:00
|
|
|
int error;
|
|
|
|
struct apm_clone_data *clone;
|
2001-10-26 17:43:05 +00:00
|
|
|
struct acpi_softc *acpi_sc;
|
2007-06-21 22:50:37 +00:00
|
|
|
struct apm_info info;
|
|
|
|
struct apm_event_info *ev_info;
|
2001-10-26 17:43:05 +00:00
|
|
|
apm_info_old_t aiop;
|
|
|
|
|
2007-06-21 22:50:37 +00:00
|
|
|
error = 0;
|
|
|
|
clone = dev->si_drv1;
|
|
|
|
acpi_sc = clone->acpi_sc;
|
2001-10-26 17:43:05 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case APMIO_SUSPEND:
|
2003-08-28 16:26:24 +00:00
|
|
|
if ((flag & FWRITE) == 0)
|
2001-10-26 17:43:05 +00:00
|
|
|
return (EPERM);
|
2007-06-21 22:50:37 +00:00
|
|
|
if (acpi_sc->acpi_next_sstate == 0) {
|
|
|
|
if (acpi_sc->acpi_suspend_sx != ACPI_STATE_S5) {
|
|
|
|
error = acpi_ReqSleepState(acpi_sc,
|
|
|
|
acpi_sc->acpi_suspend_sx);
|
|
|
|
} else {
|
|
|
|
printf(
|
|
|
|
"power off via apm suspend not supported\n");
|
|
|
|
error = ENXIO;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
error = acpi_AckSleepState(clone, 0);
|
2001-10-26 17:43:05 +00:00
|
|
|
break;
|
|
|
|
case APMIO_STANDBY:
|
2003-08-28 16:26:24 +00:00
|
|
|
if ((flag & FWRITE) == 0)
|
2001-10-26 17:43:05 +00:00
|
|
|
return (EPERM);
|
2007-06-21 22:50:37 +00:00
|
|
|
if (acpi_sc->acpi_next_sstate == 0) {
|
|
|
|
if (acpi_sc->acpi_standby_sx != ACPI_STATE_S5) {
|
|
|
|
error = acpi_ReqSleepState(acpi_sc,
|
|
|
|
acpi_sc->acpi_standby_sx);
|
|
|
|
} else {
|
|
|
|
printf(
|
|
|
|
"power off via apm standby not supported\n");
|
|
|
|
error = ENXIO;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
error = acpi_AckSleepState(clone, 0);
|
|
|
|
break;
|
|
|
|
case APMIO_NEXTEVENT:
|
|
|
|
printf("apm nextevent start\n");
|
|
|
|
ACPI_LOCK(acpi);
|
|
|
|
if (acpi_sc->acpi_next_sstate != 0 && clone->notify_status ==
|
|
|
|
APM_EV_NONE) {
|
|
|
|
ev_info = (struct apm_event_info *)addr;
|
|
|
|
if (acpi_sc->acpi_next_sstate <= ACPI_STATE_S3)
|
|
|
|
ev_info->type = PMEV_STANDBYREQ;
|
|
|
|
else
|
|
|
|
ev_info->type = PMEV_SUSPENDREQ;
|
|
|
|
ev_info->index = 0;
|
|
|
|
clone->notify_status = APM_EV_NOTIFIED;
|
|
|
|
printf("apm event returning %d\n", ev_info->type);
|
|
|
|
} else
|
|
|
|
error = EAGAIN;
|
|
|
|
ACPI_UNLOCK(acpi);
|
2001-10-26 17:43:05 +00:00
|
|
|
break;
|
|
|
|
case APMIO_GETINFO_OLD:
|
|
|
|
if (acpi_capm_get_info(&info))
|
|
|
|
error = ENXIO;
|
|
|
|
aiop = (apm_info_old_t)addr;
|
|
|
|
aiop->ai_major = info.ai_major;
|
|
|
|
aiop->ai_minor = info.ai_minor;
|
|
|
|
aiop->ai_acline = info.ai_acline;
|
|
|
|
aiop->ai_batt_stat = info.ai_batt_stat;
|
|
|
|
aiop->ai_batt_life = info.ai_batt_life;
|
|
|
|
aiop->ai_status = info.ai_status;
|
|
|
|
break;
|
|
|
|
case APMIO_GETINFO:
|
|
|
|
if (acpi_capm_get_info((apm_info_t)addr))
|
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
case APMIO_GETPWSTATUS:
|
|
|
|
if (acpi_capm_get_pwstatus((apm_pwstatus_t)addr))
|
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
case APMIO_ENABLE:
|
2003-08-28 16:26:24 +00:00
|
|
|
if ((flag & FWRITE) == 0)
|
2001-10-26 17:43:05 +00:00
|
|
|
return (EPERM);
|
2004-07-24 22:41:30 +00:00
|
|
|
apm_active = 1;
|
2001-10-26 17:43:05 +00:00
|
|
|
break;
|
|
|
|
case APMIO_DISABLE:
|
2003-08-28 16:26:24 +00:00
|
|
|
if ((flag & FWRITE) == 0)
|
2001-10-26 17:43:05 +00:00
|
|
|
return (EPERM);
|
2004-07-24 22:41:30 +00:00
|
|
|
apm_active = 0;
|
2001-10-26 17:43:05 +00:00
|
|
|
break;
|
|
|
|
case APMIO_HALTCPU:
|
|
|
|
break;
|
|
|
|
case APMIO_NOTHALTCPU:
|
|
|
|
break;
|
|
|
|
case APMIO_DISPLAY:
|
2003-08-28 16:26:24 +00:00
|
|
|
if ((flag & FWRITE) == 0)
|
2001-10-26 17:43:05 +00:00
|
|
|
return (EPERM);
|
|
|
|
break;
|
|
|
|
case APMIO_BIOS:
|
2003-08-28 16:26:24 +00:00
|
|
|
if ((flag & FWRITE) == 0)
|
2001-10-26 17:43:05 +00:00
|
|
|
return (EPERM);
|
|
|
|
bzero(addr, sizeof(struct apm_bios_arg));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
apmwrite(struct cdev *dev, struct uio *uio, int ioflag)
|
2001-10-26 17:43:05 +00:00
|
|
|
{
|
|
|
|
return (uio->uio_resid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
apmpoll(struct cdev *dev, int events, d_thread_t *td)
|
2001-10-26 17:43:05 +00:00
|
|
|
{
|
2007-06-21 22:50:37 +00:00
|
|
|
struct apm_clone_data *clone;
|
|
|
|
int revents;
|
|
|
|
|
|
|
|
revents = 0;
|
|
|
|
ACPI_LOCK(acpi);
|
|
|
|
clone = dev->si_drv1;
|
|
|
|
if (clone->acpi_sc->acpi_next_sstate)
|
|
|
|
revents |= events & (POLLIN | POLLRDNORM);
|
|
|
|
else
|
|
|
|
selrecord(td, &clone->sel_read);
|
|
|
|
ACPI_UNLOCK(acpi);
|
|
|
|
return (revents);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
apmkqfilter(struct cdev *dev, struct knote *kn)
|
|
|
|
{
|
|
|
|
struct apm_clone_data *clone;
|
|
|
|
|
|
|
|
ACPI_LOCK(acpi);
|
|
|
|
clone = dev->si_drv1;
|
|
|
|
kn->kn_hook = clone;
|
|
|
|
kn->kn_fop = &apm_readfiltops;
|
|
|
|
knlist_add(&clone->sel_read.si_note, kn, 0);
|
|
|
|
ACPI_UNLOCK(acpi);
|
2001-10-26 17:43:05 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-06-21 22:50:37 +00:00
|
|
|
apmreadfiltdetach(struct knote *kn)
|
|
|
|
{
|
|
|
|
struct apm_clone_data *clone;
|
|
|
|
|
|
|
|
ACPI_LOCK(acpi);
|
|
|
|
clone = kn->kn_hook;
|
|
|
|
knlist_remove(&clone->sel_read.si_note, kn, 0);
|
|
|
|
ACPI_UNLOCK(acpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
apmreadfilt(struct knote *kn, long hint)
|
2001-10-26 17:43:05 +00:00
|
|
|
{
|
2007-06-21 22:50:37 +00:00
|
|
|
struct apm_clone_data *clone;
|
|
|
|
int sleeping;
|
|
|
|
|
|
|
|
ACPI_LOCK(acpi);
|
|
|
|
clone = kn->kn_hook;
|
|
|
|
sleeping = clone->acpi_sc->acpi_next_sstate ? 1 : 0;
|
|
|
|
ACPI_UNLOCK(acpi);
|
|
|
|
return (sleeping);
|
2001-10-26 17:43:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
acpi_machdep_init(device_t dev)
|
|
|
|
{
|
2007-06-21 22:50:37 +00:00
|
|
|
struct acpi_softc *acpi_sc;
|
2001-10-26 17:43:05 +00:00
|
|
|
|
2007-06-21 22:50:37 +00:00
|
|
|
acpi_sc = devclass_get_softc(devclass_find("acpi"), 0);
|
2001-10-26 17:43:05 +00:00
|
|
|
|
2007-06-21 22:50:37 +00:00
|
|
|
/* Create a clone for /dev/acpi also. */
|
|
|
|
STAILQ_INIT(&acpi_sc->apm_cdevs);
|
|
|
|
acpi_sc->acpi_clone = apm_create_clone(acpi_sc->acpi_dev_t, acpi_sc);
|
|
|
|
clone_setup(&apm_clones);
|
|
|
|
EVENTHANDLER_REGISTER(dev_clone, apm_clone, 0, 1000);
|
|
|
|
acpi_install_wakeup_handler(acpi_sc);
|
2001-10-26 17:43:05 +00:00
|
|
|
|
2004-05-04 21:04:24 +00:00
|
|
|
if (intr_model == ACPI_INTR_PIC)
|
2007-03-22 18:16:43 +00:00
|
|
|
BUS_CONFIG_INTR(dev, AcpiGbl_FADT.SciInterrupt,
|
|
|
|
INTR_TRIGGER_LEVEL, INTR_POLARITY_LOW);
|
2004-05-04 21:04:24 +00:00
|
|
|
else
|
2003-09-10 05:29:30 +00:00
|
|
|
acpi_SetIntrModel(intr_model);
|
2003-10-30 16:14:55 +00:00
|
|
|
|
2007-06-21 22:50:37 +00:00
|
|
|
SYSCTL_ADD_UINT(&acpi_sc->acpi_sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), OID_AUTO,
|
2006-06-10 08:06:16 +00:00
|
|
|
"reset_video", CTLFLAG_RW, &acpi_reset_video, 0,
|
2003-11-01 00:18:29 +00:00
|
|
|
"Call the VESA reset BIOS vector on the resume path");
|
2003-10-30 16:14:55 +00:00
|
|
|
|
2001-10-26 17:43:05 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2003-09-10 05:29:30 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
acpi_SetDefaultIntrModel(int model)
|
|
|
|
{
|
|
|
|
|
|
|
|
intr_model = model;
|
|
|
|
}
|
2004-06-30 04:42:29 +00:00
|
|
|
|
|
|
|
/* Check BIOS date. If 1998 or older, disable ACPI. */
|
|
|
|
int
|
|
|
|
acpi_machdep_quirks(int *quirks)
|
|
|
|
{
|
2004-10-11 05:42:12 +00:00
|
|
|
char *va;
|
|
|
|
int year;
|
|
|
|
|
|
|
|
/* BIOS address 0xffff5 contains the date in the format mm/dd/yy. */
|
2006-08-11 19:22:57 +00:00
|
|
|
va = pmap_mapbios(0xffff0, 16);
|
2004-10-11 05:42:12 +00:00
|
|
|
sscanf(va + 11, "%2d", &year);
|
2006-08-11 19:22:57 +00:00
|
|
|
pmap_unmapbios((vm_offset_t)va, 16);
|
2004-10-11 05:42:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Date must be >= 1/1/1999 or we don't trust ACPI. Note that this
|
|
|
|
* check must be changed by my 114th birthday.
|
|
|
|
*/
|
|
|
|
if (year > 90 && year < 99)
|
|
|
|
*quirks = ACPI_Q_BROKEN;
|
|
|
|
|
|
|
|
return (0);
|
2004-06-30 04:42:29 +00:00
|
|
|
}
|
2004-10-11 05:39:15 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
acpi_cpu_c1()
|
|
|
|
{
|
|
|
|
__asm __volatile("sti; hlt");
|
|
|
|
}
|
2008-03-13 20:39:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPI nexus(4) driver.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
nexus_acpi_probe(device_t dev)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = acpi_identify();
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
return (BUS_PROBE_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nexus_acpi_attach(device_t dev)
|
|
|
|
{
|
|
|
|
|
|
|
|
nexus_init_resources();
|
|
|
|
bus_generic_probe(dev);
|
|
|
|
if (BUS_ADD_CHILD(dev, 10, "acpi", 0) == NULL)
|
|
|
|
panic("failed to add acpi0 device");
|
|
|
|
|
|
|
|
return (bus_generic_attach(dev));
|
|
|
|
}
|
|
|
|
|
|
|
|
static device_method_t nexus_acpi_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, nexus_acpi_probe),
|
|
|
|
DEVMETHOD(device_attach, nexus_acpi_attach),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_CLASS_1(nexus, nexus_acpi_driver, nexus_acpi_methods, 1, nexus_driver);
|
|
|
|
static devclass_t nexus_devclass;
|
|
|
|
|
|
|
|
DRIVER_MODULE(nexus_acpi, root, nexus_acpi_driver, nexus_devclass, 0, 0);
|