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.


source code clean up,
[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(ptr, num_pages)                   \
69   do {                                                  \
70     extern struct vmm_os_hooks * os_hooks;              \
71     ptr = 0;                                            \
72     if ((os_hooks) && (os_hooks)->allocate_pages) {     \
73       ptr = (os_hooks)->allocate_pages(num_pages);      \
74     }                                                   \
75   } while (0)                                           \
76
77
78 #define V3_FreePage(page)                       \
79   do {                                          \
80     extern struct vmm_os_hooks * os_hooks;      \
81     if ((os_hooks) && (os_hooks)->free_page) {  \
82       (os_hooks)->free_page(page);              \
83     }                                           \
84   } while(0)                                    \
85
86
87
88
89 #define V3_Malloc(size) ({                      \
90       extern struct vmm_os_hooks * os_hooks;    \
91       void * var = 0;                           \
92       if ((os_hooks) && (os_hooks)->malloc) {   \
93         var = (os_hooks)->malloc(size);         \
94       }                                         \
95       var;                                      \
96     })
97
98 // We need to check the hook structure at runtime to ensure its SAFE
99 #define V3_Free(addr)                                   \
100   do {                                                  \
101     extern struct vmm_os_hooks * os_hooks;              \
102     if ((os_hooks) && (os_hooks)->free) {               \
103       (os_hooks)->free(addr);                           \
104     }                                                   \
105   } while (0)                                           \
106
107
108 // uint_t V3_CPU_KHZ();
109 #define V3_CPU_KHZ()                                    \
110   ({                                                    \
111     unsigned int khz = 0;                               \
112     extern struct vmm_os_hooks * os_hooks;              \
113     if ((os_hooks) && (os_hooks)->get_cpu_khz) {        \
114       khz = (os_hooks)->get_cpu_khz();                  \
115     }                                                   \
116     khz;                                                \
117   })                                                    \
118     
119
120
121 #define V3_Hook_Interrupt(irq, opaque)                          \
122   ({                                                            \
123     int ret = 0;                                                        \
124     extern struct vmm_os_hooks * os_hooks;                      \
125     if ((os_hooks) && (os_hooks)->hook_interrupt) {             \
126       ret = (os_hooks)->hook_interrupt(irq, opaque);            \
127     }                                                           \
128     ret;                                                        \
129   })                                                            \
130
131
132 /* ** */
133
134 #define V3_ASSERT(x)                                                    \
135   do {                                                                  \
136     if (!(x)) {                                                         \
137       PrintDebug("Failed assertion in %s: %s at %s, line %d, RA=%lx\n", \
138                  __func__, #x, __FILE__, __LINE__,                      \
139                  (ulong_t) __builtin_return_address(0));                \
140       while(1);                                                         \
141     }                                                                   \
142   } while(0)                                                            \
143     
144
145
146
147 #define VMM_INVALID_CPU 0
148 #define VMM_VMX_CPU 1
149 #define VMM_SVM_CPU 2
150
151 #endif //!__V3VEE__
152
153
154 //
155 //
156 // This is the interrupt state that the VMM's interrupt handlers need to see
157 //
158 struct vmm_intr_state {
159   uint_t irq;
160   uint_t error;
161
162   uint_t should_ack;  // Should the vmm ack this interrupt, or will
163                       // the host OS do it?
164
165   // This is the value given when the interrupt is hooked.
166   // This will never be NULL
167   void *opaque;
168 };
169
170 void deliver_interrupt_to_vmm(struct vmm_intr_state *state);
171
172
173 /* This will contain function pointers that provide OS services */
174 struct vmm_os_hooks {
175   void (*print_info)(const char * format, ...);
176   void (*print_debug)(const char * format, ...);
177   void (*print_trace)(const char * format, ...);
178   
179   void *(*allocate_pages)(int numPages);
180   void (*free_page)(void * page);
181
182   void *(*malloc)(unsigned int size);
183   void (*free)(void * addr);
184
185   void *(*paddr_to_vaddr)(void *addr);
186   void *(*vaddr_to_paddr)(void *addr);
187
188   //  int (*hook_interrupt)(struct guest_info *s, int irq);
189
190   int (*hook_interrupt)(uint_t irq, void *opaque);
191
192   int (*ack_irq)(int irq);
193
194
195   unsigned int (*get_cpu_khz)();
196
197
198   void (*start_kernel_thread)(); // include pointer to function
199 };
200
201
202
203 /* This will contain Function pointers that control the VMs */
204 struct vmm_ctrl_ops {
205   int (*init_guest)(struct guest_info* info);
206   int (*start_guest)(struct guest_info * info);
207   //  int (*stop_vm)(uint_t vm_id);
208
209   int (*has_nested_paging)();
210 };
211
212
213
214
215 void Init_V3(struct vmm_os_hooks * hooks, struct vmm_ctrl_ops * vmm_ops);
216
217
218
219
220
221 #endif