customer-idl.c 2.54 KB
Newer Older
Charlie Jacobsen's avatar
Charlie Jacobsen committed
1 2 3 4 5 6
/*
 * Author: Charles Jacobsen <charlesj@cs.utah.edu>
 * Copyright: University of Utah
 *
 */

7
#ifdef CONFIG_LCD_PROTOTYPE_TEST_IN_LCD
Charlie Jacobsen's avatar
Charlie Jacobsen committed
8 9 10 11 12 13 14 15 16 17

/* INTERNAL DEFS -------------------------------------------------- */

#include "dealer.h"

extern int __customer_init(void);
extern void __customer_exit(void);

/* IDL/LCD DEFS -------------------------------------------------- */

18
#include <linux/slab.h>
Charlie Jacobsen's avatar
Charlie Jacobsen committed
19
#include "dealer-idl.h"
20
#include "customer-idl.h"
Charlie Jacobsen's avatar
Charlie Jacobsen committed
21 22
#include "../include/common.h"
#include "../include/ipc.h"
23
#include "../include/api-internal.h"
Charlie Jacobsen's avatar
Charlie Jacobsen committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
#include "../include/utcb.h"

/* INTERFACE WRAPPERS -------------------------------------------------- */

/* (none) */

/* DEPENDENCIES -------------------------------------------------- */

/* See callee (dealer) for interface */

/**
 * dealer_buy_car
 * --------------
 */
struct automobile * dealer_buy_car(void)
{
	struct automobile *a;
	struct engine *e;
	int ret;
	/*
	 * Alloc caller copy of hierarchy
	 */
	a = kmalloc(sizeof(a), GFP_KERNEL);
	if (!a)
		goto fail1;
	e = kmalloc(sizeof(e), GFP_KERNEL);
	if (!e)
		goto fail2;
	a->engine = e;
	/*
	 * Alloc on callee side, and get pointer to callee copies
	 */
	lcd_store_r0(DEALER_BUY_CAR);
	ret = lcd_call(CUSTOMER_DEALER_INTERFACE_CAP);
	if (ret) {
		LCD_ERR("call failed");
		goto fail3;
	}
	if (lcd_r0()) {
		LCD_ERR("non zero ret val");
		goto fail3;
	}
	a->self = lcd_r1();
	a->engine->self = lcd_r2();

	/*
	 * XXX: How to automate code generation for transferring this info?
	 */
	a->doors = 4;
	a->engine->cylinders = 8;

	return a;	

fail3:
	kfree(e);
fail2:
	kfree(a);
fail1:
	return NULL;
}

/**
 * dealer_return_car
 * -----------------
 */
void dealer_return_car(struct automobile *a)
{
91
	int ret;
Charlie Jacobsen's avatar
Charlie Jacobsen committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
	/*
	 * Free on callee side
	 */
	lcd_store_r0(DEALER_RETURN_CAR);
	ret = lcd_call(CUSTOMER_DEALER_INTERFACE_CAP);
	if (ret) {
		LCD_ERR("call failed");
		goto fail;
	}
	if (lcd_r0()) {
		LCD_ERR("non zero ret val");
		goto fail;
	}

	kfree(a->engine);
	kfree(a);

	return;

111
fail:
Charlie Jacobsen's avatar
Charlie Jacobsen committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
	return;
}

/* MAIN EXEC LOOP -------------------------------------------------- */

int customer_start(void)
{
	int ret;
	/*
	 * Call customer init (will buy car)
	 */
	ret = __customer_init();
	if (ret) {
		LCD_ERR("customer init");
		return -1;
	}
	/*
	 * Now tear down
	 */
	lcd_store_r0(DEALER_DIE);
	ret = lcd_call(CUSTOMER_DEALER_INTERFACE_CAP);
	if (ret) {
		LCD_ERR("call failed");
		return ret;
	}

	return 0;
}
EXPORT_SYMBOL(customer_start);

int __init customer_init(void)
{
	return 0;
}

void __exit customer_exit(void)
{
	return;
}

module_init(customer_init);
module_exit(customer_exit);

155
#endif