1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-19 10:53:58 +00:00

Consolidate CPUID to CPU family/model macros for amd64 and i386 to reduce

unnecessary #ifdef's for shared code between them.
This commit is contained in:
Jung-uk Kim 2009-09-10 17:27:36 +00:00
parent 80c03b8eee
commit 3bcdfb9bf8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=197070
10 changed files with 31 additions and 37 deletions

View File

@ -371,21 +371,21 @@ printcpuinfo(void)
switch (cpu_vendor_id) {
case CPU_VENDOR_AMD:
if ((amd_pminfo & AMDPM_TSC_INVARIANT) ||
AMD64_CPU_FAMILY(cpu_id) >= 0x10 ||
CPUID_TO_FAMILY(cpu_id) >= 0x10 ||
cpu_id == 0x60fb2)
tsc_is_invariant = 1;
break;
case CPU_VENDOR_INTEL:
if ((amd_pminfo & AMDPM_TSC_INVARIANT) ||
(AMD64_CPU_FAMILY(cpu_id) == 0x6 &&
AMD64_CPU_MODEL(cpu_id) >= 0xe) ||
(AMD64_CPU_FAMILY(cpu_id) == 0xf &&
AMD64_CPU_MODEL(cpu_id) >= 0x3))
(CPUID_TO_FAMILY(cpu_id) == 0x6 &&
CPUID_TO_MODEL(cpu_id) >= 0xe) ||
(CPUID_TO_FAMILY(cpu_id) == 0xf &&
CPUID_TO_MODEL(cpu_id) >= 0x3))
tsc_is_invariant = 1;
break;
case CPU_VENDOR_CENTAUR:
if (AMD64_CPU_FAMILY(cpu_id) == 0x6 &&
AMD64_CPU_MODEL(cpu_id) >= 0xf &&
if (CPUID_TO_FAMILY(cpu_id) == 0x6 &&
CPUID_TO_MODEL(cpu_id) >= 0xf &&
(rdmsr(0x1203) & 0x100000000ULL) == 0)
tsc_is_invariant = 1;
break;

View File

@ -154,8 +154,8 @@ initializecpu(void)
pg_nx = PG_NX;
}
if (cpu_vendor_id == CPU_VENDOR_CENTAUR &&
AMD64_CPU_FAMILY(cpu_id) == 0x6 &&
AMD64_CPU_MODEL(cpu_id) >= 0xf)
CPUID_TO_FAMILY(cpu_id) == 0x6 &&
CPUID_TO_MODEL(cpu_id) >= 0xf)
init_via();
/*

View File

@ -275,8 +275,8 @@ msi_init(void)
case CPU_VENDOR_AMD:
break;
case CPU_VENDOR_CENTAUR:
if (AMD64_CPU_FAMILY(cpu_id) == 0x6 &&
AMD64_CPU_MODEL(cpu_id) >= 0xf)
if (CPUID_TO_FAMILY(cpu_id) == 0x6 &&
CPUID_TO_MODEL(cpu_id) >= 0xf)
break;
/* FALLTHROUGH */
default:

View File

@ -168,10 +168,10 @@
#define CPUID_FAMILY 0x00000f00
#define CPUID_EXT_MODEL 0x000f0000
#define CPUID_EXT_FAMILY 0x0ff00000
#define AMD64_CPU_MODEL(id) \
#define CPUID_TO_MODEL(id) \
((((id) & CPUID_MODEL) >> 4) | \
(((id) & CPUID_EXT_MODEL) >> 12))
#define AMD64_CPU_FAMILY(id) \
#define CPUID_TO_FAMILY(id) \
((((id) & CPUID_FAMILY) >> 8) + \
(((id) & CPUID_EXT_FAMILY) >> 20))

View File

@ -83,12 +83,6 @@ __FBSDID("$FreeBSD$");
#define AMD_10H_11H_CUR_DID(msr) (((msr) >> 6) & 0x07)
#define AMD_10H_11H_CUR_FID(msr) ((msr) & 0x3F)
#if defined(__amd64__)
#define CPU_FAMILY(id) AMD64_CPU_FAMILY(id)
#elif defined(__i386__)
#define CPU_FAMILY(id) I386_CPU_FAMILY(id)
#endif
#define HWPSTATE_DEBUG(dev, msg...) \
do{ \
if(hwpstate_verbose) \
@ -302,7 +296,7 @@ hwpstate_identify(driver_t *driver, device_t parent)
if (device_find_child(parent, "hwpstate", -1) != NULL)
return;
if (cpu_vendor_id != CPU_VENDOR_AMD || CPU_FAMILY(cpu_id) < 0x10)
if (cpu_vendor_id != CPU_VENDOR_AMD || CPUID_TO_FAMILY(cpu_id) < 0x10)
return;
/*
@ -405,7 +399,7 @@ hwpstate_get_info_from_msr(device_t dev)
uint64_t msr;
int family, i, fid, did;
family = CPU_FAMILY(cpu_id);
family = CPUID_TO_FAMILY(cpu_id);
sc = device_get_softc(dev);
/* Get pstate count */
msr = rdmsr(MSR_AMD_10H_11H_LIMIT);

View File

@ -858,21 +858,21 @@ printcpuinfo(void)
switch (cpu_vendor_id) {
case CPU_VENDOR_AMD:
if ((amd_pminfo & AMDPM_TSC_INVARIANT) ||
I386_CPU_FAMILY(cpu_id) >= 0x10 ||
CPUID_TO_FAMILY(cpu_id) >= 0x10 ||
cpu_id == 0x60fb2)
tsc_is_invariant = 1;
break;
case CPU_VENDOR_INTEL:
if ((amd_pminfo & AMDPM_TSC_INVARIANT) ||
(I386_CPU_FAMILY(cpu_id) == 0x6 &&
I386_CPU_MODEL(cpu_id) >= 0xe) ||
(I386_CPU_FAMILY(cpu_id) == 0xf &&
I386_CPU_MODEL(cpu_id) >= 0x3))
(CPUID_TO_FAMILY(cpu_id) == 0x6 &&
CPUID_TO_MODEL(cpu_id) >= 0xe) ||
(CPUID_TO_FAMILY(cpu_id) == 0xf &&
CPUID_TO_MODEL(cpu_id) >= 0x3))
tsc_is_invariant = 1;
break;
case CPU_VENDOR_CENTAUR:
if (I386_CPU_FAMILY(cpu_id) == 0x6 &&
I386_CPU_MODEL(cpu_id) >= 0xf &&
if (CPUID_TO_FAMILY(cpu_id) == 0x6 &&
CPUID_TO_MODEL(cpu_id) >= 0xf &&
(rdmsr(0x1203) & 0x100000000ULL) == 0)
tsc_is_invariant = 1;
break;
@ -1106,8 +1106,8 @@ finishidentcpu(void)
* XXX This is only done on the BSP package.
*/
if (cpu_vendor_id == CPU_VENDOR_INTEL && cpu_high > 0 && cpu_high < 4 &&
((I386_CPU_FAMILY(cpu_id) == 0xf && I386_CPU_MODEL(cpu_id) >= 0x3) ||
(I386_CPU_FAMILY(cpu_id) == 0x6 && I386_CPU_MODEL(cpu_id) >= 0xe))) {
((CPUID_TO_FAMILY(cpu_id) == 0xf && CPUID_TO_MODEL(cpu_id) >= 0x3) ||
(CPUID_TO_FAMILY(cpu_id) == 0x6 && CPUID_TO_MODEL(cpu_id) >= 0xe))) {
uint64_t msr;
msr = rdmsr(MSR_IA32_MISC_ENABLE);
if ((msr & 0x400000ULL) != 0) {

View File

@ -275,8 +275,8 @@ msi_init(void)
case CPU_VENDOR_AMD:
break;
case CPU_VENDOR_CENTAUR:
if (I386_CPU_FAMILY(cpu_id) == 0x6 &&
I386_CPU_MODEL(cpu_id) >= 0xf)
if (CPUID_TO_FAMILY(cpu_id) == 0x6 &&
CPUID_TO_MODEL(cpu_id) >= 0xf)
break;
/* FALLTHROUGH */
default:

View File

@ -501,8 +501,8 @@ pmap_init_pat(void)
*/
if (!pat_tested) {
if (cpu_vendor_id != CPU_VENDOR_INTEL ||
(I386_CPU_FAMILY(cpu_id) == 6 &&
I386_CPU_MODEL(cpu_id) >= 0xe)) {
(CPUID_TO_FAMILY(cpu_id) == 6 &&
CPUID_TO_MODEL(cpu_id) >= 0xe)) {
pat_works = 1;
sysenv = getenv("smbios.system.product");
if (sysenv != NULL) {

View File

@ -165,11 +165,11 @@
#define CPUID_FAMILY 0x00000f00
#define CPUID_EXT_MODEL 0x000f0000
#define CPUID_EXT_FAMILY 0x0ff00000
#define I386_CPU_MODEL(id) \
#define CPUID_TO_MODEL(id) \
((((id) & CPUID_MODEL) >> 4) | \
((((id) & CPUID_FAMILY) >= 0x600) ? \
(((id) & CPUID_EXT_MODEL) >> 12) : 0))
#define I386_CPU_FAMILY(id) \
#define CPUID_TO_FAMILY(id) \
((((id) & CPUID_FAMILY) >> 8) + \
((((id) & CPUID_FAMILY) == 0xf00) ? \
(((id) & CPUID_EXT_FAMILY) >> 20) : 0))

View File

@ -517,7 +517,7 @@ pmap_init_pat(void)
return;
if (cpu_vendor_id != CPU_VENDOR_INTEL ||
(I386_CPU_FAMILY(cpu_id) == 6 && I386_CPU_MODEL(cpu_id) >= 0xe)) {
(CPUID_TO_FAMILY(cpu_id) == 6 && CPUID_TO_MODEL(cpu_id) >= 0xe)) {
/*
* Leave the indices 0-3 at the default of WB, WT, UC, and UC-.
* Program 4 and 5 as WP and WC.