setup.c 12 KB

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