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