1139825Simp/*-
284192Sjake * Initial implementation:
384192Sjake * Copyright (c) 2001 Robert Drehmel
484192Sjake * All rights reserved.
584192Sjake *
684192Sjake * As long as the above copyright statement and this notice remain
784192Sjake * unchanged, you can do what ever you want with this file.
884192Sjake */
9169795Smarius
10169795Smarius#include <sys/cdefs.h>
11169795Smarius__FBSDID("$FreeBSD$");
12169795Smarius
1384192Sjake#include <sys/param.h>
1484192Sjake#include <sys/systm.h>
1586522Sjake#include <sys/kernel.h>
1686522Sjake#include <sys/sysctl.h>
1784192Sjake
1884848Stmm#include <machine/md_var.h>
1984192Sjake#include <machine/ver.h>
2084192Sjake
21164372Skmacychar machine[] = MACHINE;
2286522SjakeSYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD,
2386522Sjake    machine, 0, "Machine class");
2486522Sjake
2586522Sjakestatic char cpu_model[128];
2686522SjakeSYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD,
2786522Sjake    cpu_model, 0, "Machine model");
2886522Sjake
29248085Smariusstatic SYSCTL_NODE(_hw, OID_AUTO, freq, CTLFLAG_RD, 0, "");
30200891Smarcel
31200891Smarcelstatic u_int cpu_count;
32200891Smarcelstatic u_int cpu_freq;
33200891SmarcelSYSCTL_UINT(_hw_freq, OID_AUTO, cpu, CTLFLAG_RD, &cpu_freq, 0,
34200891Smarcel    "CPU clock frequency");
35200891Smarcel
3684192Sjakevoid
3791359Sjakecpu_identify(u_long vers, u_int freq, u_int id)
3884192Sjake{
3984192Sjake	const char *manus;
4084192Sjake	const char *impls;
4184192Sjake
4284192Sjake	switch (VER_MANUF(vers)) {
4384192Sjake	case 0x04:
44207537Smarius		manus = "HAL/Fujitsu";
4584192Sjake		break;
4684192Sjake	case 0x13:
4784192Sjake	case 0x17:
4888791Sjake	case 0x22:
4999896Sjake	case 0x3e:
5084192Sjake		manus = "Sun Microsystems";
5184192Sjake		break;
5299896Sjake	default:
5399896Sjake		manus = NULL;
5499896Sjake		break;
5584192Sjake	}
56112398Sjake	switch (VER_IMPL(vers)) {
5790614Stmm	case CPU_IMPL_SPARC64:
5884192Sjake		impls = "SPARC64";
5984192Sjake		break;
60207537Smarius	case CPU_IMPL_SPARC64II:
61207537Smarius		impls = "SPARC64-II";
62207537Smarius		break;
63207537Smarius	case CPU_IMPL_SPARC64III:
64207537Smarius		impls = "SPARC64-III";
65207537Smarius		break;
66207537Smarius	case CPU_IMPL_SPARC64IV:
67207537Smarius		impls = "SPARC64-IV";
68207537Smarius		break;
69207537Smarius	case CPU_IMPL_SPARC64V:
70207537Smarius		impls = "SPARC64-V";
71207537Smarius		break;
72207537Smarius	case CPU_IMPL_SPARC64VI:
73207537Smarius		impls = "SPARC64-VI";
74207537Smarius		break;
75207537Smarius	case CPU_IMPL_SPARC64VII:
76207537Smarius		impls = "SPARC64-VII";
77207537Smarius		break;
78207537Smarius	case CPU_IMPL_SPARC64VIIIfx:
79207537Smarius		impls = "SPARC64-VIIIfx";
80207537Smarius		break;
8190614Stmm	case CPU_IMPL_ULTRASPARCI:
8284192Sjake		impls = "UltraSparc-I";
8384192Sjake		break;
8490614Stmm	case CPU_IMPL_ULTRASPARCII:
8584192Sjake		impls = "UltraSparc-II";
8684192Sjake		break;
8790614Stmm	case CPU_IMPL_ULTRASPARCIIi:
8884192Sjake		impls = "UltraSparc-IIi";
8984192Sjake		break;
9090614Stmm	case CPU_IMPL_ULTRASPARCIIe:
9184192Sjake		impls = "UltraSparc-IIe";
9284192Sjake		break;
9399896Sjake	case CPU_IMPL_ULTRASPARCIII:
9499896Sjake		impls = "UltraSparc-III";
9599896Sjake		break;
9699896Sjake	case CPU_IMPL_ULTRASPARCIIIp:
9799896Sjake		impls = "UltraSparc-III+";
9899896Sjake		break;
99139264Sscottl	case CPU_IMPL_ULTRASPARCIIIi:
100139264Sscottl		impls = "UltraSparc-IIIi";
101139264Sscottl		break;
102169795Smarius	case CPU_IMPL_ULTRASPARCIV:
103169795Smarius		impls = "UltraSparc-IV";
104169795Smarius		break;
105169795Smarius	case CPU_IMPL_ULTRASPARCIVp:
106169795Smarius		impls = "UltraSparc-IV+";
107169795Smarius		break;
108169795Smarius	case CPU_IMPL_ULTRASPARCIIIip:
109169795Smarius		impls = "UltraSparc-IIIi+";
110169795Smarius		break;
11199896Sjake	default:
11299896Sjake		impls = NULL;
11399896Sjake		break;
11484192Sjake	}
11584192Sjake	if (manus == NULL || impls == NULL) {
11684192Sjake		printf(
11784192Sjake		    "CPU: unknown; please e-mail the following value together\n"
11884192Sjake		    "     with the exact name of your processor to "
119128756Smarius		    "<freebsd-sparc64@FreeBSD.org>.\n"
12084192Sjake		    "     version register: <0x%lx>\n", vers);
12184192Sjake		return;
12284192Sjake	}
12384192Sjake
12486522Sjake	snprintf(cpu_model, sizeof(cpu_model), "%s %s", manus, impls);
125106541Smux	printf("cpu%d: %s %s Processor (%d.%02d MHz CPU)\n", id, manus, impls,
12684192Sjake	    (freq + 4999) / 1000000, ((freq + 4999) / 10000) % 100);
12784192Sjake	if (bootverbose) {
12884848Stmm		printf("  mask=0x%lx maxtl=%ld maxwin=%ld\n", VER_MASK(vers),
12984192Sjake		    VER_MAXTL(vers), VER_MAXWIN(vers));
13084192Sjake	}
131200891Smarcel
132200891Smarcel	/*
133200891Smarcel	 * Calculate the average CPU frequency.
134200891Smarcel	 */
135200891Smarcel	freq = (freq + 500000ul) / 1000000ul;
136200891Smarcel	cpu_freq = (cpu_freq * cpu_count + freq) / (cpu_count + 1);
137200891Smarcel	cpu_count++;
13884192Sjake}
139