2 * Palacios VNET Host Hooks Implementations
6 #include <linux/kernel.h>
7 #include <linux/kthread.h>
8 #include <linux/spinlock.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>
16 #include <vnet/vnet.h>
19 #include "palacios-vnet.h"
20 #include "linux-exts.h"
25 static void host_kthread_sleep(long timeout){
26 set_current_state(TASK_INTERRUPTIBLE);
31 schedule_timeout(timeout);
37 static void host_kthread_wakeup(void * thread){
38 struct task_struct * kthread = (struct task_struct *)thread;
40 wake_up_process(kthread);
43 static void host_kthread_stop(void * thread){
44 struct task_struct * kthread = (struct task_struct *)thread;
46 while (kthread_stop(kthread)==-EINTR)
50 static int host_kthread_should_stop(void){
51 return kthread_should_stop();
55 static void host_udelay(unsigned long usecs){
66 struct timer_list timer;
67 unsigned long interval;
70 void (* timer_fun)(void * private_data);
75 void timeout_fn(unsigned long arg){
76 struct host_timer * timer = (struct host_timer *)arg;
79 timer->timer_fun(timer->pri_data);
81 mod_timer(&(timer->timer), timer->interval);
86 host_create_timer(unsigned long interval,
87 void (* timer_fun)(void * priv_data),
89 struct host_timer * timer = (struct host_timer *)palacios_alloc(sizeof(struct host_timer));
92 ERROR("Unable to allocate timer in VNET\n");
96 timer->interval = interval;
97 timer->timer_fun = timer_fun;
98 timer->pri_data = data;
100 init_timer(&(timer->timer));
102 timer->timer.data = (unsigned long)timer;
103 timer->timer.function = timeout_fn;
104 timer->timer.expires = interval;
110 host_start_timer(void * vnet_timer){
111 struct host_timer * timer = (struct host_timer *)vnet_timer;
114 add_timer(&(timer->timer));
118 host_reset_timer(void * vnet_timer, unsigned long interval){
119 struct host_timer * timer = (struct host_timer *)timer;
121 timer->interval = interval;
125 host_stop_timer(void * vnet_timer){
126 struct host_timer * timer = (struct host_timer *)vnet_timer;
129 del_timer(&(timer->timer));
133 host_del_timer(void * vnet_timer){
134 struct host_timer * timer = (struct host_timer *)vnet_timer;
136 del_timer(&(timer->timer));
138 palacios_free(timer);
143 static struct vnet_host_hooks vnet_host_hooks = {
144 .timer_create = host_create_timer,
145 .timer_del = host_del_timer,
146 .timer_start = host_start_timer,
147 .timer_stop = host_stop_timer,
148 .timer_reset = host_reset_timer,
150 .thread_start = palacios_start_kernel_thread,
151 .thread_sleep = host_kthread_sleep,
152 .thread_wakeup = host_kthread_wakeup,
153 .thread_stop = host_kthread_stop,
154 .thread_should_stop = host_kthread_should_stop,
155 .udelay = host_udelay,
157 .yield_cpu = palacios_yield_cpu,
158 .mutex_alloc = palacios_mutex_alloc,
159 .mutex_free = palacios_mutex_free,
160 .mutex_lock = palacios_mutex_lock,
161 .mutex_unlock = palacios_mutex_unlock,
162 .mutex_lock_irqsave = palacios_mutex_lock_irqsave,
163 .mutex_unlock_irqrestore = palacios_mutex_unlock_irqrestore,
165 .print = palacios_print_scoped,
166 .allocate_pages = palacios_allocate_pages,
167 .free_pages = palacios_free_pages,
168 .malloc = palacios_alloc,
169 .free = palacios_free,
170 .vaddr_to_paddr = palacios_vaddr_to_paddr,
171 .paddr_to_vaddr = palacios_paddr_to_vaddr,
176 static int vnet_init( void ) {
177 init_vnet(&vnet_host_hooks);
182 INFO("V3 VNET Inited\n");
188 static int vnet_deinit( void ) {
190 INFO("V3 Control Deinit Start\n");
194 INFO("V3 Bridge Deinit Start\n");
196 vnet_bridge_deinit();
198 INFO("V3 VNET Deinit Start\n");
202 INFO("V3 VNET Deinited\n");
207 static struct linux_ext vnet_ext = {
210 .deinit = vnet_deinit,
215 register_extension(&vnet_ext);