Harrison Mutai | 6e01164 | 2023-09-22 17:17:35 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | |
Harrison Mutai | cc89c2f | 2025-05-22 11:08:46 +0000 | [diff] [blame^] | 9 | #include <tcg.h> |
Harrison Mutai | 6e01164 | 2023-09-22 17:17:35 +0100 | [diff] [blame] | 10 | #include <test_helpers.h> |
| 11 | #include <tftf_lib.h> |
| 12 | #include <transfer_list.h> |
| 13 | |
Harrison Mutai | 089c9ad | 2025-04-25 16:03:54 +0000 | [diff] [blame] | 14 | #include "event_log.h" |
| 15 | |
Harrison Mutai | 6e01164 | 2023-09-22 17:17:35 +0100 | [diff] [blame] | 16 | extern u_register_t hw_config_base; |
| 17 | extern u_register_t ns_tl; |
| 18 | extern u_register_t tl_signature; |
| 19 | |
| 20 | #define DTB_PREAMBLE U(0xedfe0dd0) |
| 21 | |
| 22 | test_result_t test_handoff_header(void) |
| 23 | { |
| 24 | struct transfer_list_header *tl = (struct transfer_list_header *)ns_tl; |
| 25 | |
Harrison Mutai | 112498c | 2025-02-18 11:52:12 +0000 | [diff] [blame] | 26 | #if __aarch64__ |
| 27 | uint64_t signature = TRANSFER_LIST_HANDOFF_X1_VALUE(TRANSFER_LIST_VERSION); |
| 28 | #else |
| 29 | uint32_t signature = TRANSFER_LIST_HANDOFF_R1_VALUE(TRANSFER_LIST_VERSION); |
| 30 | #endif /* __aarch64__ */ |
| 31 | |
| 32 | if (signature != tl_signature) { |
| 33 | return TEST_RESULT_FAIL; |
| 34 | } |
Harrison Mutai | 6e01164 | 2023-09-22 17:17:35 +0100 | [diff] [blame] | 35 | |
| 36 | if (transfer_list_check_header(tl) == TL_OPS_NON) { |
| 37 | return TEST_RESULT_FAIL; |
| 38 | } |
| 39 | |
| 40 | return TEST_RESULT_SUCCESS; |
| 41 | } |
| 42 | |
| 43 | test_result_t test_handoff_dtb_payload(void) |
| 44 | { |
| 45 | tftf_testcase_printf("Validating HW_CONFIG from transfer list.\n"); |
| 46 | struct transfer_list_header *tl = (struct transfer_list_header *)ns_tl; |
| 47 | struct transfer_list_entry *te = (void *)tl + tl->hdr_size; |
| 48 | uintptr_t dtb_ptr; |
| 49 | |
| 50 | te = transfer_list_find(tl, TL_TAG_FDT); |
| 51 | |
| 52 | if (te == NULL) { |
| 53 | tftf_testcase_printf( |
| 54 | "Failed to find HW CONFIG TE in transfer list!"); |
| 55 | return TEST_RESULT_FAIL; |
| 56 | } |
| 57 | |
| 58 | dtb_ptr = (unsigned long)transfer_list_entry_data(te); |
| 59 | |
| 60 | if ((dtb_ptr != hw_config_base) && |
| 61 | (*(uint32_t *)dtb_ptr != DTB_PREAMBLE)) { |
| 62 | return TEST_RESULT_FAIL; |
| 63 | } |
| 64 | |
| 65 | return TEST_RESULT_SUCCESS; |
| 66 | } |
Harrison Mutai | 089c9ad | 2025-04-25 16:03:54 +0000 | [diff] [blame] | 67 | |
| 68 | test_result_t test_handoff_event_payload(void) |
| 69 | { |
| 70 | |
| 71 | struct transfer_list_header *tl = (struct transfer_list_header *)ns_tl; |
| 72 | struct transfer_list_entry *te; |
| 73 | uint8_t *log_addr; |
| 74 | size_t log_size; |
| 75 | |
| 76 | tftf_testcase_printf( |
| 77 | "Validate that a TPM event log can be successfully dumped when " |
| 78 | "present in the transfer list."); |
| 79 | |
| 80 | te = transfer_list_find(tl, TL_TAG_TPM_EVLOG); |
| 81 | if (te == NULL) { |
| 82 | return TEST_RESULT_SKIPPED; |
| 83 | } |
| 84 | |
| 85 | /* 4-bytes are reserved in TE data section. */ |
| 86 | log_addr = (uint8_t *)transfer_list_entry_data(te) + U(4); |
| 87 | log_size = te->data_size - U(4); |
| 88 | |
| 89 | if (event_log_dump(log_addr, log_size) != 0) { |
| 90 | return TEST_RESULT_FAIL; |
| 91 | } |
| 92 | |
| 93 | return TEST_RESULT_SUCCESS; |
| 94 | } |