blob: a3afecdae14599bfe0e77a65a19f66eb7e26581b [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 Glauberb03d541a2012-03-23 11:13:05 +010024
Hendrik Brueckner212188a2012-03-23 11:13:06 +010025#define CPU_MF_INT_CF_MASK (CPU_MF_INT_CF_CACA|CPU_MF_INT_CF_LCDA)
26#define CPU_MF_INT_SF_MASK (CPU_MF_INT_SF_IAE|CPU_MF_INT_SF_ISE| \
27 CPU_MF_INT_SF_PRA|CPU_MF_INT_SF_SACA| \
28 CPU_MF_INT_SF_LSDA)
29
30/* CPU measurement facility support */
31static inline int cpum_cf_avail(void)
32{
33 return MACHINE_HAS_SPP && test_facility(67);
34}
35
36static inline int cpum_sf_avail(void)
37{
38 return MACHINE_HAS_SPP && test_facility(68);
39}
40
41
42struct cpumf_ctr_info {
43 u16 cfvn;
44 u16 auth_ctl;
45 u16 enable_ctl;
46 u16 act_ctl;
47 u16 max_cpu;
48 u16 csvn;
49 u16 max_cg;
50 u16 reserved1;
51 u32 reserved2[12];
52} __packed;
53
54/* Query counter information */
55static inline int qctri(struct cpumf_ctr_info *info)
56{
57 int rc = -EINVAL;
58
59 asm volatile (
60 "0: .insn s,0xb28e0000,%1\n"
61 "1: lhi %0,0\n"
62 "2:\n"
63 EX_TABLE(1b, 2b)
64 : "+d" (rc), "=Q" (*info));
65 return rc;
66}
67
68/* Load CPU-counter-set controls */
69static inline int lcctl(u64 ctl)
70{
71 int cc;
72
73 asm volatile (
74 " .insn s,0xb2840000,%1\n"
75 " ipm %0\n"
76 " srl %0,28\n"
77 : "=d" (cc) : "m" (ctl) : "cc");
78 return cc;
79}
80
81/* Extract CPU counter */
82static inline int ecctr(u64 ctr, u64 *val)
83{
84 register u64 content asm("4") = 0;
85 int cc;
86
87 asm volatile (
88 " .insn rre,0xb2e40000,%0,%2\n"
89 " ipm %1\n"
90 " srl %1,28\n"
91 : "=d" (content), "=d" (cc) : "d" (ctr) : "cc");
92 if (!cc)
93 *val = content;
94 return cc;
95}
96
97#endif /* _ASM_S390_CPU_MF_H */