laurenw-arm | 2ce1e35 | 2023-02-07 13:40:05 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023, ARM Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <stdint.h> |
| 8 | #include <stdio.h> |
| 9 | |
| 10 | #include <drivers/arm/rss_comms.h> |
| 11 | #include <plat/common/platform.h> |
| 12 | #include "rss_platform_api.h" |
| 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 | |
| 23 | status = rss_comms_init(PLAT_RSS_AP_SND_MHU_BASE, PLAT_RSS_AP_RCV_MHU_BASE); |
| 24 | if (status != PSA_SUCCESS) { |
| 25 | printf("Failed to initialize RSS communication channel\n"); |
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++) { |
| 30 | status = rss_platform_nv_counter_read(id, sizeof(old_val), (uint8_t *)&old_val); |
| 31 | if (status != PSA_SUCCESS) { |
| 32 | printf("Failed during first id=(%d) rss_platform_nv_counter_read\n", |
| 33 | id); |
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 | |
| 37 | status = rss_platform_nv_counter_increment(id); |
| 38 | if (status != PSA_SUCCESS) { |
| 39 | printf("Failed during id=(%d) rss_platform_nv_counter_increment\n", |
| 40 | id); |
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 | |
| 44 | status = rss_platform_nv_counter_read(id, sizeof(new_val), (uint8_t *)&new_val); |
| 45 | if (status != PSA_SUCCESS) { |
| 46 | printf("Failed during second id=(%d) rss_platform_nv_counter_read\n", |
| 47 | id); |
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 | } |