setup.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. /*
  2. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/seq_file.h>
  9. #include <linux/fs.h>
  10. #include <linux/delay.h>
  11. #include <linux/root_dev.h>
  12. #include <linux/console.h>
  13. #include <linux/module.h>
  14. #include <linux/cpu.h>
  15. #include <linux/of_fdt.h>
  16. #include <linux/of.h>
  17. #include <linux/cache.h>
  18. #include <asm/sections.h>
  19. #include <asm/arcregs.h>
  20. #include <asm/tlb.h>
  21. #include <asm/setup.h>
  22. #include <asm/page.h>
  23. #include <asm/irq.h>
  24. #include <asm/unwind.h>
  25. #include <asm/mach_desc.h>
  26. #include <asm/smp.h>
  27. #define FIX_PTR(x) __asm__ __volatile__(";" : "+r"(x))
  28. unsigned int intr_to_DE_cnt;
  29. /* Part of U-boot ABI: see head.S */
  30. int __initdata uboot_tag;
  31. char __initdata *uboot_arg;
  32. const struct machine_desc *machine_desc;
  33. struct task_struct *_current_task[NR_CPUS]; /* For stack switching */
  34. struct cpuinfo_arc cpuinfo_arc700[NR_CPUS];
  35. static const struct id_to_str arc_cpu_rel[] = {
  36. #ifdef CONFIG_ISA_ARCOMPACT
  37. { 0x34, "R4.10"},
  38. { 0x35, "R4.11"},
  39. #else
  40. { 0x51, "R2.0" },
  41. { 0x52, "R2.1" },
  42. { 0x53, "R3.0" },
  43. #endif
  44. { 0x00, NULL }
  45. };
  46. static const struct id_to_str arc_cpu_nm[] = {
  47. #ifdef CONFIG_ISA_ARCOMPACT
  48. { 0x20, "ARC 600" },
  49. { 0x30, "ARC 770" }, /* 750 identified seperately */
  50. #else
  51. { 0x40, "ARC EM" },
  52. { 0x50, "ARC HS38" },
  53. #endif
  54. { 0x00, "Unknown" }
  55. };
  56. static void read_decode_ccm_bcr(struct cpuinfo_arc *cpu)
  57. {
  58. if (is_isa_arcompact()) {
  59. struct bcr_iccm_arcompact iccm;
  60. struct bcr_dccm_arcompact dccm;
  61. READ_BCR(ARC_REG_ICCM_BUILD, iccm);
  62. if (iccm.ver) {
  63. cpu->iccm.sz = 4096 << iccm.sz; /* 8K to 512K */
  64. cpu->iccm.base_addr = iccm.base << 16;
  65. }
  66. READ_BCR(ARC_REG_DCCM_BUILD, dccm);
  67. if (dccm.ver) {
  68. unsigned long base;
  69. cpu->dccm.sz = 2048 << dccm.sz; /* 2K to 256K */
  70. base = read_aux_reg(ARC_REG_DCCM_BASE_BUILD);
  71. cpu->dccm.base_addr = base & ~0xF;
  72. }
  73. } else {
  74. struct bcr_iccm_arcv2 iccm;
  75. struct bcr_dccm_arcv2 dccm;
  76. unsigned long region;
  77. READ_BCR(ARC_REG_ICCM_BUILD, iccm);
  78. if (iccm.ver) {
  79. cpu->iccm.sz = 256 << iccm.sz00; /* 512B to 16M */
  80. if (iccm.sz00 == 0xF && iccm.sz01 > 0)
  81. cpu->iccm.sz <<= iccm.sz01;
  82. region = read_aux_reg(ARC_REG_AUX_ICCM);
  83. cpu->iccm.base_addr = region & 0xF0000000;
  84. }
  85. READ_BCR(ARC_REG_DCCM_BUILD, dccm);
  86. if (dccm.ver) {
  87. cpu->dccm.sz = 256 << dccm.sz0;
  88. if (dccm.sz0 == 0xF && dccm.sz1 > 0)
  89. cpu->dccm.sz <<= dccm.sz1;
  90. region = read_aux_reg(ARC_REG_AUX_DCCM);
  91. cpu->dccm.base_addr = region & 0xF0000000;
  92. }
  93. }
  94. }
  95. static void read_arc_build_cfg_regs(void)
  96. {
  97. struct bcr_timer timer;
  98. struct bcr_generic bcr;
  99. struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
  100. const struct id_to_str *tbl;
  101. FIX_PTR(cpu);
  102. READ_BCR(AUX_IDENTITY, cpu->core);
  103. READ_BCR(ARC_REG_ISA_CFG_BCR, cpu->isa);
  104. for (tbl = &arc_cpu_rel[0]; tbl->id != 0; tbl++) {
  105. if (cpu->core.family == tbl->id) {
  106. cpu->details = tbl->str;
  107. break;
  108. }
  109. }
  110. for (tbl = &arc_cpu_nm[0]; tbl->id != 0; tbl++) {
  111. if ((cpu->core.family & 0xF0) == tbl->id)
  112. break;
  113. }
  114. cpu->name = tbl->str;
  115. READ_BCR(ARC_REG_TIMERS_BCR, timer);
  116. cpu->extn.timer0 = timer.t0;
  117. cpu->extn.timer1 = timer.t1;
  118. cpu->extn.rtc = timer.rtc;
  119. cpu->vec_base = read_aux_reg(AUX_INTR_VEC_BASE);
  120. READ_BCR(ARC_REG_MUL_BCR, cpu->extn_mpy);
  121. cpu->extn.norm = read_aux_reg(ARC_REG_NORM_BCR) > 1 ? 1 : 0; /* 2,3 */
  122. cpu->extn.barrel = read_aux_reg(ARC_REG_BARREL_BCR) > 1 ? 1 : 0; /* 2,3 */
  123. cpu->extn.swap = read_aux_reg(ARC_REG_SWAP_BCR) ? 1 : 0; /* 1,3 */
  124. cpu->extn.crc = read_aux_reg(ARC_REG_CRC_BCR) ? 1 : 0;
  125. cpu->extn.minmax = read_aux_reg(ARC_REG_MIXMAX_BCR) > 1 ? 1 : 0; /* 2 */
  126. cpu->extn.swape = (cpu->core.family >= 0x34) ? 1 :
  127. IS_ENABLED(CONFIG_ARC_HAS_SWAPE);
  128. READ_BCR(ARC_REG_XY_MEM_BCR, cpu->extn_xymem);
  129. /* Read CCM BCRs for boot reporting even if not enabled in Kconfig */
  130. read_decode_ccm_bcr(cpu);
  131. read_decode_mmu_bcr();
  132. read_decode_cache_bcr();
  133. if (is_isa_arcompact()) {
  134. struct bcr_fp_arcompact sp, dp;
  135. struct bcr_bpu_arcompact bpu;
  136. READ_BCR(ARC_REG_FP_BCR, sp);
  137. READ_BCR(ARC_REG_DPFP_BCR, dp);
  138. cpu->extn.fpu_sp = sp.ver ? 1 : 0;
  139. cpu->extn.fpu_dp = dp.ver ? 1 : 0;
  140. READ_BCR(ARC_REG_BPU_BCR, bpu);
  141. cpu->bpu.ver = bpu.ver;
  142. cpu->bpu.full = bpu.fam ? 1 : 0;
  143. if (bpu.ent) {
  144. cpu->bpu.num_cache = 256 << (bpu.ent - 1);
  145. cpu->bpu.num_pred = 256 << (bpu.ent - 1);
  146. }
  147. } else {
  148. struct bcr_fp_arcv2 spdp;
  149. struct bcr_bpu_arcv2 bpu;
  150. READ_BCR(ARC_REG_FP_V2_BCR, spdp);
  151. cpu->extn.fpu_sp = spdp.sp ? 1 : 0;
  152. cpu->extn.fpu_dp = spdp.dp ? 1 : 0;
  153. READ_BCR(ARC_REG_BPU_BCR, bpu);
  154. cpu->bpu.ver = bpu.ver;
  155. cpu->bpu.full = bpu.ft;
  156. cpu->bpu.num_cache = 256 << bpu.bce;
  157. cpu->bpu.num_pred = 2048 << bpu.pte;
  158. }
  159. READ_BCR(ARC_REG_AP_BCR, bcr);
  160. cpu->extn.ap = bcr.ver ? 1 : 0;
  161. READ_BCR(ARC_REG_SMART_BCR, bcr);
  162. cpu->extn.smart = bcr.ver ? 1 : 0;
  163. READ_BCR(ARC_REG_RTT_BCR, bcr);
  164. cpu->extn.rtt = bcr.ver ? 1 : 0;
  165. cpu->extn.debug = cpu->extn.ap | cpu->extn.smart | cpu->extn.rtt;
  166. /* some hacks for lack of feature BCR info in old ARC700 cores */
  167. if (is_isa_arcompact()) {
  168. if (!cpu->isa.ver) /* ISA BCR absent, use Kconfig info */
  169. cpu->isa.atomic = IS_ENABLED(CONFIG_ARC_HAS_LLSC);
  170. else
  171. cpu->isa.atomic = cpu->isa.atomic1;
  172. cpu->isa.be = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN);
  173. /* there's no direct way to distinguish 750 vs. 770 */
  174. if (unlikely(cpu->core.family < 0x34 || cpu->mmu.ver < 3))
  175. cpu->name = "ARC750";
  176. }
  177. }
  178. static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
  179. {
  180. struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
  181. struct bcr_identity *core = &cpu->core;
  182. int i, n = 0;
  183. FIX_PTR(cpu);
  184. n += scnprintf(buf + n, len - n,
  185. "\nIDENTITY\t: ARCVER [%#02x] ARCNUM [%#02x] CHIPID [%#4x]\n",
  186. core->family, core->cpu_id, core->chip_id);
  187. n += scnprintf(buf + n, len - n, "processor [%d]\t: %s %s (%s ISA) %s\n",
  188. cpu_id, cpu->name, cpu->details,
  189. is_isa_arcompact() ? "ARCompact" : "ARCv2",
  190. IS_AVAIL1(cpu->isa.be, "[Big-Endian]"));
  191. n += scnprintf(buf + n, len - n, "Timers\t\t: %s%s%s%s\nISA Extn\t: ",
  192. IS_AVAIL1(cpu->extn.timer0, "Timer0 "),
  193. IS_AVAIL1(cpu->extn.timer1, "Timer1 "),
  194. IS_AVAIL2(cpu->extn.rtc, "Local-64-bit-Ctr ",
  195. CONFIG_ARC_HAS_RTC));
  196. n += i = scnprintf(buf + n, len - n, "%s%s%s%s%s",
  197. IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
  198. IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
  199. IS_AVAIL1(cpu->isa.unalign, "unalign (not used)"));
  200. if (i)
  201. n += scnprintf(buf + n, len - n, "\n\t\t: ");
  202. if (cpu->extn_mpy.ver) {
  203. if (cpu->extn_mpy.ver <= 0x2) { /* ARCompact */
  204. n += scnprintf(buf + n, len - n, "mpy ");
  205. } else {
  206. int opt = 2; /* stock MPY/MPYH */
  207. if (cpu->extn_mpy.dsp) /* OPT 7-9 */
  208. opt = cpu->extn_mpy.dsp + 6;
  209. n += scnprintf(buf + n, len - n, "mpy[opt %d] ", opt);
  210. }
  211. }
  212. n += scnprintf(buf + n, len - n, "%s%s%s%s%s%s%s%s\n",
  213. IS_AVAIL1(cpu->isa.div_rem, "div_rem "),
  214. IS_AVAIL1(cpu->extn.norm, "norm "),
  215. IS_AVAIL1(cpu->extn.barrel, "barrel-shift "),
  216. IS_AVAIL1(cpu->extn.swap, "swap "),
  217. IS_AVAIL1(cpu->extn.minmax, "minmax "),
  218. IS_AVAIL1(cpu->extn.crc, "crc "),
  219. IS_AVAIL2(cpu->extn.swape, "swape", CONFIG_ARC_HAS_SWAPE));
  220. if (cpu->bpu.ver)
  221. n += scnprintf(buf + n, len - n,
  222. "BPU\t\t: %s%s match, cache:%d, Predict Table:%d\n",
  223. IS_AVAIL1(cpu->bpu.full, "full"),
  224. IS_AVAIL1(!cpu->bpu.full, "partial"),
  225. cpu->bpu.num_cache, cpu->bpu.num_pred);
  226. return buf;
  227. }
  228. static char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
  229. {
  230. int n = 0;
  231. struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
  232. FIX_PTR(cpu);
  233. n += scnprintf(buf + n, len - n, "Vector Table\t: %#x\n", cpu->vec_base);
  234. if (cpu->extn.fpu_sp || cpu->extn.fpu_dp)
  235. n += scnprintf(buf + n, len - n, "FPU\t\t: %s%s\n",
  236. IS_AVAIL1(cpu->extn.fpu_sp, "SP "),
  237. IS_AVAIL1(cpu->extn.fpu_dp, "DP "));
  238. if (cpu->extn.debug)
  239. n += scnprintf(buf + n, len - n, "DEBUG\t\t: %s%s%s\n",
  240. IS_AVAIL1(cpu->extn.ap, "ActionPoint "),
  241. IS_AVAIL1(cpu->extn.smart, "smaRT "),
  242. IS_AVAIL1(cpu->extn.rtt, "RTT "));
  243. if (cpu->dccm.sz || cpu->iccm.sz)
  244. n += scnprintf(buf + n, len - n, "Extn [CCM]\t: DCCM @ %x, %d KB / ICCM: @ %x, %d KB\n",
  245. cpu->dccm.base_addr, TO_KB(cpu->dccm.sz),
  246. cpu->iccm.base_addr, TO_KB(cpu->iccm.sz));
  247. n += scnprintf(buf + n, len - n, "OS ABI [v%d]\t: %s\n",
  248. EF_ARC_OSABI_CURRENT >> 8,
  249. EF_ARC_OSABI_CURRENT == EF_ARC_OSABI_V3 ?
  250. "no-legacy-syscalls" : "64-bit data any register aligned");
  251. return buf;
  252. }
  253. static void arc_chk_core_config(void)
  254. {
  255. struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
  256. int fpu_enabled;
  257. if (!cpu->extn.timer0)
  258. panic("Timer0 is not present!\n");
  259. if (!cpu->extn.timer1)
  260. panic("Timer1 is not present!\n");
  261. #ifdef CONFIG_ARC_HAS_DCCM
  262. /*
  263. * DCCM can be arbit placed in hardware.
  264. * Make sure it's placement/sz matches what Linux is built with
  265. */
  266. if ((unsigned int)__arc_dccm_base != cpu->dccm.base_addr)
  267. panic("Linux built with incorrect DCCM Base address\n");
  268. if (CONFIG_ARC_DCCM_SZ != cpu->dccm.sz)
  269. panic("Linux built with incorrect DCCM Size\n");
  270. #endif
  271. #ifdef CONFIG_ARC_HAS_ICCM
  272. if (CONFIG_ARC_ICCM_SZ != cpu->iccm.sz)
  273. panic("Linux built with incorrect ICCM Size\n");
  274. #endif
  275. /*
  276. * FP hardware/software config sanity
  277. * -If hardware contains DPFP, kernel needs to save/restore FPU state
  278. * -If not, it will crash trying to save/restore the non-existant regs
  279. *
  280. * (only DPDP checked since SP has no arch visible regs)
  281. */
  282. fpu_enabled = IS_ENABLED(CONFIG_ARC_FPU_SAVE_RESTORE);
  283. if (cpu->extn.fpu_dp && !fpu_enabled)
  284. pr_warn("CONFIG_ARC_FPU_SAVE_RESTORE needed for working apps\n");
  285. else if (!cpu->extn.fpu_dp && fpu_enabled)
  286. panic("FPU non-existent, disable CONFIG_ARC_FPU_SAVE_RESTORE\n");
  287. }
  288. /*
  289. * Initialize and setup the processor core
  290. * This is called by all the CPUs thus should not do special case stuff
  291. * such as only for boot CPU etc
  292. */
  293. void setup_processor(void)
  294. {
  295. char str[512];
  296. int cpu_id = smp_processor_id();
  297. read_arc_build_cfg_regs();
  298. arc_init_IRQ();
  299. printk(arc_cpu_mumbojumbo(cpu_id, str, sizeof(str)));
  300. arc_mmu_init();
  301. arc_cache_init();
  302. printk(arc_extn_mumbojumbo(cpu_id, str, sizeof(str)));
  303. printk(arc_platform_smp_cpuinfo());
  304. arc_chk_core_config();
  305. }
  306. static inline int is_kernel(unsigned long addr)
  307. {
  308. if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
  309. return 1;
  310. return 0;
  311. }
  312. void __init setup_arch(char **cmdline_p)
  313. {
  314. #ifdef CONFIG_ARC_UBOOT_SUPPORT
  315. /* make sure that uboot passed pointer to cmdline/dtb is valid */
  316. if (uboot_tag && is_kernel((unsigned long)uboot_arg))
  317. panic("Invalid uboot arg\n");
  318. /* See if u-boot passed an external Device Tree blob */
  319. machine_desc = setup_machine_fdt(uboot_arg); /* uboot_tag == 2 */
  320. if (!machine_desc)
  321. #endif
  322. {
  323. /* No, so try the embedded one */
  324. machine_desc = setup_machine_fdt(__dtb_start);
  325. if (!machine_desc)
  326. panic("Embedded DT invalid\n");
  327. /*
  328. * If we are here, it is established that @uboot_arg didn't
  329. * point to DT blob. Instead if u-boot says it is cmdline,
  330. * append to embedded DT cmdline.
  331. * setup_machine_fdt() would have populated @boot_command_line
  332. */
  333. if (uboot_tag == 1) {
  334. /* Ensure a whitespace between the 2 cmdlines */
  335. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  336. strlcat(boot_command_line, uboot_arg,
  337. COMMAND_LINE_SIZE);
  338. }
  339. }
  340. /* Save unparsed command line copy for /proc/cmdline */
  341. *cmdline_p = boot_command_line;
  342. /* To force early parsing of things like mem=xxx */
  343. parse_early_param();
  344. /* Platform/board specific: e.g. early console registration */
  345. if (machine_desc->init_early)
  346. machine_desc->init_early();
  347. smp_init_cpus();
  348. setup_processor();
  349. setup_arch_memory();
  350. /* copy flat DT out of .init and then unflatten it */
  351. unflatten_and_copy_device_tree();
  352. /* Can be issue if someone passes cmd line arg "ro"
  353. * But that is unlikely so keeping it as it is
  354. */
  355. root_mountflags &= ~MS_RDONLY;
  356. #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
  357. conswitchp = &dummy_con;
  358. #endif
  359. arc_unwind_init();
  360. }
  361. static int __init customize_machine(void)
  362. {
  363. if (machine_desc->init_machine)
  364. machine_desc->init_machine();
  365. return 0;
  366. }
  367. arch_initcall(customize_machine);
  368. static int __init init_late_machine(void)
  369. {
  370. if (machine_desc->init_late)
  371. machine_desc->init_late();
  372. return 0;
  373. }
  374. late_initcall(init_late_machine);
  375. /*
  376. * Get CPU information for use by the procfs.
  377. */
  378. #define cpu_to_ptr(c) ((void *)(0xFFFF0000 | (unsigned int)(c)))
  379. #define ptr_to_cpu(p) (~0xFFFF0000UL & (unsigned int)(p))
  380. static int show_cpuinfo(struct seq_file *m, void *v)
  381. {
  382. char *str;
  383. int cpu_id = ptr_to_cpu(v);
  384. struct device_node *core_clk = of_find_node_by_name(NULL, "core_clk");
  385. u32 freq = 0;
  386. if (!cpu_online(cpu_id)) {
  387. seq_printf(m, "processor [%d]\t: Offline\n", cpu_id);
  388. goto done;
  389. }
  390. str = (char *)__get_free_page(GFP_TEMPORARY);
  391. if (!str)
  392. goto done;
  393. seq_printf(m, arc_cpu_mumbojumbo(cpu_id, str, PAGE_SIZE));
  394. of_property_read_u32(core_clk, "clock-frequency", &freq);
  395. if (freq)
  396. seq_printf(m, "CPU speed\t: %u.%02u Mhz\n",
  397. freq / 1000000, (freq / 10000) % 100);
  398. seq_printf(m, "Bogo MIPS\t: %lu.%02lu\n",
  399. loops_per_jiffy / (500000 / HZ),
  400. (loops_per_jiffy / (5000 / HZ)) % 100);
  401. seq_printf(m, arc_mmu_mumbojumbo(cpu_id, str, PAGE_SIZE));
  402. seq_printf(m, arc_cache_mumbojumbo(cpu_id, str, PAGE_SIZE));
  403. seq_printf(m, arc_extn_mumbojumbo(cpu_id, str, PAGE_SIZE));
  404. seq_printf(m, arc_platform_smp_cpuinfo());
  405. free_page((unsigned long)str);
  406. done:
  407. seq_printf(m, "\n");
  408. return 0;
  409. }
  410. static void *c_start(struct seq_file *m, loff_t *pos)
  411. {
  412. /*
  413. * Callback returns cpu-id to iterator for show routine, NULL to stop.
  414. * However since NULL is also a valid cpu-id (0), we use a round-about
  415. * way to pass it w/o having to kmalloc/free a 2 byte string.
  416. * Encode cpu-id as 0xFFcccc, which is decoded by show routine.
  417. */
  418. return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
  419. }
  420. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  421. {
  422. ++*pos;
  423. return c_start(m, pos);
  424. }
  425. static void c_stop(struct seq_file *m, void *v)
  426. {
  427. }
  428. const struct seq_operations cpuinfo_op = {
  429. .start = c_start,
  430. .next = c_next,
  431. .stop = c_stop,
  432. .show = show_cpuinfo
  433. };
  434. static DEFINE_PER_CPU(struct cpu, cpu_topology);
  435. static int __init topology_init(void)
  436. {
  437. int cpu;
  438. for_each_present_cpu(cpu)
  439. register_cpu(&per_cpu(cpu_topology, cpu), cpu);
  440. return 0;
  441. }
  442. subsys_initcall(topology_init);