1 // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
2 /*
3 * Copyright 2019 IBM Corp.
4 */
5
6 #include <skiboot.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <stdbool.h>
10
11 /* Override this for testing. */
12 #define is_rodata(p) fake_is_rodata(p)
13
14 char __rodata_start[16];
15 #define __rodata_end (__rodata_start + sizeof(__rodata_start))
16
fake_is_rodata(const void * p)17 static inline bool fake_is_rodata(const void *p)
18 {
19 return ((char *)p >= __rodata_start && (char *)p < __rodata_end);
20 }
21
22 #define zalloc(bytes) calloc((bytes), 1)
23
24 #include "../device.c"
25 #include <assert.h>
26 #include "../../test/dt_common.c"
27
28 #define __TEST__
29
30 static inline unsigned long mfspr(unsigned int spr);
31
32 #include <ccan/str/str.c>
33
34 #include "../cpufeatures.c"
35
36 static unsigned long fake_pvr = PVR_TYPE_P8;
37
mfspr(unsigned int spr)38 static inline unsigned long mfspr(unsigned int spr)
39 {
40 assert(spr == SPR_PVR);
41 return fake_pvr;
42 }
43
main(void)44 int main(void)
45 {
46 struct dt_node *dt_root;
47
48 dt_root = dt_new_root("");
49 dt_add_cpufeatures(dt_root);
50 dump_dt(dt_root, 0, true);
51 dt_free(dt_root);
52
53 fake_pvr = (PVR_TYPE_P8E << 16) | 0x100; // P8E DD1.0
54 dt_root = dt_new_root("");
55 dt_add_cpufeatures(dt_root);
56 dump_dt(dt_root, 0, false);
57 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix") == 0);
58 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
59 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
60 dt_free(dt_root);
61
62 fake_pvr = (PVR_TYPE_P8E << 16) | 0x200; // P8E DD2.0
63 dt_root = dt_new_root("");
64 dt_add_cpufeatures(dt_root);
65 dump_dt(dt_root, 0, false);
66 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix") == 0);
67 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
68 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
69 dt_free(dt_root);
70
71 fake_pvr = (PVR_TYPE_P8 << 16) | 0x100; // P8 DD1.0
72 dt_root = dt_new_root("");
73 dt_add_cpufeatures(dt_root);
74 dump_dt(dt_root, 0, false);
75 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix") == 0);
76 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
77 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
78 dt_free(dt_root);
79
80 fake_pvr = (PVR_TYPE_P8 << 16) | 0x200; // P8 DD2.0
81 dt_root = dt_new_root("");
82 dt_add_cpufeatures(dt_root);
83 dump_dt(dt_root, 0, false);
84 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix") == 0);
85 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
86 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
87 dt_free(dt_root);
88
89 fake_pvr = (PVR_TYPE_P8NVL << 16) | 0x100; // P8NVL DD1.0
90 dt_root = dt_new_root("");
91 dt_add_cpufeatures(dt_root);
92 dump_dt(dt_root, 0, false);
93 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix") == 0);
94 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
95 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
96 dt_free(dt_root);
97
98 fake_pvr = (PVR_TYPE_P9 << 16) | 0x200; // P9 DD2.0
99 dt_root = dt_new_root("");
100 dt_add_cpufeatures(dt_root);
101 dump_dt(dt_root, 0, false);
102 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix"));
103 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
104 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
105 dt_free(dt_root);
106
107 fake_pvr = (PVR_TYPE_P9 << 16) | 0x201; // P9 DD2.1
108 dt_root = dt_new_root("");
109 dt_add_cpufeatures(dt_root);
110 dump_dt(dt_root, 0, false);
111 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix"));
112 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
113 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
114 dt_free(dt_root);
115
116 fake_pvr = (PVR_TYPE_P9 << 16) | 0x202; // P9 DD2.2
117 dt_root = dt_new_root("");
118 dt_add_cpufeatures(dt_root);
119 dump_dt(dt_root, 0, false);
120 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix"));
121 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") != 0);
122 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") != 0);
123 dt_free(dt_root);
124
125 fake_pvr = (PVR_TYPE_P9 << 16) | 0x203; // P9 DD2.3
126 dt_root = dt_new_root("");
127 dt_add_cpufeatures(dt_root);
128 dump_dt(dt_root, 0, false);
129 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix"));
130 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") != 0);
131 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
132 dt_free(dt_root);
133
134 fake_pvr = (PVR_TYPE_P9P << 16) | 0x100; // P9P DD1.0
135 dt_root = dt_new_root("");
136 dt_add_cpufeatures(dt_root);
137 dump_dt(dt_root, 0, false);
138 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix"));
139 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") != 0);
140 assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
141 dt_free(dt_root);
142
143 exit(EXIT_SUCCESS);
144 }
145