Commit 0fd7375a authored by Mao Minkai's avatar Mao Minkai Committed by guzitao
Browse files

sw64: add syscall pfh_ops

Sunway inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IBDJNZ



--------------------------------

Add a new syscall pfh_ops which allows system administrators to
modify hardware cache prefetch configuration.

Signed-off-by: default avatarMao Minkai <maominkai@wxiat.com>
Reviewed-by: default avatarHe Sheng <hesheng@wxiat.com>
Signed-off-by: default avatarGu Zitao <guzitao@wxiat.com>
parent d0ced270
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -20,8 +20,10 @@
#define CSR_EXC_PC		0xe
#define CSR_AS_INFO		0x3c
#define CSR_DS_STAT		0x48
#define CSR_PFH_CTL		0x4f
#define CSR_SOFTCID		0xc9
#define CSR_DVA			0x54
#define CSR_PFH_CNT		0x5c
#define CSR_BRRETC		0x5e
#define CSR_BRFAILC		0x5f
#define CSR_PTBR_SYS		0x68
+61 −0
Original line number Diff line number Diff line
@@ -151,3 +151,64 @@ SYSCALL_DEFINE0(sw64_pipe)
	}
	return res;
}

#ifdef CONFIG_SUBARCH_C4

struct pfh_val {
	unsigned long pfh_ctl;
	unsigned long pfh_cnt;
};

static void local_set_pfh(void *info)
{
	struct pfh_val *kbuf = info;

	if (kbuf->pfh_ctl)
		sw64_write_csr(kbuf->pfh_ctl, CSR_PFH_CTL);
	if (kbuf->pfh_cnt)
		sw64_write_csr(kbuf->pfh_cnt, CSR_PFH_CNT);
}

SYSCALL_DEFINE3(pfh_ops, unsigned long, op,
		unsigned long __user *, pfh_ctl_p,
		unsigned long __user *, pfh_cnt_p)
{
	struct pfh_val kbuf = {0, 0};
	long error = 0;

	if (!capable(CAP_SYS_ADMIN))
		return -EPERM;

	if (op) {	// op != 0, set
		if (pfh_ctl_p)
			error |= get_user(kbuf.pfh_ctl, pfh_ctl_p);
		if (pfh_cnt_p)
			error |= get_user(kbuf.pfh_cnt, pfh_cnt_p);

		if (!error && (kbuf.pfh_ctl || kbuf.pfh_cnt)) {
			smp_call_function(local_set_pfh, &kbuf, 1);
			local_set_pfh(&kbuf);
		}
	} else {	// op == 0, get
		if (pfh_ctl_p) {
			kbuf.pfh_ctl = sw64_read_csr(CSR_PFH_CTL);
			error |= put_user(kbuf.pfh_ctl, pfh_ctl_p);
		}

		if (pfh_cnt_p) {
			kbuf.pfh_cnt = sw64_read_csr(CSR_PFH_CNT);
			error |= put_user(kbuf.pfh_cnt, pfh_cnt_p);
		}
	}

	return error;
}

#else

SYSCALL_DEFINE0(pfh_ops)
{
	return -ENOSYS;
}

#endif /* CONFIG_SUBARCH_C4 */
+1 −1
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@
#107 is unused
#108 is unused
#109 is unused
#110 is unused
110	common	pfh_ops				sys_pfh_ops
111	common	sigsuspend			sys_sigsuspend
#112 is unused
113	common	recvmsg				sys_recvmsg