VirtualBox

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

Last change on this file since 66544 was 66544, checked in by vboxsync, 8 years ago

bugref:8524: Additions/linux: play nicely with distribution-installed Additions
Change header of files which are expected to end up in the Linux kernel to the MIT licence to simplify life for people wanting to port vboxvideo to other kernels and to simplify synchronising changes back to VirtualBox. Update author information in files which have it, but do not add it to files which do not.

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