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>
36 typedef void * v3_dev_data_t;
45 struct v3_device_ops * ops;
47 struct v3_vm_info * vm;
49 struct list_head dev_link;
53 struct list_head io_hooks;
59 struct list_head dev_list;
60 struct hashtable * dev_table;
62 struct list_head blk_list;
63 struct hashtable * blk_table;
65 struct list_head net_list;
66 struct hashtable * net_table;
68 struct list_head char_list;
69 struct hashtable * char_table;
71 struct list_head cons_list;
72 struct hashtable * cons_table;
76 int v3_create_device(struct v3_vm_info * vm, const char * dev_name, v3_cfg_tree_t * cfg);
78 struct vm_device * v3_find_dev(struct v3_vm_info * info, const char * dev_name);
81 // Registration of devices
84 // The following device manager functions should only be called
85 // when the guest is stopped
90 int v3_init_dev_mgr(struct v3_vm_info * vm);
91 int v3_dev_mgr_deinit(struct v3_vm_info * vm);
98 int v3_init_devices();
101 struct v3_device_ops {
102 int (*free)(struct vm_device * dev);
104 //int (*save)(struct vm_device *dev, struct *iostream);
105 //int (*restore)(struct vm_device *dev, struct *iostream);
113 int v3_dev_hook_io(struct vm_device * dev,
115 int (*read)(struct guest_info * core, ushort_t port, void * dst, uint_t length, void * priv_data),
116 int (*write)(struct guest_info * core, ushort_t port, void * src, uint_t length, void * priv_data));
118 int v3_dev_unhook_io(struct vm_device * dev,
123 struct vm_device * v3_add_device(struct v3_vm_info * vm, char * name,
124 struct v3_device_ops * ops, void * private_data);
125 int v3_remove_device(struct vm_device * dev);
128 int v3_attach_device(struct v3_vm_info * vm, struct vm_device * dev);
129 int v3_detach_device(struct vm_device * dev);
130 struct vm_device * v3_allocate_device(char * name, struct v3_device_ops * ops, void * private_data);
133 struct v3_device_info {
135 int (*init)(struct v3_vm_info * info, v3_cfg_tree_t * cfg);
139 #define device_register(name, init_dev_fn) \
140 static char _v3_device_name[] = name; \
141 static struct v3_device_info _v3_device \
142 __attribute__((__used__)) \
143 __attribute__((unused, __section__ ("_v3_devices"), \
144 aligned(sizeof(addr_t)))) \
145 = {_v3_device_name , init_dev_fn};
150 void v3_print_dev_mgr(struct v3_vm_info * vm);
153 struct v3_dev_blk_ops {
154 uint64_t (*get_capacity)(void * private_data);
155 // Reads always operate on 2048 byte blocks
156 int (*read)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
157 int (*write)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
160 struct v3_dev_net_ops {
161 /* Backend implemented functions */
162 int (*send)(uint8_t * buf, uint32_t count, void * private_data);
163 void (*start_rx)(void * back_data);
164 void (*stop_rx)(void * back_data);
166 /* Frontend implemented functions */
167 int (*recv)(uint8_t * buf, uint32_t count, void * frnt_data);
168 void (*poll)(struct v3_vm_info * vm, void * frnt_data);
169 void (*start_tx)(void * frnt_data);
170 void (*stop_tx)(void * frnt_data);
172 /* This is ugly... */
173 void * frontend_data;
176 struct v3_dev_console_ops {
177 int (*update_screen)(uint_t x, uint_t y, uint_t length, uint8_t * fb_data, void * private_data);
178 int (*update_cursor)(uint_t x, uint_t y, void * private_data);
179 int (*scroll)(int rows, void * private_data);
181 /* frontend implemented functions */
182 int (*get_screen)(uint_t x, uint_t y, uint_t length, void * frontend_data);
186 struct v3_dev_char_ops {
187 /* Backend implemented functions */
188 int (*write)(uint8_t * buf, uint64_t len, void * private_data);
189 // int (*read)(uint8_t * buf, uint64_t len, void * private_data);
191 /* Frontend Implemented functions */
192 int (*push)(struct v3_vm_info * vm, uint8_t * buf, uint64_t len, void * private_data);
196 int v3_dev_add_blk_frontend(struct v3_vm_info * vm,
198 int (*connect)(struct v3_vm_info * vm,
199 void * frontend_data,
200 struct v3_dev_blk_ops * ops,
202 void * private_data),
205 int v3_dev_connect_blk(struct v3_vm_info * vm,
206 char * frontend_name,
207 struct v3_dev_blk_ops * ops,
209 void * private_data);
211 int v3_dev_add_net_frontend(struct v3_vm_info * vm,
213 int (*connect)(struct v3_vm_info * vm,
214 void * frontend_data,
215 struct v3_dev_net_ops * ops,
217 void * private_data),
220 int v3_dev_connect_net(struct v3_vm_info * vm,
221 char * frontend_name,
222 struct v3_dev_net_ops * ops,
224 void * private_data);
229 int v3_dev_add_console_frontend(struct v3_vm_info * vm,
231 int (*connect)(struct v3_vm_info * vm,
232 void * frontend_data,
233 struct v3_dev_console_ops * ops,
235 void * private_data),
238 int v3_dev_connect_console(struct v3_vm_info * vm,
239 char * frontend_name,
240 struct v3_dev_console_ops * ops,
242 void * private_data);
246 int v3_dev_add_char_frontend(struct v3_vm_info * vm,
248 int (*connect)(struct v3_vm_info * vm,
249 void * frontend_data,
250 struct v3_dev_char_ops * ops,
253 void ** push_fn_arg),
256 int v3_dev_connect_char(struct v3_vm_info * vm,
257 char * frontend_name,
258 struct v3_dev_char_ops * ops,
261 void ** push_fn_arg);
264 #endif // ! __V3VEE__