-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmu_ranges.c
86 lines (74 loc) · 1.98 KB
/
mmu_ranges.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "pvp.h"
#include "mmu_ranges.h"
#include "mon.h"
mmu_range_t *
mmu_range_alloc(uint32_t base,
uint32_t limit,
gra_t ra,
uint32_t flags)
{
mmu_range_t *r = malloc(sizeof(mmu_range_t));
if (r == NULL) {
ERROR(ERR_NO_MEM, "failed to alloc mmu_range struct for 0x%x-0x%x",
base, limit);
return NULL;
}
r->base = base;
r->limit = limit;
r->ra =ra;
r->flags = flags;
INIT_LIST_HEAD(&r->link);
return r;
}
void
mmu_range_dump(mmu_ranges_t *mmu_ranges)
{
mmu_range_t *mmu_range;
list_for_each_entry(mmu_range, mmu_ranges, link) {
mon_printf(" mmu_range RA 0x%08x-0x%08x -> EA 0x%08x-0x%08x\n",
mmu_range->ra, mmu_range->limit - mmu_range->base +
mmu_range->ra,
mmu_range->base, mmu_range->limit);
}
}
void
mmu_range_add(mmu_ranges_t *mmu_ranges,
uint32_t base,
uint32_t limit,
gra_t ra,
uint32_t flags)
{
mmu_range_t *mmu_range;
mmu_range_t *r = mmu_range_alloc(base, limit, ra, flags);
BUG_ON(r == NULL, "mmu_range alloc");
BUG_ON(base >= limit, "base (0x%x) >= limit (0x%x)",
base, limit);
list_for_each_entry(mmu_range, mmu_ranges, link) {
if (base >= mmu_range->base && limit <= mmu_range->limit) {
BUG_ON ((base - mmu_range->base + mmu_range->ra != ra) ||
flags != mmu_range->flags,
"incompatible overlapping range");
} else {
BUG_ON (limit >= mmu_range->base && base <= mmu_range->limit,
"partially overlapping range");
}
if (mmu_range->base > limit) {
list_add_tail(&r->link, &mmu_range->link);
return;
}
}
list_add_tail(&r->link, mmu_ranges);
}
mmu_range_t *
mmu_range_find(mmu_ranges_t *mmu_ranges,
gea_t ea)
{
mmu_range_t *mmu_range;
list_for_each_entry(mmu_range, mmu_ranges, link) {
if (ea >= mmu_range->base &&
ea <= mmu_range->limit) {
return mmu_range;
}
}
return NULL;
}