Commit 55947eac authored by Vikram Narayanan's avatar Vikram Narayanan
Browse files

lcds/foobar: Make foobar test_module compile

There is still some work left to make this runnable.
parent 80e14624
#ifndef _FOOBAR_DEVICE_H
#define _FOOBAR_DEVICE_H
#include <linux/types.h>
typedef u64 foobar_features_t;
/* features */
......
......@@ -27,3 +27,4 @@ obj-m += llvm_example/
obj-m += ioremap/
obj-m += ixgbe/
obj-m += nullnet/
obj-m += foobar/
......@@ -57,3 +57,7 @@ ixgbe/net_klcd nonisolated
nullnet/boot nonisolated
nullnet/dummy_lcd isolated
nullnet/net_klcd nonisolated
foobar/boot nonisolated
foobar/dummy_lcd isolated
foobar/foobar_klcd nonisolated
/*
* boot.c - non-isolated kernel module, does setup
* when fake minix and vfs are to be launched
* in isolated containers
*/
#include <lcd_config/pre_hook.h>
#include <liblcd/liblcd.h>
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kmod.h>
#include "../foobar_glue_helper.h"
#include <lcd_config/post_hook.h>
cptr_t foobar_klcd, dummy_lcd;
struct lcd_create_ctx *dummy_ctx;
cptr_t net_chnl;
cptr_t net_chnl_domain_cptr, dummy_chnl_domain_cptr;
static int boot_main(void)
{
int ret;
/*
* Enter lcd mode
*/
ret = lcd_enter();
if (ret) {
LIBLCD_ERR("lcd enter failed");
goto fail1;
}
/* ---------- Create vfs channel ---------- */
ret = lcd_create_sync_endpoint(&net_chnl);
if (ret) {
LIBLCD_ERR("lcd create sync endpoint");
goto fail2;
}
/* ---------- Create LCDs ---------- */
ret = lcd_create_module_klcd(LCD_DIR("foobar/foobar_klcd"),
"lcd_test_mod_foobar_foobar_klcd",
&foobar_klcd);
if (ret) {
LIBLCD_ERR("failed to create net klcd");
goto fail3;
}
ret = lcd_create_module_lcd(LCD_DIR("foobar/dummy_lcd"),
"lcd_test_mod_foobar_dummy_lcd",
&dummy_lcd,
&dummy_ctx);
if (ret) {
LIBLCD_ERR("failed to create dummy lcd");
goto fail4;
}
ret = cptr_alloc(lcd_to_boot_cptr_cache(dummy_ctx),
&dummy_chnl_domain_cptr);
if (ret) {
LIBLCD_ERR("alloc cptr");
goto fail5;
}
ret = lcd_cap_grant(dummy_lcd, net_chnl, dummy_chnl_domain_cptr);
if (ret) {
LIBLCD_ERR("grant");
goto fail6;
}
/* ---------- Set up boot info ---------- */
// HACK: But WTF is this?
net_chnl_domain_cptr = __cptr(3);
ret = lcd_cap_grant(foobar_klcd, net_chnl, net_chnl_domain_cptr);
if (ret) {
LIBLCD_ERR("grant");
goto fail7;
}
lcd_to_boot_info(dummy_ctx)->cptrs[0] = dummy_chnl_domain_cptr;
/* ---------- RUN! ---------- */
LIBLCD_MSG("starting foobar subsystem...");
ret = lcd_run(foobar_klcd);
if (ret) {
LIBLCD_ERR("failed to start foobar klcd");
goto fail8;
}
LIBLCD_MSG("starting dummy foobar device...");
ret = lcd_run(dummy_lcd);
if (ret) {
LIBLCD_ERR("failed to start dummy lcd");
goto fail9;
}
/*
* Wait for 4 seconds
*/
//msleep(100000);
/*
* Tear everything down
*/
ret = 0;
// return
goto fail1;
/* The destroy's will free up everything ... */
fail9:
fail8:
fail7:
lcd_cap_delete(dummy_lcd);
lcd_destroy_create_ctx(dummy_ctx);
fail6:
fail5:
fail4:
//lcd_cap_delete(foobar_klcd);
lcd_destroy_module_klcd(foobar_klcd, "lcd_test_mod_foobar_foobar_klcd");
fail3:
fail2:
lcd_exit(0); /* will free endpoints */
fail1:
return ret;
}
static DECLARE_WAIT_QUEUE_HEAD(wq);
static int shutdown = 0;
int boot_lcd_thread(void *data)
{
static unsigned once = 0;
int ret;
while (!kthread_should_stop()) {
if (!once) {
LCD_MAIN({
ret = boot_main();
});
}
once = 1;
wait_event_interruptible(wq, shutdown != 0);
}
msleep(2000);
LIBLCD_MSG("Exiting thread");
lcd_destroy_module_klcd(foobar_klcd,
"lcd_test_mod_foobar_foobar_klcd");
if (current->lcd)
lcd_cap_delete(dummy_lcd);
if (dummy_ctx)
lcd_destroy_create_ctx(dummy_ctx);
lcd_exit(0);
return 0;
}
struct task_struct *boot_task;
static int boot_init(void)
{
LIBLCD_MSG("%s: entering", __func__);
boot_task = kthread_create(boot_lcd_thread, NULL, "boot_lcd_thread");
if (!IS_ERR(boot_task))
wake_up_process(boot_task);
return 0;
}
static void boot_exit(void)
{
/* nothing to do */
if (!IS_ERR(boot_task)) {
LIBLCD_MSG("%s: exiting", __func__);
shutdown = 1;
wake_up_interruptible(&wq);
kthread_stop(boot_task);
}
}
module_init(boot_init);
module_exit(boot_exit);
MODULE_LICENSE("GPL");
......@@ -12,7 +12,7 @@ lcd_test_mod_foobar_dummy_lcd-y += $(LIBLCD)
lcd_test_mod_foobar_dummy_lcd-y += $(addprefix glue/, foobar_caller.o \
foobar_caller_dispatch.o )
lcd_test_mod_foobar_dummy_lcd-y += $(addprefix ../, foobar_cap.o)
lcd_test_mod_foobar_dummy_lcd-y += $(addprefix ../, foobar_glue_helper.o)
ccflags-y += $(ISOLATED_CFLAGS)
#ifndef __FOOBAR_CALLER_H__
#define __FOOBAR_CALLER_H__
#include "../foobar_glue_helper.h"
void dispatch_sync_loop(void);
int dispatch_async_loop(struct thc_channel *_channel,
struct fipc_message *message,
......@@ -16,3 +18,5 @@ int uninit_callee(struct fipc_message *_request,
struct thc_channel *_channel,
struct glue_cspace *cspace,
struct cptr sync_ep);
#endif
#include "../foobar_caller.h"
static struct cptr c;
__maybe_unused static struct cptr c;
static struct glue_cspace *c_cspace;
static struct lcd_sync_channel_group *foobar_group;
extern struct thc_channel *foobar_async;
__maybe_unused static struct lcd_sync_channel_group *foobar_group;
int dummy_dev_init(struct foobar_device *dev);
void dummy_dev_uninit(struct foobar_device *dev);
int glue_foobar_init(void)
{
int ret;
......@@ -36,7 +42,7 @@ int register_foobar(struct foobar_device *dev)
struct fipc_message *_request;
struct fipc_message *_response;
int func_ret;
ret = async_msg_blocking_send_start(net_async,
ret = async_msg_blocking_send_start(foobar_async,
&_request);
if (ret) {
LIBLCD_ERR("failed to get a send slot");
......@@ -44,13 +50,13 @@ int register_foobar(struct foobar_device *dev)
}
async_msg_set_fn_type(_request,
REGISTER_FOOBAR);
fipc_set_reg5(_request,
fipc_set_reg4(_request,
dev->features);
fipc_set_reg6(_request,
fipc_set_reg5(_request,
dev->hw_features);
fipc_set_reg7(_request,
fipc_set_reg6(_request,
dev->flags);
ret = thc_ipc_call(net_async,
ret = thc_ipc_call(foobar_async,
_request,
&_response);
if (ret) {
......@@ -58,12 +64,12 @@ int register_foobar(struct foobar_device *dev)
goto fail_ipc;
}
func_ret = fipc_get_reg1(_response);
fipc_recv_msg_end(thc_channel_to_fipc(net_async),
fipc_recv_msg_end(thc_channel_to_fipc(foobar_async),
_response);
return func_ret;
fail_async:
fail_ipc:
return ret;
}
void unregister_foobar(struct foobar_device *dev)
......@@ -71,7 +77,7 @@ void unregister_foobar(struct foobar_device *dev)
int ret;
struct fipc_message *_request;
struct fipc_message *_response;
ret = async_msg_blocking_send_start(net_async,
ret = async_msg_blocking_send_start(foobar_async,
&_request);
if (ret) {
LIBLCD_ERR("failed to get a send slot");
......@@ -79,35 +85,36 @@ void unregister_foobar(struct foobar_device *dev)
}
async_msg_set_fn_type(_request,
UNREGISTER_FOOBAR);
ret = thc_ipc_call(net_async,
ret = thc_ipc_call(foobar_async,
_request,
&_response);
if (ret) {
LIBLCD_ERR("thc_ipc_call");
goto fail_ipc;
}
fipc_recv_msg_end(thc_channel_to_fipc(net_async),
fipc_recv_msg_end(thc_channel_to_fipc(foobar_async),
_response);
return;
fail_async:
fail_ipc:
return;
}
struct foobar_device *alloc_foobardev(int idsd,
char *name)
struct foobar_device *alloc_foobardev(int id,
const char *name)
{
struct foobar_device_container *func_ret_container;
int ret;
struct fipc_message *_request;
struct fipc_message *_response;
struct foobar_device *func_ret;
struct foobar_device *func_ret = NULL;
func_ret_container = kzalloc(sizeof( struct foobar_device_container ),
GFP_KERNEL);
if (!func_ret_container) {
LIBLCD_ERR("kzalloc");
goto fail_alloc;
}
func_ret = &func_ret_container->foobar_device;
ret = glue_cap_insert_foobar_device_type(c_cspace,
func_ret_container,
&func_ret_container->my_ref);
......@@ -115,7 +122,7 @@ struct foobar_device *alloc_foobardev(int idsd,
LIBLCD_ERR("lcd insert");
goto fail_insert;
}
ret = async_msg_blocking_send_start(net_async,
ret = async_msg_blocking_send_start(foobar_async,
&_request);
if (ret) {
LIBLCD_ERR("failed to get a send slot");
......@@ -124,29 +131,31 @@ struct foobar_device *alloc_foobardev(int idsd,
async_msg_set_fn_type(_request,
ALLOC_FOOBARDEV);
fipc_set_reg1(_request,
idsd);
fipc_set_reg2(_request,
name);
id);
// fipc_set_reg2(_request,
// name);
fipc_set_reg4(_request,
func_ret_container->my_ref.cptr);
fipc_set_reg5(_request,
func_ret->id);
fipc_set_reg6(_request,
func_ret->name);
ret = thc_ipc_call(net_async,
// fipc_set_reg5(_request,
// func_ret->id);
// fipc_set_reg6(_request,
// func_ret->name);
ret = thc_ipc_call(foobar_async,
_request,
&_response);
if (ret) {
LIBLCD_ERR("thc_ipc_call");
goto fail_ipc;
}
func_ret_container->other_ref.cptr = fipc_get_reg7(_response);
fipc_recv_msg_end(thc_channel_to_fipc(net_async),
func_ret_container->other_ref.cptr = fipc_get_reg2(_response);
fipc_recv_msg_end(thc_channel_to_fipc(foobar_async),
_response);
return func_ret;
fail_alloc:
fail_insert:
fail_async:
fail_ipc:
return func_ret;
}
void free_foobardev(struct foobar_device *dev)
......@@ -154,7 +163,7 @@ void free_foobardev(struct foobar_device *dev)
int ret;
struct fipc_message *_request;
struct fipc_message *_response;
ret = async_msg_blocking_send_start(net_async,
ret = async_msg_blocking_send_start(foobar_async,
&_request);
if (ret) {
LIBLCD_ERR("failed to get a send slot");
......@@ -162,47 +171,19 @@ void free_foobardev(struct foobar_device *dev)
}
async_msg_set_fn_type(_request,
FREE_FOOBARDEV);
ret = thc_ipc_call(net_async,
ret = thc_ipc_call(foobar_async,
_request,
&_response);
if (ret) {
LIBLCD_ERR("thc_ipc_call");
goto fail_ipc;
}
fipc_recv_msg_end(thc_channel_to_fipc(net_async),
fipc_recv_msg_end(thc_channel_to_fipc(foobar_async),
_response);
return;
fail_async:
fail_ipc:
}
void free_foobardev(struct foobar_device *dev)
{
int ret;
struct fipc_message *_request;
struct fipc_message *_response;
ret = async_msg_blocking_send_start(net_async,
&_request);
if (ret) {
LIBLCD_ERR("failed to get a send slot");
goto fail_async;
}
async_msg_set_fn_type(_request,
FREE_FOOBARDEV);
ret = thc_ipc_call(net_async,
_request,
&_response);
if (ret) {
LIBLCD_ERR("thc_ipc_call");
goto fail_ipc;
}
fipc_recv_msg_end(thc_channel_to_fipc(net_async),
_response);
return;
fail_async:
fail_ipc:
}
int init_callee(struct fipc_message *_request,
......@@ -224,7 +205,7 @@ int init_callee(struct fipc_message *_request,
LIBLCD_ERR("kzalloc");
goto fail_alloc;
}
func_ret = init(dev);
func_ret = dummy_dev_init(dev);
if (async_msg_blocking_send_start(_channel,
&_response)) {
LIBLCD_ERR("error getting response msg");
......@@ -235,8 +216,8 @@ int init_callee(struct fipc_message *_request,
thc_ipc_reply(_channel,
request_cookie,
_response);
fail_alloc:
return ret;
}
int uninit_callee(struct fipc_message *_request,
......@@ -257,7 +238,7 @@ int uninit_callee(struct fipc_message *_request,
LIBLCD_ERR("kzalloc");
goto fail_alloc;
}
uninit(dev);
dummy_dev_uninit(dev);
if (async_msg_blocking_send_start(_channel,
&_response)) {
LIBLCD_ERR("error getting response msg");
......@@ -266,7 +247,6 @@ int uninit_callee(struct fipc_message *_request,
thc_ipc_reply(_channel,
request_cookie,
_response);
fail_alloc:
return ret;
}
......@@ -2,6 +2,9 @@
#include <liblcd/liblcd.h>
#include "../foobar_caller.h"
#include <lcd_config/post_hook.h>
#define trace(x) LIBLCD_MSG(#x)
int dispatch_async_loop(struct thc_channel *_channel,
struct fipc_message *message,
struct glue_cspace *cspace,
......
#include <lcd_config/pre_hook.h>
#include <libcap.h>
#include <liblcd/liblcd.h>
#include <linux/slab.h>
#include "foobar_glue_helper.h"
#include <lcd_config/post_hook.h>
/* ------------------------------------------------------------ */
static struct cap_type_system *glue_libcap_type_system;
struct type_ops_id {
struct cap_type_ops ops;
cap_type_t libcap_type;
};
enum glue_type {
GLUE_TYPE_FOOBAR_DEVICE_CONTAINER,
GLUE_TYPE_FOOBAR_DEVICE_OPS_REGISTER_FOOBAR_CONTAINER,
GLUE_TYPE_FOOBAR_DEVICE_OPS_CONTAINER,
GLUE_NR_TYPES,
};
static int dummy_func(struct cspace *cspace, struct cnode *cnode,
void *object)
{
return 0;
}
static struct type_ops_id glue_libcap_type_ops[GLUE_NR_TYPES] = {
{
{
.name = "struct foobar_device",
.delete = dummy_func,
.revoke = dummy_func,
}
},
{
{
.name = "struct foobar_device_ops",
.delete = dummy_func,
.revoke = dummy_func,
}
},
};
int glue_cap_init(void)
{
int ret;
int i;
cap_type_t libcap_type;
/*
* Alloc and init microkernel type system
*/
ret = cap_type_system_alloc(&glue_libcap_type_system);
if (ret) {
LIBLCD_ERR("alloc glue type system failed");
goto fail1;
}
ret = cap_type_system_init(glue_libcap_type_system);
if (ret) {
LIBLCD_ERR("init glue type system failed");
goto fail2;
}
/*
* Add types
*/
for (i = 0; i < GLUE_NR_TYPES; i++) {
libcap_type = cap_register_private_type(
glue_libcap_type_system,
0,
&glue_libcap_type_ops[i].ops);
if (libcap_type == CAP_TYPE_ERR) {
LIBLCD_ERR("failed to register glue cap type %s",
glue_libcap_type_ops[i].ops.name);
ret = -EIO;
goto fail3;
}
glue_libcap_type_ops[i].libcap_type = libcap_type;
}
return 0;
fail3:
cap_type_system_destroy(glue_libcap_type_system);
fail2:
cap_type_system_free(glue_libcap_type_system);
glue_libcap_type_system = NULL;
fail1:
return ret;
}
int glue_cap_create(struct glue_cspace **cspace_out)
{
return glue_cspace_alloc_init(glue_libcap_type_system, cspace_out);
}
void glue_cap_destroy(struct glue_cspace *cspace)
{
glue_cspace_destroy_free(cspace);
}
void glue_cap_exit(void)
{
/*
* Destroy and free type system if necessary