| 
									
										
										
										
											2008-12-04 20:33:06 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Virtio Support | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright IBM, Corp. 2007-2008 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Authors: | 
					
						
							|  |  |  |  *  Anthony Liguori   <aliguori@us.ibm.com> | 
					
						
							|  |  |  |  *  Rusty Russell     <rusty@rustcorp.com.au> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This work is licensed under the terms of the GNU GPL, version 2.  See | 
					
						
							|  |  |  |  * the COPYING file in the top-level directory. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 13:47:03 +02:00
										 |  |  | #ifndef QEMU_VIRTIO_BALLOON_H
 | 
					
						
							|  |  |  | #define QEMU_VIRTIO_BALLOON_H
 | 
					
						
							| 
									
										
										
										
											2008-12-04 20:33:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-16 22:35:52 +01:00
										 |  |  | #include "standard-headers/linux/virtio_balloon.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-05 17:06:20 +01:00
										 |  |  | #include "hw/virtio/virtio.h"
 | 
					
						
							| 
									
										
										
										
											2018-12-11 16:24:53 +08:00
										 |  |  | #include "sysemu/iothread.h"
 | 
					
						
							| 
									
										
										
										
											2020-09-03 16:43:22 -04:00
										 |  |  | #include "qom/object.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-04 20:33:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-09 12:04:48 +02:00
										 |  |  | #define TYPE_VIRTIO_BALLOON "virtio-balloon-device"
 | 
					
						
							| 
									
										
										
										
											2020-09-16 14:25:19 -04:00
										 |  |  | OBJECT_DECLARE_SIMPLE_TYPE(VirtIOBalloon, VIRTIO_BALLOON) | 
					
						
							| 
									
										
										
										
											2013-03-27 10:49:10 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 10:51:28 -07:00
										 |  |  | #define VIRTIO_BALLOON_FREE_PAGE_HINT_CMD_ID_MIN 0x80000000
 | 
					
						
							| 
									
										
										
										
											2018-12-11 16:24:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-16 22:35:52 +01:00
										 |  |  | typedef struct virtio_balloon_stat VirtIOBalloonStat; | 
					
						
							| 
									
										
										
										
											2010-01-26 14:17:35 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-04 12:34:31 +02:00
										 |  |  | typedef struct virtio_balloon_stat_modern { | 
					
						
							|  |  |  |        uint16_t tag; | 
					
						
							|  |  |  |        uint8_t reserved[6]; | 
					
						
							|  |  |  |        uint64_t val; | 
					
						
							|  |  |  | } VirtIOBalloonStatModern; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 10:51:28 -07:00
										 |  |  | enum virtio_balloon_free_page_hint_status { | 
					
						
							|  |  |  |     FREE_PAGE_HINT_S_STOP = 0, | 
					
						
							|  |  |  |     FREE_PAGE_HINT_S_REQUESTED = 1, | 
					
						
							|  |  |  |     FREE_PAGE_HINT_S_START = 2, | 
					
						
							|  |  |  |     FREE_PAGE_HINT_S_DONE = 3, | 
					
						
							| 
									
										
										
										
											2018-12-11 16:24:53 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 16:43:22 -04:00
										 |  |  | struct VirtIOBalloon { | 
					
						
							| 
									
										
										
										
											2013-03-27 10:49:14 +01:00
										 |  |  |     VirtIODevice parent_obj; | 
					
						
							| 
									
										
										
										
											2020-05-26 21:14:07 -07:00
										 |  |  |     VirtQueue *ivq, *dvq, *svq, *free_page_vq, *reporting_vq; | 
					
						
							| 
									
										
										
										
											2020-07-20 10:51:28 -07:00
										 |  |  |     uint32_t free_page_hint_status; | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:18 +01:00
										 |  |  |     uint32_t num_pages; | 
					
						
							|  |  |  |     uint32_t actual; | 
					
						
							| 
									
										
										
										
											2020-07-20 10:51:28 -07:00
										 |  |  |     uint32_t free_page_hint_cmd_id; | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:18 +01:00
										 |  |  |     uint64_t stats[VIRTIO_BALLOON_S_NR]; | 
					
						
							| 
									
										
										
										
											2016-02-04 16:26:51 +02:00
										 |  |  |     VirtQueueElement *stats_vq_elem; | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:18 +01:00
										 |  |  |     size_t stats_vq_offset; | 
					
						
							|  |  |  |     QEMUTimer *stats_timer; | 
					
						
							| 
									
										
										
										
											2018-12-11 16:24:53 +08:00
										 |  |  |     IOThread *iothread; | 
					
						
							|  |  |  |     QEMUBH *free_page_bh; | 
					
						
							|  |  |  |     /*
 | 
					
						
							|  |  |  |      * Lock to synchronize threads to access the free page reporting related | 
					
						
							| 
									
										
										
										
											2020-07-20 10:51:28 -07:00
										 |  |  |      * fields (e.g. free_page_hint_status). | 
					
						
							| 
									
										
										
										
											2018-12-11 16:24:53 +08:00
										 |  |  |      */ | 
					
						
							|  |  |  |     QemuMutex free_page_lock; | 
					
						
							|  |  |  |     QemuCond  free_page_cond; | 
					
						
							|  |  |  |     /*
 | 
					
						
							|  |  |  |      * Set to block iothread to continue reading free page hints as the VM is | 
					
						
							|  |  |  |      * stopped. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     bool block_iothread; | 
					
						
							| 
									
										
										
										
											2020-07-20 10:51:28 -07:00
										 |  |  |     NotifierWithReturn free_page_hint_notify; | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:18 +01:00
										 |  |  |     int64_t stats_last_update; | 
					
						
							|  |  |  |     int64_t stats_poll_interval; | 
					
						
							| 
									
										
										
										
											2015-06-15 13:52:52 +03:00
										 |  |  |     uint32_t host_features; | 
					
						
							| 
									
										
										
										
											2019-07-10 16:14:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool qemu_4_0_config_size; | 
					
						
							| 
									
										
										
										
											2020-05-26 21:14:00 -07:00
										 |  |  |     uint32_t poison_val; | 
					
						
							| 
									
										
										
										
											2020-09-03 16:43:22 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-03-18 17:37:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-04 20:33:06 +00:00
										 |  |  | #endif
 |