Commit ea133a9d authored by Anton Burtsev's avatar Anton Burtsev Committed by Vikram Narayanan

Create LCD code inside LCD API layer

 -- Still need an actual function to load the module into LCD
parent d3811abf
......@@ -25,10 +25,16 @@ MODULE_DESCRIPTION("LCD client-server test launcher");
static int __init cslaunch_init(void)
{
capability_t boot_caps[3];
capability_t shared_rvp = 2;
capability_t client_lcd_cap = 3;
capability_t server_lcd_cap = 4;
boot_caps[0] = lcd_api_cap();
boot_caps[1] = lcd_api_reply_cap();
boot_caps[2] = shared_rvp;
ret = lcd_init_current();
if (ret) {
printk(KERN_ERR "Failed to init current thread with LCD:%d\n", ret);
......@@ -41,19 +47,18 @@ static int __init cslaunch_init(void)
return -ENOSPC;
};
ret = lcd_api_create_lcd("cs-client", &shared_rvp, 1, client_lcd_cap);
ret = lcd_api_create_lcd("cs-client", &boot_caps, 3, client_lcd_cap);
if(ret) {
printk(KERN_ERR "Failed to create client LCD\n");
return -ENOSPC;
};
ret = lcd_api_create_lcd("cs-server", &shared_rvp, 1, server_lcd_cap);
ret = lcd_api_create_lcd("cs-server", &boot_caps, 3, server_lcd_cap);
if(ret) {
printk(KERN_ERR "Failed to create server LCD\n");
return -ENOSPC;
};
return;
}
......
......@@ -111,5 +111,6 @@ int lcd_enter(void);
int lcd_api_connect(struct lcd_api *api);
struct lcd_api *lcd_get_api(void);
int lcd_init_current(void);
struct task_struct *lcd_create_as_module(char *name);
#endif /* LCD_LCD_H */
......@@ -10,14 +10,14 @@
#include <linux/sched.h>
#include <linux/kthread.h>
int lcd_api_create_sync_endpoint(struct lcd_api *api, capability_t reply_cap) {
int lcd_api_create_sync_endpoint(struct message_info *msg, struct lcd_api *api, capability_t reply_cap) {
int ret;
struct sync_ipc *rvp;
capability_t rvp_cap;
struct cnode *cnode;
struct message_info *msg = &current->utcb->msg_info;
rvp = alloc_sync_ipc();
rvp = lcd_create_sync_ep();
if(!rvp) {
printk(KERN_ERR "Failed to allocate memory\n");
ret = -ENOMEM;
......@@ -34,17 +34,91 @@ int lcd_api_create_sync_endpoint(struct lcd_api *api, capability_t reply_cap) {
ret = lcd_cap_insert_object(&current->cspace, rvp_cap, rvp, LCD_TYPE_SYNC_EP);
if(cnode == 0) {
kfree(rvp);
lcd_destroy_rvp(rvp);
goto err;
};
msg->cap_regs[0] = free_cap;
msg->cap_regs[0] = rvp_cap;
msg->valid_cap_regs = 1;
ipc_reply(reply_cap, msg);
lcd_cap_drop(&current->cspace, free_cap);
lcd_cap_drop(&current->cspace, rvp_cap);
lcd_free_cap(&current->cap_cache, free_cap);
lcd_free_cap(&current->cap_cache, rvp_cap);
return 0;
err:
msg->err = ret;
ipc_reply(reply_cap, msg);
return ret;
};
int lcd_api_create_lcd(struct message_info *msg, struct lcd_api *api, capability_t reply_cap) {
int ret;
int i;
capability_t lcd_cap;
struct cnode *cnode;
char *module_name;
module_name = lcd_cap_marshal_string(&msg->regs[1], LCD_MAX_REGS - 1);
if (!module_name) {
printk(KERN_ERR "Failed to unmarshal LCD name\n");
ret = -EINVAL;
goto err;
};
lcd_task = lcd_create_as_module(module_name);
if(!lcd_task) {
printk(KERN_ERR "Failed to create LCD from a module:%s\n", module_name);
ret = -ENOMEM;
goto err;
};
ret = lcd_alloc_cap(&current->cap_cache, &lcd_cap);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
ret = -ENOSPC;
lcd_destroy(lcd_task);
goto err;
};
ret = lcd_cap_insert_object(&current->cspace, lcd_cap, lcd_task, LCD_TYPE_LCD);
if(cnode == 0) {
lcd_destroy(lcd_task);
goto err;
};
for (int i = 0; i < cap_regs - 2; i++) {
capability_t boot_cap;
ret = lcd_alloc_cap(&lcd_task->cap_cache, &boot_cap);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
ret = -ENOSPC;
lcd_destroy(lcd_task);
goto err;
};
ret = lcd_cap_move_object(&lcd_task->cspace, boot_cap, &current->cspace, msg->cap_regs[i]);
if(ret) {
printk(KERN_ERR "Failed to move boot capability number:d\n", i);
ret = -ENOSPC;
lcd_destroy(lcd_task);
goto err;
};
lcd_task->utcb->boot_info.boot_caps[i] = boot_cap;
lcd_drop_cap(&current->cspace, msg->cap_regs[i]);
};
msg->cap_regs[0] = lcd_cap;
msg->valid_cap_regs = 1;
ipc_reply(reply_cap, msg);
lcd_cap_drop(&current->cspace, lcd_cap);
lcd_free_cap(&current->cap_cache, lcd_cap);
return 0;
err:
msg->err = ret;
......@@ -57,11 +131,16 @@ int lcd_api_execution_loop(struct lcd_api *lcd_api) {
capability_t reply_cap;
enum lcd_api_calls call;
int ret;
int i;
ret = lcd_alloc_cap(&current->cap_cache, &reply_cap);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
return -ENOSPC;
for (i = 0; i < LCD_MAX_CAP_REGS; i++) {
ret = lcd_alloc_cap(&current->cap_cache,
&msg->cap_regs[i]);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
return -ENOSPC;
};
};
while (!lcd_api->exit_flag)
......@@ -73,6 +152,8 @@ int lcd_api_execution_loop(struct lcd_api *lcd_api) {
continue;
}
reply_cap = msg->cap_regs[msg->valid_cap_regs];
// We know we're serving a call invocation, reply cap is
// verified by the ipc_call()
......@@ -89,10 +170,10 @@ int lcd_api_execution_loop(struct lcd_api *lcd_api) {
switch (call) {
case LCD_CREATE_SYNC_ENDPOINT:
ret = lcd_api_create_sync_endpoint(lcd_api, reply_cap);
ret = lcd_api_create_sync_endpoint(msg, lcd_api, reply_cap);
break;
case LCD_CREATE_LCD:
ret = lcd_api_create_sync_endpoint(lcd_api, reply_cap);
ret = lcd_api_create_lcd(msg, lcd_api, reply_cap);
break;
default:
......@@ -105,7 +186,10 @@ int lcd_api_execution_loop(struct lcd_api *lcd_api) {
};
lcd_free_cap(&current->cap_cache, reply_cap);
for (i = 0; i < LCD_MAX_CAP_REGS; i++) {
ret = lcd_free_cap(&current->cap_cache, msg->cap_regs[i]);
};
return 0;
};
......
......@@ -110,7 +110,12 @@ int lcd_init_current(void) {
return 0;
};
EXPORT_SYMBOL(lcd_init_current);
EXPORT_SYMBOL(lcd_init_current);
struct task_struct *lcd_create_as_module(char *name) {
return NULL;
};
static long lcd_dev_ioctl(struct file *filp ,
unsigned int ioctl, unsigned long arg)
......
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