Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/regset.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <asm/switch_to.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "ptrace-decl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Regardless of transactions, 'fp_state' holds the current running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * value of all FPR registers and 'ckfp_state' holds the last checkpointed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * value of all FPR registers for the current transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Userspace interface buffer layout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * struct data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *	u64	fpr[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *	u64	fpscr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) int fpr_get(struct task_struct *target, const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	    struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	u64 buf[33];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	flush_fp_to_thread(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	/* copy to local buffer then write that out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	for (i = 0; i < 32 ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		buf[i] = target->thread.TS_FPR(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	buf[32] = target->thread.fp_state.fpscr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	return membuf_write(&to, buf, 33 * sizeof(u64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * Regardless of transactions, 'fp_state' holds the current running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * value of all FPR registers and 'ckfp_state' holds the last checkpointed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * value of all FPR registers for the current transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * Userspace interface buffer layout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * struct data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  *	u64	fpr[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  *	u64	fpscr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) int fpr_set(struct task_struct *target, const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	    unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	    const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	u64 buf[33];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	flush_fp_to_thread(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	for (i = 0; i < 32 ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		buf[i] = target->thread.TS_FPR(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	buf[32] = target->thread.fp_state.fpscr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	/* copy to local buffer then write that out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	for (i = 0; i < 32 ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		target->thread.TS_FPR(i) = buf[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	target->thread.fp_state.fpscr = buf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * Currently to set and and get all the vsx state, you need to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * the fp and VMX calls as well.  This only get/sets the lower 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * 128bit VSX registers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) int vsr_active(struct task_struct *target, const struct user_regset *regset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	flush_vsx_to_thread(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return target->thread.used_vsr ? regset->n : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * Regardless of transactions, 'fp_state' holds the current running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * value of all FPR registers and 'ckfp_state' holds the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * checkpointed value of all FPR registers for the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * Userspace interface buffer layout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * struct data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  *	u64	vsx[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) int vsr_get(struct task_struct *target, const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	    struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	u64 buf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	flush_tmregs_to_thread(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	flush_fp_to_thread(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	flush_altivec_to_thread(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	flush_vsx_to_thread(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	for (i = 0; i < 32 ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return membuf_write(&to, buf, 32 * sizeof(double));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * Regardless of transactions, 'fp_state' holds the current running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * value of all FPR registers and 'ckfp_state' holds the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * checkpointed value of all FPR registers for the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * Userspace interface buffer layout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * struct data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  *	u64	vsx[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int vsr_set(struct task_struct *target, const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	    unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	    const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	u64 buf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	flush_tmregs_to_thread(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	flush_fp_to_thread(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	flush_altivec_to_thread(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	flush_vsx_to_thread(target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	for (i = 0; i < 32 ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				 buf, 0, 32 * sizeof(double));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		for (i = 0; i < 32 ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }