blob: 9bc3bde555882634d8ef046b6e92ab18b84df22b [file] [log] [blame]
Javier Almansa Sobrinobb66f8a2023-01-05 16:43:43 +00001/*
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>
8#include <xlat_tables.h>
9
10/*
11 * Return the PA mapped to a given slot.
12 *
13 * NOTE: This API assumes a 4KB granularity and that the architecture
14 * has a VA space of 48 bits.
15 */
Javier Almansa Sobrinoed0ffd22022-07-25 09:35:32 +010016uintptr_t realm_test_util_slot_to_pa(enum buffer_slot slot)
Javier Almansa Sobrinobb66f8a2023-01-05 16:43:43 +000017{
18 struct xlat_table_entry *entry = get_cache_entry();
19 uintptr_t va = slot_to_va(slot);
20 uint64_t *desc_ptr = xlat_get_pte_from_table(entry, va);
21 uint64_t descriptor = xlat_read_descriptor(desc_ptr);
22
23 return (uintptr_t)(descriptor & XLAT_TTE_L3_PA_MASK);
24}
25
26/*
27 * Helper function to find the slot VA to which a PA is mapped to.
28 * This function is used to validate that the slot buffer library
29 * mapped the given PA to the VA that would be expected by the
30 * aarch64 VMSA.
31 */
Javier Almansa Sobrinoed0ffd22022-07-25 09:35:32 +010032uintptr_t realm_test_util_slot_va_from_pa(uintptr_t pa)
Javier Almansa Sobrinobb66f8a2023-01-05 16:43:43 +000033{
34 for (unsigned int i = 0U; i < NR_CPU_SLOTS; i++) {
Javier Almansa Sobrinoed0ffd22022-07-25 09:35:32 +010035 if (pa == realm_test_util_slot_to_pa((enum buffer_slot)i)) {
Javier Almansa Sobrinobb66f8a2023-01-05 16:43:43 +000036 /*
37 * Found a slot returning the same address, get
38 * the VA for that slot (the one that would be
39 * used by the aarch64 VMSA).
40 */
41 return slot_to_va((enum buffer_slot)i);
42 }
43 }
44
45 /* No buffer slot found */
46 return (uintptr_t)NULL;
47}