setup.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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. static void __init setup_processor(void)
  418. {
  419. struct proc_info_list *list;
  420. /*
  421. * locate processor in the list of supported processor
  422. * types. The linker builds this table for us from the
  423. * entries in arch/arm/mm/proc-*.S
  424. */
  425. list = lookup_processor_type(read_cpuid_id());
  426. if (!list) {
  427. printk("CPU configuration botched (ID %08x), unable "
  428. "to continue.\n", read_cpuid_id());
  429. while (1);
  430. }
  431. cpu_name = list->cpu_name;
  432. __cpu_architecture = __get_cpu_architecture();
  433. #ifdef MULTI_CPU
  434. processor = *list->proc;
  435. #endif
  436. #ifdef MULTI_TLB
  437. cpu_tlb = *list->tlb;
  438. #endif
  439. #ifdef MULTI_USER
  440. cpu_user = *list->user;
  441. #endif
  442. #ifdef MULTI_CACHE
  443. cpu_cache = *list->cache;
  444. #endif
  445. printk("CPU: %s [%08x] revision %d (ARMv%s), cr=%08lx\n",
  446. cpu_name, read_cpuid_id(), read_cpuid_id() & 15,
  447. proc_arch[cpu_architecture()], cr_alignment);
  448. snprintf(init_utsname()->machine, __NEW_UTS_LEN + 1, "%s%c",
  449. list->arch_name, ENDIANNESS);
  450. snprintf(elf_platform, ELF_PLATFORM_SIZE, "%s%c",
  451. list->elf_name, ENDIANNESS);
  452. elf_hwcap = list->elf_hwcap;
  453. cpuid_init_hwcaps();
  454. #ifndef CONFIG_ARM_THUMB
  455. elf_hwcap &= ~(HWCAP_THUMB | HWCAP_IDIVT);
  456. #endif
  457. feat_v6_fixup();
  458. cacheid_init();
  459. cpu_init();
  460. }
  461. void __init dump_machine_table(void)
  462. {
  463. struct machine_desc *p;
  464. early_print("Available machine support:\n\nID (hex)\tNAME\n");
  465. for_each_machine_desc(p)
  466. early_print("%08x\t%s\n", p->nr, p->name);
  467. early_print("\nPlease check your kernel config and/or bootloader.\n");
  468. while (true)
  469. /* can't use cpu_relax() here as it may require MMU setup */;
  470. }
  471. int __init arm_add_memory(phys_addr_t start, phys_addr_t size)
  472. {
  473. struct membank *bank = &meminfo.bank[meminfo.nr_banks];
  474. if (meminfo.nr_banks >= NR_BANKS) {
  475. printk(KERN_CRIT "NR_BANKS too low, "
  476. "ignoring memory at 0x%08llx\n", (long long)start);
  477. return -EINVAL;
  478. }
  479. /*
  480. * Ensure that start/size are aligned to a page boundary.
  481. * Size is appropriately rounded down, start is rounded up.
  482. */
  483. size -= start & ~PAGE_MASK;
  484. bank->start = PAGE_ALIGN(start);
  485. #ifndef CONFIG_ARM_LPAE
  486. if (bank->start + size < bank->start) {
  487. printk(KERN_CRIT "Truncating memory at 0x%08llx to fit in "
  488. "32-bit physical address space\n", (long long)start);
  489. /*
  490. * To ensure bank->start + bank->size is representable in
  491. * 32 bits, we use ULONG_MAX as the upper limit rather than 4GB.
  492. * This means we lose a page after masking.
  493. */
  494. size = ULONG_MAX - bank->start;
  495. }
  496. #endif
  497. bank->size = size & ~(phys_addr_t)(PAGE_SIZE - 1);
  498. /*
  499. * Check whether this memory region has non-zero size or
  500. * invalid node number.
  501. */
  502. if (bank->size == 0)
  503. return -EINVAL;
  504. meminfo.nr_banks++;
  505. return 0;
  506. }
  507. /*
  508. * Pick out the memory size. We look for mem=size@start,
  509. * where start and size are "size[KkMm]"
  510. */
  511. static int __init early_mem(char *p)
  512. {
  513. static int usermem __initdata = 0;
  514. phys_addr_t size;
  515. phys_addr_t start;
  516. char *endp;
  517. /*
  518. * If the user specifies memory size, we
  519. * blow away any automatically generated
  520. * size.
  521. */
  522. if (usermem == 0) {
  523. usermem = 1;
  524. meminfo.nr_banks = 0;
  525. }
  526. start = PHYS_OFFSET;
  527. size = memparse(p, &endp);
  528. if (*endp == '@')
  529. start = memparse(endp + 1, NULL);
  530. arm_add_memory(start, size);
  531. return 0;
  532. }
  533. early_param("mem", early_mem);
  534. static void __init request_standard_resources(struct machine_desc *mdesc)
  535. {
  536. struct memblock_region *region;
  537. struct resource *res;
  538. kernel_code.start = virt_to_phys(_text);
  539. kernel_code.end = virt_to_phys(_etext - 1);
  540. kernel_data.start = virt_to_phys(_sdata);
  541. kernel_data.end = virt_to_phys(_end - 1);
  542. for_each_memblock(memory, region) {
  543. res = alloc_bootmem_low(sizeof(*res));
  544. res->name = "System RAM";
  545. res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
  546. res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
  547. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  548. request_resource(&iomem_resource, res);
  549. if (kernel_code.start >= res->start &&
  550. kernel_code.end <= res->end)
  551. request_resource(res, &kernel_code);
  552. if (kernel_data.start >= res->start &&
  553. kernel_data.end <= res->end)
  554. request_resource(res, &kernel_data);
  555. }
  556. if (mdesc->video_start) {
  557. video_ram.start = mdesc->video_start;
  558. video_ram.end = mdesc->video_end;
  559. request_resource(&iomem_resource, &video_ram);
  560. }
  561. /*
  562. * Some machines don't have the possibility of ever
  563. * possessing lp0, lp1 or lp2
  564. */
  565. if (mdesc->reserve_lp0)
  566. request_resource(&ioport_resource, &lp0);
  567. if (mdesc->reserve_lp1)
  568. request_resource(&ioport_resource, &lp1);
  569. if (mdesc->reserve_lp2)
  570. request_resource(&ioport_resource, &lp2);
  571. }
  572. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
  573. struct screen_info screen_info = {
  574. .orig_video_lines = 30,
  575. .orig_video_cols = 80,
  576. .orig_video_mode = 0,
  577. .orig_video_ega_bx = 0,
  578. .orig_video_isVGA = 1,
  579. .orig_video_points = 8
  580. };
  581. #endif
  582. static int __init customize_machine(void)
  583. {
  584. /*
  585. * customizes platform devices, or adds new ones
  586. * On DT based machines, we fall back to populating the
  587. * machine from the device tree, if no callback is provided,
  588. * otherwise we would always need an init_machine callback.
  589. */
  590. if (machine_desc->init_machine)
  591. machine_desc->init_machine();
  592. #ifdef CONFIG_OF
  593. else
  594. of_platform_populate(NULL, of_default_bus_match_table,
  595. NULL, NULL);
  596. #endif
  597. return 0;
  598. }
  599. arch_initcall(customize_machine);
  600. static int __init init_machine_late(void)
  601. {
  602. if (machine_desc->init_late)
  603. machine_desc->init_late();
  604. return 0;
  605. }
  606. late_initcall(init_machine_late);
  607. #ifdef CONFIG_KEXEC
  608. static inline unsigned long long get_total_mem(void)
  609. {
  610. unsigned long total;
  611. total = max_low_pfn - min_low_pfn;
  612. return total << PAGE_SHIFT;
  613. }
  614. /**
  615. * reserve_crashkernel() - reserves memory are for crash kernel
  616. *
  617. * This function reserves memory area given in "crashkernel=" kernel command
  618. * line parameter. The memory reserved is used by a dump capture kernel when
  619. * primary kernel is crashing.
  620. */
  621. static void __init reserve_crashkernel(void)
  622. {
  623. unsigned long long crash_size, crash_base;
  624. unsigned long long total_mem;
  625. int ret;
  626. total_mem = get_total_mem();
  627. ret = parse_crashkernel(boot_command_line, total_mem,
  628. &crash_size, &crash_base);
  629. if (ret)
  630. return;
  631. ret = reserve_bootmem(crash_base, crash_size, BOOTMEM_EXCLUSIVE);
  632. if (ret < 0) {
  633. printk(KERN_WARNING "crashkernel reservation failed - "
  634. "memory is in use (0x%lx)\n", (unsigned long)crash_base);
  635. return;
  636. }
  637. printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
  638. "for crashkernel (System RAM: %ldMB)\n",
  639. (unsigned long)(crash_size >> 20),
  640. (unsigned long)(crash_base >> 20),
  641. (unsigned long)(total_mem >> 20));
  642. crashk_res.start = crash_base;
  643. crashk_res.end = crash_base + crash_size - 1;
  644. insert_resource(&iomem_resource, &crashk_res);
  645. }
  646. #else
  647. static inline void reserve_crashkernel(void) {}
  648. #endif /* CONFIG_KEXEC */
  649. static int __init meminfo_cmp(const void *_a, const void *_b)
  650. {
  651. const struct membank *a = _a, *b = _b;
  652. long cmp = bank_pfn_start(a) - bank_pfn_start(b);
  653. return cmp < 0 ? -1 : cmp > 0 ? 1 : 0;
  654. }
  655. void __init hyp_mode_check(void)
  656. {
  657. #ifdef CONFIG_ARM_VIRT_EXT
  658. if (is_hyp_mode_available()) {
  659. pr_info("CPU: All CPU(s) started in HYP mode.\n");
  660. pr_info("CPU: Virtualization extensions available.\n");
  661. } else if (is_hyp_mode_mismatched()) {
  662. pr_warn("CPU: WARNING: CPU(s) started in wrong/inconsistent modes (primary CPU mode 0x%x)\n",
  663. __boot_cpu_mode & MODE_MASK);
  664. pr_warn("CPU: This may indicate a broken bootloader or firmware.\n");
  665. } else
  666. pr_info("CPU: All CPU(s) started in SVC mode.\n");
  667. #endif
  668. }
  669. void __init setup_arch(char **cmdline_p)
  670. {
  671. struct machine_desc *mdesc;
  672. setup_processor();
  673. mdesc = setup_machine_fdt(__atags_pointer);
  674. if (!mdesc)
  675. mdesc = setup_machine_tags(__atags_pointer, __machine_arch_type);
  676. machine_desc = mdesc;
  677. machine_name = mdesc->name;
  678. setup_dma_zone(mdesc);
  679. if (mdesc->restart_mode)
  680. reboot_setup(&mdesc->restart_mode);
  681. init_mm.start_code = (unsigned long) _text;
  682. init_mm.end_code = (unsigned long) _etext;
  683. init_mm.end_data = (unsigned long) _edata;
  684. init_mm.brk = (unsigned long) _end;
  685. /* populate cmd_line too for later use, preserving boot_command_line */
  686. strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
  687. *cmdline_p = cmd_line;
  688. parse_early_param();
  689. sort(&meminfo.bank, meminfo.nr_banks, sizeof(meminfo.bank[0]), meminfo_cmp, NULL);
  690. sanity_check_meminfo();
  691. arm_memblock_init(&meminfo, mdesc);
  692. paging_init(mdesc);
  693. request_standard_resources(mdesc);
  694. if (mdesc->restart)
  695. arm_pm_restart = mdesc->restart;
  696. unflatten_device_tree();
  697. arm_dt_init_cpu_maps();
  698. psci_init();
  699. #ifdef CONFIG_SMP
  700. if (is_smp()) {
  701. if (!mdesc->smp_init || !mdesc->smp_init()) {
  702. if (psci_smp_available())
  703. smp_set_ops(&psci_smp_ops);
  704. else if (mdesc->smp)
  705. smp_set_ops(mdesc->smp);
  706. }
  707. smp_init_cpus();
  708. }
  709. #endif
  710. if (!is_smp())
  711. hyp_mode_check();
  712. reserve_crashkernel();
  713. #ifdef CONFIG_MULTI_IRQ_HANDLER
  714. handle_arch_irq = mdesc->handle_irq;
  715. #endif
  716. #ifdef CONFIG_VT
  717. #if defined(CONFIG_VGA_CONSOLE)
  718. conswitchp = &vga_con;
  719. #elif defined(CONFIG_DUMMY_CONSOLE)
  720. conswitchp = &dummy_con;
  721. #endif
  722. #endif
  723. if (mdesc->init_early)
  724. mdesc->init_early();
  725. }
  726. static int __init topology_init(void)
  727. {
  728. int cpu;
  729. for_each_possible_cpu(cpu) {
  730. struct cpuinfo_arm *cpuinfo = &per_cpu(cpu_data, cpu);
  731. cpuinfo->cpu.hotpluggable = 1;
  732. register_cpu(&cpuinfo->cpu, cpu);
  733. }
  734. return 0;
  735. }
  736. subsys_initcall(topology_init);
  737. #ifdef CONFIG_HAVE_PROC_CPU
  738. static int __init proc_cpu_init(void)
  739. {
  740. struct proc_dir_entry *res;
  741. res = proc_mkdir("cpu", NULL);
  742. if (!res)
  743. return -ENOMEM;
  744. return 0;
  745. }
  746. fs_initcall(proc_cpu_init);
  747. #endif
  748. static const char *hwcap_str[] = {
  749. "swp",
  750. "half",
  751. "thumb",
  752. "26bit",
  753. "fastmult",
  754. "fpa",
  755. "vfp",
  756. "edsp",
  757. "java",
  758. "iwmmxt",
  759. "crunch",
  760. "thumbee",
  761. "neon",
  762. "vfpv3",
  763. "vfpv3d16",
  764. "tls",
  765. "vfpv4",
  766. "idiva",
  767. "idivt",
  768. "lpae",
  769. NULL
  770. };
  771. static int c_show(struct seq_file *m, void *v)
  772. {
  773. int i, j;
  774. u32 cpuid;
  775. for_each_online_cpu(i) {
  776. /*
  777. * glibc reads /proc/cpuinfo to determine the number of
  778. * online processors, looking for lines beginning with
  779. * "processor". Give glibc what it expects.
  780. */
  781. seq_printf(m, "processor\t: %d\n", i);
  782. cpuid = is_smp() ? per_cpu(cpu_data, i).cpuid : read_cpuid_id();
  783. seq_printf(m, "model name\t: %s rev %d (%s)\n",
  784. cpu_name, cpuid & 15, elf_platform);
  785. #if defined(CONFIG_SMP)
  786. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
  787. per_cpu(cpu_data, i).loops_per_jiffy / (500000UL/HZ),
  788. (per_cpu(cpu_data, i).loops_per_jiffy / (5000UL/HZ)) % 100);
  789. #else
  790. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
  791. loops_per_jiffy / (500000/HZ),
  792. (loops_per_jiffy / (5000/HZ)) % 100);
  793. #endif
  794. /* dump out the processor features */
  795. seq_puts(m, "Features\t: ");
  796. for (j = 0; hwcap_str[j]; j++)
  797. if (elf_hwcap & (1 << j))
  798. seq_printf(m, "%s ", hwcap_str[j]);
  799. seq_printf(m, "\nCPU implementer\t: 0x%02x\n", cpuid >> 24);
  800. seq_printf(m, "CPU architecture: %s\n",
  801. proc_arch[cpu_architecture()]);
  802. if ((cpuid & 0x0008f000) == 0x00000000) {
  803. /* pre-ARM7 */
  804. seq_printf(m, "CPU part\t: %07x\n", cpuid >> 4);
  805. } else {
  806. if ((cpuid & 0x0008f000) == 0x00007000) {
  807. /* ARM7 */
  808. seq_printf(m, "CPU variant\t: 0x%02x\n",
  809. (cpuid >> 16) & 127);
  810. } else {
  811. /* post-ARM7 */
  812. seq_printf(m, "CPU variant\t: 0x%x\n",
  813. (cpuid >> 20) & 15);
  814. }
  815. seq_printf(m, "CPU part\t: 0x%03x\n",
  816. (cpuid >> 4) & 0xfff);
  817. }
  818. seq_printf(m, "CPU revision\t: %d\n\n", cpuid & 15);
  819. }
  820. seq_printf(m, "Hardware\t: %s\n", machine_name);
  821. seq_printf(m, "Revision\t: %04x\n", system_rev);
  822. seq_printf(m, "Serial\t\t: %08x%08x\n",
  823. system_serial_high, system_serial_low);
  824. return 0;
  825. }
  826. static void *c_start(struct seq_file *m, loff_t *pos)
  827. {
  828. return *pos < 1 ? (void *)1 : NULL;
  829. }
  830. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  831. {
  832. ++*pos;
  833. return NULL;
  834. }
  835. static void c_stop(struct seq_file *m, void *v)
  836. {
  837. }
  838. const struct seq_operations cpuinfo_op = {
  839. .start = c_start,
  840. .next = c_next,
  841. .stop = c_stop,
  842. .show = c_show
  843. };