1778e411dSEtienne Carriere/* 2*3fb52e41SRyan Everett * Copyright (c) 2017-2024, Arm Limited and Contributors. All rights reserved. 3778e411dSEtienne Carriere * 4778e411dSEtienne Carriere * SPDX-License-Identifier: BSD-3-Clause 5778e411dSEtienne Carriere */ 6778e411dSEtienne Carriere 7778e411dSEtienne Carriere#include <arch.h> 8778e411dSEtienne Carriere#include <asm_macros.S> 9778e411dSEtienne Carriere#include <assert_macros.S> 10778e411dSEtienne Carriere#include <cortex_a17.h> 11778e411dSEtienne Carriere#include <cpu_macros.S> 12778e411dSEtienne Carriere 13778e411dSEtienne Carriere .macro assert_cache_enabled 14778e411dSEtienne Carriere#if ENABLE_ASSERTIONS 15778e411dSEtienne Carriere ldcopr r0, SCTLR 16778e411dSEtienne Carriere tst r0, #SCTLR_C_BIT 17778e411dSEtienne Carriere ASM_ASSERT(eq) 18778e411dSEtienne Carriere#endif 19778e411dSEtienne Carriere .endm 20778e411dSEtienne Carriere 21778e411dSEtienne Carrierefunc cortex_a17_disable_smp 22778e411dSEtienne Carriere ldcopr r0, ACTLR 23778e411dSEtienne Carriere bic r0, #CORTEX_A17_ACTLR_SMP_BIT 24778e411dSEtienne Carriere stcopr r0, ACTLR 25778e411dSEtienne Carriere isb 26778e411dSEtienne Carriere dsb sy 27778e411dSEtienne Carriere bx lr 28778e411dSEtienne Carriereendfunc cortex_a17_disable_smp 29778e411dSEtienne Carriere 30778e411dSEtienne Carrierefunc cortex_a17_enable_smp 31778e411dSEtienne Carriere ldcopr r0, ACTLR 32778e411dSEtienne Carriere orr r0, #CORTEX_A17_ACTLR_SMP_BIT 33778e411dSEtienne Carriere stcopr r0, ACTLR 34778e411dSEtienne Carriere isb 35778e411dSEtienne Carriere bx lr 36778e411dSEtienne Carriereendfunc cortex_a17_enable_smp 37778e411dSEtienne Carriere 380b64c194SAmbroise Vincent /* ---------------------------------------------------- 390b64c194SAmbroise Vincent * Errata Workaround for Cortex A17 Errata #852421. 400b64c194SAmbroise Vincent * This applies only to revision <= r1p2 of Cortex A17. 410b64c194SAmbroise Vincent * Inputs: 420b64c194SAmbroise Vincent * r0: variant[4:7] and revision[0:3] of current cpu. 430b64c194SAmbroise Vincent * Shall clobber: r0-r3 440b64c194SAmbroise Vincent * ---------------------------------------------------- 450b64c194SAmbroise Vincent */ 460b64c194SAmbroise Vincentfunc errata_a17_852421_wa 470b64c194SAmbroise Vincent /* 480b64c194SAmbroise Vincent * Compare r0 against revision r1p2 490b64c194SAmbroise Vincent */ 500b64c194SAmbroise Vincent mov r2, lr 510b64c194SAmbroise Vincent bl check_errata_852421 520b64c194SAmbroise Vincent cmp r0, #ERRATA_NOT_APPLIES 530b64c194SAmbroise Vincent beq 1f 540b64c194SAmbroise Vincent ldcopr r0, CORTEX_A17_IMP_DEF_REG1 550b64c194SAmbroise Vincent orr r0, r0, #(1<<24) 560b64c194SAmbroise Vincent stcopr r0, CORTEX_A17_IMP_DEF_REG1 570b64c194SAmbroise Vincent1: 580b64c194SAmbroise Vincent bx r2 590b64c194SAmbroise Vincentendfunc errata_a17_852421_wa 600b64c194SAmbroise Vincent 610b64c194SAmbroise Vincentfunc check_errata_852421 620b64c194SAmbroise Vincent mov r1, #0x12 630b64c194SAmbroise Vincent b cpu_rev_var_ls 640b64c194SAmbroise Vincentendfunc check_errata_852421 650b64c194SAmbroise Vincent 66f3965b6cSHarrison Mutaiadd_erratum_entry cortex_a17, ERRATUM(852421), ERRATA_A17_852421 67f3965b6cSHarrison Mutai 68be10dcdeSAmbroise Vincent /* ---------------------------------------------------- 69be10dcdeSAmbroise Vincent * Errata Workaround for Cortex A17 Errata #852423. 70be10dcdeSAmbroise Vincent * This applies only to revision <= r1p2 of Cortex A17. 71be10dcdeSAmbroise Vincent * Inputs: 72be10dcdeSAmbroise Vincent * r0: variant[4:7] and revision[0:3] of current cpu. 73be10dcdeSAmbroise Vincent * Shall clobber: r0-r3 74be10dcdeSAmbroise Vincent * ---------------------------------------------------- 75be10dcdeSAmbroise Vincent */ 76be10dcdeSAmbroise Vincentfunc errata_a17_852423_wa 77be10dcdeSAmbroise Vincent /* 78be10dcdeSAmbroise Vincent * Compare r0 against revision r1p2 79be10dcdeSAmbroise Vincent */ 80be10dcdeSAmbroise Vincent mov r2, lr 81be10dcdeSAmbroise Vincent bl check_errata_852423 82be10dcdeSAmbroise Vincent cmp r0, #ERRATA_NOT_APPLIES 83be10dcdeSAmbroise Vincent beq 1f 84be10dcdeSAmbroise Vincent ldcopr r0, CORTEX_A17_IMP_DEF_REG1 85be10dcdeSAmbroise Vincent orr r0, r0, #(1<<12) 86be10dcdeSAmbroise Vincent stcopr r0, CORTEX_A17_IMP_DEF_REG1 87be10dcdeSAmbroise Vincent1: 88be10dcdeSAmbroise Vincent bx r2 89be10dcdeSAmbroise Vincentendfunc errata_a17_852423_wa 90be10dcdeSAmbroise Vincent 91be10dcdeSAmbroise Vincentfunc check_errata_852423 92be10dcdeSAmbroise Vincent mov r1, #0x12 93be10dcdeSAmbroise Vincent b cpu_rev_var_ls 94be10dcdeSAmbroise Vincentendfunc check_errata_852423 95be10dcdeSAmbroise Vincent 96f3965b6cSHarrison Mutaiadd_erratum_entry cortex_a17, ERRATUM(852423), ERRATA_A17_852423 97f3965b6cSHarrison Mutai 98e4b34efaSDimitris Papastamosfunc check_errata_cve_2017_5715 99e4b34efaSDimitris Papastamos#if WORKAROUND_CVE_2017_5715 100e4b34efaSDimitris Papastamos mov r0, #ERRATA_APPLIES 101e4b34efaSDimitris Papastamos#else 102e4b34efaSDimitris Papastamos mov r0, #ERRATA_MISSING 103e4b34efaSDimitris Papastamos#endif 104e4b34efaSDimitris Papastamos bx lr 105e4b34efaSDimitris Papastamosendfunc check_errata_cve_2017_5715 106e4b34efaSDimitris Papastamos 107f3965b6cSHarrison Mutaiadd_erratum_entry cortex_a17, CVE(2017, 5715), WORKAROUND_CVE_2017_5715 108e4b34efaSDimitris Papastamos 109778e411dSEtienne Carrierefunc cortex_a17_reset_func 1100b64c194SAmbroise Vincent mov r5, lr 1110b64c194SAmbroise Vincent bl cpu_get_rev_var 112be10dcdeSAmbroise Vincent mov r4, r0 1130b64c194SAmbroise Vincent 1140b64c194SAmbroise Vincent#if ERRATA_A17_852421 115be10dcdeSAmbroise Vincent mov r0, r4 1160b64c194SAmbroise Vincent bl errata_a17_852421_wa 1170b64c194SAmbroise Vincent#endif 1180b64c194SAmbroise Vincent 119be10dcdeSAmbroise Vincent#if ERRATA_A17_852423 120be10dcdeSAmbroise Vincent mov r0, r4 121be10dcdeSAmbroise Vincent bl errata_a17_852423_wa 122be10dcdeSAmbroise Vincent#endif 123be10dcdeSAmbroise Vincent 124e4b34efaSDimitris Papastamos#if IMAGE_BL32 && WORKAROUND_CVE_2017_5715 125bcb3ea92SHarrison Mutai ldr r0, =wa_cve_2017_5715_bpiall_vbar 126e4b34efaSDimitris Papastamos stcopr r0, VBAR 127e4b34efaSDimitris Papastamos stcopr r0, MVBAR 128e4b34efaSDimitris Papastamos /* isb will be applied in the course of the reset func */ 129e4b34efaSDimitris Papastamos#endif 1300b64c194SAmbroise Vincent 1310b64c194SAmbroise Vincent mov lr, r5 132778e411dSEtienne Carriere b cortex_a17_enable_smp 133778e411dSEtienne Carriereendfunc cortex_a17_reset_func 134778e411dSEtienne Carriere 135778e411dSEtienne Carrierefunc cortex_a17_core_pwr_dwn 136778e411dSEtienne Carriere push {r12, lr} 137778e411dSEtienne Carriere 138778e411dSEtienne Carriere assert_cache_enabled 139778e411dSEtienne Carriere 140778e411dSEtienne Carriere /* Flush L1 cache */ 141778e411dSEtienne Carriere mov r0, #DC_OP_CISW 142778e411dSEtienne Carriere bl dcsw_op_level1 143778e411dSEtienne Carriere 144778e411dSEtienne Carriere /* Exit cluster coherency */ 145778e411dSEtienne Carriere pop {r12, lr} 146778e411dSEtienne Carriere b cortex_a17_disable_smp 147778e411dSEtienne Carriereendfunc cortex_a17_core_pwr_dwn 148778e411dSEtienne Carriere 149778e411dSEtienne Carrierefunc cortex_a17_cluster_pwr_dwn 150778e411dSEtienne Carriere push {r12, lr} 151778e411dSEtienne Carriere 152778e411dSEtienne Carriere assert_cache_enabled 153778e411dSEtienne Carriere 154778e411dSEtienne Carriere /* Flush L1 caches */ 155778e411dSEtienne Carriere mov r0, #DC_OP_CISW 156778e411dSEtienne Carriere bl dcsw_op_level1 157778e411dSEtienne Carriere 158778e411dSEtienne Carriere bl plat_disable_acp 159778e411dSEtienne Carriere 160c5c160cdSStephan Gerhold /* Flush L2 caches */ 161c5c160cdSStephan Gerhold mov r0, #DC_OP_CISW 162c5c160cdSStephan Gerhold bl dcsw_op_level2 163c5c160cdSStephan Gerhold 164778e411dSEtienne Carriere /* Exit cluster coherency */ 165778e411dSEtienne Carriere pop {r12, lr} 166778e411dSEtienne Carriere b cortex_a17_disable_smp 167778e411dSEtienne Carriereendfunc cortex_a17_cluster_pwr_dwn 168778e411dSEtienne Carriere 169778e411dSEtienne Carrieredeclare_cpu_ops cortex_a17, CORTEX_A17_MIDR, \ 170778e411dSEtienne Carriere cortex_a17_reset_func, \ 171778e411dSEtienne Carriere cortex_a17_core_pwr_dwn, \ 172778e411dSEtienne Carriere cortex_a17_cluster_pwr_dwn 173