setup.c 25 KB

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