setup.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  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/root_dev.h>
  25. #include <linux/cpu.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/smp.h>
  28. #include <linux/fs.h>
  29. #include <linux/proc_fs.h>
  30. #include <linux/memblock.h>
  31. #include <linux/bug.h>
  32. #include <linux/compiler.h>
  33. #include <linux/sort.h>
  34. #include <asm/unified.h>
  35. #include <asm/cp15.h>
  36. #include <asm/cpu.h>
  37. #include <asm/cputype.h>
  38. #include <asm/elf.h>
  39. #include <asm/procinfo.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. #if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
  57. #include "compat.h"
  58. #endif
  59. #include "atags.h"
  60. #include "tcm.h"
  61. #ifndef MEM_SIZE
  62. #define MEM_SIZE (16*1024*1024)
  63. #endif
  64. #if defined(CONFIG_FPE_NWFPE) || defined(CONFIG_FPE_FASTFPE)
  65. char fpe_type[8];
  66. static int __init fpe_setup(char *line)
  67. {
  68. memcpy(fpe_type, line, 8);
  69. return 1;
  70. }
  71. __setup("fpe=", fpe_setup);
  72. #endif
  73. extern void paging_init(struct machine_desc *desc);
  74. extern void sanity_check_meminfo(void);
  75. extern void reboot_setup(char *str);
  76. unsigned int processor_id;
  77. EXPORT_SYMBOL(processor_id);
  78. unsigned int __machine_arch_type __read_mostly;
  79. EXPORT_SYMBOL(__machine_arch_type);
  80. unsigned int cacheid __read_mostly;
  81. EXPORT_SYMBOL(cacheid);
  82. unsigned int __atags_pointer __initdata;
  83. unsigned int system_rev;
  84. EXPORT_SYMBOL(system_rev);
  85. unsigned int system_serial_low;
  86. EXPORT_SYMBOL(system_serial_low);
  87. unsigned int system_serial_high;
  88. EXPORT_SYMBOL(system_serial_high);
  89. unsigned int elf_hwcap __read_mostly;
  90. EXPORT_SYMBOL(elf_hwcap);
  91. #ifdef MULTI_CPU
  92. struct processor processor __read_mostly;
  93. #endif
  94. #ifdef MULTI_TLB
  95. struct cpu_tlb_fns cpu_tlb __read_mostly;
  96. #endif
  97. #ifdef MULTI_USER
  98. struct cpu_user_fns cpu_user __read_mostly;
  99. #endif
  100. #ifdef MULTI_CACHE
  101. struct cpu_cache_fns cpu_cache __read_mostly;
  102. #endif
  103. #ifdef CONFIG_OUTER_CACHE
  104. struct outer_cache_fns outer_cache __read_mostly;
  105. EXPORT_SYMBOL(outer_cache);
  106. #endif
  107. /*
  108. * Cached cpu_architecture() result for use by assembler code.
  109. * C code should use the cpu_architecture() function instead of accessing this
  110. * variable directly.
  111. */
  112. int __cpu_architecture __read_mostly = CPU_ARCH_UNKNOWN;
  113. struct stack {
  114. u32 irq[3];
  115. u32 abt[3];
  116. u32 und[3];
  117. } ____cacheline_aligned;
  118. static struct stack stacks[NR_CPUS];
  119. char elf_platform[ELF_PLATFORM_SIZE];
  120. EXPORT_SYMBOL(elf_platform);
  121. static const char *cpu_name;
  122. static const char *machine_name;
  123. static char __initdata cmd_line[COMMAND_LINE_SIZE];
  124. struct machine_desc *machine_desc __initdata;
  125. static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
  126. static union { char c[4]; unsigned long l; } endian_test __initdata = { { 'l', '?', '?', 'b' } };
  127. #define ENDIANNESS ((char)endian_test.l)
  128. DEFINE_PER_CPU(struct cpuinfo_arm, cpu_data);
  129. /*
  130. * Standard memory resources
  131. */
  132. static struct resource mem_res[] = {
  133. {
  134. .name = "Video RAM",
  135. .start = 0,
  136. .end = 0,
  137. .flags = IORESOURCE_MEM
  138. },
  139. {
  140. .name = "Kernel code",
  141. .start = 0,
  142. .end = 0,
  143. .flags = IORESOURCE_MEM
  144. },
  145. {
  146. .name = "Kernel data",
  147. .start = 0,
  148. .end = 0,
  149. .flags = IORESOURCE_MEM
  150. }
  151. };
  152. #define video_ram mem_res[0]
  153. #define kernel_code mem_res[1]
  154. #define kernel_data mem_res[2]
  155. static struct resource io_res[] = {
  156. {
  157. .name = "reserved",
  158. .start = 0x3bc,
  159. .end = 0x3be,
  160. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  161. },
  162. {
  163. .name = "reserved",
  164. .start = 0x378,
  165. .end = 0x37f,
  166. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  167. },
  168. {
  169. .name = "reserved",
  170. .start = 0x278,
  171. .end = 0x27f,
  172. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  173. }
  174. };
  175. #define lp0 io_res[0]
  176. #define lp1 io_res[1]
  177. #define lp2 io_res[2]
  178. static const char *proc_arch[] = {
  179. "undefined/unknown",
  180. "3",
  181. "4",
  182. "4T",
  183. "5",
  184. "5T",
  185. "5TE",
  186. "5TEJ",
  187. "6TEJ",
  188. "7",
  189. "?(11)",
  190. "?(12)",
  191. "?(13)",
  192. "?(14)",
  193. "?(15)",
  194. "?(16)",
  195. "?(17)",
  196. };
  197. static int __get_cpu_architecture(void)
  198. {
  199. int cpu_arch;
  200. if ((read_cpuid_id() & 0x0008f000) == 0) {
  201. cpu_arch = CPU_ARCH_UNKNOWN;
  202. } else if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
  203. cpu_arch = (read_cpuid_id() & (1 << 23)) ? CPU_ARCH_ARMv4T : CPU_ARCH_ARMv3;
  204. } else if ((read_cpuid_id() & 0x00080000) == 0x00000000) {
  205. cpu_arch = (read_cpuid_id() >> 16) & 7;
  206. if (cpu_arch)
  207. cpu_arch += CPU_ARCH_ARMv3;
  208. } else if ((read_cpuid_id() & 0x000f0000) == 0x000f0000) {
  209. unsigned int mmfr0;
  210. /* Revised CPUID format. Read the Memory Model Feature
  211. * Register 0 and check for VMSAv7 or PMSAv7 */
  212. asm("mrc p15, 0, %0, c0, c1, 4"
  213. : "=r" (mmfr0));
  214. if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
  215. (mmfr0 & 0x000000f0) >= 0x00000030)
  216. cpu_arch = CPU_ARCH_ARMv7;
  217. else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
  218. (mmfr0 & 0x000000f0) == 0x00000020)
  219. cpu_arch = CPU_ARCH_ARMv6;
  220. else
  221. cpu_arch = CPU_ARCH_UNKNOWN;
  222. } else
  223. cpu_arch = CPU_ARCH_UNKNOWN;
  224. return cpu_arch;
  225. }
  226. int __pure cpu_architecture(void)
  227. {
  228. BUG_ON(__cpu_architecture == CPU_ARCH_UNKNOWN);
  229. return __cpu_architecture;
  230. }
  231. static int cpu_has_aliasing_icache(unsigned int arch)
  232. {
  233. int aliasing_icache;
  234. unsigned int id_reg, num_sets, line_size;
  235. /* PIPT caches never alias. */
  236. if (icache_is_pipt())
  237. return 0;
  238. /* arch specifies the register format */
  239. switch (arch) {
  240. case CPU_ARCH_ARMv7:
  241. asm("mcr p15, 2, %0, c0, c0, 0 @ set CSSELR"
  242. : /* No output operands */
  243. : "r" (1));
  244. isb();
  245. asm("mrc p15, 1, %0, c0, c0, 0 @ read CCSIDR"
  246. : "=r" (id_reg));
  247. line_size = 4 << ((id_reg & 0x7) + 2);
  248. num_sets = ((id_reg >> 13) & 0x7fff) + 1;
  249. aliasing_icache = (line_size * num_sets) > PAGE_SIZE;
  250. break;
  251. case CPU_ARCH_ARMv6:
  252. aliasing_icache = read_cpuid_cachetype() & (1 << 11);
  253. break;
  254. default:
  255. /* I-cache aliases will be handled by D-cache aliasing code */
  256. aliasing_icache = 0;
  257. }
  258. return aliasing_icache;
  259. }
  260. static void __init cacheid_init(void)
  261. {
  262. unsigned int cachetype = read_cpuid_cachetype();
  263. unsigned int arch = cpu_architecture();
  264. if (arch >= CPU_ARCH_ARMv6) {
  265. if ((cachetype & (7 << 29)) == 4 << 29) {
  266. /* ARMv7 register format */
  267. arch = CPU_ARCH_ARMv7;
  268. cacheid = CACHEID_VIPT_NONALIASING;
  269. switch (cachetype & (3 << 14)) {
  270. case (1 << 14):
  271. cacheid |= CACHEID_ASID_TAGGED;
  272. break;
  273. case (3 << 14):
  274. cacheid |= CACHEID_PIPT;
  275. break;
  276. }
  277. } else {
  278. arch = CPU_ARCH_ARMv6;
  279. if (cachetype & (1 << 23))
  280. cacheid = CACHEID_VIPT_ALIASING;
  281. else
  282. cacheid = CACHEID_VIPT_NONALIASING;
  283. }
  284. if (cpu_has_aliasing_icache(arch))
  285. cacheid |= CACHEID_VIPT_I_ALIASING;
  286. } else {
  287. cacheid = CACHEID_VIVT;
  288. }
  289. printk("CPU: %s data cache, %s instruction cache\n",
  290. cache_is_vivt() ? "VIVT" :
  291. cache_is_vipt_aliasing() ? "VIPT aliasing" :
  292. cache_is_vipt_nonaliasing() ? "PIPT / VIPT nonaliasing" : "unknown",
  293. cache_is_vivt() ? "VIVT" :
  294. icache_is_vivt_asid_tagged() ? "VIVT ASID tagged" :
  295. icache_is_vipt_aliasing() ? "VIPT aliasing" :
  296. icache_is_pipt() ? "PIPT" :
  297. cache_is_vipt_nonaliasing() ? "VIPT nonaliasing" : "unknown");
  298. }
  299. /*
  300. * These functions re-use the assembly code in head.S, which
  301. * already provide the required functionality.
  302. */
  303. extern struct proc_info_list *lookup_processor_type(unsigned int);
  304. void __init early_print(const char *str, ...)
  305. {
  306. extern void printascii(const char *);
  307. char buf[256];
  308. va_list ap;
  309. va_start(ap, str);
  310. vsnprintf(buf, sizeof(buf), str, ap);
  311. va_end(ap);
  312. #ifdef CONFIG_DEBUG_LL
  313. printascii(buf);
  314. #endif
  315. printk("%s", buf);
  316. }
  317. static void __init feat_v6_fixup(void)
  318. {
  319. int id = read_cpuid_id();
  320. if ((id & 0xff0f0000) != 0x41070000)
  321. return;
  322. /*
  323. * HWCAP_TLS is available only on 1136 r1p0 and later,
  324. * see also kuser_get_tls_init.
  325. */
  326. if ((((id >> 4) & 0xfff) == 0xb36) && (((id >> 20) & 3) == 0))
  327. elf_hwcap &= ~HWCAP_TLS;
  328. }
  329. /*
  330. * cpu_init - initialise one CPU.
  331. *
  332. * cpu_init sets up the per-CPU stacks.
  333. */
  334. void cpu_init(void)
  335. {
  336. unsigned int cpu = smp_processor_id();
  337. struct stack *stk = &stacks[cpu];
  338. if (cpu >= NR_CPUS) {
  339. printk(KERN_CRIT "CPU%u: bad primary CPU number\n", cpu);
  340. BUG();
  341. }
  342. cpu_proc_init();
  343. /*
  344. * Define the placement constraint for the inline asm directive below.
  345. * In Thumb-2, msr with an immediate value is not allowed.
  346. */
  347. #ifdef CONFIG_THUMB2_KERNEL
  348. #define PLC "r"
  349. #else
  350. #define PLC "I"
  351. #endif
  352. /*
  353. * setup stacks for re-entrant exception handlers
  354. */
  355. __asm__ (
  356. "msr cpsr_c, %1\n\t"
  357. "add r14, %0, %2\n\t"
  358. "mov sp, r14\n\t"
  359. "msr cpsr_c, %3\n\t"
  360. "add r14, %0, %4\n\t"
  361. "mov sp, r14\n\t"
  362. "msr cpsr_c, %5\n\t"
  363. "add r14, %0, %6\n\t"
  364. "mov sp, r14\n\t"
  365. "msr cpsr_c, %7"
  366. :
  367. : "r" (stk),
  368. PLC (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
  369. "I" (offsetof(struct stack, irq[0])),
  370. PLC (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
  371. "I" (offsetof(struct stack, abt[0])),
  372. PLC (PSR_F_BIT | PSR_I_BIT | UND_MODE),
  373. "I" (offsetof(struct stack, und[0])),
  374. PLC (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
  375. : "r14");
  376. }
  377. int __cpu_logical_map[NR_CPUS];
  378. void __init smp_setup_processor_id(void)
  379. {
  380. int i;
  381. u32 cpu = is_smp() ? read_cpuid_mpidr() & 0xff : 0;
  382. cpu_logical_map(0) = cpu;
  383. for (i = 1; i < NR_CPUS; ++i)
  384. cpu_logical_map(i) = i == cpu ? 0 : i;
  385. printk(KERN_INFO "Booting Linux on physical CPU %d\n", cpu);
  386. }
  387. static void __init setup_processor(void)
  388. {
  389. struct proc_info_list *list;
  390. /*
  391. * locate processor in the list of supported processor
  392. * types. The linker builds this table for us from the
  393. * entries in arch/arm/mm/proc-*.S
  394. */
  395. list = lookup_processor_type(read_cpuid_id());
  396. if (!list) {
  397. printk("CPU configuration botched (ID %08x), unable "
  398. "to continue.\n", read_cpuid_id());
  399. while (1);
  400. }
  401. cpu_name = list->cpu_name;
  402. __cpu_architecture = __get_cpu_architecture();
  403. #ifdef MULTI_CPU
  404. processor = *list->proc;
  405. #endif
  406. #ifdef MULTI_TLB
  407. cpu_tlb = *list->tlb;
  408. #endif
  409. #ifdef MULTI_USER
  410. cpu_user = *list->user;
  411. #endif
  412. #ifdef MULTI_CACHE
  413. cpu_cache = *list->cache;
  414. #endif
  415. printk("CPU: %s [%08x] revision %d (ARMv%s), cr=%08lx\n",
  416. cpu_name, read_cpuid_id(), read_cpuid_id() & 15,
  417. proc_arch[cpu_architecture()], cr_alignment);
  418. snprintf(init_utsname()->machine, __NEW_UTS_LEN + 1, "%s%c",
  419. list->arch_name, ENDIANNESS);
  420. snprintf(elf_platform, ELF_PLATFORM_SIZE, "%s%c",
  421. list->elf_name, ENDIANNESS);
  422. elf_hwcap = list->elf_hwcap;
  423. #ifndef CONFIG_ARM_THUMB
  424. elf_hwcap &= ~HWCAP_THUMB;
  425. #endif
  426. feat_v6_fixup();
  427. cacheid_init();
  428. cpu_init();
  429. }
  430. void __init dump_machine_table(void)
  431. {
  432. struct machine_desc *p;
  433. early_print("Available machine support:\n\nID (hex)\tNAME\n");
  434. for_each_machine_desc(p)
  435. early_print("%08x\t%s\n", p->nr, p->name);
  436. early_print("\nPlease check your kernel config and/or bootloader.\n");
  437. while (true)
  438. /* can't use cpu_relax() here as it may require MMU setup */;
  439. }
  440. int __init arm_add_memory(phys_addr_t start, unsigned long size)
  441. {
  442. struct membank *bank = &meminfo.bank[meminfo.nr_banks];
  443. if (meminfo.nr_banks >= NR_BANKS) {
  444. printk(KERN_CRIT "NR_BANKS too low, "
  445. "ignoring memory at 0x%08llx\n", (long long)start);
  446. return -EINVAL;
  447. }
  448. /*
  449. * Ensure that start/size are aligned to a page boundary.
  450. * Size is appropriately rounded down, start is rounded up.
  451. */
  452. size -= start & ~PAGE_MASK;
  453. bank->start = PAGE_ALIGN(start);
  454. #ifndef CONFIG_LPAE
  455. if (bank->start + size < bank->start) {
  456. printk(KERN_CRIT "Truncating memory at 0x%08llx to fit in "
  457. "32-bit physical address space\n", (long long)start);
  458. /*
  459. * To ensure bank->start + bank->size is representable in
  460. * 32 bits, we use ULONG_MAX as the upper limit rather than 4GB.
  461. * This means we lose a page after masking.
  462. */
  463. size = ULONG_MAX - bank->start;
  464. }
  465. #endif
  466. bank->size = size & PAGE_MASK;
  467. /*
  468. * Check whether this memory region has non-zero size or
  469. * invalid node number.
  470. */
  471. if (bank->size == 0)
  472. return -EINVAL;
  473. meminfo.nr_banks++;
  474. return 0;
  475. }
  476. /*
  477. * Pick out the memory size. We look for mem=size@start,
  478. * where start and size are "size[KkMm]"
  479. */
  480. static int __init early_mem(char *p)
  481. {
  482. static int usermem __initdata = 0;
  483. unsigned long size;
  484. phys_addr_t start;
  485. char *endp;
  486. /*
  487. * If the user specifies memory size, we
  488. * blow away any automatically generated
  489. * size.
  490. */
  491. if (usermem == 0) {
  492. usermem = 1;
  493. meminfo.nr_banks = 0;
  494. }
  495. start = PHYS_OFFSET;
  496. size = memparse(p, &endp);
  497. if (*endp == '@')
  498. start = memparse(endp + 1, NULL);
  499. arm_add_memory(start, size);
  500. return 0;
  501. }
  502. early_param("mem", early_mem);
  503. static void __init
  504. setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
  505. {
  506. #ifdef CONFIG_BLK_DEV_RAM
  507. extern int rd_size, rd_image_start, rd_prompt, rd_doload;
  508. rd_image_start = image_start;
  509. rd_prompt = prompt;
  510. rd_doload = doload;
  511. if (rd_sz)
  512. rd_size = rd_sz;
  513. #endif
  514. }
  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. /*
  554. * Tag parsing.
  555. *
  556. * This is the new way of passing data to the kernel at boot time. Rather
  557. * than passing a fixed inflexible structure to the kernel, we pass a list
  558. * of variable-sized tags to the kernel. The first tag must be a ATAG_CORE
  559. * tag for the list to be recognised (to distinguish the tagged list from
  560. * a param_struct). The list is terminated with a zero-length tag (this tag
  561. * is not parsed in any way).
  562. */
  563. static int __init parse_tag_core(const struct tag *tag)
  564. {
  565. if (tag->hdr.size > 2) {
  566. if ((tag->u.core.flags & 1) == 0)
  567. root_mountflags &= ~MS_RDONLY;
  568. ROOT_DEV = old_decode_dev(tag->u.core.rootdev);
  569. }
  570. return 0;
  571. }
  572. __tagtable(ATAG_CORE, parse_tag_core);
  573. static int __init parse_tag_mem32(const struct tag *tag)
  574. {
  575. return arm_add_memory(tag->u.mem.start, tag->u.mem.size);
  576. }
  577. __tagtable(ATAG_MEM, parse_tag_mem32);
  578. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
  579. struct screen_info screen_info = {
  580. .orig_video_lines = 30,
  581. .orig_video_cols = 80,
  582. .orig_video_mode = 0,
  583. .orig_video_ega_bx = 0,
  584. .orig_video_isVGA = 1,
  585. .orig_video_points = 8
  586. };
  587. static int __init parse_tag_videotext(const struct tag *tag)
  588. {
  589. screen_info.orig_x = tag->u.videotext.x;
  590. screen_info.orig_y = tag->u.videotext.y;
  591. screen_info.orig_video_page = tag->u.videotext.video_page;
  592. screen_info.orig_video_mode = tag->u.videotext.video_mode;
  593. screen_info.orig_video_cols = tag->u.videotext.video_cols;
  594. screen_info.orig_video_ega_bx = tag->u.videotext.video_ega_bx;
  595. screen_info.orig_video_lines = tag->u.videotext.video_lines;
  596. screen_info.orig_video_isVGA = tag->u.videotext.video_isvga;
  597. screen_info.orig_video_points = tag->u.videotext.video_points;
  598. return 0;
  599. }
  600. __tagtable(ATAG_VIDEOTEXT, parse_tag_videotext);
  601. #endif
  602. static int __init parse_tag_ramdisk(const struct tag *tag)
  603. {
  604. setup_ramdisk((tag->u.ramdisk.flags & 1) == 0,
  605. (tag->u.ramdisk.flags & 2) == 0,
  606. tag->u.ramdisk.start, tag->u.ramdisk.size);
  607. return 0;
  608. }
  609. __tagtable(ATAG_RAMDISK, parse_tag_ramdisk);
  610. static int __init parse_tag_serialnr(const struct tag *tag)
  611. {
  612. system_serial_low = tag->u.serialnr.low;
  613. system_serial_high = tag->u.serialnr.high;
  614. return 0;
  615. }
  616. __tagtable(ATAG_SERIAL, parse_tag_serialnr);
  617. static int __init parse_tag_revision(const struct tag *tag)
  618. {
  619. system_rev = tag->u.revision.rev;
  620. return 0;
  621. }
  622. __tagtable(ATAG_REVISION, parse_tag_revision);
  623. static int __init parse_tag_cmdline(const struct tag *tag)
  624. {
  625. #if defined(CONFIG_CMDLINE_EXTEND)
  626. strlcat(default_command_line, " ", COMMAND_LINE_SIZE);
  627. strlcat(default_command_line, tag->u.cmdline.cmdline,
  628. COMMAND_LINE_SIZE);
  629. #elif defined(CONFIG_CMDLINE_FORCE)
  630. pr_warning("Ignoring tag cmdline (using the default kernel command line)\n");
  631. #else
  632. strlcpy(default_command_line, tag->u.cmdline.cmdline,
  633. COMMAND_LINE_SIZE);
  634. #endif
  635. return 0;
  636. }
  637. __tagtable(ATAG_CMDLINE, parse_tag_cmdline);
  638. /*
  639. * Scan the tag table for this tag, and call its parse function.
  640. * The tag table is built by the linker from all the __tagtable
  641. * declarations.
  642. */
  643. static int __init parse_tag(const struct tag *tag)
  644. {
  645. extern struct tagtable __tagtable_begin, __tagtable_end;
  646. struct tagtable *t;
  647. for (t = &__tagtable_begin; t < &__tagtable_end; t++)
  648. if (tag->hdr.tag == t->tag) {
  649. t->parse(tag);
  650. break;
  651. }
  652. return t < &__tagtable_end;
  653. }
  654. /*
  655. * Parse all tags in the list, checking both the global and architecture
  656. * specific tag tables.
  657. */
  658. static void __init parse_tags(const struct tag *t)
  659. {
  660. for (; t->hdr.size; t = tag_next(t))
  661. if (!parse_tag(t))
  662. printk(KERN_WARNING
  663. "Ignoring unrecognised tag 0x%08x\n",
  664. t->hdr.tag);
  665. }
  666. /*
  667. * This holds our defaults.
  668. */
  669. static struct init_tags {
  670. struct tag_header hdr1;
  671. struct tag_core core;
  672. struct tag_header hdr2;
  673. struct tag_mem32 mem;
  674. struct tag_header hdr3;
  675. } init_tags __initdata = {
  676. { tag_size(tag_core), ATAG_CORE },
  677. { 1, PAGE_SIZE, 0xff },
  678. { tag_size(tag_mem32), ATAG_MEM },
  679. { MEM_SIZE },
  680. { 0, ATAG_NONE }
  681. };
  682. static int __init customize_machine(void)
  683. {
  684. /* customizes platform devices, or adds new ones */
  685. if (machine_desc->init_machine)
  686. machine_desc->init_machine();
  687. return 0;
  688. }
  689. arch_initcall(customize_machine);
  690. #ifdef CONFIG_KEXEC
  691. static inline unsigned long long get_total_mem(void)
  692. {
  693. unsigned long total;
  694. total = max_low_pfn - min_low_pfn;
  695. return total << PAGE_SHIFT;
  696. }
  697. /**
  698. * reserve_crashkernel() - reserves memory are for crash kernel
  699. *
  700. * This function reserves memory area given in "crashkernel=" kernel command
  701. * line parameter. The memory reserved is used by a dump capture kernel when
  702. * primary kernel is crashing.
  703. */
  704. static void __init reserve_crashkernel(void)
  705. {
  706. unsigned long long crash_size, crash_base;
  707. unsigned long long total_mem;
  708. int ret;
  709. total_mem = get_total_mem();
  710. ret = parse_crashkernel(boot_command_line, total_mem,
  711. &crash_size, &crash_base);
  712. if (ret)
  713. return;
  714. ret = reserve_bootmem(crash_base, crash_size, BOOTMEM_EXCLUSIVE);
  715. if (ret < 0) {
  716. printk(KERN_WARNING "crashkernel reservation failed - "
  717. "memory is in use (0x%lx)\n", (unsigned long)crash_base);
  718. return;
  719. }
  720. printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
  721. "for crashkernel (System RAM: %ldMB)\n",
  722. (unsigned long)(crash_size >> 20),
  723. (unsigned long)(crash_base >> 20),
  724. (unsigned long)(total_mem >> 20));
  725. crashk_res.start = crash_base;
  726. crashk_res.end = crash_base + crash_size - 1;
  727. insert_resource(&iomem_resource, &crashk_res);
  728. }
  729. #else
  730. static inline void reserve_crashkernel(void) {}
  731. #endif /* CONFIG_KEXEC */
  732. static void __init squash_mem_tags(struct tag *tag)
  733. {
  734. for (; tag->hdr.size; tag = tag_next(tag))
  735. if (tag->hdr.tag == ATAG_MEM)
  736. tag->hdr.tag = ATAG_NONE;
  737. }
  738. static struct machine_desc * __init setup_machine_tags(unsigned int nr)
  739. {
  740. struct tag *tags = (struct tag *)&init_tags;
  741. struct machine_desc *mdesc = NULL, *p;
  742. char *from = default_command_line;
  743. init_tags.mem.start = PHYS_OFFSET;
  744. /*
  745. * locate machine in the list of supported machines.
  746. */
  747. for_each_machine_desc(p)
  748. if (nr == p->nr) {
  749. printk("Machine: %s\n", p->name);
  750. mdesc = p;
  751. break;
  752. }
  753. if (!mdesc) {
  754. early_print("\nError: unrecognized/unsupported machine ID"
  755. " (r1 = 0x%08x).\n\n", nr);
  756. dump_machine_table(); /* does not return */
  757. }
  758. if (__atags_pointer)
  759. tags = phys_to_virt(__atags_pointer);
  760. else if (mdesc->atag_offset)
  761. tags = (void *)(PAGE_OFFSET + mdesc->atag_offset);
  762. #if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
  763. /*
  764. * If we have the old style parameters, convert them to
  765. * a tag list.
  766. */
  767. if (tags->hdr.tag != ATAG_CORE)
  768. convert_to_tag_list(tags);
  769. #endif
  770. if (tags->hdr.tag != ATAG_CORE) {
  771. #if defined(CONFIG_OF)
  772. /*
  773. * If CONFIG_OF is set, then assume this is a reasonably
  774. * modern system that should pass boot parameters
  775. */
  776. early_print("Warning: Neither atags nor dtb found\n");
  777. #endif
  778. tags = (struct tag *)&init_tags;
  779. }
  780. if (mdesc->fixup)
  781. mdesc->fixup(tags, &from, &meminfo);
  782. if (tags->hdr.tag == ATAG_CORE) {
  783. if (meminfo.nr_banks != 0)
  784. squash_mem_tags(tags);
  785. save_atags(tags);
  786. parse_tags(tags);
  787. }
  788. /* parse_early_param needs a boot_command_line */
  789. strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
  790. return mdesc;
  791. }
  792. static int __init meminfo_cmp(const void *_a, const void *_b)
  793. {
  794. const struct membank *a = _a, *b = _b;
  795. long cmp = bank_pfn_start(a) - bank_pfn_start(b);
  796. return cmp < 0 ? -1 : cmp > 0 ? 1 : 0;
  797. }
  798. void __init setup_arch(char **cmdline_p)
  799. {
  800. struct machine_desc *mdesc;
  801. setup_processor();
  802. mdesc = setup_machine_fdt(__atags_pointer);
  803. if (!mdesc)
  804. mdesc = setup_machine_tags(machine_arch_type);
  805. machine_desc = mdesc;
  806. machine_name = mdesc->name;
  807. #ifdef CONFIG_ZONE_DMA
  808. if (mdesc->dma_zone_size) {
  809. extern unsigned long arm_dma_zone_size;
  810. arm_dma_zone_size = mdesc->dma_zone_size;
  811. }
  812. #endif
  813. if (mdesc->restart_mode)
  814. reboot_setup(&mdesc->restart_mode);
  815. init_mm.start_code = (unsigned long) _text;
  816. init_mm.end_code = (unsigned long) _etext;
  817. init_mm.end_data = (unsigned long) _edata;
  818. init_mm.brk = (unsigned long) _end;
  819. /* populate cmd_line too for later use, preserving boot_command_line */
  820. strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
  821. *cmdline_p = cmd_line;
  822. parse_early_param();
  823. sort(&meminfo.bank, meminfo.nr_banks, sizeof(meminfo.bank[0]), meminfo_cmp, NULL);
  824. sanity_check_meminfo();
  825. arm_memblock_init(&meminfo, mdesc);
  826. paging_init(mdesc);
  827. request_standard_resources(mdesc);
  828. if (mdesc->restart)
  829. arm_pm_restart = mdesc->restart;
  830. unflatten_device_tree();
  831. #ifdef CONFIG_SMP
  832. if (is_smp())
  833. smp_init_cpus();
  834. #endif
  835. reserve_crashkernel();
  836. tcm_init();
  837. #ifdef CONFIG_MULTI_IRQ_HANDLER
  838. handle_arch_irq = mdesc->handle_irq;
  839. #endif
  840. #ifdef CONFIG_VT
  841. #if defined(CONFIG_VGA_CONSOLE)
  842. conswitchp = &vga_con;
  843. #elif defined(CONFIG_DUMMY_CONSOLE)
  844. conswitchp = &dummy_con;
  845. #endif
  846. #endif
  847. if (mdesc->init_early)
  848. mdesc->init_early();
  849. }
  850. static int __init topology_init(void)
  851. {
  852. int cpu;
  853. for_each_possible_cpu(cpu) {
  854. struct cpuinfo_arm *cpuinfo = &per_cpu(cpu_data, cpu);
  855. cpuinfo->cpu.hotpluggable = 1;
  856. register_cpu(&cpuinfo->cpu, cpu);
  857. }
  858. return 0;
  859. }
  860. subsys_initcall(topology_init);
  861. #ifdef CONFIG_HAVE_PROC_CPU
  862. static int __init proc_cpu_init(void)
  863. {
  864. struct proc_dir_entry *res;
  865. res = proc_mkdir("cpu", NULL);
  866. if (!res)
  867. return -ENOMEM;
  868. return 0;
  869. }
  870. fs_initcall(proc_cpu_init);
  871. #endif
  872. static const char *hwcap_str[] = {
  873. "swp",
  874. "half",
  875. "thumb",
  876. "26bit",
  877. "fastmult",
  878. "fpa",
  879. "vfp",
  880. "edsp",
  881. "java",
  882. "iwmmxt",
  883. "crunch",
  884. "thumbee",
  885. "neon",
  886. "vfpv3",
  887. "vfpv3d16",
  888. "tls",
  889. "vfpv4",
  890. "idiva",
  891. "idivt",
  892. NULL
  893. };
  894. static int c_show(struct seq_file *m, void *v)
  895. {
  896. int i;
  897. seq_printf(m, "Processor\t: %s rev %d (%s)\n",
  898. cpu_name, read_cpuid_id() & 15, elf_platform);
  899. #if defined(CONFIG_SMP)
  900. for_each_online_cpu(i) {
  901. /*
  902. * glibc reads /proc/cpuinfo to determine the number of
  903. * online processors, looking for lines beginning with
  904. * "processor". Give glibc what it expects.
  905. */
  906. seq_printf(m, "processor\t: %d\n", i);
  907. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n\n",
  908. per_cpu(cpu_data, i).loops_per_jiffy / (500000UL/HZ),
  909. (per_cpu(cpu_data, i).loops_per_jiffy / (5000UL/HZ)) % 100);
  910. }
  911. #else /* CONFIG_SMP */
  912. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
  913. loops_per_jiffy / (500000/HZ),
  914. (loops_per_jiffy / (5000/HZ)) % 100);
  915. #endif
  916. /* dump out the processor features */
  917. seq_puts(m, "Features\t: ");
  918. for (i = 0; hwcap_str[i]; i++)
  919. if (elf_hwcap & (1 << i))
  920. seq_printf(m, "%s ", hwcap_str[i]);
  921. seq_printf(m, "\nCPU implementer\t: 0x%02x\n", read_cpuid_id() >> 24);
  922. seq_printf(m, "CPU architecture: %s\n", proc_arch[cpu_architecture()]);
  923. if ((read_cpuid_id() & 0x0008f000) == 0x00000000) {
  924. /* pre-ARM7 */
  925. seq_printf(m, "CPU part\t: %07x\n", read_cpuid_id() >> 4);
  926. } else {
  927. if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
  928. /* ARM7 */
  929. seq_printf(m, "CPU variant\t: 0x%02x\n",
  930. (read_cpuid_id() >> 16) & 127);
  931. } else {
  932. /* post-ARM7 */
  933. seq_printf(m, "CPU variant\t: 0x%x\n",
  934. (read_cpuid_id() >> 20) & 15);
  935. }
  936. seq_printf(m, "CPU part\t: 0x%03x\n",
  937. (read_cpuid_id() >> 4) & 0xfff);
  938. }
  939. seq_printf(m, "CPU revision\t: %d\n", read_cpuid_id() & 15);
  940. seq_puts(m, "\n");
  941. seq_printf(m, "Hardware\t: %s\n", machine_name);
  942. seq_printf(m, "Revision\t: %04x\n", system_rev);
  943. seq_printf(m, "Serial\t\t: %08x%08x\n",
  944. system_serial_high, system_serial_low);
  945. return 0;
  946. }
  947. static void *c_start(struct seq_file *m, loff_t *pos)
  948. {
  949. return *pos < 1 ? (void *)1 : NULL;
  950. }
  951. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  952. {
  953. ++*pos;
  954. return NULL;
  955. }
  956. static void c_stop(struct seq_file *m, void *v)
  957. {
  958. }
  959. const struct seq_operations cpuinfo_op = {
  960. .start = c_start,
  961. .next = c_next,
  962. .stop = c_stop,
  963. .show = c_show
  964. };