msrtool: Factor out cpuid() from target probe functions into main()
Almost all probe functions called cpuid(). Those calls are replaced by a single cpuid() call in main() and a new parameter to the target probe functions with the cpuid() result. The vendor_t and struct cpuid_t definitions are moved closer to the top of msrtool.h and the vendor_t enum is reformatted to simplify addition of further values. Change-Id: Icd615636207499cfa46b8b99bf819ef8ca2d97c0 Signed-off-by: Anton Kochkov <anton.kochkov@gmail.com> Signed-off-by: Peter Stuge <peter@stuge.se> Reviewed-on: http://review.coreboot.org/1259 Tested-by: build bot (Jenkins)
This commit is contained in:
parent
c7fc4422a0
commit
59b36f1026
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
#include "msrtool.h"
|
#include "msrtool.h"
|
||||||
|
|
||||||
int cs5536_probe(const struct targetdef *target) {
|
int cs5536_probe(const struct targetdef *target, const struct cpuid_t *id) {
|
||||||
return (NULL != pci_dev_find(0x1022, 0x2090));
|
return (NULL != pci_dev_find(0x1022, 0x2090));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,7 @@
|
||||||
|
|
||||||
#include "msrtool.h"
|
#include "msrtool.h"
|
||||||
|
|
||||||
int geodegx2_probe(const struct targetdef *target) {
|
int geodegx2_probe(const struct targetdef *target, const struct cpuid_t *id) {
|
||||||
struct cpuid_t *id = cpuid();
|
|
||||||
return 5 == id->family && 5 == id->model;
|
return 5 == id->family && 5 == id->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
#include "msrtool.h"
|
#include "msrtool.h"
|
||||||
|
|
||||||
int geodelx_probe(const struct targetdef *target) {
|
int geodelx_probe(const struct targetdef *target, const struct cpuid_t *id) {
|
||||||
struct cpuid_t *id = cpuid();
|
|
||||||
return 5 == id->family && 10 == id->model;
|
return 5 == id->family && 10 == id->model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
#include "msrtool.h"
|
#include "msrtool.h"
|
||||||
|
|
||||||
int intel_core1_probe(const struct targetdef *target) {
|
int intel_core1_probe(const struct targetdef *target, const struct cpuid_t *id) {
|
||||||
struct cpuid_t *id = cpuid();
|
|
||||||
return ((0x6 == id->family) && (0xe == id->model));
|
return ((0x6 == id->family) && (0xe == id->model));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
#include "msrtool.h"
|
#include "msrtool.h"
|
||||||
|
|
||||||
int intel_core2_early_probe(const struct targetdef *target) {
|
int intel_core2_early_probe(const struct targetdef *target, const struct cpuid_t *id) {
|
||||||
struct cpuid_t *id = cpuid();
|
|
||||||
return ((0x6 == id->family) && (0xf == id->model));
|
return ((0x6 == id->family) && (0xf == id->model));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
#include "msrtool.h"
|
#include "msrtool.h"
|
||||||
|
|
||||||
int intel_core2_later_probe(const struct targetdef *target) {
|
int intel_core2_later_probe(const struct targetdef *target, const struct cpuid_t *id) {
|
||||||
struct cpuid_t *id = cpuid();
|
|
||||||
return ((0x6 == id->family)&(0x17 == id->model));
|
return ((0x6 == id->family)&(0x17 == id->model));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
#include "msrtool.h"
|
#include "msrtool.h"
|
||||||
|
|
||||||
int intel_nehalem_probe(const struct targetdef *target) {
|
int intel_nehalem_probe(const struct targetdef *target, const struct cpuid_t *id) {
|
||||||
struct cpuid_t *id = cpuid();
|
|
||||||
return ((0x6 == id->family) && (
|
return ((0x6 == id->family) && (
|
||||||
(0x1a == id->model) ||
|
(0x1a == id->model) ||
|
||||||
(0x1e == id->model) ||
|
(0x1e == id->model) ||
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
#include "msrtool.h"
|
#include "msrtool.h"
|
||||||
|
|
||||||
int intel_pentium3_probe(const struct targetdef *target) {
|
int intel_pentium3_probe(const struct targetdef *target, const struct cpuid_t *id) {
|
||||||
struct cpuid_t *id = cpuid();
|
|
||||||
return ((0x6 == id->family) && (
|
return ((0x6 == id->family) && (
|
||||||
(0xa == id->model) ||
|
(0xa == id->model) ||
|
||||||
(0xb == id->model)
|
(0xb == id->model)
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
#include "msrtool.h"
|
#include "msrtool.h"
|
||||||
|
|
||||||
int intel_pentium3_early_probe(const struct targetdef *target) {
|
int intel_pentium3_early_probe(const struct targetdef *target, const struct cpuid_t *id) {
|
||||||
struct cpuid_t *id = cpuid();
|
|
||||||
return ((0x6 == id->family) && (
|
return ((0x6 == id->family) && (
|
||||||
(0x7 == id->model) ||
|
(0x7 == id->model) ||
|
||||||
(0x8 == id->model)
|
(0x8 == id->model)
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
#include "msrtool.h"
|
#include "msrtool.h"
|
||||||
|
|
||||||
int intel_pentium4_early_probe(const struct targetdef *target) {
|
int intel_pentium4_early_probe(const struct targetdef *target, const struct cpuid_t *id) {
|
||||||
struct cpuid_t *id = cpuid();
|
|
||||||
return ((0xf == id->family) && (0x2 == id->model));
|
return ((0xf == id->family) && (0x2 == id->model));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
#include "msrtool.h"
|
#include "msrtool.h"
|
||||||
|
|
||||||
int intel_pentium4_later_probe(const struct targetdef *target) {
|
int intel_pentium4_later_probe(const struct targetdef *target, const struct cpuid_t *id) {
|
||||||
struct cpuid_t *id = cpuid();
|
|
||||||
return ((0xf == id->family) && (
|
return ((0xf == id->family) && (
|
||||||
(0x3 == id->model) ||
|
(0x3 == id->model) ||
|
||||||
(0x4 == id->model)
|
(0x4 == id->model)
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
#include "msrtool.h"
|
#include "msrtool.h"
|
||||||
|
|
||||||
int k8_probe(const struct targetdef *target) {
|
int k8_probe(const struct targetdef *target, const struct cpuid_t *id) {
|
||||||
struct cpuid_t *id = cpuid();
|
|
||||||
return 0xF == id->family;
|
return 0xF == id->family;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -270,6 +270,7 @@ int main(int argc, char *argv[]) {
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
const struct sysdef *s;
|
const struct sysdef *s;
|
||||||
const struct targetdef *t;
|
const struct targetdef *t;
|
||||||
|
const struct cpuid_t *id = cpuid();
|
||||||
uint8_t tn, listmsrs = 0, listknown = 0, input = 0;
|
uint8_t tn, listmsrs = 0, listknown = 0, input = 0;
|
||||||
uint32_t addr = 0;
|
uint32_t addr = 0;
|
||||||
const char *streamfn = NULL, *difffn = NULL;
|
const char *streamfn = NULL, *difffn = NULL;
|
||||||
|
@ -357,7 +358,7 @@ int main(int argc, char *argv[]) {
|
||||||
else
|
else
|
||||||
for (t = alltargets; !TARGET_ISEOT(*t); t++) {
|
for (t = alltargets; !TARGET_ISEOT(*t); t++) {
|
||||||
printf_verbose("Probing for target %s: %s\n", t->name, t->prettyname);
|
printf_verbose("Probing for target %s: %s\n", t->name, t->prettyname);
|
||||||
if (!t->probe(t))
|
if (!t->probe(t, id))
|
||||||
continue;
|
continue;
|
||||||
printf_quiet("Detected target %s: %s\n", t->name, t->prettyname);
|
printf_quiet("Detected target %s: %s\n", t->name, t->prettyname);
|
||||||
add_target(t);
|
add_target(t);
|
||||||
|
|
|
@ -97,10 +97,24 @@ struct msrdef {
|
||||||
|
|
||||||
#define MAX_CORES 8
|
#define MAX_CORES 8
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
VENDOR_INTEL = 1,
|
||||||
|
VENDOR_AMD = 2,
|
||||||
|
} vendor_t;
|
||||||
|
|
||||||
|
struct cpuid_t {
|
||||||
|
uint8_t family;
|
||||||
|
uint8_t model;
|
||||||
|
uint8_t stepping;
|
||||||
|
uint8_t ext_family;
|
||||||
|
uint8_t ext_model;
|
||||||
|
vendor_t vendor;
|
||||||
|
};
|
||||||
|
|
||||||
struct targetdef {
|
struct targetdef {
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *prettyname;
|
const char *prettyname;
|
||||||
int (*probe)(const struct targetdef *target);
|
int (*probe)(const struct targetdef *target, const struct cpuid_t *id);
|
||||||
const struct msrdef *msrs;
|
const struct msrdef *msrs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -126,18 +140,6 @@ struct sysdef {
|
||||||
#define SYSTEM_EOT .name = NULL
|
#define SYSTEM_EOT .name = NULL
|
||||||
#define SYSTEM_ISEOT(s) (NULL == (s).name)
|
#define SYSTEM_ISEOT(s) (NULL == (s).name)
|
||||||
|
|
||||||
typedef enum { VENDOR_INTEL = 1, VENDOR_AMD = 2 } vendor_t;
|
|
||||||
|
|
||||||
struct cpuid_t {
|
|
||||||
uint8_t family;
|
|
||||||
uint8_t model;
|
|
||||||
uint8_t stepping;
|
|
||||||
uint8_t ext_family;
|
|
||||||
uint8_t ext_model;
|
|
||||||
vendor_t vendor;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
extern const struct sysdef *sys;
|
extern const struct sysdef *sys;
|
||||||
|
|
||||||
extern uint8_t targets_found;
|
extern uint8_t targets_found;
|
||||||
|
@ -201,51 +203,51 @@ extern int freebsd_rdmsr(uint8_t cpu, uint32_t addr, struct msr *val);
|
||||||
/** target externs **/
|
/** target externs **/
|
||||||
|
|
||||||
/* geodegx2.c */
|
/* geodegx2.c */
|
||||||
extern int geodegx2_probe(const struct targetdef *t);
|
extern int geodegx2_probe(const struct targetdef *t, const struct cpuid_t *id);
|
||||||
extern const struct msrdef geodegx2_msrs[];
|
extern const struct msrdef geodegx2_msrs[];
|
||||||
|
|
||||||
/* geodelx.c */
|
/* geodelx.c */
|
||||||
extern int geodelx_probe(const struct targetdef *t);
|
extern int geodelx_probe(const struct targetdef *t, const struct cpuid_t *id);
|
||||||
extern const struct msrdef geodelx_msrs[];
|
extern const struct msrdef geodelx_msrs[];
|
||||||
|
|
||||||
/* cs5536.c */
|
/* cs5536.c */
|
||||||
extern int cs5536_probe(const struct targetdef *t);
|
extern int cs5536_probe(const struct targetdef *t, const struct cpuid_t *id);
|
||||||
extern const struct msrdef cs5536_msrs[];
|
extern const struct msrdef cs5536_msrs[];
|
||||||
|
|
||||||
/* k8.c */
|
/* k8.c */
|
||||||
extern int k8_probe(const struct targetdef *t);
|
extern int k8_probe(const struct targetdef *t, const struct cpuid_t *id);
|
||||||
extern const struct msrdef k8_msrs[];
|
extern const struct msrdef k8_msrs[];
|
||||||
|
|
||||||
/* intel_pentium3_early.c */
|
/* intel_pentium3_early.c */
|
||||||
extern int intel_pentium3_early_probe(const struct targetdef *t);
|
extern int intel_pentium3_early_probe(const struct targetdef *t, const struct cpuid_t *id);
|
||||||
extern const struct msrdef intel_pentium3_early_msrs[];
|
extern const struct msrdef intel_pentium3_early_msrs[];
|
||||||
|
|
||||||
/* intel_pentium3.c */
|
/* intel_pentium3.c */
|
||||||
extern int intel_pentium3_probe(const struct targetdef *t);
|
extern int intel_pentium3_probe(const struct targetdef *t, const struct cpuid_t *id);
|
||||||
extern const struct msrdef intel_pentium3_msrs[];
|
extern const struct msrdef intel_pentium3_msrs[];
|
||||||
|
|
||||||
/* intel_core1.c */
|
/* intel_core1.c */
|
||||||
extern int intel_core1_probe(const struct targetdef *t);
|
extern int intel_core1_probe(const struct targetdef *t, const struct cpuid_t *id);
|
||||||
extern const struct msrdef intel_core1_msrs[];
|
extern const struct msrdef intel_core1_msrs[];
|
||||||
|
|
||||||
/* intel_core2_early.c */
|
/* intel_core2_early.c */
|
||||||
extern int intel_core2_early_probe(const struct targetdef *t);
|
extern int intel_core2_early_probe(const struct targetdef *t, const struct cpuid_t *id);
|
||||||
extern const struct msrdef intel_core2_early_msrs[];
|
extern const struct msrdef intel_core2_early_msrs[];
|
||||||
|
|
||||||
/* intel_core2_later.c */
|
/* intel_core2_later.c */
|
||||||
extern int intel_core2_later_probe(const struct targetdef *t);
|
extern int intel_core2_later_probe(const struct targetdef *t, const struct cpuid_t *id);
|
||||||
extern const struct msrdef intel_core2_later_msrs[];
|
extern const struct msrdef intel_core2_later_msrs[];
|
||||||
|
|
||||||
/* intel_pentium4_early.c */
|
/* intel_pentium4_early.c */
|
||||||
extern int intel_pentium4_early_probe(const struct targetdef *t);
|
extern int intel_pentium4_early_probe(const struct targetdef *t, const struct cpuid_t *id);
|
||||||
extern const struct msrdef intel_pentium4_early_msrs[];
|
extern const struct msrdef intel_pentium4_early_msrs[];
|
||||||
|
|
||||||
/* intel_pentium4_later.c */
|
/* intel_pentium4_later.c */
|
||||||
extern int intel_pentium4_later_probe(const struct targetdef *t);
|
extern int intel_pentium4_later_probe(const struct targetdef *t, const struct cpuid_t *id);
|
||||||
extern const struct msrdef intel_pentium4_later_msrs[];
|
extern const struct msrdef intel_pentium4_later_msrs[];
|
||||||
|
|
||||||
/* intel_nehalem.c */
|
/* intel_nehalem.c */
|
||||||
extern int intel_nehalem_probe(const struct targetdef *t);
|
extern int intel_nehalem_probe(const struct targetdef *t, const struct cpuid_t *id);
|
||||||
extern const struct msrdef intel_nehalem_msrs[];
|
extern const struct msrdef intel_nehalem_msrs[];
|
||||||
|
|
||||||
#endif /* MSRTOOL_H */
|
#endif /* MSRTOOL_H */
|
||||||
|
|
Loading…
Reference in New Issue