Subject: CPUID patch for recent Intel processors
To: None <port-i386@netbsd.org>
From: Bang Jun-Young <junyoung@netbsd.org>
List: port-i386
Date: 12/06/2002 15:44:19
Hi,

People have complaint that NetBSD doesn't properly identify their Intel
processors. I made a patch to address that, here it is:

Index: machdep.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/i386/machdep.c,v
retrieving revision 1.502
diff -u -r1.502 machdep.c
--- machdep.c	2002/12/06 05:03:02	1.502
+++ machdep.c	2002/12/06 06:42:06
@@ -315,8 +315,17 @@
 	"Celeron",	    /* Intel (R) Celeron (TM) processor */
 	"Pentium III",      /* Intel (R) Pentium (R) III processor */
 	"Pentium III Xeon", /* Intel (R) Pentium (R) III Xeon (TM) processor */
-	"", "", "",	    /* Reserved */
-	"Pentium 4"	    /* Intel (R) Pentium (R) 4 processor */
+	"Pentium III",      /* Intel (R) Pentium (R) III processor */
+	"",		    /* Reserved */
+	"Mobile Pentium III", /* Mobile Intel (R) Pentium (R) III processor-M */
+	"Mobile Celeron",   /* Mobile Intel (R) Celeron (R) processor */    
+	"Pentium 4",	    /* Intel (R) Pentium (R) 4 processor */
+	"Pentium 4",	    /* Intel (R) Pentium (R) 4 processor */
+	"Celeron",	    /* Intel (R) Celeron (TM) processor */
+	"Xeon",		    /* Intel (R) Xeon (TM) processor */
+	"Xeon MP",	    /* Intel (R) Xeon (TM) processor MP */
+	"Mobile Pentium 4", /* Mobile Intel (R) Pentium (R) 4 processor-M */
+	"Mobile Celeron",   /* Mobile Intel (R) Celeron (R) processor */
 };
 
 /*
@@ -344,6 +353,8 @@
 static void via_cpu_probe __P((struct cpu_info *));
 static void amd_family6_probe __P((struct cpu_info *));
 
+static const char *intel_family6_name __P((struct cpu_info *));
+
 static void transmeta_cpu_info __P((struct cpu_info *));
 static void amd_cpu_cacheinfo __P((struct cpu_info *));
 
@@ -1122,6 +1133,62 @@
 	}
 }
 
+const char *
+intel_family6_name(struct cpu_info *ci)
+{
+	int model = CPUID2MODEL(ci->ci_signature);
+	const char *ret = NULL;
+	u_int l2cache = ci->ci_cinfo[CAI_L2CACHE].cai_totalsize;
+
+	switch (model) {
+	case 5:
+		switch (l2cache) {
+		case 0:
+		case 128 * 1024:
+			ret = "Celeron (Covington)";
+			break;
+		case 256 * 1024:
+			ret = "Mobile Pentium II (Dixon)";
+			break;
+		case 512 * 1024:
+			ret = "Pentium II";
+			break;
+		case 1 * 1024 * 1024:
+		case 2 * 1024 * 1024:
+			ret = "Pentium II Xeon";
+			break;
+		}
+		break;
+	case 6:
+		switch (l2cache) {
+		case 256 * 1024:
+			ret = "Mobile Pentium II";
+			break;
+		case 512 * 1024:
+			ret = "Mobile Pentium II w/512 KB L2 cache";
+			break;
+		}
+		break;
+	case 7:
+		switch (l2cache) {
+		case 512 * 1024:
+			ret = "Pentium III";
+			break;
+		case 1 * 1024 * 1024:
+		case 2 * 1024 * 1024:
+			ret = "Pentium III Xeon";
+			break;
+		}
+		break;
+	case 8:
+		if (ci->ci_brand_id && ci->ci_brand_id < 0x10)
+			ret = i386_intel_brand[ci->ci_brand_id];
+		break;
+	}
+
+	return (ret);
+}
+
 static void
 cpu_probe_base_features(struct cpu_info *ci)
 {
@@ -1724,7 +1791,7 @@
 	} else {
 		max = sizeof (i386_cpuid_cpus) / sizeof (i386_cpuid_cpus[0]);
 		modif = (ci->ci_signature >> 12) & 0x3;
-		family = (ci->ci_signature >> 8) & 0xf;
+		family = CPUID2FAMILY(ci->ci_signature);
 		if (family < CPU_MINFAMILY)
 			panic("identifycpu: strange family value");
 		model = CPUID2MODEL(ci->ci_signature);
@@ -1772,14 +1839,12 @@
 			ci->cpu_setup = cpufam->cpu_setup;
 			ci->ci_info = cpufam->cpu_info;
 
-			/*
-			 * Intel processors family >= 6, model 8 allow to
-			 * recognize brand by Brand ID value.
-			 */
-			if (vendor == CPUVENDOR_INTEL && family >= 6 &&
-			    model >= 8 && ci->ci_brand_id &&
-			    ci->ci_brand_id < 8)
-				brand = i386_intel_brand[ci->ci_brand_id];
+			if (vendor == CPUVENDOR_INTEL && family == 6 &&
+			    model >= 5 && model <= 8) {
+				const char *tmp = intel_family6_name(ci);
+				if (tmp != NULL)
+					name = tmp;
+			}
 			
 			if (vendor == CPUVENDOR_AMD && family == 6 &&
 			    model >= 6) {

Since I have no Intel processor based machine at home, I can't test the
patch myself. I'd appreciate it if you Intel users would do it.

Jun-Young

-- 
Bang Jun-Young <junyoung@netbsd.org>