/*
* Copyright (c) 2010 Minoura Makoto.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Part of the file derived from `Virtio PCI Card Specification v0.8.6 DRAFT'
* Appendix A.
*/
/* An interface for efficient virtio implementation.
*
* This header is BSD licensed so anyone can use the definitions
* to implement compatible drivers/servers.
*
* Copyright 2007, 2009, IBM Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of IBM nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* virtqueue allocation info */
void *vq_vaddr;
int vq_availoffset;
int vq_usedoffset;
int vq_indirectoffset;
bus_dma_segment_t vq_segs[1];
unsigned int vq_bytesize;
bus_dmamap_t vq_dmamap;
int vq_maxsegsize;
int vq_maxnsegs;
/* enqueue/dequeue status */
uint16_t vq_avail_idx;
uint16_t vq_used_idx;
uint16_t vq_free_idx;
int vq_queued;
kmutex_t vq_aring_lock;
kmutex_t vq_uring_lock;
kmutex_t vq_freedesc_lock;
/* interrupt handler */
int (*vq_done)(struct virtqueue*); /* for compatibility */
int (*vq_intrhand)(void *);
void *vq_intrhand_arg;
/* for 1.0 */
uint32_t vq_notify_off;
struct vring_desc_extra {
bool use_indirect; /* true if using indirect */
struct vring_desc
*desc_base;
uint16_t desc_free_idx;
} *vq_descx;
};
struct virtio_attach_args {
int sc_childdevid;
};
typedef int (*virtio_callback)(struct virtio_softc*);
/*
* Virtio structures are read/written in host endian for 0.9 but little endian
* for 1.0. One notable exception is AArch BE that always uses little endian.
*/
uint16_t virtio_rw16(struct virtio_softc *sc, uint16_t val);
uint32_t virtio_rw32(struct virtio_softc *sc, uint32_t val);
uint64_t virtio_rw64(struct virtio_softc *sc, uint64_t val);