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>
27 * Generic wrapper for command line arguments to disable on-chip
28 * peripherals (nofpu, nodsp, and so forth).
30 #define onchip_setup(x) \
31 static int x##_disabled __initdata = 0; \
33 static int __init x##_setup(char *opts) \
38 __setup("no" __stringify(x), x##_setup);
43 #ifdef CONFIG_SPECULATIVE_EXECUTION
44 #define CPUOPM 0xff2f0000
45 #define CPUOPM_RABD (1 << 5)
47 static void __init speculative_execution_init(void)
50 ctrl_outl(ctrl_inl(CPUOPM) & ~CPUOPM_RABD, CPUOPM);
52 /* Flush the update */
53 (void)ctrl_inl(CPUOPM);
57 #define speculative_execution_init() do { } while (0)
61 * Generic first-level cache init
63 static void __init cache_init(void)
65 unsigned long ccr, flags;
67 /* First setup the rest of the I-cache info */
68 current_cpu_data.icache.entry_mask = current_cpu_data.icache.way_incr -
69 current_cpu_data.icache.linesz;
71 current_cpu_data.icache.way_size = current_cpu_data.icache.sets *
72 current_cpu_data.icache.linesz;
74 /* And the D-cache too */
75 current_cpu_data.dcache.entry_mask = current_cpu_data.dcache.way_incr -
76 current_cpu_data.dcache.linesz;
78 current_cpu_data.dcache.way_size = current_cpu_data.dcache.sets *
79 current_cpu_data.dcache.linesz;
85 * At this point we don't know whether the cache is enabled or not - a
86 * bootloader may have enabled it. There are at least 2 things that
87 * could be dirty in the cache at this point:
88 * 1. kernel command line set up by boot loader
89 * 2. spilled registers from the prolog of this function
90 * => before re-initialising the cache, we must do a purge of the whole
91 * cache out to memory for safety. As long as nothing is spilled
92 * during the loop to lines that have already been done, this is safe.
95 if (ccr & CCR_CACHE_ENABLE) {
96 unsigned long ways, waysize, addrstart;
98 waysize = current_cpu_data.dcache.sets;
102 * If the OC is already in RAM mode, we only have
103 * half of the entries to flush..
105 if (ccr & CCR_CACHE_ORA)
109 waysize <<= current_cpu_data.dcache.entry_shift;
111 #ifdef CCR_CACHE_EMODE
112 /* If EMODE is not set, we only have 1 way to flush. */
113 if (!(ccr & CCR_CACHE_EMODE))
117 ways = current_cpu_data.dcache.ways;
119 addrstart = CACHE_OC_ADDRESS_ARRAY;
123 for (addr = addrstart;
124 addr < addrstart + waysize;
125 addr += current_cpu_data.dcache.linesz)
128 addrstart += current_cpu_data.dcache.way_incr;
133 * Default CCR values .. enable the caches
134 * and invalidate them immediately..
136 flags = CCR_CACHE_ENABLE | CCR_CACHE_INVALIDATE;
138 #ifdef CCR_CACHE_EMODE
139 /* Force EMODE if possible */
140 if (current_cpu_data.dcache.ways > 1)
141 flags |= CCR_CACHE_EMODE;
143 flags &= ~CCR_CACHE_EMODE;
146 #ifdef CONFIG_SH_WRITETHROUGH
147 /* Turn on Write-through caching */
148 flags |= CCR_CACHE_WT;
150 /* .. or default to Write-back */
151 flags |= CCR_CACHE_CB;
154 ctrl_outl(flags, CCR);
159 static void __init release_dsp(void)
163 /* Clear SR.DSP bit */
164 __asm__ __volatile__ (
173 static void __init dsp_init(void)
178 * Set the SR.DSP bit, wait for one instruction, and then read
181 __asm__ __volatile__ (
191 /* If the DSP bit is still set, this CPU has a DSP */
193 current_cpu_data.flags |= CPU_HAS_DSP;
195 /* Now that we've determined the DSP status, clear the DSP bit. */
198 #endif /* CONFIG_SH_DSP */
203 * This is our initial entry point for each CPU, and is invoked on the boot
204 * CPU prior to calling start_kernel(). For SMP, a combination of this and
205 * start_secondary() will bring up each processor to a ready state prior
206 * to hand forking the idle loop.
208 * We do all of the basic processor init here, including setting up the
209 * caches, FPU, DSP, kicking the UBC, etc. By the time start_kernel() is
210 * hit (and subsequently platform_setup()) things like determining the
211 * CPU subtype and initial configuration will all be done.
213 * Each processor family is still responsible for doing its own probing
214 * and cache configuration in detect_cpu_and_cache_system().
216 asmlinkage void __init sh_cpu_init(void)
218 /* First, probe the CPU */
219 detect_cpu_and_cache_system();
221 if (current_cpu_data.type == CPU_SH_NONE)
222 panic("Unknown CPU");
227 shm_align_mask = max_t(unsigned long,
228 current_cpu_data.dcache.way_size - 1,
231 /* Disable the FPU */
233 printk("FPU Disabled\n");
234 current_cpu_data.flags &= ~CPU_HAS_FPU;
238 /* FPU initialization */
239 if ((current_cpu_data.flags & CPU_HAS_FPU)) {
240 clear_thread_flag(TIF_USEDFPU);
245 * Initialize the per-CPU ASID cache very early, since the
246 * TLB flushing routines depend on this being setup.
248 current_cpu_data.asid_cache = NO_CONTEXT;
254 /* Disable the DSP */
256 printk("DSP Disabled\n");
257 current_cpu_data.flags &= ~CPU_HAS_DSP;
263 * Some brain-damaged loaders decided it would be a good idea to put
264 * the UBC to sleep. This causes some issues when it comes to things
265 * like PTRACE_SINGLESTEP or doing hardware watchpoints in GDB. So ..
266 * we wake it up and hope that all is well.
269 speculative_execution_init();