2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2010, Peter Dinda <pdinda@northwestern.edu>
11 * Copyright (c) 2010, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Peter Dinda <pdinda@northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
20 #include <palacios/vmm.h>
21 #include <palacios/vmm_stream.h>
22 #include <palacios/vmm_dev_mgr.h>
23 #include <palacios/vmm_sprintf.h>
24 #include <palacios/vmm_host_events.h>
25 #include <palacios/vmm_lock.h>
26 #include <palacios/vmm_string.h>
32 struct v3_dev_char_ops char_ops;
39 static int stream_write(uint8_t * buf, uint64_t length, void * private_data)
41 struct stream_state *state = (struct stream_state *)private_data;
43 return v3_stream_write(state->stream, buf, length);
48 static struct v3_device_ops dev_ops = {
55 static int stream_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg)
57 char * dev_id = v3_cfg_val(cfg, "ID");
58 char * stream_name = v3_cfg_val(cfg, "name");
59 struct stream_state * state = NULL;
61 v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend");
64 state = (struct stream_state *)V3_Malloc(sizeof(struct stream_state));
67 PrintError("Could not allocate stream backend device\n");
71 memset(state, 0, sizeof(struct stream_state));
73 state->stream = v3_stream_open(vm, stream_name);
75 if (state->stream == NULL) {
76 PrintError("Could not open stream %s\n", stream_name);
81 state->char_ops.write = stream_write;
83 struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, state);
86 PrintError("Could not allocate device %s\n", dev_id);
90 if (v3_attach_device(vm, dev) == -1) {
91 PrintError("Could not attach device %s\n", dev_id);
96 if (v3_dev_connect_char(vm, v3_cfg_val(frontend_cfg, "tag"),
97 &(state->char_ops), frontend_cfg,
98 state, &(state->push_fn_arg)) == -1) {
99 PrintError("Could not connect %s to frontend %s\n",
100 dev_id, v3_cfg_val(frontend_cfg, "tag"));
109 device_register("CHAR_STREAM", stream_init)