setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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/clk-provider.h>
  16. #include <linux/of_fdt.h>
  17. #include <linux/of_platform.h>
  18. #include <linux/cache.h>
  19. #include <asm/sections.h>
  20. #include <asm/arcregs.h>
  21. #include <asm/tlb.h>
  22. #include <asm/setup.h>
  23. #include <asm/page.h>
  24. #include <asm/irq.h>
  25. #include <asm/unwind.h>
  26. #include <asm/clk.h>
  27. #include <asm/mach_desc.h>
  28. #include <asm/smp.h>
  29. #define FIX_PTR(x) __asm__ __volatile__(";" : "+r"(x))
  30. int running_on_hw = 1; /* vs. on ISS */
  31. /* Part of U-boot ABI: see head.S */
  32. int __initdata uboot_tag;
  33. char __initdata *uboot_arg;
  34. const struct machine_desc *machine_desc;
  35. struct task_struct *_current_task[NR_CPUS]; /* For stack switching */
  36. struct cpuinfo_arc cpuinfo_arc700[NR_CPUS];
  37. static void read_arc_build_cfg_regs(void)
  38. {
  39. struct bcr_perip uncached_space;
  40. struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
  41. FIX_PTR(cpu);
  42. READ_BCR(AUX_IDENTITY, cpu->core);
  43. cpu->timers = read_aux_reg(ARC_REG_TIMERS_BCR);
  44. cpu->vec_base = read_aux_reg(AUX_INTR_VEC_BASE);
  45. READ_BCR(ARC_REG_D_UNCACH_BCR, uncached_space);
  46. cpu->uncached_base = uncached_space.start << 24;
  47. cpu->extn.mul = read_aux_reg(ARC_REG_MUL_BCR);
  48. cpu->extn.swap = read_aux_reg(ARC_REG_SWAP_BCR);
  49. cpu->extn.norm = read_aux_reg(ARC_REG_NORM_BCR);
  50. cpu->extn.minmax = read_aux_reg(ARC_REG_MIXMAX_BCR);
  51. cpu->extn.barrel = read_aux_reg(ARC_REG_BARREL_BCR);
  52. READ_BCR(ARC_REG_MAC_BCR, cpu->extn_mac_mul);
  53. cpu->extn.ext_arith = read_aux_reg(ARC_REG_EXTARITH_BCR);
  54. cpu->extn.crc = read_aux_reg(ARC_REG_CRC_BCR);
  55. /* Note that we read the CCM BCRs independent of kernel config
  56. * This is to catch the cases where user doesn't know that
  57. * CCMs are present in hardware build
  58. */
  59. {
  60. struct bcr_iccm iccm;
  61. struct bcr_dccm dccm;
  62. struct bcr_dccm_base dccm_base;
  63. unsigned int bcr_32bit_val;
  64. bcr_32bit_val = read_aux_reg(ARC_REG_ICCM_BCR);
  65. if (bcr_32bit_val) {
  66. iccm = *((struct bcr_iccm *)&bcr_32bit_val);
  67. cpu->iccm.base_addr = iccm.base << 16;
  68. cpu->iccm.sz = 0x2000 << (iccm.sz - 1);
  69. }
  70. bcr_32bit_val = read_aux_reg(ARC_REG_DCCM_BCR);
  71. if (bcr_32bit_val) {
  72. dccm = *((struct bcr_dccm *)&bcr_32bit_val);
  73. cpu->dccm.sz = 0x800 << (dccm.sz);
  74. READ_BCR(ARC_REG_DCCMBASE_BCR, dccm_base);
  75. cpu->dccm.base_addr = dccm_base.addr << 8;
  76. }
  77. }
  78. READ_BCR(ARC_REG_XY_MEM_BCR, cpu->extn_xymem);
  79. read_decode_mmu_bcr();
  80. read_decode_cache_bcr();
  81. READ_BCR(ARC_REG_FP_BCR, cpu->fp);
  82. READ_BCR(ARC_REG_DPFP_BCR, cpu->dpfp);
  83. }
  84. static const struct cpuinfo_data arc_cpu_tbl[] = {
  85. { {0x10, "ARCTangent A5"}, 0x1F},
  86. { {0x20, "ARC 600" }, 0x2F},
  87. { {0x30, "ARC 700" }, 0x33},
  88. { {0x34, "ARC 700 R4.10"}, 0x34},
  89. { {0x00, NULL } }
  90. };
  91. static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
  92. {
  93. int n = 0;
  94. struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
  95. struct bcr_identity *core = &cpu->core;
  96. const struct cpuinfo_data *tbl;
  97. int be = 0;
  98. #ifdef CONFIG_CPU_BIG_ENDIAN
  99. be = 1;
  100. #endif
  101. FIX_PTR(cpu);
  102. n += scnprintf(buf + n, len - n,
  103. "\nARC IDENTITY\t: Family [%#02x]"
  104. " Cpu-id [%#02x] Chip-id [%#4x]\n",
  105. core->family, core->cpu_id,
  106. core->chip_id);
  107. for (tbl = &arc_cpu_tbl[0]; tbl->info.id != 0; tbl++) {
  108. if ((core->family >= tbl->info.id) &&
  109. (core->family <= tbl->up_range)) {
  110. n += scnprintf(buf + n, len - n,
  111. "processor\t: %s %s\n",
  112. tbl->info.str,
  113. be ? "[Big Endian]" : "");
  114. break;
  115. }
  116. }
  117. if (tbl->info.id == 0)
  118. n += scnprintf(buf + n, len - n, "UNKNOWN ARC Processor\n");
  119. n += scnprintf(buf + n, len - n, "CPU speed\t: %u.%02u Mhz\n",
  120. (unsigned int)(arc_get_core_freq() / 1000000),
  121. (unsigned int)(arc_get_core_freq() / 10000) % 100);
  122. n += scnprintf(buf + n, len - n, "Timers\t\t: %s %s\n",
  123. (cpu->timers & 0x200) ? "TIMER1" : "",
  124. (cpu->timers & 0x100) ? "TIMER0" : "");
  125. n += scnprintf(buf + n, len - n, "Vect Tbl Base\t: %#x\n",
  126. cpu->vec_base);
  127. n += scnprintf(buf + n, len - n, "UNCACHED Base\t: %#x\n",
  128. cpu->uncached_base);
  129. return buf;
  130. }
  131. static const struct id_to_str mul_type_nm[] = {
  132. { 0x0, "N/A"},
  133. { 0x1, "32x32 (spl Result Reg)" },
  134. { 0x2, "32x32 (ANY Result Reg)" }
  135. };
  136. static const struct id_to_str mac_mul_nm[] = {
  137. {0x0, "N/A"},
  138. {0x1, "N/A"},
  139. {0x2, "Dual 16 x 16"},
  140. {0x3, "N/A"},
  141. {0x4, "32x16"},
  142. {0x5, "N/A"},
  143. {0x6, "Dual 16x16 and 32x16"}
  144. };
  145. static char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
  146. {
  147. int n = 0;
  148. struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
  149. FIX_PTR(cpu);
  150. #define IS_AVAIL1(var, str) ((var) ? str : "")
  151. #define IS_AVAIL2(var, str) ((var == 0x2) ? str : "")
  152. #define IS_USED(cfg) (IS_ENABLED(cfg) ? "(in-use)" : "(not used)")
  153. n += scnprintf(buf + n, len - n,
  154. "Extn [700-Base]\t: %s %s %s %s %s %s\n",
  155. IS_AVAIL2(cpu->extn.norm, "norm,"),
  156. IS_AVAIL2(cpu->extn.barrel, "barrel-shift,"),
  157. IS_AVAIL1(cpu->extn.swap, "swap,"),
  158. IS_AVAIL2(cpu->extn.minmax, "minmax,"),
  159. IS_AVAIL1(cpu->extn.crc, "crc,"),
  160. IS_AVAIL2(cpu->extn.ext_arith, "ext-arith"));
  161. n += scnprintf(buf + n, len - n, "Extn [700-MPY]\t: %s",
  162. mul_type_nm[cpu->extn.mul].str);
  163. n += scnprintf(buf + n, len - n, " MAC MPY: %s\n",
  164. mac_mul_nm[cpu->extn_mac_mul.type].str);
  165. if (cpu->core.family == 0x34) {
  166. n += scnprintf(buf + n, len - n,
  167. "Extn [700-4.10]\t: LLOCK/SCOND %s, SWAPE %s, RTSC %s\n",
  168. IS_USED(CONFIG_ARC_HAS_LLSC),
  169. IS_USED(CONFIG_ARC_HAS_SWAPE),
  170. IS_USED(CONFIG_ARC_HAS_RTSC));
  171. }
  172. n += scnprintf(buf + n, len - n, "Extn [CCM]\t: %s",
  173. !(cpu->dccm.sz || cpu->iccm.sz) ? "N/A" : "");
  174. if (cpu->dccm.sz)
  175. n += scnprintf(buf + n, len - n, "DCCM: @ %x, %d KB ",
  176. cpu->dccm.base_addr, TO_KB(cpu->dccm.sz));
  177. if (cpu->iccm.sz)
  178. n += scnprintf(buf + n, len - n, "ICCM: @ %x, %d KB",
  179. cpu->iccm.base_addr, TO_KB(cpu->iccm.sz));
  180. n += scnprintf(buf + n, len - n, "\nExtn [FPU]\t: %s",
  181. !(cpu->fp.ver || cpu->dpfp.ver) ? "N/A" : "");
  182. if (cpu->fp.ver)
  183. n += scnprintf(buf + n, len - n, "SP [v%d] %s",
  184. cpu->fp.ver, cpu->fp.fast ? "(fast)" : "");
  185. if (cpu->dpfp.ver)
  186. n += scnprintf(buf + n, len - n, "DP [v%d] %s",
  187. cpu->dpfp.ver, cpu->dpfp.fast ? "(fast)" : "");
  188. n += scnprintf(buf + n, len - n, "\n");
  189. n += scnprintf(buf + n, len - n,
  190. "OS ABI [v3]\t: no-legacy-syscalls\n");
  191. return buf;
  192. }
  193. static void arc_chk_ccms(void)
  194. {
  195. #if defined(CONFIG_ARC_HAS_DCCM) || defined(CONFIG_ARC_HAS_ICCM)
  196. struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
  197. #ifdef CONFIG_ARC_HAS_DCCM
  198. /*
  199. * DCCM can be arbit placed in hardware.
  200. * Make sure it's placement/sz matches what Linux is built with
  201. */
  202. if ((unsigned int)__arc_dccm_base != cpu->dccm.base_addr)
  203. panic("Linux built with incorrect DCCM Base address\n");
  204. if (CONFIG_ARC_DCCM_SZ != cpu->dccm.sz)
  205. panic("Linux built with incorrect DCCM Size\n");
  206. #endif
  207. #ifdef CONFIG_ARC_HAS_ICCM
  208. if (CONFIG_ARC_ICCM_SZ != cpu->iccm.sz)
  209. panic("Linux built with incorrect ICCM Size\n");
  210. #endif
  211. #endif
  212. }
  213. /*
  214. * Ensure that FP hardware and kernel config match
  215. * -If hardware contains DPFP, kernel needs to save/restore FPU state
  216. * across context switches
  217. * -If hardware lacks DPFP, but kernel configured to save FPU state then
  218. * kernel trying to access non-existant DPFP regs will crash
  219. *
  220. * We only check for Dbl precision Floating Point, because only DPFP
  221. * hardware has dedicated regs which need to be saved/restored on ctx-sw
  222. * (Single Precision uses core regs), thus kernel is kind of oblivious to it
  223. */
  224. static void arc_chk_fpu(void)
  225. {
  226. struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
  227. if (cpu->dpfp.ver) {
  228. #ifndef CONFIG_ARC_FPU_SAVE_RESTORE
  229. pr_warn("DPFP support broken in this kernel...\n");
  230. #endif
  231. } else {
  232. #ifdef CONFIG_ARC_FPU_SAVE_RESTORE
  233. panic("H/w lacks DPFP support, apps won't work\n");
  234. #endif
  235. }
  236. }
  237. /*
  238. * Initialize and setup the processor core
  239. * This is called by all the CPUs thus should not do special case stuff
  240. * such as only for boot CPU etc
  241. */
  242. void setup_processor(void)
  243. {
  244. char str[512];
  245. int cpu_id = smp_processor_id();
  246. read_arc_build_cfg_regs();
  247. arc_init_IRQ();
  248. printk(arc_cpu_mumbojumbo(cpu_id, str, sizeof(str)));
  249. arc_mmu_init();
  250. arc_cache_init();
  251. arc_chk_ccms();
  252. printk(arc_extn_mumbojumbo(cpu_id, str, sizeof(str)));
  253. printk(arc_platform_smp_cpuinfo());
  254. arc_chk_fpu();
  255. }
  256. static inline int is_kernel(unsigned long addr)
  257. {
  258. if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
  259. return 1;
  260. return 0;
  261. }
  262. void __init setup_arch(char **cmdline_p)
  263. {
  264. /* make sure that uboot passed pointer to cmdline/dtb is valid */
  265. if (uboot_tag && is_kernel((unsigned long)uboot_arg))
  266. panic("Invalid uboot arg\n");
  267. /* See if u-boot passed an external Device Tree blob */
  268. machine_desc = setup_machine_fdt(uboot_arg); /* uboot_tag == 2 */
  269. if (!machine_desc) {
  270. /* No, so try the embedded one */
  271. machine_desc = setup_machine_fdt(__dtb_start);
  272. if (!machine_desc)
  273. panic("Embedded DT invalid\n");
  274. /*
  275. * If we are here, it is established that @uboot_arg didn't
  276. * point to DT blob. Instead if u-boot says it is cmdline,
  277. * Appent to embedded DT cmdline.
  278. * setup_machine_fdt() would have populated @boot_command_line
  279. */
  280. if (uboot_tag == 1) {
  281. /* Ensure a whitespace between the 2 cmdlines */
  282. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  283. strlcat(boot_command_line, uboot_arg,
  284. COMMAND_LINE_SIZE);
  285. }
  286. }
  287. /* Save unparsed command line copy for /proc/cmdline */
  288. *cmdline_p = boot_command_line;
  289. /* To force early parsing of things like mem=xxx */
  290. parse_early_param();
  291. /* Platform/board specific: e.g. early console registration */
  292. if (machine_desc->init_early)
  293. machine_desc->init_early();
  294. setup_processor();
  295. smp_init_cpus();
  296. setup_arch_memory();
  297. /* copy flat DT out of .init and then unflatten it */
  298. unflatten_and_copy_device_tree();
  299. /* Can be issue if someone passes cmd line arg "ro"
  300. * But that is unlikely so keeping it as it is
  301. */
  302. root_mountflags &= ~MS_RDONLY;
  303. #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
  304. conswitchp = &dummy_con;
  305. #endif
  306. arc_unwind_init();
  307. arc_unwind_setup();
  308. }
  309. static int __init customize_machine(void)
  310. {
  311. of_clk_init(NULL);
  312. /*
  313. * Traverses flattened DeviceTree - registering platform devices
  314. * (if any) complete with their resources
  315. */
  316. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  317. if (machine_desc->init_machine)
  318. machine_desc->init_machine();
  319. return 0;
  320. }
  321. arch_initcall(customize_machine);
  322. static int __init init_late_machine(void)
  323. {
  324. if (machine_desc->init_late)
  325. machine_desc->init_late();
  326. return 0;
  327. }
  328. late_initcall(init_late_machine);
  329. /*
  330. * Get CPU information for use by the procfs.
  331. */
  332. #define cpu_to_ptr(c) ((void *)(0xFFFF0000 | (unsigned int)(c)))
  333. #define ptr_to_cpu(p) (~0xFFFF0000UL & (unsigned int)(p))
  334. static int show_cpuinfo(struct seq_file *m, void *v)
  335. {
  336. char *str;
  337. int cpu_id = ptr_to_cpu(v);
  338. str = (char *)__get_free_page(GFP_TEMPORARY);
  339. if (!str)
  340. goto done;
  341. seq_printf(m, arc_cpu_mumbojumbo(cpu_id, str, PAGE_SIZE));
  342. seq_printf(m, "Bogo MIPS : \t%lu.%02lu\n",
  343. loops_per_jiffy / (500000 / HZ),
  344. (loops_per_jiffy / (5000 / HZ)) % 100);
  345. seq_printf(m, arc_mmu_mumbojumbo(cpu_id, str, PAGE_SIZE));
  346. seq_printf(m, arc_cache_mumbojumbo(cpu_id, str, PAGE_SIZE));
  347. seq_printf(m, arc_extn_mumbojumbo(cpu_id, str, PAGE_SIZE));
  348. seq_printf(m, arc_platform_smp_cpuinfo());
  349. free_page((unsigned long)str);
  350. done:
  351. seq_printf(m, "\n\n");
  352. return 0;
  353. }
  354. static void *c_start(struct seq_file *m, loff_t *pos)
  355. {
  356. /*
  357. * Callback returns cpu-id to iterator for show routine, NULL to stop.
  358. * However since NULL is also a valid cpu-id (0), we use a round-about
  359. * way to pass it w/o having to kmalloc/free a 2 byte string.
  360. * Encode cpu-id as 0xFFcccc, which is decoded by show routine.
  361. */
  362. return *pos < num_possible_cpus() ? cpu_to_ptr(*pos) : NULL;
  363. }
  364. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  365. {
  366. ++*pos;
  367. return c_start(m, pos);
  368. }
  369. static void c_stop(struct seq_file *m, void *v)
  370. {
  371. }
  372. const struct seq_operations cpuinfo_op = {
  373. .start = c_start,
  374. .next = c_next,
  375. .stop = c_stop,
  376. .show = show_cpuinfo
  377. };
  378. static DEFINE_PER_CPU(struct cpu, cpu_topology);
  379. static int __init topology_init(void)
  380. {
  381. int cpu;
  382. for_each_present_cpu(cpu)
  383. register_cpu(&per_cpu(cpu_topology, cpu), cpu);
  384. return 0;
  385. }
  386. subsys_initcall(topology_init);