setup.c 32 KB

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