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.


added mem_size config variable
[palacios.git] / palacios / include / palacios / vmm.h
1 /*
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20 #ifndef __VMM_H__
21 #define __VMM_H__
22
23
24 #include <palacios/vm_guest.h>
25 #include <palacios/vmm_mem.h>
26
27 #ifdef __V3VEE__
28
29 //#include <palacios/vmm_types.h>
30 #include <palacios/vmm_string.h>
31
32
33 //#include <palacios/vmm_paging.h>
34
35 /* utility definitions */
36
37 #ifdef VMM_DEBUG
38 #define PrintDebug(fmt, args...)                        \
39   do {                                                  \
40     extern struct v3_os_hooks * os_hooks;               \
41     if ((os_hooks) && (os_hooks)->print_debug) {        \
42       (os_hooks)->print_debug((fmt), ##args);           \
43     }                                                   \
44   } while (0)                                           
45 #else
46 #define PrintDebug(fmt,args ...)
47 #endif
48
49
50
51 #define PrintError(fmt, args...)                                        \
52   do {                                                                  \
53     extern struct v3_os_hooks * os_hooks;                               \
54     if ((os_hooks) && (os_hooks)->print_debug) {                        \
55       (os_hooks)->print_debug("%s(%d): " fmt, __FILE__, __LINE__, ##args); \
56     }                                                                   \
57   } while (0)                                           
58
59
60
61 #ifdef VMM_INFO
62 #define PrintInfo(fmt, args...)                         \
63   do {                                                  \
64     extern struct v3_os_hooks * os_hooks;               \
65     if ((os_hooks) && (os_hooks)->print_info) {         \
66       (os_hooks)->print_info((fmt), ##args);            \
67     }                                                   \
68   } while (0)                                           
69 #else
70 #define PrintInfo(fmt, args...)
71 #endif
72
73
74 #ifdef VMM_TRACE
75 #define PrintTrace(fmt, args...)                                        \
76   do {                                                                  \
77     extern struct v3_os_hooks * os_hooks;                               \
78     if ((os_hooks) && (os_hooks)->print_trace) {                        \
79       (os_hooks)->print_trace(fmt, ##args);                             \
80     }                                                                   \
81   } while (0)                                           
82 #else
83 #define PrintTrace(fmt, args...)
84 #endif
85
86
87 #define V3_AllocPages(num_pages)                        \
88   ({                                                    \
89     extern struct v3_os_hooks * os_hooks;               \
90     void * ptr = 0;                                     \
91     if ((os_hooks) && (os_hooks)->allocate_pages) {     \
92       ptr = (os_hooks)->allocate_pages(num_pages);      \
93     }                                                   \
94     ptr;                                                \
95   })                                                    \
96
97
98 #define V3_FreePage(page)                       \
99   do {                                          \
100     extern struct v3_os_hooks * os_hooks;       \
101     if ((os_hooks) && (os_hooks)->free_page) {  \
102       (os_hooks)->free_page(page);              \
103     }                                           \
104   } while(0)                                    \
105
106
107 #define V3_VAddr(addr) ({                               \
108       extern struct v3_os_hooks * os_hooks;             \
109       void * var = 0;                                   \
110       if ((os_hooks) && (os_hooks)->paddr_to_vaddr) {   \
111         var = (os_hooks)->paddr_to_vaddr(addr);         \
112       }                                                 \
113       var;                                              \
114     })
115
116
117 #define V3_PAddr(addr) ({                               \
118       extern struct v3_os_hooks * os_hooks;             \
119       void * var = 0;                                   \
120       if ((os_hooks) && (os_hooks)->vaddr_to_paddr) {   \
121         var = (os_hooks)->vaddr_to_paddr(addr);         \
122       }                                                 \
123       var;                                              \
124     })
125
126
127
128 #define V3_Malloc(size) ({                      \
129       extern struct v3_os_hooks * os_hooks;     \
130       void * var = 0;                           \
131       if ((os_hooks) && (os_hooks)->malloc) {   \
132         var = (os_hooks)->malloc(size);         \
133       }                                         \
134       var;                                      \
135     })
136
137 // We need to check the hook structure at runtime to ensure its SAFE
138 #define V3_Free(addr)                                   \
139   do {                                                  \
140     extern struct v3_os_hooks * os_hooks;               \
141     if ((os_hooks) && (os_hooks)->free) {               \
142       (os_hooks)->free(addr);                           \
143     }                                                   \
144   } while (0)                                           \
145
146
147 // uint_t V3_CPU_KHZ();
148 #define V3_CPU_KHZ()                                    \
149   ({                                                    \
150     unsigned int khz = 0;                               \
151     extern struct v3_os_hooks * os_hooks;               \
152     if ((os_hooks) && (os_hooks)->get_cpu_khz) {        \
153       khz = (os_hooks)->get_cpu_khz();                  \
154     }                                                   \
155     khz;                                                \
156   })                                                    \
157     
158
159
160 #define V3_Hook_Interrupt(irq, opaque)                          \
161   ({                                                            \
162     int ret = 0;                                                \
163     extern struct v3_os_hooks * os_hooks;                       \
164     if ((os_hooks) && (os_hooks)->hook_interrupt) {             \
165       ret = (os_hooks)->hook_interrupt(irq, opaque);            \
166     }                                                           \
167     ret;                                                        \
168   })                                                            \
169
170 #define V3_Yield(addr)                                  \
171   do {                                                  \
172     extern struct v3_os_hooks * os_hooks;               \
173     if ((os_hooks) && (os_hooks)->yield_cpu) {          \
174       (os_hooks)->yield_cpu();                          \
175     }                                                   \
176   } while (0)                                           \
177
178
179
180
181
182 /* ** */
183
184 #define V3_ASSERT(x)                                                    \
185   do {                                                                  \
186     if (!(x)) {                                                         \
187       PrintDebug("Failed assertion in %s: %s at %s, line %d, RA=%lx\n", \
188                  __func__, #x, __FILE__, __LINE__,                      \
189                  (ulong_t) __builtin_return_address(0));                \
190       while(1);                                                         \
191     }                                                                   \
192   } while(0)                                                            \
193     
194
195
196
197 #define VMM_INVALID_CPU 0
198 #define VMM_VMX_CPU 1
199 #define VMM_SVM_CPU 2
200
201
202 // Maybe make this a define....
203 typedef enum v3_cpu_arch {V3_INVALID_CPU, V3_SVM_CPU, V3_SVM_REV3_CPU, V3_VMX_CPU} v3_cpu_arch_t;
204
205
206 #endif //!__V3VEE__
207
208
209
210 struct guest_info;
211
212 /* This will contain function pointers that provide OS services */
213 struct v3_os_hooks {
214   void (*print_info)(const char * format, ...)
215         __attribute__ ((format (printf, 1, 2)));
216   void (*print_debug)(const char * format, ...)
217         __attribute__ ((format (printf, 1, 2)));
218   void (*print_trace)(const char * format, ...)
219         __attribute__ ((format (printf, 1, 2)));
220   
221   void *(*allocate_pages)(int numPages);
222   void (*free_page)(void * page);
223
224   void *(*malloc)(unsigned int size);
225   void (*free)(void * addr);
226
227   void *(*paddr_to_vaddr)(void *addr);
228   void *(*vaddr_to_paddr)(void *addr);
229
230   //  int (*hook_interrupt)(struct guest_info *s, int irq);
231
232   int (*hook_interrupt)(struct guest_info * vm, unsigned int irq);
233
234   int (*ack_irq)(int irq);
235
236
237   unsigned int (*get_cpu_khz)(void);
238
239
240   void (*start_kernel_thread)(void); // include pointer to function
241
242   void (*yield_cpu)(void);
243
244 };
245
246
247 struct v3_vm_config {
248   void * rombios;
249   int rombios_size;
250
251   void * vgabios;
252   int vgabios_size;
253
254   unsigned long mem_size; // in bytes, var should be natural size of cpu
255                           // so we can specify maximum physical address size
256                           // (We're screwed if we want to do 32 bit host/64 bit guest)
257
258   int use_ramdisk;
259   void * ramdisk;
260   int ramdisk_size;
261 };
262
263
264
265 /* This will contain Function pointers that control the VMs */
266 struct v3_ctrl_ops {
267   struct guest_info *(*allocate_guest)(void);
268
269   int (*config_guest)(struct guest_info * info, struct v3_vm_config * config_ptr);
270   int (*init_guest)(struct guest_info * info);
271   int (*start_guest)(struct guest_info * info);
272   //  int (*stop_vm)(uint_t vm_id);
273
274   int (*has_nested_paging)(void);
275
276   //  v3_cpu_arch_t (*get_cpu_arch)();
277 };
278
279
280
281
282 //
283 //
284 // This is the interrupt state that the VMM's interrupt handlers need to see
285 //
286 struct v3_interrupt {
287   unsigned int irq;
288   unsigned int error;
289
290   unsigned int should_ack;  // Should the vmm ack this interrupt, or will
291                       // the host OS do it?
292 };
293
294
295
296
297 void Init_V3(struct v3_os_hooks * hooks, struct v3_ctrl_ops * vmm_ops);
298
299 int v3_deliver_irq(struct guest_info * vm, struct v3_interrupt * intr);
300 int v3_deliver_keyboard_evt(struct guest_info * vm);
301
302
303 #endif