1 --- a/arch/mips/Kconfig
2 +++ b/arch/mips/Kconfig
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
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)
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
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.
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 */
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>
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 @@ -1328,6 +1328,13 @@
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
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)
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.
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);
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
449 if ( (v->__start == 0) || (v->shared_ptr == NULL))
452 +#ifdef CONFIG_IFX_VPE_EXT
458 @@ -995,6 +1077,15 @@
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 @@ -1065,6 +1156,9 @@
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 @@ -1091,14 +1185,22 @@
485 cleanup_tc(get_tc(tclimit));
488 +#ifdef CONFIG_IFX_VPE_EXT
489 + progsize = (vpe1_mem != 0) ? vpe1_mem : P_SIZE;
490 + //printk("progsize = %x\n", progsize);
491 + v->pbuffer = vmalloc(progsize);
492 + v->plen = progsize;
494 /* this of-course trashes what was there before... */
495 v->pbuffer = vmalloc(P_SIZE);
502 v->uid = filp->f_cred->fsuid;
503 v->gid = filp->f_cred->fsgid;
506 #ifdef CONFIG_MIPS_APSP_KSPD
507 /* get kspd to tell us when a syscall_exit happens */
508 @@ -1351,6 +1453,133 @@
509 cleanup_tc(get_tc(sp_id));
512 +#ifdef CONFIG_IFX_VPE_EXT
513 +int32_t vpe1_sw_start(void* sw_start_addr, uint32_t tcmask, uint32_t flags)
515 + enum vpe_state state;
516 + struct vpe *v = get_vpe(tclimit);
517 + struct vpe_notifications *not;
519 + if (tcmask || flags) {
520 + printk(KERN_WARNING "Currently tcmask and flags should be 0.\
521 + other values not supported\n");
525 + state = xchg(&v->state, VPE_STATE_INUSE);
526 + if (state != VPE_STATE_UNUSED) {
529 + list_for_each_entry(not, &v->notify, list) {
530 + not->stop(tclimit);
534 + v->__start = (unsigned long)sw_start_addr;
538 + printk(KERN_DEBUG "VPE loader: VPE1 running successfully\n");
544 +EXPORT_SYMBOL(vpe1_sw_start);
546 +int32_t vpe1_sw_stop(uint32_t flags)
548 + struct vpe *v = get_vpe(tclimit);
550 + if (!vpe_free(v)) {
551 + printk(KERN_DEBUG "RP Stopped\n");
558 +EXPORT_SYMBOL(vpe1_sw_stop);
560 +uint32_t vpe1_get_load_addr (uint32_t flags)
562 + return vpe1_load_addr;
565 +EXPORT_SYMBOL(vpe1_get_load_addr);
567 +uint32_t vpe1_get_max_mem (uint32_t flags)
575 +EXPORT_SYMBOL(vpe1_get_max_mem);
577 +void* vpe1_get_cmdline_argument(void)
579 + return saved_command_line;
582 +EXPORT_SYMBOL(vpe1_get_cmdline_argument);
584 +int32_t vpe1_set_boot_param(char *field, char *value, char flags)
586 + char *ptr, string[64];
587 + int start_off, end_off;
590 + strcpy(string, field);
592 + strcat(string, "=");
593 + strcat(string, value);
594 + strcat(command_line, " ");
595 + strcat(command_line, string);
598 + ptr = strstr(command_line, string);
600 + start_off = ptr - command_line;
601 + ptr += strlen(string);
602 + while ((*ptr != ' ') && (*ptr != '\0'))
604 + end_off = ptr - command_line;
605 + command_line[start_off] = '\0';
606 + strcat (command_line, command_line+end_off);
612 +EXPORT_SYMBOL(vpe1_set_boot_param);
614 +int32_t vpe1_get_boot_param(char *field, char **value, char flags)
616 + char *ptr, string[64];
620 + if ((ptr = strstr(command_line, field))) {
621 + ptr += strlen(field) + 1; /* including = */
622 + while ((*ptr != ' ') && (*ptr != '\0'))
623 + string[i++] = *ptr++;
625 + *value = kmalloc((strlen(string) + 1), GFP_KERNEL);
626 + if (*value != NULL)
627 + strcpy(*value, string);
635 +EXPORT_SYMBOL(vpe1_get_boot_param);
637 +extern void configure_tlb(void);
640 static ssize_t store_kill(struct device *dev, struct device_attribute *attr,
641 const char *buf, size_t len)
642 @@ -1432,6 +1661,18 @@
643 printk("VPE loader: not a MIPS MT capable processor\n");
646 +#ifdef CONFIG_IFX_VPE_EXT
647 +#ifndef CONFIG_MIPS_MT_SMTC
652 +#ifndef CONFIG_MIPS_MT_SMTC
660 printk(KERN_WARNING "No VPEs reserved for AP/SP, not "
661 @@ -1476,10 +1717,12 @@
665 + back_to_back_c0_hazard();
667 /* Put MVPE's into 'configuration state' */
668 set_c0_mvpcontrol(MVPCONTROL_VPC);
670 - /* dump_mtregs(); */
673 val = read_c0_mvpconf0();
674 hw_tcs = (val & MVPCONF0_PTC) + 1;
675 @@ -1491,6 +1734,7 @@
676 * reschedule send IPIs or similar we might hang.
678 clear_c0_mvpcontrol(MVPCONTROL_VPC);
679 + back_to_back_c0_hazard();
682 local_irq_restore(flags);
683 @@ -1516,6 +1760,7 @@
686 v->ntcs = hw_tcs - tclimit;
687 + write_tc_c0_tcbind((read_tc_c0_tcbind() & ~TCBIND_CURVPE) | 1);
689 /* add the tc to the list of this vpe's tc's. */
690 list_add(&t->tc, &v->tc);
691 @@ -1584,6 +1829,7 @@
693 /* release config state */
694 clear_c0_mvpcontrol(MVPCONTROL_VPC);
695 + back_to_back_c0_hazard();
700 +++ b/arch/mips/kernel/mtsched_proc.c
703 + * /proc hooks for MIPS MT scheduling policy management for 34K cores
705 + * This program is free software; you can distribute it and/or modify it
706 + * under the terms of the GNU General Public License (Version 2) as
707 + * published by the Free Software Foundation.
709 + * This program is distributed in the hope it will be useful, but WITHOUT
710 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
711 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
712 + * for more details.
714 + * You should have received a copy of the GNU General Public License along
715 + * with this program; if not, write to the Free Software Foundation, Inc.,
716 + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
718 + * Copyright (C) 2006 Mips Technologies, Inc
721 +#include <linux/kernel.h>
723 +#include <asm/cpu.h>
724 +#include <asm/processor.h>
725 +#include <asm/system.h>
726 +#include <asm/mipsregs.h>
727 +#include <asm/mipsmtregs.h>
728 +#include <asm/uaccess.h>
729 +#include <linux/proc_fs.h>
731 +static struct proc_dir_entry *mtsched_proc;
733 +#ifndef CONFIG_MIPS_MT_SMTC
736 +#define NTCS NR_CPUS
743 +static int proc_read_mtsched(char *page, char **start, off_t off,
744 + int count, int *eof, void *data)
752 + unsigned long flags;
753 + unsigned int mtflags;
754 + unsigned int haltstate;
755 + unsigned int vpes_checked[NVPES];
756 + unsigned int vpeschedule[NVPES];
757 + unsigned int vpeschefback[NVPES];
758 + unsigned int tcschedule[NTCS];
759 + unsigned int tcschefback[NTCS];
761 + /* Dump the state of the MIPS MT scheduling policy manager */
762 + /* Inititalize control state */
763 + for(i = 0; i < NVPES; i++) {
764 + vpes_checked[i] = 0;
765 + vpeschedule[i] = 0;
766 + vpeschefback[i] = 0;
768 + for(i = 0; i < NTCS; i++) {
770 + tcschefback[i] = 0;
773 + /* Disable interrupts and multithreaded issue */
774 + local_irq_save(flags);
777 + /* Then go through the TCs, halt 'em, and extract the values */
778 + mytc = (read_c0_tcbind() & TCBIND_CURTC) >> TCBIND_CURTC_SHIFT;
779 + for(i = 0; i < NTCS; i++) {
781 + /* No need to halt ourselves! */
782 + tcschedule[i] = read_c0_tcschedule();
783 + tcschefback[i] = read_c0_tcschefback();
784 + /* If VPE bound to TC hasn't been checked, do it */
785 + vpe = read_c0_tcbind() & TCBIND_CURVPE;
786 + if(!vpes_checked[vpe]) {
787 + vpeschedule[vpe] = read_c0_vpeschedule();
788 + vpeschefback[vpe] = read_c0_vpeschefback();
789 + vpes_checked[vpe] = 1;
793 + haltstate = read_tc_c0_tchalt();
794 + write_tc_c0_tchalt(TCHALT_H);
796 + tcschedule[i] = read_tc_c0_tcschedule();
797 + tcschefback[i] = read_tc_c0_tcschefback();
798 + /* If VPE bound to TC hasn't been checked, do it */
799 + vpe = read_tc_c0_tcbind() & TCBIND_CURVPE;
800 + if(!vpes_checked[vpe]) {
801 + vpeschedule[vpe] = read_vpe_c0_vpeschedule();
802 + vpeschefback[vpe] = read_vpe_c0_vpeschefback();
803 + vpes_checked[vpe] = 1;
805 + if(!haltstate) write_tc_c0_tchalt(0);
808 + /* Re-enable MT and interrupts */
810 + local_irq_restore(flags);
812 + for(vpe=0; vpe < NVPES; vpe++) {
813 + len = sprintf(page, "VPE[%d].VPEschedule = 0x%08x\n",
814 + vpe, vpeschedule[vpe]);
817 + len = sprintf(page, "VPE[%d].VPEschefback = 0x%08x\n",
818 + vpe, vpeschefback[vpe]);
822 + for(i=0; i < NTCS; i++) {
823 + len = sprintf(page, "TC[%d].TCschedule = 0x%08x\n",
827 + len = sprintf(page, "TC[%d].TCschefback = 0x%08x\n",
828 + i, tcschefback[i]);
836 + * Write to perf counter registers based on text input
839 +#define TXTBUFSZ 100
841 +static int proc_write_mtsched(struct file *file, const char *buffer,
842 + unsigned long count, void *data)
845 + char mybuf[TXTBUFSZ];
846 + /* At most, we will set up 9 TCs and 2 VPEs, 11 entries in all */
847 + char entity[1]; //, entity1[1];
849 + unsigned long value[1];
850 + int nparsed = 0 , index = 0;
851 + unsigned long flags;
852 + unsigned int mtflags;
853 + unsigned int haltstate;
854 + unsigned int tcbindval;
856 + if(count >= TXTBUFSZ) len = TXTBUFSZ-1;
858 + memset(mybuf,0,TXTBUFSZ);
859 + if(copy_from_user(mybuf, buffer, len)) return -EFAULT;
861 + nparsed = sscanf(mybuf, "%c%d %lx",
862 + &entity[0] ,&number[0], &value[0]);
865 + * Having acquired the inputs, which might have
866 + * generated exceptions and preemptions,
867 + * program the registers.
869 + /* Disable interrupts and multithreaded issue */
870 + local_irq_save(flags);
873 + if(entity[index] == 't' ) {
874 + /* Set TCSchedule or TCScheFBack of specified TC */
875 + if(number[index] > NTCS) goto skip;
876 + /* If it's our own TC, do it direct */
877 + if(number[index] ==
878 + ((read_c0_tcbind() & TCBIND_CURTC)
879 + >> TCBIND_CURTC_SHIFT)) {
880 + if(entity[index] == 't')
881 + write_c0_tcschedule(value[index]);
883 + write_c0_tcschefback(value[index]);
885 + /* Otherwise, we do it via MTTR */
886 + settc(number[index]);
887 + haltstate = read_tc_c0_tchalt();
888 + write_tc_c0_tchalt(TCHALT_H);
890 + if(entity[index] == 't')
891 + write_tc_c0_tcschedule(value[index]);
893 + write_tc_c0_tcschefback(value[index]);
895 + if(!haltstate) write_tc_c0_tchalt(0);
897 + } else if(entity[index] == 'v') {
898 + /* Set VPESchedule of specified VPE */
899 + if(number[index] > NVPES) goto skip;
900 + tcbindval = read_c0_tcbind();
901 + /* Are we doing this to our current VPE? */
902 + if((tcbindval & TCBIND_CURVPE) == number[index]) {
903 + /* Then life is simple */
904 + write_c0_vpeschedule(value[index]);
907 + * Bind ourselves to the other VPE long enough
908 + * to program the bind value.
910 + write_c0_tcbind((tcbindval & ~TCBIND_CURVPE)
913 + write_c0_vpeschedule(value[index]);
915 + /* Restore previous binding */
916 + write_c0_tcbind(tcbindval);
921 + else if(entity[index] == 'r') {
922 + unsigned int vpes_checked[2], vpe ,i , mytc;
923 + vpes_checked[0] = vpes_checked[1] = 0;
925 + /* Then go through the TCs, halt 'em, and extract the values */
926 + mytc = (read_c0_tcbind() & TCBIND_CURTC) >> TCBIND_CURTC_SHIFT;
928 + for(i = 0; i < NTCS; i++) {
930 + /* No need to halt ourselves! */
931 + write_c0_vpeschefback(0);
932 + write_c0_tcschefback(0);
935 + haltstate = read_tc_c0_tchalt();
936 + write_tc_c0_tchalt(TCHALT_H);
938 + write_tc_c0_tcschefback(0);
939 + /* If VPE bound to TC hasn't been checked, do it */
940 + vpe = read_tc_c0_tcbind() & TCBIND_CURVPE;
941 + if(!vpes_checked[vpe]) {
942 + write_vpe_c0_vpeschefback(0);
943 + vpes_checked[vpe] = 1;
945 + if(!haltstate) write_tc_c0_tchalt(0);
950 + printk ("\n Usage : <t/v><0/1> <Hex Value>\n Example : t0 0x01\n");
954 + /* Re-enable MT and interrupts */
956 + local_irq_restore(flags);
960 +static int __init init_mtsched_proc(void)
962 + extern struct proc_dir_entry *get_mips_proc_dir(void);
963 + struct proc_dir_entry *mips_proc_dir;
965 + if (!cpu_has_mipsmt) {
966 + printk("mtsched: not a MIPS MT capable processor\n");
970 + mips_proc_dir = get_mips_proc_dir();
972 + mtsched_proc = create_proc_entry("mtsched", 0644, mips_proc_dir);
973 + mtsched_proc->read_proc = proc_read_mtsched;
974 + mtsched_proc->write_proc = proc_write_mtsched;
979 +/* Automagically create the entry */
980 +module_init(init_mtsched_proc);
982 +++ b/arch/mips/kernel/perf_proc.c
985 + * /proc hooks for CPU performance counter support for SMTC kernel
986 + * (and ultimately others)
987 + * Copyright (C) 2006 Mips Technologies, Inc
990 +#include <linux/kernel.h>
992 +#include <asm/cpu.h>
993 +#include <asm/processor.h>
994 +#include <asm/system.h>
995 +#include <asm/mipsregs.h>
996 +#include <asm/uaccess.h>
997 +#include <linux/proc_fs.h>
1000 + * /proc diagnostic and statistics hooks
1004 +/* Internal software-extended event counters */
1006 +static unsigned long long extencount[4] = {0,0,0,0};
1008 +static struct proc_dir_entry *perf_proc;
1010 +static int proc_read_perf(char *page, char **start, off_t off,
1011 + int count, int *eof, void *data)
1016 + len = sprintf(page, "PerfCnt[0].Ctl : 0x%08x\n", read_c0_perfctrl0());
1019 + len = sprintf(page, "PerfCnt[0].Cnt : %Lu\n",
1020 + extencount[0] + (unsigned long long)((unsigned)read_c0_perfcntr0()));
1023 + len = sprintf(page, "PerfCnt[1].Ctl : 0x%08x\n", read_c0_perfctrl1());
1026 + len = sprintf(page, "PerfCnt[1].Cnt : %Lu\n",
1027 + extencount[1] + (unsigned long long)((unsigned)read_c0_perfcntr1()));
1030 + len = sprintf(page, "PerfCnt[2].Ctl : 0x%08x\n", read_c0_perfctrl2());
1033 + len = sprintf(page, "PerfCnt[2].Cnt : %Lu\n",
1034 + extencount[2] + (unsigned long long)((unsigned)read_c0_perfcntr2()));
1037 + len = sprintf(page, "PerfCnt[3].Ctl : 0x%08x\n", read_c0_perfctrl3());
1040 + len = sprintf(page, "PerfCnt[3].Cnt : %Lu\n",
1041 + extencount[3] + (unsigned long long)((unsigned)read_c0_perfcntr3()));
1049 + * Write to perf counter registers based on text input
1052 +#define TXTBUFSZ 100
1054 +static int proc_write_perf(struct file *file, const char *buffer,
1055 + unsigned long count, void *data)
1060 + char mybuf[TXTBUFSZ];
1063 + unsigned long control[4];
1064 + long long ctrdata[4];
1066 + if(count >= TXTBUFSZ) len = TXTBUFSZ-1;
1068 + memset(mybuf,0,TXTBUFSZ);
1069 + if(copy_from_user(mybuf, buffer, len)) return -EFAULT;
1071 + nparsed = sscanf(mybuf,
1072 + "%d %lx %Ld %d %lx %Ld %d %lx %Ld %d %lx %Ld",
1073 + &which[0], &control[0], &ctrdata[0],
1074 + &which[1], &control[1], &ctrdata[1],
1075 + &which[2], &control[2], &ctrdata[2],
1076 + &which[3], &control[3], &ctrdata[3]);
1078 + for(index = 0; nparsed >= 3; index++) {
1079 + switch (which[index]) {
1081 + write_c0_perfctrl0(control[index]);
1082 + if(ctrdata[index] != -1) {
1083 + extencount[0] = (unsigned long long)ctrdata[index];
1084 + write_c0_perfcntr0((unsigned long)0);
1088 + write_c0_perfctrl1(control[index]);
1089 + if(ctrdata[index] != -1) {
1090 + extencount[1] = (unsigned long long)ctrdata[index];
1091 + write_c0_perfcntr1((unsigned long)0);
1095 + write_c0_perfctrl2(control[index]);
1096 + if(ctrdata[index] != -1) {
1097 + extencount[2] = (unsigned long long)ctrdata[index];
1098 + write_c0_perfcntr2((unsigned long)0);
1102 + write_c0_perfctrl3(control[index]);
1103 + if(ctrdata[index] != -1) {
1104 + extencount[3] = (unsigned long long)ctrdata[index];
1105 + write_c0_perfcntr3((unsigned long)0);
1114 +extern int (*perf_irq)(void);
1117 + * Invoked when timer interrupt vector picks up a perf counter overflow
1120 +static int perf_proc_irq(void)
1122 + unsigned long snapshot;
1125 + * It would be nice to do this as a loop, but we don't have
1126 + * indirect access to CP0 registers.
1128 + snapshot = read_c0_perfcntr0();
1129 + if ((long)snapshot < 0) {
1131 + (unsigned long long)((unsigned)read_c0_perfcntr0());
1132 + write_c0_perfcntr0(0);
1134 + snapshot = read_c0_perfcntr1();
1135 + if ((long)snapshot < 0) {
1137 + (unsigned long long)((unsigned)read_c0_perfcntr1());
1138 + write_c0_perfcntr1(0);
1140 + snapshot = read_c0_perfcntr2();
1141 + if ((long)snapshot < 0) {
1143 + (unsigned long long)((unsigned)read_c0_perfcntr2());
1144 + write_c0_perfcntr2(0);
1146 + snapshot = read_c0_perfcntr3();
1147 + if ((long)snapshot < 0) {
1149 + (unsigned long long)((unsigned)read_c0_perfcntr3());
1150 + write_c0_perfcntr3(0);
1155 +static int __init init_perf_proc(void)
1157 + extern struct proc_dir_entry *get_mips_proc_dir(void);
1159 + struct proc_dir_entry *mips_proc_dir = get_mips_proc_dir();
1161 + write_c0_perfcntr0(0);
1162 + write_c0_perfcntr1(0);
1163 + write_c0_perfcntr2(0);
1164 + write_c0_perfcntr3(0);
1165 + perf_proc = create_proc_entry("perf", 0644, mips_proc_dir);
1166 + perf_proc->read_proc = proc_read_perf;
1167 + perf_proc->write_proc = proc_write_perf;
1168 + perf_irq = perf_proc_irq;
1173 +/* Automagically create the entry */
1174 +module_init(init_perf_proc);