1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
4 * Chen Liqin <liqin.chen@sunplusct.com>
5 * Lennox Wu <lennox.wu@sunplusct.com>
6 * Copyright (C) 2012 Regents of the University of California
7 */
8
9 #include <linux/init.h>
10 #include <linux/mm.h>
11 #include <linux/memblock.h>
12 #include <linux/sched.h>
13 #include <linux/console.h>
14 #include <linux/screen_info.h>
15 #include <linux/of_fdt.h>
16 #include <linux/of_platform.h>
17 #include <linux/sched/task.h>
18 #include <linux/swiotlb.h>
19 #include <linux/smp.h>
20 #include <linux/efi.h>
21
22 #include <asm/cpu_ops.h>
23 #include <asm/early_ioremap.h>
24 #include <asm/setup.h>
25 #include <asm/sections.h>
26 #include <asm/sbi.h>
27 #include <asm/tlbflush.h>
28 #include <asm/thread_info.h>
29 #include <asm/kasan.h>
30 #include <asm/efi.h>
31
32 #include "head.h"
33
34 #if defined(CONFIG_DUMMY_CONSOLE) || defined(CONFIG_EFI)
35 struct screen_info screen_info __section(".data") = {
36 .orig_video_lines = 30,
37 .orig_video_cols = 80,
38 .orig_video_mode = 0,
39 .orig_video_ega_bx = 0,
40 .orig_video_isVGA = 1,
41 .orig_video_points = 8
42 };
43 #endif
44
45 /*
46 * The lucky hart to first increment this variable will boot the other cores.
47 * This is used before the kernel initializes the BSS so it can't be in the
48 * BSS.
49 */
50 atomic_t hart_lottery __section(".sdata");
51 unsigned long boot_cpu_hartid;
52 static DEFINE_PER_CPU(struct cpu, cpu_devices);
53
parse_dtb(void)54 static void __init parse_dtb(void)
55 {
56 /* Early scan of device tree from init memory */
57 if (early_init_dt_scan(dtb_early_va)) {
58 const char *name = of_flat_dt_get_machine_name();
59
60 if (name) {
61 pr_info("Machine model: %s\n", name);
62 dump_stack_set_arch_desc("%s (DT)", name);
63 }
64 } else {
65 pr_err("No DTB passed to the kernel\n");
66 }
67
68 #ifdef CONFIG_CMDLINE_FORCE
69 strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
70 pr_info("Forcing kernel command line to: %s\n", boot_command_line);
71 #endif
72 }
73
setup_arch(char ** cmdline_p)74 void __init setup_arch(char **cmdline_p)
75 {
76 parse_dtb();
77 init_mm.start_code = (unsigned long) _stext;
78 init_mm.end_code = (unsigned long) _etext;
79 init_mm.end_data = (unsigned long) _edata;
80 init_mm.brk = (unsigned long) _end;
81
82 *cmdline_p = boot_command_line;
83
84 early_ioremap_setup();
85 jump_label_init();
86 parse_early_param();
87
88 efi_init();
89 setup_bootmem();
90 paging_init();
91 #if IS_ENABLED(CONFIG_BUILTIN_DTB)
92 unflatten_and_copy_device_tree();
93 #else
94 if (early_init_dt_verify(__va(dtb_early_pa)))
95 unflatten_device_tree();
96 else
97 pr_err("No DTB found in kernel mappings\n");
98 #endif
99 early_init_fdt_scan_reserved_mem();
100 misc_mem_init();
101
102 #ifdef CONFIG_SWIOTLB
103 swiotlb_init(1);
104 #endif
105
106 #ifdef CONFIG_KASAN
107 kasan_init();
108 #endif
109
110 #if IS_ENABLED(CONFIG_RISCV_SBI)
111 sbi_init();
112 #endif
113
114 #ifdef CONFIG_SMP
115 setup_smp();
116 #endif
117
118 riscv_fill_hwcap();
119 }
120
topology_init(void)121 static int __init topology_init(void)
122 {
123 int i;
124
125 for_each_possible_cpu(i) {
126 struct cpu *cpu = &per_cpu(cpu_devices, i);
127
128 cpu->hotpluggable = cpu_has_hotplug(i);
129 register_cpu(cpu, i);
130 }
131
132 return 0;
133 }
134 subsys_initcall(topology_init);
135