1
2
3
4
5
6
7
8
9
10
11
12#ifndef _ASM_S390_CPU_MF_H
13#define _ASM_S390_CPU_MF_H
14
15#include <linux/errno.h>
16#include <asm/facility.h>
17
18#define CPU_MF_INT_SF_IAE (1 << 31)
19#define CPU_MF_INT_SF_ISE (1 << 30)
20#define CPU_MF_INT_SF_PRA (1 << 29)
21#define CPU_MF_INT_SF_SACA (1 << 23)
22#define CPU_MF_INT_SF_LSDA (1 << 22)
23#define CPU_MF_INT_CF_CACA (1 << 7)
24#define CPU_MF_INT_CF_LCDA (1 << 6)
25#define CPU_MF_INT_RI_HALTED (1 << 5)
26#define CPU_MF_INT_RI_BUF_FULL (1 << 4)
27
28
29#define CPU_MF_INT_CF_MASK (CPU_MF_INT_CF_CACA|CPU_MF_INT_CF_LCDA)
30#define CPU_MF_INT_SF_MASK (CPU_MF_INT_SF_IAE|CPU_MF_INT_SF_ISE| \
31 CPU_MF_INT_SF_PRA|CPU_MF_INT_SF_SACA| \
32 CPU_MF_INT_SF_LSDA)
33#define CPU_MF_INT_RI_MASK (CPU_MF_INT_RI_HALTED|CPU_MF_INT_RI_BUF_FULL)
34
35
36static inline int cpum_cf_avail(void)
37{
38 return MACHINE_HAS_LPP && test_facility(67);
39}
40
41static inline int cpum_sf_avail(void)
42{
43 return MACHINE_HAS_LPP && test_facility(68);
44}
45
46
47struct cpumf_ctr_info {
48 u16 cfvn;
49 u16 auth_ctl;
50 u16 enable_ctl;
51 u16 act_ctl;
52 u16 max_cpu;
53 u16 csvn;
54 u16 max_cg;
55 u16 reserved1;
56 u32 reserved2[12];
57} __packed;
58
59
60struct hws_qsi_info_block {
61 unsigned int b0_13:14;
62 unsigned int as:1;
63 unsigned int ad:1;
64 unsigned int b16_21:6;
65 unsigned int es:1;
66 unsigned int ed:1;
67 unsigned int b24_29:6;
68 unsigned int cs:1;
69 unsigned int cd:1;
70 unsigned int bsdes:16;
71 unsigned int dsdes:16;
72 unsigned long min_sampl_rate;
73 unsigned long max_sampl_rate;
74 unsigned long tear;
75 unsigned long dear;
76 unsigned int rsvrd0;
77 unsigned int cpu_speed;
78 unsigned long long rsvrd1;
79 unsigned long long rsvrd2;
80} __packed;
81
82
83struct hws_lsctl_request_block {
84 unsigned int s:1;
85 unsigned int h:1;
86 unsigned long long b2_53:52;
87 unsigned int es:1;
88 unsigned int ed:1;
89 unsigned int b56_61:6;
90 unsigned int cs:1;
91 unsigned int cd:1;
92 unsigned long interval;
93 unsigned long tear;
94 unsigned long dear;
95
96 unsigned long rsvrd1;
97 unsigned long rsvrd2;
98 unsigned long rsvrd3;
99 unsigned long rsvrd4;
100} __packed;
101
102struct hws_basic_entry {
103 unsigned int def:16;
104 unsigned int R:4;
105 unsigned int U:4;
106 unsigned int z:2;
107 unsigned int T:1;
108 unsigned int W:1;
109 unsigned int P:1;
110 unsigned int AS:2;
111 unsigned int I:1;
112 unsigned int:16;
113 unsigned int prim_asn:16;
114 unsigned long long ia;
115 unsigned long long gpp;
116 unsigned long long hpp;
117} __packed;
118
119struct hws_diag_entry {
120 unsigned int def:16;
121 unsigned int R:14;
122 unsigned int I:1;
123 u8 data[];
124} __packed;
125
126struct hws_combined_entry {
127 struct hws_basic_entry basic;
128 struct hws_diag_entry diag;
129} __packed;
130
131struct hws_trailer_entry {
132 unsigned int f:1;
133 unsigned int a:1;
134 unsigned int t:1;
135 unsigned long long:61;
136 unsigned long long overflow;
137 unsigned char timestamp[16];
138 unsigned long long reserved1;
139 unsigned long long reserved2;
140 unsigned long long progusage1;
141 unsigned long long progusage2;
142} __packed;
143
144
145static inline int qctri(struct cpumf_ctr_info *info)
146{
147 int rc = -EINVAL;
148
149 asm volatile (
150 "0: .insn s,0xb28e0000,%1\n"
151 "1: lhi %0,0\n"
152 "2:\n"
153 EX_TABLE(1b, 2b)
154 : "+d" (rc), "=Q" (*info));
155 return rc;
156}
157
158
159static inline int lcctl(u64 ctl)
160{
161 int cc;
162
163 asm volatile (
164 " .insn s,0xb2840000,%1\n"
165 " ipm %0\n"
166 " srl %0,28\n"
167 : "=d" (cc) : "m" (ctl) : "cc");
168 return cc;
169}
170
171
172static inline int ecctr(u64 ctr, u64 *val)
173{
174 register u64 content asm("4") = 0;
175 int cc;
176
177 asm volatile (
178 " .insn rre,0xb2e40000,%0,%2\n"
179 " ipm %1\n"
180 " srl %1,28\n"
181 : "=d" (content), "=d" (cc) : "d" (ctr) : "cc");
182 if (!cc)
183 *val = content;
184 return cc;
185}
186
187
188static inline int stcctm5(u64 num, u64 *val)
189{
190 typedef struct { u64 _[num]; } addrtype;
191 int cc;
192
193 asm volatile (
194 " .insn rsy,0xeb0000000017,%2,5,%1\n"
195 " ipm %0\n"
196 " srl %0,28\n"
197 : "=d" (cc), "=Q" (*(addrtype *) val) : "d" (num) : "cc");
198 return cc;
199}
200
201
202static inline int qsi(struct hws_qsi_info_block *info)
203{
204 int cc;
205 cc = 1;
206
207 asm volatile(
208 "0: .insn s,0xb2860000,0(%1)\n"
209 "1: lhi %0,0\n"
210 "2:\n"
211 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
212 : "=d" (cc), "+a" (info)
213 : "m" (*info)
214 : "cc", "memory");
215
216 return cc ? -EINVAL : 0;
217}
218
219
220static inline int lsctl(struct hws_lsctl_request_block *req)
221{
222 int cc;
223
224 cc = 1;
225 asm volatile(
226 "0: .insn s,0xb2870000,0(%1)\n"
227 "1: ipm %0\n"
228 " srl %0,28\n"
229 "2:\n"
230 EX_TABLE(0b, 2b) EX_TABLE(1b, 2b)
231 : "+d" (cc), "+a" (req)
232 : "m" (*req)
233 : "cc", "memory");
234
235 return cc ? -EINVAL : 0;
236}
237
238
239
240#include <linux/time.h>
241
242static inline unsigned long freq_to_sample_rate(struct hws_qsi_info_block *qsi,
243 unsigned long freq)
244{
245 return (USEC_PER_SEC / freq) * qsi->cpu_speed;
246}
247
248static inline unsigned long sample_rate_to_freq(struct hws_qsi_info_block *qsi,
249 unsigned long rate)
250{
251 return USEC_PER_SEC * qsi->cpu_speed / rate;
252}
253
254#define SDB_TE_ALERT_REQ_MASK 0x4000000000000000UL
255#define SDB_TE_BUFFER_FULL_MASK 0x8000000000000000UL
256
257
258static inline unsigned long long trailer_timestamp(struct hws_trailer_entry *te)
259{
260
261 if (te->t)
262 return *((unsigned long long *) &te->timestamp[1]);
263
264
265 return *((unsigned long long *) &te->timestamp[0]);
266}
267
268
269static inline unsigned long *trailer_entry_ptr(unsigned long v)
270{
271 void *ret;
272
273 ret = (void *) v;
274 ret += PAGE_SIZE;
275 ret -= sizeof(struct hws_trailer_entry);
276
277 return (unsigned long *) ret;
278}
279
280
281
282static inline int is_link_entry(unsigned long *s)
283{
284 return *s & 0x1ul ? 1 : 0;
285}
286
287
288static inline unsigned long *get_next_sdbt(unsigned long *s)
289{
290 return (unsigned long *) (*s & ~0x1ul);
291}
292#endif
293