xref: /rk3399_ARM-atf/plat/arm/board/tc/nv_counter_test.c (revision cb6b7505051ef59a81d50ab2f4c6e56ba2b41275)
11b076113Slaurenw-arm /*
200b7e0bfSlaurenw-arm  * Copyright (c) 2023, Arm Limited. All rights reserved.
31b076113Slaurenw-arm  *
41b076113Slaurenw-arm  * SPDX-License-Identifier: BSD-3-Clause
51b076113Slaurenw-arm  */
61b076113Slaurenw-arm 
71b076113Slaurenw-arm #include <stdint.h>
81b076113Slaurenw-arm #include <stdio.h>
91b076113Slaurenw-arm 
101b076113Slaurenw-arm #include <drivers/arm/rss_comms.h>
111b076113Slaurenw-arm #include <plat/common/platform.h>
121b076113Slaurenw-arm #include "rss_platform_api.h"
131b076113Slaurenw-arm 
141b076113Slaurenw-arm #include <platform_def.h>
151b076113Slaurenw-arm 
1657cc12c8SSandrine Bailleux int nv_counter_test(void)
171b076113Slaurenw-arm {
181b076113Slaurenw-arm 	psa_status_t status;
191b076113Slaurenw-arm 	uint32_t old_val;
201b076113Slaurenw-arm 	uint32_t new_val;
211b076113Slaurenw-arm 	uint32_t id;
221b076113Slaurenw-arm 
231b076113Slaurenw-arm 	status = rss_comms_init(PLAT_RSS_AP_SND_MHU_BASE, PLAT_RSS_AP_RCV_MHU_BASE);
241b076113Slaurenw-arm 	if (status != PSA_SUCCESS) {
25*cb6b7505Slaurenw-arm 		printf("Failed to initialize RSS communication channel - psa_status = %d\n", status);
2657cc12c8SSandrine Bailleux 		return -1;
271b076113Slaurenw-arm 	}
281b076113Slaurenw-arm 
291b076113Slaurenw-arm 	for (id = 0; id < 3; id++) {
301b076113Slaurenw-arm 		status = rss_platform_nv_counter_read(id, sizeof(old_val), (uint8_t *)&old_val);
311b076113Slaurenw-arm 		if (status != PSA_SUCCESS) {
32*cb6b7505Slaurenw-arm 			printf("Failed during first id=(%d) rss_platform_nv_counter_read - psa_status = %d\n",
33*cb6b7505Slaurenw-arm 				       id, status);
3457cc12c8SSandrine Bailleux 			return -1;
351b076113Slaurenw-arm 		}
361b076113Slaurenw-arm 
371b076113Slaurenw-arm 		status = rss_platform_nv_counter_increment(id);
381b076113Slaurenw-arm 		if (status != PSA_SUCCESS) {
39*cb6b7505Slaurenw-arm 			printf("Failed during id=(%d) rss_platform_nv_counter_increment - psa_status = %d\n",
40*cb6b7505Slaurenw-arm 					id, status);
4157cc12c8SSandrine Bailleux 			return -1;
421b076113Slaurenw-arm 		}
431b076113Slaurenw-arm 
441b076113Slaurenw-arm 		status = rss_platform_nv_counter_read(id, sizeof(new_val), (uint8_t *)&new_val);
451b076113Slaurenw-arm 		if (status != PSA_SUCCESS) {
46*cb6b7505Slaurenw-arm 			printf("Failed during second id=(%d) rss_platform_nv_counter_read - psa_status = %d\n",
47*cb6b7505Slaurenw-arm 					id, status);
4857cc12c8SSandrine Bailleux 			return -1;
491b076113Slaurenw-arm 		}
501b076113Slaurenw-arm 
511b076113Slaurenw-arm 		if (old_val + 1 != new_val) {
521b076113Slaurenw-arm 			printf("Failed nv_counter_test: old_val (%d) + 1 != new_val (%d)\n",
531b076113Slaurenw-arm 					old_val, new_val);
5457cc12c8SSandrine Bailleux 			return -1;
551b076113Slaurenw-arm 		}
561b076113Slaurenw-arm 	}
571b076113Slaurenw-arm 	printf("Passed nv_counter_test\n");
5857cc12c8SSandrine Bailleux 
5957cc12c8SSandrine Bailleux 	return 0;
601b076113Slaurenw-arm }
61