[PATCH] uninline zone helpers
[linux-2.6-block.git] / arch / m32r / kernel / setup.c
CommitLineData
1da177e4
LT
1/*
2 * linux/arch/m32r/kernel/setup.c
3 *
4 * Setup routines for Renesas M32R
5 *
6 * Copyright (c) 2001, 2002 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto
8 */
9
10#include <linux/config.h>
11#include <linux/init.h>
12#include <linux/stddef.h>
13#include <linux/fs.h>
14#include <linux/sched.h>
15#include <linux/ioport.h>
16#include <linux/mm.h>
17#include <linux/bootmem.h>
18#include <linux/console.h>
19#include <linux/initrd.h>
20#include <linux/major.h>
21#include <linux/root_dev.h>
22#include <linux/seq_file.h>
23#include <linux/timex.h>
24#include <linux/tty.h>
25#include <linux/cpu.h>
26#include <linux/nodemask.h>
27
28#include <asm/processor.h>
29#include <asm/pgtable.h>
30#include <asm/io.h>
31#include <asm/mmu_context.h>
32#include <asm/m32r.h>
33#include <asm/setup.h>
34#include <asm/sections.h>
35
36#ifdef CONFIG_MMU
37extern void init_mmu(void);
38#endif
39
1da177e4
LT
40extern char _end[];
41
42/*
43 * Machine setup..
44 */
45struct cpuinfo_m32r boot_cpu_data;
46
47#ifdef CONFIG_BLK_DEV_RAM
48extern int rd_doload; /* 1 = load ramdisk, 0 = don't load */
49extern int rd_prompt; /* 1 = prompt for ramdisk, 0 = don't prompt */
50extern int rd_image_start; /* starting block # of image */
51#endif
52
53#if defined(CONFIG_VGA_CONSOLE)
54struct screen_info screen_info = {
55 .orig_video_lines = 25,
56 .orig_video_cols = 80,
57 .orig_video_mode = 0,
58 .orig_video_ega_bx = 0,
59 .orig_video_isVGA = 1,
60 .orig_video_points = 8
61};
62#endif
63
64extern int root_mountflags;
65
66static char command_line[COMMAND_LINE_SIZE];
67
68static struct resource data_resource = {
69 .name = "Kernel data",
70 .start = 0,
71 .end = 0,
72 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
73};
74
75static struct resource code_resource = {
76 .name = "Kernel code",
77 .start = 0,
78 .end = 0,
79 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
80};
81
82unsigned long memory_start;
83unsigned long memory_end;
84
85void __init setup_arch(char **);
86int get_cpuinfo(char *);
87
88static __inline__ void parse_mem_cmdline(char ** cmdline_p)
89{
90 char c = ' ';
91 char *to = command_line;
92 char *from = COMMAND_LINE;
93 int len = 0;
94 int usermem = 0;
95
96 /* Save unparsed command line copy for /proc/cmdline */
97 memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
98 saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
99
100 memory_start = (unsigned long)CONFIG_MEMORY_START+PAGE_OFFSET;
101 memory_end = memory_start+(unsigned long)CONFIG_MEMORY_SIZE;
102
103 for ( ; ; ) {
104 if (c == ' ' && !memcmp(from, "mem=", 4)) {
105 if (to != command_line)
106 to--;
107
108 {
109 unsigned long mem_size;
110
111 usermem = 1;
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
120 if (COMMAND_LINE_SIZE <= ++len)
121 break;
122
123 *(to++) = c;
124 }
125 *to = '\0';
126 *cmdline_p = command_line;
127 if (usermem)
128 printk(KERN_INFO "user-defined physical RAM map:\n");
129}
130
131#ifndef CONFIG_DISCONTIGMEM
132static unsigned long __init setup_memory(void)
133{
134 unsigned long start_pfn, max_low_pfn, bootmap_size;
135
136 start_pfn = PFN_UP( __pa(_end) );
137 max_low_pfn = PFN_DOWN( __pa(memory_end) );
138
139 /*
140 * Initialize the boot-time allocator (with low memory only):
141 */
142 bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
143 CONFIG_MEMORY_START>>PAGE_SHIFT, max_low_pfn);
144
145 /*
146 * Register fully available low RAM pages with the bootmem allocator.
147 */
148 {
149 unsigned long curr_pfn;
150 unsigned long last_pfn;
151 unsigned long pages;
152
153 /*
154 * We are rounding up the start address of usable memory:
155 */
156 curr_pfn = PFN_UP(__pa(memory_start));
157
158 /*
159 * ... and at the end of the usable range downwards:
160 */
161 last_pfn = PFN_DOWN(__pa(memory_end));
162
163 if (last_pfn > max_low_pfn)
164 last_pfn = max_low_pfn;
165
166 pages = last_pfn - curr_pfn;
167 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(pages));
168 }
169
170 /*
171 * Reserve the kernel text and
172 * Reserve the bootmem bitmap. We do this in two steps (first step
173 * was init_bootmem()), because this catches the (definitely buggy)
174 * case of us accidentally initializing the bootmem allocator with
175 * an invalid RAM area.
176 */
177 reserve_bootmem(CONFIG_MEMORY_START + PAGE_SIZE,
178 (PFN_PHYS(start_pfn) + bootmap_size + PAGE_SIZE - 1)
179 - CONFIG_MEMORY_START);
180
181 /*
182 * reserve physical page 0 - it's a special BIOS page on many boxes,
183 * enabling clean reboots, SMP operation, laptop functions.
184 */
185 reserve_bootmem(CONFIG_MEMORY_START, PAGE_SIZE);
186
187 /*
188 * reserve memory hole
189 */
190#ifdef CONFIG_MEMHOLE
191 reserve_bootmem(CONFIG_MEMHOLE_START, CONFIG_MEMHOLE_SIZE);
192#endif
193
194#ifdef CONFIG_BLK_DEV_INITRD
195 if (LOADER_TYPE && INITRD_START) {
196 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
197 reserve_bootmem(INITRD_START, INITRD_SIZE);
198 initrd_start = INITRD_START ?
199 INITRD_START + PAGE_OFFSET : 0;
200
201 initrd_end = initrd_start + INITRD_SIZE;
202 printk("initrd:start[%08lx],size[%08lx]\n",
203 initrd_start, INITRD_SIZE);
204 } else {
205 printk("initrd extends beyond end of memory "
206 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
207 INITRD_START + INITRD_SIZE,
208 max_low_pfn << PAGE_SHIFT);
209
210 initrd_start = 0;
211 }
212 }
213#endif
214
215 return max_low_pfn;
216}
217#else /* CONFIG_DISCONTIGMEM */
218extern unsigned long setup_memory(void);
219#endif /* CONFIG_DISCONTIGMEM */
220
221#define M32R_PCC_PCATCR 0x00ef7014 /* will move to m32r.h */
222
223void __init setup_arch(char **cmdline_p)
224{
225 ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
226
227 boot_cpu_data.cpu_clock = M32R_CPUCLK;
228 boot_cpu_data.bus_clock = M32R_BUSCLK;
229 boot_cpu_data.timer_divide = M32R_TIMER_DIVIDE;
230
231#ifdef CONFIG_BLK_DEV_RAM
232 rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
233 rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
234 rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
235#endif
236
237 if (!MOUNT_ROOT_RDONLY)
238 root_mountflags &= ~MS_RDONLY;
239
240#ifdef CONFIG_VT
241#if defined(CONFIG_VGA_CONSOLE)
242 conswitchp = &vga_con;
243#elif defined(CONFIG_DUMMY_CONSOLE)
244 conswitchp = &dummy_con;
245#endif
246#endif
247
248#ifdef CONFIG_DISCONTIGMEM
249 nodes_clear(node_online_map);
250 node_set_online(0);
251 node_set_online(1);
252#endif /* CONFIG_DISCONTIGMEM */
253
254 init_mm.start_code = (unsigned long) _text;
255 init_mm.end_code = (unsigned long) _etext;
256 init_mm.end_data = (unsigned long) _edata;
257 init_mm.brk = (unsigned long) _end;
258
259 code_resource.start = virt_to_phys(_text);
260 code_resource.end = virt_to_phys(_etext)-1;
261 data_resource.start = virt_to_phys(_etext);
262 data_resource.end = virt_to_phys(_edata)-1;
263
264 parse_mem_cmdline(cmdline_p);
265
266 setup_memory();
267
268 paging_init();
269}
270
271static struct cpu cpu[NR_CPUS];
272
273static int __init topology_init(void)
274{
275 int cpu_id;
276
277 for (cpu_id = 0; cpu_id < NR_CPUS; cpu_id++)
278 if (cpu_possible(cpu_id))
279 register_cpu(&cpu[cpu_id], cpu_id, NULL);
280
281 return 0;
282}
283
284subsys_initcall(topology_init);
285
286#ifdef CONFIG_PROC_FS
287/*
288 * Get CPU information for use by the procfs.
289 */
290static int show_cpuinfo(struct seq_file *m, void *v)
291{
292 struct cpuinfo_m32r *c = v;
293 unsigned long cpu = c - cpu_data;
294
295#ifdef CONFIG_SMP
296 if (!cpu_online(cpu))
297 return 0;
298#endif /* CONFIG_SMP */
299
300 seq_printf(m, "processor\t: %ld\n", cpu);
301
c978b017 302#if defined(CONFIG_CHIP_VDEC2)
1da177e4
LT
303 seq_printf(m, "cpu family\t: VDEC2\n"
304 "cache size\t: Unknown\n");
c978b017 305#elif defined(CONFIG_CHIP_M32700)
1da177e4
LT
306 seq_printf(m,"cpu family\t: M32700\n"
307 "cache size\t: I-8KB/D-8KB\n");
c978b017 308#elif defined(CONFIG_CHIP_M32102)
1da177e4
LT
309 seq_printf(m,"cpu family\t: M32102\n"
310 "cache size\t: I-8KB\n");
c978b017 311#elif defined(CONFIG_CHIP_OPSP)
1da177e4
LT
312 seq_printf(m,"cpu family\t: OPSP\n"
313 "cache size\t: I-8KB/D-8KB\n");
c978b017 314#elif defined(CONFIG_CHIP_MP)
1da177e4
LT
315 seq_printf(m, "cpu family\t: M32R-MP\n"
316 "cache size\t: I-xxKB/D-xxKB\n");
9287d95e
HT
317#elif defined(CONFIG_CHIP_M32104)
318 seq_printf(m,"cpu family\t: M32104\n"
319 "cache size\t: I-8KB/D-8KB\n");
1da177e4
LT
320#else
321 seq_printf(m, "cpu family\t: Unknown\n");
322#endif
323 seq_printf(m, "bogomips\t: %lu.%02lu\n",
324 c->loops_per_jiffy/(500000/HZ),
325 (c->loops_per_jiffy/(5000/HZ)) % 100);
c978b017 326#if defined(CONFIG_PLAT_MAPPI)
1da177e4 327 seq_printf(m, "Machine\t\t: Mappi Evaluation board\n");
c978b017 328#elif defined(CONFIG_PLAT_MAPPI2)
1da177e4 329 seq_printf(m, "Machine\t\t: Mappi-II Evaluation board\n");
c978b017 330#elif defined(CONFIG_PLAT_MAPPI3)
23680863 331 seq_printf(m, "Machine\t\t: Mappi-III Evaluation board\n");
c978b017 332#elif defined(CONFIG_PLAT_M32700UT)
1da177e4 333 seq_printf(m, "Machine\t\t: M32700UT Evaluation board\n");
c978b017 334#elif defined(CONFIG_PLAT_OPSPUT)
1da177e4 335 seq_printf(m, "Machine\t\t: OPSPUT Evaluation board\n");
c978b017 336#elif defined(CONFIG_PLAT_USRV)
1da177e4 337 seq_printf(m, "Machine\t\t: uServer\n");
c978b017 338#elif defined(CONFIG_PLAT_OAKS32R)
1da177e4 339 seq_printf(m, "Machine\t\t: OAKS32R\n");
9287d95e
HT
340#elif defined(CONFIG_PLAT_M32104UT)
341 seq_printf(m, "Machine\t\t: M3T-M32104UT uT Engine board\n");
1da177e4
LT
342#else
343 seq_printf(m, "Machine\t\t: Unknown\n");
344#endif
345
346#define PRINT_CLOCK(name, value) \
347 seq_printf(m, name " clock\t: %d.%02dMHz\n", \
348 ((value) / 1000000), ((value) % 1000000)/10000)
349
350 PRINT_CLOCK("CPU", (int)c->cpu_clock);
351 PRINT_CLOCK("Bus", (int)c->bus_clock);
352
353 seq_printf(m, "\n");
354
355 return 0;
356}
357
358static void *c_start(struct seq_file *m, loff_t *pos)
359{
360 return *pos < NR_CPUS ? cpu_data + *pos : NULL;
361}
362
363static void *c_next(struct seq_file *m, void *v, loff_t *pos)
364{
365 ++*pos;
366 return c_start(m, pos);
367}
368
369static void c_stop(struct seq_file *m, void *v)
370{
371}
372
373struct seq_operations cpuinfo_op = {
374 start: c_start,
375 next: c_next,
376 stop: c_stop,
377 show: show_cpuinfo,
378};
379#endif /* CONFIG_PROC_FS */
380
381unsigned long cpu_initialized __initdata = 0;
382
383/*
384 * cpu_init() initializes state that is per-CPU. Some data is already
385 * initialized (naturally) in the bootstrap process.
386 * We reload them nevertheless, this function acts as a
387 * 'CPU state barrier', nothing should get across.
388 */
389#if defined(CONFIG_CHIP_VDEC2) || defined(CONFIG_CHIP_XNUX2) \
390 || defined(CONFIG_CHIP_M32700) || defined(CONFIG_CHIP_M32102) \
9287d95e 391 || defined(CONFIG_CHIP_OPSP) || defined(CONFIG_CHIP_M32104)
1da177e4
LT
392void __init cpu_init (void)
393{
394 int cpu_id = smp_processor_id();
395
396 if (test_and_set_bit(cpu_id, &cpu_initialized)) {
397 printk(KERN_WARNING "CPU#%d already initialized!\n", cpu_id);
398 for ( ; ; )
399 local_irq_enable();
400 }
401 printk(KERN_INFO "Initializing CPU#%d\n", cpu_id);
402
403 /* Set up and load the per-CPU TSS and LDT */
404 atomic_inc(&init_mm.mm_count);
405 current->active_mm = &init_mm;
406 if (current->mm)
407 BUG();
408
409 /* Force FPU initialization */
410 current_thread_info()->status = 0;
411 clear_used_math();
412
413#ifdef CONFIG_MMU
414 /* Set up MMU */
415 init_mmu();
416#endif
417
418 /* Set up ICUIMASK */
419 outl(0x00070000, M32R_ICU_IMASK_PORTL); /* imask=111 */
420}
421#endif /* defined(CONFIG_CHIP_VDEC2) ... */