Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 4 | */ |
| 5 | |
| 6 | #include <arch_helpers.h> |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 7 | #include <assert.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 8 | #include <bitmap.h> |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 9 | #include <buffer.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 10 | #include <granule.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 11 | #include <ripas.h> |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 12 | #include <s2tt.h> |
| 13 | #include <s2tt_pvt_defs.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 14 | #include <smc.h> |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 15 | #include <stdbool.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 16 | #include <stddef.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 17 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 18 | /* |
| 19 | * Return a mask for the IPA field on a S2TTE |
| 20 | */ |
| 21 | static unsigned long s2tte_lvl_mask(long level, bool lpa2) |
| 22 | { |
| 23 | assert(level <= S2TT_PAGE_LEVEL); |
| 24 | assert(level >= S2TT_MIN_STARTING_LEVEL_LPA2); |
| 25 | |
| 26 | unsigned long mask; |
| 27 | unsigned long levels = (unsigned long)(S2TT_PAGE_LEVEL - level); |
| 28 | unsigned long lsb = (levels * S2TTE_STRIDE) + GRANULE_SHIFT; |
| 29 | |
| 30 | mask = BIT_MASK_ULL((S2TTE_OA_BITS - 1U), lsb); |
| 31 | |
| 32 | if (lpa2 == true) { |
| 33 | mask |= (MASK(LPA2_S2TTE_51_50) | MASK(LPA2_OA_49_48)); |
| 34 | } |
| 35 | |
| 36 | return mask; |
| 37 | } |
| 38 | |
| 39 | /* |
| 40 | * Extracts the PA mapped by an S2TTE, aligned to a given level. |
| 41 | */ |
| 42 | static unsigned long s2tte_to_pa(unsigned long s2tte, long level, bool lpa2) |
| 43 | { |
| 44 | unsigned long pa = s2tte & s2tte_lvl_mask(level, lpa2); |
| 45 | |
| 46 | if (lpa2 == true) { |
| 47 | pa &= ~MASK(LPA2_S2TTE_51_50); |
| 48 | pa |= INPLACE(LPA2_OA_51_50, EXTRACT(LPA2_S2TTE_51_50, s2tte)); |
| 49 | } |
| 50 | |
| 51 | return pa; |
| 52 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * Invalidates S2 TLB entries from [ipa, ipa + size] region tagged with `vmid`. |
| 56 | */ |
Javier Almansa Sobrino | 2eb98b0 | 2023-12-18 18:10:55 +0000 | [diff] [blame] | 57 | static void stage2_tlbi_ipa(const struct s2tt_context *s2_ctx, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 58 | unsigned long ipa, |
| 59 | unsigned long size) |
| 60 | { |
| 61 | /* |
| 62 | * Notes: |
| 63 | * |
| 64 | * - This follows the description provided in the Arm ARM on |
| 65 | * "Invalidation of TLB entries from stage 2 translations". |
| 66 | * |
| 67 | * - @TODO: Provide additional information to this primitive so that |
| 68 | * we can utilize: |
| 69 | * - The TTL level hint, see FEAT_TTL, |
| 70 | * - Final level lookup only invalidation, |
| 71 | * - Address range invalidation. |
| 72 | */ |
| 73 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 74 | assert(s2_ctx != NULL); |
| 75 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 76 | /* |
| 77 | * Save the current content of vttb_el2. |
| 78 | */ |
| 79 | unsigned long old_vttbr_el2 = read_vttbr_el2(); |
| 80 | |
| 81 | /* |
| 82 | * Make 'vmid' the `current vmid`. Note that the tlbi instructions |
| 83 | * bellow target the TLB entries that match the `current vmid`. |
| 84 | */ |
| 85 | write_vttbr_el2(INPLACE(VTTBR_EL2_VMID, s2_ctx->vmid)); |
| 86 | isb(); |
| 87 | |
| 88 | /* |
| 89 | * Invalidate entries in S2 TLB caches that |
| 90 | * match both `ipa` & the `current vmid`. |
| 91 | */ |
| 92 | while (size != 0UL) { |
| 93 | tlbiipas2e1is(ipa >> 12); |
| 94 | size -= GRANULE_SIZE; |
| 95 | ipa += GRANULE_SIZE; |
| 96 | } |
| 97 | dsb(ish); |
| 98 | |
| 99 | /* |
| 100 | * The architecture does not require TLB invalidation by IPA to affect |
| 101 | * combined Stage-1 + Stage-2 TLBs. Therefore we must invalidate all of |
| 102 | * Stage-1 (tagged with the `current vmid`) after invalidating Stage-2. |
| 103 | */ |
| 104 | tlbivmalle1is(); |
| 105 | dsb(ish); |
| 106 | isb(); |
| 107 | |
| 108 | /* |
| 109 | * Restore the old content of vttb_el2. |
| 110 | */ |
| 111 | write_vttbr_el2(old_vttbr_el2); |
| 112 | isb(); |
| 113 | } |
| 114 | |
| 115 | /* |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 116 | * Returns true if s2tte has 'output address' field, namely, if it is one of: |
| 117 | * - assigned_empty |
| 118 | * - assigned_ram |
| 119 | * - assigned_ns |
| 120 | * - assigned_destroyed |
| 121 | * - table |
| 122 | */ |
| 123 | static bool s2tte_has_pa(const struct s2tt_context *s2_ctx, |
| 124 | unsigned long s2tte, long level) |
| 125 | { |
| 126 | unsigned long desc_type = s2tte & S2TT_DESC_TYPE_MASK; |
| 127 | |
| 128 | return ((desc_type != S2TTE_INVALID) || /* block, page or table */ |
| 129 | s2tte_is_assigned_empty(s2_ctx, s2tte, level) || |
| 130 | s2tte_is_assigned_destroyed(s2_ctx, s2tte, level)); |
| 131 | } |
| 132 | |
| 133 | /* |
| 134 | * Creates a TTE containing only the PA. |
| 135 | * This function expects 'pa' to be aligned and bounded. |
| 136 | */ |
| 137 | static unsigned long pa_to_s2tte(unsigned long pa, bool lpa2) |
| 138 | { |
| 139 | unsigned long tte = pa; |
| 140 | |
| 141 | if (lpa2 == true) { |
| 142 | tte &= ~MASK(LPA2_OA_51_50); |
| 143 | tte |= INPLACE(LPA2_S2TTE_51_50, EXTRACT(LPA2_OA_51_50, pa)); |
| 144 | } |
| 145 | |
| 146 | return tte; |
| 147 | } |
| 148 | |
| 149 | /* |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 150 | * Invalidate S2 TLB entries with "addr" IPA. |
| 151 | * Call this function after: |
| 152 | * 1. A L3 page desc has been removed. |
| 153 | */ |
Javier Almansa Sobrino | 2eb98b0 | 2023-12-18 18:10:55 +0000 | [diff] [blame] | 154 | void s2tt_invalidate_page(const struct s2tt_context *s2_ctx, unsigned long addr) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 155 | { |
| 156 | stage2_tlbi_ipa(s2_ctx, addr, GRANULE_SIZE); |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 | * Invalidate S2 TLB entries with "addr" IPA. |
| 161 | * Call this function after: |
| 162 | * 1. A L2 block desc has been removed, or |
| 163 | * 2a. A L2 table desc has been removed, where |
| 164 | * 2b. All S2TTEs in L3 table that the L2 table desc was pointed to were invalid. |
| 165 | */ |
Javier Almansa Sobrino | 2eb98b0 | 2023-12-18 18:10:55 +0000 | [diff] [blame] | 166 | void s2tt_invalidate_block(const struct s2tt_context *s2_ctx, unsigned long addr) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 167 | { |
| 168 | stage2_tlbi_ipa(s2_ctx, addr, GRANULE_SIZE); |
| 169 | } |
| 170 | |
| 171 | /* |
| 172 | * Invalidate S2 TLB entries with "addr" IPA. |
| 173 | * Call this function after: |
| 174 | * 1a. A L2 table desc has been removed, where |
| 175 | * 1b. Some S2TTEs in the table that the L2 table desc was pointed to were valid. |
| 176 | */ |
Javier Almansa Sobrino | 2eb98b0 | 2023-12-18 18:10:55 +0000 | [diff] [blame] | 177 | void s2tt_invalidate_pages_in_block(const struct s2tt_context *s2_ctx, |
| 178 | unsigned long addr) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 179 | { |
| 180 | stage2_tlbi_ipa(s2_ctx, addr, BLOCK_L2_SIZE); |
| 181 | } |
| 182 | |
| 183 | /* |
| 184 | * Return the index of the entry describing @addr in the translation table at |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 185 | * level @level. This only works for non-concatenated page tables, so should |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 186 | * not be called to get the index for the starting level. |
| 187 | * |
| 188 | * See the library pseudocode |
| 189 | * aarch64/translation/vmsa_addrcalc/AArch64.TTEntryAddress on which this is |
| 190 | * modeled. |
| 191 | */ |
| 192 | static unsigned long s2_addr_to_idx(unsigned long addr, long level) |
| 193 | { |
AlexeiFedorov | bb1f1c8 | 2023-08-25 10:44:49 +0100 | [diff] [blame] | 194 | unsigned int levels, lsb; |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 195 | unsigned int s2tte_stride = (level < S2TT_MIN_STARTING_LEVEL) ? |
| 196 | S2TTE_STRIDE_LM1 : S2TTE_STRIDE; |
AlexeiFedorov | bb1f1c8 | 2023-08-25 10:44:49 +0100 | [diff] [blame] | 197 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 198 | levels = (unsigned int)(S2TT_PAGE_LEVEL - level); |
AlexeiFedorov | 56e1a8e | 2023-09-01 17:06:13 +0100 | [diff] [blame] | 199 | lsb = (levels * S2TTE_STRIDE) + GRANULE_SHIFT; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 200 | |
| 201 | addr >>= lsb; |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 202 | addr &= (1UL << s2tte_stride) - 1UL; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 203 | return addr; |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * Return the index of the entry describing @addr in the translation table |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 208 | * starting level. This may return an index >= S2TTES_PER_S2TT when the |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 209 | * combination of @start_level and @ipa_bits implies concatenated |
| 210 | * stage 2 tables. |
| 211 | * |
| 212 | * See the library pseudocode |
| 213 | * aarch64/translation/vmsa_addrcalc/AArch64.S2SLTTEntryAddress on which |
| 214 | * this is modeled. |
| 215 | */ |
| 216 | static unsigned long s2_sl_addr_to_idx(unsigned long addr, int start_level, |
| 217 | unsigned long ipa_bits) |
| 218 | { |
AlexeiFedorov | bb1f1c8 | 2023-08-25 10:44:49 +0100 | [diff] [blame] | 219 | unsigned int levels, lsb; |
| 220 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 221 | levels = (unsigned int)(S2TT_PAGE_LEVEL - start_level); |
AlexeiFedorov | 56e1a8e | 2023-09-01 17:06:13 +0100 | [diff] [blame] | 222 | lsb = (levels * S2TTE_STRIDE) + GRANULE_SHIFT; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 223 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 224 | addr &= ((1UL << ipa_bits) - 1UL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 225 | addr >>= lsb; |
| 226 | return addr; |
| 227 | } |
| 228 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 229 | static bool entry_is_table(unsigned long entry) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 230 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 231 | return ((entry & S2TT_DESC_TYPE_MASK) == S2TTE_L012_TABLE); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 234 | static unsigned long table_get_entry(const struct s2tt_context *s2_ctx, |
| 235 | struct granule *g_tbl, |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 236 | unsigned long idx) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 237 | { |
| 238 | unsigned long *table, entry; |
| 239 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 240 | (void)s2_ctx; |
| 241 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 242 | table = buffer_granule_map(g_tbl, SLOT_RTT); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 243 | assert(table != NULL); |
| 244 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 245 | entry = s2tte_read(&table[idx]); |
| 246 | buffer_unmap(table); |
| 247 | |
| 248 | return entry; |
| 249 | } |
| 250 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 251 | #define table_entry_to_phys(tte, lpa2) \ |
| 252 | s2tte_to_pa(tte, S2TT_PAGE_LEVEL, lpa2) |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 253 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 254 | static struct granule *find_next_level_idx(const struct s2tt_context *s2_ctx, |
| 255 | struct granule *g_tbl, |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 256 | unsigned long idx) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 257 | { |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 258 | assert(s2_ctx != NULL); |
| 259 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 260 | const unsigned long entry = table_get_entry(s2_ctx, g_tbl, idx); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 261 | |
| 262 | if (!entry_is_table(entry)) { |
| 263 | return NULL; |
| 264 | } |
| 265 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 266 | return addr_to_granule(table_entry_to_phys(entry, s2_ctx->enable_lpa2)); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 269 | static struct granule *find_lock_next_level(const struct s2tt_context *s2_ctx, |
| 270 | struct granule *g_tbl, |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 271 | unsigned long map_addr, |
| 272 | long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 273 | { |
| 274 | const unsigned long idx = s2_addr_to_idx(map_addr, level); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 275 | struct granule *g = find_next_level_idx(s2_ctx, g_tbl, idx); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 276 | |
| 277 | if (g != NULL) { |
| 278 | granule_lock(g, GRANULE_STATE_RTT); |
| 279 | } |
| 280 | |
| 281 | return g; |
| 282 | } |
| 283 | |
| 284 | /* |
| 285 | * Walk an RTT until level @level using @map_addr. |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 286 | * @g_root is the root (level 0/-1) table and must be locked before the call. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 287 | * @start_level is the initial lookup level used for the stage 2 translation |
| 288 | * tables which may depend on the configuration of the realm, factoring in the |
| 289 | * IPA size of the realm and the desired starting level (within the limits |
| 290 | * defined by the Armv8 VMSA including options for stage 2 table concatenation). |
| 291 | * The function uses hand-over-hand locking to avoid race conditions and allow |
| 292 | * concurrent access to RTT tree which is not part of the current walk; when a |
| 293 | * next level table is reached it is locked before releasing previously locked |
| 294 | * table. |
| 295 | * The walk stops when either: |
| 296 | * - The entry found is a leaf entry (not an RTT Table entry), or |
| 297 | * - Level @level is reached. |
| 298 | * |
| 299 | * On return: |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 300 | * - s2tt_walk::last_level is the last level that has been reached by the walk. |
| 301 | * - s2tt_walk.g_llt points to the TABLE granule at level @s2tt_walk::level. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 302 | * The granule is locked. |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 303 | * - s2tt_walk::index is the entry index at s2tt_walk.g_llt for @map_addr.i |
| 304 | * |
| 305 | * NOTE: This function expects that the root table on the s2 context is |
| 306 | * already locked. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 307 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 308 | void s2tt_walk_lock_unlock(const struct s2tt_context *s2_ctx, |
| 309 | unsigned long map_addr, |
| 310 | long level, |
| 311 | struct s2tt_walk *wi) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 312 | { |
Aliyha Ajmal | 7f9ee6e | 2024-10-10 10:44:17 +0100 | [diff] [blame^] | 313 | /* coverity[misra_c_2012_rule_11_9_violation:SUPRESS] */ |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 314 | struct granule *g_tbls[NR_RTT_LEVELS_LPA2] = { (struct granule *)NULL }; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 315 | struct granule *g_root; |
| 316 | unsigned long sl_idx, ipa_bits; |
| 317 | int i, start_level, last_level; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 318 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 319 | assert(s2_ctx != NULL); |
| 320 | |
| 321 | start_level = s2_ctx->s2_starting_level; |
| 322 | ipa_bits = s2_ctx->ipa_bits; |
| 323 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 324 | assert(level >= start_level); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 325 | assert(level <= S2TT_PAGE_LEVEL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 326 | assert(map_addr < (1UL << ipa_bits)); |
| 327 | assert(wi != NULL); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 328 | |
Javier Almansa Sobrino | 6e3b552 | 2024-04-10 12:12:13 +0100 | [diff] [blame] | 329 | if (s2_ctx->enable_lpa2 == true) { |
| 330 | assert(ipa_bits <= S2TTE_OA_BITS_LPA2); |
| 331 | } else { |
| 332 | assert(ipa_bits <= S2TTE_OA_BITS); |
| 333 | } |
| 334 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 335 | g_root = s2_ctx->g_rtt; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 336 | |
| 337 | /* Handle concatenated starting level (SL) tables */ |
| 338 | sl_idx = s2_sl_addr_to_idx(map_addr, start_level, ipa_bits); |
| 339 | if (sl_idx >= S2TTES_PER_S2TT) { |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 340 | unsigned int tt_num = (unsigned int)(sl_idx >> S2TTE_STRIDE); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 341 | struct granule *g_concat_root; |
| 342 | |
Javier Almansa Sobrino | 6e3b552 | 2024-04-10 12:12:13 +0100 | [diff] [blame] | 343 | assert(tt_num < s2_ctx->num_root_rtts); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 344 | |
| 345 | g_concat_root = (struct granule *)((uintptr_t)g_root + |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 346 | (tt_num * sizeof(struct granule))); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 347 | |
| 348 | granule_lock(g_concat_root, GRANULE_STATE_RTT); |
| 349 | granule_unlock(g_root); |
| 350 | g_root = g_concat_root; |
| 351 | } |
| 352 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 353 | /* 'start_level' can be '-1', so add 1 when used as an index */ |
| 354 | g_tbls[start_level + 1] = g_root; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 355 | for (i = start_level; i < level; i++) { |
| 356 | /* |
| 357 | * Lock next RTT level. Correct locking order is guaranteed |
| 358 | * because reference is obtained from a locked granule |
| 359 | * (previous level). Also, hand-over-hand locking/unlocking is |
| 360 | * used to avoid race conditions. |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 361 | * |
| 362 | * Note that as 'start_level' can be -1, we add '1' to the |
| 363 | * index 'i' to compensate for the negative value when we |
| 364 | * use it to index then 'g_tbls' list. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 365 | */ |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 366 | g_tbls[i + 1 + 1] = find_lock_next_level(s2_ctx, g_tbls[i + 1], |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 367 | map_addr, i); |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 368 | if (g_tbls[i + 1 + 1] == NULL) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 369 | last_level = i; |
| 370 | goto out; |
| 371 | } |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 372 | granule_unlock(g_tbls[i + 1]); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 373 | } |
| 374 | |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 375 | last_level = (int)level; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 376 | out: |
| 377 | wi->last_level = last_level; |
AlexeiFedorov | e956db3 | 2024-04-04 14:36:21 +0100 | [diff] [blame] | 378 | /* coverity[deref_overflow:SUPPRESS] */ |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 379 | wi->g_llt = g_tbls[last_level + 1]; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 380 | wi->index = s2_addr_to_idx(map_addr, last_level); |
| 381 | } |
| 382 | |
| 383 | /* |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 384 | * Creates an unassigned_empty s2tte. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 385 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 386 | unsigned long s2tte_create_unassigned_empty(const struct s2tt_context *s2_ctx) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 387 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 388 | (void)s2_ctx; |
| 389 | |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 390 | return (S2TTE_INVALID_HIPAS_UNASSIGNED | S2TTE_INVALID_RIPAS_EMPTY); |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | /* |
| 394 | * Creates an unassigned_ram s2tte. |
| 395 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 396 | unsigned long s2tte_create_unassigned_ram(const struct s2tt_context *s2_ctx) |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 397 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 398 | (void)s2_ctx; |
| 399 | |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 400 | return (S2TTE_INVALID_HIPAS_UNASSIGNED | S2TTE_INVALID_RIPAS_RAM); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | /* |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 404 | * Creates an unassigned_destroyed s2tte. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 405 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 406 | unsigned long s2tte_create_unassigned_destroyed(const struct s2tt_context *s2_ctx) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 407 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 408 | (void)s2_ctx; |
| 409 | |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 410 | return (S2TTE_INVALID_HIPAS_UNASSIGNED | S2TTE_INVALID_RIPAS_DESTROYED); |
| 411 | } |
| 412 | |
| 413 | /* |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 414 | * Creates an unassigned_ns s2tte. |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 415 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 416 | unsigned long s2tte_create_unassigned_ns(const struct s2tt_context *s2_ctx) |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 417 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 418 | (void)s2_ctx; |
| 419 | |
Javier Almansa Sobrino | 6e3b552 | 2024-04-10 12:12:13 +0100 | [diff] [blame] | 420 | return (S2TTE_NS | S2TTE_INVALID_HIPAS_UNASSIGNED); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* |
| 424 | * Creates an invalid s2tte with output address @pa, HIPAS=ASSIGNED and |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 425 | * RIPAS=@s2tte_ripas, at level @level. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 426 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 427 | static unsigned long s2tte_create_assigned(const struct s2tt_context *s2_ctx, |
| 428 | unsigned long pa, long level, |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 429 | unsigned long s2tte_ripas) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 430 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 431 | assert(level >= S2TT_MIN_BLOCK_LEVEL); |
| 432 | assert(level <= S2TT_PAGE_LEVEL); |
Javier Almansa Sobrino | 6e3b552 | 2024-04-10 12:12:13 +0100 | [diff] [blame] | 433 | assert(EXTRACT(S2TTE_INVALID_RIPAS, s2tte_ripas) |
| 434 | <= EXTRACT(S2TTE_INVALID_RIPAS, S2TTE_INVALID_RIPAS_DESTROYED)); |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 435 | assert(s2_ctx != NULL); |
Javier Almansa Sobrino | 6e3b552 | 2024-04-10 12:12:13 +0100 | [diff] [blame] | 436 | assert(s2tte_is_addr_lvl_aligned(s2_ctx, pa, level)); |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 437 | |
| 438 | unsigned long tte = pa_to_s2tte(pa, s2_ctx->enable_lpa2); |
| 439 | unsigned long s2tte_page, s2tte_block; |
| 440 | |
| 441 | if (s2_ctx->enable_lpa2 == true) { |
| 442 | s2tte_page = S2TTE_PAGE_LPA2; |
| 443 | s2tte_block = S2TTE_BLOCK_LPA2; |
| 444 | } else { |
| 445 | s2tte_page = S2TTE_PAGE; |
| 446 | s2tte_block = S2TTE_BLOCK; |
| 447 | } |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 448 | |
| 449 | if (s2tte_ripas == S2TTE_INVALID_RIPAS_RAM) { |
| 450 | if (level == S2TT_PAGE_LEVEL) { |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 451 | return (tte | s2tte_page); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 452 | } |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 453 | return (tte | s2tte_block); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 454 | } |
| 455 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 456 | return (tte | S2TTE_INVALID_HIPAS_ASSIGNED | s2tte_ripas); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | /* |
| 460 | * Creates and invalid s2tte with output address @pa, HIPAS=ASSIGNED and |
| 461 | * RIPAS=DESTROYED at level @level. |
| 462 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 463 | unsigned long s2tte_create_assigned_destroyed(const struct s2tt_context *s2_ctx, |
| 464 | unsigned long pa, long level) |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 465 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 466 | return s2tte_create_assigned(s2_ctx, pa, level, |
| 467 | S2TTE_INVALID_RIPAS_DESTROYED); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /* |
| 471 | * Creates an invalid s2tte with output address @pa, HIPAS=ASSIGNED and |
| 472 | * RIPAS=EMPTY at level @level. |
| 473 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 474 | unsigned long s2tte_create_assigned_empty(const struct s2tt_context *s2_ctx, |
| 475 | unsigned long pa, long level) |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 476 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 477 | return s2tte_create_assigned(s2_ctx, pa, level, |
| 478 | S2TTE_INVALID_RIPAS_EMPTY); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | /* |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 482 | * Creates an assigned_ram s2tte with output address @pa. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 483 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 484 | unsigned long s2tte_create_assigned_ram(const struct s2tt_context *s2_ctx, |
| 485 | unsigned long pa, long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 486 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 487 | return s2tte_create_assigned(s2_ctx, pa, level, |
| 488 | S2TTE_INVALID_RIPAS_RAM); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | /* |
Javier Almansa Sobrino | 84a1b16 | 2023-09-26 17:32:44 +0100 | [diff] [blame] | 492 | * Creates an assigned s2tte with output address @pa and the same |
| 493 | * RIPAS as passed on @s2tte. |
| 494 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 495 | unsigned long s2tte_create_assigned_unchanged(const struct s2tt_context *s2_ctx, |
| 496 | unsigned long s2tte, |
Javier Almansa Sobrino | 84a1b16 | 2023-09-26 17:32:44 +0100 | [diff] [blame] | 497 | unsigned long pa, |
| 498 | long level) |
| 499 | { |
| 500 | unsigned long current_ripas = s2tte & S2TTE_INVALID_RIPAS_MASK; |
| 501 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 502 | return s2tte_create_assigned(s2_ctx, pa, level, current_ripas); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /* |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 506 | * Creates an assigned_ns s2tte at level @level. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 507 | * |
| 508 | * The following S2 TTE fields are provided through @s2tte argument: |
| 509 | * - The physical address |
| 510 | * - MemAttr |
| 511 | * - S2AP |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 512 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 513 | unsigned long s2tte_create_assigned_ns(const struct s2tt_context *s2_ctx, |
| 514 | unsigned long s2tte, long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 515 | { |
Soby Mathew | 217748d | 2024-10-02 11:02:19 +0100 | [diff] [blame] | 516 | assert(s2_ctx != NULL); |
| 517 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 518 | /* |
Soby Mathew | 217748d | 2024-10-02 11:02:19 +0100 | [diff] [blame] | 519 | * We just mask out the DESC_TYPE below. We assume rest of the |
| 520 | * bits have been setup properly by the caller. |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 521 | */ |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 522 | unsigned long new_s2tte = s2tte & ~S2TT_DESC_TYPE_MASK; |
Soby Mathew | 217748d | 2024-10-02 11:02:19 +0100 | [diff] [blame] | 523 | bool lpa2 = s2_ctx->enable_lpa2; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 524 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 525 | assert(level >= S2TT_MIN_BLOCK_LEVEL); |
| 526 | assert(level <= S2TT_PAGE_LEVEL); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 527 | |
Soby Mathew | 217748d | 2024-10-02 11:02:19 +0100 | [diff] [blame] | 528 | /* The Shareability bits need to be added if FEAT_LPA2 is not enabled */ |
| 529 | if (!lpa2) { |
| 530 | new_s2tte |= S2TTE_SH_IS; |
| 531 | } |
| 532 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 533 | if (level == S2TT_PAGE_LEVEL) { |
Javier Almansa Sobrino | 15fc44e | 2023-09-29 13:52:04 +0100 | [diff] [blame] | 534 | return (new_s2tte | S2TTE_PAGE_NS); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 535 | } |
Javier Almansa Sobrino | 15fc44e | 2023-09-29 13:52:04 +0100 | [diff] [blame] | 536 | return (new_s2tte | S2TTE_BLOCK_NS); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /* |
| 540 | * Validate the portion of NS S2TTE that is provided by the host. |
| 541 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 542 | bool host_ns_s2tte_is_valid(const struct s2tt_context *s2_ctx, |
| 543 | unsigned long s2tte, long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 544 | { |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 545 | bool lpa2; |
| 546 | unsigned long mask; |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 547 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 548 | assert(s2_ctx != NULL); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 549 | assert(level >= S2TT_MIN_BLOCK_LEVEL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 550 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 551 | lpa2 = s2_ctx->enable_lpa2; |
| 552 | |
Soby Mathew | 217748d | 2024-10-02 11:02:19 +0100 | [diff] [blame] | 553 | mask = s2tte_lvl_mask(level, lpa2) | S2TTE_NS_ATTR_MASK; |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 554 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 555 | /* |
| 556 | * Test that all fields that are not controlled by the host are zero |
| 557 | * and that the output address is correctly aligned. Note that |
| 558 | * the host is permitted to map any physical address outside PAR. |
Shruti Gupta | 3530a71 | 2024-09-12 10:50:21 +0100 | [diff] [blame] | 559 | * Note that this also checks for the case when FEAT_LPA2 is disabled |
| 560 | * for the Realm, then the PA in `s2tte` must be <= 48 bits wide. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 561 | */ |
| 562 | if ((s2tte & ~mask) != 0UL) { |
| 563 | return false; |
| 564 | } |
| 565 | |
| 566 | /* |
| 567 | * Only one value masked by S2TTE_MEMATTR_MASK is invalid/reserved. |
| 568 | */ |
| 569 | if ((s2tte & S2TTE_MEMATTR_MASK) == S2TTE_MEMATTR_FWB_RESERVED) { |
| 570 | return false; |
| 571 | } |
| 572 | |
| 573 | /* |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 574 | * Note that all the values that are masked by S2TTE_AP_MASK are valid. |
| 575 | */ |
| 576 | return true; |
| 577 | } |
| 578 | |
| 579 | /* |
| 580 | * Returns the portion of NS S2TTE that is set by the host. |
| 581 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 582 | unsigned long host_ns_s2tte(const struct s2tt_context *s2_ctx, |
| 583 | unsigned long s2tte, long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 584 | { |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 585 | assert(s2_ctx != NULL); |
| 586 | |
Soby Mathew | 217748d | 2024-10-02 11:02:19 +0100 | [diff] [blame] | 587 | unsigned long mask = s2tte_lvl_mask(level, s2_ctx->enable_lpa2) |
| 588 | | S2TTE_NS_ATTR_MASK; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 589 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 590 | assert(level >= S2TT_MIN_BLOCK_LEVEL); |
| 591 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 592 | return (s2tte & mask); |
| 593 | } |
| 594 | |
| 595 | /* |
| 596 | * Creates a table s2tte at level @level with output address @pa. |
| 597 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 598 | unsigned long s2tte_create_table(const struct s2tt_context *s2_ctx, |
| 599 | unsigned long pa, long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 600 | { |
Shruti Gupta | 0a0d4ee | 2024-04-22 21:37:25 +0100 | [diff] [blame] | 601 | __unused long min_starting_level; |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 602 | |
Chuyue Luo | 5ef71d9 | 2023-10-24 14:29:20 +0100 | [diff] [blame] | 603 | (void)level; |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 604 | |
| 605 | assert(s2_ctx != NULL); |
Shruti Gupta | 0a0d4ee | 2024-04-22 21:37:25 +0100 | [diff] [blame] | 606 | |
| 607 | /* cppcheck-suppress misra-c2012-10.6 */ |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 608 | min_starting_level = (s2_ctx->enable_lpa2 == true) ? |
| 609 | S2TT_MIN_STARTING_LEVEL_LPA2 : S2TT_MIN_STARTING_LEVEL; |
Chuyue Luo | 5ef71d9 | 2023-10-24 14:29:20 +0100 | [diff] [blame] | 610 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 611 | assert(level < S2TT_PAGE_LEVEL); |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 612 | assert(level >= min_starting_level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 613 | assert(GRANULE_ALIGNED(pa)); |
| 614 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 615 | return (pa_to_s2tte(pa, s2_ctx->enable_lpa2) | S2TTE_TABLE); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /* |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 619 | * Returns true if s2tte has defined ripas value, namely if it is one of: |
| 620 | * - unassigned_empty |
| 621 | * - unassigned_ram |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 622 | * - unassigned_destroyed |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 623 | * - assigned_empty |
| 624 | * - assigned_ram |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 625 | * - assigned_destroyed |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 626 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 627 | bool s2tte_has_ripas(const struct s2tt_context *s2_ctx, |
| 628 | unsigned long s2tte, long level) |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 629 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 630 | return (((s2tte & S2TTE_NS) == 0UL) && !s2tte_is_table(s2_ctx, |
| 631 | s2tte, level)); |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /* |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 635 | * Returns true if @s2tte has HIPAS=@hipas. |
| 636 | */ |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 637 | static inline bool s2tte_has_hipas(unsigned long s2tte, unsigned long hipas) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 638 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 639 | unsigned long desc_type = s2tte & S2TT_DESC_TYPE_MASK; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 640 | unsigned long invalid_desc_hipas = s2tte & S2TTE_INVALID_HIPAS_MASK; |
| 641 | |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 642 | return ((desc_type == S2TTE_INVALID) && (invalid_desc_hipas == hipas)); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | /* |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 646 | * Returns true if @s2tte has HIPAS=UNASSIGNED and RIPAS=@ripas. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 647 | */ |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 648 | static inline bool s2tte_has_unassigned_ripas(unsigned long s2tte, |
| 649 | unsigned long ripas) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 650 | { |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 651 | return (((s2tte & S2TTE_INVALID_RIPAS_MASK) == ripas) && |
| 652 | s2tte_has_hipas(s2tte, S2TTE_INVALID_HIPAS_UNASSIGNED)); |
| 653 | } |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 654 | |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 655 | /* |
| 656 | * Returns true if @s2tte has HIPAS=ASSIGNED and RIPAS=@ripas. |
| 657 | */ |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 658 | static inline bool s2tte_has_assigned_ripas(unsigned long s2tte, |
| 659 | unsigned long ripas) |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 660 | { |
| 661 | return (((s2tte & S2TTE_INVALID_RIPAS_MASK) == ripas) && |
| 662 | s2tte_has_hipas(s2tte, S2TTE_INVALID_HIPAS_ASSIGNED)); |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | /* |
AlexeiFedorov | 0f9cd1f | 2023-07-10 17:04:58 +0100 | [diff] [blame] | 666 | * Returns true if @s2tte has HIPAS=UNASSIGNED. |
| 667 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 668 | bool s2tte_is_unassigned(const struct s2tt_context *s2_ctx, unsigned long s2tte) |
AlexeiFedorov | 0f9cd1f | 2023-07-10 17:04:58 +0100 | [diff] [blame] | 669 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 670 | (void)s2_ctx; |
| 671 | |
AlexeiFedorov | 0f9cd1f | 2023-07-10 17:04:58 +0100 | [diff] [blame] | 672 | return s2tte_has_hipas(s2tte, S2TTE_INVALID_HIPAS_UNASSIGNED); |
| 673 | } |
| 674 | |
| 675 | /* |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 676 | * Returns true if @s2tte is an unassigned_empty. |
| 677 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 678 | bool s2tte_is_unassigned_empty(const struct s2tt_context *s2_ctx, |
| 679 | unsigned long s2tte) |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 680 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 681 | (void)s2_ctx; |
| 682 | |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 683 | return (((s2tte & S2TTE_NS) == 0UL) && |
| 684 | s2tte_has_unassigned_ripas(s2tte, S2TTE_INVALID_RIPAS_EMPTY)); |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | /* |
| 688 | * Returns true if @s2tte is an unassigned_ram. |
| 689 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 690 | bool s2tte_is_unassigned_ram(const struct s2tt_context *s2_ctx, |
| 691 | unsigned long s2tte) |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 692 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 693 | (void)s2_ctx; |
| 694 | |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 695 | return s2tte_has_unassigned_ripas(s2tte, S2TTE_INVALID_RIPAS_RAM); |
| 696 | } |
| 697 | |
| 698 | /* |
AlexeiFedorov | 5ceff35 | 2023-04-12 16:17:00 +0100 | [diff] [blame] | 699 | * Returns true if @s2tte is unassigned_ns. |
| 700 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 701 | bool s2tte_is_unassigned_ns(const struct s2tt_context *s2_ctx, |
| 702 | unsigned long s2tte) |
AlexeiFedorov | 5ceff35 | 2023-04-12 16:17:00 +0100 | [diff] [blame] | 703 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 704 | (void)s2_ctx; |
| 705 | |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 706 | return (((s2tte & S2TTE_NS) != 0UL) && |
| 707 | s2tte_has_hipas(s2tte, S2TTE_INVALID_HIPAS_UNASSIGNED)); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | /* |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 711 | * Returns true if @s2tte has RIPAS=DESTROYED. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 712 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 713 | bool s2tte_is_unassigned_destroyed(const struct s2tt_context *s2_ctx, |
| 714 | unsigned long s2tte) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 715 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 716 | (void)s2_ctx; |
| 717 | |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 718 | return s2tte_has_unassigned_ripas(s2tte, S2TTE_INVALID_RIPAS_DESTROYED); |
| 719 | } |
| 720 | |
| 721 | /* |
| 722 | * Returns true if @s2tte is an assigned_destroyed. |
| 723 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 724 | bool s2tte_is_assigned_destroyed(const struct s2tt_context *s2_ctx, |
| 725 | unsigned long s2tte, long level) |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 726 | { |
| 727 | (void)level; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 728 | (void)s2_ctx; |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 729 | |
| 730 | return s2tte_has_assigned_ripas(s2tte, S2TTE_INVALID_RIPAS_DESTROYED); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | /* |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 734 | * Returns true if @s2tte is an assigned_empty. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 735 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 736 | bool s2tte_is_assigned_empty(const struct s2tt_context *s2_ctx, |
| 737 | unsigned long s2tte, long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 738 | { |
| 739 | (void)level; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 740 | (void)s2_ctx; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 741 | |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 742 | return s2tte_has_assigned_ripas(s2tte, S2TTE_INVALID_RIPAS_EMPTY); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 743 | } |
| 744 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 745 | static bool s2tte_check(const struct s2tt_context *s2_ctx, unsigned long s2tte, |
| 746 | long level, unsigned long ns) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 747 | { |
| 748 | unsigned long desc_type; |
| 749 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 750 | (void)s2_ctx; |
| 751 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 752 | if ((s2tte & S2TTE_NS) != ns) { |
| 753 | return false; |
| 754 | } |
| 755 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 756 | desc_type = s2tte & S2TT_DESC_TYPE_MASK; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 757 | |
Shruti Gupta | 3105c3f | 2024-02-26 14:06:11 +0000 | [diff] [blame] | 758 | /* Only pages at L3 and valid blocks at L2 and L1 allowed */ |
Javier Almansa Sobrino | 6e3b552 | 2024-04-10 12:12:13 +0100 | [diff] [blame] | 759 | if (level == S2TT_PAGE_LEVEL) { |
| 760 | return (desc_type == S2TTE_L3_PAGE); |
| 761 | } |
| 762 | |
| 763 | if ((level >= S2TT_MIN_BLOCK_LEVEL) && (desc_type == S2TTE_L012_BLOCK)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 764 | return true; |
| 765 | } |
| 766 | |
| 767 | return false; |
| 768 | } |
| 769 | |
| 770 | /* |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 771 | * Returns true if @s2tte is an assigned_ram. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 772 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 773 | bool s2tte_is_assigned_ram(const struct s2tt_context *s2_ctx, |
| 774 | unsigned long s2tte, long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 775 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 776 | return s2tte_check(s2_ctx, s2tte, level, 0UL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | /* |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 780 | * Returns true if @s2tte is an assigned_ns s2tte. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 781 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 782 | bool s2tte_is_assigned_ns(const struct s2tt_context *s2_ctx, |
| 783 | unsigned long s2tte, long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 784 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 785 | return s2tte_check(s2_ctx, s2tte, level, S2TTE_NS); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | /* |
| 789 | * Returns true if @s2tte is a table at level @level. |
| 790 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 791 | bool s2tte_is_table(const struct s2tt_context *s2_ctx, unsigned long s2tte, |
| 792 | long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 793 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 794 | (void)s2_ctx; |
| 795 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 796 | return ((level < S2TT_PAGE_LEVEL) && |
| 797 | ((s2tte & S2TT_DESC_TYPE_MASK) == S2TTE_L012_TABLE)); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | /* |
| 801 | * Returns RIPAS of @s2tte. |
| 802 | * |
| 803 | * Caller should ensure that HIPAS=UNASSIGNED or HIPAS=ASSIGNED. |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 804 | * The s2tte, if valid, should correspond to RIPAS_RAM. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 805 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 806 | enum ripas s2tte_get_ripas(const struct s2tt_context *s2_ctx, unsigned long s2tte) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 807 | { |
| 808 | unsigned long desc_ripas = s2tte & S2TTE_INVALID_RIPAS_MASK; |
Javier Almansa Sobrino | b802a0e | 2024-07-05 12:52:23 +0100 | [diff] [blame] | 809 | unsigned long desc_type = s2tte & S2TT_DESC_TYPE_MASK; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 810 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 811 | (void)s2_ctx; |
| 812 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 813 | /* |
Javier Almansa Sobrino | b802a0e | 2024-07-05 12:52:23 +0100 | [diff] [blame] | 814 | * If a valid S2TTE descriptor is passed, the RIPAS corresponds to |
| 815 | * RIPAS_RAM. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 816 | */ |
Javier Almansa Sobrino | b802a0e | 2024-07-05 12:52:23 +0100 | [diff] [blame] | 817 | if (desc_type != S2TTE_INVALID) { |
| 818 | assert((desc_type == S2TTE_L012_BLOCK) || |
| 819 | (desc_type == S2TTE_L3_PAGE)); |
| 820 | return RIPAS_RAM; |
| 821 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 822 | |
Javier Almansa Sobrino | b802a0e | 2024-07-05 12:52:23 +0100 | [diff] [blame] | 823 | assert(EXTRACT(S2TTE_INVALID_HIPAS, s2tte) <= RMI_ASSIGNED); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 824 | |
| 825 | desc_ripas = desc_ripas >> S2TTE_INVALID_RIPAS_SHIFT; |
| 826 | |
| 827 | assert(desc_ripas <= (unsigned int)RIPAS_DESTROYED); |
| 828 | |
| 829 | return (enum ripas)desc_ripas; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | /* |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 833 | * Populates @s2tt with unassigned_empty s2ttes. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 834 | * |
| 835 | * The granule is populated before it is made a table, |
| 836 | * hence, don't use s2tte_write for access. |
| 837 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 838 | void s2tt_init_unassigned_empty(const struct s2tt_context *s2_ctx, |
| 839 | unsigned long *s2tt) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 840 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 841 | assert(s2tt != NULL); |
| 842 | |
| 843 | unsigned long s2tte = |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 844 | s2tte_create_unassigned_empty(s2_ctx); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 845 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 846 | for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 847 | s2tt[i] = s2tte; |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | dsb(ish); |
| 851 | } |
| 852 | |
| 853 | /* |
| 854 | * Populates @s2tt with unassigned_ram s2ttes. |
| 855 | * |
| 856 | * The granule is populated before it is made a table, |
| 857 | * hence, don't use s2tte_write for access. |
| 858 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 859 | void s2tt_init_unassigned_ram(const struct s2tt_context *s2_ctx, |
| 860 | unsigned long *s2tt) |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 861 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 862 | assert(s2tt != NULL); |
| 863 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 864 | unsigned long s2tte = s2tte_create_unassigned_ram(s2_ctx); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 865 | |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 866 | for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 867 | s2tt[i] = s2tte; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | dsb(ish); |
| 871 | } |
| 872 | |
| 873 | /* |
AlexeiFedorov | 5ceff35 | 2023-04-12 16:17:00 +0100 | [diff] [blame] | 874 | * Populates @s2tt with unassigned_ns s2ttes. |
| 875 | * |
| 876 | * The granule is populated before it is made a table, |
| 877 | * hence, don't use s2tte_write for access. |
| 878 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 879 | void s2tt_init_unassigned_ns(const struct s2tt_context *s2_ctx, |
| 880 | unsigned long *s2tt) |
AlexeiFedorov | 5ceff35 | 2023-04-12 16:17:00 +0100 | [diff] [blame] | 881 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 882 | assert(s2tt != NULL); |
| 883 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 884 | unsigned long s2tte = s2tte_create_unassigned_ns(s2_ctx); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 885 | |
AlexeiFedorov | 5ceff35 | 2023-04-12 16:17:00 +0100 | [diff] [blame] | 886 | for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 887 | s2tt[i] = s2tte; |
AlexeiFedorov | 5ceff35 | 2023-04-12 16:17:00 +0100 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | dsb(ish); |
| 891 | } |
| 892 | |
| 893 | /* |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 894 | * Populates @s2tt with s2ttes which have HIPAS=DESTROYED. |
| 895 | * |
| 896 | * The granule is populated before it is made a table, |
| 897 | * hence, don't use s2tte_write for access. |
| 898 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 899 | void s2tt_init_unassigned_destroyed(const struct s2tt_context *s2_ctx, |
| 900 | unsigned long *s2tt) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 901 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 902 | assert(s2tt != NULL); |
| 903 | |
| 904 | unsigned long s2tte = |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 905 | s2tte_create_unassigned_destroyed(s2_ctx); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 906 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 907 | for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 908 | s2tt[i] = s2tte; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 909 | } |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 910 | dsb(ish); |
| 911 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 912 | |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 913 | /* |
| 914 | * Populates @s2tt with HIPAS=ASSIGNED, RIPAS=DESTROYED s2ttes that refer to a |
| 915 | * contiguous memory block starting at @pa, and mapped at level @level. |
| 916 | * |
| 917 | * The granule is populated before it is made a table, |
| 918 | * hence, don't use s2tte_write for access. |
| 919 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 920 | void s2tt_init_assigned_destroyed(const struct s2tt_context *s2_ctx, |
| 921 | unsigned long *s2tt, unsigned long pa, |
| 922 | long level) |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 923 | { |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 924 | assert(s2tt != NULL); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 925 | assert(level >= S2TT_MIN_BLOCK_LEVEL); |
| 926 | assert(level <= S2TT_PAGE_LEVEL); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 927 | assert(s2tte_is_addr_lvl_aligned(s2_ctx, pa, level)); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 928 | |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 929 | const unsigned long map_size = s2tte_map_size(level); |
| 930 | |
| 931 | for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 932 | s2tt[i] = s2tte_create_assigned_destroyed(s2_ctx, pa, level); |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 933 | pa += map_size; |
| 934 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 935 | dsb(ish); |
| 936 | } |
| 937 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 938 | /* |
| 939 | * Populates @s2tt with HIPAS=ASSIGNED, RIPAS=EMPTY s2ttes that refer to a |
| 940 | * contiguous memory block starting at @pa, and mapped at level @level. |
| 941 | * |
| 942 | * The granule is populated before it is made a table, |
| 943 | * hence, don't use s2tte_write for access. |
| 944 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 945 | void s2tt_init_assigned_empty(const struct s2tt_context *s2_ctx, |
| 946 | unsigned long *s2tt, unsigned long pa, |
| 947 | long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 948 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 949 | assert(level >= S2TT_MIN_BLOCK_LEVEL); |
| 950 | assert(level <= S2TT_PAGE_LEVEL); |
| 951 | assert(s2tt != NULL); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 952 | assert(s2tte_is_addr_lvl_aligned(s2_ctx, pa, level)); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 953 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 954 | const unsigned long map_size = s2tte_map_size(level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 955 | |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 956 | for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 957 | s2tt[i] = s2tte_create_assigned_empty(s2_ctx, pa, level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 958 | pa += map_size; |
| 959 | } |
| 960 | dsb(ish); |
| 961 | } |
| 962 | |
| 963 | /* |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 964 | * Populates @s2tt with assigned_ram s2ttes that refer to a |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 965 | * contiguous memory block starting at @pa, and mapped at level @level. |
| 966 | * |
| 967 | * The granule is populated before it is made a table, |
| 968 | * hence, don't use s2tte_write for access. |
| 969 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 970 | void s2tt_init_assigned_ram(const struct s2tt_context *s2_ctx, |
| 971 | unsigned long *s2tt, unsigned long pa, |
| 972 | long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 973 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 974 | assert(level >= S2TT_MIN_BLOCK_LEVEL); |
| 975 | assert(level <= S2TT_PAGE_LEVEL); |
| 976 | assert(s2tt != NULL); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 977 | assert(s2tte_is_addr_lvl_aligned(s2_ctx, pa, level)); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 978 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 979 | const unsigned long map_size = s2tte_map_size(level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 980 | |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 981 | for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 982 | s2tt[i] = s2tte_create_assigned_ram(s2_ctx, pa, level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 983 | pa += map_size; |
| 984 | } |
| 985 | dsb(ish); |
| 986 | } |
| 987 | |
| 988 | /* |
Javier Almansa Sobrino | 15fc44e | 2023-09-29 13:52:04 +0100 | [diff] [blame] | 989 | * Populates @s2tt with NS attributes @attrs that refer to a |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 990 | * contiguous memory block starting at @pa, and mapped at level @level. |
| 991 | * |
| 992 | * The granule is populated before it is made a table, |
| 993 | * hence, don't use s2tte_write for access. |
| 994 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 995 | void s2tt_init_assigned_ns(const struct s2tt_context *s2_ctx, |
| 996 | unsigned long *s2tt, unsigned long attrs, |
Javier Almansa Sobrino | 15fc44e | 2023-09-29 13:52:04 +0100 | [diff] [blame] | 997 | unsigned long pa, long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 998 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 999 | assert(level >= S2TT_MIN_BLOCK_LEVEL); |
| 1000 | assert(level <= S2TT_PAGE_LEVEL); |
| 1001 | assert(s2tt != NULL); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1002 | assert(s2tte_is_addr_lvl_aligned(s2_ctx, pa, level)); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1003 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1004 | const unsigned long map_size = s2tte_map_size(level); |
Soby Mathew | 217748d | 2024-10-02 11:02:19 +0100 | [diff] [blame] | 1005 | |
| 1006 | attrs &= S2TTE_NS_ATTR_MASK; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1007 | |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 1008 | for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) { |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1009 | s2tt[i] = s2tte_create_assigned_ns(s2_ctx, |
Soby Mathew | 217748d | 2024-10-02 11:02:19 +0100 | [diff] [blame] | 1010 | attrs | pa_to_s2tte(pa, s2_ctx->enable_lpa2), |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1011 | level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1012 | pa += map_size; |
| 1013 | } |
Javier Almansa Sobrino | 15fc44e | 2023-09-29 13:52:04 +0100 | [diff] [blame] | 1014 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1015 | dsb(ish); |
| 1016 | } |
| 1017 | |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 1018 | /* |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1019 | * Returns true if s2tte is a live RTTE entry. i.e., |
AlexeiFedorov | 3ebd462 | 2023-07-18 16:27:39 +0100 | [diff] [blame] | 1020 | * HIPAS is ASSIGNED. |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1021 | * |
| 1022 | * NOTE: For now, only the RTTE with PA are live. |
| 1023 | * This could change with EXPORT/IMPORT support. |
| 1024 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1025 | static bool s2tte_is_live(const struct s2tt_context *s2_ctx, |
| 1026 | unsigned long s2tte, long level) |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1027 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1028 | return s2tte_has_pa(s2_ctx, s2tte, level); |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1029 | } |
| 1030 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1031 | /* Returns physical address of a S2TTE */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1032 | unsigned long s2tte_pa(const struct s2tt_context *s2_ctx, unsigned long s2tte, |
| 1033 | long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1034 | { |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1035 | bool lpa2; |
| 1036 | unsigned long pa; |
| 1037 | __unused long min_starting_level; |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1038 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1039 | assert(s2_ctx != NULL); |
| 1040 | |
Shruti Gupta | 0a0d4ee | 2024-04-22 21:37:25 +0100 | [diff] [blame] | 1041 | /* cppcheck-suppress misra-c2012-10.6 */ |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1042 | min_starting_level = (s2_ctx->enable_lpa2 == true) ? |
| 1043 | S2TT_MIN_STARTING_LEVEL_LPA2 : S2TT_MIN_STARTING_LEVEL; |
| 1044 | assert(level >= min_starting_level); |
| 1045 | assert(level <= S2TT_PAGE_LEVEL); |
| 1046 | assert(s2tte_has_pa(s2_ctx, s2tte, level)); |
| 1047 | |
| 1048 | lpa2 = s2_ctx->enable_lpa2; |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 1049 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1050 | if (s2tte_is_table(s2_ctx, s2tte, level)) { |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1051 | pa = table_entry_to_phys(s2tte, lpa2); |
| 1052 | } else { |
| 1053 | pa = s2tte_to_pa(s2tte, level, lpa2); |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 1054 | } |
| 1055 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1056 | return pa; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1059 | bool s2tte_is_addr_lvl_aligned(const struct s2tt_context *s2_ctx, |
| 1060 | unsigned long addr, long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1061 | { |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1062 | assert(s2_ctx != NULL); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1063 | |
Shruti Gupta | 0a0d4ee | 2024-04-22 21:37:25 +0100 | [diff] [blame] | 1064 | /* cppcheck-suppress misra-c2012-10.6 */ |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1065 | __unused long min_starting_level = (s2_ctx->enable_lpa2 == true) ? |
| 1066 | S2TT_MIN_STARTING_LEVEL_LPA2 : S2TT_MIN_STARTING_LEVEL; |
| 1067 | unsigned long levels = (unsigned long)(S2TT_PAGE_LEVEL - level); |
| 1068 | unsigned long lsb = (levels * S2TTE_STRIDE) + GRANULE_SHIFT; |
| 1069 | unsigned long s2tte_oa_bits = (s2_ctx->enable_lpa2 == true) ? |
| 1070 | S2TTE_OA_BITS_LPA2 : S2TTE_OA_BITS; |
| 1071 | |
| 1072 | assert(level <= S2TT_PAGE_LEVEL); |
| 1073 | assert(level >= min_starting_level); |
| 1074 | |
| 1075 | return (addr == (addr & BIT_MASK_ULL((s2tte_oa_bits - 1U), lsb))); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1078 | typedef bool (*s2tte_type_checker)(const struct s2tt_context *s2_ctx, |
| 1079 | unsigned long s2tte); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1080 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1081 | static bool table_is_uniform_block(const struct s2tt_context *s2_ctx, |
| 1082 | unsigned long *table, |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1083 | s2tte_type_checker s2tte_is_x) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1084 | { |
AlexeiFedorov | 377d81f | 2023-04-14 16:29:12 +0100 | [diff] [blame] | 1085 | for (unsigned int i = 0U; i < S2TTES_PER_S2TT; i++) { |
| 1086 | unsigned long s2tte = s2tte_read(&table[i]); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1087 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1088 | if (!s2tte_is_x(s2_ctx, s2tte)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1089 | return false; |
| 1090 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | return true; |
| 1094 | } |
| 1095 | |
| 1096 | /* |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 1097 | * Returns true if all s2ttes in @table are unassigned_empty. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1098 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1099 | bool s2tt_is_unassigned_empty_block(const struct s2tt_context *s2_ctx, |
| 1100 | unsigned long *table) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1101 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1102 | assert(table != NULL); |
| 1103 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1104 | return table_is_uniform_block(s2_ctx, table, s2tte_is_unassigned_empty); |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | /* |
| 1108 | * Returns true if all s2ttes in @table are unassigned_ram. |
| 1109 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1110 | bool s2tt_is_unassigned_ram_block(const struct s2tt_context *s2_ctx, |
| 1111 | unsigned long *table) |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 1112 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1113 | assert(table != NULL); |
| 1114 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1115 | return table_is_uniform_block(s2_ctx, table, s2tte_is_unassigned_ram); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | /* |
AlexeiFedorov | 5ceff35 | 2023-04-12 16:17:00 +0100 | [diff] [blame] | 1119 | * Returns true if all s2ttes in @table are unassigned_ns |
| 1120 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1121 | bool s2tt_is_unassigned_ns_block(const struct s2tt_context *s2_ctx, |
| 1122 | unsigned long *table) |
AlexeiFedorov | 5ceff35 | 2023-04-12 16:17:00 +0100 | [diff] [blame] | 1123 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1124 | assert(table != NULL); |
| 1125 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1126 | return table_is_uniform_block(s2_ctx, table, s2tte_is_unassigned_ns); |
AlexeiFedorov | 5ceff35 | 2023-04-12 16:17:00 +0100 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | /* |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 1130 | * Returns true if all s2ttes in @table are unassigned_destroyed |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1131 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1132 | bool s2tt_is_unassigned_destroyed_block(const struct s2tt_context *s2_ctx, |
| 1133 | unsigned long *table) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1134 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1135 | assert(table != NULL); |
| 1136 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1137 | return table_is_uniform_block(s2_ctx, table, |
| 1138 | s2tte_is_unassigned_destroyed); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1141 | typedef bool (*s2tte_type_level_checker)(const struct s2tt_context *s2_ctx, |
| 1142 | unsigned long s2tte, long level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1143 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1144 | static bool table_maps_block(const struct s2tt_context *s2_ctx, |
| 1145 | unsigned long *table, |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1146 | long level, |
| 1147 | s2tte_type_level_checker s2tte_is_x, |
| 1148 | bool check_ns_attrs) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1149 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1150 | assert(table != NULL); |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1151 | assert(s2_ctx != NULL); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1152 | |
Soby Mathew | 217748d | 2024-10-02 11:02:19 +0100 | [diff] [blame] | 1153 | unsigned long base_pa; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1154 | unsigned long map_size = s2tte_map_size(level); |
| 1155 | unsigned long s2tte = s2tte_read(&table[0]); |
Javier Almansa Sobrino | 8865ec3 | 2024-04-18 10:50:03 +0100 | [diff] [blame] | 1156 | unsigned long s2tt_ns_attrs; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1157 | unsigned int i; |
| 1158 | |
Javier Almansa Sobrino | 6e3b552 | 2024-04-10 12:12:13 +0100 | [diff] [blame] | 1159 | if (s2_ctx->enable_lpa2 == true) { |
| 1160 | assert(level >= S2TT_MIN_STARTING_LEVEL_LPA2); |
| 1161 | } else { |
| 1162 | assert(level >= S2TT_MIN_STARTING_LEVEL); |
| 1163 | } |
| 1164 | |
| 1165 | assert(level <= S2TT_PAGE_LEVEL); |
| 1166 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1167 | if (!s2tte_is_x(s2_ctx, s2tte, level)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1168 | return false; |
| 1169 | } |
| 1170 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1171 | base_pa = s2tte_pa(s2_ctx, s2tte, level); |
| 1172 | if (!s2tte_is_addr_lvl_aligned(s2_ctx, base_pa, level - 1L)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1173 | return false; |
| 1174 | } |
| 1175 | |
Soby Mathew | 217748d | 2024-10-02 11:02:19 +0100 | [diff] [blame] | 1176 | s2tt_ns_attrs = s2tte & S2TTE_NS_ATTR_MASK; |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1177 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1178 | for (i = 1U; i < S2TTES_PER_S2TT; i++) { |
| 1179 | unsigned long expected_pa = base_pa + (i * map_size); |
| 1180 | |
| 1181 | s2tte = s2tte_read(&table[i]); |
| 1182 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1183 | if (!s2tte_is_x(s2_ctx, s2tte, level)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1184 | return false; |
| 1185 | } |
| 1186 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1187 | if (s2tte_pa(s2_ctx, s2tte, level) != expected_pa) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1188 | return false; |
| 1189 | } |
Javier Almansa Sobrino | 15fc44e | 2023-09-29 13:52:04 +0100 | [diff] [blame] | 1190 | |
| 1191 | if (check_ns_attrs) { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1192 | unsigned long ns_attrs = |
Soby Mathew | 217748d | 2024-10-02 11:02:19 +0100 | [diff] [blame] | 1193 | s2tte & S2TTE_NS_ATTR_MASK; |
Javier Almansa Sobrino | 15fc44e | 2023-09-29 13:52:04 +0100 | [diff] [blame] | 1194 | |
| 1195 | /* |
| 1196 | * We match all the attributes in the S2TTE |
| 1197 | * except for the AF bit. |
| 1198 | */ |
Javier Almansa Sobrino | 8865ec3 | 2024-04-18 10:50:03 +0100 | [diff] [blame] | 1199 | if (s2tt_ns_attrs != ns_attrs) { |
Javier Almansa Sobrino | 15fc44e | 2023-09-29 13:52:04 +0100 | [diff] [blame] | 1200 | return false; |
| 1201 | } |
| 1202 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | return true; |
| 1206 | } |
| 1207 | |
| 1208 | /* |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 1209 | * Returns true if all s2ttes are assigned_empty |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1210 | * and refer to a contiguous block of granules aligned to @level - 1. |
| 1211 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1212 | bool s2tt_maps_assigned_empty_block(const struct s2tt_context *s2_ctx, |
| 1213 | unsigned long *table, long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1214 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1215 | return table_maps_block(s2_ctx, table, level, |
| 1216 | s2tte_is_assigned_empty, false); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | /* |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 1220 | * Returns true if all s2ttes are assigned_ram and |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1221 | * refer to a contiguous block of granules aligned to @level - 1. |
| 1222 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1223 | bool s2tt_maps_assigned_ram_block(const struct s2tt_context *s2_ctx, |
| 1224 | unsigned long *table, long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1225 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1226 | return table_maps_block(s2_ctx, table, level, |
| 1227 | s2tte_is_assigned_ram, false); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | /* |
Javier Almansa Sobrino | 15fc44e | 2023-09-29 13:52:04 +0100 | [diff] [blame] | 1231 | * Returns true if |
| 1232 | * - all s2ttes in @table are assigned_ns s2ttes and |
| 1233 | * - they refer to a contiguous block of granules aligned to @level - 1 and |
| 1234 | * - all the s2tte attributes in @table controlled by the host are identical |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 1235 | * |
| 1236 | * @pre: @table maps IPA outside PAR. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1237 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1238 | bool s2tt_maps_assigned_ns_block(const struct s2tt_context *s2_ctx, |
| 1239 | unsigned long *table, long level) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1240 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1241 | return table_maps_block(s2_ctx, table, level, |
| 1242 | s2tte_is_assigned_ns, true); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1243 | } |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1244 | |
| 1245 | /* |
AlexeiFedorov | 3f840a0 | 2023-07-19 10:55:05 +0100 | [diff] [blame] | 1246 | * Returns true if all s2ttes are assigned_destroyed and |
| 1247 | * refer to a contiguous block of granules aligned to @level - 1. |
| 1248 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1249 | bool s2tt_maps_assigned_destroyed_block(const struct s2tt_context *s2_ctx, |
| 1250 | unsigned long *table, long level) |
AlexeiFedorov | 3f840a0 | 2023-07-19 10:55:05 +0100 | [diff] [blame] | 1251 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1252 | return table_maps_block(s2_ctx, table, level, |
| 1253 | s2tte_is_assigned_destroyed, false); |
AlexeiFedorov | 3f840a0 | 2023-07-19 10:55:05 +0100 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | /* |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1257 | * Scan the RTT @s2tt (which is @wi.level), from the entry (@wi.index) and |
AlexeiFedorov | 3ebd462 | 2023-07-18 16:27:39 +0100 | [diff] [blame] | 1258 | * skip the non-live entries (i.e., HIPAS=UNASSIGNED). |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1259 | * In other words, the scanning stops when a live RTTE is encountered or we |
| 1260 | * reach the end of this RTT. |
| 1261 | * |
| 1262 | * For now an RTTE can be considered non-live if it doesn't have a PA. |
| 1263 | * NOTE: This would change with EXPORT/IMPORT where we may have metadata stored |
| 1264 | * in the RTTE. |
| 1265 | * |
| 1266 | * @addr is not necessarily aligned to the wi.last_level (e.g., if we were called |
| 1267 | * with RMI_ERROR_RTT). |
| 1268 | * |
| 1269 | * Returns: |
| 1270 | * - If the entry @wi.index is live, returns @addr. |
| 1271 | * - If none of the entries in the @s2tt are "live", returns the address of the |
| 1272 | * first entry in the next table. |
| 1273 | * - Otherwise, the address of the first live entry in @s2tt |
| 1274 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1275 | unsigned long s2tt_skip_non_live_entries(const struct s2tt_context *s2_ctx, |
| 1276 | unsigned long addr, |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1277 | unsigned long *table, |
| 1278 | const struct s2tt_walk *wi) |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1279 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1280 | assert(table != NULL); |
| 1281 | assert(wi != NULL); |
| 1282 | assert(wi->index <= S2TTES_PER_S2TT); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1283 | assert(wi->last_level <= S2TT_PAGE_LEVEL); |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1284 | assert(s2_ctx != NULL); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1285 | |
AlexeiFedorov | 56e1a8e | 2023-09-01 17:06:13 +0100 | [diff] [blame] | 1286 | unsigned long i, index = wi->index; |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1287 | long level = wi->last_level; |
| 1288 | unsigned long map_size; |
Shruti Gupta | 0a0d4ee | 2024-04-22 21:37:25 +0100 | [diff] [blame] | 1289 | |
| 1290 | /* cppcheck-suppress misra-c2012-10.6 */ |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1291 | __unused long min_starting_level = (s2_ctx->enable_lpa2 == true) ? |
| 1292 | S2TT_MIN_STARTING_LEVEL_LPA2 : S2TT_MIN_STARTING_LEVEL; |
| 1293 | |
| 1294 | assert(wi->last_level >= min_starting_level); |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1295 | |
| 1296 | /* |
| 1297 | * If the entry for the map_addr is live, |
| 1298 | * return @addr. |
| 1299 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1300 | if (s2tte_is_live(s2_ctx, s2tte_read(&table[index]), level)) { |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1301 | return addr; |
| 1302 | } |
| 1303 | |
| 1304 | /* |
| 1305 | * Align the address DOWN to the map_size, as expected for the @level, |
| 1306 | * so that we can compute the correct address by using the index. |
| 1307 | */ |
| 1308 | map_size = s2tte_map_size(level); |
| 1309 | addr &= ~(map_size - 1UL); |
| 1310 | |
| 1311 | /* Skip the "index" */ |
AlexeiFedorov | 56e1a8e | 2023-09-01 17:06:13 +0100 | [diff] [blame] | 1312 | for (i = index + 1UL; i < S2TTES_PER_S2TT; i++) { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1313 | unsigned long s2tte = s2tte_read(&table[i]); |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1314 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1315 | if (s2tte_is_live(s2_ctx, s2tte, level)) { |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1316 | break; |
| 1317 | } |
| 1318 | } |
| 1319 | |
AlexeiFedorov | 56e1a8e | 2023-09-01 17:06:13 +0100 | [diff] [blame] | 1320 | return (addr + ((i - index) * map_size)); |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1321 | } |