Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Linux kernel compatability enhancements (through 3.19)
[palacios.git] / linux_module / palacios.h
1 #ifndef _PALACIOS_H
2 #define _PALACIOS_H
3
4 #include <linux/cdev.h>
5 #include <linux/list.h>
6 #include <linux/sched.h>
7 #include <linux/slab.h>
8 #include <linux/version.h>
9
10
11 /* Global Control IOCTLs */
12 #define V3_CREATE_GUEST 12
13 #define V3_FREE_GUEST 13
14
15 #define V3_ADD_MEMORY    50
16 #define V3_RESET_MEMORY  51
17 #define V3_REMOVE_MEMORY 52
18
19 #define V3_ADD_PCI_HW_DEV 55
20 #define V3_ADD_PCI_USER_DEV 56
21
22 #define V3_DVFS_CTRL  60
23
24
25 /* VM Specific IOCTLs */
26 #define V3_VM_CONSOLE_CONNECT 20
27 #define V3_VM_STREAM_CONNECT 21
28
29 #define V3_VM_PAUSE 23
30 #define V3_VM_CONTINUE 24
31
32 #define V3_VM_LAUNCH 25
33 #define V3_VM_STOP 26
34 #define V3_VM_LOAD 27
35 #define V3_VM_SAVE 28
36 #define V3_VM_SIMULATE 29
37
38 #define V3_VM_INSPECT 30
39 #define V3_VM_DEBUG 31
40
41 #define V3_VM_MOVE_CORE 33
42
43 #define V3_VM_SEND    34
44 #define V3_VM_RECEIVE 35
45
46 #define V3_VM_MOVE_MEM 36
47
48 #define V3_VM_RESET    40
49
50 #define V3_VM_FB_INPUT 257
51 #define V3_VM_FB_QUERY 258
52
53 #define V3_VM_MEM_TRACK_SIZE 300
54 #define V3_VM_MEM_TRACK_CMD  301
55 #define V3_VM_MEM_TRACK_SNAP 302
56
57 #define V3_VM_HOST_DEV_CONNECT 10245
58
59 #define V3_VM_KSTREAM_USER_CONNECT 11245
60
61
62 struct v3_guest_img {
63     unsigned long long size;
64     void * guest_data;
65     char name[128];
66 } __attribute__((packed));
67
68 typedef enum { PREALLOCATED=0,         // user space-allocated (e.g. hot remove)
69               REQUESTED,               // kernel will attempt allocation (anywhere)
70               REQUESTED32,             // kernel will attempt allocation (<4GB)
71 } v3_mem_region_type_t;
72
73 struct v3_mem_region {
74     v3_mem_region_type_t type;         // 
75     int                  node;         // numa node for REQUESTED (-1 = any)
76     unsigned long long   base_addr;    // region start (hpa) for PREALLOCATED
77     unsigned long long   num_pages;    // size for PREALLOCATED or request size for REQUESTED
78                                        // should be power of 2 and > V3_CONFIG_MEM_BLOCK
79 } __attribute__((packed));
80
81 struct v3_debug_cmd {
82     unsigned int core; 
83     unsigned int cmd;
84 } __attribute__((packed));
85
86 struct v3_core_move_cmd {
87     unsigned short vcore_id;
88     unsigned short pcore_id;
89 } __attribute__((packed));
90
91 struct v3_mem_move_cmd{
92     unsigned long long gpa;
93     unsigned short     pcore_id;
94 } __attribute__((packed));
95
96 struct v3_reset_cmd {
97 #define V3_RESET_VM_ALL    0
98 #define V3_RESET_VM_HRT    1
99 #define V3_RESET_VM_ROS    2
100 #define V3_RESET_VM_CORE_RANGE  3
101     unsigned int type;
102     unsigned int first_core;  // for CORE_RANGE
103     unsigned int num_cores;   // for CORE_RANGE
104 } __attribute__((packed));
105     
106 struct v3_chkpt_info {
107     char store[128];
108     char url[256]; /* This might need to be bigger... */
109     unsigned long long opts;
110 #define V3_CHKPT_OPT_NONE         0
111 #define V3_CHKPT_OPT_SKIP_MEM     1  // don't write memory to store
112 #define V3_CHKPT_OPT_SKIP_DEVS    2  // don't write devices to store
113 #define V3_CHKPT_OPT_SKIP_CORES   4  // don't write core arch ind data to store
114 #define V3_CHKPT_OPT_SKIP_ARCHDEP 8  // don't write core arch dep data to store
115 } __attribute__((packed));
116
117
118 struct v3_hw_pci_dev {
119     char name[128];
120     unsigned int bus;
121     unsigned int dev;
122     unsigned int func;
123 } __attribute__((packed));
124
125 struct v3_user_pci_dev {
126     char name[128];
127     unsigned short vendor_id;
128     unsigned short dev_id;
129 } __attribute__((packed));
130
131
132
133 void * trace_malloc(size_t size, gfp_t flags);
134 void trace_free(const void * objp);
135
136
137 struct v3_guest {
138     void * v3_ctx;
139
140     void * img; 
141     u32 img_size;
142
143     char name[128];
144
145
146     struct rb_root vm_ctrls;
147     struct list_head exts;
148
149     dev_t vm_dev; 
150     struct cdev cdev;
151 };
152
153 // For now MAX_VMS must be a multiple of 8
154 // This is due to the minor number bitmap
155 #define MAX_VMS 32
156 #define MAX_THREADS (MAX_VMS*64)
157
158
159 int palacios_vmm_init( char *options );
160 int palacios_vmm_exit( void );
161
162
163 // This is how a component finds the proc dir we are using for global state
164 struct proc_dir_entry *palacios_get_procdir(void);
165
166 struct v3_resource_control;
167
168 // Selected exported stubs, for use in other palacios components, like vnet
169 // The idea is that everything uses the same stubs
170 void  palacios_print_scoped(void *vm, int vcore, const char *fmt, ...);
171 #define palacios_print(...) palacios_print_scoped(0,-1, __VA_ARGS__)
172 // node_id=-1 => no node constraint
173 void *palacios_allocate_pages(int num_pages, unsigned int alignment, int node_id, int (*filter_func)(void *paddr, void *filter_state), void *filter_state);
174 void  palacios_free_pages(void *page_addr, int num_pages);
175 void *palacios_alloc(unsigned int size);
176 // node_id=-1 => no node constraint
177 void *palacios_alloc_extended(unsigned int size, unsigned int flags, int node_id);
178 void  palacios_free(void *);
179 void *palacios_valloc(unsigned int size); // use instead of vmalloc
180 void  palacios_vfree(void *);             // use instead of vfree
181 void *palacios_vaddr_to_paddr(void *vaddr);
182 void *palacios_paddr_to_vaddr(void *paddr);
183 void  palacios_xcall(int cpu_id, void (*fn)(void *arg), void *arg);
184 void *palacios_create_and_start_kernel_thread(int (*fn)(void * arg), void *arg, char *thread_name, struct v3_resource_control *rc);
185 void *palacios_create_thread_on_cpu(int cpu_id, int (*fn)(void * arg), void *arg, char *thread_name, struct v3_resource_control *rc);
186 void  palacios_start_thread(void *thread_ptr);
187 void *palacios_creeate_and_start_thread_on_cpu(int cpu_id, int (*fn)(void * arg), void *arg, char *thread_name, struct v3_resource_control *rc);
188 int   palacios_move_thread_to_cpu(int new_cpu_id, void *thread_ptr);
189 void  palacios_yield_cpu(void);
190 void  palacios_sleep_cpu(unsigned int us);
191 unsigned int palacios_get_cpu(void);
192 unsigned int palacios_get_cpu_khz(void);
193 void  palacios_used_fpu(void);
194 void  palacios_need_fpu(void);
195 void *palacios_mutex_alloc(void);         // allocates and inits a lock
196 void  palacios_mutex_init(void *mutex);   // only inits a lock
197 void  palacios_mutex_deinit(void *mutex); // only deinits a lock
198 void  palacios_mutex_free(void *mutex);   // deinits and frees a lock
199 void  palacios_mutex_lock(void *mutex, int must_spin);
200 void  palacios_mutex_unlock(void *mutex);
201 void *palacios_mutex_lock_irqsave(void *mutex, int must_spin);
202 void  palacios_mutex_unlock_irqrestore(void *mutex, void *flags);
203 // Macros for spin-locks in the module code
204 // By using these macros, the lock checker will be able
205 // to see the module code as well as the core VMM
206 #define palacios_spinlock_init(l) palacios_mutex_init(l)
207 #define palacios_spinlock_deinit(l) palacios_mutex_deinit(l)
208 #define palacios_spinlock_lock(l) palacios_mutex_lock(l,0)
209 #define palacios_spinlock_unlock(l) palacios_mutex_unlock(l)
210 #define palacios_spinlock_lock_irqsave(l,f) do { f=(unsigned long)palacios_mutex_lock_irqsave(l,0); } while (0)
211 #define palacios_spinlock_unlock_irqrestore(l,f) palacios_mutex_unlock_irqrestore(l,(void*)f)
212
213
214 // Palacios Printing Support
215
216 // These macros affect how palacios_print will generate output
217 // Turn this on for unprefaced output from palacios_print
218 #define V3_PRINTK_OLD_STYLE_OUTPUT 0
219 // Maximum length output from palacios_print
220 #define V3_PRINTK_BUF_SIZE 1024
221 // Turn this on to check if new-style output for palacios_print  contains only 7-bit chars
222 #define V3_PRINTK_CHECK_7BIT 1
223
224 //
225 // The following macros are for printing in the linux module itself, even before
226 // Palacios is initialized and after it it deinitialized
227 // All printk's in linux_module use these macros, for easier control
228 #define ERROR(fmt, args...) printk((KERN_ERR "palacios (pcore %u) %s(%d): " fmt), palacios_get_cpu(), __FILE__, __LINE__, ##args)
229 #define WARNING(fmt, args...) printk((KERN_WARNING "palacios (pcore %u): " fmt), palacios_get_cpu(), ##args)
230 #define NOTICE(fmt, args...) printk((KERN_NOTICE "palacios (pcore %u): " fmt), palacios_get_cpu(), ##args)
231 #define INFO(fmt, args...) printk((KERN_INFO "palacios (pcore %u): " fmt), palacios_get_cpu(), ##args)
232 #define DEBUG(fmt, args...) printk((KERN_DEBUG "palacios (pcore %u): " fmt), palacios_get_cpu(), ##args)
233
234 /* Linux proc versioning */
235 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
236
237 #define PAL_PROC_CREATE(ent, fname, perm, parent, fops) \
238     ent = proc_create(fname, perm, parent, fops); 
239
240 #define PAL_PROC_CREATE_DATA(ent, fname, perm, parent, fops, data) \
241     ent = proc_create_data(fname, perm, parent, fops, data);
242
243 #define PAL_PDE(inode) NULL
244 #define PAL_PROC_GETDATA(inode) PDE_DATA((inode))
245
246 #else
247
248 #define PAL_PROC_CREATE(ent, fname, perm, parent, fops) \
249     ent = create_proc_entry(fname, perm, parent); \
250     if (ent) { \
251         ent->proc_fops = fops; \
252     }
253
254 #define PAL_PROC_CREATE_DATA(ent, fname, perm, parent, fops, data) \
255     ent = proc_create_data(fname, perm, parent, fops, data);
256
257 #define PAL_PDE(inode)          PDE((inode))
258 #define PAL_PROC_GETDATA(inode) PDE((inode))->data
259
260 #endif
261
262
263 #if LINUX_VERSION_CODE > KERNEL_VERSION(3,9,0)
264 #define strict_strtoull(s,b,r) kstrtoull(s,b,r)
265 #endif
266
267
268
269 #endif