1 /* This file is part of msrtool. */
2 /* SPDX-License-Identifier: GPL-2.0-only */
9 #if (defined(__MACH__) && defined(__APPLE__))
10 /* DirectHW is available here: https://www.coreboot.org/DirectHW */
12 #include <DirectHW/DirectHW.h>
14 #if defined(__FreeBSD__)
15 #include <sys/ioctl.h>
16 #include <sys/cpuctl.h>
20 #define HEXCHARS "0123456789abcdefABCDEF"
45 const struct msr value
;
54 const uint8_t present
;
55 const struct msrbitvalues bitval
[32];
61 const struct msr resetval
;
64 const struct msrbits bits
[65];
67 #define MSR1(lo) { 0, (lo) }
68 #define MSR2(hi,lo) { (hi), (lo) }
70 #define BITVAL_EOT .text = NULL
71 #define BITVAL_ISEOT(bv) (NULL == (bv).text)
73 #define BITS_EOT .size = 0
74 #define BITS_ISEOT(b) (0 == (b).size)
76 #define MSR_EOT .type = MSRTYPE_EOT
77 #define MSR_ISEOT(m) (MSRTYPE_EOT == (m).type)
79 #define NOBITS {{ BITVAL_EOT }}
80 #define RESERVED "RSVD", "Reserved", PRESENT_HEXDEC, NOBITS
85 VENDOR_INTEL
= 0x756e6547,
86 VENDOR_AMD
= 0x68747541,
87 VENDOR_CENTAUR
= 0x746e6543,
101 const char *prettyname
;
102 int (*probe
)(const struct targetdef
*target
, const struct cpuid_t
*id
);
103 const struct msrdef
*msrs
;
106 #define TARGET_EOT .name = NULL
107 #define TARGET_ISEOT(t) (NULL == (t).name)
118 const char *prettyname
;
119 int (*probe
)(const struct sysdef
*system
);
120 int (*open
)(uint8_t cpu
, enum SysModes mode
);
121 int (*close
)(uint8_t cpu
);
122 int (*rdmsr
)(uint8_t cpu
, uint32_t addr
, struct msr
*val
);
125 #define SYSTEM_EOT .name = NULL
126 #define SYSTEM_ISEOT(s) (NULL == (s).name)
128 extern const struct sysdef
*sys
;
130 extern uint8_t targets_found
;
131 extern const struct targetdef
**targets
;
133 extern uint8_t reserved
, verbose
, quiet
;
135 extern struct pci_access
*pacc
;
137 #define printf_quiet(x...) do { if (!quiet) fprintf(stderr,x); } while(0)
138 #define printf_verbose(x...) do { if (verbose && !quiet) fprintf(stderr,x); } while(0)
140 #define SYSERROR(call, addr) do { \
141 const struct msrdef *m = findmsrdef(addr); \
143 fprintf(stderr, "%s: " #call "(0x%08x) %s: %s\n", __func__, addr, m->symbol, strerror(errno)); \
145 fprintf(stderr, "%s: " #call "(0x%08x): %s\n", __func__, addr, strerror(errno)); \
149 struct cpuid_t
*cpuid(void);
150 struct pci_dev
*pci_dev_find(uint16_t vendor
, uint16_t device
);
153 void hexprint(FILE *f
, const struct msr val
, const uint8_t bits
);
154 void strprint(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 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
, char **endptr
);
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 extern int darwin_probe(const struct sysdef
*system
);
179 extern int darwin_open(uint8_t cpu
, enum SysModes mode
);
180 extern int darwin_close(uint8_t cpu
);
181 extern int darwin_rdmsr(uint8_t cpu
, uint32_t addr
, struct msr
*val
);
184 extern int freebsd_probe(const struct sysdef
*system
);
185 extern int freebsd_open(uint8_t cpu
, enum SysModes mode
);
186 extern int freebsd_close(uint8_t cpu
);
187 extern int freebsd_rdmsr(uint8_t cpu
, uint32_t addr
, struct msr
*val
);
189 /** target externs **/
192 extern int geodegx2_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
193 extern const struct msrdef geodegx2_msrs
[];
196 extern int geodelx_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
197 extern const struct msrdef geodelx_msrs
[];
200 extern int cs5536_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
201 extern const struct msrdef cs5536_msrs
[];
204 extern int k8_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
205 extern const struct msrdef k8_msrs
[];
208 extern int via_c7_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
209 extern const struct msrdef via_c7_msrs
[];
211 /* intel_pentium3_early.c */
212 extern int intel_pentium3_early_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
213 extern const struct msrdef intel_pentium3_early_msrs
[];
215 /* intel_pentium3.c */
216 extern int intel_pentium3_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
217 extern const struct msrdef intel_pentium3_msrs
[];
220 extern int intel_core1_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
221 extern const struct msrdef intel_core1_msrs
[];
223 /* intel_core2_early.c */
224 extern int intel_core2_early_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
225 extern const struct msrdef intel_core2_early_msrs
[];
227 /* intel_core2_later.c */
228 extern int intel_core2_later_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
229 extern const struct msrdef intel_core2_later_msrs
[];
231 /* intel_pentium4_early.c */
232 extern int intel_pentium4_early_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
233 extern const struct msrdef intel_pentium4_early_msrs
[];
235 /* intel_pentium4_later.c */
236 extern int intel_pentium4_later_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
237 extern const struct msrdef intel_pentium4_later_msrs
[];
239 /* intel_pentium_d.c */
240 extern int intel_pentium_d_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
241 extern const struct msrdef intel_pentium_d_msrs
[];
243 /* intel_nehalem.c */
244 extern int intel_nehalem_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
245 extern const struct msrdef intel_nehalem_msrs
[];
248 extern int intel_atom_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
249 extern const struct msrdef intel_atom_msrs
[];
251 #endif /* MSRTOOL_H */