setup.c 32 KB

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