Date: Wed, 30 Jan 2008 12:35:04 GMT From: Sven Berkvens-Matthijsse <sven@berkvens.net> To: freebsd-gnats-submit@FreeBSD.org Subject: ports/120149: [PATCH] sysutils/gkrellm2 ACPI battery support on amd64 patch Message-ID: <200801301235.m0UCZ4Pm039983@www.freebsd.org> Resent-Message-ID: <200801301240.m0UCe3jE058111@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 120149 >Category: ports >Synopsis: [PATCH] sysutils/gkrellm2 ACPI battery support on amd64 patch >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Jan 30 12:40:03 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Sven Berkvens-Matthijsse >Release: 7.0-PRERELEASE >Organization: De Kattenfabriek >Environment: FreeBSD paws.berkvens.net 7.0-PRERELEASE FreeBSD 7.0-PRERELEASE #6: Thu Jan 17 15:33:53 CET 2008 sven@paws.berkvens.net:/usr/obj/usr/src/sys/PAWS amd64 >Description: The sysutils/gkrellm2 port works fine on amd64 machines, but has no support for the battery state on my laptop. This is because the battery code is only compiled if __i386__ is defined. But on __amd64__, the ACPI code for the battery is usable. I've modified the existing patch for freebsd.c so that it will compile a part of the battery code for __amd64__, which actually yields the correct results on my laptop. >How-To-Repeat: >Fix: Patch attached which is intended to replace the existing /usr/ports/sysutils/gkrellm2/files/patch-src::sysdeps::freebsd.c file. Patch attached with submission follows: --- src/sysdeps/freebsd.c.orig 2007-07-07 01:53:07.000000000 +0200 +++ src/sysdeps/freebsd.c 2008-01-30 13:15:45.000000000 +0100 @@ -1078,9 +1078,13 @@ /* ===================================================================== */ /* Battery monitor interface */ -#if defined(__i386__) +#if defined(__i386__) || defined(__amd64__) #include <osreldate.h> +#if defined(__i386__) #include <machine/apm_bios.h> +#else +#include <machine/acpica_machdep.h> +#endif #define APMDEV "/dev/apm" #define L_NO_BATTERY 0x80 @@ -1114,7 +1118,9 @@ int acpi_info[4]; int i; int f, r; +#if defined(__i386__) struct apm_info info; +#endif gboolean available, on_line, charging; gint percent, time_left; gint batt_num = 0; @@ -1122,7 +1128,7 @@ if (!first_time_done) { first_time_done = TRUE; -#ifdef ACPI_SUPPORTS_MULTIPLE_BATTERIES +#if defined(ACPI_SUPPORTS_MULTIPLE_BATTERIES) || defined(__amd64__) /* * XXX: Disable getting battery information via ACPI * to support multiple batteries via APM sim until @@ -1162,6 +1168,7 @@ return; } +#if defined(__i386__) if ((f = open(APMDEV, O_RDONLY)) == -1) return; if ((r = ioctl(f, APMIO_GETINFO, &info)) == -1) { @@ -1219,6 +1226,7 @@ #endif close(f); +#endif } gboolean @@ -1286,6 +1294,7 @@ #define INTERFACE_IO 0 #define INTERFACE_SMB 1 #define INTERFACE_ACPI 2 +#define INTERFACE_CORETEMP 3 /* Already in Celsius */ /* Addresses to use for /dev/io */ #define WBIO1 0x295 @@ -1345,6 +1354,8 @@ { u_char byte; + int value; + size_t size; if (interface == MBMON_INTERFACE) { @@ -1354,15 +1365,24 @@ if (interface == INTERFACE_ACPI) { - int value; - size_t size = sizeof(value); - + size = sizeof(value); if (sysctlbyname(path, &value, &size, NULL, 0) < 0) return FALSE; if (temp) *temp = (gfloat) TZ_KELVTOC(value); return TRUE; } + + if (interface == INTERFACE_CORETEMP) + { + size = sizeof(value); + if (sysctlbyname(path, &value, &size, NULL, 0) < 0) + return FALSE; + if (temp) + *temp = (gfloat) value; + return TRUE; + } + if (get_data(iodev, LM78_TEMP, interface, &byte)) { if (temp) @@ -1435,7 +1455,7 @@ gchar mib_name[256], label[8]; gint interface, id; int oid_acpi_temp[CTL_MAXNAME + 2]; - size_t oid_acpi_temp_len = sizeof(oid_acpi_temp); + size_t oid_acpi_temp_len; GList *list; struct freebsd_sensor *sensor; @@ -1443,10 +1463,12 @@ */ gkrellm_sys_sensors_mbmon_check(TRUE); - for (id = 0;;) - { + /* ACPI Thermal */ + for (id = 0;; id++) + { snprintf(mib_name, sizeof(mib_name), "hw.acpi.thermal.tz%d.temperature", id); + oid_acpi_temp_len = sizeof(oid_acpi_temp); if (gk_sysctlnametomib(mib_name, oid_acpi_temp, &oid_acpi_temp_len) < 0) break; @@ -1458,7 +1480,27 @@ gkrellm_sensors_add_sensor(SENSOR_TEMPERATURE, NULL, mib_name, 0, 0, interface, 1.0, 0.0, NULL, label); - } + } + + /* Coretemp */ + for (id = 0;; id++) + { + snprintf(mib_name, sizeof(mib_name), + "dev.cpu.%d.temperature", id); + oid_acpi_temp_len = sizeof(oid_acpi_temp); + if (gk_sysctlnametomib(mib_name, oid_acpi_temp, + &oid_acpi_temp_len) < 0) + break; + interface = INTERFACE_CORETEMP; + if (!gkrellm_sys_sensors_get_temperature(mib_name, 0, 0, + interface, NULL)) + continue; + snprintf(label, sizeof(label), "cpu%d", id); + gkrellm_sensors_add_sensor(SENSOR_TEMPERATURE, NULL, + mib_name, 0, 0, + interface, 1.0, 0.0, NULL, label); + } + if (freebsd_sensor_list) { >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200801301235.m0UCZ4Pm039983>