blob: c879fad404c8d36d73aff75ea1174df65374061b [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
Li Zefancb16b912013-03-07 17:35:53 +080015#include <linux/errno.h>
Heiko Carstens1e3cab22012-03-30 09:40:55 +020016#include <asm/facility.h>
17
Jan Glauberb03d541a2012-03-23 11:13:05 +010018#define CPU_MF_INT_SF_IAE (1 << 31) /* invalid entry address */
19#define CPU_MF_INT_SF_ISE (1 << 30) /* incorrect SDBT entry */
20#define CPU_MF_INT_SF_PRA (1 << 29) /* program request alert */
21#define CPU_MF_INT_SF_SACA (1 << 23) /* sampler auth. change alert */
22#define CPU_MF_INT_SF_LSDA (1 << 22) /* loss of sample data alert */
Hendrik Brueckner212188a2012-03-23 11:13:06 +010023#define CPU_MF_INT_CF_CACA (1 << 7) /* counter auth. change alert */
24#define CPU_MF_INT_CF_LCDA (1 << 6) /* loss of counter data alert */
Jan Glaubere4b8b3f2012-07-31 10:52:05 +020025#define CPU_MF_INT_RI_HALTED (1 << 5) /* run-time instr. halted */
26#define CPU_MF_INT_RI_BUF_FULL (1 << 4) /* run-time instr. program
27 buffer full */
Jan Glauberb03d541a2012-03-23 11:13:05 +010028
Hendrik Brueckner212188a2012-03-23 11:13:06 +010029#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)
Jan Glaubere4b8b3f2012-07-31 10:52:05 +020033#define CPU_MF_INT_RI_MASK (CPU_MF_INT_RI_HALTED|CPU_MF_INT_RI_BUF_FULL)
Hendrik Brueckner212188a2012-03-23 11:13:06 +010034
35/* CPU measurement facility support */
36static inline int cpum_cf_avail(void)
37{
Hendrik Brueckner23d18e82013-02-11 18:11:09 +010038 return MACHINE_HAS_LPP && test_facility(67);
Hendrik Brueckner212188a2012-03-23 11:13:06 +010039}
40
41static inline int cpum_sf_avail(void)
42{
Hendrik Brueckner23d18e82013-02-11 18:11:09 +010043 return MACHINE_HAS_LPP && test_facility(68);
Hendrik Brueckner212188a2012-03-23 11:13:06 +010044}
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/* Query counter information */
60static inline int qctri(struct cpumf_ctr_info *info)
61{
62 int rc = -EINVAL;
63
64 asm volatile (
65 "0: .insn s,0xb28e0000,%1\n"
66 "1: lhi %0,0\n"
67 "2:\n"
68 EX_TABLE(1b, 2b)
69 : "+d" (rc), "=Q" (*info));
70 return rc;
71}
72
73/* Load CPU-counter-set controls */
74static inline int lcctl(u64 ctl)
75{
76 int cc;
77
78 asm volatile (
79 " .insn s,0xb2840000,%1\n"
80 " ipm %0\n"
81 " srl %0,28\n"
82 : "=d" (cc) : "m" (ctl) : "cc");
83 return cc;
84}
85
86/* Extract CPU counter */
87static inline int ecctr(u64 ctr, u64 *val)
88{
89 register u64 content asm("4") = 0;
90 int cc;
91
92 asm volatile (
93 " .insn rre,0xb2e40000,%0,%2\n"
94 " ipm %1\n"
95 " srl %1,28\n"
96 : "=d" (content), "=d" (cc) : "d" (ctr) : "cc");
97 if (!cc)
98 *val = content;
99 return cc;
100}
101
102#endif /* _ASM_S390_CPU_MF_H */