VirtualBox

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

Last change on this file since 69028 was 69015, checked in by vboxsync, 7 years ago

Fix up header files for graphics hardware.
bugref:9017: Additions/x11: put vboxvideo into upstream X.Org

Make sure that all graphics hardware header files have svn Id tags to be
able to match X.Org files with VirtualBox revisions.

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