xref: /rk3399_ARM-atf/plat/arm/board/tc/nv_counter_test.c (revision 1b0761130bab90306b48674dcdd86b42543fb81e)
1*1b076113Slaurenw-arm /*
2*1b076113Slaurenw-arm  * Copyright (c) 2023, ARM Limited. All rights reserved.
3*1b076113Slaurenw-arm  *
4*1b076113Slaurenw-arm  * SPDX-License-Identifier: BSD-3-Clause
5*1b076113Slaurenw-arm  */
6*1b076113Slaurenw-arm 
7*1b076113Slaurenw-arm #include <stdint.h>
8*1b076113Slaurenw-arm #include <stdio.h>
9*1b076113Slaurenw-arm 
10*1b076113Slaurenw-arm #include <drivers/arm/rss_comms.h>
11*1b076113Slaurenw-arm #include <plat/common/platform.h>
12*1b076113Slaurenw-arm #include "rss_platform_api.h"
13*1b076113Slaurenw-arm 
14*1b076113Slaurenw-arm #include <platform_def.h>
15*1b076113Slaurenw-arm 
16*1b076113Slaurenw-arm void nv_counter_test(void)
17*1b076113Slaurenw-arm {
18*1b076113Slaurenw-arm 	psa_status_t status;
19*1b076113Slaurenw-arm 	uint32_t old_val;
20*1b076113Slaurenw-arm 	uint32_t new_val;
21*1b076113Slaurenw-arm 	uint32_t id;
22*1b076113Slaurenw-arm 
23*1b076113Slaurenw-arm 	status = rss_comms_init(PLAT_RSS_AP_SND_MHU_BASE, PLAT_RSS_AP_RCV_MHU_BASE);
24*1b076113Slaurenw-arm 	if (status != PSA_SUCCESS) {
25*1b076113Slaurenw-arm 		printf("Failed to initialize RSS communication channel\n");
26*1b076113Slaurenw-arm 		plat_error_handler(-1);
27*1b076113Slaurenw-arm 	}
28*1b076113Slaurenw-arm 
29*1b076113Slaurenw-arm 	for (id = 0; id < 3; id++) {
30*1b076113Slaurenw-arm 		status = rss_platform_nv_counter_read(id, sizeof(old_val), (uint8_t *)&old_val);
31*1b076113Slaurenw-arm 		if (status != PSA_SUCCESS) {
32*1b076113Slaurenw-arm 			printf("Failed during first id=(%d) rss_platform_nv_counter_read\n",
33*1b076113Slaurenw-arm 				       id);
34*1b076113Slaurenw-arm 			plat_error_handler(-1);
35*1b076113Slaurenw-arm 		}
36*1b076113Slaurenw-arm 
37*1b076113Slaurenw-arm 		status = rss_platform_nv_counter_increment(id);
38*1b076113Slaurenw-arm 		if (status != PSA_SUCCESS) {
39*1b076113Slaurenw-arm 			printf("Failed during id=(%d) rss_platform_nv_counter_increment\n",
40*1b076113Slaurenw-arm 					id);
41*1b076113Slaurenw-arm 			plat_error_handler(-1);
42*1b076113Slaurenw-arm 		}
43*1b076113Slaurenw-arm 
44*1b076113Slaurenw-arm 		status = rss_platform_nv_counter_read(id, sizeof(new_val), (uint8_t *)&new_val);
45*1b076113Slaurenw-arm 		if (status != PSA_SUCCESS) {
46*1b076113Slaurenw-arm 			printf("Failed during second id=(%d) rss_platform_nv_counter_read\n",
47*1b076113Slaurenw-arm 					id);
48*1b076113Slaurenw-arm 			plat_error_handler(-1);
49*1b076113Slaurenw-arm 		}
50*1b076113Slaurenw-arm 
51*1b076113Slaurenw-arm 		if (old_val + 1 != new_val) {
52*1b076113Slaurenw-arm 			printf("Failed nv_counter_test: old_val (%d) + 1 != new_val (%d)\n",
53*1b076113Slaurenw-arm 					old_val, new_val);
54*1b076113Slaurenw-arm 			plat_error_handler(-1);
55*1b076113Slaurenw-arm 		}
56*1b076113Slaurenw-arm 	}
57*1b076113Slaurenw-arm 	printf("Passed nv_counter_test\n");
58*1b076113Slaurenw-arm }
59