VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/common/VBoxMPCommon.cpp@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* $Id: VBoxMPCommon.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * VBox Miniport common utils
4 */
5
6/*
7 * Copyright (C) 2011-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#include "VBoxMPCommon.h"
29#include <VBoxVideoVBE.h>
30
31int VBoxMPCmnMapAdapterMemory(PVBOXMP_COMMON pCommon, void **ppv, uint32_t ulOffset, uint32_t ulSize)
32{
33 PVBOXMP_DEVEXT pPEXT = VBoxCommonToPrimaryExt(pCommon);
34
35 LOGF(("0x%08X[0x%X]", ulOffset, ulSize));
36
37 if (!ulSize)
38 {
39 WARN(("Illegal length 0!"));
40 return ERROR_INVALID_PARAMETER;
41 }
42
43 PHYSICAL_ADDRESS FrameBuffer;
44 FrameBuffer.QuadPart = VBoxCommonFromDeviceExt(pPEXT)->phVRAM.QuadPart + ulOffset;
45
46 PVOID VideoRamBase = NULL;
47 ULONG VideoRamLength = ulSize;
48 VP_STATUS Status;
49#ifndef VBOX_WITH_WDDM
50 ULONG inIoSpace = 0;
51
52 Status = VideoPortMapMemory(pPEXT, FrameBuffer, &VideoRamLength, &inIoSpace, &VideoRamBase);
53#else
54 NTSTATUS ntStatus = pPEXT->u.primary.DxgkInterface.DxgkCbMapMemory(pPEXT->u.primary.DxgkInterface.DeviceHandle,
55 FrameBuffer,
56 VideoRamLength,
57 FALSE, /* IN BOOLEAN InIoSpace */
58 FALSE, /* IN BOOLEAN MapToUserMode */
59 MmNonCached, /* IN MEMORY_CACHING_TYPE CacheType */
60 &VideoRamBase /*OUT PVOID *VirtualAddress*/
61 );
62 Assert(ntStatus == STATUS_SUCCESS);
63 /* this is what VideoPortMapMemory returns according to the docs */
64 Status = ntStatus == STATUS_SUCCESS ? NO_ERROR : ERROR_INVALID_PARAMETER;
65#endif
66
67 if (Status == NO_ERROR)
68 {
69 *ppv = VideoRamBase;
70 }
71
72 LOGF(("rc = %d", Status));
73
74 return (Status==NO_ERROR) ? VINF_SUCCESS:VERR_INVALID_PARAMETER;
75}
76
77void VBoxMPCmnUnmapAdapterMemory(PVBOXMP_COMMON pCommon, void **ppv)
78{
79 LOGF_ENTER();
80
81 PVBOXMP_DEVEXT pPEXT = VBoxCommonToPrimaryExt(pCommon);
82
83 if (*ppv)
84 {
85#ifndef VBOX_WITH_WDDM
86 VP_STATUS Status;
87 Status = VideoPortUnmapMemory(pPEXT, *ppv, NULL);
88 VBOXMP_WARN_VPS(Status);
89#else
90 NTSTATUS ntStatus;
91 ntStatus = pPEXT->u.primary.DxgkInterface.DxgkCbUnmapMemory(pPEXT->u.primary.DxgkInterface.DeviceHandle, *ppv);
92 Assert(ntStatus == STATUS_SUCCESS);
93#endif
94 }
95
96 *ppv = NULL;
97
98 LOGF_LEAVE();
99}
100
101bool VBoxMPCmnSyncToVideoIRQ(PVBOXMP_COMMON pCommon, PFNVIDEOIRQSYNC pfnSync, void *pvUser)
102{
103 PVBOXMP_DEVEXT pPEXT = VBoxCommonToPrimaryExt(pCommon);
104 PMINIPORT_SYNCHRONIZE_ROUTINE pfnSyncMiniport = (PMINIPORT_SYNCHRONIZE_ROUTINE) pfnSync;
105
106#ifndef VBOX_WITH_WDDM
107 return !!VideoPortSynchronizeExecution(pPEXT, VpMediumPriority, pfnSyncMiniport, pvUser);
108#else
109 BOOLEAN fRet;
110 DXGKCB_SYNCHRONIZE_EXECUTION pfnDxgkCbSync = pPEXT->u.primary.DxgkInterface.DxgkCbSynchronizeExecution;
111 HANDLE hDev = pPEXT->u.primary.DxgkInterface.DeviceHandle;
112 NTSTATUS ntStatus = pfnDxgkCbSync(hDev, pfnSyncMiniport, pvUser, 0, &fRet);
113 AssertReturn(ntStatus == STATUS_SUCCESS, false);
114 return !!fRet;
115#endif
116}
117
118bool VBoxMPCmnUpdatePointerShape(PVBOXMP_COMMON pCommon, PVIDEO_POINTER_ATTRIBUTES pAttrs, uint32_t cbLength)
119{
120 const uint32_t fFlags = pAttrs->Enable & 0x0000FFFF;
121 const uint32_t cHotX = (pAttrs->Enable >> 16) & 0xFF;
122 const uint32_t cHotY = (pAttrs->Enable >> 24) & 0xFF;
123 const uint32_t cWidth = pAttrs->Width;
124 const uint32_t cHeight = pAttrs->Height;
125 uint8_t *pPixels = &pAttrs->Pixels[0];
126
127 int rc = VBoxHGSMIUpdatePointerShape(&pCommon->guestCtx,
128 fFlags, cHotX, cHotY,
129 cWidth, cHeight, pPixels,
130 cbLength - sizeof(VIDEO_POINTER_ATTRIBUTES));
131 return RT_SUCCESS(rc);
132}
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