Blame view

arch/mips/kernel/mips-mt.c 7.74 KB
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
1
2
3
4
  /*
   * General MIPS MT support routines, usable in AP/SP, SMVP, or SMTC kernels
   * Copyright (C) 2005 Mips Technologies, Inc
   */
27a3bbaf4   Ralf Baechle   [MIPS] VPE: Sprin...
5
  #include <linux/device.h>
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
6
7
  #include <linux/kernel.h>
  #include <linux/sched.h>
73bc256d4   Paul Gortmaker   mips: migrate cor...
8
  #include <linux/export.h>
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
9
  #include <linux/interrupt.h>
f72af3cf0   Yoichi Yuasa   [MIPS] MIPS MT: F...
10
  #include <linux/security.h>
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
11
12
13
  
  #include <asm/cpu.h>
  #include <asm/processor.h>
60063497a   Arun Sharma   atomic: use <linu...
14
  #include <linux/atomic.h>
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
15
16
17
  #include <asm/system.h>
  #include <asm/hardirq.h>
  #include <asm/mmu_context.h>
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
18
19
20
  #include <asm/mipsmtregs.h>
  #include <asm/r4kcache.h>
  #include <asm/cacheflush.h>
07cc0c9e6   Ralf Baechle   [MIPS] MT: Enable...
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  int vpelimit;
  
  static int __init maxvpes(char *str)
  {
  	get_option(&str, &vpelimit);
  
  	return 1;
  }
  
  __setup("maxvpes=", maxvpes);
  
  int tclimit;
  
  static int __init maxtcs(char *str)
  {
  	get_option(&str, &tclimit);
  
  	return 1;
  }
  
  __setup("maxtcs=", maxtcs);
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
42
  /*
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
   * Dump new MIPS MT state for the core. Does not leave TCs halted.
   * Takes an argument which taken to be a pre-call MVPControl value.
   */
  
  void mips_mt_regdump(unsigned long mvpctl)
  {
  	unsigned long flags;
  	unsigned long vpflags;
  	unsigned long mvpconf0;
  	int nvpe;
  	int ntc;
  	int i;
  	int tc;
  	unsigned long haltval;
  	unsigned long tcstatval;
  #ifdef CONFIG_MIPS_MT_SMTC
  	void smtc_soft_dump(void);
  #endif /* CONFIG_MIPT_MT_SMTC */
  
  	local_irq_save(flags);
  	vpflags = dvpe();
  	printk("=== MIPS MT State Dump ===
  ");
  	printk("-- Global State --
  ");
  	printk("   MVPControl Passed: %08lx
  ", mvpctl);
  	printk("   MVPControl Read: %08lx
  ", vpflags);
  	printk("   MVPConf0 : %08lx
  ", (mvpconf0 = read_c0_mvpconf0()));
  	nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
  	ntc = ((mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1;
  	printk("-- per-VPE State --
  ");
d223a8615   Ralf Baechle   [MIPS] FP affinit...
78
79
  	for (i = 0; i < nvpe; i++) {
  		for (tc = 0; tc < ntc; tc++) {
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
80
  			settc(tc);
d223a8615   Ralf Baechle   [MIPS] FP affinit...
81
82
83
84
85
86
87
88
89
90
91
92
  			if ((read_tc_c0_tcbind() & TCBIND_CURVPE) == i) {
  				printk("  VPE %d
  ", i);
  				printk("   VPEControl : %08lx
  ",
  				       read_vpe_c0_vpecontrol());
  				printk("   VPEConf0 : %08lx
  ",
  				       read_vpe_c0_vpeconf0());
  				printk("   VPE%d.Status : %08lx
  ",
  				       i, read_vpe_c0_status());
b012cffe7   Ralf Baechle   [MIPS] Replace us...
93
94
95
96
  				printk("   VPE%d.EPC : %08lx %pS
  ",
  				       i, read_vpe_c0_epc(),
  				       (void *) read_vpe_c0_epc());
d223a8615   Ralf Baechle   [MIPS] FP affinit...
97
98
99
100
101
102
103
104
  				printk("   VPE%d.Cause : %08lx
  ",
  				       i, read_vpe_c0_cause());
  				printk("   VPE%d.Config7 : %08lx
  ",
  				       i, read_vpe_c0_config7());
  				break; /* Next VPE */
  			}
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
105
  		}
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
106
107
108
  	}
  	printk("-- per-TC State --
  ");
d223a8615   Ralf Baechle   [MIPS] FP affinit...
109
  	for (tc = 0; tc < ntc; tc++) {
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
110
  		settc(tc);
d223a8615   Ralf Baechle   [MIPS] FP affinit...
111
  		if (read_tc_c0_tcbind() == read_c0_tcbind()) {
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  			/* Are we dumping ourself?  */
  			haltval = 0; /* Then we're not halted, and mustn't be */
  			tcstatval = flags; /* And pre-dump TCStatus is flags */
  			printk("  TC %d (current TC with VPE EPC above)
  ", tc);
  		} else {
  			haltval = read_tc_c0_tchalt();
  			write_tc_c0_tchalt(1);
  			tcstatval = read_tc_c0_tcstatus();
  			printk("  TC %d
  ", tc);
  		}
  		printk("   TCStatus : %08lx
  ", tcstatval);
  		printk("   TCBind : %08lx
  ", read_tc_c0_tcbind());
b012cffe7   Ralf Baechle   [MIPS] Replace us...
128
129
130
  		printk("   TCRestart : %08lx %pS
  ",
  		       read_tc_c0_tcrestart(), (void *) read_tc_c0_tcrestart());
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  		printk("   TCHalt : %08lx
  ", haltval);
  		printk("   TCContext : %08lx
  ", read_tc_c0_tccontext());
  		if (!haltval)
  			write_tc_c0_tchalt(0);
  	}
  #ifdef CONFIG_MIPS_MT_SMTC
  	smtc_soft_dump();
  #endif /* CONFIG_MIPT_MT_SMTC */
  	printk("===========================
  ");
  	evpe(vpflags);
  	local_irq_restore(flags);
  }
982f6ffee   Ralf Baechle   MIPS: Remove usel...
146
  static int mt_opt_norps;
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
147
148
  static int mt_opt_rpsctl = -1;
  static int mt_opt_nblsu = -1;
982f6ffee   Ralf Baechle   MIPS: Remove usel...
149
  static int mt_opt_forceconfig7;
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
  static int mt_opt_config7 = -1;
  
  static int __init rps_disable(char *s)
  {
  	mt_opt_norps = 1;
  	return 1;
  }
  __setup("norps", rps_disable);
  
  static int __init rpsctl_set(char *str)
  {
  	get_option(&str, &mt_opt_rpsctl);
  	return 1;
  }
  __setup("rpsctl=", rpsctl_set);
  
  static int __init nblsu_set(char *str)
  {
  	get_option(&str, &mt_opt_nblsu);
  	return 1;
  }
  __setup("nblsu=", nblsu_set);
  
  static int __init config7_set(char *str)
  {
  	get_option(&str, &mt_opt_config7);
  	mt_opt_forceconfig7 = 1;
  	return 1;
  }
  __setup("config7=", config7_set);
  
  /* Experimental cache flush control parameters that should go away some day */
982f6ffee   Ralf Baechle   MIPS: Remove usel...
182
183
  int mt_protiflush;
  int mt_protdflush;
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
  int mt_n_iflushes = 1;
  int mt_n_dflushes = 1;
  
  static int __init set_protiflush(char *s)
  {
  	mt_protiflush = 1;
  	return 1;
  }
  __setup("protiflush", set_protiflush);
  
  static int __init set_protdflush(char *s)
  {
  	mt_protdflush = 1;
  	return 1;
  }
  __setup("protdflush", set_protdflush);
  
  static int __init niflush(char *s)
  {
  	get_option(&s, &mt_n_iflushes);
  	return 1;
  }
  __setup("niflush=", niflush);
  
  static int __init ndflush(char *s)
  {
  	get_option(&s, &mt_n_dflushes);
  	return 1;
  }
  __setup("ndflush=", ndflush);
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
214

982f6ffee   Ralf Baechle   MIPS: Remove usel...
215
  static unsigned int itc_base;
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
  
  static int __init set_itc_base(char *str)
  {
  	get_option(&str, &itc_base);
  	return 1;
  }
  
  __setup("itcbase=", set_itc_base);
  
  void mips_mt_set_cpuoptions(void)
  {
  	unsigned int oconfig7 = read_c0_config7();
  	unsigned int nconfig7 = oconfig7;
  
  	if (mt_opt_norps) {
  		printk("\"norps\" option deprectated: use \"rpsctl=\"
  ");
  	}
  	if (mt_opt_rpsctl >= 0) {
  		printk("34K return prediction stack override set to %d.
  ",
  			mt_opt_rpsctl);
  		if (mt_opt_rpsctl)
  			nconfig7 |= (1 << 2);
  		else
  			nconfig7 &= ~(1 << 2);
  	}
  	if (mt_opt_nblsu >= 0) {
  		printk("34K ALU/LSU sync override set to %d.
  ", mt_opt_nblsu);
  		if (mt_opt_nblsu)
  			nconfig7 |= (1 << 5);
  		else
  			nconfig7 &= ~(1 << 5);
  	}
  	if (mt_opt_forceconfig7) {
  		printk("CP0.Config7 forced to 0x%08x.
  ", mt_opt_config7);
  		nconfig7 = mt_opt_config7;
  	}
  	if (oconfig7 != nconfig7) {
  		__asm__ __volatile("sync");
  		write_c0_config7(nconfig7);
49a89efbb   Ralf Baechle   [MIPS] Fix "no sp...
259
  		ehb();
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
  		printk("Config7: 0x%08x
  ", read_c0_config7());
  	}
  
  	/* Report Cache management debug options */
  	if (mt_protiflush)
  		printk("I-cache flushes single-threaded
  ");
  	if (mt_protdflush)
  		printk("D-cache flushes single-threaded
  ");
  	if (mt_n_iflushes != 1)
  		printk("I-Cache Flushes Repeated %d times
  ", mt_n_iflushes);
  	if (mt_n_dflushes != 1)
  		printk("D-Cache Flushes Repeated %d times
  ", mt_n_dflushes);
41c594ab6   Ralf Baechle   [MIPS] MT: Improv...
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
  	if (itc_base != 0) {
  		/*
  		 * Configure ITC mapping.  This code is very
  		 * specific to the 34K core family, which uses
  		 * a special mode bit ("ITC") in the ErrCtl
  		 * register to enable access to ITC control
  		 * registers via cache "tag" operations.
  		 */
  		unsigned long ectlval;
  		unsigned long itcblkgrn;
  
  		/* ErrCtl register is known as "ecc" to Linux */
  		ectlval = read_c0_ecc();
  		write_c0_ecc(ectlval | (0x1 << 26));
  		ehb();
  #define INDEX_0 (0x80000000)
  #define INDEX_8 (0x80000008)
  		/* Read "cache tag" for Dcache pseudo-index 8 */
  		cache_op(Index_Load_Tag_D, INDEX_8);
  		ehb();
  		itcblkgrn = read_c0_dtaglo();
  		itcblkgrn &= 0xfffe0000;
  		/* Set for 128 byte pitch of ITC cells */
  		itcblkgrn |= 0x00000c00;
  		/* Stage in Tag register */
  		write_c0_dtaglo(itcblkgrn);
  		ehb();
  		/* Write out to ITU with CACHE op */
  		cache_op(Index_Store_Tag_D, INDEX_8);
  		/* Now set base address, and turn ITC on with 0x1 bit */
  		write_c0_dtaglo((itc_base & 0xfffffc00) | 0x1 );
  		ehb();
  		/* Write out to ITU with CACHE op */
  		cache_op(Index_Store_Tag_D, INDEX_0);
  		write_c0_ecc(ectlval);
  		ehb();
  		printk("Mapped %ld ITC cells starting at 0x%08x
  ",
  			((itcblkgrn & 0x7fe00000) >> 20), itc_base);
  	}
  }
  
  /*
   * Function to protect cache flushes from concurrent execution
   * depends on MP software model chosen.
   */
  
  void mt_cflush_lockdown(void)
  {
  #ifdef CONFIG_MIPS_MT_SMTC
  	void smtc_cflush_lockdown(void);
  
  	smtc_cflush_lockdown();
  #endif /* CONFIG_MIPS_MT_SMTC */
  	/* FILL IN VSMP and AP/SP VERSIONS HERE */
  }
  
  void mt_cflush_release(void)
  {
  #ifdef CONFIG_MIPS_MT_SMTC
  	void smtc_cflush_release(void);
  
  	smtc_cflush_release();
  #endif /* CONFIG_MIPS_MT_SMTC */
  	/* FILL IN VSMP and AP/SP VERSIONS HERE */
  }
27a3bbaf4   Ralf Baechle   [MIPS] VPE: Sprin...
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
  
  struct class *mt_class;
  
  static int __init mt_init(void)
  {
  	struct class *mtc;
  
  	mtc = class_create(THIS_MODULE, "mt");
  	if (IS_ERR(mtc))
  		return PTR_ERR(mtc);
  
  	mt_class = mtc;
  
  	return 0;
  }
  
  subsys_initcall(mt_init);