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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
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.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
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>
33 #ifdef V3_CONFIG_CHECKPOINT
34 #include <palacios/vmm_checkpoint.h>
41 typedef void * v3_dev_data_t;
50 struct v3_device_ops * ops;
52 struct v3_vm_info * vm;
54 struct list_head dev_link;
57 struct list_head res_hooks;
63 struct list_head dev_list;
64 struct hashtable * dev_table;
66 struct list_head blk_list;
67 struct hashtable * blk_table;
69 struct list_head net_list;
70 struct hashtable * net_table;
72 struct list_head char_list;
73 struct hashtable * char_table;
75 struct list_head cons_list;
76 struct hashtable * cons_table;
80 int v3_create_device(struct v3_vm_info * vm, const char * dev_name, v3_cfg_tree_t * cfg);
82 struct vm_device * v3_find_dev(struct v3_vm_info * info, const char * dev_name);
85 // Registration of devices
88 // The following device manager functions should only be called
89 // when the guest is stopped
94 int v3_init_dev_mgr(struct v3_vm_info * vm);
95 int v3_deinit_dev_mgr(struct v3_vm_info * vm);
97 int v3_free_vm_devices(struct v3_vm_info * vm);
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);
106 int V3_init_devices();
107 int V3_deinit_devices();
110 struct v3_device_ops {
111 int (*free)(void * private_data);
113 #ifdef V3_CONFIG_CHECKPOINT
114 int (*save)(struct v3_chkpt_ctx * ctx, void * private_data);
115 int (*load)(struct v3_chkpt_ctx * ctx, void * privata_data);
124 int v3_dev_hook_io(struct vm_device * dev,
126 int (*read)(struct guest_info * core, uint16_t port, void * dst, uint_t length, void * priv_data),
127 int (*write)(struct guest_info * core, uint16_t port, void * src, uint_t length, void * priv_data));
129 int v3_dev_unhook_io(struct vm_device * dev,
133 int v3_dev_hook_msr(struct vm_device * dev,
135 int (*read)(struct guest_info * core, uint32_t msr, struct v3_msr * dst, void * priv_data),
136 int (*write)(struct guest_info * core, uint32_t msr, struct v3_msr src, void * priv_data));
138 int v3_dev_unhook_msr(struct vm_device * dev,
144 struct vm_device * v3_add_device(struct v3_vm_info * vm, char * name,
145 struct v3_device_ops * ops, void * private_data);
146 int v3_remove_device(struct vm_device * dev);
149 int v3_attach_device(struct v3_vm_info * vm, struct vm_device * dev);
150 int v3_detach_device(struct vm_device * dev);
151 struct vm_device * v3_allocate_device(char * name, struct v3_device_ops * ops, void * private_data);
154 struct v3_device_info {
156 int (*init)(struct v3_vm_info * info, v3_cfg_tree_t * cfg);
160 #define device_register(name, init_dev_fn) \
161 static char _v3_device_name[] = name; \
162 static struct v3_device_info _v3_device \
163 __attribute__((__used__)) \
164 __attribute__((unused, __section__ ("_v3_devices"), \
165 aligned(sizeof(addr_t)))) \
166 = {_v3_device_name , init_dev_fn};
171 void v3_print_dev_mgr(struct v3_vm_info * vm);
174 struct v3_dev_blk_ops {
175 uint64_t (*get_capacity)(void * private_data);
176 // Reads always operate on 2048 byte blocks
177 int (*read)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
178 int (*write)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
182 struct v3_dev_net_ops_cfg{
183 void * frontend_data;
186 int poll; /* need poll? */
189 struct v3_dev_net_ops {
190 /* Backend implemented functions */
191 int (*send)(uint8_t * buf, uint32_t len, void * private_data);
193 /* Frontend implemented functions */
194 int (*recv)(uint8_t * buf, uint32_t len, void * frnt_data);
195 int (*poll)(int quote, void * frnt_data);
197 /* This is ugly... */
198 struct v3_dev_net_ops_cfg config;
201 struct v3_dev_console_ops {
202 int (*update_screen)(uint_t x, uint_t y, uint_t length, uint8_t * fb_data, void * private_data);
203 int (*update_cursor)(uint_t x, uint_t y, void * private_data);
204 int (*scroll)(int rows, void * private_data);
205 int (*set_text_resolution)(int cols, int rows, void * private_data);
207 /* frontend implemented functions */
208 int (*get_screen)(uint_t x, uint_t y, uint_t length, void * frontend_data);
212 struct v3_dev_char_ops {
213 /* Backend implemented functions */
214 uint64_t (*output)(uint8_t * buf, uint64_t len, void * private_data);
215 // int (*read)(uint8_t * buf, uint64_t len, void * private_data);
217 /* Frontend Implemented functions */
218 uint64_t (*input)(struct v3_vm_info * vm, uint8_t * buf, uint64_t len, void * private_data);
222 int v3_dev_add_blk_frontend(struct v3_vm_info * vm,
224 int (*connect)(struct v3_vm_info * vm,
225 void * frontend_data,
226 struct v3_dev_blk_ops * ops,
228 void * private_data),
231 int v3_dev_connect_blk(struct v3_vm_info * vm,
232 char * frontend_name,
233 struct v3_dev_blk_ops * ops,
235 void * private_data);
237 int v3_dev_add_net_frontend(struct v3_vm_info * vm,
239 int (*connect)(struct v3_vm_info * vm,
240 void * frontend_data,
241 struct v3_dev_net_ops * ops,
243 void * private_data),
246 int v3_dev_connect_net(struct v3_vm_info * vm,
247 char * frontend_name,
248 struct v3_dev_net_ops * ops,
250 void * private_data);
255 int v3_dev_add_console_frontend(struct v3_vm_info * vm,
257 int (*connect)(struct v3_vm_info * vm,
258 void * frontend_data,
259 struct v3_dev_console_ops * ops,
261 void * private_data),
264 int v3_dev_connect_console(struct v3_vm_info * vm,
265 char * frontend_name,
266 struct v3_dev_console_ops * ops,
268 void * private_data);
272 int v3_dev_add_char_frontend(struct v3_vm_info * vm,
274 int (*connect)(struct v3_vm_info * vm,
275 void * frontend_data,
276 struct v3_dev_char_ops * ops,
279 void ** push_fn_arg),
282 int v3_dev_connect_char(struct v3_vm_info * vm,
283 char * frontend_name,
284 struct v3_dev_char_ops * ops,
287 void ** push_fn_arg);
290 #endif // ! __V3VEE__