Index: /trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.cpp	(revision 70226)
+++ /trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.cpp	(revision 70227)
@@ -203,5 +203,5 @@
 static VOID     vgdrvNtDpcHandler(PKDPC pDPC, PDEVICE_OBJECT pDevObj, PIRP pIrp, PVOID pContext);
 static BOOLEAN  vgdrvNtIsrHandler(PKINTERRUPT interrupt, PVOID serviceContext);
-static NTSTATUS vgdrvNtScanPCIResourceList(PCM_RESOURCE_LIST pResList, PVBOXGUESTDEVEXTWIN pDevExt);
+static NTSTATUS vgdrvNtScanPCIResourceList(PVBOXGUESTDEVEXTWIN pDevExt, PCM_RESOURCE_LIST pResList, bool fTranslated);
 static NTSTATUS vgdrvNtMapVMMDevMemory(PVBOXGUESTDEVEXTWIN pDevExt, PHYSICAL_ADDRESS PhysAddr, ULONG cbToMap,
                                        void **ppvMMIOBase, uint32_t *pcbMMIO);
@@ -545,5 +545,5 @@
         if (NT_SUCCESS(rcNt))
         {
-            rcNt = vgdrvNtScanPCIResourceList(pResourceList, pDevExt);
+            rcNt = vgdrvNtScanPCIResourceList(pDevExt, pResourceList, false /*fTranslated*/);
             ExFreePool(pResourceList);
         }
@@ -564,5 +564,6 @@
         vgdrvNtShowDeviceResources(pStack->Parameters.StartDevice.AllocatedResources);
 # endif
-        rcNt = vgdrvNtScanPCIResourceList(pStack->Parameters.StartDevice.AllocatedResourcesTranslated, pDevExt);
+        rcNt = vgdrvNtScanPCIResourceList(pDevExt, pStack->Parameters.StartDevice.AllocatedResourcesTranslated,
+                                          true /*fTranslated*/);
     }
     if (NT_SUCCESS(rcNt))
@@ -2214,8 +2215,9 @@
  * Helper to scan the PCI resource list and remember stuff.
  *
- * @param pResList  Resource list
- * @param pDevExt   Device extension
- */
-static NTSTATUS vgdrvNtScanPCIResourceList(PCM_RESOURCE_LIST pResList, PVBOXGUESTDEVEXTWIN pDevExt)
+ * @param   pDevExt         The device extension.
+ * @param   pResList        Resource list
+ * @param   fTranslated     Whether the addresses are translated or not.
+ */
+static NTSTATUS vgdrvNtScanPCIResourceList(PVBOXGUESTDEVEXTWIN pDevExt, PCM_RESOURCE_LIST pResList, bool fTranslated)
 {
     /* Enumerate the resource list. */
@@ -2225,7 +2227,9 @@
     NTSTATUS rc = STATUS_SUCCESS;
     PCM_PARTIAL_RESOURCE_DESCRIPTOR pPartialData = NULL;
-    ULONG rangeCount = 0;
-    ULONG cMMIORange = 0;
-    PVBOXGUESTWINBASEADDRESS pBaseAddress = pDevExt->aPciBaseAddresses;
+    PVBOXGUESTWINBASEADDRESS pBaseAddress   = pDevExt->aPciBaseAddresses;
+    uint32_t                 cBaseAddresses = 0;
+    bool                     fGotIrq        = false;
+    bool                     fGotMmio       = false;
+    bool                     fGotIoPorts    = false;
     for (ULONG i = 0; i < pResList->List->PartialResourceList.Count; i++)
     {
@@ -2235,16 +2239,18 @@
             case CmResourceTypePort:
             {
+                LogFlowFunc(("I/O range: Base=%#RX64, length=%08x\n",
+                             pPartialData->u.Port.Start.QuadPart, pPartialData->u.Port.Length));
+
                 /* Overflow protection. */
-                if (rangeCount < PCI_TYPE0_ADDRESSES)
+                if (cBaseAddresses < PCI_TYPE0_ADDRESSES)
                 {
-                    LogFlowFunc(("I/O range: Base=%08x:%08x, length=%08x\n",
-                                 pPartialData->u.Port.Start.HighPart,
-                                 pPartialData->u.Port.Start.LowPart,
-                                 pPartialData->u.Port.Length));
-
-                    /* Save the IO port base. */
-                    /** @todo Not so good.
-                     * Update/bird: What is not so good? That we just consider the last range?  */
-                    pDevExt->Core.IOPortBase = (RTIOPORT)pPartialData->u.Port.Start.LowPart;
+                    /* Save the first I/O port base. */
+                    if (!fGotIoPorts)
+                    {
+                        pDevExt->Core.IOPortBase = (RTIOPORT)pPartialData->u.Port.Start.LowPart;
+                        fGotIoPorts = true;
+                    }
+                    else
+                        LogRelFunc(("More than one I/O port range?!?\n"));
 
                     /* Save resource information. */
@@ -2254,12 +2260,13 @@
                     pBaseAddress->ResourceMapped = FALSE;
 
-                    LogFunc(("I/O range for VMMDev found! Base=%08x:%08x, length=%08x\n",
-                             pPartialData->u.Port.Start.HighPart,
-                             pPartialData->u.Port.Start.LowPart,
-                             pPartialData->u.Port.Length));
+                    LogFunc(("I/O range for VMMDev found! Base=%#RX64, length=%08x\n",
+                             pPartialData->u.Port.Start.QuadPart, pPartialData->u.Port.Length));
 
                     /* Next item ... */
-                    rangeCount++; pBaseAddress++;
+                    pBaseAddress++;
+                    cBaseAddresses++;
                 }
+                else
+                    LogFunc(("Too many PCI addresses!\n"));
                 break;
             }
@@ -2268,18 +2275,22 @@
             {
                 LogFunc(("Interrupt: Level=%x, vector=%x, mode=%x\n",
-                         pPartialData->u.Interrupt.Level,
-                         pPartialData->u.Interrupt.Vector,
-                         pPartialData->Flags));
-
-                /* Save information. */
-                pDevExt->uInterruptLevel    = pPartialData->u.Interrupt.Level;
-                pDevExt->uInterruptVector   = pPartialData->u.Interrupt.Vector;
-                pDevExt->fInterruptAffinity = pPartialData->u.Interrupt.Affinity;
-
-                /* Check interrupt mode. */
-                if (pPartialData->Flags & CM_RESOURCE_INTERRUPT_LATCHED)
-                    pDevExt->enmInterruptMode = Latched;
+                         pPartialData->u.Interrupt.Level, pPartialData->u.Interrupt.Vector, pPartialData->Flags));
+
+                if (!fGotIrq)
+                {
+                    /* Save information. */
+                    pDevExt->uInterruptLevel    = pPartialData->u.Interrupt.Level;
+                    pDevExt->uInterruptVector   = pPartialData->u.Interrupt.Vector;
+                    pDevExt->fInterruptAffinity = pPartialData->u.Interrupt.Affinity;
+
+                    /* Check interrupt mode. */
+                    if (pPartialData->Flags & CM_RESOURCE_INTERRUPT_LATCHED)
+                        pDevExt->enmInterruptMode = Latched;
+                    else
+                        pDevExt->enmInterruptMode = LevelSensitive;
+                    fGotIrq = true;
+                }
                 else
-                    pDevExt->enmInterruptMode = LevelSensitive;
+                    LogFunc(("More than one IRQ resource!\n"));
                 break;
             }
@@ -2287,16 +2298,13 @@
             case CmResourceTypeMemory:
             {
+                LogFlowFunc(("Memory range: Base=%#RX64, length=%08x\n",
+                             pPartialData->u.Memory.Start.QuadPart, pPartialData->u.Memory.Length));
+
                 /* Overflow protection. */
-                if (rangeCount < PCI_TYPE0_ADDRESSES)
+                if (cBaseAddresses < PCI_TYPE0_ADDRESSES)
                 {
-                    LogFlowFunc(("Memory range: Base=%08x:%08x, length=%08x\n",
-                                 pPartialData->u.Memory.Start.HighPart,
-                                 pPartialData->u.Memory.Start.LowPart,
-                                 pPartialData->u.Memory.Length));
-
-                    /* We only care about read/write memory. */
-                    /** @todo Reconsider memory type. */
-                    if (   cMMIORange == 0 /* Only care about the first MMIO range (!!!). */
-                        && (pPartialData->Flags & VBOX_CM_PRE_VISTA_MASK) == CM_RESOURCE_MEMORY_READ_WRITE)
+                    /* We only care about the first read/write memory range. */
+                    if (   !fGotMmio
+                        && (pPartialData->Flags & CM_RESOURCE_MEMORY_WRITEABILITY_MASK) == CM_RESOURCE_MEMORY_READ_WRITE)
                     {
                         /* Save physical MMIO base + length for VMMDev. */
@@ -2304,19 +2312,22 @@
                         pDevExt->cbVmmDevMemory = (ULONG)pPartialData->u.Memory.Length;
 
-                        /* Technically we need to make the HAL translate the address.  since we
-                           didn't used to do this and it probably just returns the input address,
-                           we allow ourselves to ignore failures. */
-                        ULONG               uAddressSpace = 0;
-                        PHYSICAL_ADDRESS    PhysAddr = pPartialData->u.Memory.Start;
-                        if (HalTranslateBusAddress(pResList->List->InterfaceType, pResList->List->BusNumber, PhysAddr,
-                                                   &uAddressSpace, &PhysAddr))
+                        if (!fTranslated)
                         {
-                            Log(("HalTranslateBusAddress(%#RX64) -> %RX64, type %#x\n",
-                                 pPartialData->u.Memory.Start.QuadPart, PhysAddr.QuadPart, uAddressSpace));
-                            if (pPartialData->u.Memory.Start.QuadPart != PhysAddr.QuadPart)
-                                pDevExt->uVmmDevMemoryPhysAddr = PhysAddr;
+                            /* Technically we need to make the HAL translate the address.  since we
+                               didn't used to do this and it probably just returns the input address,
+                               we allow ourselves to ignore failures. */
+                            ULONG               uAddressSpace = 0;
+                            PHYSICAL_ADDRESS    PhysAddr = pPartialData->u.Memory.Start;
+                            if (HalTranslateBusAddress(pResList->List->InterfaceType, pResList->List->BusNumber, PhysAddr,
+                                                       &uAddressSpace, &PhysAddr))
+                            {
+                                Log(("HalTranslateBusAddress(%#RX64) -> %RX64, type %#x\n",
+                                     pPartialData->u.Memory.Start.QuadPart, PhysAddr.QuadPart, uAddressSpace));
+                                if (pPartialData->u.Memory.Start.QuadPart != PhysAddr.QuadPart)
+                                    pDevExt->uVmmDevMemoryPhysAddr = PhysAddr;
+                            }
+                            else
+                                Log(("HalTranslateBusAddress(%#RX64) -> failed!\n", pPartialData->u.Memory.Start.QuadPart));
                         }
-                        else
-                            Log(("HalTranslateBusAddress(%#RX64) -> failed!\n", pPartialData->u.Memory.Start.QuadPart));
 
                         /* Save resource information. */
@@ -2326,15 +2337,18 @@
                         pBaseAddress->ResourceMapped = FALSE;
 
-                        LogFunc(("Memory range for VMMDev found! Base = %08x:%08x, Length = %08x\n",
-                                 pPartialData->u.Memory.Start.HighPart,
-                                 pPartialData->u.Memory.Start.LowPart,
-                                 pPartialData->u.Memory.Length));
+                        LogFunc(("Found memory range for VMMDev! Base = %#RX64, Length = %08x\n",
+                                 pPartialData->u.Memory.Start.QuadPart, pPartialData->u.Memory.Length));
 
                         /* Next item ... */
-                        rangeCount++; pBaseAddress++; cMMIORange++;
+                        cBaseAddresses++;
+                        pBaseAddress++;
+                        fGotMmio = true;
                     }
                     else
-                        LogFunc(("Ignoring memory: Flags=%08x\n", pPartialData->Flags));
+                        LogFunc(("Ignoring memory: Flags=%08x Base=%#RX64\n",
+                                 pPartialData->Flags, pPartialData->u.Memory.Start.QuadPart));
                 }
+                else
+                    LogFunc(("Too many PCI addresses!\n"));
                 break;
             }
@@ -2349,5 +2363,5 @@
 
     /* Memorize the number of resources found. */
-    pDevExt->cPciAddresses = rangeCount;
+    pDevExt->cPciAddresses = cBaseAddresses;
     return rc;
 }
