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-map-ops.h>
11 #include <asm/sections.h>
12 #include <asm/mmu_context.h>
13 #include <asm/pgalloc.h>
15 static void __init
csky_memblock_init(void)
17 unsigned long lowmem_size
= PFN_DOWN(LOWMEM_LIMIT
- PHYS_OFFSET_OFFSET
);
18 unsigned long sseg_size
= PFN_DOWN(SSEG_SIZE
- PHYS_OFFSET_OFFSET
);
19 unsigned long max_zone_pfn
[MAX_NR_ZONES
] = { 0 };
22 memblock_reserve(__pa(_start
), _end
- _start
);
24 early_init_fdt_reserve_self();
25 early_init_fdt_scan_reserved_mem();
29 min_low_pfn
= PFN_UP(memblock_start_of_DRAM());
30 max_low_pfn
= max_pfn
= PFN_DOWN(memblock_end_of_DRAM());
32 size
= max_pfn
- min_low_pfn
;
34 if (size
>= lowmem_size
) {
35 max_low_pfn
= min_low_pfn
+ lowmem_size
;
36 #ifdef CONFIG_PAGE_OFFSET_80000000
37 write_mmu_msa1(read_mmu_msa0() + SSEG_SIZE
);
39 } else if (size
> sseg_size
) {
40 max_low_pfn
= min_low_pfn
+ sseg_size
;
43 max_zone_pfn
[ZONE_NORMAL
] = max_low_pfn
;
45 mmu_init(min_low_pfn
, max_low_pfn
);
48 max_zone_pfn
[ZONE_HIGHMEM
] = max_pfn
;
50 highstart_pfn
= max_low_pfn
;
51 highend_pfn
= max_pfn
;
53 memblock_set_current_limit(PFN_PHYS(max_low_pfn
));
55 dma_contiguous_reserve(0);
57 free_area_init(max_zone_pfn
);
60 void __init
setup_arch(char **cmdline_p
)
62 *cmdline_p
= boot_command_line
;
66 pr_info("Phys. mem: %ldMB\n",
67 (unsigned long) memblock_phys_mem_size()/1024/1024);
69 setup_initial_init_mm(_start
, _etext
, _edata
, _end
);
75 unflatten_and_copy_device_tree();
90 unsigned long va_pa_offset
;
91 EXPORT_SYMBOL(va_pa_offset
);
93 static inline unsigned long read_mmu_msa(void)
95 #ifdef CONFIG_PAGE_OFFSET_80000000
96 return read_mmu_msa0();
99 #ifdef CONFIG_PAGE_OFFSET_A0000000
100 return read_mmu_msa1();
104 asmlinkage __visible
void __init
csky_start(unsigned int unused
,
107 /* Clean up bss section */
108 memset(__bss_start
, 0, __bss_stop
- __bss_start
);
110 va_pa_offset
= read_mmu_msa() & ~(SSEG_SIZE
- 1);
114 if (dtb_start
== NULL
)
115 early_init_dt_scan(__dtb_start
);
117 early_init_dt_scan(dtb_start
);
121 asm volatile("br .\n");