setup.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  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. * Copyright (C) 2014 - 2016 Cadence Design Systems Inc.
  11. *
  12. * Chris Zankel <chris@zankel.net>
  13. * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
  14. * Kevin Chea
  15. * Marc Gauthier<marc@tensilica.com> <marc@alumni.uwaterloo.ca>
  16. */
  17. #include <linux/errno.h>
  18. #include <linux/init.h>
  19. #include <linux/mm.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/screen_info.h>
  22. #include <linux/bootmem.h>
  23. #include <linux/kernel.h>
  24. #include <linux/percpu.h>
  25. #include <linux/cpu.h>
  26. #include <linux/of.h>
  27. #include <linux/of_fdt.h>
  28. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
  29. # include <linux/console.h>
  30. #endif
  31. #ifdef CONFIG_RTC
  32. # include <linux/timex.h>
  33. #endif
  34. #ifdef CONFIG_PROC_FS
  35. # include <linux/seq_file.h>
  36. #endif
  37. #include <asm/bootparam.h>
  38. #include <asm/mmu_context.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/processor.h>
  41. #include <asm/timex.h>
  42. #include <asm/platform.h>
  43. #include <asm/page.h>
  44. #include <asm/setup.h>
  45. #include <asm/param.h>
  46. #include <asm/traps.h>
  47. #include <asm/smp.h>
  48. #include <asm/sysmem.h>
  49. #include <platform/hardware.h>
  50. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
  51. struct screen_info screen_info = { 0, 24, 0, 0, 0, 80, 0, 0, 0, 24, 1, 16};
  52. #endif
  53. #ifdef CONFIG_BLK_DEV_FD
  54. extern struct fd_ops no_fd_ops;
  55. struct fd_ops *fd_ops;
  56. #endif
  57. extern struct rtc_ops no_rtc_ops;
  58. struct rtc_ops *rtc_ops;
  59. #ifdef CONFIG_BLK_DEV_INITRD
  60. extern unsigned long initrd_start;
  61. extern unsigned long initrd_end;
  62. int initrd_is_mapped = 0;
  63. extern int initrd_below_start_ok;
  64. #endif
  65. #ifdef CONFIG_OF
  66. void *dtb_start = __dtb_start;
  67. #endif
  68. unsigned char aux_device_present;
  69. extern unsigned long loops_per_jiffy;
  70. /* Command line specified as configuration option. */
  71. static char __initdata command_line[COMMAND_LINE_SIZE];
  72. #ifdef CONFIG_CMDLINE_BOOL
  73. static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
  74. #endif
  75. /*
  76. * Boot parameter parsing.
  77. *
  78. * The Xtensa port uses a list of variable-sized tags to pass data to
  79. * the kernel. The first tag must be a BP_TAG_FIRST tag for the list
  80. * to be recognised. The list is terminated with a zero-sized
  81. * BP_TAG_LAST tag.
  82. */
  83. typedef struct tagtable {
  84. u32 tag;
  85. int (*parse)(const bp_tag_t*);
  86. } tagtable_t;
  87. #define __tagtable(tag, fn) static tagtable_t __tagtable_##fn \
  88. __attribute__((used, section(".taglist"))) = { tag, fn }
  89. /* parse current tag */
  90. static int __init parse_tag_mem(const bp_tag_t *tag)
  91. {
  92. struct bp_meminfo *mi = (struct bp_meminfo *)(tag->data);
  93. if (mi->type != MEMORY_TYPE_CONVENTIONAL)
  94. return -1;
  95. return memblock_add(mi->start, mi->end - mi->start);
  96. }
  97. __tagtable(BP_TAG_MEMORY, parse_tag_mem);
  98. #ifdef CONFIG_BLK_DEV_INITRD
  99. static int __init parse_tag_initrd(const bp_tag_t* tag)
  100. {
  101. struct bp_meminfo *mi = (struct bp_meminfo *)(tag->data);
  102. initrd_start = (unsigned long)__va(mi->start);
  103. initrd_end = (unsigned long)__va(mi->end);
  104. return 0;
  105. }
  106. __tagtable(BP_TAG_INITRD, parse_tag_initrd);
  107. #endif /* CONFIG_BLK_DEV_INITRD */
  108. #ifdef CONFIG_OF
  109. static int __init parse_tag_fdt(const bp_tag_t *tag)
  110. {
  111. dtb_start = __va(tag->data[0]);
  112. return 0;
  113. }
  114. __tagtable(BP_TAG_FDT, parse_tag_fdt);
  115. #endif /* CONFIG_OF */
  116. static int __init parse_tag_cmdline(const bp_tag_t* tag)
  117. {
  118. strlcpy(command_line, (char *)(tag->data), COMMAND_LINE_SIZE);
  119. return 0;
  120. }
  121. __tagtable(BP_TAG_COMMAND_LINE, parse_tag_cmdline);
  122. static int __init parse_bootparam(const bp_tag_t* tag)
  123. {
  124. extern tagtable_t __tagtable_begin, __tagtable_end;
  125. tagtable_t *t;
  126. /* Boot parameters must start with a BP_TAG_FIRST tag. */
  127. if (tag->id != BP_TAG_FIRST) {
  128. printk(KERN_WARNING "Invalid boot parameters!\n");
  129. return 0;
  130. }
  131. tag = (bp_tag_t*)((unsigned long)tag + sizeof(bp_tag_t) + tag->size);
  132. /* Parse all tags. */
  133. while (tag != NULL && tag->id != BP_TAG_LAST) {
  134. for (t = &__tagtable_begin; t < &__tagtable_end; t++) {
  135. if (tag->id == t->tag) {
  136. t->parse(tag);
  137. break;
  138. }
  139. }
  140. if (t == &__tagtable_end)
  141. printk(KERN_WARNING "Ignoring tag "
  142. "0x%08x\n", tag->id);
  143. tag = (bp_tag_t*)((unsigned long)(tag + 1) + tag->size);
  144. }
  145. return 0;
  146. }
  147. #ifdef CONFIG_OF
  148. #if !XCHAL_HAVE_PTP_MMU || XCHAL_HAVE_SPANNING_WAY
  149. unsigned long xtensa_kio_paddr = XCHAL_KIO_DEFAULT_PADDR;
  150. EXPORT_SYMBOL(xtensa_kio_paddr);
  151. static int __init xtensa_dt_io_area(unsigned long node, const char *uname,
  152. int depth, void *data)
  153. {
  154. const __be32 *ranges;
  155. int len;
  156. if (depth > 1)
  157. return 0;
  158. if (!of_flat_dt_is_compatible(node, "simple-bus"))
  159. return 0;
  160. ranges = of_get_flat_dt_prop(node, "ranges", &len);
  161. if (!ranges)
  162. return 1;
  163. if (len == 0)
  164. return 1;
  165. xtensa_kio_paddr = of_read_ulong(ranges+1, 1);
  166. /* round down to nearest 256MB boundary */
  167. xtensa_kio_paddr &= 0xf0000000;
  168. return 1;
  169. }
  170. #else
  171. static int __init xtensa_dt_io_area(unsigned long node, const char *uname,
  172. int depth, void *data)
  173. {
  174. return 1;
  175. }
  176. #endif
  177. void __init early_init_dt_add_memory_arch(u64 base, u64 size)
  178. {
  179. size &= PAGE_MASK;
  180. memblock_add(base, size);
  181. }
  182. void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
  183. {
  184. return __alloc_bootmem(size, align, 0);
  185. }
  186. void __init early_init_devtree(void *params)
  187. {
  188. early_init_dt_scan(params);
  189. of_scan_flat_dt(xtensa_dt_io_area, NULL);
  190. if (!command_line[0])
  191. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  192. }
  193. #endif /* CONFIG_OF */
  194. /*
  195. * Initialize architecture. (Early stage)
  196. */
  197. void __init init_arch(bp_tag_t *bp_start)
  198. {
  199. /* Parse boot parameters */
  200. if (bp_start)
  201. parse_bootparam(bp_start);
  202. #ifdef CONFIG_OF
  203. early_init_devtree(dtb_start);
  204. #endif
  205. #ifdef CONFIG_CMDLINE_BOOL
  206. if (!command_line[0])
  207. strlcpy(command_line, default_command_line, COMMAND_LINE_SIZE);
  208. #endif
  209. /* Early hook for platforms */
  210. platform_init(bp_start);
  211. /* Initialize MMU. */
  212. init_mmu();
  213. }
  214. /*
  215. * Initialize system. Setup memory and reserve regions.
  216. */
  217. extern char _end;
  218. extern char _stext;
  219. extern char _WindowVectors_text_start;
  220. extern char _WindowVectors_text_end;
  221. extern char _DebugInterruptVector_literal_start;
  222. extern char _DebugInterruptVector_text_end;
  223. extern char _KernelExceptionVector_literal_start;
  224. extern char _KernelExceptionVector_text_end;
  225. extern char _UserExceptionVector_literal_start;
  226. extern char _UserExceptionVector_text_end;
  227. extern char _DoubleExceptionVector_literal_start;
  228. extern char _DoubleExceptionVector_text_end;
  229. #if XCHAL_EXCM_LEVEL >= 2
  230. extern char _Level2InterruptVector_text_start;
  231. extern char _Level2InterruptVector_text_end;
  232. #endif
  233. #if XCHAL_EXCM_LEVEL >= 3
  234. extern char _Level3InterruptVector_text_start;
  235. extern char _Level3InterruptVector_text_end;
  236. #endif
  237. #if XCHAL_EXCM_LEVEL >= 4
  238. extern char _Level4InterruptVector_text_start;
  239. extern char _Level4InterruptVector_text_end;
  240. #endif
  241. #if XCHAL_EXCM_LEVEL >= 5
  242. extern char _Level5InterruptVector_text_start;
  243. extern char _Level5InterruptVector_text_end;
  244. #endif
  245. #if XCHAL_EXCM_LEVEL >= 6
  246. extern char _Level6InterruptVector_text_start;
  247. extern char _Level6InterruptVector_text_end;
  248. #endif
  249. #ifdef CONFIG_SMP
  250. extern char _SecondaryResetVector_text_start;
  251. extern char _SecondaryResetVector_text_end;
  252. #endif
  253. #ifdef CONFIG_S32C1I_SELFTEST
  254. #if XCHAL_HAVE_S32C1I
  255. static int __initdata rcw_word, rcw_probe_pc, rcw_exc;
  256. /*
  257. * Basic atomic compare-and-swap, that records PC of S32C1I for probing.
  258. *
  259. * If *v == cmp, set *v = set. Return previous *v.
  260. */
  261. static inline int probed_compare_swap(int *v, int cmp, int set)
  262. {
  263. int tmp;
  264. __asm__ __volatile__(
  265. " movi %1, 1f\n"
  266. " s32i %1, %4, 0\n"
  267. " wsr %2, scompare1\n"
  268. "1: s32c1i %0, %3, 0\n"
  269. : "=a" (set), "=&a" (tmp)
  270. : "a" (cmp), "a" (v), "a" (&rcw_probe_pc), "0" (set)
  271. : "memory"
  272. );
  273. return set;
  274. }
  275. /* Handle probed exception */
  276. static void __init do_probed_exception(struct pt_regs *regs,
  277. unsigned long exccause)
  278. {
  279. if (regs->pc == rcw_probe_pc) { /* exception on s32c1i ? */
  280. regs->pc += 3; /* skip the s32c1i instruction */
  281. rcw_exc = exccause;
  282. } else {
  283. do_unhandled(regs, exccause);
  284. }
  285. }
  286. /* Simple test of S32C1I (soc bringup assist) */
  287. static int __init check_s32c1i(void)
  288. {
  289. int n, cause1, cause2;
  290. void *handbus, *handdata, *handaddr; /* temporarily saved handlers */
  291. rcw_probe_pc = 0;
  292. handbus = trap_set_handler(EXCCAUSE_LOAD_STORE_ERROR,
  293. do_probed_exception);
  294. handdata = trap_set_handler(EXCCAUSE_LOAD_STORE_DATA_ERROR,
  295. do_probed_exception);
  296. handaddr = trap_set_handler(EXCCAUSE_LOAD_STORE_ADDR_ERROR,
  297. do_probed_exception);
  298. /* First try an S32C1I that does not store: */
  299. rcw_exc = 0;
  300. rcw_word = 1;
  301. n = probed_compare_swap(&rcw_word, 0, 2);
  302. cause1 = rcw_exc;
  303. /* took exception? */
  304. if (cause1 != 0) {
  305. /* unclean exception? */
  306. if (n != 2 || rcw_word != 1)
  307. panic("S32C1I exception error");
  308. } else if (rcw_word != 1 || n != 1) {
  309. panic("S32C1I compare error");
  310. }
  311. /* Then an S32C1I that stores: */
  312. rcw_exc = 0;
  313. rcw_word = 0x1234567;
  314. n = probed_compare_swap(&rcw_word, 0x1234567, 0xabcde);
  315. cause2 = rcw_exc;
  316. if (cause2 != 0) {
  317. /* unclean exception? */
  318. if (n != 0xabcde || rcw_word != 0x1234567)
  319. panic("S32C1I exception error (b)");
  320. } else if (rcw_word != 0xabcde || n != 0x1234567) {
  321. panic("S32C1I store error");
  322. }
  323. /* Verify consistency of exceptions: */
  324. if (cause1 || cause2) {
  325. pr_warn("S32C1I took exception %d, %d\n", cause1, cause2);
  326. /* If emulation of S32C1I upon bus error gets implemented,
  327. we can get rid of this panic for single core (not SMP) */
  328. panic("S32C1I exceptions not currently supported");
  329. }
  330. if (cause1 != cause2)
  331. panic("inconsistent S32C1I exceptions");
  332. trap_set_handler(EXCCAUSE_LOAD_STORE_ERROR, handbus);
  333. trap_set_handler(EXCCAUSE_LOAD_STORE_DATA_ERROR, handdata);
  334. trap_set_handler(EXCCAUSE_LOAD_STORE_ADDR_ERROR, handaddr);
  335. return 0;
  336. }
  337. #else /* XCHAL_HAVE_S32C1I */
  338. /* This condition should not occur with a commercially deployed processor.
  339. Display reminder for early engr test or demo chips / FPGA bitstreams */
  340. static int __init check_s32c1i(void)
  341. {
  342. pr_warn("Processor configuration lacks atomic compare-and-swap support!\n");
  343. return 0;
  344. }
  345. #endif /* XCHAL_HAVE_S32C1I */
  346. early_initcall(check_s32c1i);
  347. #endif /* CONFIG_S32C1I_SELFTEST */
  348. static inline int mem_reserve(unsigned long start, unsigned long end)
  349. {
  350. return memblock_reserve(start, end - start);
  351. }
  352. void __init setup_arch(char **cmdline_p)
  353. {
  354. strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  355. *cmdline_p = command_line;
  356. /* Reserve some memory regions */
  357. #ifdef CONFIG_BLK_DEV_INITRD
  358. if (initrd_start < initrd_end) {
  359. initrd_is_mapped = mem_reserve(__pa(initrd_start),
  360. __pa(initrd_end)) == 0;
  361. initrd_below_start_ok = 1;
  362. } else {
  363. initrd_start = 0;
  364. }
  365. #endif
  366. mem_reserve(__pa(&_stext), __pa(&_end));
  367. mem_reserve(__pa(&_WindowVectors_text_start),
  368. __pa(&_WindowVectors_text_end));
  369. mem_reserve(__pa(&_DebugInterruptVector_literal_start),
  370. __pa(&_DebugInterruptVector_text_end));
  371. mem_reserve(__pa(&_KernelExceptionVector_literal_start),
  372. __pa(&_KernelExceptionVector_text_end));
  373. mem_reserve(__pa(&_UserExceptionVector_literal_start),
  374. __pa(&_UserExceptionVector_text_end));
  375. mem_reserve(__pa(&_DoubleExceptionVector_literal_start),
  376. __pa(&_DoubleExceptionVector_text_end));
  377. #if XCHAL_EXCM_LEVEL >= 2
  378. mem_reserve(__pa(&_Level2InterruptVector_text_start),
  379. __pa(&_Level2InterruptVector_text_end));
  380. #endif
  381. #if XCHAL_EXCM_LEVEL >= 3
  382. mem_reserve(__pa(&_Level3InterruptVector_text_start),
  383. __pa(&_Level3InterruptVector_text_end));
  384. #endif
  385. #if XCHAL_EXCM_LEVEL >= 4
  386. mem_reserve(__pa(&_Level4InterruptVector_text_start),
  387. __pa(&_Level4InterruptVector_text_end));
  388. #endif
  389. #if XCHAL_EXCM_LEVEL >= 5
  390. mem_reserve(__pa(&_Level5InterruptVector_text_start),
  391. __pa(&_Level5InterruptVector_text_end));
  392. #endif
  393. #if XCHAL_EXCM_LEVEL >= 6
  394. mem_reserve(__pa(&_Level6InterruptVector_text_start),
  395. __pa(&_Level6InterruptVector_text_end));
  396. #endif
  397. #ifdef CONFIG_SMP
  398. mem_reserve(__pa(&_SecondaryResetVector_text_start),
  399. __pa(&_SecondaryResetVector_text_end));
  400. #endif
  401. parse_early_param();
  402. bootmem_init();
  403. unflatten_and_copy_device_tree();
  404. platform_setup(cmdline_p);
  405. #ifdef CONFIG_SMP
  406. smp_init_cpus();
  407. #endif
  408. paging_init();
  409. zones_init();
  410. #ifdef CONFIG_VT
  411. # if defined(CONFIG_VGA_CONSOLE)
  412. conswitchp = &vga_con;
  413. # elif defined(CONFIG_DUMMY_CONSOLE)
  414. conswitchp = &dummy_con;
  415. # endif
  416. #endif
  417. #ifdef CONFIG_PCI
  418. platform_pcibios_init();
  419. #endif
  420. }
  421. static DEFINE_PER_CPU(struct cpu, cpu_data);
  422. static int __init topology_init(void)
  423. {
  424. int i;
  425. for_each_possible_cpu(i) {
  426. struct cpu *cpu = &per_cpu(cpu_data, i);
  427. cpu->hotpluggable = !!i;
  428. register_cpu(cpu, i);
  429. }
  430. return 0;
  431. }
  432. subsys_initcall(topology_init);
  433. void cpu_reset(void)
  434. {
  435. #if XCHAL_HAVE_PTP_MMU && IS_ENABLED(CONFIG_MMU)
  436. local_irq_disable();
  437. /*
  438. * We have full MMU: all autoload ways, ways 7, 8 and 9 of DTLB must
  439. * be flushed.
  440. * Way 4 is not currently used by linux.
  441. * Ways 5 and 6 shall not be touched on MMUv2 as they are hardwired.
  442. * Way 5 shall be flushed and way 6 shall be set to identity mapping
  443. * on MMUv3.
  444. */
  445. local_flush_tlb_all();
  446. invalidate_page_directory();
  447. #if XCHAL_HAVE_SPANNING_WAY
  448. /* MMU v3 */
  449. {
  450. unsigned long vaddr = (unsigned long)cpu_reset;
  451. unsigned long paddr = __pa(vaddr);
  452. unsigned long tmpaddr = vaddr + SZ_512M;
  453. unsigned long tmp0, tmp1, tmp2, tmp3;
  454. /*
  455. * Find a place for the temporary mapping. It must not be
  456. * in the same 512MB region with vaddr or paddr, otherwise
  457. * there may be multihit exception either on entry to the
  458. * temporary mapping, or on entry to the identity mapping.
  459. * (512MB is the biggest page size supported by TLB.)
  460. */
  461. while (((tmpaddr ^ paddr) & -SZ_512M) == 0)
  462. tmpaddr += SZ_512M;
  463. /* Invalidate mapping in the selected temporary area */
  464. if (itlb_probe(tmpaddr) & 0x8)
  465. invalidate_itlb_entry(itlb_probe(tmpaddr));
  466. if (itlb_probe(tmpaddr + PAGE_SIZE) & 0x8)
  467. invalidate_itlb_entry(itlb_probe(tmpaddr + PAGE_SIZE));
  468. /*
  469. * Map two consecutive pages starting at the physical address
  470. * of this function to the temporary mapping area.
  471. */
  472. write_itlb_entry(__pte((paddr & PAGE_MASK) |
  473. _PAGE_HW_VALID |
  474. _PAGE_HW_EXEC |
  475. _PAGE_CA_BYPASS),
  476. tmpaddr & PAGE_MASK);
  477. write_itlb_entry(__pte(((paddr & PAGE_MASK) + PAGE_SIZE) |
  478. _PAGE_HW_VALID |
  479. _PAGE_HW_EXEC |
  480. _PAGE_CA_BYPASS),
  481. (tmpaddr & PAGE_MASK) + PAGE_SIZE);
  482. /* Reinitialize TLB */
  483. __asm__ __volatile__ ("movi %0, 1f\n\t"
  484. "movi %3, 2f\n\t"
  485. "add %0, %0, %4\n\t"
  486. "add %3, %3, %5\n\t"
  487. "jx %0\n"
  488. /*
  489. * No literal, data or stack access
  490. * below this point
  491. */
  492. "1:\n\t"
  493. /* Initialize *tlbcfg */
  494. "movi %0, 0\n\t"
  495. "wsr %0, itlbcfg\n\t"
  496. "wsr %0, dtlbcfg\n\t"
  497. /* Invalidate TLB way 5 */
  498. "movi %0, 4\n\t"
  499. "movi %1, 5\n"
  500. "1:\n\t"
  501. "iitlb %1\n\t"
  502. "idtlb %1\n\t"
  503. "add %1, %1, %6\n\t"
  504. "addi %0, %0, -1\n\t"
  505. "bnez %0, 1b\n\t"
  506. /* Initialize TLB way 6 */
  507. "movi %0, 7\n\t"
  508. "addi %1, %9, 3\n\t"
  509. "addi %2, %9, 6\n"
  510. "1:\n\t"
  511. "witlb %1, %2\n\t"
  512. "wdtlb %1, %2\n\t"
  513. "add %1, %1, %7\n\t"
  514. "add %2, %2, %7\n\t"
  515. "addi %0, %0, -1\n\t"
  516. "bnez %0, 1b\n\t"
  517. /* Jump to identity mapping */
  518. "jx %3\n"
  519. "2:\n\t"
  520. /* Complete way 6 initialization */
  521. "witlb %1, %2\n\t"
  522. "wdtlb %1, %2\n\t"
  523. /* Invalidate temporary mapping */
  524. "sub %0, %9, %7\n\t"
  525. "iitlb %0\n\t"
  526. "add %0, %0, %8\n\t"
  527. "iitlb %0"
  528. : "=&a"(tmp0), "=&a"(tmp1), "=&a"(tmp2),
  529. "=&a"(tmp3)
  530. : "a"(tmpaddr - vaddr),
  531. "a"(paddr - vaddr),
  532. "a"(SZ_128M), "a"(SZ_512M),
  533. "a"(PAGE_SIZE),
  534. "a"((tmpaddr + SZ_512M) & PAGE_MASK)
  535. : "memory");
  536. }
  537. #endif
  538. #endif
  539. __asm__ __volatile__ ("movi a2, 0\n\t"
  540. "wsr a2, icountlevel\n\t"
  541. "movi a2, 0\n\t"
  542. "wsr a2, icount\n\t"
  543. #if XCHAL_NUM_IBREAK > 0
  544. "wsr a2, ibreakenable\n\t"
  545. #endif
  546. #if XCHAL_HAVE_LOOPS
  547. "wsr a2, lcount\n\t"
  548. #endif
  549. "movi a2, 0x1f\n\t"
  550. "wsr a2, ps\n\t"
  551. "isync\n\t"
  552. "jx %0\n\t"
  553. :
  554. : "a" (XCHAL_RESET_VECTOR_VADDR)
  555. : "a2");
  556. for (;;)
  557. ;
  558. }
  559. void machine_restart(char * cmd)
  560. {
  561. platform_restart();
  562. }
  563. void machine_halt(void)
  564. {
  565. platform_halt();
  566. while (1);
  567. }
  568. void machine_power_off(void)
  569. {
  570. platform_power_off();
  571. while (1);
  572. }
  573. #ifdef CONFIG_PROC_FS
  574. /*
  575. * Display some core information through /proc/cpuinfo.
  576. */
  577. static int
  578. c_show(struct seq_file *f, void *slot)
  579. {
  580. /* high-level stuff */
  581. seq_printf(f, "CPU count\t: %u\n"
  582. "CPU list\t: %*pbl\n"
  583. "vendor_id\t: Tensilica\n"
  584. "model\t\t: Xtensa " XCHAL_HW_VERSION_NAME "\n"
  585. "core ID\t\t: " XCHAL_CORE_ID "\n"
  586. "build ID\t: 0x%x\n"
  587. "byte order\t: %s\n"
  588. "cpu MHz\t\t: %lu.%02lu\n"
  589. "bogomips\t: %lu.%02lu\n",
  590. num_online_cpus(),
  591. cpumask_pr_args(cpu_online_mask),
  592. XCHAL_BUILD_UNIQUE_ID,
  593. XCHAL_HAVE_BE ? "big" : "little",
  594. ccount_freq/1000000,
  595. (ccount_freq/10000) % 100,
  596. loops_per_jiffy/(500000/HZ),
  597. (loops_per_jiffy/(5000/HZ)) % 100);
  598. seq_printf(f,"flags\t\t: "
  599. #if XCHAL_HAVE_NMI
  600. "nmi "
  601. #endif
  602. #if XCHAL_HAVE_DEBUG
  603. "debug "
  604. # if XCHAL_HAVE_OCD
  605. "ocd "
  606. # endif
  607. #endif
  608. #if XCHAL_HAVE_DENSITY
  609. "density "
  610. #endif
  611. #if XCHAL_HAVE_BOOLEANS
  612. "boolean "
  613. #endif
  614. #if XCHAL_HAVE_LOOPS
  615. "loop "
  616. #endif
  617. #if XCHAL_HAVE_NSA
  618. "nsa "
  619. #endif
  620. #if XCHAL_HAVE_MINMAX
  621. "minmax "
  622. #endif
  623. #if XCHAL_HAVE_SEXT
  624. "sext "
  625. #endif
  626. #if XCHAL_HAVE_CLAMPS
  627. "clamps "
  628. #endif
  629. #if XCHAL_HAVE_MAC16
  630. "mac16 "
  631. #endif
  632. #if XCHAL_HAVE_MUL16
  633. "mul16 "
  634. #endif
  635. #if XCHAL_HAVE_MUL32
  636. "mul32 "
  637. #endif
  638. #if XCHAL_HAVE_MUL32_HIGH
  639. "mul32h "
  640. #endif
  641. #if XCHAL_HAVE_FP
  642. "fpu "
  643. #endif
  644. #if XCHAL_HAVE_S32C1I
  645. "s32c1i "
  646. #endif
  647. "\n");
  648. /* Registers. */
  649. seq_printf(f,"physical aregs\t: %d\n"
  650. "misc regs\t: %d\n"
  651. "ibreak\t\t: %d\n"
  652. "dbreak\t\t: %d\n",
  653. XCHAL_NUM_AREGS,
  654. XCHAL_NUM_MISC_REGS,
  655. XCHAL_NUM_IBREAK,
  656. XCHAL_NUM_DBREAK);
  657. /* Interrupt. */
  658. seq_printf(f,"num ints\t: %d\n"
  659. "ext ints\t: %d\n"
  660. "int levels\t: %d\n"
  661. "timers\t\t: %d\n"
  662. "debug level\t: %d\n",
  663. XCHAL_NUM_INTERRUPTS,
  664. XCHAL_NUM_EXTINTERRUPTS,
  665. XCHAL_NUM_INTLEVELS,
  666. XCHAL_NUM_TIMERS,
  667. XCHAL_DEBUGLEVEL);
  668. /* Cache */
  669. seq_printf(f,"icache line size: %d\n"
  670. "icache ways\t: %d\n"
  671. "icache size\t: %d\n"
  672. "icache flags\t: "
  673. #if XCHAL_ICACHE_LINE_LOCKABLE
  674. "lock "
  675. #endif
  676. "\n"
  677. "dcache line size: %d\n"
  678. "dcache ways\t: %d\n"
  679. "dcache size\t: %d\n"
  680. "dcache flags\t: "
  681. #if XCHAL_DCACHE_IS_WRITEBACK
  682. "writeback "
  683. #endif
  684. #if XCHAL_DCACHE_LINE_LOCKABLE
  685. "lock "
  686. #endif
  687. "\n",
  688. XCHAL_ICACHE_LINESIZE,
  689. XCHAL_ICACHE_WAYS,
  690. XCHAL_ICACHE_SIZE,
  691. XCHAL_DCACHE_LINESIZE,
  692. XCHAL_DCACHE_WAYS,
  693. XCHAL_DCACHE_SIZE);
  694. return 0;
  695. }
  696. /*
  697. * We show only CPU #0 info.
  698. */
  699. static void *
  700. c_start(struct seq_file *f, loff_t *pos)
  701. {
  702. return (*pos == 0) ? (void *)1 : NULL;
  703. }
  704. static void *
  705. c_next(struct seq_file *f, void *v, loff_t *pos)
  706. {
  707. return NULL;
  708. }
  709. static void
  710. c_stop(struct seq_file *f, void *v)
  711. {
  712. }
  713. const struct seq_operations cpuinfo_op =
  714. {
  715. .start = c_start,
  716. .next = c_next,
  717. .stop = c_stop,
  718. .show = c_show,
  719. };
  720. #endif /* CONFIG_PROC_FS */