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.


new interrupt hooking mechanism
[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 #if VMM_INFO
32 #define PrintInfo(fmt, args...)                         \
33   do {                                                  \
34     extern struct vmm_os_hooks * os_hooks;              \
35     if ((os_hooks) && (os_hooks)->print_info) {         \
36       (os_hooks)->print_info((fmt), ##args);            \
37     }                                                   \
38   } while (0)                                           
39 #else
40 #define PrintInfo(fmt, args...)
41 #endif
42
43
44 #if VMM_TRACE
45 #define PrintTrace(fmt, args...)                        \
46   do {                                                  \
47     extern struct vmm_os_hooks * os_hooks;              \
48     if ((os_hooks) && (os_hooks)->print_trace) {        \
49       (os_hooks)->print_trace((fmt), ##args);           \
50     }                                                   \
51   } while (0)                                           
52 #else
53 #define PrintTrace(fmt, args...)
54 #endif
55
56
57 #define V3_AllocPages(ptr, num_pages)                   \
58   do {                                                  \
59     extern struct vmm_os_hooks * os_hooks;              \
60     ptr = 0;                                            \
61     if ((os_hooks) && (os_hooks)->allocate_pages) {     \
62       ptr = (os_hooks)->allocate_pages(num_pages);      \
63     }                                                   \
64   } while (0)                                           \
65
66
67 /*
68 #define V3_Malloc(type, var, size)                      \
69   do {                                                  \
70     extern struct vmm_os_hooks * os_hooks;              \
71     var = 0;                                            \
72     if ((os_hooks) && (os_hooks)->malloc) {             \
73       var = (type)(os_hooks)->malloc(size);             \
74     }                                                   \
75   } while (0)                                           \
76 */
77
78 #define V3_Malloc(size) ({                      \
79       extern struct vmm_os_hooks * os_hooks;    \
80       void * var = 0;                           \
81       if ((os_hooks) && (os_hooks)->malloc) {   \
82         var = (os_hooks)->malloc(size);         \
83       }                                         \
84       var;                                      \
85     })
86
87 // We need to check the hook structure at runtime to ensure its SAFE
88 #define V3_Free(addr)                                   \
89   do {                                                  \
90     extern struct vmm_os_hooks * os_hooks;              \
91     if ((os_hooks) && (os_hooks)->free) {               \
92       (os_hooks)->free(addr);                           \
93     }                                                   \
94   } while (0)                                           \
95
96 #define V3_CPU_KHZ()                                    \
97   ({                                                    \
98     unsigned int khz = 0;                               \
99     extern struct vmm_os_hooks * os_hooks;              \
100     if ((os_hooks) && (os_hooks)->get_cpu_khz) {        \
101       khz = (os_hooks)->get_cpu_khz();                  \
102     }                                                   \
103     khz;                                                \
104   })                                                    \
105     
106
107 /* ** */
108
109 #define V3_ASSERT(x)                                                    \
110   do {                                                                  \
111     if (!(x)) {                                                         \
112       PrintDebug("Failed assertion in %s: %s at %s, line %d, RA=%lx\n", \
113                  __func__, #x, __FILE__, __LINE__,                      \
114                  (ulong_t) __builtin_return_address(0));                \
115       while(1);                                                         \
116     }                                                                   \
117   } while(0)                                                            \
118     
119
120 #define VMM_INVALID_CPU 0
121 #define VMM_VMX_CPU 1
122 #define VMM_SVM_CPU 2
123
124 #endif //!__V3VEE__
125
126
127 //
128 //
129 // This is the interrupt state that the VMM's interrupt handlers need to see
130 //
131 struct vmm_intr_state {
132   uint_t irq;
133   uint_t error;
134
135   uint_t should_ack;  // Should the vmm ack this interrupt, or will
136                       // the host OS do it?
137
138   // This is the value given when the interrupt is hooked.
139   // This will never be NULL
140   void *opaque;
141 };
142
143 void deliver_interrupt_to_vmm(struct vmm_intr_state *state);
144
145
146 /* This will contain function pointers that provide OS services */
147 struct vmm_os_hooks {
148   void (*print_info)(const char * format, ...);
149   void (*print_debug)(const char * format, ...);
150   void (*print_trace)(const char * format, ...);
151   
152   void *(*allocate_pages)(int numPages);
153   void (*free_page)(void * page);
154
155   void *(*malloc)(unsigned int size);
156   void (*free)(void * addr);
157
158   void *(*paddr_to_vaddr)(void *addr);
159   void *(*vaddr_to_paddr)(void *addr);
160
161   //  int (*hook_interrupt)(int irq, vmm_intr_handler handler, uint_t opaque);
162
163   int (*hook_interrupt)(struct guest_info *s, int irq);
164
165   int (*hook_interrupt_new)(uint_t irq, void *opaque);
166
167   int (*ack_irq)(int irq);
168
169
170   unsigned int (*get_cpu_khz)();
171
172   // Do we need this here?
173   //  void (*snprintf)(char * dst, char * format, int len, ...);
174
175
176
177   void (*start_kernel_thread)(); // include pointer to function
178 };
179
180
181
182 /* This will contain Function pointers that control the VMs */
183 struct vmm_ctrl_ops {
184   int (*init_guest)(struct guest_info* info);
185   int (*start_guest)(struct guest_info * info);
186   //  int (*stop_vm)(uint_t vm_id);
187
188   int (*has_nested_paging)();
189 };
190
191
192
193
194 void Init_VMM(struct vmm_os_hooks * hooks, struct vmm_ctrl_ops * vmm_ops);
195
196
197
198
199
200 #endif