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
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
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>
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>
35 #include <asm/addrspace.h>
36 #include <asm/bootinfo.h>
38 #include <asm/sections.h>
39 #include <asm/system.h>
41 struct cpuinfo_mips cpu_data[NR_CPUS];
44 struct screen_info screen_info;
48 * Set if box has EISA slots.
53 EXPORT_SYMBOL(EISA_bus);
56 #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
57 extern struct fd_ops no_fd_ops;
58 struct fd_ops *fd_ops;
61 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
62 extern struct ide_ops no_ide_ops;
63 struct ide_ops *ide_ops;
66 extern void * __rd_start, * __rd_end;
68 extern struct rtc_ops no_rtc_ops;
69 struct rtc_ops *rtc_ops;
74 * These are initialized so they are in the .data section
76 unsigned long mips_machtype = MACH_UNKNOWN;
77 unsigned long mips_machgroup = MACH_GROUP_UNKNOWN;
79 struct boot_mem_map boot_mem_map;
81 static char command_line[CL_SIZE];
82 char saved_command_line[CL_SIZE];
83 extern char arcs_cmdline[CL_SIZE];
86 * mips_io_port_base is the begin of the address space to which x86 style
87 * I/O ports are mapped.
89 const unsigned long mips_io_port_base = -1;
90 EXPORT_SYMBOL(mips_io_port_base);
93 * isa_slot_offset is the address where E(ISA) busaddress 0 is mapped
96 unsigned long isa_slot_offset;
97 EXPORT_SYMBOL(isa_slot_offset);
99 extern void SetUpBootInfo(void);
100 extern void load_mmu(void);
101 extern ATTRIB_NORET asmlinkage void start_kernel(void);
102 extern void prom_init(int, char **, char **, int *);
104 static struct resource code_resource = { "Kernel code" };
105 static struct resource data_resource = { "Kernel data" };
107 asmlinkage void __init init_arch(int argc, char **argv, char **envp,
110 /* Determine which MIPS variant we are running on. */
113 prom_init(argc, argv, envp, prom_vec);
118 * Determine the mmu/cache attached to this machine, then flush the
119 * tlb and caches. On the r4xx0 variants this also sets CP0_WIRED to
125 /* Disable coprocessors and set FPU for 16/32 FPR register model */
126 clear_c0_status(ST0_CU1|ST0_CU2|ST0_CU3|ST0_KX|ST0_SX|ST0_FR);
127 set_c0_status(ST0_CU0);
131 * On IP27, I am seeing the TS bit set when the kernel is loaded.
132 * Maybe because the kernel is in ckseg0 and not xkphys? Clear it
135 clear_c0_status(ST0_BEV|ST0_TS|ST0_CU1|ST0_CU2|ST0_CU3);
136 set_c0_status(ST0_CU0|ST0_KX|ST0_SX|ST0_FR);
142 void __init add_memory_region(phys_t start, phys_t size,
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");
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)
162 for (i = 0; i < boot_mem_map.nr_map; i++) {
163 printk(" memory: %0*Lx @ %0*Lx ",
164 sizeof(long) * 2, (u64) boot_mem_map.map[i].size,
165 sizeof(long) * 2, (u64) boot_mem_map.map[i].addr);
167 switch (boot_mem_map.map[i].type) {
169 printk("(usable)\n");
171 case BOOT_MEM_ROM_DATA:
172 printk("(ROM data)\n");
174 case BOOT_MEM_RESERVED:
175 printk("(reserved)\n");
178 printk("type %lu\n", boot_mem_map.map[i].type);
184 static inline void parse_cmdline_early(void)
186 char c = ' ', *to = command_line, *from = saved_command_line;
187 unsigned long start_at, mem_size;
191 printk("Determined physical RAM map:\n");
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)
205 * If a user specifies memory size, we
206 * blow away any automatically generated
210 boot_mem_map.nr_map = 0;
213 mem_size = memparse(from + 4, &from);
215 start_at = memparse(from + 1, &from);
218 add_memory_region(start_at, mem_size, BOOT_MEM_RAM);
223 if (CL_SIZE <= ++len)
230 printk("User-defined physical RAM map:\n");
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
247 unsigned long *initrd_header;
249 unsigned long bootmap_size;
250 unsigned long start_pfn, max_low_pfn, first_usable_pfn;
253 #ifdef CONFIG_BLK_DEV_INITRD
254 tmp = (((unsigned long)&_end + PAGE_SIZE-1) & PAGE_MASK) - 8;
255 if (tmp < (unsigned long)&_end)
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(CPHYSADDR((&_end)+(initrd_end - initrd_start) + PAGE_SIZE));
265 * Partially used pages are not usable - thus
266 * we are rounding upwards.
268 start_pfn = PFN_UP(CPHYSADDR(&_end));
269 #endif /* CONFIG_BLK_DEV_INITRD */
271 #ifndef CONFIG_SGI_IP27
272 /* Find the highest page frame number we have available. */
274 first_usable_pfn = -1UL;
275 for (i = 0; i < boot_mem_map.nr_map; i++) {
276 unsigned long start, end;
278 if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
281 start = PFN_UP(boot_mem_map.map[i].addr);
282 end = PFN_DOWN(boot_mem_map.map[i].addr
283 + boot_mem_map.map[i].size);
289 if (start < first_usable_pfn) {
290 if (start > start_pfn) {
291 first_usable_pfn = start;
292 } else if (end > start_pfn) {
293 first_usable_pfn = start_pfn;
299 * Determine low and high memory ranges
301 max_low_pfn = max_pfn;
302 if (max_low_pfn > MAXMEM_PFN) {
303 max_low_pfn = MAXMEM_PFN;
304 #ifndef CONFIG_HIGHMEM
305 /* Maximum memory usable is what is directly addressable */
306 printk(KERN_WARNING "Warning only %ldMB will be used.\n",
308 printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
312 #ifdef CONFIG_HIGHMEM
314 * Crude, we really should make a better attempt at detecting
317 highstart_pfn = highend_pfn = max_pfn;
318 if (max_pfn > MAXMEM_PFN) {
319 highstart_pfn = MAXMEM_PFN;
320 printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
321 (highend_pfn - highstart_pfn) >> (20 - PAGE_SHIFT));
325 /* Initialize the boot-time allocator with low memory only. */
326 bootmap_size = init_bootmem(first_usable_pfn, max_low_pfn);
329 * Register fully available low RAM pages with the bootmem allocator.
331 for (i = 0; i < boot_mem_map.nr_map; i++) {
332 unsigned long curr_pfn, last_pfn, size;
335 * Reserve usable memory.
337 if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
341 * We are rounding up the start address of usable memory:
343 curr_pfn = PFN_UP(boot_mem_map.map[i].addr);
344 if (curr_pfn >= max_low_pfn)
346 if (curr_pfn < start_pfn)
347 curr_pfn = start_pfn;
350 * ... and at the end of the usable range downwards:
352 last_pfn = PFN_DOWN(boot_mem_map.map[i].addr
353 + boot_mem_map.map[i].size);
355 if (last_pfn > max_low_pfn)
356 last_pfn = max_low_pfn;
359 * Only register lowmem part of lowmem segment with bootmem.
361 size = last_pfn - curr_pfn;
362 if (curr_pfn > PFN_DOWN(HIGHMEM_START))
364 if (curr_pfn + size - 1 > PFN_DOWN(HIGHMEM_START))
365 size = PFN_DOWN(HIGHMEM_START) - curr_pfn;
370 * ... finally, did all the rounding and playing
371 * around just make the area go away?
373 if (last_pfn <= curr_pfn)
376 /* Register lowmem ranges */
377 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
380 /* Reserve the bootmap memory. */
381 reserve_bootmem(PFN_PHYS(first_usable_pfn), bootmap_size);
384 #ifdef CONFIG_BLK_DEV_INITRD
385 /* Board specific code should have set up initrd_start and initrd_end */
386 ROOT_DEV = Root_RAM0;
387 if (&__rd_start != &__rd_end) {
388 initrd_start = (unsigned long)&__rd_start;
389 initrd_end = (unsigned long)&__rd_end;
391 initrd_below_start_ok = 1;
393 unsigned long initrd_size = ((unsigned char *)initrd_end) - ((unsigned char *)initrd_start);
394 printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
395 (void *)initrd_start,
397 /* FIXME: is this right? */
398 #ifndef CONFIG_SGI_IP27
399 if (CPHYSADDR(initrd_end) > PFN_PHYS(max_low_pfn)) {
400 printk("initrd extends beyond end of memory "
401 "(0x%0*Lx > 0x%0*Lx)\ndisabling initrd\n",
402 sizeof(long) * 2, CPHYSADDR(initrd_end),
403 sizeof(long) * 2, PFN_PHYS(max_low_pfn));
404 initrd_start = initrd_end = 0;
406 #endif /* !CONFIG_SGI_IP27 */
408 #endif /* CONFIG_BLK_DEV_INITRD */
411 static inline void resource_init(void)
415 code_resource.start = virt_to_phys(&_text);
416 code_resource.end = virt_to_phys(&_etext) - 1;
417 data_resource.start = virt_to_phys(&_etext);
418 data_resource.end = virt_to_phys(&_edata) - 1;
421 * Request address space for all standard RAM.
423 for (i = 0; i < boot_mem_map.nr_map; i++) {
424 struct resource *res;
425 unsigned long start, end;
427 start = boot_mem_map.map[i].addr;
428 end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
434 res = alloc_bootmem(sizeof(struct resource));
435 switch (boot_mem_map.map[i].type) {
437 case BOOT_MEM_ROM_DATA:
438 res->name = "System RAM";
440 case BOOT_MEM_RESERVED:
442 res->name = "reserved";
448 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
449 request_resource(&iomem_resource, res);
452 * We don't know which RAM region contains kernel data,
453 * so we try it repeatedly and let the resource manager
456 request_resource(res, &code_resource);
457 request_resource(res, &data_resource);
468 void __init setup_arch(char **cmdline_p)
470 extern void atlas_setup(void);
471 extern void baget_setup(void);
472 extern void cobalt_setup(void);
473 extern void lasat_setup(void);
474 extern void ddb_setup(void);
475 extern void decstation_setup(void);
476 extern void deskstation_setup(void);
477 extern void jazz_setup(void);
478 extern void sni_rm200_pci_setup(void);
479 extern void ip22_setup(void);
480 extern void ip27_setup(void);
481 extern void ip32_setup(void);
482 extern void ev96100_setup(void);
483 extern void malta_setup(void);
484 extern void sead_setup(void);
485 extern void ikos_setup(void);
486 extern void momenco_ocelot_setup(void);
487 extern void momenco_ocelot_g_setup(void);
488 extern void momenco_ocelot_c_setup(void);
489 extern void nec_osprey_setup(void);
490 extern void nec_eagle_setup(void);
491 extern void zao_capcella_setup(void);
492 extern void victor_mpc30x_setup(void);
493 extern void ibm_workpad_setup(void);
494 extern void casio_e55_setup(void);
495 extern void jmr3927_setup(void);
496 extern void it8172_setup(void);
497 extern void swarm_setup(void);
498 extern void hp_setup(void);
499 extern void au1x00_setup(void);
500 extern void frame_info_init(void);
504 #ifdef CONFIG_BLK_DEV_FD
508 #ifdef CONFIG_BLK_DEV_IDE
509 ide_ops = &no_ide_ops;
512 rtc_ops = &no_rtc_ops;
514 switch (mips_machgroup) {
515 #ifdef CONFIG_BAGET_MIPS
516 case MACH_GROUP_BAGET:
520 #ifdef CONFIG_MIPS_COBALT
521 case MACH_GROUP_COBALT:
525 #ifdef CONFIG_DECSTATION
530 #ifdef CONFIG_MIPS_ATLAS
531 case MACH_GROUP_UNKNOWN:
535 #ifdef CONFIG_MIPS_JAZZ
536 case MACH_GROUP_JAZZ:
540 #ifdef CONFIG_MIPS_MALTA
541 case MACH_GROUP_UNKNOWN:
545 #ifdef CONFIG_MOMENCO_OCELOT
546 case MACH_GROUP_MOMENCO:
547 momenco_ocelot_setup();
550 #ifdef CONFIG_MOMENCO_OCELOT_G
551 case MACH_GROUP_MOMENCO:
552 momenco_ocelot_g_setup();
555 #ifdef CONFIG_MOMENCO_OCELOT_C
556 case MACH_GROUP_MOMENCO:
557 momenco_ocelot_c_setup();
560 #ifdef CONFIG_MIPS_SEAD
561 case MACH_GROUP_UNKNOWN:
565 #ifdef CONFIG_SGI_IP22
566 /* As of now this is only IP22. */
571 #ifdef CONFIG_SGI_IP27
576 #ifdef CONFIG_SGI_IP32
581 #ifdef CONFIG_SNI_RM200_PCI
582 case MACH_GROUP_SNI_RM:
583 sni_rm200_pci_setup();
586 #ifdef CONFIG_DDB5074
587 case MACH_GROUP_NEC_DDB:
591 #ifdef CONFIG_DDB5476
592 case MACH_GROUP_NEC_DDB:
596 #ifdef CONFIG_DDB5477
597 case MACH_GROUP_NEC_DDB:
601 #ifdef CONFIG_CPU_VR41XX
602 case MACH_GROUP_NEC_VR41XX:
603 switch (mips_machtype) {
604 #ifdef CONFIG_NEC_OSPREY
605 case MACH_NEC_OSPREY:
609 #ifdef CONFIG_NEC_EAGLE
614 #ifdef CONFIG_ZAO_CAPCELLA
615 case MACH_ZAO_CAPCELLA:
616 zao_capcella_setup();
619 #ifdef CONFIG_VICTOR_MPC30X
620 case MACH_VICTOR_MPC30X:
621 victor_mpc30x_setup();
624 #ifdef CONFIG_IBM_WORKPAD
625 case MACH_IBM_WORKPAD:
629 #ifdef CONFIG_CASIO_E55
634 #ifdef CONFIG_TANBAC_TB0229
635 case MACH_TANBAC_TB0229:
636 tanbac_tb0229_setup();
642 #ifdef CONFIG_MIPS_EV96100
643 case MACH_GROUP_GALILEO:
647 #ifdef CONFIG_MIPS_EV64120
648 case MACH_GROUP_GALILEO:
652 #if defined(CONFIG_MIPS_IVR) || defined(CONFIG_MIPS_ITE8172)
654 case MACH_GROUP_GLOBESPAN:
659 case MACH_GROUP_LASAT:
663 #ifdef CONFIG_SOC_AU1X00
664 case MACH_GROUP_ALCHEMY:
668 #ifdef CONFIG_TOSHIBA_JMR3927
669 case MACH_GROUP_TOSHIBA:
673 #ifdef CONFIG_TOSHIBA_RBTX4927
674 case MACH_GROUP_TOSHIBA:
678 #ifdef CONFIG_SIBYTE_BOARD
679 case MACH_GROUP_SIBYTE:
683 #ifdef CONFIG_HP_LASERJET
684 case MACH_GROUP_HP_LJ:
689 panic("Unsupported architecture");
692 strlcpy(command_line, arcs_cmdline, sizeof(command_line));
693 strlcpy(saved_command_line, command_line, sizeof(saved_command_line));
695 *cmdline_p = command_line;
697 parse_cmdline_early();
706 int __init fpu_disable(char *s)
708 cpu_data[0].options &= ~MIPS_CPU_FPU;
713 __setup("nofpu", fpu_disable);