Original kernel 2.4.37.5
[tomato.git] / release / src / linux / linux / arch / mips / kernel / setup.c
blobdbdb8da125c7cfe8520e4d7b26decec948db450d
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.
6 * Copyright (C) 1995 Linus Torvalds
7 * Copyright (C) 1995 Waldorf Electronics
8 * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001 Ralf Baechle
9 * Copyright (C) 1996 Stoned Elipot
10 * Copyright (C) 2000, 2001, 2002 Maciej W. Rozycki
12 #include <linux/config.h>
13 #include <linux/errno.h>
14 #include <linux/hdreg.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/blk.h>
31 #include <linux/ide.h>
32 #include <linux/timex.h>
34 #include <asm/asm.h>
35 #include <asm/bootinfo.h>
36 #include <asm/cachectl.h>
37 #include <asm/cpu.h>
38 #include <asm/io.h>
39 #include <asm/ptrace.h>
40 #include <asm/system.h>
42 struct cpuinfo_mips cpu_data[NR_CPUS];
43 EXPORT_SYMBOL(cpu_data);
46 * There are several bus types available for MIPS machines. "RISC PC"
47 * type machines have ISA, EISA, VLB or PCI available, DECstations
48 * have Turbochannel or Q-Bus, SGI has GIO, there are lots of VME
49 * boxes ...
50 * This flag is set if a EISA slots are available.
52 #ifdef CONFIG_EISA
53 int EISA_bus = 0;
54 #endif
56 struct screen_info screen_info;
58 #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
59 #include <asm/floppy.h>
60 extern struct fd_ops no_fd_ops;
61 struct fd_ops *fd_ops;
62 #endif
64 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
65 extern struct ide_ops no_ide_ops;
66 struct ide_ops *ide_ops;
67 #endif
69 extern void * __rd_start, * __rd_end;
71 extern struct rtc_ops no_rtc_ops;
72 struct rtc_ops *rtc_ops;
74 #ifdef CONFIG_PC_KEYB
75 struct kbd_ops *kbd_ops;
76 #endif
79 * Setup information
81 * These are initialized so they are in the .data section
83 unsigned long mips_machtype = MACH_UNKNOWN;
84 unsigned long mips_machgroup = MACH_GROUP_UNKNOWN;
86 struct boot_mem_map boot_mem_map;
88 unsigned char aux_device_present;
89 extern char _ftext, _etext, _fdata, _edata, _end;
91 static char command_line[CL_SIZE];
92 char saved_command_line[CL_SIZE];
93 extern char arcs_cmdline[CL_SIZE];
96 * mips_io_port_base is the begin of the address space to which x86 style
97 * I/O ports are mapped.
99 const unsigned long mips_io_port_base = -1;
100 EXPORT_SYMBOL(mips_io_port_base);
104 * isa_slot_offset is the address where E(ISA) busaddress 0 is mapped
105 * for the processor.
107 unsigned long isa_slot_offset;
108 EXPORT_SYMBOL(isa_slot_offset);
110 extern void SetUpBootInfo(void);
111 extern void load_mmu(void);
112 extern asmlinkage void start_kernel(void);
113 extern void prom_init(int, char **, char **, int *);
115 static struct resource code_resource = { "Kernel code" };
116 static struct resource data_resource = { "Kernel data" };
118 asmlinkage void __init
119 init_arch(int argc, char **argv, char **envp, int *prom_vec)
121 /* Determine which MIPS variant we are running on. */
122 cpu_probe();
124 prom_init(argc, argv, envp, prom_vec);
126 cpu_report();
129 * Determine the mmu/cache attached to this machine,
130 * then flush the tlb and caches. On the r4xx0
131 * variants this also sets CP0_WIRED to zero.
133 load_mmu();
135 /* Disable coprocessors and set FPU for 16/32 FPR register model */
136 clear_c0_status(ST0_CU1|ST0_CU2|ST0_CU3|ST0_KX|ST0_SX|ST0_FR);
137 set_c0_status(ST0_CU0);
139 start_kernel();
142 void __init add_memory_region(phys_t start, phys_t size,
143 long type)
145 int x = boot_mem_map.nr_map;
147 if (x == BOOT_MEM_MAP_MAX) {
148 printk("Ooops! Too many entries in the memory map!\n");
149 return;
152 boot_mem_map.map[x].addr = start;
153 boot_mem_map.map[x].size = size;
154 boot_mem_map.map[x].type = type;
155 boot_mem_map.nr_map++;
158 static void __init print_memory_map(void)
160 int i;
162 for (i = 0; i < boot_mem_map.nr_map; i++) {
163 printk(" memory: %08Lx @ %08Lx ",
164 (u64) boot_mem_map.map[i].size,
165 (u64) boot_mem_map.map[i].addr);
167 switch (boot_mem_map.map[i].type) {
168 case BOOT_MEM_RAM:
169 printk("(usable)\n");
170 break;
171 case BOOT_MEM_ROM_DATA:
172 printk("(ROM data)\n");
173 break;
174 case BOOT_MEM_RESERVED:
175 printk("(reserved)\n");
176 break;
177 default:
178 printk("type %lu\n", boot_mem_map.map[i].type);
179 break;
184 static inline void parse_mem_cmdline(void)
186 char c = ' ', *to = command_line, *from = saved_command_line;
187 unsigned long start_at, mem_size;
188 int len = 0;
189 int usermem = 0;
191 printk("Determined physical RAM map:\n");
192 print_memory_map();
194 for (;;) {
196 * "mem=XXX[kKmM]" defines a memory region from
197 * 0 to <XXX>, overriding the determined size.
198 * "mem=XXX[KkmM]@YYY[KkmM]" defines a memory region from
199 * <YYY> to <YYY>+<XXX>, overriding the determined size.
201 if (c == ' ' && !memcmp(from, "mem=", 4)) {
202 if (to != command_line)
203 to--;
205 * If a user specifies memory size, we
206 * blow away any automatically generated
207 * size.
209 if (usermem == 0) {
210 boot_mem_map.nr_map = 0;
211 usermem = 1;
213 mem_size = memparse(from + 4, &from);
214 if (*from == '@')
215 start_at = memparse(from + 1, &from);
216 else
217 start_at = 0;
218 add_memory_region(start_at, mem_size, BOOT_MEM_RAM);
220 c = *(from++);
221 if (!c)
222 break;
223 if (CL_SIZE <= ++len)
224 break;
225 *(to++) = c;
227 *to = '\0';
229 if (usermem) {
230 printk("User-defined physical RAM map:\n");
231 print_memory_map();
236 #define PFN_UP(x) (((x) + PAGE_SIZE - 1) >> PAGE_SHIFT)
237 #define PFN_DOWN(x) ((x) >> PAGE_SHIFT)
238 #define PFN_PHYS(x) ((x) << PAGE_SHIFT)
240 #define MAXMEM HIGHMEM_START
241 #define MAXMEM_PFN PFN_DOWN(MAXMEM)
243 static inline void bootmem_init(void)
245 #ifdef CONFIG_BLK_DEV_INITRD
246 unsigned long tmp;
247 unsigned long *initrd_header;
248 #endif
249 unsigned long bootmap_size;
250 unsigned long start_pfn, max_pfn, max_low_pfn, first_usable_pfn;
251 int i;
253 #ifdef CONFIG_BLK_DEV_INITRD
254 tmp = (((unsigned long)&_end + PAGE_SIZE-1) & PAGE_MASK) - 8;
255 if (tmp < (unsigned long)&_end)
256 tmp += PAGE_SIZE;
257 initrd_header = (unsigned long *)tmp;
258 if (initrd_header[0] == 0x494E5244) {
259 initrd_start = (unsigned long)&initrd_header[2];
260 initrd_end = initrd_start + initrd_header[1];
262 start_pfn = PFN_UP(__pa((&_end)+(initrd_end - initrd_start) + PAGE_SIZE));
263 #else
265 * Partially used pages are not usable - thus
266 * we are rounding upwards.
268 start_pfn = PFN_UP(__pa(&_end));
269 #endif /* CONFIG_BLK_DEV_INITRD */
271 /* Find the highest page frame number we have available. */
272 max_pfn = 0;
273 first_usable_pfn = -1UL;
274 for (i = 0; i < boot_mem_map.nr_map; i++) {
275 unsigned long start, end;
277 if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
278 continue;
280 start = PFN_UP(boot_mem_map.map[i].addr);
281 end = PFN_DOWN(boot_mem_map.map[i].addr
282 + boot_mem_map.map[i].size);
284 if (start >= end)
285 continue;
286 if (end > max_pfn)
287 max_pfn = end;
288 if (start < first_usable_pfn) {
289 if (start > start_pfn) {
290 first_usable_pfn = start;
291 } else if (end > start_pfn) {
292 first_usable_pfn = start_pfn;
298 * Determine low and high memory ranges
300 max_low_pfn = max_pfn;
301 if (max_low_pfn > MAXMEM_PFN) {
302 max_low_pfn = MAXMEM_PFN;
303 #ifndef CONFIG_HIGHMEM
304 /* Maximum memory usable is what is directly addressable */
305 printk(KERN_WARNING "Warning only %ldMB will be used.\n",
306 MAXMEM>>20);
307 printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
308 #endif
311 #ifdef CONFIG_HIGHMEM
313 * Crude, we really should make a better attempt at detecting
314 * highstart_pfn
316 highstart_pfn = highend_pfn = max_pfn;
317 if (max_pfn > MAXMEM_PFN) {
318 highstart_pfn = MAXMEM_PFN;
319 printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
320 (highend_pfn - highstart_pfn) >> (20 - PAGE_SHIFT));
322 #endif
324 /* Initialize the boot-time allocator with low memory only. */
325 bootmap_size = init_bootmem(first_usable_pfn, max_low_pfn);
328 * Register fully available low RAM pages with the bootmem allocator.
330 for (i = 0; i < boot_mem_map.nr_map; i++) {
331 unsigned long curr_pfn, last_pfn, size;
334 * Reserve usable memory.
336 if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
337 continue;
340 * We are rounding up the start address of usable memory:
342 curr_pfn = PFN_UP(boot_mem_map.map[i].addr);
343 if (curr_pfn >= max_low_pfn)
344 continue;
345 if (curr_pfn < start_pfn)
346 curr_pfn = start_pfn;
349 * ... and at the end of the usable range downwards:
351 last_pfn = PFN_DOWN(boot_mem_map.map[i].addr
352 + boot_mem_map.map[i].size);
354 if (last_pfn > max_low_pfn)
355 last_pfn = max_low_pfn;
358 * Only register lowmem part of lowmem segment with bootmem.
360 size = last_pfn - curr_pfn;
361 if (curr_pfn > PFN_DOWN(HIGHMEM_START))
362 continue;
363 if (curr_pfn + size - 1 > PFN_DOWN(HIGHMEM_START))
364 size = PFN_DOWN(HIGHMEM_START) - curr_pfn;
365 if (!size)
366 continue;
369 * ... finally, did all the rounding and playing
370 * around just make the area go away?
372 if (last_pfn <= curr_pfn)
373 continue;
375 /* Register lowmem ranges */
376 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
379 /* Reserve the bootmap memory. */
380 reserve_bootmem(PFN_PHYS(first_usable_pfn), bootmap_size);
382 #ifdef CONFIG_BLK_DEV_INITRD
383 /* Board specific code should have set up initrd_start and initrd_end */
384 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
385 if (&__rd_start != &__rd_end) {
386 initrd_start = (unsigned long)&__rd_start;
387 initrd_end = (unsigned long)&__rd_end;
389 initrd_below_start_ok = 1;
390 if (initrd_start) {
391 unsigned long initrd_size = ((unsigned char *)initrd_end) - ((unsigned char *)initrd_start);
392 printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
393 (void *)initrd_start,
394 initrd_size);
395 if (PHYSADDR(initrd_end) > PFN_PHYS(max_low_pfn)) {
396 printk("initrd extends beyond end of memory "
397 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
398 (unsigned long) PHYSADDR(initrd_end),
399 PFN_PHYS(max_low_pfn));
400 initrd_start = initrd_end = 0;
403 #endif /* CONFIG_BLK_DEV_INITRD */
406 static inline void resource_init(void)
408 int i;
410 code_resource.start = virt_to_bus(&_ftext);
411 code_resource.end = virt_to_bus(&_etext) - 1;
412 data_resource.start = virt_to_bus(&_fdata);
413 data_resource.end = virt_to_bus(&_edata) - 1;
416 * Request address space for all standard RAM.
418 for (i = 0; i < boot_mem_map.nr_map; i++) {
419 struct resource *res;
420 unsigned long start, end;
422 start = boot_mem_map.map[i].addr;
423 end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
424 if (start >= MAXMEM)
425 continue;
426 if (end >= MAXMEM)
427 end = MAXMEM - 1;
429 res = alloc_bootmem(sizeof(struct resource));
430 switch (boot_mem_map.map[i].type) {
431 case BOOT_MEM_RAM:
432 case BOOT_MEM_ROM_DATA:
433 res->name = "System RAM";
434 break;
435 case BOOT_MEM_RESERVED:
436 default:
437 res->name = "reserved";
440 res->start = start;
441 res->end = end;
443 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
444 request_resource(&iomem_resource, res);
447 * We dont't know which RAM region contains kernel data,
448 * so we try it repeatedly and let the resource manager
449 * test it.
451 request_resource(res, &code_resource);
452 request_resource(res, &data_resource);
456 #undef PFN_UP
457 #undef PFN_DOWN
458 #undef PFN_PHYS
460 #undef MAXMEM
461 #undef MAXMEM_PFN
464 void __init setup_arch(char **cmdline_p)
466 void atlas_setup(void);
467 void baget_setup(void);
468 void cobalt_setup(void);
469 void lasat_setup(void);
470 void ddb_setup(void);
471 void decstation_setup(void);
472 void deskstation_setup(void);
473 void jazz_setup(void);
474 void sni_rm200_pci_setup(void);
475 void ip22_setup(void);
476 void ev96100_setup(void);
477 void malta_setup(void);
478 void sead_setup(void);
479 void ikos_setup(void);
480 void momenco_ocelot_setup(void);
481 void momenco_ocelot_g_setup(void);
482 void momenco_ocelot_c_setup(void);
483 void momenco_jaguar_atx_setup(void);
484 void nino_setup(void);
485 void nec_osprey_setup(void);
486 void nec_eagle_setup(void);
487 void zao_capcella_setup(void);
488 void victor_mpc30x_setup(void);
489 void ibm_workpad_setup(void);
490 void casio_e55_setup(void);
491 void tanbac_tb0226_setup(void);
492 void jmr3927_setup(void);
493 void tx4927_setup(void);
494 void it8172_setup(void);
495 void swarm_setup(void);
496 void hp_setup(void);
497 void au1x00_setup(void);
498 void frame_info_init(void);
500 frame_info_init();
501 #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
502 fd_ops = &no_fd_ops;
503 #endif
505 #ifdef CONFIG_BLK_DEV_IDE
506 ide_ops = &no_ide_ops;
507 #endif
509 rtc_ops = &no_rtc_ops;
511 switch(mips_machgroup)
513 #ifdef CONFIG_BAGET_MIPS
514 case MACH_GROUP_BAGET:
515 baget_setup();
516 break;
517 #endif
518 #ifdef CONFIG_MIPS_COBALT
519 case MACH_GROUP_COBALT:
520 cobalt_setup();
521 break;
522 #endif
523 #ifdef CONFIG_DECSTATION
524 case MACH_GROUP_DEC:
525 decstation_setup();
526 break;
527 #endif
528 #ifdef CONFIG_MIPS_ATLAS
529 case MACH_GROUP_UNKNOWN:
530 atlas_setup();
531 break;
532 #endif
533 #ifdef CONFIG_MIPS_JAZZ
534 case MACH_GROUP_JAZZ:
535 jazz_setup();
536 break;
537 #endif
538 #ifdef CONFIG_MIPS_MALTA
539 case MACH_GROUP_UNKNOWN:
540 malta_setup();
541 break;
542 #endif
543 #ifdef CONFIG_MOMENCO_OCELOT
544 case MACH_GROUP_MOMENCO:
545 momenco_ocelot_setup();
546 break;
547 #endif
548 #ifdef CONFIG_MOMENCO_OCELOT_G
549 case MACH_GROUP_MOMENCO:
550 momenco_ocelot_g_setup();
551 break;
552 #endif
553 #ifdef CONFIG_MOMENCO_OCELOT_C
554 case MACH_GROUP_MOMENCO:
555 momenco_ocelot_c_setup();
556 break;
557 #endif
558 #ifdef CONFIG_MOMENCO_JAGUAR_ATX
559 case MACH_GROUP_MOMENCO:
560 momenco_jaguar_atx_setup();
561 break;
562 #endif
563 #ifdef CONFIG_MIPS_SEAD
564 case MACH_GROUP_UNKNOWN:
565 sead_setup();
566 break;
567 #endif
568 #ifdef CONFIG_SGI_IP22
569 /* As of now this is only IP22. */
570 case MACH_GROUP_SGI:
571 ip22_setup();
572 break;
573 #endif
574 #ifdef CONFIG_SNI_RM200_PCI
575 case MACH_GROUP_SNI_RM:
576 sni_rm200_pci_setup();
577 break;
578 #endif
579 #ifdef CONFIG_DDB5074
580 case MACH_GROUP_NEC_DDB:
581 ddb_setup();
582 break;
583 #endif
584 #ifdef CONFIG_DDB5476
585 case MACH_GROUP_NEC_DDB:
586 ddb_setup();
587 break;
588 #endif
589 #ifdef CONFIG_DDB5477
590 case MACH_GROUP_NEC_DDB:
591 ddb_setup();
592 break;
593 #endif
594 #ifdef CONFIG_CPU_VR41XX
595 case MACH_GROUP_NEC_VR41XX:
596 switch (mips_machtype) {
597 #ifdef CONFIG_NEC_OSPREY
598 case MACH_NEC_OSPREY:
599 nec_osprey_setup();
600 break;
601 #endif
602 #ifdef CONFIG_NEC_EAGLE
603 case MACH_NEC_EAGLE:
604 nec_eagle_setup();
605 break;
606 #endif
607 #ifdef CONFIG_ZAO_CAPCELLA
608 case MACH_ZAO_CAPCELLA:
609 zao_capcella_setup();
610 break;
611 #endif
612 #ifdef CONFIG_VICTOR_MPC30X
613 case MACH_VICTOR_MPC30X:
614 victor_mpc30x_setup();
615 break;
616 #endif
617 #ifdef CONFIG_IBM_WORKPAD
618 case MACH_IBM_WORKPAD:
619 ibm_workpad_setup();
620 break;
621 #endif
622 #ifdef CONFIG_CASIO_E55
623 case MACH_CASIO_E55:
624 casio_e55_setup();
625 break;
626 #endif
627 #ifdef CONFIG_TANBAC_TB0226
628 case MACH_TANBAC_TB0226:
629 tanbac_tb0226_setup();
630 break;
631 #endif
632 #ifdef CONFIG_TANBAC_TB0229
633 case MACH_TANBAC_TB0229:
634 tanbac_tb0229_setup();
635 break;
636 #endif
638 break;
639 #endif
640 #ifdef CONFIG_MIPS_EV96100
641 case MACH_GROUP_GALILEO:
642 ev96100_setup();
643 break;
644 #endif
645 #ifdef CONFIG_MIPS_EV64120
646 case MACH_GROUP_GALILEO:
647 ev64120_setup();
648 break;
649 #endif
650 #if defined(CONFIG_MIPS_IVR) || defined(CONFIG_MIPS_ITE8172)
651 case MACH_GROUP_ITE:
652 case MACH_GROUP_GLOBESPAN:
653 it8172_setup();
654 break;
655 #endif
656 #ifdef CONFIG_NINO
657 case MACH_GROUP_PHILIPS:
658 nino_setup();
659 break;
660 #endif
661 #ifdef CONFIG_LASAT
662 case MACH_GROUP_LASAT:
663 lasat_setup();
664 break;
665 #endif
666 #ifdef CONFIG_SOC_AU1X00
667 case MACH_GROUP_ALCHEMY:
668 au1x00_setup();
669 break;
670 #endif
671 #ifdef CONFIG_TOSHIBA_JMR3927
672 case MACH_GROUP_TOSHIBA:
673 jmr3927_setup();
674 break;
675 #endif
676 #ifdef CONFIG_TOSHIBA_RBTX4927
677 case MACH_GROUP_TOSHIBA:
678 tx4927_setup();
679 break;
680 #endif
681 #ifdef CONFIG_SIBYTE_BOARD
682 case MACH_GROUP_SIBYTE:
683 swarm_setup();
684 break;
685 #endif
686 #ifdef CONFIG_HP_LASERJET
687 case MACH_GROUP_HP_LJ:
688 hp_setup();
689 break;
690 #endif
691 #ifdef CONFIG_PMC_YOSEMITE
692 case MACH_GROUP_TITAN:
693 pmc_yosemite_setup();
694 break;
695 #endif
696 default:
697 panic("Unsupported architecture");
700 strncpy(command_line, arcs_cmdline, sizeof command_line);
701 command_line[sizeof command_line - 1] = 0;
702 strcpy(saved_command_line, command_line);
703 *cmdline_p = command_line;
705 parse_mem_cmdline();
707 bootmem_init();
709 paging_init();
711 resource_init();
714 static int __init fpu_disable(char *s)
716 cpu_data[0].options &= ~MIPS_CPU_FPU;
718 return 1;
720 __setup("nofpu", fpu_disable);