VirtualBox

source: vbox/trunk/src/VBox/Additions/solaris/Virtio/Virtio-solaris.h@ 104448

Last change on this file since 104448 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
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 */
64struct 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};
71typedef struct VirtioRingDesc VIRTIORINGDESC;
72typedef VIRTIORINGDESC *PVIRTIORINGDESC;
73
74/**
75 * The available ring refers to what descriptors are being offered to the
76 * device.
77 */
78struct 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};
84typedef struct VirtioRingAvail VIRTIORINGAVAIL;
85typedef 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 */
92struct 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};
97typedef struct VirtioRingUsedElem VIRTIORINGUSEDELEM;
98typedef VIRTIORINGUSEDELEM *PVIRTIORINGUSEDELEM;
99
100/**
101 * The Virtio Ring which contains the descriptors.
102 */
103struct 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};
110typedef struct VirtioRing VIRTIORING;
111typedef VIRTIORING *PVIRTIORING;
112
113struct VirtioDevice;
114struct VirtioQueue;
115
116typedef void *(*PFNVIRTIOALLOC)(struct VirtioDevice *pDevice);
117typedef void (*PFNVIRTIOFREE)(struct VirtioDevice *pDevice);
118typedef int (*PFNVIRTIOATTACH)(struct VirtioDevice *pDevice);
119typedef int (*PFNVIRTIODETACH)(struct VirtioDevice *pDevice);
120typedef uint32_t (*PFNVIRTIOGETFEATURES)(struct VirtioDevice *pDevice);
121typedef void (*PFNVIRTIOSETFEATURES)(struct VirtioDevice *pDevice, uint32_t fFeatures);
122typedef void (*PFNVIRTIOGET)(struct VirtioDevice *pDevice, off_t off, void *pv, size_t cb);
123typedef void (*PFNVIRTIOSET)(struct VirtioDevice *pDevice, off_t off, void *pv, size_t cb);
124typedef void *(*PFNVIRTIOGETQUEUE)(struct VirtioDevice *pDevice, struct VirtioQueue *pQueue);
125typedef void (*PFNVIRTIOPUTQUEUE)(struct VirtioDevice *pDevice, struct VirtioQueue *pQueue);
126typedef int (*PFNVIRTIONOTIFYQUEUE)(struct VirtioDevice *pDevice, struct VirtioQueue *pQueue);
127typedef void (*PFNVIRTIOSETSTATUS)(struct VirtioDevice *pDevice, uint8_t Status);
128
129/**
130 * Virtio device operations.
131 */
132struct VirtioDeviceOps
133{
134 PFNVIRTIOALLOC pfnAlloc; /* Device alloc. */
135 PFNVIRTIOFREE pfnFree; /* Device free. */
136 PFNVIRTIOATTACH pfnAttach; /* Device attach. */
137 PFNVIRTIODETACH pfnDetach; /* Device detach. */
138};
139typedef struct VirtioDeviceOps VIRTIODEVICEOPS;
140typedef VIRTIODEVICEOPS *PVIRTIODEVICEOPS;
141
142/**
143 * Hypervisor access operations.
144 */
145struct 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};
160typedef struct VirtioHyperOps VIRTIOHYPEROPS;
161typedef VIRTIOHYPEROPS *PVIRTIOHYPEROPS;
162
163/**
164 * Virtio Queue into which buffers are posted.
165 */
166struct 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};
175typedef struct VirtioQueue VIRTIOQUEUE;
176typedef VIRTIOQUEUE *PVIRTIOQUEUE;
177
178/**
179 * Virtio device descriptor, common to all Virtio devices.
180 */
181struct 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};
190typedef struct VirtioDevice VIRTIODEVICE;
191typedef VIRTIODEVICE *PVIRTIODEVICE;
192
193
194int VirtioAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd, PVIRTIODEVICEOPS pDeviceOps, PVIRTIOHYPEROPS pHyperOps);
195int VirtioDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd);
196
197PVIRTIOQUEUE VirtioGetQueue(PVIRTIODEVICE pDevice, uint16_t Index);
198void VirtioPutQueue(PVIRTIODEVICE pDevice, PVIRTIOQUEUE pQueue);
199
200void VirtioRingInit(PVIRTIOQUEUE pQueue, uint_t cDescs, caddr_t virtBuf, ulong_t Align);
201int VirtioRingPush(PVIRTIOQUEUE pQueue, paddr_t physBuf, uint32_t cbBuf, uint16_t fFlags);
202size_t VirtioRingSize(uint64_t cElements, ulong_t Align);
203
204#endif /* !GA_INCLUDED_SRC_solaris_Virtio_Virtio_solaris_h */
205
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette