1 --- a/arch/mips/Kconfig
2 +++ b/arch/mips/Kconfig
3 @@ -1871,6 +1871,28 @@ config MIPS_VPE_LOADER
4 Includes a loader for loading an elf relocatable object
5 onto another VPE and running it.
8 + bool "IFX APRP Extensions"
9 + depends on MIPS_VPE_LOADER
12 + IFX included extensions in APRP
15 + bool "34K Performance counters"
16 + depends on MIPS_MT && PROC_FS
19 + 34K Performance counter through /proc
22 + bool "Support mtsched priority configuration for TCs"
23 + depends on MIPS_MT && PROC_FS
26 + Support for mtsched priority configuration for TCs through
29 config MIPS_MT_SMTC_IM_BACKSTOP
30 bool "Use per-TC register bits as backstop for inhibited IM bits"
31 depends on MIPS_MT_SMTC
32 --- a/arch/mips/include/asm/mipsmtregs.h
33 +++ b/arch/mips/include/asm/mipsmtregs.h
35 #define read_c0_vpeconf0() __read_32bit_c0_register($1, 2)
36 #define write_c0_vpeconf0(val) __write_32bit_c0_register($1, 2, val)
38 +#define read_c0_vpeconf1() __read_32bit_c0_register($1, 3)
39 +#define write_c0_vpeconf1(val) __write_32bit_c0_register($1, 3, val)
41 +#define read_c0_vpeschedule() __read_32bit_c0_register($1, 5)
42 +#define write_c0_vpeschedule(val) __write_32bit_c0_register($1, 5, val)
44 +#define read_c0_vpeschefback() __read_32bit_c0_register($1, 6)
45 +#define write_c0_vpeschefback(val) __write_32bit_c0_register($1, 6, val)
47 +#define read_c0_vpeopt() __read_32bit_c0_register($1, 7)
48 +#define write_c0_vpeopt(val) __write_32bit_c0_register($1, 7, val)
50 #define read_c0_tcstatus() __read_32bit_c0_register($2, 1)
51 #define write_c0_tcstatus(val) __write_32bit_c0_register($2, 1, val)
53 #define read_c0_tcbind() __read_32bit_c0_register($2, 2)
54 +#define write_c0_tcbind(val) __write_32bit_c0_register($2, 2, val)
56 #define read_c0_tccontext() __read_32bit_c0_register($2, 5)
57 #define write_c0_tccontext(val) __write_32bit_c0_register($2, 5, val)
59 +#define read_c0_tcschedule() __read_32bit_c0_register($2, 6)
60 +#define write_c0_tcschedule(val) __write_32bit_c0_register($2, 6, val)
62 +#define read_c0_tcschefback() __read_32bit_c0_register($2, 7)
63 +#define write_c0_tcschefback(val) __write_32bit_c0_register($2, 7, val)
68 * Macros for use in assembly language code
70 #define MVPCONTROL_STLB_SHIFT 2
71 #define MVPCONTROL_STLB (_ULCAST_(1) << MVPCONTROL_STLB_SHIFT)
73 +#define MVPCONTROL_CPA_SHIFT 3
74 +#define MVPCONTROL_CPA (_ULCAST_(1) << MVPCONTROL_CPA_SHIFT)
77 #define MVPCONF0_PTC_SHIFT 0
79 #define MVPCONF0_TCA ( _ULCAST_(1) << MVPCONF0_TCA_SHIFT)
80 #define MVPCONF0_PTLBE_SHIFT 16
81 #define MVPCONF0_PTLBE (_ULCAST_(0x3ff) << MVPCONF0_PTLBE_SHIFT)
82 +#define MVPCONF0_PCP_SHIFT 27
83 +#define MVPCONF0_PCP (_ULCAST_(1) << MVPCONF0_PCP_SHIFT)
84 #define MVPCONF0_TLBS_SHIFT 29
85 #define MVPCONF0_TLBS (_ULCAST_(1) << MVPCONF0_TLBS_SHIFT)
86 #define MVPCONF0_M_SHIFT 31
88 #define VPECONF0_VPA (_ULCAST_(1) << VPECONF0_VPA_SHIFT)
89 #define VPECONF0_MVP_SHIFT 1
90 #define VPECONF0_MVP (_ULCAST_(1) << VPECONF0_MVP_SHIFT)
91 +#define VPECONF0_ICS_SHIFT 16
92 +#define VPECONF0_ICS (_ULCAST_(1) << VPECONF0_ICS_SHIFT)
93 +#define VPECONF0_DCS_SHIFT 17
94 +#define VPECONF0_DCS (_ULCAST_(1) << VPECONF0_DCS_SHIFT)
95 #define VPECONF0_XTC_SHIFT 21
96 #define VPECONF0_XTC (_ULCAST_(0xff) << VPECONF0_XTC_SHIFT)
99 +#define VPEOPT_DWX_SHIFT 0
100 +#define VPEOPT_IWX_SHIFT 8
101 +#define VPEOPT_IWX0 ( _ULCAST_(0x1) << VPEOPT_IWX_SHIFT)
102 +#define VPEOPT_IWX1 ( _ULCAST_(0x2) << VPEOPT_IWX_SHIFT)
103 +#define VPEOPT_IWX2 ( _ULCAST_(0x4) << VPEOPT_IWX_SHIFT)
104 +#define VPEOPT_IWX3 ( _ULCAST_(0x8) << VPEOPT_IWX_SHIFT)
105 +#define VPEOPT_DWX0 ( _ULCAST_(0x1) << VPEOPT_DWX_SHIFT)
106 +#define VPEOPT_DWX1 ( _ULCAST_(0x2) << VPEOPT_DWX_SHIFT)
107 +#define VPEOPT_DWX2 ( _ULCAST_(0x4) << VPEOPT_DWX_SHIFT)
108 +#define VPEOPT_DWX3 ( _ULCAST_(0x8) << VPEOPT_DWX_SHIFT)
110 /* TCStatus fields (per TC) */
111 #define TCSTATUS_TASID (_ULCAST_(0xff))
112 #define TCSTATUS_IXMT_SHIFT 10
113 @@ -350,6 +390,14 @@ do { \
114 #define write_vpe_c0_vpecontrol(val) mttc0(1, 1, val)
115 #define read_vpe_c0_vpeconf0() mftc0(1, 2)
116 #define write_vpe_c0_vpeconf0(val) mttc0(1, 2, val)
117 +#define read_vpe_c0_vpeschedule() mftc0(1, 5)
118 +#define write_vpe_c0_vpeschedule(val) mttc0(1, 5, val)
119 +#define read_vpe_c0_vpeschefback() mftc0(1, 6)
120 +#define write_vpe_c0_vpeschefback(val) mttc0(1, 6, val)
121 +#define read_vpe_c0_vpeopt() mftc0(1, 7)
122 +#define write_vpe_c0_vpeopt(val) mttc0(1, 7, val)
123 +#define read_vpe_c0_wired() mftc0(6, 0)
124 +#define write_vpe_c0_wired(val) mttc0(6, 0, val)
125 #define read_vpe_c0_count() mftc0(9, 0)
126 #define write_vpe_c0_count(val) mttc0(9, 0, val)
127 #define read_vpe_c0_status() mftc0(12, 0)
128 @@ -381,6 +429,12 @@ do { \
129 #define write_tc_c0_tchalt(val) mttc0(2, 4, val)
130 #define read_tc_c0_tccontext() mftc0(2, 5)
131 #define write_tc_c0_tccontext(val) mttc0(2, 5, val)
132 +#define read_tc_c0_tcschedule() mftc0(2, 6)
133 +#define write_tc_c0_tcschedule(val) mttc0(2, 6, val)
134 +#define read_tc_c0_tcschefback() mftc0(2, 7)
135 +#define write_tc_c0_tcschefback(val) mttc0(2, 7, val)
136 +#define read_tc_c0_entryhi() mftc0(10, 0)
137 +#define write_tc_c0_entryhi(val) mttc0(10, 0, val)
140 #define read_tc_gpr_sp() mftgpr(29)
141 --- a/arch/mips/kernel/Makefile
142 +++ b/arch/mips/kernel/Makefile
143 @@ -85,7 +85,8 @@ obj-$(CONFIG_MIPS32_O32) += binfmt_elfo3
145 obj-$(CONFIG_KGDB) += kgdb.o
146 obj-$(CONFIG_PROC_FS) += proc.o
148 +obj-$(CONFIG_MTSCHED) += mtsched_proc.o
149 +obj-$(CONFIG_PERFCTRS) += perf_proc.o
150 obj-$(CONFIG_64BIT) += cpu-bugs64.o
152 obj-$(CONFIG_I8253) += i8253.o
153 --- a/arch/mips/kernel/mips-mt.c
154 +++ b/arch/mips/kernel/mips-mt.c
156 #include <asm/cacheflush.h>
160 static int __init maxvpes(char *str)
162 get_option(&str, &vpelimit);
167 __setup("maxvpes=", maxvpes);
171 static int __init maxtcs(char *str)
173 get_option(&str, &tclimit);
176 +__setup("maxtcs=", maxtcs);
178 +#ifdef CONFIG_IFX_VPE_EXT
180 +static int __init istlbshared(char *str)
182 + get_option(&str, &stlb);
185 +__setup("vpe_tlb_shared=", istlbshared);
187 -__setup("maxtcs=", maxtcs);
189 +static int __init vpe0wired(char *str)
191 + get_option(&str, &vpe0_wired);
194 +__setup("vpe0_wired_tlb_entries=", vpe0wired);
197 +static int __init vpe1wired(char *str)
199 + get_option(&str, &vpe1_wired);
202 +__setup("vpe1_wired_tlb_entries=", vpe1wired);
204 +#ifdef CONFIG_MIPS_MT_SMTC
207 +void configure_tlb(void)
209 + int vpeflags, tcflags, tlbsiz;
210 + unsigned int config1val;
213 + write_c0_vpeconf0((read_c0_vpeconf0() | VPECONF0_MVP));
214 + write_c0_mvpcontrol((read_c0_mvpcontrol() | MVPCONTROL_VPC));
216 + //printk("stlb = %d, vpe0_wired = %d vpe1_wired=%d\n", stlb,vpe0_wired, vpe1_wired);
218 + if (!(read_c0_mvpconf0() & MVPCONF0_TLBS)) {
224 + write_c0_mvpcontrol(read_c0_mvpcontrol() | MVPCONTROL_STLB);
225 + write_c0_wired(vpe0_wired + vpe1_wired);
226 + if (((read_vpe_c0_config() & MIPS_CONF_MT) >> 7) == 1) {
227 + config1val = read_vpe_c0_config1();
228 + tlbsiz = (((config1val >> 25) & 0x3f) + 1);
231 + cpu_data[0].tlbsize = tlbsiz;
232 + current_cpu_data.tlbsize = tlbsiz;
237 + write_c0_mvpcontrol(read_c0_mvpcontrol() & ~MVPCONTROL_STLB);
238 + write_c0_wired(vpe0_wired);
242 + write_c0_mvpcontrol((read_c0_mvpcontrol() & ~MVPCONTROL_VPC));
244 + local_flush_tlb_all();
246 + printk("Wired TLB entries for Linux read_c0_wired() = %d\n", read_c0_wired());
247 +#ifdef CONFIG_MIPS_MT_SMTC
256 * Dump new MIPS MT state for the core. Does not leave TCs halted.
257 @@ -78,18 +148,18 @@ void mips_mt_regdump(unsigned long mvpct
258 if ((read_tc_c0_tcbind() & TCBIND_CURVPE) == i) {
259 printk(" VPE %d\n", i);
260 printk(" VPEControl : %08lx\n",
261 - read_vpe_c0_vpecontrol());
262 + read_vpe_c0_vpecontrol());
263 printk(" VPEConf0 : %08lx\n",
264 - read_vpe_c0_vpeconf0());
265 + read_vpe_c0_vpeconf0());
266 printk(" VPE%d.Status : %08lx\n",
267 - i, read_vpe_c0_status());
268 + i, read_vpe_c0_status());
269 printk(" VPE%d.EPC : %08lx %pS\n",
270 - i, read_vpe_c0_epc(),
271 - (void *) read_vpe_c0_epc());
272 + i, read_vpe_c0_epc(),
273 + (void *) read_vpe_c0_epc());
274 printk(" VPE%d.Cause : %08lx\n",
275 - i, read_vpe_c0_cause());
276 + i, read_vpe_c0_cause());
277 printk(" VPE%d.Config7 : %08lx\n",
278 - i, read_vpe_c0_config7());
279 + i, read_vpe_c0_config7());
280 break; /* Next VPE */
283 @@ -287,6 +357,9 @@ void mips_mt_set_cpuoptions(void)
284 printk("Mapped %ld ITC cells starting at 0x%08x\n",
285 ((itcblkgrn & 0x7fe00000) >> 20), itc_base);
287 +#ifdef CONFIG_IFX_VPE_EXT
293 --- a/arch/mips/kernel/proc.c
294 +++ b/arch/mips/kernel/proc.c
296 #include <linux/kernel.h>
297 #include <linux/sched.h>
298 #include <linux/seq_file.h>
299 +#include <linux/proc_fs.h>
300 #include <asm/bootinfo.h>
302 #include <asm/cpu-features.h>
303 @@ -110,3 +111,19 @@ const struct seq_operations cpuinfo_op =
305 .show = show_cpuinfo,
309 + * Support for MIPS/local /proc hooks in /proc/mips/
312 +static struct proc_dir_entry *mips_proc = NULL;
314 +struct proc_dir_entry *get_mips_proc_dir(void)
317 + * This ought not to be preemptable.
319 + if(mips_proc == NULL)
320 + mips_proc = proc_mkdir("mips", NULL);
323 --- a/arch/mips/kernel/smtc.c
324 +++ b/arch/mips/kernel/smtc.c
325 @@ -1334,6 +1334,13 @@ void smtc_get_new_mmu_context(struct mm_
326 asid = asid_cache(cpu);
329 +#ifdef CONFIG_IFX_VPE_EXT
330 + /* If TLB is shared between AP and RP (AP is running SMTC),
331 + leave out max ASID i.e., ASID_MASK for RP
333 + if (!nostlb && ((asid & ASID_MASK) == (ASID_MASK - 1)))
336 if (!((asid += ASID_INC) & ASID_MASK) ) {
337 if (cpu_has_vtag_icache)
339 --- a/arch/mips/kernel/vpe.c
340 +++ b/arch/mips/kernel/vpe.c
341 @@ -76,6 +76,58 @@ static struct kspd_notifications kspd_ev
342 static int kspd_events_reqd;
345 +#ifdef CONFIG_IFX_VPE_EXT
346 +static int is_sdepgm;
348 +extern int vpe0_wired;
349 +extern int vpe1_wired;
350 +unsigned int vpe1_load_addr;
352 +static int __init load_address(char *str)
354 + get_option(&str, &vpe1_load_addr);
357 +__setup("vpe1_load_addr=", load_address);
359 +#include <asm/mipsmtregs.h>
360 +#define write_vpe_c0_wired(val) mttc0(6, 0, val)
362 +#ifndef COMMAND_LINE_SIZE
363 +# define COMMAND_LINE_SIZE 512
366 +char command_line[COMMAND_LINE_SIZE * 2];
368 +static unsigned int vpe1_mem;
369 +static int __init vpe1mem(char *str)
371 + vpe1_mem = memparse(str, &str);
374 +__setup("vpe1_mem=", vpe1mem);
376 +uint32_t vpe1_wdog_ctr;
377 +static int __init wdog_ctr(char *str)
379 + get_option(&str, &vpe1_wdog_ctr);
383 +__setup("vpe1_wdog_ctr_addr=", wdog_ctr);
384 +EXPORT_SYMBOL(vpe1_wdog_ctr);
386 +uint32_t vpe1_wdog_timeout;
387 +static int __init wdog_timeout(char *str)
389 + get_option(&str, &vpe1_wdog_timeout);
393 +__setup("vpe1_wdog_timeout=", wdog_timeout);
394 +EXPORT_SYMBOL(vpe1_wdog_timeout);
397 /* grab the likely amount of memory we will need. */
398 #ifdef CONFIG_MIPS_VPE_LOADER_TOM
399 #define P_SIZE (2 * 1024 * 1024)
400 @@ -268,6 +320,13 @@ static void *alloc_progmem(unsigned long
403 #ifdef CONFIG_MIPS_VPE_LOADER_TOM
404 +#ifdef CONFIG_IFX_VPE_EXT
405 + if (vpe1_load_addr) {
406 + memset((void *)vpe1_load_addr, 0, len);
407 + return (void *)vpe1_load_addr;
412 * This means you must tell Linux to use less memory than you
413 * physically have, for example by passing a mem= boot argument.
414 @@ -746,6 +805,12 @@ static int vpe_run(struct vpe * v)
417 /* Write the address we want it to start running from in the TCPC register. */
418 +#if defined(CONFIG_IFX_VPE_EXT) && 0
420 + write_vpe_c0_wired(vpe0_wired + vpe1_wired);
422 + write_vpe_c0_wired(vpe1_wired);
424 write_tc_c0_tcrestart((unsigned long)v->__start);
425 write_tc_c0_tccontext((unsigned long)0);
427 @@ -759,6 +824,20 @@ static int vpe_run(struct vpe * v)
429 write_tc_c0_tchalt(read_tc_c0_tchalt() & ~TCHALT_H);
431 +#if defined(CONFIG_IFX_VPE_EXT) && 0
433 + * $a2 & $a3 are used to pass command line parameters to VPE1. $a2
434 + * points to the start of the command line string and $a3 points to
435 + * the end of the string. This convention is identical to the Linux
436 + * kernel boot parameter passing mechanism. Please note that $a3 is
437 + * used to pass physical memory size or 0 in SDE tool kit. So, if you
438 + * are passing comand line parameters through $a2 & $a3 SDE programs
439 + * don't work as desired.
441 + mttgpr(6, command_line);
442 + mttgpr(7, (command_line + strlen(command_line)));
446 * The sde-kit passes 'memsize' to __start in $a3, so set something
447 * here... Or set $a3 to zero and define DFLT_STACK_SIZE and
448 @@ -833,6 +912,9 @@ static int find_vpe_symbols(struct vpe *
449 if ( (v->__start == 0) || (v->shared_ptr == NULL))
452 +#ifdef CONFIG_IFX_VPE_EXT
458 @@ -994,6 +1076,15 @@ static int vpe_elfload(struct vpe * v)
459 (unsigned long)v->load_addr + v->len);
461 if ((find_vpe_symbols(v, sechdrs, symindex, strtab, &mod)) < 0) {
462 +#ifdef CONFIG_IFX_VPE_EXT
463 + if (vpe1_load_addr) {
464 + /* Conversion to KSEG1 is required ??? */
465 + v->__start = KSEG1ADDR(vpe1_load_addr);
471 if (v->__start == 0) {
472 printk(KERN_WARNING "VPE loader: program does not contain "
473 "a __start symbol\n");
474 @@ -1064,6 +1155,9 @@ static int vpe_open(struct inode *inode,
475 struct vpe_notifications *not;
478 +#ifdef CONFIG_IFX_VPE_EXT
482 if (minor != iminor(inode)) {
483 /* assume only 1 device at the moment. */
484 @@ -1089,7 +1183,12 @@ static int vpe_open(struct inode *inode,
485 release_progmem(v->load_addr);
486 cleanup_tc(get_tc(tclimit));
489 +#ifdef CONFIG_IFX_VPE_EXT
490 + progsize = (vpe1_mem != 0) ? vpe1_mem : P_SIZE;
491 + //printk("progsize = %x\n", progsize);
492 + v->pbuffer = vmalloc(progsize);
493 + v->plen = progsize;
495 /* this of-course trashes what was there before... */
496 v->pbuffer = vmalloc(P_SIZE);
498 @@ -1097,11 +1196,14 @@ static int vpe_open(struct inode *inode,
507 v->uid = filp->f_cred->fsuid;
508 v->gid = filp->f_cred->fsgid;
511 #ifdef CONFIG_MIPS_APSP_KSPD
512 /* get kspd to tell us when a syscall_exit happens */
513 @@ -1349,6 +1451,133 @@ static void kspd_sp_exit( int sp_id)
514 cleanup_tc(get_tc(sp_id));
517 +#ifdef CONFIG_IFX_VPE_EXT
518 +int32_t vpe1_sw_start(void* sw_start_addr, uint32_t tcmask, uint32_t flags)
520 + enum vpe_state state;
521 + struct vpe *v = get_vpe(tclimit);
522 + struct vpe_notifications *not;
524 + if (tcmask || flags) {
525 + printk(KERN_WARNING "Currently tcmask and flags should be 0.\
526 + other values not supported\n");
530 + state = xchg(&v->state, VPE_STATE_INUSE);
531 + if (state != VPE_STATE_UNUSED) {
534 + list_for_each_entry(not, &v->notify, list) {
535 + not->stop(tclimit);
539 + v->__start = (unsigned long)sw_start_addr;
543 + printk(KERN_DEBUG "VPE loader: VPE1 running successfully\n");
549 +EXPORT_SYMBOL(vpe1_sw_start);
551 +int32_t vpe1_sw_stop(uint32_t flags)
553 + struct vpe *v = get_vpe(tclimit);
555 + if (!vpe_free(v)) {
556 + printk(KERN_DEBUG "RP Stopped\n");
563 +EXPORT_SYMBOL(vpe1_sw_stop);
565 +uint32_t vpe1_get_load_addr (uint32_t flags)
567 + return vpe1_load_addr;
570 +EXPORT_SYMBOL(vpe1_get_load_addr);
572 +uint32_t vpe1_get_max_mem (uint32_t flags)
580 +EXPORT_SYMBOL(vpe1_get_max_mem);
582 +void* vpe1_get_cmdline_argument(void)
584 + return saved_command_line;
587 +EXPORT_SYMBOL(vpe1_get_cmdline_argument);
589 +int32_t vpe1_set_boot_param(char *field, char *value, char flags)
591 + char *ptr, string[64];
592 + int start_off, end_off;
595 + strcpy(string, field);
597 + strcat(string, "=");
598 + strcat(string, value);
599 + strcat(command_line, " ");
600 + strcat(command_line, string);
603 + ptr = strstr(command_line, string);
605 + start_off = ptr - command_line;
606 + ptr += strlen(string);
607 + while ((*ptr != ' ') && (*ptr != '\0'))
609 + end_off = ptr - command_line;
610 + command_line[start_off] = '\0';
611 + strcat (command_line, command_line+end_off);
617 +EXPORT_SYMBOL(vpe1_set_boot_param);
619 +int32_t vpe1_get_boot_param(char *field, char **value, char flags)
621 + char *ptr, string[64];
625 + if ((ptr = strstr(command_line, field))) {
626 + ptr += strlen(field) + 1; /* including = */
627 + while ((*ptr != ' ') && (*ptr != '\0'))
628 + string[i++] = *ptr++;
630 + *value = kmalloc((strlen(string) + 1), GFP_KERNEL);
631 + if (*value != NULL)
632 + strcpy(*value, string);
640 +EXPORT_SYMBOL(vpe1_get_boot_param);
642 +extern void configure_tlb(void);
645 static ssize_t store_kill(struct device *dev, struct device_attribute *attr,
646 const char *buf, size_t len)
647 @@ -1430,6 +1659,18 @@ static int __init vpe_module_init(void)
648 printk("VPE loader: not a MIPS MT capable processor\n");
651 +#ifdef CONFIG_IFX_VPE_EXT
652 +#ifndef CONFIG_MIPS_MT_SMTC
657 +#ifndef CONFIG_MIPS_MT_SMTC
665 printk(KERN_WARNING "No VPEs reserved for AP/SP, not "
666 @@ -1474,10 +1715,12 @@ static int __init vpe_module_init(void)
670 + back_to_back_c0_hazard();
672 /* Put MVPE's into 'configuration state' */
673 set_c0_mvpcontrol(MVPCONTROL_VPC);
675 - /* dump_mtregs(); */
678 val = read_c0_mvpconf0();
679 hw_tcs = (val & MVPCONF0_PTC) + 1;
680 @@ -1489,6 +1732,7 @@ static int __init vpe_module_init(void)
681 * reschedule send IPIs or similar we might hang.
683 clear_c0_mvpcontrol(MVPCONTROL_VPC);
684 + back_to_back_c0_hazard();
687 local_irq_restore(flags);
688 @@ -1514,6 +1758,7 @@ static int __init vpe_module_init(void)
691 v->ntcs = hw_tcs - tclimit;
692 + write_tc_c0_tcbind((read_tc_c0_tcbind() & ~TCBIND_CURVPE) | 1);
694 /* add the tc to the list of this vpe's tc's. */
695 list_add(&t->tc, &v->tc);
696 @@ -1582,6 +1827,7 @@ static int __init vpe_module_init(void)
698 /* release config state */
699 clear_c0_mvpcontrol(MVPCONTROL_VPC);
700 + back_to_back_c0_hazard();
705 +++ b/arch/mips/kernel/mtsched_proc.c
708 + * /proc hooks for MIPS MT scheduling policy management for 34K cores
710 + * This program is free software; you can distribute it and/or modify it
711 + * under the terms of the GNU General Public License (Version 2) as
712 + * published by the Free Software Foundation.
714 + * This program is distributed in the hope it will be useful, but WITHOUT
715 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
716 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
717 + * for more details.
719 + * You should have received a copy of the GNU General Public License along
720 + * with this program; if not, write to the Free Software Foundation, Inc.,
721 + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
723 + * Copyright (C) 2006 Mips Technologies, Inc
726 +#include <linux/kernel.h>
728 +#include <asm/cpu.h>
729 +#include <asm/processor.h>
730 +#include <asm/system.h>
731 +#include <asm/mipsregs.h>
732 +#include <asm/mipsmtregs.h>
733 +#include <asm/uaccess.h>
734 +#include <linux/proc_fs.h>
736 +static struct proc_dir_entry *mtsched_proc;
738 +#ifndef CONFIG_MIPS_MT_SMTC
741 +#define NTCS NR_CPUS
748 +static int proc_read_mtsched(char *page, char **start, off_t off,
749 + int count, int *eof, void *data)
757 + unsigned long flags;
758 + unsigned int mtflags;
759 + unsigned int haltstate;
760 + unsigned int vpes_checked[NVPES];
761 + unsigned int vpeschedule[NVPES];
762 + unsigned int vpeschefback[NVPES];
763 + unsigned int tcschedule[NTCS];
764 + unsigned int tcschefback[NTCS];
766 + /* Dump the state of the MIPS MT scheduling policy manager */
767 + /* Inititalize control state */
768 + for(i = 0; i < NVPES; i++) {
769 + vpes_checked[i] = 0;
770 + vpeschedule[i] = 0;
771 + vpeschefback[i] = 0;
773 + for(i = 0; i < NTCS; i++) {
775 + tcschefback[i] = 0;
778 + /* Disable interrupts and multithreaded issue */
779 + local_irq_save(flags);
782 + /* Then go through the TCs, halt 'em, and extract the values */
783 + mytc = (read_c0_tcbind() & TCBIND_CURTC) >> TCBIND_CURTC_SHIFT;
784 + for(i = 0; i < NTCS; i++) {
786 + /* No need to halt ourselves! */
787 + tcschedule[i] = read_c0_tcschedule();
788 + tcschefback[i] = read_c0_tcschefback();
789 + /* If VPE bound to TC hasn't been checked, do it */
790 + vpe = read_c0_tcbind() & TCBIND_CURVPE;
791 + if(!vpes_checked[vpe]) {
792 + vpeschedule[vpe] = read_c0_vpeschedule();
793 + vpeschefback[vpe] = read_c0_vpeschefback();
794 + vpes_checked[vpe] = 1;
798 + haltstate = read_tc_c0_tchalt();
799 + write_tc_c0_tchalt(TCHALT_H);
801 + tcschedule[i] = read_tc_c0_tcschedule();
802 + tcschefback[i] = read_tc_c0_tcschefback();
803 + /* If VPE bound to TC hasn't been checked, do it */
804 + vpe = read_tc_c0_tcbind() & TCBIND_CURVPE;
805 + if(!vpes_checked[vpe]) {
806 + vpeschedule[vpe] = read_vpe_c0_vpeschedule();
807 + vpeschefback[vpe] = read_vpe_c0_vpeschefback();
808 + vpes_checked[vpe] = 1;
810 + if(!haltstate) write_tc_c0_tchalt(0);
813 + /* Re-enable MT and interrupts */
815 + local_irq_restore(flags);
817 + for(vpe=0; vpe < NVPES; vpe++) {
818 + len = sprintf(page, "VPE[%d].VPEschedule = 0x%08x\n",
819 + vpe, vpeschedule[vpe]);
822 + len = sprintf(page, "VPE[%d].VPEschefback = 0x%08x\n",
823 + vpe, vpeschefback[vpe]);
827 + for(i=0; i < NTCS; i++) {
828 + len = sprintf(page, "TC[%d].TCschedule = 0x%08x\n",
832 + len = sprintf(page, "TC[%d].TCschefback = 0x%08x\n",
833 + i, tcschefback[i]);
841 + * Write to perf counter registers based on text input
844 +#define TXTBUFSZ 100
846 +static int proc_write_mtsched(struct file *file, const char *buffer,
847 + unsigned long count, void *data)
850 + char mybuf[TXTBUFSZ];
851 + /* At most, we will set up 9 TCs and 2 VPEs, 11 entries in all */
852 + char entity[1]; //, entity1[1];
854 + unsigned long value[1];
855 + int nparsed = 0 , index = 0;
856 + unsigned long flags;
857 + unsigned int mtflags;
858 + unsigned int haltstate;
859 + unsigned int tcbindval;
861 + if(count >= TXTBUFSZ) len = TXTBUFSZ-1;
863 + memset(mybuf,0,TXTBUFSZ);
864 + if(copy_from_user(mybuf, buffer, len)) return -EFAULT;
866 + nparsed = sscanf(mybuf, "%c%d %lx",
867 + &entity[0] ,&number[0], &value[0]);
870 + * Having acquired the inputs, which might have
871 + * generated exceptions and preemptions,
872 + * program the registers.
874 + /* Disable interrupts and multithreaded issue */
875 + local_irq_save(flags);
878 + if(entity[index] == 't' ) {
879 + /* Set TCSchedule or TCScheFBack of specified TC */
880 + if(number[index] > NTCS) goto skip;
881 + /* If it's our own TC, do it direct */
882 + if(number[index] ==
883 + ((read_c0_tcbind() & TCBIND_CURTC)
884 + >> TCBIND_CURTC_SHIFT)) {
885 + if(entity[index] == 't')
886 + write_c0_tcschedule(value[index]);
888 + write_c0_tcschefback(value[index]);
890 + /* Otherwise, we do it via MTTR */
891 + settc(number[index]);
892 + haltstate = read_tc_c0_tchalt();
893 + write_tc_c0_tchalt(TCHALT_H);
895 + if(entity[index] == 't')
896 + write_tc_c0_tcschedule(value[index]);
898 + write_tc_c0_tcschefback(value[index]);
900 + if(!haltstate) write_tc_c0_tchalt(0);
902 + } else if(entity[index] == 'v') {
903 + /* Set VPESchedule of specified VPE */
904 + if(number[index] > NVPES) goto skip;
905 + tcbindval = read_c0_tcbind();
906 + /* Are we doing this to our current VPE? */
907 + if((tcbindval & TCBIND_CURVPE) == number[index]) {
908 + /* Then life is simple */
909 + write_c0_vpeschedule(value[index]);
912 + * Bind ourselves to the other VPE long enough
913 + * to program the bind value.
915 + write_c0_tcbind((tcbindval & ~TCBIND_CURVPE)
918 + write_c0_vpeschedule(value[index]);
920 + /* Restore previous binding */
921 + write_c0_tcbind(tcbindval);
926 + else if(entity[index] == 'r') {
927 + unsigned int vpes_checked[2], vpe ,i , mytc;
928 + vpes_checked[0] = vpes_checked[1] = 0;
930 + /* Then go through the TCs, halt 'em, and extract the values */
931 + mytc = (read_c0_tcbind() & TCBIND_CURTC) >> TCBIND_CURTC_SHIFT;
933 + for(i = 0; i < NTCS; i++) {
935 + /* No need to halt ourselves! */
936 + write_c0_vpeschefback(0);
937 + write_c0_tcschefback(0);
940 + haltstate = read_tc_c0_tchalt();
941 + write_tc_c0_tchalt(TCHALT_H);
943 + write_tc_c0_tcschefback(0);
944 + /* If VPE bound to TC hasn't been checked, do it */
945 + vpe = read_tc_c0_tcbind() & TCBIND_CURVPE;
946 + if(!vpes_checked[vpe]) {
947 + write_vpe_c0_vpeschefback(0);
948 + vpes_checked[vpe] = 1;
950 + if(!haltstate) write_tc_c0_tchalt(0);
955 + printk ("\n Usage : <t/v><0/1> <Hex Value>\n Example : t0 0x01\n");
959 + /* Re-enable MT and interrupts */
961 + local_irq_restore(flags);
965 +static int __init init_mtsched_proc(void)
967 + extern struct proc_dir_entry *get_mips_proc_dir(void);
968 + struct proc_dir_entry *mips_proc_dir;
970 + if (!cpu_has_mipsmt) {
971 + printk("mtsched: not a MIPS MT capable processor\n");
975 + mips_proc_dir = get_mips_proc_dir();
977 + mtsched_proc = create_proc_entry("mtsched", 0644, mips_proc_dir);
978 + mtsched_proc->read_proc = proc_read_mtsched;
979 + mtsched_proc->write_proc = proc_write_mtsched;
984 +/* Automagically create the entry */
985 +module_init(init_mtsched_proc);
987 +++ b/arch/mips/kernel/perf_proc.c
990 + * /proc hooks for CPU performance counter support for SMTC kernel
991 + * (and ultimately others)
992 + * Copyright (C) 2006 Mips Technologies, Inc
995 +#include <linux/kernel.h>
997 +#include <asm/cpu.h>
998 +#include <asm/processor.h>
999 +#include <asm/system.h>
1000 +#include <asm/mipsregs.h>
1001 +#include <asm/uaccess.h>
1002 +#include <linux/proc_fs.h>
1005 + * /proc diagnostic and statistics hooks
1009 +/* Internal software-extended event counters */
1011 +static unsigned long long extencount[4] = {0,0,0,0};
1013 +static struct proc_dir_entry *perf_proc;
1015 +static int proc_read_perf(char *page, char **start, off_t off,
1016 + int count, int *eof, void *data)
1021 + len = sprintf(page, "PerfCnt[0].Ctl : 0x%08x\n", read_c0_perfctrl0());
1024 + len = sprintf(page, "PerfCnt[0].Cnt : %Lu\n",
1025 + extencount[0] + (unsigned long long)((unsigned)read_c0_perfcntr0()));
1028 + len = sprintf(page, "PerfCnt[1].Ctl : 0x%08x\n", read_c0_perfctrl1());
1031 + len = sprintf(page, "PerfCnt[1].Cnt : %Lu\n",
1032 + extencount[1] + (unsigned long long)((unsigned)read_c0_perfcntr1()));
1035 + len = sprintf(page, "PerfCnt[2].Ctl : 0x%08x\n", read_c0_perfctrl2());
1038 + len = sprintf(page, "PerfCnt[2].Cnt : %Lu\n",
1039 + extencount[2] + (unsigned long long)((unsigned)read_c0_perfcntr2()));
1042 + len = sprintf(page, "PerfCnt[3].Ctl : 0x%08x\n", read_c0_perfctrl3());
1045 + len = sprintf(page, "PerfCnt[3].Cnt : %Lu\n",
1046 + extencount[3] + (unsigned long long)((unsigned)read_c0_perfcntr3()));
1054 + * Write to perf counter registers based on text input
1057 +#define TXTBUFSZ 100
1059 +static int proc_write_perf(struct file *file, const char *buffer,
1060 + unsigned long count, void *data)
1065 + char mybuf[TXTBUFSZ];
1068 + unsigned long control[4];
1069 + long long ctrdata[4];
1071 + if(count >= TXTBUFSZ) len = TXTBUFSZ-1;
1073 + memset(mybuf,0,TXTBUFSZ);
1074 + if(copy_from_user(mybuf, buffer, len)) return -EFAULT;
1076 + nparsed = sscanf(mybuf,
1077 + "%d %lx %Ld %d %lx %Ld %d %lx %Ld %d %lx %Ld",
1078 + &which[0], &control[0], &ctrdata[0],
1079 + &which[1], &control[1], &ctrdata[1],
1080 + &which[2], &control[2], &ctrdata[2],
1081 + &which[3], &control[3], &ctrdata[3]);
1083 + for(index = 0; nparsed >= 3; index++) {
1084 + switch (which[index]) {
1086 + write_c0_perfctrl0(control[index]);
1087 + if(ctrdata[index] != -1) {
1088 + extencount[0] = (unsigned long long)ctrdata[index];
1089 + write_c0_perfcntr0((unsigned long)0);
1093 + write_c0_perfctrl1(control[index]);
1094 + if(ctrdata[index] != -1) {
1095 + extencount[1] = (unsigned long long)ctrdata[index];
1096 + write_c0_perfcntr1((unsigned long)0);
1100 + write_c0_perfctrl2(control[index]);
1101 + if(ctrdata[index] != -1) {
1102 + extencount[2] = (unsigned long long)ctrdata[index];
1103 + write_c0_perfcntr2((unsigned long)0);
1107 + write_c0_perfctrl3(control[index]);
1108 + if(ctrdata[index] != -1) {
1109 + extencount[3] = (unsigned long long)ctrdata[index];
1110 + write_c0_perfcntr3((unsigned long)0);
1119 +extern int (*perf_irq)(void);
1122 + * Invoked when timer interrupt vector picks up a perf counter overflow
1125 +static int perf_proc_irq(void)
1127 + unsigned long snapshot;
1130 + * It would be nice to do this as a loop, but we don't have
1131 + * indirect access to CP0 registers.
1133 + snapshot = read_c0_perfcntr0();
1134 + if ((long)snapshot < 0) {
1136 + (unsigned long long)((unsigned)read_c0_perfcntr0());
1137 + write_c0_perfcntr0(0);
1139 + snapshot = read_c0_perfcntr1();
1140 + if ((long)snapshot < 0) {
1142 + (unsigned long long)((unsigned)read_c0_perfcntr1());
1143 + write_c0_perfcntr1(0);
1145 + snapshot = read_c0_perfcntr2();
1146 + if ((long)snapshot < 0) {
1148 + (unsigned long long)((unsigned)read_c0_perfcntr2());
1149 + write_c0_perfcntr2(0);
1151 + snapshot = read_c0_perfcntr3();
1152 + if ((long)snapshot < 0) {
1154 + (unsigned long long)((unsigned)read_c0_perfcntr3());
1155 + write_c0_perfcntr3(0);
1160 +static int __init init_perf_proc(void)
1162 + extern struct proc_dir_entry *get_mips_proc_dir(void);
1164 + struct proc_dir_entry *mips_proc_dir = get_mips_proc_dir();
1166 + write_c0_perfcntr0(0);
1167 + write_c0_perfcntr1(0);
1168 + write_c0_perfcntr2(0);
1169 + write_c0_perfcntr3(0);
1170 + perf_proc = create_proc_entry("perf", 0644, mips_proc_dir);
1171 + perf_proc->read_proc = proc_read_perf;
1172 + perf_proc->write_proc = proc_write_perf;
1173 + perf_irq = perf_proc_irq;
1178 +/* Automagically create the entry */
1179 +module_init(init_perf_proc);