1 // SPDX-License-Identifier: GPL-2.0-only
3 * (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
5 * Based on code found in
6 * linux/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
7 * and originally developed by Paul Devriendt
17 #include <sys/types.h>
22 #define MSR_FIDVID_STATUS 0xc0010042
24 #define MSR_S_HI_CURRENT_VID 0x0000001f
25 #define MSR_S_LO_CURRENT_FID 0x0000003f
27 static int get_fidvid(uint32_t cpu, uint32_t *fid, uint32_t *vid)
37 sprintf(file, "/dev/cpu/%d/msr", cpu);
39 fd = open(file, O_RDONLY);
42 lseek(fd, MSR_FIDVID_STATUS, SEEK_CUR);
43 if (read(fd, &msr, 8) != 8)
46 *fid = ((uint32_t )(msr & 0xffffffffull)) & MSR_S_LO_CURRENT_FID;
47 *vid = ((uint32_t )(msr>>32 & 0xffffffffull)) & MSR_S_HI_CURRENT_VID;
56 /* Return a frequency in MHz, given an input fid */
57 static uint32_t find_freq_from_fid(uint32_t fid)
59 return 800 + (fid * 100);
62 /* Return a voltage in miliVolts, given an input vid */
63 static uint32_t find_millivolts_from_vid(uint32_t vid)
68 int main (int argc, char *argv[])
77 cpu = strtoul(argv[1], NULL, 0);
79 err = get_fidvid(cpu, &fid, &vid);
82 printf("can't get fid, vid from MSR\n");
83 printf("Possible trouble: you don't run a powernow-k8 capable cpu\n");
84 printf("or you are not root, or the msr driver is not present\n");
89 printf("cpu %d currently at %d MHz and %d mV\n",
91 find_freq_from_fid(fid),
92 find_millivolts_from_vid(vid));