2 * arch/sh/kernel/cpu/init.c
6 * Copyright (C) 2002 - 2009 Paul Mundt
7 * Copyright (C) 2003 Richard Curnow
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
13 #include <linux/init.h>
14 #include <linux/kernel.h>
16 #include <linux/log2.h>
17 #include <asm/mmu_context.h>
18 #include <asm/processor.h>
19 #include <asm/uaccess.h>
21 #include <asm/system.h>
22 #include <asm/cacheflush.h>
23 #include <asm/cache.h>
27 #include <asm/sh_bios.h>
42 * Generic wrapper for command line arguments to disable on-chip
43 * peripherals (nofpu, nodsp, and so forth).
45 #define onchip_setup(x) \
46 static int x##_disabled __cpuinitdata = !cpu_has_##x; \
48 static int __cpuinit x##_setup(char *opts) \
53 __setup("no" __stringify(x), x##_setup);
58 #ifdef CONFIG_SPECULATIVE_EXECUTION
59 #define CPUOPM 0xff2f0000
60 #define CPUOPM_RABD (1 << 5)
62 static void __cpuinit
speculative_execution_init(void)
65 __raw_writel(__raw_readl(CPUOPM
) & ~CPUOPM_RABD
, CPUOPM
);
67 /* Flush the update */
68 (void)__raw_readl(CPUOPM
);
72 #define speculative_execution_init() do { } while (0)
75 #ifdef CONFIG_CPU_SH4A
76 #define EXPMASK 0xff2f0004
77 #define EXPMASK_RTEDS (1 << 0)
78 #define EXPMASK_BRDSSLP (1 << 1)
79 #define EXPMASK_MMCAW (1 << 4)
81 static void __cpuinit
expmask_init(void)
83 unsigned long expmask
= __raw_readl(EXPMASK
);
88 * Disable support for slottable sleep instruction, non-nop
89 * instructions in the rte delay slot, and associative writes to
90 * the memory-mapped cache array.
92 expmask
&= ~(EXPMASK_RTEDS
| EXPMASK_BRDSSLP
| EXPMASK_MMCAW
);
94 __raw_writel(expmask
, EXPMASK
);
98 #define expmask_init() do { } while (0)
101 /* 2nd-level cache init */
102 void __attribute__ ((weak
)) l2_cache_init(void)
107 * Generic first-level cache init
109 #ifdef CONFIG_SUPERH32
110 static void cache_init(void)
112 unsigned long ccr
, flags
;
115 ccr
= __raw_readl(CCR
);
118 * At this point we don't know whether the cache is enabled or not - a
119 * bootloader may have enabled it. There are at least 2 things that
120 * could be dirty in the cache at this point:
121 * 1. kernel command line set up by boot loader
122 * 2. spilled registers from the prolog of this function
123 * => before re-initialising the cache, we must do a purge of the whole
124 * cache out to memory for safety. As long as nothing is spilled
125 * during the loop to lines that have already been done, this is safe.
128 if (ccr
& CCR_CACHE_ENABLE
) {
129 unsigned long ways
, waysize
, addrstart
;
131 waysize
= current_cpu_data
.dcache
.sets
;
135 * If the OC is already in RAM mode, we only have
136 * half of the entries to flush..
138 if (ccr
& CCR_CACHE_ORA
)
142 waysize
<<= current_cpu_data
.dcache
.entry_shift
;
144 #ifdef CCR_CACHE_EMODE
145 /* If EMODE is not set, we only have 1 way to flush. */
146 if (!(ccr
& CCR_CACHE_EMODE
))
150 ways
= current_cpu_data
.dcache
.ways
;
152 addrstart
= CACHE_OC_ADDRESS_ARRAY
;
156 for (addr
= addrstart
;
157 addr
< addrstart
+ waysize
;
158 addr
+= current_cpu_data
.dcache
.linesz
)
159 __raw_writel(0, addr
);
161 addrstart
+= current_cpu_data
.dcache
.way_incr
;
166 * Default CCR values .. enable the caches
167 * and invalidate them immediately..
169 flags
= CCR_CACHE_ENABLE
| CCR_CACHE_INVALIDATE
;
171 #ifdef CCR_CACHE_EMODE
172 /* Force EMODE if possible */
173 if (current_cpu_data
.dcache
.ways
> 1)
174 flags
|= CCR_CACHE_EMODE
;
176 flags
&= ~CCR_CACHE_EMODE
;
179 #if defined(CONFIG_CACHE_WRITETHROUGH)
181 flags
|= CCR_CACHE_WT
;
182 #elif defined(CONFIG_CACHE_WRITEBACK)
184 flags
|= CCR_CACHE_CB
;
187 flags
&= ~CCR_CACHE_ENABLE
;
192 __raw_writel(flags
, CCR
);
196 #define cache_init() do { } while (0)
199 #define CSHAPE(totalsize, linesize, assoc) \
200 ((totalsize & ~0xff) | (linesize << 4) | assoc)
202 #define CACHE_DESC_SHAPE(desc) \
203 CSHAPE((desc).way_size * (desc).ways, ilog2((desc).linesz), (desc).ways)
205 static void detect_cache_shape(void)
207 l1d_cache_shape
= CACHE_DESC_SHAPE(current_cpu_data
.dcache
);
209 if (current_cpu_data
.dcache
.flags
& SH_CACHE_COMBINED
)
210 l1i_cache_shape
= l1d_cache_shape
;
212 l1i_cache_shape
= CACHE_DESC_SHAPE(current_cpu_data
.icache
);
214 if (current_cpu_data
.flags
& CPU_HAS_L2_CACHE
)
215 l2_cache_shape
= CACHE_DESC_SHAPE(current_cpu_data
.scache
);
217 l2_cache_shape
= -1; /* No S-cache */
220 static void __cpuinit
fpu_init(void)
222 /* Disable the FPU */
223 if (fpu_disabled
&& (current_cpu_data
.flags
& CPU_HAS_FPU
)) {
224 printk("FPU Disabled\n");
225 current_cpu_data
.flags
&= ~CPU_HAS_FPU
;
233 static void __cpuinit
release_dsp(void)
237 /* Clear SR.DSP bit */
238 __asm__
__volatile__ (
247 static void __cpuinit
dsp_init(void)
252 * Set the SR.DSP bit, wait for one instruction, and then read
255 __asm__
__volatile__ (
265 /* If the DSP bit is still set, this CPU has a DSP */
267 current_cpu_data
.flags
|= CPU_HAS_DSP
;
269 /* Disable the DSP */
270 if (dsp_disabled
&& (current_cpu_data
.flags
& CPU_HAS_DSP
)) {
271 printk("DSP Disabled\n");
272 current_cpu_data
.flags
&= ~CPU_HAS_DSP
;
275 /* Now that we've determined the DSP status, clear the DSP bit. */
279 static inline void __cpuinit
dsp_init(void) { }
280 #endif /* CONFIG_SH_DSP */
285 * This is our initial entry point for each CPU, and is invoked on the
286 * boot CPU prior to calling start_kernel(). For SMP, a combination of
287 * this and start_secondary() will bring up each processor to a ready
288 * state prior to hand forking the idle loop.
290 * We do all of the basic processor init here, including setting up
291 * the caches, FPU, DSP, etc. By the time start_kernel() is hit (and
292 * subsequently platform_setup()) things like determining the CPU
293 * subtype and initial configuration will all be done.
295 * Each processor family is still responsible for doing its own probing
296 * and cache configuration in cpu_probe().
298 asmlinkage
void __cpuinit
cpu_init(void)
300 current_thread_info()->cpu
= hard_smp_processor_id();
302 /* First, probe the CPU */
305 if (current_cpu_data
.type
== CPU_SH_NONE
)
306 panic("Unknown CPU");
308 /* First setup the rest of the I-cache info */
309 current_cpu_data
.icache
.entry_mask
= current_cpu_data
.icache
.way_incr
-
310 current_cpu_data
.icache
.linesz
;
312 current_cpu_data
.icache
.way_size
= current_cpu_data
.icache
.sets
*
313 current_cpu_data
.icache
.linesz
;
315 /* And the D-cache too */
316 current_cpu_data
.dcache
.entry_mask
= current_cpu_data
.dcache
.way_incr
-
317 current_cpu_data
.dcache
.linesz
;
319 current_cpu_data
.dcache
.way_size
= current_cpu_data
.dcache
.sets
*
320 current_cpu_data
.dcache
.linesz
;
325 if (raw_smp_processor_id() == 0) {
326 shm_align_mask
= max_t(unsigned long,
327 current_cpu_data
.dcache
.way_size
- 1,
330 /* Boot CPU sets the cache shape */
331 detect_cache_shape();
338 * Initialize the per-CPU ASID cache very early, since the
339 * TLB flushing routines depend on this being setup.
341 current_cpu_data
.asid_cache
= NO_CONTEXT
;
343 current_cpu_data
.phys_bits
= __in_29bit_mode() ? 29 : 32;
345 speculative_execution_init();
348 /* Do the rest of the boot processor setup */
349 if (raw_smp_processor_id() == 0) {
350 /* Save off the BIOS VBR, if there is one */
354 * Setup VBR for boot CPU. Secondary CPUs do this through
360 * Boot processor to setup the FP and extended state
363 init_thread_xstate();