2 * linux/arch/arm/kernel/setup.c
4 * Copyright (C) 1995-2001 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 #include <linux/config.h>
11 #include <linux/kernel.h>
12 #include <linux/stddef.h>
13 #include <linux/ioport.h>
14 #include <linux/delay.h>
15 #include <linux/utsname.h>
16 #include <linux/initrd.h>
17 #include <linux/console.h>
18 #include <linux/bootmem.h>
19 #include <linux/seq_file.h>
20 #include <linux/tty.h>
21 #include <linux/init.h>
22 #include <linux/root_dev.h>
23 #include <linux/cpu.h>
26 #include <asm/hardware.h>
28 #include <asm/procinfo.h>
29 #include <asm/setup.h>
30 #include <asm/mach-types.h>
31 #include <asm/cacheflush.h>
32 #include <asm/tlbflush.h>
34 #include <asm/mach/arch.h>
35 #include <asm/mach/irq.h>
38 #define MEM_SIZE (16*1024*1024)
41 #if defined(CONFIG_FPE_NWFPE) || defined(CONFIG_FPE_FASTFPE)
44 static int __init fpe_setup(char *line)
46 memcpy(fpe_type, line, 8);
50 __setup("fpe=", fpe_setup);
53 extern unsigned int mem_fclk_21285;
54 extern void paging_init(struct meminfo *, struct machine_desc *desc);
55 extern void convert_to_tag_list(struct tag *tags);
56 extern void squash_mem_tags(struct tag *tag);
57 extern void bootmem_init(struct meminfo *);
58 extern void reboot_setup(char *str);
59 extern int root_mountflags;
60 extern int _stext, _text, _etext, _edata, _end;
62 unsigned int processor_id;
63 unsigned int __machine_arch_type;
64 unsigned int system_rev;
65 unsigned int system_serial_low;
66 unsigned int system_serial_high;
67 unsigned int elf_hwcap;
70 struct processor processor;
73 struct cpu_tlb_fns cpu_tlb;
76 struct cpu_user_fns cpu_user;
79 struct cpu_cache_fns cpu_cache;
82 unsigned char aux_device_present;
83 char elf_platform[ELF_PLATFORM_SIZE];
84 char saved_command_line[COMMAND_LINE_SIZE];
85 unsigned long phys_initrd_start __initdata = 0;
86 unsigned long phys_initrd_size __initdata = 0;
88 static struct meminfo meminfo __initdata = { 0, };
89 static const char *cpu_name;
90 static const char *machine_name;
91 static char command_line[COMMAND_LINE_SIZE];
93 static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
94 static union { char c[4]; unsigned long l; } endian_test __initdata = { { 'l', '?', '?', 'b' } };
95 #define ENDIANNESS ((char)endian_test.l)
98 * Standard memory resources
100 static struct resource mem_res[] = {
101 { "Video RAM", 0, 0, IORESOURCE_MEM },
102 { "Kernel code", 0, 0, IORESOURCE_MEM },
103 { "Kernel data", 0, 0, IORESOURCE_MEM }
106 #define video_ram mem_res[0]
107 #define kernel_code mem_res[1]
108 #define kernel_data mem_res[2]
110 static struct resource io_res[] = {
111 { "reserved", 0x3bc, 0x3be, IORESOURCE_IO | IORESOURCE_BUSY },
112 { "reserved", 0x378, 0x37f, IORESOURCE_IO | IORESOURCE_BUSY },
113 { "reserved", 0x278, 0x27f, IORESOURCE_IO | IORESOURCE_BUSY }
116 #define lp0 io_res[0]
117 #define lp1 io_res[1]
118 #define lp2 io_res[2]
120 static const char *cache_types[16] = {
121 "VIVT write-through",
139 static const char *cache_clean[16] = {
158 static const char *cache_lockdown[16] = {
177 static const char *proc_arch[] = {
197 #define CACHE_TYPE(x) (((x) >> 25) & 15)
198 #define CACHE_S(x) ((x) & (1 << 24))
199 #define CACHE_DSIZE(x) (((x) >> 12) & 4095) /* only if S=1 */
200 #define CACHE_ISIZE(x) ((x) & 4095)
202 #define CACHE_SIZE(y) (((y) >> 6) & 7)
203 #define CACHE_ASSOC(y) (((y) >> 3) & 7)
204 #define CACHE_M(y) ((y) & (1 << 2))
205 #define CACHE_LINE(y) ((y) & 3)
207 static inline void dump_cache(const char *prefix, unsigned int cache)
209 unsigned int mult = 2 + (CACHE_M(cache) ? 1 : 0);
211 printk("%s: %d bytes, associativity %d, %d byte lines, %d sets\n",
213 mult << (8 + CACHE_SIZE(cache)),
214 (mult << CACHE_ASSOC(cache)) >> 1,
215 8 << CACHE_LINE(cache),
216 1 << (6 + CACHE_SIZE(cache) - CACHE_ASSOC(cache) -
220 static void __init dump_cpu_info(void)
222 unsigned int info = read_cpuid(CPUID_CACHETYPE);
224 if (info != processor_id) {
225 printk("CPU: D %s cache\n", cache_types[CACHE_TYPE(info)]);
227 dump_cache("CPU: I cache", CACHE_ISIZE(info));
228 dump_cache("CPU: D cache", CACHE_DSIZE(info));
230 dump_cache("CPU: cache", CACHE_ISIZE(info));
235 int cpu_architecture(void)
239 if ((processor_id & 0x0000f000) == 0) {
240 cpu_arch = CPU_ARCH_UNKNOWN;
241 } else if ((processor_id & 0x0000f000) == 0x00007000) {
242 cpu_arch = (processor_id & (1 << 23)) ? CPU_ARCH_ARMv4T : CPU_ARCH_ARMv3;
244 cpu_arch = (processor_id >> 16) & 15;
246 cpu_arch += CPU_ARCH_ARMv3;
252 static void __init setup_processor(void)
254 extern struct proc_info_list __proc_info_begin, __proc_info_end;
255 struct proc_info_list *list;
258 * locate processor in the list of supported processor
259 * types. The linker builds this table for us from the
260 * entries in arch/arm/mm/proc-*.S
262 for (list = &__proc_info_begin; list < &__proc_info_end ; list++)
263 if ((processor_id & list->cpu_mask) == list->cpu_val)
267 * If processor type is unrecognised, then we
270 if (list >= &__proc_info_end) {
271 printk("CPU configuration botched (ID %08x), unable "
272 "to continue.\n", processor_id);
276 cpu_name = list->cpu_name;
279 processor = *list->proc;
282 cpu_tlb = *list->tlb;
285 cpu_user = *list->user;
288 cpu_cache = *list->cache;
291 printk("CPU: %s [%08x] revision %d (ARMv%s)\n",
292 cpu_name, processor_id, (int)processor_id & 15,
293 proc_arch[cpu_architecture()]);
297 sprintf(system_utsname.machine, "%s%c", list->arch_name, ENDIANNESS);
298 sprintf(elf_platform, "%s%c", list->elf_name, ENDIANNESS);
299 elf_hwcap = list->elf_hwcap;
304 static struct machine_desc * __init setup_machine(unsigned int nr)
306 extern struct machine_desc __arch_info_begin, __arch_info_end;
307 struct machine_desc *list;
310 * locate architecture in the list of supported architectures.
312 for (list = &__arch_info_begin; list < &__arch_info_end; list++)
317 * If the architecture type is not recognised, then we
320 if (list >= &__arch_info_end) {
321 printk("Architecture configuration botched (nr %d), unable "
322 "to continue.\n", nr);
326 printk("Machine: %s\n", list->name);
331 static void __init early_initrd(char **p)
333 unsigned long start, size;
335 start = memparse(*p, p);
337 size = memparse((*p) + 1, p);
339 phys_initrd_start = start;
340 phys_initrd_size = size;
343 __early_param("initrd=", early_initrd);
346 * Pick out the memory size. We look for mem=size@start,
347 * where start and size are "size[KkMm]"
349 static void __init early_mem(char **p)
351 static int usermem __initdata = 0;
352 unsigned long size, start;
355 * If the user specifies memory size, we
356 * blow away any automatically generated
361 meminfo.nr_banks = 0;
365 size = memparse(*p, p);
367 start = memparse(*p + 1, p);
369 meminfo.bank[meminfo.nr_banks].start = start;
370 meminfo.bank[meminfo.nr_banks].size = size;
371 meminfo.bank[meminfo.nr_banks].node = PHYS_TO_NID(start);
372 meminfo.nr_banks += 1;
374 __early_param("mem=", early_mem);
377 * Initial parsing of the command line.
379 static void __init parse_cmdline(char **cmdline_p, char *from)
381 char c = ' ', *to = command_line;
386 extern struct early_params __early_begin, __early_end;
387 struct early_params *p;
389 for (p = &__early_begin; p < &__early_end; p++) {
390 int len = strlen(p->arg);
392 if (memcmp(from, p->arg, len) == 0) {
393 if (to != command_line)
398 while (*from != ' ' && *from != '\0')
407 if (COMMAND_LINE_SIZE <= ++len)
412 *cmdline_p = command_line;
416 setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
418 #ifdef CONFIG_BLK_DEV_RAM
419 extern int rd_size, rd_image_start, rd_prompt, rd_doload;
421 rd_image_start = image_start;
431 request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
433 struct resource *res;
436 kernel_code.start = __virt_to_phys(init_mm.start_code);
437 kernel_code.end = __virt_to_phys(init_mm.end_code - 1);
438 kernel_data.start = __virt_to_phys(init_mm.end_code);
439 kernel_data.end = __virt_to_phys(init_mm.brk - 1);
441 for (i = 0; i < mi->nr_banks; i++) {
442 unsigned long virt_start, virt_end;
444 if (mi->bank[i].size == 0)
447 virt_start = __phys_to_virt(mi->bank[i].start);
448 virt_end = virt_start + mi->bank[i].size - 1;
450 res = alloc_bootmem_low(sizeof(*res));
451 res->name = "System RAM";
452 res->start = __virt_to_phys(virt_start);
453 res->end = __virt_to_phys(virt_end);
454 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
456 request_resource(&iomem_resource, res);
458 if (kernel_code.start >= res->start &&
459 kernel_code.end <= res->end)
460 request_resource(res, &kernel_code);
461 if (kernel_data.start >= res->start &&
462 kernel_data.end <= res->end)
463 request_resource(res, &kernel_data);
466 if (mdesc->video_start) {
467 video_ram.start = mdesc->video_start;
468 video_ram.end = mdesc->video_end;
469 request_resource(&iomem_resource, &video_ram);
473 * Some machines don't have the possibility of ever
474 * possessing lp0, lp1 or lp2
476 if (mdesc->reserve_lp0)
477 request_resource(&ioport_resource, &lp0);
478 if (mdesc->reserve_lp1)
479 request_resource(&ioport_resource, &lp1);
480 if (mdesc->reserve_lp2)
481 request_resource(&ioport_resource, &lp2);
487 * This is the new way of passing data to the kernel at boot time. Rather
488 * than passing a fixed inflexible structure to the kernel, we pass a list
489 * of variable-sized tags to the kernel. The first tag must be a ATAG_CORE
490 * tag for the list to be recognised (to distinguish the tagged list from
491 * a param_struct). The list is terminated with a zero-length tag (this tag
492 * is not parsed in any way).
494 static int __init parse_tag_core(const struct tag *tag)
496 if (tag->hdr.size > 2) {
497 if ((tag->u.core.flags & 1) == 0)
498 root_mountflags &= ~MS_RDONLY;
499 ROOT_DEV = old_decode_dev(tag->u.core.rootdev);
504 __tagtable(ATAG_CORE, parse_tag_core);
506 static int __init parse_tag_mem32(const struct tag *tag)
508 if (meminfo.nr_banks >= NR_BANKS) {
510 "Ignoring memory bank 0x%08x size %dKB\n",
511 tag->u.mem.start, tag->u.mem.size / 1024);
514 meminfo.bank[meminfo.nr_banks].start = tag->u.mem.start;
515 meminfo.bank[meminfo.nr_banks].size = tag->u.mem.size;
516 meminfo.bank[meminfo.nr_banks].node = PHYS_TO_NID(tag->u.mem.start);
517 meminfo.nr_banks += 1;
522 __tagtable(ATAG_MEM, parse_tag_mem32);
524 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
525 struct screen_info screen_info = {
526 .orig_video_lines = 30,
527 .orig_video_cols = 80,
528 .orig_video_mode = 0,
529 .orig_video_ega_bx = 0,
530 .orig_video_isVGA = 1,
531 .orig_video_points = 8
534 static int __init parse_tag_videotext(const struct tag *tag)
536 screen_info.orig_x = tag->u.videotext.x;
537 screen_info.orig_y = tag->u.videotext.y;
538 screen_info.orig_video_page = tag->u.videotext.video_page;
539 screen_info.orig_video_mode = tag->u.videotext.video_mode;
540 screen_info.orig_video_cols = tag->u.videotext.video_cols;
541 screen_info.orig_video_ega_bx = tag->u.videotext.video_ega_bx;
542 screen_info.orig_video_lines = tag->u.videotext.video_lines;
543 screen_info.orig_video_isVGA = tag->u.videotext.video_isvga;
544 screen_info.orig_video_points = tag->u.videotext.video_points;
548 __tagtable(ATAG_VIDEOTEXT, parse_tag_videotext);
551 static int __init parse_tag_ramdisk(const struct tag *tag)
553 setup_ramdisk((tag->u.ramdisk.flags & 1) == 0,
554 (tag->u.ramdisk.flags & 2) == 0,
555 tag->u.ramdisk.start, tag->u.ramdisk.size);
559 __tagtable(ATAG_RAMDISK, parse_tag_ramdisk);
561 static int __init parse_tag_initrd(const struct tag *tag)
563 printk(KERN_WARNING "ATAG_INITRD is deprecated; "
564 "please update your bootloader.\n");
565 phys_initrd_start = __virt_to_phys(tag->u.initrd.start);
566 phys_initrd_size = tag->u.initrd.size;
570 __tagtable(ATAG_INITRD, parse_tag_initrd);
572 static int __init parse_tag_initrd2(const struct tag *tag)
574 phys_initrd_start = tag->u.initrd.start;
575 phys_initrd_size = tag->u.initrd.size;
579 __tagtable(ATAG_INITRD2, parse_tag_initrd2);
581 static int __init parse_tag_serialnr(const struct tag *tag)
583 system_serial_low = tag->u.serialnr.low;
584 system_serial_high = tag->u.serialnr.high;
588 __tagtable(ATAG_SERIAL, parse_tag_serialnr);
590 static int __init parse_tag_revision(const struct tag *tag)
592 system_rev = tag->u.revision.rev;
596 __tagtable(ATAG_REVISION, parse_tag_revision);
598 static int __init parse_tag_cmdline(const struct tag *tag)
600 strlcpy(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE);
604 __tagtable(ATAG_CMDLINE, parse_tag_cmdline);
607 * Scan the tag table for this tag, and call its parse function.
608 * The tag table is built by the linker from all the __tagtable
611 static int __init parse_tag(const struct tag *tag)
613 extern struct tagtable __tagtable_begin, __tagtable_end;
616 for (t = &__tagtable_begin; t < &__tagtable_end; t++)
617 if (tag->hdr.tag == t->tag) {
622 return t < &__tagtable_end;
626 * Parse all tags in the list, checking both the global and architecture
627 * specific tag tables.
629 static void __init parse_tags(const struct tag *t)
631 for (; t->hdr.size; t = tag_next(t))
634 "Ignoring unrecognised tag 0x%08x\n",
639 * This holds our defaults.
641 static struct init_tags {
642 struct tag_header hdr1;
643 struct tag_core core;
644 struct tag_header hdr2;
645 struct tag_mem32 mem;
646 struct tag_header hdr3;
647 } init_tags __initdata = {
648 { tag_size(tag_core), ATAG_CORE },
649 { 1, PAGE_SIZE, 0xff },
650 { tag_size(tag_mem32), ATAG_MEM },
651 { MEM_SIZE, PHYS_OFFSET },
655 static void (*init_machine)(void) __initdata;
657 static int __init customize_machine(void)
659 /* customizes platform devices, or adds new ones */
664 arch_initcall(customize_machine);
666 void __init setup_arch(char **cmdline_p)
668 struct tag *tags = (struct tag *)&init_tags;
669 struct machine_desc *mdesc;
670 char *from = default_command_line;
673 mdesc = setup_machine(machine_arch_type);
674 machine_name = mdesc->name;
676 if (mdesc->soft_reboot)
679 if (mdesc->param_offset)
680 tags = phys_to_virt(mdesc->param_offset);
683 * If we have the old style parameters, convert them to
686 if (tags->hdr.tag != ATAG_CORE)
687 convert_to_tag_list(tags);
688 if (tags->hdr.tag != ATAG_CORE)
689 tags = (struct tag *)&init_tags;
692 mdesc->fixup(mdesc, tags, &from, &meminfo);
694 if (tags->hdr.tag == ATAG_CORE) {
695 if (meminfo.nr_banks != 0)
696 squash_mem_tags(tags);
700 init_mm.start_code = (unsigned long) &_text;
701 init_mm.end_code = (unsigned long) &_etext;
702 init_mm.end_data = (unsigned long) &_edata;
703 init_mm.brk = (unsigned long) &_end;
705 memcpy(saved_command_line, from, COMMAND_LINE_SIZE);
706 saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
707 parse_cmdline(cmdline_p, from);
708 bootmem_init(&meminfo);
709 paging_init(&meminfo, mdesc);
710 request_standard_resources(&meminfo, mdesc);
713 * Set up various architecture-specific pointers
715 init_arch_irq = mdesc->init_irq;
716 init_machine = mdesc->init_machine;
719 #if defined(CONFIG_VGA_CONSOLE)
720 conswitchp = &vga_con;
721 #elif defined(CONFIG_DUMMY_CONSOLE)
722 conswitchp = &dummy_con;
727 static struct cpu cpu[1];
729 static int __init topology_init(void)
731 return register_cpu(cpu, 0, NULL);
734 subsys_initcall(topology_init);
736 static const char *hwcap_str[] = {
749 c_show_cache(struct seq_file *m, const char *type, unsigned int cache)
751 unsigned int mult = 2 + (CACHE_M(cache) ? 1 : 0);
753 seq_printf(m, "%s size\t\t: %d\n"
755 "%s line length\t: %d\n"
757 type, mult << (8 + CACHE_SIZE(cache)),
758 type, (mult << CACHE_ASSOC(cache)) >> 1,
759 type, 8 << CACHE_LINE(cache),
760 type, 1 << (6 + CACHE_SIZE(cache) - CACHE_ASSOC(cache) -
764 static int c_show(struct seq_file *m, void *v)
768 seq_printf(m, "Processor\t: %s rev %d (%s)\n",
769 cpu_name, (int)processor_id & 15, elf_platform);
771 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
772 loops_per_jiffy / (500000/HZ),
773 (loops_per_jiffy / (5000/HZ)) % 100);
775 /* dump out the processor features */
776 seq_puts(m, "Features\t: ");
778 for (i = 0; hwcap_str[i]; i++)
779 if (elf_hwcap & (1 << i))
780 seq_printf(m, "%s ", hwcap_str[i]);
782 seq_printf(m, "\nCPU implementer\t: 0x%02x\n", processor_id >> 24);
783 seq_printf(m, "CPU architecture: %s\n", proc_arch[cpu_architecture()]);
785 if ((processor_id & 0x0000f000) == 0x00000000) {
787 seq_printf(m, "CPU part\t\t: %07x\n", processor_id >> 4);
789 if ((processor_id & 0x0000f000) == 0x00007000) {
791 seq_printf(m, "CPU variant\t: 0x%02x\n",
792 (processor_id >> 16) & 127);
795 seq_printf(m, "CPU variant\t: 0x%x\n",
796 (processor_id >> 20) & 15);
798 seq_printf(m, "CPU part\t: 0x%03x\n",
799 (processor_id >> 4) & 0xfff);
801 seq_printf(m, "CPU revision\t: %d\n", processor_id & 15);
804 unsigned int cache_info = read_cpuid(CPUID_CACHETYPE);
805 if (cache_info != processor_id) {
806 seq_printf(m, "Cache type\t: %s\n"
807 "Cache clean\t: %s\n"
808 "Cache lockdown\t: %s\n"
809 "Cache format\t: %s\n",
810 cache_types[CACHE_TYPE(cache_info)],
811 cache_clean[CACHE_TYPE(cache_info)],
812 cache_lockdown[CACHE_TYPE(cache_info)],
813 CACHE_S(cache_info) ? "Harvard" : "Unified");
815 if (CACHE_S(cache_info)) {
816 c_show_cache(m, "I", CACHE_ISIZE(cache_info));
817 c_show_cache(m, "D", CACHE_DSIZE(cache_info));
819 c_show_cache(m, "Cache", CACHE_ISIZE(cache_info));
826 seq_printf(m, "Hardware\t: %s\n", machine_name);
827 seq_printf(m, "Revision\t: %04x\n", system_rev);
828 seq_printf(m, "Serial\t\t: %08x%08x\n",
829 system_serial_high, system_serial_low);
834 static void *c_start(struct seq_file *m, loff_t *pos)
836 return *pos < 1 ? (void *)1 : NULL;
839 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
845 static void c_stop(struct seq_file *m, void *v)
849 struct seq_operations cpuinfo_op = {