2 * This file is part of msrtool.
4 * Copyright (c) 2008 Peter Stuge <peter@stuge.se>
5 * Copyright (c) 2009 coresystems GmbH
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #if (defined(__MACH__) && defined(__APPLE__))
27 /* DirectHW is available here: http://www.coreboot.org/DirectHW */
29 #include <DirectHW/DirectHW.h>
31 #if defined(__FreeBSD__)
32 #include <sys/ioctl.h>
33 #include <sys/cpuctl.h>
37 #define HEXCHARS "0123456789abcdefABCDEF"
61 const struct msr value;
70 const uint8_t present;
71 const struct msrbitvalues bitval[32];
77 const struct msr resetval;
80 const struct msrbits bits[65];
83 #define MSR1(lo) { 0, (lo) }
84 #define MSR2(hi,lo) { (hi), (lo) }
86 #define BITVAL_EOT .text = NULL
87 #define BITVAL_ISEOT(bv) (NULL == (bv).text)
89 #define BITS_EOT .size = 0
90 #define BITS_ISEOT(b) (0 == (b).size)
92 #define MSR_EOT .type = MSRTYPE_EOT
93 #define MSR_ISEOT(m) (MSRTYPE_EOT == (m).type)
95 #define NOBITS {{ BITVAL_EOT }}
96 #define RESERVED "RSVD", "Reserved", PRESENT_HEXDEC, NOBITS
102 const char *prettyname;
103 int (*probe)(const struct targetdef *target);
104 const struct msrdef *msrs;
107 #define TARGET_EOT .name = NULL
108 #define TARGET_ISEOT(t) (NULL == (t).name)
119 const char *prettyname;
120 int (*probe)(const struct sysdef *system);
121 int (*open)(uint8_t cpu, enum SysModes mode);
122 int (*close)(uint8_t cpu);
123 int (*rdmsr)(uint8_t cpu, uint32_t addr, struct msr *val);
126 #define SYSTEM_EOT .name = NULL
127 #define SYSTEM_ISEOT(s) (NULL == (s).name)
139 extern const struct sysdef *sys;
141 extern uint8_t targets_found;
142 extern const struct targetdef **targets;
144 extern uint8_t reserved, verbose, quiet;
146 extern struct pci_access *pacc;
148 #define printf_quiet(x...) do { if (!quiet) fprintf(stderr,x); } while(0)
149 #define printf_verbose(x...) do { if (verbose && !quiet) fprintf(stderr,x); } while(0)
151 #define SYSERROR(call, addr) do { \
152 const struct msrdef *m = findmsrdef(addr); \
154 fprintf(stderr, "%s: " #call "(0x%08x) %s: %s\n", __func__, addr, m->symbol, strerror(errno)); \
156 fprintf(stderr, "%s: " #call "(0x%08x): %s\n", __func__, addr, strerror(errno)); \
160 struct cpuid_t *cpuid(void);
161 struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
164 void hexprint(FILE *f, const struct msr val, const uint8_t bits);
165 int msr_eq(const struct msr a, const struct msr b);
166 struct msr msr_shl(const struct msr a, const uint8_t bits);
167 struct msr msr_shr(const struct msr a, const uint8_t bits);
168 void msr_and(struct msr *a, const struct msr b);
169 const struct msrdef *findmsrdef(const uint32_t addr);
170 uint32_t msraddrbyname(const char *name);
171 void dumpmsrdefs(const struct targetdef *t);
172 int dumpmsrdefsvals(FILE *f, const struct targetdef *t, const uint8_t cpu);
173 uint8_t str2msr(char *str, struct msr *msr, char **endptr);
174 void decodemsr(const uint8_t cpu, const uint32_t addr, const struct msr val);
175 uint8_t diff_msr(FILE *fout, const uint32_t addr, const struct msr a, const struct msr b);
179 /** system externs **/
182 extern int linux_probe(const struct sysdef *system);
183 extern int linux_open(uint8_t cpu, enum SysModes mode);
184 extern int linux_close(uint8_t cpu);
185 extern int linux_rdmsr(uint8_t cpu, uint32_t addr, struct msr *val);
188 extern int darwin_probe(const struct sysdef *system);
189 extern int darwin_open(uint8_t cpu, enum SysModes mode);
190 extern int darwin_close(uint8_t cpu);
191 extern int darwin_rdmsr(uint8_t cpu, uint32_t addr, struct msr *val);
194 extern int freebsd_probe(const struct sysdef *system);
195 extern int freebsd_open(uint8_t cpu, enum SysModes mode);
196 extern int freebsd_close(uint8_t cpu);
197 extern int freebsd_rdmsr(uint8_t cpu, uint32_t addr, struct msr *val);
199 /** target externs **/
202 extern int geodegx2_probe(const struct targetdef *t);
203 extern const struct msrdef geodegx2_msrs[];
206 extern int geodelx_probe(const struct targetdef *t);
207 extern const struct msrdef geodelx_msrs[];
210 extern int cs5536_probe(const struct targetdef *t);
211 extern const struct msrdef cs5536_msrs[];
214 extern int k8_probe(const struct targetdef *t);
215 extern const struct msrdef k8_msrs[];
217 /* intel_pentium3_early.c */
218 extern int intel_pentium3_early_probe(const struct targetdef *t);
219 extern const struct msrdef intel_pentium3_early_msrs[];
221 /* intel_pentium3.c */
222 extern int intel_pentium3_probe(const struct targetdef *t);
223 extern const struct msrdef intel_pentium3_msrs[];
226 extern int intel_core1_probe(const struct targetdef *t);
227 extern const struct msrdef intel_core1_msrs[];
229 /* intel_core2_early.c */
230 extern int intel_core2_early_probe(const struct targetdef *t);
231 extern const struct msrdef intel_core2_early_msrs[];
233 /* intel_core2_later.c */
234 extern int intel_core2_later_probe(const struct targetdef *t);
235 extern const struct msrdef intel_core2_later_msrs[];
237 /* intel_pentium4_early.c */
238 extern int intel_pentium4_early_probe(const struct targetdef *t);
239 extern const struct msrdef intel_pentium4_early_msrs[];
241 /* intel_pentium4_later.c */
242 extern int intel_pentium4_later_probe(const struct targetdef *t);
243 extern const struct msrdef intel_pentium4_later_msrs[];
245 #endif /* MSRTOOL_H */