setup.c 21 KB

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