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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * License.  See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2004, 2005 MIPS Technologies, Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2013 Imagination Technologies Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/mipsregs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/mipsmtregs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/mips_mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/vpe.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static int major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /* The number of TCs and VPEs physically available on the core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static int hw_tcs, hw_vpes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /* We are prepared so configure and start the VPE... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) int vpe_run(struct vpe *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	unsigned long flags, val, dmt_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct vpe_notifications *notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	unsigned int vpeflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct tc *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	/* check we are the Master VPE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	val = read_c0_vpeconf0();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	if (!(val & VPECONF0_MVP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		pr_warn("VPE loader: only Master VPE's are able to config MT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	dmt_flag = dmt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	vpeflags = dvpe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (list_empty(&v->tc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		evpe(vpeflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		emt(dmt_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		pr_warn("VPE loader: No TC's associated with VPE %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			v->minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	t = list_first_entry(&v->tc, struct tc, tc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	/* Put MVPE's into 'configuration state' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	set_c0_mvpcontrol(MVPCONTROL_VPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	settc(t->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	/* should check it is halted, and not activated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if ((read_tc_c0_tcstatus() & TCSTATUS_A) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	   !(read_tc_c0_tchalt() & TCHALT_H)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		evpe(vpeflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		emt(dmt_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		pr_warn("VPE loader: TC %d is already active!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			t->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	 * Write the address we want it to start running from in the TCPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	 * register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	write_tc_c0_tcrestart((unsigned long)v->__start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	write_tc_c0_tccontext((unsigned long)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) 	 * Mark the TC as activated, not interrupt exempt and not dynamically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 * allocatable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	val = read_tc_c0_tcstatus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	val = (val & ~(TCSTATUS_DA | TCSTATUS_IXMT)) | TCSTATUS_A;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	write_tc_c0_tcstatus(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	write_tc_c0_tchalt(read_tc_c0_tchalt() & ~TCHALT_H);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	 * The sde-kit passes 'memsize' to __start in $a3, so set something
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	 * here...  Or set $a3 to zero and define DFLT_STACK_SIZE and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	 * DFLT_HEAP_SIZE when you compile your program
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	mttgpr(6, v->ntcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	mttgpr(7, physical_memsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	/* set up VPE1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	 * bind the TC to VPE 1 as late as possible so we only have the final
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	 * VPE registers to set up, and so an EJTAG probe can trigger on it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	write_tc_c0_tcbind((read_tc_c0_tcbind() & ~TCBIND_CURVPE) | 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	write_vpe_c0_vpeconf0(read_vpe_c0_vpeconf0() & ~(VPECONF0_VPA));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	back_to_back_c0_hazard();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/* Set up the XTC bit in vpeconf0 to point at our tc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	write_vpe_c0_vpeconf0((read_vpe_c0_vpeconf0() & ~(VPECONF0_XTC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			      | (t->index << VPECONF0_XTC_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	back_to_back_c0_hazard();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/* enable this VPE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	write_vpe_c0_vpeconf0(read_vpe_c0_vpeconf0() | VPECONF0_VPA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	/* clear out any left overs from a previous program */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	write_vpe_c0_status(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	write_vpe_c0_cause(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	/* take system out of configuration state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	clear_c0_mvpcontrol(MVPCONTROL_VPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	 * SMVP kernels manage VPE enable independently, but uniprocessor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	 * kernels need to turn it on, even if that wasn't the pre-dvpe() state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	evpe(vpeflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	evpe(EVPE_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	emt(dmt_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	list_for_each_entry(notifier, &v->notify, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		notifier->start(VPE_MODULE_MINOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) void cleanup_tc(struct tc *tc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	unsigned int mtflags, vpflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	int tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	mtflags = dmt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	vpflags = dvpe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	/* Put MVPE's into 'configuration state' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	set_c0_mvpcontrol(MVPCONTROL_VPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	settc(tc->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	tmp = read_tc_c0_tcstatus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/* mark not allocated and not dynamically allocatable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	tmp &= ~(TCSTATUS_A | TCSTATUS_DA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	tmp |= TCSTATUS_IXMT;	/* interrupt exempt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	write_tc_c0_tcstatus(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	write_tc_c0_tchalt(TCHALT_H);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	mips_ihb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	clear_c0_mvpcontrol(MVPCONTROL_VPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	evpe(vpflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	emt(mtflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* module wrapper entry points */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* give me a vpe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) void *vpe_alloc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct vpe *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	/* find a vpe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	for (i = 1; i < MAX_VPES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		v = get_vpe(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		if (v != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			v->state = VPE_STATE_INUSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			return v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) EXPORT_SYMBOL(vpe_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* start running from here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) int vpe_start(void *vpe, unsigned long start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	struct vpe *v = vpe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	v->__start = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	return vpe_run(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) EXPORT_SYMBOL(vpe_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /* halt it for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) int vpe_stop(void *vpe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct vpe *v = vpe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct tc *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	unsigned int evpe_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	evpe_flags = dvpe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	t = list_entry(v->tc.next, struct tc, tc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (t != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		settc(t->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		write_vpe_c0_vpeconf0(read_vpe_c0_vpeconf0() & ~VPECONF0_VPA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	evpe(evpe_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) EXPORT_SYMBOL(vpe_stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* I've done with it thank you */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int vpe_free(void *vpe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	struct vpe *v = vpe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	struct tc *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	unsigned int evpe_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	t = list_entry(v->tc.next, struct tc, tc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (t == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	evpe_flags = dvpe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	/* Put MVPE's into 'configuration state' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	set_c0_mvpcontrol(MVPCONTROL_VPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	settc(t->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	write_vpe_c0_vpeconf0(read_vpe_c0_vpeconf0() & ~VPECONF0_VPA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	/* halt the TC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	write_tc_c0_tchalt(TCHALT_H);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	mips_ihb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	/* mark the TC unallocated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	write_tc_c0_tcstatus(read_tc_c0_tcstatus() & ~TCSTATUS_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	v->state = VPE_STATE_UNUSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	clear_c0_mvpcontrol(MVPCONTROL_VPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	evpe(evpe_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) EXPORT_SYMBOL(vpe_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static ssize_t store_kill(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			  const char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	struct vpe *vpe = get_vpe(aprp_cpu_index());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	struct vpe_notifications *notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	list_for_each_entry(notifier, &vpe->notify, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		notifier->stop(aprp_cpu_index());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	release_progmem(vpe->load_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	cleanup_tc(get_tc(aprp_cpu_index()));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	vpe_stop(vpe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	vpe_free(vpe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static DEVICE_ATTR(kill, S_IWUSR, NULL, store_kill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static ssize_t ntcs_show(struct device *cd, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	struct vpe *vpe = get_vpe(aprp_cpu_index());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	return sprintf(buf, "%d\n", vpe->ntcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static ssize_t ntcs_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			  const char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct vpe *vpe = get_vpe(aprp_cpu_index());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	unsigned long new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	ret = kstrtoul(buf, 0, &new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (new == 0 || new > (hw_tcs - aprp_cpu_index()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	vpe->ntcs = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static DEVICE_ATTR_RW(ntcs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static struct attribute *vpe_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	&dev_attr_kill.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	&dev_attr_ntcs.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) ATTRIBUTE_GROUPS(vpe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static void vpe_device_release(struct device *cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	kfree(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static struct class vpe_class = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	.name = "vpe",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	.dev_release = vpe_device_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	.dev_groups = vpe_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static struct device vpe_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) int __init vpe_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	unsigned int mtflags, vpflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	unsigned long flags, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	struct vpe *v = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	struct tc *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	int tc, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (!cpu_has_mipsmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		pr_warn("VPE loader: not a MIPS MT capable processor\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (vpelimit == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		pr_warn("No VPEs reserved for AP/SP, not initialize VPE loader\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			"Pass maxvpes=<n> argument as kernel argument\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (aprp_cpu_index() == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		pr_warn("No TCs reserved for AP/SP, not initialize VPE loader\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 			"Pass maxtcs=<n> argument as kernel argument\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	major = register_chrdev(0, VPE_MODULE_NAME, &vpe_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	if (major < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		pr_warn("VPE loader: unable to register character device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		return major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	err = class_register(&vpe_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		pr_err("vpe_class registration failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		goto out_chrdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	device_initialize(&vpe_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	vpe_device.class	= &vpe_class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	vpe_device.parent	= NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	dev_set_name(&vpe_device, "vpe1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	vpe_device.devt = MKDEV(major, VPE_MODULE_MINOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	err = device_add(&vpe_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		pr_err("Adding vpe_device failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		goto out_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	mtflags = dmt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	vpflags = dvpe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	/* Put MVPE's into 'configuration state' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	set_c0_mvpcontrol(MVPCONTROL_VPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	val = read_c0_mvpconf0();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	hw_tcs = (val & MVPCONF0_PTC) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	hw_vpes = ((val & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	for (tc = aprp_cpu_index(); tc < hw_tcs; tc++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		 * Must re-enable multithreading temporarily or in case we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		 * reschedule send IPIs or similar we might hang.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		clear_c0_mvpcontrol(MVPCONTROL_VPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		evpe(vpflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		emt(mtflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		t = alloc_tc(tc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		if (!t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 			err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 			goto out_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		mtflags = dmt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		vpflags = dvpe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		set_c0_mvpcontrol(MVPCONTROL_VPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		/* VPE's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		if (tc < hw_tcs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			settc(tc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			v = alloc_vpe(tc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 			if (v == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 				pr_warn("VPE: unable to allocate VPE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 				goto out_reenable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			v->ntcs = hw_tcs - aprp_cpu_index();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 			/* add the tc to the list of this vpe's tc's. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 			list_add(&t->tc, &v->tc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			/* deactivate all but vpe0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			if (tc >= aprp_cpu_index()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 				unsigned long tmp = read_vpe_c0_vpeconf0();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 				tmp &= ~VPECONF0_VPA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 				/* master VPE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 				tmp |= VPECONF0_MVP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 				write_vpe_c0_vpeconf0(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			/* disable multi-threading with TC's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			write_vpe_c0_vpecontrol(read_vpe_c0_vpecontrol() &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 						~VPECONTROL_TE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 			if (tc >= vpelimit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 				 * Set config to be the same as vpe0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 				 * particularly kseg0 coherency alg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 				write_vpe_c0_config(read_c0_config());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		/* TC's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		t->pvpe = v;	/* set the parent vpe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		if (tc >= aprp_cpu_index()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 			unsigned long tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 			settc(tc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 			 * A TC that is bound to any other VPE gets bound to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 			 * VPE0, ideally I'd like to make it homeless but it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 			 * doesn't appear to let me bind a TC to a non-existent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 			 * VPE. Which is perfectly reasonable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 			 * The (un)bound state is visible to an EJTAG probe so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 			 * may notify GDB...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 			tmp = read_tc_c0_tcbind();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 			if (tmp & TCBIND_CURVPE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 				/* tc is bound >vpe0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 				write_tc_c0_tcbind(tmp & ~TCBIND_CURVPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 				t->pvpe = get_vpe(0);	/* set the parent vpe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 			/* halt the TC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 			write_tc_c0_tchalt(TCHALT_H);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 			mips_ihb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 			tmp = read_tc_c0_tcstatus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 			/* mark not activated and not dynamically allocatable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 			tmp &= ~(TCSTATUS_A | TCSTATUS_DA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 			tmp |= TCSTATUS_IXMT;	/* interrupt exempt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 			write_tc_c0_tcstatus(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) out_reenable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	/* release config state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	clear_c0_mvpcontrol(MVPCONTROL_VPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	evpe(vpflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	emt(mtflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) out_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	device_del(&vpe_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) out_class:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	class_unregister(&vpe_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) out_chrdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	unregister_chrdev(major, VPE_MODULE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) void __exit vpe_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	struct vpe *v, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	device_del(&vpe_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	class_unregister(&vpe_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	unregister_chrdev(major, VPE_MODULE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	/* No locking needed here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	list_for_each_entry_safe(v, n, &vpecontrol.vpe_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		if (v->state != VPE_STATE_UNUSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 			release_vpe(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }