setup.c 20 KB

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