1 diff -u -N -r linux-3.10.49.orig/arch/mips/include/asm/mipsmtregs.h linux-3.10.49/arch/mips/include/asm/mipsmtregs.h
2 --- linux-3.10.49.orig/arch/mips/include/asm/mipsmtregs.h 2014-10-15 21:41:48.000000000 +0200
3 +++ linux-3.10.49/arch/mips/include/asm/mipsmtregs.h 2014-10-15 21:44:25.000000000 +0200
5 #define read_c0_vpeconf1() __read_32bit_c0_register($1, 3)
6 #define write_c0_vpeconf1(val) __write_32bit_c0_register($1, 3, val)
8 +#define read_c0_vpeconf1() __read_32bit_c0_register($1, 3)
9 +#define write_c0_vpeconf1(val) __write_32bit_c0_register($1, 3, val)
11 +#define read_c0_vpeschedule() __read_32bit_c0_register($1, 5)
12 +#define write_c0_vpeschedule(val) __write_32bit_c0_register($1, 5, val)
14 +#define read_c0_vpeschefback() __read_32bit_c0_register($1, 6)
15 +#define write_c0_vpeschefback(val) __write_32bit_c0_register($1, 6, val)
17 +#define read_c0_vpeopt() __read_32bit_c0_register($1, 7)
18 +#define write_c0_vpeopt(val) __write_32bit_c0_register($1, 7, val)
20 #define read_c0_tcstatus() __read_32bit_c0_register($2, 1)
21 #define write_c0_tcstatus(val) __write_32bit_c0_register($2, 1, val)
23 #define read_c0_tcbind() __read_32bit_c0_register($2, 2)
24 +#define write_c0_tcbind(val) __write_32bit_c0_register($2, 2, val)
26 #define read_c0_tccontext() __read_32bit_c0_register($2, 5)
27 #define write_c0_tccontext(val) __write_32bit_c0_register($2, 5, val)
29 +#define read_c0_tcschedule() __read_32bit_c0_register($2, 6)
30 +#define write_c0_tcschedule(val) __write_32bit_c0_register($2, 6, val)
32 +#define read_c0_tcschefback() __read_32bit_c0_register($2, 7)
33 +#define write_c0_tcschefback(val) __write_32bit_c0_register($2, 7, val)
38 * Macros for use in assembly language code
40 #define MVPCONTROL_STLB_SHIFT 2
41 #define MVPCONTROL_STLB (_ULCAST_(1) << MVPCONTROL_STLB_SHIFT)
43 +#define MVPCONTROL_CPA_SHIFT 3
44 +#define MVPCONTROL_CPA (_ULCAST_(1) << MVPCONTROL_CPA_SHIFT)
47 #define MVPCONF0_PTC_SHIFT 0
49 #define MVPCONF0_TCA ( _ULCAST_(1) << MVPCONF0_TCA_SHIFT)
50 #define MVPCONF0_PTLBE_SHIFT 16
51 #define MVPCONF0_PTLBE (_ULCAST_(0x3ff) << MVPCONF0_PTLBE_SHIFT)
52 +#define MVPCONF0_PCP_SHIFT 27
53 +#define MVPCONF0_PCP (_ULCAST_(1) << MVPCONF0_PCP_SHIFT)
54 #define MVPCONF0_TLBS_SHIFT 29
55 #define MVPCONF0_TLBS (_ULCAST_(1) << MVPCONF0_TLBS_SHIFT)
56 #define MVPCONF0_M_SHIFT 31
58 #define VPECONF0_VPA (_ULCAST_(1) << VPECONF0_VPA_SHIFT)
59 #define VPECONF0_MVP_SHIFT 1
60 #define VPECONF0_MVP (_ULCAST_(1) << VPECONF0_MVP_SHIFT)
61 +#define VPECONF0_ICS_SHIFT 16
62 +#define VPECONF0_ICS (_ULCAST_(1) << VPECONF0_ICS_SHIFT)
63 +#define VPECONF0_DCS_SHIFT 17
64 +#define VPECONF0_DCS (_ULCAST_(1) << VPECONF0_DCS_SHIFT)
65 #define VPECONF0_XTC_SHIFT 21
66 #define VPECONF0_XTC (_ULCAST_(0xff) << VPECONF0_XTC_SHIFT)
69 +#define VPEOPT_DWX_SHIFT 0
70 +#define VPEOPT_IWX_SHIFT 8
71 +#define VPEOPT_IWX0 ( _ULCAST_(0x1) << VPEOPT_IWX_SHIFT)
72 +#define VPEOPT_IWX1 ( _ULCAST_(0x2) << VPEOPT_IWX_SHIFT)
73 +#define VPEOPT_IWX2 ( _ULCAST_(0x4) << VPEOPT_IWX_SHIFT)
74 +#define VPEOPT_IWX3 ( _ULCAST_(0x8) << VPEOPT_IWX_SHIFT)
75 +#define VPEOPT_DWX0 ( _ULCAST_(0x1) << VPEOPT_DWX_SHIFT)
76 +#define VPEOPT_DWX1 ( _ULCAST_(0x2) << VPEOPT_DWX_SHIFT)
77 +#define VPEOPT_DWX2 ( _ULCAST_(0x4) << VPEOPT_DWX_SHIFT)
78 +#define VPEOPT_DWX3 ( _ULCAST_(0x8) << VPEOPT_DWX_SHIFT)
80 /* VPEConf1 fields (per VPE) */
81 #define VPECONF1_NCP1_SHIFT 0
82 #define VPECONF1_NCP1 (_ULCAST_(0xff) << VPECONF1_NCP1_SHIFT)
84 #define write_vpe_c0_vpeconf0(val) mttc0(1, 2, val)
85 #define read_vpe_c0_vpeconf1() mftc0(1, 3)
86 #define write_vpe_c0_vpeconf1(val) mttc0(1, 3, val)
87 +#define read_vpe_c0_vpeschedule() mftc0(1, 5)
88 +#define write_vpe_c0_vpeschedule(val) mttc0(1, 5, val)
89 +#define read_vpe_c0_vpeschefback() mftc0(1, 6)
90 +#define write_vpe_c0_vpeschefback(val) mttc0(1, 6, val)
91 +#define read_vpe_c0_vpeopt() mftc0(1, 7)
92 +#define write_vpe_c0_vpeopt(val) mttc0(1, 7, val)
93 +#define read_vpe_c0_wired() mftc0(6, 0)
94 +#define write_vpe_c0_wired(val) mttc0(6, 0, val)
95 #define read_vpe_c0_count() mftc0(9, 0)
96 #define write_vpe_c0_count(val) mttc0(9, 0, val)
97 #define read_vpe_c0_status() mftc0(12, 0)
99 #define write_tc_c0_tchalt(val) mttc0(2, 4, val)
100 #define read_tc_c0_tccontext() mftc0(2, 5)
101 #define write_tc_c0_tccontext(val) mttc0(2, 5, val)
102 +#define read_tc_c0_tcschedule() mftc0(2, 6)
103 +#define write_tc_c0_tcschedule(val) mttc0(2, 6, val)
104 +#define read_tc_c0_tcschefback() mftc0(2, 7)
105 +#define write_tc_c0_tcschefback(val) mttc0(2, 7, val)
106 +#define read_tc_c0_entryhi() mftc0(10, 0)
107 +#define write_tc_c0_entryhi(val) mttc0(10, 0, val)
110 #define read_tc_gpr_sp() mftgpr(29)
111 diff -u -N -r linux-3.10.49.orig/arch/mips/Kconfig linux-3.10.49/arch/mips/Kconfig
112 --- linux-3.10.49.orig/arch/mips/Kconfig 2014-10-15 21:41:48.000000000 +0200
113 +++ linux-3.10.49/arch/mips/Kconfig 2014-10-15 21:44:25.000000000 +0200
114 @@ -1992,6 +1992,28 @@
115 Includes a loader for loading an elf relocatable object
116 onto another VPE and running it.
119 + bool "IFX APRP Extensions"
120 + depends on MIPS_VPE_LOADER
123 + IFX included extensions in APRP
126 + bool "34K Performance counters"
127 + depends on MIPS_MT && PROC_FS
130 + 34K Performance counter through /proc
133 + bool "Support mtsched priority configuration for TCs"
134 + depends on MIPS_MT && PROC_FS
137 + Support for mtsched priority configuration for TCs through
140 config MIPS_MT_SMTC_IM_BACKSTOP
141 bool "Use per-TC register bits as backstop for inhibited IM bits"
142 depends on MIPS_MT_SMTC
143 diff -u -N -r linux-3.10.49.orig/arch/mips/kernel/Makefile linux-3.10.49/arch/mips/kernel/Makefile
144 --- linux-3.10.49.orig/arch/mips/kernel/Makefile 2014-10-15 21:41:48.000000000 +0200
145 +++ linux-3.10.49/arch/mips/kernel/Makefile 2014-10-15 21:44:25.000000000 +0200
148 obj-$(CONFIG_KGDB) += kgdb.o
149 obj-$(CONFIG_PROC_FS) += proc.o
151 +obj-$(CONFIG_MTSCHED) += mtsched_proc.o
152 +obj-$(CONFIG_PERFCTRS) += perf_proc.o
153 obj-$(CONFIG_64BIT) += cpu-bugs64.o
155 obj-$(CONFIG_I8253) += i8253.o
156 diff -u -N -r linux-3.10.49.orig/arch/mips/kernel/mips-mt.c linux-3.10.49/arch/mips/kernel/mips-mt.c
157 --- linux-3.10.49.orig/arch/mips/kernel/mips-mt.c 2014-10-15 21:41:48.000000000 +0200
158 +++ linux-3.10.49/arch/mips/kernel/mips-mt.c 2014-10-15 21:44:25.000000000 +0200
160 #include <asm/cacheflush.h>
164 static int __init maxvpes(char *str)
166 get_option(&str, &vpelimit);
171 __setup("maxvpes=", maxvpes);
175 static int __init maxtcs(char *str)
177 get_option(&str, &tclimit);
180 +__setup("maxtcs=", maxtcs);
182 +#ifdef CONFIG_IFX_VPE_EXT
184 +static int __init istlbshared(char *str)
186 + get_option(&str, &stlb);
189 +__setup("vpe_tlb_shared=", istlbshared);
191 -__setup("maxtcs=", maxtcs);
193 +static int __init vpe0wired(char *str)
195 + get_option(&str, &vpe0_wired);
198 +__setup("vpe0_wired_tlb_entries=", vpe0wired);
201 +static int __init vpe1wired(char *str)
203 + get_option(&str, &vpe1_wired);
206 +__setup("vpe1_wired_tlb_entries=", vpe1wired);
208 +#ifdef CONFIG_MIPS_MT_SMTC
211 +void configure_tlb(void)
213 + int vpeflags, tcflags, tlbsiz;
214 + unsigned int config1val;
217 + write_c0_vpeconf0((read_c0_vpeconf0() | VPECONF0_MVP));
218 + write_c0_mvpcontrol((read_c0_mvpcontrol() | MVPCONTROL_VPC));
220 + //printk("stlb = %d, vpe0_wired = %d vpe1_wired=%d\n", stlb,vpe0_wired, vpe1_wired);
222 + if (!(read_c0_mvpconf0() & MVPCONF0_TLBS)) {
228 + write_c0_mvpcontrol(read_c0_mvpcontrol() | MVPCONTROL_STLB);
229 + write_c0_wired(vpe0_wired + vpe1_wired);
230 + if (((read_vpe_c0_config() & MIPS_CONF_MT) >> 7) == 1) {
231 + config1val = read_vpe_c0_config1();
232 + tlbsiz = (((config1val >> 25) & 0x3f) + 1);
235 + cpu_data[0].tlbsize = tlbsiz;
236 + current_cpu_data.tlbsize = tlbsiz;
241 + write_c0_mvpcontrol(read_c0_mvpcontrol() & ~MVPCONTROL_STLB);
242 + write_c0_wired(vpe0_wired);
246 + write_c0_mvpcontrol((read_c0_mvpcontrol() & ~MVPCONTROL_VPC));
248 + local_flush_tlb_all();
250 + printk("Wired TLB entries for Linux read_c0_wired() = %d\n", read_c0_wired());
251 +#ifdef CONFIG_MIPS_MT_SMTC
260 * Dump new MIPS MT state for the core. Does not leave TCs halted.
262 if ((read_tc_c0_tcbind() & TCBIND_CURVPE) == i) {
263 printk(" VPE %d\n", i);
264 printk(" VPEControl : %08lx\n",
265 - read_vpe_c0_vpecontrol());
266 + read_vpe_c0_vpecontrol());
267 printk(" VPEConf0 : %08lx\n",
268 - read_vpe_c0_vpeconf0());
269 + read_vpe_c0_vpeconf0());
270 printk(" VPE%d.Status : %08lx\n",
271 - i, read_vpe_c0_status());
272 + i, read_vpe_c0_status());
273 printk(" VPE%d.EPC : %08lx %pS\n",
274 - i, read_vpe_c0_epc(),
275 - (void *) read_vpe_c0_epc());
276 + i, read_vpe_c0_epc(),
277 + (void *) read_vpe_c0_epc());
278 printk(" VPE%d.Cause : %08lx\n",
279 - i, read_vpe_c0_cause());
280 + i, read_vpe_c0_cause());
281 printk(" VPE%d.Config7 : %08lx\n",
282 - i, read_vpe_c0_config7());
283 + i, read_vpe_c0_config7());
284 break; /* Next VPE */
288 printk("Mapped %ld ITC cells starting at 0x%08x\n",
289 ((itcblkgrn & 0x7fe00000) >> 20), itc_base);
291 +#ifdef CONFIG_IFX_VPE_EXT
297 diff -u -N -r linux-3.10.49.orig/arch/mips/kernel/mtsched_proc.c linux-3.10.49/arch/mips/kernel/mtsched_proc.c
298 --- linux-3.10.49.orig/arch/mips/kernel/mtsched_proc.c 1970-01-01 01:00:00.000000000 +0100
299 +++ linux-3.10.49/arch/mips/kernel/mtsched_proc.c 2014-10-15 21:44:25.000000000 +0200
302 + * /proc hooks for MIPS MT scheduling policy management for 34K cores
304 + * This program is free software; you can distribute it and/or modify it
305 + * under the terms of the GNU General Public License (Version 2) as
306 + * published by the Free Software Foundation.
308 + * This program is distributed in the hope it will be useful, but WITHOUT
309 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
310 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
311 + * for more details.
313 + * You should have received a copy of the GNU General Public License along
314 + * with this program; if not, write to the Free Software Foundation, Inc.,
315 + * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
317 + * Copyright (C) 2006 Mips Technologies, Inc
320 +#include <linux/kernel.h>
322 +#include <asm/cpu.h>
323 +#include <asm/processor.h>
324 +#include <asm/system.h>
325 +#include <asm/mipsregs.h>
326 +#include <asm/mipsmtregs.h>
327 +#include <asm/uaccess.h>
328 +#include <linux/proc_fs.h>
330 +static struct proc_dir_entry *mtsched_proc;
332 +#ifndef CONFIG_MIPS_MT_SMTC
335 +#define NTCS NR_CPUS
342 +static int proc_read_mtsched(char *page, char **start, off_t off,
343 + int count, int *eof, void *data)
351 + unsigned long flags;
352 + unsigned int mtflags;
353 + unsigned int haltstate;
354 + unsigned int vpes_checked[NVPES];
355 + unsigned int vpeschedule[NVPES];
356 + unsigned int vpeschefback[NVPES];
357 + unsigned int tcschedule[NTCS];
358 + unsigned int tcschefback[NTCS];
360 + /* Dump the state of the MIPS MT scheduling policy manager */
361 + /* Inititalize control state */
362 + for(i = 0; i < NVPES; i++) {
363 + vpes_checked[i] = 0;
364 + vpeschedule[i] = 0;
365 + vpeschefback[i] = 0;
367 + for(i = 0; i < NTCS; i++) {
369 + tcschefback[i] = 0;
372 + /* Disable interrupts and multithreaded issue */
373 + local_irq_save(flags);
376 + /* Then go through the TCs, halt 'em, and extract the values */
377 + mytc = (read_c0_tcbind() & TCBIND_CURTC) >> TCBIND_CURTC_SHIFT;
378 + for(i = 0; i < NTCS; i++) {
380 + /* No need to halt ourselves! */
381 + tcschedule[i] = read_c0_tcschedule();
382 + tcschefback[i] = read_c0_tcschefback();
383 + /* If VPE bound to TC hasn't been checked, do it */
384 + vpe = read_c0_tcbind() & TCBIND_CURVPE;
385 + if(!vpes_checked[vpe]) {
386 + vpeschedule[vpe] = read_c0_vpeschedule();
387 + vpeschefback[vpe] = read_c0_vpeschefback();
388 + vpes_checked[vpe] = 1;
392 + haltstate = read_tc_c0_tchalt();
393 + write_tc_c0_tchalt(TCHALT_H);
395 + tcschedule[i] = read_tc_c0_tcschedule();
396 + tcschefback[i] = read_tc_c0_tcschefback();
397 + /* If VPE bound to TC hasn't been checked, do it */
398 + vpe = read_tc_c0_tcbind() & TCBIND_CURVPE;
399 + if(!vpes_checked[vpe]) {
400 + vpeschedule[vpe] = read_vpe_c0_vpeschedule();
401 + vpeschefback[vpe] = read_vpe_c0_vpeschefback();
402 + vpes_checked[vpe] = 1;
404 + if(!haltstate) write_tc_c0_tchalt(0);
407 + /* Re-enable MT and interrupts */
409 + local_irq_restore(flags);
411 + for(vpe=0; vpe < NVPES; vpe++) {
412 + len = sprintf(page, "VPE[%d].VPEschedule = 0x%08x\n",
413 + vpe, vpeschedule[vpe]);
416 + len = sprintf(page, "VPE[%d].VPEschefback = 0x%08x\n",
417 + vpe, vpeschefback[vpe]);
421 + for(i=0; i < NTCS; i++) {
422 + len = sprintf(page, "TC[%d].TCschedule = 0x%08x\n",
426 + len = sprintf(page, "TC[%d].TCschefback = 0x%08x\n",
427 + i, tcschefback[i]);
435 + * Write to perf counter registers based on text input
438 +#define TXTBUFSZ 100
440 +static int proc_write_mtsched(struct file *file, const char *buffer,
441 + unsigned long count, void *data)
444 + char mybuf[TXTBUFSZ];
445 + /* At most, we will set up 9 TCs and 2 VPEs, 11 entries in all */
446 + char entity[1]; //, entity1[1];
448 + unsigned long value[1];
449 + int nparsed = 0 , index = 0;
450 + unsigned long flags;
451 + unsigned int mtflags;
452 + unsigned int haltstate;
453 + unsigned int tcbindval;
455 + if(count >= TXTBUFSZ) len = TXTBUFSZ-1;
457 + memset(mybuf,0,TXTBUFSZ);
458 + if(copy_from_user(mybuf, buffer, len)) return -EFAULT;
460 + nparsed = sscanf(mybuf, "%c%d %lx",
461 + &entity[0] ,&number[0], &value[0]);
464 + * Having acquired the inputs, which might have
465 + * generated exceptions and preemptions,
466 + * program the registers.
468 + /* Disable interrupts and multithreaded issue */
469 + local_irq_save(flags);
472 + if(entity[index] == 't' ) {
473 + /* Set TCSchedule or TCScheFBack of specified TC */
474 + if(number[index] > NTCS) goto skip;
475 + /* If it's our own TC, do it direct */
476 + if(number[index] ==
477 + ((read_c0_tcbind() & TCBIND_CURTC)
478 + >> TCBIND_CURTC_SHIFT)) {
479 + if(entity[index] == 't')
480 + write_c0_tcschedule(value[index]);
482 + write_c0_tcschefback(value[index]);
484 + /* Otherwise, we do it via MTTR */
485 + settc(number[index]);
486 + haltstate = read_tc_c0_tchalt();
487 + write_tc_c0_tchalt(TCHALT_H);
489 + if(entity[index] == 't')
490 + write_tc_c0_tcschedule(value[index]);
492 + write_tc_c0_tcschefback(value[index]);
494 + if(!haltstate) write_tc_c0_tchalt(0);
496 + } else if(entity[index] == 'v') {
497 + /* Set VPESchedule of specified VPE */
498 + if(number[index] > NVPES) goto skip;
499 + tcbindval = read_c0_tcbind();
500 + /* Are we doing this to our current VPE? */
501 + if((tcbindval & TCBIND_CURVPE) == number[index]) {
502 + /* Then life is simple */
503 + write_c0_vpeschedule(value[index]);
506 + * Bind ourselves to the other VPE long enough
507 + * to program the bind value.
509 + write_c0_tcbind((tcbindval & ~TCBIND_CURVPE)
512 + write_c0_vpeschedule(value[index]);
514 + /* Restore previous binding */
515 + write_c0_tcbind(tcbindval);
520 + else if(entity[index] == 'r') {
521 + unsigned int vpes_checked[2], vpe ,i , mytc;
522 + vpes_checked[0] = vpes_checked[1] = 0;
524 + /* Then go through the TCs, halt 'em, and extract the values */
525 + mytc = (read_c0_tcbind() & TCBIND_CURTC) >> TCBIND_CURTC_SHIFT;
527 + for(i = 0; i < NTCS; i++) {
529 + /* No need to halt ourselves! */
530 + write_c0_vpeschefback(0);
531 + write_c0_tcschefback(0);
534 + haltstate = read_tc_c0_tchalt();
535 + write_tc_c0_tchalt(TCHALT_H);
537 + write_tc_c0_tcschefback(0);
538 + /* If VPE bound to TC hasn't been checked, do it */
539 + vpe = read_tc_c0_tcbind() & TCBIND_CURVPE;
540 + if(!vpes_checked[vpe]) {
541 + write_vpe_c0_vpeschefback(0);
542 + vpes_checked[vpe] = 1;
544 + if(!haltstate) write_tc_c0_tchalt(0);
549 + printk ("\n Usage : <t/v><0/1> <Hex Value>\n Example : t0 0x01\n");
553 + /* Re-enable MT and interrupts */
555 + local_irq_restore(flags);
559 +static int __init init_mtsched_proc(void)
561 + extern struct proc_dir_entry *get_mips_proc_dir(void);
562 + struct proc_dir_entry *mips_proc_dir;
564 + if (!cpu_has_mipsmt) {
565 + printk("mtsched: not a MIPS MT capable processor\n");
569 + mips_proc_dir = get_mips_proc_dir();
571 + mtsched_proc = create_proc_entry("mtsched", 0644, mips_proc_dir);
572 + mtsched_proc->read_proc = proc_read_mtsched;
573 + mtsched_proc->write_proc = proc_write_mtsched;
578 +/* Automagically create the entry */
579 +module_init(init_mtsched_proc);
580 diff -u -N -r linux-3.10.49.orig/arch/mips/kernel/perf_proc.c linux-3.10.49/arch/mips/kernel/perf_proc.c
581 --- linux-3.10.49.orig/arch/mips/kernel/perf_proc.c 1970-01-01 01:00:00.000000000 +0100
582 +++ linux-3.10.49/arch/mips/kernel/perf_proc.c 2014-10-15 21:44:25.000000000 +0200
585 + * /proc hooks for CPU performance counter support for SMTC kernel
586 + * (and ultimately others)
587 + * Copyright (C) 2006 Mips Technologies, Inc
590 +#include <linux/kernel.h>
592 +#include <asm/cpu.h>
593 +#include <asm/processor.h>
594 +#include <asm/system.h>
595 +#include <asm/mipsregs.h>
596 +#include <asm/uaccess.h>
597 +#include <linux/proc_fs.h>
600 + * /proc diagnostic and statistics hooks
604 +/* Internal software-extended event counters */
606 +static unsigned long long extencount[4] = {0,0,0,0};
608 +static struct proc_dir_entry *perf_proc;
610 +static int proc_read_perf(char *page, char **start, off_t off,
611 + int count, int *eof, void *data)
616 + len = sprintf(page, "PerfCnt[0].Ctl : 0x%08x\n", read_c0_perfctrl0());
619 + len = sprintf(page, "PerfCnt[0].Cnt : %Lu\n",
620 + extencount[0] + (unsigned long long)((unsigned)read_c0_perfcntr0()));
623 + len = sprintf(page, "PerfCnt[1].Ctl : 0x%08x\n", read_c0_perfctrl1());
626 + len = sprintf(page, "PerfCnt[1].Cnt : %Lu\n",
627 + extencount[1] + (unsigned long long)((unsigned)read_c0_perfcntr1()));
630 + len = sprintf(page, "PerfCnt[2].Ctl : 0x%08x\n", read_c0_perfctrl2());
633 + len = sprintf(page, "PerfCnt[2].Cnt : %Lu\n",
634 + extencount[2] + (unsigned long long)((unsigned)read_c0_perfcntr2()));
637 + len = sprintf(page, "PerfCnt[3].Ctl : 0x%08x\n", read_c0_perfctrl3());
640 + len = sprintf(page, "PerfCnt[3].Cnt : %Lu\n",
641 + extencount[3] + (unsigned long long)((unsigned)read_c0_perfcntr3()));
649 + * Write to perf counter registers based on text input
652 +#define TXTBUFSZ 100
654 +static int proc_write_perf(struct file *file, const char *buffer,
655 + unsigned long count, void *data)
660 + char mybuf[TXTBUFSZ];
663 + unsigned long control[4];
664 + long long ctrdata[4];
666 + if(count >= TXTBUFSZ) len = TXTBUFSZ-1;
668 + memset(mybuf,0,TXTBUFSZ);
669 + if(copy_from_user(mybuf, buffer, len)) return -EFAULT;
671 + nparsed = sscanf(mybuf,
672 + "%d %lx %Ld %d %lx %Ld %d %lx %Ld %d %lx %Ld",
673 + &which[0], &control[0], &ctrdata[0],
674 + &which[1], &control[1], &ctrdata[1],
675 + &which[2], &control[2], &ctrdata[2],
676 + &which[3], &control[3], &ctrdata[3]);
678 + for(index = 0; nparsed >= 3; index++) {
679 + switch (which[index]) {
681 + write_c0_perfctrl0(control[index]);
682 + if(ctrdata[index] != -1) {
683 + extencount[0] = (unsigned long long)ctrdata[index];
684 + write_c0_perfcntr0((unsigned long)0);
688 + write_c0_perfctrl1(control[index]);
689 + if(ctrdata[index] != -1) {
690 + extencount[1] = (unsigned long long)ctrdata[index];
691 + write_c0_perfcntr1((unsigned long)0);
695 + write_c0_perfctrl2(control[index]);
696 + if(ctrdata[index] != -1) {
697 + extencount[2] = (unsigned long long)ctrdata[index];
698 + write_c0_perfcntr2((unsigned long)0);
702 + write_c0_perfctrl3(control[index]);
703 + if(ctrdata[index] != -1) {
704 + extencount[3] = (unsigned long long)ctrdata[index];
705 + write_c0_perfcntr3((unsigned long)0);
714 +extern int (*perf_irq)(void);
717 + * Invoked when timer interrupt vector picks up a perf counter overflow
720 +static int perf_proc_irq(void)
722 + unsigned long snapshot;
725 + * It would be nice to do this as a loop, but we don't have
726 + * indirect access to CP0 registers.
728 + snapshot = read_c0_perfcntr0();
729 + if ((long)snapshot < 0) {
731 + (unsigned long long)((unsigned)read_c0_perfcntr0());
732 + write_c0_perfcntr0(0);
734 + snapshot = read_c0_perfcntr1();
735 + if ((long)snapshot < 0) {
737 + (unsigned long long)((unsigned)read_c0_perfcntr1());
738 + write_c0_perfcntr1(0);
740 + snapshot = read_c0_perfcntr2();
741 + if ((long)snapshot < 0) {
743 + (unsigned long long)((unsigned)read_c0_perfcntr2());
744 + write_c0_perfcntr2(0);
746 + snapshot = read_c0_perfcntr3();
747 + if ((long)snapshot < 0) {
749 + (unsigned long long)((unsigned)read_c0_perfcntr3());
750 + write_c0_perfcntr3(0);
755 +static int __init init_perf_proc(void)
757 + extern struct proc_dir_entry *get_mips_proc_dir(void);
759 + struct proc_dir_entry *mips_proc_dir = get_mips_proc_dir();
761 + write_c0_perfcntr0(0);
762 + write_c0_perfcntr1(0);
763 + write_c0_perfcntr2(0);
764 + write_c0_perfcntr3(0);
765 + perf_proc = create_proc_entry("perf", 0644, mips_proc_dir);
766 + perf_proc->read_proc = proc_read_perf;
767 + perf_proc->write_proc = proc_write_perf;
768 + perf_irq = perf_proc_irq;
773 +/* Automagically create the entry */
774 +module_init(init_perf_proc);
775 diff -u -N -r linux-3.10.49.orig/arch/mips/kernel/proc.c linux-3.10.49/arch/mips/kernel/proc.c
776 --- linux-3.10.49.orig/arch/mips/kernel/proc.c 2014-10-15 21:41:48.000000000 +0200
777 +++ linux-3.10.49/arch/mips/kernel/proc.c 2014-10-15 21:44:25.000000000 +0200
779 #include <linux/kernel.h>
780 #include <linux/sched.h>
781 #include <linux/seq_file.h>
782 +#include <linux/proc_fs.h>
783 #include <asm/bootinfo.h>
785 #include <asm/cpu-features.h>
788 .show = show_cpuinfo,
792 + * Support for MIPS/local /proc hooks in /proc/mips/
795 +static struct proc_dir_entry *mips_proc = NULL;
797 +struct proc_dir_entry *get_mips_proc_dir(void)
800 + * This ought not to be preemptable.
802 + if(mips_proc == NULL)
803 + mips_proc = proc_mkdir("mips", NULL);
806 diff -u -N -r linux-3.10.49.orig/arch/mips/kernel/prom.c linux-3.10.49/arch/mips/kernel/prom.c
807 --- linux-3.10.49.orig/arch/mips/kernel/prom.c 2014-10-15 21:41:48.000000000 +0200
808 +++ linux-3.10.49/arch/mips/kernel/prom.c 2014-10-15 21:45:47.000000000 +0200
810 return mips_machine_name;
813 +unsigned long physical_memsize = 0L;
816 int __init early_init_dt_scan_memory_arch(unsigned long node,
817 const char *uname, int depth,
819 void __init early_init_dt_add_memory_arch(u64 base, u64 size)
821 return add_memory_region(base, size, BOOT_MEM_RAM);
822 + physical_memsize = size;
825 void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
826 diff -u -N -r linux-3.10.49.orig/arch/mips/kernel/smtc.c linux-3.10.49/arch/mips/kernel/smtc.c
827 --- linux-3.10.49.orig/arch/mips/kernel/smtc.c 2014-10-15 21:41:48.000000000 +0200
828 +++ linux-3.10.49/arch/mips/kernel/smtc.c 2014-10-15 21:44:25.000000000 +0200
829 @@ -1394,6 +1394,13 @@
830 asid = asid_cache(cpu);
833 +#ifdef CONFIG_IFX_VPE_EXT
834 + /* If TLB is shared between AP and RP (AP is running SMTC),
835 + leave out max ASID i.e., ASID_MASK for RP
837 + if (!nostlb && ((asid & ASID_MASK) == (ASID_MASK - 1)))
840 if (!((asid += ASID_INC) & ASID_MASK) ) {
841 if (cpu_has_vtag_icache)
843 diff -u -N -r linux-3.10.49.orig/arch/mips/kernel/vpe.c linux-3.10.49/arch/mips/kernel/vpe.c
844 --- linux-3.10.49.orig/arch/mips/kernel/vpe.c 2014-10-15 21:41:48.000000000 +0200
845 +++ linux-3.10.49/arch/mips/kernel/vpe.c 2014-10-15 21:54:34.000000000 +0200
848 static const int minor = 1; /* fixed for now */
850 +#ifdef CONFIG_IFX_VPE_EXT
851 +static int is_sdepgm;
853 +extern int vpe0_wired;
854 +extern int vpe1_wired;
855 +unsigned int vpe1_load_addr;
857 +static int __init load_address(char *str)
859 + get_option(&str, &vpe1_load_addr);
862 +__setup("vpe1_load_addr=", load_address);
864 +#include <asm/mipsmtregs.h>
865 +#define write_vpe_c0_wired(val) mttc0(6, 0, val)
867 +#ifndef COMMAND_LINE_SIZE
868 +# define COMMAND_LINE_SIZE 512
871 +char command_line[COMMAND_LINE_SIZE * 2];
873 +static unsigned int vpe1_mem;
874 +static int __init vpe1mem(char *str)
876 + vpe1_mem = memparse(str, &str);
879 +__setup("vpe1_mem=", vpe1mem);
881 +uint32_t vpe1_wdog_ctr;
882 +static int __init wdog_ctr(char *str)
884 + get_option(&str, &vpe1_wdog_ctr);
888 +__setup("vpe1_wdog_ctr_addr=", wdog_ctr);
889 +EXPORT_SYMBOL(vpe1_wdog_ctr);
891 +uint32_t vpe1_wdog_timeout;
892 +static int __init wdog_timeout(char *str)
894 + get_option(&str, &vpe1_wdog_timeout);
898 +__setup("vpe1_wdog_timeout=", wdog_timeout);
899 +EXPORT_SYMBOL(vpe1_wdog_timeout);
902 /* grab the likely amount of memory we will need. */
903 #ifdef CONFIG_MIPS_VPE_LOADER_TOM
904 #define P_SIZE (2 * 1024 * 1024)
908 #ifdef CONFIG_MIPS_VPE_LOADER_TOM
909 +#ifdef CONFIG_IFX_VPE_EXT
910 + if (vpe1_load_addr) {
911 + memset((void *)vpe1_load_addr, 0, len);
912 + return (void *)vpe1_load_addr;
917 * This means you must tell Linux to use less memory than you
918 * physically have, for example by passing a mem= boot argument.
922 /* Write the address we want it to start running from in the TCPC register. */
923 +#if defined(CONFIG_IFX_VPE_EXT) && 0
925 + write_vpe_c0_wired(vpe0_wired + vpe1_wired);
927 + write_vpe_c0_wired(vpe1_wired);
929 write_tc_c0_tcrestart((unsigned long)v->__start);
930 write_tc_c0_tccontext((unsigned long)0);
934 write_tc_c0_tchalt(read_tc_c0_tchalt() & ~TCHALT_H);
936 +#if defined(CONFIG_IFX_VPE_EXT) && 0
938 + * $a2 & $a3 are used to pass command line parameters to VPE1. $a2
939 + * points to the start of the command line string and $a3 points to
940 + * the end of the string. This convention is identical to the Linux
941 + * kernel boot parameter passing mechanism. Please note that $a3 is
942 + * used to pass physical memory size or 0 in SDE tool kit. So, if you
943 + * are passing comand line parameters through $a2 & $a3 SDE programs
944 + * don't work as desired.
946 + mttgpr(6, command_line);
947 + mttgpr(7, (command_line + strlen(command_line)));
951 * The sde-kit passes 'memsize' to __start in $a3, so set something
952 * here... Or set $a3 to zero and define DFLT_STACK_SIZE and
954 if ( (v->__start == 0) || (v->shared_ptr == NULL))
957 +#ifdef CONFIG_IFX_VPE_EXT
963 @@ -977,6 +1059,15 @@
964 (unsigned long)v->load_addr + v->len);
966 if ((find_vpe_symbols(v, sechdrs, symindex, strtab, &mod)) < 0) {
967 +#ifdef CONFIG_IFX_VPE_EXT
968 + if (vpe1_load_addr) {
969 + /* Conversion to KSEG1 is required ??? */
970 + v->__start = KSEG1ADDR(vpe1_load_addr);
976 if (v->__start == 0) {
977 printk(KERN_WARNING "VPE loader: program does not contain "
978 "a __start symbol\n");
979 @@ -1047,6 +1138,9 @@
980 struct vpe_notifications *not;
983 +#ifdef CONFIG_IFX_VPE_EXT
987 if (minor != iminor(inode)) {
988 /* assume only 1 device at the moment. */
989 @@ -1072,7 +1166,12 @@
990 release_progmem(v->load_addr);
991 cleanup_tc(get_tc(tclimit));
994 +#ifdef CONFIG_IFX_VPE_EXT
995 + progsize = (vpe1_mem != 0) ? vpe1_mem : P_SIZE;
996 + //printk("progsize = %x\n", progsize);
997 + v->pbuffer = vmalloc(progsize);
998 + v->plen = progsize;
1000 /* this of-course trashes what was there before... */
1001 v->pbuffer = vmalloc(P_SIZE);
1003 @@ -1080,11 +1179,14 @@
1008 v->load_addr = NULL;
1012 v->uid = filp->f_cred->fsuid;
1013 v->gid = filp->f_cred->fsgid;
1017 ret = getcwd(v->cwd, VPE_PATH_MAX);
1018 @@ -1318,6 +1420,134 @@
1020 EXPORT_SYMBOL(vpe_getcwd);
1022 +#ifdef CONFIG_IFX_VPE_EXT
1023 +int32_t vpe1_sw_start(void* sw_start_addr, uint32_t tcmask, uint32_t flags)
1025 + enum vpe_state state;
1026 + struct vpe *v = get_vpe(tclimit);
1027 + struct vpe_notifications *not;
1029 + if (tcmask || flags) {
1030 + printk(KERN_WARNING "Currently tcmask and flags should be 0.\
1031 + other values not supported\n");
1035 + state = xchg(&v->state, VPE_STATE_INUSE);
1036 + if (state != VPE_STATE_UNUSED) {
1039 + list_for_each_entry(not, &v->notify, list) {
1040 + not->stop(tclimit);
1044 + v->__start = (unsigned long)sw_start_addr;
1047 + if (!vpe_run(v)) {
1048 + printk(KERN_DEBUG "VPE loader: VPE1 running successfully\n");
1054 +EXPORT_SYMBOL(vpe1_sw_start);
1056 +int32_t vpe1_sw_stop(uint32_t flags)
1058 + struct vpe *v = get_vpe(tclimit);
1060 + if (!vpe_free(v)) {
1061 + printk(KERN_DEBUG "RP Stopped\n");
1068 +EXPORT_SYMBOL(vpe1_sw_stop);
1070 +uint32_t vpe1_get_load_addr (uint32_t flags)
1072 + return vpe1_load_addr;
1075 +EXPORT_SYMBOL(vpe1_get_load_addr);
1077 +uint32_t vpe1_get_max_mem (uint32_t flags)
1085 +EXPORT_SYMBOL(vpe1_get_max_mem);
1087 +void* vpe1_get_cmdline_argument(void)
1089 + return saved_command_line;
1092 +EXPORT_SYMBOL(vpe1_get_cmdline_argument);
1094 +int32_t vpe1_set_boot_param(char *field, char *value, char flags)
1096 + char *ptr, string[64];
1097 + int start_off, end_off;
1100 + strcpy(string, field);
1102 + strcat(string, "=");
1103 + strcat(string, value);
1104 + strcat(command_line, " ");
1105 + strcat(command_line, string);
1108 + ptr = strstr(command_line, string);
1110 + start_off = ptr - command_line;
1111 + ptr += strlen(string);
1112 + while ((*ptr != ' ') && (*ptr != '\0'))
1114 + end_off = ptr - command_line;
1115 + command_line[start_off] = '\0';
1116 + strcat (command_line, command_line+end_off);
1122 +EXPORT_SYMBOL(vpe1_set_boot_param);
1124 +int32_t vpe1_get_boot_param(char *field, char **value, char flags)
1126 + char *ptr, string[64];
1130 + if ((ptr = strstr(command_line, field))) {
1131 + ptr += strlen(field) + 1; /* including = */
1132 + while ((*ptr != ' ') && (*ptr != '\0'))
1133 + string[i++] = *ptr++;
1135 + *value = kmalloc((strlen(string) + 1), GFP_KERNEL);
1136 + if (*value != NULL)
1137 + strcpy(*value, string);
1145 +EXPORT_SYMBOL(vpe1_get_boot_param);
1147 +extern void configure_tlb(void);
1150 static ssize_t store_kill(struct device *dev, struct device_attribute *attr,
1151 const char *buf, size_t len)
1153 @@ -1398,6 +1628,18 @@
1154 printk("VPE loader: not a MIPS MT capable processor\n");
1157 +#ifdef CONFIG_IFX_VPE_EXT
1158 +#ifndef CONFIG_MIPS_MT_SMTC
1163 +#ifndef CONFIG_MIPS_MT_SMTC
1170 if (vpelimit == 0) {
1171 printk(KERN_WARNING "No VPEs reserved for AP/SP, not "
1172 @@ -1442,10 +1684,12 @@
1176 + back_to_back_c0_hazard();
1178 /* Put MVPE's into 'configuration state' */
1179 set_c0_mvpcontrol(MVPCONTROL_VPC);
1181 - /* dump_mtregs(); */
1184 val = read_c0_mvpconf0();
1185 hw_tcs = (val & MVPCONF0_PTC) + 1;
1186 @@ -1457,6 +1701,7 @@
1187 * reschedule send IPIs or similar we might hang.
1189 clear_c0_mvpcontrol(MVPCONTROL_VPC);
1190 + back_to_back_c0_hazard();
1193 local_irq_restore(flags);
1194 @@ -1482,6 +1727,7 @@
1197 v->ntcs = hw_tcs - tclimit;
1198 + write_tc_c0_tcbind((read_tc_c0_tcbind() & ~TCBIND_CURVPE) | 1);
1200 /* add the tc to the list of this vpe's tc's. */
1201 list_add(&t->tc, &v->tc);
1202 @@ -1550,6 +1796,7 @@
1204 /* release config state */
1205 clear_c0_mvpcontrol(MVPCONTROL_VPC);
1206 + back_to_back_c0_hazard();
1210 diff -u -N -r linux-3.10.49.orig/arch/mips/kernel/vpe.c.patched linux-3.10.49/arch/mips/kernel/vpe.c.patched
1211 diff -u -N -r linux-3.10.49.orig/arch/mips/kernel/vpe.h linux-3.10.49/arch/mips/kernel/vpe.h
1212 --- linux-3.10.49.orig/arch/mips/kernel/vpe.h 1970-01-01 01:00:00.000000000 +0100
1213 +++ linux-3.10.49/arch/mips/kernel/vpe.h 2014-10-15 21:44:25.000000000 +0200
1216 + * This file is subject to the terms and conditions of the GNU General Public
1217 + * License. See the file "COPYING" in the main directory of this archive
1218 + * for more details.
1220 + * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.
1221 + * Copyright (C) 2013 Imagination Technologies Ltd.
1226 +#include <linux/init.h>
1227 +#include <linux/list.h>
1228 +#include <linux/smp.h>
1229 +#include <linux/spinlock.h>
1231 +#define VPE_MODULE_NAME "vpe"
1232 +#define VPE_MODULE_MINOR 1
1234 +/* grab the likely amount of memory we will need. */
1235 +#ifdef CONFIG_MIPS_VPE_LOADER_TOM
1236 +#define P_SIZE (2 * 1024 * 1024)
1238 +/* add an overhead to the max kmalloc size for non-striped symbols/etc */
1239 +#define P_SIZE (256 * 1024)
1242 +#define MAX_VPES 16
1243 +#define VPE_PATH_MAX 256
1245 +static inline int aprp_cpu_index(void)
1247 +#ifdef CONFIG_MIPS_CMP
1248 + return setup_max_cpus;
1250 + extern int tclimit;
1256 + VPE_STATE_UNUSED = 0,
1262 + TC_STATE_UNUSED = 0,
1269 + enum vpe_state state;
1271 + /* (device) minor associated with this vpe */
1274 + /* elfloader stuff */
1276 + unsigned long len;
1278 + unsigned long plen;
1279 + char cwd[VPE_PATH_MAX];
1281 + unsigned long __start;
1283 + /* tc's associated with this vpe */
1284 + struct list_head tc;
1286 + /* The list of vpe's */
1287 + struct list_head list;
1289 + /* shared symbol address */
1292 + /* the list of who wants to know when something major happens */
1293 + struct list_head notify;
1295 + unsigned int ntcs;
1299 + enum tc_state state;
1302 + struct vpe *pvpe; /* parent VPE */
1303 + struct list_head tc; /* The list of TC's with this VPE */
1304 + struct list_head list; /* The global list of tc's */
1307 +struct vpe_notifications {
1308 + void (*start)(int vpe);
1309 + void (*stop)(int vpe);
1311 + struct list_head list;
1314 +struct vpe_control {
1315 + spinlock_t vpe_list_lock;
1316 + struct list_head vpe_list; /* Virtual processing elements */
1317 + spinlock_t tc_list_lock;
1318 + struct list_head tc_list; /* Thread contexts */
1321 +extern unsigned long physical_memsize;
1322 +extern struct vpe_control vpecontrol;
1323 +extern const struct file_operations vpe_fops;
1325 +int vpe_notify(int index, struct vpe_notifications *notify);
1327 +void *vpe_get_shared(int index);
1328 +char *vpe_getcwd(int index);
1330 +struct vpe *get_vpe(int minor);
1331 +struct tc *get_tc(int index);
1332 +struct vpe *alloc_vpe(int minor);
1333 +struct tc *alloc_tc(int index);
1334 +void release_vpe(struct vpe *v);
1336 +void *alloc_progmem(unsigned long len);
1337 +void release_progmem(void *ptr);
1339 +int __weak vpe_run(struct vpe *v);
1340 +void cleanup_tc(struct tc *tc);
1342 +int __init vpe_module_init(void);
1343 +void __exit vpe_module_exit(void);
1344 +#endif /* _ASM_VPE_H */
1345 diff -u -N -r linux-3.10.49.orig/arch/mips/lantiq/prom.c linux-3.10.49/arch/mips/lantiq/prom.c
1346 --- linux-3.10.49.orig/arch/mips/lantiq/prom.c 2014-10-15 21:41:48.000000000 +0200
1347 +++ linux-3.10.49/arch/mips/lantiq/prom.c 2014-10-15 21:44:39.000000000 +0200
1350 static struct ltq_soc_info soc_info;
1352 +/* for Multithreading (APRP), vpe.c will use it */
1353 +//unsigned long physical_memsize = 0;
1354 +unsigned long cp0_memsize = 0;
1356 const char *get_system_type(void)
1358 return soc_info.sys_type;