setup.c 17 KB

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