setup.c 16 KB

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