4 * Copyright (C) IBM Corporation 2014.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of IBM Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "rte_cpuflags.h"
40 /* Symbolic values for the entries in the auxiliary table */
44 /* software based registers */
50 typedef uint32_t cpuid_registers_t[4];
53 * Struct to hold a processor feature entry
55 struct feature_entry {
56 uint32_t leaf; /**< cpuid leaf */
57 uint32_t subleaf; /**< cpuid subleaf */
58 uint32_t reg; /**< cpuid register */
59 uint32_t bit; /**< cpuid register bit */
60 #define CPU_FLAG_NAME_MAX_LEN 64
61 char name[CPU_FLAG_NAME_MAX_LEN]; /**< String for printing */
64 #define FEAT_DEF(name, leaf, subleaf, reg, bit) \
65 [RTE_CPUFLAG_##name] = {leaf, subleaf, reg, bit, #name },
67 const struct feature_entry rte_cpu_feature_table[] = {
68 FEAT_DEF(PPC_LE, 0x00000001, 0, REG_HWCAP, 0)
69 FEAT_DEF(TRUE_LE, 0x00000001, 0, REG_HWCAP, 1)
70 FEAT_DEF(PSERIES_PERFMON_COMPAT, 0x00000001, 0, REG_HWCAP, 6)
71 FEAT_DEF(VSX, 0x00000001, 0, REG_HWCAP, 7)
72 FEAT_DEF(ARCH_2_06, 0x00000001, 0, REG_HWCAP, 8)
73 FEAT_DEF(POWER6_EXT, 0x00000001, 0, REG_HWCAP, 9)
74 FEAT_DEF(DFP, 0x00000001, 0, REG_HWCAP, 10)
75 FEAT_DEF(PA6T, 0x00000001, 0, REG_HWCAP, 11)
76 FEAT_DEF(ARCH_2_05, 0x00000001, 0, REG_HWCAP, 12)
77 FEAT_DEF(ICACHE_SNOOP, 0x00000001, 0, REG_HWCAP, 13)
78 FEAT_DEF(SMT, 0x00000001, 0, REG_HWCAP, 14)
79 FEAT_DEF(BOOKE, 0x00000001, 0, REG_HWCAP, 15)
80 FEAT_DEF(CELLBE, 0x00000001, 0, REG_HWCAP, 16)
81 FEAT_DEF(POWER5_PLUS, 0x00000001, 0, REG_HWCAP, 17)
82 FEAT_DEF(POWER5, 0x00000001, 0, REG_HWCAP, 18)
83 FEAT_DEF(POWER4, 0x00000001, 0, REG_HWCAP, 19)
84 FEAT_DEF(NOTB, 0x00000001, 0, REG_HWCAP, 20)
85 FEAT_DEF(EFP_DOUBLE, 0x00000001, 0, REG_HWCAP, 21)
86 FEAT_DEF(EFP_SINGLE, 0x00000001, 0, REG_HWCAP, 22)
87 FEAT_DEF(SPE, 0x00000001, 0, REG_HWCAP, 23)
88 FEAT_DEF(UNIFIED_CACHE, 0x00000001, 0, REG_HWCAP, 24)
89 FEAT_DEF(4xxMAC, 0x00000001, 0, REG_HWCAP, 25)
90 FEAT_DEF(MMU, 0x00000001, 0, REG_HWCAP, 26)
91 FEAT_DEF(FPU, 0x00000001, 0, REG_HWCAP, 27)
92 FEAT_DEF(ALTIVEC, 0x00000001, 0, REG_HWCAP, 28)
93 FEAT_DEF(PPC601, 0x00000001, 0, REG_HWCAP, 29)
94 FEAT_DEF(PPC64, 0x00000001, 0, REG_HWCAP, 30)
95 FEAT_DEF(PPC32, 0x00000001, 0, REG_HWCAP, 31)
96 FEAT_DEF(TAR, 0x00000001, 0, REG_HWCAP2, 26)
97 FEAT_DEF(LSEL, 0x00000001, 0, REG_HWCAP2, 27)
98 FEAT_DEF(EBB, 0x00000001, 0, REG_HWCAP2, 28)
99 FEAT_DEF(DSCR, 0x00000001, 0, REG_HWCAP2, 29)
100 FEAT_DEF(HTM, 0x00000001, 0, REG_HWCAP2, 30)
101 FEAT_DEF(ARCH_2_07, 0x00000001, 0, REG_HWCAP2, 31)
105 * Read AUXV software register and get cpu features for Power
108 rte_cpu_get_features(__attribute__((unused)) uint32_t leaf,
109 __attribute__((unused)) uint32_t subleaf, cpuid_registers_t out)
114 auxv_fd = open("/proc/self/auxv", O_RDONLY);
116 while (read(auxv_fd, &auxv,
117 sizeof(Elf64_auxv_t)) == sizeof(Elf64_auxv_t)) {
118 if (auxv.a_type == AT_HWCAP)
119 out[REG_HWCAP] = auxv.a_un.a_val;
120 else if (auxv.a_type == AT_HWCAP2)
121 out[REG_HWCAP2] = auxv.a_un.a_val;
126 * Checks if a particular flag is available on current machine.
129 rte_cpu_get_flag_enabled(enum rte_cpu_flag_t feature)
131 const struct feature_entry *feat;
132 cpuid_registers_t regs = {0};
134 if (feature >= RTE_CPUFLAG_NUMFLAGS)
135 /* Flag does not match anything in the feature tables */
138 feat = &rte_cpu_feature_table[feature];
141 /* This entry in the table wasn't filled out! */
144 /* get the cpuid leaf containing the desired feature */
145 rte_cpu_get_features(feat->leaf, feat->subleaf, regs);
147 /* check if the feature is enabled */
148 return (regs[feat->reg] >> feat->bit) & 1;
152 rte_cpu_get_flag_name(enum rte_cpu_flag_t feature)
154 if (feature >= RTE_CPUFLAG_NUMFLAGS)
156 return rte_cpu_feature_table[feature].name;