setup.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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, ua = 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. #ifdef __ARC_UNALIGNED__
  216. ua = 1;
  217. #endif
  218. n += i = scnprintf(buf + n, len - n, "%s%s%s%s%s%s",
  219. IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
  220. IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
  221. IS_AVAIL1(cpu->isa.unalign, "unalign "), IS_USED_RUN(ua));
  222. if (i)
  223. n += scnprintf(buf + n, len - n, "\n\t\t: ");
  224. if (cpu->extn_mpy.ver) {
  225. if (cpu->extn_mpy.ver <= 0x2) { /* ARCompact */
  226. n += scnprintf(buf + n, len - n, "mpy ");
  227. } else {
  228. int opt = 2; /* stock MPY/MPYH */
  229. if (cpu->extn_mpy.dsp) /* OPT 7-9 */
  230. opt = cpu->extn_mpy.dsp + 6;
  231. n += scnprintf(buf + n, len - n, "mpy[opt %d] ", opt);
  232. }
  233. }
  234. n += scnprintf(buf + n, len - n, "%s%s%s%s%s%s%s%s\n",
  235. IS_AVAIL1(cpu->isa.div_rem, "div_rem "),
  236. IS_AVAIL1(cpu->extn.norm, "norm "),
  237. IS_AVAIL1(cpu->extn.barrel, "barrel-shift "),
  238. IS_AVAIL1(cpu->extn.swap, "swap "),
  239. IS_AVAIL1(cpu->extn.minmax, "minmax "),
  240. IS_AVAIL1(cpu->extn.crc, "crc "),
  241. IS_AVAIL2(cpu->extn.swape, "swape", CONFIG_ARC_HAS_SWAPE));
  242. if (cpu->bpu.ver)
  243. n += scnprintf(buf + n, len - n,
  244. "BPU\t\t: %s%s match, cache:%d, Predict Table:%d",
  245. IS_AVAIL1(cpu->bpu.full, "full"),
  246. IS_AVAIL1(!cpu->bpu.full, "partial"),
  247. cpu->bpu.num_cache, cpu->bpu.num_pred);
  248. if (is_isa_arcv2()) {
  249. struct bcr_lpb lpb;
  250. READ_BCR(ARC_REG_LPB_BUILD, lpb);
  251. if (lpb.ver) {
  252. unsigned int ctl;
  253. ctl = read_aux_reg(ARC_REG_LPB_CTRL);
  254. n += scnprintf(buf + n, len - n, " Loop Buffer:%d %s",
  255. lpb.entries,
  256. IS_DISABLED_RUN(!ctl));
  257. }
  258. }
  259. n += scnprintf(buf + n, len - n, "\n");
  260. return buf;
  261. }
  262. static char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
  263. {
  264. int n = 0;
  265. struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
  266. FIX_PTR(cpu);
  267. n += scnprintf(buf + n, len - n, "Vector Table\t: %#x\n", cpu->vec_base);
  268. if (cpu->extn.fpu_sp || cpu->extn.fpu_dp)
  269. n += scnprintf(buf + n, len - n, "FPU\t\t: %s%s\n",
  270. IS_AVAIL1(cpu->extn.fpu_sp, "SP "),
  271. IS_AVAIL1(cpu->extn.fpu_dp, "DP "));
  272. if (cpu->extn.debug)
  273. n += scnprintf(buf + n, len - n, "DEBUG\t\t: %s%s%s\n",
  274. IS_AVAIL1(cpu->extn.ap, "ActionPoint "),
  275. IS_AVAIL1(cpu->extn.smart, "smaRT "),
  276. IS_AVAIL1(cpu->extn.rtt, "RTT "));
  277. if (cpu->dccm.sz || cpu->iccm.sz)
  278. n += scnprintf(buf + n, len - n, "Extn [CCM]\t: DCCM @ %x, %d KB / ICCM: @ %x, %d KB\n",
  279. cpu->dccm.base_addr, TO_KB(cpu->dccm.sz),
  280. cpu->iccm.base_addr, TO_KB(cpu->iccm.sz));
  281. if (is_isa_arcv2()) {
  282. /* Error Protection: ECC/Parity */
  283. struct bcr_erp erp;
  284. READ_BCR(ARC_REG_ERP_BUILD, erp);
  285. if (erp.ver) {
  286. struct ctl_erp ctl;
  287. READ_BCR(ARC_REG_ERP_CTRL, ctl);
  288. /* inverted bits: 0 means enabled */
  289. n += scnprintf(buf + n, len - n, "Extn [ECC]\t: %s%s%s%s%s%s\n",
  290. IS_AVAIL3(erp.ic, !ctl.dpi, "IC "),
  291. IS_AVAIL3(erp.dc, !ctl.dpd, "DC "),
  292. IS_AVAIL3(erp.mmu, !ctl.mpd, "MMU "));
  293. }
  294. }
  295. n += scnprintf(buf + n, len - n, "OS ABI [v%d]\t: %s\n",
  296. EF_ARC_OSABI_CURRENT >> 8,
  297. EF_ARC_OSABI_CURRENT == EF_ARC_OSABI_V3 ?
  298. "no-legacy-syscalls" : "64-bit data any register aligned");
  299. return buf;
  300. }
  301. static void arc_chk_core_config(void)
  302. {
  303. struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
  304. int saved = 0, present = 0;
  305. char *opt_nm = NULL;
  306. if (!cpu->extn.timer0)
  307. panic("Timer0 is not present!\n");
  308. if (!cpu->extn.timer1)
  309. panic("Timer1 is not present!\n");
  310. #ifdef CONFIG_ARC_HAS_DCCM
  311. /*
  312. * DCCM can be arbit placed in hardware.
  313. * Make sure it's placement/sz matches what Linux is built with
  314. */
  315. if ((unsigned int)__arc_dccm_base != cpu->dccm.base_addr)
  316. panic("Linux built with incorrect DCCM Base address\n");
  317. if (CONFIG_ARC_DCCM_SZ != cpu->dccm.sz)
  318. panic("Linux built with incorrect DCCM Size\n");
  319. #endif
  320. #ifdef CONFIG_ARC_HAS_ICCM
  321. if (CONFIG_ARC_ICCM_SZ != cpu->iccm.sz)
  322. panic("Linux built with incorrect ICCM Size\n");
  323. #endif
  324. /*
  325. * FP hardware/software config sanity
  326. * -If hardware present, kernel needs to save/restore FPU state
  327. * -If not, it will crash trying to save/restore the non-existant regs
  328. */
  329. if (is_isa_arcompact()) {
  330. opt_nm = "CONFIG_ARC_FPU_SAVE_RESTORE";
  331. saved = IS_ENABLED(CONFIG_ARC_FPU_SAVE_RESTORE);
  332. /* only DPDP checked since SP has no arch visible regs */
  333. present = cpu->extn.fpu_dp;
  334. } else {
  335. opt_nm = "CONFIG_ARC_HAS_ACCL_REGS";
  336. saved = IS_ENABLED(CONFIG_ARC_HAS_ACCL_REGS);
  337. /* Accumulator Low:High pair (r58:59) present if DSP MPY or FPU */
  338. present = cpu->extn_mpy.dsp | cpu->extn.fpu_sp | cpu->extn.fpu_dp;
  339. }
  340. if (present && !saved)
  341. pr_warn("Enable %s for working apps\n", opt_nm);
  342. else if (!present && saved)
  343. panic("Disable %s, hardware NOT present\n", opt_nm);
  344. }
  345. /*
  346. * Initialize and setup the processor core
  347. * This is called by all the CPUs thus should not do special case stuff
  348. * such as only for boot CPU etc
  349. */
  350. void setup_processor(void)
  351. {
  352. char str[512];
  353. int cpu_id = smp_processor_id();
  354. read_arc_build_cfg_regs();
  355. arc_init_IRQ();
  356. pr_info("%s", arc_cpu_mumbojumbo(cpu_id, str, sizeof(str)));
  357. arc_mmu_init();
  358. arc_cache_init();
  359. pr_info("%s", arc_extn_mumbojumbo(cpu_id, str, sizeof(str)));
  360. pr_info("%s", arc_platform_smp_cpuinfo());
  361. arc_chk_core_config();
  362. }
  363. static inline int is_kernel(unsigned long addr)
  364. {
  365. if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
  366. return 1;
  367. return 0;
  368. }
  369. void __init setup_arch(char **cmdline_p)
  370. {
  371. #ifdef CONFIG_ARC_UBOOT_SUPPORT
  372. /* make sure that uboot passed pointer to cmdline/dtb is valid */
  373. if (uboot_tag && is_kernel((unsigned long)uboot_arg))
  374. panic("Invalid uboot arg\n");
  375. /* See if u-boot passed an external Device Tree blob */
  376. machine_desc = setup_machine_fdt(uboot_arg); /* uboot_tag == 2 */
  377. if (!machine_desc)
  378. #endif
  379. {
  380. /* No, so try the embedded one */
  381. machine_desc = setup_machine_fdt(__dtb_start);
  382. if (!machine_desc)
  383. panic("Embedded DT invalid\n");
  384. /*
  385. * If we are here, it is established that @uboot_arg didn't
  386. * point to DT blob. Instead if u-boot says it is cmdline,
  387. * append to embedded DT cmdline.
  388. * setup_machine_fdt() would have populated @boot_command_line
  389. */
  390. if (uboot_tag == 1) {
  391. /* Ensure a whitespace between the 2 cmdlines */
  392. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  393. strlcat(boot_command_line, uboot_arg,
  394. COMMAND_LINE_SIZE);
  395. }
  396. }
  397. /* Save unparsed command line copy for /proc/cmdline */
  398. *cmdline_p = boot_command_line;
  399. /* To force early parsing of things like mem=xxx */
  400. parse_early_param();
  401. /* Platform/board specific: e.g. early console registration */
  402. if (machine_desc->init_early)
  403. machine_desc->init_early();
  404. smp_init_cpus();
  405. setup_processor();
  406. setup_arch_memory();
  407. /* copy flat DT out of .init and then unflatten it */
  408. unflatten_and_copy_device_tree();
  409. /* Can be issue if someone passes cmd line arg "ro"
  410. * But that is unlikely so keeping it as it is
  411. */
  412. root_mountflags &= ~MS_RDONLY;
  413. #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
  414. conswitchp = &dummy_con;
  415. #endif
  416. arc_unwind_init();
  417. }
  418. /*
  419. * Called from start_kernel() - boot CPU only
  420. */
  421. void __init time_init(void)
  422. {
  423. of_clk_init(NULL);
  424. timer_probe();
  425. }
  426. static int __init customize_machine(void)
  427. {
  428. if (machine_desc->init_machine)
  429. machine_desc->init_machine();
  430. return 0;
  431. }
  432. arch_initcall(customize_machine);
  433. static int __init init_late_machine(void)
  434. {
  435. if (machine_desc->init_late)
  436. machine_desc->init_late();
  437. return 0;
  438. }
  439. late_initcall(init_late_machine);
  440. /*
  441. * Get CPU information for use by the procfs.
  442. */
  443. #define cpu_to_ptr(c) ((void *)(0xFFFF0000 | (unsigned int)(c)))
  444. #define ptr_to_cpu(p) (~0xFFFF0000UL & (unsigned int)(p))
  445. static int show_cpuinfo(struct seq_file *m, void *v)
  446. {
  447. char *str;
  448. int cpu_id = ptr_to_cpu(v);
  449. struct device *cpu_dev = get_cpu_device(cpu_id);
  450. struct clk *cpu_clk;
  451. unsigned long freq = 0;
  452. if (!cpu_online(cpu_id)) {
  453. seq_printf(m, "processor [%d]\t: Offline\n", cpu_id);
  454. goto done;
  455. }
  456. str = (char *)__get_free_page(GFP_KERNEL);
  457. if (!str)
  458. goto done;
  459. seq_printf(m, arc_cpu_mumbojumbo(cpu_id, str, PAGE_SIZE));
  460. cpu_clk = clk_get(cpu_dev, NULL);
  461. if (IS_ERR(cpu_clk)) {
  462. seq_printf(m, "CPU speed \t: Cannot get clock for processor [%d]\n",
  463. cpu_id);
  464. } else {
  465. freq = clk_get_rate(cpu_clk);
  466. }
  467. if (freq)
  468. seq_printf(m, "CPU speed\t: %lu.%02lu Mhz\n",
  469. freq / 1000000, (freq / 10000) % 100);
  470. seq_printf(m, "Bogo MIPS\t: %lu.%02lu\n",
  471. loops_per_jiffy / (500000 / HZ),
  472. (loops_per_jiffy / (5000 / HZ)) % 100);
  473. seq_printf(m, arc_mmu_mumbojumbo(cpu_id, str, PAGE_SIZE));
  474. seq_printf(m, arc_cache_mumbojumbo(cpu_id, str, PAGE_SIZE));
  475. seq_printf(m, arc_extn_mumbojumbo(cpu_id, str, PAGE_SIZE));
  476. seq_printf(m, arc_platform_smp_cpuinfo());
  477. free_page((unsigned long)str);
  478. done:
  479. seq_printf(m, "\n");
  480. return 0;
  481. }
  482. static void *c_start(struct seq_file *m, loff_t *pos)
  483. {
  484. /*
  485. * Callback returns cpu-id to iterator for show routine, NULL to stop.
  486. * However since NULL is also a valid cpu-id (0), we use a round-about
  487. * way to pass it w/o having to kmalloc/free a 2 byte string.
  488. * Encode cpu-id as 0xFFcccc, which is decoded by show routine.
  489. */
  490. return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
  491. }
  492. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  493. {
  494. ++*pos;
  495. return c_start(m, pos);
  496. }
  497. static void c_stop(struct seq_file *m, void *v)
  498. {
  499. }
  500. const struct seq_operations cpuinfo_op = {
  501. .start = c_start,
  502. .next = c_next,
  503. .stop = c_stop,
  504. .show = show_cpuinfo
  505. };
  506. static DEFINE_PER_CPU(struct cpu, cpu_topology);
  507. static int __init topology_init(void)
  508. {
  509. int cpu;
  510. for_each_present_cpu(cpu)
  511. register_cpu(&per_cpu(cpu_topology, cpu), cpu);
  512. return 0;
  513. }
  514. subsys_initcall(topology_init);