1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
4 #include <linux/console.h>
5 #include <linux/memblock.h>
6 #include <linux/initrd.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>
16 #ifdef CONFIG_DUMMY_CONSOLE
17 struct screen_info screen_info
= {
18 .orig_video_lines
= 30,
19 .orig_video_cols
= 80,
21 .orig_video_ega_bx
= 0,
22 .orig_video_isVGA
= 1,
23 .orig_video_points
= 8
27 phys_addr_t __init_memblock
memblock_end_of_REG0(void)
29 return (memblock
.memory
.regions
[0].base
+
30 memblock
.memory
.regions
[0].size
);
33 phys_addr_t __init_memblock
memblock_start_of_REG1(void)
35 return memblock
.memory
.regions
[1].base
;
38 size_t __init_memblock
memblock_size_of_REG1(void)
40 return memblock
.memory
.regions
[1].size
;
43 static void __init
csky_memblock_init(void)
45 unsigned long zone_size
[MAX_NR_ZONES
];
46 unsigned long zhole_size
[MAX_NR_ZONES
];
49 memblock_reserve(__pa(_stext
), _end
- _stext
);
51 early_init_fdt_reserve_self();
52 early_init_fdt_scan_reserved_mem();
56 memset(zone_size
, 0, sizeof(zone_size
));
57 memset(zhole_size
, 0, sizeof(zhole_size
));
59 min_low_pfn
= PFN_UP(memblock_start_of_DRAM());
60 max_pfn
= PFN_DOWN(memblock_end_of_DRAM());
62 max_low_pfn
= PFN_UP(memblock_end_of_REG0());
64 max_low_pfn
= max_pfn
;
66 size
= max_pfn
- min_low_pfn
;
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
;
74 if (size
<= PFN_DOWN(LOWMEM_LIMIT
- PHYS_OFFSET_OFFSET
))
75 zone_size
[ZONE_NORMAL
] = max_pfn
- min_low_pfn
;
77 zone_size
[ZONE_NORMAL
] =
78 PFN_DOWN(LOWMEM_LIMIT
- PHYS_OFFSET_OFFSET
);
79 max_low_pfn
= min_low_pfn
+ zone_size
[ZONE_NORMAL
];
85 if (memblock
.memory
.cnt
> 1) {
86 size
= PFN_DOWN(memblock_size_of_REG1());
87 highstart_pfn
= PFN_DOWN(memblock_start_of_REG1());
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
);
96 zone_size
[ZONE_HIGHMEM
] = size
;
98 highend_pfn
= max_pfn
;
100 memblock_set_current_limit(PFN_PHYS(max_low_pfn
));
102 dma_contiguous_reserve(0);
104 free_area_init_node(0, zone_size
, min_low_pfn
, zhole_size
);
107 void __init
setup_arch(char **cmdline_p
)
109 *cmdline_p
= boot_command_line
;
113 pr_info("Phys. mem: %ldMB\n",
114 (unsigned long) memblock_phys_mem_size()/1024/1024);
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
;
123 csky_memblock_init();
125 unflatten_and_copy_device_tree();
135 #ifdef CONFIG_HIGHMEM
140 unsigned long va_pa_offset
;
141 EXPORT_SYMBOL(va_pa_offset
);
143 asmlinkage __visible
void __init
csky_start(unsigned int unused
,
146 /* Clean up bss section */
147 memset(__bss_start
, 0, __bss_stop
- __bss_start
);
149 va_pa_offset
= read_mmu_msa0() & ~(SSEG_SIZE
- 1);
154 if (dtb_start
== NULL
)
155 early_init_dt_scan(__dtb_start
);
157 early_init_dt_scan(dtb_start
);
161 asm volatile("br .\n");