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.


Deallocation bug fix in device manager to allow backing out from VM creation failure
[palacios.git] / palacios / include / palacios / vmm_dev_mgr.h
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) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.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 #ifndef _VMM_DEV_MGR
21 #define _VMM_DEV_MGR
22
23 #ifdef __V3VEE__
24
25 #include <palacios/vmm_types.h>
26 #include <palacios/vmm_list.h>
27 #include <palacios/vmm_string.h>
28 #include <palacios/vmm_hashtable.h>
29 #include <palacios/vmm_msr.h>
30 #include <palacios/vmm_config.h>
31
32 #ifdef V3_CONFIG_CHECKPOINT
33 #include <palacios/vmm_checkpoint.h>
34 #endif
35
36 struct v3_vm_info;
37
38 struct v3_device_ops;
39
40 typedef void * v3_dev_data_t;
41
42 struct vm_device;
43
44 struct vm_device {
45     char name[32];
46   
47     void * private_data;
48
49     struct v3_device_ops * ops;
50
51     struct v3_vm_info * vm;
52
53     struct list_head dev_link;
54
55     uint_t num_res_hooks;
56     struct list_head res_hooks;
57 };
58
59
60 struct vmm_dev_mgr {
61     int    inited;
62     uint_t num_devs;
63     struct list_head dev_list;
64     struct hashtable * dev_table;
65
66     struct list_head blk_list;
67     struct hashtable * blk_table;
68
69     struct list_head net_list;
70     struct hashtable * net_table;
71
72     struct list_head char_list;
73     struct hashtable * char_table;
74
75     struct list_head cons_list;
76     struct hashtable * cons_table;
77
78 };
79
80 int v3_create_device(struct v3_vm_info * vm, const char * dev_name, v3_cfg_tree_t * cfg);
81
82 struct vm_device * v3_find_dev(struct v3_vm_info * info, const char * dev_name);
83
84
85 // Registration of devices
86
87 //
88 // The following device manager functions should only be called
89 // when the guest is stopped
90 //
91
92
93
94 int v3_init_dev_mgr(struct v3_vm_info * vm);
95 int v3_deinit_dev_mgr(struct v3_vm_info * vm);
96
97 int v3_free_vm_devices(struct v3_vm_info * vm);
98
99 #ifdef V3_CONFIG_CHECKPOINT
100 int v3_save_vm_devices(struct v3_vm_info * vm, struct v3_chkpt * chkpt);
101 int v3_load_vm_devices(struct v3_vm_info * vm, struct v3_chkpt * chkpt);
102 #endif
103
104
105
106 int V3_init_devices();
107 int V3_deinit_devices();
108
109
110 struct v3_device_ops {
111     int (*free)(void * private_data);
112
113 #ifdef V3_CONFIG_CHECKPOINT
114   /*
115     Both the base and extended save/load functions are optional.
116     If save_extended is defined, then it will be called in
117     preference to save.  The idea is that with "save", the caller
118     opens the context using the name of the device, and expects
119     the callee to write it and then return.  With "save_extended"
120     the caller passes the checkpoint store and the device name
121     to the callee.  The callee is then expected to open 
122     contexts as desired, write to them, and then close them 
123     before returning.  Load and load/extended are symmetric. 
124   */
125     
126   int (*save)(struct v3_chkpt_ctx * ctx, void * private_data);
127   int (*load)(struct v3_chkpt_ctx * ctx, void * privata_data);
128   int (*save_extended)(struct v3_chkpt * chkpt, char * id, void * private_data);
129   int (*load_extended)(struct v3_chkpt * chkpt, char * id, void * privata_data);
130 #endif
131 };
132
133
134
135
136
137
138 int v3_dev_hook_io(struct vm_device   * dev,
139                    uint16_t            port,
140                    int (*read)(struct guest_info * core, uint16_t port, void * dst, uint_t length, void * priv_data),
141                    int (*write)(struct guest_info * core, uint16_t port, void * src, uint_t length, void * priv_data));
142
143 int v3_dev_unhook_io(struct vm_device   * dev,
144                      uint16_t            port);
145
146
147 int v3_dev_hook_msr(struct vm_device * dev, 
148                     uint32_t           msr,
149                     int (*read)(struct guest_info * core, uint32_t msr, struct v3_msr * dst, void * priv_data), 
150                     int (*write)(struct guest_info * core, uint32_t msr, struct v3_msr src, void * priv_data));
151
152 int v3_dev_unhook_msr(struct vm_device * dev, 
153                       uint32_t msr);
154             
155
156
157
158 struct vm_device * v3_add_device(struct v3_vm_info * vm, char * name, 
159                                  struct v3_device_ops * ops, void * private_data);
160 int v3_remove_device(struct vm_device * dev);
161
162
163 int v3_attach_device(struct v3_vm_info * vm, struct vm_device * dev);
164 int v3_detach_device(struct vm_device * dev);
165 struct vm_device * v3_allocate_device(char * name, struct v3_device_ops * ops, void * private_data);
166
167
168 struct v3_device_info {
169     char * name;
170     int (*init)(struct v3_vm_info * info, v3_cfg_tree_t * cfg);
171 };
172
173
174 #define device_register(name, init_dev_fn)                              \
175     static char _v3_device_name[] = name;                               \
176     static struct v3_device_info _v3_device                             \
177     __attribute__((__used__))                                           \
178         __attribute__((unused, __section__ ("_v3_devices"),             \
179                        aligned(sizeof(addr_t))))                        \
180         = {_v3_device_name , init_dev_fn};
181
182
183
184
185 void v3_print_dev_mgr(struct v3_vm_info * vm);
186
187
188 struct v3_dev_blk_ops {
189     uint64_t (*get_capacity)(void * private_data);
190     // Reads always operate on 2048 byte blocks
191
192     // how does this signal bytes_read < requested but not error? 
193
194     int (*read)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
195     int (*write)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
196 };
197
198
199 struct v3_dev_net_ops_cfg{
200     void * frontend_data; 
201     char * fnt_mac;
202     int quote;
203     int poll;  /* need poll? */
204 };
205
206 struct v3_dev_net_ops {
207     /* Backend implemented functions */
208     int (*send)(uint8_t * buf, uint32_t len, void * private_data);
209
210     /* Frontend implemented functions */
211     int (*recv)(uint8_t * buf, uint32_t len, void * frnt_data);
212     int (*poll)(int quote, void * frnt_data);
213
214     /* This is ugly... */
215     struct v3_dev_net_ops_cfg config;
216 };
217
218 struct v3_dev_console_ops {
219     int (*update_screen)(uint_t x, uint_t y, uint_t length, uint8_t * fb_data, void * private_data);
220     int (*update_cursor)(uint_t x, uint_t y, void * private_data);
221     int (*scroll)(int rows, void * private_data);
222     int (*set_text_resolution)(int cols, int rows, void * private_data);
223
224     /* frontend implemented functions */
225     int (*get_screen)(uint_t x, uint_t y, uint_t length, void * frontend_data);
226     void * push_fn_arg;
227 };
228
229 struct v3_dev_char_ops {
230     /* Backend implemented functions */
231     sint64_t (*output)(uint8_t * buf, sint64_t len, void * private_data);
232     //  int (*read)(uint8_t * buf, uint64_t len, void * private_data);
233
234     /* Frontend Implemented functions */
235     sint64_t (*input)(struct v3_vm_info * vm, uint8_t * buf, sint64_t len, void * private_data);
236 };
237
238
239 int v3_dev_add_blk_frontend(struct v3_vm_info * vm, 
240                             char * name, 
241                             int (*connect)(struct v3_vm_info * vm, 
242                                             void * frontend_data, 
243                                             struct v3_dev_blk_ops * ops, 
244                                             v3_cfg_tree_t * cfg, 
245                                             void * private_data), 
246                             void * priv_data);
247
248 int v3_dev_connect_blk(struct v3_vm_info * vm, 
249                        char * frontend_name, 
250                        struct v3_dev_blk_ops * ops, 
251                        v3_cfg_tree_t * cfg, 
252                        void * private_data);
253
254 int v3_dev_add_net_frontend(struct v3_vm_info * vm, 
255                             char * name, 
256                             int (*connect)(struct v3_vm_info * vm, 
257                                             void * frontend_data, 
258                                             struct v3_dev_net_ops * ops, 
259                                             v3_cfg_tree_t * cfg, 
260                                             void * private_data), 
261                             void * priv_data);
262
263 int v3_dev_connect_net(struct v3_vm_info * vm, 
264                        char * frontend_name, 
265                        struct v3_dev_net_ops * ops, 
266                        v3_cfg_tree_t * cfg, 
267                        void * private_data);
268
269
270
271
272 int v3_dev_add_console_frontend(struct v3_vm_info * vm, 
273                                 char * name, 
274                                 int (*connect)(struct v3_vm_info * vm, 
275                                                void * frontend_data, 
276                                                struct v3_dev_console_ops * ops, 
277                                                v3_cfg_tree_t * cfg, 
278                                                void * private_data), 
279                                 void * priv_data);
280
281 int v3_dev_connect_console(struct v3_vm_info * vm, 
282                            char * frontend_name, 
283                            struct v3_dev_console_ops * ops, 
284                            v3_cfg_tree_t * cfg, 
285                            void * private_data);
286
287
288
289 int v3_dev_add_char_frontend(struct v3_vm_info * vm, 
290                              char * name, 
291                              int (*connect)(struct v3_vm_info * vm, 
292                                             void * frontend_data, 
293                                             struct v3_dev_char_ops * ops, 
294                                             v3_cfg_tree_t * cfg, 
295                                             void * private_data,
296                                             void ** push_fn_arg), 
297                              void * priv_data);
298
299 int v3_dev_connect_char(struct v3_vm_info * vm, 
300                         char * frontend_name, 
301                         struct v3_dev_char_ops * ops, 
302                         v3_cfg_tree_t * cfg, 
303                         void * private_data, 
304                         void ** push_fn_arg);
305
306
307 #endif // ! __V3VEE__
308
309 #endif