-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsel4_vmm.c
56 lines (43 loc) · 943 Bytes
/
sel4_vmm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright 2022, 2023, 2024, Technology Innovation Institute
*
*/
#include "linux/mm.h"
#include "linux/atomic.h"
#include "linux/types.h"
#include "linux/slab.h"
#include "sel4_virt_drv.h"
static atomic_t id = ATOMIC_INIT(0);
static bool sel4_mem_map_valid(struct sel4_mem_map *mem)
{
if (WARN_ON(IS_ERR_OR_NULL(mem))) {
return false;
}
return (mem->size &&
mem->addr &&
PAGE_ALIGNED(mem->addr));
}
bool sel4_vmm_valid(struct sel4_vmm *vmm)
{
int i;
if (WARN_ON(IS_ERR_OR_NULL(vmm))) {
return false;
}
for (i = 0; i < NUM_SEL4_MEM_MAP; i++) {
if (!sel4_mem_map_valid(&vmm->maps[i]))
return false;
}
return true;
}
struct sel4_vmm *sel4_vmm_alloc(struct sel4_vmm_ops ops)
{
struct sel4_vmm *vmm;
vmm = kzalloc(sizeof(struct sel4_vmm), GFP_KERNEL);
if (!vmm) {
return ERR_PTR(-ENOMEM);
}
vmm->ops = ops;
vmm->id = atomic_inc_return(&id);
return vmm;
}