Commit 6127ef9a authored by Muktesh Khole's avatar Muktesh Khole Committed by Vikram Narayanan
Browse files

lookup_capability implementation

parent f9a246cc
......@@ -70,7 +70,37 @@ cap_id lcd_lookup_free_slot(struct cap_space *cspace, struct cte **cap)
struct cte * lcd_lookup_capability(struct cap_space *cspace, cap_id cid)
{
struct cte *cap;
struct cte *cap = NULL, *cnode = NULL;
cap_id id = cid;
int index = 0;
int mask = (~0);
mask = mask << (CNODE_INDEX_BITS);
mask = ~mask;
// check if input is valid
if (cspace == NULL || cid == 0)
return NULL;
cnode = cspace->root_cnode;
while (id > 0)
{
index = (int)(id) & mask;
id = id >> (CNODE_INDEX_BITS);
if (cnode[index].ctetype == lcd_type_capability && id == 0)
{
cap = &cnode[index];
break;
}
else if (cnode[index].ctetype == lcd_type_cnode && id != 0)
{
cnode = cnode[index].cnode.cap_entry;
}
else
{
break;
}
}
return cap;
}
......@@ -111,7 +141,7 @@ success:
cap_id lcd_create_cap(void * ptcb, void * hobject, lcd_cap_rights crights)
{
struct task_struct *tcb = (struct task_struct *)ptcb;
struct task_struct *tcb = ptcb;
struct cap_space *cspace;
struct cte *cap;
cap_id cid;
......
......@@ -8,18 +8,27 @@
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/kthread.h>
#include <linux/semaphore.h>
#include <linux/log2.h>
#include <linux/delay.h>
#include <asm/page.h>
#include "../../../SeL4/seL4-release-1.2/code/apps/wombat-vmlinux/linux-2.6.38.1/arch/arm/nwfpe/ARM-gcc.h"
MODULE_LICENSE("GPL");
MODULE_AUTHOR ("FLUX-LAB University of Utah");
#define LCD_CAPABILITY
#define MAX_SLOTS (PAGE_SIZE/sizeof(struct cte))
#define CNODE_INDEX_BITS (ilog2(MAX_SLOTS))
typedef uint32_t lcd_cnode; // a pointer to the cnode
typedef uint64_t cap_id ; // a locally unique identifier (address within cspace)
typedef uint32_t lcd_cnode_entry; // a pointer to an entry within a cnode
typedef uint64_t lcd_tcb; // a pointer/handle to the thread contrl block
typedef uint16_t lcd_cap_rights; // holds the rights associated with a capability.
#define MAX_SLOTS (PAGE_SIZE/sizeof(struct cte))
#define CNODE_SLOTS_PER_CNODE 5
#define CNODE_SLOTS_START (MAX_SLOTS - CNODE_SLOTS_PER_CNODE)
#define CNODE_INDEX_BITS (ilog2(MAX_SLOTS))
#define CAP_ID_SIZE (sizeof(cap_id) * 8)
#define MAX_DEPTH ((CAP_ID_SIZE - 1)/CNODE_INDEX_BITS)
#define SAFE_EXIT_IF_ALLOC_FAILED(ptr, label) \
if (ptr == NULL) \
......@@ -52,11 +61,7 @@ enum {
LCD_CapFirstFreeSlot = 6
};
typedef uint32_t lcd_cnode; // a pointer to the cnode
typedef uint64_t cap_id ; // a locally unique identifier (address within cspace)
typedef uint32_t lcd_cnode_entry; // a pointer to an entry within a cnode
typedef uint64_t lcd_tcb; // a pointer/handle to the thread contrl block
typedef uint16_t lcd_cap_rights; // holds the rights associated with a capability.
#define CAPRIGHTS_READ (1 << 0)
#define CAPRIGHTS_WRITE (1 << 1)
......@@ -115,6 +120,28 @@ struct cap_space
/* Helper Functions */
static inline int get_bits_at_level(cap_id id, int level)
{
int bits = 0;
id = id << ((MAX_DEPTH - level - 1) * CNODE_INDEX_BITS);
id = id >> ((MAX_DEPTH - 1) * CNODE_INDEX_BITS);
bits = (int) id;
return bits;
}
static inline void clear_bits_at_level(cap_id *id, int level)
{
cap_id mask = (~0);
// clear all higher order bits.
mask = mask << ((MAX_DEPTH - level - 1) * CNODE_INDEX_BITS);
// clear lower order bits
mask = mask >> ((MAX_DEPTH - 1) * CNODE_INDEX_BITS);
// get the mask to appropriate position
mask = mask << (level * CNODE_INDEX_BITS);
mask = ~mask;
*id = (*id) & mask;
}
// initializes the free slots available in the cnode structure.
void lcd_initialize_freelist(struct cte *cnode, int size, bool bFirstCNode);
......
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