blob: 731dd61419ddedc552426f879f5fbcb33e47b066 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/sh/kernel/cpu/init.c
3 *
4 * CPU init code
5 *
6 * Copyright (C) 2002, 2003 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>
15#include <asm/processor.h>
16#include <asm/uaccess.h>
17#include <asm/system.h>
18#include <asm/cacheflush.h>
19#include <asm/cache.h>
20#include <asm/io.h>
21
22extern void detect_cpu_and_cache_system(void);
23
24/*
25 * Generic wrapper for command line arguments to disable on-chip
26 * peripherals (nofpu, nodsp, and so forth).
27 */
28#define onchip_setup(x) \
29static int x##_disabled __initdata = 0; \
30 \
31static int __init x##_setup(char *opts) \
32{ \
33 x##_disabled = 1; \
OGAWA Hirofumi9b410462006-03-31 02:30:33 -080034 return 1; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070035} \
36__setup("no" __stringify(x), x##_setup);
37
38onchip_setup(fpu);
39onchip_setup(dsp);
40
41/*
42 * Generic first-level cache init
43 */
44static void __init cache_init(void)
45{
46 unsigned long ccr, flags;
47
48 if (cpu_data->type == CPU_SH_NONE)
49 panic("Unknown CPU");
50
51 jump_to_P2();
52 ccr = ctrl_inl(CCR);
53
54 /*
Richard Curnowb638d0b2006-09-27 14:09:26 +090055 * At this point we don't know whether the cache is enabled or not - a
56 * bootloader may have enabled it. There are at least 2 things that
57 * could be dirty in the cache at this point:
58 * 1. kernel command line set up by boot loader
59 * 2. spilled registers from the prolog of this function
60 * => before re-initialising the cache, we must do a purge of the whole
61 * cache out to memory for safety. As long as nothing is spilled
62 * during the loop to lines that have already been done, this is safe.
63 * - RPC
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 */
65 if (ccr & CCR_CACHE_ENABLE) {
66 unsigned long ways, waysize, addrstart;
67
68 waysize = cpu_data->dcache.sets;
69
70 /*
71 * If the OC is already in RAM mode, we only have
72 * half of the entries to flush..
73 */
74 if (ccr & CCR_CACHE_ORA)
75 waysize >>= 1;
76
77 waysize <<= cpu_data->dcache.entry_shift;
78
79#ifdef CCR_CACHE_EMODE
80 /* If EMODE is not set, we only have 1 way to flush. */
81 if (!(ccr & CCR_CACHE_EMODE))
82 ways = 1;
83 else
84#endif
85 ways = cpu_data->dcache.ways;
86
87 addrstart = CACHE_OC_ADDRESS_ARRAY;
88 do {
89 unsigned long addr;
90
91 for (addr = addrstart;
92 addr < addrstart + waysize;
93 addr += cpu_data->dcache.linesz)
94 ctrl_outl(0, addr);
95
96 addrstart += cpu_data->dcache.way_incr;
97 } while (--ways);
98 }
99
100 /*
101 * Default CCR values .. enable the caches
102 * and invalidate them immediately..
103 */
104 flags = CCR_CACHE_ENABLE | CCR_CACHE_INVALIDATE;
105
106#ifdef CCR_CACHE_EMODE
107 /* Force EMODE if possible */
108 if (cpu_data->dcache.ways > 1)
109 flags |= CCR_CACHE_EMODE;
Richard Curnowb638d0b2006-09-27 14:09:26 +0900110 else
111 flags &= ~CCR_CACHE_EMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#endif
113
114#ifdef CONFIG_SH_WRITETHROUGH
115 /* Turn on Write-through caching */
116 flags |= CCR_CACHE_WT;
117#else
118 /* .. or default to Write-back */
119 flags |= CCR_CACHE_CB;
120#endif
121
122#ifdef CONFIG_SH_OCRAM
123 /* Turn on OCRAM -- halve the OC */
124 flags |= CCR_CACHE_ORA;
125 cpu_data->dcache.sets >>= 1;
Richard Curnowb638d0b2006-09-27 14:09:26 +0900126
127 cpu_data->dcache.way_size = cpu_data->dcache.sets *
128 cpu_data->dcache.linesz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#endif
130
131 ctrl_outl(flags, CCR);
132 back_to_P1();
133}
134
135#ifdef CONFIG_SH_DSP
136static void __init release_dsp(void)
137{
138 unsigned long sr;
139
140 /* Clear SR.DSP bit */
141 __asm__ __volatile__ (
142 "stc\tsr, %0\n\t"
143 "and\t%1, %0\n\t"
144 "ldc\t%0, sr\n\t"
145 : "=&r" (sr)
146 : "r" (~SR_DSP)
147 );
148}
149
150static void __init dsp_init(void)
151{
152 unsigned long sr;
153
154 /*
155 * Set the SR.DSP bit, wait for one instruction, and then read
156 * back the SR value.
157 */
158 __asm__ __volatile__ (
159 "stc\tsr, %0\n\t"
160 "or\t%1, %0\n\t"
161 "ldc\t%0, sr\n\t"
162 "nop\n\t"
163 "stc\tsr, %0\n\t"
164 : "=&r" (sr)
165 : "r" (SR_DSP)
166 );
167
168 /* If the DSP bit is still set, this CPU has a DSP */
169 if (sr & SR_DSP)
170 cpu_data->flags |= CPU_HAS_DSP;
171
172 /* Now that we've determined the DSP status, clear the DSP bit. */
173 release_dsp();
174}
175#endif /* CONFIG_SH_DSP */
176
177/**
178 * sh_cpu_init
179 *
180 * This is our initial entry point for each CPU, and is invoked on the boot
181 * CPU prior to calling start_kernel(). For SMP, a combination of this and
182 * start_secondary() will bring up each processor to a ready state prior
183 * to hand forking the idle loop.
184 *
185 * We do all of the basic processor init here, including setting up the
186 * caches, FPU, DSP, kicking the UBC, etc. By the time start_kernel() is
187 * hit (and subsequently platform_setup()) things like determining the
188 * CPU subtype and initial configuration will all be done.
189 *
190 * Each processor family is still responsible for doing its own probing
191 * and cache configuration in detect_cpu_and_cache_system().
192 */
193asmlinkage void __init sh_cpu_init(void)
194{
195 /* First, probe the CPU */
196 detect_cpu_and_cache_system();
197
198 /* Init the cache */
199 cache_init();
200
201 /* Disable the FPU */
202 if (fpu_disabled) {
203 printk("FPU Disabled\n");
204 cpu_data->flags &= ~CPU_HAS_FPU;
205 disable_fpu();
206 }
207
208 /* FPU initialization */
209 if ((cpu_data->flags & CPU_HAS_FPU)) {
210 clear_thread_flag(TIF_USEDFPU);
211 clear_used_math();
212 }
213
214#ifdef CONFIG_SH_DSP
215 /* Probe for DSP */
216 dsp_init();
217
218 /* Disable the DSP */
219 if (dsp_disabled) {
220 printk("DSP Disabled\n");
221 cpu_data->flags &= ~CPU_HAS_DSP;
222 release_dsp();
223 }
224#endif
225
226#ifdef CONFIG_UBC_WAKEUP
227 /*
228 * Some brain-damaged loaders decided it would be a good idea to put
229 * the UBC to sleep. This causes some issues when it comes to things
230 * like PTRACE_SINGLESTEP or doing hardware watchpoints in GDB. So ..
231 * we wake it up and hope that all is well.
232 */
233 ubc_wakeup();
234#endif
235}
236