1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 #include <linux/regset.h>
4 
5 #include <asm/switch_to.h>
6 
7 #include "ptrace-decl.h"
8 
9 /*
10  * For get_evrregs/set_evrregs functions 'data' has the following layout:
11  *
12  * struct {
13  *   u32 evr[32];
14  *   u64 acc;
15  *   u32 spefscr;
16  * }
17  */
18 
19 int evr_active(struct task_struct *target, const struct user_regset *regset)
20 {
21 	flush_spe_to_thread(target);
22 	return target->thread.used_spe ? regset->n : 0;
23 }
24 
25 int evr_get(struct task_struct *target, const struct user_regset *regset,
26 	    unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf)
27 {
28 	int ret;
29 
30 	flush_spe_to_thread(target);
31 
32 	ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
33 				  &target->thread.evr,
34 				  0, sizeof(target->thread.evr));
35 
36 	BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
37 		     offsetof(struct thread_struct, spefscr));
38 
39 	if (!ret)
40 		ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
41 					  &target->thread.acc,
42 					  sizeof(target->thread.evr), -1);
43 
44 	return ret;
45 }
46 
47 int evr_set(struct task_struct *target, const struct user_regset *regset,
48 	    unsigned int pos, unsigned int count,
49 	    const void *kbuf, const void __user *ubuf)
50 {
51 	int ret;
52 
53 	flush_spe_to_thread(target);
54 
55 	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
56 				 &target->thread.evr,
57 				 0, sizeof(target->thread.evr));
58 
59 	BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
60 		     offsetof(struct thread_struct, spefscr));
61 
62 	if (!ret)
63 		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
64 					 &target->thread.acc,
65 					 sizeof(target->thread.evr), -1);
66 
67 	return ret;
68 }
69