laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 1 | /* |
laurenw-arm | 116f10c | 2023-06-13 16:43:39 -0500 | [diff] [blame] | 2 | * Copyright (c) 2023, Arm Limited. All rights reserved. |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <stdint.h> |
| 8 | #include <stdio.h> |
| 9 | |
Tamas Ban | dc15bf4 | 2024-02-22 11:35:28 +0100 | [diff] [blame] | 10 | #include <drivers/arm/rse_comms.h> |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 11 | #include <plat/common/platform.h> |
Tamas Ban | dc15bf4 | 2024-02-22 11:35:28 +0100 | [diff] [blame] | 12 | #include "rse_platform_api.h" |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 13 | |
| 14 | #include <platform_def.h> |
| 15 | |
Sandrine Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 16 | int nv_counter_test(void) |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 17 | { |
| 18 | psa_status_t status; |
| 19 | uint32_t old_val; |
| 20 | uint32_t new_val; |
| 21 | uint32_t id; |
| 22 | |
Tamas Ban | dc15bf4 | 2024-02-22 11:35:28 +0100 | [diff] [blame] | 23 | status = rse_comms_init(PLAT_RSE_AP_SND_MHU_BASE, PLAT_RSE_AP_RCV_MHU_BASE); |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 24 | if (status != PSA_SUCCESS) { |
Tamas Ban | dc15bf4 | 2024-02-22 11:35:28 +0100 | [diff] [blame] | 25 | printf("Failed to initialize RSE communication channel - psa_status = %d\n", status); |
Sandrine Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 26 | return -1; |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | for (id = 0; id < 3; id++) { |
Tamas Ban | dc15bf4 | 2024-02-22 11:35:28 +0100 | [diff] [blame] | 30 | status = rse_platform_nv_counter_read(id, sizeof(old_val), (uint8_t *)&old_val); |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 31 | if (status != PSA_SUCCESS) { |
Tamas Ban | dc15bf4 | 2024-02-22 11:35:28 +0100 | [diff] [blame] | 32 | printf("Failed during first id=(%d) rse_platform_nv_counter_read - psa_status = %d\n", |
laurenw-arm | 5f939a9 | 2023-07-14 14:24:55 -0500 | [diff] [blame] | 33 | id, status); |
Sandrine Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 34 | return -1; |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 35 | } |
| 36 | |
Tamas Ban | dc15bf4 | 2024-02-22 11:35:28 +0100 | [diff] [blame] | 37 | status = rse_platform_nv_counter_increment(id); |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 38 | if (status != PSA_SUCCESS) { |
Tamas Ban | dc15bf4 | 2024-02-22 11:35:28 +0100 | [diff] [blame] | 39 | printf("Failed during id=(%d) rse_platform_nv_counter_increment - psa_status = %d\n", |
laurenw-arm | 5f939a9 | 2023-07-14 14:24:55 -0500 | [diff] [blame] | 40 | id, status); |
Sandrine Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 41 | return -1; |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 42 | } |
| 43 | |
Tamas Ban | dc15bf4 | 2024-02-22 11:35:28 +0100 | [diff] [blame] | 44 | status = rse_platform_nv_counter_read(id, sizeof(new_val), (uint8_t *)&new_val); |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 45 | if (status != PSA_SUCCESS) { |
Tamas Ban | dc15bf4 | 2024-02-22 11:35:28 +0100 | [diff] [blame] | 46 | printf("Failed during second id=(%d) rse_platform_nv_counter_read - psa_status = %d\n", |
laurenw-arm | 5f939a9 | 2023-07-14 14:24:55 -0500 | [diff] [blame] | 47 | id, status); |
Sandrine Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 48 | return -1; |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 49 | } |
| 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 Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 54 | return -1; |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | printf("Passed nv_counter_test\n"); |
Sandrine Bailleux | e1da6c4 | 2023-05-05 13:59:07 +0200 | [diff] [blame] | 58 | |
| 59 | return 0; |
laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 60 | } |