probe.c 5.5 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 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 * 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>
#include <asm/processor.h>
#include <asm/cache.h>
#include <asm/io.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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
	prr = (ctrl_inl(CCN_PRR) >> 4) & 0xff;
	cvr = (ctrl_inl(CCN_CVR));

	/*
	 * Setup some sane SH-4 defaults for the icache
	 */
	cpu_data->icache.way_incr	= (1 << 13);
	cpu_data->icache.entry_shift	= 5;
	cpu_data->icache.sets		= 256;
	cpu_data->icache.ways		= 1;
	cpu_data->icache.linesz		= L1_CACHE_BYTES;

	/*
	 * And again for the dcache ..
	 */
	cpu_data->dcache.way_incr	= (1 << 14);
	cpu_data->dcache.entry_shift	= 5;
	cpu_data->dcache.sets		= 512;
	cpu_data->dcache.ways		= 1;
	cpu_data->dcache.linesz		= L1_CACHE_BYTES;

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
	/*
	 * 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)
			cpu_data->flags |= CPU_HAS_L2_CACHE;
		if ((cvr & 0x10000000) == 0)
			cpu_data->flags |= CPU_HAS_DSP;

		cpu_data->flags |= CPU_HAS_LLSC;
	}

	/* FPU detection works for everyone */
	if ((cvr & 0x20000000) == 1)
		cpu_data->flags |= CPU_HAS_FPU;

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

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

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

114 115
		cpu_data->icache.ways = 4;
		cpu_data->dcache.ways = 4;
116

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

		cpu_data->icache.ways = 2;
		cpu_data->dcache.ways = 2;

171
		cpu_data->flags |= CPU_HAS_FPU;
172

L
Linus Torvalds 已提交
173 174 175 176 177 178
		break;
	default:
		cpu_data->type = CPU_SH_NONE;
		break;
	}

179 180 181 182 183
#ifdef CONFIG_SH_DIRECT_MAPPED
	cpu_data->icache.ways = 1;
	cpu_data->dcache.ways = 1;
#endif

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

L
Linus Torvalds 已提交
193 194
	}

195 196 197 198
	/* Setup the rest of the I-cache info */
	cpu_data->icache.entry_mask = cpu_data->icache.way_incr -
				      cpu_data->icache.linesz;

199 200 201
	cpu_data->icache.way_size = cpu_data->icache.sets *
				    cpu_data->icache.linesz;

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

209 210 211
	cpu_data->dcache.entry_mask = cpu_data->dcache.way_incr -
				      cpu_data->dcache.linesz;

212 213 214
	cpu_data->dcache.way_size = cpu_data->dcache.sets *
				    cpu_data->dcache.linesz;

215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
	/*
	 * Setup the L2 cache desc
	 *
	 * SH-4A's have an optional PIPT L2.
	 */
	if (cpu_data->flags & CPU_HAS_L2_CACHE) {
		/*
		 * 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);

		cpu_data->scache.way_incr	= (1 << 16);
		cpu_data->scache.entry_shift	= 5;
		cpu_data->scache.ways		= 4;
		cpu_data->scache.linesz		= L1_CACHE_BYTES;
235 236
		cpu_data->scache.entry_mask	=
			(cpu_data->scache.way_incr - cpu_data->scache.linesz);
237 238
		cpu_data->scache.sets		= size /
			(cpu_data->scache.linesz * cpu_data->scache.ways);
239 240
		cpu_data->scache.way_size	=
			(cpu_data->scache.sets * cpu_data->scache.linesz);
241 242
	}

L
Linus Torvalds 已提交
243 244
	return 0;
}