setup.c 31 KB

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