b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* |
| 3 | * ARC CPU startup Code |
| 4 | * |
| 5 | * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com) |
| 6 | * |
| 7 | * Vineetg: Dec 2007 |
| 8 | * -Check if we are running on Simulator or on real hardware |
| 9 | * to skip certain things during boot on simulator |
| 10 | */ |
| 11 | |
| 12 | #include <linux/linkage.h> |
| 13 | #include <asm/asm-offsets.h> |
| 14 | #include <asm/entry.h> |
| 15 | #include <asm/arcregs.h> |
| 16 | #include <asm/cache.h> |
| 17 | #include <asm/irqflags.h> |
| 18 | |
| 19 | .macro CPU_EARLY_SETUP |
| 20 | |
| 21 | ; Setting up Vectror Table (in case exception happens in early boot |
| 22 | sr @_int_vec_base_lds, [AUX_INTR_VEC_BASE] |
| 23 | |
| 24 | ; Disable I-cache/D-cache if kernel so configured |
| 25 | lr r5, [ARC_REG_IC_BCR] |
| 26 | breq r5, 0, 1f ; I$ doesn't exist |
| 27 | lr r5, [ARC_REG_IC_CTRL] |
| 28 | #ifdef CONFIG_ARC_HAS_ICACHE |
| 29 | bclr r5, r5, 0 ; 0 - Enable, 1 is Disable |
| 30 | #else |
| 31 | bset r5, r5, 0 ; I$ exists, but is not used |
| 32 | #endif |
| 33 | sr r5, [ARC_REG_IC_CTRL] |
| 34 | |
| 35 | 1: |
| 36 | lr r5, [ARC_REG_DC_BCR] |
| 37 | breq r5, 0, 1f ; D$ doesn't exist |
| 38 | lr r5, [ARC_REG_DC_CTRL] |
| 39 | bclr r5, r5, 6 ; Invalidate (discard w/o wback) |
| 40 | #ifdef CONFIG_ARC_HAS_DCACHE |
| 41 | bclr r5, r5, 0 ; Enable (+Inv) |
| 42 | #else |
| 43 | bset r5, r5, 0 ; Disable (+Inv) |
| 44 | #endif |
| 45 | sr r5, [ARC_REG_DC_CTRL] |
| 46 | |
| 47 | 1: |
| 48 | |
| 49 | #ifdef CONFIG_ISA_ARCV2 |
| 50 | ; Unaligned access is disabled at reset, so re-enable early as |
| 51 | ; gcc 7.3.1 (ARC GNU 2018.03) onwards generates unaligned access |
| 52 | ; by default |
| 53 | lr r5, [status32] |
| 54 | #ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS |
| 55 | bset r5, r5, STATUS_AD_BIT |
| 56 | #else |
| 57 | ; Although disabled at reset, bootloader might have enabled it |
| 58 | bclr r5, r5, STATUS_AD_BIT |
| 59 | #endif |
| 60 | kflag r5 |
| 61 | #endif |
| 62 | .endm |
| 63 | |
| 64 | ; Here "patch-dtb" will embed external .dtb |
| 65 | ; Note "patch-dtb" searches for ASCII "OWRTDTB:" string |
| 66 | ; and pastes .dtb right after it, hense the string precedes |
| 67 | ; __image_dtb symbol. |
| 68 | .section .owrt, "aw",@progbits |
| 69 | .ascii "OWRTDTB:" |
| 70 | ENTRY(__image_dtb) |
| 71 | .fill 0x4000 |
| 72 | END(__image_dtb) |
| 73 | |
| 74 | .section .init.text, "ax",@progbits |
| 75 | |
| 76 | ;---------------------------------------------------------------- |
| 77 | ; Default Reset Handler (jumped into from Reset vector) |
| 78 | ; - Don't clobber r0,r1,r2 as they might have u-boot provided args |
| 79 | ; - Platforms can override this weak version if needed |
| 80 | ;---------------------------------------------------------------- |
| 81 | WEAK(res_service) |
| 82 | j stext |
| 83 | END(res_service) |
| 84 | |
| 85 | ;---------------------------------------------------------------- |
| 86 | ; Kernel Entry point |
| 87 | ;---------------------------------------------------------------- |
| 88 | ENTRY(stext) |
| 89 | |
| 90 | CPU_EARLY_SETUP |
| 91 | |
| 92 | #ifdef CONFIG_SMP |
| 93 | GET_CPU_ID r5 |
| 94 | cmp r5, 0 |
| 95 | mov.nz r0, r5 |
| 96 | bz .Lmaster_proceed |
| 97 | |
| 98 | ; Non-Masters wait for Master to boot enough and bring them up |
| 99 | ; when they resume, tail-call to entry point |
| 100 | mov blink, @first_lines_of_secondary |
| 101 | j arc_platform_smp_wait_to_boot |
| 102 | |
| 103 | .Lmaster_proceed: |
| 104 | #endif |
| 105 | |
| 106 | ; Clear BSS before updating any globals |
| 107 | ; XXX: use ZOL here |
| 108 | mov r5, __bss_start |
| 109 | sub r6, __bss_stop, r5 |
| 110 | lsr.f lp_count, r6, 2 |
| 111 | lpnz 1f |
| 112 | st.ab 0, [r5, 4] |
| 113 | 1: |
| 114 | |
| 115 | ; Uboot - kernel ABI |
| 116 | ; r0 = [0] No uboot interaction, [1] cmdline in r2, [2] DTB in r2 |
| 117 | ; r1 = magic number (always zero as of now) |
| 118 | ; r2 = pointer to uboot provided cmdline or external DTB in mem |
| 119 | ; These are handled later in handle_uboot_args() |
| 120 | st r0, [@uboot_tag] |
| 121 | st r1, [@uboot_magic] |
| 122 | st r2, [@uboot_arg] |
| 123 | |
| 124 | ; setup "current" tsk and optionally cache it in dedicated r25 |
| 125 | mov r9, @init_task |
| 126 | SET_CURR_TASK_ON_CPU r9, r0 ; r9 = tsk, r0 = scratch |
| 127 | |
| 128 | ; setup stack (fp, sp) |
| 129 | mov fp, 0 |
| 130 | |
| 131 | ; tsk->thread_info is really a PAGE, whose bottom hoists stack |
| 132 | GET_TSK_STACK_BASE r9, sp ; r9 = tsk, sp = stack base(output) |
| 133 | |
| 134 | j start_kernel ; "C" entry point |
| 135 | END(stext) |
| 136 | |
| 137 | #ifdef CONFIG_SMP |
| 138 | ;---------------------------------------------------------------- |
| 139 | ; First lines of code run by secondary before jumping to 'C' |
| 140 | ;---------------------------------------------------------------- |
| 141 | .section .text, "ax",@progbits |
| 142 | ENTRY(first_lines_of_secondary) |
| 143 | |
| 144 | ; setup per-cpu idle task as "current" on this CPU |
| 145 | ld r0, [@secondary_idle_tsk] |
| 146 | SET_CURR_TASK_ON_CPU r0, r1 |
| 147 | |
| 148 | ; setup stack (fp, sp) |
| 149 | mov fp, 0 |
| 150 | |
| 151 | ; set it's stack base to tsk->thread_info bottom |
| 152 | GET_TSK_STACK_BASE r0, sp |
| 153 | |
| 154 | j start_kernel_secondary |
| 155 | END(first_lines_of_secondary) |
| 156 | #endif |