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 | */
|
---|
54 | struct 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 | };
|
---|
61 | typedef struct VirtioRingDesc VIRTIORINGDESC;
|
---|
62 | typedef VIRTIORINGDESC *PVIRTIORINGDESC;
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * The available ring refers to what descriptors are being offered to the
|
---|
66 | * device.
|
---|
67 | */
|
---|
68 | struct 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 | };
|
---|
74 | typedef struct VirtioRingAvail VIRTIORINGAVAIL;
|
---|
75 | typedef 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 | */
|
---|
82 | struct 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 | };
|
---|
87 | typedef struct VirtioRingUsedElem VIRTIORINGUSEDELEM;
|
---|
88 | typedef VIRTIORINGUSEDELEM *PVIRTIORINGUSEDELEM;
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * The Virtio Ring which contains the descriptors.
|
---|
92 | */
|
---|
93 | struct 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 | };
|
---|
100 | typedef struct VirtioRing VIRTIORING;
|
---|
101 | typedef VIRTIORING *PVIRTIORING;
|
---|
102 |
|
---|
103 | struct VirtioDevice;
|
---|
104 | struct VirtioQueue;
|
---|
105 |
|
---|
106 | typedef void *(*PFNVIRTIOALLOC)(struct VirtioDevice *pDevice);
|
---|
107 | typedef void (*PFNVIRTIOFREE)(struct VirtioDevice *pDevice);
|
---|
108 | typedef int (*PFNVIRTIOATTACH)(struct VirtioDevice *pDevice);
|
---|
109 | typedef int (*PFNVIRTIODETACH)(struct VirtioDevice *pDevice);
|
---|
110 | typedef uint32_t (*PFNVIRTIOGETFEATURES)(struct VirtioDevice *pDevice);
|
---|
111 | typedef void (*PFNVIRTIOSETFEATURES)(struct VirtioDevice *pDevice, uint32_t fFeatures);
|
---|
112 | typedef void (*PFNVIRTIOGET)(struct VirtioDevice *pDevice, off_t off, void *pv, size_t cb);
|
---|
113 | typedef void (*PFNVIRTIOSET)(struct VirtioDevice *pDevice, off_t off, void *pv, size_t cb);
|
---|
114 | typedef void *(*PFNVIRTIOGETQUEUE)(struct VirtioDevice *pDevice, struct VirtioQueue *pQueue);
|
---|
115 | typedef void (*PFNVIRTIOPUTQUEUE)(struct VirtioDevice *pDevice, struct VirtioQueue *pQueue);
|
---|
116 | typedef int (*PFNVIRTIONOTIFYQUEUE)(struct VirtioDevice *pDevice, struct VirtioQueue *pQueue);
|
---|
117 | typedef void (*PFNVIRTIOSETSTATUS)(struct VirtioDevice *pDevice, uint8_t Status);
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Virtio device operations.
|
---|
121 | */
|
---|
122 | struct VirtioDeviceOps
|
---|
123 | {
|
---|
124 | PFNVIRTIOALLOC pfnAlloc; /* Device alloc. */
|
---|
125 | PFNVIRTIOFREE pfnFree; /* Device free. */
|
---|
126 | PFNVIRTIOATTACH pfnAttach; /* Device attach. */
|
---|
127 | PFNVIRTIODETACH pfnDetach; /* Device detach. */
|
---|
128 | };
|
---|
129 | typedef struct VirtioDeviceOps VIRTIODEVICEOPS;
|
---|
130 | typedef VIRTIODEVICEOPS *PVIRTIODEVICEOPS;
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Hypervisor access operations.
|
---|
134 | */
|
---|
135 | struct 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 | };
|
---|
150 | typedef struct VirtioHyperOps VIRTIOHYPEROPS;
|
---|
151 | typedef VIRTIOHYPEROPS *PVIRTIOHYPEROPS;
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Virtio Queue into which buffers are posted.
|
---|
155 | */
|
---|
156 | struct 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 | };
|
---|
165 | typedef struct VirtioQueue VIRTIOQUEUE;
|
---|
166 | typedef VIRTIOQUEUE *PVIRTIOQUEUE;
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Virtio device descriptor, common to all Virtio devices.
|
---|
170 | */
|
---|
171 | struct 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 | };
|
---|
180 | typedef struct VirtioDevice VIRTIODEVICE;
|
---|
181 | typedef VIRTIODEVICE *PVIRTIODEVICE;
|
---|
182 |
|
---|
183 |
|
---|
184 | int VirtioAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd, PVIRTIODEVICEOPS pDeviceOps, PVIRTIOHYPEROPS pHyperOps);
|
---|
185 | int VirtioDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd);
|
---|
186 |
|
---|
187 | PVIRTIOQUEUE VirtioGetQueue(PVIRTIODEVICE pDevice, uint16_t Index);
|
---|
188 | void VirtioPutQueue(PVIRTIODEVICE pDevice, PVIRTIOQUEUE pQueue);
|
---|
189 |
|
---|
190 | void VirtioRingInit(PVIRTIOQUEUE pQueue, uint_t cDescs, caddr_t virtBuf, ulong_t Align);
|
---|
191 | int VirtioRingPush(PVIRTIOQUEUE pQueue, paddr_t physBuf, uint32_t cbBuf, uint16_t fFlags);
|
---|
192 | size_t VirtioRingSize(uint64_t cElements, ulong_t Align);
|
---|
193 |
|
---|
194 | #endif /* !GA_INCLUDED_SRC_solaris_Virtio_Virtio_solaris_h */
|
---|
195 |
|
---|