2 * Copyright (c) 2014 Andrew Turner
3 * Copyright (c) 2014 The FreeBSD Foundation
6 * Portions of this software were developed by Semihalf
7 * under sponsorship of the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
37 #include <sys/sysctl.h>
38 #include <sys/systm.h>
40 #include <machine/cpu.h>
41 #include <machine/cpufunc.h>
43 char machine[] = "arm64";
45 SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0,
49 * Per-CPU affinity as provided in MPIDR_EL1
50 * Indexed by CPU number in logical order selected by the system.
51 * Relevant fields can be extracted using CPU_AFFn macros,
52 * Aff3.Aff2.Aff1.Aff0 construct a unique CPU address in the system.
55 * Aff1 - Cluster number
56 * Aff0 - CPU number in Aff1 cluster
58 uint64_t __cpu_affinity[MAXCPU];
65 const char *cpu_impl_name;
66 const char *cpu_part_name;
69 struct cpu_desc cpu_desc[MAXCPU];
73 const char *part_name;
75 #define CPU_PART_NONE { 0, "Unknown Processor" }
77 struct cpu_implementers {
79 const char *impl_name;
81 * Part number is implementation defined
82 * so each vendor will have its own set of values and names.
84 const struct cpu_parts *cpu_parts;
86 #define CPU_IMPLEMENTER_NONE { 0, "Unknown Implementer", cpu_parts_none }
89 * Per-implementer table of (PartNum, CPU Name) pairs.
92 static const struct cpu_parts cpu_parts_arm[] = {
93 { CPU_PART_FOUNDATION, "Foundation-Model" },
94 { CPU_PART_CORTEX_A53, "Cortex-A53" },
95 { CPU_PART_CORTEX_A57, "Cortex-A57" },
99 static const struct cpu_parts cpu_parts_cavium[] = {
100 { CPU_PART_THUNDER, "Thunder" },
105 static const struct cpu_parts cpu_parts_none[] = {
110 * Implementers table.
112 const struct cpu_implementers cpu_implementers[] = {
113 { CPU_IMPL_ARM, "ARM", cpu_parts_arm },
114 { CPU_IMPL_BROADCOM, "Broadcom", cpu_parts_none },
115 { CPU_IMPL_CAVIUM, "Cavium", cpu_parts_cavium },
116 { CPU_IMPL_DEC, "DEC", cpu_parts_none },
117 { CPU_IMPL_INFINEON, "IFX", cpu_parts_none },
118 { CPU_IMPL_FREESCALE, "Freescale", cpu_parts_none },
119 { CPU_IMPL_NVIDIA, "NVIDIA", cpu_parts_none },
120 { CPU_IMPL_APM, "APM", cpu_parts_none },
121 { CPU_IMPL_QUALCOMM, "Qualcomm", cpu_parts_none },
122 { CPU_IMPL_MARVELL, "Marvell", cpu_parts_none },
123 { CPU_IMPL_INTEL, "Intel", cpu_parts_none },
124 CPU_IMPLEMENTER_NONE,
127 void identify_cpu(void);
138 const struct cpu_parts *cpu_partsp = NULL;
140 cpu = PCPU_GET(cpuid);
144 * Store midr to pcpu to allow fast reading
145 * from EL0, EL1 and assembly code.
147 PCPU_SET(midr, midr);
149 impl_id = CPU_IMPL(midr);
150 for (i = 0; i < nitems(cpu_implementers); i++) {
151 if (impl_id == cpu_implementers[i].impl_id ||
152 cpu_implementers[i].impl_id == 0) {
153 cpu_desc[cpu].cpu_impl = impl_id;
154 cpu_desc[cpu].cpu_impl_name = cpu_implementers[i].impl_name;
155 cpu_partsp = cpu_implementers[i].cpu_parts;
160 part_id = CPU_PART(midr);
161 for (i = 0; &cpu_partsp[i] != NULL; i++) {
162 if (part_id == cpu_partsp[i].part_id ||
163 cpu_partsp[i].part_id == 0) {
164 cpu_desc[cpu].cpu_part_num = part_id;
165 cpu_desc[cpu].cpu_part_name = cpu_partsp[i].part_name;
170 cpu_desc[cpu].cpu_revision = CPU_REV(midr);
171 cpu_desc[cpu].cpu_variant = CPU_VAR(midr);
173 /* Save affinity for current CPU */
175 CPU_AFFINITY(cpu) = mpidr & CPU_AFF_MASK;
177 /* Print details for boot CPU or if we want verbose output */
178 if (cpu == 0 || bootverbose) {
179 printf("CPU(%d): %s %s r%dp%d\n", cpu,
180 cpu_desc[cpu].cpu_impl_name,
181 cpu_desc[cpu].cpu_part_name,
182 cpu_desc[cpu].cpu_variant,
183 cpu_desc[cpu].cpu_revision);
187 printf("CPU%u affinity: %u.%u.%u.%u\n", 0, CPU_AFF0(mpidr),
188 CPU_AFF1(mpidr), CPU_AFF2(mpidr), CPU_AFF3(mpidr));