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.


3d441025e7b20e9494679b7e924824a9a9537a45
[palacios-OLD.git] / kitten / palacios-glue / vmm_stubs.c
1 /*
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20 #include <palacios/vmm.h>
21 #include <palacios/vmm_host_events.h>
22
23 #include <lwk/pmem.h>
24
25 struct guest_info * g_vm_guest = NULL;
26
27
28 // This is the function the interface code should call to deliver
29 // the interrupt to the vmm for handling
30 //extern int v3_deliver_interrupt(struct guest_info * vm, struct v3_interrupt *intr);
31
32
33 struct guest_info * irq_to_guest_map[256];
34
35
36
37
38
39 void Init_Stubs(struct guest_info * info) {
40   memset(irq_to_guest_map, 0, sizeof(struct guest_info *) * 256);
41   g_vm_guest = info;
42 }
43
44
45 void * kitten_pa_to_va(void *ptr)
46 {
47   return __va(ptr);
48 }
49
50 void * kitten_va_to_pa(void *ptr)
51 {
52   return __pa(ptr);
53 }
54
55 void * Allocate_VMM_Pages(int num_pages) 
56 {
57   int rc;
58   struct pmem_region result;
59   
60   rc=pmem_alloc_umem(num_pages*PAGE_SIZE,PAGE_SIZE,&result);
61   
62   if (rc) {
63     return 0;
64   } else {
65     return result.start;
66   }
67 }
68
69 void Free_VMM_Page(void * page) 
70 {
71   int rc;
72   struct pmem_region query;
73   struct pmem_region result;
74
75   pmem_region_unset_all(&query);
76
77   query.start=page;
78   query.end=page+PAGE_SIZE;
79
80   rc=pmem_query(&query,&result);
81
82   if (!rc) { 
83     result.allocated=FALSE;
84     pmem_update(&result);
85   } else {
86     // BAD
87   }
88 }
89
90
91 void * VMM_Malloc(unsigned int size) {
92   return Malloc((unsigned long) size);
93 }
94
95
96 void VMM_Free(void * addr) {
97   Free(addr);
98 }
99
100
101
102 void send_key_to_vmm(unsigned char status, unsigned char scancode) {
103   struct v3_keyboard_event evt;
104
105   evt.status = status;
106   evt.scan_code = scancode;
107
108   if (g_vm_guest) {
109     v3_deliver_keyboard_event(g_vm_guest, &evt);
110   }
111 }
112
113
114 void send_mouse_to_vmm(unsigned char packet[3]) {
115   struct v3_mouse_event evt;
116
117   memcpy(evt.data, packet, 3);
118
119   if (g_vm_guest) {
120     v3_deliver_mouse_event(g_vm_guest, &evt);
121   }
122 }
123
124 void send_tick_to_vmm(unsigned int period_us) {
125   struct v3_timer_event evt;
126
127   evt.period_us = period_us;
128
129   if (g_vm_guest) {
130     v3_deliver_timer_event(g_vm_guest, &evt);
131   }
132 }
133
134
135 void translate_intr_handler(struct pt_regs *regs, unsigned int vector) 
136 {
137   struct v3_interrupt intr;
138
139   intr.irq = vector-32;
140   intr.error = regs->orig_rax;
141   intr.should_ack = 0;
142
143   //  PrintBoth("translate_intr_handler: opaque=0x%x\n",mystate.opaque);
144
145   v3_deliver_irq(irq_to_guest_map[intr.irq], &intr);
146
147 }
148
149
150
151 int kitten_hook_interrupt(struct guest_info * vm, unsigned int  irq)
152 {
153   if (irq_to_guest_map[irq]) { 
154     //PrintBoth("Attempt to hook interrupt that is already hooked\n");
155     return -1;
156   } else {
157     //PrintBoth("Hooked interrupt 0x%x with opaque 0x%x\n", irq, vm);
158     irq_to_guest_map[irq] = vm;
159   }
160
161   set_idtvec_handler(irq,translate_intr_handler);
162   return 0;
163 }
164
165
166 int ack_irq(int irq) 
167 {
168   lapic_ack_interrupt();
169   return 0;
170 }
171
172   
173
174
175 unsigned int get_cpu_khz() 
176 {
177   return   cpu_info[0].arch.cur_cpu_khz;
178 }
179
180