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.


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