1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the GNU General Public License version 2. Note that NO WARRANTY is provided.
8 * See "LICENSE_GPLv2.txt" for details.
9 *
10 * @TAG(DATA61_GPL)
11 */
12
13#ifndef __ARCH_KERNEL_TLB_BITMAP_H_
14#define __ARCH_KERNEL_TLB_BITMAP_H_
15
16#include <config.h>
17#include <types.h>
18#include <mode/types.h>
19#include <plat_mode/machine/hardware.h>
20#include <arch/kernel/tlb_bitmap_defs.h>
21#include <mode/kernel/vspace.h>
22
23#ifdef ENABLE_SMP_SUPPORT
24
25static inline void
26tlb_bitmap_init(vspace_root_t *root)
27{
28    for (int i = 0; i < TLBBITMAP_ROOT_ENTRIES; i++) {
29        root[TLBBITMAP_ROOT_INDEX + i] = x86_make_empty_root_mapping();
30    }
31}
32
33static inline void
34tlb_bitmap_set(vspace_root_t *root, word_t cpu)
35{
36    assert(cpu < TLBBITMAP_ROOT_BITS && cpu <= wordBits);
37    root[TLBBITMAP_ROOT_MAKE_INDEX(cpu)].words[0] |= TLBBITMAP_ROOT_MAKE_BIT(cpu);
38}
39
40static inline void
41tlb_bitmap_unset(vspace_root_t *root, word_t cpu)
42{
43    assert(cpu < TLBBITMAP_ROOT_BITS && cpu <= wordBits);
44    root[TLBBITMAP_ROOT_MAKE_INDEX(cpu)].words[0] &= ~TLBBITMAP_ROOT_MAKE_BIT(cpu);
45}
46
47static inline word_t
48tlb_bitmap_get(vspace_root_t *root)
49{
50    word_t bitmap = 0;
51
52    for (int i = 0; i < TLBBITMAP_ROOT_ENTRIES; i++) {
53        word_t entry = root[TLBBITMAP_ROOT_INDEX + i].words[0];
54        // skip present bit
55        entry >>= 1;
56
57        int shift = i * TLBBITMAP_ENTRIES_PER_ROOT;
58        bitmap |= entry << shift;
59    }
60    return bitmap;
61}
62
63#else
64#define TLBBITMAP_ROOT_ENTRIES 0
65#endif /* ENABLE_SMP_SUPPORT */
66
67#endif /* __ARCH_KERNEL_TLB_BITMAP_H_ */
68