ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / sh / kernel / cpu / init.c
1 /*
2  * arch/sh/kernel/cpu/init.c
3  *
4  * CPU init code
5  *
6  * Copyright (C) 2002, 2003  Paul Mundt
7  *
8  * This file is subject to the terms and conditions of the GNU General Public
9  * License.  See the file "COPYING" in the main directory of this archive
10  * for more details.
11  */
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <asm/processor.h>
15 #include <asm/uaccess.h>
16 #include <asm/system.h>
17 #include <asm/cacheflush.h>
18 #include <asm/cache.h>
19 #include <asm/io.h>
20
21 extern void detect_cpu_and_cache_system(void);
22
23 /*
24  * Generic wrapper for command line arguments to disable on-chip
25  * peripherals (nofpu, nodsp, and so forth).
26  */
27 #define onchip_setup(x)                         \
28 static int x##_disabled __initdata = 0;         \
29                                                 \
30 static int __init x##_setup(char *opts)         \
31 {                                               \
32         x##_disabled = 1;                       \
33         return 0;                               \
34 }                                               \
35 __setup("no" __stringify(x), x##_setup);
36
37 onchip_setup(fpu);
38 onchip_setup(dsp);
39
40 /*
41  * Generic first-level cache init
42  */
43 static void __init cache_init(void)
44 {
45         unsigned long ccr, flags = 0;
46
47         if (cpu_data->type == CPU_SH_NONE)
48                 panic("Unknown CPU");
49
50         jump_to_P2();
51         ccr = ctrl_inl(CCR);
52
53         /*
54          * If the cache is already enabled .. flush it.
55          */
56         if (ccr & CCR_CACHE_ENABLE) {
57                 unsigned long entries, i, j;
58
59                 entries = cpu_data->dcache.sets;
60
61                 /*
62                  * If the OC is already in RAM mode, we only have
63                  * half of the entries to flush..
64                  */
65                 if (ccr & CCR_CACHE_ORA)
66                         entries >>= 1;
67
68                 for (i = 0; i < entries; i++) {
69                         for (j = 0; j < cpu_data->dcache.ways; j++) {
70                                 unsigned long data, addr;
71
72                                 addr = CACHE_OC_ADDRESS_ARRAY |
73                                         (j << cpu_data->dcache.way_shift) |
74                                         (i << cpu_data->dcache.entry_shift);
75
76                                 data = ctrl_inl(addr);
77
78                                 if ((data & (SH_CACHE_UPDATED | SH_CACHE_VALID))
79                                         == (SH_CACHE_UPDATED | SH_CACHE_VALID))
80                                         ctrl_outl(data & ~SH_CACHE_UPDATED, addr);
81                         }
82                 }
83         }
84
85         /* 
86          * Default CCR values .. enable the caches
87          * and flush them immediately..
88          */
89         flags |= CCR_CACHE_ENABLE | CCR_CACHE_INVALIDATE;
90         
91 #ifdef CCR_CACHE_EMODE
92         flags |= (ccr & CCR_CACHE_EMODE);
93 #endif
94
95 #ifdef CONFIG_SH_WRITETHROUGH
96         /* Turn on Write-through caching */
97         flags |= CCR_CACHE_WT;
98 #else
99         /* .. or default to Write-back */
100         flags |= CCR_CACHE_CB;
101 #endif
102
103 #ifdef CONFIG_SH_OCRAM
104         /* Turn on OCRAM -- halve the OC */
105         flags |= CCR_CACHE_ORA;
106         cpu_data->dcache.sets >>= 1;
107 #endif
108
109         ctrl_outl(flags, CCR);
110         back_to_P1();
111 }
112
113 #ifdef CONFIG_SH_DSP
114 static void __init release_dsp(void)
115 {
116         unsigned long sr;
117
118         /* Clear SR.DSP bit */
119         __asm__ __volatile__ (
120                 "stc\tsr, %0\n\t"
121                 "and\t%1, %0\n\t"
122                 "ldc\t%0, sr\n\t"
123                 : "=&r" (sr)
124                 : "r" (~SR_DSP)
125         );
126 }
127
128 static void __init dsp_init(void)
129 {
130         unsigned long sr;
131
132         /*
133          * Set the SR.DSP bit, wait for one instruction, and then read
134          * back the SR value.
135          */
136         __asm__ __volatile__ (
137                 "stc\tsr, %0\n\t"
138                 "or\t%1, %0\n\t"
139                 "ldc\t%0, sr\n\t"
140                 "nop\n\t"
141                 "stc\tsr, %0\n\t"
142                 : "=&r" (sr)
143                 : "r" (SR_DSP)
144         );
145
146         /* If the DSP bit is still set, this CPU has a DSP */
147         if (sr & SR_DSP)
148                 set_bit(CPU_HAS_DSP, &(cpu_data->flags));
149         
150         /* Now that we've determined the DSP status, clear the DSP bit. */
151         release_dsp();
152 }
153 #endif /* CONFIG_SH_DSP */
154
155 /*
156  * sh_cpu_init
157  *
158  * This is our initial entry point for each CPU, and is invoked on the boot
159  * CPU prior to calling start_kernel(). For SMP, a combination of this and
160  * start_secondary() will bring up each processor to a ready state prior
161  * to hand forking the idle loop.
162  *
163  * We do all of the basic processor init here, including setting up the
164  * caches, FPU, DSP, kicking the UBC, etc. By the time start_kernel() is
165  * hit (and subsequently platform_setup()) things like determining the
166  * CPU subtype and initial configuration will all be done.
167  *
168  * Each processor family is still responsible for doing its own probing
169  * and cache configuration in detect_cpu_and_cache_system().
170  */
171 asmlinkage void __init sh_cpu_init(void)
172 {
173         /* First, probe the CPU */
174         detect_cpu_and_cache_system();
175
176         /* Init the cache */
177         cache_init();
178
179         /* Disable the FPU */
180         if (fpu_disabled) {
181                 printk("FPU Disabled\n");
182                 cpu_data->flags &= ~CPU_HAS_FPU;
183                 disable_fpu();
184         }
185
186         /* FPU initialization */
187         if (test_bit(CPU_HAS_FPU, &(cpu_data->flags))) {
188                 clear_thread_flag(TIF_USEDFPU);
189                 current->used_math = 0;
190         }
191
192 #ifdef CONFIG_SH_DSP
193         /* Probe for DSP */
194         dsp_init();
195         
196         /* Disable the DSP */
197         if (dsp_disabled) {
198                 printk("DSP Disabled\n");
199                 cpu_data->flags &= ~CPU_HAS_DSP;
200                 release_dsp();
201         }
202 #endif
203
204 #ifdef CONFIG_UBC_WAKEUP
205         /*
206          * Some brain-damaged loaders decided it would be a good idea to put
207          * the UBC to sleep. This causes some issues when it comes to things
208          * like PTRACE_SINGLESTEP or doing hardware watchpoints in GDB.  So ..
209          * we wake it up and hope that all is well.
210          */
211         ubc_wakeup();
212 #endif
213 }
214