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 - 2006  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>
E
Evgeniy Polyakov 已提交
15
#include <linux/smp.h>
L
Linus Torvalds 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#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)
	};

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

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

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

54 55 56 57 58 59
	/*
	 * Setup some generic flags we can probe
	 * (L2 and DSP detection only work on SH-4A)
	 */
	if (((pvr >> 16) & 0xff) == 0x10) {
		if ((cvr & 0x02000000) == 0)
60
			current_cpu_data.flags |= CPU_HAS_L2_CACHE;
61
		if ((cvr & 0x10000000) == 0)
62
			current_cpu_data.flags |= CPU_HAS_DSP;
63

64
		current_cpu_data.flags |= CPU_HAS_LLSC;
65 66 67 68
	}

	/* FPU detection works for everyone */
	if ((cvr & 0x20000000) == 1)
69
		current_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
		current_cpu_data.type = CPU_SH7750;
		current_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
		current_cpu_data.type = CPU_SH7750S;
		current_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
		current_cpu_data.type = CPU_SH7751;
		current_cpu_data.flags |= CPU_HAS_FPU;
L
Linus Torvalds 已提交
92 93
		break;
	case 0x2000:
94 95 96 97
		current_cpu_data.type = CPU_SH73180;
		current_cpu_data.icache.ways = 4;
		current_cpu_data.dcache.ways = 4;
		current_cpu_data.flags |= CPU_HAS_LLSC;
L
Linus Torvalds 已提交
98
		break;
99 100
	case 0x2001:
	case 0x2004:
101 102 103
		current_cpu_data.type = CPU_SH7770;
		current_cpu_data.icache.ways = 4;
		current_cpu_data.dcache.ways = 4;
104

105
		current_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_LLSC;
106 107 108 109
		break;
	case 0x2006:
	case 0x200A:
		if (prr == 0x61)
110
			current_cpu_data.type = CPU_SH7781;
111
		else
112
			current_cpu_data.type = CPU_SH7780;
113

114 115
		current_cpu_data.icache.ways = 4;
		current_cpu_data.dcache.ways = 4;
116

117
		current_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
118
				   CPU_HAS_LLSC;
119
		break;
120 121
	case 0x3000:
	case 0x3003:
P
Paul Mundt 已提交
122
	case 0x3009:
123 124 125 126
		current_cpu_data.type = CPU_SH7343;
		current_cpu_data.icache.ways = 4;
		current_cpu_data.dcache.ways = 4;
		current_cpu_data.flags |= CPU_HAS_LLSC;
127
		break;
128 129 130 131 132 133 134 135
	case 0x3004:
	case 0x3007:
		current_cpu_data.type = CPU_SH7785;
		current_cpu_data.icache.ways = 4;
		current_cpu_data.dcache.ways = 4;
		current_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
					  CPU_HAS_LLSC;
		break;
P
Paul Mundt 已提交
136 137
	case 0x3008:
		if (prr == 0xa0) {
138 139 140 141
			current_cpu_data.type = CPU_SH7722;
			current_cpu_data.icache.ways = 4;
			current_cpu_data.dcache.ways = 4;
			current_cpu_data.flags |= CPU_HAS_LLSC;
P
Paul Mundt 已提交
142 143
		}
		break;
144 145 146 147 148 149 150 151
	case 0x4000:	/* 1st cut */
	case 0x4001:	/* 2nd cut */
		current_cpu_data.type = CPU_SHX3;
		current_cpu_data.icache.ways = 4;
		current_cpu_data.dcache.ways = 4;
		current_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
					  CPU_HAS_LLSC;
		break;
L
Linus Torvalds 已提交
152
	case 0x8000:
153 154
		current_cpu_data.type = CPU_ST40RA;
		current_cpu_data.flags |= CPU_HAS_FPU;
L
Linus Torvalds 已提交
155 156
		break;
	case 0x8100:
157 158
		current_cpu_data.type = CPU_ST40GX1;
		current_cpu_data.flags |= CPU_HAS_FPU;
L
Linus Torvalds 已提交
159 160
		break;
	case 0x700:
161 162 163
		current_cpu_data.type = CPU_SH4_501;
		current_cpu_data.icache.ways = 2;
		current_cpu_data.dcache.ways = 2;
L
Linus Torvalds 已提交
164 165
		break;
	case 0x600:
166 167 168 169
		current_cpu_data.type = CPU_SH4_202;
		current_cpu_data.icache.ways = 2;
		current_cpu_data.dcache.ways = 2;
		current_cpu_data.flags |= CPU_HAS_FPU;
L
Linus Torvalds 已提交
170 171 172
		break;
	case 0x500 ... 0x501:
		switch (prr) {
173
		case 0x10:
174
			current_cpu_data.type = CPU_SH7750R;
175 176
			break;
		case 0x11:
177
			current_cpu_data.type = CPU_SH7751R;
178 179
			break;
		case 0x50 ... 0x5f:
180
			current_cpu_data.type = CPU_SH7760;
181
			break;
L
Linus Torvalds 已提交
182 183
		}

184 185
		current_cpu_data.icache.ways = 2;
		current_cpu_data.dcache.ways = 2;
L
Linus Torvalds 已提交
186

187
		current_cpu_data.flags |= CPU_HAS_FPU;
188

L
Linus Torvalds 已提交
189 190
		break;
	default:
191
		current_cpu_data.type = CPU_SH_NONE;
L
Linus Torvalds 已提交
192 193 194
		break;
	}

195
#ifdef CONFIG_SH_DIRECT_MAPPED
196 197 198 199 200 201
	current_cpu_data.icache.ways = 1;
	current_cpu_data.dcache.ways = 1;
#endif

#ifdef CONFIG_CPU_HAS_PTEA
	current_cpu_data.flags |= CPU_HAS_PTEA;
202 203
#endif

L
Linus Torvalds 已提交
204 205 206 207
	/*
	 * On anything that's not a direct-mapped cache, look to the CVR
	 * for I/D-cache specifics.
	 */
208
	if (current_cpu_data.icache.ways > 1) {
L
Linus Torvalds 已提交
209
		size = sizes[(cvr >> 20) & 0xf];
210 211
		current_cpu_data.icache.way_incr	= (size >> 1);
		current_cpu_data.icache.sets		= (size >> 6);
212

L
Linus Torvalds 已提交
213 214
	}

215
	/* And the rest of the D-cache */
216
	if (current_cpu_data.dcache.ways > 1) {
L
Linus Torvalds 已提交
217
		size = sizes[(cvr >> 16) & 0xf];
218 219
		current_cpu_data.dcache.way_incr	= (size >> 1);
		current_cpu_data.dcache.sets		= (size >> 6);
L
Linus Torvalds 已提交
220 221
	}

222 223 224 225 226
	/*
	 * Setup the L2 cache desc
	 *
	 * SH-4A's have an optional PIPT L2.
	 */
227
	if (current_cpu_data.flags & CPU_HAS_L2_CACHE) {
228 229 230 231 232 233 234 235 236 237
		/*
		 * 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);

238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
		current_cpu_data.scache.way_incr	= (1 << 16);
		current_cpu_data.scache.entry_shift	= 5;
		current_cpu_data.scache.ways		= 4;
		current_cpu_data.scache.linesz		= L1_CACHE_BYTES;

		current_cpu_data.scache.entry_mask	=
			(current_cpu_data.scache.way_incr -
			 current_cpu_data.scache.linesz);

		current_cpu_data.scache.sets		= size /
			(current_cpu_data.scache.linesz *
			 current_cpu_data.scache.ways);

		current_cpu_data.scache.way_size	=
			(current_cpu_data.scache.sets *
			 current_cpu_data.scache.linesz);
254 255
	}

L
Linus Torvalds 已提交
256 257
	return 0;
}