Index: /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVga.c
===================================================================
--- /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVga.c	(revision 76899)
+++ /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVga.c	(revision 76900)
@@ -312,8 +312,8 @@
   //  if (((Pci.Hdr.Command & 0x01) == 0x01)) {
   //
-  // See if this is a VirtualBox VGA PCI controller
-  //
-  if (Pci.Hdr.VendorId == VBOX_VENDOR_ID) {
-    if (Pci.Hdr.DeviceId == VBOX_VGA_DEVICE_ID) {
+  // See if this is a VirtualBox VGA or VMSVGA II PCI controller
+  //
+  if ( (Pci.Hdr.VendorId == VBOX_VENDOR_ID) && (Pci.Hdr.DeviceId == VBOX_VGA_DEVICE_ID)
+    || (Pci.Hdr.VendorId == VMSVGA_VENDOR_ID) && (Pci.Hdr.DeviceId == VMSVGA_II_DEVICE_ID)) {
 
       Status = EFI_SUCCESS;
@@ -337,5 +337,4 @@
         }
       }
-    }
   }
 
@@ -375,4 +374,5 @@
   EFI_DEVICE_PATH_PROTOCOL        *ParentDevicePath;
   ACPI_ADR_DEVICE_PATH            AcpiDeviceNode;
+  PCI_TYPE00                      Pci;
 
   PciAttributesSaved = FALSE;
@@ -408,4 +408,21 @@
 
   //
+  // Read the PCI Configuration Header from the PCI Device again to figure out the model.
+  //
+  Status = Private->PciIo->Pci.Read (
+                                   Private->PciIo,
+                                   EfiPciIoWidthUint32,
+                                   0,
+                                   sizeof (Pci) / sizeof (UINT32),
+                                   &Pci
+                                   );
+  if (EFI_ERROR (Status)) {
+    DEBUG((DEBUG_INFO, "%a:%d status:%r\n", __FILE__, __LINE__, Status));
+    goto Error;
+  }
+
+  Private->DeviceType = Pci.Hdr.DeviceId;
+
+  //
   // Save original PCI attributes
   //
@@ -488,7 +505,54 @@
 
   //
-  // Get VRAM size, needed for constructing a correct video mode list
-  //
-  Private->VRAMSize = ASMInU32(VBE_DISPI_IOPORT_DATA);
+  // Now do some model-specific setup.
+  //
+  if (Private->DeviceType == VMSVGA_II_DEVICE_ID) {
+      EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR     *IOPortDesc;
+
+      // VMSVGA
+      Private->BarIndexFB = 1;
+
+      Private->PciIo->GetBarAttributes (
+                          Private->PciIo,
+                          0,    // BAR 0 is the I/O port space
+                          NULL,
+                          (VOID**) &IOPortDesc
+                          );
+      Private->IOBase = (UINT16)IOPortDesc->AddrRangeMin;
+
+      //
+      // Query the VRAM size (for proper mode filtering)
+      //
+      ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_VRAM_SIZE);
+      Private->VRAMSize = ASMInU32(Private->IOBase + SVGA_VALUE_PORT);
+
+#if 0
+      // Not used because of buggy emulation(?) which is not fully compatible
+      // with the simple "legacy" VMSVGA II register interface.
+
+      // Enable the device, set initial mode
+      ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_WIDTH);
+      ASMOutU32(Private->IOBase + SVGA_VALUE_PORT, 1024);
+      ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_HEIGHT);
+      ASMOutU32(Private->IOBase + SVGA_VALUE_PORT, 768);
+      ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_BYTES_PER_LINE);
+      ASMOutU32(Private->IOBase + SVGA_VALUE_PORT, 768 * 4);
+      ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_BITS_PER_PIXEL);
+      ASMOutU32(Private->IOBase + SVGA_VALUE_PORT, 32);
+      ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_CONFIG_DONE);
+      ASMOutU32(Private->IOBase + SVGA_VALUE_PORT, 1);
+
+      ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_ENABLE);
+      ASMOutU32(Private->IOBase + SVGA_VALUE_PORT, SVGA_REG_ENABLE_ENABLE);
+#endif
+  } else {
+      // VBoxVGA / VBoxSVGA
+      Private->BarIndexFB = 0;
+      //
+      // Get VRAM size, needed for constructing a correct video mode list
+      //
+      Private->VRAMSize = ASMInU32(VBE_DISPI_IOPORT_DATA);
+  }
+
 
   //
@@ -896,5 +960,5 @@
                         Private->PciIo,
                         EfiPciIoWidthFillUint32,
-                        0,
+                        Private->BarIndexFB,
                         0,
                           Private->ModeData[Private->CurrentMode].HorizontalResolution
@@ -1043,5 +1107,5 @@
     Private->PciIo->GetBarAttributes (
                         Private->PciIo,
-                        0,
+                        Private->BarIndexFB,
                         NULL,
                         (VOID**) &FrameBufDesc
Index: /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVga.h
===================================================================
--- /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVga.h	(revision 76899)
+++ /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVga.h	(revision 76900)
@@ -79,6 +79,35 @@
 // VirtualBox VGA PCI Configuration Header values
 //
-#define VBOX_VENDOR_ID           0x80ee
-#define VBOX_VGA_DEVICE_ID           0xbeef
+#define VBOX_VENDOR_ID          0x80ee
+#define VBOX_VGA_DEVICE_ID      0xbeef
+
+
+//
+// VMSVGA II PCI Configuration Header values
+//
+#define VMSVGA_VENDOR_ID        0x15ad
+#define VMSVGA_II_DEVICE_ID     0x0405
+
+// Port offsets relative to BAR 0
+#define SVGA_INDEX_PORT     0
+#define SVGA_VALUE_PORT     1
+
+// SVGA_REG_ENABLE bits
+#define SVGA_REG_ENABLE_DISABLE     0
+#define SVGA_REG_ENABLE_ENABLE      1
+
+// Registers
+#define SVGA_REG_ENABLE             1
+#define SVGA_REG_WIDTH              2
+#define SVGA_REG_HEIGHT             3
+#define SVGA_REG_MAX_WIDTH          4
+#define SVGA_REG_MAX_HEIGHT         5
+#define SVGA_REG_DEPTH              6
+#define SVGA_REG_BITS_PER_PIXEL     7
+#define SVGA_REG_BYTES_PER_LINE     12
+#define SVGA_REG_FB_START           13
+#define SVGA_REG_FB_OFFSET          14
+#define SVGA_REG_VRAM_SIZE          15
+#define SVGA_REG_CONFIG_DONE        20      ///@todo: Why do we need this?
 
 //
@@ -115,4 +144,7 @@
   VBOX_VGA_MODE_DATA                    *ModeData;
   BOOLEAN                               HardwareNeedsStarting;
+  UINT8                                 BarIndexFB;
+  UINT16                                DeviceType;
+  UINT16                                IOBase;
   UINT32                                VRAMSize;
 } VBOX_VGA_PRIVATE_DATA;
Index: /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVgaGraphicsOutput.c
===================================================================
--- /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVgaGraphicsOutput.c	(revision 76899)
+++ /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVgaGraphicsOutput.c	(revision 76900)
@@ -79,5 +79,5 @@
   Private->PciIo->GetBarAttributes (
                         Private->PciIo,
-                        0,
+                        Private->BarIndexFB,
                         NULL,
                         (VOID**) &FrameBufDesc
@@ -317,5 +317,5 @@
                                     Private->PciIo,
                                     EfiPciIoWidthUint32,
-                                    0,
+                                    Private->BarIndexFB,
                                     ((SrcY * ScreenWidth) + SourceX) * 4,
                                     Width,
@@ -335,5 +335,5 @@
                                     Private->PciIo,
                                     EfiPciIoWidthUint32,
-                                    0,
+                                    Private->BarIndexFB,
                                     ((DstY * ScreenWidth) + DestinationX) * 4,
                                     Width,
@@ -355,7 +355,7 @@
                                     Private->PciIo,
                                     EfiPciIoWidthUint32,
-                                    0,
+                                    Private->BarIndexFB,
                                     ((DstY * ScreenWidth) + DestinationX) * 4,
-                                    0,
+                                    Private->BarIndexFB,
                                     ((SrcY * ScreenWidth) + SourceX) * 4,
                                     Width
@@ -370,7 +370,7 @@
                                     Private->PciIo,
                                     EfiPciIoWidthUint32,
-                                    0,
+                                    Private->BarIndexFB,
                                     ((DstY * ScreenWidth) + DestinationX) * 4,
-                                    0,
+                                    Private->BarIndexFB,
                                     ((SrcY * ScreenWidth) + SourceX) * 4,
                                     Width
@@ -390,5 +390,5 @@
                                     Private->PciIo,
                                     EfiPciIoWidthFillUint32,
-                                    0,
+                                    Private->BarIndexFB,
                                     DestinationY * ScreenWidth * 4,
                                     (Width * Height),
@@ -402,5 +402,5 @@
                                       Private->PciIo,
                                       EfiPciIoWidthFillUint32,
-                                      0,
+                                      Private->BarIndexFB,
                                       ((DstY * ScreenWidth) + DestinationX) * 4,
                                       Width,
Index: /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVgaUgaDraw.c
===================================================================
--- /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVgaUgaDraw.c	(revision 76899)
+++ /trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVgaUgaDraw.c	(revision 76900)
@@ -216,5 +216,5 @@
                                     Private->PciIo,
                                     EfiPciIoWidthUint32,
-                                    0,
+                                    Private->BarIndexFB,
                                     ((SrcY * ScreenWidth) + SourceX) * 4,
                                     Width,
@@ -234,5 +234,5 @@
                                     Private->PciIo,
                                     EfiPciIoWidthUint32,
-                                    0,
+                                    Private->BarIndexFB,
                                     ((DstY * ScreenWidth) + DestinationX) * 4,
                                     Width,
@@ -254,7 +254,7 @@
                                     Private->PciIo,
                                     EfiPciIoWidthUint32,
-                                    0,
+                                    Private->BarIndexFB,
                                     ((DstY * ScreenWidth) + DestinationX) * 4,
-                                    0,
+                                    Private->BarIndexFB,
                                     ((SrcY * ScreenWidth) + SourceX) * 4,
                                     Width
@@ -269,7 +269,7 @@
                                     Private->PciIo,
                                     EfiPciIoWidthUint32,
-                                    0,
+                                    Private->BarIndexFB,
                                     ((DstY * ScreenWidth) + DestinationX) * 4,
-                                    0,
+                                    Private->BarIndexFB,
                                     ((SrcY * ScreenWidth) + SourceX) * 4,
                                     Width
@@ -289,5 +289,5 @@
                                     Private->PciIo,
                                     EfiPciIoWidthFillUint32,
-                                    0,
+                                    Private->BarIndexFB,
                                     DestinationY * ScreenWidth * 4,
                                     (Width * Height),
@@ -301,5 +301,5 @@
                               Private->PciIo,
                               EfiPciIoWidthFillUint32,
-                              0,
+                              Private->BarIndexFB,
                               ((DstY * ScreenWidth) + DestinationX) * 4,
                               Width,
