VirtualBox

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

Last change on this file since 25728 was 25062, checked in by vboxsync, 15 years ago

HGSMI,DevVGA: Use the offset based heap for the hostHeap (resides in VRAM). New staved state version for DevVGA for indicating this change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 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-2008 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
28 * Clara, CA 95054 USA or visit http://www.sun.com if you need
29 * additional information or have any questions.
30 */
31
32
33#ifndef __HGSMI_h__
34#define __HGSMI_h__
35
36#include <iprt/assert.h>
37#include <iprt/types.h>
38
39#include <VBox/HGSMI/HGSMIChannels.h>
40
41/* HGSMI uses 32 bit offsets and sizes. */
42typedef uint32_t HGSMISIZE;
43typedef uint32_t HGSMIOFFSET;
44
45#define HGSMIOFFSET_VOID ((HGSMIOFFSET)~0)
46
47/*
48 * Basic mechanism for the HGSMI is to prepare and pass data buffer to the host and the guest.
49 * Data inside these buffers are opaque for the HGSMI and are interpreted by higher levels.
50 *
51 * Every shared memory buffer passed between the guest/host has the following structure:
52 *
53 * HGSMIBUFFERHEADER header;
54 * uint8_t data[header.u32BufferSize];
55 * HGSMIBUFFERTAIL tail;
56 *
57 * Note: Offset of the 'header' in the memory is used for virtual hardware IO.
58 *
59 * Buffers are verifyed using the offset and the content of the header and the tail,
60 * which are constant during a call.
61 *
62 * Invalid buffers are ignored.
63 *
64 * Actual 'data' is not verifyed, as it is expected that the data can be changed by the
65 * called function.
66 *
67 * Since only the offset of the buffer is passed in a IO operation, the header and tail
68 * must contain:
69 * * size of data in this buffer;
70 * * checksum for buffer verification.
71 *
72 * For segmented transfers:
73 * * the sequence identifier;
74 * * offset of the current segment in the sequence;
75 * * total bytes in the transfer.
76 *
77 * Additionally contains:
78 * * the channel ID;
79 * * the channel information.
80 */
81
82
83/* Describes a shared memory area buffer.
84 * Used for calculations with offsets and for buffers verification.
85 */
86typedef struct _HGSMIAREA
87{
88 uint8_t *pu8Base; /* The starting address of the area. Corresponds to offset 'offBase'. */
89 HGSMIOFFSET offBase; /* The starting offset of the area. */
90 HGSMIOFFSET offLast; /* The last valid offset:
91 * offBase + cbArea - 1 - (sizeof (header) + sizeof (tail)).
92 */
93 HGSMISIZE cbArea; /* Size of the area. */
94} HGSMIAREA;
95
96
97/* The buffer description flags. */
98#define HGSMI_BUFFER_HEADER_F_SEQ_MASK 0x03 /* Buffer sequence type mask. */
99#define HGSMI_BUFFER_HEADER_F_SEQ_SINGLE 0x00 /* Single buffer, not a part of a sequence. */
100#define HGSMI_BUFFER_HEADER_F_SEQ_START 0x01 /* The first buffer in a sequence. */
101#define HGSMI_BUFFER_HEADER_F_SEQ_CONTINUE 0x02 /* A middle buffer in a sequence. */
102#define HGSMI_BUFFER_HEADER_F_SEQ_END 0x03 /* The last buffer in a sequence. */
103
104
105#pragma pack(1)
106/* 16 bytes buffer header. */
107typedef struct _HGSMIBUFFERHEADER
108{
109 uint32_t u32DataSize; /* Size of data that follows the header. */
110
111 uint8_t u8Flags; /* The buffer description: HGSMI_BUFFER_HEADER_F_* */
112
113 uint8_t u8Channel; /* The channel the data must be routed to. */
114 uint16_t u16ChannelInfo; /* Opaque to the HGSMI, used by the channel. */
115
116 union {
117 uint8_t au8Union[8]; /* Opaque placeholder to make the union 8 bytes. */
118
119 struct
120 { /* HGSMI_BUFFER_HEADER_F_SEQ_SINGLE */
121 uint32_t u32Reserved1; /* A reserved field, initialize to 0. */
122 uint32_t u32Reserved2; /* A reserved field, initialize to 0. */
123 } Buffer;
124
125 struct
126 { /* HGSMI_BUFFER_HEADER_F_SEQ_START */
127 uint32_t u32SequenceNumber; /* The sequence number, the same for all buffers in the sequence. */
128 uint32_t u32SequenceSize; /* The total size of the sequence. */
129 } SequenceStart;
130
131 struct
132 { /* HGSMI_BUFFER_HEADER_F_SEQ_CONTINUE and HGSMI_BUFFER_HEADER_F_SEQ_END */
133 uint32_t u32SequenceNumber; /* The sequence number, the same for all buffers in the sequence. */
134 uint32_t u32SequenceOffset; /* Data offset in the entire sequence. */
135 } SequenceContinue;
136 } u;
137
138} HGSMIBUFFERHEADER;
139
140/* 8 bytes buffer tail. */
141typedef struct _HGSMIBUFFERTAIL
142{
143 uint32_t u32Reserved; /* Reserved, must be initialized to 0. */
144 uint32_t u32Checksum; /* Verifyer for the buffer header and offset and for first 4 bytes of the tail. */
145} HGSMIBUFFERTAIL;
146#pragma pack()
147
148AssertCompile(sizeof (HGSMIBUFFERHEADER) == 16);
149AssertCompile(sizeof (HGSMIBUFFERTAIL) == 8);
150
151
152#pragma pack(1)
153typedef struct _HGSMIHEAP
154{
155 union
156 {
157 RTHEAPSIMPLE hPtr; /**< Pointer based heap. */
158 RTHEAPOFFSET hOff; /**< Offset based heap. */
159 } u;
160 HGSMIAREA area; /**< Description. */
161 int cRefs; /**< Number of heap allocations. */
162 bool fOffsetBased; /**< Set if offset based. */
163} HGSMIHEAP;
164#pragma pack()
165
166#pragma pack(1)
167/* The size of the array of channels. Array indexes are uint8_t. Note: the value must not be changed. */
168#define HGSMI_NUMBER_OF_CHANNELS 0x100
169
170/* Channel handler called when the guest submits a buffer. */
171typedef DECLCALLBACK(int) FNHGSMICHANNELHANDLER(void *pvHandler, uint16_t u16ChannelInfo, void *pvBuffer, HGSMISIZE cbBuffer);
172typedef FNHGSMICHANNELHANDLER *PFNHGSMICHANNELHANDLER;
173
174/* Information about a handler: pfn + context. */
175typedef struct _HGSMICHANNELHANDLER
176{
177 PFNHGSMICHANNELHANDLER pfnHandler;
178 void *pvHandler;
179} HGSMICHANNELHANDLER;
180
181/* Channel description. */
182typedef struct _HGSMICHANNEL
183{
184 HGSMICHANNELHANDLER handler; /* The channel handler. */
185 const char *pszName; /* NULL for hardcoded channels or RTStrDup'ed name. */
186 uint8_t u8Channel; /* The channel id, equal to the channel index in the array. */
187 uint8_t u8Flags; /* HGSMI_CH_F_* */
188} HGSMICHANNEL;
189
190typedef struct _HGSMICHANNELINFO
191{
192 HGSMICHANNEL Channels[HGSMI_NUMBER_OF_CHANNELS]; /* Channel handlers indexed by the channel id.
193 * The array is accessed under the instance lock.
194 */
195} HGSMICHANNELINFO;
196#pragma pack()
197
198
199RT_C_DECLS_BEGIN
200
201DECLINLINE(HGSMISIZE) HGSMIBufferMinimumSize (void)
202{
203 return sizeof (HGSMIBUFFERHEADER) + sizeof (HGSMIBUFFERTAIL);
204}
205
206DECLINLINE(uint8_t *) HGSMIBufferData (const HGSMIBUFFERHEADER *pHeader)
207{
208 return (uint8_t *)pHeader + sizeof (HGSMIBUFFERHEADER);
209}
210
211DECLINLINE(HGSMIBUFFERTAIL *) HGSMIBufferTail (const HGSMIBUFFERHEADER *pHeader)
212{
213 return (HGSMIBUFFERTAIL *)(HGSMIBufferData (pHeader) + pHeader->u32DataSize);
214}
215
216DECLINLINE(HGSMIBUFFERHEADER *) HGSMIBufferHeaderFromData (const void *pvData)
217{
218 return (HGSMIBUFFERHEADER *)((uint8_t *)pvData - sizeof (HGSMIBUFFERHEADER));
219}
220
221DECLINLINE(HGSMISIZE) HGSMIBufferRequiredSize (uint32_t u32DataSize)
222{
223 return HGSMIBufferMinimumSize () + u32DataSize;
224}
225
226DECLINLINE(HGSMIOFFSET) HGSMIPointerToOffset (const HGSMIAREA *pArea,
227 const HGSMIBUFFERHEADER *pHeader)
228{
229 return pArea->offBase + (HGSMIOFFSET)((uint8_t *)pHeader - pArea->pu8Base);
230}
231
232DECLINLINE(HGSMIBUFFERHEADER *) HGSMIOffsetToPointer (const HGSMIAREA *pArea,
233 HGSMIOFFSET offBuffer)
234{
235 return (HGSMIBUFFERHEADER *)(pArea->pu8Base + (offBuffer - pArea->offBase));
236}
237
238DECLINLINE(uint8_t *) HGSMIBufferDataFromOffset (const HGSMIAREA *pArea, HGSMIOFFSET offBuffer)
239{
240 HGSMIBUFFERHEADER *pHeader = HGSMIOffsetToPointer (pArea, offBuffer);
241 Assert(pHeader);
242 if(pHeader)
243 return HGSMIBufferData(pHeader);
244 return NULL;
245}
246
247HGSMICHANNEL *HGSMIChannelFindById (HGSMICHANNELINFO * pChannelInfo, uint8_t u8Channel);
248
249uint32_t HGSMIChecksum (HGSMIOFFSET offBuffer,
250 const HGSMIBUFFERHEADER *pHeader,
251 const HGSMIBUFFERTAIL *pTail);
252
253int HGSMIAreaInitialize (HGSMIAREA *pArea,
254 void *pvBase,
255 HGSMISIZE cbArea,
256 HGSMIOFFSET offBase);
257
258void HGSMIAreaClear (HGSMIAREA *pArea);
259
260HGSMIOFFSET HGSMIBufferInitializeSingle (const HGSMIAREA *pArea,
261 HGSMIBUFFERHEADER *pHeader,
262 HGSMISIZE cbBuffer,
263 uint8_t u8Channel,
264 uint16_t u16ChannelInfo);
265
266int HGSMIHeapSetup (HGSMIHEAP *pHeap,
267 void *pvBase,
268 HGSMISIZE cbArea,
269 HGSMIOFFSET offBase,
270 bool fOffsetBased);
271
272int HGSMIHeapRelocate (HGSMIHEAP *pHeap,
273 void *pvBase,
274 uint32_t offHeapHandle,
275 uintptr_t offDelta,
276 HGSMISIZE cbArea,
277 HGSMIOFFSET offBase,
278 bool fOffsetBased);
279
280void HGSMIHeapSetupUnitialized (HGSMIHEAP *pHeap);
281bool HGSMIHeapIsItialized (HGSMIHEAP *pHeap);
282
283void HGSMIHeapDestroy (HGSMIHEAP *pHeap);
284
285void *HGSMIHeapAlloc (HGSMIHEAP *pHeap,
286 HGSMISIZE cbData,
287 uint8_t u8Channel,
288 uint16_t u16ChannelInfo);
289
290HGSMIOFFSET HGSMIHeapBufferOffset (HGSMIHEAP *pHeap,
291 void *pvData);
292
293void HGSMIHeapFree (HGSMIHEAP *pHeap,
294 void *pvData);
295
296DECLINLINE(HGSMIOFFSET) HGSMIHeapOffset(HGSMIHEAP *pHeap)
297{
298 return pHeap->area.offBase;
299}
300
301/* needed for heap relocation */
302DECLINLINE(HGSMIOFFSET) HGSMIHeapHandleLocationOffset(HGSMIHEAP *pHeap)
303{
304 AssertCompile((uintptr_t)NIL_RTHEAPSIMPLE == (uintptr_t)NIL_RTHEAPOFFSET);
305 return pHeap->u.hPtr != NIL_RTHEAPSIMPLE
306 ? (HGSMIOFFSET)(pHeap->area.pu8Base - (uint8_t*)pHeap->u.hPtr)
307 : HGSMIOFFSET_VOID;
308}
309
310DECLINLINE(HGSMISIZE) HGSMIHeapSize(HGSMIHEAP *pHeap)
311{
312 return pHeap->area.cbArea;
313}
314
315int HGSMIChannelRegister (HGSMICHANNELINFO * pChannelInfo,
316 uint8_t u8Channel,
317 const char *pszName,
318 PFNHGSMICHANNELHANDLER pfnChannelHandler,
319 void *pvChannelHandler,
320 HGSMICHANNELHANDLER *pOldHandler);
321
322int HGSMIBufferProcess (HGSMIAREA *pArea,
323 HGSMICHANNELINFO * pChannelInfo,
324 HGSMIOFFSET offBuffer);
325RT_C_DECLS_END
326
327#endif /* __HGSMI_h__*/
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