2 * arch/sh/kernel/cpu/init.c
6 * Copyright (C) 2002 - 2007 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 <asm/mmu_context.h>
17 #include <asm/processor.h>
18 #include <asm/uaccess.h>
20 #include <asm/system.h>
21 #include <asm/cacheflush.h>
22 #include <asm/cache.h>
25 #ifdef CONFIG_SUPERH32
30 * Generic wrapper for command line arguments to disable on-chip
31 * peripherals (nofpu, nodsp, and so forth).
33 #define onchip_setup(x) \
34 static int x##_disabled __initdata = 0; \
36 static int __init x##_setup(char *opts) \
41 __setup("no" __stringify(x), x##_setup);
46 #ifdef CONFIG_SPECULATIVE_EXECUTION
47 #define CPUOPM 0xff2f0000
48 #define CPUOPM_RABD (1 << 5)
50 static void __init speculative_execution_init(void)
53 ctrl_outl(ctrl_inl(CPUOPM) & ~CPUOPM_RABD, CPUOPM);
55 /* Flush the update */
56 (void)ctrl_inl(CPUOPM);
60 #define speculative_execution_init() do { } while (0)
64 * Generic first-level cache init
66 #ifdef CONFIG_SUPERH32
67 static void __uses_jump_to_uncached cache_init(void)
69 unsigned long ccr, flags;
75 * 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.
85 if (ccr & CCR_CACHE_ENABLE) {
86 unsigned long ways, waysize, addrstart;
88 waysize = current_cpu_data.dcache.sets;
92 * If the OC is already in RAM mode, we only have
93 * half of the entries to flush..
95 if (ccr & CCR_CACHE_ORA)
99 waysize <<= current_cpu_data.dcache.entry_shift;
101 #ifdef CCR_CACHE_EMODE
102 /* If EMODE is not set, we only have 1 way to flush. */
103 if (!(ccr & CCR_CACHE_EMODE))
107 ways = current_cpu_data.dcache.ways;
109 addrstart = CACHE_OC_ADDRESS_ARRAY;
113 for (addr = addrstart;
114 addr < addrstart + waysize;
115 addr += current_cpu_data.dcache.linesz)
118 addrstart += current_cpu_data.dcache.way_incr;
123 * Default CCR values .. enable the caches
124 * and invalidate them immediately..
126 flags = CCR_CACHE_ENABLE | CCR_CACHE_INVALIDATE;
128 #ifdef CCR_CACHE_EMODE
129 /* Force EMODE if possible */
130 if (current_cpu_data.dcache.ways > 1)
131 flags |= CCR_CACHE_EMODE;
133 flags &= ~CCR_CACHE_EMODE;
136 #if defined(CONFIG_CACHE_WRITETHROUGH)
138 flags |= CCR_CACHE_WT;
139 #elif defined(CONFIG_CACHE_WRITEBACK)
141 flags |= CCR_CACHE_CB;
144 flags &= ~CCR_CACHE_ENABLE;
147 ctrl_outl(flags, CCR);
151 #define cache_init() do { } while (0)
155 static void __init release_dsp(void)
159 /* Clear SR.DSP bit */
160 __asm__ __volatile__ (
169 static void __init dsp_init(void)
174 * Set the SR.DSP bit, wait for one instruction, and then read
177 __asm__ __volatile__ (
187 /* If the DSP bit is still set, this CPU has a DSP */
189 current_cpu_data.flags |= CPU_HAS_DSP;
191 /* Now that we've determined the DSP status, clear the DSP bit. */
194 #endif /* CONFIG_SH_DSP */
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.
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.
209 * Each processor family is still responsible for doing its own probing
210 * and cache configuration in detect_cpu_and_cache_system().
213 asmlinkage void __cpuinit sh_cpu_init(void)
215 current_thread_info()->cpu = hard_smp_processor_id();
217 /* First, probe the CPU */
218 detect_cpu_and_cache_system();
220 if (current_cpu_data.type == CPU_SH_NONE)
221 panic("Unknown CPU");
223 /* 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;
227 current_cpu_data.icache.way_size = current_cpu_data.icache.sets *
228 current_cpu_data.icache.linesz;
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;
234 current_cpu_data.dcache.way_size = current_cpu_data.dcache.sets *
235 current_cpu_data.dcache.linesz;
240 if (raw_smp_processor_id() == 0)
241 shm_align_mask = max_t(unsigned long,
242 current_cpu_data.dcache.way_size - 1,
245 /* Disable the FPU */
247 printk("FPU Disabled\n");
248 current_cpu_data.flags &= ~CPU_HAS_FPU;
252 /* FPU initialization */
253 if ((current_cpu_data.flags & CPU_HAS_FPU)) {
254 clear_thread_flag(TIF_USEDFPU);
259 * Initialize the per-CPU ASID cache very early, since the
260 * TLB flushing routines depend on this being setup.
262 current_cpu_data.asid_cache = NO_CONTEXT;
268 /* Disable the DSP */
270 printk("DSP Disabled\n");
271 current_cpu_data.flags &= ~CPU_HAS_DSP;
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.
282 #ifdef CONFIG_SUPERH32
283 if (raw_smp_processor_id() == 0)
287 speculative_execution_init();