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_config.h>
30 #include <palacios/vmm_ethernet.h>
37 typedef void * v3_dev_data_t;
46 struct v3_device_ops * ops;
48 struct v3_vm_info * vm;
50 struct list_head dev_link;
54 struct list_head io_hooks;
60 struct list_head dev_list;
61 struct hashtable * dev_table;
63 struct list_head blk_list;
64 struct hashtable * blk_table;
66 struct list_head net_list;
67 struct hashtable * net_table;
69 struct list_head char_list;
70 struct hashtable * char_table;
72 struct list_head cons_list;
73 struct hashtable * cons_table;
77 int v3_create_device(struct v3_vm_info * vm, const char * dev_name, v3_cfg_tree_t * cfg);
79 struct vm_device * v3_find_dev(struct v3_vm_info * info, const char * dev_name);
82 // Registration of devices
85 // The following device manager functions should only be called
86 // when the guest is stopped
91 int v3_init_dev_mgr(struct v3_vm_info * vm);
92 int v3_deinit_dev_mgr(struct v3_vm_info * vm);
94 int v3_free_vm_devices(struct v3_vm_info * vm);
102 int V3_init_devices();
103 int V3_deinit_devices();
106 struct v3_device_ops {
107 int (*free)(void * private_data);
109 //int (*save)(struct vm_device *dev, struct *iostream);
110 //int (*restore)(struct vm_device *dev, struct *iostream);
118 int v3_dev_hook_io(struct vm_device * dev,
120 int (*read)(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data),
121 int (*write)(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data));
123 int v3_dev_unhook_io(struct vm_device * dev,
128 struct vm_device * v3_add_device(struct v3_vm_info * vm, char * name,
129 struct v3_device_ops * ops, void * private_data);
130 int v3_remove_device(struct vm_device * dev);
133 int v3_attach_device(struct v3_vm_info * vm, struct vm_device * dev);
134 int v3_detach_device(struct vm_device * dev);
135 struct vm_device * v3_allocate_device(char * name, struct v3_device_ops * ops, void * private_data);
138 struct v3_device_info {
140 int (*init)(struct v3_vm_info * info, v3_cfg_tree_t * cfg);
144 #define device_register(name, init_dev_fn) \
145 static char _v3_device_name[] = name; \
146 static struct v3_device_info _v3_device \
147 __attribute__((__used__)) \
148 __attribute__((unused, __section__ ("_v3_devices"), \
149 aligned(sizeof(addr_t)))) \
150 = {_v3_device_name , init_dev_fn};
155 void v3_print_dev_mgr(struct v3_vm_info * vm);
158 struct v3_dev_blk_ops {
159 uint64_t (*get_capacity)(void * private_data);
160 // Reads always operate on 2048 byte blocks
161 int (*read)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
162 int (*write)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
165 struct v3_dev_net_ops {
166 /* Backend implemented functions */
167 int (*send)(uint8_t * buf, uint32_t count, void * private_data);
168 void (*start_rx)(void * back_data);
169 void (*stop_rx)(void * back_data);
171 /* Frontend implemented functions */
172 int (*recv)(uint8_t * buf, uint32_t count, void * frnt_data);
173 void (*poll)(struct v3_vm_info * vm, void * frnt_data);
174 void (*start_tx)(void * frnt_data);
175 void (*stop_tx)(void * frnt_data);
177 /* This is ugly... */
178 void * frontend_data;
179 char fnt_mac[ETH_ALEN];
182 struct v3_dev_console_ops {
183 int (*update_screen)(uint_t x, uint_t y, uint_t length, uint8_t * fb_data, void * private_data);
184 int (*update_cursor)(uint_t x, uint_t y, void * private_data);
185 int (*scroll)(int rows, void * private_data);
186 int (*set_text_resolution)(int cols, int rows, void * private_data);
188 /* frontend implemented functions */
189 int (*get_screen)(uint_t x, uint_t y, uint_t length, void * frontend_data);
193 struct v3_dev_char_ops {
194 /* Backend implemented functions */
195 int (*write)(uint8_t * buf, uint64_t len, void * private_data);
196 // int (*read)(uint8_t * buf, uint64_t len, void * private_data);
198 /* Frontend Implemented functions */
199 int (*push)(struct v3_vm_info * vm, uint8_t * buf, uint64_t len, void * private_data);
203 int v3_dev_add_blk_frontend(struct v3_vm_info * vm,
205 int (*connect)(struct v3_vm_info * vm,
206 void * frontend_data,
207 struct v3_dev_blk_ops * ops,
209 void * private_data),
212 int v3_dev_connect_blk(struct v3_vm_info * vm,
213 char * frontend_name,
214 struct v3_dev_blk_ops * ops,
216 void * private_data);
218 int v3_dev_add_net_frontend(struct v3_vm_info * vm,
220 int (*connect)(struct v3_vm_info * vm,
221 void * frontend_data,
222 struct v3_dev_net_ops * ops,
224 void * private_data),
227 int v3_dev_connect_net(struct v3_vm_info * vm,
228 char * frontend_name,
229 struct v3_dev_net_ops * ops,
231 void * private_data);
236 int v3_dev_add_console_frontend(struct v3_vm_info * vm,
238 int (*connect)(struct v3_vm_info * vm,
239 void * frontend_data,
240 struct v3_dev_console_ops * ops,
242 void * private_data),
245 int v3_dev_connect_console(struct v3_vm_info * vm,
246 char * frontend_name,
247 struct v3_dev_console_ops * ops,
249 void * private_data);
253 int v3_dev_add_char_frontend(struct v3_vm_info * vm,
255 int (*connect)(struct v3_vm_info * vm,
256 void * frontend_data,
257 struct v3_dev_char_ops * ops,
260 void ** push_fn_arg),
263 int v3_dev_connect_char(struct v3_vm_info * vm,
264 char * frontend_name,
265 struct v3_dev_char_ops * ops,
268 void ** push_fn_arg);
271 #endif // ! __V3VEE__