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