/*- * Copyright (c) 2009 Andriy Gapon * 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. */ #include #include #include #include #include #include #include struct therm_sensor { int8_t valid; int32_t value; } __attribute__((packed)); struct volt_sensor { int8_t valid; int32_t value; } __attribute__((packed)); struct fan_sensor { int8_t valid; int16_t value; } __attribute__((packed)); #define THERM_SENSOR_COUNT 12 struct therm_data { int8_t status; struct therm_sensor data[THERM_SENSOR_COUNT]; } __attribute__((packed)); #define VOLT_SENSOR_COUNT 8 struct volt_data { int8_t status; struct volt_sensor data[VOLT_SENSOR_COUNT]; } __attribute__((packed)); #define FAN_SENSOR_COUNT 8 struct fan_data { int8_t status; struct fan_sensor data[FAN_SENSOR_COUNT]; } __attribute__((packed)); struct qst_cmd { uint8_t cmd; uint16_t in_len; uint16_t out_len; } __attribute__((packed)); #define QST_THERMAL_CMD 0x12 static const struct qst_cmd therm_cmd = { QST_THERMAL_CMD, 0, sizeof(struct therm_data) }; #define QST_VOLT_CMD 0x58 static const struct qst_cmd volt_cmd = { QST_VOLT_CMD, 0, sizeof(struct volt_data) }; #define QST_FAN_CMD 0x37 static const struct qst_cmd fan_cmd = { QST_FAN_CMD, 0, sizeof(struct fan_data) }; const char * const temp_names[THERM_SENSOR_COUNT] = { "CPU", "MB1", NULL, "MB2", "ICH", "MCH", NULL, NULL, NULL, NULL, NULL, NULL, }; const char * const volt_names[VOLT_SENSOR_COUNT] = { "12P", "50P", "33", "15", "C0", NULL, NULL, NULL, }; const char * const fan_names[FAN_SENSOR_COUNT] = { "CPU", "INL", "OUTL", "AUX", NULL, NULL, NULL, NULL, }; static const struct heci_guid hwm_guid = { 0x6B5205B9, 0x8185, 0x4519, {0xB8, 0x89, 0xD9, 0x87, 0x24, 0xB5, 0x86, 0x07} }; int main() { int fd; int rc; int i; fd = open("/dev/heci0", O_RDWR); if (fd < 0) { perror("/dev/heci0"); return 1; } rc = ioctl(fd, HECI_CONNECT, &hwm_guid); if (rc < 0) { perror("ioctl HECI_CONNECT"); return 1; } /* Request temp. */ struct therm_data therm_data; rc = write(fd, &therm_cmd, sizeof(therm_cmd)); if (rc < 0) { perror("therm write"); return 1; } rc = read(fd, &therm_data, sizeof(therm_data)); if (rc < 0) { perror("therm read"); return 1; } for (i = 0; i < THERM_SENSOR_COUNT; i++) { if (therm_data.data[i].valid) { int32_t value = therm_data.data[i].value; printf("TEMP"); if (temp_names[i]) printf("%s", temp_names[i]); else printf("%02d", i); printf("\t:\t%d.%02d\n", value / 100, abs(value) % 100); } } /* Request fans */ struct fan_data fan_data; rc = write(fd, &fan_cmd, sizeof(fan_cmd)); if (rc < 0) { perror("fan write"); return 1; } rc = read(fd, &fan_data, sizeof(fan_data)); if (rc < 0) { perror("fan read"); return 1; } for (i = 0; i < FAN_SENSOR_COUNT; i++) { if (fan_data.data[i].valid) { int32_t value = fan_data.data[i].value; printf("FAN"); if (fan_names[i]) printf("%s", fan_names[i]); else printf("%02d", i); printf("\t:\t%d\n", value); } } /* Request volts. */ struct volt_data volt_data; rc = write(fd, &volt_cmd, sizeof(volt_cmd)); if (rc < 0) { perror("volts write"); return 1; } rc = read(fd, &volt_data, sizeof(volt_data)); if (rc < 0) { perror("volts read"); return 1; } for (i = 0; i < VOLT_SENSOR_COUNT; i++) { if (volt_data.data[i].valid) { int32_t value = volt_data.data[i].value; printf("V"); if (volt_names[i]) printf("%s", volt_names[i]); else printf("%02d", i); printf("\t:\t%+d.%03d\n", value / 1000, abs(value) % 1000); } } close(fd); return 0; }