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.


added virtio console, finished the stream interface implementation, added v3_stream...
[palacios.git] / palacios / src / devices / char_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 <interfaces/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
28
29 struct stream_state {
30     struct v3_stream * stream;
31
32     struct v3_dev_char_ops char_ops;
33
34     struct v3_vm_info * vm;
35
36     void * push_fn_arg;
37 };
38
39
40 static uint64_t  stream_input(struct v3_stream * stream, uint8_t * buf, uint64_t len) {
41     struct stream_state * state = stream->guest_stream_data;
42
43     return state->char_ops.input(state->vm, buf, len, state->push_fn_arg);
44
45 }
46
47 static uint64_t  stream_output(uint8_t * buf, uint64_t length, void * private_data) {
48     struct stream_state * state = (struct stream_state *)private_data;
49    
50     return v3_stream_output(state->stream, buf, length);
51 }
52
53 static int stream_free(struct stream_state * state) {
54     v3_stream_close(state->stream);
55
56     // detach host event
57
58     V3_Free(state);
59
60     return 0;
61 }
62
63
64 static struct v3_device_ops dev_ops = {
65     .free = (int (*)(void *))stream_free,
66 };
67
68 static int stream_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
69     char * dev_id = v3_cfg_val(cfg, "ID");
70     char * stream_name = v3_cfg_val(cfg, "name");
71     struct stream_state * state = NULL;
72
73     v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend");
74
75     state = (struct stream_state *)V3_Malloc(sizeof(struct stream_state));
76
77     if (state == NULL) {
78         PrintError("Could not allocate stream backend device\n");
79         return -1;
80     }
81
82     memset(state, 0, sizeof(struct stream_state));
83
84     struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, state);
85
86     if (dev == NULL) {
87         PrintError("Could not allocate device %s\n", dev_id);
88         V3_Free(state);
89         return -1;
90     }
91
92
93     state->stream = v3_stream_open(vm, stream_name, stream_input, state);
94
95     if (state->stream == NULL) {
96         PrintError("Could not open stream %s\n", stream_name);
97         v3_remove_device(dev);
98         return -1;
99     }
100
101     state->vm = vm;
102     state->char_ops.output = stream_output;
103
104     if (v3_dev_connect_char(vm, v3_cfg_val(frontend_cfg, "tag"), 
105                             &(state->char_ops), frontend_cfg, 
106                             state, &(state->push_fn_arg)) == -1) {
107         PrintError("Could not connect %s to frontend %s\n", 
108                    dev_id, v3_cfg_val(frontend_cfg, "tag"));
109         v3_remove_device(dev);
110         return -1;
111     }
112
113
114
115     return 0;
116 }
117
118 device_register("CHAR_STREAM", stream_init);