|
Packit |
6c4009 |
/* Initialize CPU feature data. AArch64 version.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
Copyright (C) 2017-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <cpu-features.h>
|
|
Packit |
6c4009 |
#include <sys/auxv.h>
|
|
Packit |
6c4009 |
#include <elf/dl-hwcaps.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define DCZID_DZP_MASK (1 << 4)
|
|
Packit |
6c4009 |
#define DCZID_BS_MASK (0xf)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if HAVE_TUNABLES
|
|
Packit |
6c4009 |
struct cpu_list
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
const char *name;
|
|
Packit |
6c4009 |
uint64_t midr;
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static struct cpu_list cpu_list[] = {
|
|
Packit |
6c4009 |
{"falkor", 0x510FC000},
|
|
Packit |
6c4009 |
{"thunderxt88", 0x430F0A10},
|
|
Packit |
6c4009 |
{"thunderx2t99", 0x431F0AF0},
|
|
Packit |
6c4009 |
{"thunderx2t99p1", 0x420F5160},
|
|
Packit |
6c4009 |
{"phecda", 0x680F0000},
|
|
Packit |
6c4009 |
{"generic", 0x0}
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static uint64_t
|
|
Packit |
6c4009 |
get_midr_from_mcpu (const char *mcpu)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
for (int i = 0; i < sizeof (cpu_list) / sizeof (struct cpu_list); i++)
|
|
Packit |
6c4009 |
if (strcmp (mcpu, cpu_list[i].name) == 0)
|
|
Packit |
6c4009 |
return cpu_list[i].midr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return UINT64_MAX;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static inline void
|
|
Packit |
6c4009 |
init_cpu_features (struct cpu_features *cpu_features)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
register uint64_t midr = UINT64_MAX;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if HAVE_TUNABLES
|
|
Packit |
6c4009 |
/* Get the tunable override. */
|
|
Packit Service |
c82647 |
const char *mcpu = TUNABLE_GET (glibc, tune, cpu, const char *, NULL);
|
|
Packit |
6c4009 |
if (mcpu != NULL)
|
|
Packit |
6c4009 |
midr = get_midr_from_mcpu (mcpu);
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* If there was no useful tunable override, query the MIDR if the kernel
|
|
Packit |
6c4009 |
allows it. */
|
|
Packit |
6c4009 |
if (midr == UINT64_MAX)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (GLRO (dl_hwcap) & HWCAP_CPUID)
|
|
Packit |
6c4009 |
asm volatile ("mrs %0, midr_el1" : "=r"(midr));
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
midr = 0;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
cpu_features->midr_el1 = midr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Check if ZVA is enabled. */
|
|
Packit |
6c4009 |
unsigned dczid;
|
|
Packit |
6c4009 |
asm volatile ("mrs %0, dczid_el0" : "=r"(dczid));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if ((dczid & DCZID_DZP_MASK) == 0)
|
|
Packit |
6c4009 |
cpu_features->zva_size = 4 << (dczid & DCZID_BS_MASK);
|
|
Packit |
6c4009 |
}
|