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