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