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