xref: /linux/arch/csky/kernel/setup.c (revision fd90410e)
19143a935SGuo Ren // SPDX-License-Identifier: GPL-2.0
29143a935SGuo Ren // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
39143a935SGuo Ren 
49143a935SGuo Ren #include <linux/console.h>
59143a935SGuo Ren #include <linux/memblock.h>
69143a935SGuo Ren #include <linux/initrd.h>
79143a935SGuo Ren #include <linux/of.h>
89143a935SGuo Ren #include <linux/of_fdt.h>
99143a935SGuo Ren #include <linux/start_kernel.h>
100b1abd1fSChristoph Hellwig #include <linux/dma-map-ops.h>
119143a935SGuo Ren #include <asm/sections.h>
129143a935SGuo Ren #include <asm/mmu_context.h>
139143a935SGuo Ren #include <asm/pgalloc.h>
149143a935SGuo Ren 
csky_memblock_init(void)159143a935SGuo Ren static void __init csky_memblock_init(void)
169143a935SGuo Ren {
178f4693f0SMike Rapoport 	unsigned long lowmem_size = PFN_DOWN(LOWMEM_LIMIT - PHYS_OFFSET_OFFSET);
188f4693f0SMike Rapoport 	unsigned long sseg_size = PFN_DOWN(SSEG_SIZE - PHYS_OFFSET_OFFSET);
198f4693f0SMike Rapoport 	unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
209143a935SGuo Ren 	signed long size;
219143a935SGuo Ren 
22*f54af50dSGuo Ren 	memblock_reserve(__pa(_start), _end - _start);
239143a935SGuo Ren 
249143a935SGuo Ren 	early_init_fdt_reserve_self();
259143a935SGuo Ren 	early_init_fdt_scan_reserved_mem();
269143a935SGuo Ren 
279143a935SGuo Ren 	memblock_dump_all();
289143a935SGuo Ren 
299143a935SGuo Ren 	min_low_pfn = PFN_UP(memblock_start_of_DRAM());
30aefd9461SGuo Ren 	max_low_pfn = max_pfn = PFN_DOWN(memblock_end_of_DRAM());
319143a935SGuo Ren 
329143a935SGuo Ren 	size = max_pfn - min_low_pfn;
339143a935SGuo Ren 
348f4693f0SMike Rapoport 	if (size >= lowmem_size) {
358f4693f0SMike Rapoport 		max_low_pfn = min_low_pfn + lowmem_size;
360c8a32eeSGuo Ren #ifdef CONFIG_PAGE_OFFSET_80000000
37aefd9461SGuo Ren 		write_mmu_msa1(read_mmu_msa0() + SSEG_SIZE);
380c8a32eeSGuo Ren #endif
398f4693f0SMike Rapoport 	} else if (size > sseg_size) {
408f4693f0SMike Rapoport 		max_low_pfn = min_low_pfn + sseg_size;
419143a935SGuo Ren 	}
429143a935SGuo Ren 
438f4693f0SMike Rapoport 	max_zone_pfn[ZONE_NORMAL] = max_low_pfn;
448f4693f0SMike Rapoport 
450c8a32eeSGuo Ren 	mmu_init(min_low_pfn, max_low_pfn);
460c8a32eeSGuo Ren 
479143a935SGuo Ren #ifdef CONFIG_HIGHMEM
488f4693f0SMike Rapoport 	max_zone_pfn[ZONE_HIGHMEM] = max_pfn;
499143a935SGuo Ren 
50aefd9461SGuo Ren 	highstart_pfn = max_low_pfn;
519143a935SGuo Ren 	highend_pfn   = max_pfn;
529143a935SGuo Ren #endif
539143a935SGuo Ren 	memblock_set_current_limit(PFN_PHYS(max_low_pfn));
549143a935SGuo Ren 
559143a935SGuo Ren 	dma_contiguous_reserve(0);
569143a935SGuo Ren 
578f4693f0SMike Rapoport 	free_area_init(max_zone_pfn);
589143a935SGuo Ren }
599143a935SGuo Ren 
setup_arch(char ** cmdline_p)609143a935SGuo Ren void __init setup_arch(char **cmdline_p)
619143a935SGuo Ren {
629143a935SGuo Ren 	*cmdline_p = boot_command_line;
639143a935SGuo Ren 
649143a935SGuo Ren 	console_verbose();
659143a935SGuo Ren 
669143a935SGuo Ren 	pr_info("Phys. mem: %ldMB\n",
679143a935SGuo Ren 		(unsigned long) memblock_phys_mem_size()/1024/1024);
689143a935SGuo Ren 
69*f54af50dSGuo Ren 	setup_initial_init_mm(_start, _etext, _edata, _end);
709143a935SGuo Ren 
719143a935SGuo Ren 	parse_early_param();
729143a935SGuo Ren 
739143a935SGuo Ren 	csky_memblock_init();
749143a935SGuo Ren 
759143a935SGuo Ren 	unflatten_and_copy_device_tree();
769143a935SGuo Ren 
779143a935SGuo Ren #ifdef CONFIG_SMP
789143a935SGuo Ren 	setup_smp();
799143a935SGuo Ren #endif
809143a935SGuo Ren 
819143a935SGuo Ren 	sparse_init();
829143a935SGuo Ren 
83f136008fSGuo Ren 	fixaddr_init();
84f136008fSGuo Ren 
859143a935SGuo Ren #ifdef CONFIG_HIGHMEM
869143a935SGuo Ren 	kmap_init();
879143a935SGuo Ren #endif
889143a935SGuo Ren }
899143a935SGuo Ren 
90683fafebSGuo Ren unsigned long va_pa_offset;
91683fafebSGuo Ren EXPORT_SYMBOL(va_pa_offset);
92f62e3162SGuo Ren 
read_mmu_msa(void)930c8a32eeSGuo Ren static inline unsigned long read_mmu_msa(void)
940c8a32eeSGuo Ren {
950c8a32eeSGuo Ren #ifdef CONFIG_PAGE_OFFSET_80000000
960c8a32eeSGuo Ren 	return read_mmu_msa0();
970c8a32eeSGuo Ren #endif
980c8a32eeSGuo Ren 
990c8a32eeSGuo Ren #ifdef CONFIG_PAGE_OFFSET_A0000000
1000c8a32eeSGuo Ren 	return read_mmu_msa1();
1010c8a32eeSGuo Ren #endif
1020c8a32eeSGuo Ren }
1030c8a32eeSGuo Ren 
csky_start(unsigned int unused,void * dtb_start)104205353faSGuo Ren asmlinkage __visible void __init csky_start(unsigned int unused,
105205353faSGuo Ren 					    void *dtb_start)
1069143a935SGuo Ren {
1079143a935SGuo Ren 	/* Clean up bss section */
1089143a935SGuo Ren 	memset(__bss_start, 0, __bss_stop - __bss_start);
1099143a935SGuo Ren 
1100c8a32eeSGuo Ren 	va_pa_offset = read_mmu_msa() & ~(SSEG_SIZE - 1);
111f62e3162SGuo Ren 
1129143a935SGuo Ren 	pre_trap_init();
1139143a935SGuo Ren 
114205353faSGuo Ren 	if (dtb_start == NULL)
1159143a935SGuo Ren 		early_init_dt_scan(__dtb_start);
1169143a935SGuo Ren 	else
117205353faSGuo Ren 		early_init_dt_scan(dtb_start);
1189143a935SGuo Ren 
1199143a935SGuo Ren 	start_kernel();
1209143a935SGuo Ren 
1219143a935SGuo Ren 	asm volatile("br .\n");
1229143a935SGuo Ren }
123