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.


57fea7cbbc8cebe97ef69843ed1eb80b25f878a6
[palacios.git] / palacios / include / interfaces / vmm_host_dev.h
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 #ifndef __VMM_HOST_DEV_H__
22 #define __VMM_HOST_DEV_H__
23
24 #include <palacios/vmm.h>
25
26
27 /*
28
29   The purpose of this interface is to make it possible to implement
30   virtual devices in the host OS.   It is intended to be used by 
31   passthrough device implementations, such as the generic device 
32   and the PCI passthrough device.  
33
34   One use of this interface, and the generic and PCI passthrough devices
35   might be to build an interface with simulated devices in SST 
36   under a Linux host.  That scenario would look like this:
37
38 Guest config:
39
40   generic device:
41     <device class="generic" id="mydev" impl="host_sst">
42        ports, memory regions, interrupts set with PASSTHROUGH option 
43     </device>
44
45   PCI passthrough devive:
46     <device class="pci_passthrough" id="mydev", impl="host_sst">
47        vendor and device ids, etc
48     </device>
49
50 impl="physical" or lack of an impl key would indicate that direct hardware
51 access is expected, which is how these devices currently operate. 
52
53
54 Host (Linux) side:
55
56     There would be an implementation and registration of the hooks 
57     defined and explained in this file
58
59     The implementation might, for example, create an interface to 
60     a user space process, for example like the console 
61     (palacios-console.[ch] + v3_cons.c) or graphics console
62     (palacios-graphics-console.[ch] + v3_vncserver.c) do
63     and route the hook functions defined here through it. 
64     Through this interface, the calls could be routed to an SST
65     device module.   
66
67 */
68
69
70 /* A host device is opaque to the palacios */
71 typedef void * v3_host_dev_t;
72 /* A guest device is opaque to the host */
73 typedef void * v3_guest_dev_t;
74
75
76 /* There is a notion of a bus class to which the device is attached */
77 typedef enum { V3_BUS_CLASS_DIRECT, V3_BUS_CLASS_PCI } v3_bus_class_t;
78
79 #ifdef __V3VEE__
80
81 struct v3_vm_info;
82
83 v3_host_dev_t v3_host_dev_open(char *impl, 
84                                v3_bus_class_t bus,
85                                v3_guest_dev_t gdev,
86                                struct v3_vm_info *vm); 
87
88 int v3_host_dev_close(v3_host_dev_t hdev);
89     
90 uint64_t v3_host_dev_read_io(v3_host_dev_t hostdev,  
91                              uint16_t      port,
92                              void          *dest,
93                              uint64_t      len);
94
95 uint64_t v3_host_dev_write_io(v3_host_dev_t hostdev, 
96                               uint16_t      port,
97                               void          *src,
98                               uint64_t      len);
99
100 uint64_t v3_host_dev_read_mem(v3_host_dev_t hostdev, 
101                               addr_t        gpa,
102                               void          *dest,
103                               uint64_t      len);
104
105 uint64_t v3_host_dev_write_mem(v3_host_dev_t hostdev, 
106                                addr_t        gpa,
107                                void          *src,
108                                uint64_t      len);
109
110 int v3_host_dev_ack_irq(v3_host_dev_t hostdev, uint8_t irq);
111
112 uint64_t v3_host_dev_config_read(v3_host_dev_t hostdev, 
113                                  uint64_t      offset,
114                                  void          *dest,
115                                  uint64_t      len);
116
117 uint64_t v3_host_dev_config_write(v3_host_dev_t hostdev, 
118                                  uint64_t      offset,
119                                   void          *src,
120                                   uint64_t      len);
121  
122 #endif
123
124 struct v3_host_dev_hooks {
125     
126     // The host is given the implementation name, the type of bus
127     // this device is attached to and an opaque pointer back to the
128     // guest device.  It returns an opaque representation of 
129     // the host device it has attached to, with zero indicating
130     // failure.  The host_priv_data arguement supplies to the 
131     // host the pointer that the VM was originally registered with
132     v3_host_dev_t (*open)(char *impl, 
133                           v3_bus_class_t bus,
134                           v3_guest_dev_t gdev,
135                           void *host_priv_data);
136
137     int (*close)(v3_host_dev_t hdev);
138     
139     // Read/Write from/to an IO port. The read must either
140     // completely succeed, returning len or completely
141     // fail, returning != len
142     // Callee gets the host dev id and the port in the guest
143     uint64_t (*read_io)(v3_host_dev_t hostdev, 
144                         uint16_t      port,
145                         void          *dest,
146                         uint64_t      len);
147
148     uint64_t (*write_io)(v3_host_dev_t hostdev, 
149                          uint16_t      port,
150                          void          *src,
151                          uint64_t      len);
152     
153     // Read/Write from/to memory. The reads/writes must
154     // completely succeed, returning len or completely
155     // fail, returning != len
156     // Callee gets the host dev id, and the guest physical address
157     uint64_t (*read_mem)(v3_host_dev_t hostdev, 
158                          addr_t        gpa,
159                          void          *dest,
160                          uint64_t      len);
161     
162     uint64_t (*write_mem)(v3_host_dev_t hostdev, 
163                           addr_t        gpa,
164                           void          *src,
165                           uint64_t      len);
166     
167     //
168     // Palacios or the guest device will call this
169     // function when it has injected the irq
170     // requested by the guest
171     // 
172     int (*ack_irq)(v3_host_dev_t hostdev, uint8_t irq);
173
174     // Configuration space reads/writes for devices that
175     // have them, such as PCI devices
176     // As with other reads/writes, these must be fully successful
177     // or fail
178     //
179     // Palacios maintains its own configuration for some
180     // devices (e.g., pci_passthrough) and will take care of 
181     // relevant hooking/unhooking, and maintain its own
182     // config space info.   However, a read will return
183     // the host device's config, while a write will affect
184     // both the palacios-internal config and the hsot device's config
185     //
186     // for V3_BUS_CLASS_PCI they correspond to PCI config space (e.g., BARS, etc)
187     // reads and writes
188     //
189     uint64_t (*read_config)(v3_host_dev_t hostdev, 
190                             uint64_t      offset,
191                             void          *dest,
192                             uint64_t      len);
193     
194     uint64_t (*write_config)(v3_host_dev_t hostdev,
195                              uint64_t      offset,
196                              void          *src,
197                              uint64_t      len);
198  
199 };
200
201 /* This function is how the host will raise an irq to palacios
202    for the device.   The IRQ argument will be ignored for devices
203    whose irqs are managed by palacios */
204 int v3_host_dev_raise_irq(v3_host_dev_t hostdev,
205                           v3_guest_dev_t guest_dev,
206                           uint8_t irq);
207
208 /* These functions allow the host to read and write the guest
209    memory by physical address, for example to implement DMA 
210 */
211 uint64_t v3_host_dev_read_guest_mem(v3_host_dev_t  hostdev,
212                                     v3_guest_dev_t guest_dev,
213                                     addr_t         gpa,
214                                     void           *dest,
215                                     uint64_t       len);
216
217 uint64_t v3_host_dev_write_guest_mem(v3_host_dev_t  hostdev,
218                                      v3_guest_dev_t guest_dev,
219                                      addr_t         gpa,
220                                      void           *src,
221                                      uint64_t       len);
222                               
223
224 extern void V3_Init_Host_Device_Support(struct v3_host_dev_hooks *hooks);
225
226 #endif