xref: /openbmc/linux/arch/csky/kernel/setup.c (revision f17f06a0)
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3 
4 #include <linux/console.h>
5 #include <linux/memblock.h>
6 #include <linux/initrd.h>
7 #include <linux/of.h>
8 #include <linux/of_fdt.h>
9 #include <linux/start_kernel.h>
10 #include <linux/dma-contiguous.h>
11 #include <linux/screen_info.h>
12 #include <asm/sections.h>
13 #include <asm/mmu_context.h>
14 #include <asm/pgalloc.h>
15 
16 #ifdef CONFIG_DUMMY_CONSOLE
17 struct screen_info screen_info = {
18 	.orig_video_lines	= 30,
19 	.orig_video_cols	= 80,
20 	.orig_video_mode	= 0,
21 	.orig_video_ega_bx	= 0,
22 	.orig_video_isVGA	= 1,
23 	.orig_video_points	= 8
24 };
25 #endif
26 
27 phys_addr_t __init_memblock memblock_end_of_REG0(void)
28 {
29 	return (memblock.memory.regions[0].base +
30 		memblock.memory.regions[0].size);
31 }
32 
33 phys_addr_t __init_memblock memblock_start_of_REG1(void)
34 {
35 	return memblock.memory.regions[1].base;
36 }
37 
38 size_t __init_memblock memblock_size_of_REG1(void)
39 {
40 	return memblock.memory.regions[1].size;
41 }
42 
43 static void __init csky_memblock_init(void)
44 {
45 	unsigned long zone_size[MAX_NR_ZONES];
46 	unsigned long zhole_size[MAX_NR_ZONES];
47 	signed long size;
48 
49 	memblock_reserve(__pa(_stext), _end - _stext);
50 
51 	early_init_fdt_reserve_self();
52 	early_init_fdt_scan_reserved_mem();
53 
54 	memblock_dump_all();
55 
56 	memset(zone_size, 0, sizeof(zone_size));
57 	memset(zhole_size, 0, sizeof(zhole_size));
58 
59 	min_low_pfn = PFN_UP(memblock_start_of_DRAM());
60 	max_pfn	    = PFN_DOWN(memblock_end_of_DRAM());
61 
62 	max_low_pfn = PFN_UP(memblock_end_of_REG0());
63 	if (max_low_pfn == 0)
64 		max_low_pfn = max_pfn;
65 
66 	size = max_pfn - min_low_pfn;
67 
68 	if (memblock.memory.cnt > 1) {
69 		zone_size[ZONE_NORMAL]  =
70 			PFN_DOWN(memblock_start_of_REG1()) - min_low_pfn;
71 		zhole_size[ZONE_NORMAL] =
72 			PFN_DOWN(memblock_start_of_REG1()) - max_low_pfn;
73 	} else {
74 		if (size <= PFN_DOWN(LOWMEM_LIMIT - PHYS_OFFSET_OFFSET))
75 			zone_size[ZONE_NORMAL] = max_pfn - min_low_pfn;
76 		else {
77 			zone_size[ZONE_NORMAL] =
78 				PFN_DOWN(LOWMEM_LIMIT - PHYS_OFFSET_OFFSET);
79 			max_low_pfn = min_low_pfn + zone_size[ZONE_NORMAL];
80 		}
81 	}
82 
83 #ifdef CONFIG_HIGHMEM
84 	size = 0;
85 	if (memblock.memory.cnt > 1) {
86 		size = PFN_DOWN(memblock_size_of_REG1());
87 		highstart_pfn = PFN_DOWN(memblock_start_of_REG1());
88 	} else {
89 		size = max_pfn - min_low_pfn -
90 			PFN_DOWN(LOWMEM_LIMIT - PHYS_OFFSET_OFFSET);
91 		highstart_pfn =  min_low_pfn +
92 			PFN_DOWN(LOWMEM_LIMIT - PHYS_OFFSET_OFFSET);
93 	}
94 
95 	if (size > 0)
96 		zone_size[ZONE_HIGHMEM] = size;
97 
98 	highend_pfn = max_pfn;
99 #endif
100 	memblock_set_current_limit(PFN_PHYS(max_low_pfn));
101 
102 	dma_contiguous_reserve(0);
103 
104 	free_area_init_node(0, zone_size, min_low_pfn, zhole_size);
105 }
106 
107 void __init setup_arch(char **cmdline_p)
108 {
109 	*cmdline_p = boot_command_line;
110 
111 	console_verbose();
112 
113 	pr_info("Phys. mem: %ldMB\n",
114 		(unsigned long) memblock_phys_mem_size()/1024/1024);
115 
116 	init_mm.start_code = (unsigned long) _stext;
117 	init_mm.end_code = (unsigned long) _etext;
118 	init_mm.end_data = (unsigned long) _edata;
119 	init_mm.brk = (unsigned long) _end;
120 
121 	parse_early_param();
122 
123 	csky_memblock_init();
124 
125 	unflatten_and_copy_device_tree();
126 
127 #ifdef CONFIG_SMP
128 	setup_smp();
129 #endif
130 
131 	sparse_init();
132 
133 	fixaddr_init();
134 
135 #ifdef CONFIG_HIGHMEM
136 	kmap_init();
137 #endif
138 }
139 
140 unsigned long va_pa_offset;
141 EXPORT_SYMBOL(va_pa_offset);
142 
143 asmlinkage __visible void __init csky_start(unsigned int unused,
144 					    void *dtb_start)
145 {
146 	/* Clean up bss section */
147 	memset(__bss_start, 0, __bss_stop - __bss_start);
148 
149 	va_pa_offset = read_mmu_msa0() & ~(SSEG_SIZE - 1);
150 
151 	pre_trap_init();
152 	pre_mmu_init();
153 
154 	if (dtb_start == NULL)
155 		early_init_dt_scan(__dtb_start);
156 	else
157 		early_init_dt_scan(dtb_start);
158 
159 	start_kernel();
160 
161 	asm volatile("br .\n");
162 }
163