Index: conf/files.i386 =================================================================== RCS file: /home/ncvs/src/sys/conf/files.i386,v retrieving revision 1.377 diff -u -r1.377 files.i386 --- conf/files.i386 23 Oct 2001 15:17:33 -0000 1.377 +++ conf/files.i386 24 Oct 2001 15:49:43 -0000 @@ -168,6 +168,7 @@ gnu/i386/fpemul/wm_shrx.s optional gpl_math_emulate gnu/i386/fpemul/wm_sqrt.s optional gpl_math_emulate i386/acpica/OsdEnvironment.c optional acpica +i386/acpica/acpi_machdep.c optional acpica i386/acpica/acpi_wakeup.c optional acpica acpi_wakecode.h optional acpica \ dependency "$S/i386/acpica/acpi_wakecode.S" \ Index: conf/files.ia64 =================================================================== RCS file: /home/ncvs/src/sys/conf/files.ia64,v retrieving revision 1.21 diff -u -r1.21 files.ia64 --- conf/files.ia64 23 Oct 2001 15:17:33 -0000 1.21 +++ conf/files.ia64 24 Oct 2001 15:49:43 -0000 @@ -18,6 +18,7 @@ no-obj no-implicit-rule before-depend \ clean "atkbdmap.h" # +ia64/acpica/acpi_machdep.c optional acpica ia64/acpica/acpi_wakeup.c optional acpica ia64/acpica/OsdEnvironment.c optional acpica ia64/acpica/madt.c optional acpica Index: dev/acpica/acpi.c =================================================================== RCS file: /home/ncvs/src/sys/dev/acpica/acpi.c,v retrieving revision 1.42 diff -u -r1.42 acpi.c --- dev/acpica/acpi.c 4 Oct 2001 23:21:09 -0000 1.42 +++ dev/acpica/acpi.c 24 Oct 2001 15:49:43 -0000 @@ -124,7 +124,6 @@ static void acpi_system_eventhandler_sleep(void *arg, int state); static void acpi_system_eventhandler_wakeup(void *arg, int state); -static int acpi_sleep_state_sysctl(SYSCTL_HANDLER_ARGS); static device_method_t acpi_methods[] = { /* Device interface */ @@ -300,8 +299,6 @@ bzero(sc, sizeof(*sc)); sc->acpi_dev = dev; - acpi_install_wakeup_handler(sc); - #ifdef ENABLE_DEBUGGER if (debugpoint && !strcmp(debugpoint, "spaces")) acpi_EnterDebugger(); @@ -425,6 +422,11 @@ if (debugpoint && !strcmp(debugpoint, "running")) acpi_EnterDebugger(); #endif + + if ((error = acpi_machdep_init(dev))) { + goto out; + } + error = 0; out: @@ -1683,7 +1685,7 @@ return(error); } -static int +int acpi_sleep_state_sysctl(SYSCTL_HANDLER_ARGS) { char sleep_state[10]; Index: dev/acpica/acpi_acad.c =================================================================== RCS file: /home/ncvs/src/sys/dev/acpica/acpi_acad.c,v retrieving revision 1.8 diff -u -r1.8 acpi_acad.c --- dev/acpica/acpi_acad.c 6 Sep 2001 23:33:22 -0000 1.8 +++ dev/acpica/acpi_acad.c 24 Oct 2001 15:49:43 -0000 @@ -207,18 +207,37 @@ { int val; int error; - device_t dev; + + if (acpi_acad_get_acline(&val)) { + return (ENXIO); + } + + val = *(u_int *)oidp->oid_arg1; + error = sysctl_handle_int(oidp, &val, 0, req); + return (error); +} + +/* + * Public interfaces. + */ + +int +acpi_acad_get_acline(int *status) +{ + device_t dev; struct acpi_acad_softc *sc; if ((dev = devclass_get_device(acpi_acad_devclass, 0)) == NULL) { return (ENXIO); } + if ((sc = device_get_softc(dev)) == NULL) { return (ENXIO); } + acpi_acad_get_status(dev); - val = *(u_int *)oidp->oid_arg1; - error = sysctl_handle_int(oidp, &val, 0, req); - return (error); + *status = sc->status; + + return (0); } Index: dev/acpica/acpi_battery.c =================================================================== RCS file: /home/ncvs/src/sys/dev/acpica/acpi_battery.c,v retrieving revision 1.2 diff -u -r1.2 acpi_battery.c --- dev/acpica/acpi_battery.c 26 Aug 2001 22:50:15 -0000 1.2 +++ dev/acpica/acpi_battery.c 24 Oct 2001 15:49:43 -0000 @@ -65,14 +65,14 @@ static int acpi_batteries_units = 0; static struct acpi_battinfo acpi_battery_battinfo; -static int +int acpi_battery_get_units(void) { return (acpi_batteries_units); } -static int +int acpi_battery_get_battdesc(int logical_unit, struct acpi_battdesc *battdesc) { int i; @@ -95,7 +95,7 @@ return (ENXIO); } -static int +int acpi_battery_get_battinfo(int unit, struct acpi_battinfo *battinfo) { int error; Index: dev/acpica/acpivar.h =================================================================== RCS file: /home/ncvs/src/sys/dev/acpica/acpivar.h,v retrieving revision 1.18 diff -u -r1.18 acpivar.h --- dev/acpica/acpivar.h 6 Oct 2001 04:09:26 -0000 1.18 +++ dev/acpica/acpivar.h 24 Oct 2001 15:49:43 -0000 @@ -303,6 +303,7 @@ extern int acpi_avoid(ACPI_HANDLE handle); extern int acpi_disabled(char *subsys); +extern int acpi_machdep_init(device_t dev); extern void acpi_install_wakeup_handler(struct acpi_softc *sc); extern int acpi_sleep_machdep(struct acpi_softc *sc, int state); @@ -310,11 +311,22 @@ * Battery Abstruction. */ struct acpi_battinfo; +struct acpi_battdesc; extern int acpi_battery_register(int, int); +extern int acpi_battery_get_battinfo(int, struct acpi_battinfo *); +extern int acpi_battery_get_units(void); +extern int acpi_battery_get_battdesc(int, struct acpi_battdesc *); + extern int acpi_cmbat_get_battinfo(int, struct acpi_battinfo *); /* + * AC adapter interface. + */ + +extern int acpi_acad_get_acline(int *); + +/* * System power API. * * XXX should this be further generalised? @@ -328,3 +340,6 @@ typedef void (*powerprofile_change_hook)(void *); EVENTHANDLER_DECLARE(powerprofile_change, powerprofile_change_hook); + +extern int acpi_sleep_state_sysctl(SYSCTL_HANDLER_ARGS); + Index: modules/acpi/Makefile =================================================================== RCS file: /home/ncvs/src/sys/modules/acpi/Makefile,v retrieving revision 1.14 diff -u -r1.14 Makefile --- modules/acpi/Makefile 4 Oct 2001 23:19:17 -0000 1.14 +++ modules/acpi/Makefile 24 Oct 2001 15:49:43 -0000 @@ -47,8 +47,8 @@ echo '' >opt_ddb.h .endif -# Machine-specific sleep/wakeup code -SRCS+= acpi_wakecode.h acpi_wakeup.c +# Machine-specific code such as sleep/wakeup +SRCS+= acpi_machdep.c acpi_wakecode.h acpi_wakeup.c CLEANFILES+= acpi_wakecode.h acpi_wakecode.o acpi_wakecode.bin acpi_wakecode.h: acpi_wakecode.S --- /dev/null Thu Oct 25 00:33:00 2001 +++ i386/acpica/acpi_machdep.c Tue Oct 23 19:50:05 2001 @@ -0,0 +1,314 @@ +#include +#include +#include +#include +#include + +#include "acpi.h" + +#include +#include + +/* + * APM driver emulation + */ + +#include + +static device_t acpi_dev; +static int apm_active = 0; +static int apm_suspend_state = ACPI_STATE_S3; +static int apm_standby_state = ACPI_STATE_S1; + +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; + +#define CDEV_MAJOR 39 +static struct cdevsw apm_cdevsw = { + /* open */ apmopen, + /* close */ apmclose, + /* read */ noread, + /* write */ apmwrite, + /* ioctl */ apmioctl, + /* poll */ apmpoll, + /* mmap */ nommap, + /* strategy */ nostrategy, + /* name */ "apm", + /* maj */ CDEV_MAJOR, + /* dump */ nodump, + /* psize */ nopsize, + /* flags */ 0, +}; + +static int +acpi_capm_convert_battstate(struct acpi_battinfo *battp) +{ + int state; + + state = 0xff; /* XXX unknown */ + + if (battp->state & ACPI_BATT_STAT_DISCHARG) { + if (battp->cap >= 50) { + state = 0; + } else { + state = 1; + } + } + if (battp->state & ACPI_BATT_STAT_CRITICAL) { + state = 2; + } + if (battp->state & ACPI_BATT_STAT_CHARGING) { + state = 3; + } + return (state); +} + +static int +acpi_capm_convert_battflags(struct acpi_battinfo *battp) +{ + int flags; + + flags = 0; + + if (battp->cap >= 50) { + flags |= APM_BATT_HIGH; + } else { + if (battp->state & ACPI_BATT_STAT_CRITICAL) { + flags |= APM_BATT_CRITICAL; + } else { + flags |= APM_BATT_LOW; + } + } + if (battp->state & ACPI_BATT_STAT_CHARGING) { + flags |= APM_BATT_CHARGING; + } + if (battp->state == ACPI_BATT_STAT_NOT_PRESENT) { + 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; + aip->ai_status = apm_active; + aip->ai_capabilities= 0xff00; /* XXX unknown */ + + if (acpi_acad_get_acline(&acline)) { + aip->ai_acline = 0xff; + } else { + aip->ai_acline = acline; + } + + if (acpi_battery_get_battinfo(-1, &batt)) { + aip->ai_batt_stat = 0xff; + aip->ai_batt_life = 0xff; + aip->ai_batt_time = -1; + aip->ai_batteries = 0; + } 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) +{ + int batt_unit; + int acline; + struct acpi_battinfo batt; + + if (app->ap_device != PMDV_ALLDEV && + (app->ap_device < PMDV_BATT0 || app->ap_device > PMDV_BATT_ALL)) { + return (1); + } + + if (app->ap_device == PMDV_ALLDEV) { + batt_unit = -1; + } else { + batt_unit = app->ap_device - PMDV_BATT0; + } + + if (acpi_battery_get_battinfo(batt_unit, &batt)) { + 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; + + if (acpi_acad_get_acline(&acline)) { + app->ap_acline = 0xff; + } else { + app->ap_acline = acline; + } + + return (0); +} + +static int +apmopen(dev_t dev, int flag, int fmt, struct thread *td) +{ + return (0); +} + +static int +apmclose(dev_t dev, int flag, int fmt, struct thread *td) +{ + return (0); +} + +static int +apmioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td) +{ + int error = 0; + struct acpi_softc *acpi_sc; + + if ((acpi_sc = device_get_softc(acpi_dev)) == NULL) { + return (ENXIO); + } + + switch (cmd) { + case APMIO_SUSPEND: + if (!(flag & FWRITE)) + return (EPERM); + if (apm_active) + acpi_SetSleepState(acpi_sc, apm_suspend_state); + else + error = EINVAL; + break; + + case APMIO_STANDBY: + if (!(flag & FWRITE)) + return (EPERM); + if (apm_active) + acpi_SetSleepState(acpi_sc, apm_standby_state); + else + error = EINVAL; + break; + + case APMIO_GETINFO_OLD: + { + struct apm_info info; + apm_info_old_t aiop; + + 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: + if (!(flag & FWRITE)) + return (EPERM); + apm_active = 1; + break; + + case APMIO_DISABLE: + if (!(flag & FWRITE)) + return (EPERM); + apm_active = 0; + break; + + case APMIO_HALTCPU: + break; + + case APMIO_NOTHALTCPU: + break; + + case APMIO_DISPLAY: + if (!(flag & FWRITE)) + return (EPERM); + break; + + case APMIO_BIOS: + if (!(flag & FWRITE)) + return (EPERM); + bzero(addr, sizeof(struct apm_bios_arg)); + break; + + default: + error = EINVAL; + break; + } + + return (error); +} + +static int +apmwrite(dev_t dev, struct uio *uio, int ioflag) +{ + + return (uio->uio_resid); +} + +static int +apmpoll(dev_t dev, int events, struct thread *td) +{ + return (0); +} + +static void +acpi_capm_init(struct acpi_softc *sc) +{ + + make_dev(&apm_cdevsw, 0, 0, 5, 0664, "apm"); + SYSCTL_ADD_PROC(&sc->acpi_sysctl_ctx, + SYSCTL_CHILDREN(sc->acpi_sysctl_tree), + OID_AUTO, "apm_suspend_state", CTLTYPE_STRING | CTLFLAG_RW, + &apm_suspend_state, 0, acpi_sleep_state_sysctl, "A", ""); + SYSCTL_ADD_PROC(&sc->acpi_sysctl_ctx, + SYSCTL_CHILDREN(sc->acpi_sysctl_tree), + OID_AUTO, "apm_standby_state", CTLTYPE_STRING | CTLFLAG_RW, + &apm_standby_state, 0, acpi_sleep_state_sysctl, "A", ""); +} + +int +acpi_machdep_init(device_t dev) +{ + struct acpi_softc *sc; + + acpi_dev = dev; + if ((sc = device_get_softc(acpi_dev)) == NULL) { + return (ENXIO); + } + + acpi_capm_init(sc); + + acpi_install_wakeup_handler(sc); + + return (0); +} + --- /dev/null Thu Oct 25 00:33:00 2001 +++ ia64/acpica/acpi_machdep.c Mon Oct 22 23:37:35 2001 @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2001 Doug Rabson + * 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. + * + * $FreeBSD$ + */ + +#include +#include + +#include "acpi.h" +#include + +int +acpi_machdep_init(device_t dev) +{ + struct acpi_softc *sc; + + if ((sc = device_get_softc(dev)) == NULL) { + return (ENXIO); + } + + acpi_install_wakeup_handler(sc); + + return (0); +} +