Modules - Added VirtIO Network driver (and VirtIO library)
[tpg/acess2.git] / KernelLand / Modules / Libraries / VirtIO / include / virtio.h
1 /*
2  * Acess2 Kernel Common
3  * - By John Hodge (thePowersGang)
4  *
5  * virtio.h
6  * - VirtIO Common Header
7  *
8  * Reference: LinuxKernel:/Documentation/virtual/virtio-spec.txt
9  */
10 #ifndef _VIRTIO__VIRTIO_H_
11 #define _VIRTIO__VIRTIO_H_
12
13 typedef struct sVirtIO_Dev      tVirtIO_Dev;
14 typedef struct sVirtIO_Buf      tVirtIO_Buf;
15
16 typedef enum eVirtIO_DeviceClasses      tVirtIO_DeviceClass;
17
18 /**
19  * Function called when a queue entry is passed to the guest
20  *
21  * \param Index Index of the entry in the queue
22  */
23 typedef int     (*tVirtIO_QueueCallback)(tVirtIO_Dev *Dev, int Index, size_t UsedBytes, void *Handle);
24
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)
28
29 enum eVirtIO_DeviceClasses
30 {
31         VIRTIO_DEVCLASS_NETWORK,
32 };
33
34 // === FUNCTIONS ===
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);
40 /**
41  * \brief Sets the Queue Callback
42  * 
43  * The queue callback is called when the device writes an entry to the used ring.
44  * 
45  * \param NoAutoRel     Keep descriptors in ring buffer until explicitly popped and released
46  */
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);\
51 /**
52  * \brief Get the next buffer in a chain
53  */
54 extern tVirtIO_Buf      *VirtIO_GetNextBuffer(tVirtIO_Buf *Buf);
55 /**
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.
58  */
59 extern const void       *VirtIO_GetBufferPtr(tVirtIO_Buf *Buf, size_t *Size);
60 /**
61  * \brief Get the device for a buffer
62  */
63 extern tVirtIO_Dev      *VirtIO_GetBufferDev(tVirtIO_Buf *Buf);
64 /**
65  * \brief Release all qdescs associated with a buffer into the free pool
66  */
67 extern void     VirtIO_ReleaseBuffer(tVirtIO_Buf *Buffer);
68
69 #endif
70
71

UCC git Repository :: git.ucc.asn.au