sh: Kill off dead UBC headers.
[linux-2.6.git] / arch / sh / kernel / cpu / init.c
blob39b93828c872237de97cc5dc8d9ee5db08f4c7be
1 /*
2 * arch/sh/kernel/cpu/init.c
4 * CPU init code
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
11 * for more details.
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/mm.h>
16 #include <linux/log2.h>
17 #include <asm/mmu_context.h>
18 #include <asm/processor.h>
19 #include <asm/uaccess.h>
20 #include <asm/page.h>
21 #include <asm/system.h>
22 #include <asm/cacheflush.h>
23 #include <asm/cache.h>
24 #include <asm/elf.h>
25 #include <asm/io.h>
26 #include <asm/smp.h>
29 * Generic wrapper for command line arguments to disable on-chip
30 * peripherals (nofpu, nodsp, and so forth).
32 #define onchip_setup(x) \
33 static int x##_disabled __initdata = 0; \
35 static int __init x##_setup(char *opts) \
36 { \
37 x##_disabled = 1; \
38 return 1; \
39 } \
40 __setup("no" __stringify(x), x##_setup);
42 onchip_setup(fpu);
43 onchip_setup(dsp);
45 #ifdef CONFIG_SPECULATIVE_EXECUTION
46 #define CPUOPM 0xff2f0000
47 #define CPUOPM_RABD (1 << 5)
49 static void __init speculative_execution_init(void)
51 /* Clear RABD */
52 ctrl_outl(ctrl_inl(CPUOPM) & ~CPUOPM_RABD, CPUOPM);
54 /* Flush the update */
55 (void)ctrl_inl(CPUOPM);
56 ctrl_barrier();
58 #else
59 #define speculative_execution_init() do { } while (0)
60 #endif
62 #ifdef CONFIG_CPU_SH4A
63 #define EXPMASK 0xff2f0004
64 #define EXPMASK_RTEDS (1 << 0)
65 #define EXPMASK_BRDSSLP (1 << 1)
66 #define EXPMASK_MMCAW (1 << 4)
68 static void __init expmask_init(void)
70 unsigned long expmask = __raw_readl(EXPMASK);
73 * Future proofing.
75 * Disable support for slottable sleep instruction, non-nop
76 * instructions in the rte delay slot, and associative writes to
77 * the memory-mapped cache array.
79 expmask &= ~(EXPMASK_RTEDS | EXPMASK_BRDSSLP | EXPMASK_MMCAW);
81 __raw_writel(expmask, EXPMASK);
82 ctrl_barrier();
84 #else
85 #define expmask_init() do { } while (0)
86 #endif
88 /* 2nd-level cache init */
89 void __uses_jump_to_uncached __attribute__ ((weak)) l2_cache_init(void)
94 * Generic first-level cache init
96 #ifdef CONFIG_SUPERH32
97 static void __uses_jump_to_uncached cache_init(void)
99 unsigned long ccr, flags;
101 jump_to_uncached();
102 ccr = ctrl_inl(CCR);
105 * At this point we don't know whether the cache is enabled or not - a
106 * bootloader may have enabled it. There are at least 2 things that
107 * could be dirty in the cache at this point:
108 * 1. kernel command line set up by boot loader
109 * 2. spilled registers from the prolog of this function
110 * => before re-initialising the cache, we must do a purge of the whole
111 * cache out to memory for safety. As long as nothing is spilled
112 * during the loop to lines that have already been done, this is safe.
113 * - RPC
115 if (ccr & CCR_CACHE_ENABLE) {
116 unsigned long ways, waysize, addrstart;
118 waysize = current_cpu_data.dcache.sets;
120 #ifdef CCR_CACHE_ORA
122 * If the OC is already in RAM mode, we only have
123 * half of the entries to flush..
125 if (ccr & CCR_CACHE_ORA)
126 waysize >>= 1;
127 #endif
129 waysize <<= current_cpu_data.dcache.entry_shift;
131 #ifdef CCR_CACHE_EMODE
132 /* If EMODE is not set, we only have 1 way to flush. */
133 if (!(ccr & CCR_CACHE_EMODE))
134 ways = 1;
135 else
136 #endif
137 ways = current_cpu_data.dcache.ways;
139 addrstart = CACHE_OC_ADDRESS_ARRAY;
140 do {
141 unsigned long addr;
143 for (addr = addrstart;
144 addr < addrstart + waysize;
145 addr += current_cpu_data.dcache.linesz)
146 ctrl_outl(0, addr);
148 addrstart += current_cpu_data.dcache.way_incr;
149 } while (--ways);
153 * Default CCR values .. enable the caches
154 * and invalidate them immediately..
156 flags = CCR_CACHE_ENABLE | CCR_CACHE_INVALIDATE;
158 #ifdef CCR_CACHE_EMODE
159 /* Force EMODE if possible */
160 if (current_cpu_data.dcache.ways > 1)
161 flags |= CCR_CACHE_EMODE;
162 else
163 flags &= ~CCR_CACHE_EMODE;
164 #endif
166 #if defined(CONFIG_CACHE_WRITETHROUGH)
167 /* Write-through */
168 flags |= CCR_CACHE_WT;
169 #elif defined(CONFIG_CACHE_WRITEBACK)
170 /* Write-back */
171 flags |= CCR_CACHE_CB;
172 #else
173 /* Off */
174 flags &= ~CCR_CACHE_ENABLE;
175 #endif
177 l2_cache_init();
179 ctrl_outl(flags, CCR);
180 back_to_cached();
182 #else
183 #define cache_init() do { } while (0)
184 #endif
186 #define CSHAPE(totalsize, linesize, assoc) \
187 ((totalsize & ~0xff) | (linesize << 4) | assoc)
189 #define CACHE_DESC_SHAPE(desc) \
190 CSHAPE((desc).way_size * (desc).ways, ilog2((desc).linesz), (desc).ways)
192 static void detect_cache_shape(void)
194 l1d_cache_shape = CACHE_DESC_SHAPE(current_cpu_data.dcache);
196 if (current_cpu_data.dcache.flags & SH_CACHE_COMBINED)
197 l1i_cache_shape = l1d_cache_shape;
198 else
199 l1i_cache_shape = CACHE_DESC_SHAPE(current_cpu_data.icache);
201 if (current_cpu_data.flags & CPU_HAS_L2_CACHE)
202 l2_cache_shape = CACHE_DESC_SHAPE(current_cpu_data.scache);
203 else
204 l2_cache_shape = -1; /* No S-cache */
207 #ifdef CONFIG_SH_DSP
208 static void __init release_dsp(void)
210 unsigned long sr;
212 /* Clear SR.DSP bit */
213 __asm__ __volatile__ (
214 "stc\tsr, %0\n\t"
215 "and\t%1, %0\n\t"
216 "ldc\t%0, sr\n\t"
217 : "=&r" (sr)
218 : "r" (~SR_DSP)
222 static void __init dsp_init(void)
224 unsigned long sr;
227 * Set the SR.DSP bit, wait for one instruction, and then read
228 * back the SR value.
230 __asm__ __volatile__ (
231 "stc\tsr, %0\n\t"
232 "or\t%1, %0\n\t"
233 "ldc\t%0, sr\n\t"
234 "nop\n\t"
235 "stc\tsr, %0\n\t"
236 : "=&r" (sr)
237 : "r" (SR_DSP)
240 /* If the DSP bit is still set, this CPU has a DSP */
241 if (sr & SR_DSP)
242 current_cpu_data.flags |= CPU_HAS_DSP;
244 /* Now that we've determined the DSP status, clear the DSP bit. */
245 release_dsp();
247 #endif /* CONFIG_SH_DSP */
250 * sh_cpu_init
252 * This is our initial entry point for each CPU, and is invoked on the
253 * boot CPU prior to calling start_kernel(). For SMP, a combination of
254 * this and start_secondary() will bring up each processor to a ready
255 * state prior to hand forking the idle loop.
257 * We do all of the basic processor init here, including setting up
258 * the caches, FPU, DSP, etc. By the time start_kernel() is hit (and
259 * subsequently platform_setup()) things like determining the CPU
260 * subtype and initial configuration will all be done.
262 * Each processor family is still responsible for doing its own probing
263 * and cache configuration in detect_cpu_and_cache_system().
265 asmlinkage void __init sh_cpu_init(void)
267 current_thread_info()->cpu = hard_smp_processor_id();
269 /* First, probe the CPU */
270 detect_cpu_and_cache_system();
272 if (current_cpu_data.type == CPU_SH_NONE)
273 panic("Unknown CPU");
275 /* First setup the rest of the I-cache info */
276 current_cpu_data.icache.entry_mask = current_cpu_data.icache.way_incr -
277 current_cpu_data.icache.linesz;
279 current_cpu_data.icache.way_size = current_cpu_data.icache.sets *
280 current_cpu_data.icache.linesz;
282 /* And the D-cache too */
283 current_cpu_data.dcache.entry_mask = current_cpu_data.dcache.way_incr -
284 current_cpu_data.dcache.linesz;
286 current_cpu_data.dcache.way_size = current_cpu_data.dcache.sets *
287 current_cpu_data.dcache.linesz;
289 /* Init the cache */
290 cache_init();
292 if (raw_smp_processor_id() == 0) {
293 shm_align_mask = max_t(unsigned long,
294 current_cpu_data.dcache.way_size - 1,
295 PAGE_SIZE - 1);
297 /* Boot CPU sets the cache shape */
298 detect_cache_shape();
301 /* Disable the FPU */
302 if (fpu_disabled) {
303 printk("FPU Disabled\n");
304 current_cpu_data.flags &= ~CPU_HAS_FPU;
307 /* FPU initialization */
308 disable_fpu();
309 if ((current_cpu_data.flags & CPU_HAS_FPU)) {
310 current_thread_info()->status &= ~TS_USEDFPU;
311 clear_used_math();
315 * Initialize the per-CPU ASID cache very early, since the
316 * TLB flushing routines depend on this being setup.
318 current_cpu_data.asid_cache = NO_CONTEXT;
320 #ifdef CONFIG_SH_DSP
321 /* Probe for DSP */
322 dsp_init();
324 /* Disable the DSP */
325 if (dsp_disabled) {
326 printk("DSP Disabled\n");
327 current_cpu_data.flags &= ~CPU_HAS_DSP;
328 release_dsp();
330 #endif
332 speculative_execution_init();
333 expmask_init();