/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 2004, 2005 MIPS Technologies, Inc. All rights reserved. * Copyright (C) 2013 Imagination Technologies Ltd.
*/ #include <linux/kernel.h> #include <linux/device.h> #include <linux/fs.h> #include <linux/slab.h> #include <linux/export.h>
/* The number of TCs and VPEs physically available on the core */ staticint hw_tcs, hw_vpes;
/* We are prepared so configure and start the VPE... */ int vpe_run(struct vpe *v)
{ unsignedlong flags, val, dmt_flag; struct vpe_notifications *notifier; unsignedint vpeflags; struct tc *t;
/* check we are the Master VPE */
local_irq_save(flags);
val = read_c0_vpeconf0(); if (!(val & VPECONF0_MVP)) {
pr_warn("VPE loader: only Master VPE's are able to config MT\n");
local_irq_restore(flags);
return -1;
}
dmt_flag = dmt();
vpeflags = dvpe();
if (list_empty(&v->tc)) {
evpe(vpeflags);
emt(dmt_flag);
local_irq_restore(flags);
pr_warn("VPE loader: No TC's associated with VPE %d\n",
v->minor);
return -ENOEXEC;
}
t = list_first_entry(&v->tc, struct tc, tc);
/* Put MVPE's into 'configuration state' */
set_c0_mvpcontrol(MVPCONTROL_VPC);
settc(t->index);
/* should check it is halted, and not activated */ if ((read_tc_c0_tcstatus() & TCSTATUS_A) ||
!(read_tc_c0_tchalt() & TCHALT_H)) {
evpe(vpeflags);
emt(dmt_flag);
local_irq_restore(flags);
pr_warn("VPE loader: TC %d is already active!\n",
t->index);
return -ENOEXEC;
}
/* * Write the address we want it to start running from in the TCPC * register.
*/
write_tc_c0_tcrestart((unsignedlong)v->__start);
write_tc_c0_tccontext((unsignedlong)0);
/* * Mark the TC as activated, not interrupt exempt and not dynamically * allocatable
*/
val = read_tc_c0_tcstatus();
val = (val & ~(TCSTATUS_DA | TCSTATUS_IXMT)) | TCSTATUS_A;
write_tc_c0_tcstatus(val);
/* * We don't pass the memsize here, so VPE programs need to be * compiled with DFLT_STACK_SIZE and DFLT_HEAP_SIZE defined.
*/
mttgpr($7, 0);
mttgpr($6, v->ntcs);
/* set up VPE1 */ /* * bind the TC to VPE 1 as late as possible so we only have the final * VPE registers to set up, and so an EJTAG probe can trigger on it
*/
write_tc_c0_tcbind((read_tc_c0_tcbind() & ~TCBIND_CURVPE) | 1);
/* Set up the XTC bit in vpeconf0 to point at our tc */
write_vpe_c0_vpeconf0((read_vpe_c0_vpeconf0() & ~(VPECONF0_XTC))
| (t->index << VPECONF0_XTC_SHIFT));
back_to_back_c0_hazard();
/* enable this VPE */
write_vpe_c0_vpeconf0(read_vpe_c0_vpeconf0() | VPECONF0_VPA);
/* clear out any left overs from a previous program */
write_vpe_c0_status(0);
write_vpe_c0_cause(0);
/* take system out of configuration state */
clear_c0_mvpcontrol(MVPCONTROL_VPC);
/* * SMVP kernels manage VPE enable independently, but uniprocessor * kernels need to turn it on, even if that wasn't the pre-dvpe() state.
*/ #ifdef CONFIG_SMP
evpe(vpeflags); #else
evpe(EVPE_ENABLE); #endif
emt(dmt_flag);
local_irq_restore(flags);
/* module wrapper entry points */ /* give me a vpe */ void *vpe_alloc(void)
{ int i; struct vpe *v;
/* find a vpe */ for (i = 1; i < MAX_VPES; i++) {
v = get_vpe(i); if (v != NULL) {
v->state = VPE_STATE_INUSE; return v;
}
} return NULL;
}
EXPORT_SYMBOL(vpe_alloc);
/* start running from here */ int vpe_start(void *vpe, unsignedlong start)
{ struct vpe *v = vpe;
for (tc = aprp_cpu_index(); tc < hw_tcs; tc++) { /* * Must re-enable multithreading temporarily or in case we * reschedule send IPIs or similar we might hang.
*/
clear_c0_mvpcontrol(MVPCONTROL_VPC);
evpe(vpflags);
emt(mtflags);
local_irq_restore(flags);
t = alloc_tc(tc); if (!t) {
err = -ENOMEM; goto out_dev;
}
/* disable multi-threading with TC's */
write_vpe_c0_vpecontrol(read_vpe_c0_vpecontrol() &
~VPECONTROL_TE);
if (tc >= vpelimit) { /* * Set config to be the same as vpe0, * particularly kseg0 coherency alg
*/
write_vpe_c0_config(read_c0_config());
}
}
/* TC's */
t->pvpe = v; /* set the parent vpe */
if (tc >= aprp_cpu_index()) { unsignedlong tmp;
settc(tc);
/* * A TC that is bound to any other VPE gets bound to * VPE0, ideally I'd like to make it homeless but it * doesn't appear to let me bind a TC to a non-existent * VPE. Which is perfectly reasonable. * * The (un)bound state is visible to an EJTAG probe so * may notify GDB...
*/
tmp = read_tc_c0_tcbind(); if (tmp & TCBIND_CURVPE) { /* tc is bound >vpe0 */
write_tc_c0_tcbind(tmp & ~TCBIND_CURVPE);
t->pvpe = get_vpe(0); /* set the parent vpe */
}
/* halt the TC */
write_tc_c0_tchalt(TCHALT_H);
mips_ihb();
tmp = read_tc_c0_tcstatus();
/* mark not activated and not dynamically allocatable */
tmp &= ~(TCSTATUS_A | TCSTATUS_DA);
tmp |= TCSTATUS_IXMT; /* interrupt exempt */
write_tc_c0_tcstatus(tmp);
}
}
out_reenable: /* release config state */
clear_c0_mvpcontrol(MVPCONTROL_VPC);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.