xref: /openbmc/linux/arch/riscv/kernel/setup.c (revision 8f3a2b4a96dc014e99e1df327db1450fdbbd5e15)
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 
21 #include <asm/cpu_ops.h>
22 #include <asm/setup.h>
23 #include <asm/sections.h>
24 #include <asm/sbi.h>
25 #include <asm/tlbflush.h>
26 #include <asm/thread_info.h>
27 #include <asm/kasan.h>
28 
29 #include "head.h"
30 
31 #ifdef CONFIG_DUMMY_CONSOLE
32 struct screen_info screen_info = {
33 	.orig_video_lines	= 30,
34 	.orig_video_cols	= 80,
35 	.orig_video_mode	= 0,
36 	.orig_video_ega_bx	= 0,
37 	.orig_video_isVGA	= 1,
38 	.orig_video_points	= 8
39 };
40 #endif
41 
42 /*
43  * The lucky hart to first increment this variable will boot the other cores.
44  * This is used before the kernel initializes the BSS so it can't be in the
45  * BSS.
46  */
47 atomic_t hart_lottery __section(.sdata);
48 unsigned long boot_cpu_hartid;
49 static DEFINE_PER_CPU(struct cpu, cpu_devices);
50 
51 static void __init parse_dtb(void)
52 {
53 	/* Early scan of device tree from init memory */
54 	if (early_init_dt_scan(dtb_early_va))
55 		return;
56 
57 	pr_err("No DTB passed to the kernel\n");
58 #ifdef CONFIG_CMDLINE_FORCE
59 	strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
60 	pr_info("Forcing kernel command line to: %s\n", boot_command_line);
61 #endif
62 }
63 
64 void __init setup_arch(char **cmdline_p)
65 {
66 	parse_dtb();
67 	init_mm.start_code = (unsigned long) _stext;
68 	init_mm.end_code   = (unsigned long) _etext;
69 	init_mm.end_data   = (unsigned long) _edata;
70 	init_mm.brk        = (unsigned long) _end;
71 
72 	*cmdline_p = boot_command_line;
73 
74 	parse_early_param();
75 
76 	setup_bootmem();
77 	paging_init();
78 #if IS_ENABLED(CONFIG_BUILTIN_DTB)
79 	unflatten_and_copy_device_tree();
80 #else
81 	if (early_init_dt_verify(__va(dtb_early_pa)))
82 		unflatten_device_tree();
83 	else
84 		pr_err("No DTB found in kernel mappings\n");
85 #endif
86 
87 #ifdef CONFIG_SWIOTLB
88 	swiotlb_init(1);
89 #endif
90 
91 #ifdef CONFIG_KASAN
92 	kasan_init();
93 #endif
94 
95 #if IS_ENABLED(CONFIG_RISCV_SBI)
96 	sbi_init();
97 #endif
98 
99 #ifdef CONFIG_SMP
100 	setup_smp();
101 #endif
102 
103 	riscv_fill_hwcap();
104 }
105 
106 static int __init topology_init(void)
107 {
108 	int i;
109 
110 	for_each_possible_cpu(i) {
111 		struct cpu *cpu = &per_cpu(cpu_devices, i);
112 
113 		cpu->hotpluggable = cpu_has_hotplug(i);
114 		register_cpu(cpu, i);
115 	}
116 
117 	return 0;
118 }
119 subsys_initcall(topology_init);
120