setup.c 27 KB

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