2 * (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
4 * Licensed under the terms of the GNU GPL License version 2.
6 * Based on code found in
7 * linux/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
8 * and originally developed by Paul Devriendt
18 #include <sys/types.h>
23 #define MSR_FIDVID_STATUS 0xc0010042
25 #define MSR_S_HI_CURRENT_VID 0x0000001f
26 #define MSR_S_LO_CURRENT_FID 0x0000003f
28 static int get_fidvid(uint32_t cpu
, uint32_t *fid
, uint32_t *vid
)
38 sprintf(file
, "/dev/cpu/%d/msr", cpu
);
40 fd
= open(file
, O_RDONLY
);
43 lseek(fd
, MSR_FIDVID_STATUS
, SEEK_CUR
);
44 if (read(fd
, &msr
, 8) != 8)
47 *fid
= ((uint32_t )(msr
& 0xffffffffull
)) & MSR_S_LO_CURRENT_FID
;
48 *vid
= ((uint32_t )(msr
>>32 & 0xffffffffull
)) & MSR_S_HI_CURRENT_VID
;
57 /* Return a frequency in MHz, given an input fid */
58 static uint32_t find_freq_from_fid(uint32_t fid
)
60 return 800 + (fid
* 100);
63 /* Return a voltage in miliVolts, given an input vid */
64 static uint32_t find_millivolts_from_vid(uint32_t vid
)
69 int main (int argc
, char *argv
[])
78 cpu
= strtoul(argv
[1], NULL
, 0);
80 err
= get_fidvid(cpu
, &fid
, &vid
);
83 printf("can't get fid, vid from MSR\n");
84 printf("Possible trouble: you don't run a powernow-k8 capable cpu\n");
85 printf("or you are not root, or the msr driver is not present\n");
90 printf("cpu %d currently at %d MHz and %d mV\n",
92 find_freq_from_fid(fid
),
93 find_millivolts_from_vid(vid
));