1d69ca6baSChristophe Leroy // SPDX-License-Identifier: GPL-2.0 2d69ca6baSChristophe Leroy 3d69ca6baSChristophe Leroy /* 4d69ca6baSChristophe Leroy * Early init before relocation 5d69ca6baSChristophe Leroy */ 6d69ca6baSChristophe Leroy 7d69ca6baSChristophe Leroy #include <linux/init.h> 8d69ca6baSChristophe Leroy #include <linux/kernel.h> 9d69ca6baSChristophe Leroy #include <asm/setup.h> 10d69ca6baSChristophe Leroy #include <asm/sections.h> 11d69ca6baSChristophe Leroy 12d69ca6baSChristophe Leroy /* 13d69ca6baSChristophe Leroy * We're called here very early in the boot. 14d69ca6baSChristophe Leroy * 15d69ca6baSChristophe Leroy * Note that the kernel may be running at an address which is different 16d69ca6baSChristophe Leroy * from the address that it was linked at, so we must use RELOC/PTRRELOC 17d69ca6baSChristophe Leroy * to access static data (including strings). -- paulus 18d69ca6baSChristophe Leroy */ early_init(unsigned long dt_ptr)19d69ca6baSChristophe Leroynotrace unsigned long __init early_init(unsigned long dt_ptr) 20d69ca6baSChristophe Leroy { 21*2b0e86ccSJason Yan unsigned long kva, offset = reloc_offset(); 22*2b0e86ccSJason Yan 23*2b0e86ccSJason Yan kva = *PTRRELOC(&kernstart_virt_addr); 24d69ca6baSChristophe Leroy 257934cea7SChristophe Leroy /* First zero the BSS */ 26*2b0e86ccSJason Yan if (kva == KERNELBASE) 277934cea7SChristophe Leroy memset(PTRRELOC(&__bss_start), 0, __bss_stop - __bss_start); 28d69ca6baSChristophe Leroy 29d69ca6baSChristophe Leroy /* 30d69ca6baSChristophe Leroy * Identify the CPU type and fix up code sections 31d69ca6baSChristophe Leroy * that depend on which cpu we have. 32d69ca6baSChristophe Leroy */ 33d69ca6baSChristophe Leroy identify_cpu(offset, mfspr(SPRN_PVR)); 34d69ca6baSChristophe Leroy 35d69ca6baSChristophe Leroy apply_feature_fixups(); 36d69ca6baSChristophe Leroy 37*2b0e86ccSJason Yan return kva + offset; 38d69ca6baSChristophe Leroy } 39