VirtualBox

source: vbox/trunk/include/VBox/HGSMI/HGSMI.h@ 55421

Last change on this file since 55421 was 55421, checked in by vboxsync, 10 years ago

HGSMI: cleanup, logging, comments, move legacy host heap support from common code to the host code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.9 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-2015 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * The contents of this file may alternatively be used under the terms
19 * of the Common Development and Distribution License Version 1.0
20 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
21 * VirtualBox OSE distribution, in which case the provisions of the
22 * CDDL are applicable instead of those of the GPL.
23 *
24 * You may elect to license modified versions of this file under the
25 * terms and conditions of either the GPL or the CDDL or both.
26 */
27
28
29#ifndef ___VBox_HGSMI_HGSMI_h
30#define ___VBox_HGSMI_HGSMI_h
31
32#include <iprt/assert.h>
33#include <iprt/types.h>
34
35#include <VBox/HGSMI/HGSMIDefs.h>
36#include <VBox/HGSMI/HGSMIChannels.h>
37#include <VBox/HGSMI/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
74#pragma pack(1)
75typedef struct HGSMIHEAP
76{
77 HGSMIAREA area; /* Description. */
78 HGSMIMADATA ma; /* Memory allocator */
79} HGSMIHEAP;
80#pragma pack()
81
82#pragma pack(1)
83/* The size of the array of channels. Array indexes are uint8_t. Note: the value must not be changed. */
84#define HGSMI_NUMBER_OF_CHANNELS 0x100
85
86/* Channel handler called when the guest submits a buffer. */
87typedef DECLCALLBACK(int) FNHGSMICHANNELHANDLER(void *pvHandler, uint16_t u16ChannelInfo, void *pvBuffer, HGSMISIZE cbBuffer);
88typedef FNHGSMICHANNELHANDLER *PFNHGSMICHANNELHANDLER;
89
90/* Information about a handler: pfn + context. */
91typedef struct _HGSMICHANNELHANDLER
92{
93 PFNHGSMICHANNELHANDLER pfnHandler;
94 void *pvHandler;
95} HGSMICHANNELHANDLER;
96
97/* Channel description. */
98typedef struct _HGSMICHANNEL
99{
100 HGSMICHANNELHANDLER handler; /* The channel handler. */
101 const char *pszName; /* NULL for hardcoded channels or RTStrDup'ed name. */
102 uint8_t u8Channel; /* The channel id, equal to the channel index in the array. */
103 uint8_t u8Flags; /* HGSMI_CH_F_* */
104} HGSMICHANNEL;
105
106typedef struct _HGSMICHANNELINFO
107{
108 HGSMICHANNEL Channels[HGSMI_NUMBER_OF_CHANNELS]; /* Channel handlers indexed by the channel id.
109 * The array is accessed under the instance lock.
110 */
111} HGSMICHANNELINFO;
112#pragma pack()
113
114
115RT_C_DECLS_BEGIN
116
117DECLINLINE(HGSMIBUFFERHEADER *) HGSMIBufferHeaderFromPtr(void *pvBuffer)
118{
119 return (HGSMIBUFFERHEADER *)pvBuffer;
120}
121
122DECLINLINE(uint8_t *) HGSMIBufferDataFromPtr(void *pvBuffer)
123{
124 return (uint8_t *)pvBuffer + sizeof(HGSMIBUFFERHEADER);
125}
126
127DECLINLINE(HGSMIBUFFERTAIL *) HGSMIBufferTailFromPtr(void *pvBuffer, uint32_t u32DataSize)
128{
129 return (HGSMIBUFFERTAIL *)(HGSMIBufferDataFromPtr(pvBuffer) + u32DataSize);
130}
131
132DECLINLINE(HGSMISIZE) HGSMIBufferMinimumSize (void)
133{
134 return sizeof (HGSMIBUFFERHEADER) + sizeof (HGSMIBUFFERTAIL);
135}
136
137DECLINLINE(uint8_t *) HGSMIBufferData (const HGSMIBUFFERHEADER *pHeader)
138{
139 return (uint8_t *)pHeader + sizeof (HGSMIBUFFERHEADER);
140}
141
142DECLINLINE(HGSMIBUFFERTAIL *) HGSMIBufferTail (const HGSMIBUFFERHEADER *pHeader)
143{
144 return (HGSMIBUFFERTAIL *)(HGSMIBufferData (pHeader) + pHeader->u32DataSize);
145}
146
147DECLINLINE(HGSMIBUFFERHEADER *) HGSMIBufferHeaderFromData (const void *pvData)
148{
149 return (HGSMIBUFFERHEADER *)((uint8_t *)pvData - sizeof (HGSMIBUFFERHEADER));
150}
151
152DECLINLINE(HGSMISIZE) HGSMIBufferRequiredSize (uint32_t u32DataSize)
153{
154 return HGSMIBufferMinimumSize () + u32DataSize;
155}
156
157DECLINLINE(HGSMIOFFSET) HGSMIPointerToOffset(const HGSMIAREA *pArea,
158 const void *pv)
159{
160 return pArea->offBase + (HGSMIOFFSET)((uint8_t *)pv - pArea->pu8Base);
161}
162
163DECLINLINE(void *) HGSMIOffsetToPointer(const HGSMIAREA *pArea,
164 HGSMIOFFSET offBuffer)
165{
166 return pArea->pu8Base + (offBuffer - pArea->offBase);
167}
168
169DECLINLINE(uint8_t *) HGSMIBufferDataFromOffset(const HGSMIAREA *pArea,
170 HGSMIOFFSET offBuffer)
171{
172 void *pvBuffer = HGSMIOffsetToPointer(pArea, offBuffer);
173 return HGSMIBufferDataFromPtr(pvBuffer);
174}
175
176DECLINLINE(HGSMIOFFSET) HGSMIBufferOffsetFromData(const HGSMIAREA *pArea,
177 void *pvData)
178{
179 HGSMIBUFFERHEADER *pHeader = HGSMIBufferHeaderFromData(pvData);
180 return HGSMIPointerToOffset(pArea, pHeader);
181}
182
183DECLINLINE(uint8_t *) HGSMIBufferDataAndChInfoFromOffset (const HGSMIAREA *pArea, HGSMIOFFSET offBuffer, uint16_t * pChInfo)
184{
185 HGSMIBUFFERHEADER *pHeader = (HGSMIBUFFERHEADER *)HGSMIOffsetToPointer (pArea, offBuffer);
186 Assert(pHeader);
187 if(pHeader)
188 {
189 *pChInfo = pHeader->u16ChannelInfo;
190 return HGSMIBufferData(pHeader);
191 }
192 return NULL;
193}
194
195uint32_t HGSMIChecksum (HGSMIOFFSET offBuffer,
196 const HGSMIBUFFERHEADER *pHeader,
197 const HGSMIBUFFERTAIL *pTail);
198
199int HGSMIAreaInitialize (HGSMIAREA *pArea,
200 void *pvBase,
201 HGSMISIZE cbArea,
202 HGSMIOFFSET offBase);
203
204void HGSMIAreaClear (HGSMIAREA *pArea);
205
206DECLINLINE(bool) HGSMIAreaContainsOffset(const HGSMIAREA *pArea, HGSMIOFFSET off)
207{
208 return off >= pArea->offBase && off - pArea->offBase < pArea->cbArea;
209}
210
211DECLINLINE(bool) HGSMIAreaContainsPointer(const HGSMIAREA *pArea, const void *pv)
212{
213 return (uintptr_t)pv >= (uintptr_t)pArea->pu8Base && (uintptr_t)pv - (uintptr_t)pArea->pu8Base < pArea->cbArea;
214}
215
216HGSMIOFFSET HGSMIBufferInitializeSingle (const HGSMIAREA *pArea,
217 HGSMIBUFFERHEADER *pHeader,
218 HGSMISIZE cbBuffer,
219 uint8_t u8Channel,
220 uint16_t u16ChannelInfo);
221
222DECLINLINE(const HGSMIAREA *) HGSMIHeapArea(HGSMIHEAP *pHeap)
223{
224 return &pHeap->area;
225}
226
227int HGSMIHeapSetup (HGSMIHEAP *pHeap,
228 void *pvBase,
229 HGSMISIZE cbArea,
230 HGSMIOFFSET offBase,
231 const HGSMIENV *pEnv);
232
233void HGSMIHeapDestroy (HGSMIHEAP *pHeap);
234
235void* HGSMIHeapBufferAlloc (HGSMIHEAP *pHeap,
236 HGSMISIZE cbBuffer);
237
238void HGSMIHeapBufferFree(HGSMIHEAP *pHeap,
239 void *pvBuf);
240
241void *HGSMIHeapAlloc (HGSMIHEAP *pHeap,
242 HGSMISIZE cbData,
243 uint8_t u8Channel,
244 uint16_t u16ChannelInfo);
245
246DECLINLINE(HGSMIOFFSET) HGSMIHeapBufferOffset(HGSMIHEAP *pHeap, void *pvData)
247{
248 return HGSMIBufferOffsetFromData(HGSMIHeapArea(pHeap), pvData);
249}
250
251void HGSMIHeapFree (HGSMIHEAP *pHeap,
252 void *pvData);
253
254DECLINLINE(HGSMIOFFSET) HGSMIHeapOffset(HGSMIHEAP *pHeap)
255{
256 return HGSMIHeapArea(pHeap)->offBase;
257}
258
259DECLINLINE(HGSMISIZE) HGSMIHeapSize(HGSMIHEAP *pHeap)
260{
261 return HGSMIHeapArea(pHeap)->cbArea;
262}
263
264HGSMICHANNEL *HGSMIChannelFindById(HGSMICHANNELINFO *pChannelInfo,
265 uint8_t u8Channel);
266
267int HGSMIChannelRegister(HGSMICHANNELINFO *pChannelInfo,
268 uint8_t u8Channel,
269 const char *pszName,
270 PFNHGSMICHANNELHANDLER pfnChannelHandler,
271 void *pvChannelHandler);
272
273int HGSMIBufferProcess(HGSMIAREA *pArea,
274 HGSMICHANNELINFO *pChannelInfo,
275 HGSMIOFFSET offBuffer);
276RT_C_DECLS_END
277
278#endif /* !___VBox_HGSMI_HGSMI_h */
279
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