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.


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