1*91f16700Schasinglulu/* 2*91f16700Schasinglulu * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved. 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu */ 6*91f16700Schasinglulu 7*91f16700Schasinglulu#include <arch.h> 8*91f16700Schasinglulu#include <asm_macros.S> 9*91f16700Schasinglulu#include <assert_macros.S> 10*91f16700Schasinglulu#include <platform_def.h> 11*91f16700Schasinglulu 12*91f16700Schasinglulu .globl plat_my_core_pos 13*91f16700Schasinglulu .globl plat_get_my_entrypoint 14*91f16700Schasinglulu .globl platform_mem_init 15*91f16700Schasinglulu .globl plat_qemu_calc_core_pos 16*91f16700Schasinglulu .globl plat_crash_console_init 17*91f16700Schasinglulu .globl plat_crash_console_putc 18*91f16700Schasinglulu .globl plat_crash_console_flush 19*91f16700Schasinglulu .globl plat_secondary_cold_boot_setup 20*91f16700Schasinglulu .globl plat_get_my_entrypoint 21*91f16700Schasinglulu .globl plat_is_my_cpu_primary 22*91f16700Schasinglulu 23*91f16700Schasinglulu 24*91f16700Schasinglulufunc plat_my_core_pos 25*91f16700Schasinglulu ldcopr r0, MPIDR 26*91f16700Schasinglulu b plat_qemu_calc_core_pos 27*91f16700Schasingluluendfunc plat_my_core_pos 28*91f16700Schasinglulu 29*91f16700Schasinglulu/* 30*91f16700Schasinglulu * unsigned int plat_qemu_calc_core_pos(u_register_t mpidr); 31*91f16700Schasinglulu * With this function: CorePos = (ClusterId * 4) + CoreId 32*91f16700Schasinglulu */ 33*91f16700Schasinglulufunc plat_qemu_calc_core_pos 34*91f16700Schasinglulu and r1, r0, #MPIDR_CPU_MASK 35*91f16700Schasinglulu and r0, r0, #MPIDR_CLUSTER_MASK 36*91f16700Schasinglulu add r0, r1, r0, LSR #6 37*91f16700Schasinglulu bx lr 38*91f16700Schasingluluendfunc plat_qemu_calc_core_pos 39*91f16700Schasinglulu 40*91f16700Schasinglulu /* ----------------------------------------------------- 41*91f16700Schasinglulu * unsigned int plat_is_my_cpu_primary (void); 42*91f16700Schasinglulu * 43*91f16700Schasinglulu * Find out whether the current cpu is the primary 44*91f16700Schasinglulu * cpu. 45*91f16700Schasinglulu * ----------------------------------------------------- 46*91f16700Schasinglulu */ 47*91f16700Schasinglulufunc plat_is_my_cpu_primary 48*91f16700Schasinglulu ldcopr r0, MPIDR 49*91f16700Schasinglulu ldr r1, =(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK) 50*91f16700Schasinglulu and r0, r1 51*91f16700Schasinglulu cmp r0, #QEMU_PRIMARY_CPU 52*91f16700Schasinglulu moveq r0, #1 53*91f16700Schasinglulu movne r0, #0 54*91f16700Schasinglulu bx lr 55*91f16700Schasingluluendfunc plat_is_my_cpu_primary 56*91f16700Schasinglulu 57*91f16700Schasinglulu /* ----------------------------------------------------- 58*91f16700Schasinglulu * void plat_secondary_cold_boot_setup (void); 59*91f16700Schasinglulu * 60*91f16700Schasinglulu * This function performs any platform specific actions 61*91f16700Schasinglulu * needed for a secondary cpu after a cold reset e.g 62*91f16700Schasinglulu * mark the cpu's presence, mechanism to place it in a 63*91f16700Schasinglulu * holding pen etc. 64*91f16700Schasinglulu * ----------------------------------------------------- 65*91f16700Schasinglulu */ 66*91f16700Schasinglulufunc plat_secondary_cold_boot_setup 67*91f16700Schasinglulu /* Calculate address of our hold entry */ 68*91f16700Schasinglulu bl plat_my_core_pos 69*91f16700Schasinglulu lsl r0, r0, #PLAT_QEMU_HOLD_ENTRY_SHIFT 70*91f16700Schasinglulu mov_imm r2, PLAT_QEMU_HOLD_BASE 71*91f16700Schasinglulu 72*91f16700Schasinglulu /* Wait until we have a go */ 73*91f16700Schasinglulupoll_mailbox: 74*91f16700Schasinglulu ldr r1, [r2, r0] 75*91f16700Schasinglulu cmp r1, #PLAT_QEMU_HOLD_STATE_WAIT 76*91f16700Schasinglulu beq 1f 77*91f16700Schasinglulu 78*91f16700Schasinglulu /* Clear the mailbox again ready for next time. */ 79*91f16700Schasinglulu mov r1, #PLAT_QEMU_HOLD_STATE_WAIT 80*91f16700Schasinglulu str r1, [r2, r0] 81*91f16700Schasinglulu 82*91f16700Schasinglulu /* Jump to the provided entrypoint. */ 83*91f16700Schasinglulu mov_imm r0, PLAT_QEMU_TRUSTED_MAILBOX_BASE 84*91f16700Schasinglulu ldr r1, [r0] 85*91f16700Schasinglulu bx r1 86*91f16700Schasinglulu1: 87*91f16700Schasinglulu wfe 88*91f16700Schasinglulu b poll_mailbox 89*91f16700Schasingluluendfunc plat_secondary_cold_boot_setup 90*91f16700Schasinglulu 91*91f16700Schasinglulufunc plat_get_my_entrypoint 92*91f16700Schasinglulu /* TODO support warm boot */ 93*91f16700Schasinglulu mov r0, #0 94*91f16700Schasinglulu bx lr 95*91f16700Schasingluluendfunc plat_get_my_entrypoint 96*91f16700Schasinglulu 97*91f16700Schasinglulufunc platform_mem_init 98*91f16700Schasinglulu bx lr 99*91f16700Schasingluluendfunc platform_mem_init 100*91f16700Schasinglulu 101*91f16700Schasinglulu /* --------------------------------------------- 102*91f16700Schasinglulu * int plat_crash_console_init(void) 103*91f16700Schasinglulu * Function to initialize the crash console 104*91f16700Schasinglulu * without a C Runtime to print crash report. 105*91f16700Schasinglulu * Clobber list : x0, x1, x2 106*91f16700Schasinglulu * --------------------------------------------- 107*91f16700Schasinglulu */ 108*91f16700Schasinglulufunc plat_crash_console_init 109*91f16700Schasinglulu mov_imm r0, PLAT_QEMU_CRASH_UART_BASE 110*91f16700Schasinglulu mov_imm r1, PLAT_QEMU_CRASH_UART_CLK_IN_HZ 111*91f16700Schasinglulu mov_imm r2, PLAT_QEMU_CONSOLE_BAUDRATE 112*91f16700Schasinglulu b console_pl011_core_init 113*91f16700Schasingluluendfunc plat_crash_console_init 114*91f16700Schasinglulu 115*91f16700Schasinglulu /* --------------------------------------------- 116*91f16700Schasinglulu * int plat_crash_console_putc(int c) 117*91f16700Schasinglulu * Function to print a character on the crash 118*91f16700Schasinglulu * console without a C Runtime. 119*91f16700Schasinglulu * Clobber list : x1, x2 120*91f16700Schasinglulu * --------------------------------------------- 121*91f16700Schasinglulu */ 122*91f16700Schasinglulufunc plat_crash_console_putc 123*91f16700Schasinglulu mov_imm r1, PLAT_QEMU_CRASH_UART_BASE 124*91f16700Schasinglulu b console_pl011_core_putc 125*91f16700Schasingluluendfunc plat_crash_console_putc 126*91f16700Schasinglulu 127*91f16700Schasinglulu /* --------------------------------------------- 128*91f16700Schasinglulu * void plat_crash_console_flush(int c) 129*91f16700Schasinglulu * Function to force a write of all buffered 130*91f16700Schasinglulu * data that hasn't been output. 131*91f16700Schasinglulu * Out : void. 132*91f16700Schasinglulu * Clobber list : x0, x1 133*91f16700Schasinglulu * --------------------------------------------- 134*91f16700Schasinglulu */ 135*91f16700Schasinglulufunc plat_crash_console_flush 136*91f16700Schasinglulu mov_imm r0, PLAT_QEMU_CRASH_UART_BASE 137*91f16700Schasinglulu b console_pl011_core_flush 138*91f16700Schasingluluendfunc plat_crash_console_flush 139*91f16700Schasinglulu 140