1 | /* $Id: Virtio-solaris.h 69500 2017-10-28 15:14:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Guest Additions: Virtio Driver for Solaris, header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef ___Virtio_solaris_h
|
---|
28 | #define ___Virtio_solaris_h
|
---|
29 |
|
---|
30 | #include <sys/sunddi.h>
|
---|
31 |
|
---|
32 | /** Release log descriptive prefix. */
|
---|
33 | #define VIRTIOLOGNAME "Virtio"
|
---|
34 | /** Buffer continues via the Next field */
|
---|
35 | #define VIRTIO_FLAGS_RING_DESC_NEXT RT_BIT(0)
|
---|
36 | /** Buffer is write-only, else is read-only. */
|
---|
37 | #define VIRTIO_FLAGS_RING_DESC_WRITE RT_BIT(1)
|
---|
38 | /** Indirect buffer (buffer contains list of buffer descriptors) */
|
---|
39 | #define VIRTIO_FLAGS_RING_DESC_INDIRECT RT_BIT(2)
|
---|
40 |
|
---|
41 | /* Values from our Virtio.h */
|
---|
42 | #define VIRTIO_PCI_STATUS_ACK 0x01
|
---|
43 | #define VIRTIO_PCI_STATUS_DRV 0x02
|
---|
44 | #define VIRTIO_PCI_STATUS_DRV_OK 0x04
|
---|
45 | #define VIRTIO_PCI_STATUS_FAILED 0x80
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * The ring descriptor table refers to the buffers the guest is using for the
|
---|
49 | * device.
|
---|
50 | */
|
---|
51 | struct VirtioRingDesc
|
---|
52 | {
|
---|
53 | uint64_t AddrBuf; /* Physical address of buffer. */
|
---|
54 | uint32_t cbBuf; /* Length of the buffer in bytes. */
|
---|
55 | uint16_t fFlags; /* Flags of the next buffer. */
|
---|
56 | uint16_t Next; /* Index of the next buffer. */
|
---|
57 | };
|
---|
58 | typedef struct VirtioRingDesc VIRTIORINGDESC;
|
---|
59 | typedef VIRTIORINGDESC *PVIRTIORINGDESC;
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * The available ring refers to what descriptors are being offered to the
|
---|
63 | * device.
|
---|
64 | */
|
---|
65 | struct VirtioRingAvail
|
---|
66 | {
|
---|
67 | uint16_t fFlags; /* Interrupt supression flag. */
|
---|
68 | uint16_t Index; /* Index of available ring. */
|
---|
69 | uint16_t aRings[1]; /* Array of indices into descriptor table. */
|
---|
70 | };
|
---|
71 | typedef struct VirtioRingAvail VIRTIORINGAVAIL;
|
---|
72 | typedef VIRTIORINGAVAIL *PVIRTIORINGAVAIL;
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * The used ring refers to the buffers the device is done using them. The
|
---|
76 | * element is a pair-descriptor refers to the buffer once the device is done
|
---|
77 | * with the buffer.
|
---|
78 | */
|
---|
79 | struct VirtioRingUsedElem
|
---|
80 | {
|
---|
81 | uint32_t Index; /* Index of start of used descriptor chain. */
|
---|
82 | uint32_t cbElem; /* Number of bytes written into the buffer. */
|
---|
83 | };
|
---|
84 | typedef struct VirtioRingUsedElem VIRTIORINGUSEDELEM;
|
---|
85 | typedef VIRTIORINGUSEDELEM *PVIRTIORINGUSEDELEM;
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * The Virtio Ring which contains the descriptors.
|
---|
89 | */
|
---|
90 | struct VirtioRing
|
---|
91 | {
|
---|
92 | uint_t cDesc; /* Number of descriptors. */
|
---|
93 | PVIRTIORINGDESC pRingDesc; /* Pointer to ring descriptor. */
|
---|
94 | PVIRTIORINGAVAIL pRingAvail; /* Pointer to available ring. */
|
---|
95 | PVIRTIORINGUSEDELEM pRingUsedElem; /* Pointer to used ring element. */
|
---|
96 | };
|
---|
97 | typedef struct VirtioRing VIRTIORING;
|
---|
98 | typedef VIRTIORING *PVIRTIORING;
|
---|
99 |
|
---|
100 | struct VirtioDevice;
|
---|
101 | struct VirtioQueue;
|
---|
102 |
|
---|
103 | typedef void *(*PFNVIRTIOALLOC)(struct VirtioDevice *pDevice);
|
---|
104 | typedef void (*PFNVIRTIOFREE)(struct VirtioDevice *pDevice);
|
---|
105 | typedef int (*PFNVIRTIOATTACH)(struct VirtioDevice *pDevice);
|
---|
106 | typedef int (*PFNVIRTIODETACH)(struct VirtioDevice *pDevice);
|
---|
107 | typedef uint32_t (*PFNVIRTIOGETFEATURES)(struct VirtioDevice *pDevice);
|
---|
108 | typedef void (*PFNVIRTIOSETFEATURES)(struct VirtioDevice *pDevice, uint32_t fFeatures);
|
---|
109 | typedef void (*PFNVIRTIOGET)(struct VirtioDevice *pDevice, off_t off, void *pv, size_t cb);
|
---|
110 | typedef void (*PFNVIRTIOSET)(struct VirtioDevice *pDevice, off_t off, void *pv, size_t cb);
|
---|
111 | typedef void *(*PFNVIRTIOGETQUEUE)(struct VirtioDevice *pDevice, struct VirtioQueue *pQueue);
|
---|
112 | typedef void (*PFNVIRTIOPUTQUEUE)(struct VirtioDevice *pDevice, struct VirtioQueue *pQueue);
|
---|
113 | typedef int (*PFNVIRTIONOTIFYQUEUE)(struct VirtioDevice *pDevice, struct VirtioQueue *pQueue);
|
---|
114 | typedef void (*PFNVIRTIOSETSTATUS)(struct VirtioDevice *pDevice, uint8_t Status);
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Virtio device operations.
|
---|
118 | */
|
---|
119 | struct VirtioDeviceOps
|
---|
120 | {
|
---|
121 | PFNVIRTIOALLOC pfnAlloc; /* Device alloc. */
|
---|
122 | PFNVIRTIOFREE pfnFree; /* Device free. */
|
---|
123 | PFNVIRTIOATTACH pfnAttach; /* Device attach. */
|
---|
124 | PFNVIRTIODETACH pfnDetach; /* Device detach. */
|
---|
125 | };
|
---|
126 | typedef struct VirtioDeviceOps VIRTIODEVICEOPS;
|
---|
127 | typedef VIRTIODEVICEOPS *PVIRTIODEVICEOPS;
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Hypervisor access operations.
|
---|
131 | */
|
---|
132 | struct VirtioHyperOps
|
---|
133 | {
|
---|
134 | PFNVIRTIOALLOC pfnAlloc; /* Hypervisor alloc. */
|
---|
135 | PFNVIRTIOFREE pfnFree; /* Hypervisor free */
|
---|
136 | PFNVIRTIOATTACH pfnAttach; /* Hypervisor attach. */
|
---|
137 | PFNVIRTIODETACH pfnDetach; /* Hypervisor detach. */
|
---|
138 | PFNVIRTIOGETFEATURES pfnGetFeatures; /* Hypervisor get features. */
|
---|
139 | PFNVIRTIOSETFEATURES pfnSetFeatures; /* Hypervisor set features. */
|
---|
140 | PFNVIRTIONOTIFYQUEUE pfnNotifyQueue; /* Hypervisor notify queue. */
|
---|
141 | PFNVIRTIOGET pfnGet; /* Hypervisor get. */
|
---|
142 | PFNVIRTIOSET pfnSet; /* Hypervisor set. */
|
---|
143 | PFNVIRTIOGETQUEUE pfnGetQueue; /* Hypervisor get queue. */
|
---|
144 | PFNVIRTIOPUTQUEUE pfnPutQueue; /* Hypervisor put queue. */
|
---|
145 | PFNVIRTIOSETSTATUS pfnSetStatus; /* Hypervisor set status. */
|
---|
146 | };
|
---|
147 | typedef struct VirtioHyperOps VIRTIOHYPEROPS;
|
---|
148 | typedef VIRTIOHYPEROPS *PVIRTIOHYPEROPS;
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Virtio Queue into which buffers are posted.
|
---|
152 | */
|
---|
153 | struct VirtioQueue
|
---|
154 | {
|
---|
155 | VIRTIORING Ring; /* Ring buffer of this queue. */
|
---|
156 | uint16_t cBufs; /* Number of pushed, unnotified buffers. */
|
---|
157 | uint16_t FreeHeadIndex; /* Index of head of free list. */
|
---|
158 | uint16_t QueueIndex; /* Index of this queue. */
|
---|
159 | caddr_t pQueue; /* Allocated DMA region for queue. */
|
---|
160 | void *pvData; /* Queue private data. */
|
---|
161 | };
|
---|
162 | typedef struct VirtioQueue VIRTIOQUEUE;
|
---|
163 | typedef VIRTIOQUEUE *PVIRTIOQUEUE;
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Virtio device descriptor, common to all Virtio devices.
|
---|
167 | */
|
---|
168 | struct VirtioDevice
|
---|
169 | {
|
---|
170 | dev_info_t *pDip; /* OS device info. */
|
---|
171 | PVIRTIODEVICEOPS pDeviceOps; /* Device hooks. */
|
---|
172 | void *pvDevice; /* Device opaque data. */
|
---|
173 | PVIRTIOHYPEROPS pHyperOps; /* Hypervisor hooks. */
|
---|
174 | void *pvHyper; /* Hypervisor opaque data. */
|
---|
175 | uint32_t fHostFeatures; /* Features provided by the host. */
|
---|
176 | };
|
---|
177 | typedef struct VirtioDevice VIRTIODEVICE;
|
---|
178 | typedef VIRTIODEVICE *PVIRTIODEVICE;
|
---|
179 |
|
---|
180 |
|
---|
181 | int VirtioAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd, PVIRTIODEVICEOPS pDeviceOps, PVIRTIOHYPEROPS pHyperOps);
|
---|
182 | int VirtioDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd);
|
---|
183 |
|
---|
184 | PVIRTIOQUEUE VirtioGetQueue(PVIRTIODEVICE pDevice, uint16_t Index);
|
---|
185 | void VirtioPutQueue(PVIRTIODEVICE pDevice, PVIRTIOQUEUE pQueue);
|
---|
186 |
|
---|
187 | void VirtioRingInit(PVIRTIOQUEUE pQueue, uint_t cDescs, caddr_t virtBuf, ulong_t Align);
|
---|
188 | int VirtioRingPush(PVIRTIOQUEUE pQueue, paddr_t physBuf, uint32_t cbBuf, uint16_t fFlags);
|
---|
189 | size_t VirtioRingSize(uint64_t cElements, ulong_t Align);
|
---|
190 |
|
---|
191 | #endif
|
---|
192 |
|
---|