1 /* SPDX-License-Identifier: GPL-2.0-only */
8 #if (defined(__MACH__) && defined(__APPLE__))
9 /* DirectHW is available here: https://www.coreboot.org/DirectHW */
11 #include <DirectHW/DirectHW.h>
13 #if defined(__FreeBSD__)
14 #include <sys/ioctl.h>
15 #include <sys/cpuctl.h>
19 #define HEXCHARS "0123456789abcdefABCDEF"
44 const struct msr value
;
53 const uint8_t present
;
54 const struct msrbitvalues bitval
[32];
60 const struct msr resetval
;
63 const struct msrbits bits
[65];
66 #define MSR1(lo) { 0, (lo) }
67 #define MSR2(hi,lo) { (hi), (lo) }
69 #define BITVAL_EOT .text = NULL
70 #define BITVAL_ISEOT(bv) (NULL == (bv).text)
72 #define BITS_EOT .size = 0
73 #define BITS_ISEOT(b) (0 == (b).size)
75 #define MSR_EOT .type = MSRTYPE_EOT
76 #define MSR_ISEOT(m) (MSRTYPE_EOT == (m).type)
78 #define NOBITS {{ BITVAL_EOT }}
79 #define RESERVED "RSVD", "Reserved", PRESENT_HEXDEC, NOBITS
84 VENDOR_INTEL
= 0x756e6547,
85 VENDOR_AMD
= 0x68747541,
86 VENDOR_CENTAUR
= 0x746e6543,
100 const char *prettyname
;
101 int (*probe
)(const struct targetdef
*target
, const struct cpuid_t
*id
);
102 const struct msrdef
*msrs
;
105 #define TARGET_EOT .name = NULL
106 #define TARGET_ISEOT(t) (NULL == (t).name)
117 const char *prettyname
;
118 int (*probe
)(const struct sysdef
*system
);
119 int (*open
)(uint8_t cpu
, enum SysModes mode
);
120 int (*close
)(uint8_t cpu
);
121 int (*rdmsr
)(uint8_t cpu
, uint32_t addr
, struct msr
*val
);
124 #define SYSTEM_EOT .name = NULL
125 #define SYSTEM_ISEOT(s) (NULL == (s).name)
127 extern const struct sysdef
*sys
;
129 extern uint8_t targets_found
;
130 extern const struct targetdef
**targets
;
132 extern uint8_t reserved
, verbose
, quiet
;
134 extern struct pci_access
*pacc
;
136 #define printf_quiet(x...) do { if (!quiet) fprintf(stderr,x); } while(0)
137 #define printf_verbose(x...) do { if (verbose && !quiet) fprintf(stderr,x); } while(0)
139 #define SYSERROR(call, addr) do { \
140 const struct msrdef *m = findmsrdef(addr); \
142 fprintf(stderr, "%s: " #call "(0x%08x) %s: %s\n", __func__, addr, m->symbol, strerror(errno)); \
144 fprintf(stderr, "%s: " #call "(0x%08x): %s\n", __func__, addr, strerror(errno)); \
148 struct cpuid_t
*cpuid(void);
149 struct pci_dev
*pci_dev_find(uint16_t vendor
, uint16_t device
);
152 void hexprint(FILE *f
, const struct msr val
, const uint8_t bits
);
153 void strprint(FILE *f
, const struct msr val
, const uint8_t bits
);
154 int msr_eq(const struct msr a
, const struct msr b
);
155 struct msr
msr_shl(const struct msr a
, const uint8_t bits
);
156 struct msr
msr_shr(const struct msr a
, const uint8_t bits
);
157 void msr_and(struct msr
*a
, const struct msr b
);
158 const struct msrdef
*findmsrdef(const uint32_t addr
);
159 uint32_t msraddrbyname(const char *name
);
160 void dumpmsrdefs(const struct targetdef
*t
);
161 int dumpmsrdefsvals(FILE *f
, const struct targetdef
*t
, const uint8_t cpu
);
162 uint8_t str2msr(char *str
, struct msr
*msr
, char **endptr
);
163 void decodemsr(const uint8_t cpu
, const uint32_t addr
, const struct msr val
);
164 uint8_t diff_msr(FILE *fout
, const uint32_t addr
, const struct msr a
, const struct msr b
);
168 /** system externs **/
171 extern int linux_probe(const struct sysdef
*system
);
172 extern int linux_open(uint8_t cpu
, enum SysModes mode
);
173 extern int linux_close(uint8_t cpu
);
174 extern int linux_rdmsr(uint8_t cpu
, uint32_t addr
, struct msr
*val
);
177 extern int darwin_probe(const struct sysdef
*system
);
178 extern int darwin_open(uint8_t cpu
, enum SysModes mode
);
179 extern int darwin_close(uint8_t cpu
);
180 extern int darwin_rdmsr(uint8_t cpu
, uint32_t addr
, struct msr
*val
);
183 extern int freebsd_probe(const struct sysdef
*system
);
184 extern int freebsd_open(uint8_t cpu
, enum SysModes mode
);
185 extern int freebsd_close(uint8_t cpu
);
186 extern int freebsd_rdmsr(uint8_t cpu
, uint32_t addr
, struct msr
*val
);
188 /** target externs **/
191 extern int geodegx2_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
192 extern const struct msrdef geodegx2_msrs
[];
195 extern int geodelx_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
196 extern const struct msrdef geodelx_msrs
[];
199 extern int cs5536_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
200 extern const struct msrdef cs5536_msrs
[];
203 extern int k8_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
204 extern const struct msrdef k8_msrs
[];
207 extern int via_c7_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
208 extern const struct msrdef via_c7_msrs
[];
210 /* intel_pentium3_early.c */
211 extern int intel_pentium3_early_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
212 extern const struct msrdef intel_pentium3_early_msrs
[];
214 /* intel_pentium3.c */
215 extern int intel_pentium3_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
216 extern const struct msrdef intel_pentium3_msrs
[];
219 extern int intel_core1_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
220 extern const struct msrdef intel_core1_msrs
[];
222 /* intel_core2_early.c */
223 extern int intel_core2_early_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
224 extern const struct msrdef intel_core2_early_msrs
[];
226 /* intel_core2_later.c */
227 extern int intel_core2_later_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
228 extern const struct msrdef intel_core2_later_msrs
[];
230 /* intel_pentium4_early.c */
231 extern int intel_pentium4_early_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
232 extern const struct msrdef intel_pentium4_early_msrs
[];
234 /* intel_pentium4_later.c */
235 extern int intel_pentium4_later_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
236 extern const struct msrdef intel_pentium4_later_msrs
[];
238 /* intel_pentium_d.c */
239 extern int intel_pentium_d_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
240 extern const struct msrdef intel_pentium_d_msrs
[];
242 /* intel_nehalem.c */
243 extern int intel_nehalem_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
244 extern const struct msrdef intel_nehalem_msrs
[];
247 extern int intel_atom_probe(const struct targetdef
*t
, const struct cpuid_t
*id
);
248 extern const struct msrdef intel_atom_msrs
[];
250 #endif /* MSRTOOL_H */