1/* 2 * Copyright (c) 2021-2025, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7#include <asm_macros.S> 8#include <services/rmmd_svc.h> 9 10#include <platform_def.h> 11#include "trp_private.h" 12 13.global trp_head 14.global trp_smc 15 16.section ".head.text", "ax" 17 18 /* --------------------------------------------- 19 * Populate the params in x0-x7 from the pointer 20 * to the smc args structure in x0. 21 * --------------------------------------------- 22 */ 23 .macro restore_args_call_smc 24 ldp x10, x11, [x0, #TRP_ARG10] 25 ldp x8, x9, [x0, #TRP_ARG8] 26 ldp x6, x7, [x0, #TRP_ARG6] 27 ldp x4, x5, [x0, #TRP_ARG4] 28 ldp x2, x3, [x0, #TRP_ARG2] 29 ldp x0, x1, [x0, #TRP_ARG0] 30 smc #0 31 .endm 32 33 /* --------------------------------------------- 34 * Entry point for TRP 35 * --------------------------------------------- 36 */ 37trp_head: 38 /* 39 * Stash arguments from previous boot stage 40 */ 41 mov x20, x0 42 mov x21, x1 43 mov x22, x2 44 mov x23, x3 45 46 /* 47 * Validate CPUId before allocating a stack. 48 */ 49 cmp x20, #PLATFORM_CORE_COUNT 50 b.lo 1f 51 52 mov_imm x0, RMM_BOOT_COMPLETE 53 mov_imm x1, E_RMM_BOOT_CPU_ID_OUT_OF_RANGE 54 smc #0 55 56 /* EL3 should never return back here, so panic if it does */ 57 b trp_panic 58 591: 60 bl plat_set_my_stack 61 62 /* 63 * Find out whether this is a cold or warm boot 64 */ 65 ldr x1, cold_boot_flag 66 cbz x1, warm_boot 67 68 /* 69 * Update cold boot flag to indicate cold boot is done 70 */ 71 adr x2, cold_boot_flag 72 str xzr, [x2] 73 74 /* --------------------------------------------- 75 * Zero out BSS section 76 * --------------------------------------------- 77 */ 78 ldr x0, =__BSS_START__ 79 ldr x1, =__BSS_SIZE__ 80 bl zeromem 81 82 mov x0, x20 83 mov x1, x21 84 mov x2, x22 85 mov x3, x23 86 bl trp_setup 87 bl trp_main 88 b 1f 89 90warm_boot: 91 mov x0, x20 92 mov x1, x21 93 mov x2, x22 94 mov x3, x23 95 bl trp_validate_warmboot_args 96 cbnz x0, trp_panic /* Failed to validate warmboot args */ 97 981: 99 mov_imm x0, RMM_BOOT_COMPLETE 100 mov x1, xzr /* RMM_BOOT_SUCCESS */ 101 smc #0 102 b trp_handler 103 104trp_panic: 105 no_ret plat_panic_handler 106 107 /* 108 * Flag to mark if it is a cold boot. 109 * 1: cold boot, 0: warmboot. 110 */ 111.align 3 112cold_boot_flag: 113 .dword 1 114 115 /* --------------------------------------------- 116 * Direct SMC call to BL31 service provided by 117 * RMM Dispatcher 118 * --------------------------------------------- 119 */ 120func trp_smc 121 restore_args_call_smc 122 ret 123endfunc trp_smc 124 125 /* --------------------------------------------- 126 * RMI call handler 127 * --------------------------------------------- 128 */ 129func trp_handler 130 /* 131 * Save Link Register and X4, as per SMCCC v1.2 its value 132 * must be preserved unless it contains result, as specified 133 * in the function definition. 134 */ 135 stp x4, lr, [sp, #-16]! 136 137 /* 138 * Zero the space for X0-X3 in trp_smc_result structure 139 * and pass its address as the last argument. 140 */ 141 stp xzr, xzr, [sp, #-16]! 142 stp xzr, xzr, [sp, #-16]! 143 mov x7, sp 144 145 bl trp_rmi_handler 146 147 ldp x1, x2, [sp], #16 148 ldp x3, x4, [sp], #16 149 ldp x5, lr, [sp], #16 150 151 ldr x0, =RMM_RMI_REQ_COMPLETE 152 smc #0 153 154 b trp_handler 155endfunc trp_handler 156