setup.c 14 KB

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