xref: /linux/arch/riscv/kernel/setup.c (revision 037fc3368be46dc1a2a90f6e50c8cbce49d75fd6)
1 /*
2  * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
3  *  Chen Liqin <liqin.chen@sunplusct.com>
4  *  Lennox Wu <lennox.wu@sunplusct.com>
5  * Copyright (C) 2012 Regents of the University of California
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 as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see the file COPYING, or write
19  * to the Free Software Foundation, Inc.,
20  */
21 
22 #include <linux/init.h>
23 #include <linux/mm.h>
24 #include <linux/memblock.h>
25 #include <linux/sched.h>
26 #include <linux/console.h>
27 #include <linux/screen_info.h>
28 #include <linux/of_fdt.h>
29 #include <linux/of_platform.h>
30 #include <linux/sched/task.h>
31 #include <linux/swiotlb.h>
32 
33 #include <asm/setup.h>
34 #include <asm/sections.h>
35 #include <asm/pgtable.h>
36 #include <asm/smp.h>
37 #include <asm/tlbflush.h>
38 #include <asm/thread_info.h>
39 
40 #ifdef CONFIG_DUMMY_CONSOLE
41 struct screen_info screen_info = {
42 	.orig_video_lines	= 30,
43 	.orig_video_cols	= 80,
44 	.orig_video_mode	= 0,
45 	.orig_video_ega_bx	= 0,
46 	.orig_video_isVGA	= 1,
47 	.orig_video_points	= 8
48 };
49 #endif
50 
51 unsigned long va_pa_offset;
52 EXPORT_SYMBOL(va_pa_offset);
53 unsigned long pfn_base;
54 EXPORT_SYMBOL(pfn_base);
55 
56 unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss;
57 EXPORT_SYMBOL(empty_zero_page);
58 
59 /* The lucky hart to first increment this variable will boot the other cores */
60 atomic_t hart_lottery;
61 unsigned long boot_cpu_hartid;
62 
63 void __init parse_dtb(unsigned int hartid, void *dtb)
64 {
65 	if (early_init_dt_scan(__va(dtb)))
66 		return;
67 
68 	pr_err("No DTB passed to the kernel\n");
69 #ifdef CONFIG_CMDLINE_FORCE
70 	strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
71 	pr_info("Forcing kernel command line to: %s\n", boot_command_line);
72 #endif
73 }
74 
75 void __init setup_arch(char **cmdline_p)
76 {
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 	parse_early_param();
85 
86 	setup_bootmem();
87 	paging_init();
88 	unflatten_device_tree();
89 
90 #ifdef CONFIG_SWIOTLB
91 	swiotlb_init(1);
92 #endif
93 
94 #ifdef CONFIG_SMP
95 	setup_smp();
96 #endif
97 
98 #ifdef CONFIG_DUMMY_CONSOLE
99 	conswitchp = &dummy_con;
100 #endif
101 
102 	riscv_fill_hwcap();
103 }
104