setup.c 15 KB

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