probe.c 6.3 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5
/*
 * arch/sh/kernel/cpu/sh4/probe.c
 *
 * CPU Subtype Probing for SH-4.
 *
6
 * Copyright (C) 2001 - 2007  Paul Mundt
L
Linus Torvalds 已提交
7 8 9 10 11 12 13
 * Copyright (C) 2003  Richard Curnow
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */
#include <linux/init.h>
14
#include <linux/io.h>
L
Linus Torvalds 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#include <asm/processor.h>
#include <asm/cache.h>

int __init detect_cpu_and_cache_system(void)
{
	unsigned long pvr, prr, cvr;
	unsigned long size;

	static unsigned long sizes[16] = {
		[1] = (1 << 12),
		[2] = (1 << 13),
		[4] = (1 << 14),
		[8] = (1 << 15),
		[9] = (1 << 16)
	};

31
	pvr = (ctrl_inl(CCN_PVR) >> 8) & 0xffffff;
L
Linus Torvalds 已提交
32 33 34 35 36 37
	prr = (ctrl_inl(CCN_PRR) >> 4) & 0xff;
	cvr = (ctrl_inl(CCN_CVR));

	/*
	 * Setup some sane SH-4 defaults for the icache
	 */
38 39 40 41 42
	boot_cpu_data.icache.way_incr		= (1 << 13);
	boot_cpu_data.icache.entry_shift	= 5;
	boot_cpu_data.icache.sets		= 256;
	boot_cpu_data.icache.ways		= 1;
	boot_cpu_data.icache.linesz		= L1_CACHE_BYTES;
L
Linus Torvalds 已提交
43 44 45 46

	/*
	 * And again for the dcache ..
	 */
47 48 49 50 51
	boot_cpu_data.dcache.way_incr		= (1 << 14);
	boot_cpu_data.dcache.entry_shift	= 5;
	boot_cpu_data.dcache.sets		= 512;
	boot_cpu_data.dcache.ways		= 1;
	boot_cpu_data.dcache.linesz		= L1_CACHE_BYTES;
L
Linus Torvalds 已提交
52

53 54 55
	/* We don't know the chip cut */
	boot_cpu_data.cut_major = boot_cpu_data.cut_minor = -1;

56
	/*
57
	 * Setup some generic flags we can probe on SH-4A parts
58
	 */
59
	if (((pvr >> 16) & 0xff) == 0x10) {
60
		if ((cvr & 0x10000000) == 0)
61
			boot_cpu_data.flags |= CPU_HAS_DSP;
62

63
		boot_cpu_data.flags |= CPU_HAS_LLSC;
64
		boot_cpu_data.cut_major = pvr & 0x7f;
65 66 67 68
	}

	/* FPU detection works for everyone */
	if ((cvr & 0x20000000) == 1)
69
		boot_cpu_data.flags |= CPU_HAS_FPU;
70 71 72 73

	/* Mask off the upper chip ID */
	pvr &= 0xffff;

L
Linus Torvalds 已提交
74 75 76 77 78 79
	/*
	 * Probe the underlying processor version/revision and
	 * adjust cpu_data setup accordingly.
	 */
	switch (pvr) {
	case 0x205:
80 81
		boot_cpu_data.type = CPU_SH7750;
		boot_cpu_data.flags |= CPU_HAS_P2_FLUSH_BUG | CPU_HAS_FPU |
82
				   CPU_HAS_PERF_COUNTER;
L
Linus Torvalds 已提交
83 84
		break;
	case 0x206:
85 86
		boot_cpu_data.type = CPU_SH7750S;
		boot_cpu_data.flags |= CPU_HAS_P2_FLUSH_BUG | CPU_HAS_FPU |
87
				   CPU_HAS_PERF_COUNTER;
L
Linus Torvalds 已提交
88 89
		break;
	case 0x1100:
90 91
		boot_cpu_data.type = CPU_SH7751;
		boot_cpu_data.flags |= CPU_HAS_FPU;
L
Linus Torvalds 已提交
92
		break;
93 94
	case 0x2001:
	case 0x2004:
95 96 97
		boot_cpu_data.type = CPU_SH7770;
		boot_cpu_data.icache.ways = 4;
		boot_cpu_data.dcache.ways = 4;
98

99
		boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_LLSC;
100 101 102 103
		break;
	case 0x2006:
	case 0x200A:
		if (prr == 0x61)
104
			boot_cpu_data.type = CPU_SH7781;
105 106
		else if (prr == 0xa1)
			boot_cpu_data.type = CPU_SH7763;
107
		else
108
			boot_cpu_data.type = CPU_SH7780;
109

110 111
		boot_cpu_data.icache.ways = 4;
		boot_cpu_data.dcache.ways = 4;
112

113
		boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
114
				   CPU_HAS_LLSC;
115
		break;
116 117
	case 0x3000:
	case 0x3003:
P
Paul Mundt 已提交
118
	case 0x3009:
119 120 121 122
		boot_cpu_data.type = CPU_SH7343;
		boot_cpu_data.icache.ways = 4;
		boot_cpu_data.dcache.ways = 4;
		boot_cpu_data.flags |= CPU_HAS_LLSC;
123
		break;
124 125
	case 0x3004:
	case 0x3007:
126 127 128 129
		boot_cpu_data.type = CPU_SH7785;
		boot_cpu_data.icache.ways = 4;
		boot_cpu_data.dcache.ways = 4;
		boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
130 131
					  CPU_HAS_LLSC;
		break;
132 133 134 135 136
	case 0x4004:
		boot_cpu_data.type = CPU_SH7786;
		boot_cpu_data.icache.ways = 4;
		boot_cpu_data.dcache.ways = 4;
		boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
137
			CPU_HAS_LLSC | CPU_HAS_PTEAEX;
138
		break;
P
Paul Mundt 已提交
139
	case 0x3008:
140 141 142 143 144 145
		boot_cpu_data.icache.ways = 4;
		boot_cpu_data.dcache.ways = 4;
		boot_cpu_data.flags |= CPU_HAS_LLSC;

		switch (prr) {
		case 0x50:
146
		case 0x51:
147 148 149 150
			boot_cpu_data.type = CPU_SH7723;
			boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_L2_CACHE;
			break;
		case 0x70:
151
			boot_cpu_data.type = CPU_SH7366;
152 153 154 155 156
			break;
		case 0xa0:
		case 0xa1:
			boot_cpu_data.type = CPU_SH7722;
			break;
157
		}
P
Paul Mundt 已提交
158
		break;
159 160
	case 0x4000:	/* 1st cut */
	case 0x4001:	/* 2nd cut */
161 162 163 164
		boot_cpu_data.type = CPU_SHX3;
		boot_cpu_data.icache.ways = 4;
		boot_cpu_data.dcache.ways = 4;
		boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
165 166
					  CPU_HAS_LLSC;
		break;
L
Linus Torvalds 已提交
167
	case 0x700:
168 169 170
		boot_cpu_data.type = CPU_SH4_501;
		boot_cpu_data.icache.ways = 2;
		boot_cpu_data.dcache.ways = 2;
L
Linus Torvalds 已提交
171 172
		break;
	case 0x600:
173 174 175 176
		boot_cpu_data.type = CPU_SH4_202;
		boot_cpu_data.icache.ways = 2;
		boot_cpu_data.dcache.ways = 2;
		boot_cpu_data.flags |= CPU_HAS_FPU;
L
Linus Torvalds 已提交
177 178 179
		break;
	case 0x500 ... 0x501:
		switch (prr) {
180
		case 0x10:
181
			boot_cpu_data.type = CPU_SH7750R;
182 183
			break;
		case 0x11:
184
			boot_cpu_data.type = CPU_SH7751R;
185 186
			break;
		case 0x50 ... 0x5f:
187
			boot_cpu_data.type = CPU_SH7760;
188
			break;
L
Linus Torvalds 已提交
189 190
		}

191 192
		boot_cpu_data.icache.ways = 2;
		boot_cpu_data.dcache.ways = 2;
L
Linus Torvalds 已提交
193

194
		boot_cpu_data.flags |= CPU_HAS_FPU;
195

L
Linus Torvalds 已提交
196 197
		break;
	default:
198
		boot_cpu_data.type = CPU_SH_NONE;
L
Linus Torvalds 已提交
199 200 201
		break;
	}

202
#ifdef CONFIG_SH_DIRECT_MAPPED
203 204
	boot_cpu_data.icache.ways = 1;
	boot_cpu_data.dcache.ways = 1;
205 206 207
#endif

#ifdef CONFIG_CPU_HAS_PTEA
208
	boot_cpu_data.flags |= CPU_HAS_PTEA;
209 210
#endif

L
Linus Torvalds 已提交
211 212 213 214
	/*
	 * On anything that's not a direct-mapped cache, look to the CVR
	 * for I/D-cache specifics.
	 */
215
	if (boot_cpu_data.icache.ways > 1) {
L
Linus Torvalds 已提交
216
		size = sizes[(cvr >> 20) & 0xf];
217 218
		boot_cpu_data.icache.way_incr	= (size >> 1);
		boot_cpu_data.icache.sets	= (size >> 6);
219

L
Linus Torvalds 已提交
220 221
	}

222
	/* And the rest of the D-cache */
223
	if (boot_cpu_data.dcache.ways > 1) {
L
Linus Torvalds 已提交
224
		size = sizes[(cvr >> 16) & 0xf];
225 226
		boot_cpu_data.dcache.way_incr	= (size >> 1);
		boot_cpu_data.dcache.sets	= (size >> 6);
L
Linus Torvalds 已提交
227 228
	}

229 230 231 232 233
	/*
	 * Setup the L2 cache desc
	 *
	 * SH-4A's have an optional PIPT L2.
	 */
234
	if (boot_cpu_data.flags & CPU_HAS_L2_CACHE) {
P
Paul Mundt 已提交
235 236 237 238 239 240
		/* Bug if we can't decode the L2 info */
		BUG_ON(!(cvr & 0xf));

		/* Silicon and specifications have clearly never met.. */
		cvr ^= 0xf;

241 242 243 244 245 246 247 248 249 250
		/*
		 * Size calculation is much more sensible
		 * than it is for the L1.
		 *
		 * Sizes are 128KB, 258KB, 512KB, and 1MB.
		 */
		size = (cvr & 0xf) << 17;

		BUG_ON(!size);

251 252 253 254
		boot_cpu_data.scache.way_incr		= (1 << 16);
		boot_cpu_data.scache.entry_shift	= 5;
		boot_cpu_data.scache.ways		= 4;
		boot_cpu_data.scache.linesz		= L1_CACHE_BYTES;
255

256 257 258
		boot_cpu_data.scache.entry_mask	=
			(boot_cpu_data.scache.way_incr -
			 boot_cpu_data.scache.linesz);
259

260 261 262
		boot_cpu_data.scache.sets	= size /
			(boot_cpu_data.scache.linesz *
			 boot_cpu_data.scache.ways);
263

264 265 266
		boot_cpu_data.scache.way_size	=
			(boot_cpu_data.scache.sets *
			 boot_cpu_data.scache.linesz);
267 268
	}

L
Linus Torvalds 已提交
269 270
	return 0;
}