1 // SPDX-License-Identifier: GPL-2.0+
11 static unsigned int dexcr;
12 static unsigned int hdexcr;
13 static unsigned int effective;
21 static const struct dexcr_aspect aspects[] = {
24 .desc = "Speculative branch hint enable",
29 .desc = "Indirect branch recurrent target prediction disable",
34 .desc = "Subroutine return address prediction disable",
39 .desc = "Non-privileged hash instruction enable",
44 .desc = "Privileged hash instruction enable",
49 static void print_list(const char *list[], size_t len)
51 for (size_t i = 0; i < len; i++) {
52 printf("%s", list[i]);
58 static void print_dexcr(char *name, unsigned int bits)
60 const char *enabled_aspects[ARRAY_SIZE(aspects) + 1] = {NULL};
63 printf("%s: %08x", name, bits);
70 for (size_t i = 0; i < ARRAY_SIZE(aspects); i++) {
71 unsigned int mask = DEXCR_PR_BIT(aspects[i].index);
74 enabled_aspects[j++] = aspects[i].name;
80 enabled_aspects[j++] = "unknown";
83 print_list(enabled_aspects, j);
87 static void print_aspect(const struct dexcr_aspect *aspect)
89 const char *attributes[8] = {NULL};
93 mask = DEXCR_PR_BIT(aspect->index);
95 attributes[j++] = "set";
97 attributes[j++] = "set (hypervisor)";
98 if (!(effective & mask))
99 attributes[j++] = "clear";
101 printf("%12s %c (%d): ", aspect->name, effective & mask ? '*' : ' ', aspect->index);
102 print_list(attributes, j);
103 printf(" \t(%s)\n", aspect->desc);
106 int main(int argc, char *argv[])
108 if (!dexcr_exists()) {
109 printf("DEXCR not detected on this hardware\n");
113 dexcr = get_dexcr(DEXCR);
114 hdexcr = get_dexcr(HDEXCR);
115 effective = dexcr | hdexcr;
117 print_dexcr(" DEXCR", dexcr);
118 print_dexcr(" HDEXCR", hdexcr);
119 print_dexcr("Effective", effective);
122 for (size_t i = 0; i < ARRAY_SIZE(aspects); i++)
123 print_aspect(&aspects[i]);
126 if (effective & DEXCR_PR_NPHIE) {
127 printf("DEXCR[NPHIE] enabled: hashst/hashchk ");
128 if (hashchk_triggers())
131 printf("failed to trigger\n");
133 printf("DEXCR[NPHIE] disabled: hashst/hashchk ");
134 if (hashchk_triggers())
135 printf("unexpectedly triggered\n");