cap.h 2.19 KB
Newer Older
1 2 3
/* Author: Anton Burtsev
 * Copyright: University of Utah */

4 5 6 7
#ifndef __LCD_CAP_H__
#define __LCD_CAP_H__

#include <linux/types.h>
8
#include <linux/spinlock.h>
root's avatar
root committed
9
#include "cap-cache.h"
10

11
#include <uapi/linux/lcd-cap.h>
Anton Burtsev's avatar
Anton Burtsev committed
12

root's avatar
root committed
13 14 15 16 17 18 19 20 21 22 23 24
#define LCD_MAX_CAPS 32

#define CAP_IDENTIFIER_BITS 2
#define TABLE_IDENTIFIER_BITS 1

// should always be 2^CAP_IDENTIFIER_BITS
#define MAX_CAP_SLOTS 4	
// should always be 2^TABLE_IDENTIFIER_BITS
#define MAX_TABLE_ID_SLOTS 2
// should always be 2^CAP_IDENTIFIER_BITS + 2^TABLE_IDENTIFIER_BITS
#define MAX_SLOTS_PER_TABLE 6

Muktesh Khole's avatar
Muktesh Khole committed
25
struct cdt_root_node;
root's avatar
root committed
26 27 28
struct cnode;
struct cspace;

Muktesh Khole's avatar
Muktesh Khole committed
29 30 31
extern struct cdt_root_node * get_cdt_root(void);
extern void free_cdt_root(struct cdt_root_node *cdt_node);

32
enum lcd_cap_type
33
{
root's avatar
root committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
	LCD_CAP_TYPE_INVALID,
	LCD_CAP_TYPE_FREE,
	LCD_CAP_TYPE_SYNC_EP,
	LCD_CAP_TYPE_CNODE
};

enum allocation_state {
	ALLOCATION_INVALID,
	ALLOCATION_VALID,
	ALLOCATION_MARKED_FOR_DELETE,
	ALLOCATION_REMOVED
};

struct cdt_root_node {
	spinlock_t lock;
	struct cnode *cnode;
	unsigned long node_count;
	enum allocation_state state;
52 53
};

54 55 56
struct cnode {
	enum lcd_cap_type type;
	void *object;
root's avatar
root committed
57 58 59
	spinlock_t lock;
	struct cdt_root_node *cdt_root;
	struct cnode *parent, *child, *prev, *next;
Muktesh Khole's avatar
Muktesh Khole committed
60
	capability_t cap;
root's avatar
root committed
61 62 63 64 65 66
	struct cspace *cspace;
};

struct cnode_table {
	struct cnode cnode[MAX_SLOTS_PER_TABLE];
	uint8_t table_level;
67 68
};

69 70
struct cspace {
	spinlock_t lock; 
root's avatar
root committed
71 72 73 74
	enum allocation_state state;
	struct cnode_table *cnode_table;
	struct kmem_cache *cnode_table_cache;
	struct cap_cache cap_cache;
75 76
};

root's avatar
root committed
77
bool _get_level_bits(int table_level, capability_t cap, capability_t *levelId);
Muktesh Khole's avatar
Muktesh Khole committed
78
bool _lcd_delete_node (struct cnode *cnode);
Muktesh Khole's avatar
Muktesh Khole committed
79
int _lcd_delete_table(struct cspace *cspace, struct cnode_table *table);
80

root's avatar
root committed
81 82 83 84 85
int lcd_cap_init_cspace(struct cspace *cspace);
struct cnode *lcd_cnode_lookup(struct cspace *cspace, capability_t cap, bool alloc);
int lcd_cap_insert(struct cspace *cspace, capability_t cap, 
		void *object, enum lcd_cap_type type);
void lcd_cap_delete(struct cspace *cspace, capability_t cap);
86
int lcd_cap_grant(struct cspace *cspacesrc, capability_t capsrc, struct cspace *cspacedst, capability_t capdst);
Muktesh Khole's avatar
Muktesh Khole committed
87
int lcd_cap_revoke(struct cspace *cspace, capability_t cap);
Muktesh Khole's avatar
Muktesh Khole committed
88
int lcd_cap_destroy_cspace(struct cspace *cspace);
89
#endif