blob: 35f0020b7ba77827fc08a503d8f58f5a6a17844e [file] [log] [blame]
Hendrik Brueckner212188a2012-03-23 11:13:06 +01001/*
2 * CPU-measurement facilities
3 *
4 * Copyright IBM Corp. 2012
5 * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
6 * Jan Glauber <jang@linux.vnet.ibm.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License (version 2 only)
10 * as published by the Free Software Foundation.
11 */
Jan Glauberb03d541a2012-03-23 11:13:05 +010012#ifndef _ASM_S390_CPU_MF_H
13#define _ASM_S390_CPU_MF_H
14
Heiko Carstens1e3cab22012-03-30 09:40:55 +020015#include <asm/facility.h>
16
Jan Glauberb03d541a2012-03-23 11:13:05 +010017#define CPU_MF_INT_SF_IAE (1 << 31) /* invalid entry address */
18#define CPU_MF_INT_SF_ISE (1 << 30) /* incorrect SDBT entry */
19#define CPU_MF_INT_SF_PRA (1 << 29) /* program request alert */
20#define CPU_MF_INT_SF_SACA (1 << 23) /* sampler auth. change alert */
21#define CPU_MF_INT_SF_LSDA (1 << 22) /* loss of sample data alert */
Hendrik Brueckner212188a2012-03-23 11:13:06 +010022#define CPU_MF_INT_CF_CACA (1 << 7) /* counter auth. change alert */
23#define CPU_MF_INT_CF_LCDA (1 << 6) /* loss of counter data alert */
Jan Glaubere4b8b3f2012-07-31 10:52:05 +020024#define CPU_MF_INT_RI_HALTED (1 << 5) /* run-time instr. halted */
25#define CPU_MF_INT_RI_BUF_FULL (1 << 4) /* run-time instr. program
26 buffer full */
Jan Glauberb03d541a2012-03-23 11:13:05 +010027
Hendrik Brueckner212188a2012-03-23 11:13:06 +010028#define CPU_MF_INT_CF_MASK (CPU_MF_INT_CF_CACA|CPU_MF_INT_CF_LCDA)
29#define CPU_MF_INT_SF_MASK (CPU_MF_INT_SF_IAE|CPU_MF_INT_SF_ISE| \
30 CPU_MF_INT_SF_PRA|CPU_MF_INT_SF_SACA| \
31 CPU_MF_INT_SF_LSDA)
Jan Glaubere4b8b3f2012-07-31 10:52:05 +020032#define CPU_MF_INT_RI_MASK (CPU_MF_INT_RI_HALTED|CPU_MF_INT_RI_BUF_FULL)
Hendrik Brueckner212188a2012-03-23 11:13:06 +010033
34/* CPU measurement facility support */
35static inline int cpum_cf_avail(void)
36{
37 return MACHINE_HAS_SPP && test_facility(67);
38}
39
40static inline int cpum_sf_avail(void)
41{
42 return MACHINE_HAS_SPP && test_facility(68);
43}
44
45
46struct cpumf_ctr_info {
47 u16 cfvn;
48 u16 auth_ctl;
49 u16 enable_ctl;
50 u16 act_ctl;
51 u16 max_cpu;
52 u16 csvn;
53 u16 max_cg;
54 u16 reserved1;
55 u32 reserved2[12];
56} __packed;
57
58/* Query counter information */
59static inline int qctri(struct cpumf_ctr_info *info)
60{
61 int rc = -EINVAL;
62
63 asm volatile (
64 "0: .insn s,0xb28e0000,%1\n"
65 "1: lhi %0,0\n"
66 "2:\n"
67 EX_TABLE(1b, 2b)
68 : "+d" (rc), "=Q" (*info));
69 return rc;
70}
71
72/* Load CPU-counter-set controls */
73static inline int lcctl(u64 ctl)
74{
75 int cc;
76
77 asm volatile (
78 " .insn s,0xb2840000,%1\n"
79 " ipm %0\n"
80 " srl %0,28\n"
81 : "=d" (cc) : "m" (ctl) : "cc");
82 return cc;
83}
84
85/* Extract CPU counter */
86static inline int ecctr(u64 ctr, u64 *val)
87{
88 register u64 content asm("4") = 0;
89 int cc;
90
91 asm volatile (
92 " .insn rre,0xb2e40000,%0,%2\n"
93 " ipm %1\n"
94 " srl %1,28\n"
95 : "=d" (content), "=d" (cc) : "d" (ctr) : "cc");
96 if (!cc)
97 *val = content;
98 return cc;
99}
100
101#endif /* _ASM_S390_CPU_MF_H */