setup.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  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. bank->size = size & PAGE_MASK;
  455. /*
  456. * Check whether this memory region has non-zero size or
  457. * invalid node number.
  458. */
  459. if (bank->size == 0)
  460. return -EINVAL;
  461. meminfo.nr_banks++;
  462. return 0;
  463. }
  464. /*
  465. * Pick out the memory size. We look for mem=size@start,
  466. * where start and size are "size[KkMm]"
  467. */
  468. static int __init early_mem(char *p)
  469. {
  470. static int usermem __initdata = 0;
  471. unsigned long size;
  472. phys_addr_t start;
  473. char *endp;
  474. /*
  475. * If the user specifies memory size, we
  476. * blow away any automatically generated
  477. * size.
  478. */
  479. if (usermem == 0) {
  480. usermem = 1;
  481. meminfo.nr_banks = 0;
  482. }
  483. start = PHYS_OFFSET;
  484. size = memparse(p, &endp);
  485. if (*endp == '@')
  486. start = memparse(endp + 1, NULL);
  487. arm_add_memory(start, size);
  488. return 0;
  489. }
  490. early_param("mem", early_mem);
  491. static void __init
  492. setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
  493. {
  494. #ifdef CONFIG_BLK_DEV_RAM
  495. extern int rd_size, rd_image_start, rd_prompt, rd_doload;
  496. rd_image_start = image_start;
  497. rd_prompt = prompt;
  498. rd_doload = doload;
  499. if (rd_sz)
  500. rd_size = rd_sz;
  501. #endif
  502. }
  503. static void __init request_standard_resources(struct machine_desc *mdesc)
  504. {
  505. struct memblock_region *region;
  506. struct resource *res;
  507. kernel_code.start = virt_to_phys(_text);
  508. kernel_code.end = virt_to_phys(_etext - 1);
  509. kernel_data.start = virt_to_phys(_sdata);
  510. kernel_data.end = virt_to_phys(_end - 1);
  511. for_each_memblock(memory, region) {
  512. res = alloc_bootmem_low(sizeof(*res));
  513. res->name = "System RAM";
  514. res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
  515. res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
  516. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  517. request_resource(&iomem_resource, res);
  518. if (kernel_code.start >= res->start &&
  519. kernel_code.end <= res->end)
  520. request_resource(res, &kernel_code);
  521. if (kernel_data.start >= res->start &&
  522. kernel_data.end <= res->end)
  523. request_resource(res, &kernel_data);
  524. }
  525. if (mdesc->video_start) {
  526. video_ram.start = mdesc->video_start;
  527. video_ram.end = mdesc->video_end;
  528. request_resource(&iomem_resource, &video_ram);
  529. }
  530. /*
  531. * Some machines don't have the possibility of ever
  532. * possessing lp0, lp1 or lp2
  533. */
  534. if (mdesc->reserve_lp0)
  535. request_resource(&ioport_resource, &lp0);
  536. if (mdesc->reserve_lp1)
  537. request_resource(&ioport_resource, &lp1);
  538. if (mdesc->reserve_lp2)
  539. request_resource(&ioport_resource, &lp2);
  540. }
  541. /*
  542. * Tag parsing.
  543. *
  544. * This is the new way of passing data to the kernel at boot time. Rather
  545. * than passing a fixed inflexible structure to the kernel, we pass a list
  546. * of variable-sized tags to the kernel. The first tag must be a ATAG_CORE
  547. * tag for the list to be recognised (to distinguish the tagged list from
  548. * a param_struct). The list is terminated with a zero-length tag (this tag
  549. * is not parsed in any way).
  550. */
  551. static int __init parse_tag_core(const struct tag *tag)
  552. {
  553. if (tag->hdr.size > 2) {
  554. if ((tag->u.core.flags & 1) == 0)
  555. root_mountflags &= ~MS_RDONLY;
  556. ROOT_DEV = old_decode_dev(tag->u.core.rootdev);
  557. }
  558. return 0;
  559. }
  560. __tagtable(ATAG_CORE, parse_tag_core);
  561. static int __init parse_tag_mem32(const struct tag *tag)
  562. {
  563. return arm_add_memory(tag->u.mem.start, tag->u.mem.size);
  564. }
  565. __tagtable(ATAG_MEM, parse_tag_mem32);
  566. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
  567. struct screen_info screen_info = {
  568. .orig_video_lines = 30,
  569. .orig_video_cols = 80,
  570. .orig_video_mode = 0,
  571. .orig_video_ega_bx = 0,
  572. .orig_video_isVGA = 1,
  573. .orig_video_points = 8
  574. };
  575. static int __init parse_tag_videotext(const struct tag *tag)
  576. {
  577. screen_info.orig_x = tag->u.videotext.x;
  578. screen_info.orig_y = tag->u.videotext.y;
  579. screen_info.orig_video_page = tag->u.videotext.video_page;
  580. screen_info.orig_video_mode = tag->u.videotext.video_mode;
  581. screen_info.orig_video_cols = tag->u.videotext.video_cols;
  582. screen_info.orig_video_ega_bx = tag->u.videotext.video_ega_bx;
  583. screen_info.orig_video_lines = tag->u.videotext.video_lines;
  584. screen_info.orig_video_isVGA = tag->u.videotext.video_isvga;
  585. screen_info.orig_video_points = tag->u.videotext.video_points;
  586. return 0;
  587. }
  588. __tagtable(ATAG_VIDEOTEXT, parse_tag_videotext);
  589. #endif
  590. static int __init parse_tag_ramdisk(const struct tag *tag)
  591. {
  592. setup_ramdisk((tag->u.ramdisk.flags & 1) == 0,
  593. (tag->u.ramdisk.flags & 2) == 0,
  594. tag->u.ramdisk.start, tag->u.ramdisk.size);
  595. return 0;
  596. }
  597. __tagtable(ATAG_RAMDISK, parse_tag_ramdisk);
  598. static int __init parse_tag_serialnr(const struct tag *tag)
  599. {
  600. system_serial_low = tag->u.serialnr.low;
  601. system_serial_high = tag->u.serialnr.high;
  602. return 0;
  603. }
  604. __tagtable(ATAG_SERIAL, parse_tag_serialnr);
  605. static int __init parse_tag_revision(const struct tag *tag)
  606. {
  607. system_rev = tag->u.revision.rev;
  608. return 0;
  609. }
  610. __tagtable(ATAG_REVISION, parse_tag_revision);
  611. static int __init parse_tag_cmdline(const struct tag *tag)
  612. {
  613. #if defined(CONFIG_CMDLINE_EXTEND)
  614. strlcat(default_command_line, " ", COMMAND_LINE_SIZE);
  615. strlcat(default_command_line, tag->u.cmdline.cmdline,
  616. COMMAND_LINE_SIZE);
  617. #elif defined(CONFIG_CMDLINE_FORCE)
  618. pr_warning("Ignoring tag cmdline (using the default kernel command line)\n");
  619. #else
  620. strlcpy(default_command_line, tag->u.cmdline.cmdline,
  621. COMMAND_LINE_SIZE);
  622. #endif
  623. return 0;
  624. }
  625. __tagtable(ATAG_CMDLINE, parse_tag_cmdline);
  626. /*
  627. * Scan the tag table for this tag, and call its parse function.
  628. * The tag table is built by the linker from all the __tagtable
  629. * declarations.
  630. */
  631. static int __init parse_tag(const struct tag *tag)
  632. {
  633. extern struct tagtable __tagtable_begin, __tagtable_end;
  634. struct tagtable *t;
  635. for (t = &__tagtable_begin; t < &__tagtable_end; t++)
  636. if (tag->hdr.tag == t->tag) {
  637. t->parse(tag);
  638. break;
  639. }
  640. return t < &__tagtable_end;
  641. }
  642. /*
  643. * Parse all tags in the list, checking both the global and architecture
  644. * specific tag tables.
  645. */
  646. static void __init parse_tags(const struct tag *t)
  647. {
  648. for (; t->hdr.size; t = tag_next(t))
  649. if (!parse_tag(t))
  650. printk(KERN_WARNING
  651. "Ignoring unrecognised tag 0x%08x\n",
  652. t->hdr.tag);
  653. }
  654. /*
  655. * This holds our defaults.
  656. */
  657. static struct init_tags {
  658. struct tag_header hdr1;
  659. struct tag_core core;
  660. struct tag_header hdr2;
  661. struct tag_mem32 mem;
  662. struct tag_header hdr3;
  663. } init_tags __initdata = {
  664. { tag_size(tag_core), ATAG_CORE },
  665. { 1, PAGE_SIZE, 0xff },
  666. { tag_size(tag_mem32), ATAG_MEM },
  667. { MEM_SIZE },
  668. { 0, ATAG_NONE }
  669. };
  670. static int __init customize_machine(void)
  671. {
  672. /* customizes platform devices, or adds new ones */
  673. if (machine_desc->init_machine)
  674. machine_desc->init_machine();
  675. return 0;
  676. }
  677. arch_initcall(customize_machine);
  678. #ifdef CONFIG_KEXEC
  679. static inline unsigned long long get_total_mem(void)
  680. {
  681. unsigned long total;
  682. total = max_low_pfn - min_low_pfn;
  683. return total << PAGE_SHIFT;
  684. }
  685. /**
  686. * reserve_crashkernel() - reserves memory are for crash kernel
  687. *
  688. * This function reserves memory area given in "crashkernel=" kernel command
  689. * line parameter. The memory reserved is used by a dump capture kernel when
  690. * primary kernel is crashing.
  691. */
  692. static void __init reserve_crashkernel(void)
  693. {
  694. unsigned long long crash_size, crash_base;
  695. unsigned long long total_mem;
  696. int ret;
  697. total_mem = get_total_mem();
  698. ret = parse_crashkernel(boot_command_line, total_mem,
  699. &crash_size, &crash_base);
  700. if (ret)
  701. return;
  702. ret = reserve_bootmem(crash_base, crash_size, BOOTMEM_EXCLUSIVE);
  703. if (ret < 0) {
  704. printk(KERN_WARNING "crashkernel reservation failed - "
  705. "memory is in use (0x%lx)\n", (unsigned long)crash_base);
  706. return;
  707. }
  708. printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
  709. "for crashkernel (System RAM: %ldMB)\n",
  710. (unsigned long)(crash_size >> 20),
  711. (unsigned long)(crash_base >> 20),
  712. (unsigned long)(total_mem >> 20));
  713. crashk_res.start = crash_base;
  714. crashk_res.end = crash_base + crash_size - 1;
  715. insert_resource(&iomem_resource, &crashk_res);
  716. }
  717. #else
  718. static inline void reserve_crashkernel(void) {}
  719. #endif /* CONFIG_KEXEC */
  720. static void __init squash_mem_tags(struct tag *tag)
  721. {
  722. for (; tag->hdr.size; tag = tag_next(tag))
  723. if (tag->hdr.tag == ATAG_MEM)
  724. tag->hdr.tag = ATAG_NONE;
  725. }
  726. static struct machine_desc * __init setup_machine_tags(unsigned int nr)
  727. {
  728. struct tag *tags = (struct tag *)&init_tags;
  729. struct machine_desc *mdesc = NULL, *p;
  730. char *from = default_command_line;
  731. init_tags.mem.start = PHYS_OFFSET;
  732. /*
  733. * locate machine in the list of supported machines.
  734. */
  735. for_each_machine_desc(p)
  736. if (nr == p->nr) {
  737. printk("Machine: %s\n", p->name);
  738. mdesc = p;
  739. break;
  740. }
  741. if (!mdesc) {
  742. early_print("\nError: unrecognized/unsupported machine ID"
  743. " (r1 = 0x%08x).\n\n", nr);
  744. dump_machine_table(); /* does not return */
  745. }
  746. if (__atags_pointer)
  747. tags = phys_to_virt(__atags_pointer);
  748. else if (mdesc->atag_offset)
  749. tags = (void *)(PAGE_OFFSET + mdesc->atag_offset);
  750. #if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
  751. /*
  752. * If we have the old style parameters, convert them to
  753. * a tag list.
  754. */
  755. if (tags->hdr.tag != ATAG_CORE)
  756. convert_to_tag_list(tags);
  757. #endif
  758. if (tags->hdr.tag != ATAG_CORE) {
  759. #if defined(CONFIG_OF)
  760. /*
  761. * If CONFIG_OF is set, then assume this is a reasonably
  762. * modern system that should pass boot parameters
  763. */
  764. early_print("Warning: Neither atags nor dtb found\n");
  765. #endif
  766. tags = (struct tag *)&init_tags;
  767. }
  768. if (mdesc->fixup)
  769. mdesc->fixup(tags, &from, &meminfo);
  770. if (tags->hdr.tag == ATAG_CORE) {
  771. if (meminfo.nr_banks != 0)
  772. squash_mem_tags(tags);
  773. save_atags(tags);
  774. parse_tags(tags);
  775. }
  776. /* parse_early_param needs a boot_command_line */
  777. strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
  778. return mdesc;
  779. }
  780. static int __init meminfo_cmp(const void *_a, const void *_b)
  781. {
  782. const struct membank *a = _a, *b = _b;
  783. long cmp = bank_pfn_start(a) - bank_pfn_start(b);
  784. return cmp < 0 ? -1 : cmp > 0 ? 1 : 0;
  785. }
  786. void __init setup_arch(char **cmdline_p)
  787. {
  788. struct machine_desc *mdesc;
  789. setup_processor();
  790. mdesc = setup_machine_fdt(__atags_pointer);
  791. if (!mdesc)
  792. mdesc = setup_machine_tags(machine_arch_type);
  793. machine_desc = mdesc;
  794. machine_name = mdesc->name;
  795. #ifdef CONFIG_ZONE_DMA
  796. if (mdesc->dma_zone_size) {
  797. extern unsigned long arm_dma_zone_size;
  798. arm_dma_zone_size = mdesc->dma_zone_size;
  799. }
  800. #endif
  801. if (mdesc->restart_mode)
  802. reboot_setup(&mdesc->restart_mode);
  803. init_mm.start_code = (unsigned long) _text;
  804. init_mm.end_code = (unsigned long) _etext;
  805. init_mm.end_data = (unsigned long) _edata;
  806. init_mm.brk = (unsigned long) _end;
  807. /* populate cmd_line too for later use, preserving boot_command_line */
  808. strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
  809. *cmdline_p = cmd_line;
  810. parse_early_param();
  811. sort(&meminfo.bank, meminfo.nr_banks, sizeof(meminfo.bank[0]), meminfo_cmp, NULL);
  812. sanity_check_meminfo();
  813. arm_memblock_init(&meminfo, mdesc);
  814. paging_init(mdesc);
  815. request_standard_resources(mdesc);
  816. if (mdesc->restart)
  817. arm_pm_restart = mdesc->restart;
  818. unflatten_device_tree();
  819. #ifdef CONFIG_SMP
  820. if (is_smp())
  821. smp_init_cpus();
  822. #endif
  823. reserve_crashkernel();
  824. tcm_init();
  825. #ifdef CONFIG_MULTI_IRQ_HANDLER
  826. handle_arch_irq = mdesc->handle_irq;
  827. #endif
  828. #ifdef CONFIG_VT
  829. #if defined(CONFIG_VGA_CONSOLE)
  830. conswitchp = &vga_con;
  831. #elif defined(CONFIG_DUMMY_CONSOLE)
  832. conswitchp = &dummy_con;
  833. #endif
  834. #endif
  835. if (mdesc->init_early)
  836. mdesc->init_early();
  837. }
  838. static int __init topology_init(void)
  839. {
  840. int cpu;
  841. for_each_possible_cpu(cpu) {
  842. struct cpuinfo_arm *cpuinfo = &per_cpu(cpu_data, cpu);
  843. cpuinfo->cpu.hotpluggable = 1;
  844. register_cpu(&cpuinfo->cpu, cpu);
  845. }
  846. return 0;
  847. }
  848. subsys_initcall(topology_init);
  849. #ifdef CONFIG_HAVE_PROC_CPU
  850. static int __init proc_cpu_init(void)
  851. {
  852. struct proc_dir_entry *res;
  853. res = proc_mkdir("cpu", NULL);
  854. if (!res)
  855. return -ENOMEM;
  856. return 0;
  857. }
  858. fs_initcall(proc_cpu_init);
  859. #endif
  860. static const char *hwcap_str[] = {
  861. "swp",
  862. "half",
  863. "thumb",
  864. "26bit",
  865. "fastmult",
  866. "fpa",
  867. "vfp",
  868. "edsp",
  869. "java",
  870. "iwmmxt",
  871. "crunch",
  872. "thumbee",
  873. "neon",
  874. "vfpv3",
  875. "vfpv3d16",
  876. "tls",
  877. "vfpv4",
  878. "idiva",
  879. "idivt",
  880. NULL
  881. };
  882. static int c_show(struct seq_file *m, void *v)
  883. {
  884. int i;
  885. seq_printf(m, "Processor\t: %s rev %d (%s)\n",
  886. cpu_name, read_cpuid_id() & 15, elf_platform);
  887. #if defined(CONFIG_SMP)
  888. for_each_online_cpu(i) {
  889. /*
  890. * glibc reads /proc/cpuinfo to determine the number of
  891. * online processors, looking for lines beginning with
  892. * "processor". Give glibc what it expects.
  893. */
  894. seq_printf(m, "processor\t: %d\n", i);
  895. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n\n",
  896. per_cpu(cpu_data, i).loops_per_jiffy / (500000UL/HZ),
  897. (per_cpu(cpu_data, i).loops_per_jiffy / (5000UL/HZ)) % 100);
  898. }
  899. #else /* CONFIG_SMP */
  900. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
  901. loops_per_jiffy / (500000/HZ),
  902. (loops_per_jiffy / (5000/HZ)) % 100);
  903. #endif
  904. /* dump out the processor features */
  905. seq_puts(m, "Features\t: ");
  906. for (i = 0; hwcap_str[i]; i++)
  907. if (elf_hwcap & (1 << i))
  908. seq_printf(m, "%s ", hwcap_str[i]);
  909. seq_printf(m, "\nCPU implementer\t: 0x%02x\n", read_cpuid_id() >> 24);
  910. seq_printf(m, "CPU architecture: %s\n", proc_arch[cpu_architecture()]);
  911. if ((read_cpuid_id() & 0x0008f000) == 0x00000000) {
  912. /* pre-ARM7 */
  913. seq_printf(m, "CPU part\t: %07x\n", read_cpuid_id() >> 4);
  914. } else {
  915. if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
  916. /* ARM7 */
  917. seq_printf(m, "CPU variant\t: 0x%02x\n",
  918. (read_cpuid_id() >> 16) & 127);
  919. } else {
  920. /* post-ARM7 */
  921. seq_printf(m, "CPU variant\t: 0x%x\n",
  922. (read_cpuid_id() >> 20) & 15);
  923. }
  924. seq_printf(m, "CPU part\t: 0x%03x\n",
  925. (read_cpuid_id() >> 4) & 0xfff);
  926. }
  927. seq_printf(m, "CPU revision\t: %d\n", read_cpuid_id() & 15);
  928. seq_puts(m, "\n");
  929. seq_printf(m, "Hardware\t: %s\n", machine_name);
  930. seq_printf(m, "Revision\t: %04x\n", system_rev);
  931. seq_printf(m, "Serial\t\t: %08x%08x\n",
  932. system_serial_high, system_serial_low);
  933. return 0;
  934. }
  935. static void *c_start(struct seq_file *m, loff_t *pos)
  936. {
  937. return *pos < 1 ? (void *)1 : NULL;
  938. }
  939. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  940. {
  941. ++*pos;
  942. return NULL;
  943. }
  944. static void c_stop(struct seq_file *m, void *v)
  945. {
  946. }
  947. const struct seq_operations cpuinfo_op = {
  948. .start = c_start,
  949. .next = c_next,
  950. .stop = c_stop,
  951. .show = c_show
  952. };