VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxVideo/HGSMIHostCmd.cpp@ 68822

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

bugref:8524: Additions/linux: play nicely with distribution-installed Additions
Re-arrange the file structure of the guest graphics APIs to make it easier to only include the necessary parts in the Linux vboxvideo driver.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 9.1 KB
 
1/* $Id: HGSMIHostCmd.cpp 67066 2017-05-24 13:37:42Z vboxsync $ */
2/** @file
3 * VirtualBox Video driver, common code - HGSMI host-to-guest communication.
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#include <VBoxVideoGuest.h>
29#include <VBoxVideoVBE.h>
30#include <VBoxVideoIPRT.h>
31#include <HGSMIHostCmd.h>
32
33/**
34 * Initialise the host context structure.
35 *
36 * @param pCtx the context structure to initialise
37 * @param pvBaseMapping where the basic HGSMI structures are mapped at
38 * @param offHostFlags the offset of the host flags into the basic HGSMI
39 * structures
40 * @param pvHostAreaMapping where the area for the host heap is mapped at
41 * @param offVRAMHostArea offset of the host heap area into VRAM
42 * @param cbHostArea size in bytes of the host heap area
43 */
44DECLHIDDEN(void) VBoxHGSMISetupHostContext(PHGSMIHOSTCOMMANDCONTEXT pCtx,
45 void *pvBaseMapping,
46 uint32_t offHostFlags,
47 void *pvHostAreaMapping,
48 uint32_t offVRAMHostArea,
49 uint32_t cbHostArea)
50{
51 uint8_t *pu8HostFlags = ((uint8_t *)pvBaseMapping) + offHostFlags;
52 pCtx->pfHostFlags = (HGSMIHOSTFLAGS *)pu8HostFlags;
53 /** @todo should we really be using a fixed ISA port value here? */
54 pCtx->port = (RTIOPORT)VGA_PORT_HGSMI_HOST;
55 HGSMIAreaInitialize(&pCtx->areaCtx, pvHostAreaMapping, cbHostArea,
56 offVRAMHostArea);
57}
58
59
60/** Send completion notification to the host for the command located at offset
61 * @a offt into the host command buffer. */
62static void HGSMINotifyHostCmdComplete(PHGSMIHOSTCOMMANDCONTEXT pCtx, HGSMIOFFSET offt)
63{
64 VBVO_PORT_WRITE_U32(pCtx->port, offt);
65}
66
67
68/**
69 * Inform the host that a command has been handled.
70 *
71 * @param pCtx the context containing the heap to be used
72 * @param pvMem pointer into the heap as mapped in @a pCtx to the command to
73 * be completed
74 */
75DECLHIDDEN(void) VBoxHGSMIHostCmdComplete(PHGSMIHOSTCOMMANDCONTEXT pCtx,
76 void *pvMem)
77{
78 HGSMIBUFFERHEADER *pHdr = HGSMIBufferHeaderFromData(pvMem);
79 HGSMIOFFSET offMem = HGSMIPointerToOffset(&pCtx->areaCtx, pHdr);
80 Assert(offMem != HGSMIOFFSET_VOID);
81 if(offMem != HGSMIOFFSET_VOID)
82 {
83 HGSMINotifyHostCmdComplete(pCtx, offMem);
84 }
85}
86
87
88/** Submit an incoming host command to the appropriate handler. */
89static void hgsmiHostCmdProcess(PHGSMIHOSTCOMMANDCONTEXT pCtx,
90 HGSMIOFFSET offBuffer)
91{
92 int rc = HGSMIBufferProcess(&pCtx->areaCtx, &pCtx->channels, offBuffer);
93 Assert(!RT_FAILURE(rc));
94 if(RT_FAILURE(rc))
95 {
96 /* failure means the command was not submitted to the handler for some reason
97 * it's our responsibility to notify its completion in this case */
98 HGSMINotifyHostCmdComplete(pCtx, offBuffer);
99 }
100 /* if the cmd succeeded it's responsibility of the callback to complete it */
101}
102
103/** Get the next command from the host. */
104static HGSMIOFFSET hgsmiGetHostBuffer(PHGSMIHOSTCOMMANDCONTEXT pCtx)
105{
106 return VBVO_PORT_READ_U32(pCtx->port);
107}
108
109
110/** Get and handle the next command from the host. */
111static void hgsmiHostCommandQueryProcess(PHGSMIHOSTCOMMANDCONTEXT pCtx)
112{
113 HGSMIOFFSET offset = hgsmiGetHostBuffer(pCtx);
114 AssertReturnVoid(offset != HGSMIOFFSET_VOID);
115 hgsmiHostCmdProcess(pCtx, offset);
116}
117
118
119/** Drain the host command queue. */
120DECLHIDDEN(void) VBoxHGSMIProcessHostQueue(PHGSMIHOSTCOMMANDCONTEXT pCtx)
121{
122 while (pCtx->pfHostFlags->u32HostFlags & HGSMIHOSTFLAGS_COMMANDS_PENDING)
123 {
124 if (!ASMAtomicCmpXchgBool(&pCtx->fHostCmdProcessing, true, false))
125 return;
126 hgsmiHostCommandQueryProcess(pCtx);
127 ASMAtomicWriteBool(&pCtx->fHostCmdProcessing, false);
128 }
129}
130
131
132/** Tell the host about the location of the area of VRAM set aside for the host
133 * heap. */
134static int vboxHGSMIReportHostArea(PHGSMIGUESTCOMMANDCONTEXT pCtx,
135 uint32_t u32AreaOffset, uint32_t u32AreaSize)
136{
137 VBVAINFOHEAP *p;
138 int rc = VINF_SUCCESS;
139
140 /* Allocate the IO buffer. */
141 p = (VBVAINFOHEAP *)VBoxHGSMIBufferAlloc(pCtx,
142 sizeof (VBVAINFOHEAP), HGSMI_CH_VBVA,
143 VBVA_INFO_HEAP);
144 if (p)
145 {
146 /* Prepare data to be sent to the host. */
147 p->u32HeapOffset = u32AreaOffset;
148 p->u32HeapSize = u32AreaSize;
149 rc = VBoxHGSMIBufferSubmit(pCtx, p);
150 /* Free the IO buffer. */
151 VBoxHGSMIBufferFree(pCtx, p);
152 }
153 else
154 rc = VERR_NO_MEMORY;
155 return rc;
156}
157
158
159/**
160 * Get the information needed to map the area used by the host to send back
161 * requests.
162 *
163 * @param pCtx the context containing the heap to use
164 * @param cbVRAM how much video RAM is allocated to the device
165 * @param offVRAMBaseMapping the offset of the basic communication structures
166 * into the guest's VRAM
167 * @param poffVRAMHostArea where to store the offset into VRAM of the host
168 * heap area
169 * @param pcbHostArea where to store the size of the host heap area
170 */
171DECLHIDDEN(void) VBoxHGSMIGetHostAreaMapping(PHGSMIGUESTCOMMANDCONTEXT pCtx,
172 uint32_t cbVRAM,
173 uint32_t offVRAMBaseMapping,
174 uint32_t *poffVRAMHostArea,
175 uint32_t *pcbHostArea)
176{
177 uint32_t offVRAMHostArea = offVRAMBaseMapping, cbHostArea = 0;
178
179 AssertPtrReturnVoid(poffVRAMHostArea);
180 AssertPtrReturnVoid(pcbHostArea);
181 VBoxQueryConfHGSMI(pCtx, VBOX_VBVA_CONF32_HOST_HEAP_SIZE, &cbHostArea);
182 if (cbHostArea != 0)
183 {
184 uint32_t cbHostAreaMaxSize = cbVRAM / 4;
185 /** @todo what is the idea of this? */
186 if (cbHostAreaMaxSize >= VBVA_ADAPTER_INFORMATION_SIZE)
187 {
188 cbHostAreaMaxSize -= VBVA_ADAPTER_INFORMATION_SIZE;
189 }
190 if (cbHostArea > cbHostAreaMaxSize)
191 {
192 cbHostArea = cbHostAreaMaxSize;
193 }
194 /* Round up to 4096 bytes. */
195 cbHostArea = (cbHostArea + 0xFFF) & ~0xFFF;
196 offVRAMHostArea = offVRAMBaseMapping - cbHostArea;
197 }
198
199 *pcbHostArea = cbHostArea;
200 *poffVRAMHostArea = offVRAMHostArea;
201 // LogFunc(("offVRAMHostArea = 0x%08X, cbHostArea = 0x%08X\n",
202 // offVRAMHostArea, cbHostArea));
203}
204
205
206/**
207 * Tell the host about the ways it can use to communicate back to us via an
208 * HGSMI command
209 *
210 * @returns iprt status value
211 * @param pCtx the context containing the heap to use
212 * @param offVRAMFlagsLocation where we wish the host to place its flags
213 * relative to the start of the VRAM
214 * @param fCaps additions HGSMI capabilities the guest
215 * supports
216 * @param offVRAMHostArea offset into VRAM of the host heap area
217 * @param cbHostArea size in bytes of the host heap area
218 */
219DECLHIDDEN(int) VBoxHGSMISendHostCtxInfo(PHGSMIGUESTCOMMANDCONTEXT pCtx,
220 HGSMIOFFSET offVRAMFlagsLocation,
221 uint32_t fCaps,
222 uint32_t offVRAMHostArea,
223 uint32_t cbHostArea)
224{
225 // Log(("VBoxVideo::vboxSetupAdapterInfo\n"));
226
227 /* setup the flags first to ensure they are initialized by the time the
228 * host heap is ready */
229 int rc = VBoxHGSMIReportFlagsLocation(pCtx, offVRAMFlagsLocation);
230 AssertRC(rc);
231 if (RT_SUCCESS(rc) && fCaps)
232 {
233 /* Inform about caps */
234 rc = VBoxHGSMISendCapsInfo(pCtx, fCaps);
235 AssertRC(rc);
236 }
237 if (RT_SUCCESS (rc))
238 {
239 /* Report the host heap location. */
240 rc = vboxHGSMIReportHostArea(pCtx, offVRAMHostArea, cbHostArea);
241 AssertRC(rc);
242 }
243 // Log(("VBoxVideo::vboxSetupAdapterInfo finished rc = %d\n", rc));
244 return rc;
245}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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