setup.c 25 KB

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