Commit 4ad6d6aa authored by Charlie Jacobsen's avatar Charlie Jacobsen Committed by Vikram Narayanan

Half-way through dealer idl.

parent d183b184
/*
* Author: Charles Jacobsen <charlesj@cs.utah.edu>
* Copyright: University of Utah
*
*/
#ifdef CONFIG_RUN_IN_LCD
/* Main execution loop */
int execution_loop(void)
{
/* INTERNAL DEFS -------------------------------------------------- */
int ret;
enum client_interface call;
capability_t server = current->utcb->boot_info.boot_caps[LCD_BOOT_FREE_CAP0];
capability_t server_interface;
struct message_info *msg = &current->utcb->msg_info;
#include "dealer.h"
ret = lcd_alloc_cap(&current->cap_cache, &server_interface);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
return -ENOSPC;
};
extern int __manufacturer_init(void);
extern void __manufacturer_exit(void);
msg->cap_regs[0] = server_interface;
msg->valid_cap_regs = 1;
/* IDL/LCD DEFS -------------------------------------------------- */
ret = ipc_recv(server, msg);
if (ret) {
printk(KERN_ERR "client failed to receive from the server:%d\n", ret);
return ret;
};
#include "dealer-idl.h"
#include "manufacturer-idl.h"
#include "../include/common.h"
#include "../include/ipc.h"
#include "../include/api.h"
#include "../include/utcb.h"
/* INTERFACE WRAPPERS -------------------------------------------------- */
call = msg->regs[0];
struct manufacturer_interface __mi = {
switch (call) {
case client_interface_register_server:
ret = register(lcd_api, reply_cap);
break;
default:
printk(KERN_ERR "lcd_api: invalid call number:%d\n", call);
msg->valid_regs = 0;
msg->valid_cap_regs = 0;
ipc_reply(reply_cap, msg);
lcd_cap_drop(&current->cspace, reply_cap);
};
return 0;
};
struct sync_ipc *client_server_rvp;
int accept_client_introduction(void) {
return lcd_accept_introduction(&client_server_rvp,
&client);
/**
* dealer_register_manufacturer_callee
* -----------------------------------
*
* IN:
* lcd_in_cap0 = cptr to capability for endpoint to manuf. interface
* OUT:
* lcd_r0 = 0
*/
static int dealer_register_manufacturer_callee(void)
{
/*
* Reply
*/
lcd_store_r0(0);
ret = lcd_reply();
if (ret) {
LCD_ERR("couldn't reply");
goto fail1;
}
};
EXPORT_SYMBOL(accept_client_introduction);
return ret;
int execution_loop_thread(void *p) {
int ret;
fail1:
return ret;
}
ret = lcd_init_current();
/**
* dealer_buy_car_callee
* ---------------------
* IN:
* (reply endpoint cap)
* OUT:
* lcd_r0 = ret val
* lcd_r1 = (cptr) to auto; used to refer to car in dealer space
*/
static int * dealer_buy_car_callee(void)
{
int ret;
struct automobile *a;
dsptr_t auto_dsptr;
/*
* Call into internal code
*/
a = dealer_buy_car();
if (!a) {
LCD_ERR("bad auto");
ret = -1;
goto fail1;
}
/*
* Alloc capability
*/
ret = lcd_ds_store(a, &auto_dsptr, lcd_reply_badge());
if(ret) {
LCD_ERR("store auto");
goto fail2;
}
/*
* Reply
*/
lcd_store_r0(0);
lcd_store_r1(auto_dsptr);
ret = lcd_reply();
if (ret) {
printk(KERN_ERR "Failed to init current thread with LCD:%d\n", ret);
return -EINVAL;
LCD_ERR("couldn't reply");
goto fail3;
}
ret = lcd_init_cspace(&module_cspace);
if (ret) {
printk(KERN_ERR "Failed to init global cspace for this module:%d\n", ret);
return ret;
fail3:
lcd_ds_drop(lcd_reply_badge(), auto_dsptr);
fail2:
dealer_return_car(a);
fail1:
return ret;
}
/**
* dealer_return_car_callee
* ------------------------
* IN:
* lcd_r1 = dsptr to allocated auto (in dealer space)
* OUT:
* lcd_r0 = ret val
*/
static int dealer_return_car_callee(void)
{
int ret;
struct automobile *a;
dsptr_t auto_dsptr;
/*
* Get and remove engine from data store
*/
auto_dsptr = (dsptr_t)lcd_r1();
a = lcd_ds_drop(lcd_reply_badge(), engine_dsptr);
if (!a) {
LCD_ERR("bad auto dsptr %lld", engine_dsptr);
ret = -EINVAL;
goto fail1;
}
/*
* Return car
*/
dealer_return_car(a);
/*
* Reply
*/
lcd_store_r0(0);
ret = lcd_reply();
if (ret)
LCD_ERR("couldn't reply");
return ret;
fail1:
return ret;
}
/**
* dealer_die_callee
* -----------------
* IN:
* (reply info)
* OUT:
* (nothing)
*/
int dealer_die_callee(void)
{
int ret;
/*
* Call internal exit
*/
__dealer_exit();
/*
* Kill manufacturer
*/
lcd_store_r0(MANUFACTURER_DIE);
ret = lcd_call(lcd_boot_cap(DEALER_MANUFACTURER_INTERFACE_CAP));
if (ret)
return ret;
};
/*
* Reply
*/
lcd_store_r0(0);
ret = lcd_reply();
if (ret)
LCD_ERR("couldn't reply");
return ret;
}
/* DEPENDENCIES -------------------------------------------------- */
/* Introduction code */
ret = lcd_prepare_introduction(lcd_api_cap(),
lcd_api_reply_cap(),
&client_server_rvp,
&current->utcb->boot_info.boot_caps[LCD_BOOT_FREE_CAP0]);
/**
* dealer_register_manufacturer
* ----------------------------
*
* See callee for interface.
*/
int dealer_register_manufacturer(struct manufacturer_interface *__mi)
{
int ret;
/*
* Store pointer to original interface
*/
mi = __mi;
/*
* Create endpoint for interface
*/
ret = lcd_mk_sync_endpoint(&manufacturer_interface_cap);
if(ret) {
LCD_ERR("mk manufacturer iface endpoint");
goto fail1;
}
/*
* Store in the cap regs for the caller, and send
*/
lcd_store_out_cap0(manufacturer_interface_cap);
ret = lcd_call(lcd_boot_cptr(MANUFACTURER_DEALER_INTERFACE_CAP));
if (ret) {
printk(KERN_ERR "client failed to initialize client-server environtment\n");
return -EINVAL;
LCD_ERR("call to dealer");
goto fail2;
}
/* Record the clients session */
lcd_cap_make_cspace(&module_cspace, &module_cap_cache, *
return (int)lcd_r0();
fail2:
lcd_rm_sync_endpoint(manufacturer_interface_cap);
fail1:
return -1;
}
/* MAIN EXEC LOOP -------------------------------------------------- */
int execution_loop(void)
{
int ret;
/*
* Loop unless there's an internal error, or we get killed
*/
for (;;) {
/*
* Listen for incoming message
*/
ret = lcd_recv(manufacturer_interface_cap);
if (ret)
goto out;
switch (lcd_r0()) {
case MANUFACTURER_MK_ENGINE:
ret = mk_engine_callee();
break;
case MANUFACTURER_MK_AUTOMOBILE:
ret = mk_automobile_callee();
break;
case MANUFACTURER_FREE_ENGINE:
ret = free_engine_callee();
break;
case MANUFACTURER_FREE_AUTOMOBILE:
ret = free_automobile_callee();
break;
case MANUFACTURER_DIE:
manufacturer_die();
goto out;
}
/* internal error ? */
if (ret)
goto out;
}
out:
return ret;
}
int manufacturer_start(void)
{
int ret;
/*
* Call manufacturer init, should register interface.
*/
ret = __manufacturer_init();
if (ret) {
LCD_ERR("manufacturer init");
return -1;
}
/*
* Ensure interface is set
*/
if (!mi) {
LCD_ERR("interface not set");
return -1;
}
/*
* Now enter loop and listen for calls
*/
return execution_loop();
}
EXPORT_SYMBOL(manufacturer_start);
int __init manufacturer_init(void)
{
return 0;
}
/* manufacturer_die does the actual tear down */
void __exit manufacturer_exit(void)
{
return;
}
module_init(manufacturer_init);
module_exit(manufacturer_exit);
#endif /* CONFIG_RUN_IN_LCD */
......@@ -13,4 +13,6 @@ enum dealer_interface {
DEALER_REGISTER_MANUFACTURER,
};
#define DEALER_MANUFACTURER_INTERFACE_CAP 1
#endif
......@@ -280,6 +280,14 @@ int dealer_register_manufacturer(struct manufacturer_interface *__mi)
* Store in the cap regs for the caller, and send
*/
lcd_store_out_cap0(manufacturer_interface_cap);
/*
* Set up call.
*
* r0 = enum for calling reg manufacturer in dealer interface
* boot cptr = points to end point for dealer interface
*/
lcd_store_r0(DEALER_REGISTER_MANUFACTURER);
ret = lcd_call(lcd_boot_cptr(MANUFACTURER_DEALER_INTERFACE_CAP));
if (ret) {
LCD_ERR("call to dealer");
......@@ -337,7 +345,7 @@ out:
return ret;
}
int __init manufacturer_init(void)
int manufacturer_start(void)
{
int ret;
/*
......@@ -360,6 +368,12 @@ int __init manufacturer_init(void)
*/
return execution_loop();
}
EXPORT_SYMBOL(manufacturer_start);
int __init manufacturer_init(void)
{
return 0;
}
/* manufacturer_die does the actual tear down */
void __exit manufacturer_exit(void)
......
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