Commit bd924ac1 authored by Charlie Jacobsen's avatar Charlie Jacobsen Committed by Vikram Narayanan

Pulls dispatch loop definitions into headers.

This is a simple commit that pulls some common dispatch
loop infrastructure (struct defs, etc.) into
include/lcd-domains/dispatch_loop.h.

Updated glue example, all working.
parent f0d297ad
/*
* dispatch_loop.h - definitions and helpers for setting up
* the dispatch loop in the glue code
*/
#ifndef LCD_DOMAINS_DISPATCH_LOOP_H
#define LCD_DOMAINS_DISPATCH_LOOP_H
#ifdef LCD_ISOLATE
#include <lcd-domains/liblcd-config.h>
#endif
#include <linux/list.h>
#include <lcd-domains/types.h>
#ifdef LCD_ISOLATE
#include <lcd-domains/liblcd-hacks.h>
#endif
/**
* This represents an ipc channel.
*
* type: the integer flag the dispatch loop should use
* to select from a subset of the function labels
*
* channel_cptr: the cptr to the actual ipc channel / endpoint
*
* channel_list: the dispatch loop (context) puts channels in a list
*/
struct ipc_channel {
int type;
cptr_t channel_cptr;
struct list_head channel_list;
int expected_cptrs;
};
static inline void init_ipc_channel(struct ipc_channel *c, int type,
cptr_t chnl, int expected_cptrs)
{
c->type = type;
c->channel_cptr = chnl;
c->expected_cptrs = expected_cptrs;
INIT_LIST_HEAD(&c->channel_list);
}
/**
* This represents the data used by the dispatch loop.
*
* channel_list: list of channels registered with the dispatch loop
*
* Call loop_add_channel/loop_rm_channel below to add/remove a channel
* from the dispatch loop context (from the dispatch loop).
*/
struct dispatch_ctx {
struct list_head channel_list;
};
static inline void init_dispatch_ctx(struct dispatch_ctx *ctx)
{
INIT_LIST_HEAD(&ctx->channel_list);
}
static inline void loop_add_channel(struct dispatch_ctx *ctx,
struct ipc_channel *channel)
{
list_add(&channel->channel_list, &ctx->channel_list);
}
static inline void loop_rm_channel(struct dispatch_ctx *ctx,
struct ipc_channel *channel)
{
list_del_init(&channel->channel_list);
}
#endif /* LCD_DOMAINS_DISPATCH_LOOP_H */
......@@ -7,6 +7,9 @@
/* COMPILER: This is always included. */
#include <lcd-domains/liblcd.h>
/* COMPILER: This is always included. */
#include <lcd-domains/dispatch_loop.h>
/* LOOP -------------------------------------------------- */
/* COMPILER: For every channel a module listens on for function calls,
......@@ -15,20 +18,6 @@
* are part of interfaces and projections of function pointers. */
#define MINIX_CHANNEL_TYPE 1
/* COMPILER: These struct definitions are the same every time. (In the future,
* we may move them to liblcd.) This is an object-oriented interface the
* interface glue code will use to add channels to the dispatch loop. */
struct ipc_channel {
int type;
cptr_t channel_cptr;
struct list_head channel_list;
};
struct dispatch_ctx {
struct list_head channel_list;
void (*add_channel)(struct dispatch_ctx *, struct ipc_channel *);
void (*rm_channel)(struct dispatch_ctx *, struct ipc_channel *);
};
#define NEW_FILE 1
#define RM_FILE 2
void new_file_callee(void);
......@@ -117,16 +106,6 @@ static void loop(struct dispatch_ctx *ctx)
}
}
static void add_channel(struct dispatch_ctx *ctx, struct ipc_channel *channel)
{
list_add(&channel->channel_list, &ctx->channel_list);
}
static void rm_channel(struct dispatch_ctx *ctx, struct ipc_channel *channel)
{
list_del_init(&channel->channel_list);
}
/* INIT -------------------------------------------------- */
int glue_vfs_init(cptr_t vfs_chnl, struct dispatch_ctx *ctx);
......@@ -152,9 +131,7 @@ static int __init minix_lcd_boot(void)
/* COMPILER: Initialize dispatch loop context. This will be
* passed to each piece of interface glue. */
INIT_LIST_HEAD(&ctx.channel_list);
ctx.add_channel = add_channel;
ctx.rm_channel = rm_channel;
init_dispatch_ctx(&ctx);
/* COMPILER: Because minix required vfs, whoever boots minix should
* provide it with a capability to a channel for invoking vfs
......@@ -189,6 +166,8 @@ static int __init minix_lcd_boot(void)
/* Call original exit. */
original_minix_lcd_exit();
/* Done */
lcd_exit(0);
}
......
......@@ -10,25 +10,15 @@
* for using the LIBLCD interface). */
#include <lcd-domains/liblcd.h>
/* COMPILER: This header is always included. */
#include <lcd-domains/dispatch_loop.h>
/* COMPILER: Since this header was included in vfs.idl, the include
* is pasted here (the compiler does not need to be smart about paths - the
* IDL writer needs to use relative or absolute paths that should just
* work). */
#include "../../include/vfs.h"
/* Some struct defs. These should probably go in a header at some point
* so we don't duplicate defs. */
struct ipc_channel {
int type;
cptr_t channel_cptr;
struct list_head channel_list;
};
struct dispatch_ctx {
struct list_head channel_list;
void (*add_channel)(struct dispatch_ctx *, struct ipc_channel *);
void (*rm_channel)(struct dispatch_ctx *, struct ipc_channel *);
};
#define MINIX_CHANNEL_TYPE 1
/* INIT -------------------------------------------------- */
......@@ -55,6 +45,9 @@ struct dispatch_ctx {
* linking at runtime if we really wanted to ...) */
static cptr_t vfs_chnl;
static struct dstore *vfs_dstore;
/* COMPILER: We store a reference to the dispatch loop so we can
* dynamically add channels to it (see e.g., register_fs below). */
static struct dispatch_ctx *loop_ctx;
int glue_vfs_init(cptr_t _vfs_channel, struct dispatch_ctx *ctx)
......@@ -215,11 +208,12 @@ int register_fs(struct fs *fs)
* with the channel we created above, so we initialize the
* ipc channel here, and add it to the dispatch loop.
*/
fs_operations_container->chnl.type = MINIX_CHANNEL_TYPE;
fs_operations_container->chnl.channel_cptr = fs_container->chnl;
INIT_LIST_HEAD(&fs_operations_container->chnl.channel_list);
init_ipc_channel(&fs_operations_container->chnl,
MINIX_CHANNEL_TYPE,
fs_container->chnl,
0);
loop_ctx->add_channel(loop_ctx, &fs_operations_container->chnl);
loop_add_channel(loop_ctx, &fs_operations_container->chnl);
/* COMPILER: Both projections were marked as alloc(callee) and
* are hence already allocated on this side (caller side). So, we
......@@ -371,7 +365,7 @@ void unregister_fs(struct fs *fs)
* (the dispatch loop is hacked to exit after receiving two messages,
* and unregister_fs is invoked when we're exiting the module
* entirely, after the dispatch loop is dead). */
loop_ctx->rm_channel(loop_ctx, &fs_operations_container->chnl);
loop_rm_channel(loop_ctx, &fs_operations_container->chnl);
lcd_cap_delete(fs_operations_container->chnl.channel_cptr);
......
......@@ -7,23 +7,14 @@
/* COMPILER: This is always included. */
#include <lcd-domains/liblcd.h>
/* COMPILER: This is always included. */
#include <lcd-domains/dispatch_loop.h>
/* LOOP -------------------------------------------------- */
/* COMPILER: See notes in minix's boot.c. */
#define VFS_CHANNEL_TYPE 1
struct ipc_channel {
int type;
cptr_t channel_cptr;
int num_cptrs;
struct list_head channel_list;
};
struct dispatch_ctx {
struct list_head channel_list;
void (*add_channel)(struct dispatch_ctx *, struct ipc_channel *);
void (*rm_channel)(struct dispatch_ctx *, struct ipc_channel *);
};
#define REGISTER_FS 1
#define UNREGISTER_FS 2
void register_fs_callee(void);
......@@ -86,13 +77,13 @@ static int alloc_cptrs_for_channel(struct ipc_channel *c)
int ret;
cptr_t t;
if (c->num_cptrs >= LCD_NUM_REGS - 1) {
if (c->expected_cptrs >= LCD_NUM_REGS - 1) {
LIBLCD_ERR("too many cptrs");
return -EINVAL;
}
/* First cr is reserved */
for (i = 0; i < c->num_cptrs; i++) {
for (i = 0; i < c->expected_cptrs; i++) {
ret = lcd_alloc_cptr(&t);
if (ret) {
......@@ -148,16 +139,6 @@ static void loop(struct dispatch_ctx *ctx)
}
}
static void add_channel(struct dispatch_ctx *ctx, struct ipc_channel *channel)
{
list_add(&channel->channel_list, &ctx->channel_list);
}
static void rm_channel(struct dispatch_ctx *ctx, struct ipc_channel *channel)
{
list_del_init(&channel->channel_list);
}
/* INIT -------------------------------------------------- */
int glue_vfs_init(cptr_t vfs_chnl, struct dispatch_ctx *ctx);
......@@ -183,9 +164,7 @@ static int __init vfs_lcd_boot(void)
/* COMPILER: Initialize dispatch loop context. This will be
* passed to each piece of interface glue. */
INIT_LIST_HEAD(&ctx.channel_list);
ctx.add_channel = add_channel;
ctx.rm_channel = rm_channel;
init_dispatch_ctx(&ctx);
/* COMPILER: Because minix required vfs, whoever boots vfs should
* provide it with a capability to a channel for invoking vfs
......@@ -225,6 +204,8 @@ static int __init vfs_lcd_boot(void)
/* Call original exit. */
original_vfs_lcd_exit();
glue_vfs_exit();
/* Done */
lcd_exit(0);
}
......
......@@ -10,6 +10,9 @@
* for using the LIBLCD interface). */
#include <lcd-domains/liblcd.h>
/* COMPILER: This is always included. */
#include <lcd-domains/dispatch_loop.h>
/* COMPILER: We probably always need the slab header. */
#include <linux/slab.h>
......@@ -34,21 +37,11 @@
* a domain id). */
static struct dstore *minix_dstore;
/* COMPILER: In general, we also should store a reference to the dispatch
* context so we can dynamically add channels to listen on at run time. In
* this simple example, the vfs doesn't create any new channels to listen
* on. */
struct ipc_channel {
int type;
cptr_t channel_cptr;
int num_cptrs;
struct list_head channel_list;
};
struct dispatch_ctx {
struct list_head channel_list;
void (*add_channel)(struct dispatch_ctx *, struct ipc_channel *);
void (*rm_channel)(struct dispatch_ctx *, struct ipc_channel *);
};
/* COMPILER: It's possible, but maybe unlikely, that the callee code
* will dynamically add channels to the dispatch loop. We store a
* reference to it. (This is also convenient for init/teardown to
* add/remove the main channel to the dispatch loop.)
*/
static struct dispatch_ctx *loop_ctx;
/* CONTAINER STRUCTS -------------------------------------------------- */
......@@ -657,15 +650,12 @@ int glue_vfs_init(cptr_t vfs_chnl, struct dispatch_ctx *ctx)
int ret;
/* Set up ipc channel */
vfs_channel.type = VFS_CHANNEL_TYPE;
vfs_channel.channel_cptr = vfs_chnl;
vfs_channel.num_cptrs = 1;
INIT_LIST_HEAD(&vfs_channel.channel_list);
init_ipc_channel(&vfs_channel, VFS_CHANNEL_TYPE, vfs_chnl, 1);
loop_ctx = ctx;
/* Add it to dispatch loop */
loop_ctx->add_channel(loop_ctx, &vfs_channel);
loop_add_channel(loop_ctx, &vfs_channel);
/* Initialize minix data store */
ret = lcd_dstore_init_dstore(&minix_dstore);
......@@ -684,5 +674,5 @@ void glue_vfs_exit(void)
/* We may as well remove the channel from the loop, though
* it doesn't matter in this simple example. (In general, we
* probably should.) */
loop_ctx->rm_channel(loop_ctx, &vfs_channel);
loop_rm_channel(loop_ctx, &vfs_channel);
}
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