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>
34 #include <linux/highmem.h>
35 #include <linux/console.h>
36 #include <linux/mmzone.h>
38 #include <asm/addrspace.h>
39 #include <asm/bootinfo.h>
40 #include <asm/cache.h>
42 #include <asm/sections.h>
43 #include <asm/setup.h>
44 #include <asm/system.h>
46 struct cpuinfo_mips cpu_data
[NR_CPUS
] __read_mostly
;
48 EXPORT_SYMBOL(cpu_data
);
51 struct screen_info screen_info
;
55 * Despite it's name this variable is even if we don't have PCI
57 unsigned int PCI_DMA_BUS_IS_PHYS
;
59 EXPORT_SYMBOL(PCI_DMA_BUS_IS_PHYS
);
64 * These are initialized so they are in the .data section
66 unsigned long mips_machtype __read_mostly
= MACH_UNKNOWN
;
67 unsigned long mips_machgroup __read_mostly
= MACH_GROUP_UNKNOWN
;
69 EXPORT_SYMBOL(mips_machtype
);
70 EXPORT_SYMBOL(mips_machgroup
);
72 struct boot_mem_map boot_mem_map
;
74 static char command_line
[CL_SIZE
];
75 char arcs_cmdline
[CL_SIZE
]=CONFIG_CMDLINE
;
78 * mips_io_port_base is the begin of the address space to which x86 style
79 * I/O ports are mapped.
81 const unsigned long mips_io_port_base __read_mostly
= -1;
82 EXPORT_SYMBOL(mips_io_port_base
);
85 * isa_slot_offset is the address where E(ISA) busaddress 0 is mapped
88 unsigned long isa_slot_offset
;
89 EXPORT_SYMBOL(isa_slot_offset
);
91 static struct resource code_resource
= { .name
= "Kernel code", };
92 static struct resource data_resource
= { .name
= "Kernel data", };
94 void __init
add_memory_region(phys_t start
, phys_t size
, long type
)
96 int x
= boot_mem_map
.nr_map
;
97 struct boot_mem_map_entry
*prev
= boot_mem_map
.map
+ x
- 1;
100 * Try to merge with previous entry if any. This is far less than
101 * perfect but is sufficient for most real world cases.
103 if (x
&& prev
->addr
+ prev
->size
== start
&& prev
->type
== type
) {
108 if (x
== BOOT_MEM_MAP_MAX
) {
109 printk("Ooops! Too many entries in the memory map!\n");
113 boot_mem_map
.map
[x
].addr
= start
;
114 boot_mem_map
.map
[x
].size
= size
;
115 boot_mem_map
.map
[x
].type
= type
;
116 boot_mem_map
.nr_map
++;
119 static void __init
print_memory_map(void)
122 const int field
= 2 * sizeof(unsigned long);
124 for (i
= 0; i
< boot_mem_map
.nr_map
; i
++) {
125 printk(" memory: %0*Lx @ %0*Lx ",
126 field
, (unsigned long long) boot_mem_map
.map
[i
].size
,
127 field
, (unsigned long long) boot_mem_map
.map
[i
].addr
);
129 switch (boot_mem_map
.map
[i
].type
) {
131 printk("(usable)\n");
133 case BOOT_MEM_ROM_DATA
:
134 printk("(ROM data)\n");
136 case BOOT_MEM_RESERVED
:
137 printk("(reserved)\n");
140 printk("type %lu\n", boot_mem_map
.map
[i
].type
);
146 static inline void parse_cmdline_early(void)
148 char c
= ' ', *to
= command_line
, *from
= saved_command_line
;
149 unsigned long start_at
, mem_size
;
153 printk("Determined physical RAM map:\n");
158 * "mem=XXX[kKmM]" defines a memory region from
159 * 0 to <XXX>, overriding the determined size.
160 * "mem=XXX[KkmM]@YYY[KkmM]" defines a memory region from
161 * <YYY> to <YYY>+<XXX>, overriding the determined size.
163 if (c
== ' ' && !memcmp(from
, "mem=", 4)) {
164 if (to
!= command_line
)
167 * If a user specifies memory size, we
168 * blow away any automatically generated
172 boot_mem_map
.nr_map
= 0;
175 mem_size
= memparse(from
+ 4, &from
);
177 start_at
= memparse(from
+ 1, &from
);
180 add_memory_region(start_at
, mem_size
, BOOT_MEM_RAM
);
185 if (CL_SIZE
<= ++len
)
192 printk("User-defined physical RAM map:\n");
197 static inline int parse_rd_cmdline(unsigned long* rd_start
, unsigned long* rd_end
)
200 * "rd_start=0xNNNNNNNN" defines the memory address of an initrd
201 * "rd_size=0xNN" it's size
203 unsigned long start
= 0;
204 unsigned long size
= 0;
206 char cmd_line
[CL_SIZE
];
211 strcpy(cmd_line
, command_line
);
214 /* Ignore "rd_start=" strings in other parameters. */
215 start_str
= strstr(cmd_line
, "rd_start=");
216 if (start_str
&& start_str
!= cmd_line
&& *(start_str
- 1) != ' ')
217 start_str
= strstr(start_str
, " rd_start=");
219 if (start_str
!= cmd_line
)
220 strncat(command_line
, tmp
, start_str
- tmp
);
221 start
= memparse(start_str
+ 9, &start_str
);
223 start_str
= strstr(start_str
, " rd_start=");
226 strcat(command_line
, tmp
);
228 strcpy(cmd_line
, command_line
);
231 /* Ignore "rd_size" strings in other parameters. */
232 size_str
= strstr(cmd_line
, "rd_size=");
233 if (size_str
&& size_str
!= cmd_line
&& *(size_str
- 1) != ' ')
234 size_str
= strstr(size_str
, " rd_size=");
236 if (size_str
!= cmd_line
)
237 strncat(command_line
, tmp
, size_str
- tmp
);
238 size
= memparse(size_str
+ 8, &size_str
);
240 size_str
= strstr(size_str
, " rd_size=");
243 strcat(command_line
, tmp
);
246 /* HACK: Guess if the sign extension was forgotten */
247 if (start
> 0x0000000080000000 && start
< 0x00000000ffffffff)
248 start
|= 0xffffffff00000000;
260 #define PFN_UP(x) (((x) + PAGE_SIZE - 1) >> PAGE_SHIFT)
261 #define PFN_DOWN(x) ((x) >> PAGE_SHIFT)
262 #define PFN_PHYS(x) ((x) << PAGE_SHIFT)
264 #define MAXMEM HIGHMEM_START
265 #define MAXMEM_PFN PFN_DOWN(MAXMEM)
267 static inline void bootmem_init(void)
269 unsigned long start_pfn
;
270 unsigned long reserved_end
= (unsigned long)&_end
;
271 #ifndef CONFIG_SGI_IP27
272 unsigned long first_usable_pfn
;
273 unsigned long bootmap_size
;
276 #ifdef CONFIG_BLK_DEV_INITRD
277 int initrd_reserve_bootmem
= 0;
279 /* Board specific code should have set up initrd_start and initrd_end */
280 ROOT_DEV
= Root_RAM0
;
281 if (parse_rd_cmdline(&initrd_start
, &initrd_end
)) {
282 reserved_end
= max(reserved_end
, initrd_end
);
283 initrd_reserve_bootmem
= 1;
288 tmp
= ((reserved_end
+ PAGE_SIZE
-1) & PAGE_MASK
) - sizeof(u32
) * 2;
289 if (tmp
< reserved_end
)
291 initrd_header
= (u32
*)tmp
;
292 if (initrd_header
[0] == 0x494E5244) {
293 initrd_start
= (unsigned long)&initrd_header
[2];
294 initrd_end
= initrd_start
+ initrd_header
[1];
295 reserved_end
= max(reserved_end
, initrd_end
);
296 initrd_reserve_bootmem
= 1;
299 #endif /* CONFIG_BLK_DEV_INITRD */
302 * Partially used pages are not usable - thus
303 * we are rounding upwards.
305 start_pfn
= PFN_UP(CPHYSADDR(reserved_end
));
307 #ifndef CONFIG_SGI_IP27
308 /* Find the highest page frame number we have available. */
310 first_usable_pfn
= -1UL;
311 for (i
= 0; i
< boot_mem_map
.nr_map
; i
++) {
312 unsigned long start
, end
;
314 if (boot_mem_map
.map
[i
].type
!= BOOT_MEM_RAM
)
317 start
= PFN_UP(boot_mem_map
.map
[i
].addr
);
318 end
= PFN_DOWN(boot_mem_map
.map
[i
].addr
319 + boot_mem_map
.map
[i
].size
);
325 if (start
< first_usable_pfn
) {
326 if (start
> start_pfn
) {
327 first_usable_pfn
= start
;
328 } else if (end
> start_pfn
) {
329 first_usable_pfn
= start_pfn
;
335 * Determine low and high memory ranges
337 max_low_pfn
= max_pfn
;
338 if (max_low_pfn
> MAXMEM_PFN
) {
339 max_low_pfn
= MAXMEM_PFN
;
340 #ifndef CONFIG_HIGHMEM
341 /* Maximum memory usable is what is directly addressable */
342 printk(KERN_WARNING
"Warning only %ldMB will be used.\n",
344 printk(KERN_WARNING
"Use a HIGHMEM enabled kernel.\n");
348 #ifdef CONFIG_HIGHMEM
350 * Crude, we really should make a better attempt at detecting
353 highstart_pfn
= highend_pfn
= max_pfn
;
354 if (max_pfn
> MAXMEM_PFN
) {
355 highstart_pfn
= MAXMEM_PFN
;
356 printk(KERN_NOTICE
"%ldMB HIGHMEM available.\n",
357 (highend_pfn
- highstart_pfn
) >> (20 - PAGE_SHIFT
));
361 memory_present(0, first_usable_pfn
, max_low_pfn
);
363 /* Initialize the boot-time allocator with low memory only. */
364 bootmap_size
= init_bootmem(first_usable_pfn
, max_low_pfn
);
367 * Register fully available low RAM pages with the bootmem allocator.
369 for (i
= 0; i
< boot_mem_map
.nr_map
; i
++) {
370 unsigned long curr_pfn
, last_pfn
, size
;
373 * Reserve usable memory.
375 if (boot_mem_map
.map
[i
].type
!= BOOT_MEM_RAM
)
379 * We are rounding up the start address of usable memory:
381 curr_pfn
= PFN_UP(boot_mem_map
.map
[i
].addr
);
382 if (curr_pfn
>= max_low_pfn
)
384 if (curr_pfn
< start_pfn
)
385 curr_pfn
= start_pfn
;
388 * ... and at the end of the usable range downwards:
390 last_pfn
= PFN_DOWN(boot_mem_map
.map
[i
].addr
391 + boot_mem_map
.map
[i
].size
);
393 if (last_pfn
> max_low_pfn
)
394 last_pfn
= max_low_pfn
;
397 * Only register lowmem part of lowmem segment with bootmem.
399 size
= last_pfn
- curr_pfn
;
400 if (curr_pfn
> PFN_DOWN(HIGHMEM_START
))
402 if (curr_pfn
+ size
- 1 > PFN_DOWN(HIGHMEM_START
))
403 size
= PFN_DOWN(HIGHMEM_START
) - curr_pfn
;
408 * ... finally, did all the rounding and playing
409 * around just make the area go away?
411 if (last_pfn
<= curr_pfn
)
414 /* Register lowmem ranges */
415 free_bootmem(PFN_PHYS(curr_pfn
), PFN_PHYS(size
));
418 /* Reserve the bootmap memory. */
419 reserve_bootmem(PFN_PHYS(first_usable_pfn
), bootmap_size
);
420 #endif /* CONFIG_SGI_IP27 */
422 #ifdef CONFIG_BLK_DEV_INITRD
423 initrd_below_start_ok
= 1;
425 unsigned long initrd_size
= ((unsigned char *)initrd_end
) - ((unsigned char *)initrd_start
);
426 printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
427 (void *)initrd_start
, initrd_size
);
429 if (CPHYSADDR(initrd_end
) > PFN_PHYS(max_low_pfn
)) {
430 printk("initrd extends beyond end of memory "
431 "(0x%0*Lx > 0x%0*Lx)\ndisabling initrd\n",
433 (unsigned long long)CPHYSADDR(initrd_end
),
435 (unsigned long long)PFN_PHYS(max_low_pfn
));
436 initrd_start
= initrd_end
= 0;
437 initrd_reserve_bootmem
= 0;
440 if (initrd_reserve_bootmem
)
441 reserve_bootmem(CPHYSADDR(initrd_start
), initrd_size
);
443 #endif /* CONFIG_BLK_DEV_INITRD */
446 static inline void resource_init(void)
450 code_resource
.start
= virt_to_phys(&_text
);
451 code_resource
.end
= virt_to_phys(&_etext
) - 1;
452 data_resource
.start
= virt_to_phys(&_etext
);
453 data_resource
.end
= virt_to_phys(&_edata
) - 1;
456 * Request address space for all standard RAM.
458 for (i
= 0; i
< boot_mem_map
.nr_map
; i
++) {
459 struct resource
*res
;
460 unsigned long start
, end
;
462 start
= boot_mem_map
.map
[i
].addr
;
463 end
= boot_mem_map
.map
[i
].addr
+ boot_mem_map
.map
[i
].size
- 1;
469 res
= alloc_bootmem(sizeof(struct resource
));
470 switch (boot_mem_map
.map
[i
].type
) {
472 case BOOT_MEM_ROM_DATA
:
473 res
->name
= "System RAM";
475 case BOOT_MEM_RESERVED
:
477 res
->name
= "reserved";
483 res
->flags
= IORESOURCE_MEM
| IORESOURCE_BUSY
;
484 request_resource(&iomem_resource
, res
);
487 * We don't know which RAM region contains kernel data,
488 * so we try it repeatedly and let the resource manager
491 request_resource(res
, &code_resource
);
492 request_resource(res
, &data_resource
);
503 extern void plat_setup(void);
505 void __init
setup_arch(char **cmdline_p
)
511 #if defined(CONFIG_VT)
512 #if defined(CONFIG_VGA_CONSOLE)
513 conswitchp
= &vga_con
;
514 #elif defined(CONFIG_DUMMY_CONSOLE)
515 conswitchp
= &dummy_con
;
519 /* call board setup routine */
522 strlcpy(command_line
, arcs_cmdline
, sizeof(command_line
));
523 strlcpy(saved_command_line
, command_line
, COMMAND_LINE_SIZE
);
525 *cmdline_p
= command_line
;
527 parse_cmdline_early();
537 int __init
fpu_disable(char *s
)
539 cpu_data
[0].options
&= ~MIPS_CPU_FPU
;
544 __setup("nofpu", fpu_disable
);
546 int __init
dsp_disable(char *s
)
548 cpu_data
[0].ases
&= ~MIPS_ASE_DSP
;
553 __setup("nodsp", dsp_disable
);