1 /*
2  * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3  *
4  * SPDX-License-Identifier: GPL-2.0-only
5  */
6 
7 #pragma once
8 
9 #include <config.h>
10 #include <types.h>
11 #include <mode/types.h>
12 #include <plat_mode/machine/hardware.h>
13 #include <arch/kernel/tlb_bitmap_defs.h>
14 #include <mode/kernel/vspace.h>
15 
16 #ifdef ENABLE_SMP_SUPPORT
17 
tlb_bitmap_init(vspace_root_t * root)18 static inline void tlb_bitmap_init(vspace_root_t *root)
19 {
20     for (int i = 0; i < TLBBITMAP_ROOT_ENTRIES; i++) {
21         root[TLBBITMAP_ROOT_INDEX + i] = x86_make_empty_root_mapping();
22     }
23 }
24 
tlb_bitmap_set(vspace_root_t * root,word_t cpu)25 static inline void tlb_bitmap_set(vspace_root_t *root, word_t cpu)
26 {
27     assert(cpu < TLBBITMAP_ROOT_BITS && cpu <= wordBits);
28     root[TLBBITMAP_ROOT_MAKE_INDEX(cpu)].words[0] |= TLBBITMAP_ROOT_MAKE_BIT(cpu);
29 }
30 
tlb_bitmap_unset(vspace_root_t * root,word_t cpu)31 static inline void tlb_bitmap_unset(vspace_root_t *root, word_t cpu)
32 {
33     assert(cpu < TLBBITMAP_ROOT_BITS && cpu <= wordBits);
34     root[TLBBITMAP_ROOT_MAKE_INDEX(cpu)].words[0] &= ~TLBBITMAP_ROOT_MAKE_BIT(cpu);
35 }
36 
tlb_bitmap_get(vspace_root_t * root)37 static inline word_t tlb_bitmap_get(vspace_root_t *root)
38 {
39     word_t bitmap = 0;
40 
41     for (int i = 0; i < TLBBITMAP_ROOT_ENTRIES; i++) {
42         word_t entry = root[TLBBITMAP_ROOT_INDEX + i].words[0];
43         // skip present bit
44         entry >>= 1;
45 
46         int shift = i * TLBBITMAP_ENTRIES_PER_ROOT;
47         bitmap |= entry << shift;
48     }
49     return bitmap;
50 }
51 
52 #else
53 #define TLBBITMAP_ROOT_ENTRIES 0
54 #endif /* ENABLE_SMP_SUPPORT */
55 
56