xref: /linux/arch/arm64/include/uapi/asm/sve_context.h (revision b7df4cc3a088a8ce6973c96731bc792dbf54ce28)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /* Copyright (C) 2017-2018 ARM Limited */
3 
4 /*
5  * For use by other UAPI headers only.
6  * Do not make direct use of header or its definitions.
7  */
8 
9 #ifndef _UAPI__ASM_SVE_CONTEXT_H
10 #define _UAPI__ASM_SVE_CONTEXT_H
11 
12 #include <linux/types.h>
13 
14 #define __SVE_VQ_BYTES		16	/* number of bytes per quadword */
15 
16 /*
17  * Yes, __SVE_VQ_MAX is 512 QUADWORDS.
18  *
19  * To help ensure forward portability, this is much larger than the
20  * current maximum value defined by the SVE architecture.  While arrays
21  * or static allocations can be sized based on this value, watch out!
22  * It will waste a surprisingly large amount of memory.
23  *
24  * Dynamic sizing based on the actual runtime vector length is likely to
25  * be preferable for most purposes.
26  */
27 #define __SVE_VQ_MIN		1
28 #define __SVE_VQ_MAX		512
29 
30 #define __SVE_VL_MIN		(__SVE_VQ_MIN * __SVE_VQ_BYTES)
31 #define __SVE_VL_MAX		(__SVE_VQ_MAX * __SVE_VQ_BYTES)
32 
33 #define __SVE_NUM_ZREGS		32
34 #define __SVE_NUM_PREGS		16
35 
36 #define __sve_vl_valid(vl)			\
37 	((vl) % __SVE_VQ_BYTES == 0 &&		\
38 	 (vl) >= __SVE_VL_MIN &&		\
39 	 (vl) <= __SVE_VL_MAX)
40 
41 #define __sve_vq_from_vl(vl)	((vl) / __SVE_VQ_BYTES)
42 #define __sve_vl_from_vq(vq)	((vq) * __SVE_VQ_BYTES)
43 
44 #define __SVE_ZREG_SIZE(vq)	((__u32)(vq) * __SVE_VQ_BYTES)
45 #define __SVE_PREG_SIZE(vq)	((__u32)(vq) * (__SVE_VQ_BYTES / 8))
46 #define __SVE_FFR_SIZE(vq)	__SVE_PREG_SIZE(vq)
47 
48 #define __SVE_ZREGS_OFFSET	0
49 #define __SVE_ZREG_OFFSET(vq, n) \
50 	(__SVE_ZREGS_OFFSET + __SVE_ZREG_SIZE(vq) * (n))
51 #define __SVE_ZREGS_SIZE(vq) \
52 	(__SVE_ZREG_OFFSET(vq, __SVE_NUM_ZREGS) - __SVE_ZREGS_OFFSET)
53 
54 #define __SVE_PREGS_OFFSET(vq) \
55 	(__SVE_ZREGS_OFFSET + __SVE_ZREGS_SIZE(vq))
56 #define __SVE_PREG_OFFSET(vq, n) \
57 	(__SVE_PREGS_OFFSET(vq) + __SVE_PREG_SIZE(vq) * (n))
58 #define __SVE_PREGS_SIZE(vq) \
59 	(__SVE_PREG_OFFSET(vq, __SVE_NUM_PREGS) - __SVE_PREGS_OFFSET(vq))
60 
61 #define __SVE_FFR_OFFSET(vq) \
62 	(__SVE_PREGS_OFFSET(vq) + __SVE_PREGS_SIZE(vq))
63 
64 #endif /* ! _UAPI__ASM_SVE_CONTEXT_H */
65