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.


large scale namespace changes
[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
108
109 #define V3_Malloc(size) ({                      \
110       extern struct v3_os_hooks * os_hooks;     \
111       void * var = 0;                           \
112       if ((os_hooks) && (os_hooks)->malloc) {   \
113         var = (os_hooks)->malloc(size);         \
114       }                                         \
115       var;                                      \
116     })
117
118 // We need to check the hook structure at runtime to ensure its SAFE
119 #define V3_Free(addr)                                   \
120   do {                                                  \
121     extern struct v3_os_hooks * os_hooks;               \
122     if ((os_hooks) && (os_hooks)->free) {               \
123       (os_hooks)->free(addr);                           \
124     }                                                   \
125   } while (0)                                           \
126
127
128 // uint_t V3_CPU_KHZ();
129 #define V3_CPU_KHZ()                                    \
130   ({                                                    \
131     unsigned int khz = 0;                               \
132     extern struct v3_os_hooks * os_hooks;               \
133     if ((os_hooks) && (os_hooks)->get_cpu_khz) {        \
134       khz = (os_hooks)->get_cpu_khz();                  \
135     }                                                   \
136     khz;                                                \
137   })                                                    \
138     
139
140
141 #define V3_Hook_Interrupt(irq, opaque)                          \
142   ({                                                            \
143     int ret = 0;                                                \
144     extern struct v3_os_hooks * os_hooks;                       \
145     if ((os_hooks) && (os_hooks)->hook_interrupt) {             \
146       ret = (os_hooks)->hook_interrupt(irq, opaque);            \
147     }                                                           \
148     ret;                                                        \
149   })                                                            \
150
151 #define V3_Yield(addr)                                  \
152   do {                                                  \
153     extern struct v3_os_hooks * os_hooks;               \
154     if ((os_hooks) && (os_hooks)->yield_cpu) {          \
155       (os_hooks)->yield_cpu();                          \
156     }                                                   \
157   } while (0)                                           \
158
159
160
161
162
163 /* ** */
164
165 #define V3_ASSERT(x)                                                    \
166   do {                                                                  \
167     if (!(x)) {                                                         \
168       PrintDebug("Failed assertion in %s: %s at %s, line %d, RA=%lx\n", \
169                  __func__, #x, __FILE__, __LINE__,                      \
170                  (ulong_t) __builtin_return_address(0));                \
171       while(1);                                                         \
172     }                                                                   \
173   } while(0)                                                            \
174     
175
176
177
178 #define VMM_INVALID_CPU 0
179 #define VMM_VMX_CPU 1
180 #define VMM_SVM_CPU 2
181
182
183 // Maybe make this a define....
184 typedef enum v3_cpu_arch {V3_INVALID_CPU, V3_SVM_CPU, V3_SVM_REV3_CPU, V3_VMX_CPU} v3_cpu_arch_t;
185
186
187 #endif //!__V3VEE__
188
189
190
191 struct guest_info;
192
193 /* This will contain function pointers that provide OS services */
194 struct v3_os_hooks {
195   void (*print_info)(const char * format, ...);
196   void (*print_debug)(const char * format, ...);
197   void (*print_trace)(const char * format, ...);
198   
199   void *(*allocate_pages)(int numPages);
200   void (*free_page)(void * page);
201
202   void *(*malloc)(unsigned int size);
203   void (*free)(void * addr);
204
205   void *(*paddr_to_vaddr)(void *addr);
206   void *(*vaddr_to_paddr)(void *addr);
207
208   //  int (*hook_interrupt)(struct guest_info *s, int irq);
209
210   int (*hook_interrupt)(struct guest_info * vm, unsigned int irq);
211
212   int (*ack_irq)(int irq);
213
214
215   unsigned int (*get_cpu_khz)();
216
217
218   void (*start_kernel_thread)(); // include pointer to function
219
220   void (*yield_cpu)();
221
222 };
223
224
225 struct v3_vm_config {
226   void * vm_kernel;
227   int use_ramdisk;
228   void * ramdisk;
229   int ramdisk_size;
230 };
231
232
233
234 /* This will contain Function pointers that control the VMs */
235 struct v3_ctrl_ops {
236   struct guest_info *(*allocate_guest)();
237
238   int (*config_guest)(struct guest_info * info, struct v3_vm_config * config_ptr);
239   int (*init_guest)(struct guest_info * info);
240   int (*start_guest)(struct guest_info * info);
241   //  int (*stop_vm)(uint_t vm_id);
242
243   int (*has_nested_paging)();
244
245   //  v3_cpu_arch_t (*get_cpu_arch)();
246 };
247
248
249
250
251 //
252 //
253 // This is the interrupt state that the VMM's interrupt handlers need to see
254 //
255 struct v3_interrupt {
256   unsigned int irq;
257   unsigned int error;
258
259   unsigned int should_ack;  // Should the vmm ack this interrupt, or will
260                       // the host OS do it?
261 };
262
263
264
265
266 void Init_V3(struct v3_os_hooks * hooks, struct v3_ctrl_ops * vmm_ops);
267
268 int v3_deliver_irq(struct guest_info * vm, struct v3_interrupt * intr);
269 int v3_deliver_keyboard_evt(struct guest_info * vm);
270
271
272 #endif