aboutsummaryrefslogtreecommitdiff
path: root/src/zenmonitor.c
blob: 5fe042a2d7f47568ffdaf4c58e56f2969aa6eae3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <gtk/gtk.h>
#include <cpuid.h>
#include "zenmonitor.h"
#include "zenpower.h"
#include "msr.h"
#include "gui.h"

#define AMD_STRING "AuthenticAMD"
#define ZEN_FAMILY 0x17

gboolean check_zen() {
    unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0, ext_family; 
    char vendor[13];

    __get_cpuid(0, &eax, &ebx, &ecx, &edx);

    memcpy(vendor, &ebx, 4);
    memcpy(vendor+4, &edx, 4);
    memcpy(vendor+8, &ecx, 4);
    vendor[12] = 0;

    if (strcmp(vendor, AMD_STRING) != 0){
        return FALSE;
    }

    __get_cpuid(1, &eax, &ebx, &ecx, &edx);

    ext_family = ((eax >> 8) & 0xF) + ((eax >> 20) & 0xFF);
    if (ext_family != ZEN_FAMILY){
        return FALSE;
    }

    return TRUE;
}

static SensorSource sensor_sources[] = {
  { "zenpower", zenpower_init, zenpower_get_sensors, zenpower_update, FALSE, NULL },
  { "msr",      msr_init,      msr_get_sensors,      msr_update,      FALSE, NULL },
  { NULL }
};

SensorInit *sensor_init_new() {
    return g_new0(SensorInit, 1);
}

void sensor_init_free(SensorInit *s) {
    if (s) {
        g_free(s->label);
        g_free(s);
    }
}

int main (int argc, char *argv[])
{
    gtk_init(&argc, &argv);
    start_gui(sensor_sources);
}