setup.c 25 KB

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