VirtualBox

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

Last change on this file since 79067 was 76563, checked in by vboxsync, 6 years ago

Additions: Use GA_INCLUDED_ and variations_ as header guard prefixes with scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 KB
Line 
1/* $Id: Virtio-solaris.h 76563 2019-01-01 03:53:56Z vboxsync $ */
2/** @file
3 * VirtualBox Guest Additions: Virtio Driver for Solaris, header.
4 */
5
6/*
7 * Copyright (C) 2010-2019 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 GA_INCLUDED_SRC_solaris_Virtio_Virtio_solaris_h
28#define GA_INCLUDED_SRC_solaris_Virtio_Virtio_solaris_h
29#ifndef RT_WITHOUT_PRAGMA_ONCE
30# pragma once
31#endif
32
33#include <sys/sunddi.h>
34
35/** Release log descriptive prefix. */
36#define VIRTIOLOGNAME "Virtio"
37/** Buffer continues via the Next field */
38#define VIRTIO_FLAGS_RING_DESC_NEXT RT_BIT(0)
39/** Buffer is write-only, else is read-only. */
40#define VIRTIO_FLAGS_RING_DESC_WRITE RT_BIT(1)
41/** Indirect buffer (buffer contains list of buffer descriptors) */
42#define VIRTIO_FLAGS_RING_DESC_INDIRECT RT_BIT(2)
43
44/* Values from our Virtio.h */
45#define VIRTIO_PCI_STATUS_ACK 0x01
46#define VIRTIO_PCI_STATUS_DRV 0x02
47#define VIRTIO_PCI_STATUS_DRV_OK 0x04
48#define VIRTIO_PCI_STATUS_FAILED 0x80
49
50/**
51 * The ring descriptor table refers to the buffers the guest is using for the
52 * device.
53 */
54struct VirtioRingDesc
55{
56 uint64_t AddrBuf; /* Physical address of buffer. */
57 uint32_t cbBuf; /* Length of the buffer in bytes. */
58 uint16_t fFlags; /* Flags of the next buffer. */
59 uint16_t Next; /* Index of the next buffer. */
60};
61typedef struct VirtioRingDesc VIRTIORINGDESC;
62typedef VIRTIORINGDESC *PVIRTIORINGDESC;
63
64/**
65 * The available ring refers to what descriptors are being offered to the
66 * device.
67 */
68struct VirtioRingAvail
69{
70 uint16_t fFlags; /* Interrupt supression flag. */
71 uint16_t Index; /* Index of available ring. */
72 uint16_t aRings[1]; /* Array of indices into descriptor table. */
73};
74typedef struct VirtioRingAvail VIRTIORINGAVAIL;
75typedef VIRTIORINGAVAIL *PVIRTIORINGAVAIL;
76
77/**
78 * The used ring refers to the buffers the device is done using them. The
79 * element is a pair-descriptor refers to the buffer once the device is done
80 * with the buffer.
81 */
82struct VirtioRingUsedElem
83{
84 uint32_t Index; /* Index of start of used descriptor chain. */
85 uint32_t cbElem; /* Number of bytes written into the buffer. */
86};
87typedef struct VirtioRingUsedElem VIRTIORINGUSEDELEM;
88typedef VIRTIORINGUSEDELEM *PVIRTIORINGUSEDELEM;
89
90/**
91 * The Virtio Ring which contains the descriptors.
92 */
93struct VirtioRing
94{
95 uint_t cDesc; /* Number of descriptors. */
96 PVIRTIORINGDESC pRingDesc; /* Pointer to ring descriptor. */
97 PVIRTIORINGAVAIL pRingAvail; /* Pointer to available ring. */
98 PVIRTIORINGUSEDELEM pRingUsedElem; /* Pointer to used ring element. */
99};
100typedef struct VirtioRing VIRTIORING;
101typedef VIRTIORING *PVIRTIORING;
102
103struct VirtioDevice;
104struct VirtioQueue;
105
106typedef void *(*PFNVIRTIOALLOC)(struct VirtioDevice *pDevice);
107typedef void (*PFNVIRTIOFREE)(struct VirtioDevice *pDevice);
108typedef int (*PFNVIRTIOATTACH)(struct VirtioDevice *pDevice);
109typedef int (*PFNVIRTIODETACH)(struct VirtioDevice *pDevice);
110typedef uint32_t (*PFNVIRTIOGETFEATURES)(struct VirtioDevice *pDevice);
111typedef void (*PFNVIRTIOSETFEATURES)(struct VirtioDevice *pDevice, uint32_t fFeatures);
112typedef void (*PFNVIRTIOGET)(struct VirtioDevice *pDevice, off_t off, void *pv, size_t cb);
113typedef void (*PFNVIRTIOSET)(struct VirtioDevice *pDevice, off_t off, void *pv, size_t cb);
114typedef void *(*PFNVIRTIOGETQUEUE)(struct VirtioDevice *pDevice, struct VirtioQueue *pQueue);
115typedef void (*PFNVIRTIOPUTQUEUE)(struct VirtioDevice *pDevice, struct VirtioQueue *pQueue);
116typedef int (*PFNVIRTIONOTIFYQUEUE)(struct VirtioDevice *pDevice, struct VirtioQueue *pQueue);
117typedef void (*PFNVIRTIOSETSTATUS)(struct VirtioDevice *pDevice, uint8_t Status);
118
119/**
120 * Virtio device operations.
121 */
122struct VirtioDeviceOps
123{
124 PFNVIRTIOALLOC pfnAlloc; /* Device alloc. */
125 PFNVIRTIOFREE pfnFree; /* Device free. */
126 PFNVIRTIOATTACH pfnAttach; /* Device attach. */
127 PFNVIRTIODETACH pfnDetach; /* Device detach. */
128};
129typedef struct VirtioDeviceOps VIRTIODEVICEOPS;
130typedef VIRTIODEVICEOPS *PVIRTIODEVICEOPS;
131
132/**
133 * Hypervisor access operations.
134 */
135struct VirtioHyperOps
136{
137 PFNVIRTIOALLOC pfnAlloc; /* Hypervisor alloc. */
138 PFNVIRTIOFREE pfnFree; /* Hypervisor free */
139 PFNVIRTIOATTACH pfnAttach; /* Hypervisor attach. */
140 PFNVIRTIODETACH pfnDetach; /* Hypervisor detach. */
141 PFNVIRTIOGETFEATURES pfnGetFeatures; /* Hypervisor get features. */
142 PFNVIRTIOSETFEATURES pfnSetFeatures; /* Hypervisor set features. */
143 PFNVIRTIONOTIFYQUEUE pfnNotifyQueue; /* Hypervisor notify queue. */
144 PFNVIRTIOGET pfnGet; /* Hypervisor get. */
145 PFNVIRTIOSET pfnSet; /* Hypervisor set. */
146 PFNVIRTIOGETQUEUE pfnGetQueue; /* Hypervisor get queue. */
147 PFNVIRTIOPUTQUEUE pfnPutQueue; /* Hypervisor put queue. */
148 PFNVIRTIOSETSTATUS pfnSetStatus; /* Hypervisor set status. */
149};
150typedef struct VirtioHyperOps VIRTIOHYPEROPS;
151typedef VIRTIOHYPEROPS *PVIRTIOHYPEROPS;
152
153/**
154 * Virtio Queue into which buffers are posted.
155 */
156struct VirtioQueue
157{
158 VIRTIORING Ring; /* Ring buffer of this queue. */
159 uint16_t cBufs; /* Number of pushed, unnotified buffers. */
160 uint16_t FreeHeadIndex; /* Index of head of free list. */
161 uint16_t QueueIndex; /* Index of this queue. */
162 caddr_t pQueue; /* Allocated DMA region for queue. */
163 void *pvData; /* Queue private data. */
164};
165typedef struct VirtioQueue VIRTIOQUEUE;
166typedef VIRTIOQUEUE *PVIRTIOQUEUE;
167
168/**
169 * Virtio device descriptor, common to all Virtio devices.
170 */
171struct VirtioDevice
172{
173 dev_info_t *pDip; /* OS device info. */
174 PVIRTIODEVICEOPS pDeviceOps; /* Device hooks. */
175 void *pvDevice; /* Device opaque data. */
176 PVIRTIOHYPEROPS pHyperOps; /* Hypervisor hooks. */
177 void *pvHyper; /* Hypervisor opaque data. */
178 uint32_t fHostFeatures; /* Features provided by the host. */
179};
180typedef struct VirtioDevice VIRTIODEVICE;
181typedef VIRTIODEVICE *PVIRTIODEVICE;
182
183
184int VirtioAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd, PVIRTIODEVICEOPS pDeviceOps, PVIRTIOHYPEROPS pHyperOps);
185int VirtioDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd);
186
187PVIRTIOQUEUE VirtioGetQueue(PVIRTIODEVICE pDevice, uint16_t Index);
188void VirtioPutQueue(PVIRTIODEVICE pDevice, PVIRTIOQUEUE pQueue);
189
190void VirtioRingInit(PVIRTIOQUEUE pQueue, uint_t cDescs, caddr_t virtBuf, ulong_t Align);
191int VirtioRingPush(PVIRTIOQUEUE pQueue, paddr_t physBuf, uint32_t cbBuf, uint16_t fFlags);
192size_t VirtioRingSize(uint64_t cElements, ulong_t Align);
193
194#endif /* !GA_INCLUDED_SRC_solaris_Virtio_Virtio_solaris_h */
195
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