1 | /* $Id: VBoxMPCommon.cpp 40566 2012-03-21 14:12:23Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox Miniport common utils
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2011 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "VBoxMPCommon.h"
|
---|
20 | #include <VBox/Hardware/VBoxVideoVBE.h>
|
---|
21 |
|
---|
22 | int VBoxMPCmnMapAdapterMemory(PVBOXMP_COMMON pCommon, void **ppv, uint32_t ulOffset, uint32_t ulSize)
|
---|
23 | {
|
---|
24 | PVBOXMP_DEVEXT pPEXT = VBoxCommonToPrimaryExt(pCommon);
|
---|
25 |
|
---|
26 | LOGF(("0x%08X[0x%X]", ulOffset, ulSize));
|
---|
27 |
|
---|
28 | if (!ulSize)
|
---|
29 | {
|
---|
30 | WARN(("Illegal length 0!"));
|
---|
31 | return ERROR_INVALID_PARAMETER;
|
---|
32 | }
|
---|
33 |
|
---|
34 | PHYSICAL_ADDRESS FrameBuffer;
|
---|
35 | FrameBuffer.QuadPart = VBoxCommonFromDeviceExt(pPEXT)->phVRAM.QuadPart + ulOffset;
|
---|
36 |
|
---|
37 | PVOID VideoRamBase = NULL;
|
---|
38 | ULONG VideoRamLength = ulSize;
|
---|
39 | VP_STATUS Status;
|
---|
40 | #ifndef VBOX_WITH_WDDM
|
---|
41 | ULONG inIoSpace = 0;
|
---|
42 |
|
---|
43 | Status = VideoPortMapMemory(pPEXT, FrameBuffer, &VideoRamLength, &inIoSpace, &VideoRamBase);
|
---|
44 | #else
|
---|
45 | NTSTATUS ntStatus = pPEXT->u.primary.DxgkInterface.DxgkCbMapMemory(pPEXT->u.primary.DxgkInterface.DeviceHandle,
|
---|
46 | FrameBuffer,
|
---|
47 | VideoRamLength,
|
---|
48 | FALSE, /* IN BOOLEAN InIoSpace */
|
---|
49 | FALSE, /* IN BOOLEAN MapToUserMode */
|
---|
50 | MmNonCached, /* IN MEMORY_CACHING_TYPE CacheType */
|
---|
51 | &VideoRamBase /*OUT PVOID *VirtualAddress*/
|
---|
52 | );
|
---|
53 | Assert(ntStatus == STATUS_SUCCESS);
|
---|
54 | /* this is what VideoPortMapMemory returns according to the docs */
|
---|
55 | Status = ntStatus == STATUS_SUCCESS ? NO_ERROR : ERROR_INVALID_PARAMETER;
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | if (Status == NO_ERROR)
|
---|
59 | {
|
---|
60 | *ppv = VideoRamBase;
|
---|
61 | }
|
---|
62 |
|
---|
63 | LOGF(("rc = %d", Status));
|
---|
64 |
|
---|
65 | return (Status==NO_ERROR) ? VINF_SUCCESS:VERR_INVALID_PARAMETER;
|
---|
66 | }
|
---|
67 |
|
---|
68 | void VBoxMPCmnUnmapAdapterMemory(PVBOXMP_COMMON pCommon, void **ppv)
|
---|
69 | {
|
---|
70 | LOGF_ENTER();
|
---|
71 |
|
---|
72 | PVBOXMP_DEVEXT pPEXT = VBoxCommonToPrimaryExt(pCommon);
|
---|
73 |
|
---|
74 | if (*ppv)
|
---|
75 | {
|
---|
76 | #ifndef VBOX_WITH_WDDM
|
---|
77 | VP_STATUS Status;
|
---|
78 | Status = VideoPortUnmapMemory(pPEXT, *ppv, NULL);
|
---|
79 | VBOXMP_WARN_VPS(Status);
|
---|
80 | #else
|
---|
81 | NTSTATUS ntStatus;
|
---|
82 | ntStatus = pPEXT->u.primary.DxgkInterface.DxgkCbUnmapMemory(pPEXT->u.primary.DxgkInterface.DeviceHandle, *ppv);
|
---|
83 | Assert(ntStatus == STATUS_SUCCESS);
|
---|
84 | #endif
|
---|
85 | }
|
---|
86 |
|
---|
87 | *ppv = NULL;
|
---|
88 |
|
---|
89 | LOGF_LEAVE();
|
---|
90 | }
|
---|
91 |
|
---|
92 | bool VBoxMPCmnSyncToVideoIRQ(PVBOXMP_COMMON pCommon, PFNVIDEOIRQSYNC pfnSync, void *pvUser)
|
---|
93 | {
|
---|
94 | PVBOXMP_DEVEXT pPEXT = VBoxCommonToPrimaryExt(pCommon);
|
---|
95 | PMINIPORT_SYNCHRONIZE_ROUTINE pfnSyncMiniport = (PMINIPORT_SYNCHRONIZE_ROUTINE) pfnSync;
|
---|
96 |
|
---|
97 | #ifndef VBOX_WITH_WDDM
|
---|
98 | return !!VideoPortSynchronizeExecution(pPEXT, VpMediumPriority, pfnSyncMiniport, pvUser);
|
---|
99 | #else
|
---|
100 | BOOLEAN fRet;
|
---|
101 | DXGKCB_SYNCHRONIZE_EXECUTION pfnDxgkCbSync = pPEXT->u.primary.DxgkInterface.DxgkCbSynchronizeExecution;
|
---|
102 | HANDLE hDev = pPEXT->u.primary.DxgkInterface.DeviceHandle;
|
---|
103 | NTSTATUS ntStatus = pfnDxgkCbSync(hDev, pfnSyncMiniport, pvUser, 0, &fRet);
|
---|
104 | AssertReturn(ntStatus == STATUS_SUCCESS, false);
|
---|
105 | return !!fRet;
|
---|
106 | #endif
|
---|
107 | }
|
---|