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.


changed debug output to be more granular
[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 /*
79 #define V3_Malloc(type, var, size)                      \
80   do {                                                  \
81     extern struct vmm_os_hooks * os_hooks;              \
82     var = 0;                                            \
83     if ((os_hooks) && (os_hooks)->malloc) {             \
84       var = (type)(os_hooks)->malloc(size);             \
85     }                                                   \
86   } while (0)                                           \
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 #define V3_CPU_KHZ()                                    \
108   ({                                                    \
109     unsigned int khz = 0;                               \
110     extern struct vmm_os_hooks * os_hooks;              \
111     if ((os_hooks) && (os_hooks)->get_cpu_khz) {        \
112       khz = (os_hooks)->get_cpu_khz();                  \
113     }                                                   \
114     khz;                                                \
115   })                                                    \
116     
117
118 /* ** */
119
120 #define V3_ASSERT(x)                                                    \
121   do {                                                                  \
122     if (!(x)) {                                                         \
123       PrintDebug("Failed assertion in %s: %s at %s, line %d, RA=%lx\n", \
124                  __func__, #x, __FILE__, __LINE__,                      \
125                  (ulong_t) __builtin_return_address(0));                \
126       while(1);                                                         \
127     }                                                                   \
128   } while(0)                                                            \
129     
130
131 #define VMM_INVALID_CPU 0
132 #define VMM_VMX_CPU 1
133 #define VMM_SVM_CPU 2
134
135 #endif //!__V3VEE__
136
137
138 //
139 //
140 // This is the interrupt state that the VMM's interrupt handlers need to see
141 //
142 struct vmm_intr_state {
143   uint_t irq;
144   uint_t error;
145
146   uint_t should_ack;  // Should the vmm ack this interrupt, or will
147                       // the host OS do it?
148
149   // This is the value given when the interrupt is hooked.
150   // This will never be NULL
151   void *opaque;
152 };
153
154 void deliver_interrupt_to_vmm(struct vmm_intr_state *state);
155
156
157 /* This will contain function pointers that provide OS services */
158 struct vmm_os_hooks {
159   void (*print_info)(const char * format, ...);
160   void (*print_debug)(const char * format, ...);
161   void (*print_trace)(const char * format, ...);
162   
163   void *(*allocate_pages)(int numPages);
164   void (*free_page)(void * page);
165
166   void *(*malloc)(unsigned int size);
167   void (*free)(void * addr);
168
169   void *(*paddr_to_vaddr)(void *addr);
170   void *(*vaddr_to_paddr)(void *addr);
171
172   //  int (*hook_interrupt)(int irq, vmm_intr_handler handler, uint_t opaque);
173
174   int (*hook_interrupt)(struct guest_info *s, int irq);
175
176   int (*hook_interrupt_new)(uint_t irq, void *opaque);
177
178   int (*ack_irq)(int irq);
179
180
181   unsigned int (*get_cpu_khz)();
182
183   // Do we need this here?
184   //  void (*snprintf)(char * dst, char * format, int len, ...);
185
186
187
188   void (*start_kernel_thread)(); // include pointer to function
189 };
190
191
192
193 /* This will contain Function pointers that control the VMs */
194 struct vmm_ctrl_ops {
195   int (*init_guest)(struct guest_info* info);
196   int (*start_guest)(struct guest_info * info);
197   //  int (*stop_vm)(uint_t vm_id);
198
199   int (*has_nested_paging)();
200 };
201
202
203
204
205 void Init_VMM(struct vmm_os_hooks * hooks, struct vmm_ctrl_ops * vmm_ops);
206
207
208
209
210
211 #endif