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.


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