Update mallinfo2 ABI, and test
[glibc.git] / sysdeps / unix / sysv / linux / aarch64 / cpu-features.c
blobb9ab827acafb9c62521437bb59fa89ca73e2a8fa
1 /* Initialize CPU feature data. AArch64 version.
2 This file is part of the GNU C Library.
3 Copyright (C) 2017-2020 Free Software Foundation, Inc.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <cpu-features.h>
20 #include <sys/auxv.h>
21 #include <elf/dl-hwcaps.h>
23 #define DCZID_DZP_MASK (1 << 4)
24 #define DCZID_BS_MASK (0xf)
26 #if HAVE_TUNABLES
27 struct cpu_list
29 const char *name;
30 uint64_t midr;
33 static struct cpu_list cpu_list[] = {
34 {"falkor", 0x510FC000},
35 {"thunderxt88", 0x430F0A10},
36 {"thunderx2t99", 0x431F0AF0},
37 {"thunderx2t99p1", 0x420F5160},
38 {"phecda", 0x680F0000},
39 {"ares", 0x411FD0C0},
40 {"emag", 0x503F0001},
41 {"kunpeng920", 0x481FD010},
42 {"generic", 0x0}
45 static uint64_t
46 get_midr_from_mcpu (const char *mcpu)
48 for (int i = 0; i < sizeof (cpu_list) / sizeof (struct cpu_list); i++)
49 if (strcmp (mcpu, cpu_list[i].name) == 0)
50 return cpu_list[i].midr;
52 return UINT64_MAX;
54 #endif
56 static inline void
57 init_cpu_features (struct cpu_features *cpu_features)
59 register uint64_t midr = UINT64_MAX;
61 #if HAVE_TUNABLES
62 /* Get the tunable override. */
63 const char *mcpu = TUNABLE_GET (glibc, cpu, name, const char *, NULL);
64 if (mcpu != NULL)
65 midr = get_midr_from_mcpu (mcpu);
66 #endif
68 /* If there was no useful tunable override, query the MIDR if the kernel
69 allows it. */
70 if (midr == UINT64_MAX)
72 if (GLRO (dl_hwcap) & HWCAP_CPUID)
73 asm volatile ("mrs %0, midr_el1" : "=r"(midr));
74 else
75 midr = 0;
78 cpu_features->midr_el1 = midr;
80 /* Check if ZVA is enabled. */
81 unsigned dczid;
82 asm volatile ("mrs %0, dczid_el0" : "=r"(dczid));
84 if ((dczid & DCZID_DZP_MASK) == 0)
85 cpu_features->zva_size = 4 << (dczid & DCZID_BS_MASK);
87 /* Check if BTI is supported. */
88 cpu_features->bti = GLRO (dl_hwcap2) & HWCAP2_BTI;