blob: 902556932a44bb8cf777d8b3a58b2838620a2307 [file] [log] [blame]
laurenw-arm2ce1e352023-02-07 13:40:05 -06001/*
laurenw-arm116f10c2023-06-13 16:43:39 -05002 * Copyright (c) 2023, Arm Limited. All rights reserved.
laurenw-arm2ce1e352023-02-07 13:40:05 -06003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <stdint.h>
8#include <stdio.h>
9
Tamas Bandc15bf42024-02-22 11:35:28 +010010#include <drivers/arm/rse_comms.h>
laurenw-arm2ce1e352023-02-07 13:40:05 -060011#include <plat/common/platform.h>
Tamas Bandc15bf42024-02-22 11:35:28 +010012#include "rse_platform_api.h"
laurenw-arm2ce1e352023-02-07 13:40:05 -060013
14#include <platform_def.h>
15
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020016int nv_counter_test(void)
laurenw-arm2ce1e352023-02-07 13:40:05 -060017{
18 psa_status_t status;
19 uint32_t old_val;
20 uint32_t new_val;
21 uint32_t id;
22
Tamas Bandc15bf42024-02-22 11:35:28 +010023 status = rse_comms_init(PLAT_RSE_AP_SND_MHU_BASE, PLAT_RSE_AP_RCV_MHU_BASE);
laurenw-arm2ce1e352023-02-07 13:40:05 -060024 if (status != PSA_SUCCESS) {
Tamas Bandc15bf42024-02-22 11:35:28 +010025 printf("Failed to initialize RSE communication channel - psa_status = %d\n", status);
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020026 return -1;
laurenw-arm2ce1e352023-02-07 13:40:05 -060027 }
28
29 for (id = 0; id < 3; id++) {
Tamas Bandc15bf42024-02-22 11:35:28 +010030 status = rse_platform_nv_counter_read(id, sizeof(old_val), (uint8_t *)&old_val);
laurenw-arm2ce1e352023-02-07 13:40:05 -060031 if (status != PSA_SUCCESS) {
Tamas Bandc15bf42024-02-22 11:35:28 +010032 printf("Failed during first id=(%d) rse_platform_nv_counter_read - psa_status = %d\n",
laurenw-arm5f939a92023-07-14 14:24:55 -050033 id, status);
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020034 return -1;
laurenw-arm2ce1e352023-02-07 13:40:05 -060035 }
36
Tamas Bandc15bf42024-02-22 11:35:28 +010037 status = rse_platform_nv_counter_increment(id);
laurenw-arm2ce1e352023-02-07 13:40:05 -060038 if (status != PSA_SUCCESS) {
Tamas Bandc15bf42024-02-22 11:35:28 +010039 printf("Failed during id=(%d) rse_platform_nv_counter_increment - psa_status = %d\n",
laurenw-arm5f939a92023-07-14 14:24:55 -050040 id, status);
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020041 return -1;
laurenw-arm2ce1e352023-02-07 13:40:05 -060042 }
43
Tamas Bandc15bf42024-02-22 11:35:28 +010044 status = rse_platform_nv_counter_read(id, sizeof(new_val), (uint8_t *)&new_val);
laurenw-arm2ce1e352023-02-07 13:40:05 -060045 if (status != PSA_SUCCESS) {
Tamas Bandc15bf42024-02-22 11:35:28 +010046 printf("Failed during second id=(%d) rse_platform_nv_counter_read - psa_status = %d\n",
laurenw-arm5f939a92023-07-14 14:24:55 -050047 id, status);
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020048 return -1;
laurenw-arm2ce1e352023-02-07 13:40:05 -060049 }
50
51 if (old_val + 1 != new_val) {
52 printf("Failed nv_counter_test: old_val (%d) + 1 != new_val (%d)\n",
53 old_val, new_val);
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020054 return -1;
laurenw-arm2ce1e352023-02-07 13:40:05 -060055 }
56 }
57 printf("Passed nv_counter_test\n");
Sandrine Bailleuxe1da6c42023-05-05 13:59:07 +020058
59 return 0;
laurenw-arm2ce1e352023-02-07 13:40:05 -060060}