All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

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

Finished modifying manufacturer.c to jive with api.

parent c4b3deb9
......@@ -511,7 +511,7 @@ static int test06(void)
ret = lcd_cnode_alloc(lcd1->cspace, &cptr1);
if (ret)
goto clean3;
ret = lcd_mk_sync_endpoint(lcd1, cptr1);
ret = __lcd_mk_sync_endpoint(lcd1, cptr1);
if (ret) {
LCD_ERR("mk sync endpoint");
goto clean3;
......@@ -591,7 +591,7 @@ static int test06(void)
goto clean4;
clean4:
lcd_rm_sync_endpoint(lcd1, cptr1);
__lcd_rm_sync_endpoint(lcd1, cptr1);
clean3:
test_rm_lcd(lcd2);
clean2:
......@@ -680,7 +680,7 @@ static int test07(void)
ret = lcd_cnode_alloc(lcd1->cspace, &cptr1a);
if (ret)
goto clean3;
ret = lcd_mk_sync_endpoint(lcd1, cptr1a);
ret = __lcd_mk_sync_endpoint(lcd1, cptr1a);
if (ret) {
LCD_ERR("mk sync endpoint");
goto clean3;
......@@ -709,7 +709,7 @@ static int test07(void)
ret = lcd_cnode_alloc(lcd2->cspace, &cptr2b);
if (ret)
goto clean4;
ret = lcd_mk_sync_endpoint(lcd2, cptr2b);
ret = __lcd_mk_sync_endpoint(lcd2, cptr2b);
if (ret) {
LCD_ERR("mk lcd2 reply sync endpoint");
goto clean5;
......@@ -791,9 +791,9 @@ static int test07(void)
goto clean5;
clean5:
lcd_rm_sync_endpoint(lcd2, cptr2b);
__lcd_rm_sync_endpoint(lcd2, cptr2b);
clean4:
lcd_rm_sync_endpoint(lcd1, cptr1a);
__lcd_rm_sync_endpoint(lcd1, cptr1a);
clean3:
test_rm_lcd(lcd2);
clean2:
......
......@@ -83,6 +83,7 @@ enum lcd_cap_type {
LCD_CAP_TYPE_FREE = 0,
LCD_CAP_TYPE_UNFORMED = 1,
LCD_CAP_TYPE_SYNC_EP = 2,
LCD_CAP_TYPE_DSTORE = 3,
};
enum lcd_cap_right {
......@@ -277,15 +278,4 @@ struct sync_endpoint {
struct mutex lock;
};
/**
* Create a synchronous end point, and install it in lcd's cspace
* at location cptr.
*/
int lcd_mk_sync_endpoint(struct lcd *lcd, cptr_t cptr);
/**
* Remove synchronous end point identified by cptr in lcd's cspace.
*/
int lcd_rm_sync_endpoint(struct lcd *lcd, cptr_t cptr);
#endif /* LCD_PROTOTYPE_API_DEFS_H */
......@@ -330,7 +330,7 @@ int __lcd_reply(struct lcd *lcd)
return ret;
}
int lcd_mk_sync_endpoint(struct lcd *lcd, cptr_t c)
int __lcd_mk_sync_endpoint(struct lcd *lcd, cptr_t c)
{
struct sync_endpoint *e;
int ret = -EINVAL;
......@@ -391,7 +391,7 @@ static int __cleanup_sync_endpoint(struct cnode *cnode)
return 0;
}
static int __lcd_rm_sync_endpoint(struct lcd *lcd, cptr_t cptr)
static int lcd_do_rm_sync_endpoint(struct lcd *lcd, cptr_t cptr)
{
int ret;
struct cnode *cnode;
......@@ -410,7 +410,7 @@ static int __lcd_rm_sync_endpoint(struct lcd *lcd, cptr_t cptr)
return __cleanup_sync_endpoint(cnode);
}
int lcd_rm_sync_endpoint(struct lcd *lcd, cptr_t cptr)
int __lcd_rm_sync_endpoint(struct lcd *lcd, cptr_t cptr)
{
int ret;
/*
......@@ -419,7 +419,7 @@ int lcd_rm_sync_endpoint(struct lcd *lcd, cptr_t cptr)
ret = lcd_cap_lock();
if (ret)
return ret;
ret = __lcd_rm_sync_endpoint(lcd, cptr);
ret = lcd_do_rm_sync_endpoint(lcd, cptr);
/*
* UNLOCK cap
*/
......
......@@ -49,6 +49,17 @@ int __lcd_call(struct lcd *lcd, cptr_t c);
* Other side of a lcd call.
*/
int __lcd_reply(struct lcd *lcd);
/**
* Create a synchronous end point, and install it in lcd's cspace
* at location cptr.
*/
int __lcd_mk_sync_endpoint(struct lcd *lcd, cptr_t cptr);
/**
* Remove synchronous end point identified by cptr in lcd's cspace.
*/
int __lcd_rm_sync_endpoint(struct lcd *lcd, cptr_t cptr);
/**
* Places from on receive queue for all end points identified by the
* cptr's cs. When a matching send is received, idx points to the
......
/*
* api.h - wrappers for calls into api code, via ipc
*
* Author: Charles Jacobsen <charlesj@cs.utah.edu>
* Copyright: University of Utah
*
* Implemented by liblcd. Sets up and performs calls
* into api code, via ipc. See api code for more info.
*/
#ifndef LCD_PROTOTYPE_API_H
#define LCD_PROTOTYPE_API_H
#include <lcd-prototype/lcd.h>
int lcd_mk_sync_endpoint(cptr_t c);
int lcd_rm_sync_endpoint(cptr_t c);
#endif /* LCD_PROTOTYPE_API_H */
/*
* dstore.h - routines for creating and manipulating a data store
*
* Author: Charles Jacobsen <charlesj@cs.utah.edu>
* Copyright: University of Utah
*
* Implemented by liblcd.
*/
#ifndef LCD_PROTOTYPE_DSTORE_H
#define LCD_PROTOTYPE_DSTORE_H
#include <lcd-prototype/lcd.h>
typedef u64 dsptr_t;
enum dstore_rights {
DSTORE_READ_RIGHTS = 0x01,
DSTORE_WRITE_RIGHTS = 0x02,
};
#define DSTORE_ALL_RIGHTS (DSTORE_READ_RIGHTS | DSTORE_WRITE_RIGHTS)
struct dsnode {
int rights;
void *object;
};
#define DSTORE_CAN_READ(dsnode) ((dsnode)->rights & DSTORE_READ_RIGHTS)
#define DSTORE_CAN_WRITE(dsnode) ((dsnode)->rights & DSTORE_WRITE_RIGHTS)
/**
* Initializes the lcd's data store. Must call before
* other routines.
*/
int lcd_ds_init(void);
/**
* Tears down lcd's data store. Should call before
* lcd dies.
*/
int lcd_ds_exit(void);
/**
* Stores object in lcd's data store for the remote lcd identified
* by badge, and returns an identifying dsptr. Object can be
* retrieved in the future via lcd_ds_lookup with dsptr and badge.
*/
int lcd_ds_store(void *object, dsptr_t *dsptr, u64 badge, int rights);
/**
* Looks up dsnode containing object referred to by (badge, dsptr) combo.
* Returns NULL if no such combo is mapped. No permission checks.
*/
struct dsnode *__lcd_ds_lookup(u64 badge, dsptr_t dsptr);
/**
* Unmaps (badge, dsptr) combo from data store. Returns pointer to mapped
* object (so that e.g. caller can free it). If check is non-zero,
* confirms dnode has all rights.
*/
void * __lcd_ds_drop(u64 badge, dsptr_t dsptr, int check);
static inline void * lcd_ds_drop(u64 badge, dsptr_t dsptr)
{
return __lcd_ds_drop(badge, dsptr, 1);
}
static inline void * lcd_ds_drop_no_check(u64 badge, dsptr_t dsptr)
{
return __lcd_ds_drop(badge, dsptr, 0);
}
/**
* Looks up and returns object mapped by (badge, dsptr) combo. Confirms
* read right to object; returns NULL if no read right. Caller is
* responsible for not accidentally writing to the object.
*/
static inline void * lcd_ds_read(u64 badge, dsptr_t dsptr)
{
struct dsnode *dsnode;
dsnode = __lcd_ds_lookup(badge, dsptr);
if (!dsnode)
return NULL;
else if (!DSTORE_CAN_READ(dsnode))
return NULL;
else
return dsnode->object;
}
/**
* Looks up and returns object mapped by (badge, dsptr) combo. Confirms
* write right to object; returns NULL if no write right. Caller is
* responsible for not accidentally reading the object.
*/
static inline void * lcd_ds_write(u64 badge, dsptr_t dsptr)
{
struct dsnode *dsnode;
dsnode = __lcd_ds_lookup(badge, dsptr);
if (!dsnode)
return NULL;
else if (!DSTORE_CAN_WRITE(dsnode))
return NULL;
else
return dsnode->object;
}
#endif /* LCD_PROTOTYPE_DSTORE_H */
......@@ -15,37 +15,49 @@
#include <lcd-prototype/lcd.h>
#include "utcb.h"
#include "api-internal.h"
#include "../api/defs.h"
struct lcd_handler {
cptr_t c;
int (*handler)(void);
};
static inline struct lcd * current_lcd(void)
{
return current->lcd;
}
static inline int lcd_send(cptr_t c)
{
return __lcd_send(current, c);
return __lcd_send(current_lcd(), c);
}
static inline int lcd_reply(void)
{
return lcd_send(current, lcd_reply_cap());
return lcd_send(current_lcd(), lcd_reply_cap());
}
static inline int lcd_call(cptr_t c)
{
return __lcd_call(current, c);
return __lcd_call(current_lcd(), c);
}
static inline int lcd_select(struct lcd_handlers *hs, int hs_count)
static inline int lcd_mk_sync_endpoint(cptr_t *c)
{
cptr_t cs[hs_count];
int recv_idx;
int i;
int ret;
for (i = 0; i < hs_count; i++)
cs[i] = hs[i].c;
ret = __lcd_select(current, cs, hs_count, &idx);
ret = lcd_cnode_alloc(current_lcd()->cspace, c);
if (ret)
return ret;
else
return hs[idx].handler();
return __lcd_mk_sync_endpoint(current_lcd(), *c);
}
static inline int lcd_rm_sync_endpoint(cptr_t c)
{
return __lcd_rm_sync_endpoint(current_lcd(), c);
}
static inline int lcd_select(struct lcd_handlers *hs, int hs_count)
{
return -ENOSYS;
}
#endif /* LCD_PROTOTYPE_IPC_H */
......@@ -10,6 +10,11 @@
#include <lcd-prototype/lcd.h>
static inline struct lcd * current_lcd(void)
{
return current->lcd;
}
/* BOOT CPTRS -------------------------------------------------- */
static inline cptr_t lcd_boot_cptr(u8 idx)
......@@ -114,23 +119,12 @@ LCD_MK_IN_CAP_REG_ACCESS(5);
LCD_MK_IN_CAP_REG_ACCESS(6);
LCD_MK_IN_CAP_REG_ACCESS(7);
/* REPLY INFO -------------------------------------------------- */
/* REPLY INFO ---------------------------------------- */
static inline u64 lcd_reply_badge(void)
{
return current->lcd->utcb.reply_badge;
}
static inline void lcd_store_reply_badge(u64 val)
{
current->lcd->utcb.reply_badge = val;
}
static inline cptr_t lcd_reply_cap(void)
{
return current->lcd->utcb.reply_cap;
}
static inline void lcd_store_reply_cap(cptr_t val)
{
current->lcd->utcb.reply_cap = val;
/* not implemented */
return 0;
}
#endif /* LCD_PROTOTYPE_UTCB_H */
/*
* Author: Charles Jacobsen <charlesj@cs.utah.edu>
* Copyright: University of Utah
*
*/
#ifndef LCD_IPC_AUTO_COMMON_H
#define LCD_IPC_AUTO_COMMON_H
#define AU_ERR(msg...) __au_err(__FILE__, __LINE__, msg)
static inline void __au_err(char *file, int lineno, char *fmt, ...)
{
va_list args;
pr_err("lcd-ipc-auto: %s:%d: error: ", file, lineno);
va_start(args, fmt);
vprintk(fmt, args);
va_end(args);
}
#define AU_MSG(msg...) __au_msg(__FILE__, __LINE__, msg)
static inline void __au_msg(char *file, int lineno, char *fmt, ...)
{
va_list args;
pr_info("lcd-ipc-auto: %s:%d: note: ", file, lineno);
va_start(args, fmt);
vprintk(fmt, args);
va_end(args);
}
#define AU_WARN(msg...) __au_warn(__FILE__, __LINE__, msg)
static inline void __au_warn(char *file, int lineno, char *fmt, ...)
{
va_list args;
pr_warn("lcd-ipc-auto: %s:%d: warning: ", file, lineno);
va_start(args, fmt);
vprintk(fmt, args);
va_end(args);
}
#endif /* LCD_IPC_AUTO_COMMON_H */
......@@ -19,26 +19,18 @@ extern void __manufacturer_exit(void);
#include "../include/common.h"
#include "../include/ipc.h"
#include "../include/api.h"
#include "../include/dstore.h"
#include "../include/utcb.h"
/* INTERFACE WRAPPERS -------------------------------------------------- */
struct manufacturer_interface *mi;
struct {
cptr_t mk_engine;
cptr_t mk_automobile;
cptr_t free_engine;
cptr_t free_automobile;
} manufacturer_interface_cptrs;
cptr_t manufacturer_interface_cap;
/**
* mk_engine_callee
* ----------------
* IN:
* lcd_r0 = number of cylinders
* lcd_reply_cap = cptr to reply rendezvous point
* lcd_reply_badge = badge identifying sender
* lcd_r1 = number of cylinders
* OUT:
* lcd_r0 = 0
* lcd_r1 = dsptr to allocated engine
......@@ -52,19 +44,19 @@ static int mk_engine_callee(void)
/*
* Build engine
*/
cylinders = (int)lcd_r0();
cylinders = (int)lcd_r1();
e = mi->mk_engine(cylinders);
if (!e) {
AU_ERR("bad engine");
LCD_ERR("bad engine");
ret = -1;
goto fail1;
}
/*
* Put in data store
* Alloc capability
*/
ret = lcd_ds_store(e, &engine_dsptr, lcd_reply_badge());
if(ret) {
AU_ERR("store engine");
LCD_ERR("store engine");
goto fail2;
}
/*
......@@ -74,7 +66,7 @@ static int mk_engine_callee(void)
lcd_store_r1(engine_dsptr);
ret = lcd_reply();
if (ret) {
AU_ERR("couldn't reply");
LCD_ERR("couldn't reply");
goto fail3;
}
......@@ -91,10 +83,8 @@ fail1:
* mk_automobile_callee
* --------------------
* IN:
* lcd_r0 = number of doors
* lcd_r1 = dsptr to allocated engine
* lcd_reply_cap = cptr to reply rendezvous point
* lcd_reply_badge = badge identifying sender
* lcd_r1 = number of doors
* lcd_r2 = dsptr to allocated engine
* OUT:
* lcd_r0 = 0
* lcd_r1 = dsptr to allocated auto
......@@ -110,20 +100,20 @@ static int mk_automobile_callee(void)
/*
* Get the engine from the data store
*/
engine_dsptr = (dsptr_t)lcd_r1();
engine_dsptr = (dsptr_t)lcd_r2();
e = lcd_ds_read(lcd_reply_badge(), engine_dsptr);
if (!e) {
AU_ERR("bad engine dsptr %lld", engine_dsptr);
LCD_ERR("bad engine dsptr %lld", engine_dsptr);
ret = -EINVAL;
goto fail1;
}
/*
* Build car
*/
doors = (int)lcd_r0();
doors = (int)lcd_r1();
a = mi->mk_automobile(e, doors);
if (!a) {
AU_ERR("bad auto");
LCD_ERR("bad auto");
ret = -ENOMEM;
goto fail1;
}
......@@ -132,7 +122,7 @@ static int mk_automobile_callee(void)
*/
ret = lcd_ds_store(a, &auto_dsptr, lcd_reply_badge());
if(ret) {
AU_ERR("store auto");
LCD_ERR("store auto");
goto fail2;
}
/*
......@@ -142,7 +132,7 @@ static int mk_automobile_callee(void)
lcd_store_r1(auto_dsptr);
ret = lcd_reply();
if (ret) {
AU_ERR("couldn't reply");
LCD_ERR("couldn't reply");
goto fail3;
}
......@@ -160,9 +150,7 @@ fail1:
* free_engine_callee
* ------------------
* IN:
* lcd_r0 = dsptr to allocated engine
* lcd_reply_cap = cptr to reply rendezvous point
* lcd_reply_badge = badge identifying sender
* lcd_r1 = dsptr to allocated engine
* OUT:
* lcd_r0 = 0
*/
......@@ -174,10 +162,10 @@ static int free_engine_callee(void)
/*
* Get and remove engine from data store
*/
engine_dsptr = (dsptr_t)lcd_r0();
engine_dsptr = (dsptr_t)lcd_r1();
e = lcd_ds_drop(lcd_reply_badge(), engine_dsptr);
if (!e) {
AU_ERR("bad engine dsptr %lld", engine_dsptr);
LCD_ERR("bad engine dsptr %lld", engine_dsptr);
ret = -EINVAL;
goto fail1;
}
......@@ -191,7 +179,7 @@ static int free_engine_callee(void)
lcd_store_r0(0);
ret = lcd_reply();
if (ret)
AU_ERR("couldn't reply");
LCD_ERR("couldn't reply");
return ret;
......@@ -203,9 +191,7 @@ fail1:
* free_automobile_callee
* ----------------------
* IN:
* lcd_r0 = dsptr to allocated auto
* lcd_reply_cap = cptr to reply rendezvous point
* lcd_reply_badge = badge identifying sender
* lcd_r1 = dsptr to allocated auto
* OUT:
* lcd_r0 = 0
*/
......@@ -217,10 +203,10 @@ static int free_automobile_callee(void)
/*
* Get and remove auto from data store
*/
auto_dsptr = (dsptr_t)lcd_r0();
auto_dsptr = (dsptr_t)lcd_r1();
e = lcd_ds_drop(lcd_reply_badge(), auto_dsptr);
if (!e) {
AU_ERR("bad auto dsptr %lld", auto_dsptr);
LCD_ERR("bad auto dsptr %lld", auto_dsptr);
ret = -EINVAL;
goto fail1;
}
......@@ -234,7 +220,7 @@ static int free_automobile_callee(void)
lcd_store_r0(0);
ret = lcd_reply();
if (ret)
AU_ERR("couldn't reply");
LCD_ERR("couldn't reply");
return ret;
......@@ -246,8 +232,7 @@ fail1:
* manufacturer_die_callee
* -----------------------
* IN:
* lcd_reply_cap = cptr to reply rendezvous point
* lcd_reply_badge = badge identifying sender
* (reply info)
* OUT:
* (nothing)
*/
......@@ -263,7 +248,7 @@ int manufacturer_die_callee(void)
*/
ret = lcd_reply();
if (ret)
AU_ERR("couldn't reply");
LCD_ERR("couldn't reply");
return ret;
}
......@@ -283,52 +268,28 @@ int dealer_register_manufacturer(struct manufacturer_interface *__mi)
*/
mi = __mi;
/*
* Create endpoints for functions in interface
* Create endpoint for interface
*/
ret = lcd_mk_sync_endpoint(manufacturer_interface_cptrs.mk_engine);
ret = lcd_mk_sync_endpoint(&manufacturer_interface_cap);
if(ret) {
AU_ERR("mk engine endpoint");
LCD_ERR("mk manufacturer iface endpoint");
goto fail1;
}
ret = lcd_mk_sync_endpoint(manufacturer_interface_cptrs.mk_automobile);
if(ret) {
AU_ERR("mk auto endpoint");
goto fail2;
}
ret = lcd_mk_sync_endpoint(manufacturer_interface_cptrs.free_engine);
if(ret) {
AU_ERR("free engine endpoint");
goto fail3;
}
ret = lcd_mk_sync_endpoint(manufacturer_interface_cptrs.free_automobile);
if(ret) {
AU_ERR("free auto endpoint");
goto fail4;
}
/*
* Store in the cap regs for the caller, and send
*/
lcd_store_out_cap0(manufacturer_interface_cptrs.mk_engine);
lcd_store_out_cap1(manufacturer_interface_cptrs.mk_automobile);
lcd_store_out_cap2(manufacturer_interface_cptrs.free_engine);
lcd_store_out_cap3(manufacturer_interface_cptrs.free_automobile);
ret = lcd_call(lcd_boot_cptr(DEALER_REGISTER_MANUFACTURER));
lcd_store_out_cap0(manufacturer_interface_cap);
ret = lcd_call(lcd_boot_cptr(MANUFACTURER_DEALER_INTERFACE_CAP));
if (ret) {
AU_ERR("call to dealer");
goto fail5;
LCD_ERR("call to dealer");
goto fail2;
}
return (int)lcd_r0();
fail5:
lcd_rm_sync_endpoint(manufacturer_interface_cptrs.free_automobile);
fail4:
lcd_rm_sync_endpoint(manufacturer_interface_cptrs.free_engine);
fail3:
lcd_rm_sync_endpoint(manufacturer_interface_cptrs.mk_automobile);
fail2:
lcd_rm_sync_endpoint(manufacturer_interface_cptrs.mk_engine);
lcd_rm_sync_endpoint(manufacturer_interface_cap);
fail1:
return -1;
}
......@@ -338,17 +299,6 @@ fail1:
int execution_loop(void)
{
int ret;
struct lcd_handler handlers[] = {
{ manufacturer_interface_cptrs.mk_engine,
mk_engine_callee },
{ manufacturer_interface_cptrs.mk_automobile,
mk_automobile_callee },
{ manufacturer_interface_cptrs.free_engine,
free_engine_callee<