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.


ebae33148ae3122027e50277ae75be4cbfbe99e2
[palacios.git] / palacios / src / interfaces / vmm_host_dev.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) 2011, Peter Dinda <pdinda@northwestern.edu>
11  * Copyright (c) 2011, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Peter Dinda <pdinda@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
21 #include <interfaces/vmm_host_dev.h>
22 #include <palacios/vmm.h>
23 #include <palacios/vmm_debug.h>
24 #include <palacios/vmm_types.h>
25 #include <palacios/vm_guest.h>
26 #include <palacios/vm_guest_mem.h>
27
28 struct v3_host_dev_hooks * host_dev_hooks = 0;
29
30 v3_host_dev_t v3_host_dev_open(char *impl,
31                                v3_bus_class_t bus,
32                                v3_guest_dev_t gdev,
33                                struct v3_vm_info *vm)
34 {                                              
35     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks != NULL);
36     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks->open != NULL);
37
38     return host_dev_hooks->open(impl,bus,gdev,vm->host_priv_data);
39 }
40
41 int v3_host_dev_close(v3_host_dev_t hdev) 
42 {
43     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks);
44     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks->close);
45
46     return host_dev_hooks->close(hdev);
47 }
48
49 uint64_t v3_host_dev_read_io(v3_host_dev_t hdev,
50                              uint16_t port,
51                              void *dst,
52                              uint64_t len)
53 {
54     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks != NULL);
55     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks->read_io != NULL);
56     
57     return host_dev_hooks->read_io(hdev,port,dst,len);
58 }
59
60 uint64_t v3_host_dev_write_io(v3_host_dev_t hdev,
61                               uint16_t port,
62                               void *src,
63                               uint64_t len)
64 {
65     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks != NULL);
66     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks->write_io != NULL);
67     
68     return host_dev_hooks->write_io(hdev,port,src,len);
69 }
70
71 uint64_t v3_host_dev_read_mem(v3_host_dev_t hdev,
72                               addr_t gpa,
73                               void *dst,
74                               uint64_t len)
75 {
76     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks != NULL);
77     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks->read_mem != NULL);
78     
79     return host_dev_hooks->read_mem(hdev,(void*)gpa,dst,len);
80 }
81
82 uint64_t v3_host_dev_write_mem(v3_host_dev_t hdev,
83                               addr_t gpa,
84                               void *src,
85                               uint64_t len)
86 {
87     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks != NULL);
88     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks->write_mem != NULL);
89     
90     return host_dev_hooks->write_mem(hdev,(void*)gpa,src,len);
91 }
92
93 uint64_t v3_host_dev_read_config(v3_host_dev_t hdev,
94                                  uint64_t offset,
95                                  void *dst,
96                                  uint64_t len)
97 {
98     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks != NULL);
99     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks->read_config);
100
101     return host_dev_hooks->read_config(hdev,offset,dst,len);
102 }
103
104 uint64_t v3_host_dev_write_config(v3_host_dev_t hdev,
105                                   uint64_t offset,
106                                   void *src,
107                                   uint64_t len)
108 {
109     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks != NULL);
110     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks->write_config);
111     
112     return host_dev_hooks->write_config(hdev,offset,src,len);
113
114 }
115
116
117 int v3_host_dev_ack_irq(v3_host_dev_t hdev, uint8_t irq)
118 {
119     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks != NULL);
120     V3_ASSERT(VM_NONE, VCORE_NONE, host_dev_hooks->ack_irq);
121
122     return host_dev_hooks->ack_irq(hdev,irq);
123 }
124
125
126 int v3_host_dev_raise_irq(v3_host_dev_t hostdev,
127                           v3_guest_dev_t guest_dev,
128                           uint8_t irq)
129 {
130     // Make this smarter later...
131
132     struct vm_device *dev = (struct vm_device *) guest_dev;
133     
134     if (dev && dev->vm) { 
135         return v3_raise_irq(dev->vm,irq);
136     } else {
137         return -1;
138     }
139 }
140
141
142 uint64_t v3_host_dev_read_guest_mem(v3_host_dev_t  hostdev,
143                                     v3_guest_dev_t guest_dev,
144                                     void *         gpa,
145                                     void           *dst,
146                                     uint64_t       len)
147 {
148     struct vm_device *dev = (struct vm_device *) guest_dev;
149
150     if (!dev) { 
151         return 0;
152     } else {
153         struct v3_vm_info *vm = dev->vm;
154         
155         if (!vm) { 
156             return 0;
157         } else {
158             return v3_read_gpa_memory(&(vm->cores[0]), (addr_t)gpa, len, dst);
159         }
160     }
161 }
162
163 uint64_t v3_host_dev_write_guest_mem(v3_host_dev_t  hostdev,
164                                      v3_guest_dev_t guest_dev,
165                                      void *         gpa,
166                                      void           *src,
167                                      uint64_t       len)
168 {
169     struct vm_device *dev = (struct vm_device *) guest_dev;
170
171     if (!dev) { 
172         return 0;
173     } else {
174         struct v3_vm_info *vm = dev->vm;
175         
176         if (!vm) { 
177             return 0;
178         } else {
179             return v3_write_gpa_memory(&(vm->cores[0]), (addr_t)gpa, len, src);
180         }
181     }
182 }
183
184
185
186 void V3_Init_Host_Device_Support(struct v3_host_dev_hooks * hooks) {
187     host_dev_hooks = hooks;
188     PrintDebug(VM_NONE, VCORE_NONE, "V3 host device interface inited\n");
189
190     return;
191 }