setup.c 22 KB

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