This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / sh64 / kernel / setup.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * arch/sh64/kernel/setup.c
7  *
8  * sh64 Arch Support
9  *
10  * This file handles the architecture-dependent parts of initialization
11  *
12  * Copyright (C) 2000, 2001  Paolo Alberelli
13  * Copyright (C) 2003, 2004  Paul Mundt
14  *
15  * benedict.gaster@superh.com:   2nd May 2002
16  *    Modified to use the empty_zero_page to pass command line arguments.
17  *
18  * benedict.gaster@superh.com:   3rd May 2002
19  *    Added support for ramdisk, removing statically linked romfs at the same time.
20  *
21  * lethal@linux-sh.org:          15th May 2003
22  *    Added generic procfs cpuinfo reporting. Make boards just export their name.
23  *
24  * lethal@linux-sh.org:          25th May 2003
25  *    Added generic get_cpu_subtype() for subtype reporting from cpu_data->type.
26  *
27  */
28 #include <linux/errno.h>
29 #include <linux/rwsem.h>
30 #include <linux/sched.h>
31 #include <linux/kernel.h>
32 #include <linux/mm.h>
33 #include <linux/stddef.h>
34 #include <linux/unistd.h>
35 #include <linux/ptrace.h>
36 #include <linux/slab.h>
37 #include <linux/user.h>
38 #include <linux/a.out.h>
39 #include <linux/tty.h>
40 #include <linux/ioport.h>
41 #include <linux/delay.h>
42 #include <linux/config.h>
43 #include <linux/init.h>
44 #include <linux/seq_file.h>
45 #include <linux/blkdev.h>
46 #include <linux/bootmem.h>
47 #include <linux/console.h>
48 #include <linux/root_dev.h>
49 #include <linux/cpu.h>
50 #include <linux/initrd.h>
51 #include <asm/processor.h>
52 #include <asm/page.h>
53 #include <asm/pgtable.h>
54 #include <asm/platform.h>
55 #include <asm/uaccess.h>
56 #include <asm/system.h>
57 #include <asm/io.h>
58 #include <asm/sections.h>
59 #include <asm/setup.h>
60 #include <asm/smp.h>
61
62 #ifdef CONFIG_VT
63 #include <linux/console.h>
64 #endif
65
66 struct screen_info screen_info;
67
68 /* On a PC this would be initialised as a result of the BIOS detecting the
69  * mouse. */
70 unsigned char aux_device_present = 0xaa;
71
72 #ifdef CONFIG_BLK_DEV_RAM
73 extern int rd_doload;           /* 1 = load ramdisk, 0 = don't load */
74 extern int rd_prompt;           /* 1 = prompt for ramdisk, 0 = don't prompt */
75 extern int rd_image_start;      /* starting block # of image */
76 #endif
77
78 extern int root_mountflags;
79 extern char *get_system_type(void);
80 extern void platform_setup(void);
81 extern void platform_monitor(void);
82 extern void platform_reserve(void);
83 extern int sh64_cache_init(void);
84 extern int sh64_tlb_init(void);
85
86 #define RAMDISK_IMAGE_START_MASK        0x07FF
87 #define RAMDISK_PROMPT_FLAG             0x8000
88 #define RAMDISK_LOAD_FLAG               0x4000
89
90 static char command_line[COMMAND_LINE_SIZE] = { 0, };
91 unsigned long long memory_start = CONFIG_MEMORY_START;
92 unsigned long long memory_end = CONFIG_MEMORY_START + (CONFIG_MEMORY_SIZE_IN_MB * 1024 * 1024);
93
94 struct sh_cpuinfo boot_cpu_data;
95
96 static inline void parse_mem_cmdline (char ** cmdline_p)
97 {
98         char c = ' ', *to = command_line, *from = COMMAND_LINE;
99         int len = 0;
100
101         /* Save unparsed command line copy for /proc/cmdline */
102         memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
103         saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
104
105         for (;;) {
106           /*
107            * "mem=XXX[kKmM]" defines a size of memory.
108            */
109                 if (c == ' ' && !memcmp(from, "mem=", 4)) {
110                       if (to != command_line)
111                         to--;
112                       {
113                         unsigned long mem_size;
114
115                         mem_size = memparse(from+4, &from);
116                         memory_end = memory_start + mem_size;
117                       }
118                 }
119                 c = *(from++);
120                 if (!c)
121                   break;
122                 if (COMMAND_LINE_SIZE <= ++len)
123                   break;
124                 *(to++) = c;
125         }
126         *to = '\0';
127
128         *cmdline_p = command_line;
129 }
130
131 static void __init sh64_cpu_type_detect(void)
132 {
133         extern unsigned long long peek_real_address_q(unsigned long long addr);
134         unsigned long long cir;
135         /* Do peeks in real mode to avoid having to set up a mapping for the
136            WPC registers.  On SH5-101 cut2, such a mapping would be exposed to
137            an address translation erratum which would make it hard to set up
138            correctly. */
139         cir = peek_real_address_q(0x0d000008);
140
141         if ((cir & 0xffff) == 0x5103) {
142                 boot_cpu_data.type = CPU_SH5_103;
143         } else if (((cir >> 32) & 0xffff) == 0x51e2) {
144                 /* CPU.VCR aliased at CIR address on SH5-101 */
145                 boot_cpu_data.type = CPU_SH5_101;
146         } else {
147                 boot_cpu_data.type = CPU_SH_NONE;
148         }
149 }
150
151 void __init setup_arch(char **cmdline_p)
152 {
153         unsigned long bootmap_size, i;
154         unsigned long first_pfn, start_pfn, last_pfn, pages;
155
156 #ifdef CONFIG_EARLY_PRINTK
157         extern void enable_early_printk(void);
158
159         /*
160          * Setup Early SCIF console
161          */
162         enable_early_printk();
163 #endif
164
165         /*
166          * Setup TLB mappings
167          */
168         sh64_tlb_init();
169
170         /*
171          * Caches are already initialized by the time we get here, so we just
172          * fill in cpu_data info for the caches.
173          */
174         sh64_cache_init();
175
176         platform_setup();
177         platform_monitor();
178
179         sh64_cpu_type_detect();
180
181         ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
182
183 #ifdef CONFIG_BLK_DEV_RAM
184         rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
185         rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
186         rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
187 #endif
188
189         if (!MOUNT_ROOT_RDONLY)
190                 root_mountflags &= ~MS_RDONLY;
191         init_mm.start_code = (unsigned long) _text;
192         init_mm.end_code = (unsigned long) _etext;
193         init_mm.end_data = (unsigned long) _edata;
194         init_mm.brk = (unsigned long) _end;
195
196         code_resource.start = __pa(_text);
197         code_resource.end = __pa(_etext)-1;
198         data_resource.start = __pa(_etext);
199         data_resource.end = __pa(_edata)-1;
200
201         parse_mem_cmdline(cmdline_p);
202
203         /*
204          * Find the lowest and highest page frame numbers we have available
205          */
206         first_pfn = PFN_DOWN(memory_start);
207         last_pfn = PFN_DOWN(memory_end);
208         pages = last_pfn - first_pfn;
209
210         /*
211          * Partially used pages are not usable - thus
212          * we are rounding upwards:
213          */
214         start_pfn = PFN_UP(__pa(_end));
215
216         /*
217          * Find a proper area for the bootmem bitmap. After this
218          * bootstrap step all allocations (until the page allocator
219          * is intact) must be done via bootmem_alloc().
220          */
221         bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
222                                          first_pfn,
223                                          last_pfn);
224         /*
225          * Round it up.
226          */
227         bootmap_size = PFN_PHYS(PFN_UP(bootmap_size));
228
229         /*
230          * Register fully available RAM pages with the bootmem allocator.
231          */
232         free_bootmem_node(NODE_DATA(0), PFN_PHYS(first_pfn), PFN_PHYS(pages));
233
234         /*
235          * Reserve all kernel sections + bootmem bitmap + a guard page.
236          */
237         reserve_bootmem_node(NODE_DATA(0), PFN_PHYS(first_pfn),
238                         (PFN_PHYS(start_pfn) + bootmap_size + PAGE_SIZE) - PFN_PHYS(first_pfn));
239
240         /*
241          * Reserve platform dependent sections
242          */
243         platform_reserve();
244
245 #ifdef CONFIG_BLK_DEV_INITRD
246         if (LOADER_TYPE && INITRD_START) {
247                 if (INITRD_START + INITRD_SIZE <= (PFN_PHYS(last_pfn))) {
248                         reserve_bootmem_node(NODE_DATA(0), INITRD_START + __MEMORY_START, INITRD_SIZE);
249
250                         initrd_start =
251                           (long) INITRD_START ? INITRD_START + PAGE_OFFSET +  __MEMORY_START : 0;
252
253                         initrd_end = initrd_start + INITRD_SIZE;
254                 } else {
255                         printk("initrd extends beyond end of memory "
256                             "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
257                                     (long) INITRD_START + INITRD_SIZE,
258                                     PFN_PHYS(last_pfn));
259                         initrd_start = 0;
260                 }
261         }
262 #endif
263
264         /*
265          * Claim all RAM, ROM, and I/O resources.
266          */
267
268         /* Kernel RAM */
269         request_resource(&iomem_resource, &code_resource);
270         request_resource(&iomem_resource, &data_resource);
271
272         /* Other KRAM space */
273         for (i = 0; i < STANDARD_KRAM_RESOURCES - 2; i++)
274                 request_resource(&iomem_resource,
275                                  &platform_parms.kram_res_p[i]);
276
277         /* XRAM space */
278         for (i = 0; i < STANDARD_XRAM_RESOURCES; i++)
279                 request_resource(&iomem_resource,
280                                  &platform_parms.xram_res_p[i]);
281
282         /* ROM space */
283         for (i = 0; i < STANDARD_ROM_RESOURCES; i++)
284                 request_resource(&iomem_resource,
285                                  &platform_parms.rom_res_p[i]);
286
287         /* I/O space */
288         for (i = 0; i < STANDARD_IO_RESOURCES; i++)
289                 request_resource(&ioport_resource,
290                                  &platform_parms.io_res_p[i]);
291
292
293 #ifdef CONFIG_VT
294 #if defined(CONFIG_VGA_CONSOLE)
295         conswitchp = &vga_con;
296 #elif defined(CONFIG_DUMMY_CONSOLE)
297         conswitchp = &dummy_con;
298 #endif
299 #endif
300
301         printk("Hardware FPU: %s\n", fpu_in_use ? "enabled" : "disabled");
302
303         paging_init();
304 }
305
306 void __xchg_called_with_bad_pointer(void)
307 {
308         printk(KERN_EMERG "xchg() called with bad pointer !\n");
309 }
310
311 static struct cpu cpu[1];
312
313 static int __init topology_init(void)
314 {
315         return register_cpu(cpu, 0, NULL);
316 }
317
318 subsys_initcall(topology_init);
319
320 /*
321  *      Get CPU information
322  */
323 static const char *cpu_name[] = {
324         [CPU_SH5_101]   = "SH5-101",
325         [CPU_SH5_103]   = "SH5-103",
326         [CPU_SH_NONE]   = "Unknown",
327 };
328
329 const char *get_cpu_subtype(void)
330 {
331         return cpu_name[boot_cpu_data.type];
332 }
333
334 #ifdef CONFIG_PROC_FS
335 static int show_cpuinfo(struct seq_file *m,void *v)
336 {
337         unsigned int cpu = smp_processor_id();
338
339         if (!cpu)
340                 seq_printf(m, "machine\t\t: %s\n", get_system_type());
341
342         seq_printf(m, "processor\t: %d\n", cpu);
343         seq_printf(m, "cpu family\t: SH-5\n");
344         seq_printf(m, "cpu type\t: %s\n", get_cpu_subtype());
345
346         seq_printf(m, "icache size\t: %dK-bytes\n",
347                    (boot_cpu_data.icache.ways *
348                     boot_cpu_data.icache.sets *
349                     boot_cpu_data.icache.linesz) >> 10);
350         seq_printf(m, "dcache size\t: %dK-bytes\n",
351                    (boot_cpu_data.dcache.ways *
352                     boot_cpu_data.dcache.sets *
353                     boot_cpu_data.dcache.linesz) >> 10);
354         seq_printf(m, "itlb entries\t: %d\n", boot_cpu_data.itlb.entries);
355         seq_printf(m, "dtlb entries\t: %d\n", boot_cpu_data.dtlb.entries);
356
357 #define PRINT_CLOCK(name, value) \
358         seq_printf(m, name " clock\t: %d.%02dMHz\n", \
359                      ((value) / 1000000), ((value) % 1000000)/10000)
360
361         PRINT_CLOCK("cpu", boot_cpu_data.cpu_clock);
362         PRINT_CLOCK("bus", boot_cpu_data.bus_clock);
363         PRINT_CLOCK("module", boot_cpu_data.module_clock);
364
365         seq_printf(m, "bogomips\t: %lu.%02lu\n\n",
366                      (loops_per_jiffy*HZ+2500)/500000,
367                      ((loops_per_jiffy*HZ+2500)/5000) % 100);
368
369         return 0;
370 }
371
372 static void *c_start(struct seq_file *m, loff_t *pos)
373 {
374         return (void*)(*pos == 0);
375 }
376 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
377 {
378         return NULL;
379 }
380 static void c_stop(struct seq_file *m, void *v)
381 {
382 }
383 struct seq_operations cpuinfo_op = {
384         .start  = c_start,
385         .next   = c_next,
386         .stop   = c_stop,
387         .show   = show_cpuinfo,
388 };
389 #endif /* CONFIG_PROC_FS */