setup.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /*
  2. * linux/arch/arm26/kernel/setup.c
  3. *
  4. * Copyright (C) 1995-2001 Russell King
  5. * Copyright (C) 2003 Ian Molton
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/config.h>
  12. #include <linux/kernel.h>
  13. #include <linux/stddef.h>
  14. #include <linux/ioport.h>
  15. #include <linux/delay.h>
  16. #include <linux/utsname.h>
  17. #include <linux/blkdev.h>
  18. #include <linux/console.h>
  19. #include <linux/bootmem.h>
  20. #include <linux/seq_file.h>
  21. #include <linux/tty.h>
  22. #include <linux/init.h>
  23. #include <linux/root_dev.h>
  24. #include <asm/elf.h>
  25. #include <asm/hardware.h>
  26. #include <asm/io.h>
  27. #include <asm/procinfo.h>
  28. #include <asm/setup.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/tlbflush.h>
  31. #include <asm/irqchip.h>
  32. #ifndef MEM_SIZE
  33. #define MEM_SIZE (16*1024*1024)
  34. #endif
  35. #ifdef CONFIG_PREEMPT
  36. DEFINE_SPINLOCK(kernel_flag);
  37. #endif
  38. #if defined(CONFIG_FPE_NWFPE)
  39. char fpe_type[8];
  40. static int __init fpe_setup(char *line)
  41. {
  42. memcpy(fpe_type, line, 8);
  43. return 1;
  44. }
  45. __setup("fpe=", fpe_setup);
  46. #endif
  47. extern void paging_init(struct meminfo *);
  48. extern void convert_to_tag_list(struct tag *tags);
  49. extern void squash_mem_tags(struct tag *tag);
  50. extern void bootmem_init(struct meminfo *);
  51. extern int root_mountflags;
  52. extern int _stext, _text, _etext, _edata, _end;
  53. #ifdef CONFIG_XIP_KERNEL
  54. extern int _endtext, _sdata;
  55. #endif
  56. unsigned int processor_id;
  57. unsigned int __machine_arch_type;
  58. unsigned int system_rev;
  59. unsigned int system_serial_low;
  60. unsigned int system_serial_high;
  61. unsigned int elf_hwcap;
  62. unsigned int memc_ctrl_reg;
  63. unsigned int number_mfm_drives;
  64. struct processor processor;
  65. char elf_platform[ELF_PLATFORM_SIZE];
  66. unsigned long phys_initrd_start __initdata = 0;
  67. unsigned long phys_initrd_size __initdata = 0;
  68. static struct meminfo meminfo __initdata = { 0, };
  69. static struct proc_info_item proc_info;
  70. static const char *machine_name;
  71. static char command_line[COMMAND_LINE_SIZE];
  72. static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
  73. /*
  74. * Standard memory resources
  75. */
  76. static struct resource mem_res[] = {
  77. { "Video RAM", 0, 0, IORESOURCE_MEM },
  78. { "Kernel code", 0, 0, IORESOURCE_MEM },
  79. { "Kernel data", 0, 0, IORESOURCE_MEM }
  80. };
  81. #define video_ram mem_res[0]
  82. #define kernel_code mem_res[1]
  83. #define kernel_data mem_res[2]
  84. static struct resource io_res[] = {
  85. { "reserved", 0x3bc, 0x3be, IORESOURCE_IO | IORESOURCE_BUSY },
  86. { "reserved", 0x378, 0x37f, IORESOURCE_IO | IORESOURCE_BUSY },
  87. { "reserved", 0x278, 0x27f, IORESOURCE_IO | IORESOURCE_BUSY }
  88. };
  89. #define lp0 io_res[0]
  90. #define lp1 io_res[1]
  91. #define lp2 io_res[2]
  92. #define dump_cpu_info() do { } while (0)
  93. static void __init setup_processor(void)
  94. {
  95. extern struct proc_info_list __proc_info_begin, __proc_info_end;
  96. struct proc_info_list *list;
  97. /*
  98. * locate processor in the list of supported processor
  99. * types. The linker builds this table for us from the
  100. * entries in arch/arm26/mm/proc-*.S
  101. */
  102. for (list = &__proc_info_begin; list < &__proc_info_end ; list++)
  103. if ((processor_id & list->cpu_mask) == list->cpu_val)
  104. break;
  105. /*
  106. * If processor type is unrecognised, then we
  107. * can do nothing...
  108. */
  109. if (list >= &__proc_info_end) {
  110. printk("CPU configuration botched (ID %08x), unable "
  111. "to continue.\n", processor_id);
  112. while (1);
  113. }
  114. proc_info = *list->info;
  115. processor = *list->proc;
  116. printk("CPU: %s %s revision %d\n",
  117. proc_info.manufacturer, proc_info.cpu_name,
  118. (int)processor_id & 15);
  119. dump_cpu_info();
  120. sprintf(system_utsname.machine, "%s", list->arch_name);
  121. sprintf(elf_platform, "%s", list->elf_name);
  122. elf_hwcap = list->elf_hwcap;
  123. cpu_proc_init();
  124. }
  125. /*
  126. * Initial parsing of the command line. We need to pick out the
  127. * memory size. We look for mem=size@start, where start and size
  128. * are "size[KkMm]"
  129. */
  130. static void __init
  131. parse_cmdline(struct meminfo *mi, char **cmdline_p, char *from)
  132. {
  133. char c = ' ', *to = command_line;
  134. int usermem = 0, len = 0;
  135. for (;;) {
  136. if (c == ' ' && !memcmp(from, "mem=", 4)) {
  137. unsigned long size, start;
  138. if (to != command_line)
  139. to -= 1;
  140. /*
  141. * If the user specifies memory size, we
  142. * blow away any automatically generated
  143. * size.
  144. */
  145. if (usermem == 0) {
  146. usermem = 1;
  147. mi->nr_banks = 0;
  148. }
  149. start = PHYS_OFFSET;
  150. size = memparse(from + 4, &from);
  151. if (*from == '@')
  152. start = memparse(from + 1, &from);
  153. mi->bank[mi->nr_banks].start = start;
  154. mi->bank[mi->nr_banks].size = size;
  155. mi->bank[mi->nr_banks].node = PHYS_TO_NID(start);
  156. mi->nr_banks += 1;
  157. }
  158. c = *from++;
  159. if (!c)
  160. break;
  161. if (COMMAND_LINE_SIZE <= ++len)
  162. break;
  163. *to++ = c;
  164. }
  165. *to = '\0';
  166. *cmdline_p = command_line;
  167. }
  168. static void __init
  169. setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
  170. {
  171. #ifdef CONFIG_BLK_DEV_RAM
  172. extern int rd_size, rd_image_start, rd_prompt, rd_doload;
  173. rd_image_start = image_start;
  174. rd_prompt = prompt;
  175. rd_doload = doload;
  176. if (rd_sz)
  177. rd_size = rd_sz;
  178. #endif
  179. }
  180. static void __init
  181. request_standard_resources(struct meminfo *mi)
  182. {
  183. struct resource *res;
  184. int i;
  185. kernel_code.start = init_mm.start_code;
  186. kernel_code.end = init_mm.end_code - 1;
  187. #ifdef CONFIG_XIP_KERNEL
  188. kernel_data.start = init_mm.start_data;
  189. #else
  190. kernel_data.start = init_mm.end_code;
  191. #endif
  192. kernel_data.end = init_mm.brk - 1;
  193. for (i = 0; i < mi->nr_banks; i++) {
  194. unsigned long virt_start, virt_end;
  195. if (mi->bank[i].size == 0)
  196. continue;
  197. virt_start = mi->bank[i].start;
  198. virt_end = virt_start + mi->bank[i].size - 1;
  199. res = alloc_bootmem_low(sizeof(*res));
  200. res->name = "System RAM";
  201. res->start = virt_start;
  202. res->end = virt_end;
  203. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  204. request_resource(&iomem_resource, res);
  205. if (kernel_code.start >= res->start &&
  206. kernel_code.end <= res->end)
  207. request_resource(res, &kernel_code);
  208. if (kernel_data.start >= res->start &&
  209. kernel_data.end <= res->end)
  210. request_resource(res, &kernel_data);
  211. }
  212. /* FIXME - needed? if (mdesc->video_start) {
  213. video_ram.start = mdesc->video_start;
  214. video_ram.end = mdesc->video_end;
  215. request_resource(&iomem_resource, &video_ram);
  216. }*/
  217. /*
  218. * Some machines don't have the possibility of ever
  219. * possessing lp1 or lp2
  220. */
  221. if (0) /* FIXME - need to do this for A5k at least */
  222. request_resource(&ioport_resource, &lp0);
  223. }
  224. /*
  225. * Tag parsing.
  226. *
  227. * This is the new way of passing data to the kernel at boot time. Rather
  228. * than passing a fixed inflexible structure to the kernel, we pass a list
  229. * of variable-sized tags to the kernel. The first tag must be a ATAG_CORE
  230. * tag for the list to be recognised (to distinguish the tagged list from
  231. * a param_struct). The list is terminated with a zero-length tag (this tag
  232. * is not parsed in any way).
  233. */
  234. static int __init parse_tag_core(const struct tag *tag)
  235. {
  236. if (tag->hdr.size > 2) {
  237. if ((tag->u.core.flags & 1) == 0)
  238. root_mountflags &= ~MS_RDONLY;
  239. ROOT_DEV = old_decode_dev(tag->u.core.rootdev);
  240. }
  241. return 0;
  242. }
  243. __tagtable(ATAG_CORE, parse_tag_core);
  244. static int __init parse_tag_mem32(const struct tag *tag)
  245. {
  246. if (meminfo.nr_banks >= NR_BANKS) {
  247. printk(KERN_WARNING
  248. "Ignoring memory bank 0x%08x size %dKB\n",
  249. tag->u.mem.start, tag->u.mem.size / 1024);
  250. return -EINVAL;
  251. }
  252. meminfo.bank[meminfo.nr_banks].start = tag->u.mem.start;
  253. meminfo.bank[meminfo.nr_banks].size = tag->u.mem.size;
  254. meminfo.bank[meminfo.nr_banks].node = PHYS_TO_NID(tag->u.mem.start);
  255. meminfo.nr_banks += 1;
  256. return 0;
  257. }
  258. __tagtable(ATAG_MEM, parse_tag_mem32);
  259. #if defined(CONFIG_DUMMY_CONSOLE)
  260. struct screen_info screen_info = {
  261. .orig_video_lines = 30,
  262. .orig_video_cols = 80,
  263. .orig_video_mode = 0,
  264. .orig_video_ega_bx = 0,
  265. .orig_video_isVGA = 1,
  266. .orig_video_points = 8
  267. };
  268. static int __init parse_tag_videotext(const struct tag *tag)
  269. {
  270. screen_info.orig_x = tag->u.videotext.x;
  271. screen_info.orig_y = tag->u.videotext.y;
  272. screen_info.orig_video_page = tag->u.videotext.video_page;
  273. screen_info.orig_video_mode = tag->u.videotext.video_mode;
  274. screen_info.orig_video_cols = tag->u.videotext.video_cols;
  275. screen_info.orig_video_ega_bx = tag->u.videotext.video_ega_bx;
  276. screen_info.orig_video_lines = tag->u.videotext.video_lines;
  277. screen_info.orig_video_isVGA = tag->u.videotext.video_isvga;
  278. screen_info.orig_video_points = tag->u.videotext.video_points;
  279. return 0;
  280. }
  281. __tagtable(ATAG_VIDEOTEXT, parse_tag_videotext);
  282. #endif
  283. static int __init parse_tag_acorn(const struct tag *tag)
  284. {
  285. memc_ctrl_reg = tag->u.acorn.memc_control_reg;
  286. number_mfm_drives = tag->u.acorn.adfsdrives;
  287. return 0;
  288. }
  289. __tagtable(ATAG_ACORN, parse_tag_acorn);
  290. static int __init parse_tag_ramdisk(const struct tag *tag)
  291. {
  292. setup_ramdisk((tag->u.ramdisk.flags & 1) == 0,
  293. (tag->u.ramdisk.flags & 2) == 0,
  294. tag->u.ramdisk.start, tag->u.ramdisk.size);
  295. return 0;
  296. }
  297. __tagtable(ATAG_RAMDISK, parse_tag_ramdisk);
  298. static int __init parse_tag_initrd(const struct tag *tag)
  299. {
  300. printk(KERN_WARNING "ATAG_INITRD is deprecated; please update your bootloader. \n");
  301. phys_initrd_start = (unsigned long)tag->u.initrd.start;
  302. phys_initrd_size = (unsigned long)tag->u.initrd.size;
  303. return 0;
  304. }
  305. __tagtable(ATAG_INITRD, parse_tag_initrd);
  306. static int __init parse_tag_initrd2(const struct tag *tag)
  307. {
  308. printk(KERN_WARNING "ATAG_INITRD is deprecated; please update your bootloader. \n");
  309. phys_initrd_start = (unsigned long)tag->u.initrd.start;
  310. phys_initrd_size = (unsigned long)tag->u.initrd.size;
  311. return 0;
  312. }
  313. __tagtable(ATAG_INITRD2, parse_tag_initrd2);
  314. static int __init parse_tag_serialnr(const struct tag *tag)
  315. {
  316. system_serial_low = tag->u.serialnr.low;
  317. system_serial_high = tag->u.serialnr.high;
  318. return 0;
  319. }
  320. __tagtable(ATAG_SERIAL, parse_tag_serialnr);
  321. static int __init parse_tag_revision(const struct tag *tag)
  322. {
  323. system_rev = tag->u.revision.rev;
  324. return 0;
  325. }
  326. __tagtable(ATAG_REVISION, parse_tag_revision);
  327. static int __init parse_tag_cmdline(const struct tag *tag)
  328. {
  329. strncpy(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE);
  330. default_command_line[COMMAND_LINE_SIZE - 1] = '\0';
  331. return 0;
  332. }
  333. __tagtable(ATAG_CMDLINE, parse_tag_cmdline);
  334. /*
  335. * Scan the tag table for this tag, and call its parse function.
  336. * The tag table is built by the linker from all the __tagtable
  337. * declarations.
  338. */
  339. static int __init parse_tag(const struct tag *tag)
  340. {
  341. extern struct tagtable __tagtable_begin, __tagtable_end;
  342. struct tagtable *t;
  343. for (t = &__tagtable_begin; t < &__tagtable_end; t++)
  344. if (tag->hdr.tag == t->tag) {
  345. t->parse(tag);
  346. break;
  347. }
  348. return t < &__tagtable_end;
  349. }
  350. /*
  351. * Parse all tags in the list, checking both the global and architecture
  352. * specific tag tables.
  353. */
  354. static void __init parse_tags(const struct tag *t)
  355. {
  356. for (; t->hdr.size; t = tag_next(t))
  357. if (!parse_tag(t))
  358. printk(KERN_WARNING
  359. "Ignoring unrecognised tag 0x%08x\n",
  360. t->hdr.tag);
  361. }
  362. /*
  363. * This holds our defaults.
  364. */
  365. static struct init_tags {
  366. struct tag_header hdr1;
  367. struct tag_core core;
  368. struct tag_header hdr2;
  369. struct tag_mem32 mem;
  370. struct tag_header hdr3;
  371. } init_tags __initdata = {
  372. { tag_size(tag_core), ATAG_CORE },
  373. { 1, PAGE_SIZE, 0xff },
  374. { tag_size(tag_mem32), ATAG_MEM },
  375. { MEM_SIZE, PHYS_OFFSET },
  376. { 0, ATAG_NONE }
  377. };
  378. void __init setup_arch(char **cmdline_p)
  379. {
  380. struct tag *tags = (struct tag *)&init_tags;
  381. char *from = default_command_line;
  382. setup_processor();
  383. if(machine_arch_type == MACH_TYPE_A5K)
  384. machine_name = "A5000";
  385. else if(machine_arch_type == MACH_TYPE_ARCHIMEDES)
  386. machine_name = "Archimedes";
  387. else
  388. machine_name = "UNKNOWN";
  389. //FIXME - the tag struct is always copied here but this is a block
  390. // of RAM that is accidentally reserved along with video RAM. perhaps
  391. // it would be a good idea to explicitly reserve this?
  392. tags = (struct tag *)0x0207c000;
  393. /*
  394. * If we have the old style parameters, convert them to
  395. * a tag list.
  396. */
  397. if (tags->hdr.tag != ATAG_CORE)
  398. convert_to_tag_list(tags);
  399. if (tags->hdr.tag != ATAG_CORE)
  400. tags = (struct tag *)&init_tags;
  401. if (tags->hdr.tag == ATAG_CORE) {
  402. if (meminfo.nr_banks != 0)
  403. squash_mem_tags(tags);
  404. parse_tags(tags);
  405. }
  406. init_mm.start_code = (unsigned long) &_text;
  407. #ifndef CONFIG_XIP_KERNEL
  408. init_mm.end_code = (unsigned long) &_etext;
  409. #else
  410. init_mm.end_code = (unsigned long) &_endtext;
  411. init_mm.start_data = (unsigned long) &_sdata;
  412. #endif
  413. init_mm.end_data = (unsigned long) &_edata;
  414. init_mm.brk = (unsigned long) &_end;
  415. memcpy(saved_command_line, from, COMMAND_LINE_SIZE);
  416. saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
  417. parse_cmdline(&meminfo, cmdline_p, from);
  418. bootmem_init(&meminfo);
  419. paging_init(&meminfo);
  420. request_standard_resources(&meminfo);
  421. #ifdef CONFIG_VT
  422. #if defined(CONFIG_DUMMY_CONSOLE)
  423. conswitchp = &dummy_con;
  424. #endif
  425. #endif
  426. }
  427. static const char *hwcap_str[] = {
  428. "swp",
  429. "half",
  430. "thumb",
  431. "26bit",
  432. "fastmult",
  433. "fpa",
  434. "vfp",
  435. "edsp",
  436. NULL
  437. };
  438. static int c_show(struct seq_file *m, void *v)
  439. {
  440. int i;
  441. seq_printf(m, "Processor\t: %s %s rev %d (%s)\n",
  442. proc_info.manufacturer, proc_info.cpu_name,
  443. (int)processor_id & 15, elf_platform);
  444. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
  445. loops_per_jiffy / (500000/HZ),
  446. (loops_per_jiffy / (5000/HZ)) % 100);
  447. /* dump out the processor features */
  448. seq_puts(m, "Features\t: ");
  449. for (i = 0; hwcap_str[i]; i++)
  450. if (elf_hwcap & (1 << i))
  451. seq_printf(m, "%s ", hwcap_str[i]);
  452. seq_puts(m, "\n");
  453. seq_printf(m, "CPU part\t\t: %07x\n", processor_id >> 4);
  454. seq_printf(m, "CPU revision\t: %d\n\n", processor_id & 15);
  455. seq_printf(m, "Hardware\t: %s\n", machine_name);
  456. seq_printf(m, "Revision\t: %04x\n", system_rev);
  457. seq_printf(m, "Serial\t\t: %08x%08x\n",
  458. system_serial_high, system_serial_low);
  459. return 0;
  460. }
  461. static void *c_start(struct seq_file *m, loff_t *pos)
  462. {
  463. return *pos < 1 ? (void *)1 : NULL;
  464. }
  465. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  466. {
  467. ++*pos;
  468. return NULL;
  469. }
  470. static void c_stop(struct seq_file *m, void *v)
  471. {
  472. }
  473. struct seq_operations cpuinfo_op = {
  474. .start = c_start,
  475. .next = c_next,
  476. .stop = c_stop,
  477. .show = c_show
  478. };