2 * This file is part of msrtool.
4 * Copyright (c) 2008 Peter Stuge <peter@stuge.se>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #define HEXCHARS "0123456789abcdefABCDEF"
51 const struct msr value;
60 const uint8_t present;
61 const struct msrbitvalues bitval[32];
67 const struct msr resetval;
70 const struct msrbits bits[65];
73 #define MSR1(lo) { 0, (lo) }
74 #define MSR2(hi,lo) { (hi), (lo) }
76 #define BITVAL_EOT .text = NULL
77 #define BITVAL_ISEOT(bv) (NULL == (bv).text)
79 #define BITS_EOT .size = 0
80 #define BITS_ISEOT(b) (0 == (b).size)
82 #define MSR_EOT .type = MSRTYPE_EOT
83 #define MSR_ISEOT(m) (MSRTYPE_EOT == (m).type)
85 #define NOBITS {{ BITVAL_EOT }}
86 #define RESERVED "RSVD", "Reserved", PRESENT_HEXDEC, NOBITS
92 const char *prettyname;
93 int (*probe)(const struct targetdef *target);
94 const struct msrdef *msrs;
97 #define TARGET_EOT .name = NULL
98 #define TARGET_ISEOT(t) (NULL == (t).name)
109 const char *prettyname;
110 int (*probe)(const struct sysdef *system);
111 int (*open)(uint8_t cpu, enum SysModes mode);
112 int (*close)(uint8_t cpu);
113 int (*rdmsr)(uint8_t cpu, uint32_t addr, struct msr *val);
116 #define SYSTEM_EOT .name = NULL
117 #define SYSTEM_ISEOT(s) (NULL == (s).name)
129 extern const struct sysdef *sys;
131 extern uint8_t targets_found;
132 extern const struct targetdef **targets;
134 extern uint8_t reserved, verbose, quiet;
136 extern struct pci_access *pacc;
138 #define printf_quiet(x...) do { if (!quiet) fprintf(stderr,x); } while(0)
139 #define printf_verbose(x...) do { if (verbose && !quiet) fprintf(stderr,x); } while(0)
141 #define SYSERROR(call, addr) do { \
142 const struct msrdef *m = findmsrdef(addr); \
144 fprintf(stderr, "%s: " #call "(0x%08x) %s: %s\n", __func__, addr, m->symbol, strerror(errno)); \
146 fprintf(stderr, "%s: " #call "(0x%08x): %s\n", __func__, addr, strerror(errno)); \
150 struct cpuid_t *cpuid(void);
151 struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
154 void hexprint(FILE *f, const struct msr val, const uint8_t bits);
155 int msr_eq(const struct msr a, const struct msr b);
156 struct msr msr_shl(const struct msr a, const uint8_t bits);
157 struct msr msr_shr(const struct msr a, const uint8_t bits);
158 void msr_and(struct msr *a, const struct msr b);
159 const struct msrdef *findmsrdef(const uint32_t addr);
160 const uint32_t msraddrbyname(const char *name);
161 void dumpmsrdefs(const struct targetdef *t);
162 int dumpmsrdefsvals(FILE *f, const struct targetdef *t, const uint8_t cpu);
163 uint8_t str2msr(char *str, struct msr *msr);
164 void decodemsr(const uint8_t cpu, const uint32_t addr, const struct msr val);
165 uint8_t diff_msr(FILE *fout, const uint32_t addr, const struct msr a, const struct msr b);
169 /** system externs **/
172 extern int linux_probe(const struct sysdef *system);
173 extern int linux_open(uint8_t cpu, enum SysModes mode);
174 extern int linux_close(uint8_t cpu);
175 extern int linux_rdmsr(uint8_t cpu, uint32_t addr, struct msr *val);
178 /** target externs **/
181 extern int geodelx_probe(const struct targetdef *t);
182 extern const struct msrdef geodelx_msrs[];
185 extern int cs5536_probe(const struct targetdef *t);
186 extern const struct msrdef cs5536_msrs[];
188 #endif /* MSRTOOL_H */