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 functioning ramdisk, makefile support
[palacios.git] / palacios / include / palacios / vmm.h
1 /* (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> */
2 /* (c) 2008, The V3VEE Project <http://www.v3vee.org> */
3
4 #ifndef __VMM_H
5 #define __VMM_H
6
7
8 #include <palacios/vm_guest.h>
9 #include <palacios/vmm_mem.h>
10
11 #ifdef __V3VEE__
12
13 //#include <palacios/vmm_types.h>
14 #include <palacios/vmm_string.h>
15
16
17 //#include <palacios/vmm_paging.h>
18
19 /* utility definitions */
20
21 #if VMM_DEBUG
22 #define PrintDebug(fmt, args...)                        \
23   do {                                                  \
24     extern struct vmm_os_hooks * os_hooks;              \
25     if ((os_hooks) && (os_hooks)->print_debug) {        \
26       (os_hooks)->print_debug((fmt), ##args);           \
27     }                                                   \
28   } while (0)                                           
29 #else
30 #define PrintDebug(fmt,args ...)
31 #endif
32
33
34
35 #define PrintError(fmt, args...)                                        \
36   do {                                                                  \
37     extern struct vmm_os_hooks * os_hooks;                              \
38     if ((os_hooks) && (os_hooks)->print_debug) {                        \
39       (os_hooks)->print_debug("%s(%d): " fmt, __FILE__, __LINE__, ##args); \
40     }                                                                   \
41   } while (0)                                           
42
43
44
45 #if VMM_INFO
46 #define PrintInfo(fmt, args...)                         \
47   do {                                                  \
48     extern struct vmm_os_hooks * os_hooks;              \
49     if ((os_hooks) && (os_hooks)->print_info) {         \
50       (os_hooks)->print_info((fmt), ##args);            \
51     }                                                   \
52   } while (0)                                           
53 #else
54 #define PrintInfo(fmt, args...)
55 #endif
56
57
58 #if VMM_TRACE
59 #define PrintTrace(fmt, args...)                                        \
60   do {                                                                  \
61     extern struct vmm_os_hooks * os_hooks;                              \
62     if ((os_hooks) && (os_hooks)->print_trace) {                        \
63       (os_hooks)->print_trace(fmt, ##args);                             \
64     }                                                                   \
65   } while (0)                                           
66 #else
67 #define PrintTrace(fmt, args...)
68 #endif
69
70
71 #define V3_AllocPages(num_pages)                        \
72   ({                                                    \
73     extern struct vmm_os_hooks * os_hooks;              \
74     void * ptr = 0;                                     \
75     if ((os_hooks) && (os_hooks)->allocate_pages) {     \
76       ptr = (os_hooks)->allocate_pages(num_pages);      \
77     }                                                   \
78     ptr;                                                \
79   })                                                    \
80
81
82 #define V3_FreePage(page)                       \
83   do {                                          \
84     extern struct vmm_os_hooks * os_hooks;      \
85     if ((os_hooks) && (os_hooks)->free_page) {  \
86       (os_hooks)->free_page(page);              \
87     }                                           \
88   } while(0)                                    \
89
90
91
92
93 #define V3_Malloc(size) ({                      \
94       extern struct vmm_os_hooks * os_hooks;    \
95       void * var = 0;                           \
96       if ((os_hooks) && (os_hooks)->malloc) {   \
97         var = (os_hooks)->malloc(size);         \
98       }                                         \
99       var;                                      \
100     })
101
102 // We need to check the hook structure at runtime to ensure its SAFE
103 #define V3_Free(addr)                                   \
104   do {                                                  \
105     extern struct vmm_os_hooks * os_hooks;              \
106     if ((os_hooks) && (os_hooks)->free) {               \
107       (os_hooks)->free(addr);                           \
108     }                                                   \
109   } while (0)                                           \
110
111
112 // uint_t V3_CPU_KHZ();
113 #define V3_CPU_KHZ()                                    \
114   ({                                                    \
115     unsigned int khz = 0;                               \
116     extern struct vmm_os_hooks * os_hooks;              \
117     if ((os_hooks) && (os_hooks)->get_cpu_khz) {        \
118       khz = (os_hooks)->get_cpu_khz();                  \
119     }                                                   \
120     khz;                                                \
121   })                                                    \
122     
123
124
125 #define V3_Hook_Interrupt(irq, opaque)                          \
126   ({                                                            \
127     int ret = 0;                                                \
128     extern struct vmm_os_hooks * os_hooks;                      \
129     if ((os_hooks) && (os_hooks)->hook_interrupt) {             \
130       ret = (os_hooks)->hook_interrupt(irq, opaque);            \
131     }                                                           \
132     ret;                                                        \
133   })                                                            \
134
135
136 /* ** */
137
138 #define V3_ASSERT(x)                                                    \
139   do {                                                                  \
140     if (!(x)) {                                                         \
141       PrintDebug("Failed assertion in %s: %s at %s, line %d, RA=%lx\n", \
142                  __func__, #x, __FILE__, __LINE__,                      \
143                  (ulong_t) __builtin_return_address(0));                \
144       while(1);                                                         \
145     }                                                                   \
146   } while(0)                                                            \
147     
148
149
150
151 #define VMM_INVALID_CPU 0
152 #define VMM_VMX_CPU 1
153 #define VMM_SVM_CPU 2
154
155
156 // Maybe make this a define....
157 typedef enum v3_cpu_arch {V3_INVALID_CPU, V3_SVM_CPU, V3_SVM_REV3_CPU, V3_VMX_CPU} v3_cpu_arch_t;
158
159
160 #endif //!__V3VEE__
161
162
163
164 //
165 //
166 // This is the interrupt state that the VMM's interrupt handlers need to see
167 //
168 struct vmm_intr_state {
169   unsigned int irq;
170   unsigned int error;
171
172   unsigned int should_ack;  // Should the vmm ack this interrupt, or will
173                       // the host OS do it?
174
175   // This is the value given when the interrupt is hooked.
176   // This will never be NULL
177   void *opaque;
178 };
179
180 void deliver_interrupt_to_vmm(struct vmm_intr_state *state);
181
182
183 /* This will contain function pointers that provide OS services */
184 struct vmm_os_hooks {
185   void (*print_info)(const char * format, ...);
186   void (*print_debug)(const char * format, ...);
187   void (*print_trace)(const char * format, ...);
188   
189   void *(*allocate_pages)(int numPages);
190   void (*free_page)(void * page);
191
192   void *(*malloc)(unsigned int size);
193   void (*free)(void * addr);
194
195   void *(*paddr_to_vaddr)(void *addr);
196   void *(*vaddr_to_paddr)(void *addr);
197
198   //  int (*hook_interrupt)(struct guest_info *s, int irq);
199
200   int (*hook_interrupt)(unsigned int irq, void *opaque);
201
202   int (*ack_irq)(int irq);
203
204
205   unsigned int (*get_cpu_khz)();
206
207
208   void (*start_kernel_thread)(); // include pointer to function
209
210
211
212 };
213
214
215 /* This will contain Function pointers that control the VMs */
216 struct vmm_ctrl_ops {
217   struct guest_info *(*allocate_guest)();
218
219   int (*config_guest)(struct guest_info * info, void * config_ptr);
220   int (*init_guest)(struct guest_info * info);
221   int (*start_guest)(struct guest_info * info);
222   //  int (*stop_vm)(uint_t vm_id);
223
224   int (*has_nested_paging)();
225
226   //  v3_cpu_arch_t (*get_cpu_arch)();
227 };
228
229
230
231
232 void Init_V3(struct vmm_os_hooks * hooks, struct vmm_ctrl_ops * vmm_ops);
233
234
235
236
237
238 #endif