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 */
52 typedef uint32_t hwcap_registers_t[REG_MAX];
54 struct feature_entry {
57 #define CPU_FLAG_NAME_MAX_LEN 64
58 char name[CPU_FLAG_NAME_MAX_LEN];
61 #define FEAT_DEF(name, reg, bit) \
62 [RTE_CPUFLAG_##name] = {reg, bit, #name},
64 const struct feature_entry rte_cpu_feature_table[] = {
65 FEAT_DEF(PPC_LE, REG_HWCAP, 0)
66 FEAT_DEF(TRUE_LE, REG_HWCAP, 1)
67 FEAT_DEF(PSERIES_PERFMON_COMPAT, REG_HWCAP, 6)
68 FEAT_DEF(VSX, REG_HWCAP, 7)
69 FEAT_DEF(ARCH_2_06, REG_HWCAP, 8)
70 FEAT_DEF(POWER6_EXT, REG_HWCAP, 9)
71 FEAT_DEF(DFP, REG_HWCAP, 10)
72 FEAT_DEF(PA6T, REG_HWCAP, 11)
73 FEAT_DEF(ARCH_2_05, REG_HWCAP, 12)
74 FEAT_DEF(ICACHE_SNOOP, REG_HWCAP, 13)
75 FEAT_DEF(SMT, REG_HWCAP, 14)
76 FEAT_DEF(BOOKE, REG_HWCAP, 15)
77 FEAT_DEF(CELLBE, REG_HWCAP, 16)
78 FEAT_DEF(POWER5_PLUS, REG_HWCAP, 17)
79 FEAT_DEF(POWER5, REG_HWCAP, 18)
80 FEAT_DEF(POWER4, REG_HWCAP, 19)
81 FEAT_DEF(NOTB, REG_HWCAP, 20)
82 FEAT_DEF(EFP_DOUBLE, REG_HWCAP, 21)
83 FEAT_DEF(EFP_SINGLE, REG_HWCAP, 22)
84 FEAT_DEF(SPE, REG_HWCAP, 23)
85 FEAT_DEF(UNIFIED_CACHE, REG_HWCAP, 24)
86 FEAT_DEF(4xxMAC, REG_HWCAP, 25)
87 FEAT_DEF(MMU, REG_HWCAP, 26)
88 FEAT_DEF(FPU, REG_HWCAP, 27)
89 FEAT_DEF(ALTIVEC, REG_HWCAP, 28)
90 FEAT_DEF(PPC601, REG_HWCAP, 29)
91 FEAT_DEF(PPC64, REG_HWCAP, 30)
92 FEAT_DEF(PPC32, REG_HWCAP, 31)
93 FEAT_DEF(TAR, REG_HWCAP2, 26)
94 FEAT_DEF(LSEL, REG_HWCAP2, 27)
95 FEAT_DEF(EBB, REG_HWCAP2, 28)
96 FEAT_DEF(DSCR, REG_HWCAP2, 29)
97 FEAT_DEF(HTM, REG_HWCAP2, 30)
98 FEAT_DEF(ARCH_2_07, REG_HWCAP2, 31)
102 * Read AUXV software register and get cpu features for Power
105 rte_cpu_get_features(hwcap_registers_t out)
107 out[REG_HWCAP] = rte_cpu_getauxval(AT_HWCAP);
108 out[REG_HWCAP2] = rte_cpu_getauxval(AT_HWCAP2);
112 * Checks if a particular flag is available on current machine.
115 rte_cpu_get_flag_enabled(enum rte_cpu_flag_t feature)
117 const struct feature_entry *feat;
118 hwcap_registers_t regs = {0};
120 if (feature >= RTE_CPUFLAG_NUMFLAGS)
123 feat = &rte_cpu_feature_table[feature];
124 if (feat->reg == REG_NONE)
127 rte_cpu_get_features(regs);
128 return (regs[feat->reg] >> feat->bit) & 1;
132 rte_cpu_get_flag_name(enum rte_cpu_flag_t feature)
134 if (feature >= RTE_CPUFLAG_NUMFLAGS)
136 return rte_cpu_feature_table[feature].name;