Javier Almansa Sobrino | bb66f8a | 2023-01-05 16:43:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 4 | */ |
| 5 | |
| 6 | #include <buffer.h> |
| 7 | #include <buffer_private.h> |
Javier Almansa Sobrino | 1948e69 | 2023-01-16 17:10:38 +0000 | [diff] [blame] | 8 | #include <granule.h> |
| 9 | #include <host_utils.h> |
Javier Almansa Sobrino | bb66f8a | 2023-01-05 16:43:43 +0000 | [diff] [blame] | 10 | #include <xlat_tables.h> |
| 11 | |
| 12 | /* |
| 13 | * Return the PA mapped to a given slot. |
| 14 | * |
| 15 | * NOTE: This API assumes a 4KB granularity and that the architecture |
| 16 | * has a VA space of 48 bits. |
| 17 | */ |
Javier Almansa Sobrino | ed0ffd2 | 2022-07-25 09:35:32 +0100 | [diff] [blame] | 18 | uintptr_t realm_test_util_slot_to_pa(enum buffer_slot slot) |
Javier Almansa Sobrino | bb66f8a | 2023-01-05 16:43:43 +0000 | [diff] [blame] | 19 | { |
Javier Almansa Sobrino | e7aa1ab | 2023-03-09 17:38:02 +0000 | [diff] [blame] | 20 | struct xlat_llt_info *entry = get_cached_llt_info(); |
Javier Almansa Sobrino | bb66f8a | 2023-01-05 16:43:43 +0000 | [diff] [blame] | 21 | uintptr_t va = slot_to_va(slot); |
Javier Almansa Sobrino | ed93259 | 2023-01-24 12:50:41 +0000 | [diff] [blame] | 22 | uint64_t *desc_ptr = xlat_get_tte_ptr(entry, va); |
| 23 | uint64_t descriptor = xlat_read_tte(desc_ptr); |
Javier Almansa Sobrino | bb66f8a | 2023-01-05 16:43:43 +0000 | [diff] [blame] | 24 | |
Javier Almansa Sobrino | 765a316 | 2023-04-27 17:42:58 +0100 | [diff] [blame] | 25 | return (uintptr_t)xlat_get_oa_from_tte(descriptor); |
Javier Almansa Sobrino | bb66f8a | 2023-01-05 16:43:43 +0000 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | /* |
| 29 | * Helper function to find the slot VA to which a PA is mapped to. |
| 30 | * This function is used to validate that the slot buffer library |
| 31 | * mapped the given PA to the VA that would be expected by the |
| 32 | * aarch64 VMSA. |
| 33 | */ |
Javier Almansa Sobrino | ed0ffd2 | 2022-07-25 09:35:32 +0100 | [diff] [blame] | 34 | uintptr_t realm_test_util_slot_va_from_pa(uintptr_t pa) |
Javier Almansa Sobrino | bb66f8a | 2023-01-05 16:43:43 +0000 | [diff] [blame] | 35 | { |
AlexeiFedorov | b80042d | 2023-08-25 12:02:24 +0100 | [diff] [blame^] | 36 | for (unsigned int i = 0U; i < (unsigned int)NR_CPU_SLOTS; i++) { |
Javier Almansa Sobrino | ed0ffd2 | 2022-07-25 09:35:32 +0100 | [diff] [blame] | 37 | if (pa == realm_test_util_slot_to_pa((enum buffer_slot)i)) { |
Javier Almansa Sobrino | bb66f8a | 2023-01-05 16:43:43 +0000 | [diff] [blame] | 38 | /* |
| 39 | * Found a slot returning the same address, get |
| 40 | * the VA for that slot (the one that would be |
| 41 | * used by the aarch64 VMSA). |
| 42 | */ |
| 43 | return slot_to_va((enum buffer_slot)i); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /* No buffer slot found */ |
| 48 | return (uintptr_t)NULL; |
| 49 | } |
Javier Almansa Sobrino | 1948e69 | 2023-01-16 17:10:38 +0000 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * Function to return the base pointer to granule structure. |
| 53 | * This function relies on addr_to_granule(). |
| 54 | */ |
| 55 | struct granule *realm_test_util_granule_struct_base(void) |
| 56 | { |
| 57 | return addr_to_granule(host_util_get_granule_base()); |
| 58 | } |