VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxGuest/Helper.cpp@ 3539

Last change on this file since 3539 was 2981, checked in by vboxsync, 17 years ago

InnoTek -> innotek: all the headers and comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 KB
Line 
1/** @file
2 *
3 * VBoxGuest -- VirtualBox Win32 guest support driver
4 *
5 * Copyright (C) 2006-2007 innotek GmbH
6 *
7 * This file is part of VirtualBox Open Source Edition (OSE), as
8 * available from http://www.virtualbox.org. This file is free software;
9 * you can redistribute it and/or modify it under the terms of the GNU
10 * General Public License as published by the Free Software Foundation,
11 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
12 * distribution. VirtualBox OSE is distributed in the hope that it will
13 * be useful, but WITHOUT ANY WARRANTY of any kind.
14 *
15 * If you received this file as part of a commercial VirtualBox
16 * distribution, then only the terms of your commercial VirtualBox
17 * license agreement apply instead of the previous paragraph.
18 *
19 */
20
21//#define LOG_ENABLED
22
23#include "VBoxGuest_Internal.h"
24#include "Helper.h"
25#include <VBox/err.h>
26#include <VBox/VBoxGuestLib.h>
27
28#ifdef ALLOC_PRAGMA
29#pragma alloc_text (PAGE, VBoxScanPCIResourceList)
30#endif
31
32/* CM_RESOURCE_MEMORY_* flags which were used on XP or earlier. */
33#define VBOX_CM_PRE_VISTA_MASK (0x3f)
34
35/**
36 * Helper to scan the PCI resource list and remember stuff.
37 *
38 * @param pResList Resource list
39 * @param pDevExt Device extension
40 */
41NTSTATUS VBoxScanPCIResourceList(PCM_RESOURCE_LIST pResList, PVBOXGUESTDEVEXT pDevExt)
42{
43 NTSTATUS rc = STATUS_SUCCESS;
44 PCM_PARTIAL_RESOURCE_DESCRIPTOR partialData;
45
46 // enumerate the resource list
47 dprintf(("found %d resources\n", pResList->List->PartialResourceList.Count));
48 ULONG rangeCount = 0;
49 PBASE_ADDRESS baseAddress = pDevExt->baseAddress;
50 for (ULONG i = 0; i < pResList->List->PartialResourceList.Count; i++)
51 {
52 partialData = &pResList->List->PartialResourceList.PartialDescriptors[i];
53 switch (partialData->Type)
54 {
55 case CmResourceTypePort:
56 {
57 // overflow protection
58 if (rangeCount < PCI_TYPE0_ADDRESSES)
59 {
60 dprintf(("I/O range: Base = %08x : %08x Length = %08x \n",
61 partialData->u.Port.Start.HighPart,
62 partialData->u.Port.Start.LowPart,
63 partialData->u.Port.Length));
64 //@todo not so gut
65 dprintf(("I got all I want, my dear port, oh!\n"));
66 pDevExt->startPortAddress = (ULONG)partialData->u.Port.Start.LowPart;
67 // save resource information
68 baseAddress->RangeStart = partialData->u.Port.Start;
69 baseAddress->RangeLength = partialData->u.Port.Length;
70 baseAddress->RangeInMemory = FALSE;
71 baseAddress->ResourceMapped = FALSE;
72 // next item
73 rangeCount++; baseAddress++;
74 }
75 break;
76 }
77
78 case CmResourceTypeInterrupt:
79 {
80 dprintf(("Interrupt: Level = %x Vector = %x Mode = %x \n",
81 partialData->u.Interrupt.Level,
82 partialData->u.Interrupt.Vector,
83 partialData->Flags));
84 // save information
85 pDevExt->interruptLevel = partialData->u.Interrupt.Level;
86 pDevExt->interruptVector = partialData->u.Interrupt.Vector;
87 pDevExt->interruptAffinity = partialData->u.Interrupt.Affinity;
88 // check interrupt mode
89 if (partialData->Flags & CM_RESOURCE_INTERRUPT_LATCHED)
90 {
91 pDevExt->interruptMode = Latched;
92 }
93 else
94 {
95 pDevExt->interruptMode = LevelSensitive;
96 }
97 break;
98 }
99
100 case CmResourceTypeMemory:
101 {
102 // overflow protection
103 if (rangeCount < PCI_TYPE0_ADDRESSES)
104 {
105 dprintf(("Memory range: Base = %08x : %08x Length = %08x \n",
106 partialData->u.Memory.Start.HighPart,
107 partialData->u.Memory.Start.LowPart,
108 partialData->u.Memory.Length));
109 // we only care about read/write memory
110 /** @todo reconsider memory type */
111 if ((partialData->Flags & VBOX_CM_PRE_VISTA_MASK) == CM_RESOURCE_MEMORY_READ_WRITE)
112 {
113 pDevExt->memoryAddress = partialData->u.Memory.Start;
114 pDevExt->memoryLength = (ULONG)partialData->u.Memory.Length;
115 // save resource information
116 baseAddress->RangeStart = partialData->u.Memory.Start;
117 baseAddress->RangeLength = partialData->u.Memory.Length;
118 baseAddress->RangeInMemory = TRUE;
119 baseAddress->ResourceMapped = FALSE;
120 // next item
121 rangeCount++; baseAddress++;
122 } else
123 {
124 dprintf(("Ignoring memory: flags = %08x \n", partialData->Flags));
125 }
126 }
127 break;
128 }
129
130 case CmResourceTypeDma:
131 {
132 dprintf(("DMA resource found. Hmm...\n"));
133 break;
134 }
135
136 default:
137 {
138 dprintf(("Unexpected resource found %d. Hmm...\n", partialData->Type));
139 break;
140 }
141 }
142 }
143 // memorize the number of resources found
144 pDevExt->addressCount = rangeCount;
145
146 return rc;
147}
148
149
150NTSTATUS hlpVBoxMapVMMDevMemory (PVBOXGUESTDEVEXT pDevExt)
151{
152 NTSTATUS rc = STATUS_SUCCESS;
153
154 if (pDevExt->memoryLength != 0)
155 {
156 pDevExt->pVMMDevMemory = (VMMDevMemory *)MmMapIoSpace (pDevExt->memoryAddress, pDevExt->memoryLength, MmNonCached);
157 dprintf(("VBoxGuest::VBoxGuestPnp: VMMDevMemory: ptr = 0x%x\n", pDevExt->pVMMDevMemory));
158 if (pDevExt->pVMMDevMemory)
159 {
160 dprintf(("VBoxGuest::VBoxGuestPnp: VMMDevMemory: version = 0x%x, size = %d\n", pDevExt->pVMMDevMemory->u32Version, pDevExt->pVMMDevMemory->u32Size));
161
162 /* Check version of the structure */
163 if (pDevExt->pVMMDevMemory->u32Version != VMMDEV_MEMORY_VERSION)
164 {
165 /* Not our version, refuse operation and unmap the memory */
166 hlpVBoxUnmapVMMDevMemory (pDevExt);
167
168 rc = STATUS_UNSUCCESSFUL;
169 }
170 }
171 else
172 {
173 rc = STATUS_UNSUCCESSFUL;
174 }
175 }
176
177 return rc;
178}
179
180void hlpVBoxUnmapVMMDevMemory (PVBOXGUESTDEVEXT pDevExt)
181{
182 if (pDevExt->pVMMDevMemory)
183 {
184 MmUnmapIoSpace (pDevExt->pVMMDevMemory, pDevExt->memoryLength);
185 pDevExt->pVMMDevMemory = NULL;
186 }
187
188 pDevExt->memoryAddress.QuadPart = 0;
189 pDevExt->memoryLength = 0;
190}
191
192NTSTATUS hlpVBoxReportGuestInfo (PVBOXGUESTDEVEXT pDevExt)
193{
194 VMMDevReportGuestInfo *req = NULL;
195
196 int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReportGuestInfo), VMMDevReq_ReportGuestInfo);
197
198 dprintf(("hlpVBoxReportGuestInfo: VbglGRAlloc rc = %d\n", rc));
199
200 if (VBOX_SUCCESS(rc))
201 {
202 req->guestInfo.additionsVersion = VMMDEV_VERSION;
203
204 /* we've already determined the Windows product before */
205 switch (winVersion)
206 {
207 case WINNT4:
208 req->guestInfo.osType = OSTypeWinNT4;
209 break;
210 case WIN2K:
211 req->guestInfo.osType = OSTypeWin2k;
212 break;
213 case WINXP:
214 req->guestInfo.osType = OSTypeWinXP;
215 break;
216 case WIN2K3:
217 req->guestInfo.osType = OSTypeWin2k3;
218 break;
219 case WINVISTA:
220 req->guestInfo.osType = OSTypeWinVista;
221 break;
222 default:
223 /* we don't know, therefore NT family */
224 req->guestInfo.osType = OSTypeWinNT;
225 break;
226 }
227
228 /** @todo registry lookup for additional information */
229
230
231 rc = VbglGRPerform (&req->header);
232
233 if (VBOX_FAILURE(rc) || VBOX_FAILURE(req->header.rc))
234 {
235 dprintf(("VBoxGuest::hlpVBoxReportGuestInfo: error reporting guest info to VMMDev."
236 "rc = %d, VMMDev rc = %Vrc\n", rc, req->header.rc));
237 }
238
239 rc = VBOX_SUCCESS(rc) ? req->header.rc : rc;
240
241 VbglGRFree (&req->header);
242 }
243
244 return VBOX_FAILURE(rc) ? STATUS_UNSUCCESSFUL : STATUS_SUCCESS;
245}
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