Index: conf/files =================================================================== RCS file: /home/ncvs/src/sys/conf/files,v retrieving revision 1.590 diff -u -r1.590 files --- conf/files 7 Dec 2001 01:52:40 -0000 1.590 +++ conf/files 26 Dec 2001 05:24:22 -0000 @@ -207,7 +207,6 @@ dev/acpica/acpi_lid.c optional acpica dev/acpica/acpi_pcib.c optional acpica pci dev/acpica/acpi_powerres.c optional acpica -dev/acpica/acpi_powerprofile.c optional acpica dev/acpica/acpi_resource.c optional acpica dev/acpica/acpi_thermal.c optional acpica dev/acpica/acpi_timer.c optional acpica Index: dev/acpica/acpi_acad.c =================================================================== RCS file: /home/ncvs/src/sys/dev/acpica/acpi_acad.c,v retrieving revision 1.10 diff -u -r1.10 acpi_acad.c --- dev/acpica/acpi_acad.c 18 Nov 2001 18:12:07 -0000 1.10 +++ dev/acpica/acpi_acad.c 26 Dec 2001 05:24:22 -0000 @@ -37,6 +37,7 @@ #include #include #include +#include #include "acpi.h" #include @@ -79,7 +80,7 @@ if (sc->status != newstatus) { sc->status = newstatus; /* set system power profile based on AC adapter status */ - powerprofile_set_state(sc->status ? POWERPROFILE_PERFORMANCE : POWERPROFILE_ECONOMY); + power_profile_set_state(sc->status ? POWER_PROFILE_PERFORMANCE : POWER_PROFILE_ECONOMY); ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "%s Line\n",(sc->status) ? "On" : "Off"); } Index: dev/acpica/acpi_cpu.c =================================================================== RCS file: /home/ncvs/src/sys/dev/acpica/acpi_cpu.c,v retrieving revision 1.8 diff -u -r1.8 acpi_cpu.c --- dev/acpica/acpi_cpu.c 18 Nov 2001 18:12:07 -0000 1.8 +++ dev/acpica/acpi_cpu.c 26 Dec 2001 05:24:22 -0000 @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -99,7 +100,7 @@ static int acpi_cpu_attach(device_t dev); static void acpi_cpu_init_throttling(void *arg); static void acpi_cpu_set_speed(u_int32_t speed); -static void acpi_cpu_powerprofile(void *arg); +static void acpi_cpu_power_profile(void *arg); static int acpi_cpu_speed_sysctl(SYSCTL_HANDLER_ARGS); static device_method_t acpi_cpu_methods[] = { @@ -278,7 +279,7 @@ cpu_economy_state = cpu_temp_speed; /* register performance profile change handler */ - EVENTHANDLER_REGISTER(powerprofile_change, acpi_cpu_powerprofile, NULL, 0); + EVENTHANDLER_REGISTER(power_profile_change, acpi_cpu_power_profile, NULL, 0); /* if ACPI 2.0+, signal platform that we are taking over throttling */ if (cpu_pstate_cnt != 0) { @@ -289,7 +290,7 @@ ACPI_UNLOCK; /* set initial speed */ - acpi_cpu_powerprofile(NULL); + acpi_cpu_power_profile(NULL); printf("acpi_cpu: CPU throttling enabled, %d steps from 100%% to %d.%d%%\n", CPU_MAX_SPEED, CPU_SPEED_PRINTABLE(1)); @@ -345,13 +346,13 @@ * Uses the ACPI lock to avoid reentrancy. */ static void -acpi_cpu_powerprofile(void *arg) +acpi_cpu_power_profile(void *arg) { u_int32_t new; ACPI_LOCK; - new = (powerprofile_get_state() == POWERPROFILE_PERFORMANCE) ? cpu_performance_state : cpu_economy_state; + new = (power_profile_get_state() == POWER_PROFILE_PERFORMANCE) ? cpu_performance_state : cpu_economy_state; if (cpu_current_state != new) acpi_cpu_set_speed(new); @@ -385,7 +386,7 @@ /* set new value and possibly switch */ *argp = arg; - acpi_cpu_powerprofile(NULL); + acpi_cpu_power_profile(NULL); return(0); } Index: dev/acpica/acpi_thermal.c =================================================================== RCS file: /home/ncvs/src/sys/dev/acpica/acpi_thermal.c,v retrieving revision 1.20 diff -u -r1.20 acpi_thermal.c --- dev/acpica/acpi_thermal.c 22 Dec 2001 16:05:34 -0000 1.20 +++ dev/acpica/acpi_thermal.c 26 Dec 2001 05:24:22 -0000 @@ -33,6 +33,7 @@ #include #include #include +#include #include "acpi.h" @@ -83,7 +84,7 @@ #define TZ_THFLAG_CRT (1<<3) int tz_flags; #define TZ_FLAG_NO_SCP (1<<0) /* no _SCP method */ -#define TZ_FLAG_GETPROFILE (1<<1) /* fetch powerprofile in timeout */ +#define TZ_FLAG_GETPROFILE (1<<1) /* fetch power_profile in timeout */ struct timespec tz_cooling_started; /* current cooling starting time */ struct sysctl_ctx_list tz_sysctl_ctx; /* sysctl tree */ @@ -106,7 +107,7 @@ static int acpi_tz_active_sysctl(SYSCTL_HANDLER_ARGS); static void acpi_tz_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context); static void acpi_tz_timeout(void *arg); -static void acpi_tz_powerprofile(void *arg); +static void acpi_tz_power_profile(void *arg); static device_method_t acpi_tz_methods[] = { /* Device interface */ @@ -243,7 +244,7 @@ * invocation by our timeout. We defer it like this so that the rest * of the subsystem has time to come up. */ - EVENTHANDLER_REGISTER(powerprofile_change, acpi_tz_powerprofile, sc, 0); + EVENTHANDLER_REGISTER(power_profile_change, acpi_tz_power_profile, sc, 0); sc->tz_flags |= TZ_FLAG_GETPROFILE; /* @@ -707,7 +708,7 @@ /* do we need to get the power profile settings? */ if (sc->tz_flags & TZ_FLAG_GETPROFILE) { - acpi_tz_powerprofile(arg); + acpi_tz_power_profile(arg); sc->tz_flags &= ~TZ_FLAG_GETPROFILE; } @@ -732,7 +733,7 @@ * to get the ACPI lock itself. */ static void -acpi_tz_powerprofile(void *arg) +acpi_tz_power_profile(void *arg) { ACPI_OBJECT_LIST args; ACPI_OBJECT obj; @@ -746,7 +747,7 @@ /* call _SCP to set the new profile */ obj.Type = ACPI_TYPE_INTEGER; - obj.Integer.Value = (powerprofile_get_state() == POWERPROFILE_PERFORMANCE) ? 0 : 1; + obj.Integer.Value = (power_profile_get_state() == POWER_PROFILE_PERFORMANCE) ? 0 : 1; args.Count = 1; args.Pointer = &obj; if (ACPI_FAILURE(status = AcpiEvaluateObject(sc->tz_handle, "_SCP", &args, NULL))) { Index: dev/acpica/acpivar.h =================================================================== RCS file: /home/ncvs/src/sys/dev/acpica/acpivar.h,v retrieving revision 1.26 diff -u -r1.26 acpivar.h --- dev/acpica/acpivar.h 25 Dec 2001 06:06:56 -0000 1.26 +++ dev/acpica/acpivar.h 26 Dec 2001 05:24:22 -0000 @@ -349,21 +349,6 @@ extern int acpi_acad_get_acline(int *); -/* - * System power API. - * - * XXX should this be further generalised? - * - */ -#define POWERPROFILE_PERFORMANCE 0 -#define POWERPROFILE_ECONOMY 1 - -extern int powerprofile_get_state(void); -extern void powerprofile_set_state(int state); - -typedef void (*powerprofile_change_hook)(void *); -EVENTHANDLER_DECLARE(powerprofile_change, powerprofile_change_hook); - #if defined(ACPI_MAX_THREADS) && ACPI_MAX_THREADS > 0 /* * ACPI task kernel thread initialization. Index: i386/apm/apm.c =================================================================== RCS file: /home/ncvs/src/sys/i386/apm/apm.c,v retrieving revision 1.124 diff -u -r1.124 apm.c --- i386/apm/apm.c 1 Nov 2001 16:33:31 -0000 1.124 +++ i386/apm/apm.c 26 Dec 2001 05:24:22 -0000 @@ -906,6 +906,24 @@ return (sc->sc_flags & SCFLAG_OCTL) ? 0 : 1; /* user may handle */ } +/* Power profile */ +static void +apm_power_profile(struct apm_softc *sc) +{ + int state; + struct apm_info info; + static int apm_acline = 0; + + if (apm_get_info(&info)) + return; + + if (apm_acline != info.ai_acline) { + apm_acline = info.ai_acline; + state = apm_acline ? POWER_PROFILE_PERFORMANCE : POWER_PROFILE_ECONOMY; + power_profile_set_state(state); + } +} + /* Process APM event */ static void apm_processevent(void) @@ -975,6 +993,7 @@ break; OPMEV_DEBUGMESSAGE(PMEV_POWERSTATECHANGE); apm_record_event(sc, apm_event); + apm_power_profile(sc); break; OPMEV_DEBUGMESSAGE(PMEV_UPDATETIME); apm_record_event(sc, apm_event); @@ -982,6 +1001,7 @@ break; OPMEV_DEBUGMESSAGE(PMEV_CAPABILITIESCHANGE); apm_record_event(sc, apm_event); + apm_power_profile(sc); break; case PMEV_NOEVENT: break; Index: i386/i386/identcpu.c =================================================================== RCS file: /home/ncvs/src/sys/i386/i386/identcpu.c,v retrieving revision 1.96 diff -u -r1.96 identcpu.c --- i386/i386/identcpu.c 30 Nov 2001 11:57:23 -0000 1.96 +++ i386/i386/identcpu.c 26 Dec 2001 05:24:22 -0000 @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -1140,9 +1141,22 @@ static u_int crusoe_frequency; static u_int crusoe_voltage; static u_int crusoe_percentage; +static u_int crusoe_performance_longrun = LONGRUN_MODE_PERFORMANCE; +static u_int crusoe_economy_longrun = LONGRUN_MODE_ECONOMY; static struct sysctl_ctx_list crusoe_sysctl_ctx; static struct sysctl_oid *crusoe_sysctl_tree; +static void +tmx86_longrun_power_profile(void *arg) +{ + u_int new; + + new = (power_profile_get_state() == POWER_PROFILE_PERFORMANCE) ? crusoe_performance_longrun : crusoe_economy_longrun; + if (tmx86_get_longrun_mode() != new) { + tmx86_set_longrun_mode(new); + } +} + static int tmx86_longrun_sysctl(SYSCTL_HANDLER_ARGS) { @@ -1180,6 +1194,34 @@ return (error); } +static int +tmx86_longrun_profile_sysctl(SYSCTL_HANDLER_ARGS) +{ + u_int32_t *argp; + u_int32_t arg; + int error; + + argp = (u_int32_t *)oidp->oid_arg1; + arg = *argp; + error = sysctl_handle_int(oidp, &arg, 0, req); + + /* error or no new value */ + if ((error != 0) || (req->newptr == NULL)) + return(error); + + /* range check */ + if (arg >= LONGRUN_MODE_UNKNOWN) + return(EINVAL); + + /* set new value and possibly switch */ + *argp = arg; + + tmx86_longrun_power_profile(NULL); + + return(0); + +} + static void setup_tmx86_longrun(void) { @@ -1210,6 +1252,16 @@ OID_AUTO, "percentage", CTLTYPE_INT | CTLFLAG_RD, &crusoe_percentage, 0, tmx86_status_sysctl, "I", "Processing performance (%)"); + SYSCTL_ADD_PROC(&crusoe_sysctl_ctx, SYSCTL_CHILDREN(crusoe_sysctl_tree), + OID_AUTO, "performance_longrun", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_RW, + &crusoe_performance_longrun, 0, tmx86_longrun_profile_sysctl, "I", ""); + SYSCTL_ADD_PROC(&crusoe_sysctl_ctx, SYSCTL_CHILDREN(crusoe_sysctl_tree), + OID_AUTO, "economy_longrun", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_RW, + &crusoe_economy_longrun, 0, tmx86_longrun_profile_sysctl, "I", ""); + + /* register performance profile change handler */ + EVENTHANDLER_REGISTER(power_profile_change, tmx86_longrun_power_profile, NULL, 0); + } static void Index: kern/subr_power.c =================================================================== RCS file: /home/ncvs/src/sys/kern/subr_power.c,v retrieving revision 1.1 diff -u -r1.1 subr_power.c --- kern/subr_power.c 1 Nov 2001 16:33:48 -0000 1.1 +++ kern/subr_power.c 26 Dec 2001 05:24:22 -0000 @@ -28,6 +28,7 @@ #include #include +#include #include @@ -72,5 +73,35 @@ return; power_pm_fn(POWER_CMD_SUSPEND, power_pm_arg, state); +} + +/* + * Power profile. + */ + +static int power_profile_state = POWER_PROFILE_PERFORMANCE; + +int +power_profile_get_state(void) +{ + return(power_profile_state); +} + +void +power_profile_set_state(int state) +{ + int changed; + + if (state != power_profile_state) { + power_profile_state = state; + changed = 1; + printf("system power profile changed to '%s'\n", + (state == POWER_PROFILE_PERFORMANCE) ? "performance" : "economy"); + } else { + changed = 0; + } + + if (changed) + EVENTHANDLER_INVOKE(power_profile_change); } Index: modules/acpi/Makefile =================================================================== RCS file: /home/ncvs/src/sys/modules/acpi/Makefile,v retrieving revision 1.18 diff -u -r1.18 Makefile --- modules/acpi/Makefile 22 Dec 2001 16:05:41 -0000 1.18 +++ modules/acpi/Makefile 26 Dec 2001 05:24:22 -0000 @@ -28,7 +28,7 @@ # OSD layer SRCS+= acpi.c acpi_acad.c acpi_battery.c acpi_button.c acpi_cmbat.c acpi_cpu.c -SRCS+= acpi_ec.c acpi_lid.c acpi_pcib.c acpi_powerprofile.c +SRCS+= acpi_ec.c acpi_lid.c acpi_pcib.c SRCS+= acpi_powerres.c acpi_resource.c acpi_thermal.c acpi_timer.c SRCS+= acpica_support.c SRCS+= OsdDebug.c Index: sys/power.h =================================================================== RCS file: /home/ncvs/src/sys/sys/power.h,v retrieving revision 1.1 diff -u -r1.1 power.h --- sys/power.h 1 Nov 2001 16:34:07 -0000 1.1 +++ sys/power.h 26 Dec 2001 05:24:22 -0000 @@ -29,6 +29,8 @@ #ifndef _SYS_POWER_H_ #define _SYS_POWER_H_ +#include + /* Power management system type */ #define POWER_PM_TYPE_APM 0x00 #define POWER_PM_TYPE_ACPI 0x01 @@ -46,6 +48,18 @@ extern int power_pm_register(u_int, power_pm_fn_t, void *); extern u_int power_pm_get_type(void); extern void power_pm_suspend(int); + +/* + * System power API. + */ +#define POWER_PROFILE_PERFORMANCE 0 +#define POWER_PROFILE_ECONOMY 1 + +extern int power_profile_get_state(void); +extern void power_profile_set_state(int); + +typedef void (*power_profile_change_hook)(void *); +EVENTHANDLER_DECLARE(power_profile_change, power_profile_change_hook); #endif /* !_SYS_POWER_H_ */