Commit 0018dda0 authored by Charles Jacobsen's avatar Charles Jacobsen Committed by Vikram Narayanan

test-v2: string_example working.

New resource tree design appears to work. glue_example and
liblcd_test work.
parent a17104f3
......@@ -139,17 +139,17 @@ static inline int node_cmp(struct lcd_resource_node *n1,
{
unsigned long left_addr = lcd_resource_node_start(n1);
unsigned long right_addr = lcd_resource_node_start(n2);
unsigned long left_cptr = cptr_val(lcd_resource_node_cptr(n1)),
unsigned long right_cptr = cptr_val(lcd_resource_node_cptr(n2)),
unsigned long left_cptr = cptr_val(lcd_resource_node_cptr(n1));
unsigned long right_cptr = cptr_val(lcd_resource_node_cptr(n2));
/* Sort in dictionary order on (start addr, cptr val) */
if (left_addr < right_addr)
return -1;
if (right_addr < left_addr)
return 1;
if (cptr_val(left_cptr) < cptr_val(right_cptr))
if (left_cptr < right_cptr)
return -1;
if (cptr_val(right_cptr) < cptr_val(left_cptr))
if (left_cptr > right_cptr)
return 1;
return 0; /* equal */
}
......@@ -165,16 +165,16 @@ static inline int overlapping_non_equal_intervals(
struct lcd_resource_node *n2)
{
int ret = in_interval(lcd_resource_node_start(n1),
lcd_resrouce_node_start(n2),
lcd_resrouce_node_last(n2)) ||
lcd_resource_node_start(n2),
lcd_resource_node_last(n2)) ||
in_interval(lcd_resource_node_start(n2),
lcd_resrouce_node_start(n1),
lcd_resrouce_node_last(n2));
lcd_resource_node_start(n1),
lcd_resource_node_last(n1));
if (unlikely(ret))
ret = (lcd_resource_node_start(n1) !=
lcd_resrouce_node_start(n2)) ||
lcd_resource_node_start(n2)) ||
(lcd_resource_node_last(n1) !=
lcd_resrouce_node_last(n2));
lcd_resource_node_last(n2));
return ret;
}
......@@ -184,19 +184,24 @@ void lcd_resource_tree_insert(struct lcd_resource_tree *t,
/*
* This code was adapted from the rbtree documentation.
*/
struct rb_node **new = &(t->root->rb_node), *parent = NULL;
struct rb_node **new = &(t->root.rb_node), *parent = NULL;
/* Figure out where to put new node */
while (*new) {
struct lcd_resource_node *this =
container_of(*new, struct lcd_resource_node, rb_node);
int result;
/* We don't allow overlapping intervals *unless* the intervals
* are identical */
if (unlikely(overlapping_non_equal_intervals(n, this)))
if (unlikely(overlapping_non_equal_intervals(n, this))) {
LIBLCD_ERR("OVERLAPPING INTERVALS:");
lcd_resource_node_dump(n);
lcd_resource_node_dump(this);
BUG();
}
int result = node_cmp(n, this);
result = node_cmp(n, this);
parent = *new;
if (result < 0)
......@@ -212,7 +217,7 @@ void lcd_resource_tree_insert(struct lcd_resource_tree *t,
/* Add new node and rebalance tree. */
rb_link_node(&n->rb_node, parent, new);
rb_insert_color(&n->rb_node, root);
rb_insert_color(&n->rb_node, &t->root);
}
int lcd_resource_tree_search(struct lcd_resource_tree *t,
......@@ -220,7 +225,7 @@ int lcd_resource_tree_search(struct lcd_resource_tree *t,
cptr_t cptr,
struct lcd_resource_node **n_out)
{
struct rb_node *node = t->root->rb_node;
struct rb_node *node = t->root.rb_node;
while (node) {
struct lcd_resource_node *this =
......@@ -245,7 +250,7 @@ int lcd_resource_tree_search_addr(struct lcd_resource_tree *t,
unsigned long addr,
struct lcd_resource_node **n_out)
{
struct rb_node *node = t->root->rb_node;
struct rb_node *node = t->root.rb_node;
while (node) {
struct lcd_resource_node *this =
......@@ -298,6 +303,21 @@ void lcd_resource_tree_remove(struct lcd_resource_tree *t,
rb_erase(&n->rb_node, &t->root);
}
void lcd_resource_node_dump(struct lcd_resource_node *n)
{
printk(" node:\n");
printk(" start: 0x%lx\n",
lcd_resource_node_start(n));
printk(" last: 0x%lx\n",
lcd_resource_node_last(n));
printk(" size: 0x%lx\n",
lcd_resource_node_size(n));
printk(" cptr: 0x%lx\n",
cptr_val(lcd_resource_node_cptr(n)));
printk(" flags: 0x%x\n",
lcd_resource_node_flags(n));
}
void lcd_resource_tree_dump(struct lcd_resource_tree *t)
{
struct lcd_resource_node *cursor;
......@@ -306,17 +326,8 @@ void lcd_resource_tree_dump(struct lcd_resource_tree *t)
cursor = lcd_resource_tree_first(t);
while (cursor) {
printk(" node:\n");
printk(" start: 0x%lx\n",
lcd_resource_node_start(cursor));
printk(" last: 0x%lx\n",
lcd_resource_node_last(cursor));
printk(" size: 0x%lx\n",
lcd_resource_node_size(cursor));
printk(" cptr: 0x%lx\n",
cptr_val(lcd_resource_node_cptr(cursor)));
printk(" flags: 0x%x\n",
lcd_resource_node_flags(cursor));
lcd_resource_node_dump(cursor);
cursor = lcd_resource_tree_next(cursor);
}
......
......@@ -191,5 +191,9 @@ void lcd_resource_tree_remove(struct lcd_resource_tree *t,
* @t: tree to dump
*/
void lcd_resource_tree_dump(struct lcd_resource_tree *t);
/**
* lcd_resource_node_dump -- Print @n to console, for debugging
*/
void lcd_resource_node_dump(struct lcd_resource_node *n);
#endif /* LCD_DOMAINS_RESOURCE_TREE_H */
......@@ -325,8 +325,7 @@ static void do_phys_unmap(struct lcd *lcd, struct lcd_memory_object *mo,
/*
* Remove from resource trees
*/
mo_remove_from_trees(current, mo, cap_cnode_cptr(mo_cnode),
cap_cnode_cptr(mo_cnode));
mo_remove_from_trees(current, mo, cap_cnode_cptr(mo_cnode));
/*
* "Unmap" from physical address space (this is a no-op for
* non-isolated code right now)
......@@ -855,7 +854,7 @@ int lcd_phys_to_resource_node(gpa_t paddr, struct lcd_resource_node **n)
*
* (For vmalloc mem, should use lcd_virt_to_resource_node.)
*/
return lcd_resource_tree_search(
return lcd_resource_tree_search_addr(
current->lcd_resource_trees[LCD_RESOURCE_TREE_CONTIGUOUS],
gpa_val(paddr),
n);
......@@ -895,7 +894,7 @@ int virt_to_resource_node(gva_t vaddr, struct lcd_resource_node **n,
/*
* Look in non-contiguous mem first
*/
ret = lcd_resource_tree_search(
ret = lcd_resource_tree_search_addr(
current->lcd_resource_trees[LCD_RESOURCE_TREE_NON_CONTIGUOUS],
gva_val(vaddr),
n);
......
......@@ -183,8 +183,8 @@ static int add_boot_memory(void)
n = alloc_itree_node();
if (!n)
goto fail1;
n->it_node.start = __liblcd_pa(THIS_MODULE->module_init);
n->it_node.last = n->it_node.start + THIS_MODULE->init_size - 1;
n->start = __liblcd_pa(THIS_MODULE->module_init);
n->last = n->start + THIS_MODULE->init_size - 1;
n->cptr = lcd_get_boot_info()->lcd_boot_cptrs.module_init;
lcd_resource_tree_insert(&itree, n);
/*
......@@ -193,8 +193,8 @@ static int add_boot_memory(void)
n = alloc_itree_node();
if (!n)
goto fail2;
n->it_node.start = __liblcd_pa(THIS_MODULE->module_core);
n->it_node.last = n->it_node.start + THIS_MODULE->core_size - 1;
n->start = __liblcd_pa(THIS_MODULE->module_core);
n->last = n->start + THIS_MODULE->core_size - 1;
n->cptr = lcd_get_boot_info()->lcd_boot_cptrs.module_core;
lcd_resource_tree_insert(&itree, n);
/*
......@@ -203,8 +203,8 @@ static int add_boot_memory(void)
n = alloc_itree_node();
if (!n)
goto fail3;
n->it_node.start = gpa_val(LCD_BOOTSTRAP_PAGES_GP_ADDR);
n->it_node.last = gpa_val(LCD_BOOTSTRAP_PAGES_GP_ADDR) +
n->start = gpa_val(LCD_BOOTSTRAP_PAGES_GP_ADDR);
n->last = gpa_val(LCD_BOOTSTRAP_PAGES_GP_ADDR) +
LCD_BOOTSTRAP_PAGES_SIZE - 1;
n->cptr = lcd_get_boot_info()->lcd_boot_cptrs.boot_pages;
lcd_resource_tree_insert(&itree, n);
......@@ -214,8 +214,8 @@ static int add_boot_memory(void)
n = alloc_itree_node();
if (!n)
goto fail4;
n->it_node.start = gpa_val(LCD_STACK_GP_ADDR);
n->it_node.last = gpa_val(LCD_STACK_GP_ADDR) +
n->start = gpa_val(LCD_STACK_GP_ADDR);
n->last = gpa_val(LCD_STACK_GP_ADDR) +
LCD_STACK_SIZE - 1;
n->cptr = lcd_get_boot_info()->lcd_boot_cptrs.stack;
lcd_resource_tree_insert(&itree, n);
......@@ -225,8 +225,8 @@ static int add_boot_memory(void)
n = alloc_itree_node();
if (!n)
goto fail5;
n->it_node.start = gpa_val(LCD_BOOTSTRAP_PAGE_TABLES_GP_ADDR);
n->it_node.last = gpa_val(LCD_BOOTSTRAP_PAGE_TABLES_GP_ADDR) +
n->start = gpa_val(LCD_BOOTSTRAP_PAGE_TABLES_GP_ADDR);
n->last = gpa_val(LCD_BOOTSTRAP_PAGE_TABLES_GP_ADDR) +
LCD_BOOTSTRAP_PAGE_TABLES_SIZE - 1;
n->cptr = lcd_get_boot_info()->lcd_boot_cptrs.gv;
lcd_resource_tree_insert(&itree, n);
......
......@@ -507,6 +507,7 @@ int __lcd_do_map_memory_object(struct lcd *lcd,
* physical is available to non-isolated code. Recall that
* this function is about mapping in physical, not virtual.)
*/
ret = 0;
break;
default:
LCD_ERR("unrecognized lcd type %d", lcd->type);
......
......@@ -7,11 +7,30 @@
* Copyright: University of Utah
*/
#include <linux/rbtree.h>
#include <linux/interval_tree.h>
#include <linux/interval_tree_generic.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <lcd_domains/microkernel.h>
/* INTERVAL TREE DEFs -------------------------------------------------- */
/*
* The lib/interval_tree.c does not export its functions, so we just
* declare our own here.
*/
#define START(node) ((node)->start)
#define LAST(node) ((node)->last)
INTERVAL_TREE_DEFINE(struct interval_tree_node, rb,
unsigned long, __subtree_last,
START, LAST,, interval_tree)
/* ------------------------------------------------------------ */
static struct lcd_mem_itree lcd_physical_mem_itree;
static struct lcd_mem_itree lcd_vmalloc_mem_itree;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment