VirtualBox

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

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

include file build fixes (kmk -C include)

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

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