setup.c 14 KB

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