VirtualBox

source: vbox/trunk/include/VBox/Graphics/HGSMI.h@ 74865

Last change on this file since 74865 was 71590, checked in by vboxsync, 7 years ago

DevVGA,HGSMI,++: Code cleanup in progress. bugref:9094

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1/* $Id: HGSMI.h 71590 2018-03-31 18:34:28Z vboxsync $ */
2/** @file
3 * VBox Host Guest Shared Memory Interface (HGSMI) - Host/Guest shared part.
4 */
5
6/*
7 * Copyright (C) 2006-2017 Oracle Corporation
8 *
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31
32#ifndef ___VBox_Graphics_HGSMI_h
33#define ___VBox_Graphics_HGSMI_h
34
35#include "VBoxVideoIPRT.h"
36
37#include "HGSMIDefs.h"
38#include "HGSMIChannels.h"
39#include "HGSMIMemAlloc.h"
40
41/**
42 * Basic mechanism for the HGSMI is to prepare and pass data buffer to the host and the guest.
43 * Data inside these buffers are opaque for the HGSMI and are interpreted by higher levels.
44 *
45 * Every shared memory buffer passed between the guest/host has the following structure:
46 *
47 * HGSMIBUFFERHEADER header;
48 * uint8_t data[header.u32BufferSize];
49 * HGSMIBUFFERTAIL tail;
50 *
51 * Note: Offset of the 'header' in the memory is used for virtual hardware IO.
52 *
53 * Buffers are verifyed using the offset and the content of the header and the tail,
54 * which are constant during a call.
55 *
56 * Invalid buffers are ignored.
57 *
58 * Actual 'data' is not verifyed, as it is expected that the data can be changed by the
59 * called function.
60 *
61 * Since only the offset of the buffer is passed in a IO operation, the header and tail
62 * must contain:
63 * * size of data in this buffer;
64 * * checksum for buffer verification.
65 *
66 * For segmented transfers:
67 * * the sequence identifier;
68 * * offset of the current segment in the sequence;
69 * * total bytes in the transfer.
70 *
71 * Additionally contains:
72 * * the channel ID;
73 * * the channel information.
74 */
75
76typedef struct HGSMIHEAP
77{
78 HGSMIAREA area; /**< Description. */
79 HGSMIMADATA ma; /**< Memory allocator */
80} HGSMIHEAP;
81
82/* The size of the array of channels. Array indexes are uint8_t. Note: the value must not be changed. */
83#define HGSMI_NUMBER_OF_CHANNELS 0x100
84
85/**
86 * Channel handler called when the guest submits a buffer.
87 *
88 * @returns stuff
89 * @param pvHandler Value specified when registring.
90 * @param u16ChannelInfo Command code.
91 * @param pvBuffer HGSMI buffer with command data. This is shared with
92 * the guest. Consider untrusted and volatile!
93 * @param cbBuffer Size of command data.
94 * @thread EMT on the host side.
95 */
96typedef DECLCALLBACK(int) FNHGSMICHANNELHANDLER(void *pvHandler, uint16_t u16ChannelInfo,
97 RT_UNTRUSTED_VOLATILE_HSTGST void *pvBuffer, HGSMISIZE cbBuffer);
98/** Pointer to a channel handler callback. */
99typedef FNHGSMICHANNELHANDLER *PFNHGSMICHANNELHANDLER;
100
101/** Information about a handler: pfn + context. */
102typedef struct _HGSMICHANNELHANDLER
103{
104 PFNHGSMICHANNELHANDLER pfnHandler;
105 void *pvHandler;
106} HGSMICHANNELHANDLER;
107
108/** Channel description. */
109typedef struct _HGSMICHANNEL
110{
111 HGSMICHANNELHANDLER handler; /**< The channel handler. */
112 const char *pszName; /**< NULL for hardcoded channels or RTStrDup'ed name. */
113 uint8_t u8Channel; /**< The channel id, equal to the channel index in the array. */
114 uint8_t u8Flags; /**< HGSMI_CH_F_* */
115} HGSMICHANNEL;
116
117typedef struct _HGSMICHANNELINFO
118{
119 /** Channel handlers indexed by the channel id.
120 * The array is accessed under the instance lock. */
121 HGSMICHANNEL Channels[HGSMI_NUMBER_OF_CHANNELS];
122} HGSMICHANNELINFO;
123
124
125RT_C_DECLS_BEGIN
126
127DECLINLINE(HGSMIBUFFERHEADER *) HGSMIBufferHeaderFromPtr(void RT_UNTRUSTED_VOLATILE_HSTGST *pvBuffer)
128{
129 return (HGSMIBUFFERHEADER *)pvBuffer;
130}
131
132DECLINLINE(uint8_t RT_UNTRUSTED_VOLATILE_HSTGST *) HGSMIBufferDataFromPtr(void RT_UNTRUSTED_VOLATILE_HSTGST *pvBuffer)
133{
134 return (uint8_t RT_UNTRUSTED_VOLATILE_HSTGST *)pvBuffer + sizeof(HGSMIBUFFERHEADER);
135}
136
137DECLINLINE(HGSMIBUFFERTAIL RT_UNTRUSTED_VOLATILE_HSTGST *)
138HGSMIBufferTailFromPtr(void RT_UNTRUSTED_VOLATILE_HSTGST *pvBuffer, uint32_t u32DataSize)
139{
140 return (HGSMIBUFFERTAIL RT_UNTRUSTED_VOLATILE_HSTGST *)(HGSMIBufferDataFromPtr(pvBuffer) + u32DataSize);
141}
142
143DECLINLINE(HGSMISIZE) HGSMIBufferMinimumSize(void)
144{
145 return sizeof(HGSMIBUFFERHEADER) + sizeof(HGSMIBUFFERTAIL);
146}
147
148DECLINLINE(HGSMIBUFFERHEADER RT_UNTRUSTED_VOLATILE_HSTGST *) HGSMIBufferHeaderFromData(const void RT_UNTRUSTED_VOLATILE_HSTGST *pvData)
149{
150 return (HGSMIBUFFERHEADER RT_UNTRUSTED_VOLATILE_HSTGST *)((uint8_t *)pvData - sizeof(HGSMIBUFFERHEADER));
151}
152
153DECLINLINE(HGSMISIZE) HGSMIBufferRequiredSize(uint32_t u32DataSize)
154{
155 return HGSMIBufferMinimumSize() + u32DataSize;
156}
157
158DECLINLINE(HGSMIOFFSET) HGSMIPointerToOffset(const HGSMIAREA *pArea, const void RT_UNTRUSTED_VOLATILE_HSTGST *pv)
159{
160 return pArea->offBase + (HGSMIOFFSET)((uint8_t *)pv - pArea->pu8Base);
161}
162
163DECLINLINE(void RT_UNTRUSTED_VOLATILE_HSTGST *) HGSMIOffsetToPointer(const HGSMIAREA *pArea, HGSMIOFFSET offBuffer)
164{
165 return pArea->pu8Base + (offBuffer - pArea->offBase);
166}
167
168DECLINLINE(uint8_t RT_UNTRUSTED_VOLATILE_HSTGST*) HGSMIBufferDataFromOffset(const HGSMIAREA *pArea, HGSMIOFFSET offBuffer)
169{
170 void RT_UNTRUSTED_VOLATILE_HSTGST *pvBuffer = HGSMIOffsetToPointer(pArea, offBuffer);
171 return HGSMIBufferDataFromPtr(pvBuffer);
172}
173
174DECLINLINE(HGSMIOFFSET) HGSMIBufferOffsetFromData(const HGSMIAREA *pArea, void RT_UNTRUSTED_VOLATILE_HSTGST *pvData)
175{
176 HGSMIBUFFERHEADER RT_UNTRUSTED_VOLATILE_HSTGST *pHeader = HGSMIBufferHeaderFromData(pvData);
177 return HGSMIPointerToOffset(pArea, pHeader);
178}
179
180DECLINLINE(uint8_t RT_UNTRUSTED_VOLATILE_HSTGST *) HGSMIBufferDataAndChInfoFromOffset(const HGSMIAREA *pArea,
181 HGSMIOFFSET offBuffer,
182 uint16_t *pu16ChannelInfo)
183{
184 HGSMIBUFFERHEADER RT_UNTRUSTED_VOLATILE_HSTGST *pHeader =
185 (HGSMIBUFFERHEADER RT_UNTRUSTED_VOLATILE_HSTGST *)HGSMIOffsetToPointer(pArea, offBuffer);
186 *pu16ChannelInfo = pHeader->u16ChannelInfo;
187 return HGSMIBufferDataFromPtr(pHeader);
188}
189
190uint32_t HGSMIChecksum(HGSMIOFFSET offBuffer, const HGSMIBUFFERHEADER RT_UNTRUSTED_VOLATILE_HSTGST *pHeader,
191 const HGSMIBUFFERTAIL RT_UNTRUSTED_VOLATILE_HSTGST *pTail);
192
193int HGSMIAreaInitialize(HGSMIAREA *pArea, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase);
194void HGSMIAreaClear(HGSMIAREA *pArea);
195
196DECLINLINE(bool) HGSMIAreaContainsOffset(const HGSMIAREA *pArea, HGSMIOFFSET off)
197{
198 return off >= pArea->offBase && off - pArea->offBase < pArea->cbArea;
199}
200
201DECLINLINE(bool) HGSMIAreaContainsPointer(const HGSMIAREA *pArea, const void RT_UNTRUSTED_VOLATILE_HSTGST *pv)
202{
203 return (uintptr_t)pv - (uintptr_t)pArea->pu8Base < pArea->cbArea;
204}
205
206HGSMIOFFSET HGSMIBufferInitializeSingle(const HGSMIAREA *pArea, HGSMIBUFFERHEADER *pHeader, HGSMISIZE cbBuffer,
207 uint8_t u8Channel, uint16_t u16ChannelInfo);
208
209int HGSMIHeapSetup(HGSMIHEAP *pHeap, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase, const HGSMIENV *pEnv);
210void HGSMIHeapDestroy(HGSMIHEAP *pHeap);
211void RT_UNTRUSTED_VOLATILE_HSTGST *HGSMIHeapBufferAlloc(HGSMIHEAP *pHeap, HGSMISIZE cbBuffer);
212void HGSMIHeapBufferFree(HGSMIHEAP *pHeap, void RT_UNTRUSTED_VOLATILE_HSTGST *pvBuf);
213
214void RT_UNTRUSTED_VOLATILE_HOST *HGSMIHeapAlloc(HGSMIHEAP *pHeap,
215 HGSMISIZE cbData,
216 uint8_t u8Channel,
217 uint16_t u16ChannelInfo);
218
219void HGSMIHeapFree(HGSMIHEAP *pHeap, void RT_UNTRUSTED_VOLATILE_HSTGST *pvData);
220
221DECLINLINE(const HGSMIAREA *) HGSMIHeapArea(HGSMIHEAP *pHeap)
222{
223 return &pHeap->area;
224}
225
226DECLINLINE(HGSMIOFFSET) HGSMIHeapOffset(HGSMIHEAP *pHeap)
227{
228 return HGSMIHeapArea(pHeap)->offBase;
229}
230
231DECLINLINE(HGSMISIZE) HGSMIHeapSize(HGSMIHEAP *pHeap)
232{
233 return HGSMIHeapArea(pHeap)->cbArea;
234}
235
236DECLINLINE(HGSMIOFFSET) HGSMIHeapBufferOffset(HGSMIHEAP *pHeap, void RT_UNTRUSTED_VOLATILE_HOST *pvData)
237{
238 return HGSMIBufferOffsetFromData(HGSMIHeapArea(pHeap), pvData);
239}
240
241HGSMICHANNEL *HGSMIChannelFindById(HGSMICHANNELINFO *pChannelInfo, uint8_t u8Channel);
242
243int HGSMIChannelRegister(HGSMICHANNELINFO *pChannelInfo, uint8_t u8Channel, const char *pszName,
244 PFNHGSMICHANNELHANDLER pfnChannelHandler, void *pvChannelHandler);
245int HGSMIBufferProcess(const HGSMIAREA *pArea, HGSMICHANNELINFO *pChannelInfo, HGSMIOFFSET offBuffer);
246RT_C_DECLS_END
247
248#endif /* !___VBox_Graphics_HGSMI_h */
249
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