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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2011, Peter Dinda <pdinda@northwestern.edu>
11 * Copyright (c) 2011, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Peter Dinda <pdinda@northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
21 #ifndef __VMM_HOST_DEV_H__
22 #define __VMM_HOST_DEV_H__
24 #include <palacios/vmm.h>
28 The purpose of this interface is to make it possible to implement
29 virtual devices in the host OS. It is intended to be used by
30 passthrough device implementations, such as the generic device
31 and the PCI passthrough device.
33 One use of this interface, and the generic and PCI passthrough devices
34 might be to build an interface with simulated devices in SST
35 under a Linux host. That scenario would look like this:
40 <device class="generic" id="mydev" impl="host_sst">
41 ports, memory regions, interrupts set with PASSTHROUGH option
44 PCI passthrough devive:
45 <device class="pci_passthrough" id="mydev", impl="host_sst">
46 vendor and device ids, etc
49 impl="physical" or lack of an impl key would indicate that direct hardware
50 access is expected, which is how these devices currently operate.
55 There would be an implementation and registration of the hooks
56 defined and explained in this file
58 The implementation might, for example, create an interface to
59 a user space process, for example like the console
60 (palacios-console.[ch] + v3_cons.c) or graphics console
61 (palacios-graphics-console.[ch] + v3_vncserver.c) do
62 and route the hook functions defined here through it.
63 Through this interface, the calls could be routed to an SST
69 /* A host device is opaque to the palacios */
70 typedef void * v3_host_dev_t;
71 /* A guest device is opaque to the host */
72 typedef void * v3_guest_dev_t;
75 /* There is a notion of a bus class to which the device is attached */
76 typedef enum { V3_BUS_CLASS_DIRECT, V3_BUS_CLASS_PCI } v3_bus_class_t;
82 v3_host_dev_t v3_host_dev_open(char *impl,
85 struct v3_vm_info *vm);
87 int v3_host_dev_close(v3_host_dev_t hdev);
89 uint64_t v3_host_dev_read_io(v3_host_dev_t hostdev,
94 uint64_t v3_host_dev_write_io(v3_host_dev_t hostdev,
99 uint64_t v3_host_dev_read_mem(v3_host_dev_t hostdev,
104 uint64_t v3_host_dev_write_mem(v3_host_dev_t hostdev,
109 int v3_host_dev_ack_irq(v3_host_dev_t hostdev, uint8_t irq);
111 uint64_t v3_host_dev_read_config(v3_host_dev_t hostdev,
116 uint64_t v3_host_dev_write_config(v3_host_dev_t hostdev,
123 struct v3_host_dev_hooks {
125 // The host is given the implementation name, the type of bus
126 // this device is attached to and an opaque pointer back to the
127 // guest device. It returns an opaque representation of
128 // the host device it has attached to, with zero indicating
129 // failure. The host_priv_data arguement supplies to the
130 // host the pointer that the VM was originally registered with
131 v3_host_dev_t (*open)(char *impl,
134 void *host_priv_data);
136 int (*close)(v3_host_dev_t hdev);
138 // Read/Write from/to an IO port. The read must either
139 // completely succeed, returning len or completely
140 // fail, returning != len
141 // Callee gets the host dev id and the port in the guest
142 uint64_t (*read_io)(v3_host_dev_t hostdev,
147 uint64_t (*write_io)(v3_host_dev_t hostdev,
152 // Read/Write from/to memory. The reads/writes must
153 // completely succeed, returning len or completely
154 // fail, returning != len
155 // Callee gets the host dev id, and the guest physical address
156 uint64_t (*read_mem)(v3_host_dev_t hostdev,
161 uint64_t (*write_mem)(v3_host_dev_t hostdev,
167 // Palacios or the guest device will call this
168 // function when it has injected the irq
169 // requested by the guest
171 int (*ack_irq)(v3_host_dev_t hostdev, uint8_t irq);
173 // Configuration space reads/writes for devices that
174 // have them, such as PCI devices
175 // As with other reads/writes, these must be fully successful
178 // Palacios maintains its own configuration for some
179 // devices (e.g., pci_passthrough) and will take care of
180 // relevant hooking/unhooking, and maintain its own
181 // config space info. However, a read will return
182 // the host device's config, while a write will affect
183 // both the palacios-internal config and the hsot device's config
185 // for V3_BUS_CLASS_PCI they correspond to PCI config space (e.g., BARS, etc)
188 uint64_t (*read_config)(v3_host_dev_t hostdev,
193 uint64_t (*write_config)(v3_host_dev_t hostdev,
200 /* This function is how the host will raise an irq to palacios
201 for the device. The IRQ argument will be ignored for devices
202 whose irqs are managed by palacios */
203 int v3_host_dev_raise_irq(v3_host_dev_t hostdev,
204 v3_guest_dev_t guest_dev,
207 /* These functions allow the host to read and write the guest
208 memory by physical address, for example to implement DMA
210 uint64_t v3_host_dev_read_guest_mem(v3_host_dev_t hostdev,
211 v3_guest_dev_t guest_dev,
216 uint64_t v3_host_dev_write_guest_mem(v3_host_dev_t hostdev,
217 v3_guest_dev_t guest_dev,
223 extern void V3_Init_Host_Device_Support(struct v3_host_dev_hooks *hooks);