/*- * Copyright (c) 2009 Andriy Gapon * Copyright (c) 2009 Gabriel Craciunescu * ( Added some Linux support ) * 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 /* heci.h in linux is broken ... what a surprise :P */ struct guid { uint32_t data1; uint16_t data2; uint16_t data3; uint8_t data4[8]; }; struct heci_message_data { uint32_t size; char *data; }__attribute__((packed)); #undef IOCTL_HECI_CONNECT_CLIENT #define IOCTL_HECI_CONNECT_CLIENT _IOWR(0x48, 0x01, struct heci_message_data) 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) }; /* Hmmmm seems the output is different depeinding on chipset / ICH version */ /* On my DQ45CB ( ICH10DO / Q45 ) mobo this is right also is the same output Intel Desktop Utils is giving me */ const char * const temp_names[THERM_SENSOR_COUNT] = { "CPU Temp", "MB Temp", "ICH Temp", "MCH Temp", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }; const char * const volt_names[VOLT_SENSOR_COUNT] = { "+12 Volts", "+5 Volts", "+3.3 Volts", "MCH Vccp", "CPU1 Vccp", NULL, NULL, NULL, }; const char * const fan_names[FAN_SENSOR_COUNT] = { "CPU Fan", "INL Fan", "OUTL Fan", "AUX Fan", NULL, NULL, NULL, NULL, }; static const struct guid _hwm_guid = { 0x6B5205B9, 0x8185, 0x4519, {0xB8, 0x89, 0xD9, 0x87, 0x24, 0xB5, 0x86, 0x07} }; int main() { int fd; int rc; int i; struct heci_message_data hwm_guid; fd = open("/dev/heci", O_RDWR); if (fd < 0) { perror("/dev/heci"); fprintf(stderr, "Please load the HECI Kernel module first!\n"); return 1; } hwm_guid.size = sizeof(struct guid); hwm_guid.data = (char *)malloc(hwm_guid.size); if(!hwm_guid.data) { fprintf(stderr, "malloc failure.\n"); return 1; } memcpy(hwm_guid.data, &_hwm_guid, sizeof(_hwm_guid)); rc = ioctl(fd, IOCTL_HECI_CONNECT_CLIENT, &hwm_guid); if (rc < 0) { perror("ioctl IOCTL_HECI_CONNECT_CLIENT"); 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; if (temp_names[i]) printf("%s", temp_names[i]); else printf("%02d", i); printf(":\t%d.%02d \t°C\n", abs(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; if (fan_names[i]) printf("%s", fan_names[i]); else printf("%02d", i); printf(":\t%d \tRPM\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; if (volt_names[i]) printf("%s", volt_names[i]); else printf("%02d", i); printf(":\t%d.%03d \tV\n", abs(value) / 1000, abs(value) % 1000); } } close(fd); return 0; }