From owner-svn-src-head@FreeBSD.ORG Sun May 31 10:27:24 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D5480106566B; Sun, 31 May 2009 10:27:24 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A8D028FC12; Sun, 31 May 2009 10:27:24 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n4VAROfl038325; Sun, 31 May 2009 10:27:24 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n4VAROFt038324; Sun, 31 May 2009 10:27:24 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <200905311027.n4VAROFt038324@svn.freebsd.org> From: Nathan Whitehorn Date: Sun, 31 May 2009 10:27:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r193161 - head/usr.sbin/powerd X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 May 2009 10:27:25 -0000 Author: nwhitehorn Date: Sun May 31 10:27:24 2009 New Revision: 193161 URL: http://svn.freebsd.org/changeset/base/193161 Log: Teach powerd how to query the PMU AC line state on PowerPC. Modified: head/usr.sbin/powerd/powerd.c Modified: head/usr.sbin/powerd/powerd.c ============================================================================== --- head/usr.sbin/powerd/powerd.c Sun May 31 10:13:10 2009 (r193160) +++ head/usr.sbin/powerd/powerd.c Sun May 31 10:27:24 2009 (r193161) @@ -74,6 +74,7 @@ const char *modes[] = { }; #define ACPIAC "hw.acpi.acline" +#define PMUAC "dev.pmu.0.acline" #define APMDEV "/dev/apm" #define DEVDPIPE "/var/run/devd.pipe" #define DEVCTL_MAXBUF 1024 @@ -93,7 +94,8 @@ static void usage(void); static int cp_times_mib[2]; static int freq_mib[4]; static int levels_mib[4]; -static int acline_mib[3]; +static int acline_mib[4]; +static size_t acline_mib_len; /* Configuration */ static int cpu_running_mark; @@ -105,7 +107,7 @@ static volatile sig_atomic_t exit_reques static power_src_t acline_status; static enum { ac_none, - ac_acpi_sysctl, + ac_sysctl, ac_acpi_devd, #ifdef USE_APM ac_apm, @@ -259,13 +261,18 @@ get_freq_id(int freq, int *freqs, int nu static void acline_init() { - size_t len; + acline_mib_len = 4; - len = 3; - if (sysctlnametomib(ACPIAC, acline_mib, &len) == 0) { - acline_mode = ac_acpi_sysctl; + if (sysctlnametomib(ACPIAC, acline_mib, &acline_mib_len) == 0) { + acline_mode = ac_sysctl; + if (vflag) + warnx("using sysctl for AC line status"); +#if __powerpc__ + } else if (sysctlnametomib(PMUAC, acline_mib, &acline_mib_len) == 0) { + acline_mode = ac_sysctl; if (vflag) warnx("using sysctl for AC line status"); +#endif #ifdef USE_APM } else if ((apm_fd = open(APMDEV, O_RDONLY)) >= 0) { if (vflag) @@ -291,7 +298,7 @@ acline_read(void) if (vflag) warnx("lost devd connection, switching to sysctl"); devd_close(); - acline_mode = ac_acpi_sysctl; + acline_mode = ac_sysctl; /* FALLTHROUGH */ } if (rlen > 0 && @@ -301,12 +308,13 @@ acline_read(void) sscanf(ptr, "notify=%x", ¬ify) == 1) acline_status = (notify ? SRC_AC : SRC_BATTERY); } - if (acline_mode == ac_acpi_sysctl) { + if (acline_mode == ac_sysctl) { int acline; size_t len; len = sizeof(acline); - if (sysctl(acline_mib, 3, &acline, &len, NULL, 0) == 0) + if (sysctl(acline_mib, acline_mib_len, &acline, &len, + NULL, 0) == 0) acline_status = (acline ? SRC_AC : SRC_BATTERY); else acline_status = SRC_UNKNOWN; @@ -326,7 +334,7 @@ acline_read(void) } #endif /* try to (re)connect to devd */ - if (acline_mode == ac_acpi_sysctl) { + if (acline_mode == ac_sysctl) { struct timeval now; gettimeofday(&now, NULL);