VirtualBox

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

Last change on this file since 24895 was 22652, checked in by vboxsync, 15 years ago

fixed OSE headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.1 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 RTHEAPSIMPLE heap; /* Heap instance. */
156 HGSMIAREA area; /* Description. */
157 int cRefs; /* Number of heap allocations. */
158} HGSMIHEAP;
159#pragma pack()
160
161#pragma pack(1)
162/* The size of the array of channels. Array indexes are uint8_t. Note: the value must not be changed. */
163#define HGSMI_NUMBER_OF_CHANNELS 0x100
164
165/* Channel handler called when the guest submits a buffer. */
166typedef DECLCALLBACK(int) FNHGSMICHANNELHANDLER(void *pvHandler, uint16_t u16ChannelInfo, void *pvBuffer, HGSMISIZE cbBuffer);
167typedef FNHGSMICHANNELHANDLER *PFNHGSMICHANNELHANDLER;
168
169/* Information about a handler: pfn + context. */
170typedef struct _HGSMICHANNELHANDLER
171{
172 PFNHGSMICHANNELHANDLER pfnHandler;
173 void *pvHandler;
174} HGSMICHANNELHANDLER;
175
176/* Channel description. */
177typedef struct _HGSMICHANNEL
178{
179 HGSMICHANNELHANDLER handler; /* The channel handler. */
180 const char *pszName; /* NULL for hardcoded channels or RTStrDup'ed name. */
181 uint8_t u8Channel; /* The channel id, equal to the channel index in the array. */
182 uint8_t u8Flags; /* HGSMI_CH_F_* */
183} HGSMICHANNEL;
184
185typedef struct _HGSMICHANNELINFO
186{
187 HGSMICHANNEL Channels[HGSMI_NUMBER_OF_CHANNELS]; /* Channel handlers indexed by the channel id.
188 * The array is accessed under the instance lock.
189 */
190} HGSMICHANNELINFO;
191#pragma pack()
192
193
194RT_C_DECLS_BEGIN
195
196DECLINLINE(HGSMISIZE) HGSMIBufferMinimumSize (void)
197{
198 return sizeof (HGSMIBUFFERHEADER) + sizeof (HGSMIBUFFERTAIL);
199}
200
201DECLINLINE(uint8_t *) HGSMIBufferData (const HGSMIBUFFERHEADER *pHeader)
202{
203 return (uint8_t *)pHeader + sizeof (HGSMIBUFFERHEADER);
204}
205
206DECLINLINE(HGSMIBUFFERTAIL *) HGSMIBufferTail (const HGSMIBUFFERHEADER *pHeader)
207{
208 return (HGSMIBUFFERTAIL *)(HGSMIBufferData (pHeader) + pHeader->u32DataSize);
209}
210
211DECLINLINE(HGSMIBUFFERHEADER *) HGSMIBufferHeaderFromData (const void *pvData)
212{
213 return (HGSMIBUFFERHEADER *)((uint8_t *)pvData - sizeof (HGSMIBUFFERHEADER));
214}
215
216DECLINLINE(HGSMISIZE) HGSMIBufferRequiredSize (uint32_t u32DataSize)
217{
218 return HGSMIBufferMinimumSize () + u32DataSize;
219}
220
221DECLINLINE(HGSMIOFFSET) HGSMIPointerToOffset (const HGSMIAREA *pArea,
222 const HGSMIBUFFERHEADER *pHeader)
223{
224 return pArea->offBase + (HGSMIOFFSET)((uint8_t *)pHeader - pArea->pu8Base);
225}
226
227DECLINLINE(HGSMIBUFFERHEADER *) HGSMIOffsetToPointer (const HGSMIAREA *pArea,
228 HGSMIOFFSET offBuffer)
229{
230 return (HGSMIBUFFERHEADER *)(pArea->pu8Base + (offBuffer - pArea->offBase));
231}
232
233DECLINLINE(uint8_t *) HGSMIBufferDataFromOffset (const HGSMIAREA *pArea, HGSMIOFFSET offBuffer)
234{
235 HGSMIBUFFERHEADER *pHeader = HGSMIOffsetToPointer (pArea, offBuffer);
236 Assert(pHeader);
237 if(pHeader)
238 return HGSMIBufferData(pHeader);
239 return NULL;
240}
241
242HGSMICHANNEL *HGSMIChannelFindById (HGSMICHANNELINFO * pChannelInfo, uint8_t u8Channel);
243
244uint32_t HGSMIChecksum (HGSMIOFFSET offBuffer,
245 const HGSMIBUFFERHEADER *pHeader,
246 const HGSMIBUFFERTAIL *pTail);
247
248int HGSMIAreaInitialize (HGSMIAREA *pArea,
249 void *pvBase,
250 HGSMISIZE cbArea,
251 HGSMIOFFSET offBase);
252
253void HGSMIAreaClear (HGSMIAREA *pArea);
254
255HGSMIOFFSET HGSMIBufferInitializeSingle (const HGSMIAREA *pArea,
256 HGSMIBUFFERHEADER *pHeader,
257 HGSMISIZE cbBuffer,
258 uint8_t u8Channel,
259 uint16_t u16ChannelInfo);
260
261int HGSMIHeapSetup (HGSMIHEAP *pHeap,
262 void *pvBase,
263 HGSMISIZE cbArea,
264 HGSMIOFFSET offBase);
265
266int HGSMIHeapRelocate (HGSMIHEAP *pHeap,
267 void *pvBase,
268 uint32_t offHeapHandle,
269 uintptr_t offDelta,
270 HGSMISIZE cbArea,
271 HGSMIOFFSET offBase
272 );
273
274void HGSMIHeapSetupUnitialized (HGSMIHEAP *pHeap);
275bool HGSMIHeapIsItialized (HGSMIHEAP *pHeap);
276
277void HGSMIHeapDestroy (HGSMIHEAP *pHeap);
278
279void *HGSMIHeapAlloc (HGSMIHEAP *pHeap,
280 HGSMISIZE cbData,
281 uint8_t u8Channel,
282 uint16_t u16ChannelInfo);
283
284HGSMIOFFSET HGSMIHeapBufferOffset (HGSMIHEAP *pHeap,
285 void *pvData);
286
287void HGSMIHeapFree (HGSMIHEAP *pHeap,
288 void *pvData);
289
290DECLINLINE(HGSMIOFFSET) HGSMIHeapOffset(HGSMIHEAP *pHeap)
291{
292 return pHeap->area.offBase;
293}
294
295/* needed for heap relocation */
296DECLINLINE(HGSMIOFFSET) HGSMIHeapHandleLocationOffset(HGSMIHEAP *pHeap)
297{
298 return pHeap->heap != NIL_RTHEAPSIMPLE ? (uint32_t)(pHeap->area.pu8Base - (uint8_t*)pHeap->heap) : HGSMIOFFSET_VOID;
299}
300
301DECLINLINE(HGSMISIZE) HGSMIHeapSize(HGSMIHEAP *pHeap)
302{
303 return pHeap->area.cbArea;
304}
305
306int HGSMIChannelRegister (HGSMICHANNELINFO * pChannelInfo,
307 uint8_t u8Channel,
308 const char *pszName,
309 PFNHGSMICHANNELHANDLER pfnChannelHandler,
310 void *pvChannelHandler,
311 HGSMICHANNELHANDLER *pOldHandler);
312
313int HGSMIBufferProcess (HGSMIAREA *pArea,
314 HGSMICHANNELINFO * pChannelInfo,
315 HGSMIOFFSET offBuffer);
316RT_C_DECLS_END
317
318#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