1 | /* $Id: HGSMIBuffers.cpp 67145 2017-05-30 15:11:29Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Video driver, common code - HGSMI buffer management.
|
---|
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 |
|
---|
32 | /**
|
---|
33 | * Set up the HGSMI guest-to-host command context.
|
---|
34 | * @returns iprt status value
|
---|
35 | * @param pCtx the context to set up
|
---|
36 | * @param pvGuestHeapMemory a pointer to the mapped backing memory for
|
---|
37 | * the guest heap
|
---|
38 | * @param cbGuestHeapMemory the size of the backing memory area
|
---|
39 | * @param offVRAMGuestHeapMemory the offset of the memory pointed to by
|
---|
40 | * @a pvGuestHeapMemory within the video RAM
|
---|
41 | * @param pEnv HGSMI environment.
|
---|
42 | */
|
---|
43 | DECLHIDDEN(int) VBoxHGSMISetupGuestContext(PHGSMIGUESTCOMMANDCONTEXT pCtx,
|
---|
44 | void *pvGuestHeapMemory,
|
---|
45 | uint32_t cbGuestHeapMemory,
|
---|
46 | uint32_t offVRAMGuestHeapMemory,
|
---|
47 | const HGSMIENV *pEnv)
|
---|
48 | {
|
---|
49 | /** @todo should we be using a fixed ISA port value here? */
|
---|
50 | pCtx->port = (RTIOPORT)VGA_PORT_HGSMI_GUEST;
|
---|
51 | #ifdef VBOX_WDDM_MINIPORT
|
---|
52 | return VBoxSHGSMIInit(&pCtx->heapCtx, pvGuestHeapMemory,
|
---|
53 | cbGuestHeapMemory, offVRAMGuestHeapMemory, pEnv);
|
---|
54 | #else
|
---|
55 | return HGSMIHeapSetup(&pCtx->heapCtx, pvGuestHeapMemory,
|
---|
56 | cbGuestHeapMemory, offVRAMGuestHeapMemory, pEnv);
|
---|
57 | #endif
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Allocate and initialise a command descriptor in the guest heap for a
|
---|
63 | * guest-to-host command.
|
---|
64 | *
|
---|
65 | * @returns pointer to the descriptor's command data buffer
|
---|
66 | * @param pCtx the context containing the heap to be used
|
---|
67 | * @param cbData the size of the command data to go into the descriptor
|
---|
68 | * @param u8Ch the HGSMI channel to be used, set to the descriptor
|
---|
69 | * @param u16Op the HGSMI command to be sent, set to the descriptor
|
---|
70 | */
|
---|
71 | DECLHIDDEN(void *) VBoxHGSMIBufferAlloc(PHGSMIGUESTCOMMANDCONTEXT pCtx,
|
---|
72 | HGSMISIZE cbData,
|
---|
73 | uint8_t u8Ch,
|
---|
74 | uint16_t u16Op)
|
---|
75 | {
|
---|
76 | #ifdef VBOX_WDDM_MINIPORT
|
---|
77 | return VBoxSHGSMIHeapAlloc (&pCtx->heapCtx, cbData, u8Ch, u16Op);
|
---|
78 | #else
|
---|
79 | return HGSMIHeapAlloc (&pCtx->heapCtx, cbData, u8Ch, u16Op);
|
---|
80 | #endif
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Free a descriptor allocated by @a VBoxHGSMIBufferAlloc.
|
---|
86 | *
|
---|
87 | * @param pCtx the context containing the heap used
|
---|
88 | * @param pvBuffer the pointer returned by @a VBoxHGSMIBufferAlloc
|
---|
89 | */
|
---|
90 | DECLHIDDEN(void) VBoxHGSMIBufferFree(PHGSMIGUESTCOMMANDCONTEXT pCtx,
|
---|
91 | void *pvBuffer)
|
---|
92 | {
|
---|
93 | #ifdef VBOX_WDDM_MINIPORT
|
---|
94 | VBoxSHGSMIHeapFree (&pCtx->heapCtx, pvBuffer);
|
---|
95 | #else
|
---|
96 | HGSMIHeapFree (&pCtx->heapCtx, pvBuffer);
|
---|
97 | #endif
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Submit a command descriptor allocated by @a VBoxHGSMIBufferAlloc.
|
---|
102 | *
|
---|
103 | * @param pCtx the context containing the heap used
|
---|
104 | * @param pvBuffer the pointer returned by @a VBoxHGSMIBufferAlloc
|
---|
105 | */
|
---|
106 | DECLHIDDEN(int) VBoxHGSMIBufferSubmit(PHGSMIGUESTCOMMANDCONTEXT pCtx,
|
---|
107 | void *pvBuffer)
|
---|
108 | {
|
---|
109 | /* Initialize the buffer and get the offset for port IO. */
|
---|
110 | HGSMIOFFSET offBuffer = HGSMIHeapBufferOffset (HGSMIGUESTCMDHEAP_GET(&pCtx->heapCtx), pvBuffer);
|
---|
111 |
|
---|
112 | Assert(offBuffer != HGSMIOFFSET_VOID);
|
---|
113 | if (offBuffer != HGSMIOFFSET_VOID)
|
---|
114 | {
|
---|
115 | /* Submit the buffer to the host. */
|
---|
116 | VBVO_PORT_WRITE_U32(pCtx->port, offBuffer);
|
---|
117 | /* Make the compiler aware that the host has changed memory. */
|
---|
118 | ASMCompilerBarrier();
|
---|
119 | return VINF_SUCCESS;
|
---|
120 | }
|
---|
121 |
|
---|
122 | return VERR_INVALID_PARAMETER;
|
---|
123 | }
|
---|