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.


VNET fixes and adaptation to new API
[palacios.git] / linux_module / palacios-vnet.c
1 /* 
2  * Palacios VNET Host Hooks Implementations 
3  * Lei Xia 2010
4  */
5
6 #include <linux/kernel.h>
7 #include <linux/kthread.h>
8 #include <linux/spinlock.h>
9 #include <linux/gfp.h>
10 #include <linux/sched.h>
11 #include <linux/uaccess.h>
12 #include <linux/init.h>
13 #include <asm/delay.h>
14 #include <linux/timer.h>
15
16 #include <vnet/vnet.h>
17 #include "mm.h"
18 #include "palacios.h"
19 #include "palacios-vnet.h"
20 #include "linux-exts.h"
21
22
23
24
25 static void host_kthread_sleep(long timeout){
26     set_current_state(TASK_INTERRUPTIBLE);
27
28     if(timeout <= 0){
29         schedule();
30     }else {
31        schedule_timeout(timeout);
32     }
33
34     return;
35 }
36
37 static void host_kthread_wakeup(void * thread){
38     struct task_struct * kthread = (struct task_struct *)thread;
39         
40     wake_up_process(kthread);
41 }
42
43 static void host_kthread_stop(void * thread){
44     struct task_struct * kthread = (struct task_struct *)thread;
45
46     while (kthread_stop(kthread)==-EINTR)
47         ;
48 }
49
50 static int host_kthread_should_stop(void){
51     return kthread_should_stop();
52 }
53
54
55 static void host_udelay(unsigned long usecs){
56     udelay(usecs);
57 }
58
59
60
61
62
63
64
65 struct host_timer {
66     struct timer_list timer;
67     unsigned long interval;
68
69     int active;
70     void (* timer_fun)(void * private_data);
71     void * pri_data;
72 };
73
74
75 void timeout_fn(unsigned long arg){
76     struct host_timer * timer = (struct host_timer *)arg;
77
78     if(timer->active){
79         timer->timer_fun(timer->pri_data);
80         
81         mod_timer(&(timer->timer), timer->interval);
82     }
83 }
84
85 static void *
86 host_create_timer(unsigned long interval, 
87                   void (* timer_fun)(void * priv_data), 
88                   void * data){
89     struct host_timer * timer = (struct host_timer *)kmalloc(sizeof(struct host_timer), GFP_KERNEL);
90
91     timer->interval = interval;
92     timer->timer_fun = timer_fun;
93     timer->pri_data = data;
94
95     init_timer(&(timer->timer));
96
97     timer->timer.data = (unsigned long)timer;
98     timer->timer.function = timeout_fn;
99     timer->timer.expires = interval;
100
101     return timer;
102 }
103
104 static void
105 host_start_timer(void * vnet_timer){
106     struct host_timer * timer = (struct host_timer *)vnet_timer;
107
108     timer->active = 1;
109     add_timer(&(timer->timer));
110 }
111
112 static void
113 host_reset_timer(void * vnet_timer, unsigned long interval){
114     struct host_timer * timer = (struct host_timer *)timer;
115
116     timer->interval = interval;
117 }
118
119 static void
120 host_stop_timer(void * vnet_timer){
121     struct host_timer * timer = (struct host_timer *)vnet_timer;
122
123     timer->active = 0;
124     del_timer(&(timer->timer));
125 }
126
127 static void
128 host_del_timer(void * vnet_timer){
129     struct host_timer * timer = (struct host_timer *)vnet_timer;
130
131     del_timer(&(timer->timer));
132
133     kfree(timer);
134 }
135
136
137
138
139
140 static struct vnet_host_hooks vnet_host_hooks = {
141     .timer_create               = host_create_timer,
142     .timer_del                  = host_del_timer,
143     .timer_start                = host_start_timer,
144     .timer_stop                 = host_stop_timer,
145     .timer_reset                = host_reset_timer,
146
147     .thread_start               = palacios_start_kernel_thread,
148     .thread_sleep               = host_kthread_sleep,
149     .thread_wakeup              = host_kthread_wakeup,
150     .thread_stop                = host_kthread_stop,
151     .thread_should_stop         = host_kthread_should_stop,
152     .udelay                     = host_udelay,
153
154     .yield_cpu                  = palacios_yield_cpu,
155     .mutex_alloc                = palacios_mutex_alloc,
156     .mutex_free                 = palacios_mutex_free,
157     .mutex_lock                 = palacios_mutex_lock, 
158     .mutex_unlock               = palacios_mutex_unlock,
159
160     .print                      = palacios_print,
161     .allocate_pages             = palacios_allocate_pages,
162     .free_pages                 = palacios_free_pages,
163     .malloc                     = palacios_alloc,
164     .free                       = palacios_free,
165     .vaddr_to_paddr             = palacios_vaddr_to_paddr,
166     .paddr_to_vaddr             = palacios_paddr_to_vaddr,
167 };
168
169
170
171 static int vnet_init( void ) {
172     init_vnet(&vnet_host_hooks);
173         
174     vnet_bridge_init();
175     vnet_ctrl_init();
176
177     INFO("V3 VNET Inited\n");
178         
179     return 0;
180 }
181
182
183 static int vnet_deinit( void ) {
184
185     INFO("V3 Control Deinit Start\n");
186
187     vnet_ctrl_deinit();
188
189     INFO("V3 Bridge Deinit Start\n");
190
191     vnet_bridge_deinit();
192
193     INFO("V3 VNET Deinit Start\n");
194
195     deinit_vnet();
196
197     INFO("V3 VNET Deinited\n");
198
199     return 0;
200 }
201
202 static struct linux_ext vnet_ext = {
203     .name = "VNET",
204     .init = vnet_init,
205     .deinit = vnet_deinit,
206     .guest_init = NULL,
207     .guest_deinit = NULL
208 };
209
210 register_extension(&vnet_ext);