blob: b752c5ddd1da8cde541c5771b3e300a52f9042d9 [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 */
16static uintptr_t slot_to_pa(enum buffer_slot slot)
17{
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 */
32uintptr_t realm_test_util_get_slot_va(uintptr_t pa)
33{
34 for (unsigned int i = 0U; i < NR_CPU_SLOTS; i++) {
35 if (pa == slot_to_pa((enum buffer_slot)i)) {
36 /*
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}