blob: ea17f69ffd8532838b5f0473ab12b805264f1578 [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>
Javier Almansa Sobrino1948e692023-01-16 17:10:38 +00008#include <granule.h>
9#include <host_utils.h>
Javier Almansa Sobrinobb66f8a2023-01-05 16:43:43 +000010#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 Sobrinoed0ffd22022-07-25 09:35:32 +010018uintptr_t realm_test_util_slot_to_pa(enum buffer_slot slot)
Javier Almansa Sobrinobb66f8a2023-01-05 16:43:43 +000019{
Javier Almansa Sobrinoe7aa1ab2023-03-09 17:38:02 +000020 struct xlat_llt_info *entry = get_cached_llt_info();
Javier Almansa Sobrinobb66f8a2023-01-05 16:43:43 +000021 uintptr_t va = slot_to_va(slot);
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +000022 uint64_t *desc_ptr = xlat_get_tte_ptr(entry, va);
23 uint64_t descriptor = xlat_read_tte(desc_ptr);
Javier Almansa Sobrinobb66f8a2023-01-05 16:43:43 +000024
Javier Almansa Sobrino765a3162023-04-27 17:42:58 +010025 return (uintptr_t)xlat_get_oa_from_tte(descriptor);
Javier Almansa Sobrinobb66f8a2023-01-05 16:43:43 +000026}
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 Sobrinoed0ffd22022-07-25 09:35:32 +010034uintptr_t realm_test_util_slot_va_from_pa(uintptr_t pa)
Javier Almansa Sobrinobb66f8a2023-01-05 16:43:43 +000035{
AlexeiFedorovb80042d2023-08-25 12:02:24 +010036 for (unsigned int i = 0U; i < (unsigned int)NR_CPU_SLOTS; i++) {
Javier Almansa Sobrinoed0ffd22022-07-25 09:35:32 +010037 if (pa == realm_test_util_slot_to_pa((enum buffer_slot)i)) {
Javier Almansa Sobrinobb66f8a2023-01-05 16:43:43 +000038 /*
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 Sobrino1948e692023-01-16 17:10:38 +000050