1170754Sdelphij/*- 2170754Sdelphij * SPDX-License-Identifier: BSD-2-Clause 3170754Sdelphij * 4170754Sdelphij * Copyright (c) 2013 Chris Torek <torek @ torek net> 5170754Sdelphij * All rights reserved. 6170754Sdelphij * 7170754Sdelphij * Redistribution and use in source and binary forms, with or without 8170754Sdelphij * modification, are permitted provided that the following conditions 9170754Sdelphij * are met: 10170754Sdelphij * 1. Redistributions of source code must retain the above copyright 11170754Sdelphij * notice, this list of conditions and the following disclaimer. 12170754Sdelphij * 2. Redistributions in binary form must reproduce the above copyright 13170754Sdelphij * notice, this list of conditions and the following disclaimer in the 14170754Sdelphij * documentation and/or other materials provided with the distribution. 15170754Sdelphij * 16170754Sdelphij * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17170754Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18170754Sdelphij * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19170754Sdelphij * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20170754Sdelphij * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21170754Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22170754Sdelphij * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23170754Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24170754Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25170754Sdelphij * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26170754Sdelphij * SUCH DAMAGE. 27170754Sdelphij */ 28170754Sdelphij 29170754Sdelphij#ifndef _BHYVE_VIRTIO_H_ 30170754Sdelphij#define _BHYVE_VIRTIO_H_ 31170754Sdelphij 32170754Sdelphij#include <machine/atomic.h> 33170754Sdelphij 34170754Sdelphij#include <dev/virtio/virtio.h> 35170754Sdelphij#include <dev/virtio/virtio_ring.h> 36170754Sdelphij#include <dev/virtio/pci/virtio_pci_var.h> 37170754Sdelphij 38170754Sdelphij/* 39170754Sdelphij * These are derived from several virtio specifications. 40170754Sdelphij * 41170754Sdelphij * Some useful links: 42170754Sdelphij * https://github.com/rustyrussell/virtio-spec 43170754Sdelphij * http://people.redhat.com/pbonzini/virtio-spec.pdf 44170754Sdelphij */ 45170754Sdelphij 46170754Sdelphij/* 47170754Sdelphij * A virtual device has zero or more "virtual queues" (virtqueue). 48170754Sdelphij * Each virtqueue uses at least two 4096-byte pages, laid out thus: 49170754Sdelphij * 50170754Sdelphij * +-----------------------------------------------+ 51170754Sdelphij * | "desc": <N> descriptors, 16 bytes each | 52170754Sdelphij * | ----------------------------------------- | 53170754Sdelphij * | "avail": 2 uint16; <N> uint16; 1 uint16 | 54170754Sdelphij * | ----------------------------------------- | 55170754Sdelphij * | pad to 4k boundary | 56170754Sdelphij * +-----------------------------------------------+ 57170754Sdelphij * | "used": 2 x uint16; <N> elems; 1 uint16 | 58170754Sdelphij * | ----------------------------------------- | 59170754Sdelphij * | pad to 4k boundary | 60170754Sdelphij * +-----------------------------------------------+ 61170754Sdelphij * 62170754Sdelphij * The number <N> that appears here is always a power of two and is 63170754Sdelphij * limited to no more than 32768 (as it must fit in a 16-bit field). 64170754Sdelphij * If <N> is sufficiently large, the above will occupy more than 65170754Sdelphij * two pages. In any case, all pages must be physically contiguous 66170754Sdelphij * within the guest's physical address space. 67170754Sdelphij * 68170754Sdelphij * The <N> 16-byte "desc" descriptors consist of a 64-bit guest 69170754Sdelphij * physical address <addr>, a 32-bit length <len>, a 16-bit 70170754Sdelphij * <flags>, and a 16-bit <next> field (all in guest byte order). 71170754Sdelphij * 72170754Sdelphij * There are three flags that may be set : 73170754Sdelphij * NEXT descriptor is chained, so use its "next" field 74170754Sdelphij * WRITE descriptor is for host to write into guest RAM 75170754Sdelphij * (else host is to read from guest RAM) 76170754Sdelphij * INDIRECT descriptor address field is (guest physical) 77170754Sdelphij * address of a linear array of descriptors 78170754Sdelphij * 79170754Sdelphij * Unless INDIRECT is set, <len> is the number of bytes that may 80170754Sdelphij * be read/written from guest physical address <addr>. If 81170754Sdelphij * INDIRECT is set, WRITE is ignored and <len> provides the length 82170754Sdelphij * of the indirect descriptors (and <len> must be a multiple of 83170754Sdelphij * 16). Note that NEXT may still be set in the main descriptor 84170754Sdelphij * pointing to the indirect, and should be set in each indirect 85170754Sdelphij * descriptor that uses the next descriptor (these should generally 86170754Sdelphij * be numbered sequentially). However, INDIRECT must not be set 87170754Sdelphij * in the indirect descriptors. Upon reaching an indirect descriptor 88170754Sdelphij * without a NEXT bit, control returns to the direct descriptors. 89170754Sdelphij * 90170754Sdelphij * Except inside an indirect, each <next> value must be in the 91170754Sdelphij * range [0 .. N) (i.e., the half-open interval). (Inside an 92170754Sdelphij * indirect, each <next> must be in the range [0 .. <len>/16).) 93170754Sdelphij * 94170754Sdelphij * The "avail" data structures reside in the same pages as the 95170754Sdelphij * "desc" structures since both together are used by the device to 96170754Sdelphij * pass information to the hypervisor's virtual driver. These 97170754Sdelphij * begin with a 16-bit <flags> field and 16-bit index <idx>, then 98170754Sdelphij * have <N> 16-bit <ring> values, followed by one final 16-bit 99170754Sdelphij * field <used_event>. The <N> <ring> entries are simply indices 100170754Sdelphij * into the descriptor ring (and thus must meet the same 101170754Sdelphij * constraints as each <next> value). However, <idx> is counted 102170754Sdelphij * up from 0 (initially) and simply wraps around after 65535; it 103170754Sdelphij * is taken mod <N> to find the next available entry. 104170754Sdelphij * 105170754Sdelphij * The "used" ring occupies a separate page or pages, and contains 106170754Sdelphij * values written from the virtual driver back to the guest OS. 107170754Sdelphij * This begins with a 16-bit <flags> and 16-bit <idx>, then there 108170754Sdelphij * are <N> "vring_used" elements, followed by a 16-bit <avail_event>. 109170754Sdelphij * The <N> "vring_used" elements consist of a 32-bit <id> and a 110170754Sdelphij * 32-bit <len> (vu_tlen below). The <id> is simply the index of 111170754Sdelphij * the head of a descriptor chain the guest made available 112170754Sdelphij * earlier, and the <len> is the number of bytes actually written, 113170754Sdelphij * e.g., in the case of a network driver that provided a large 114170754Sdelphij * receive buffer but received only a small amount of data. 115170754Sdelphij * 116170754Sdelphij * The two event fields, <used_event> and <avail_event>, in the 117170754Sdelphij * avail and used rings (respectively -- note the reversal!), are 118170754Sdelphij * always provided, but are used only if the virtual device 119170754Sdelphij * negotiates the VIRTIO_RING_F_EVENT_IDX feature during feature 120170754Sdelphij * negotiation. Similarly, both rings provide a flag -- 121170754Sdelphij * VRING_AVAIL_F_NO_INTERRUPT and VRING_USED_F_NO_NOTIFY -- in 122170754Sdelphij * their <flags> field, indicating that the guest does not need an 123170754Sdelphij * interrupt, or that the hypervisor driver does not need a 124170754Sdelphij * notify, when descriptors are added to the corresponding ring. 125170754Sdelphij * (These are provided only for interrupt optimization and need 126170754Sdelphij * not be implemented.) 127170754Sdelphij */ 128170754Sdelphij#define VRING_ALIGN 4096 129170754Sdelphij 130170754Sdelphij/* 131170754Sdelphij * The address of any given virtual queue is determined by a single 132170754Sdelphij * Page Frame Number register. The guest writes the PFN into the 133170754Sdelphij * PCI config space. However, a device that has two or more 134170754Sdelphij * virtqueues can have a different PFN, and size, for each queue. 135170754Sdelphij * The number of queues is determinable via the PCI config space 136170754Sdelphij * VTCFG_R_QSEL register. Writes to QSEL select the queue: 0 means 137170754Sdelphij * queue #0, 1 means queue#1, etc. Once a queue is selected, the 138170754Sdelphij * remaining PFN and QNUM registers refer to that queue. 139170754Sdelphij * 140239360Sobrien * QNUM is a read-only register containing a nonzero power of two 141170754Sdelphij * that indicates the (hypervisor's) queue size. Or, if reading it 142170754Sdelphij * produces zero, the hypervisor does not have a corresponding 143170754Sdelphij * queue. (The number of possible queues depends on the virtual 144170754Sdelphij * device. The block device has just one; the network device 145170754Sdelphij * provides either two -- 0 = receive, 1 = transmit -- or three, 146170754Sdelphij * with 2 = control.) 147170754Sdelphij * 148170754Sdelphij * PFN is a read/write register giving the physical page address of 149170754Sdelphij * the virtqueue in guest memory (the guest must allocate enough space 150170754Sdelphij * based on the hypervisor's provided QNUM). 151170754Sdelphij * 152170754Sdelphij * QNOTIFY is effectively write-only: when the guest writes a queue 153170754Sdelphij * number to the register, the hypervisor should scan the specified 154170754Sdelphij * virtqueue. (Reading QNOTIFY currently always gets 0). 155170754Sdelphij */ 156170754Sdelphij 157170754Sdelphij/* 158170754Sdelphij * PFN register shift amount 159170754Sdelphij */ 160170754Sdelphij#define VRING_PFN 12 161170754Sdelphij 162170754Sdelphij/* 163170754Sdelphij * PCI vendor/device IDs 164170754Sdelphij */ 165170754Sdelphij#define VIRTIO_VENDOR 0x1AF4 166170754Sdelphij#define VIRTIO_DEV_NET 0x1000 167170754Sdelphij#define VIRTIO_DEV_BLOCK 0x1001 168170754Sdelphij#define VIRTIO_DEV_CONSOLE 0x1003 169170754Sdelphij#define VIRTIO_DEV_SCSI 0x1004 170170754Sdelphij#define VIRTIO_DEV_RANDOM 0x1005 171170754Sdelphij#define VIRTIO_DEV_9P 0x1009 172170754Sdelphij#define VIRTIO_DEV_INPUT 0x1052 173170754Sdelphij 174170754Sdelphij/* 175170754Sdelphij * PCI revision IDs 176170754Sdelphij */ 177170754Sdelphij#define VIRTIO_REV_INPUT 1 178170754Sdelphij 179170754Sdelphij/* 180170754Sdelphij * PCI subvendor IDs 181170754Sdelphij */ 182170754Sdelphij#define VIRTIO_SUBVEN_INPUT 0x108E 183170754Sdelphij 184170754Sdelphij/* 185170754Sdelphij * PCI subdevice IDs 186170754Sdelphij */ 187170754Sdelphij#define VIRTIO_SUBDEV_INPUT 0x1100 188170754Sdelphij 189170754Sdelphij/* From section 2.3, "Virtqueue Configuration", of the virtio specification */ 190170754Sdelphijstatic inline int 191170754Sdelphijvring_size_aligned(u_int qsz) 192170754Sdelphij{ 193170754Sdelphij return (roundup2(vring_size(qsz, VRING_ALIGN), VRING_ALIGN)); 194170754Sdelphij} 195170754Sdelphij 196170754Sdelphijstruct pci_devinst; 197170754Sdelphijstruct vqueue_info; 198170754Sdelphijstruct vm_snapshot_meta; 199170754Sdelphij 200170754Sdelphij/* 201170754Sdelphij * A virtual device, with some number (possibly 0) of virtual 202170754Sdelphij * queues and some size (possibly 0) of configuration-space 203170754Sdelphij * registers private to the device. The virtio_softc should come 204170754Sdelphij * at the front of each "derived class", so that a pointer to the 205170754Sdelphij * virtio_softc is also a pointer to the more specific, derived- 206170754Sdelphij * from-virtio driver's softc. 207170754Sdelphij * 208170754Sdelphij * Note: inside each hypervisor virtio driver, changes to these 209170754Sdelphij * data structures must be locked against other threads, if any. 210170754Sdelphij * Except for PCI config space register read/write, we assume each 211170754Sdelphij * driver does the required locking, but we need a pointer to the 212170754Sdelphij * lock (if there is one) for PCI config space read/write ops. 213170754Sdelphij * 214170754Sdelphij * When the guest reads or writes the device's config space, the 215170754Sdelphij * generic layer checks for operations on the special registers 216170754Sdelphij * described above. If the offset of the register(s) being read 217170754Sdelphij * or written is past the CFG area (CFG0 or CFG1), the request is 218170754Sdelphij * passed on to the virtual device, after subtracting off the 219170754Sdelphij * generic-layer size. (So, drivers can just use the offset as 220170754Sdelphij * an offset into "struct config", for instance.) 221170754Sdelphij * 222170754Sdelphij * (The virtio layer also makes sure that the read or write is to/ 223170754Sdelphij * from a "good" config offset, hence vc_cfgsize, and on BAR #0. 224170754Sdelphij * However, the driver must verify the read or write size and offset 225170754Sdelphij * and that no one is writing a readonly register.) 226170754Sdelphij * 227170754Sdelphij * The BROKED flag ("this thing done gone and broked") is for future 228170754Sdelphij * use. 229170754Sdelphij */ 230170754Sdelphij#define VIRTIO_USE_MSIX 0x01 231170754Sdelphij#define VIRTIO_EVENT_IDX 0x02 /* use the event-index values */ 232170754Sdelphij#define VIRTIO_BROKED 0x08 /* ??? */ 233170754Sdelphij 234170754Sdelphijstruct virtio_softc { 235170754Sdelphij struct virtio_consts *vs_vc; /* constants (see below) */ 236170754Sdelphij int vs_flags; /* VIRTIO_* flags from above */ 237170754Sdelphij pthread_mutex_t *vs_mtx; /* POSIX mutex, if any */ 238170754Sdelphij struct pci_devinst *vs_pi; /* PCI device instance */ 239170754Sdelphij uint32_t vs_negotiated_caps; /* negotiated capabilities */ 240170754Sdelphij struct vqueue_info *vs_queues; /* one per vc_nvq */ 241170754Sdelphij int vs_curq; /* current queue */ 242170754Sdelphij uint8_t vs_status; /* value from last status write */ 243170754Sdelphij uint8_t vs_isr; /* ISR flags, if not MSI-X */ 244170754Sdelphij uint16_t vs_msix_cfg_idx; /* MSI-X vector for config event */ 245170754Sdelphij}; 246170754Sdelphij 247170754Sdelphij#define VS_LOCK(vs) \ 248170754Sdelphijdo { \ 249170754Sdelphij if (vs->vs_mtx) \ 250170754Sdelphij pthread_mutex_lock(vs->vs_mtx); \ 251170754Sdelphij} while (0) 252170754Sdelphij 253170754Sdelphij#define VS_UNLOCK(vs) \ 254170754Sdelphijdo { \ 255170754Sdelphij if (vs->vs_mtx) \ 256170754Sdelphij pthread_mutex_unlock(vs->vs_mtx); \ 257170754Sdelphij} while (0) 258170754Sdelphij 259170754Sdelphijstruct virtio_consts { 260170754Sdelphij const char *vc_name; /* name of driver (for diagnostics) */ 261170754Sdelphij int vc_nvq; /* number of virtual queues */ 262170754Sdelphij size_t vc_cfgsize; /* size of dev-specific config regs */ 263170754Sdelphij void (*vc_reset)(void *); /* called on virtual device reset */ 264170754Sdelphij void (*vc_qnotify)(void *, struct vqueue_info *); 265170754Sdelphij /* called on QNOTIFY if no VQ notify */ 266170754Sdelphij int (*vc_cfgread)(void *, int, int, uint32_t *); 267170754Sdelphij /* called to read config regs */ 268170754Sdelphij int (*vc_cfgwrite)(void *, int, int, uint32_t); 269170754Sdelphij /* called to write config regs */ 270170754Sdelphij void (*vc_apply_features)(void *, uint64_t); 271170754Sdelphij /* called to apply negotiated features */ 272239360Sobrien uint64_t vc_hv_caps; /* hypervisor-provided capabilities */ 273170754Sdelphij void (*vc_pause)(void *); /* called to pause device activity */ 274170754Sdelphij void (*vc_resume)(void *); /* called to resume device activity */ 275239360Sobrien int (*vc_snapshot)(void *, struct vm_snapshot_meta *); 276239360Sobrien /* called to save / restore device state */ 277170754Sdelphij}; 278170754Sdelphij 279170754Sdelphij/* 280170754Sdelphij * Data structure allocated (statically) per virtual queue. 281170754Sdelphij * 282170754Sdelphij * Drivers may change vq_qsize after a reset. When the guest OS 283170754Sdelphij * requests a device reset, the hypervisor first calls 284170754Sdelphij * vs->vs_vc->vc_reset(); then the data structure below is 285170754Sdelphij * reinitialized (for each virtqueue: vs->vs_vc->vc_nvq). 286170754Sdelphij * 287170754Sdelphij * The remaining fields should only be fussed-with by the generic 288170754Sdelphij * code. 289170754Sdelphij * 290170754Sdelphij * Note: the addresses of vq_desc, vq_avail, and vq_used are all 291170754Sdelphij * computable from each other, but it's a lot simpler if we just 292170754Sdelphij * keep a pointer to each one. The event indices are similarly 293170754Sdelphij * (but more easily) computable, and this time we'll compute them: 294170754Sdelphij * they're just XX_ring[N]. 295170754Sdelphij */ 296170754Sdelphij#define VQ_ALLOC 0x01 /* set once we have a pfn */ 297170754Sdelphij#define VQ_BROKED 0x02 /* ??? */ 298170754Sdelphijstruct vqueue_info { 299170754Sdelphij uint16_t vq_qsize; /* size of this queue (a power of 2) */ 300170754Sdelphij void (*vq_notify)(void *, struct vqueue_info *); 301170754Sdelphij /* called instead of vc_notify, if not NULL */ 302170754Sdelphij 303170754Sdelphij struct virtio_softc *vq_vs; /* backpointer to softc */ 304170754Sdelphij uint16_t vq_num; /* we're the num'th queue in the softc */ 305170754Sdelphij 306170754Sdelphij uint16_t vq_flags; /* flags (see above) */ 307170754Sdelphij uint16_t vq_last_avail; /* a recent value of vq_avail->idx */ 308170754Sdelphij uint16_t vq_next_used; /* index of the next used slot to be filled */ 309170754Sdelphij uint16_t vq_save_used; /* saved vq_used->idx; see vq_endchains */ 310170754Sdelphij uint16_t vq_msix_idx; /* MSI-X index, or VIRTIO_MSI_NO_VECTOR */ 311170754Sdelphij 312170754Sdelphij uint32_t vq_pfn; /* PFN of virt queue (not shifted!) */ 313170754Sdelphij 314170754Sdelphij struct vring_desc *vq_desc; /* descriptor array */ 315170754Sdelphij struct vring_avail *vq_avail; /* the "avail" ring */ 316170754Sdelphij struct vring_used *vq_used; /* the "used" ring */ 317170754Sdelphij 318170754Sdelphij}; 319170754Sdelphij/* as noted above, these are sort of backwards, name-wise */ 320170754Sdelphij#define VQ_AVAIL_EVENT_IDX(vq) \ 321170754Sdelphij (*(uint16_t *)&(vq)->vq_used->ring[(vq)->vq_qsize]) 322170754Sdelphij#define VQ_USED_EVENT_IDX(vq) \ 323170754Sdelphij ((vq)->vq_avail->ring[(vq)->vq_qsize]) 324170754Sdelphij 325170754Sdelphij/* 326170754Sdelphij * Is this ring ready for I/O? 327170754Sdelphij */ 328170754Sdelphijstatic inline int 329170754Sdelphijvq_ring_ready(struct vqueue_info *vq) 330170754Sdelphij{ 331170754Sdelphij 332170754Sdelphij return (vq->vq_flags & VQ_ALLOC); 333170754Sdelphij} 334170754Sdelphij 335170754Sdelphij/* 336170754Sdelphij * Are there "available" descriptors? (This does not count 337170754Sdelphij * how many, just returns True if there are some.) 338170754Sdelphij */ 339170754Sdelphijstatic inline int 340170754Sdelphijvq_has_descs(struct vqueue_info *vq) 341170754Sdelphij{ 342170754Sdelphij 343170754Sdelphij return (vq_ring_ready(vq) && vq->vq_last_avail != 344170754Sdelphij vq->vq_avail->idx); 345170754Sdelphij} 346170754Sdelphij 347170754Sdelphij/* 348170754Sdelphij * Deliver an interrupt to the guest for a specific MSI-X queue or 349170754Sdelphij * event. 350170754Sdelphij */ 351170754Sdelphijstatic inline void 352170754Sdelphijvi_interrupt(struct virtio_softc *vs, uint8_t isr, uint16_t msix_idx) 353170754Sdelphij{ 354170754Sdelphij 355170754Sdelphij if (pci_msix_enabled(vs->vs_pi)) 356170754Sdelphij pci_generate_msix(vs->vs_pi, msix_idx); 357170754Sdelphij else { 358170754Sdelphij VS_LOCK(vs); 359170754Sdelphij vs->vs_isr |= isr; 360170754Sdelphij pci_generate_msi(vs->vs_pi, 0); 361170754Sdelphij pci_lintr_assert(vs->vs_pi); 362170754Sdelphij VS_UNLOCK(vs); 363170754Sdelphij } 364170754Sdelphij} 365170754Sdelphij 366170754Sdelphij/* 367170754Sdelphij * Deliver an interrupt to the guest on the given virtual queue (if 368170754Sdelphij * possible, or a generic MSI interrupt if not using MSI-X). 369170754Sdelphij */ 370170754Sdelphijstatic inline void 371170754Sdelphijvq_interrupt(struct virtio_softc *vs, struct vqueue_info *vq) 372170754Sdelphij{ 373170754Sdelphij 374170754Sdelphij vi_interrupt(vs, VIRTIO_PCI_ISR_INTR, vq->vq_msix_idx); 375170754Sdelphij} 376170754Sdelphij 377170754Sdelphijstatic inline void 378170754Sdelphijvq_kick_enable(struct vqueue_info *vq) 379170754Sdelphij{ 380170754Sdelphij 381170754Sdelphij vq->vq_used->flags &= ~VRING_USED_F_NO_NOTIFY; 382170754Sdelphij /* 383170754Sdelphij * Full memory barrier to make sure the store to vq_used->flags 384170754Sdelphij * happens before the load from vq_avail->idx, which results from a 385170754Sdelphij * subsequent call to vq_has_descs(). 386170754Sdelphij */ 387170754Sdelphij atomic_thread_fence_seq_cst(); 388170754Sdelphij} 389170754Sdelphij 390170754Sdelphijstatic inline void 391170754Sdelphijvq_kick_disable(struct vqueue_info *vq) 392170754Sdelphij{ 393170754Sdelphij 394170754Sdelphij vq->vq_used->flags |= VRING_USED_F_NO_NOTIFY; 395170754Sdelphij} 396170754Sdelphij 397170754Sdelphijstruct iovec; 398170754Sdelphij 399170754Sdelphij/* 400170754Sdelphij * Request description returned by vq_getchain. 401170754Sdelphij * 402170754Sdelphij * Writable iovecs start at iov[req.readable]. 403170754Sdelphij */ 404170754Sdelphijstruct vi_req { 405170754Sdelphij int readable; /* num of readable iovecs */ 406170754Sdelphij int writable; /* num of writable iovecs */ 407170754Sdelphij unsigned int idx; /* ring index */ 408170754Sdelphij}; 409170754Sdelphij 410170754Sdelphijvoid vi_softc_linkup(struct virtio_softc *vs, struct virtio_consts *vc, 411170754Sdelphij void *dev_softc, struct pci_devinst *pi, 412170754Sdelphij struct vqueue_info *queues); 413170754Sdelphijint vi_intr_init(struct virtio_softc *vs, int barnum, int use_msix); 414170754Sdelphijvoid vi_reset_dev(struct virtio_softc *); 415170754Sdelphijvoid vi_set_io_bar(struct virtio_softc *, int); 416170754Sdelphij 417170754Sdelphijint vq_getchain(struct vqueue_info *vq, struct iovec *iov, int niov, 418170754Sdelphij struct vi_req *reqp); 419170754Sdelphijvoid vq_retchains(struct vqueue_info *vq, uint16_t n_chains); 420170754Sdelphijvoid vq_relchain_prepare(struct vqueue_info *vq, uint16_t idx, 421170754Sdelphij uint32_t iolen); 422170754Sdelphijvoid vq_relchain_publish(struct vqueue_info *vq); 423170754Sdelphijvoid vq_relchain(struct vqueue_info *vq, uint16_t idx, uint32_t iolen); 424170754Sdelphijvoid vq_endchains(struct vqueue_info *vq, int used_all_avail); 425170754Sdelphij 426170754Sdelphijuint64_t vi_pci_read(struct pci_devinst *pi, int baridx, uint64_t offset, 427170754Sdelphij int size); 428170754Sdelphijvoid vi_pci_write(struct pci_devinst *pi, int baridx, uint64_t offset, 429170754Sdelphij int size, uint64_t value); 430170754Sdelphij#ifdef BHYVE_SNAPSHOT 431170754Sdelphijint vi_pci_snapshot(struct vm_snapshot_meta *meta); 432239360Sobrienint vi_pci_pause(struct pci_devinst *pi); 433239360Sobrienint vi_pci_resume(struct pci_devinst *pi); 434239360Sobrien#endif 435239360Sobrien#endif /* _BHYVE_VIRTIO_H_ */ 436239360Sobrien