setup.c 31 KB

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