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.


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