[MIPS] Fix sparse warnings about too big constants.
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / mips / 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 * Copyright (C) 1995 Linus Torvalds
7 * Copyright (C) 1995 Waldorf Electronics
8 * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 01, 02, 03 Ralf Baechle
9 * Copyright (C) 1996 Stoned Elipot
10 * Copyright (C) 1999 Silicon Graphics, Inc.
11 * Copyright (C) 2000 2001, 2002 Maciej W. Rozycki
12 */
13 #include <linux/config.h>
14 #include <linux/errno.h>
15 #include <linux/init.h>
16 #include <linux/ioport.h>
17 #include <linux/sched.h>
18 #include <linux/kernel.h>
19 #include <linux/mm.h>
20 #include <linux/module.h>
21 #include <linux/stddef.h>
22 #include <linux/string.h>
23 #include <linux/unistd.h>
24 #include <linux/slab.h>
25 #include <linux/user.h>
26 #include <linux/utsname.h>
27 #include <linux/a.out.h>
28 #include <linux/tty.h>
29 #include <linux/bootmem.h>
30 #include <linux/initrd.h>
31 #include <linux/major.h>
32 #include <linux/kdev_t.h>
33 #include <linux/root_dev.h>
34 #include <linux/highmem.h>
35 #include <linux/console.h>
36 #include <linux/mmzone.h>
37 #include <linux/pfn.h>
38
39 #include <asm/addrspace.h>
40 #include <asm/bootinfo.h>
41 #include <asm/cache.h>
42 #include <asm/cpu.h>
43 #include <asm/sections.h>
44 #include <asm/setup.h>
45 #include <asm/system.h>
46
47 struct cpuinfo_mips cpu_data[NR_CPUS] __read_mostly;
48
49 EXPORT_SYMBOL(cpu_data);
50
51 #ifdef CONFIG_VT
52 struct screen_info screen_info;
53 #endif
54
55 /*
56 * Despite it's name this variable is even if we don't have PCI
57 */
58 unsigned int PCI_DMA_BUS_IS_PHYS;
59
60 EXPORT_SYMBOL(PCI_DMA_BUS_IS_PHYS);
61
62 /*
63 * Setup information
64 *
65 * These are initialized so they are in the .data section
66 */
67 unsigned long mips_machtype __read_mostly = MACH_UNKNOWN;
68 unsigned long mips_machgroup __read_mostly = MACH_GROUP_UNKNOWN;
69
70 EXPORT_SYMBOL(mips_machtype);
71 EXPORT_SYMBOL(mips_machgroup);
72
73 struct boot_mem_map boot_mem_map;
74
75 static char command_line[CL_SIZE];
76 char arcs_cmdline[CL_SIZE]=CONFIG_CMDLINE;
77
78 /*
79 * mips_io_port_base is the begin of the address space to which x86 style
80 * I/O ports are mapped.
81 */
82 const unsigned long mips_io_port_base __read_mostly = -1;
83 EXPORT_SYMBOL(mips_io_port_base);
84
85 /*
86 * isa_slot_offset is the address where E(ISA) busaddress 0 is mapped
87 * for the processor.
88 */
89 unsigned long isa_slot_offset;
90 EXPORT_SYMBOL(isa_slot_offset);
91
92 static struct resource code_resource = { .name = "Kernel code", };
93 static struct resource data_resource = { .name = "Kernel data", };
94
95 void __init add_memory_region(phys_t start, phys_t size, long type)
96 {
97 int x = boot_mem_map.nr_map;
98 struct boot_mem_map_entry *prev = boot_mem_map.map + x - 1;
99
100 /*
101 * Try to merge with previous entry if any. This is far less than
102 * perfect but is sufficient for most real world cases.
103 */
104 if (x && prev->addr + prev->size == start && prev->type == type) {
105 prev->size += size;
106 return;
107 }
108
109 if (x == BOOT_MEM_MAP_MAX) {
110 printk("Ooops! Too many entries in the memory map!\n");
111 return;
112 }
113
114 boot_mem_map.map[x].addr = start;
115 boot_mem_map.map[x].size = size;
116 boot_mem_map.map[x].type = type;
117 boot_mem_map.nr_map++;
118 }
119
120 static void __init print_memory_map(void)
121 {
122 int i;
123 const int field = 2 * sizeof(unsigned long);
124
125 for (i = 0; i < boot_mem_map.nr_map; i++) {
126 printk(" memory: %0*Lx @ %0*Lx ",
127 field, (unsigned long long) boot_mem_map.map[i].size,
128 field, (unsigned long long) boot_mem_map.map[i].addr);
129
130 switch (boot_mem_map.map[i].type) {
131 case BOOT_MEM_RAM:
132 printk("(usable)\n");
133 break;
134 case BOOT_MEM_ROM_DATA:
135 printk("(ROM data)\n");
136 break;
137 case BOOT_MEM_RESERVED:
138 printk("(reserved)\n");
139 break;
140 default:
141 printk("type %lu\n", boot_mem_map.map[i].type);
142 break;
143 }
144 }
145 }
146
147 static inline void parse_cmdline_early(void)
148 {
149 char c = ' ', *to = command_line, *from = saved_command_line;
150 unsigned long start_at, mem_size;
151 int len = 0;
152 int usermem = 0;
153
154 printk("Determined physical RAM map:\n");
155 print_memory_map();
156
157 for (;;) {
158 /*
159 * "mem=XXX[kKmM]" defines a memory region from
160 * 0 to <XXX>, overriding the determined size.
161 * "mem=XXX[KkmM]@YYY[KkmM]" defines a memory region from
162 * <YYY> to <YYY>+<XXX>, overriding the determined size.
163 */
164 if (c == ' ' && !memcmp(from, "mem=", 4)) {
165 if (to != command_line)
166 to--;
167 /*
168 * If a user specifies memory size, we
169 * blow away any automatically generated
170 * size.
171 */
172 if (usermem == 0) {
173 boot_mem_map.nr_map = 0;
174 usermem = 1;
175 }
176 mem_size = memparse(from + 4, &from);
177 if (*from == '@')
178 start_at = memparse(from + 1, &from);
179 else
180 start_at = 0;
181 add_memory_region(start_at, mem_size, BOOT_MEM_RAM);
182 }
183 c = *(from++);
184 if (!c)
185 break;
186 if (CL_SIZE <= ++len)
187 break;
188 *(to++) = c;
189 }
190 *to = '\0';
191
192 if (usermem) {
193 printk("User-defined physical RAM map:\n");
194 print_memory_map();
195 }
196 }
197
198 static inline int parse_rd_cmdline(unsigned long* rd_start, unsigned long* rd_end)
199 {
200 /*
201 * "rd_start=0xNNNNNNNN" defines the memory address of an initrd
202 * "rd_size=0xNN" it's size
203 */
204 unsigned long start = 0;
205 unsigned long size = 0;
206 unsigned long end;
207 char cmd_line[CL_SIZE];
208 char *start_str;
209 char *size_str;
210 char *tmp;
211
212 strcpy(cmd_line, command_line);
213 *command_line = 0;
214 tmp = cmd_line;
215 /* Ignore "rd_start=" strings in other parameters. */
216 start_str = strstr(cmd_line, "rd_start=");
217 if (start_str && start_str != cmd_line && *(start_str - 1) != ' ')
218 start_str = strstr(start_str, " rd_start=");
219 while (start_str) {
220 if (start_str != cmd_line)
221 strncat(command_line, tmp, start_str - tmp);
222 start = memparse(start_str + 9, &start_str);
223 tmp = start_str + 1;
224 start_str = strstr(start_str, " rd_start=");
225 }
226 if (*tmp)
227 strcat(command_line, tmp);
228
229 strcpy(cmd_line, command_line);
230 *command_line = 0;
231 tmp = cmd_line;
232 /* Ignore "rd_size" strings in other parameters. */
233 size_str = strstr(cmd_line, "rd_size=");
234 if (size_str && size_str != cmd_line && *(size_str - 1) != ' ')
235 size_str = strstr(size_str, " rd_size=");
236 while (size_str) {
237 if (size_str != cmd_line)
238 strncat(command_line, tmp, size_str - tmp);
239 size = memparse(size_str + 8, &size_str);
240 tmp = size_str + 1;
241 size_str = strstr(size_str, " rd_size=");
242 }
243 if (*tmp)
244 strcat(command_line, tmp);
245
246 #ifdef CONFIG_64BIT
247 /* HACK: Guess if the sign extension was forgotten */
248 if (start > 0x0000000080000000 && start < 0x00000000ffffffff)
249 start |= 0xffffffff00000000UL;
250 #endif
251
252 end = start + size;
253 if (start && end) {
254 *rd_start = start;
255 *rd_end = end;
256 return 1;
257 }
258 return 0;
259 }
260
261 #define MAXMEM HIGHMEM_START
262 #define MAXMEM_PFN PFN_DOWN(MAXMEM)
263
264 static inline void bootmem_init(void)
265 {
266 unsigned long start_pfn;
267 unsigned long reserved_end = (unsigned long)&_end;
268 #ifndef CONFIG_SGI_IP27
269 unsigned long first_usable_pfn;
270 unsigned long bootmap_size;
271 int i;
272 #endif
273 #ifdef CONFIG_BLK_DEV_INITRD
274 int initrd_reserve_bootmem = 0;
275
276 /* Board specific code should have set up initrd_start and initrd_end */
277 ROOT_DEV = Root_RAM0;
278 if (parse_rd_cmdline(&initrd_start, &initrd_end)) {
279 reserved_end = max(reserved_end, initrd_end);
280 initrd_reserve_bootmem = 1;
281 } else {
282 unsigned long tmp;
283 u32 *initrd_header;
284
285 tmp = ((reserved_end + PAGE_SIZE-1) & PAGE_MASK) - sizeof(u32) * 2;
286 if (tmp < reserved_end)
287 tmp += PAGE_SIZE;
288 initrd_header = (u32 *)tmp;
289 if (initrd_header[0] == 0x494E5244) {
290 initrd_start = (unsigned long)&initrd_header[2];
291 initrd_end = initrd_start + initrd_header[1];
292 reserved_end = max(reserved_end, initrd_end);
293 initrd_reserve_bootmem = 1;
294 }
295 }
296 #endif /* CONFIG_BLK_DEV_INITRD */
297
298 /*
299 * Partially used pages are not usable - thus
300 * we are rounding upwards.
301 */
302 start_pfn = PFN_UP(CPHYSADDR(reserved_end));
303
304 #ifndef CONFIG_SGI_IP27
305 /* Find the highest page frame number we have available. */
306 max_pfn = 0;
307 first_usable_pfn = -1UL;
308 for (i = 0; i < boot_mem_map.nr_map; i++) {
309 unsigned long start, end;
310
311 if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
312 continue;
313
314 start = PFN_UP(boot_mem_map.map[i].addr);
315 end = PFN_DOWN(boot_mem_map.map[i].addr
316 + boot_mem_map.map[i].size);
317
318 if (start >= end)
319 continue;
320 if (end > max_pfn)
321 max_pfn = end;
322 if (start < first_usable_pfn) {
323 if (start > start_pfn) {
324 first_usable_pfn = start;
325 } else if (end > start_pfn) {
326 first_usable_pfn = start_pfn;
327 }
328 }
329 }
330
331 /*
332 * Determine low and high memory ranges
333 */
334 max_low_pfn = max_pfn;
335 if (max_low_pfn > MAXMEM_PFN) {
336 max_low_pfn = MAXMEM_PFN;
337 #ifndef CONFIG_HIGHMEM
338 /* Maximum memory usable is what is directly addressable */
339 printk(KERN_WARNING "Warning only %ldMB will be used.\n",
340 MAXMEM >> 20);
341 printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
342 #endif
343 }
344
345 #ifdef CONFIG_HIGHMEM
346 /*
347 * Crude, we really should make a better attempt at detecting
348 * highstart_pfn
349 */
350 highstart_pfn = highend_pfn = max_pfn;
351 if (max_pfn > MAXMEM_PFN) {
352 highstart_pfn = MAXMEM_PFN;
353 printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
354 (highend_pfn - highstart_pfn) >> (20 - PAGE_SHIFT));
355 }
356 #endif
357
358 memory_present(0, first_usable_pfn, max_low_pfn);
359
360 /* Initialize the boot-time allocator with low memory only. */
361 bootmap_size = init_bootmem(first_usable_pfn, max_low_pfn);
362
363 /*
364 * Register fully available low RAM pages with the bootmem allocator.
365 */
366 for (i = 0; i < boot_mem_map.nr_map; i++) {
367 unsigned long curr_pfn, last_pfn, size;
368
369 /*
370 * Reserve usable memory.
371 */
372 if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
373 continue;
374
375 /*
376 * We are rounding up the start address of usable memory:
377 */
378 curr_pfn = PFN_UP(boot_mem_map.map[i].addr);
379 if (curr_pfn >= max_low_pfn)
380 continue;
381 if (curr_pfn < start_pfn)
382 curr_pfn = start_pfn;
383
384 /*
385 * ... and at the end of the usable range downwards:
386 */
387 last_pfn = PFN_DOWN(boot_mem_map.map[i].addr
388 + boot_mem_map.map[i].size);
389
390 if (last_pfn > max_low_pfn)
391 last_pfn = max_low_pfn;
392
393 /*
394 * Only register lowmem part of lowmem segment with bootmem.
395 */
396 size = last_pfn - curr_pfn;
397 if (curr_pfn > PFN_DOWN(HIGHMEM_START))
398 continue;
399 if (curr_pfn + size - 1 > PFN_DOWN(HIGHMEM_START))
400 size = PFN_DOWN(HIGHMEM_START) - curr_pfn;
401 if (!size)
402 continue;
403
404 /*
405 * ... finally, did all the rounding and playing
406 * around just make the area go away?
407 */
408 if (last_pfn <= curr_pfn)
409 continue;
410
411 /* Register lowmem ranges */
412 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
413 }
414
415 /* Reserve the bootmap memory. */
416 reserve_bootmem(PFN_PHYS(first_usable_pfn), bootmap_size);
417 #endif /* CONFIG_SGI_IP27 */
418
419 #ifdef CONFIG_BLK_DEV_INITRD
420 initrd_below_start_ok = 1;
421 if (initrd_start) {
422 unsigned long initrd_size = ((unsigned char *)initrd_end) - ((unsigned char *)initrd_start);
423 printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
424 (void *)initrd_start, initrd_size);
425
426 if (CPHYSADDR(initrd_end) > PFN_PHYS(max_low_pfn)) {
427 printk("initrd extends beyond end of memory "
428 "(0x%0*Lx > 0x%0*Lx)\ndisabling initrd\n",
429 sizeof(long) * 2,
430 (unsigned long long)CPHYSADDR(initrd_end),
431 sizeof(long) * 2,
432 (unsigned long long)PFN_PHYS(max_low_pfn));
433 initrd_start = initrd_end = 0;
434 initrd_reserve_bootmem = 0;
435 }
436
437 if (initrd_reserve_bootmem)
438 reserve_bootmem(CPHYSADDR(initrd_start), initrd_size);
439 }
440 #endif /* CONFIG_BLK_DEV_INITRD */
441 }
442
443 static inline void resource_init(void)
444 {
445 int i;
446
447 code_resource.start = virt_to_phys(&_text);
448 code_resource.end = virt_to_phys(&_etext) - 1;
449 data_resource.start = virt_to_phys(&_etext);
450 data_resource.end = virt_to_phys(&_edata) - 1;
451
452 /*
453 * Request address space for all standard RAM.
454 */
455 for (i = 0; i < boot_mem_map.nr_map; i++) {
456 struct resource *res;
457 unsigned long start, end;
458
459 start = boot_mem_map.map[i].addr;
460 end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
461 if (start >= MAXMEM)
462 continue;
463 if (end >= MAXMEM)
464 end = MAXMEM - 1;
465
466 res = alloc_bootmem(sizeof(struct resource));
467 switch (boot_mem_map.map[i].type) {
468 case BOOT_MEM_RAM:
469 case BOOT_MEM_ROM_DATA:
470 res->name = "System RAM";
471 break;
472 case BOOT_MEM_RESERVED:
473 default:
474 res->name = "reserved";
475 }
476
477 res->start = start;
478 res->end = end;
479
480 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
481 request_resource(&iomem_resource, res);
482
483 /*
484 * We don't know which RAM region contains kernel data,
485 * so we try it repeatedly and let the resource manager
486 * test it.
487 */
488 request_resource(res, &code_resource);
489 request_resource(res, &data_resource);
490 }
491 }
492
493 #undef MAXMEM
494 #undef MAXMEM_PFN
495
496 extern void plat_setup(void);
497
498 void __init setup_arch(char **cmdline_p)
499 {
500 cpu_probe();
501 prom_init();
502 cpu_report();
503
504 #if defined(CONFIG_VT)
505 #if defined(CONFIG_VGA_CONSOLE)
506 conswitchp = &vga_con;
507 #elif defined(CONFIG_DUMMY_CONSOLE)
508 conswitchp = &dummy_con;
509 #endif
510 #endif
511
512 /* call board setup routine */
513 plat_setup();
514
515 strlcpy(command_line, arcs_cmdline, sizeof(command_line));
516 strlcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
517
518 *cmdline_p = command_line;
519
520 parse_cmdline_early();
521 bootmem_init();
522 sparse_init();
523 paging_init();
524 resource_init();
525 #ifdef CONFIG_SMP
526 plat_smp_setup();
527 #endif
528 }
529
530 int __init fpu_disable(char *s)
531 {
532 int i;
533
534 for (i = 0; i < NR_CPUS; i++)
535 cpu_data[i].options &= ~MIPS_CPU_FPU;
536
537 return 1;
538 }
539
540 __setup("nofpu", fpu_disable);
541
542 int __init dsp_disable(char *s)
543 {
544 cpu_data[0].ases &= ~MIPS_ASE_DSP;
545
546 return 1;
547 }
548
549 __setup("nodsp", dsp_disable);