setup.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*
  2. * linux/arch/sh/kernel/setup.c
  3. *
  4. * Copyright (C) 1999 Niibe Yutaka
  5. * Copyright (C) 2002, 2003 Paul Mundt
  6. */
  7. /*
  8. * This file handles the architecture-dependent parts of initialization
  9. */
  10. #include <linux/screen_info.h>
  11. #include <linux/ioport.h>
  12. #include <linux/init.h>
  13. #include <linux/initrd.h>
  14. #include <linux/bootmem.h>
  15. #include <linux/console.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/root_dev.h>
  18. #include <linux/utsname.h>
  19. #include <linux/cpu.h>
  20. #include <linux/pfn.h>
  21. #include <linux/fs.h>
  22. #include <asm/uaccess.h>
  23. #include <asm/io.h>
  24. #include <asm/sections.h>
  25. #include <asm/irq.h>
  26. #include <asm/setup.h>
  27. #include <asm/clock.h>
  28. #ifdef CONFIG_SH_KGDB
  29. #include <asm/kgdb.h>
  30. static int kgdb_parse_options(char *options);
  31. #endif
  32. extern void * __rd_start, * __rd_end;
  33. /*
  34. * Machine setup..
  35. */
  36. /*
  37. * Initialize loops_per_jiffy as 10000000 (1000MIPS).
  38. * This value will be used at the very early stage of serial setup.
  39. * The bigger value means no problem.
  40. */
  41. struct sh_cpuinfo boot_cpu_data = { CPU_SH_NONE, 10000000, };
  42. #ifdef CONFIG_VT
  43. struct screen_info screen_info;
  44. #endif
  45. #if defined(CONFIG_SH_UNKNOWN)
  46. struct sh_machine_vector sh_mv;
  47. #endif
  48. extern int root_mountflags;
  49. #define MV_NAME_SIZE 32
  50. static struct sh_machine_vector* __init get_mv_byname(const char* name);
  51. /*
  52. * This is set up by the setup-routine at boot-time
  53. */
  54. #define PARAM ((unsigned char *)empty_zero_page)
  55. #define MOUNT_ROOT_RDONLY (*(unsigned long *) (PARAM+0x000))
  56. #define RAMDISK_FLAGS (*(unsigned long *) (PARAM+0x004))
  57. #define ORIG_ROOT_DEV (*(unsigned long *) (PARAM+0x008))
  58. #define LOADER_TYPE (*(unsigned long *) (PARAM+0x00c))
  59. #define INITRD_START (*(unsigned long *) (PARAM+0x010))
  60. #define INITRD_SIZE (*(unsigned long *) (PARAM+0x014))
  61. /* ... */
  62. #define COMMAND_LINE ((char *) (PARAM+0x100))
  63. #define RAMDISK_IMAGE_START_MASK 0x07FF
  64. #define RAMDISK_PROMPT_FLAG 0x8000
  65. #define RAMDISK_LOAD_FLAG 0x4000
  66. static char command_line[COMMAND_LINE_SIZE] = { 0, };
  67. static struct resource code_resource = { .name = "Kernel code", };
  68. static struct resource data_resource = { .name = "Kernel data", };
  69. unsigned long memory_start, memory_end;
  70. static inline void parse_cmdline (char ** cmdline_p, char mv_name[MV_NAME_SIZE],
  71. struct sh_machine_vector** mvp,
  72. unsigned long *mv_io_base,
  73. int *mv_mmio_enable)
  74. {
  75. char c = ' ', *to = command_line, *from = COMMAND_LINE;
  76. int len = 0;
  77. /* Save unparsed command line copy for /proc/cmdline */
  78. memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
  79. saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
  80. memory_start = (unsigned long)PAGE_OFFSET+__MEMORY_START;
  81. memory_end = memory_start + __MEMORY_SIZE;
  82. for (;;) {
  83. /*
  84. * "mem=XXX[kKmM]" defines a size of memory.
  85. */
  86. if (c == ' ' && !memcmp(from, "mem=", 4)) {
  87. if (to != command_line)
  88. to--;
  89. {
  90. unsigned long mem_size;
  91. mem_size = memparse(from+4, &from);
  92. memory_end = memory_start + mem_size;
  93. }
  94. }
  95. #ifdef CONFIG_EARLY_PRINTK
  96. if (c == ' ' && !memcmp(from, "earlyprintk=", 12)) {
  97. char *ep_end;
  98. if (to != command_line)
  99. to--;
  100. from += 12;
  101. ep_end = strchr(from, ' ');
  102. setup_early_printk(from);
  103. printk("early console enabled\n");
  104. from = ep_end;
  105. }
  106. #endif
  107. if (c == ' ' && !memcmp(from, "sh_mv=", 6)) {
  108. char* mv_end;
  109. char* mv_comma;
  110. int mv_len;
  111. if (to != command_line)
  112. to--;
  113. from += 6;
  114. mv_end = strchr(from, ' ');
  115. if (mv_end == NULL)
  116. mv_end = from + strlen(from);
  117. mv_comma = strchr(from, ',');
  118. if ((mv_comma != NULL) && (mv_comma < mv_end)) {
  119. int ints[3];
  120. get_options(mv_comma+1, ARRAY_SIZE(ints), ints);
  121. *mv_io_base = ints[1];
  122. *mv_mmio_enable = ints[2];
  123. mv_len = mv_comma - from;
  124. } else {
  125. mv_len = mv_end - from;
  126. }
  127. if (mv_len > (MV_NAME_SIZE-1))
  128. mv_len = MV_NAME_SIZE-1;
  129. memcpy(mv_name, from, mv_len);
  130. mv_name[mv_len] = '\0';
  131. from = mv_end;
  132. *mvp = get_mv_byname(mv_name);
  133. }
  134. c = *(from++);
  135. if (!c)
  136. break;
  137. if (COMMAND_LINE_SIZE <= ++len)
  138. break;
  139. *(to++) = c;
  140. }
  141. *to = '\0';
  142. *cmdline_p = command_line;
  143. }
  144. static int __init sh_mv_setup(char **cmdline_p)
  145. {
  146. #ifdef CONFIG_SH_UNKNOWN
  147. extern struct sh_machine_vector mv_unknown;
  148. #endif
  149. struct sh_machine_vector *mv = NULL;
  150. char mv_name[MV_NAME_SIZE] = "";
  151. unsigned long mv_io_base = 0;
  152. int mv_mmio_enable = 0;
  153. parse_cmdline(cmdline_p, mv_name, &mv, &mv_io_base, &mv_mmio_enable);
  154. #ifdef CONFIG_SH_UNKNOWN
  155. if (mv == NULL) {
  156. mv = &mv_unknown;
  157. if (*mv_name != '\0') {
  158. printk("Warning: Unsupported machine %s, using unknown\n",
  159. mv_name);
  160. }
  161. }
  162. sh_mv = *mv;
  163. #endif
  164. /*
  165. * Manually walk the vec, fill in anything that the board hasn't yet
  166. * by hand, wrapping to the generic implementation.
  167. */
  168. #define mv_set(elem) do { \
  169. if (!sh_mv.mv_##elem) \
  170. sh_mv.mv_##elem = generic_##elem; \
  171. } while (0)
  172. mv_set(inb); mv_set(inw); mv_set(inl);
  173. mv_set(outb); mv_set(outw); mv_set(outl);
  174. mv_set(inb_p); mv_set(inw_p); mv_set(inl_p);
  175. mv_set(outb_p); mv_set(outw_p); mv_set(outl_p);
  176. mv_set(insb); mv_set(insw); mv_set(insl);
  177. mv_set(outsb); mv_set(outsw); mv_set(outsl);
  178. mv_set(readb); mv_set(readw); mv_set(readl);
  179. mv_set(writeb); mv_set(writew); mv_set(writel);
  180. mv_set(ioport_map);
  181. mv_set(ioport_unmap);
  182. mv_set(irq_demux);
  183. #ifdef CONFIG_SH_UNKNOWN
  184. __set_io_port_base(mv_io_base);
  185. #endif
  186. if (!sh_mv.mv_nr_irqs)
  187. sh_mv.mv_nr_irqs = NR_IRQS;
  188. return 0;
  189. }
  190. void __init setup_arch(char **cmdline_p)
  191. {
  192. unsigned long bootmap_size;
  193. unsigned long start_pfn, max_pfn, max_low_pfn;
  194. #ifdef CONFIG_CMDLINE_BOOL
  195. strcpy(COMMAND_LINE, CONFIG_CMDLINE);
  196. #endif
  197. ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
  198. #ifdef CONFIG_BLK_DEV_RAM
  199. rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
  200. rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
  201. rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
  202. #endif
  203. if (!MOUNT_ROOT_RDONLY)
  204. root_mountflags &= ~MS_RDONLY;
  205. init_mm.start_code = (unsigned long) _text;
  206. init_mm.end_code = (unsigned long) _etext;
  207. init_mm.end_data = (unsigned long) _edata;
  208. init_mm.brk = (unsigned long) _end;
  209. code_resource.start = (unsigned long)virt_to_phys(_text);
  210. code_resource.end = (unsigned long)virt_to_phys(_etext)-1;
  211. data_resource.start = (unsigned long)virt_to_phys(_etext);
  212. data_resource.end = (unsigned long)virt_to_phys(_edata)-1;
  213. sh_mv_setup(cmdline_p);
  214. /*
  215. * Find the highest page frame number we have available
  216. */
  217. max_pfn = PFN_DOWN(__pa(memory_end));
  218. /*
  219. * Determine low and high memory ranges:
  220. */
  221. max_low_pfn = max_pfn;
  222. /*
  223. * Partially used pages are not usable - thus
  224. * we are rounding upwards:
  225. */
  226. start_pfn = PFN_UP(__pa(_end));
  227. /*
  228. * Find a proper area for the bootmem bitmap. After this
  229. * bootstrap step all allocations (until the page allocator
  230. * is intact) must be done via bootmem_alloc().
  231. */
  232. bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
  233. __MEMORY_START>>PAGE_SHIFT,
  234. max_low_pfn);
  235. /*
  236. * Register fully available low RAM pages with the bootmem allocator.
  237. */
  238. {
  239. unsigned long curr_pfn, last_pfn, pages;
  240. /*
  241. * We are rounding up the start address of usable memory:
  242. */
  243. curr_pfn = PFN_UP(__MEMORY_START);
  244. /*
  245. * ... and at the end of the usable range downwards:
  246. */
  247. last_pfn = PFN_DOWN(__pa(memory_end));
  248. if (last_pfn > max_low_pfn)
  249. last_pfn = max_low_pfn;
  250. pages = last_pfn - curr_pfn;
  251. free_bootmem_node(NODE_DATA(0), PFN_PHYS(curr_pfn),
  252. PFN_PHYS(pages));
  253. }
  254. /*
  255. * Reserve the kernel text and
  256. * Reserve the bootmem bitmap. We do this in two steps (first step
  257. * was init_bootmem()), because this catches the (definitely buggy)
  258. * case of us accidentally initializing the bootmem allocator with
  259. * an invalid RAM area.
  260. */
  261. reserve_bootmem_node(NODE_DATA(0), __MEMORY_START+PAGE_SIZE,
  262. (PFN_PHYS(start_pfn)+bootmap_size+PAGE_SIZE-1)-__MEMORY_START);
  263. /*
  264. * reserve physical page 0 - it's a special BIOS page on many boxes,
  265. * enabling clean reboots, SMP operation, laptop functions.
  266. */
  267. reserve_bootmem_node(NODE_DATA(0), __MEMORY_START, PAGE_SIZE);
  268. #ifdef CONFIG_BLK_DEV_INITRD
  269. ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
  270. if (&__rd_start != &__rd_end) {
  271. LOADER_TYPE = 1;
  272. INITRD_START = PHYSADDR((unsigned long)&__rd_start) - __MEMORY_START;
  273. INITRD_SIZE = (unsigned long)&__rd_end - (unsigned long)&__rd_start;
  274. }
  275. if (LOADER_TYPE && INITRD_START) {
  276. if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
  277. reserve_bootmem_node(NODE_DATA(0), INITRD_START+__MEMORY_START, INITRD_SIZE);
  278. initrd_start =
  279. INITRD_START ? INITRD_START + PAGE_OFFSET + __MEMORY_START : 0;
  280. initrd_end = initrd_start + INITRD_SIZE;
  281. } else {
  282. printk("initrd extends beyond end of memory "
  283. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  284. INITRD_START + INITRD_SIZE,
  285. max_low_pfn << PAGE_SHIFT);
  286. initrd_start = 0;
  287. }
  288. }
  289. #endif
  290. #ifdef CONFIG_DUMMY_CONSOLE
  291. conswitchp = &dummy_con;
  292. #endif
  293. /* Perform the machine specific initialisation */
  294. if (likely(sh_mv.mv_setup))
  295. sh_mv.mv_setup(cmdline_p);
  296. paging_init();
  297. }
  298. struct sh_machine_vector* __init get_mv_byname(const char* name)
  299. {
  300. extern long __machvec_start, __machvec_end;
  301. struct sh_machine_vector *all_vecs =
  302. (struct sh_machine_vector *)&__machvec_start;
  303. int i, n = ((unsigned long)&__machvec_end
  304. - (unsigned long)&__machvec_start)/
  305. sizeof(struct sh_machine_vector);
  306. for (i = 0; i < n; ++i) {
  307. struct sh_machine_vector *mv = &all_vecs[i];
  308. if (mv == NULL)
  309. continue;
  310. if (strcasecmp(name, get_system_type()) == 0) {
  311. return mv;
  312. }
  313. }
  314. return NULL;
  315. }
  316. static struct cpu cpu[NR_CPUS];
  317. static int __init topology_init(void)
  318. {
  319. int cpu_id;
  320. for_each_possible_cpu(cpu_id)
  321. register_cpu(&cpu[cpu_id], cpu_id);
  322. return 0;
  323. }
  324. subsys_initcall(topology_init);
  325. static const char *cpu_name[] = {
  326. [CPU_SH7604] = "SH7604", [CPU_SH7300] = "SH7300",
  327. [CPU_SH7705] = "SH7705", [CPU_SH7706] = "SH7706",
  328. [CPU_SH7707] = "SH7707", [CPU_SH7708] = "SH7708",
  329. [CPU_SH7709] = "SH7709", [CPU_SH7710] = "SH7710",
  330. [CPU_SH7729] = "SH7729", [CPU_SH7750] = "SH7750",
  331. [CPU_SH7750S] = "SH7750S", [CPU_SH7750R] = "SH7750R",
  332. [CPU_SH7751] = "SH7751", [CPU_SH7751R] = "SH7751R",
  333. [CPU_SH7760] = "SH7760", [CPU_SH73180] = "SH73180",
  334. [CPU_ST40RA] = "ST40RA", [CPU_ST40GX1] = "ST40GX1",
  335. [CPU_SH4_202] = "SH4-202", [CPU_SH4_501] = "SH4-501",
  336. [CPU_SH7770] = "SH7770", [CPU_SH7780] = "SH7780",
  337. [CPU_SH7781] = "SH7781", [CPU_SH7343] = "SH7343",
  338. [CPU_SH_NONE] = "Unknown"
  339. };
  340. const char *get_cpu_subtype(void)
  341. {
  342. return cpu_name[boot_cpu_data.type];
  343. }
  344. #ifdef CONFIG_PROC_FS
  345. /* Symbolic CPU flags, keep in sync with asm/cpu-features.h */
  346. static const char *cpu_flags[] = {
  347. "none", "fpu", "p2flush", "mmuassoc", "dsp", "perfctr",
  348. "ptea", "llsc", "l2", NULL
  349. };
  350. static void show_cpuflags(struct seq_file *m)
  351. {
  352. unsigned long i;
  353. seq_printf(m, "cpu flags\t:");
  354. if (!cpu_data->flags) {
  355. seq_printf(m, " %s\n", cpu_flags[0]);
  356. return;
  357. }
  358. for (i = 0; cpu_flags[i]; i++)
  359. if ((cpu_data->flags & (1 << i)))
  360. seq_printf(m, " %s", cpu_flags[i+1]);
  361. seq_printf(m, "\n");
  362. }
  363. static void show_cacheinfo(struct seq_file *m, const char *type,
  364. struct cache_info info)
  365. {
  366. unsigned int cache_size;
  367. cache_size = info.ways * info.sets * info.linesz;
  368. seq_printf(m, "%s size\t: %2dKiB (%d-way)\n",
  369. type, cache_size >> 10, info.ways);
  370. }
  371. /*
  372. * Get CPU information for use by the procfs.
  373. */
  374. static int show_cpuinfo(struct seq_file *m, void *v)
  375. {
  376. unsigned int cpu = smp_processor_id();
  377. if (!cpu && cpu_online(cpu))
  378. seq_printf(m, "machine\t\t: %s\n", get_system_type());
  379. seq_printf(m, "processor\t: %d\n", cpu);
  380. seq_printf(m, "cpu family\t: %s\n", init_utsname()->machine);
  381. seq_printf(m, "cpu type\t: %s\n", get_cpu_subtype());
  382. show_cpuflags(m);
  383. seq_printf(m, "cache type\t: ");
  384. /*
  385. * Check for what type of cache we have, we support both the
  386. * unified cache on the SH-2 and SH-3, as well as the harvard
  387. * style cache on the SH-4.
  388. */
  389. if (boot_cpu_data.icache.flags & SH_CACHE_COMBINED) {
  390. seq_printf(m, "unified\n");
  391. show_cacheinfo(m, "cache", boot_cpu_data.icache);
  392. } else {
  393. seq_printf(m, "split (harvard)\n");
  394. show_cacheinfo(m, "icache", boot_cpu_data.icache);
  395. show_cacheinfo(m, "dcache", boot_cpu_data.dcache);
  396. }
  397. /* Optional secondary cache */
  398. if (boot_cpu_data.flags & CPU_HAS_L2_CACHE)
  399. show_cacheinfo(m, "scache", boot_cpu_data.scache);
  400. seq_printf(m, "bogomips\t: %lu.%02lu\n",
  401. boot_cpu_data.loops_per_jiffy/(500000/HZ),
  402. (boot_cpu_data.loops_per_jiffy/(5000/HZ)) % 100);
  403. return show_clocks(m);
  404. }
  405. static void *c_start(struct seq_file *m, loff_t *pos)
  406. {
  407. return *pos < NR_CPUS ? cpu_data + *pos : NULL;
  408. }
  409. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  410. {
  411. ++*pos;
  412. return c_start(m, pos);
  413. }
  414. static void c_stop(struct seq_file *m, void *v)
  415. {
  416. }
  417. struct seq_operations cpuinfo_op = {
  418. .start = c_start,
  419. .next = c_next,
  420. .stop = c_stop,
  421. .show = show_cpuinfo,
  422. };
  423. #endif /* CONFIG_PROC_FS */
  424. #ifdef CONFIG_SH_KGDB
  425. /*
  426. * Parse command-line kgdb options. By default KGDB is enabled,
  427. * entered on error (or other action) using default serial info.
  428. * The command-line option can include a serial port specification
  429. * and an action to override default or configured behavior.
  430. */
  431. struct kgdb_sermap kgdb_sci_sermap =
  432. { "ttySC", 5, kgdb_sci_setup, NULL };
  433. struct kgdb_sermap *kgdb_serlist = &kgdb_sci_sermap;
  434. struct kgdb_sermap *kgdb_porttype = &kgdb_sci_sermap;
  435. void kgdb_register_sermap(struct kgdb_sermap *map)
  436. {
  437. struct kgdb_sermap *last;
  438. for (last = kgdb_serlist; last->next; last = last->next)
  439. ;
  440. last->next = map;
  441. if (!map->namelen) {
  442. map->namelen = strlen(map->name);
  443. }
  444. }
  445. static int __init kgdb_parse_options(char *options)
  446. {
  447. char c;
  448. int baud;
  449. /* Check for port spec (or use default) */
  450. /* Determine port type and instance */
  451. if (!memcmp(options, "tty", 3)) {
  452. struct kgdb_sermap *map = kgdb_serlist;
  453. while (map && memcmp(options, map->name, map->namelen))
  454. map = map->next;
  455. if (!map) {
  456. KGDB_PRINTK("unknown port spec in %s\n", options);
  457. return -1;
  458. }
  459. kgdb_porttype = map;
  460. kgdb_serial_setup = map->setup_fn;
  461. kgdb_portnum = options[map->namelen] - '0';
  462. options += map->namelen + 1;
  463. options = (*options == ',') ? options+1 : options;
  464. /* Read optional parameters (baud/parity/bits) */
  465. baud = simple_strtoul(options, &options, 10);
  466. if (baud != 0) {
  467. kgdb_baud = baud;
  468. c = toupper(*options);
  469. if (c == 'E' || c == 'O' || c == 'N') {
  470. kgdb_parity = c;
  471. options++;
  472. }
  473. c = *options;
  474. if (c == '7' || c == '8') {
  475. kgdb_bits = c;
  476. options++;
  477. }
  478. options = (*options == ',') ? options+1 : options;
  479. }
  480. }
  481. /* Check for action specification */
  482. if (!memcmp(options, "halt", 4)) {
  483. kgdb_halt = 1;
  484. options += 4;
  485. } else if (!memcmp(options, "disabled", 8)) {
  486. kgdb_enabled = 0;
  487. options += 8;
  488. }
  489. if (*options) {
  490. KGDB_PRINTK("ignored unknown options: %s\n", options);
  491. return 0;
  492. }
  493. return 1;
  494. }
  495. __setup("kgdb=", kgdb_parse_options);
  496. #endif /* CONFIG_SH_KGDB */