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>
27 #include <devices/serial.h>
32 struct vm_device *frontend_dev;
36 static int stream_read(char *buf, uint_t length, void *private_data)
38 struct vm_device *dev = (struct vm_device *) private_data;
39 struct stream_state *state = (struct stream_state *) dev->private_data;
41 return V3_StreamRead(state->stream,buf,length);
44 static int stream_write(char *buf, uint_t length, void *private_data)
46 struct vm_device *dev = (struct vm_device *) private_data;
47 struct stream_state *state = (struct stream_state *) dev->private_data;
49 return V3_StreamWrite(state->stream,buf,length);
54 static struct v3_stream_ops stream_ops = {
55 .write = stream_write,
59 static struct v3_device_ops dev_ops = {
66 static int stream_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg)
68 v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend");
69 const char * frontend_tag = v3_cfg_val(frontend_cfg, "tag");
70 struct vm_device * frontend = v3_find_dev(vm, frontend_tag);
71 char * dev_id = v3_cfg_val(cfg, "ID");
72 char * path = v3_cfg_val(cfg, "localname");
73 struct stream_state *state;
75 /* read configuration */
76 V3_ASSERT(frontend_cfg);
77 V3_ASSERT(frontend_tag);
82 state = (struct stream_state *)V3_Malloc(sizeof(struct stream_state));
84 state->frontend_dev = frontend;
87 /* The system is responsible for interpreting the localname of the stream */
88 state->stream = V3_StreamOpen(path, STREAM_OPEN_MODE_READ | STREAM_OPEN_MODE_WRITE);
90 PrintError("Could not open localname %s\n", path);
96 struct vm_device *dev = v3_allocate_device(dev_id, &dev_ops, state);
99 /* attach device to virtual machine */
100 if (v3_attach_device(vm, dev) == -1) {
101 PrintError("Could not attach device %s\n", dev_id);
106 v3_stream_register_serial(frontend, &stream_ops, dev);
111 device_register("STREAM", stream_init)