linux/arch/s390/include/asm/cpu_mcf.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2/*
   3 * Counter facility support definitions for the Linux perf
   4 *
   5 * Copyright IBM Corp. 2019
   6 * Author(s): Hendrik Brueckner <brueckner@linux.ibm.com>
   7 */
   8#ifndef _ASM_S390_CPU_MCF_H
   9#define _ASM_S390_CPU_MCF_H
  10
  11#include <linux/perf_event.h>
  12#include <asm/cpu_mf.h>
  13
  14enum cpumf_ctr_set {
  15        CPUMF_CTR_SET_BASIC   = 0,    /* Basic Counter Set */
  16        CPUMF_CTR_SET_USER    = 1,    /* Problem-State Counter Set */
  17        CPUMF_CTR_SET_CRYPTO  = 2,    /* Crypto-Activity Counter Set */
  18        CPUMF_CTR_SET_EXT     = 3,    /* Extended Counter Set */
  19        CPUMF_CTR_SET_MT_DIAG = 4,    /* MT-diagnostic Counter Set */
  20
  21        /* Maximum number of counter sets */
  22        CPUMF_CTR_SET_MAX,
  23};
  24
  25#define CPUMF_LCCTL_ENABLE_SHIFT    16
  26#define CPUMF_LCCTL_ACTCTL_SHIFT     0
  27static const u64 cpumf_ctr_ctl[CPUMF_CTR_SET_MAX] = {
  28        [CPUMF_CTR_SET_BASIC]   = 0x02,
  29        [CPUMF_CTR_SET_USER]    = 0x04,
  30        [CPUMF_CTR_SET_CRYPTO]  = 0x08,
  31        [CPUMF_CTR_SET_EXT]     = 0x01,
  32        [CPUMF_CTR_SET_MT_DIAG] = 0x20,
  33};
  34
  35static inline void ctr_set_enable(u64 *state, int ctr_set)
  36{
  37        *state |= cpumf_ctr_ctl[ctr_set] << CPUMF_LCCTL_ENABLE_SHIFT;
  38}
  39static inline void ctr_set_disable(u64 *state, int ctr_set)
  40{
  41        *state &= ~(cpumf_ctr_ctl[ctr_set] << CPUMF_LCCTL_ENABLE_SHIFT);
  42}
  43static inline void ctr_set_start(u64 *state, int ctr_set)
  44{
  45        *state |= cpumf_ctr_ctl[ctr_set] << CPUMF_LCCTL_ACTCTL_SHIFT;
  46}
  47static inline void ctr_set_stop(u64 *state, int ctr_set)
  48{
  49        *state &= ~(cpumf_ctr_ctl[ctr_set] << CPUMF_LCCTL_ACTCTL_SHIFT);
  50}
  51
  52static inline void ctr_set_multiple_enable(u64 *state, u64 ctrsets)
  53{
  54        *state |= ctrsets << CPUMF_LCCTL_ENABLE_SHIFT;
  55}
  56
  57static inline void ctr_set_multiple_disable(u64 *state, u64 ctrsets)
  58{
  59        *state &= ~(ctrsets << CPUMF_LCCTL_ENABLE_SHIFT);
  60}
  61
  62static inline void ctr_set_multiple_start(u64 *state, u64 ctrsets)
  63{
  64        *state |= ctrsets << CPUMF_LCCTL_ACTCTL_SHIFT;
  65}
  66
  67static inline void ctr_set_multiple_stop(u64 *state, u64 ctrsets)
  68{
  69        *state &= ~(ctrsets << CPUMF_LCCTL_ACTCTL_SHIFT);
  70}
  71
  72static inline int ctr_stcctm(enum cpumf_ctr_set set, u64 range, u64 *dest)
  73{
  74        switch (set) {
  75        case CPUMF_CTR_SET_BASIC:
  76                return stcctm(BASIC, range, dest);
  77        case CPUMF_CTR_SET_USER:
  78                return stcctm(PROBLEM_STATE, range, dest);
  79        case CPUMF_CTR_SET_CRYPTO:
  80                return stcctm(CRYPTO_ACTIVITY, range, dest);
  81        case CPUMF_CTR_SET_EXT:
  82                return stcctm(EXTENDED, range, dest);
  83        case CPUMF_CTR_SET_MT_DIAG:
  84                return stcctm(MT_DIAG_CLEARING, range, dest);
  85        case CPUMF_CTR_SET_MAX:
  86                return 3;
  87        }
  88        return 3;
  89}
  90
  91struct cpu_cf_events {
  92        struct cpumf_ctr_info   info;
  93        atomic_t                ctr_set[CPUMF_CTR_SET_MAX];
  94        atomic64_t              alert;
  95        u64                     state, tx_state;
  96        unsigned int            flags;
  97        unsigned int            txn_flags;
  98};
  99DECLARE_PER_CPU(struct cpu_cf_events, cpu_cf_events);
 100
 101bool kernel_cpumcf_avail(void);
 102int __kernel_cpumcf_begin(void);
 103unsigned long kernel_cpumcf_alert(int clear);
 104void __kernel_cpumcf_end(void);
 105
 106static inline int kernel_cpumcf_begin(void)
 107{
 108        if (!cpum_cf_avail())
 109                return -ENODEV;
 110
 111        preempt_disable();
 112        return __kernel_cpumcf_begin();
 113}
 114static inline void kernel_cpumcf_end(void)
 115{
 116        __kernel_cpumcf_end();
 117        preempt_enable();
 118}
 119
 120/* Return true if store counter set multiple instruction is available */
 121static inline int stccm_avail(void)
 122{
 123        return test_facility(142);
 124}
 125
 126#endif /* _ASM_S390_CPU_MCF_H */
 127