xref: /freebsd/sys/arm64/spe/arm_spe.h (revision 68f185ccc9f8f9498d536f4737d888b37cf11882)
1*68f185ccSZachary Leaf /*-
2*68f185ccSZachary Leaf  * SPDX-License-Identifier: BSD-2-Clause
3*68f185ccSZachary Leaf  *
4*68f185ccSZachary Leaf  * Copyright (c) 2024 Arm Ltd
5*68f185ccSZachary Leaf  *
6*68f185ccSZachary Leaf  * Redistribution and use in source and binary forms, with or without
7*68f185ccSZachary Leaf  * modification, are permitted provided that the following conditions
8*68f185ccSZachary Leaf  * are met:
9*68f185ccSZachary Leaf  * 1. Redistributions of source code must retain the above copyright
10*68f185ccSZachary Leaf  *    notice, this list of conditions and the following disclaimer.
11*68f185ccSZachary Leaf  * 2. Redistributions in binary form must reproduce the above copyright
12*68f185ccSZachary Leaf  *    notice, this list of conditions and the following disclaimer in the
13*68f185ccSZachary Leaf  *    documentation and/or other materials provided with the distribution.
14*68f185ccSZachary Leaf  *
15*68f185ccSZachary Leaf  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*68f185ccSZachary Leaf  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*68f185ccSZachary Leaf  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*68f185ccSZachary Leaf  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*68f185ccSZachary Leaf  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*68f185ccSZachary Leaf  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*68f185ccSZachary Leaf  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*68f185ccSZachary Leaf  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*68f185ccSZachary Leaf  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*68f185ccSZachary Leaf  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*68f185ccSZachary Leaf  * SUCH DAMAGE.
26*68f185ccSZachary Leaf  */
27*68f185ccSZachary Leaf 
28*68f185ccSZachary Leaf #ifndef _ARM64_ARM_SPE_H_
29*68f185ccSZachary Leaf #define _ARM64_ARM_SPE_H_
30*68f185ccSZachary Leaf 
31*68f185ccSZachary Leaf /* kqueue events */
32*68f185ccSZachary Leaf #define ARM_SPE_KQ_BUF		138
33*68f185ccSZachary Leaf #define ARM_SPE_KQ_SHUTDOWN	139
34*68f185ccSZachary Leaf #define ARM_SPE_KQ_SIGNAL	140
35*68f185ccSZachary Leaf 
36*68f185ccSZachary Leaf /* spe_backend_read() u64 data encoding */
37*68f185ccSZachary Leaf #define KQ_BUF_POS_SHIFT	0
38*68f185ccSZachary Leaf #define KQ_BUF_POS		(1 << KQ_BUF_POS_SHIFT)
39*68f185ccSZachary Leaf #define KQ_PARTREC_SHIFT	1
40*68f185ccSZachary Leaf #define KQ_PARTREC		(1 << KQ_PARTREC_SHIFT)
41*68f185ccSZachary Leaf #define KQ_FINAL_BUF_SHIFT	2
42*68f185ccSZachary Leaf #define KQ_FINAL_BUF		(1 << KQ_FINAL_BUF_SHIFT)
43*68f185ccSZachary Leaf 
44*68f185ccSZachary Leaf enum arm_spe_ctx_field {
45*68f185ccSZachary Leaf 	ARM_SPE_CTX_NONE,
46*68f185ccSZachary Leaf 	ARM_SPE_CTX_PID,
47*68f185ccSZachary Leaf 	ARM_SPE_CTX_CPU_ID
48*68f185ccSZachary Leaf };
49*68f185ccSZachary Leaf 
50*68f185ccSZachary Leaf enum arm_spe_profiling_level {
51*68f185ccSZachary Leaf 	ARM_SPE_KERNEL_AND_USER,
52*68f185ccSZachary Leaf 	ARM_SPE_KERNEL_ONLY,
53*68f185ccSZachary Leaf 	ARM_SPE_USER_ONLY
54*68f185ccSZachary Leaf };
55*68f185ccSZachary Leaf struct arm_spe_config {
56*68f185ccSZachary Leaf 	/* Minimum interval is IMP DEF up to maximum 24 bit value */
57*68f185ccSZachary Leaf 	uint32_t interval;
58*68f185ccSZachary Leaf 
59*68f185ccSZachary Leaf 	/* Profile kernel (EL1), userspace (EL0) or both */
60*68f185ccSZachary Leaf 	enum arm_spe_profiling_level level;
61*68f185ccSZachary Leaf 
62*68f185ccSZachary Leaf 	/*
63*68f185ccSZachary Leaf 	 * Configure context field in SPE records to store either the
64*68f185ccSZachary Leaf 	 * current PID, the CPU ID or neither
65*68f185ccSZachary Leaf 	 *
66*68f185ccSZachary Leaf 	 * In PID mode, kernel threads without a process context are
67*68f185ccSZachary Leaf 	 * logged as PID 0
68*68f185ccSZachary Leaf 	 */
69*68f185ccSZachary Leaf 	enum arm_spe_ctx_field ctx_field;
70*68f185ccSZachary Leaf };
71*68f185ccSZachary Leaf 
72*68f185ccSZachary Leaf struct arm_spe_svc_buf {
73*68f185ccSZachary Leaf 	uint32_t ident;
74*68f185ccSZachary Leaf 	uint8_t buf_idx : 1;
75*68f185ccSZachary Leaf };
76*68f185ccSZachary Leaf 
77*68f185ccSZachary Leaf #endif /* _ARM64_ARM_SPE_H_ */
78