Virtio.h revision fd8bc8bc503d0dd080a7658484e62f757ccb7a1c
734b6a94890be549309b21156f8ed6d4561cac51darrenm/* $Id$ */
734b6a94890be549309b21156f8ed6d4561cac51darrenm/** @file
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Virtio.h - Virtio Declarations
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/*
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Copyright (C) 2009-2013 Oracle Corporation
734b6a94890be549309b21156f8ed6d4561cac51darrenm *
734b6a94890be549309b21156f8ed6d4561cac51darrenm * This file is part of VirtualBox Open Source Edition (OSE), as
734b6a94890be549309b21156f8ed6d4561cac51darrenm * available from http://www.virtualbox.org. This file is free software;
734b6a94890be549309b21156f8ed6d4561cac51darrenm * you can redistribute it and/or modify it under the terms of the GNU
734b6a94890be549309b21156f8ed6d4561cac51darrenm * General Public License (GPL) as published by the Free Software
734b6a94890be549309b21156f8ed6d4561cac51darrenm * Foundation, in version 2 as it comes in the "COPYING" file of the
734b6a94890be549309b21156f8ed6d4561cac51darrenm * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
734b6a94890be549309b21156f8ed6d4561cac51darrenm * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#ifndef ___VBox_Virtio_h
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define ___VBox_Virtio_h
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#include <iprt/ctype.h>
734b6a94890be549309b21156f8ed6d4561cac51darrenm
d3b2efc749bec3b757d5f018cf78c9a09fa29cb3Anthony Scarpino
734b6a94890be549309b21156f8ed6d4561cac51darrenm/** @name Saved state versions.
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The saved state version is changed if either common or any of specific
734b6a94890be549309b21156f8ed6d4561cac51darrenm * parts are changed. That is, it is perfectly possible that the version
734b6a94890be549309b21156f8ed6d4561cac51darrenm * of saved vnet state will increase as a result of change in vblk structure
734b6a94890be549309b21156f8ed6d4561cac51darrenm * for example.
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VIRTIO_SAVEDSTATE_VERSION_3_1_BETA1 1
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VIRTIO_SAVEDSTATE_VERSION 2
734b6a94890be549309b21156f8ed6d4561cac51darrenm/** @} */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define DEVICE_PCI_VENDOR_ID 0x1AF4
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define DEVICE_PCI_DEVICE_ID 0x1000
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define DEVICE_PCI_SUBSYSTEM_VENDOR_ID 0x1AF4
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VIRTIO_MAX_NQUEUES 3
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_HOST_FEATURES 0x0
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_GUEST_FEATURES 0x4
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_QUEUE_PFN 0x8
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_QUEUE_NUM 0xC
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_QUEUE_SEL 0xE
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_QUEUE_NOTIFY 0x10
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_STATUS 0x12
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_ISR 0x13
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_CONFIG 0x14
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_ISR_QUEUE 0x1
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_ISR_CONFIG 0x3
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_STATUS_ACK 0x01
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_STATUS_DRV 0x02
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_STATUS_DRV_OK 0x04
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_STATUS_FAILED 0x80
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_F_NOTIFY_ON_EMPTY 0x01000000
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VPCI_F_BAD_FEATURE 0x40000000
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VRINGDESC_MAX_SIZE (2 * 1024 * 1024)
d2b323064c1e0b7131b3f784139d57c317e9b625mcpowers#define VRINGDESC_F_NEXT 0x01
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VRINGDESC_F_WRITE 0x02
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef struct VRingDesc
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint64_t u64Addr;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t uLen;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t u16Flags;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t u16Next;
734b6a94890be549309b21156f8ed6d4561cac51darrenm} VRINGDESC;
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef VRINGDESC *PVRINGDESC;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VRINGAVAIL_F_NO_INTERRUPT 0x01
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef struct VRingAvail
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t uFlags;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t uNextFreeIndex;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t auRing[1];
734b6a94890be549309b21156f8ed6d4561cac51darrenm} VRINGAVAIL;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef struct VRingUsedElem
5b675b316486993a90722f1a7ec08ce857ef7af7Vladimir Kotal{
5b675b316486993a90722f1a7ec08ce857ef7af7Vladimir Kotal uint32_t uId;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t uLen;
734b6a94890be549309b21156f8ed6d4561cac51darrenm} VRINGUSEDELEM;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VRINGUSED_F_NO_NOTIFY 0x01
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef struct VRingUsed
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t uFlags;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t uIndex;
734b6a94890be549309b21156f8ed6d4561cac51darrenm VRINGUSEDELEM aRing[1];
734b6a94890be549309b21156f8ed6d4561cac51darrenm} VRINGUSED;
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef VRINGUSED *PVRINGUSED;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#define VRING_MAX_SIZE 1024
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef struct VRing
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t uSize;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t padding[3];
734b6a94890be549309b21156f8ed6d4561cac51darrenm RTGCPHYS addrDescriptors;
734b6a94890be549309b21156f8ed6d4561cac51darrenm RTGCPHYS addrAvail;
734b6a94890be549309b21156f8ed6d4561cac51darrenm RTGCPHYS addrUsed;
734b6a94890be549309b21156f8ed6d4561cac51darrenm} VRING;
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef VRING *PVRING;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef struct VQueue
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm VRING VRing;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t uNextAvailIndex;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t uNextUsedIndex;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t uPageNumber;
8de5c4f463386063e184a851437d58080c6c626cDan OpenSolaris Anderson#ifdef IN_RING3
734b6a94890be549309b21156f8ed6d4561cac51darrenm void (*pfnCallback)(void *pvState, struct VQueue *pQueue);
734b6a94890be549309b21156f8ed6d4561cac51darrenm#else
734b6a94890be549309b21156f8ed6d4561cac51darrenm RTR3UINTPTR pfnCallback;
734b6a94890be549309b21156f8ed6d4561cac51darrenm#endif
734b6a94890be549309b21156f8ed6d4561cac51darrenm R3PTRTYPE(const char *) pcszName;
734b6a94890be549309b21156f8ed6d4561cac51darrenm} VQUEUE;
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef VQUEUE *PVQUEUE;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef struct VQueueElemSeg
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm RTGCPHYS addr;
734b6a94890be549309b21156f8ed6d4561cac51darrenm void *pv;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t cb;
734b6a94890be549309b21156f8ed6d4561cac51darrenm} VQUEUESEG;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef struct VQueueElem
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t uIndex;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t nIn;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t nOut;
734b6a94890be549309b21156f8ed6d4561cac51darrenm VQUEUESEG aSegsIn[VRING_MAX_SIZE];
734b6a94890be549309b21156f8ed6d4561cac51darrenm VQUEUESEG aSegsOut[VRING_MAX_SIZE];
734b6a94890be549309b21156f8ed6d4561cac51darrenm} VQUEUEELEM;
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef VQUEUEELEM *PVQUEUEELEM;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
5b675b316486993a90722f1a7ec08ce857ef7af7Vladimir Kotal
734b6a94890be549309b21156f8ed6d4561cac51darrenmenum VirtioDeviceType
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm VIRTIO_NET_ID = 0,
734b6a94890be549309b21156f8ed6d4561cac51darrenm VIRTIO_BLK_ID = 1,
5b675b316486993a90722f1a7ec08ce857ef7af7Vladimir Kotal VIRTIO_32BIT_HACK = 0x7fffffff
734b6a94890be549309b21156f8ed6d4561cac51darrenm};
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/**
734b6a94890be549309b21156f8ed6d4561cac51darrenm * The core (/common) state of the VirtIO PCI device
734b6a94890be549309b21156f8ed6d4561cac51darrenm *
734b6a94890be549309b21156f8ed6d4561cac51darrenm * @implements PDMILEDPORTS
734b6a94890be549309b21156f8ed6d4561cac51darrenm */
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef struct VPCIState_st
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm PDMCRITSECT cs; /**< Critical section - what is it protecting? */
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* Read-only part, never changes after initialization. */
734b6a94890be549309b21156f8ed6d4561cac51darrenm char szInstance[8]; /**< Instance name, e.g. VNet#1. */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#if HC_ARCH_BITS != 64
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t padding1;
734b6a94890be549309b21156f8ed6d4561cac51darrenm#endif
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /** Status LUN: Base interface. */
734b6a94890be549309b21156f8ed6d4561cac51darrenm PDMIBASE IBase;
734b6a94890be549309b21156f8ed6d4561cac51darrenm /** Status LUN: LED port interface. */
734b6a94890be549309b21156f8ed6d4561cac51darrenm PDMILEDPORTS ILeds;
734b6a94890be549309b21156f8ed6d4561cac51darrenm /** Status LUN: LED connector (peer). */
734b6a94890be549309b21156f8ed6d4561cac51darrenm R3PTRTYPE(PPDMILEDCONNECTORS) pLedsConnector;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm PPDMDEVINSR3 pDevInsR3; /**< Device instance - R3. */
734b6a94890be549309b21156f8ed6d4561cac51darrenm PPDMDEVINSR0 pDevInsR0; /**< Device instance - R0. */
734b6a94890be549309b21156f8ed6d4561cac51darrenm PPDMDEVINSRC pDevInsRC; /**< Device instance - RC. */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#if HC_ARCH_BITS == 64
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t padding2;
734b6a94890be549309b21156f8ed6d4561cac51darrenm#endif
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /** TODO */
734b6a94890be549309b21156f8ed6d4561cac51darrenm PCIDEVICE pciDevice;
734b6a94890be549309b21156f8ed6d4561cac51darrenm /** Base port of I/O space region. */
734b6a94890be549309b21156f8ed6d4561cac51darrenm RTIOPORT IOPortBase;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm /* Read/write part, protected with critical section. */
734b6a94890be549309b21156f8ed6d4561cac51darrenm /** Status LED. */
734b6a94890be549309b21156f8ed6d4561cac51darrenm PDMLED led;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t uGuestFeatures;
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t uQueueSelector; /**< An index in aQueues array. */
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint8_t uStatus; /**< Device Status (bits are device-specific). */
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint8_t uISR; /**< Interrupt Status Register. */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#if HC_ARCH_BITS != 64
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t padding3;
734b6a94890be549309b21156f8ed6d4561cac51darrenm#endif
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t nQueues; /**< Actual number of queues used. */
734b6a94890be549309b21156f8ed6d4561cac51darrenm VQUEUE Queues[VIRTIO_MAX_NQUEUES];
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#if defined(VBOX_WITH_STATISTICS)
734b6a94890be549309b21156f8ed6d4561cac51darrenm STAMPROFILEADV StatIOReadGC;
734b6a94890be549309b21156f8ed6d4561cac51darrenm STAMPROFILEADV StatIOReadHC;
734b6a94890be549309b21156f8ed6d4561cac51darrenm STAMPROFILEADV StatIOWriteGC;
734b6a94890be549309b21156f8ed6d4561cac51darrenm STAMPROFILEADV StatIOWriteHC;
734b6a94890be549309b21156f8ed6d4561cac51darrenm STAMCOUNTER StatIntsRaised;
734b6a94890be549309b21156f8ed6d4561cac51darrenm STAMCOUNTER StatIntsSkipped;
734b6a94890be549309b21156f8ed6d4561cac51darrenm STAMPROFILE StatCsGC;
734b6a94890be549309b21156f8ed6d4561cac51darrenm STAMPROFILE StatCsHC;
734b6a94890be549309b21156f8ed6d4561cac51darrenm#endif /* VBOX_WITH_STATISTICS */
734b6a94890be549309b21156f8ed6d4561cac51darrenm} VPCISTATE;
734b6a94890be549309b21156f8ed6d4561cac51darrenm/** Pointer to the core (/common) state of a VirtIO PCI device. */
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef VPCISTATE *PVPCISTATE;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm/** @name Callbacks
734b6a94890be549309b21156f8ed6d4561cac51darrenm * @{ */
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef uint32_t (*PFNGETHOSTFEATURES)(void *pState);
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef uint32_t (*PFNGETHOSTMINIMALFEATURES)(void *pState);
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef void (*PFNSETHOSTFEATURES)(void *pState, uint32_t uFeatures);
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef int (*PFNGETCONFIG)(void *pState, uint32_t port, uint32_t cb, void *data);
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef int (*PFNSETCONFIG)(void *pState, uint32_t port, uint32_t cb, void *data);
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef int (*PFNRESET)(void *pState);
734b6a94890be549309b21156f8ed6d4561cac51darrenmtypedef void (*PFNREADY)(void *pState);
734b6a94890be549309b21156f8ed6d4561cac51darrenm/** @} */
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmint vpciRaiseInterrupt(VPCISTATE *pState, int rcBusy, uint8_t u8IntCause);
734b6a94890be549309b21156f8ed6d4561cac51darrenmint vpciIOPortIn(PPDMDEVINS pDevIns,
734b6a94890be549309b21156f8ed6d4561cac51darrenm void *pvUser,
734b6a94890be549309b21156f8ed6d4561cac51darrenm RTIOPORT port,
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t *pu32,
734b6a94890be549309b21156f8ed6d4561cac51darrenm unsigned cb,
734b6a94890be549309b21156f8ed6d4561cac51darrenm PFNGETHOSTFEATURES pfnGetHostFeatures,
734b6a94890be549309b21156f8ed6d4561cac51darrenm PFNGETCONFIG pfnGetConfig);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmint vpciIOPortOut(PPDMDEVINS pDevIns,
734b6a94890be549309b21156f8ed6d4561cac51darrenm void *pvUser,
734b6a94890be549309b21156f8ed6d4561cac51darrenm RTIOPORT port,
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t u32,
734b6a94890be549309b21156f8ed6d4561cac51darrenm unsigned cb,
734b6a94890be549309b21156f8ed6d4561cac51darrenm PFNGETHOSTMINIMALFEATURES pfnGetHostMinimalFeatures,
734b6a94890be549309b21156f8ed6d4561cac51darrenm PFNGETHOSTFEATURES pfnGetHostFeatures,
734b6a94890be549309b21156f8ed6d4561cac51darrenm PFNSETHOSTFEATURES pfnSetHostFeatures,
734b6a94890be549309b21156f8ed6d4561cac51darrenm PFNRESET pfnReset,
734b6a94890be549309b21156f8ed6d4561cac51darrenm PFNREADY pfnReady,
d3b2efc749bec3b757d5f018cf78c9a09fa29cb3Anthony Scarpino PFNSETCONFIG pfnSetConfig);
d3b2efc749bec3b757d5f018cf78c9a09fa29cb3Anthony Scarpino
d3b2efc749bec3b757d5f018cf78c9a09fa29cb3Anthony Scarpinovoid vpciSetWriteLed(PVPCISTATE pState, bool fOn);
734b6a94890be549309b21156f8ed6d4561cac51darrenmvoid vpciSetReadLed(PVPCISTATE pState, bool fOn);
d3b2efc749bec3b757d5f018cf78c9a09fa29cb3Anthony Scarpinoint vpciSaveExec(PVPCISTATE pState, PSSMHANDLE pSSM);
734b6a94890be549309b21156f8ed6d4561cac51darrenmint vpciLoadExec(PVPCISTATE pState, PSSMHANDLE pSSM,
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t uVersion, uint32_t uPass,
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t nQueues);
734b6a94890be549309b21156f8ed6d4561cac51darrenmint vpciConstruct(PPDMDEVINS pDevIns, VPCISTATE *pState,
734b6a94890be549309b21156f8ed6d4561cac51darrenm int iInstance, const char *pcszNameFmt,
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t uSubsystemId, uint16_t uClass,
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint32_t nQueues);
734b6a94890be549309b21156f8ed6d4561cac51darrenmint vpciDestruct(VPCISTATE* pState);
734b6a94890be549309b21156f8ed6d4561cac51darrenmvoid vpciRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta);
734b6a94890be549309b21156f8ed6d4561cac51darrenmvoid vpciReset(PVPCISTATE pState);
734b6a94890be549309b21156f8ed6d4561cac51darrenmvoid *vpciQueryInterface(struct PDMIBASE *pInterface, const char *pszIID);
734b6a94890be549309b21156f8ed6d4561cac51darrenmPVQUEUE vpciAddQueue(VPCISTATE* pState, unsigned uSize,
734b6a94890be549309b21156f8ed6d4561cac51darrenm void (*pfnCallback)(void *pvState, PVQUEUE pQueue),
734b6a94890be549309b21156f8ed6d4561cac51darrenm const char *pcszName);
d3b2efc749bec3b757d5f018cf78c9a09fa29cb3Anthony Scarpino
d3b2efc749bec3b757d5f018cf78c9a09fa29cb3Anthony Scarpino#define VPCI_CS
d3b2efc749bec3b757d5f018cf78c9a09fa29cb3Anthony ScarpinoDECLINLINE(int) vpciCsEnter(VPCISTATE *pState, int iBusyRc)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm#ifdef VPCI_CS
734b6a94890be549309b21156f8ed6d4561cac51darrenm STAM_PROFILE_START(&pState->CTXSUFF(StatCs), a);
734b6a94890be549309b21156f8ed6d4561cac51darrenm int rc = PDMCritSectEnter(&pState->cs, iBusyRc);
734b6a94890be549309b21156f8ed6d4561cac51darrenm STAM_PROFILE_STOP(&pState->CTXSUFF(StatCs), a);
734b6a94890be549309b21156f8ed6d4561cac51darrenm return rc;
734b6a94890be549309b21156f8ed6d4561cac51darrenm#else
734b6a94890be549309b21156f8ed6d4561cac51darrenm return VINF_SUCCESS;
734b6a94890be549309b21156f8ed6d4561cac51darrenm#endif
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmDECLINLINE(void) vpciCsLeave(VPCISTATE *pState)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm#ifdef VPCI_CS
734b6a94890be549309b21156f8ed6d4561cac51darrenm PDMCritSectLeave(&pState->cs);
734b6a94890be549309b21156f8ed6d4561cac51darrenm#endif
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmvoid vringSetNotification(PVPCISTATE pState, PVRING pVRing, bool fEnabled);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmDECLINLINE(uint16_t) vringReadAvailIndex(PVPCISTATE pState, PVRING pVRing)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm uint16_t tmp;
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm PDMDevHlpPhysRead(pState->CTX_SUFF(pDevIns),
734b6a94890be549309b21156f8ed6d4561cac51darrenm pVRing->addrAvail + RT_OFFSETOF(VRINGAVAIL, uNextFreeIndex),
734b6a94890be549309b21156f8ed6d4561cac51darrenm &tmp, sizeof(tmp));
734b6a94890be549309b21156f8ed6d4561cac51darrenm return tmp;
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmbool vqueueSkip(PVPCISTATE pState, PVQUEUE pQueue);
734b6a94890be549309b21156f8ed6d4561cac51darrenmbool vqueueGet(PVPCISTATE pState, PVQUEUE pQueue, PVQUEUEELEM pElem, bool fRemove = true);
734b6a94890be549309b21156f8ed6d4561cac51darrenmvoid vqueuePut(PVPCISTATE pState, PVQUEUE pQueue, PVQUEUEELEM pElem, uint32_t uLen, uint32_t uReserved = 0);
734b6a94890be549309b21156f8ed6d4561cac51darrenmvoid vqueueNotify(PVPCISTATE pState, PVQUEUE pQueue);
734b6a94890be549309b21156f8ed6d4561cac51darrenmvoid vqueueSync(PVPCISTATE pState, PVQUEUE pQueue);
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmDECLINLINE(bool) vqueuePeek(PVPCISTATE pState, PVQUEUE pQueue, PVQUEUEELEM pElem)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm return vqueueGet(pState, pQueue, pElem, /* fRemove */ false);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmDECLINLINE(bool) vqueueIsReady(PVPCISTATE pState, PVQUEUE pQueue)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm NOREF(pState);
734b6a94890be549309b21156f8ed6d4561cac51darrenm return !!pQueue->VRing.addrAvail;
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenmDECLINLINE(bool) vqueueIsEmpty(PVPCISTATE pState, PVQUEUE pQueue)
734b6a94890be549309b21156f8ed6d4561cac51darrenm{
734b6a94890be549309b21156f8ed6d4561cac51darrenm return (vringReadAvailIndex(pState, &pQueue->VRing) == pQueue->uNextAvailIndex);
734b6a94890be549309b21156f8ed6d4561cac51darrenm}
734b6a94890be549309b21156f8ed6d4561cac51darrenm
734b6a94890be549309b21156f8ed6d4561cac51darrenm#endif /* !___VBox_Virtio_h */
734b6a94890be549309b21156f8ed6d4561cac51darrenm