Index: trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp
===================================================================
--- trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp	(revision 50084)
+++ trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp	(revision 50094)
@@ -508,16 +508,98 @@
 
 
-/** Helper that finds out the next SATA port used
+/** Helper that finds out the next HBA port used
  */
-static LONG GetNextUsedSataPort(LONG aSataPortUsed[30], LONG lBaseVal, uint32_t u32Size)
+static LONG GetNextUsedPort(LONG aPortUsed[30], LONG lBaseVal, uint32_t u32Size)
 {
     LONG lNextPortUsed = 30;
     for (size_t j = 0; j < u32Size; ++j)
     {
-        if (   aSataPortUsed[j] >  lBaseVal
-            && aSataPortUsed[j] <= lNextPortUsed)
-           lNextPortUsed = aSataPortUsed[j];
+        if (   aPortUsed[j] >  lBaseVal
+            && aPortUsed[j] <= lNextPortUsed)
+           lNextPortUsed = aPortUsed[j];
     }
     return lNextPortUsed;
+}
+
+#define MAX_BIOS_LUN_COUNT   4
+
+static int SetBiosDiskInfo(ComPtr<IMachine> pMachine, PCFGMNODE pCfg, PCFGMNODE pBiosCfg,
+                           Bstr controllerName, const char * const s_apszBiosConfig[4])
+{
+    HRESULT             hrc;
+#define MAX_DEVICES     30
+#define H()     AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
+
+    LONG lPortLUN[MAX_BIOS_LUN_COUNT];
+    LONG lPortUsed[MAX_DEVICES];
+    uint32_t u32HDCount = 0;
+
+    /* init to max value */
+    lPortLUN[0] = MAX_DEVICES;
+
+    com::SafeIfaceArray<IMediumAttachment> atts;
+    hrc = pMachine->GetMediumAttachmentsOfController(controllerName.raw(),
+                                        ComSafeArrayAsOutParam(atts));  H();
+    size_t uNumAttachments = atts.size();
+    if (uNumAttachments > MAX_DEVICES)
+    {
+        LogRel(("Number of Attachments > Max=%d.\n", uNumAttachments));
+        uNumAttachments = MAX_DEVICES;
+    }
+
+    /* Find the relevant ports/IDs, i.e the ones to which a HD is attached. */
+    for (size_t j = 0; j < uNumAttachments; ++j)
+    {
+        IMediumAttachment *pMediumAtt = atts[j];
+        LONG lPortNum = 0;
+        hrc = pMediumAtt->COMGETTER(Port)(&lPortNum);                   H();
+        if (SUCCEEDED(hrc))
+        {
+            DeviceType_T lType;
+            hrc = pMediumAtt->COMGETTER(Type)(&lType);                    H();
+            if (SUCCEEDED(hrc) && lType == DeviceType_HardDisk)
+            {
+                /* find min port number used for HD */
+                if (lPortNum < lPortLUN[0])
+                    lPortLUN[0] = lPortNum;
+                lPortUsed[u32HDCount++] = lPortNum;
+                LogFlowFunc(("HD port Count=%d\n", u32HDCount));
+            }
+
+            /* Configure the hotpluggable flag for the port. */
+            BOOL fHotPluggable = FALSE;
+            hrc = pMediumAtt->COMGETTER(HotPluggable)(&fHotPluggable); H();
+            if (SUCCEEDED(hrc))
+            {
+                PCFGMNODE pPortCfg;
+                char szName[24];
+                RTStrPrintf(szName, sizeof(szName), "Port%d", lPortNum);
+
+                InsertConfigNode(pCfg, szName, &pPortCfg);
+                InsertConfigInteger(pPortCfg, "Hotpluggable", fHotPluggable ? 1 : 0);
+            }
+         }
+    }
+
+
+    /* Pick only the top 4 used HD Ports as CMOS doesn't have space
+     * to save details for all 30 ports
+     */
+    uint32_t u32MaxPortCount = MAX_BIOS_LUN_COUNT;
+    if (u32HDCount < MAX_BIOS_LUN_COUNT)
+        u32MaxPortCount = u32HDCount;
+    for (size_t j = 1; j < u32MaxPortCount; j++)
+        lPortLUN[j] = GetNextUsedPort(lPortUsed,
+                                      lPortLUN[j-1],
+                                       u32HDCount);
+    if (pBiosCfg)
+    {
+        for (size_t j = 0; j < u32MaxPortCount; j++)
+        {
+            InsertConfigInteger(pBiosCfg, s_apszBiosConfig[j], lPortLUN[j]);
+            LogFlowFunc(("Top %d HBA ports = %s, %d\n", j, s_apszBiosConfig[j], lPortLUN[j]));
+        }
+    }
+    return VINF_SUCCESS;
 }
 
@@ -1859,4 +1941,10 @@
             }
 
+            static const char * const apszBiosConfigScsi[MAX_BIOS_LUN_COUNT] =
+            { "ScsiLUN1", "ScsiLUN2", "ScsiLUN3", "ScsiLUN4" };
+
+            static const char * const apszBiosConfigSata[MAX_BIOS_LUN_COUNT] =
+            { "SataLUN1", "SataLUN2", "SataLUN3", "SataLUN4" };
+
             switch (enmCtrlType)
             {
@@ -1866,4 +1954,11 @@
 
                     InsertConfigInteger(pCfg, "Bootable",  fBootable);
+
+                    if (pBiosCfg)
+                    {
+                        InsertConfigString(pBiosCfg, "ScsiHardDiskDevice", "lsilogicscsi");
+                    }
+
+                    hrc = SetBiosDiskInfo(pMachine, pCfg, pBiosCfg, controllerName, apszBiosConfigScsi);    H();
 
                     /* Attach the status driver */
@@ -1881,4 +1976,11 @@
                     InsertConfigInteger(pCfg, "Bootable",  fBootable);
 
+                    if (pBiosCfg)
+                    {
+                        InsertConfigString(pBiosCfg, "ScsiHardDiskDevice", "buslogic");
+                    }
+
+                    hrc = SetBiosDiskInfo(pMachine, pCfg, pBiosCfg, controllerName, apszBiosConfigScsi);    H();
+
                     /* Attach the status driver */
                     Assert(cLedScsi >= 16);
@@ -1901,17 +2003,4 @@
                     if (!pBusMgr->hasPCIDevice("ahci", 1))
                     {
-#define MAX_SATA_LUN_COUNT 4
-#define MAX_SATA_PORTS     30
-
-                        static const char * const s_apszBiosConfig[4] =
-                        { "SataLUN1", "SataLUN2", "SataLUN3", "SataLUN4" };
-
-                        LONG lPortLUN[MAX_SATA_LUN_COUNT];
-                        LONG lPortUsed[MAX_SATA_PORTS];
-                        uint32_t u32HDSataPortCount = 0;
-
-                        /* init to max value */
-                        lPortLUN[0] = MAX_SATA_PORTS;
-
                         if (pBiosCfg)
                         {
@@ -1919,69 +2008,5 @@
                         }
 
-                        com::SafeIfaceArray<IMediumAttachment> atts;
-                        hrc = pMachine->GetMediumAttachmentsOfController(controllerName.raw(),
-                                                            ComSafeArrayAsOutParam(atts));  H();
-                        size_t uNumAttachments = atts.size();
-                        if (uNumAttachments > MAX_SATA_PORTS)
-                        {
-                            LogRel(("Number of Sata Port Attachments > Max=%d.\n", uNumAttachments));
-                            uNumAttachments =  MAX_SATA_PORTS;
-                        }
-
-                        /* find the relavant ports i.e Sata ports to which
-                         * HD is attached.
-                         */
-                        for (size_t j = 0; j < uNumAttachments; ++j)
-                        {
-                            IMediumAttachment *pMediumAtt = atts[j];
-                            LONG lPortNum = 0;
-                            hrc = pMediumAtt->COMGETTER(Port)(&lPortNum);                   H();
-                            if (SUCCEEDED(hrc))
-                            {
-                                DeviceType_T lType;
-                                hrc = pMediumAtt->COMGETTER(Type)(&lType);                    H();
-                                if (SUCCEEDED(hrc) && lType == DeviceType_HardDisk)
-                                {
-                                    /* find min port number used for HD */
-                                    if (lPortNum < lPortLUN[0])
-                                        lPortLUN[0] = lPortNum;
-                                    lPortUsed[u32HDSataPortCount++] = lPortNum;
-                                    LogFlowFunc(("HD Sata port Count=%d\n", u32HDSataPortCount));
-                                }
-
-                                /* Configure the hotpluggable flag for the port. */
-                                BOOL fHotPluggable = FALSE;
-                                hrc = pMediumAtt->COMGETTER(HotPluggable)(&fHotPluggable); H();
-                                if (SUCCEEDED(hrc))
-                                {
-                                    PCFGMNODE pPortCfg;
-                                    char szName[24];
-                                    RTStrPrintf(szName, sizeof(szName), "Port%d", lPortNum);
-
-                                    InsertConfigNode(pCfg, szName, &pPortCfg);
-                                    InsertConfigInteger(pPortCfg, "Hotpluggable", fHotPluggable ? 1 : 0);
-                                }
-                             }
-                        }
-
-
-                        /* Pick only the top 4 used HD Sata Ports as CMOS doesn't have space
-                         * to save details for every 30 ports
-                         */
-                        uint32_t u32MaxPortCount = MAX_SATA_LUN_COUNT;
-                        if (u32HDSataPortCount < MAX_SATA_LUN_COUNT)
-                            u32MaxPortCount = u32HDSataPortCount;
-                        for (size_t j = 1; j < u32MaxPortCount; j++)
-                            lPortLUN[j] = GetNextUsedSataPort(lPortUsed,
-                                                              lPortLUN[j-1],
-                                                              u32HDSataPortCount);
-                        if (pBiosCfg)
-                        {
-                            for (size_t j = 0; j < u32MaxPortCount; j++)
-                            {
-                                InsertConfigInteger(pBiosCfg, s_apszBiosConfig[j], lPortLUN[j]);
-                                LogFlowFunc(("Top %d ports = %s, %d\n", j, s_apszBiosConfig[j], lPortLUN[j]));
-                            }
-                        }
+                        hrc = SetBiosDiskInfo(pMachine, pCfg, pBiosCfg, controllerName, apszBiosConfigSata);    H();
                     }
 
@@ -2041,4 +2066,11 @@
                     InsertConfigString(pCfg,  "ControllerType", "SAS1068");
                     InsertConfigInteger(pCfg, "Bootable",  fBootable);
+
+                    if (pBiosCfg)
+                    {
+                        InsertConfigString(pBiosCfg, "ScsiHardDiskDevice", "lsilogicsas");
+                    }
+
+                    hrc = SetBiosDiskInfo(pMachine, pCfg, pBiosCfg, controllerName, apszBiosConfigScsi);    H();
 
                     ULONG cPorts = 0;
