setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /*
  2. * arch/xtensa/kernel/setup.c
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 1995 Linus Torvalds
  9. * Copyright (C) 2001 - 2005 Tensilica Inc.
  10. *
  11. * Chris Zankel <chris@zankel.net>
  12. * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
  13. * Kevin Chea
  14. * Marc Gauthier<marc@tensilica.com> <marc@alumni.uwaterloo.ca>
  15. */
  16. #include <linux/errno.h>
  17. #include <linux/init.h>
  18. #include <linux/mm.h>
  19. #include <linux/proc_fs.h>
  20. #include <linux/screen_info.h>
  21. #include <linux/bootmem.h>
  22. #include <linux/kernel.h>
  23. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
  24. # include <linux/console.h>
  25. #endif
  26. #ifdef CONFIG_RTC
  27. # include <linux/timex.h>
  28. #endif
  29. #ifdef CONFIG_PROC_FS
  30. # include <linux/seq_file.h>
  31. #endif
  32. #include <asm/bootparam.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/processor.h>
  35. #include <asm/timex.h>
  36. #include <asm/platform.h>
  37. #include <asm/page.h>
  38. #include <asm/setup.h>
  39. #include <asm/param.h>
  40. #include <asm/traps.h>
  41. #include <platform/hardware.h>
  42. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
  43. struct screen_info screen_info = { 0, 24, 0, 0, 0, 80, 0, 0, 0, 24, 1, 16};
  44. #endif
  45. #ifdef CONFIG_BLK_DEV_FD
  46. extern struct fd_ops no_fd_ops;
  47. struct fd_ops *fd_ops;
  48. #endif
  49. extern struct rtc_ops no_rtc_ops;
  50. struct rtc_ops *rtc_ops;
  51. #ifdef CONFIG_BLK_DEV_INITRD
  52. extern void *initrd_start;
  53. extern void *initrd_end;
  54. int initrd_is_mapped = 0;
  55. extern int initrd_below_start_ok;
  56. #endif
  57. unsigned char aux_device_present;
  58. extern unsigned long loops_per_jiffy;
  59. /* Command line specified as configuration option. */
  60. static char __initdata command_line[COMMAND_LINE_SIZE];
  61. #ifdef CONFIG_CMDLINE_BOOL
  62. static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
  63. #endif
  64. sysmem_info_t __initdata sysmem;
  65. #ifdef CONFIG_MMU
  66. extern void init_mmu(void);
  67. #else
  68. static inline void init_mmu(void) { }
  69. #endif
  70. extern void zones_init(void);
  71. /*
  72. * Boot parameter parsing.
  73. *
  74. * The Xtensa port uses a list of variable-sized tags to pass data to
  75. * the kernel. The first tag must be a BP_TAG_FIRST tag for the list
  76. * to be recognised. The list is terminated with a zero-sized
  77. * BP_TAG_LAST tag.
  78. */
  79. typedef struct tagtable {
  80. u32 tag;
  81. int (*parse)(const bp_tag_t*);
  82. } tagtable_t;
  83. #define __tagtable(tag, fn) static tagtable_t __tagtable_##fn \
  84. __attribute__((used, section(".taglist"))) = { tag, fn }
  85. /* parse current tag */
  86. static int __init parse_tag_mem(const bp_tag_t *tag)
  87. {
  88. meminfo_t *mi = (meminfo_t*)(tag->data);
  89. if (mi->type != MEMORY_TYPE_CONVENTIONAL)
  90. return -1;
  91. if (sysmem.nr_banks >= SYSMEM_BANKS_MAX) {
  92. printk(KERN_WARNING
  93. "Ignoring memory bank 0x%08lx size %ldKB\n",
  94. (unsigned long)mi->start,
  95. (unsigned long)mi->end - (unsigned long)mi->start);
  96. return -EINVAL;
  97. }
  98. sysmem.bank[sysmem.nr_banks].type = mi->type;
  99. sysmem.bank[sysmem.nr_banks].start = PAGE_ALIGN(mi->start);
  100. sysmem.bank[sysmem.nr_banks].end = mi->end & PAGE_MASK;
  101. sysmem.nr_banks++;
  102. return 0;
  103. }
  104. __tagtable(BP_TAG_MEMORY, parse_tag_mem);
  105. #ifdef CONFIG_BLK_DEV_INITRD
  106. static int __init parse_tag_initrd(const bp_tag_t* tag)
  107. {
  108. meminfo_t* mi;
  109. mi = (meminfo_t*)(tag->data);
  110. initrd_start = (void*)(mi->start);
  111. initrd_end = (void*)(mi->end);
  112. return 0;
  113. }
  114. __tagtable(BP_TAG_INITRD, parse_tag_initrd);
  115. #endif /* CONFIG_BLK_DEV_INITRD */
  116. static int __init parse_tag_cmdline(const bp_tag_t* tag)
  117. {
  118. strncpy(command_line, (char*)(tag->data), COMMAND_LINE_SIZE);
  119. command_line[COMMAND_LINE_SIZE - 1] = '\0';
  120. return 0;
  121. }
  122. __tagtable(BP_TAG_COMMAND_LINE, parse_tag_cmdline);
  123. static int __init parse_bootparam(const bp_tag_t* tag)
  124. {
  125. extern tagtable_t __tagtable_begin, __tagtable_end;
  126. tagtable_t *t;
  127. /* Boot parameters must start with a BP_TAG_FIRST tag. */
  128. if (tag->id != BP_TAG_FIRST) {
  129. printk(KERN_WARNING "Invalid boot parameters!\n");
  130. return 0;
  131. }
  132. tag = (bp_tag_t*)((unsigned long)tag + sizeof(bp_tag_t) + tag->size);
  133. /* Parse all tags. */
  134. while (tag != NULL && tag->id != BP_TAG_LAST) {
  135. for (t = &__tagtable_begin; t < &__tagtable_end; t++) {
  136. if (tag->id == t->tag) {
  137. t->parse(tag);
  138. break;
  139. }
  140. }
  141. if (t == &__tagtable_end)
  142. printk(KERN_WARNING "Ignoring tag "
  143. "0x%08x\n", tag->id);
  144. tag = (bp_tag_t*)((unsigned long)(tag + 1) + tag->size);
  145. }
  146. return 0;
  147. }
  148. /*
  149. * Initialize architecture. (Early stage)
  150. */
  151. void __init init_arch(bp_tag_t *bp_start)
  152. {
  153. sysmem.nr_banks = 0;
  154. #ifdef CONFIG_CMDLINE_BOOL
  155. strcpy(command_line, default_command_line);
  156. #endif
  157. /* Parse boot parameters */
  158. if (bp_start)
  159. parse_bootparam(bp_start);
  160. if (sysmem.nr_banks == 0) {
  161. sysmem.nr_banks = 1;
  162. sysmem.bank[0].start = PLATFORM_DEFAULT_MEM_START;
  163. sysmem.bank[0].end = PLATFORM_DEFAULT_MEM_START
  164. + PLATFORM_DEFAULT_MEM_SIZE;
  165. }
  166. /* Early hook for platforms */
  167. platform_init(bp_start);
  168. /* Initialize MMU. */
  169. init_mmu();
  170. }
  171. /*
  172. * Initialize system. Setup memory and reserve regions.
  173. */
  174. extern char _end;
  175. extern char _stext;
  176. extern char _WindowVectors_text_start;
  177. extern char _WindowVectors_text_end;
  178. extern char _DebugInterruptVector_literal_start;
  179. extern char _DebugInterruptVector_text_end;
  180. extern char _KernelExceptionVector_literal_start;
  181. extern char _KernelExceptionVector_text_end;
  182. extern char _UserExceptionVector_literal_start;
  183. extern char _UserExceptionVector_text_end;
  184. extern char _DoubleExceptionVector_literal_start;
  185. extern char _DoubleExceptionVector_text_end;
  186. #ifdef CONFIG_S32C1I_SELFTEST
  187. #if XCHAL_HAVE_S32C1I
  188. static int __initdata rcw_word, rcw_probe_pc, rcw_exc;
  189. /*
  190. * Basic atomic compare-and-swap, that records PC of S32C1I for probing.
  191. *
  192. * If *v == cmp, set *v = set. Return previous *v.
  193. */
  194. static inline int probed_compare_swap(int *v, int cmp, int set)
  195. {
  196. int tmp;
  197. __asm__ __volatile__(
  198. " movi %1, 1f\n"
  199. " s32i %1, %4, 0\n"
  200. " wsr %2, scompare1\n"
  201. "1: s32c1i %0, %3, 0\n"
  202. : "=a" (set), "=&a" (tmp)
  203. : "a" (cmp), "a" (v), "a" (&rcw_probe_pc), "0" (set)
  204. : "memory"
  205. );
  206. return set;
  207. }
  208. /* Handle probed exception */
  209. void __init do_probed_exception(struct pt_regs *regs, unsigned long exccause)
  210. {
  211. if (regs->pc == rcw_probe_pc) { /* exception on s32c1i ? */
  212. regs->pc += 3; /* skip the s32c1i instruction */
  213. rcw_exc = exccause;
  214. } else {
  215. do_unhandled(regs, exccause);
  216. }
  217. }
  218. /* Simple test of S32C1I (soc bringup assist) */
  219. void __init check_s32c1i(void)
  220. {
  221. int n, cause1, cause2;
  222. void *handbus, *handdata, *handaddr; /* temporarily saved handlers */
  223. rcw_probe_pc = 0;
  224. handbus = trap_set_handler(EXCCAUSE_LOAD_STORE_ERROR,
  225. do_probed_exception);
  226. handdata = trap_set_handler(EXCCAUSE_LOAD_STORE_DATA_ERROR,
  227. do_probed_exception);
  228. handaddr = trap_set_handler(EXCCAUSE_LOAD_STORE_ADDR_ERROR,
  229. do_probed_exception);
  230. /* First try an S32C1I that does not store: */
  231. rcw_exc = 0;
  232. rcw_word = 1;
  233. n = probed_compare_swap(&rcw_word, 0, 2);
  234. cause1 = rcw_exc;
  235. /* took exception? */
  236. if (cause1 != 0) {
  237. /* unclean exception? */
  238. if (n != 2 || rcw_word != 1)
  239. panic("S32C1I exception error");
  240. } else if (rcw_word != 1 || n != 1) {
  241. panic("S32C1I compare error");
  242. }
  243. /* Then an S32C1I that stores: */
  244. rcw_exc = 0;
  245. rcw_word = 0x1234567;
  246. n = probed_compare_swap(&rcw_word, 0x1234567, 0xabcde);
  247. cause2 = rcw_exc;
  248. if (cause2 != 0) {
  249. /* unclean exception? */
  250. if (n != 0xabcde || rcw_word != 0x1234567)
  251. panic("S32C1I exception error (b)");
  252. } else if (rcw_word != 0xabcde || n != 0x1234567) {
  253. panic("S32C1I store error");
  254. }
  255. /* Verify consistency of exceptions: */
  256. if (cause1 || cause2) {
  257. pr_warn("S32C1I took exception %d, %d\n", cause1, cause2);
  258. /* If emulation of S32C1I upon bus error gets implemented,
  259. we can get rid of this panic for single core (not SMP) */
  260. panic("S32C1I exceptions not currently supported");
  261. }
  262. if (cause1 != cause2)
  263. panic("inconsistent S32C1I exceptions");
  264. trap_set_handler(EXCCAUSE_LOAD_STORE_ERROR, handbus);
  265. trap_set_handler(EXCCAUSE_LOAD_STORE_DATA_ERROR, handdata);
  266. trap_set_handler(EXCCAUSE_LOAD_STORE_ADDR_ERROR, handaddr);
  267. }
  268. #else /* XCHAL_HAVE_S32C1I */
  269. /* This condition should not occur with a commercially deployed processor.
  270. Display reminder for early engr test or demo chips / FPGA bitstreams */
  271. void __init check_s32c1i(void)
  272. {
  273. pr_warn("Processor configuration lacks atomic compare-and-swap support!\n");
  274. }
  275. #endif /* XCHAL_HAVE_S32C1I */
  276. #else /* CONFIG_S32C1I_SELFTEST */
  277. void __init check_s32c1i(void)
  278. {
  279. }
  280. #endif /* CONFIG_S32C1I_SELFTEST */
  281. void __init setup_arch(char **cmdline_p)
  282. {
  283. extern int mem_reserve(unsigned long, unsigned long, int);
  284. extern void bootmem_init(void);
  285. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  286. boot_command_line[COMMAND_LINE_SIZE-1] = '\0';
  287. *cmdline_p = command_line;
  288. check_s32c1i();
  289. /* Reserve some memory regions */
  290. #ifdef CONFIG_BLK_DEV_INITRD
  291. if (initrd_start < initrd_end) {
  292. initrd_is_mapped = mem_reserve(__pa(initrd_start),
  293. __pa(initrd_end), 0);
  294. initrd_below_start_ok = 1;
  295. } else {
  296. initrd_start = 0;
  297. }
  298. #endif
  299. mem_reserve(__pa(&_stext),__pa(&_end), 1);
  300. mem_reserve(__pa(&_WindowVectors_text_start),
  301. __pa(&_WindowVectors_text_end), 0);
  302. mem_reserve(__pa(&_DebugInterruptVector_literal_start),
  303. __pa(&_DebugInterruptVector_text_end), 0);
  304. mem_reserve(__pa(&_KernelExceptionVector_literal_start),
  305. __pa(&_KernelExceptionVector_text_end), 0);
  306. mem_reserve(__pa(&_UserExceptionVector_literal_start),
  307. __pa(&_UserExceptionVector_text_end), 0);
  308. mem_reserve(__pa(&_DoubleExceptionVector_literal_start),
  309. __pa(&_DoubleExceptionVector_text_end), 0);
  310. bootmem_init();
  311. platform_setup(cmdline_p);
  312. paging_init();
  313. zones_init();
  314. #ifdef CONFIG_VT
  315. # if defined(CONFIG_VGA_CONSOLE)
  316. conswitchp = &vga_con;
  317. # elif defined(CONFIG_DUMMY_CONSOLE)
  318. conswitchp = &dummy_con;
  319. # endif
  320. #endif
  321. #ifdef CONFIG_PCI
  322. platform_pcibios_init();
  323. #endif
  324. }
  325. void machine_restart(char * cmd)
  326. {
  327. platform_restart();
  328. }
  329. void machine_halt(void)
  330. {
  331. platform_halt();
  332. while (1);
  333. }
  334. void machine_power_off(void)
  335. {
  336. platform_power_off();
  337. while (1);
  338. }
  339. #ifdef CONFIG_PROC_FS
  340. /*
  341. * Display some core information through /proc/cpuinfo.
  342. */
  343. static int
  344. c_show(struct seq_file *f, void *slot)
  345. {
  346. /* high-level stuff */
  347. seq_printf(f,"processor\t: 0\n"
  348. "vendor_id\t: Tensilica\n"
  349. "model\t\t: Xtensa " XCHAL_HW_VERSION_NAME "\n"
  350. "core ID\t\t: " XCHAL_CORE_ID "\n"
  351. "build ID\t: 0x%x\n"
  352. "byte order\t: %s\n"
  353. "cpu MHz\t\t: %lu.%02lu\n"
  354. "bogomips\t: %lu.%02lu\n",
  355. XCHAL_BUILD_UNIQUE_ID,
  356. XCHAL_HAVE_BE ? "big" : "little",
  357. CCOUNT_PER_JIFFY/(1000000/HZ),
  358. (CCOUNT_PER_JIFFY/(10000/HZ)) % 100,
  359. loops_per_jiffy/(500000/HZ),
  360. (loops_per_jiffy/(5000/HZ)) % 100);
  361. seq_printf(f,"flags\t\t: "
  362. #if XCHAL_HAVE_NMI
  363. "nmi "
  364. #endif
  365. #if XCHAL_HAVE_DEBUG
  366. "debug "
  367. # if XCHAL_HAVE_OCD
  368. "ocd "
  369. # endif
  370. #endif
  371. #if XCHAL_HAVE_DENSITY
  372. "density "
  373. #endif
  374. #if XCHAL_HAVE_BOOLEANS
  375. "boolean "
  376. #endif
  377. #if XCHAL_HAVE_LOOPS
  378. "loop "
  379. #endif
  380. #if XCHAL_HAVE_NSA
  381. "nsa "
  382. #endif
  383. #if XCHAL_HAVE_MINMAX
  384. "minmax "
  385. #endif
  386. #if XCHAL_HAVE_SEXT
  387. "sext "
  388. #endif
  389. #if XCHAL_HAVE_CLAMPS
  390. "clamps "
  391. #endif
  392. #if XCHAL_HAVE_MAC16
  393. "mac16 "
  394. #endif
  395. #if XCHAL_HAVE_MUL16
  396. "mul16 "
  397. #endif
  398. #if XCHAL_HAVE_MUL32
  399. "mul32 "
  400. #endif
  401. #if XCHAL_HAVE_MUL32_HIGH
  402. "mul32h "
  403. #endif
  404. #if XCHAL_HAVE_FP
  405. "fpu "
  406. #endif
  407. #if XCHAL_HAVE_S32C1I
  408. "s32c1i "
  409. #endif
  410. "\n");
  411. /* Registers. */
  412. seq_printf(f,"physical aregs\t: %d\n"
  413. "misc regs\t: %d\n"
  414. "ibreak\t\t: %d\n"
  415. "dbreak\t\t: %d\n",
  416. XCHAL_NUM_AREGS,
  417. XCHAL_NUM_MISC_REGS,
  418. XCHAL_NUM_IBREAK,
  419. XCHAL_NUM_DBREAK);
  420. /* Interrupt. */
  421. seq_printf(f,"num ints\t: %d\n"
  422. "ext ints\t: %d\n"
  423. "int levels\t: %d\n"
  424. "timers\t\t: %d\n"
  425. "debug level\t: %d\n",
  426. XCHAL_NUM_INTERRUPTS,
  427. XCHAL_NUM_EXTINTERRUPTS,
  428. XCHAL_NUM_INTLEVELS,
  429. XCHAL_NUM_TIMERS,
  430. XCHAL_DEBUGLEVEL);
  431. /* Cache */
  432. seq_printf(f,"icache line size: %d\n"
  433. "icache ways\t: %d\n"
  434. "icache size\t: %d\n"
  435. "icache flags\t: "
  436. #if XCHAL_ICACHE_LINE_LOCKABLE
  437. "lock "
  438. #endif
  439. "\n"
  440. "dcache line size: %d\n"
  441. "dcache ways\t: %d\n"
  442. "dcache size\t: %d\n"
  443. "dcache flags\t: "
  444. #if XCHAL_DCACHE_IS_WRITEBACK
  445. "writeback "
  446. #endif
  447. #if XCHAL_DCACHE_LINE_LOCKABLE
  448. "lock "
  449. #endif
  450. "\n",
  451. XCHAL_ICACHE_LINESIZE,
  452. XCHAL_ICACHE_WAYS,
  453. XCHAL_ICACHE_SIZE,
  454. XCHAL_DCACHE_LINESIZE,
  455. XCHAL_DCACHE_WAYS,
  456. XCHAL_DCACHE_SIZE);
  457. return 0;
  458. }
  459. /*
  460. * We show only CPU #0 info.
  461. */
  462. static void *
  463. c_start(struct seq_file *f, loff_t *pos)
  464. {
  465. return (void *) ((*pos == 0) ? (void *)1 : NULL);
  466. }
  467. static void *
  468. c_next(struct seq_file *f, void *v, loff_t *pos)
  469. {
  470. return NULL;
  471. }
  472. static void
  473. c_stop(struct seq_file *f, void *v)
  474. {
  475. }
  476. const struct seq_operations cpuinfo_op =
  477. {
  478. start: c_start,
  479. next: c_next,
  480. stop: c_stop,
  481. show: c_show
  482. };
  483. #endif /* CONFIG_PROC_FS */