X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fchar_stream.c;h=2bde1818ba72d5a3c24d8543ce6c0c6d031577c5;hb=64cc3bfb45f88a1880331093e87035a38c8f2bdb;hp=be723992a6cd26b27fac052108ab3c13af000279;hpb=72420d58d18ec71d4777d029daaf0c6a1c820b32;p=palacios.git diff --git a/palacios/src/devices/char_stream.c b/palacios/src/devices/char_stream.c index be72399..2bde181 100644 --- a/palacios/src/devices/char_stream.c +++ b/palacios/src/devices/char_stream.c @@ -18,7 +18,7 @@ */ #include -#include +#include #include #include #include @@ -27,35 +27,30 @@ struct stream_state { - v3_stream_t stream; + struct v3_stream * stream; struct v3_dev_char_ops char_ops; + struct v3_vm_info * vm; + void * push_fn_arg; }; -static int serial_event_handler(struct v3_vm_info * vm, - struct v3_serial_event * evt, - void * private_data) { - struct stream_state * state = (struct stream_state *)private_data; +static uint64_t stream_input(struct v3_stream * stream, uint8_t * buf, uint64_t len) { + struct stream_state * state = stream->guest_stream_data; - if (state->char_ops.push != NULL){ - state->char_ops.push(vm, evt->data, evt->len, state->push_fn_arg); - } + return state->char_ops.input(state->vm, buf, len, state->push_fn_arg); - return 0; } -static int stream_write(uint8_t * buf, uint64_t length, void * private_data) { +static uint64_t stream_output(uint8_t * buf, uint64_t length, void * private_data) { struct stream_state * state = (struct stream_state *)private_data; - - return v3_stream_write(state->stream, buf, length); + + return v3_stream_output(state->stream, buf, length); } -static int stream_free(struct vm_device * dev) { - struct stream_state * state = (struct stream_state *)(dev->private_data); - +static int stream_free(struct stream_state * state) { v3_stream_close(state->stream); // detach host event @@ -67,7 +62,7 @@ static int stream_free(struct vm_device * dev) { static struct v3_device_ops dev_ops = { - .free = stream_free, + .free = (int (*)(void *))stream_free, }; static int stream_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { @@ -95,8 +90,7 @@ static int stream_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { } - - state->stream = v3_stream_open(vm, stream_name); + state->stream = v3_stream_open(vm, stream_name, stream_input, state); if (state->stream == NULL) { PrintError("Could not open stream %s\n", stream_name); @@ -104,7 +98,8 @@ static int stream_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { return -1; } - state->char_ops.write = stream_write; + state->vm = vm; + state->char_ops.output = stream_output; if (v3_dev_connect_char(vm, v3_cfg_val(frontend_cfg, "tag"), &(state->char_ops), frontend_cfg, @@ -115,7 +110,7 @@ static int stream_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { return -1; } - v3_hook_host_event(vm, HOST_SERIAL_EVT, V3_HOST_EVENT_HANDLER(serial_event_handler), state); + return 0; }