From 3bcdfb9bf8c9d4774a98378885147a8490919ea4 Mon Sep 17 00:00:00 2001 From: Jung-uk Kim Date: Thu, 10 Sep 2009 17:27:36 +0000 Subject: [PATCH] Consolidate CPUID to CPU family/model macros for amd64 and i386 to reduce unnecessary #ifdef's for shared code between them. --- sys/amd64/amd64/identcpu.c | 14 +++++++------- sys/amd64/amd64/initcpu.c | 4 ++-- sys/amd64/amd64/msi.c | 4 ++-- sys/amd64/include/specialreg.h | 4 ++-- sys/i386/cpufreq/hwpstate.c | 10 ++-------- sys/i386/i386/identcpu.c | 18 +++++++++--------- sys/i386/i386/msi.c | 4 ++-- sys/i386/i386/pmap.c | 4 ++-- sys/i386/include/specialreg.h | 4 ++-- sys/i386/xen/pmap.c | 2 +- 10 files changed, 31 insertions(+), 37 deletions(-) diff --git a/sys/amd64/amd64/identcpu.c b/sys/amd64/amd64/identcpu.c index 2c1b804affd8..766977df23df 100644 --- a/sys/amd64/amd64/identcpu.c +++ b/sys/amd64/amd64/identcpu.c @@ -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; diff --git a/sys/amd64/amd64/initcpu.c b/sys/amd64/amd64/initcpu.c index c293c1ac00e0..4376dd057026 100644 --- a/sys/amd64/amd64/initcpu.c +++ b/sys/amd64/amd64/initcpu.c @@ -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(); /* diff --git a/sys/amd64/amd64/msi.c b/sys/amd64/amd64/msi.c index 736b692e34ec..91a8cbbd004f 100644 --- a/sys/amd64/amd64/msi.c +++ b/sys/amd64/amd64/msi.c @@ -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: diff --git a/sys/amd64/include/specialreg.h b/sys/amd64/include/specialreg.h index 88ff734ca114..d1f0c8924add 100644 --- a/sys/amd64/include/specialreg.h +++ b/sys/amd64/include/specialreg.h @@ -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)) diff --git a/sys/i386/cpufreq/hwpstate.c b/sys/i386/cpufreq/hwpstate.c index f46080dec000..3790b768cf9e 100644 --- a/sys/i386/cpufreq/hwpstate.c +++ b/sys/i386/cpufreq/hwpstate.c @@ -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); diff --git a/sys/i386/i386/identcpu.c b/sys/i386/i386/identcpu.c index af0da5b28b98..66c5fed5fa64 100644 --- a/sys/i386/i386/identcpu.c +++ b/sys/i386/i386/identcpu.c @@ -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) { diff --git a/sys/i386/i386/msi.c b/sys/i386/i386/msi.c index 6a0a0c991f76..91a8cbbd004f 100644 --- a/sys/i386/i386/msi.c +++ b/sys/i386/i386/msi.c @@ -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: diff --git a/sys/i386/i386/pmap.c b/sys/i386/i386/pmap.c index 9b832aefc953..f3b4d99523b0 100644 --- a/sys/i386/i386/pmap.c +++ b/sys/i386/i386/pmap.c @@ -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) { diff --git a/sys/i386/include/specialreg.h b/sys/i386/include/specialreg.h index aeda4c419808..c2030597a062 100644 --- a/sys/i386/include/specialreg.h +++ b/sys/i386/include/specialreg.h @@ -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)) diff --git a/sys/i386/xen/pmap.c b/sys/i386/xen/pmap.c index 122318c12129..1d9c9c1cd9c7 100644 --- a/sys/i386/xen/pmap.c +++ b/sys/i386/xen/pmap.c @@ -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.