| 
									
										
										
										
											2010-03-17 13:08:17 +02:00
										 |  |  | #ifndef VHOST_H
 | 
					
						
							|  |  |  | #define VHOST_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "hw/hw.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-27 15:05:35 +03:00
										 |  |  | #include "hw/virtio/vhost-backend.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-05 17:06:20 +01:00
										 |  |  | #include "hw/virtio/virtio.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-17 18:19:49 +01:00
										 |  |  | #include "exec/memory.h"
 | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Generic structures common for any vhost based device. */ | 
					
						
							|  |  |  | struct vhost_virtqueue { | 
					
						
							|  |  |  |     int kick; | 
					
						
							|  |  |  |     int call; | 
					
						
							|  |  |  |     void *desc; | 
					
						
							|  |  |  |     void *avail; | 
					
						
							|  |  |  |     void *used; | 
					
						
							|  |  |  |     int num; | 
					
						
							|  |  |  |     unsigned long long used_phys; | 
					
						
							|  |  |  |     unsigned used_size; | 
					
						
							|  |  |  |     void *ring; | 
					
						
							|  |  |  |     unsigned long long ring_phys; | 
					
						
							|  |  |  |     unsigned ring_size; | 
					
						
							| 
									
										
										
										
											2012-12-24 17:37:01 +02:00
										 |  |  |     EventNotifier masked_notifier; | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:17 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef unsigned long vhost_log_chunk_t; | 
					
						
							|  |  |  | #define VHOST_LOG_PAGE 0x1000
 | 
					
						
							|  |  |  | #define VHOST_LOG_BITS (8 * sizeof(vhost_log_chunk_t))
 | 
					
						
							|  |  |  | #define VHOST_LOG_CHUNK (VHOST_LOG_PAGE * VHOST_LOG_BITS)
 | 
					
						
							| 
									
										
										
										
											2014-05-27 15:04:42 +03:00
										 |  |  | #define VHOST_INVALID_FEATURE_BIT   (0xff)
 | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 05:28:46 -04:00
										 |  |  | struct vhost_log { | 
					
						
							|  |  |  |     unsigned long long size; | 
					
						
							|  |  |  |     int refcnt; | 
					
						
							|  |  |  |     vhost_log_chunk_t log[0]; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:17 +02:00
										 |  |  | struct vhost_memory; | 
					
						
							|  |  |  | struct vhost_dev { | 
					
						
							| 
									
										
										
										
											2011-12-18 14:06:05 +02:00
										 |  |  |     MemoryListener memory_listener; | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:17 +02:00
										 |  |  |     struct vhost_memory *mem; | 
					
						
							| 
									
										
										
										
											2011-12-19 13:18:13 +02:00
										 |  |  |     int n_mem_sections; | 
					
						
							|  |  |  |     MemoryRegionSection *mem_sections; | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:17 +02:00
										 |  |  |     struct vhost_virtqueue *vqs; | 
					
						
							|  |  |  |     int nvqs; | 
					
						
							| 
									
										
										
										
											2015-03-26 12:10:29 +01:00
										 |  |  |     /* the first virtqueue which would be used by this vhost dev */ | 
					
						
							| 
									
										
										
										
											2013-01-30 19:12:35 +08:00
										 |  |  |     int vq_index; | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:17 +02:00
										 |  |  |     unsigned long long features; | 
					
						
							|  |  |  |     unsigned long long acked_features; | 
					
						
							|  |  |  |     unsigned long long backend_features; | 
					
						
							|  |  |  |     bool started; | 
					
						
							|  |  |  |     bool log_enabled; | 
					
						
							|  |  |  |     unsigned long long log_size; | 
					
						
							| 
									
										
										
										
											2014-06-18 17:20:42 +03:00
										 |  |  |     Error *migration_blocker; | 
					
						
							| 
									
										
										
										
											2011-02-01 22:13:42 +02:00
										 |  |  |     bool force; | 
					
						
							| 
									
										
										
										
											2013-04-03 09:15:11 +00:00
										 |  |  |     bool memory_changed; | 
					
						
							|  |  |  |     hwaddr mem_changed_start_addr; | 
					
						
							|  |  |  |     hwaddr mem_changed_end_addr; | 
					
						
							| 
									
										
										
										
											2014-05-27 15:05:35 +03:00
										 |  |  |     const VhostOps *vhost_ops; | 
					
						
							| 
									
										
										
										
											2014-05-27 15:05:49 +03:00
										 |  |  |     void *opaque; | 
					
						
							| 
									
										
										
										
											2015-06-04 05:28:46 -04:00
										 |  |  |     struct vhost_log *log; | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:17 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-27 15:05:22 +03:00
										 |  |  | int vhost_dev_init(struct vhost_dev *hdev, void *opaque, | 
					
						
							| 
									
										
										
										
											2014-05-27 15:05:49 +03:00
										 |  |  |                    VhostBackendType backend_type, bool force); | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:17 +02:00
										 |  |  | void vhost_dev_cleanup(struct vhost_dev *hdev); | 
					
						
							| 
									
										
										
										
											2011-02-01 22:13:42 +02:00
										 |  |  | bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev); | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:17 +02:00
										 |  |  | int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev); | 
					
						
							|  |  |  | void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev); | 
					
						
							| 
									
										
										
										
											2011-08-11 10:21:18 +03:00
										 |  |  | int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); | 
					
						
							|  |  |  | void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev); | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-24 17:37:01 +02:00
										 |  |  | /* Test and clear masked event pending status.
 | 
					
						
							|  |  |  |  * Should be called after unmask to avoid losing events. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | bool vhost_virtqueue_pending(struct vhost_dev *hdev, int n); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Mask/unmask events from this vq.
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void vhost_virtqueue_mask(struct vhost_dev *hdev, VirtIODevice *vdev, int n, | 
					
						
							|  |  |  |                           bool mask); | 
					
						
							| 
									
										
										
										
											2014-05-27 15:04:42 +03:00
										 |  |  | unsigned vhost_get_features(struct vhost_dev *hdev, const int *feature_bits, | 
					
						
							|  |  |  |         unsigned features); | 
					
						
							|  |  |  | void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits, | 
					
						
							|  |  |  |         unsigned features); | 
					
						
							| 
									
										
										
										
											2010-03-17 13:08:17 +02:00
										 |  |  | #endif
 |