1 // SPDX-License-Identifier: GPL-2.0
3 * General MIPS MT support routines, usable in AP/SP and SMVP.
4 * Copyright (C) 2005 Mips Technologies, Inc
7 #include <linux/device.h>
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
10 #include <linux/export.h>
11 #include <linux/interrupt.h>
12 #include <linux/security.h>
15 #include <asm/processor.h>
16 #include <linux/atomic.h>
17 #include <asm/hardirq.h>
18 #include <asm/mmu_context.h>
19 #include <asm/mipsmtregs.h>
20 #include <asm/r4kcache.h>
21 #include <asm/cacheflush.h>
22 #include <asm/mips_mt.h>
26 static int __init
maxvpes(char *str
)
28 get_option(&str
, &vpelimit
);
33 __setup("maxvpes=", maxvpes
);
37 static int __init
maxtcs(char *str
)
39 get_option(&str
, &tclimit
);
44 __setup("maxtcs=", maxtcs
);
46 static int mt_opt_rpsctl
= -1;
47 static int mt_opt_nblsu
= -1;
48 static int mt_opt_forceconfig7
;
49 static int mt_opt_config7
= -1;
51 static int __init
rpsctl_set(char *str
)
53 get_option(&str
, &mt_opt_rpsctl
);
56 __setup("rpsctl=", rpsctl_set
);
58 static int __init
nblsu_set(char *str
)
60 get_option(&str
, &mt_opt_nblsu
);
63 __setup("nblsu=", nblsu_set
);
65 static int __init
config7_set(char *str
)
67 get_option(&str
, &mt_opt_config7
);
68 mt_opt_forceconfig7
= 1;
71 __setup("config7=", config7_set
);
73 static unsigned int itc_base
;
75 static int __init
set_itc_base(char *str
)
77 get_option(&str
, &itc_base
);
81 __setup("itcbase=", set_itc_base
);
83 void mips_mt_set_cpuoptions(void)
85 unsigned int oconfig7
= read_c0_config7();
86 unsigned int nconfig7
= oconfig7
;
88 if (mt_opt_rpsctl
>= 0) {
89 printk("34K return prediction stack override set to %d.\n",
94 nconfig7
&= ~(1 << 2);
96 if (mt_opt_nblsu
>= 0) {
97 printk("34K ALU/LSU sync override set to %d.\n", mt_opt_nblsu
);
101 nconfig7
&= ~(1 << 5);
103 if (mt_opt_forceconfig7
) {
104 printk("CP0.Config7 forced to 0x%08x.\n", mt_opt_config7
);
105 nconfig7
= mt_opt_config7
;
107 if (oconfig7
!= nconfig7
) {
108 __asm__
__volatile("sync");
109 write_c0_config7(nconfig7
);
111 printk("Config7: 0x%08x\n", read_c0_config7());
116 * Configure ITC mapping. This code is very
117 * specific to the 34K core family, which uses
118 * a special mode bit ("ITC") in the ErrCtl
119 * register to enable access to ITC control
120 * registers via cache "tag" operations.
122 unsigned long ectlval
;
123 unsigned long itcblkgrn
;
125 /* ErrCtl register is known as "ecc" to Linux */
126 ectlval
= read_c0_ecc();
127 write_c0_ecc(ectlval
| (0x1 << 26));
129 #define INDEX_0 (0x80000000)
130 #define INDEX_8 (0x80000008)
131 /* Read "cache tag" for Dcache pseudo-index 8 */
132 cache_op(Index_Load_Tag_D
, INDEX_8
);
134 itcblkgrn
= read_c0_dtaglo();
135 itcblkgrn
&= 0xfffe0000;
136 /* Set for 128 byte pitch of ITC cells */
137 itcblkgrn
|= 0x00000c00;
138 /* Stage in Tag register */
139 write_c0_dtaglo(itcblkgrn
);
141 /* Write out to ITU with CACHE op */
142 cache_op(Index_Store_Tag_D
, INDEX_8
);
143 /* Now set base address, and turn ITC on with 0x1 bit */
144 write_c0_dtaglo((itc_base
& 0xfffffc00) | 0x1 );
146 /* Write out to ITU with CACHE op */
147 cache_op(Index_Store_Tag_D
, INDEX_0
);
148 write_c0_ecc(ectlval
);
150 printk("Mapped %ld ITC cells starting at 0x%08x\n",
151 ((itcblkgrn
& 0x7fe00000) >> 20), itc_base
);
155 const struct class mt_class
= {
159 static int __init
mips_mt_init(void)
161 return class_register(&mt_class
);
164 subsys_initcall(mips_mt_init
);