VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp@ 69447

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

common/VBoxVideo: scm update and todo regarding syntax checking/library

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 11.5 KB
 
1/* $Id: HGSMIBase.cpp 69309 2017-10-25 13:55:39Z vboxsync $ */
2/** @file
3 * VirtualBox Video driver, common code - HGSMI guest-to-host communication.
4 */
5
6/*
7 * Copyright (C) 2006-2017 Oracle Corporation
8 *
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31#include <HGSMIBase.h>
32#include <VBoxVideoIPRT.h>
33#include <VBoxVideoGuest.h>
34#include <VBoxVideoVBE.h>
35#include <HGSMIChannels.h>
36#include <HGSMIChSetup.h>
37
38/** Detect whether HGSMI is supported by the host. */
39DECLHIDDEN(bool) VBoxHGSMIIsSupported(void)
40{
41 uint16_t DispiId;
42
43 VBVO_PORT_WRITE_U16(VBE_DISPI_IOPORT_INDEX, VBE_DISPI_INDEX_ID);
44 VBVO_PORT_WRITE_U16(VBE_DISPI_IOPORT_DATA, VBE_DISPI_ID_HGSMI);
45
46 DispiId = VBVO_PORT_READ_U16(VBE_DISPI_IOPORT_DATA);
47
48 return (DispiId == VBE_DISPI_ID_HGSMI);
49}
50
51
52/**
53 * Inform the host of the location of the host flags in VRAM via an HGSMI command.
54 * @returns IPRT status value.
55 * @returns VERR_NOT_IMPLEMENTED if the host does not support the command.
56 * @returns VERR_NO_MEMORY if a heap allocation fails.
57 * @param pCtx the context of the guest heap to use.
58 * @param offLocation the offset chosen for the flags withing guest VRAM.
59 */
60DECLHIDDEN(int) VBoxHGSMIReportFlagsLocation(PHGSMIGUESTCOMMANDCONTEXT pCtx, HGSMIOFFSET offLocation)
61{
62 HGSMIBUFFERLOCATION *p;
63
64 /* Allocate the IO buffer. */
65 p = (HGSMIBUFFERLOCATION *)VBoxHGSMIBufferAlloc(pCtx, sizeof(*p), HGSMI_CH_HGSMI,
66 HGSMI_CC_HOST_FLAGS_LOCATION);
67 if (!p)
68 return VERR_NO_MEMORY;
69
70 /* Prepare data to be sent to the host. */
71 p->offLocation = offLocation;
72 p->cbLocation = sizeof(HGSMIHOSTFLAGS);
73 /* No need to check that the buffer is valid as we have just allocated it. */
74 VBoxHGSMIBufferSubmit(pCtx, p);
75 /* Free the IO buffer. */
76 VBoxHGSMIBufferFree(pCtx, p);
77
78 return VINF_SUCCESS;
79}
80
81
82/**
83 * Notify the host of HGSMI-related guest capabilities via an HGSMI command.
84 * @returns IPRT status value.
85 * @returns VERR_NOT_IMPLEMENTED if the host does not support the command.
86 * @returns VERR_NO_MEMORY if a heap allocation fails.
87 * @param pCtx the context of the guest heap to use.
88 * @param fCaps the capabilities to report, see VBVACAPS.
89 */
90DECLHIDDEN(int) VBoxHGSMISendCapsInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx, uint32_t fCaps)
91{
92 VBVACAPS *p;
93
94 /* Allocate the IO buffer. */
95 p = (VBVACAPS *)VBoxHGSMIBufferAlloc(pCtx, sizeof(*p), HGSMI_CH_VBVA, VBVA_INFO_CAPS);
96
97 if (!p)
98 return VERR_NO_MEMORY;
99
100 /* Prepare data to be sent to the host. */
101 p->rc = VERR_NOT_IMPLEMENTED;
102 p->fCaps = fCaps;
103 /* No need to check that the buffer is valid as we have just allocated it. */
104 VBoxHGSMIBufferSubmit(pCtx, p);
105
106 AssertRC(p->rc);
107 /* Free the IO buffer. */
108 VBoxHGSMIBufferFree(pCtx, p);
109 return p->rc;
110}
111
112
113/**
114 * Get the information needed to map the basic communication structures in
115 * device memory into our address space. All pointer parameters are optional.
116 *
117 * @param cbVRAM how much video RAM is allocated to the device
118 * @param poffVRAMBaseMapping where to save the offset from the start of the
119 * device VRAM of the whole area to map
120 * @param pcbMapping where to save the mapping size
121 * @param poffGuestHeapMemory where to save the offset into the mapped area
122 * of the guest heap backing memory
123 * @param pcbGuestHeapMemory where to save the size of the guest heap
124 * backing memory
125 * @param poffHostFlags where to save the offset into the mapped area
126 * of the host flags
127 */
128DECLHIDDEN(void) VBoxHGSMIGetBaseMappingInfo(uint32_t cbVRAM,
129 uint32_t *poffVRAMBaseMapping,
130 uint32_t *pcbMapping,
131 uint32_t *poffGuestHeapMemory,
132 uint32_t *pcbGuestHeapMemory,
133 uint32_t *poffHostFlags)
134{
135 AssertPtrNullReturnVoid(poffVRAMBaseMapping);
136 AssertPtrNullReturnVoid(pcbMapping);
137 AssertPtrNullReturnVoid(poffGuestHeapMemory);
138 AssertPtrNullReturnVoid(pcbGuestHeapMemory);
139 AssertPtrNullReturnVoid(poffHostFlags);
140 if (poffVRAMBaseMapping)
141 *poffVRAMBaseMapping = cbVRAM - VBVA_ADAPTER_INFORMATION_SIZE;
142 if (pcbMapping)
143 *pcbMapping = VBVA_ADAPTER_INFORMATION_SIZE;
144 if (poffGuestHeapMemory)
145 *poffGuestHeapMemory = 0;
146 if (pcbGuestHeapMemory)
147 *pcbGuestHeapMemory = VBVA_ADAPTER_INFORMATION_SIZE
148 - sizeof(HGSMIHOSTFLAGS);
149 if (poffHostFlags)
150 *poffHostFlags = VBVA_ADAPTER_INFORMATION_SIZE
151 - sizeof(HGSMIHOSTFLAGS);
152}
153
154/**
155 * Query the host for an HGSMI configuration parameter via an HGSMI command.
156 * @returns iprt status value
157 * @param pCtx the context containing the heap used
158 * @param u32Index the index of the parameter to query,
159 * @see VBVACONF32::u32Index
160 * @param pulValue where to store the value of the parameter on success
161 */
162DECLHIDDEN(int) VBoxQueryConfHGSMI(PHGSMIGUESTCOMMANDCONTEXT pCtx, uint32_t u32Index, uint32_t *pulValue)
163{
164 VBVACONF32 *p;
165
166 /* Allocate the IO buffer. */
167 p = (VBVACONF32 *)VBoxHGSMIBufferAlloc(pCtx, sizeof(*p), HGSMI_CH_VBVA,
168 VBVA_QUERY_CONF32);
169 if (!p)
170 return VERR_NO_MEMORY;
171
172 /* Prepare data to be sent to the host. */
173 p->u32Index = u32Index;
174 p->u32Value = UINT32_MAX;
175 /* No need to check that the buffer is valid as we have just allocated it. */
176 VBoxHGSMIBufferSubmit(pCtx, p);
177 *pulValue = p->u32Value;
178 /* Free the IO buffer. */
179 VBoxHGSMIBufferFree(pCtx, p);
180 return VINF_SUCCESS;
181}
182
183/**
184 * Pass the host a new mouse pointer shape via an HGSMI command.
185 *
186 * @returns success or failure
187 * @param pCtx the context containing the heap to be used
188 * @param fFlags cursor flags, @see VMMDevReqMousePointer::fFlags
189 * @param cHotX horizontal position of the hot spot
190 * @param cHotY vertical position of the hot spot
191 * @param cWidth width in pixels of the cursor
192 * @param cHeight height in pixels of the cursor
193 * @param pPixels pixel data, @see VMMDevReqMousePointer for the format
194 * @param cbLength size in bytes of the pixel data
195 */
196DECLHIDDEN(int) VBoxHGSMIUpdatePointerShape(PHGSMIGUESTCOMMANDCONTEXT pCtx, uint32_t fFlags,
197 uint32_t cHotX, uint32_t cHotY, uint32_t cWidth, uint32_t cHeight,
198 uint8_t *pPixels, uint32_t cbLength)
199{
200 VBVAMOUSEPOINTERSHAPE *p;
201 uint32_t cbPixels = 0;
202 int rc;
203
204 if (fFlags & VBOX_MOUSE_POINTER_SHAPE)
205 {
206 /*
207 * Size of the pointer data:
208 * sizeof (AND mask) + sizeof (XOR_MASK)
209 */
210 cbPixels = ((((cWidth + 7) / 8) * cHeight + 3) & ~3)
211 + cWidth * 4 * cHeight;
212 if (cbPixels > cbLength)
213 return VERR_INVALID_PARAMETER;
214 /*
215 * If shape is supplied, then always create the pointer visible.
216 * See comments in 'vboxUpdatePointerShape'
217 */
218 fFlags |= VBOX_MOUSE_POINTER_VISIBLE;
219 }
220 /* Allocate the IO buffer. */
221 p = (VBVAMOUSEPOINTERSHAPE *)VBoxHGSMIBufferAlloc(pCtx, sizeof(*p) + cbPixels, HGSMI_CH_VBVA,
222 VBVA_MOUSE_POINTER_SHAPE);
223 if (!p)
224 return VERR_NO_MEMORY;
225 /* Prepare data to be sent to the host. */
226 /* Will be updated by the host. */
227 p->i32Result = VINF_SUCCESS;
228 /* We have our custom flags in the field */
229 p->fu32Flags = fFlags;
230 p->u32HotX = cHotX;
231 p->u32HotY = cHotY;
232 p->u32Width = cWidth;
233 p->u32Height = cHeight;
234 if (cbPixels)
235 /* Copy the actual pointer data. */
236 memcpy (p->au8Data, pPixels, cbPixels);
237 /* No need to check that the buffer is valid as we have just allocated it. */
238 VBoxHGSMIBufferSubmit(pCtx, p);
239 rc = p->i32Result;
240 /* Free the IO buffer. */
241 VBoxHGSMIBufferFree(pCtx, p);
242 return rc;
243}
244
245
246/**
247 * Report the guest cursor position. The host may wish to use this information
248 * to re-position its own cursor (though this is currently unlikely). The
249 * current host cursor position is returned.
250 * @param pCtx The context containing the heap used.
251 * @param fReportPosition Are we reporting a position?
252 * @param x Guest cursor X position.
253 * @param y Guest cursor Y position.
254 * @param pxHost Host cursor X position is stored here. Optional.
255 * @param pyHost Host cursor Y position is stored here. Optional.
256 * @returns iprt status code.
257 * @returns VERR_NO_MEMORY HGSMI heap allocation failed.
258 */
259DECLHIDDEN(int) VBoxHGSMICursorPosition(PHGSMIGUESTCOMMANDCONTEXT pCtx, bool fReportPosition,
260 uint32_t x, uint32_t y, uint32_t *pxHost, uint32_t *pyHost)
261{
262 VBVACURSORPOSITION *p;
263
264 /* Allocate the IO buffer. */
265 p = (VBVACURSORPOSITION *)VBoxHGSMIBufferAlloc(pCtx, sizeof(*p), HGSMI_CH_VBVA,
266 VBVA_CURSOR_POSITION);
267 if (!p)
268 return VERR_NO_MEMORY;
269 /* Prepare data to be sent to the host. */
270 p->fReportPosition = fReportPosition;
271 p->x = x;
272 p->y = y;
273 /* No need to check that the buffer is valid as we have just allocated it. */
274 VBoxHGSMIBufferSubmit(pCtx, p);
275 if (pxHost)
276 *pxHost = p->x;
277 if (pyHost)
278 *pyHost = p->y;
279 /* Free the IO buffer. */
280 VBoxHGSMIBufferFree(pCtx, p);
281 return VINF_SUCCESS;
282}
283
284
285/**
286 * @todo Mouse pointer position to be read from VMMDev memory, address of the
287 * memory region can be queried from VMMDev via an IOCTL. This VMMDev memory
288 * region will contain host information which is needed by the guest.
289 *
290 * Reading will not cause a switch to the host.
291 *
292 * Have to take into account:
293 * * synchronization: host must write to the memory only from EMT,
294 * large structures must be read under flag, which tells the host
295 * that the guest is currently reading the memory (OWNER flag?).
296 * * guest writes: may be allocate a page for the host info and make
297 * the page readonly for the guest.
298 * * the information should be available only for additions drivers.
299 * * VMMDev additions driver will inform the host which version of the info
300 * it expects, host must support all versions.
301 */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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