Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Modify some macros and add some new macros for CPU family an...



details:   https://anonhg.NetBSD.org/src/rev/51c8e6a827c5
branches:  trunk
changeset: 791384:51c8e6a827c5
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Fri Nov 15 08:47:55 2013 +0000

description:
Modify some macros and add some new macros for CPU family and model
to reduce code duplication and to avoid bug.

CPUID_TO_STEPPING(cpuid)        (not changed)

CPUID_TO_FAMILY(cpuid)          (new)
CPUID_TO_MODEL(cpuid)           (new)

        Return the display family and the display model.
        The macro names are the same as FreeBSD.

CPUID_TO_BASEFAMILY(cpuid)      (The old name was CPUID2FAMILY)
CPUID_TO_BASEMODEL(cpuid)       (The old name was CPUID2MODEL)

        Only for the base field.

CPUID_TO_EXTFAMILY(cpuid)       (The old name was CPUID2EXTFAMILY)
CPUID_TO_EXTMODEL(cpuid)        (The old name was CPUID2EXTMODEL)

        Only for the extended field.

See http://mail-index.netbsd.org/port-amd64/2013/11/12/msg001978.html

diffstat:

 sys/arch/x86/acpi/acpi_cpu_md.c    |  14 +++--------
 sys/arch/x86/include/specialreg.h  |  27 ++++++++++++++++------
 sys/arch/x86/pci/amdtemp.c         |  20 ++++++----------
 sys/arch/x86/x86/coretemp.c        |  16 ++++++-------
 sys/arch/x86/x86/cpu.c             |  12 +++++-----
 sys/arch/x86/x86/cpu_topology.c    |   8 ++----
 sys/arch/x86/x86/cpu_ucode_amd.c   |   8 ++----
 sys/arch/x86/x86/cpu_ucode_intel.c |   8 +++---
 sys/arch/x86/x86/est.c             |   8 +++---
 sys/arch/x86/x86/identcpu.c        |  44 +++++++++++++++----------------------
 sys/arch/x86/x86/intel_busclock.c  |  22 +++++++-----------
 sys/arch/x86/x86/lapic.c           |   6 ++--
 sys/arch/x86/x86/odcm.c            |   6 ++--
 sys/arch/x86/x86/patch.c           |  10 ++++----
 sys/arch/x86/x86/powernow.c        |  10 ++++----
 sys/arch/x86/x86/tprof_amdpmi.c    |   7 ++---
 sys/arch/x86/x86/tprof_pmi.c       |   6 ++--
 sys/arch/x86/x86/tsc.c             |  16 ++++++------
 sys/arch/x86/x86/viac7temp.c       |   8 +++---
 usr.sbin/cpuctl/arch/i386.c        |  21 +++++++----------
 20 files changed, 128 insertions(+), 149 deletions(-)

diffs (truncated from 886 to 300 lines):

diff -r 60baef8a0a4b -r 51c8e6a827c5 sys/arch/x86/acpi/acpi_cpu_md.c
--- a/sys/arch/x86/acpi/acpi_cpu_md.c   Fri Nov 15 08:42:18 2013 +0000
+++ b/sys/arch/x86/acpi/acpi_cpu_md.c   Fri Nov 15 08:47:55 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_md.c,v 1.72 2012/12/06 04:43:29 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_md.c,v 1.73 2013/11/15 08:47:55 msaitoh Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.c,v 1.72 2012/12/06 04:43:29 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.c,v 1.73 2013/11/15 08:47:55 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -243,10 +243,7 @@
 
                x86_cpuid(0x80000007, regs);
 
-               family = CPUID2FAMILY(ci->ci_signature);
-
-               if (family == 0xf)
-                       family += CPUID2EXTFAMILY(ci->ci_signature);
+               family = CPUID_TO_FAMILY(ci->ci_signature);
 
                switch (family) {
 
@@ -547,10 +544,7 @@
                if ((sc->sc_flags & ACPICPU_FLAG_P_FIDVID) != 0)
                        msr.ps_flags |= ACPICPU_FLAG_P_FIDVID;
 
-               family = CPUID2FAMILY(ci->ci_signature);
-
-               if (family == 0xf)
-                       family += CPUID2EXTFAMILY(ci->ci_signature);
+               family = CPUID_TO_FAMILY(ci->ci_signature);
 
                switch (family) {
 
diff -r 60baef8a0a4b -r 51c8e6a827c5 sys/arch/x86/include/specialreg.h
--- a/sys/arch/x86/include/specialreg.h Fri Nov 15 08:42:18 2013 +0000
+++ b/sys/arch/x86/include/specialreg.h Fri Nov 15 08:47:55 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: specialreg.h,v 1.71 2013/10/21 06:11:49 msaitoh Exp $  */
+/*     $NetBSD: specialreg.h,v 1.72 2013/11/15 08:47:55 msaitoh Exp $  */
 
 /*-
  * Copyright (c) 1991 The Regents of the University of California.
@@ -192,19 +192,30 @@
        "\31" "DEADLINE" "\32" "AES"    "\33" "XSAVE"   "\34" "OSXSAVE" \
        "\35" "AVX"     "\36" "F16C"    "\37" "RDRAND"  "\40" "RAZ"
 
-#define CPUID2FAMILY(cpuid)    (((cpuid) >> 8) & 0xf)
-#define CPUID2MODEL(cpuid)     (((cpuid) >> 4) & 0xf)
-#define CPUID2STEPPING(cpuid)  ((cpuid) & 0xf)
+/* CPUID Fn00000001 %eax */
+
+#define CPUID_TO_BASEFAMILY(cpuid)     (((cpuid) >> 8) & 0xf)
+#define CPUID_TO_BASEMODEL(cpuid)      (((cpuid) >> 4) & 0xf)
+#define CPUID_TO_STEPPING(cpuid)       ((cpuid) & 0xf)
 
 /*
- * The Extended family bits should only be inspected when CPUID2FAMILY()
+ * The Extended family bits should only be inspected when CPUID_TO_BASEFAMILY()
  * returns 15. They are use to encode family value 16 to 270 (add 15).
- * The Extended model hits are the high 4 bits of the model.
+ * The Extended model bits are the high 4 bits of the model.
  * They are only valid for family >= 15 or family 6 (intel, but all amd
  * family 6 are documented to return zero bits for them).
  */
-#define CPUID2EXTFAMILY(cpuid) (((cpuid) >> 20) & 0xff)
-#define CPUID2EXTMODEL(cpuid)  (((cpuid) >> 16) & 0xf)
+#define CPUID_TO_EXTFAMILY(cpuid)      (((cpuid) >> 20) & 0xff)
+#define CPUID_TO_EXTMODEL(cpuid)       (((cpuid) >> 16) & 0xf)
+
+/* The macros for the Display Family and the Display Model */
+#define CPUID_TO_FAMILY(cpuid) (CPUID_TO_BASEFAMILY(cpuid)     \
+           + ((CPUID_TO_BASEFAMILY(cpuid) != 0x0f)             \
+               ? 0 : CPUID_TO_EXTFAMILY(cpuid)))
+#define CPUID_TO_MODEL(cpuid)  (CPUID_TO_BASEMODEL(cpuid)      \
+           | ((CPUID_TO_BASEFAMILY(cpuid) != 0x0f)             \
+               && (CPUID_TO_BASEFAMILY(cpuid) != 0x06)         \
+               ? 0 : (CPUID_TO_EXTMODEL(cpuid) << 4)))
 
 /*
  * Intel Deterministic Cache Parameter Leaf
diff -r 60baef8a0a4b -r 51c8e6a827c5 sys/arch/x86/pci/amdtemp.c
--- a/sys/arch/x86/pci/amdtemp.c        Fri Nov 15 08:42:18 2013 +0000
+++ b/sys/arch/x86/pci/amdtemp.c        Fri Nov 15 08:47:55 2013 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: amdtemp.c,v 1.17 2013/11/12 15:08:01 msaitoh Exp $ */
+/*      $NetBSD: amdtemp.c,v 1.18 2013/11/15 08:47:55 msaitoh Exp $ */
 /*      $OpenBSD: kate.c,v 1.2 2008/03/27 04:52:03 cnst Exp $   */
 
 /*
@@ -48,7 +48,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdtemp.c,v 1.17 2013/11/12 15:08:01 msaitoh Exp $ ");
+__KERNEL_RCSID(0, "$NetBSD: amdtemp.c,v 1.18 2013/11/15 08:47:55 msaitoh Exp $ ");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -199,16 +199,14 @@
        if (cpu_signature == 0x0)
                return 0;
 
-       family = CPUID2FAMILY(cpu_signature);
-       if (family == 0xf)
-               family += CPUID2EXTFAMILY(cpu_signature);
+       family = CPUID_TO_FAMILY(cpu_signature);
 
        /* Errata #319: This has been fixed in Revision C2. */
        if (family == 0x10) {
-               if (CPUID2MODEL(cpu_signature) < 4)
+               if (CPUID_TO_BASEMODEL(cpu_signature) < 4)
                        return 0;
-               if (CPUID2MODEL(cpu_signature) == 4
-                   && CPUID2STEPPING(cpu_signature) < 2)
+               if (CPUID_TO_BASEMODEL(cpu_signature) == 4
+                   && CPUID_TO_STEPPING(cpu_signature) < 2)
                        return 0;
        }
 
@@ -238,9 +236,7 @@
        /* If we hit this, then match routine is wrong. */
        KASSERT(cpu_signature != 0x0);
 
-       sc->sc_family = CPUID2FAMILY(cpu_signature);
-       if (sc->sc_family == 0xf)
-               sc->sc_family += CPUID2EXTFAMILY(cpu_signature);
+       sc->sc_family = CPUID_TO_FAMILY(cpu_signature);
 
        KASSERT(sc->sc_family >= 0xf);
 
@@ -379,7 +375,7 @@
                        sc->sc_rev = amdtemp_core[i].rev[3];
                        aprint_normal(": core rev %.4s%.1x",
                                amdtemp_core[i].rev,
-                               CPUID2STEPPING(cpu_signature));
+                               CPUID_TO_STEPPING(cpu_signature));
 
                        switch (amdtemp_core[i].cpu[j].socket) {
                        case K8_SOCKET_AM2:
diff -r 60baef8a0a4b -r 51c8e6a827c5 sys/arch/x86/x86/coretemp.c
--- a/sys/arch/x86/x86/coretemp.c       Fri Nov 15 08:42:18 2013 +0000
+++ b/sys/arch/x86/x86/coretemp.c       Fri Nov 15 08:47:55 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: coretemp.c,v 1.30 2013/11/12 15:58:38 msaitoh Exp $ */
+/* $NetBSD: coretemp.c,v 1.31 2013/11/15 08:47:55 msaitoh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: coretemp.c,v 1.30 2013/11/12 15:58:38 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: coretemp.c,v 1.31 2013/11/15 08:47:55 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -217,8 +217,8 @@
        uint32_t model, stepping;
        uint64_t msr;
 
-       model = CPUID2MODEL(ci->ci_signature);
-       stepping = CPUID2STEPPING(ci->ci_signature);
+       model = CPUID_TO_MODEL(ci->ci_signature);
+       stepping = CPUID_TO_STEPPING(ci->ci_signature);
 
        /*
         * Check if the MSR contains thermal
@@ -259,11 +259,9 @@
        uint32_t family, model, stepping;
        uint64_t msr;
 
-       family = CPUID2FAMILY(ci->ci_signature);
-       model = CPUID2MODEL(ci->ci_signature);
-       if ((family == 0xf) || (family == 0x6))
-               model |= CPUID2EXTMODEL(ci->ci_signature) << 4;
-       stepping = CPUID2STEPPING(ci->ci_signature);
+       family = CPUID_TO_FAMILY(ci->ci_signature);
+       model = CPUID_TO_MODEL(ci->ci_signature);
+       stepping = CPUID_TO_STEPPING(ci->ci_signature);
 
        sc->sc_tjmax = 100;
 
diff -r 60baef8a0a4b -r 51c8e6a827c5 sys/arch/x86/x86/cpu.c
--- a/sys/arch/x86/x86/cpu.c    Fri Nov 15 08:42:18 2013 +0000
+++ b/sys/arch/x86/x86/cpu.c    Fri Nov 15 08:47:55 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.c,v 1.105 2013/11/12 16:15:54 msaitoh Exp $        */
+/*     $NetBSD: cpu.c,v 1.106 2013/11/15 08:47:55 msaitoh Exp $        */
 
 /*-
  * Copyright (c) 2000-2012 NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.105 2013/11/12 16:15:54 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.106 2013/11/15 08:47:55 msaitoh Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"                /* for MPDEBUG */
@@ -592,10 +592,10 @@
                /*
                 * Must be a K6-2 Step >= 7 or a K6-III.
                 */
-               if (CPUID2FAMILY(ci->ci_signature) == 5) {
-                       if (CPUID2MODEL(ci->ci_signature) > 8 ||
-                           (CPUID2MODEL(ci->ci_signature) == 8 &&
-                            CPUID2STEPPING(ci->ci_signature) >= 7)) {
+               if (CPUID_TO_FAMILY(ci->ci_signature) == 5) {
+                       if (CPUID_TO_MODEL(ci->ci_signature) > 8 ||
+                           (CPUID_TO_MODEL(ci->ci_signature) == 8 &&
+                            CPUID_TO_STEPPING(ci->ci_signature) >= 7)) {
                                mtrr_funcs = &k6_mtrr_funcs;
                                k6_mtrr_init_first();
                                mtrr_init_cpu(ci);
diff -r 60baef8a0a4b -r 51c8e6a827c5 sys/arch/x86/x86/cpu_topology.c
--- a/sys/arch/x86/x86/cpu_topology.c   Fri Nov 15 08:42:18 2013 +0000
+++ b/sys/arch/x86/x86/cpu_topology.c   Fri Nov 15 08:47:55 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu_topology.c,v 1.7 2013/11/12 16:35:57 msaitoh Exp $ */
+/*     $NetBSD: cpu_topology.c,v 1.8 2013/11/15 08:47:55 msaitoh Exp $ */
 
 /*-
  * Copyright (c) 2009 Mindaugas Rasiukevicius <rmind at NetBSD org>,
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_topology.c,v 1.7 2013/11/12 16:35:57 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_topology.c,v 1.8 2013/11/15 08:47:55 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/bitops.h>
@@ -57,9 +57,7 @@
        uint32_t descs[4], lextmode;
 
        apic_id = ci->ci_initapicid;
-       cpu_family = CPUID2FAMILY(ci->ci_signature);
-       if (cpu_family == 0xf)
-               cpu_family += CPUID2EXTFAMILY(ci->ci_signature);
+       cpu_family = CPUID_TO_FAMILY(ci->ci_signature);
 
        /* Initial values. */
        ci->ci_package_id = apic_id;
diff -r 60baef8a0a4b -r 51c8e6a827c5 sys/arch/x86/x86/cpu_ucode_amd.c
--- a/sys/arch/x86/x86/cpu_ucode_amd.c  Fri Nov 15 08:42:18 2013 +0000
+++ b/sys/arch/x86/x86/cpu_ucode_amd.c  Fri Nov 15 08:47:55 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode_amd.c,v 1.6 2013/07/06 12:03:11 gdt Exp $ */
+/* $NetBSD: cpu_ucode_amd.c,v 1.7 2013/11/15 08:47:55 msaitoh Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_amd.c,v 1.6 2013/07/06 12:03:11 gdt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_amd.c,v 1.7 2013/11/15 08:47:55 msaitoh Exp $");
 
 #include "opt_xen.h"
 #include "opt_cpu_ucode.h"
@@ -95,9 +95,7 @@
        uint32_t family;
        struct cpu_info *ci = curcpu();
 
-       family = CPUID2FAMILY(ci->ci_signature);
-       if (family == 0xf)
-               family += CPUID2EXTFAMILY(ci->ci_signature);
+       family = CPUID_TO_FAMILY(ci->ci_signature);
 
        return family;
 }
diff -r 60baef8a0a4b -r 51c8e6a827c5 sys/arch/x86/x86/cpu_ucode_intel.c
--- a/sys/arch/x86/x86/cpu_ucode_intel.c        Fri Nov 15 08:42:18 2013 +0000
+++ b/sys/arch/x86/x86/cpu_ucode_intel.c        Fri Nov 15 08:47:55 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode_intel.c,v 1.3 2013/07/06 12:11:54 gdt Exp $ */
+/* $NetBSD: cpu_ucode_intel.c,v 1.4 2013/11/15 08:47:55 msaitoh Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.3 2013/07/06 12:11:54 gdt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.4 2013/11/15 08:47:55 msaitoh Exp $");
 
 #include "opt_xen.h"



Home | Main Index | Thread Index | Old Index