setup.c 18 KB

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