2014-07-16 23:32:44 +08:00
|
|
|
/*
|
|
|
|
* Record and handle CPU attributes.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 ARM Ltd.
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <asm/arch_timer.h>
|
|
|
|
#include <asm/cachetype.h>
|
|
|
|
#include <asm/cpu.h>
|
|
|
|
#include <asm/cputype.h>
|
2014-11-14 23:54:09 +08:00
|
|
|
#include <asm/cpufeature.h>
|
2014-07-16 23:32:44 +08:00
|
|
|
|
2014-07-16 23:32:45 +08:00
|
|
|
#include <linux/bitops.h>
|
2014-08-08 19:51:39 +08:00
|
|
|
#include <linux/bug.h>
|
2014-07-16 23:32:44 +08:00
|
|
|
#include <linux/init.h>
|
2014-07-16 23:32:46 +08:00
|
|
|
#include <linux/kernel.h>
|
2015-10-19 21:24:43 +08:00
|
|
|
#include <linux/personality.h>
|
2014-08-08 19:51:39 +08:00
|
|
|
#include <linux/preempt.h>
|
2014-07-16 23:32:45 +08:00
|
|
|
#include <linux/printk.h>
|
2015-10-19 21:24:43 +08:00
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/sched.h>
|
2014-07-16 23:32:44 +08:00
|
|
|
#include <linux/smp.h>
|
2015-11-19 02:48:55 +08:00
|
|
|
#include <linux/delay.h>
|
2014-07-16 23:32:44 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In case the boot CPU is hotpluggable, we record its initial state and
|
|
|
|
* current state separately. Certain system registers may contain different
|
|
|
|
* values depending on configuration at or after reset.
|
|
|
|
*/
|
|
|
|
DEFINE_PER_CPU(struct cpuinfo_arm64, cpu_data);
|
|
|
|
static struct cpuinfo_arm64 boot_cpu_data;
|
|
|
|
|
2014-07-16 23:32:45 +08:00
|
|
|
static char *icache_policy_str[] = {
|
|
|
|
[ICACHE_POLICY_RESERVED] = "RESERVED/UNKNOWN",
|
|
|
|
[ICACHE_POLICY_AIVIVT] = "AIVIVT",
|
|
|
|
[ICACHE_POLICY_VIPT] = "VIPT",
|
|
|
|
[ICACHE_POLICY_PIPT] = "PIPT",
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned long __icache_flags;
|
|
|
|
|
2015-07-30 23:36:25 +08:00
|
|
|
static const char *const hwcap_str[] = {
|
2015-10-19 21:24:43 +08:00
|
|
|
"fp",
|
|
|
|
"asimd",
|
|
|
|
"evtstrm",
|
|
|
|
"aes",
|
|
|
|
"pmull",
|
|
|
|
"sha1",
|
|
|
|
"sha2",
|
|
|
|
"crc32",
|
|
|
|
"atomics",
|
2016-01-26 23:52:46 +08:00
|
|
|
"fphp",
|
|
|
|
"asimdhp",
|
2015-10-19 21:24:43 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_COMPAT
|
2015-07-30 23:36:25 +08:00
|
|
|
static const char *const compat_hwcap_str[] = {
|
2015-10-19 21:24:43 +08:00
|
|
|
"swp",
|
|
|
|
"half",
|
|
|
|
"thumb",
|
|
|
|
"26bit",
|
|
|
|
"fastmult",
|
|
|
|
"fpa",
|
|
|
|
"vfp",
|
|
|
|
"edsp",
|
|
|
|
"java",
|
|
|
|
"iwmmxt",
|
|
|
|
"crunch",
|
|
|
|
"thumbee",
|
|
|
|
"neon",
|
|
|
|
"vfpv3",
|
|
|
|
"vfpv3d16",
|
|
|
|
"tls",
|
|
|
|
"vfpv4",
|
|
|
|
"idiva",
|
|
|
|
"idivt",
|
|
|
|
"vfpd32",
|
|
|
|
"lpae",
|
|
|
|
"evtstrm"
|
|
|
|
};
|
|
|
|
|
2015-07-30 23:36:25 +08:00
|
|
|
static const char *const compat_hwcap2_str[] = {
|
2015-10-19 21:24:43 +08:00
|
|
|
"aes",
|
|
|
|
"pmull",
|
|
|
|
"sha1",
|
|
|
|
"sha2",
|
|
|
|
"crc32",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
#endif /* CONFIG_COMPAT */
|
|
|
|
|
|
|
|
static int c_show(struct seq_file *m, void *v)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for_each_online_cpu(i) {
|
|
|
|
struct cpuinfo_arm64 *cpuinfo = &per_cpu(cpu_data, i);
|
|
|
|
u32 midr = cpuinfo->reg_midr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* glibc reads /proc/cpuinfo to determine the number of
|
|
|
|
* online processors, looking for lines beginning with
|
|
|
|
* "processor". Give glibc what it expects.
|
|
|
|
*/
|
|
|
|
seq_printf(m, "processor\t: %d\n", i);
|
|
|
|
|
2015-11-19 02:48:55 +08:00
|
|
|
seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
|
|
|
|
loops_per_jiffy / (500000UL/HZ),
|
|
|
|
loops_per_jiffy / (5000UL/HZ) % 100);
|
|
|
|
|
2015-10-19 21:24:43 +08:00
|
|
|
/*
|
|
|
|
* Dump out the common processor features in a single line.
|
|
|
|
* Userspace should read the hwcaps with getauxval(AT_HWCAP)
|
|
|
|
* rather than attempting to parse this, but there's a body of
|
|
|
|
* software which does already (at least for 32-bit).
|
|
|
|
*/
|
|
|
|
seq_puts(m, "Features\t:");
|
|
|
|
if (personality(current->personality) == PER_LINUX32) {
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
for (j = 0; compat_hwcap_str[j]; j++)
|
|
|
|
if (compat_elf_hwcap & (1 << j))
|
|
|
|
seq_printf(m, " %s", compat_hwcap_str[j]);
|
|
|
|
|
|
|
|
for (j = 0; compat_hwcap2_str[j]; j++)
|
|
|
|
if (compat_elf_hwcap2 & (1 << j))
|
|
|
|
seq_printf(m, " %s", compat_hwcap2_str[j]);
|
|
|
|
#endif /* CONFIG_COMPAT */
|
|
|
|
} else {
|
|
|
|
for (j = 0; hwcap_str[j]; j++)
|
|
|
|
if (elf_hwcap & (1 << j))
|
|
|
|
seq_printf(m, " %s", hwcap_str[j]);
|
|
|
|
}
|
|
|
|
seq_puts(m, "\n");
|
|
|
|
|
|
|
|
seq_printf(m, "CPU implementer\t: 0x%02x\n",
|
|
|
|
MIDR_IMPLEMENTOR(midr));
|
|
|
|
seq_printf(m, "CPU architecture: 8\n");
|
|
|
|
seq_printf(m, "CPU variant\t: 0x%x\n", MIDR_VARIANT(midr));
|
|
|
|
seq_printf(m, "CPU part\t: 0x%03x\n", MIDR_PARTNUM(midr));
|
|
|
|
seq_printf(m, "CPU revision\t: %d\n\n", MIDR_REVISION(midr));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *c_start(struct seq_file *m, loff_t *pos)
|
|
|
|
{
|
|
|
|
return *pos < 1 ? (void *)1 : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *c_next(struct seq_file *m, void *v, loff_t *pos)
|
|
|
|
{
|
|
|
|
++*pos;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void c_stop(struct seq_file *m, void *v)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct seq_operations cpuinfo_op = {
|
|
|
|
.start = c_start,
|
|
|
|
.next = c_next,
|
|
|
|
.stop = c_stop,
|
|
|
|
.show = c_show
|
|
|
|
};
|
|
|
|
|
2014-07-16 23:32:45 +08:00
|
|
|
static void cpuinfo_detect_icache_policy(struct cpuinfo_arm64 *info)
|
|
|
|
{
|
|
|
|
unsigned int cpu = smp_processor_id();
|
|
|
|
u32 l1ip = CTR_L1IP(info->reg_ctr);
|
|
|
|
|
2014-08-08 19:51:40 +08:00
|
|
|
if (l1ip != ICACHE_POLICY_PIPT) {
|
|
|
|
/*
|
|
|
|
* VIPT caches are non-aliasing if the VA always equals the PA
|
|
|
|
* in all bit positions that are covered by the index. This is
|
|
|
|
* the case if the size of a way (# of sets * line size) does
|
|
|
|
* not exceed PAGE_SIZE.
|
|
|
|
*/
|
|
|
|
u32 waysize = icache_get_numsets() * icache_get_linesize();
|
|
|
|
|
|
|
|
if (l1ip != ICACHE_POLICY_VIPT || waysize > PAGE_SIZE)
|
|
|
|
set_bit(ICACHEF_ALIASING, &__icache_flags);
|
|
|
|
}
|
2014-08-05 17:25:55 +08:00
|
|
|
if (l1ip == ICACHE_POLICY_AIVIVT)
|
2014-07-16 23:32:45 +08:00
|
|
|
set_bit(ICACHEF_AIVIVT, &__icache_flags);
|
|
|
|
|
2014-08-01 17:23:20 +08:00
|
|
|
pr_info("Detected %s I-cache on CPU%d\n", icache_policy_str[l1ip], cpu);
|
2014-07-16 23:32:45 +08:00
|
|
|
}
|
|
|
|
|
2014-07-16 23:32:44 +08:00
|
|
|
static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info)
|
|
|
|
{
|
|
|
|
info->reg_cntfrq = arch_timer_get_cntfrq();
|
|
|
|
info->reg_ctr = read_cpuid_cachetype();
|
2016-02-05 22:58:46 +08:00
|
|
|
info->reg_dczid = read_cpuid(SYS_DCZID_EL0);
|
2014-07-16 23:32:44 +08:00
|
|
|
info->reg_midr = read_cpuid_id();
|
|
|
|
|
2016-02-05 22:58:46 +08:00
|
|
|
info->reg_id_aa64dfr0 = read_cpuid(SYS_ID_AA64DFR0_EL1);
|
|
|
|
info->reg_id_aa64dfr1 = read_cpuid(SYS_ID_AA64DFR1_EL1);
|
|
|
|
info->reg_id_aa64isar0 = read_cpuid(SYS_ID_AA64ISAR0_EL1);
|
|
|
|
info->reg_id_aa64isar1 = read_cpuid(SYS_ID_AA64ISAR1_EL1);
|
|
|
|
info->reg_id_aa64mmfr0 = read_cpuid(SYS_ID_AA64MMFR0_EL1);
|
|
|
|
info->reg_id_aa64mmfr1 = read_cpuid(SYS_ID_AA64MMFR1_EL1);
|
2016-02-05 22:58:47 +08:00
|
|
|
info->reg_id_aa64mmfr2 = read_cpuid(SYS_ID_AA64MMFR2_EL1);
|
2016-02-05 22:58:46 +08:00
|
|
|
info->reg_id_aa64pfr0 = read_cpuid(SYS_ID_AA64PFR0_EL1);
|
|
|
|
info->reg_id_aa64pfr1 = read_cpuid(SYS_ID_AA64PFR1_EL1);
|
|
|
|
|
|
|
|
info->reg_id_dfr0 = read_cpuid(SYS_ID_DFR0_EL1);
|
|
|
|
info->reg_id_isar0 = read_cpuid(SYS_ID_ISAR0_EL1);
|
|
|
|
info->reg_id_isar1 = read_cpuid(SYS_ID_ISAR1_EL1);
|
|
|
|
info->reg_id_isar2 = read_cpuid(SYS_ID_ISAR2_EL1);
|
|
|
|
info->reg_id_isar3 = read_cpuid(SYS_ID_ISAR3_EL1);
|
|
|
|
info->reg_id_isar4 = read_cpuid(SYS_ID_ISAR4_EL1);
|
|
|
|
info->reg_id_isar5 = read_cpuid(SYS_ID_ISAR5_EL1);
|
|
|
|
info->reg_id_mmfr0 = read_cpuid(SYS_ID_MMFR0_EL1);
|
|
|
|
info->reg_id_mmfr1 = read_cpuid(SYS_ID_MMFR1_EL1);
|
|
|
|
info->reg_id_mmfr2 = read_cpuid(SYS_ID_MMFR2_EL1);
|
|
|
|
info->reg_id_mmfr3 = read_cpuid(SYS_ID_MMFR3_EL1);
|
|
|
|
info->reg_id_pfr0 = read_cpuid(SYS_ID_PFR0_EL1);
|
|
|
|
info->reg_id_pfr1 = read_cpuid(SYS_ID_PFR1_EL1);
|
|
|
|
|
|
|
|
info->reg_mvfr0 = read_cpuid(SYS_MVFR0_EL1);
|
|
|
|
info->reg_mvfr1 = read_cpuid(SYS_MVFR1_EL1);
|
|
|
|
info->reg_mvfr2 = read_cpuid(SYS_MVFR2_EL1);
|
2015-01-07 18:31:56 +08:00
|
|
|
|
2014-07-16 23:32:45 +08:00
|
|
|
cpuinfo_detect_icache_policy(info);
|
2014-11-14 23:54:09 +08:00
|
|
|
|
|
|
|
check_local_cpu_errata();
|
2014-07-16 23:32:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void cpuinfo_store_cpu(void)
|
|
|
|
{
|
|
|
|
struct cpuinfo_arm64 *info = this_cpu_ptr(&cpu_data);
|
|
|
|
__cpuinfo_store_cpu(info);
|
2015-10-19 21:24:46 +08:00
|
|
|
update_cpu_features(smp_processor_id(), info, &boot_cpu_data);
|
2014-07-16 23:32:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __init cpuinfo_store_boot_cpu(void)
|
|
|
|
{
|
|
|
|
struct cpuinfo_arm64 *info = &per_cpu(cpu_data, 0);
|
|
|
|
__cpuinfo_store_cpu(info);
|
|
|
|
|
|
|
|
boot_cpu_data = *info;
|
2015-10-19 21:24:45 +08:00
|
|
|
init_cpu_features(&boot_cpu_data);
|
2014-07-16 23:32:44 +08:00
|
|
|
}
|