1 /* 2 * Copyright 2018, Jérôme Duval, jerome.duval@gmail.com. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef VIRTIO_BALLOON_PRIVATE_H 6 #define VIRTIO_BALLOON_PRIVATE_H 7 8 9 #include <condition_variable.h> 10 #include <lock.h> 11 #include <virtio.h> 12 #include <vm/vm_page.h> 13 14 15 //#define TRACE_VIRTIO_BALLOON 16 #ifdef TRACE_VIRTIO_BALLOON 17 # define TRACE(x...) dprintf("virtio_balloon: " x) 18 #else 19 # define TRACE(x...) ; 20 #endif 21 #define ERROR(x...) dprintf("\33[33mvirtio_rng:\33[0m " x) 22 #define CALLED() TRACE("CALLED %s\n", __PRETTY_FUNCTION__) 23 24 25 extern device_manager_info* gDeviceManager; 26 27 28 #define PAGES_COUNT 256 29 30 31 struct PageInfo : DoublyLinkedListLinkImpl<PageInfo> { 32 vm_page *page; 33 }; 34 35 36 typedef DoublyLinkedList<PageInfo> PageInfoList; 37 38 39 40 class VirtioBalloonDevice { 41 public: 42 VirtioBalloonDevice(device_node* node); 43 ~VirtioBalloonDevice(); 44 45 status_t InitCheck(); 46 47 private: 48 static void _ConfigCallback(void* driverCookie); 49 static void _QueueCallback(void* driverCookie, 50 void *cookie); 51 52 static int32 _ThreadEntry(void *data); 53 int32 _Thread(); 54 55 uint32 _DesiredSize(); 56 status_t _UpdateSize(); 57 58 device_node* fNode; 59 60 virtio_device_interface* fVirtio; 61 virtio_device* fVirtioDevice; 62 63 status_t fStatus; 64 uint64 fFeatures; 65 ::virtio_queue fVirtioQueues[2]; 66 67 physical_entry fEntry; 68 uint32 fBuffer[PAGES_COUNT]; 69 70 thread_id fThread; 71 uint32 fDesiredSize; 72 uint32 fActualSize; 73 74 spinlock fInterruptLock; 75 ConditionVariable fQueueCondition; 76 ConditionVariable fConfigCondition; 77 bool fRunning; 78 79 PageInfoList fPages; 80 }; 81 82 83 #endif // VIRTIO_BALLOON_PRIVATE_H 84