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.


Add dynamic VMM Driven/Guest Driven mode switch in VNET devices
[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 #include <palacios/vmm_ethernet.h>
32 #include <palacios/vmm_keyed_stream.h>
33
34 struct v3_vm_info;
35
36 struct v3_device_ops;
37
38 typedef void * v3_dev_data_t;
39
40 struct vm_device;
41
42 struct vm_device {
43     char name[32];
44   
45     void * private_data;
46
47     struct v3_device_ops * ops;
48
49     struct v3_vm_info * vm;
50
51     struct list_head dev_link;
52
53     uint_t num_res_hooks;
54     struct list_head res_hooks;
55 };
56
57
58 struct vmm_dev_mgr {
59     uint_t num_devs;
60     struct list_head dev_list;
61     struct hashtable * dev_table;
62
63     struct list_head blk_list;
64     struct hashtable * blk_table;
65
66     struct list_head net_list;
67     struct hashtable * net_table;
68
69     struct list_head char_list;
70     struct hashtable * char_table;
71
72     struct list_head cons_list;
73     struct hashtable * cons_table;
74
75 };
76
77 int v3_create_device(struct v3_vm_info * vm, const char * dev_name, v3_cfg_tree_t * cfg);
78
79 struct vm_device * v3_find_dev(struct v3_vm_info * info, const char * dev_name);
80
81
82 // Registration of devices
83
84 //
85 // The following device manager functions should only be called
86 // when the guest is stopped
87 //
88
89
90
91 int v3_init_dev_mgr(struct v3_vm_info * vm);
92 int v3_deinit_dev_mgr(struct v3_vm_info * vm);
93
94 int v3_free_vm_devices(struct v3_vm_info * vm);
95
96
97
98
99
100
101
102 int V3_init_devices();
103 int V3_deinit_devices();
104
105
106 struct v3_device_ops {
107     int (*free)(void * private_data);
108
109     int (*checkpoint)(struct vm_device *dev, v3_keyed_stream_t stream);
110     int (*restore)(struct vm_device *dev, v3_keyed_stream_t stream);
111 };
112
113
114
115
116
117
118 int v3_dev_hook_io(struct vm_device   * dev,
119                    uint16_t            port,
120                    int (*read)(struct guest_info * core, uint16_t port, void * dst, uint_t length, void * priv_data),
121                    int (*write)(struct guest_info * core, uint16_t port, void * src, uint_t length, void * priv_data));
122
123 int v3_dev_unhook_io(struct vm_device   * dev,
124                      uint16_t            port);
125
126
127 int v3_dev_hook_msr(struct vm_device * dev, 
128                     uint32_t           msr,
129                     int (*read)(struct guest_info * core, uint32_t msr, struct v3_msr * dst, void * priv_data), 
130                     int (*write)(struct guest_info * core, uint32_t msr, struct v3_msr src, void * priv_data));
131
132 int v3_dev_unhook_msr(struct vm_device * dev, 
133                       uint32_t msr);
134             
135
136
137
138 struct vm_device * v3_add_device(struct v3_vm_info * vm, char * name, 
139                                  struct v3_device_ops * ops, void * private_data);
140 int v3_remove_device(struct vm_device * dev);
141
142
143 int v3_attach_device(struct v3_vm_info * vm, struct vm_device * dev);
144 int v3_detach_device(struct vm_device * dev);
145 struct vm_device * v3_allocate_device(char * name, struct v3_device_ops * ops, void * private_data);
146
147
148 struct v3_device_info {
149     char * name;
150     int (*init)(struct v3_vm_info * info, v3_cfg_tree_t * cfg);
151 };
152
153
154 #define device_register(name, init_dev_fn)                              \
155     static char _v3_device_name[] = name;                               \
156     static struct v3_device_info _v3_device                             \
157     __attribute__((__used__))                                           \
158         __attribute__((unused, __section__ ("_v3_devices"),             \
159                        aligned(sizeof(addr_t))))                        \
160         = {_v3_device_name , init_dev_fn};
161
162
163
164
165 void v3_print_dev_mgr(struct v3_vm_info * vm);
166
167
168 struct v3_dev_blk_ops {
169     uint64_t (*get_capacity)(void * private_data);
170     // Reads always operate on 2048 byte blocks
171     int (*read)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
172     int (*write)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
173 };
174
175 struct v3_dev_net_ops {
176     /* Backend implemented functions */
177     int (*send)(uint8_t * buf, uint32_t count, void * private_data);
178
179     /* Frontend implemented functions */
180     int (*recv)(uint8_t * buf, uint32_t count, void * frnt_data);
181     void (*poll)(struct v3_vm_info * vm, int budget, void * frnt_data);
182
183     /* This is ugly... */
184     void * frontend_data; 
185     char fnt_mac[ETH_ALEN];
186 };
187
188 struct v3_dev_console_ops {
189     int (*update_screen)(uint_t x, uint_t y, uint_t length, uint8_t * fb_data, void * private_data);
190     int (*update_cursor)(uint_t x, uint_t y, void * private_data);
191     int (*scroll)(int rows, void * private_data);
192     int (*set_text_resolution)(int cols, int rows, void * private_data);
193
194     /* frontend implemented functions */
195     int (*get_screen)(uint_t x, uint_t y, uint_t length, void * frontend_data);
196     void * push_fn_arg;
197 };
198
199 struct v3_dev_char_ops {
200     /* Backend implemented functions */
201     int (*write)(uint8_t * buf, uint64_t len, void * private_data);
202     //  int (*read)(uint8_t * buf, uint64_t len, void * private_data);
203
204     /* Frontend Implemented functions */
205     int (*push)(struct v3_vm_info * vm, uint8_t * buf, uint64_t len, void * private_data);
206 };
207
208
209 int v3_dev_add_blk_frontend(struct v3_vm_info * vm, 
210                             char * name, 
211                             int (*connect)(struct v3_vm_info * vm, 
212                                             void * frontend_data, 
213                                             struct v3_dev_blk_ops * ops, 
214                                             v3_cfg_tree_t * cfg, 
215                                             void * private_data), 
216                             void * priv_data);
217
218 int v3_dev_connect_blk(struct v3_vm_info * vm, 
219                        char * frontend_name, 
220                        struct v3_dev_blk_ops * ops, 
221                        v3_cfg_tree_t * cfg, 
222                        void * private_data);
223
224 int v3_dev_add_net_frontend(struct v3_vm_info * vm, 
225                             char * name, 
226                             int (*connect)(struct v3_vm_info * vm, 
227                                             void * frontend_data, 
228                                             struct v3_dev_net_ops * ops, 
229                                             v3_cfg_tree_t * cfg, 
230                                             void * private_data), 
231                             void * priv_data);
232
233 int v3_dev_connect_net(struct v3_vm_info * vm, 
234                        char * frontend_name, 
235                        struct v3_dev_net_ops * ops, 
236                        v3_cfg_tree_t * cfg, 
237                        void * private_data);
238
239
240
241
242 int v3_dev_add_console_frontend(struct v3_vm_info * vm, 
243                                 char * name, 
244                                 int (*connect)(struct v3_vm_info * vm, 
245                                                void * frontend_data, 
246                                                struct v3_dev_console_ops * ops, 
247                                                v3_cfg_tree_t * cfg, 
248                                                void * private_data), 
249                                 void * priv_data);
250
251 int v3_dev_connect_console(struct v3_vm_info * vm, 
252                            char * frontend_name, 
253                            struct v3_dev_console_ops * ops, 
254                            v3_cfg_tree_t * cfg, 
255                            void * private_data);
256
257
258
259 int v3_dev_add_char_frontend(struct v3_vm_info * vm, 
260                              char * name, 
261                              int (*connect)(struct v3_vm_info * vm, 
262                                             void * frontend_data, 
263                                             struct v3_dev_char_ops * ops, 
264                                             v3_cfg_tree_t * cfg, 
265                                             void * private_data,
266                                             void ** push_fn_arg), 
267                              void * priv_data);
268
269 int v3_dev_connect_char(struct v3_vm_info * vm, 
270                         char * frontend_name, 
271                         struct v3_dev_char_ops * ops, 
272                         v3_cfg_tree_t * cfg, 
273                         void * private_data, 
274                         void ** push_fn_arg);
275
276
277 #endif // ! __V3VEE__
278
279 #endif