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.


restructured device manager deinitialization
[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_config.h>
30
31
32 struct v3_vm_info;
33
34 struct v3_device_ops;
35
36 typedef void * v3_dev_data_t;
37
38 struct vm_device;
39
40 struct vm_device {
41     char name[32];
42   
43     void * private_data;
44
45     struct v3_device_ops * ops;
46
47     struct v3_vm_info * vm;
48
49     struct list_head dev_link;
50
51
52     uint_t num_io_hooks;
53     struct list_head io_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
103
104
105 struct v3_device_ops {
106     int (*free)(void * private_data);
107
108     //int (*save)(struct vm_device *dev, struct *iostream);
109     //int (*restore)(struct vm_device *dev, struct *iostream);
110 };
111
112
113
114
115
116
117 int v3_dev_hook_io(struct vm_device   * dev,
118                    ushort_t            port,
119                    int (*read)(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data),
120                    int (*write)(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data));
121
122 int v3_dev_unhook_io(struct vm_device   * dev,
123                      ushort_t            port);
124
125
126
127 struct vm_device * v3_add_device(struct v3_vm_info * vm, char * name, 
128                                  struct v3_device_ops * ops, void * private_data);
129 int v3_remove_device(struct vm_device * dev);
130
131
132 int v3_attach_device(struct v3_vm_info * vm, struct vm_device * dev);
133 int v3_detach_device(struct vm_device * dev);
134 struct vm_device * v3_allocate_device(char * name, struct v3_device_ops * ops, void * private_data);
135
136
137 struct v3_device_info {
138     char * name;
139     int (*init)(struct v3_vm_info * info, v3_cfg_tree_t * cfg);
140 };
141
142
143 #define device_register(name, init_dev_fn)                              \
144     static char _v3_device_name[] = name;                               \
145     static struct v3_device_info _v3_device                             \
146     __attribute__((__used__))                                           \
147         __attribute__((unused, __section__ ("_v3_devices"),             \
148                        aligned(sizeof(addr_t))))                        \
149         = {_v3_device_name , init_dev_fn};
150
151
152
153
154 void v3_print_dev_mgr(struct v3_vm_info * vm);
155
156
157 struct v3_dev_blk_ops {
158     uint64_t (*get_capacity)(void * private_data);
159     // Reads always operate on 2048 byte blocks
160     int (*read)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
161     int (*write)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
162 };
163
164 struct v3_dev_net_ops {
165     /* Backend implemented functions */
166     int (*send)(uint8_t * buf, uint32_t count, void * private_data);
167     void (*start_rx)(void * back_data);
168     void (*stop_rx)(void * back_data);
169
170     /* Frontend implemented functions */
171     int (*recv)(uint8_t * buf, uint32_t count, void * frnt_data);
172     void (*poll)(struct v3_vm_info * vm, void * frnt_data);
173     void (*start_tx)(void * frnt_data);
174     void (*stop_tx)(void * frnt_data);
175
176     /* This is ugly... */
177     void * frontend_data; 
178 };
179
180 struct v3_dev_console_ops {
181     int (*update_screen)(uint_t x, uint_t y, uint_t length, uint8_t * fb_data, void * private_data);
182     int (*update_cursor)(uint_t x, uint_t y, void * private_data);
183     int (*scroll)(int rows, void * private_data);
184
185     /* frontend implemented functions */
186     int (*get_screen)(uint_t x, uint_t y, uint_t length, void * frontend_data);
187     void * push_fn_arg;
188 };
189
190 struct v3_dev_char_ops {
191     /* Backend implemented functions */
192     int (*write)(uint8_t * buf, uint64_t len, void * private_data);
193     //  int (*read)(uint8_t * buf, uint64_t len, void * private_data);
194
195     /* Frontend Implemented functions */
196     int (*push)(struct v3_vm_info * vm, uint8_t * buf, uint64_t len, void * private_data);
197 };
198
199
200 int v3_dev_add_blk_frontend(struct v3_vm_info * vm, 
201                             char * name, 
202                             int (*connect)(struct v3_vm_info * vm, 
203                                             void * frontend_data, 
204                                             struct v3_dev_blk_ops * ops, 
205                                             v3_cfg_tree_t * cfg, 
206                                             void * private_data), 
207                             void * priv_data);
208
209 int v3_dev_connect_blk(struct v3_vm_info * vm, 
210                        char * frontend_name, 
211                        struct v3_dev_blk_ops * ops, 
212                        v3_cfg_tree_t * cfg, 
213                        void * private_data);
214
215 int v3_dev_add_net_frontend(struct v3_vm_info * vm, 
216                             char * name, 
217                             int (*connect)(struct v3_vm_info * vm, 
218                                             void * frontend_data, 
219                                             struct v3_dev_net_ops * ops, 
220                                             v3_cfg_tree_t * cfg, 
221                                             void * private_data), 
222                             void * priv_data);
223
224 int v3_dev_connect_net(struct v3_vm_info * vm, 
225                        char * frontend_name, 
226                        struct v3_dev_net_ops * ops, 
227                        v3_cfg_tree_t * cfg, 
228                        void * private_data);
229
230
231
232
233 int v3_dev_add_console_frontend(struct v3_vm_info * vm, 
234                                 char * name, 
235                                 int (*connect)(struct v3_vm_info * vm, 
236                                                void * frontend_data, 
237                                                struct v3_dev_console_ops * ops, 
238                                                v3_cfg_tree_t * cfg, 
239                                                void * private_data), 
240                                 void * priv_data);
241
242 int v3_dev_connect_console(struct v3_vm_info * vm, 
243                            char * frontend_name, 
244                            struct v3_dev_console_ops * ops, 
245                            v3_cfg_tree_t * cfg, 
246                            void * private_data);
247
248
249
250 int v3_dev_add_char_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_char_ops * ops, 
255                                             v3_cfg_tree_t * cfg, 
256                                             void * private_data,
257                                             void ** push_fn_arg), 
258                              void * priv_data);
259
260 int v3_dev_connect_char(struct v3_vm_info * vm, 
261                         char * frontend_name, 
262                         struct v3_dev_char_ops * ops, 
263                         v3_cfg_tree_t * cfg, 
264                         void * private_data, 
265                         void ** push_fn_arg);
266
267
268 #endif // ! __V3VEE__
269
270 #endif