diff -ruN gkibm-acpi-0.1.1/README gkibm-acpi-0.1.1.freebsd/README --- gkibm-acpi-0.1.1/README 2005-03-30 10:28:51.000000000 +0200 +++ gkibm-acpi-0.1.1.freebsd/README 2007-05-18 12:00:00.000000000 +0200 @@ -3,6 +3,7 @@ required to run this: Gkrellm2 (http://www.gkrellm.net) ibm-acpi driver (http://ibm-acpi.sourceforge.net/) + or acpi_ibm(4) on FreeBSD Each value has in its own plugin, the plugins are: @@ -20,3 +21,5 @@ http://www.mulliner.org/collin/ This is heavily based on gkfreq by Brad Davis! + +FreeBSD support added by Fabian Keil diff -ruN gkibm-acpi-0.1.1/data.c gkibm-acpi-0.1.1.freebsd/data.c --- gkibm-acpi-0.1.1/data.c 2005-03-30 10:28:51.000000000 +0200 +++ gkibm-acpi-0.1.1.freebsd/data.c 2007-10-15 10:30:31.000000000 +0200 @@ -3,7 +3,65 @@ #include #include + +#ifdef TEST + +#include +#define FAN +#define THERMAL + +#endif /* def TEST */ + + +#ifdef __FreeBSD__ + +#include + +#endif /* def __FreeBSD__ */ + + #ifdef FAN +#ifdef __FreeBSD__ + +char *read_fan(void) +{ + static char info[20]; + int fan_speed; + size_t fan_speed_size = sizeof(fan_speed); + + if (sysctlbyname("dev.acpi_ibm.0.fan_speed", &fan_speed, &fan_speed_size, NULL, 0)) + { + return "acpi_ibm.ko loaded?"; + } + + /* + * Quoting acpi_ibm(4): + * + * dev.acpi_ibm.0.fan_speed + * + * (read-only) Fan speed in rounds per minute. A few older + * ThinkPads report the fan speed in levels ranging from 0 + * (off) to 7 (max). + */ + if (0 < fan_speed) + { + snprintf(info, sizeof(info), "%d", fan_speed); + + if (7 < fan_speed) + { + strlcat(info, " RPM", sizeof(info)); + } + } + else + { + return "Fan Off"; + } + + return info; +} + +#else + char *read_fan() { FILE *f; @@ -31,9 +89,73 @@ return(buffer); } -#endif + +#endif /* def __FreeBSD__ */ +#endif /* def FAN */ #ifdef THERMAL +#ifdef __FreeBSD__ + +static const char *sensors[] = {"CPU", "PCI", "HDD", "GPU", "BAT", "UBAT", "BAT2", "UBAT2"}; +#define NUMBER_OF_SENSORS sizeof(sensors) / sizeof(char*) + +char *read_data(int i) +{ + static char info[20]; + int thermal[NUMBER_OF_SENSORS]; + size_t thermal_size = sizeof(thermal); + + if (NUMBER_OF_SENSORS - 1 < i) + { + return "Unsupported sensor"; + } + + if (sysctlbyname("dev.acpi_ibm.0.thermal", thermal, &thermal_size, NULL, 0)) + { + return "acpi_ibm.ko loaded?"; + } + else + { + /* + * Quoting acpi_ibm(4): + * + * dev.acpi_ibm.0.thermal + * + * (read-only) Shows the readings of up to eight different tempera- + * ture sensors. Most ThinkPads include six or more temperature + * sensors but only expose the CPU temperature through + * acpi_thermal(4). Some ThinkPads have the below sensor layout + * which might vary depending on the specific model: + * + * 1. CPU + * 2. Mini PCI Module + * 3. HDD + * 4. GPU + * 5. Built-in battery + * 6. UltraBay battery + * 7. Built-in battery + * 8. UltraBay battery + */ + const int temperature = thermal[i]; + const char *sensor = sensors[i]; + + if (0 <= temperature) + { + snprintf(info, sizeof(info), "%s %dC", sensor, temperature); + } + else + { + snprintf(info, sizeof(info), "%s n/a", sensor); + } + + } + + return info; +} + +#else + +#define NUMBER_OF_SENSORS 5 char *read_data(int i) { FILE *f; @@ -72,4 +194,25 @@ return(buffer); } -#endif + +#endif /* def __FREEBSD__ */ +#endif /* def THERMAL */ + +#ifdef TEST + +int main (void) +{ + int i; + + printf("Does this look reasonable?\n"); + + for (i = 0; i < NUMBER_OF_SENSORS; i++) + { + printf("%s, ", read_data(i)); + } + printf("%s\n", read_fan()); + + exit(0); +} + +#endif /* def TEST */ diff -ruN gkibm-acpi-0.1.1/gkibm_acpi.c gkibm-acpi-0.1.1.freebsd/gkibm_acpi.c --- gkibm-acpi-0.1.1/gkibm_acpi.c 2005-03-30 10:28:51.000000000 +0200 +++ gkibm-acpi-0.1.1.freebsd/gkibm_acpi.c 2007-05-18 12:00:00.000000000 +0200 @@ -2,6 +2,7 @@ * (c) Collin R. Mulliner * http://www.mulliner.org/collin/ * + * FreeBSD acpi_ibm(4) support: (c) 2007 Fabian Keil * * This is heavily based on gkfreq by Brad Davis! * @@ -98,8 +99,10 @@ gkrellm_draw_decal_text(panel, decal_text1, info, w - x_scroll); gkrellm_draw_panel_layers(panel); +#ifndef __FreeBSD__ // malloc'd it from read_data/fan free(info); +#endif } diff -ruN gkibm-acpi-0.1.1/makefile gkibm-acpi-0.1.1.freebsd/makefile --- gkibm-acpi-0.1.1/makefile 2005-03-30 10:28:51.000000000 +0200 +++ gkibm-acpi-0.1.1.freebsd/makefile 2007-05-18 12:00:00.000000000 +0200 @@ -32,10 +32,17 @@ gcc -Wall -O2 -c data.c -DTHERMAL gcc -shared -Wall -o gkibm_hdd.so $(OBJ) +test: testclean + gcc -Wall -DTEST -o test data.c + ./test + +testclean: + rm -f ./test + bclean: rm -f *.o -clean: bclean +clean: bclean testclean rm -f *.so install: