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>
42 struct v3_device_ops * ops;
44 struct guest_info * vm;
46 struct list_head dev_link;
50 struct list_head io_hooks;
56 struct list_head dev_list;
57 struct hashtable * dev_table;
59 struct list_head blk_list;
60 struct hashtable * blk_table;
62 struct list_head net_list;
63 struct hashtable * net_table;
65 struct list_head console_list;
66 struct hashtable * console_table;
73 int v3_create_device(struct guest_info * info, const char * dev_name, v3_cfg_tree_t * cfg);
74 void v3_free_device(struct vm_device * dev);
77 struct vm_device * v3_find_dev(struct guest_info * info, const char * dev_name);
80 // Registration of devices
83 // The following device manager functions should only be called
84 // when the guest is stopped
89 int v3_init_dev_mgr(struct guest_info * info);
90 int v3_dev_mgr_deinit(struct guest_info * info);
95 int v3_init_devices();
98 struct v3_device_ops {
99 int (*free)(struct vm_device *dev);
102 int (*reset)(struct vm_device *dev);
104 int (*start)(struct vm_device *dev);
105 int (*stop)(struct vm_device *dev);
108 //int (*save)(struct vm_device *dev, struct *iostream);
109 //int (*restore)(struct vm_device *dev, struct *iostream);
117 int v3_dev_hook_io(struct vm_device *dev,
119 int (*read)(ushort_t port, void * dst, uint_t length, struct vm_device * dev),
120 int (*write)(ushort_t port, void * src, uint_t length, struct vm_device * dev));
122 int v3_dev_unhook_io(struct vm_device *dev,
126 int v3_attach_device(struct guest_info * vm, struct vm_device * dev);
127 int v3_detach_device(struct vm_device * dev);
129 struct vm_device * v3_allocate_device(char * name, struct v3_device_ops * ops, void * private_data);
132 struct v3_device_info {
134 int (*init)(struct guest_info * info, v3_cfg_tree_t * cfg);
138 #define device_register(name, init_dev_fn) \
139 static char _v3_device_name[] = name; \
140 static struct v3_device_info _v3_device \
141 __attribute__((__used__)) \
142 __attribute__((unused, __section__ ("_v3_devices"), \
143 aligned(sizeof(addr_t)))) \
144 = {_v3_device_name , init_dev_fn};
149 void v3_print_dev_mgr(struct guest_info * info);
152 struct v3_dev_blk_ops {
153 uint64_t (*get_capacity)(void * private_data);
154 // Reads always operate on 2048 byte blocks
155 int (*read)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
156 int (*write)(uint8_t * buf, uint64_t lba, uint64_t num_bytes, void * private_data);
159 struct v3_dev_net_ops {
160 int (*send)(uint8_t * buf, uint32_t count, void * private_data, struct vm_device *dest_dev);
161 int (*receive)(uint8_t * buf, uint32_t count, void * private_data, struct vm_device *src_dev);
165 struct v3_dev_console_ops {
169 int v3_dev_add_blk_frontend(struct guest_info * info,
171 int (*connect)(struct guest_info * info,
172 void * frontend_data,
173 struct v3_dev_blk_ops * ops,
175 void * private_data),
177 int v3_dev_connect_blk(struct guest_info * info,
178 char * frontend_name,
179 struct v3_dev_blk_ops * ops,
181 void * private_data);
183 int v3_dev_add_net_frontend(struct guest_info * info,
185 int (*connect)(struct guest_info * info,
186 void * frontend_data,
187 struct v3_dev_net_ops * ops,
189 void * private_data),
192 int v3_dev_connect_net(struct guest_info * info,
193 char * frontend_name,
194 struct v3_dev_net_ops * ops,
196 void * private_data);
199 #endif // ! __V3VEE__