setup.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/arch/arm/kernel/setup.c
  4. *
  5. * Copyright (C) 1995-2001 Russell King
  6. */
  7. #include <linux/efi.h>
  8. #include <linux/export.h>
  9. #include <linux/kernel.h>
  10. #include <linux/stddef.h>
  11. #include <linux/ioport.h>
  12. #include <linux/delay.h>
  13. #include <linux/utsname.h>
  14. #include <linux/initrd.h>
  15. #include <linux/console.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/screen_info.h>
  18. #include <linux/init.h>
  19. #include <linux/kexec.h>
  20. #include <linux/libfdt.h>
  21. #include <linux/of.h>
  22. #include <linux/of_fdt.h>
  23. #include <linux/cpu.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/smp.h>
  26. #include <linux/proc_fs.h>
  27. #include <linux/memblock.h>
  28. #include <linux/bug.h>
  29. #include <linux/compiler.h>
  30. #include <linux/sort.h>
  31. #include <linux/psci.h>
  32. #include <asm/unified.h>
  33. #include <asm/cp15.h>
  34. #include <asm/cpu.h>
  35. #include <asm/cputype.h>
  36. #include <asm/efi.h>
  37. #include <asm/elf.h>
  38. #include <asm/early_ioremap.h>
  39. #include <asm/fixmap.h>
  40. #include <asm/procinfo.h>
  41. #include <asm/psci.h>
  42. #include <asm/sections.h>
  43. #include <asm/setup.h>
  44. #include <asm/smp_plat.h>
  45. #include <asm/mach-types.h>
  46. #include <asm/cacheflush.h>
  47. #include <asm/cachetype.h>
  48. #include <asm/tlbflush.h>
  49. #include <asm/xen/hypervisor.h>
  50. #include <asm/prom.h>
  51. #include <asm/mach/arch.h>
  52. #include <asm/mach/irq.h>
  53. #include <asm/mach/time.h>
  54. #include <asm/system_info.h>
  55. #include <asm/system_misc.h>
  56. #include <asm/traps.h>
  57. #include <asm/unwind.h>
  58. #include <asm/memblock.h>
  59. #include <asm/virt.h>
  60. #include <asm/kasan.h>
  61. #include "atags.h"
  62. #if defined(CONFIG_FPE_NWFPE) || defined(CONFIG_FPE_FASTFPE)
  63. char fpe_type[8];
  64. static int __init fpe_setup(char *line)
  65. {
  66. memcpy(fpe_type, line, 8);
  67. return 1;
  68. }
  69. __setup("fpe=", fpe_setup);
  70. #endif
  71. unsigned int processor_id;
  72. EXPORT_SYMBOL(processor_id);
  73. unsigned int __machine_arch_type __read_mostly;
  74. EXPORT_SYMBOL(__machine_arch_type);
  75. unsigned int cacheid __read_mostly;
  76. EXPORT_SYMBOL(cacheid);
  77. unsigned int __atags_pointer __initdata;
  78. unsigned int system_rev;
  79. EXPORT_SYMBOL(system_rev);
  80. const char *system_serial;
  81. EXPORT_SYMBOL(system_serial);
  82. unsigned int system_serial_low;
  83. EXPORT_SYMBOL(system_serial_low);
  84. unsigned int system_serial_high;
  85. EXPORT_SYMBOL(system_serial_high);
  86. unsigned int elf_hwcap __read_mostly;
  87. EXPORT_SYMBOL(elf_hwcap);
  88. unsigned int elf_hwcap2 __read_mostly;
  89. EXPORT_SYMBOL(elf_hwcap2);
  90. #ifdef MULTI_CPU
  91. struct processor processor __ro_after_init;
  92. #if defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR)
  93. struct processor *cpu_vtable[NR_CPUS] = {
  94. [0] = &processor,
  95. };
  96. #endif
  97. #endif
  98. #ifdef MULTI_TLB
  99. struct cpu_tlb_fns cpu_tlb __ro_after_init;
  100. #endif
  101. #ifdef MULTI_USER
  102. struct cpu_user_fns cpu_user __ro_after_init;
  103. #endif
  104. #ifdef MULTI_CACHE
  105. struct cpu_cache_fns cpu_cache __ro_after_init;
  106. #endif
  107. #ifdef CONFIG_OUTER_CACHE
  108. struct outer_cache_fns outer_cache __ro_after_init;
  109. EXPORT_SYMBOL(outer_cache);
  110. #endif
  111. /*
  112. * Cached cpu_architecture() result for use by assembler code.
  113. * C code should use the cpu_architecture() function instead of accessing this
  114. * variable directly.
  115. */
  116. int __cpu_architecture __read_mostly = CPU_ARCH_UNKNOWN;
  117. struct stack {
  118. u32 irq[4];
  119. u32 abt[4];
  120. u32 und[4];
  121. u32 fiq[4];
  122. } ____cacheline_aligned;
  123. #ifndef CONFIG_CPU_V7M
  124. static struct stack stacks[NR_CPUS];
  125. #endif
  126. char elf_platform[ELF_PLATFORM_SIZE];
  127. EXPORT_SYMBOL(elf_platform);
  128. static const char *cpu_name;
  129. static const char *machine_name;
  130. static char __initdata cmd_line[COMMAND_LINE_SIZE];
  131. const struct machine_desc *machine_desc __initdata;
  132. static union { char c[4]; unsigned long l; } endian_test __initdata = { { 'l', '?', '?', 'b' } };
  133. #define ENDIANNESS ((char)endian_test.l)
  134. DEFINE_PER_CPU(struct cpuinfo_arm, cpu_data);
  135. /*
  136. * Standard memory resources
  137. */
  138. static struct resource mem_res[] = {
  139. {
  140. .name = "Video RAM",
  141. .start = 0,
  142. .end = 0,
  143. .flags = IORESOURCE_MEM
  144. },
  145. {
  146. .name = "Kernel code",
  147. .start = 0,
  148. .end = 0,
  149. .flags = IORESOURCE_SYSTEM_RAM
  150. },
  151. {
  152. .name = "Kernel data",
  153. .start = 0,
  154. .end = 0,
  155. .flags = IORESOURCE_SYSTEM_RAM
  156. }
  157. };
  158. #define video_ram mem_res[0]
  159. #define kernel_code mem_res[1]
  160. #define kernel_data mem_res[2]
  161. static struct resource io_res[] = {
  162. {
  163. .name = "reserved",
  164. .start = 0x3bc,
  165. .end = 0x3be,
  166. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  167. },
  168. {
  169. .name = "reserved",
  170. .start = 0x378,
  171. .end = 0x37f,
  172. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  173. },
  174. {
  175. .name = "reserved",
  176. .start = 0x278,
  177. .end = 0x27f,
  178. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  179. }
  180. };
  181. #define lp0 io_res[0]
  182. #define lp1 io_res[1]
  183. #define lp2 io_res[2]
  184. static const char *proc_arch[] = {
  185. "undefined/unknown",
  186. "3",
  187. "4",
  188. "4T",
  189. "5",
  190. "5T",
  191. "5TE",
  192. "5TEJ",
  193. "6TEJ",
  194. "7",
  195. "7M",
  196. "?(12)",
  197. "?(13)",
  198. "?(14)",
  199. "?(15)",
  200. "?(16)",
  201. "?(17)",
  202. };
  203. #ifdef CONFIG_CPU_V7M
  204. static int __get_cpu_architecture(void)
  205. {
  206. return CPU_ARCH_ARMv7M;
  207. }
  208. #else
  209. static int __get_cpu_architecture(void)
  210. {
  211. int cpu_arch;
  212. if ((read_cpuid_id() & 0x0008f000) == 0) {
  213. cpu_arch = CPU_ARCH_UNKNOWN;
  214. } else if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
  215. cpu_arch = (read_cpuid_id() & (1 << 23)) ? CPU_ARCH_ARMv4T : CPU_ARCH_ARMv3;
  216. } else if ((read_cpuid_id() & 0x00080000) == 0x00000000) {
  217. cpu_arch = (read_cpuid_id() >> 16) & 7;
  218. if (cpu_arch)
  219. cpu_arch += CPU_ARCH_ARMv3;
  220. } else if ((read_cpuid_id() & 0x000f0000) == 0x000f0000) {
  221. /* Revised CPUID format. Read the Memory Model Feature
  222. * Register 0 and check for VMSAv7 or PMSAv7 */
  223. unsigned int mmfr0 = read_cpuid_ext(CPUID_EXT_MMFR0);
  224. if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
  225. (mmfr0 & 0x000000f0) >= 0x00000030)
  226. cpu_arch = CPU_ARCH_ARMv7;
  227. else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
  228. (mmfr0 & 0x000000f0) == 0x00000020)
  229. cpu_arch = CPU_ARCH_ARMv6;
  230. else
  231. cpu_arch = CPU_ARCH_UNKNOWN;
  232. } else
  233. cpu_arch = CPU_ARCH_UNKNOWN;
  234. return cpu_arch;
  235. }
  236. #endif
  237. int __pure cpu_architecture(void)
  238. {
  239. BUG_ON(__cpu_architecture == CPU_ARCH_UNKNOWN);
  240. return __cpu_architecture;
  241. }
  242. static int cpu_has_aliasing_icache(unsigned int arch)
  243. {
  244. int aliasing_icache;
  245. unsigned int id_reg, num_sets, line_size;
  246. /* PIPT caches never alias. */
  247. if (icache_is_pipt())
  248. return 0;
  249. /* arch specifies the register format */
  250. switch (arch) {
  251. case CPU_ARCH_ARMv7:
  252. set_csselr(CSSELR_ICACHE | CSSELR_L1);
  253. isb();
  254. id_reg = read_ccsidr();
  255. line_size = 4 << ((id_reg & 0x7) + 2);
  256. num_sets = ((id_reg >> 13) & 0x7fff) + 1;
  257. aliasing_icache = (line_size * num_sets) > PAGE_SIZE;
  258. break;
  259. case CPU_ARCH_ARMv6:
  260. aliasing_icache = read_cpuid_cachetype() & (1 << 11);
  261. break;
  262. default:
  263. /* I-cache aliases will be handled by D-cache aliasing code */
  264. aliasing_icache = 0;
  265. }
  266. return aliasing_icache;
  267. }
  268. static void __init cacheid_init(void)
  269. {
  270. unsigned int arch = cpu_architecture();
  271. if (arch >= CPU_ARCH_ARMv6) {
  272. unsigned int cachetype = read_cpuid_cachetype();
  273. if ((arch == CPU_ARCH_ARMv7M) && !(cachetype & 0xf000f)) {
  274. cacheid = 0;
  275. } else if ((cachetype & (7 << 29)) == 4 << 29) {
  276. /* ARMv7 register format */
  277. arch = CPU_ARCH_ARMv7;
  278. cacheid = CACHEID_VIPT_NONALIASING;
  279. switch (cachetype & (3 << 14)) {
  280. case (1 << 14):
  281. cacheid |= CACHEID_ASID_TAGGED;
  282. break;
  283. case (3 << 14):
  284. cacheid |= CACHEID_PIPT;
  285. break;
  286. }
  287. } else {
  288. arch = CPU_ARCH_ARMv6;
  289. if (cachetype & (1 << 23))
  290. cacheid = CACHEID_VIPT_ALIASING;
  291. else
  292. cacheid = CACHEID_VIPT_NONALIASING;
  293. }
  294. if (cpu_has_aliasing_icache(arch))
  295. cacheid |= CACHEID_VIPT_I_ALIASING;
  296. } else {
  297. cacheid = CACHEID_VIVT;
  298. }
  299. pr_info("CPU: %s data cache, %s instruction cache\n",
  300. cache_is_vivt() ? "VIVT" :
  301. cache_is_vipt_aliasing() ? "VIPT aliasing" :
  302. cache_is_vipt_nonaliasing() ? "PIPT / VIPT nonaliasing" : "unknown",
  303. cache_is_vivt() ? "VIVT" :
  304. icache_is_vivt_asid_tagged() ? "VIVT ASID tagged" :
  305. icache_is_vipt_aliasing() ? "VIPT aliasing" :
  306. icache_is_pipt() ? "PIPT" :
  307. cache_is_vipt_nonaliasing() ? "VIPT nonaliasing" : "unknown");
  308. }
  309. /*
  310. * These functions re-use the assembly code in head.S, which
  311. * already provide the required functionality.
  312. */
  313. extern struct proc_info_list *lookup_processor_type(unsigned int);
  314. void __init early_print(const char *str, ...)
  315. {
  316. extern void printascii(const char *);
  317. char buf[256];
  318. va_list ap;
  319. va_start(ap, str);
  320. vsnprintf(buf, sizeof(buf), str, ap);
  321. va_end(ap);
  322. #ifdef CONFIG_DEBUG_LL
  323. printascii(buf);
  324. #endif
  325. printk("%s", buf);
  326. }
  327. #ifdef CONFIG_ARM_PATCH_IDIV
  328. static inline u32 __attribute_const__ sdiv_instruction(void)
  329. {
  330. if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) {
  331. /* "sdiv r0, r0, r1" */
  332. u32 insn = __opcode_thumb32_compose(0xfb90, 0xf0f1);
  333. return __opcode_to_mem_thumb32(insn);
  334. }
  335. /* "sdiv r0, r0, r1" */
  336. return __opcode_to_mem_arm(0xe710f110);
  337. }
  338. static inline u32 __attribute_const__ udiv_instruction(void)
  339. {
  340. if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) {
  341. /* "udiv r0, r0, r1" */
  342. u32 insn = __opcode_thumb32_compose(0xfbb0, 0xf0f1);
  343. return __opcode_to_mem_thumb32(insn);
  344. }
  345. /* "udiv r0, r0, r1" */
  346. return __opcode_to_mem_arm(0xe730f110);
  347. }
  348. static inline u32 __attribute_const__ bx_lr_instruction(void)
  349. {
  350. if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) {
  351. /* "bx lr; nop" */
  352. u32 insn = __opcode_thumb32_compose(0x4770, 0x46c0);
  353. return __opcode_to_mem_thumb32(insn);
  354. }
  355. /* "bx lr" */
  356. return __opcode_to_mem_arm(0xe12fff1e);
  357. }
  358. static void __init patch_aeabi_idiv(void)
  359. {
  360. extern void __aeabi_uidiv(void);
  361. extern void __aeabi_idiv(void);
  362. uintptr_t fn_addr;
  363. unsigned int mask;
  364. mask = IS_ENABLED(CONFIG_THUMB2_KERNEL) ? HWCAP_IDIVT : HWCAP_IDIVA;
  365. if (!(elf_hwcap & mask))
  366. return;
  367. pr_info("CPU: div instructions available: patching division code\n");
  368. fn_addr = ((uintptr_t)&__aeabi_uidiv) & ~1;
  369. asm ("" : "+g" (fn_addr));
  370. ((u32 *)fn_addr)[0] = udiv_instruction();
  371. ((u32 *)fn_addr)[1] = bx_lr_instruction();
  372. flush_icache_range(fn_addr, fn_addr + 8);
  373. fn_addr = ((uintptr_t)&__aeabi_idiv) & ~1;
  374. asm ("" : "+g" (fn_addr));
  375. ((u32 *)fn_addr)[0] = sdiv_instruction();
  376. ((u32 *)fn_addr)[1] = bx_lr_instruction();
  377. flush_icache_range(fn_addr, fn_addr + 8);
  378. }
  379. #else
  380. static inline void patch_aeabi_idiv(void) { }
  381. #endif
  382. static void __init cpuid_init_hwcaps(void)
  383. {
  384. int block;
  385. u32 isar5;
  386. u32 isar6;
  387. u32 pfr2;
  388. if (cpu_architecture() < CPU_ARCH_ARMv7)
  389. return;
  390. block = cpuid_feature_extract(CPUID_EXT_ISAR0, 24);
  391. if (block >= 2)
  392. elf_hwcap |= HWCAP_IDIVA;
  393. if (block >= 1)
  394. elf_hwcap |= HWCAP_IDIVT;
  395. /* LPAE implies atomic ldrd/strd instructions */
  396. block = cpuid_feature_extract(CPUID_EXT_MMFR0, 0);
  397. if (block >= 5)
  398. elf_hwcap |= HWCAP_LPAE;
  399. /* check for supported v8 Crypto instructions */
  400. isar5 = read_cpuid_ext(CPUID_EXT_ISAR5);
  401. block = cpuid_feature_extract_field(isar5, 4);
  402. if (block >= 2)
  403. elf_hwcap2 |= HWCAP2_PMULL;
  404. if (block >= 1)
  405. elf_hwcap2 |= HWCAP2_AES;
  406. block = cpuid_feature_extract_field(isar5, 8);
  407. if (block >= 1)
  408. elf_hwcap2 |= HWCAP2_SHA1;
  409. block = cpuid_feature_extract_field(isar5, 12);
  410. if (block >= 1)
  411. elf_hwcap2 |= HWCAP2_SHA2;
  412. block = cpuid_feature_extract_field(isar5, 16);
  413. if (block >= 1)
  414. elf_hwcap2 |= HWCAP2_CRC32;
  415. /* Check for Speculation barrier instruction */
  416. isar6 = read_cpuid_ext(CPUID_EXT_ISAR6);
  417. block = cpuid_feature_extract_field(isar6, 12);
  418. if (block >= 1)
  419. elf_hwcap2 |= HWCAP2_SB;
  420. /* Check for Speculative Store Bypassing control */
  421. pfr2 = read_cpuid_ext(CPUID_EXT_PFR2);
  422. block = cpuid_feature_extract_field(pfr2, 4);
  423. if (block >= 1)
  424. elf_hwcap2 |= HWCAP2_SSBS;
  425. }
  426. static void __init elf_hwcap_fixup(void)
  427. {
  428. unsigned id = read_cpuid_id();
  429. /*
  430. * HWCAP_TLS is available only on 1136 r1p0 and later,
  431. * see also kuser_get_tls_init.
  432. */
  433. if (read_cpuid_part() == ARM_CPU_PART_ARM1136 &&
  434. ((id >> 20) & 3) == 0) {
  435. elf_hwcap &= ~HWCAP_TLS;
  436. return;
  437. }
  438. /* Verify if CPUID scheme is implemented */
  439. if ((id & 0x000f0000) != 0x000f0000)
  440. return;
  441. /*
  442. * If the CPU supports LDREX/STREX and LDREXB/STREXB,
  443. * avoid advertising SWP; it may not be atomic with
  444. * multiprocessing cores.
  445. */
  446. if (cpuid_feature_extract(CPUID_EXT_ISAR3, 12) > 1 ||
  447. (cpuid_feature_extract(CPUID_EXT_ISAR3, 12) == 1 &&
  448. cpuid_feature_extract(CPUID_EXT_ISAR4, 20) >= 3))
  449. elf_hwcap &= ~HWCAP_SWP;
  450. }
  451. /*
  452. * cpu_init - initialise one CPU.
  453. *
  454. * cpu_init sets up the per-CPU stacks.
  455. */
  456. void notrace cpu_init(void)
  457. {
  458. #ifndef CONFIG_CPU_V7M
  459. unsigned int cpu = smp_processor_id();
  460. struct stack *stk = &stacks[cpu];
  461. if (cpu >= NR_CPUS) {
  462. pr_crit("CPU%u: bad primary CPU number\n", cpu);
  463. BUG();
  464. }
  465. /*
  466. * This only works on resume and secondary cores. For booting on the
  467. * boot cpu, smp_prepare_boot_cpu is called after percpu area setup.
  468. */
  469. set_my_cpu_offset(per_cpu_offset(cpu));
  470. cpu_proc_init();
  471. /*
  472. * Define the placement constraint for the inline asm directive below.
  473. * In Thumb-2, msr with an immediate value is not allowed.
  474. */
  475. #ifdef CONFIG_THUMB2_KERNEL
  476. #define PLC_l "l"
  477. #define PLC_r "r"
  478. #else
  479. #define PLC_l "I"
  480. #define PLC_r "I"
  481. #endif
  482. /*
  483. * setup stacks for re-entrant exception handlers
  484. */
  485. __asm__ (
  486. "msr cpsr_c, %1\n\t"
  487. "add r14, %0, %2\n\t"
  488. "mov sp, r14\n\t"
  489. "msr cpsr_c, %3\n\t"
  490. "add r14, %0, %4\n\t"
  491. "mov sp, r14\n\t"
  492. "msr cpsr_c, %5\n\t"
  493. "add r14, %0, %6\n\t"
  494. "mov sp, r14\n\t"
  495. "msr cpsr_c, %7\n\t"
  496. "add r14, %0, %8\n\t"
  497. "mov sp, r14\n\t"
  498. "msr cpsr_c, %9"
  499. :
  500. : "r" (stk),
  501. PLC_r (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
  502. "I" (offsetof(struct stack, irq[0])),
  503. PLC_r (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
  504. "I" (offsetof(struct stack, abt[0])),
  505. PLC_r (PSR_F_BIT | PSR_I_BIT | UND_MODE),
  506. "I" (offsetof(struct stack, und[0])),
  507. PLC_r (PSR_F_BIT | PSR_I_BIT | FIQ_MODE),
  508. "I" (offsetof(struct stack, fiq[0])),
  509. PLC_l (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
  510. : "r14");
  511. #endif
  512. }
  513. u32 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = MPIDR_INVALID };
  514. void __init smp_setup_processor_id(void)
  515. {
  516. int i;
  517. u32 mpidr = is_smp() ? read_cpuid_mpidr() & MPIDR_HWID_BITMASK : 0;
  518. u32 cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
  519. cpu_logical_map(0) = cpu;
  520. for (i = 1; i < nr_cpu_ids; ++i)
  521. cpu_logical_map(i) = i == cpu ? 0 : i;
  522. /*
  523. * clear __my_cpu_offset on boot CPU to avoid hang caused by
  524. * using percpu variable early, for example, lockdep will
  525. * access percpu variable inside lock_release
  526. */
  527. set_my_cpu_offset(0);
  528. pr_info("Booting Linux on physical CPU 0x%x\n", mpidr);
  529. }
  530. struct mpidr_hash mpidr_hash;
  531. #ifdef CONFIG_SMP
  532. /**
  533. * smp_build_mpidr_hash - Pre-compute shifts required at each affinity
  534. * level in order to build a linear index from an
  535. * MPIDR value. Resulting algorithm is a collision
  536. * free hash carried out through shifting and ORing
  537. */
  538. static void __init smp_build_mpidr_hash(void)
  539. {
  540. u32 i, affinity;
  541. u32 fs[3], bits[3], ls, mask = 0;
  542. /*
  543. * Pre-scan the list of MPIDRS and filter out bits that do
  544. * not contribute to affinity levels, ie they never toggle.
  545. */
  546. for_each_possible_cpu(i)
  547. mask |= (cpu_logical_map(i) ^ cpu_logical_map(0));
  548. pr_debug("mask of set bits 0x%x\n", mask);
  549. /*
  550. * Find and stash the last and first bit set at all affinity levels to
  551. * check how many bits are required to represent them.
  552. */
  553. for (i = 0; i < 3; i++) {
  554. affinity = MPIDR_AFFINITY_LEVEL(mask, i);
  555. /*
  556. * Find the MSB bit and LSB bits position
  557. * to determine how many bits are required
  558. * to express the affinity level.
  559. */
  560. ls = fls(affinity);
  561. fs[i] = affinity ? ffs(affinity) - 1 : 0;
  562. bits[i] = ls - fs[i];
  563. }
  564. /*
  565. * An index can be created from the MPIDR by isolating the
  566. * significant bits at each affinity level and by shifting
  567. * them in order to compress the 24 bits values space to a
  568. * compressed set of values. This is equivalent to hashing
  569. * the MPIDR through shifting and ORing. It is a collision free
  570. * hash though not minimal since some levels might contain a number
  571. * of CPUs that is not an exact power of 2 and their bit
  572. * representation might contain holes, eg MPIDR[7:0] = {0x2, 0x80}.
  573. */
  574. mpidr_hash.shift_aff[0] = fs[0];
  575. mpidr_hash.shift_aff[1] = MPIDR_LEVEL_BITS + fs[1] - bits[0];
  576. mpidr_hash.shift_aff[2] = 2*MPIDR_LEVEL_BITS + fs[2] -
  577. (bits[1] + bits[0]);
  578. mpidr_hash.mask = mask;
  579. mpidr_hash.bits = bits[2] + bits[1] + bits[0];
  580. pr_debug("MPIDR hash: aff0[%u] aff1[%u] aff2[%u] mask[0x%x] bits[%u]\n",
  581. mpidr_hash.shift_aff[0],
  582. mpidr_hash.shift_aff[1],
  583. mpidr_hash.shift_aff[2],
  584. mpidr_hash.mask,
  585. mpidr_hash.bits);
  586. /*
  587. * 4x is an arbitrary value used to warn on a hash table much bigger
  588. * than expected on most systems.
  589. */
  590. if (mpidr_hash_size() > 4 * num_possible_cpus())
  591. pr_warn("Large number of MPIDR hash buckets detected\n");
  592. sync_cache_w(&mpidr_hash);
  593. }
  594. #endif
  595. /*
  596. * locate processor in the list of supported processor types. The linker
  597. * builds this table for us from the entries in arch/arm/mm/proc-*.S
  598. */
  599. struct proc_info_list *lookup_processor(u32 midr)
  600. {
  601. struct proc_info_list *list = lookup_processor_type(midr);
  602. if (!list) {
  603. pr_err("CPU%u: configuration botched (ID %08x), CPU halted\n",
  604. smp_processor_id(), midr);
  605. while (1)
  606. /* can't use cpu_relax() here as it may require MMU setup */;
  607. }
  608. return list;
  609. }
  610. static void __init setup_processor(void)
  611. {
  612. unsigned int midr = read_cpuid_id();
  613. struct proc_info_list *list = lookup_processor(midr);
  614. cpu_name = list->cpu_name;
  615. __cpu_architecture = __get_cpu_architecture();
  616. init_proc_vtable(list->proc);
  617. #ifdef MULTI_TLB
  618. cpu_tlb = *list->tlb;
  619. #endif
  620. #ifdef MULTI_USER
  621. cpu_user = *list->user;
  622. #endif
  623. #ifdef MULTI_CACHE
  624. cpu_cache = *list->cache;
  625. #endif
  626. pr_info("CPU: %s [%08x] revision %d (ARMv%s), cr=%08lx\n",
  627. list->cpu_name, midr, midr & 15,
  628. proc_arch[cpu_architecture()], get_cr());
  629. snprintf(init_utsname()->machine, __NEW_UTS_LEN + 1, "%s%c",
  630. list->arch_name, ENDIANNESS);
  631. snprintf(elf_platform, ELF_PLATFORM_SIZE, "%s%c",
  632. list->elf_name, ENDIANNESS);
  633. elf_hwcap = list->elf_hwcap;
  634. cpuid_init_hwcaps();
  635. patch_aeabi_idiv();
  636. #ifndef CONFIG_ARM_THUMB
  637. elf_hwcap &= ~(HWCAP_THUMB | HWCAP_IDIVT);
  638. #endif
  639. #ifdef CONFIG_MMU
  640. init_default_cache_policy(list->__cpu_mm_mmu_flags);
  641. #endif
  642. erratum_a15_798181_init();
  643. elf_hwcap_fixup();
  644. cacheid_init();
  645. cpu_init();
  646. }
  647. void __init dump_machine_table(void)
  648. {
  649. const struct machine_desc *p;
  650. early_print("Available machine support:\n\nID (hex)\tNAME\n");
  651. for_each_machine_desc(p)
  652. early_print("%08x\t%s\n", p->nr, p->name);
  653. early_print("\nPlease check your kernel config and/or bootloader.\n");
  654. while (true)
  655. /* can't use cpu_relax() here as it may require MMU setup */;
  656. }
  657. int __init arm_add_memory(u64 start, u64 size)
  658. {
  659. u64 aligned_start;
  660. /*
  661. * Ensure that start/size are aligned to a page boundary.
  662. * Size is rounded down, start is rounded up.
  663. */
  664. aligned_start = PAGE_ALIGN(start);
  665. if (aligned_start > start + size)
  666. size = 0;
  667. else
  668. size -= aligned_start - start;
  669. #ifndef CONFIG_PHYS_ADDR_T_64BIT
  670. if (aligned_start > ULONG_MAX) {
  671. pr_crit("Ignoring memory at 0x%08llx outside 32-bit physical address space\n",
  672. start);
  673. return -EINVAL;
  674. }
  675. if (aligned_start + size > ULONG_MAX) {
  676. pr_crit("Truncating memory at 0x%08llx to fit in 32-bit physical address space\n",
  677. (long long)start);
  678. /*
  679. * To ensure bank->start + bank->size is representable in
  680. * 32 bits, we use ULONG_MAX as the upper limit rather than 4GB.
  681. * This means we lose a page after masking.
  682. */
  683. size = ULONG_MAX - aligned_start;
  684. }
  685. #endif
  686. if (aligned_start < PHYS_OFFSET) {
  687. if (aligned_start + size <= PHYS_OFFSET) {
  688. pr_info("Ignoring memory below PHYS_OFFSET: 0x%08llx-0x%08llx\n",
  689. aligned_start, aligned_start + size);
  690. return -EINVAL;
  691. }
  692. pr_info("Ignoring memory below PHYS_OFFSET: 0x%08llx-0x%08llx\n",
  693. aligned_start, (u64)PHYS_OFFSET);
  694. size -= PHYS_OFFSET - aligned_start;
  695. aligned_start = PHYS_OFFSET;
  696. }
  697. start = aligned_start;
  698. size = size & ~(phys_addr_t)(PAGE_SIZE - 1);
  699. /*
  700. * Check whether this memory region has non-zero size or
  701. * invalid node number.
  702. */
  703. if (size == 0)
  704. return -EINVAL;
  705. memblock_add(start, size);
  706. return 0;
  707. }
  708. /*
  709. * Pick out the memory size. We look for mem=size@start,
  710. * where start and size are "size[KkMm]"
  711. */
  712. static int __init early_mem(char *p)
  713. {
  714. static int usermem __initdata = 0;
  715. u64 size;
  716. u64 start;
  717. char *endp;
  718. /*
  719. * If the user specifies memory size, we
  720. * blow away any automatically generated
  721. * size.
  722. */
  723. if (usermem == 0) {
  724. usermem = 1;
  725. memblock_remove(memblock_start_of_DRAM(),
  726. memblock_end_of_DRAM() - memblock_start_of_DRAM());
  727. }
  728. start = PHYS_OFFSET;
  729. size = memparse(p, &endp);
  730. if (*endp == '@')
  731. start = memparse(endp + 1, NULL);
  732. arm_add_memory(start, size);
  733. return 0;
  734. }
  735. early_param("mem", early_mem);
  736. static void __init request_standard_resources(const struct machine_desc *mdesc)
  737. {
  738. phys_addr_t start, end, res_end;
  739. struct resource *res;
  740. u64 i;
  741. kernel_code.start = virt_to_phys(_text);
  742. kernel_code.end = virt_to_phys(__init_begin - 1);
  743. kernel_data.start = virt_to_phys(_sdata);
  744. kernel_data.end = virt_to_phys(_end - 1);
  745. for_each_mem_range(i, &start, &end) {
  746. unsigned long boot_alias_start;
  747. /*
  748. * In memblock, end points to the first byte after the
  749. * range while in resourses, end points to the last byte in
  750. * the range.
  751. */
  752. res_end = end - 1;
  753. /*
  754. * Some systems have a special memory alias which is only
  755. * used for booting. We need to advertise this region to
  756. * kexec-tools so they know where bootable RAM is located.
  757. */
  758. boot_alias_start = phys_to_idmap(start);
  759. if (arm_has_idmap_alias() && boot_alias_start != IDMAP_INVALID_ADDR) {
  760. res = memblock_alloc(sizeof(*res), SMP_CACHE_BYTES);
  761. if (!res)
  762. panic("%s: Failed to allocate %zu bytes\n",
  763. __func__, sizeof(*res));
  764. res->name = "System RAM (boot alias)";
  765. res->start = boot_alias_start;
  766. res->end = phys_to_idmap(res_end);
  767. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  768. request_resource(&iomem_resource, res);
  769. }
  770. res = memblock_alloc(sizeof(*res), SMP_CACHE_BYTES);
  771. if (!res)
  772. panic("%s: Failed to allocate %zu bytes\n", __func__,
  773. sizeof(*res));
  774. res->name = "System RAM";
  775. res->start = start;
  776. res->end = res_end;
  777. res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
  778. request_resource(&iomem_resource, res);
  779. if (kernel_code.start >= res->start &&
  780. kernel_code.end <= res->end)
  781. request_resource(res, &kernel_code);
  782. if (kernel_data.start >= res->start &&
  783. kernel_data.end <= res->end)
  784. request_resource(res, &kernel_data);
  785. }
  786. if (mdesc->video_start) {
  787. video_ram.start = mdesc->video_start;
  788. video_ram.end = mdesc->video_end;
  789. request_resource(&iomem_resource, &video_ram);
  790. }
  791. /*
  792. * Some machines don't have the possibility of ever
  793. * possessing lp0, lp1 or lp2
  794. */
  795. if (mdesc->reserve_lp0)
  796. request_resource(&ioport_resource, &lp0);
  797. if (mdesc->reserve_lp1)
  798. request_resource(&ioport_resource, &lp1);
  799. if (mdesc->reserve_lp2)
  800. request_resource(&ioport_resource, &lp2);
  801. }
  802. #if defined(CONFIG_VGA_CONSOLE)
  803. struct screen_info vgacon_screen_info = {
  804. .orig_video_lines = 30,
  805. .orig_video_cols = 80,
  806. .orig_video_mode = 0,
  807. .orig_video_ega_bx = 0,
  808. .orig_video_isVGA = 1,
  809. .orig_video_points = 8
  810. };
  811. #endif
  812. static int __init customize_machine(void)
  813. {
  814. /*
  815. * customizes platform devices, or adds new ones
  816. * On DT based machines, we fall back to populating the
  817. * machine from the device tree, if no callback is provided,
  818. * otherwise we would always need an init_machine callback.
  819. */
  820. if (machine_desc->init_machine)
  821. machine_desc->init_machine();
  822. return 0;
  823. }
  824. arch_initcall(customize_machine);
  825. static int __init init_machine_late(void)
  826. {
  827. struct device_node *root;
  828. int ret;
  829. if (machine_desc->init_late)
  830. machine_desc->init_late();
  831. root = of_find_node_by_path("/");
  832. if (root) {
  833. ret = of_property_read_string(root, "serial-number",
  834. &system_serial);
  835. if (ret)
  836. system_serial = NULL;
  837. }
  838. if (!system_serial)
  839. system_serial = kasprintf(GFP_KERNEL, "%08x%08x",
  840. system_serial_high,
  841. system_serial_low);
  842. return 0;
  843. }
  844. late_initcall(init_machine_late);
  845. #ifdef CONFIG_CRASH_RESERVE
  846. /*
  847. * The crash region must be aligned to 128MB to avoid
  848. * zImage relocating below the reserved region.
  849. */
  850. #define CRASH_ALIGN (128 << 20)
  851. static inline unsigned long long get_total_mem(void)
  852. {
  853. unsigned long total;
  854. total = max_low_pfn - min_low_pfn;
  855. return total << PAGE_SHIFT;
  856. }
  857. /**
  858. * reserve_crashkernel() - reserves memory are for crash kernel
  859. *
  860. * This function reserves memory area given in "crashkernel=" kernel command
  861. * line parameter. The memory reserved is used by a dump capture kernel when
  862. * primary kernel is crashing.
  863. */
  864. static void __init reserve_crashkernel(void)
  865. {
  866. unsigned long long crash_size, crash_base;
  867. unsigned long long total_mem;
  868. int ret;
  869. total_mem = get_total_mem();
  870. ret = parse_crashkernel(boot_command_line, total_mem,
  871. &crash_size, &crash_base,
  872. NULL, NULL);
  873. /* invalid value specified or crashkernel=0 */
  874. if (ret || !crash_size)
  875. return;
  876. if (crash_base <= 0) {
  877. unsigned long long crash_max = idmap_to_phys((u32)~0);
  878. unsigned long long lowmem_max = __pa(high_memory - 1) + 1;
  879. if (crash_max > lowmem_max)
  880. crash_max = lowmem_max;
  881. crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN,
  882. CRASH_ALIGN, crash_max);
  883. if (!crash_base) {
  884. pr_err("crashkernel reservation failed - No suitable area found.\n");
  885. return;
  886. }
  887. } else {
  888. unsigned long long crash_max = crash_base + crash_size;
  889. unsigned long long start;
  890. start = memblock_phys_alloc_range(crash_size, SECTION_SIZE,
  891. crash_base, crash_max);
  892. if (!start) {
  893. pr_err("crashkernel reservation failed - memory is in use.\n");
  894. return;
  895. }
  896. }
  897. pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n",
  898. (unsigned long)(crash_size >> 20),
  899. (unsigned long)(crash_base >> 20),
  900. (unsigned long)(total_mem >> 20));
  901. /* The crashk resource must always be located in normal mem */
  902. crashk_res.start = crash_base;
  903. crashk_res.end = crash_base + crash_size - 1;
  904. insert_resource(&iomem_resource, &crashk_res);
  905. if (arm_has_idmap_alias()) {
  906. /*
  907. * If we have a special RAM alias for use at boot, we
  908. * need to advertise to kexec tools where the alias is.
  909. */
  910. static struct resource crashk_boot_res = {
  911. .name = "Crash kernel (boot alias)",
  912. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  913. };
  914. crashk_boot_res.start = phys_to_idmap(crash_base);
  915. crashk_boot_res.end = crashk_boot_res.start + crash_size - 1;
  916. insert_resource(&iomem_resource, &crashk_boot_res);
  917. }
  918. }
  919. #else
  920. static inline void reserve_crashkernel(void) {}
  921. #endif /* CONFIG_CRASH_RESERVE*/
  922. void __init hyp_mode_check(void)
  923. {
  924. #ifdef CONFIG_ARM_VIRT_EXT
  925. sync_boot_mode();
  926. if (is_hyp_mode_available()) {
  927. pr_info("CPU: All CPU(s) started in HYP mode.\n");
  928. pr_info("CPU: Virtualization extensions available.\n");
  929. } else if (is_hyp_mode_mismatched()) {
  930. pr_warn("CPU: WARNING: CPU(s) started in wrong/inconsistent modes (primary CPU mode 0x%x)\n",
  931. __boot_cpu_mode & MODE_MASK);
  932. pr_warn("CPU: This may indicate a broken bootloader or firmware.\n");
  933. } else
  934. pr_info("CPU: All CPU(s) started in SVC mode.\n");
  935. #endif
  936. }
  937. static void (*__arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
  938. static int arm_restart(struct notifier_block *nb, unsigned long action,
  939. void *data)
  940. {
  941. __arm_pm_restart(action, data);
  942. return NOTIFY_DONE;
  943. }
  944. static struct notifier_block arm_restart_nb = {
  945. .notifier_call = arm_restart,
  946. .priority = 128,
  947. };
  948. void __init setup_arch(char **cmdline_p)
  949. {
  950. const struct machine_desc *mdesc = NULL;
  951. void *atags_vaddr = NULL;
  952. if (__atags_pointer)
  953. atags_vaddr = FDT_VIRT_BASE(__atags_pointer);
  954. setup_processor();
  955. if (atags_vaddr) {
  956. mdesc = setup_machine_fdt(atags_vaddr);
  957. if (mdesc)
  958. memblock_reserve(__atags_pointer,
  959. fdt_totalsize(atags_vaddr));
  960. }
  961. if (!mdesc)
  962. mdesc = setup_machine_tags(atags_vaddr, __machine_arch_type);
  963. if (!mdesc) {
  964. early_print("\nError: invalid dtb and unrecognized/unsupported machine ID\n");
  965. early_print(" r1=0x%08x, r2=0x%08x\n", __machine_arch_type,
  966. __atags_pointer);
  967. if (__atags_pointer)
  968. early_print(" r2[]=%*ph\n", 16, atags_vaddr);
  969. dump_machine_table();
  970. }
  971. machine_desc = mdesc;
  972. machine_name = mdesc->name;
  973. dump_stack_set_arch_desc("%s", mdesc->name);
  974. if (mdesc->reboot_mode != REBOOT_HARD)
  975. reboot_mode = mdesc->reboot_mode;
  976. setup_initial_init_mm(_text, _etext, _edata, _end);
  977. /* populate cmd_line too for later use, preserving boot_command_line */
  978. strscpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
  979. *cmdline_p = cmd_line;
  980. early_fixmap_init();
  981. early_ioremap_init();
  982. parse_early_param();
  983. #ifdef CONFIG_MMU
  984. early_mm_init(mdesc);
  985. #endif
  986. setup_dma_zone(mdesc);
  987. xen_early_init();
  988. arm_efi_init();
  989. /*
  990. * Make sure the calculation for lowmem/highmem is set appropriately
  991. * before reserving/allocating any memory
  992. */
  993. adjust_lowmem_bounds();
  994. arm_memblock_init(mdesc);
  995. /* Memory may have been removed so recalculate the bounds. */
  996. adjust_lowmem_bounds();
  997. early_ioremap_reset();
  998. paging_init(mdesc);
  999. kasan_init();
  1000. request_standard_resources(mdesc);
  1001. if (mdesc->restart) {
  1002. __arm_pm_restart = mdesc->restart;
  1003. register_restart_handler(&arm_restart_nb);
  1004. }
  1005. unflatten_device_tree();
  1006. arm_dt_init_cpu_maps();
  1007. psci_dt_init();
  1008. #ifdef CONFIG_SMP
  1009. if (is_smp()) {
  1010. if (!mdesc->smp_init || !mdesc->smp_init()) {
  1011. if (psci_smp_available())
  1012. smp_set_ops(&psci_smp_ops);
  1013. else if (mdesc->smp)
  1014. smp_set_ops(mdesc->smp);
  1015. }
  1016. smp_init_cpus();
  1017. smp_build_mpidr_hash();
  1018. }
  1019. #endif
  1020. if (!is_smp())
  1021. hyp_mode_check();
  1022. reserve_crashkernel();
  1023. #ifdef CONFIG_VT
  1024. #if defined(CONFIG_VGA_CONSOLE)
  1025. vgacon_register_screen(&vgacon_screen_info);
  1026. #endif
  1027. #endif
  1028. if (mdesc->init_early)
  1029. mdesc->init_early();
  1030. }
  1031. bool arch_cpu_is_hotpluggable(int num)
  1032. {
  1033. return platform_can_hotplug_cpu(num);
  1034. }
  1035. #ifdef CONFIG_HAVE_PROC_CPU
  1036. static int __init proc_cpu_init(void)
  1037. {
  1038. struct proc_dir_entry *res;
  1039. res = proc_mkdir("cpu", NULL);
  1040. if (!res)
  1041. return -ENOMEM;
  1042. return 0;
  1043. }
  1044. fs_initcall(proc_cpu_init);
  1045. #endif
  1046. static const char *hwcap_str[] = {
  1047. "swp",
  1048. "half",
  1049. "thumb",
  1050. "26bit",
  1051. "fastmult",
  1052. "fpa",
  1053. "vfp",
  1054. "edsp",
  1055. "java",
  1056. "iwmmxt",
  1057. "crunch",
  1058. "thumbee",
  1059. "neon",
  1060. "vfpv3",
  1061. "vfpv3d16",
  1062. "tls",
  1063. "vfpv4",
  1064. "idiva",
  1065. "idivt",
  1066. "vfpd32",
  1067. "lpae",
  1068. "evtstrm",
  1069. "fphp",
  1070. "asimdhp",
  1071. "asimddp",
  1072. "asimdfhm",
  1073. "asimdbf16",
  1074. "i8mm",
  1075. NULL
  1076. };
  1077. static const char *hwcap2_str[] = {
  1078. "aes",
  1079. "pmull",
  1080. "sha1",
  1081. "sha2",
  1082. "crc32",
  1083. "sb",
  1084. "ssbs",
  1085. NULL
  1086. };
  1087. static int c_show(struct seq_file *m, void *v)
  1088. {
  1089. int i, j;
  1090. u32 cpuid;
  1091. for_each_online_cpu(i) {
  1092. /*
  1093. * glibc reads /proc/cpuinfo to determine the number of
  1094. * online processors, looking for lines beginning with
  1095. * "processor". Give glibc what it expects.
  1096. */
  1097. seq_printf(m, "processor\t: %d\n", i);
  1098. cpuid = is_smp() ? per_cpu(cpu_data, i).cpuid : read_cpuid_id();
  1099. seq_printf(m, "model name\t: %s rev %d (%s)\n",
  1100. cpu_name, cpuid & 15, elf_platform);
  1101. #if defined(CONFIG_SMP)
  1102. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
  1103. per_cpu(cpu_data, i).loops_per_jiffy / (500000UL/HZ),
  1104. (per_cpu(cpu_data, i).loops_per_jiffy / (5000UL/HZ)) % 100);
  1105. #else
  1106. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
  1107. loops_per_jiffy / (500000/HZ),
  1108. (loops_per_jiffy / (5000/HZ)) % 100);
  1109. #endif
  1110. /* dump out the processor features */
  1111. seq_puts(m, "Features\t: ");
  1112. for (j = 0; hwcap_str[j]; j++)
  1113. if (elf_hwcap & (1 << j))
  1114. seq_printf(m, "%s ", hwcap_str[j]);
  1115. for (j = 0; hwcap2_str[j]; j++)
  1116. if (elf_hwcap2 & (1 << j))
  1117. seq_printf(m, "%s ", hwcap2_str[j]);
  1118. seq_printf(m, "\nCPU implementer\t: 0x%02x\n", cpuid >> 24);
  1119. seq_printf(m, "CPU architecture: %s\n",
  1120. proc_arch[cpu_architecture()]);
  1121. if ((cpuid & 0x0008f000) == 0x00000000) {
  1122. /* pre-ARM7 */
  1123. seq_printf(m, "CPU part\t: %07x\n", cpuid >> 4);
  1124. } else {
  1125. if ((cpuid & 0x0008f000) == 0x00007000) {
  1126. /* ARM7 */
  1127. seq_printf(m, "CPU variant\t: 0x%02x\n",
  1128. (cpuid >> 16) & 127);
  1129. } else {
  1130. /* post-ARM7 */
  1131. seq_printf(m, "CPU variant\t: 0x%x\n",
  1132. (cpuid >> 20) & 15);
  1133. }
  1134. seq_printf(m, "CPU part\t: 0x%03x\n",
  1135. (cpuid >> 4) & 0xfff);
  1136. }
  1137. seq_printf(m, "CPU revision\t: %d\n\n", cpuid & 15);
  1138. }
  1139. seq_printf(m, "Hardware\t: %s\n", machine_name);
  1140. seq_printf(m, "Revision\t: %04x\n", system_rev);
  1141. seq_printf(m, "Serial\t\t: %s\n", system_serial);
  1142. return 0;
  1143. }
  1144. static void *c_start(struct seq_file *m, loff_t *pos)
  1145. {
  1146. return *pos < 1 ? (void *)1 : NULL;
  1147. }
  1148. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  1149. {
  1150. ++*pos;
  1151. return NULL;
  1152. }
  1153. static void c_stop(struct seq_file *m, void *v)
  1154. {
  1155. }
  1156. const struct seq_operations cpuinfo_op = {
  1157. .start = c_start,
  1158. .next = c_next,
  1159. .stop = c_stop,
  1160. .show = c_show
  1161. };