nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | |
| 10 | #include <debug.h> |
| 11 | #include <host_realm_helper.h> |
| 12 | #include <host_shared_data.h> |
| 13 | #include "realm_def.h" |
| 14 | #include <realm_rsi.h> |
| 15 | #include <tftf_lib.h> |
| 16 | |
| 17 | /* |
| 18 | * This function reads sleep time in ms from shared buffer and spins PE in a loop |
| 19 | * for that time period. |
| 20 | */ |
| 21 | static void realm_sleep_cmd(void) |
| 22 | { |
| 23 | uint64_t sleep = realm_shared_data_get_host_val(HOST_SLEEP_INDEX); |
| 24 | |
| 25 | INFO("REALM_PAYLOAD: Realm payload going to sleep for %llums\n", sleep); |
| 26 | waitms(sleep); |
| 27 | } |
| 28 | |
| 29 | /* |
| 30 | * This function requests RSI/ABI version from RMM. |
| 31 | */ |
| 32 | static void realm_get_rsi_version(void) |
| 33 | { |
| 34 | u_register_t version; |
| 35 | |
| 36 | version = rsi_get_version(); |
| 37 | if (version == (u_register_t)SMC_UNKNOWN) { |
| 38 | ERROR("SMC_RSI_ABI_VERSION failed (%ld)", (long)version); |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | INFO("RSI ABI version %u.%u (expected: %u.%u)", |
| 43 | RSI_ABI_VERSION_GET_MAJOR(version), |
| 44 | RSI_ABI_VERSION_GET_MINOR(version), |
| 45 | RSI_ABI_VERSION_GET_MAJOR(RSI_ABI_VERSION), |
| 46 | RSI_ABI_VERSION_GET_MINOR(RSI_ABI_VERSION)); |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | * This is the entry function for Realm payload, it first requests the shared buffer |
| 51 | * IPA address from Host using HOST_CALL/RSI, it reads the command to be executed, |
| 52 | * performs the request, and returns to Host with the execution state SUCCESS/FAILED |
| 53 | * |
| 54 | * Host in NS world requests Realm to execute certain operations using command |
| 55 | * depending on the test case the Host wants to perform. |
| 56 | */ |
| 57 | void realm_payload_main(void) |
| 58 | { |
| 59 | uint8_t cmd = 0U; |
| 60 | bool test_succeed = false; |
| 61 | |
| 62 | realm_set_shared_structure((host_shared_data_t *)rsi_get_ns_buffer()); |
| 63 | if (realm_get_shared_structure() != NULL) { |
| 64 | cmd = realm_shared_data_get_realm_cmd(); |
| 65 | switch (cmd) { |
| 66 | case REALM_SLEEP_CMD: |
| 67 | realm_sleep_cmd(); |
| 68 | test_succeed = true; |
| 69 | break; |
| 70 | case REALM_GET_RSI_VERSION: |
| 71 | realm_get_rsi_version(); |
| 72 | test_succeed = true; |
| 73 | break; |
| 74 | default: |
| 75 | INFO("REALM_PAYLOAD: %s invalid cmd=%hhu", __func__, cmd); |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if (test_succeed) { |
| 81 | rsi_exit_to_host(HOST_CALL_EXIT_SUCCESS_CMD); |
| 82 | } else { |
| 83 | rsi_exit_to_host(HOST_CALL_EXIT_FAILED_CMD); |
| 84 | } |
| 85 | } |