Commit 4d1243ca authored by Vikram Narayanan's avatar Vikram Narayanan
Browse files

lcds/foobar: Add missing driver and main files

parent 55947eac
/* dummy.c: a dummy foobar driver */
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/foobar_device.h>
#include <linux/init.h>
#include <linux/moduleparam.h>
#include <linux/slab.h>
#define DRV_NAME "foobardummy"
#define DRV_VERSION "1.0"
int dummy_dev_init(struct foobar_device *dev)
{
dev->dstats = kmalloc(sizeof(struct foo_stats), GFP_KERNEL);
if (!dev->dstats)
return -ENOMEM;
return 0;
}
void dummy_dev_uninit(struct foobar_device *dev)
{
kfree(dev->dstats);
}
static const struct foobar_device_ops dummy_foobardev_ops = {
.init = dummy_dev_init,
.uninit = dummy_dev_uninit,
};
int numdummies = 0;
/* Number of dummy devices to be set up by this module. */
module_param(numdummies, int, 0);
MODULE_PARM_DESC(numdummies, "Number of dummy pseudo devices");
struct foobar_device *dev_dummy;
int dummy_init_module(void)// the entry point to the dummy device driver
{
int err;
dev_dummy = alloc_foobardev(0, "dummy0");
if (!dev_dummy)
return -ENOMEM;
dev_dummy->foobardev_ops = &dummy_foobardev_ops;
dev_dummy->features = FOOBAR_PRIV_ALLOC;
dev_dummy->flags = FOO_LOOPBACK;
err = register_foobar(dev_dummy);//the call to dev.c fn to register dummy
if (err < 0)
goto err;
return 0;
err:
free_foobardev(dev_dummy);// free the foobar device if an error code is received
return err;
}
void dummy_cleanup_module(void)
{
unregister_foobar(dev_dummy);
}
#ifndef LCD_ISOLATE
module_init(dummy_init_module);
module_exit(dummy_cleanup_module);
MODULE_LICENSE("GPL");
MODULE_VERSION(DRV_VERSION);
#endif
#include "../foobar_caller.h"
__maybe_unused static struct cptr c;
static struct glue_cspace *c_cspace;
struct glue_cspace *foobar_cspace;
extern struct thc_channel *foobar_async;
__maybe_unused static struct lcd_sync_channel_group *foobar_group;
extern struct lcd_sync_channel_group *ch_grp;
int dummy_dev_init(struct foobar_device *dev);
void dummy_dev_uninit(struct foobar_device *dev);
......@@ -16,7 +16,7 @@ int glue_foobar_init(void)
LIBLCD_ERR("cap init");
goto fail1;
}
ret = glue_cap_create(&c_cspace);
ret = glue_cap_create(&foobar_cspace);
if (ret) {
LIBLCD_ERR("cap create");
goto fail2;
......@@ -31,7 +31,7 @@ fail1:
void glue_foobar_exit(void)
{
glue_cap_destroy(c_cspace);
glue_cap_destroy(foobar_cspace);
glue_cap_exit();
}
......@@ -115,7 +115,7 @@ struct foobar_device *alloc_foobardev(int id,
goto fail_alloc;
}
func_ret = &func_ret_container->foobar_device;
ret = glue_cap_insert_foobar_device_type(c_cspace,
ret = glue_cap_insert_foobar_device_type(foobar_cspace,
func_ret_container,
&func_ret_container->my_ref);
if (ret) {
......
/*
* main.c - runs when dummy lcd boots
*/
#include <lcd_config/pre_hook.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <liblcd/liblcd.h>
#include <liblcd/sync_ipc_poll.h>
#include "./foobar_caller.h"
#include <lcd_config/post_hook.h>
cptr_t foobar_register_channel;
struct thc_channel *foobar_async;
extern struct glue_cspace *foobar_cspace;
cptr_t foobar_sync_endpoint;
int dummy_done = 0;
int dummy_init_module(void);
void dummy_cleanup_module(void);
struct thc_channel_group ch_grp;
static void main_and_loop(void)
{
int ret;
int stop = 0;
struct fipc_message *msg;
DO_FINISH(
ASYNC(
ret = dummy_init_module();
if (ret) {
LIBLCD_ERR("dummy register failed");
stop = 1;
} else {
LIBLCD_MSG("SUCCESSFULLY REGISTERED DUMMY!");
}
);
/* By the time we hit this loop, the async channel
* will be set up (the awe running init_dummy_fs above
* will not yield until it tries to use the async
* channel). */
while (!stop && !dummy_done) {
struct thc_channel_group_item* curr_item;
/*
* Do one async receive
*/
ret = thc_poll_recv_group(&ch_grp, &curr_item, &msg);
if (likely(ret)) {
if (ret == -EWOULDBLOCK) {
cpu_relax();
continue;
} else {
LIBLCD_ERR("async recv failed");
stop = 1; /* stop */
}
}
ASYNC(
ret = dispatch_async_loop(curr_item->channel,
msg,
foobar_cspace,
foobar_sync_endpoint);
if (ret) {
LIBLCD_ERR("async dispatch failed");
stop = 1;
}
);
}
LIBLCD_MSG("FOOBAR DUMMY EXITED DISPATCH LOOP");
);
LIBLCD_MSG("EXITED DUMMY DO_FINISH");
return;
}
static int __noreturn dummy_lcd_init(void)
{
int r = 0;
printk("LCD enter \n");
r = lcd_enter();
if (r)
goto fail1;
/*
* Get the foobar channel cptr from boot info
*/
foobar_register_channel = lcd_get_boot_info()->cptrs[0];
printk("foobar reg channel %lu\n", foobar_register_channel.cptr);
/*
* Initialize foobar glue
*/
r = glue_foobar_init();
if (r) {
LIBLCD_ERR("foobar init");
goto fail2;
}
thc_channel_group_init(&ch_grp);
/* RUN CODE / LOOP ---------------------------------------- */
main_and_loop();
/* DONE -------------------------------------------------- */
glue_foobar_exit();
lcd_exit(0); /* doesn't return */
fail2:
fail1:
lcd_exit(r);
}
static int __dummy_lcd_init(void)
{
int ret;
LIBLCD_MSG("%s: entering", __func__);
LCD_MAIN({
ret = dummy_lcd_init();
});
return ret;
}
static void __exit dummy_lcd_exit(void)
{
LIBLCD_MSG("%s: exiting", __func__);
return;
}
module_init(__dummy_lcd_init);
module_exit(dummy_lcd_exit);
MODULE_LICENSE("GPL");
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