Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


virtual console works with stream-serial implementation
[palacios.git] / palacios / src / devices / stream.c
1 /* 
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.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2010, Peter Dinda <pdinda@northwestern.edu>
11  * Copyright (c) 2010, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Peter Dinda <pdinda@northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
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>
28
29 struct stream_state {
30     void *stream_in;
31     void *stream_out;
32     struct vm_device *frontend_dev;
33     struct v3_stream_ops stream_ops;
34 };
35
36 static int stream_read(char *buf, uint_t length, void *private_data) 
37 {
38     struct vm_device *dev = (struct vm_device *) private_data;
39     struct stream_state *state = (struct stream_state *) dev->private_data;
40     
41     return V3_StreamRead(state->stream_out,buf,length);
42 }
43
44 static int stream_write(char *buf, uint_t length, void *private_data) 
45 {
46     struct vm_device *dev = (struct vm_device *) private_data;
47     struct stream_state *state = (struct stream_state *) dev->private_data;
48     
49     return V3_StreamWrite(state->stream_out,buf,length);
50 }
51
52
53 static void notify(void * data){
54     struct stream_state *state = (struct stream_state *)data;
55     char temp[1024];
56     int len;    
57         
58     len = V3_StreamRead(state->stream_in, temp, 1024);  
59     state->stream_ops.input(temp, len, state->stream_ops.front_data);
60 }
61
62 static struct v3_device_ops dev_ops = {
63     .free = NULL,
64     .reset = NULL,
65     .start = NULL,
66     .stop = NULL,
67 };
68
69 static int stream_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) 
70 {
71     v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend");
72     const char * frontend_tag = v3_cfg_val(frontend_cfg, "tag");
73     struct vm_device * frontend = v3_find_dev(vm, frontend_tag);
74     char * dev_id = v3_cfg_val(cfg, "ID");
75     char * stream_in = v3_cfg_val(cfg, "stream_in");
76     char * stream_out = v3_cfg_val(cfg, "stream_out");
77     struct stream_state *state;
78
79
80     V3_ASSERT(frontend_cfg);
81     V3_ASSERT(frontend_tag);
82     V3_ASSERT(frontend);
83     V3_ASSERT(stream_in);
84     V3_ASSERT(stream_out);
85
86     state = (struct stream_state *)V3_Malloc(sizeof(struct stream_state));
87     V3_ASSERT(state);
88     state->frontend_dev = frontend;
89
90     state->stream_out = V3_StreamOpen(stream_out, NULL, NULL, STREAM_OPEN_MODE_READ | STREAM_OPEN_MODE_WRITE);
91     state->stream_in = V3_StreamOpen(stream_in, notify, state, STREAM_OPEN_MODE_READ | STREAM_OPEN_MODE_WRITE);
92     if (!state->stream_out || !state->stream_in) {
93         PrintError("Could not open stream %s %s\n", stream_in, stream_out);
94         V3_Free(state);
95         return -1;
96     }
97         
98     struct vm_device *dev = v3_allocate_device(dev_id, &dev_ops, state);
99     V3_ASSERT(dev);
100
101     if (v3_attach_device(vm, dev) == -1) {
102         PrintError("Could not attach device %s\n", dev_id);
103         V3_Free(state);
104         return -1;
105     }
106
107     state->stream_ops.read = stream_read;
108     state->stream_ops.write = stream_write;
109
110     v3_stream_register_serial(frontend, &(state->stream_ops), dev);
111
112     return 0;
113 }
114
115 device_register("STREAM", stream_init)
116