3 * - By John Hodge (thePowersGang)
6 * - VirtIO Common Header
8 * Reference: LinuxKernel:/Documentation/virtual/virtio-spec.txt
10 #ifndef _VIRTIO__VIRTIO_H_
11 #define _VIRTIO__VIRTIO_H_
13 typedef struct sVirtIO_Dev tVirtIO_Dev;
14 typedef struct sVirtIO_Buf tVirtIO_Buf;
16 typedef enum eVirtIO_DeviceClasses tVirtIO_DeviceClass;
19 * Function called when a queue entry is passed to the guest
21 * \param Index Index of the entry in the queue
23 typedef int (*tVirtIO_QueueCallback)(tVirtIO_Dev *Dev, int Index, size_t UsedBytes, void *Handle);
25 #define VIRTIO_F_NOTIFY_ON_EMPTY (1 << 24)
26 #define VIRTIO_F_RING_INDIRECT_DESC (1 << 28)
27 #define VIRTIO_F_RING_EVENT_IDX (1 << 29)
29 enum eVirtIO_DeviceClasses
31 VIRTIO_DEVCLASS_NETWORK,
35 extern tVirtIO_Dev *VirtIO_InitDev(Uint16 IOBase, Uint IRQ, Uint32 Features, int NQueues, size_t DataSize);
36 extern Uint32 VirtIO_GetFeatures(tVirtIO_Dev *Dev);
37 extern Uint32 VirtIO_GetDevConfig(tVirtIO_Dev *Dev, int Size, Uint8 Offset);
38 extern void *VirtIO_GetDataPtr(tVirtIO_Dev *Dev);
39 extern void VirtIO_RemoveDev(tVirtIO_Dev *Dev);
41 * \brief Sets the Queue Callback
43 * The queue callback is called when the device writes an entry to the used ring.
45 * \param NoAutoRel Keep descriptors in ring buffer until explicitly popped and released
47 extern int VirtIO_SetQueueCallback(tVirtIO_Dev *Dev, int QueueID, tVirtIO_QueueCallback Callback, int NoAutoRel);
48 extern tVirtIO_Buf *VirtIO_SendBuffers(tVirtIO_Dev *Dev, int QueueID, int nBufs, size_t Sizes[], const void *Ptrs[], void *Handle);
49 extern tVirtIO_Buf *VirtIO_ReceiveBuffer(tVirtIO_Dev *Dev, int QueueID, size_t Size, void *Ptr, void *Handle);
50 extern tVirtIO_Buf *VirtIO_PopBuffer(tVirtIO_Dev *Dev, int QueueID, size_t *Size, const void **Ptr);\
52 * \brief Get the next buffer in a chain
54 extern tVirtIO_Buf *VirtIO_GetNextBuffer(tVirtIO_Buf *Buf);
56 * \brief Get the registered data pointer for this buffer
57 * \note This may not be what you want. Care should be taken that this function is called from the correct address space.
59 extern const void *VirtIO_GetBufferPtr(tVirtIO_Buf *Buf, size_t *Size);
61 * \brief Get the device for a buffer
63 extern tVirtIO_Dev *VirtIO_GetBufferDev(tVirtIO_Buf *Buf);
65 * \brief Release all qdescs associated with a buffer into the free pool
67 extern void VirtIO_ReleaseBuffer(tVirtIO_Buf *Buffer);