4 #include <linux/cdev.h>
5 #include <linux/list.h>
6 #include <linux/sched.h>
7 #include <linux/slab.h>
10 /* Global Control IOCTLs */
11 #define V3_CREATE_GUEST 12
12 #define V3_FREE_GUEST 13
14 #define V3_ADD_MEMORY 50
15 #define V3_RESET_MEMORY 51
16 #define V3_REMOVE_MEMORY 52
18 #define V3_ADD_PCI_HW_DEV 55
19 #define V3_ADD_PCI_USER_DEV 56
21 #define V3_DVFS_CTRL 60
24 /* VM Specific IOCTLs */
25 #define V3_VM_CONSOLE_CONNECT 20
26 #define V3_VM_STREAM_CONNECT 21
28 #define V3_VM_PAUSE 23
29 #define V3_VM_CONTINUE 24
31 #define V3_VM_LAUNCH 25
35 #define V3_VM_SIMULATE 29
37 #define V3_VM_INSPECT 30
38 #define V3_VM_DEBUG 31
40 #define V3_VM_MOVE_CORE 33
43 #define V3_VM_RECEIVE 35
45 #define V3_VM_MOVE_MEM 36
47 #define V3_VM_FB_INPUT 257
48 #define V3_VM_FB_QUERY 258
50 #define V3_VM_MEM_TRACK_SIZE 300
51 #define V3_VM_MEM_TRACK_CMD 301
52 #define V3_VM_MEM_TRACK_SNAP 302
54 #define V3_VM_HOST_DEV_CONNECT 10245
56 #define V3_VM_KSTREAM_USER_CONNECT 11245
60 unsigned long long size;
63 } __attribute__((packed));
65 typedef enum { PREALLOCATED=0, // user space-allocated (e.g. hot remove)
66 REQUESTED, // kernel will attempt allocation (anywhere)
67 REQUESTED32, // kernel will attempt allocation (<4GB)
68 } v3_mem_region_type_t;
70 struct v3_mem_region {
71 v3_mem_region_type_t type; //
72 int node; // numa node for REQUESTED (-1 = any)
73 unsigned long long base_addr; // region start (hpa) for PREALLOCATED
74 unsigned long long num_pages; // size for PREALLOCATED or request size for REQUESTED
75 // should be power of 2 and > V3_CONFIG_MEM_BLOCK
76 } __attribute__((packed));
81 } __attribute__((packed));
83 struct v3_core_move_cmd {
84 unsigned short vcore_id;
85 unsigned short pcore_id;
86 } __attribute__((packed));
88 struct v3_mem_move_cmd{
89 unsigned long long gpa;
90 unsigned short pcore_id;
91 } __attribute__((packed));
93 struct v3_chkpt_info {
95 char url[256]; /* This might need to be bigger... */
96 unsigned long long opts;
97 #define V3_CHKPT_OPT_NONE 0
98 #define V3_CHKPT_OPT_SKIP_MEM 1 // don't write memory to store
99 #define V3_CHKPT_OPT_SKIP_DEVS 2 // don't write devices to store
100 #define V3_CHKPT_OPT_SKIP_CORES 4 // don't write core arch ind data to store
101 #define V3_CHKPT_OPT_SKIP_ARCHDEP 8 // don't write core arch dep data to store
102 } __attribute__((packed));
105 struct v3_hw_pci_dev {
110 } __attribute__((packed));
112 struct v3_user_pci_dev {
114 unsigned short vendor_id;
115 unsigned short dev_id;
116 } __attribute__((packed));
120 void * trace_malloc(size_t size, gfp_t flags);
121 void trace_free(const void * objp);
133 struct rb_root vm_ctrls;
134 struct list_head exts;
140 // For now MAX_VMS must be a multiple of 8
141 // This is due to the minor number bitmap
146 int palacios_vmm_init( char *options );
147 int palacios_vmm_exit( void );
150 // This is how a component finds the proc dir we are using for global state
151 struct proc_dir_entry *palacios_get_procdir(void);
153 // Selected exported stubs, for use in other palacios components, like vnet
154 // The idea is that everything uses the same stubs
155 void palacios_print_scoped(void *vm, int vcore, const char *fmt, ...);
156 #define palacios_print(...) palacios_print_scoped(0,-1, __VA_ARGS__)
157 // node_id=-1 => no node constraint
158 void *palacios_allocate_pages(int num_pages, unsigned int alignment, int node_id, int (*filter_func)(void *paddr, void *filter_state), void *filter_state);
159 void palacios_free_pages(void *page_addr, int num_pages);
160 void *palacios_alloc(unsigned int size);
161 // node_id=-1 => no node constraint
162 void *palacios_alloc_extended(unsigned int size, unsigned int flags, int node_id);
163 void palacios_free(void *);
164 void *palacios_valloc(unsigned int size); // use instead of vmalloc
165 void palacios_vfree(void *); // use instead of vfree
166 void *palacios_vaddr_to_paddr(void *vaddr);
167 void *palacios_paddr_to_vaddr(void *paddr);
168 void palacios_xcall(int cpu_id, void (*fn)(void *arg), void *arg);
169 void *palacios_create_and_start_kernel_thread(int (*fn)(void * arg), void *arg, char *thread_name);
170 void *palacios_create_thread_on_cpu(int cpu_id, int (*fn)(void * arg), void *arg, char *thread_name);
171 void palacios_start_thread(void *thread_ptr);
172 void *palacios_creeate_and_start_thread_on_cpu(int cpu_id, int (*fn)(void * arg), void *arg, char *thread_name);
173 int palacios_move_thread_to_cpu(int new_cpu_id, void *thread_ptr);
174 void palacios_yield_cpu(void);
175 void palacios_sleep_cpu(unsigned int us);
176 unsigned int palacios_get_cpu(void);
177 unsigned int palacios_get_cpu_khz(void);
178 void palacios_used_fpu(void);
179 void palacios_need_fpu(void);
180 void *palacios_mutex_alloc(void); // allocates and inits a lock
181 void palacios_mutex_init(void *mutex); // only inits a lock
182 void palacios_mutex_deinit(void *mutex); // only deinits a lock
183 void palacios_mutex_free(void *mutex); // deinits and frees a lock
184 void palacios_mutex_lock(void *mutex, int must_spin);
185 void palacios_mutex_unlock(void *mutex);
186 void *palacios_mutex_lock_irqsave(void *mutex, int must_spin);
187 void palacios_mutex_unlock_irqrestore(void *mutex, void *flags);
188 // Macros for spin-locks in the module code
189 // By using these macros, the lock checker will be able
190 // to see the module code as well as the core VMM
191 #define palacios_spinlock_init(l) palacios_mutex_init(l)
192 #define palacios_spinlock_deinit(l) palacios_mutex_deinit(l)
193 #define palacios_spinlock_lock(l) palacios_mutex_lock(l,0)
194 #define palacios_spinlock_unlock(l) palacios_mutex_unlock(l)
195 #define palacios_spinlock_lock_irqsave(l,f) do { f=(unsigned long)palacios_mutex_lock_irqsave(l,0); } while (0)
196 #define palacios_spinlock_unlock_irqrestore(l,f) palacios_mutex_unlock_irqrestore(l,(void*)f)
199 // Palacios Printing Support
201 // These macros affect how palacios_print will generate output
202 // Turn this on for unprefaced output from palacios_print
203 #define V3_PRINTK_OLD_STYLE_OUTPUT 0
204 // Maximum length output from palacios_print
205 #define V3_PRINTK_BUF_SIZE 1024
206 // Turn this on to check if new-style output for palacios_print contains only 7-bit chars
207 #define V3_PRINTK_CHECK_7BIT 1
210 // The following macros are for printing in the linux module itself, even before
211 // Palacios is initialized and after it it deinitialized
212 // All printk's in linux_module use these macros, for easier control
213 #define ERROR(fmt, args...) printk((KERN_ERR "palacios (pcore %u) %s(%d): " fmt), palacios_get_cpu(), __FILE__, __LINE__, ##args)
214 #define WARNING(fmt, args...) printk((KERN_WARNING "palacios (pcore %u): " fmt), palacios_get_cpu(), ##args)
215 #define NOTICE(fmt, args...) printk((KERN_NOTICE "palacios (pcore %u): " fmt), palacios_get_cpu(), ##args)
216 #define INFO(fmt, args...) printk((KERN_INFO "palacios (pcore %u): " fmt), palacios_get_cpu(), ##args)
217 #define DEBUG(fmt, args...) printk((KERN_DEBUG "palacios (pcore %u): " fmt), palacios_get_cpu(), ##args)