Skip to content

Commit 5a61ef7

Browse files
npigginmpe
authored andcommitted
powerpc/64s: Support new device tree binding for discovering CPU features
The ibm,powerpc-cpu-features device tree binding describes CPU features with ASCII names and extensible compatibility, privilege, and enablement metadata that allows improved flexibility and compatibility with new hardware. The interface is described in detail in ibm,powerpc-cpu-features.txt in this patch. Currently this code is not enabled by default, and there are no released firmwares that provide the binding. Signed-off-by: Nicholas Piggin <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 75bda95 commit 5a61ef7

File tree

12 files changed

+1398
-16
lines changed

12 files changed

+1398
-16
lines changed
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
*** NOTE ***
2+
This document is copied from OPAL firmware
3+
(skiboot/doc/device-tree/ibm,powerpc-cpu-features/binding.txt)
4+
5+
There is more complete overview and documentation of features in that
6+
source tree. All patches and modifications should go there.
7+
************
8+
9+
ibm,powerpc-cpu-features binding
10+
================================
11+
12+
This device tree binding describes CPU features available to software, with
13+
enablement, privilege, and compatibility metadata.
14+
15+
More general description of design and implementation of this binding is
16+
found in design.txt, which also points to documentation of specific features.
17+
18+
19+
/cpus/ibm,powerpc-cpu-features node binding
20+
-------------------------------------------
21+
22+
Node: ibm,powerpc-cpu-features
23+
24+
Description: Container of CPU feature nodes.
25+
26+
The node name must be "ibm,powerpc-cpu-features".
27+
28+
It is implemented as a child of the node "/cpus", but this must not be
29+
assumed by parsers.
30+
31+
The node is optional but should be provided by new OPAL firmware.
32+
33+
Properties:
34+
35+
- compatible
36+
Usage: required
37+
Value type: string
38+
Definition: "ibm,powerpc-cpu-features"
39+
40+
This compatibility refers to backwards compatibility of the overall
41+
design with parsers that behave according to these guidelines. This can
42+
be extended in a backward compatible manner which would not warrant a
43+
revision of the compatible property.
44+
45+
- isa
46+
Usage: required
47+
Value type: <u32>
48+
Definition:
49+
50+
isa that the CPU is currently running in. This provides instruction set
51+
compatibility, less the individual feature nodes. For example, an ISA v3.0
52+
implementation that lacks the "transactional-memory" cpufeature node
53+
should not use transactional memory facilities.
54+
55+
Value corresponds to the "Power ISA Version" multiplied by 1000.
56+
For example, <3000> corresponds to Version 3.0, <2070> to Version 2.07.
57+
The minor digit is available for revisions.
58+
59+
- display-name
60+
Usage: optional
61+
Value type: string
62+
Definition:
63+
64+
A human readable name for the CPU.
65+
66+
/cpus/ibm,powerpc-cpu-features/example-feature node bindings
67+
----------------------------------------------------------------
68+
69+
Each child node of cpu-features represents a CPU feature / capability.
70+
71+
Node: A string describing an architected CPU feature, e.g., "floating-point".
72+
73+
Description: A feature or capability supported by the CPUs.
74+
75+
The name of the node is a human readable string that forms the interface
76+
used to describe features to software. Features are currently documented
77+
in the code where they are implemented in skiboot/core/cpufeatures.c
78+
79+
Presence of the node indicates the feature is available.
80+
81+
Properties:
82+
83+
- isa
84+
Usage: required
85+
Value type: <u32>
86+
Definition:
87+
88+
First level of the Power ISA that the feature appears in.
89+
Software should filter out features when constraining the
90+
environment to a particular ISA version.
91+
92+
Value is defined similarly to /cpus/features/isa
93+
94+
- usable-privilege
95+
Usage: required
96+
Value type: <u32> bit mask
97+
Definition:
98+
Bit numbers are LSB0
99+
bit 0 - PR (problem state / user mode)
100+
bit 1 - OS (privileged state)
101+
bit 2 - HV (hypervisor state)
102+
All other bits reserved and should be zero.
103+
104+
This property describes the privilege levels and/or software components
105+
that can use the feature.
106+
107+
If bit 0 is set, then the hwcap-bit-nr property will exist.
108+
109+
110+
- hv-support
111+
Usage: optional
112+
Value type: <u32> bit mask
113+
Definition:
114+
Bit numbers are LSB0
115+
bit 0 - HFSCR
116+
All other bits reserved and should be zero.
117+
118+
This property describes the HV privilege support required to enable the
119+
feature to lesser privilege levels. If the property does not exist then no
120+
support is required.
121+
122+
If no bits are set, the hypervisor must have explicit/custom support for
123+
this feature.
124+
125+
If the HFSCR bit is set, then the hfscr-bit-nr property will exist and
126+
the feature may be enabled by setting this bit in the HFSCR register.
127+
128+
129+
- os-support
130+
Usage: optional
131+
Value type: <u32> bit mask
132+
Definition:
133+
Bit numbers are LSB0
134+
bit 0 - FSCR
135+
All other bits reserved and should be zero.
136+
137+
This property describes the OS privilege support required to enable the
138+
feature to lesser privilege levels. If the property does not exist then no
139+
support is required.
140+
141+
If no bits are set, the operating system must have explicit/custom support
142+
for this feature.
143+
144+
If the FSCR bit is set, then the fscr-bit-nr property will exist and
145+
the feature may be enabled by setting this bit in the FSCR register.
146+
147+
148+
- hfscr-bit-nr
149+
Usage: optional
150+
Value type: <u32>
151+
Definition: HFSCR bit position (LSB0)
152+
153+
This property exists when the hv-support property HFSCR bit is set. This
154+
property describes the bit number in the HFSCR register that the
155+
hypervisor must set in order to enable this feature.
156+
157+
This property also exists if an HFSCR bit corresponds with this feature.
158+
This makes CPU feature parsing slightly simpler.
159+
160+
161+
- fscr-bit-nr
162+
Usage: optional
163+
Value type: <u32>
164+
Definition: FSCR bit position (LSB0)
165+
166+
This property exists when the os-support property FSCR bit is set. This
167+
property describes the bit number in the FSCR register that the
168+
operating system must set in order to enable this feature.
169+
170+
This property also exists if an FSCR bit corresponds with this feature.
171+
This makes CPU feature parsing slightly simpler.
172+
173+
174+
- hwcap-bit-nr
175+
Usage: optional
176+
Value type: <u32>
177+
Definition: Linux ELF AUX vector bit position (LSB0)
178+
179+
This property may exist when the usable-privilege property value has PR bit set.
180+
This property describes the bit number that should be set in the ELF AUX
181+
hardware capability vectors in order to advertise this feature to userspace.
182+
Bits 0-31 correspond to bits 0-31 in AT_HWCAP vector. Bits 32-63 correspond
183+
to 0-31 in AT_HWCAP2 vector, and so on. Missing AT_HWCAPx vectors implies
184+
that the feature is not enabled or can not be advertised. Operating systems
185+
may provide a number of unassigned hardware capability bits to allow for new
186+
features to be advertised.
187+
188+
Some properties representing features created before this binding are
189+
advertised to userspace without a one-to-one hwcap bit number may not specify
190+
this bit. Operating system will handle those bits specifically. All new
191+
features usable by userspace will have a hwcap-bit-nr property.
192+
193+
194+
- dependencies
195+
Usage: optional
196+
Value type: <prop-encoded-array>
197+
Definition:
198+
199+
If this property exists then it is a list of phandles to cpu feature
200+
nodes that must be enabled for this feature to be enabled.
201+
202+
203+
Example
204+
-------
205+
206+
/cpus/ibm,powerpc-cpu-features {
207+
compatible = "ibm,powerpc-cpu-features";
208+
209+
isa = <3020>;
210+
211+
darn {
212+
isa = <3000>;
213+
usable-privilege = <1 | 2 | 4>;
214+
hwcap-bit-nr = <xx>;
215+
};
216+
217+
scv {
218+
isa = <3000>;
219+
usable-privilege = <1 | 2>;
220+
os-support = <0>;
221+
hwcap-bit-nr = <xx>;
222+
};
223+
224+
stop {
225+
isa = <3000>;
226+
usable-privilege = <2 | 4>;
227+
hv-support = <0>;
228+
os-support = <0>;
229+
};
230+
231+
vsx2 (hypothetical) {
232+
isa = <3010>;
233+
usable-privilege = <1 | 2 | 4>;
234+
hv-support = <0>;
235+
os-support = <0>;
236+
hwcap-bit-nr = <xx>;
237+
};
238+
239+
vsx2-newinsns {
240+
isa = <3020>;
241+
usable-privilege = <1 | 2 | 4>;
242+
os-support = <1>;
243+
fscr-bit-nr = <xx>;
244+
hwcap-bit-nr = <xx>;
245+
dependencies = <&vsx2>;
246+
};
247+
248+
};

arch/powerpc/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,22 @@ source "arch/powerpc/platforms/Kconfig"
380380

381381
menu "Kernel options"
382382

383+
config PPC_DT_CPU_FTRS
384+
bool "Device-tree based CPU feature discovery & setup"
385+
depends on PPC_BOOK3S_64
386+
default n
387+
help
388+
This enables code to use a new device tree binding for describing CPU
389+
compatibility and features. Saying Y here will attempt to use the new
390+
binding if the firmware provides it. Currently only the skiboot
391+
firmware provides this binding.
392+
If you're not sure say Y.
393+
394+
config PPC_CPUFEATURES_ENABLE_UNKNOWN
395+
bool "cpufeatures pass through unknown features to guest/userspace"
396+
depends on PPC_DT_CPU_FTRS
397+
default y
398+
383399
config HIGHMEM
384400
bool "High memory support"
385401
depends on PPC32

arch/powerpc/include/asm/cpu_has_feature.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef __ASM_POWERPC_CPUFEATURES_H
2-
#define __ASM_POWERPC_CPUFEATURES_H
1+
#ifndef __ASM_POWERPC_CPU_HAS_FEATURE_H
2+
#define __ASM_POWERPC_CPU_HAS_FEATURE_H
33

44
#ifndef __ASSEMBLY__
55

@@ -52,4 +52,4 @@ static inline bool cpu_has_feature(unsigned long feature)
5252
#endif
5353

5454
#endif /* __ASSEMBLY__ */
55-
#endif /* __ASM_POWERPC_CPUFEATURE_H */
55+
#endif /* __ASM_POWERPC_CPU_HAS_FEATURE_H */

arch/powerpc/include/asm/cputable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ extern struct cpu_spec *cur_cpu_spec;
118118

119119
extern unsigned int __start___ftr_fixup, __stop___ftr_fixup;
120120

121+
extern void set_cur_cpu_spec(struct cpu_spec *s);
121122
extern struct cpu_spec *identify_cpu(unsigned long offset, unsigned int pvr);
123+
extern void identify_cpu_name(unsigned int pvr);
122124
extern void do_feature_fixups(unsigned long value, void *fixup_start,
123125
void *fixup_end);
124126

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef __ASM_POWERPC_DT_CPU_FTRS_H
2+
#define __ASM_POWERPC_DT_CPU_FTRS_H
3+
4+
/*
5+
* Copyright 2017, IBM Corporation
6+
* cpufeatures is the new way to discover CPU features with /cpus/features
7+
* devicetree. This supersedes PVR based discovery ("cputable"), and older
8+
* device tree feature advertisement.
9+
*/
10+
11+
#include <linux/types.h>
12+
#include <asm/asm-compat.h>
13+
#include <asm/feature-fixups.h>
14+
#include <uapi/asm/cputable.h>
15+
16+
#ifdef CONFIG_PPC_DT_CPU_FTRS
17+
bool dt_cpu_ftrs_init(void *fdt);
18+
void dt_cpu_ftrs_scan(void);
19+
bool dt_cpu_ftrs_in_use(void);
20+
#else
21+
static inline bool dt_cpu_ftrs_init(void *fdt) { return false; }
22+
static inline void dt_cpu_ftrs_scan(void) { }
23+
static inline bool dt_cpu_ftrs_in_use(void) { return false; }
24+
#endif
25+
26+
#endif /* __ASM_POWERPC_DT_CPU_FTRS_H */

arch/powerpc/include/asm/reg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,7 @@
12291229
#define PVR_POWER8E 0x004B
12301230
#define PVR_POWER8NVL 0x004C
12311231
#define PVR_POWER8 0x004D
1232+
#define PVR_POWER9 0x004E
12321233
#define PVR_BE 0x0070
12331234
#define PVR_PA6T 0x0090
12341235

arch/powerpc/include/uapi/asm/cputable.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,11 @@
4747
#define PPC_FEATURE2_ARCH_3_00 0x00800000 /* ISA 3.00 */
4848
#define PPC_FEATURE2_HAS_IEEE128 0x00400000 /* VSX IEEE Binary Float 128-bit */
4949

50+
/*
51+
* IMPORTANT!
52+
* All future PPC_FEATURE definitions should be allocated in cooperation with
53+
* OPAL / skiboot firmware, in accordance with the ibm,powerpc-cpu-features
54+
* device tree binding.
55+
*/
56+
5057
#endif /* _UAPI__ASM_POWERPC_CPUTABLE_H */

arch/powerpc/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ obj-$(CONFIG_PPC_RTAS) += rtas.o rtas-rtc.o $(rtaspci-y-y)
5656
obj-$(CONFIG_PPC_RTAS_DAEMON) += rtasd.o
5757
obj-$(CONFIG_RTAS_FLASH) += rtas_flash.o
5858
obj-$(CONFIG_RTAS_PROC) += rtas-proc.o
59+
obj-$(CONFIG_PPC_DT_CPU_FTRS) += dt_cpu_ftrs.o
5960
obj-$(CONFIG_EEH) += eeh.o eeh_pe.o eeh_dev.o eeh_cache.o \
6061
eeh_driver.o eeh_event.o eeh_sysfs.o
6162
obj-$(CONFIG_GENERIC_TBSYNC) += smp-tbsync.o

0 commit comments

Comments
 (0)