Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Makefile.kmk
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Makefile.kmk	(revision 17582)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Makefile.kmk	(revision 17583)
@@ -54,4 +54,11 @@
 	$(VBOX_LIB_IPRT_GUEST_R0_NT4)
 
+ifdef VBOX_WITH_HGSMI
+VBoxVideo_SOURCES     += \
+	VBoxVideoHGSMI.cpp
+VBoxVideo_LIBS         += \
+	$(VBOX_PATH_ADDITIONS_LIB)/HGSMIGuestR0Lib$(VBOX_SUFF_LIB)
+endif
+
 include	$(KBUILD_PATH)/subfooter.kmk
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp	(revision 17582)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp	(revision 17583)
@@ -730,5 +730,5 @@
 
 /* Computes the size of a framebuffer. DualView has a few framebuffers of the computed size. */
-static void vboxComputeFrameBufferSizes (PDEVICE_EXTENSION PrimaryExtension)
+void VBoxComputeFrameBufferSizes (PDEVICE_EXTENSION PrimaryExtension)
 {
     ULONG ulAvailable = PrimaryExtension->u.primary.cbVRAM
@@ -743,5 +743,5 @@
     ulSize &= ~0xFFF;
 
-    dprintf(("VBoxVideo::vboxComputeFrameBufferSizes: cbVRAM = 0x%08X, cDisplays = %d, ulSize = 0x%08X, ulSize * cDisplays = 0x%08X, slack = 0x%08X\n",
+    dprintf(("VBoxVideo::VBoxComputeFrameBufferSizes: cbVRAM = 0x%08X, cDisplays = %d, ulSize = 0x%08X, ulSize * cDisplays = 0x%08X, slack = 0x%08X\n",
              PrimaryExtension->u.primary.cbVRAM, PrimaryExtension->u.primary.cDisplays,
              ulSize, ulSize * PrimaryExtension->u.primary.cDisplays,
@@ -772,5 +772,5 @@
         Extension->ulFrameBufferSize = 0;
 
-        dprintf(("VBoxVideo::vboxComputeFrameBufferSizes: [%d] ulFrameBufferOffset 0x%08X\n",
+        dprintf(("VBoxVideo::VBoxComputeFrameBufferSizes: [%d] ulFrameBufferOffset 0x%08X\n",
                  Extension->iDevice, ulFrameBufferOffset));
 
@@ -782,7 +782,7 @@
 }
 
-static int vboxMapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension, void **ppv, ULONG ulOffset, ULONG ulSize)
-{
-    dprintf(("VBoxVideo::vboxMapAdapterMemory 0x%08X[0x%X]\n", ulOffset, ulSize));
+int VBoxMapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension, void **ppv, ULONG ulOffset, ULONG ulSize)
+{
+    dprintf(("VBoxVideo::VBoxMapAdapterMemory 0x%08X[0x%X]\n", ulOffset, ulSize));
 
     if (!ulSize)
@@ -808,12 +808,12 @@
     }
 
-    dprintf(("VBoxVideo::vboxMapAdapterMemory rc = %d\n", Status));
+    dprintf(("VBoxVideo::VBoxMapAdapterMemory rc = %d\n", Status));
 
     return Status;
 }
 
-static void vboxUnmapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension, void **ppv)
-{
-    dprintf(("VBoxVideo::vboxMapAdapterMemory\n"));
+void VBoxUnmapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension, void **ppv)
+{
+    dprintf(("VBoxVideo::VBoxMapAdapterMemory\n"));
 
     if (*ppv)
@@ -963,5 +963,5 @@
     {
         /* Map the adapter information. It will be needed to query some configuration values. */
-        rc = vboxMapAdapterMemory (PrimaryExtension,
+        rc = VBoxMapAdapterMemory (PrimaryExtension,
                                    &PrimaryExtension->u.primary.pvAdapterInformation,
                                    PrimaryExtension->u.primary.cbVRAM - VBOX_VIDEO_ADAPTER_INFORMATION_SIZE,
@@ -970,5 +970,5 @@
         if (rc != NO_ERROR)
         {
-            dprintf(("VBoxVideo::VBoxSetupDisplays: vboxMapAdapterMemory pvAdapterInfoirrmation failed rc = %d\n",
+            dprintf(("VBoxVideo::VBoxSetupDisplays: VBoxMapAdapterMemory pvAdapterInfoirrmation failed rc = %d\n",
                      rc));
 
@@ -1006,5 +1006,5 @@
          *
          */
-        rc = vboxMapAdapterMemory (PrimaryExtension,
+        rc = VBoxMapAdapterMemory (PrimaryExtension,
                                    &PrimaryExtension->u.primary.pvMiniportHeap,
                                    PrimaryExtension->u.primary.cbVRAM
@@ -1090,5 +1090,5 @@
      * calculate the layout of framebuffers.
      */
-    vboxComputeFrameBufferSizes (PrimaryExtension);
+    VBoxComputeFrameBufferSizes (PrimaryExtension);
 
     if (PrimaryExtension->u.primary.bVBoxVideoSupported)
@@ -1100,6 +1100,6 @@
     {
         /* Unmap the memory if VBoxVideo is not supported. */
-        vboxUnmapAdapterMemory (PrimaryExtension, &PrimaryExtension->u.primary.pvMiniportHeap);
-        vboxUnmapAdapterMemory (PrimaryExtension, &PrimaryExtension->u.primary.pvAdapterInformation);
+        VBoxUnmapAdapterMemory (PrimaryExtension, &PrimaryExtension->u.primary.pvMiniportHeap);
+        VBoxUnmapAdapterMemory (PrimaryExtension, &PrimaryExtension->u.primary.pvAdapterInformation);
     }
 
@@ -1182,4 +1182,5 @@
       rc = NO_ERROR;
 
+#ifndef VBOX_WITH_HGSMI
       /* Initialize VBoxGuest library */
       rc = VbglInit ();
@@ -1189,4 +1190,22 @@
       /* Setup the Device Extension and if possible secondary displays. */
       VBoxSetupDisplays((PDEVICE_EXTENSION)HwDeviceExtension, ConfigInfo, AdapterMemorySize);
+#else
+      if (VBoxHGSMIIsSupported ())
+      {
+          LogRel(("VBoxVideo: using HGSMI\n"));
+
+          VBoxSetupDisplaysHGSMI((PDEVICE_EXTENSION)HwDeviceExtension, ConfigInfo, AdapterMemorySize);
+      }
+      else
+      {
+          /* Initialize VBoxGuest library */
+          rc = VbglInit ();
+
+          dprintf(("VBoxVideo::VBoxVideoFindAdapter: VbglInit returned 0x%x\n", rc));
+
+          /* Setup the Device Extension and if possible secondary displays. */
+          VBoxSetupDisplays((PDEVICE_EXTENSION)HwDeviceExtension, ConfigInfo, AdapterMemorySize);
+      }
+#endif /* VBOX_WITH_HGSMI */
 
       // pretend success to make the driver work.
@@ -1785,4 +1804,38 @@
         }
 
+#ifdef VBOX_WITH_HGSMI
+        case IOCTL_VIDEO_QUERY_HGSMI_INFO:
+        {
+            dprintf(("VBoxVideo::VBoxVideoStartIO: IOCTL_VIDEO_QUERY_HGSMI_INFO\n"));
+
+            if (RequestPacket->OutputBufferLength < sizeof(QUERYHGSMIRESULT))
+            {
+                dprintf(("VBoxVideo::VBoxVideoStartIO: Output buffer too small: %d needed: %d!!!\n",
+                         RequestPacket->OutputBufferLength, sizeof(QUERYHGSMIRESULT)));
+                RequestPacket->StatusBlock->Status = ERROR_INSUFFICIENT_BUFFER;
+                return FALSE;
+            }
+
+            if (!pDevExt->pPrimary->u.primary.bHGSMI)
+            {
+                RequestPacket->StatusBlock->Status = ERROR_INVALID_FUNCTION;
+                return FALSE;
+            }
+
+            QUERYHGSMIRESULT *pInfo = (QUERYHGSMIRESULT *)RequestPacket->OutputBuffer;
+
+            pInfo->iDevice = pDevExt->iDevice;
+            pInfo->ulFlags = 0;
+
+            /* Describes VRAM chunk for this display device. */
+            pInfo->areaDisplay = pDevExt->areaDisplay;
+
+            RequestPacket->StatusBlock->Information = sizeof(QUERYHGSMIRESULT);
+            Result = TRUE;
+
+            break;
+        }
+#endif /* VBOX_WITH_HGSMI */
+
         default:
             dprintf(("VBoxVideo::VBoxVideoStartIO: Unsupported %p, fn %d(0x%x)\n",
@@ -1833,6 +1886,6 @@
     VbglTerminate ();
 
-    vboxUnmapAdapterMemory (pDevExt, &pDevExt->u.primary.pvMiniportHeap);
-    vboxUnmapAdapterMemory (pDevExt, &pDevExt->u.primary.pvAdapterInformation);
+    VBoxUnmapAdapterMemory (pDevExt, &pDevExt->u.primary.pvMiniportHeap);
+    VBoxUnmapAdapterMemory (pDevExt, &pDevExt->u.primary.pvAdapterInformation);
 
     return TRUE;
@@ -2018,4 +2071,10 @@
         /* Save the new framebuffer size */
         DeviceExtension->ulFrameBufferSize = MapInformation->FrameBufferLength;
+#ifdef VBOX_WITH_HGSMI
+        HGSMIAreaInitialize (&DeviceExtension->areaDisplay,
+                             MapInformation->FrameBufferBase,
+                             MapInformation->FrameBufferLength,
+                             DeviceExtension->ulFrameBufferOffset);
+#endif /* VBOX_WITH_HGSMI */
         return TRUE;
     }
@@ -2034,4 +2093,7 @@
 {
     dprintf(("VBoxVideo::VBoxVideoUnmapVideoMemory\n"));
+#ifdef VBOX_WITH_HGSMI
+    HGSMIAreaClear (&DeviceExtension->areaDisplay);
+#endif /* VBOX_WITH_HGSMI */
     VideoPortUnmapMemory(DeviceExtension, VideoMemory->RequestedVirtualAddress, NULL);
     return TRUE;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h	(revision 17582)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.h	(revision 17583)
@@ -24,4 +24,8 @@
 #include <iprt/assert.h>
 
+#ifdef VBOX_WITH_HGSMI
+#include <VBox/HGSMI/HGSMI.h>
+#endif /* VBOX_WITH_HGSMI */
+
 __BEGIN_DECLS
 #include "dderror.h"
@@ -43,7 +47,15 @@
 #define VBE_DISPI_INDEX_VIRT_HEIGHT     0x7
 #define VBE_DISPI_INDEX_VBOX_VIDEO      0xa
+#ifdef VBOX_WITH_HGSMI
+#define VBE_DISPI_INDEX_VBVA_HOST       0xb
+#define VBE_DISPI_INDEX_VBVA_GUEST      0xc
+#endif /* VBOX_WITH_HGSMI */
+
 #define VBE_DISPI_ID2                   0xB0C2
 /* The VBOX interface id. Indicates support for VBE_DISPI_INDEX_VBOX_VIDEO. */
 #define VBE_DISPI_ID_VBOX_VIDEO         0xBE00
+#ifdef VBOX_WITH_HGSMI
+#define VBE_DISPI_ID_HGSMI              0xBE01
+#endif /* VBOX_WITH_HGSMI */
 #define VBE_DISPI_DISABLED              0x00
 #define VBE_DISPI_ENABLED               0x01
@@ -109,4 +121,11 @@
                                                 */
            
+#ifdef VBOX_WITH_HGSMI
+           BOOLEAN bHGSMI;                     /* Whether HGSMI is enabled. */
+
+           HGSMIAREA areaHostHeap;             /* Host heap VRAM area. */
+
+           HGSMIHEAP hgsmiAdapterHeap;
+#endif /* VBOX_WITH_HGSMI */
        } primary;
    
@@ -116,4 +135,8 @@
        } secondary;
    } u;
+
+#ifdef VBOX_WITH_HGSMI
+   HGSMIAREA areaDisplay;                      /* Entire VRAM chunk for this display device. */
+#endif /* VBOX_WITH_HGSMI */
 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
 
@@ -201,4 +224,21 @@
    PULONG pUnused);
 
+int VBoxMapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension,
+                          void **ppv,
+                          ULONG ulOffset,
+                          ULONG ulSize);
+
+void VBoxUnmapAdapterMemory (PDEVICE_EXTENSION PrimaryExtension,
+                             void **ppv);
+                             
+void VBoxComputeFrameBufferSizes (PDEVICE_EXTENSION PrimaryExtension);
+
+#ifdef VBOX_WITH_HGSMI
+BOOLEAN VBoxHGSMIIsSupported (void);
+
+VOID VBoxSetupDisplaysHGSMI (PDEVICE_EXTENSION PrimaryExtension,
+                             PVIDEO_PORT_CONFIG_INFO pConfigInfo,
+                             ULONG AdapterMemorySize);
+#endif /* VBOX_WITH_HGSMI */
 } /* extern "C" */
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/vboxioctl.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/vboxioctl.h	(revision 17582)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/vboxioctl.h	(revision 17583)
@@ -25,4 +25,8 @@
 #include <VBox/VBoxGuest.h>
 
+#ifdef VBOX_WITH_HGSMI
+#include <VBox/HGSMI/HGSMI.h>
+#endif /* VBOX_WITH_HGSMI */
+
 #define IOCTL_VIDEO_INTERPRET_DISPLAY_MEMORY \
     CTL_CODE(FILE_DEVICE_VIDEO, 0x420, METHOD_BUFFERED, FILE_ANY_ACCESS)
@@ -40,4 +44,9 @@
 #define IOCTL_VIDEO_VBVA_ENABLE \
     CTL_CODE(FILE_DEVICE_VIDEO, 0x400, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#ifdef VBOX_WITH_HGSMI
+#define IOCTL_VIDEO_QUERY_HGSMI_INFO \
+    CTL_CODE(FILE_DEVICE_VIDEO, 0x430, METHOD_BUFFERED, FILE_ANY_ACCESS)
+#endif /* VBOX_WITH_HGSMI */
 
 #pragma pack(1)
@@ -77,4 +86,23 @@
     uint32_t u32DisplayInfoSize;
 } QUERYDISPLAYINFORESULT;
+
+#ifdef VBOX_WITH_HGSMI
+/**
+ * Data returned by IOCTL_VIDEO_QUERY_HGSMI_INFO.
+ *
+ */
+typedef struct _QUERYHGSMIRESULT
+{
+    /* Device index (0 for primary) */
+    ULONG iDevice;
+
+    /* Flags. Currently none are defined and the field must be initialized to 0. */
+    ULONG ulFlags;
+
+    /* Describes VRAM chunk for this display device. */
+    HGSMIAREA areaDisplay;
+
+} QUERYHGSMIRESULT;
+#endif /* VBOX_WITH_HGSMI */
 #pragma pack()
 
