setup.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*
  2. * Based on arch/arm/kernel/setup.c
  3. *
  4. * Copyright (C) 1995-2001 Russell King
  5. * Copyright (C) 2012 ARM Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/export.h>
  20. #include <linux/kernel.h>
  21. #include <linux/stddef.h>
  22. #include <linux/ioport.h>
  23. #include <linux/delay.h>
  24. #include <linux/utsname.h>
  25. #include <linux/initrd.h>
  26. #include <linux/console.h>
  27. #include <linux/bootmem.h>
  28. #include <linux/seq_file.h>
  29. #include <linux/screen_info.h>
  30. #include <linux/init.h>
  31. #include <linux/kexec.h>
  32. #include <linux/crash_dump.h>
  33. #include <linux/root_dev.h>
  34. #include <linux/cpu.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/smp.h>
  37. #include <linux/fs.h>
  38. #include <linux/proc_fs.h>
  39. #include <linux/memblock.h>
  40. #include <linux/of_fdt.h>
  41. #include <linux/of_platform.h>
  42. #include <asm/cputype.h>
  43. #include <asm/elf.h>
  44. #include <asm/cputable.h>
  45. #include <asm/sections.h>
  46. #include <asm/setup.h>
  47. #include <asm/cacheflush.h>
  48. #include <asm/tlbflush.h>
  49. #include <asm/traps.h>
  50. #include <asm/memblock.h>
  51. #include <asm/psci.h>
  52. unsigned int processor_id;
  53. EXPORT_SYMBOL(processor_id);
  54. unsigned int elf_hwcap __read_mostly;
  55. EXPORT_SYMBOL_GPL(elf_hwcap);
  56. static const char *cpu_name;
  57. static const char *machine_name;
  58. phys_addr_t __fdt_pointer __initdata;
  59. /*
  60. * Standard memory resources
  61. */
  62. static struct resource mem_res[] = {
  63. {
  64. .name = "Kernel code",
  65. .start = 0,
  66. .end = 0,
  67. .flags = IORESOURCE_MEM
  68. },
  69. {
  70. .name = "Kernel data",
  71. .start = 0,
  72. .end = 0,
  73. .flags = IORESOURCE_MEM
  74. }
  75. };
  76. #define kernel_code mem_res[0]
  77. #define kernel_data mem_res[1]
  78. void __init early_print(const char *str, ...)
  79. {
  80. char buf[256];
  81. va_list ap;
  82. va_start(ap, str);
  83. vsnprintf(buf, sizeof(buf), str, ap);
  84. va_end(ap);
  85. printk("%s", buf);
  86. }
  87. static void __init setup_processor(void)
  88. {
  89. struct cpu_info *cpu_info;
  90. /*
  91. * locate processor in the list of supported processor
  92. * types. The linker builds this table for us from the
  93. * entries in arch/arm/mm/proc.S
  94. */
  95. cpu_info = lookup_processor_type(read_cpuid_id());
  96. if (!cpu_info) {
  97. printk("CPU configuration botched (ID %08x), unable to continue.\n",
  98. read_cpuid_id());
  99. while (1);
  100. }
  101. cpu_name = cpu_info->cpu_name;
  102. printk("CPU: %s [%08x] revision %d\n",
  103. cpu_name, read_cpuid_id(), read_cpuid_id() & 15);
  104. sprintf(init_utsname()->machine, "aarch64");
  105. elf_hwcap = 0;
  106. }
  107. static void __init setup_machine_fdt(phys_addr_t dt_phys)
  108. {
  109. struct boot_param_header *devtree;
  110. unsigned long dt_root;
  111. /* Check we have a non-NULL DT pointer */
  112. if (!dt_phys) {
  113. early_print("\n"
  114. "Error: NULL or invalid device tree blob\n"
  115. "The dtb must be 8-byte aligned and passed in the first 512MB of memory\n"
  116. "\nPlease check your bootloader.\n");
  117. while (true)
  118. cpu_relax();
  119. }
  120. devtree = phys_to_virt(dt_phys);
  121. /* Check device tree validity */
  122. if (be32_to_cpu(devtree->magic) != OF_DT_HEADER) {
  123. early_print("\n"
  124. "Error: invalid device tree blob at physical address 0x%p (virtual address 0x%p)\n"
  125. "Expected 0x%x, found 0x%x\n"
  126. "\nPlease check your bootloader.\n",
  127. dt_phys, devtree, OF_DT_HEADER,
  128. be32_to_cpu(devtree->magic));
  129. while (true)
  130. cpu_relax();
  131. }
  132. initial_boot_params = devtree;
  133. dt_root = of_get_flat_dt_root();
  134. machine_name = of_get_flat_dt_prop(dt_root, "model", NULL);
  135. if (!machine_name)
  136. machine_name = of_get_flat_dt_prop(dt_root, "compatible", NULL);
  137. if (!machine_name)
  138. machine_name = "<unknown>";
  139. pr_info("Machine: %s\n", machine_name);
  140. /* Retrieve various information from the /chosen node */
  141. of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
  142. /* Initialize {size,address}-cells info */
  143. of_scan_flat_dt(early_init_dt_scan_root, NULL);
  144. /* Setup memory, calling early_init_dt_add_memory_arch */
  145. of_scan_flat_dt(early_init_dt_scan_memory, NULL);
  146. }
  147. void __init early_init_dt_add_memory_arch(u64 base, u64 size)
  148. {
  149. base &= PAGE_MASK;
  150. size &= PAGE_MASK;
  151. if (base + size < PHYS_OFFSET) {
  152. pr_warning("Ignoring memory block 0x%llx - 0x%llx\n",
  153. base, base + size);
  154. return;
  155. }
  156. if (base < PHYS_OFFSET) {
  157. pr_warning("Ignoring memory range 0x%llx - 0x%llx\n",
  158. base, PHYS_OFFSET);
  159. size -= PHYS_OFFSET - base;
  160. base = PHYS_OFFSET;
  161. }
  162. memblock_add(base, size);
  163. }
  164. void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
  165. {
  166. return __va(memblock_alloc(size, align));
  167. }
  168. /*
  169. * Limit the memory size that was specified via FDT.
  170. */
  171. static int __init early_mem(char *p)
  172. {
  173. phys_addr_t limit;
  174. if (!p)
  175. return 1;
  176. limit = memparse(p, &p) & PAGE_MASK;
  177. pr_notice("Memory limited to %lldMB\n", limit >> 20);
  178. memblock_enforce_memory_limit(limit);
  179. return 0;
  180. }
  181. early_param("mem", early_mem);
  182. static void __init request_standard_resources(void)
  183. {
  184. struct memblock_region *region;
  185. struct resource *res;
  186. kernel_code.start = virt_to_phys(_text);
  187. kernel_code.end = virt_to_phys(_etext - 1);
  188. kernel_data.start = virt_to_phys(_sdata);
  189. kernel_data.end = virt_to_phys(_end - 1);
  190. for_each_memblock(memory, region) {
  191. res = alloc_bootmem_low(sizeof(*res));
  192. res->name = "System RAM";
  193. res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
  194. res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
  195. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  196. request_resource(&iomem_resource, res);
  197. if (kernel_code.start >= res->start &&
  198. kernel_code.end <= res->end)
  199. request_resource(res, &kernel_code);
  200. if (kernel_data.start >= res->start &&
  201. kernel_data.end <= res->end)
  202. request_resource(res, &kernel_data);
  203. }
  204. }
  205. void __init setup_arch(char **cmdline_p)
  206. {
  207. setup_processor();
  208. setup_machine_fdt(__fdt_pointer);
  209. init_mm.start_code = (unsigned long) _text;
  210. init_mm.end_code = (unsigned long) _etext;
  211. init_mm.end_data = (unsigned long) _edata;
  212. init_mm.brk = (unsigned long) _end;
  213. *cmdline_p = boot_command_line;
  214. parse_early_param();
  215. arm64_memblock_init();
  216. paging_init();
  217. request_standard_resources();
  218. unflatten_device_tree();
  219. psci_init();
  220. #ifdef CONFIG_SMP
  221. smp_init_cpus();
  222. #endif
  223. #ifdef CONFIG_VT
  224. #if defined(CONFIG_VGA_CONSOLE)
  225. conswitchp = &vga_con;
  226. #elif defined(CONFIG_DUMMY_CONSOLE)
  227. conswitchp = &dummy_con;
  228. #endif
  229. #endif
  230. }
  231. static DEFINE_PER_CPU(struct cpu, cpu_data);
  232. static int __init topology_init(void)
  233. {
  234. int i;
  235. for_each_possible_cpu(i) {
  236. struct cpu *cpu = &per_cpu(cpu_data, i);
  237. cpu->hotpluggable = 1;
  238. register_cpu(cpu, i);
  239. }
  240. return 0;
  241. }
  242. subsys_initcall(topology_init);
  243. static int __init arm64_device_probe(void)
  244. {
  245. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  246. return 0;
  247. }
  248. device_initcall(arm64_device_probe);
  249. static const char *hwcap_str[] = {
  250. "fp",
  251. "asimd",
  252. NULL
  253. };
  254. static int c_show(struct seq_file *m, void *v)
  255. {
  256. int i;
  257. seq_printf(m, "Processor\t: %s rev %d (%s)\n",
  258. cpu_name, read_cpuid_id() & 15, ELF_PLATFORM);
  259. for_each_online_cpu(i) {
  260. /*
  261. * glibc reads /proc/cpuinfo to determine the number of
  262. * online processors, looking for lines beginning with
  263. * "processor". Give glibc what it expects.
  264. */
  265. #ifdef CONFIG_SMP
  266. seq_printf(m, "processor\t: %d\n", i);
  267. #endif
  268. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n\n",
  269. loops_per_jiffy / (500000UL/HZ),
  270. loops_per_jiffy / (5000UL/HZ) % 100);
  271. }
  272. /* dump out the processor features */
  273. seq_puts(m, "Features\t: ");
  274. for (i = 0; hwcap_str[i]; i++)
  275. if (elf_hwcap & (1 << i))
  276. seq_printf(m, "%s ", hwcap_str[i]);
  277. seq_printf(m, "\nCPU implementer\t: 0x%02x\n", read_cpuid_id() >> 24);
  278. seq_printf(m, "CPU architecture: AArch64\n");
  279. seq_printf(m, "CPU variant\t: 0x%x\n", (read_cpuid_id() >> 20) & 15);
  280. seq_printf(m, "CPU part\t: 0x%03x\n", (read_cpuid_id() >> 4) & 0xfff);
  281. seq_printf(m, "CPU revision\t: %d\n", read_cpuid_id() & 15);
  282. seq_puts(m, "\n");
  283. seq_printf(m, "Hardware\t: %s\n", machine_name);
  284. return 0;
  285. }
  286. static void *c_start(struct seq_file *m, loff_t *pos)
  287. {
  288. return *pos < 1 ? (void *)1 : NULL;
  289. }
  290. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  291. {
  292. ++*pos;
  293. return NULL;
  294. }
  295. static void c_stop(struct seq_file *m, void *v)
  296. {
  297. }
  298. const struct seq_operations cpuinfo_op = {
  299. .start = c_start,
  300. .next = c_next,
  301. .stop = c_stop,
  302. .show = c_show
  303. };