VirtualBox

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

最後變更 在這個檔案從69753是 69307,由 vboxsync 提交於 7 年 前

include/VBox: scm updates w/ correct MIT text

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 8.8 KB
 
1/* $Id: HGSMI.h 69307 2017-10-25 13:46:45Z 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/* Channel handler called when the guest submits a buffer. */
86typedef DECLCALLBACK(int) FNHGSMICHANNELHANDLER(void *pvHandler, uint16_t u16ChannelInfo, void *pvBuffer, HGSMISIZE cbBuffer);
87typedef FNHGSMICHANNELHANDLER *PFNHGSMICHANNELHANDLER;
88
89/* Information about a handler: pfn + context. */
90typedef struct _HGSMICHANNELHANDLER
91{
92 PFNHGSMICHANNELHANDLER pfnHandler;
93 void *pvHandler;
94} HGSMICHANNELHANDLER;
95
96/* Channel description. */
97typedef struct _HGSMICHANNEL
98{
99 HGSMICHANNELHANDLER handler; /* The channel handler. */
100 const char *pszName; /* NULL for hardcoded channels or RTStrDup'ed name. */
101 uint8_t u8Channel; /* The channel id, equal to the channel index in the array. */
102 uint8_t u8Flags; /* HGSMI_CH_F_* */
103} HGSMICHANNEL;
104
105typedef struct _HGSMICHANNELINFO
106{
107 HGSMICHANNEL Channels[HGSMI_NUMBER_OF_CHANNELS]; /* Channel handlers indexed by the channel id.
108 * The array is accessed under the instance lock.
109 */
110} HGSMICHANNELINFO;
111
112
113RT_C_DECLS_BEGIN
114
115DECLINLINE(HGSMIBUFFERHEADER *) HGSMIBufferHeaderFromPtr(void *pvBuffer)
116{
117 return (HGSMIBUFFERHEADER *)pvBuffer;
118}
119
120DECLINLINE(uint8_t *) HGSMIBufferDataFromPtr(void *pvBuffer)
121{
122 return (uint8_t *)pvBuffer + sizeof(HGSMIBUFFERHEADER);
123}
124
125DECLINLINE(HGSMIBUFFERTAIL *) HGSMIBufferTailFromPtr(void *pvBuffer,
126 uint32_t u32DataSize)
127{
128 return (HGSMIBUFFERTAIL *)(HGSMIBufferDataFromPtr(pvBuffer) + u32DataSize);
129}
130
131DECLINLINE(HGSMISIZE) HGSMIBufferMinimumSize(void)
132{
133 return sizeof(HGSMIBUFFERHEADER) + sizeof(HGSMIBUFFERTAIL);
134}
135
136DECLINLINE(HGSMIBUFFERHEADER *) HGSMIBufferHeaderFromData(const void *pvData)
137{
138 return (HGSMIBUFFERHEADER *)((uint8_t *)pvData - sizeof(HGSMIBUFFERHEADER));
139}
140
141DECLINLINE(HGSMISIZE) HGSMIBufferRequiredSize(uint32_t u32DataSize)
142{
143 return HGSMIBufferMinimumSize() + u32DataSize;
144}
145
146DECLINLINE(HGSMIOFFSET) HGSMIPointerToOffset(const HGSMIAREA *pArea,
147 const void *pv)
148{
149 return pArea->offBase + (HGSMIOFFSET)((uint8_t *)pv - pArea->pu8Base);
150}
151
152DECLINLINE(void *) HGSMIOffsetToPointer(const HGSMIAREA *pArea,
153 HGSMIOFFSET offBuffer)
154{
155 return pArea->pu8Base + (offBuffer - pArea->offBase);
156}
157
158DECLINLINE(uint8_t *) HGSMIBufferDataFromOffset(const HGSMIAREA *pArea,
159 HGSMIOFFSET offBuffer)
160{
161 void *pvBuffer = HGSMIOffsetToPointer(pArea, offBuffer);
162 return HGSMIBufferDataFromPtr(pvBuffer);
163}
164
165DECLINLINE(HGSMIOFFSET) HGSMIBufferOffsetFromData(const HGSMIAREA *pArea,
166 void *pvData)
167{
168 HGSMIBUFFERHEADER *pHeader = HGSMIBufferHeaderFromData(pvData);
169 return HGSMIPointerToOffset(pArea, pHeader);
170}
171
172DECLINLINE(uint8_t *) HGSMIBufferDataAndChInfoFromOffset(const HGSMIAREA *pArea,
173 HGSMIOFFSET offBuffer,
174 uint16_t *pu16ChannelInfo)
175{
176 HGSMIBUFFERHEADER *pHeader = (HGSMIBUFFERHEADER *)HGSMIOffsetToPointer(pArea, offBuffer);
177 *pu16ChannelInfo = pHeader->u16ChannelInfo;
178 return HGSMIBufferDataFromPtr(pHeader);
179}
180
181uint32_t HGSMIChecksum(HGSMIOFFSET offBuffer,
182 const HGSMIBUFFERHEADER *pHeader,
183 const HGSMIBUFFERTAIL *pTail);
184
185int HGSMIAreaInitialize(HGSMIAREA *pArea,
186 void *pvBase,
187 HGSMISIZE cbArea,
188 HGSMIOFFSET offBase);
189
190void HGSMIAreaClear(HGSMIAREA *pArea);
191
192DECLINLINE(bool) HGSMIAreaContainsOffset(const HGSMIAREA *pArea, HGSMIOFFSET off)
193{
194 return off >= pArea->offBase && off - pArea->offBase < pArea->cbArea;
195}
196
197DECLINLINE(bool) HGSMIAreaContainsPointer(const HGSMIAREA *pArea, const void *pv)
198{
199 return (uintptr_t)pv >= (uintptr_t)pArea->pu8Base && (uintptr_t)pv - (uintptr_t)pArea->pu8Base < pArea->cbArea;
200}
201
202HGSMIOFFSET HGSMIBufferInitializeSingle(const HGSMIAREA *pArea,
203 HGSMIBUFFERHEADER *pHeader,
204 HGSMISIZE cbBuffer,
205 uint8_t u8Channel,
206 uint16_t u16ChannelInfo);
207
208int HGSMIHeapSetup(HGSMIHEAP *pHeap,
209 void *pvBase,
210 HGSMISIZE cbArea,
211 HGSMIOFFSET offBase,
212 const HGSMIENV *pEnv);
213
214void HGSMIHeapDestroy(HGSMIHEAP *pHeap);
215
216void *HGSMIHeapBufferAlloc(HGSMIHEAP *pHeap,
217 HGSMISIZE cbBuffer);
218
219void HGSMIHeapBufferFree(HGSMIHEAP *pHeap,
220 void *pvBuf);
221
222void *HGSMIHeapAlloc(HGSMIHEAP *pHeap,
223 HGSMISIZE cbData,
224 uint8_t u8Channel,
225 uint16_t u16ChannelInfo);
226
227void HGSMIHeapFree(HGSMIHEAP *pHeap,
228 void *pvData);
229
230DECLINLINE(const HGSMIAREA *) HGSMIHeapArea(HGSMIHEAP *pHeap)
231{
232 return &pHeap->area;
233}
234
235DECLINLINE(HGSMIOFFSET) HGSMIHeapOffset(HGSMIHEAP *pHeap)
236{
237 return HGSMIHeapArea(pHeap)->offBase;
238}
239
240DECLINLINE(HGSMISIZE) HGSMIHeapSize(HGSMIHEAP *pHeap)
241{
242 return HGSMIHeapArea(pHeap)->cbArea;
243}
244
245DECLINLINE(HGSMIOFFSET) HGSMIHeapBufferOffset(HGSMIHEAP *pHeap,
246 void *pvData)
247{
248 return HGSMIBufferOffsetFromData(HGSMIHeapArea(pHeap), pvData);
249}
250
251HGSMICHANNEL *HGSMIChannelFindById(HGSMICHANNELINFO *pChannelInfo,
252 uint8_t u8Channel);
253
254int HGSMIChannelRegister(HGSMICHANNELINFO *pChannelInfo,
255 uint8_t u8Channel,
256 const char *pszName,
257 PFNHGSMICHANNELHANDLER pfnChannelHandler,
258 void *pvChannelHandler);
259
260int HGSMIBufferProcess(const HGSMIAREA *pArea,
261 HGSMICHANNELINFO *pChannelInfo,
262 HGSMIOFFSET offBuffer);
263RT_C_DECLS_END
264
265#endif /* !___VBox_Graphics_HGSMI_h */
266
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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