1d2912cb1SThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-only */ 2c121c506SVineet Gupta/* 3c121c506SVineet Gupta * ARC CPU startup Code 4c121c506SVineet Gupta * 5c121c506SVineet Gupta * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com) 6c121c506SVineet Gupta * 7c121c506SVineet Gupta * Vineetg: Dec 2007 8c121c506SVineet Gupta * -Check if we are running on Simulator or on real hardware 9c121c506SVineet Gupta * to skip certain things during boot on simulator 10c121c506SVineet Gupta */ 11c121c506SVineet Gupta 12ef680cdcSVineet Gupta#include <linux/linkage.h> 13c121c506SVineet Gupta#include <asm/asm-offsets.h> 14c121c506SVineet Gupta#include <asm/entry.h> 15c121c506SVineet Gupta#include <asm/arcregs.h> 16ef680cdcSVineet Gupta#include <asm/cache.h> 174827d0cfSEugeniy Paltsev#include <asm/dsp-impl.h> 18252f6e8eSEugeniy Paltsev#include <asm/irqflags.h> 19ef680cdcSVineet Gupta 20ef680cdcSVineet Gupta.macro CPU_EARLY_SETUP 21ef680cdcSVineet Gupta 22ef680cdcSVineet Gupta ; Setting up Vectror Table (in case exception happens in early boot 23ef680cdcSVineet Gupta sr @_int_vec_base_lds, [AUX_INTR_VEC_BASE] 24ef680cdcSVineet Gupta 25ef680cdcSVineet Gupta ; Disable I-cache/D-cache if kernel so configured 26ef680cdcSVineet Gupta lr r5, [ARC_REG_IC_BCR] 27ef680cdcSVineet Gupta breq r5, 0, 1f ; I$ doesn't exist 28ef680cdcSVineet Gupta lr r5, [ARC_REG_IC_CTRL] 29ef680cdcSVineet Gupta#ifdef CONFIG_ARC_HAS_ICACHE 30ef680cdcSVineet Gupta bclr r5, r5, 0 ; 0 - Enable, 1 is Disable 31ef680cdcSVineet Gupta#else 32ef680cdcSVineet Gupta bset r5, r5, 0 ; I$ exists, but is not used 33ef680cdcSVineet Gupta#endif 34ef680cdcSVineet Gupta sr r5, [ARC_REG_IC_CTRL] 35ef680cdcSVineet Gupta 36ef680cdcSVineet Gupta1: 37ef680cdcSVineet Gupta lr r5, [ARC_REG_DC_BCR] 38ef680cdcSVineet Gupta breq r5, 0, 1f ; D$ doesn't exist 39ef680cdcSVineet Gupta lr r5, [ARC_REG_DC_CTRL] 40ef680cdcSVineet Gupta bclr r5, r5, 6 ; Invalidate (discard w/o wback) 41ef680cdcSVineet Gupta#ifdef CONFIG_ARC_HAS_DCACHE 42ef680cdcSVineet Gupta bclr r5, r5, 0 ; Enable (+Inv) 43ef680cdcSVineet Gupta#else 44ef680cdcSVineet Gupta bset r5, r5, 0 ; Disable (+Inv) 45ef680cdcSVineet Gupta#endif 46ef680cdcSVineet Gupta sr r5, [ARC_REG_DC_CTRL] 47ef680cdcSVineet Gupta 48ef680cdcSVineet Gupta1: 49252f6e8eSEugeniy Paltsev 50252f6e8eSEugeniy Paltsev#ifdef CONFIG_ISA_ARCV2 51252f6e8eSEugeniy Paltsev ; Unaligned access is disabled at reset, so re-enable early as 52252f6e8eSEugeniy Paltsev ; gcc 7.3.1 (ARC GNU 2018.03) onwards generates unaligned access 53252f6e8eSEugeniy Paltsev ; by default 54252f6e8eSEugeniy Paltsev lr r5, [status32] 5576551468SEugeniy Paltsev#ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS 56252f6e8eSEugeniy Paltsev bset r5, r5, STATUS_AD_BIT 5776551468SEugeniy Paltsev#else 5876551468SEugeniy Paltsev ; Although disabled at reset, bootloader might have enabled it 5976551468SEugeniy Paltsev bclr r5, r5, STATUS_AD_BIT 6076551468SEugeniy Paltsev#endif 61252f6e8eSEugeniy Paltsev kflag r5 6210011f7dSEugeniy Paltsev 6310011f7dSEugeniy Paltsev#ifdef CONFIG_ARC_LPB_DISABLE 6410011f7dSEugeniy Paltsev lr r5, [ARC_REG_LPB_BUILD] 6510011f7dSEugeniy Paltsev breq r5, 0, 1f ; LPB doesn't exist 6610011f7dSEugeniy Paltsev mov r5, 1 6710011f7dSEugeniy Paltsev sr r5, [ARC_REG_LPB_CTRL] 6810011f7dSEugeniy Paltsev1: 6910011f7dSEugeniy Paltsev#endif /* CONFIG_ARC_LPB_DISABLE */ 70*3b57533bSVineet Gupta 71*3b57533bSVineet Gupta /* On HSDK, CCMs need to remapped super early */ 72*3b57533bSVineet Gupta#ifdef CONFIG_ARC_SOC_HSDK 73*3b57533bSVineet Gupta mov r6, 0x60000000 74*3b57533bSVineet Gupta lr r5, [ARC_REG_ICCM_BUILD] 75*3b57533bSVineet Gupta breq r5, 0, 1f 76*3b57533bSVineet Gupta sr r6, [ARC_REG_AUX_ICCM] 77*3b57533bSVineet Gupta1: 78*3b57533bSVineet Gupta lr r5, [ARC_REG_DCCM_BUILD] 79*3b57533bSVineet Gupta breq r5, 0, 2f 80*3b57533bSVineet Gupta sr r6, [ARC_REG_AUX_DCCM] 81*3b57533bSVineet Gupta2: 82*3b57533bSVineet Gupta#endif /* CONFIG_ARC_SOC_HSDK */ 83*3b57533bSVineet Gupta 84*3b57533bSVineet Gupta#endif /* CONFIG_ISA_ARCV2 */ 85*3b57533bSVineet Gupta 864827d0cfSEugeniy Paltsev ; Config DSP_CTRL properly, so kernel may use integer multiply, 874827d0cfSEugeniy Paltsev ; multiply-accumulate, and divide operations 884827d0cfSEugeniy Paltsev DSP_EARLY_INIT 89ef680cdcSVineet Gupta.endm 90c121c506SVineet Gupta 91c121c506SVineet Gupta .section .init.text, "ax",@progbits 923971cdc2SVineet Gupta 933971cdc2SVineet Gupta;---------------------------------------------------------------- 943971cdc2SVineet Gupta; Default Reset Handler (jumped into from Reset vector) 953971cdc2SVineet Gupta; - Don't clobber r0,r1,r2 as they might have u-boot provided args 963971cdc2SVineet Gupta; - Platforms can override this weak version if needed 973971cdc2SVineet Gupta;---------------------------------------------------------------- 983971cdc2SVineet GuptaWEAK(res_service) 993971cdc2SVineet Gupta j stext 1003971cdc2SVineet GuptaEND(res_service) 1013971cdc2SVineet Gupta 1023971cdc2SVineet Gupta;---------------------------------------------------------------- 1033971cdc2SVineet Gupta; Kernel Entry point 1043971cdc2SVineet Gupta;---------------------------------------------------------------- 1053971cdc2SVineet GuptaENTRY(stext) 106c121c506SVineet Gupta 107ef680cdcSVineet Gupta CPU_EARLY_SETUP 10805b016ecSVineet Gupta 10941195d23SVineet Gupta#ifdef CONFIG_SMP 11041195d23SVineet Gupta GET_CPU_ID r5 11141195d23SVineet Gupta cmp r5, 0 1123971cdc2SVineet Gupta mov.nz r0, r5 113bf02454aSVineet Gupta bz .Lmaster_proceed 114bf02454aSVineet Gupta 1153971cdc2SVineet Gupta ; Non-Masters wait for Master to boot enough and bring them up 116bf02454aSVineet Gupta ; when they resume, tail-call to entry point 117bf02454aSVineet Gupta mov blink, @first_lines_of_secondary 118bf02454aSVineet Gupta j arc_platform_smp_wait_to_boot 119bf02454aSVineet Gupta 120bf02454aSVineet Gupta.Lmaster_proceed: 1213971cdc2SVineet Gupta#endif 1223971cdc2SVineet Gupta 123c121c506SVineet Gupta ; Clear BSS before updating any globals 124c121c506SVineet Gupta ; XXX: use ZOL here 125c121c506SVineet Gupta mov r5, __bss_start 126bef444a3SVineet Gupta sub r6, __bss_stop, r5 127bef444a3SVineet Gupta lsr.f lp_count, r6, 2 128bef444a3SVineet Gupta lpnz 1f 129c121c506SVineet Gupta st.ab 0, [r5, 4] 130bef444a3SVineet Gupta1: 131c121c506SVineet Gupta 13259ed9413SVineet Gupta ; Uboot - kernel ABI 13359ed9413SVineet Gupta ; r0 = [0] No uboot interaction, [1] cmdline in r2, [2] DTB in r2 134a66f2e57SEugeniy Paltsev ; r1 = magic number (always zero as of now) 13559ed9413SVineet Gupta ; r2 = pointer to uboot provided cmdline or external DTB in mem 136a66f2e57SEugeniy Paltsev ; These are handled later in handle_uboot_args() 13759ed9413SVineet Gupta st r0, [@uboot_tag] 138edb64bcaSEugeniy Paltsev st r1, [@uboot_magic] 13959ed9413SVineet Gupta st r2, [@uboot_arg] 140c121c506SVineet Gupta 141c121c506SVineet Gupta ; setup "current" tsk and optionally cache it in dedicated r25 142c121c506SVineet Gupta mov r9, @init_task 143c121c506SVineet Gupta SET_CURR_TASK_ON_CPU r9, r0 ; r9 = tsk, r0 = scratch 144c121c506SVineet Gupta 145c121c506SVineet Gupta ; setup stack (fp, sp) 146c121c506SVineet Gupta mov fp, 0 147c121c506SVineet Gupta 148c121c506SVineet Gupta ; tsk->thread_info is really a PAGE, whose bottom hoists stack 149c121c506SVineet Gupta GET_TSK_STACK_BASE r9, sp ; r9 = tsk, sp = stack base(output) 150c121c506SVineet Gupta 151c121c506SVineet Gupta j start_kernel ; "C" entry point 1523971cdc2SVineet GuptaEND(stext) 15341195d23SVineet Gupta 15441195d23SVineet Gupta#ifdef CONFIG_SMP 15541195d23SVineet Gupta;---------------------------------------------------------------- 15641195d23SVineet Gupta; First lines of code run by secondary before jumping to 'C' 15741195d23SVineet Gupta;---------------------------------------------------------------- 1588f5d221bSChen Gang .section .text, "ax",@progbits 1593971cdc2SVineet GuptaENTRY(first_lines_of_secondary) 16041195d23SVineet Gupta 16141195d23SVineet Gupta ; setup per-cpu idle task as "current" on this CPU 16241195d23SVineet Gupta ld r0, [@secondary_idle_tsk] 16341195d23SVineet Gupta SET_CURR_TASK_ON_CPU r0, r1 16441195d23SVineet Gupta 16541195d23SVineet Gupta ; setup stack (fp, sp) 16641195d23SVineet Gupta mov fp, 0 16741195d23SVineet Gupta 16841195d23SVineet Gupta ; set it's stack base to tsk->thread_info bottom 16941195d23SVineet Gupta GET_TSK_STACK_BASE r0, sp 17041195d23SVineet Gupta 17141195d23SVineet Gupta j start_kernel_secondary 1723971cdc2SVineet GuptaEND(first_lines_of_secondary) 17341195d23SVineet Gupta#endif 174