13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/rbtree_augmented.h>
16 #include <linux/sched.h>
19 #include <asm/pgtable.h>
41 if (node->
start >= end || node->
end <= start)
47 static u64 get_subtree_max_end(
struct rb_node *node)
59 u64 max_end = data->
end, child_max_end;
61 child_max_end = get_subtree_max_end(data->
rb.rb_right);
62 if (child_max_end > max_end)
63 max_end = child_max_end;
65 child_max_end = get_subtree_max_end(data->
rb.rb_left);
66 if (child_max_end > max_end)
67 max_end = child_max_end;
79 struct rb_node *node = root->rb_node;
85 if (get_subtree_max_end(node->
rb_left) > start) {
88 }
else if (is_node_overlap(data, start, end)) {
91 }
else if (start >= data->
start) {
101 static struct memtype *memtype_rb_exact_match(
struct rb_root *root,
106 match = memtype_rb_lowest_match(root, start, end);
107 while (match !=
NULL && match->
start < end) {
110 if (match->
start == start && match->
end == end)
123 static int memtype_rb_check_conflict(
struct rb_root *root,
125 unsigned long reqtype,
unsigned long *newtype)
129 int found_type = reqtype;
131 match = memtype_rb_lowest_match(&memtype_rbroot, start, end);
135 if (match->
type != found_type && newtype ==
NULL)
139 found_type = match->
type;
145 if (match->
start >= end)
148 if (is_node_overlap(match, start, end) &&
149 match->
type != found_type) {
157 *newtype = found_type;
164 end, cattr_name(found_type), cattr_name(match->
type));
168 static void memtype_rb_insert(
struct rb_root *root,
struct memtype *newdata)
180 node = &((*node)->rb_left);
182 node = &((*node)->rb_right);
186 rb_link_node(&newdata->
rb, parent, node);
187 rb_insert_augmented(&newdata->
rb, root, &memtype_rb_augment_cb);
194 err = memtype_rb_check_conflict(&memtype_rbroot, new->start, new->end,
195 new->type, ret_type);
199 new->type = *ret_type;
201 new->subtree_max_end =
new->end;
202 memtype_rb_insert(&memtype_rbroot,
new);
211 data = memtype_rb_exact_match(&memtype_rbroot, start, end);
215 rb_erase_augmented(&data->
rb, &memtype_rbroot, &memtype_rb_augment_cb);
223 data = memtype_rb_lowest_match(&memtype_rbroot, addr, addr +
PAGE_SIZE);
227 #if defined(CONFIG_DEBUG_FS)
228 int rbt_memtype_copy_nth_element(
struct memtype *
out, loff_t
pos)
234 while (node && pos != i) {