setup.c 14 KB

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