setup.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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. struct bcr_uarch_build_arcv2 uarch;
  165. /*
  166. * The first 0x54 core (uarch maj:min 0:1 or 0:2) was
  167. * dual issue only (HS4x). But next uarch rev (1:0)
  168. * allows it be configured for single issue (HS3x)
  169. * Ensure we fiddle with dual issue only on HS4x
  170. */
  171. READ_BCR(ARC_REG_MICRO_ARCH_BCR, uarch);
  172. if (uarch.prod == 4) {
  173. unsigned int exec_ctrl;
  174. /* dual issue hardware always present */
  175. cpu->extn.dual = 1;
  176. READ_BCR(AUX_EXEC_CTRL, exec_ctrl);
  177. /* dual issue hardware enabled ? */
  178. cpu->extn.dual_enb = !(exec_ctrl & 1);
  179. }
  180. }
  181. }
  182. READ_BCR(ARC_REG_AP_BCR, bcr);
  183. cpu->extn.ap = bcr.ver ? 1 : 0;
  184. READ_BCR(ARC_REG_SMART_BCR, bcr);
  185. cpu->extn.smart = bcr.ver ? 1 : 0;
  186. READ_BCR(ARC_REG_RTT_BCR, bcr);
  187. cpu->extn.rtt = bcr.ver ? 1 : 0;
  188. cpu->extn.debug = cpu->extn.ap | cpu->extn.smart | cpu->extn.rtt;
  189. READ_BCR(ARC_REG_ISA_CFG_BCR, isa);
  190. /* some hacks for lack of feature BCR info in old ARC700 cores */
  191. if (is_isa_arcompact()) {
  192. if (!isa.ver) /* ISA BCR absent, use Kconfig info */
  193. cpu->isa.atomic = IS_ENABLED(CONFIG_ARC_HAS_LLSC);
  194. else {
  195. /* ARC700_BUILD only has 2 bits of isa info */
  196. struct bcr_generic bcr = *(struct bcr_generic *)&isa;
  197. cpu->isa.atomic = bcr.info & 1;
  198. }
  199. cpu->isa.be = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN);
  200. /* there's no direct way to distinguish 750 vs. 770 */
  201. if (unlikely(cpu->core.family < 0x34 || cpu->mmu.ver < 3))
  202. cpu->name = "ARC750";
  203. } else {
  204. cpu->isa = isa;
  205. }
  206. }
  207. static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
  208. {
  209. struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
  210. struct bcr_identity *core = &cpu->core;
  211. int i, n = 0;
  212. FIX_PTR(cpu);
  213. n += scnprintf(buf + n, len - n,
  214. "\nIDENTITY\t: ARCVER [%#02x] ARCNUM [%#02x] CHIPID [%#4x]\n",
  215. core->family, core->cpu_id, core->chip_id);
  216. n += scnprintf(buf + n, len - n, "processor [%d]\t: %s %s (%s ISA) %s%s%s\n",
  217. cpu_id, cpu->name, cpu->details,
  218. is_isa_arcompact() ? "ARCompact" : "ARCv2",
  219. IS_AVAIL1(cpu->isa.be, "[Big-Endian]"),
  220. IS_AVAIL3(cpu->extn.dual, cpu->extn.dual_enb, " Dual-Issue "));
  221. n += scnprintf(buf + n, len - n, "Timers\t\t: %s%s%s%s%s%s\nISA Extn\t: ",
  222. IS_AVAIL1(cpu->extn.timer0, "Timer0 "),
  223. IS_AVAIL1(cpu->extn.timer1, "Timer1 "),
  224. IS_AVAIL2(cpu->extn.rtc, "RTC [UP 64-bit] ", CONFIG_ARC_TIMERS_64BIT),
  225. IS_AVAIL2(cpu->extn.gfrc, "GFRC [SMP 64-bit] ", CONFIG_ARC_TIMERS_64BIT));
  226. n += i = scnprintf(buf + n, len - n, "%s%s%s%s%s",
  227. IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
  228. IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
  229. IS_AVAIL1(cpu->isa.unalign, "unalign (not used)"));
  230. if (i)
  231. n += scnprintf(buf + n, len - n, "\n\t\t: ");
  232. if (cpu->extn_mpy.ver) {
  233. if (cpu->extn_mpy.ver <= 0x2) { /* ARCompact */
  234. n += scnprintf(buf + n, len - n, "mpy ");
  235. } else {
  236. int opt = 2; /* stock MPY/MPYH */
  237. if (cpu->extn_mpy.dsp) /* OPT 7-9 */
  238. opt = cpu->extn_mpy.dsp + 6;
  239. n += scnprintf(buf + n, len - n, "mpy[opt %d] ", opt);
  240. }
  241. }
  242. n += scnprintf(buf + n, len - n, "%s%s%s%s%s%s%s%s\n",
  243. IS_AVAIL1(cpu->isa.div_rem, "div_rem "),
  244. IS_AVAIL1(cpu->extn.norm, "norm "),
  245. IS_AVAIL1(cpu->extn.barrel, "barrel-shift "),
  246. IS_AVAIL1(cpu->extn.swap, "swap "),
  247. IS_AVAIL1(cpu->extn.minmax, "minmax "),
  248. IS_AVAIL1(cpu->extn.crc, "crc "),
  249. IS_AVAIL2(cpu->extn.swape, "swape", CONFIG_ARC_HAS_SWAPE));
  250. if (cpu->bpu.ver)
  251. n += scnprintf(buf + n, len - n,
  252. "BPU\t\t: %s%s match, cache:%d, Predict Table:%d",
  253. IS_AVAIL1(cpu->bpu.full, "full"),
  254. IS_AVAIL1(!cpu->bpu.full, "partial"),
  255. cpu->bpu.num_cache, cpu->bpu.num_pred);
  256. if (is_isa_arcv2()) {
  257. struct bcr_lpb lpb;
  258. READ_BCR(ARC_REG_LPB_BUILD, lpb);
  259. if (lpb.ver) {
  260. unsigned int ctl;
  261. ctl = read_aux_reg(ARC_REG_LPB_CTRL);
  262. n += scnprintf(buf + n, len - n, " Loop Buffer:%d %s",
  263. lpb.entries,
  264. IS_DISABLED_RUN(!ctl));
  265. }
  266. }
  267. n += scnprintf(buf + n, len - n, "\n");
  268. return buf;
  269. }
  270. static char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
  271. {
  272. int n = 0;
  273. struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
  274. FIX_PTR(cpu);
  275. n += scnprintf(buf + n, len - n, "Vector Table\t: %#x\n", cpu->vec_base);
  276. if (cpu->extn.fpu_sp || cpu->extn.fpu_dp)
  277. n += scnprintf(buf + n, len - n, "FPU\t\t: %s%s\n",
  278. IS_AVAIL1(cpu->extn.fpu_sp, "SP "),
  279. IS_AVAIL1(cpu->extn.fpu_dp, "DP "));
  280. if (cpu->extn.debug)
  281. n += scnprintf(buf + n, len - n, "DEBUG\t\t: %s%s%s\n",
  282. IS_AVAIL1(cpu->extn.ap, "ActionPoint "),
  283. IS_AVAIL1(cpu->extn.smart, "smaRT "),
  284. IS_AVAIL1(cpu->extn.rtt, "RTT "));
  285. if (cpu->dccm.sz || cpu->iccm.sz)
  286. n += scnprintf(buf + n, len - n, "Extn [CCM]\t: DCCM @ %x, %d KB / ICCM: @ %x, %d KB\n",
  287. cpu->dccm.base_addr, TO_KB(cpu->dccm.sz),
  288. cpu->iccm.base_addr, TO_KB(cpu->iccm.sz));
  289. if (is_isa_arcv2()) {
  290. /* Error Protection: ECC/Parity */
  291. struct bcr_erp erp;
  292. READ_BCR(ARC_REG_ERP_BUILD, erp);
  293. if (erp.ver) {
  294. struct ctl_erp ctl;
  295. READ_BCR(ARC_REG_ERP_CTRL, ctl);
  296. /* inverted bits: 0 means enabled */
  297. n += scnprintf(buf + n, len - n, "Extn [ECC]\t: %s%s%s%s%s%s\n",
  298. IS_AVAIL3(erp.ic, !ctl.dpi, "IC "),
  299. IS_AVAIL3(erp.dc, !ctl.dpd, "DC "),
  300. IS_AVAIL3(erp.mmu, !ctl.mpd, "MMU "));
  301. }
  302. }
  303. n += scnprintf(buf + n, len - n, "OS ABI [v%d]\t: %s\n",
  304. EF_ARC_OSABI_CURRENT >> 8,
  305. EF_ARC_OSABI_CURRENT == EF_ARC_OSABI_V3 ?
  306. "no-legacy-syscalls" : "64-bit data any register aligned");
  307. return buf;
  308. }
  309. static void arc_chk_core_config(void)
  310. {
  311. struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
  312. int saved = 0, present = 0;
  313. char *opt_nm = NULL;
  314. if (!cpu->extn.timer0)
  315. panic("Timer0 is not present!\n");
  316. if (!cpu->extn.timer1)
  317. panic("Timer1 is not present!\n");
  318. #ifdef CONFIG_ARC_HAS_DCCM
  319. /*
  320. * DCCM can be arbit placed in hardware.
  321. * Make sure it's placement/sz matches what Linux is built with
  322. */
  323. if ((unsigned int)__arc_dccm_base != cpu->dccm.base_addr)
  324. panic("Linux built with incorrect DCCM Base address\n");
  325. if (CONFIG_ARC_DCCM_SZ != cpu->dccm.sz)
  326. panic("Linux built with incorrect DCCM Size\n");
  327. #endif
  328. #ifdef CONFIG_ARC_HAS_ICCM
  329. if (CONFIG_ARC_ICCM_SZ != cpu->iccm.sz)
  330. panic("Linux built with incorrect ICCM Size\n");
  331. #endif
  332. /*
  333. * FP hardware/software config sanity
  334. * -If hardware present, kernel needs to save/restore FPU state
  335. * -If not, it will crash trying to save/restore the non-existant regs
  336. */
  337. if (is_isa_arcompact()) {
  338. opt_nm = "CONFIG_ARC_FPU_SAVE_RESTORE";
  339. saved = IS_ENABLED(CONFIG_ARC_FPU_SAVE_RESTORE);
  340. /* only DPDP checked since SP has no arch visible regs */
  341. present = cpu->extn.fpu_dp;
  342. } else {
  343. opt_nm = "CONFIG_ARC_HAS_ACCL_REGS";
  344. saved = IS_ENABLED(CONFIG_ARC_HAS_ACCL_REGS);
  345. /* Accumulator Low:High pair (r58:59) present if DSP MPY or FPU */
  346. present = cpu->extn_mpy.dsp | cpu->extn.fpu_sp | cpu->extn.fpu_dp;
  347. }
  348. if (present && !saved)
  349. pr_warn("Enable %s for working apps\n", opt_nm);
  350. else if (!present && saved)
  351. panic("Disable %s, hardware NOT present\n", opt_nm);
  352. }
  353. /*
  354. * Initialize and setup the processor core
  355. * This is called by all the CPUs thus should not do special case stuff
  356. * such as only for boot CPU etc
  357. */
  358. void setup_processor(void)
  359. {
  360. char str[512];
  361. int cpu_id = smp_processor_id();
  362. read_arc_build_cfg_regs();
  363. arc_init_IRQ();
  364. pr_info("%s", arc_cpu_mumbojumbo(cpu_id, str, sizeof(str)));
  365. arc_mmu_init();
  366. arc_cache_init();
  367. pr_info("%s", arc_extn_mumbojumbo(cpu_id, str, sizeof(str)));
  368. pr_info("%s", arc_platform_smp_cpuinfo());
  369. arc_chk_core_config();
  370. }
  371. static inline bool uboot_arg_invalid(unsigned long addr)
  372. {
  373. /*
  374. * Check that it is a untranslated address (although MMU is not enabled
  375. * yet, it being a high address ensures this is not by fluke)
  376. */
  377. if (addr < PAGE_OFFSET)
  378. return true;
  379. /* Check that address doesn't clobber resident kernel image */
  380. return addr >= (unsigned long)_stext && addr <= (unsigned long)_end;
  381. }
  382. #define IGNORE_ARGS "Ignore U-boot args: "
  383. /* uboot_tag values for U-boot - kernel ABI revision 0; see head.S */
  384. #define UBOOT_TAG_NONE 0
  385. #define UBOOT_TAG_CMDLINE 1
  386. #define UBOOT_TAG_DTB 2
  387. void __init handle_uboot_args(void)
  388. {
  389. bool use_embedded_dtb = true;
  390. bool append_cmdline = false;
  391. #ifdef CONFIG_ARC_UBOOT_SUPPORT
  392. /* check that we know this tag */
  393. if (uboot_tag != UBOOT_TAG_NONE &&
  394. uboot_tag != UBOOT_TAG_CMDLINE &&
  395. uboot_tag != UBOOT_TAG_DTB) {
  396. pr_warn(IGNORE_ARGS "invalid uboot tag: '%08x'\n", uboot_tag);
  397. goto ignore_uboot_args;
  398. }
  399. if (uboot_tag != UBOOT_TAG_NONE &&
  400. uboot_arg_invalid((unsigned long)uboot_arg)) {
  401. pr_warn(IGNORE_ARGS "invalid uboot arg: '%px'\n", uboot_arg);
  402. goto ignore_uboot_args;
  403. }
  404. /* see if U-boot passed an external Device Tree blob */
  405. if (uboot_tag == UBOOT_TAG_DTB) {
  406. machine_desc = setup_machine_fdt((void *)uboot_arg);
  407. /* external Device Tree blob is invalid - use embedded one */
  408. use_embedded_dtb = !machine_desc;
  409. }
  410. if (uboot_tag == UBOOT_TAG_CMDLINE)
  411. append_cmdline = true;
  412. ignore_uboot_args:
  413. #endif
  414. if (use_embedded_dtb) {
  415. machine_desc = setup_machine_fdt(__dtb_start);
  416. if (!machine_desc)
  417. panic("Embedded DT invalid\n");
  418. }
  419. /*
  420. * NOTE: @boot_command_line is populated by setup_machine_fdt() so this
  421. * append processing can only happen after.
  422. */
  423. if (append_cmdline) {
  424. /* Ensure a whitespace between the 2 cmdlines */
  425. strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
  426. strlcat(boot_command_line, uboot_arg, COMMAND_LINE_SIZE);
  427. }
  428. }
  429. void __init setup_arch(char **cmdline_p)
  430. {
  431. handle_uboot_args();
  432. /* Save unparsed command line copy for /proc/cmdline */
  433. *cmdline_p = boot_command_line;
  434. /* To force early parsing of things like mem=xxx */
  435. parse_early_param();
  436. /* Platform/board specific: e.g. early console registration */
  437. if (machine_desc->init_early)
  438. machine_desc->init_early();
  439. smp_init_cpus();
  440. setup_processor();
  441. setup_arch_memory();
  442. /* copy flat DT out of .init and then unflatten it */
  443. unflatten_and_copy_device_tree();
  444. /* Can be issue if someone passes cmd line arg "ro"
  445. * But that is unlikely so keeping it as it is
  446. */
  447. root_mountflags &= ~MS_RDONLY;
  448. #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
  449. conswitchp = &dummy_con;
  450. #endif
  451. arc_unwind_init();
  452. }
  453. /*
  454. * Called from start_kernel() - boot CPU only
  455. */
  456. void __init time_init(void)
  457. {
  458. of_clk_init(NULL);
  459. timer_probe();
  460. }
  461. static int __init customize_machine(void)
  462. {
  463. if (machine_desc->init_machine)
  464. machine_desc->init_machine();
  465. return 0;
  466. }
  467. arch_initcall(customize_machine);
  468. static int __init init_late_machine(void)
  469. {
  470. if (machine_desc->init_late)
  471. machine_desc->init_late();
  472. return 0;
  473. }
  474. late_initcall(init_late_machine);
  475. /*
  476. * Get CPU information for use by the procfs.
  477. */
  478. #define cpu_to_ptr(c) ((void *)(0xFFFF0000 | (unsigned int)(c)))
  479. #define ptr_to_cpu(p) (~0xFFFF0000UL & (unsigned int)(p))
  480. static int show_cpuinfo(struct seq_file *m, void *v)
  481. {
  482. char *str;
  483. int cpu_id = ptr_to_cpu(v);
  484. struct device *cpu_dev = get_cpu_device(cpu_id);
  485. struct clk *cpu_clk;
  486. unsigned long freq = 0;
  487. if (!cpu_online(cpu_id)) {
  488. seq_printf(m, "processor [%d]\t: Offline\n", cpu_id);
  489. goto done;
  490. }
  491. str = (char *)__get_free_page(GFP_KERNEL);
  492. if (!str)
  493. goto done;
  494. seq_printf(m, arc_cpu_mumbojumbo(cpu_id, str, PAGE_SIZE));
  495. cpu_clk = clk_get(cpu_dev, NULL);
  496. if (IS_ERR(cpu_clk)) {
  497. seq_printf(m, "CPU speed \t: Cannot get clock for processor [%d]\n",
  498. cpu_id);
  499. } else {
  500. freq = clk_get_rate(cpu_clk);
  501. }
  502. if (freq)
  503. seq_printf(m, "CPU speed\t: %lu.%02lu Mhz\n",
  504. freq / 1000000, (freq / 10000) % 100);
  505. seq_printf(m, "Bogo MIPS\t: %lu.%02lu\n",
  506. loops_per_jiffy / (500000 / HZ),
  507. (loops_per_jiffy / (5000 / HZ)) % 100);
  508. seq_printf(m, arc_mmu_mumbojumbo(cpu_id, str, PAGE_SIZE));
  509. seq_printf(m, arc_cache_mumbojumbo(cpu_id, str, PAGE_SIZE));
  510. seq_printf(m, arc_extn_mumbojumbo(cpu_id, str, PAGE_SIZE));
  511. seq_printf(m, arc_platform_smp_cpuinfo());
  512. free_page((unsigned long)str);
  513. done:
  514. seq_printf(m, "\n");
  515. return 0;
  516. }
  517. static void *c_start(struct seq_file *m, loff_t *pos)
  518. {
  519. /*
  520. * Callback returns cpu-id to iterator for show routine, NULL to stop.
  521. * However since NULL is also a valid cpu-id (0), we use a round-about
  522. * way to pass it w/o having to kmalloc/free a 2 byte string.
  523. * Encode cpu-id as 0xFFcccc, which is decoded by show routine.
  524. */
  525. return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
  526. }
  527. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  528. {
  529. ++*pos;
  530. return c_start(m, pos);
  531. }
  532. static void c_stop(struct seq_file *m, void *v)
  533. {
  534. }
  535. const struct seq_operations cpuinfo_op = {
  536. .start = c_start,
  537. .next = c_next,
  538. .stop = c_stop,
  539. .show = show_cpuinfo
  540. };
  541. static DEFINE_PER_CPU(struct cpu, cpu_topology);
  542. static int __init topology_init(void)
  543. {
  544. int cpu;
  545. for_each_present_cpu(cpu)
  546. register_cpu(&per_cpu(cpu_topology, cpu), cpu);
  547. return 0;
  548. }
  549. subsys_initcall(topology_init);