probe.c 5.7 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>
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
	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 已提交
43 44 45 46

	/*
	 * And again for the dcache ..
	 */
47 48 49 50 51
	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 已提交
52

53 54 55 56 57 58
	/*
	 * 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)
59
			current_cpu_data.flags |= CPU_HAS_L2_CACHE;
60
		if ((cvr & 0x10000000) == 0)
61
			current_cpu_data.flags |= CPU_HAS_DSP;
62

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

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

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

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

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

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

116
		current_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
117
				   CPU_HAS_LLSC;
118
		break;
119 120
	case 0x3000:
	case 0x3003:
P
Paul Mundt 已提交
121
	case 0x3009:
122 123 124 125
		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;
126
		break;
P
Paul Mundt 已提交
127 128
	case 0x3008:
		if (prr == 0xa0) {
129 130 131 132
			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 已提交
133 134
		}
		break;
L
Linus Torvalds 已提交
135
	case 0x8000:
136 137
		current_cpu_data.type = CPU_ST40RA;
		current_cpu_data.flags |= CPU_HAS_FPU;
L
Linus Torvalds 已提交
138 139
		break;
	case 0x8100:
140 141
		current_cpu_data.type = CPU_ST40GX1;
		current_cpu_data.flags |= CPU_HAS_FPU;
L
Linus Torvalds 已提交
142 143
		break;
	case 0x700:
144 145 146
		current_cpu_data.type = CPU_SH4_501;
		current_cpu_data.icache.ways = 2;
		current_cpu_data.dcache.ways = 2;
L
Linus Torvalds 已提交
147 148
		break;
	case 0x600:
149 150 151 152
		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 已提交
153 154 155
		break;
	case 0x500 ... 0x501:
		switch (prr) {
156
		case 0x10:
157
			current_cpu_data.type = CPU_SH7750R;
158 159
			break;
		case 0x11:
160
			current_cpu_data.type = CPU_SH7751R;
161 162
			break;
		case 0x50 ... 0x5f:
163
			current_cpu_data.type = CPU_SH7760;
164
			break;
L
Linus Torvalds 已提交
165 166
		}

167 168
		current_cpu_data.icache.ways = 2;
		current_cpu_data.dcache.ways = 2;
L
Linus Torvalds 已提交
169

170
		current_cpu_data.flags |= CPU_HAS_FPU;
171

L
Linus Torvalds 已提交
172 173
		break;
	default:
174
		current_cpu_data.type = CPU_SH_NONE;
L
Linus Torvalds 已提交
175 176 177
		break;
	}

178
#ifdef CONFIG_SH_DIRECT_MAPPED
179 180 181 182 183 184
	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;
185 186
#endif

L
Linus Torvalds 已提交
187 188 189 190
	/*
	 * On anything that's not a direct-mapped cache, look to the CVR
	 * for I/D-cache specifics.
	 */
191
	if (current_cpu_data.icache.ways > 1) {
L
Linus Torvalds 已提交
192
		size = sizes[(cvr >> 20) & 0xf];
193 194
		current_cpu_data.icache.way_incr	= (size >> 1);
		current_cpu_data.icache.sets		= (size >> 6);
195

L
Linus Torvalds 已提交
196 197
	}

198
	/* And the rest of the D-cache */
199
	if (current_cpu_data.dcache.ways > 1) {
L
Linus Torvalds 已提交
200
		size = sizes[(cvr >> 16) & 0xf];
201 202
		current_cpu_data.dcache.way_incr	= (size >> 1);
		current_cpu_data.dcache.sets		= (size >> 6);
L
Linus Torvalds 已提交
203 204
	}

205 206 207 208 209
	/*
	 * Setup the L2 cache desc
	 *
	 * SH-4A's have an optional PIPT L2.
	 */
210
	if (current_cpu_data.flags & CPU_HAS_L2_CACHE) {
211 212 213 214 215 216 217 218 219 220
		/*
		 * 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);

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
		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);
237 238
	}

L
Linus Torvalds 已提交
239 240
	return 0;
}