blob: 0f0c76a842e43e3922510ad3d50869b23a507269 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/sh/kernel/cpu/init.c
3 *
4 * CPU init code
5 *
Paul Mundtffe1b4e2007-03-12 16:15:22 +09006 * Copyright (C) 2002 - 2007 Paul Mundt
Richard Curnowb638d0b2006-09-27 14:09:26 +09007 * Copyright (C) 2003 Richard Curnow
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 */
13#include <linux/init.h>
14#include <linux/kernel.h>
Paul Mundtaec5e0e2006-12-25 09:51:47 +090015#include <linux/mm.h>
16#include <asm/mmu_context.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/processor.h>
18#include <asm/uaccess.h>
Paul Mundtf3c25752006-09-27 18:36:17 +090019#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/system.h>
21#include <asm/cacheflush.h>
22#include <asm/cache.h>
23#include <asm/io.h>
Paul Mundtaba10302007-09-21 18:32:32 +090024#include <asm/smp.h>
Paul Mundtc881cbc2007-11-10 20:18:18 +090025#ifdef CONFIG_SUPERH32
26#include <asm/ubc.h>
27#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29/*
30 * Generic wrapper for command line arguments to disable on-chip
31 * peripherals (nofpu, nodsp, and so forth).
32 */
33#define onchip_setup(x) \
34static int x##_disabled __initdata = 0; \
35 \
36static int __init x##_setup(char *opts) \
37{ \
38 x##_disabled = 1; \
OGAWA Hirofumi9b410462006-03-31 02:30:33 -080039 return 1; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070040} \
41__setup("no" __stringify(x), x##_setup);
42
43onchip_setup(fpu);
44onchip_setup(dsp);
45
Paul Mundt45ed2852007-03-08 18:12:17 +090046#ifdef CONFIG_SPECULATIVE_EXECUTION
47#define CPUOPM 0xff2f0000
48#define CPUOPM_RABD (1 << 5)
49
50static void __init speculative_execution_init(void)
51{
52 /* Clear RABD */
53 ctrl_outl(ctrl_inl(CPUOPM) & ~CPUOPM_RABD, CPUOPM);
54
55 /* Flush the update */
56 (void)ctrl_inl(CPUOPM);
57 ctrl_barrier();
58}
59#else
60#define speculative_execution_init() do { } while (0)
61#endif
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063/*
64 * Generic first-level cache init
65 */
Paul Mundt27a511c2007-11-10 20:25:28 +090066#ifdef CONFIG_SUPERH32
Stuart Menefycbaa1182007-11-30 17:06:36 +090067static void __uses_jump_to_uncached cache_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 unsigned long ccr, flags;
70
Stuart Menefycbaa1182007-11-30 17:06:36 +090071 jump_to_uncached();
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 ccr = ctrl_inl(CCR);
73
74 /*
Richard Curnowb638d0b2006-09-27 14:09:26 +090075 * At this point we don't know whether the cache is enabled or not - a
76 * bootloader may have enabled it. There are at least 2 things that
77 * could be dirty in the cache at this point:
78 * 1. kernel command line set up by boot loader
79 * 2. spilled registers from the prolog of this function
80 * => before re-initialising the cache, we must do a purge of the whole
81 * cache out to memory for safety. As long as nothing is spilled
82 * during the loop to lines that have already been done, this is safe.
83 * - RPC
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 */
85 if (ccr & CCR_CACHE_ENABLE) {
86 unsigned long ways, waysize, addrstart;
87
Paul Mundt11c19652006-12-25 10:19:56 +090088 waysize = current_cpu_data.dcache.sets;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Yoshinori Sato9d4436a2006-11-05 15:40:13 +090090#ifdef CCR_CACHE_ORA
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 /*
92 * If the OC is already in RAM mode, we only have
93 * half of the entries to flush..
94 */
95 if (ccr & CCR_CACHE_ORA)
96 waysize >>= 1;
Yoshinori Sato9d4436a2006-11-05 15:40:13 +090097#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Paul Mundt11c19652006-12-25 10:19:56 +090099 waysize <<= current_cpu_data.dcache.entry_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101#ifdef CCR_CACHE_EMODE
102 /* If EMODE is not set, we only have 1 way to flush. */
103 if (!(ccr & CCR_CACHE_EMODE))
104 ways = 1;
105 else
106#endif
Paul Mundt11c19652006-12-25 10:19:56 +0900107 ways = current_cpu_data.dcache.ways;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109 addrstart = CACHE_OC_ADDRESS_ARRAY;
110 do {
111 unsigned long addr;
112
113 for (addr = addrstart;
114 addr < addrstart + waysize;
Paul Mundt11c19652006-12-25 10:19:56 +0900115 addr += current_cpu_data.dcache.linesz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 ctrl_outl(0, addr);
117
Paul Mundt11c19652006-12-25 10:19:56 +0900118 addrstart += current_cpu_data.dcache.way_incr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 } while (--ways);
120 }
121
122 /*
123 * Default CCR values .. enable the caches
124 * and invalidate them immediately..
125 */
126 flags = CCR_CACHE_ENABLE | CCR_CACHE_INVALIDATE;
127
128#ifdef CCR_CACHE_EMODE
129 /* Force EMODE if possible */
Paul Mundt11c19652006-12-25 10:19:56 +0900130 if (current_cpu_data.dcache.ways > 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 flags |= CCR_CACHE_EMODE;
Richard Curnowb638d0b2006-09-27 14:09:26 +0900132 else
133 flags &= ~CCR_CACHE_EMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#endif
135
Paul Mundte7bd34a2007-07-31 17:07:28 +0900136#if defined(CONFIG_CACHE_WRITETHROUGH)
137 /* Write-through */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 flags |= CCR_CACHE_WT;
Paul Mundte7bd34a2007-07-31 17:07:28 +0900139#elif defined(CONFIG_CACHE_WRITEBACK)
140 /* Write-back */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 flags |= CCR_CACHE_CB;
Paul Mundte7bd34a2007-07-31 17:07:28 +0900142#else
143 /* Off */
144 flags &= ~CCR_CACHE_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#endif
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 ctrl_outl(flags, CCR);
Stuart Menefycbaa1182007-11-30 17:06:36 +0900148 back_to_cached();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
Paul Mundt27a511c2007-11-10 20:25:28 +0900150#else
151#define cache_init() do { } while (0)
152#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154#ifdef CONFIG_SH_DSP
155static void __init release_dsp(void)
156{
157 unsigned long sr;
158
159 /* Clear SR.DSP bit */
160 __asm__ __volatile__ (
161 "stc\tsr, %0\n\t"
162 "and\t%1, %0\n\t"
163 "ldc\t%0, sr\n\t"
164 : "=&r" (sr)
165 : "r" (~SR_DSP)
166 );
167}
168
169static void __init dsp_init(void)
170{
171 unsigned long sr;
172
173 /*
174 * Set the SR.DSP bit, wait for one instruction, and then read
175 * back the SR value.
176 */
177 __asm__ __volatile__ (
178 "stc\tsr, %0\n\t"
179 "or\t%1, %0\n\t"
180 "ldc\t%0, sr\n\t"
181 "nop\n\t"
182 "stc\tsr, %0\n\t"
183 : "=&r" (sr)
184 : "r" (SR_DSP)
185 );
186
187 /* If the DSP bit is still set, this CPU has a DSP */
188 if (sr & SR_DSP)
Paul Mundt11c19652006-12-25 10:19:56 +0900189 current_cpu_data.flags |= CPU_HAS_DSP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 /* Now that we've determined the DSP status, clear the DSP bit. */
192 release_dsp();
193}
194#endif /* CONFIG_SH_DSP */
195
196/**
197 * sh_cpu_init
198 *
199 * This is our initial entry point for each CPU, and is invoked on the boot
200 * CPU prior to calling start_kernel(). For SMP, a combination of this and
201 * start_secondary() will bring up each processor to a ready state prior
202 * to hand forking the idle loop.
203 *
204 * We do all of the basic processor init here, including setting up the
205 * caches, FPU, DSP, kicking the UBC, etc. By the time start_kernel() is
206 * hit (and subsequently platform_setup()) things like determining the
207 * CPU subtype and initial configuration will all be done.
208 *
209 * Each processor family is still responsible for doing its own probing
210 * and cache configuration in detect_cpu_and_cache_system().
211 */
Paul Mundtaba10302007-09-21 18:32:32 +0900212
213asmlinkage void __cpuinit sh_cpu_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Paul Mundtaba10302007-09-21 18:32:32 +0900215 current_thread_info()->cpu = hard_smp_processor_id();
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 /* First, probe the CPU */
218 detect_cpu_and_cache_system();
219
Paul Mundtffe1b4e2007-03-12 16:15:22 +0900220 if (current_cpu_data.type == CPU_SH_NONE)
221 panic("Unknown CPU");
222
Paul Mundt27a511c2007-11-10 20:25:28 +0900223 /* First setup the rest of the I-cache info */
224 current_cpu_data.icache.entry_mask = current_cpu_data.icache.way_incr -
225 current_cpu_data.icache.linesz;
226
227 current_cpu_data.icache.way_size = current_cpu_data.icache.sets *
228 current_cpu_data.icache.linesz;
229
230 /* And the D-cache too */
231 current_cpu_data.dcache.entry_mask = current_cpu_data.dcache.way_incr -
232 current_cpu_data.dcache.linesz;
233
234 current_cpu_data.dcache.way_size = current_cpu_data.dcache.sets *
235 current_cpu_data.dcache.linesz;
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 /* Init the cache */
238 cache_init();
239
Paul Mundtaba10302007-09-21 18:32:32 +0900240 if (raw_smp_processor_id() == 0)
241 shm_align_mask = max_t(unsigned long,
242 current_cpu_data.dcache.way_size - 1,
243 PAGE_SIZE - 1);
Paul Mundtf3c25752006-09-27 18:36:17 +0900244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 /* Disable the FPU */
246 if (fpu_disabled) {
247 printk("FPU Disabled\n");
Paul Mundt11c19652006-12-25 10:19:56 +0900248 current_cpu_data.flags &= ~CPU_HAS_FPU;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 disable_fpu();
250 }
251
252 /* FPU initialization */
Paul Mundt11c19652006-12-25 10:19:56 +0900253 if ((current_cpu_data.flags & CPU_HAS_FPU)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 clear_thread_flag(TIF_USEDFPU);
255 clear_used_math();
256 }
257
Paul Mundtaec5e0e2006-12-25 09:51:47 +0900258 /*
259 * Initialize the per-CPU ASID cache very early, since the
260 * TLB flushing routines depend on this being setup.
261 */
262 current_cpu_data.asid_cache = NO_CONTEXT;
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#ifdef CONFIG_SH_DSP
265 /* Probe for DSP */
266 dsp_init();
267
268 /* Disable the DSP */
269 if (dsp_disabled) {
270 printk("DSP Disabled\n");
Paul Mundt11c19652006-12-25 10:19:56 +0900271 current_cpu_data.flags &= ~CPU_HAS_DSP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 release_dsp();
273 }
274#endif
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 /*
277 * Some brain-damaged loaders decided it would be a good idea to put
278 * the UBC to sleep. This causes some issues when it comes to things
279 * like PTRACE_SINGLESTEP or doing hardware watchpoints in GDB. So ..
280 * we wake it up and hope that all is well.
281 */
Paul Mundtc881cbc2007-11-10 20:18:18 +0900282#ifdef CONFIG_SUPERH32
Paul Mundtaba10302007-09-21 18:32:32 +0900283 if (raw_smp_processor_id() == 0)
284 ubc_wakeup();
Paul Mundtc881cbc2007-11-10 20:18:18 +0900285#endif
286
Paul Mundt45ed2852007-03-08 18:12:17 +0900287 speculative_execution_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}