1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Processor Activity Instrumentation support for cryptography counters
5 * Copyright IBM Corp. 2022
8 #ifndef _ASM_S390_PAI_H
9 #define _ASM_S390_PAI_H
11 #include <linux/jump_label.h>
12 #include <asm/lowcore.h>
13 #include <asm/ptrace.h>
15 struct qpaci_info_block {
19 u64 num_cc : 8; /* # of supported crypto counters */
21 u64 num_nnpa : 7; /* # of supported NNPA counters */
26 static inline int qpaci(struct qpaci_info_block *info)
28 /* Size of info (in double words minus one) */
29 size_t size = sizeof(*info) / sizeof(u64) - 1;
34 " .insn s,0xb28f0000,%[info]\n"
38 : [cc] "=d" (cc), [info] "=Q" (*info), [size] "+&d" (size)
40 : "0", "cc", "memory");
41 return cc ? (size + 1) * sizeof(u64) : 0;
44 #define PAI_CRYPTO_BASE 0x1000 /* First event number */
45 #define PAI_CRYPTO_MAXCTR 256 /* Max # of event counters */
46 #define PAI_CRYPTO_KERNEL_OFFSET 2048
47 #define PAI_NNPA_BASE 0x1800 /* First event number */
48 #define PAI_NNPA_MAXCTR 128 /* Max # of event counters */
50 DECLARE_STATIC_KEY_FALSE(pai_key);
52 static __always_inline void pai_kernel_enter(struct pt_regs *regs)
54 if (!IS_ENABLED(CONFIG_PERF_EVENTS))
56 if (!static_branch_unlikely(&pai_key))
58 if (!S390_lowcore.ccd)
62 WRITE_ONCE(S390_lowcore.ccd, S390_lowcore.ccd | PAI_CRYPTO_KERNEL_OFFSET);
65 static __always_inline void pai_kernel_exit(struct pt_regs *regs)
67 if (!IS_ENABLED(CONFIG_PERF_EVENTS))
69 if (!static_branch_unlikely(&pai_key))
71 if (!S390_lowcore.ccd)
75 WRITE_ONCE(S390_lowcore.ccd, S390_lowcore.ccd & ~PAI_CRYPTO_KERNEL_OFFSET);