1 /* 2 * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <assert.h> 8 #include <stdint.h> 9 #include <string.h> 10 11 #include <lib/mmio.h> 12 13 #include <plat/common/platform.h> 14 #include <platform_def.h> 15 #include <tools_share/tbbr_oid.h> 16 17 /* 18 * Store a new non-volatile counter value. 19 * 20 * On some FVP versions, the non-volatile counters are read-only so this 21 * function will always fail. 22 * 23 * Return: 0 = success, Otherwise = error 24 */ plat_set_nv_ctr(void * cookie,unsigned int nv_ctr)25int plat_set_nv_ctr(void *cookie, unsigned int nv_ctr) 26 { 27 const char *oid; 28 uintptr_t nv_ctr_addr; 29 30 assert(cookie != NULL); 31 32 oid = (const char *)cookie; 33 if (strcmp(oid, TRUSTED_FW_NVCOUNTER_OID) == 0) { 34 nv_ctr_addr = TFW_NVCTR_BASE; 35 } else if (strcmp(oid, NON_TRUSTED_FW_NVCOUNTER_OID) == 0) { 36 nv_ctr_addr = NTFW_CTR_BASE; 37 } else { 38 return 1; 39 } 40 41 mmio_write_32(nv_ctr_addr, nv_ctr); 42 43 /* 44 * If the FVP models a locked counter then its value cannot be updated 45 * and the above write operation has been silently ignored. 46 */ 47 return (mmio_read_32(nv_ctr_addr) == nv_ctr) ? 0 : 1; 48 } 49