~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Devices/PC/DevPcBios.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: DevPcBios.cpp $ */
 
1
/* $Id: DevPcBios.cpp 35400 2011-01-04 11:58:52Z vboxsync $ */
2
2
/** @file
3
3
 * PC BIOS Device.
4
4
 */
19
19
*   Header Files                                                               *
20
20
*******************************************************************************/
21
21
#define LOG_GROUP LOG_GROUP_DEV_PC_BIOS
22
 
#include <VBox/pdmdev.h>
23
 
#include <VBox/mm.h>
24
 
#include <VBox/pgm.h>
 
22
#include <VBox/vmm/pdmdev.h>
 
23
#include <VBox/vmm/mm.h>
 
24
#include <VBox/vmm/pgm.h>
25
25
 
26
26
#include <VBox/log.h>
27
27
#include <iprt/asm.h>
34
34
#include <VBox/err.h>
35
35
#include <VBox/param.h>
36
36
 
37
 
#include "../Builtins.h"
38
 
#include "../Builtins2.h"
 
37
#include "VBoxDD.h"
 
38
#include "VBoxDD2.h"
39
39
#include "DevPcBios.h"
40
40
#include "DevFwCommon.h"
41
41
 
177
177
    uint16_t        au16NetBootDev[NET_BOOT_DEVS];
178
178
    /** Number of logical CPUs in guest */
179
179
    uint16_t        cCpus;
 
180
    uint32_t        u32McfgBase;
 
181
    uint32_t        cbMcfgLength;
180
182
} DEVPCBIOS, *PDEVPCBIOS;
181
183
 
182
184
 
231
233
    Assert(off < 256);
232
234
    Assert(u32Val < 256);
233
235
 
234
 
#if 1
235
236
    int rc = PDMDevHlpCMOSWrite(pDevIns, off, u32Val);
236
237
    AssertRC(rc);
237
 
#else
238
 
    PVM pVM = PDMDevHlpGetVM(pDevIns);
239
 
    IOMIOPortWrite(pVM, 0x70, off, 1);
240
 
    IOMIOPortWrite(pVM, 0x71, u32Val, 1);
241
 
    IOMIOPortWrite(pVM, 0x70, 0, 1);
242
 
#endif
243
238
}
244
239
 
245
240
/* -=-=-=-=-=-=- based on code from pc.c -=-=-=-=-=-=- */
640
635
    return VINF_SUCCESS;
641
636
}
642
637
 
643
 
 
644
638
/**
645
639
 * Port I/O Handler for IN operations.
646
640
 *
654
648
 */
655
649
static DECLCALLBACK(int) pcbiosIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
656
650
{
657
 
    NOREF(pDevIns);
658
 
    NOREF(pvUser);
659
 
    NOREF(Port);
660
 
    NOREF(pu32);
661
 
    NOREF(cb);
662
651
    return VERR_IOM_IOPORT_UNUSED;
663
652
}
664
653
 
844
833
        pThis->pszLanBootFile = NULL;
845
834
    }
846
835
 
 
836
    if (pThis->pszHDDevice)
 
837
    {
 
838
        MMR3HeapFree(pThis->pszHDDevice);
 
839
        pThis->pszHDDevice = NULL;
 
840
    }
 
841
 
 
842
    if (pThis->pszFDDevice)
 
843
    {
 
844
        MMR3HeapFree(pThis->pszFDDevice);
 
845
        pThis->pszFDDevice = NULL;
 
846
    }
 
847
 
 
848
    if (pThis->pszSataDevice)
 
849
    {
 
850
        MMR3HeapFree(pThis->pszSataDevice);
 
851
        pThis->pszSataDevice = NULL;
 
852
    }
 
853
 
847
854
    return VINF_SUCCESS;
848
855
}
849
856
 
922
929
                              "UUID\0"
923
930
                              "IOAPIC\0"
924
931
                              "NumCPUs\0"
 
932
                              "McfgBase\0"
 
933
                              "McfgLength\0"
925
934
                              "DmiBIOSVendor\0"
926
935
                              "DmiBIOSVersion\0"
927
936
                              "DmiBIOSReleaseDate\0"
968
977
        return PDMDEV_SET_ERROR(pDevIns, rc,
969
978
                                N_("Configuration error: Querying \"NumCPUs\" as integer failed"));
970
979
 
 
980
    rc = CFGMR3QueryU32Def(pCfg, "McfgBase", &pThis->u32McfgBase, 0);
 
981
    if (RT_FAILURE(rc))
 
982
        return PDMDEV_SET_ERROR(pDevIns, rc,
 
983
                                N_("Configuration error: Querying \"\" as integer failed"));
 
984
    rc = CFGMR3QueryU32Def(pCfg, "McfgLength", &pThis->cbMcfgLength, 0);
 
985
    if (RT_FAILURE(rc))
 
986
        return PDMDEV_SET_ERROR(pDevIns, rc,
 
987
                                N_("Configuration error: Querying \"McfgLength\" as integer failed"));
 
988
 
 
989
 
971
990
    LogRel(("[SMP] BIOS with %u CPUs\n", pThis->cCpus));
972
991
 
973
992
    rc = CFGMR3QueryU8Def(pCfg, "IOAPIC", &pThis->u8IOAPIC, 1);
1050
1069
        FwCommonPlantMpsTable(pDevIns, pThis->au8DMIPage + VBOX_DMI_TABLE_SIZE,
1051
1070
                              _4K - VBOX_DMI_TABLE_SIZE, pThis->cCpus);
1052
1071
 
1053
 
    rc = PDMDevHlpROMRegister(pDevIns, VBOX_DMI_TABLE_BASE, _4K, pThis->au8DMIPage,
 
1072
    rc = PDMDevHlpROMRegister(pDevIns, VBOX_DMI_TABLE_BASE, _4K, pThis->au8DMIPage, _4K,
1054
1073
                              PGMPHYS_ROM_FLAGS_PERMANENT_BINARY, "DMI tables");
1055
1074
    if (RT_FAILURE(rc))
1056
1075
        return rc;
1080
1099
    else
1081
1100
    {
1082
1101
        PCFGMNODE   pCfgNetBootDevice;
 
1102
        uint8_t     u8PciBus;
1083
1103
        uint8_t     u8PciDev;
1084
1104
        uint8_t     u8PciFn;
1085
1105
        uint16_t    u16BusDevFn;
1090
1110
        {
1091
1111
            szIndex[0] = '0' + i;
1092
1112
            pCfgNetBootDevice = CFGMR3GetChild(pCfgNetBoot, szIndex);
 
1113
 
 
1114
            rc = CFGMR3QueryU8(pCfgNetBootDevice, "PCIBusNo", &u8PciBus);
 
1115
            if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
 
1116
            {
 
1117
                /* Do nothing and stop iterating. */
 
1118
                rc = VINF_SUCCESS;
 
1119
                break;
 
1120
            }
 
1121
            else if (RT_FAILURE(rc))
 
1122
                return PDMDEV_SET_ERROR(pDevIns, rc,
 
1123
                                        N_("Configuration error: Querying \"Netboot/x/PCIBusNo\" as integer failed"));
1093
1124
            rc = CFGMR3QueryU8(pCfgNetBootDevice, "PCIDeviceNo", &u8PciDev);
1094
1125
            if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
1095
1126
            {
1110
1141
            else if (RT_FAILURE(rc))
1111
1142
                return PDMDEV_SET_ERROR(pDevIns, rc,
1112
1143
                                        N_("Configuration error: Querying \"Netboot/x/PCIFunctionNo\" as integer failed"));
1113
 
            u16BusDevFn = ((u8PciDev & 0x1F) << 3) | (u8PciFn & 0x7);
 
1144
            u16BusDevFn = (((uint16_t)u8PciBus) << 8) | ((u8PciDev & 0x1F) << 3) | (u8PciFn & 0x7);
1114
1145
            pThis->au16NetBootDev[i] = u16BusDevFn;
1115
1146
        }
1116
1147
    }
1224
1255
    AssertReleaseMsg(RT_ALIGN_Z(cbPcBiosBinary, _64K) == cbPcBiosBinary,
1225
1256
                     ("cbPcBiosBinary=%#x\n", cbPcBiosBinary));
1226
1257
    cb = RT_MIN(cbPcBiosBinary, 128 * _1K); /* Effectively either 64 or 128K. */
1227
 
    rc = PDMDevHlpROMRegister(pDevIns, 0x00100000 - cb, cb, &pu8PcBiosBinary[cbPcBiosBinary - cb],
 
1258
    rc = PDMDevHlpROMRegister(pDevIns, 0x00100000 - cb, cb, &pu8PcBiosBinary[cbPcBiosBinary - cb], cb,
1228
1259
                              fFlags, "PC BIOS - 0xfffff");
1229
1260
    if (RT_FAILURE(rc))
1230
1261
        return rc;
1231
 
    rc = PDMDevHlpROMRegister(pDevIns, (uint32_t)-(int32_t)cbPcBiosBinary, cbPcBiosBinary, pu8PcBiosBinary,
 
1262
    rc = PDMDevHlpROMRegister(pDevIns, (uint32_t)-(int32_t)cbPcBiosBinary, cbPcBiosBinary, pu8PcBiosBinary, cbPcBiosBinary,
1232
1263
                              fFlags, "PC BIOS - 0xffffffff");
1233
1264
    if (RT_FAILURE(rc))
1234
1265
        return rc;
1235
1266
 
1236
1267
    /*
1237
 
     * Call reset to set values and stuff.
1238
 
     */
1239
 
    pcbiosReset(pDevIns);
1240
 
 
1241
 
    /*
1242
1268
     * Get the LAN boot ROM file name.
1243
1269
     */
1244
1270
    rc = CFGMR3QueryStringAlloc(pCfg, "LanBootRom", &pThis->pszLanBootFile);
1273
1299
            rc = RTFileGetSize(FileLanBoot, &cbFileLanBoot);
1274
1300
            if (RT_SUCCESS(rc))
1275
1301
            {
1276
 
                if (    RT_ALIGN(cbFileLanBoot, _4K) != cbFileLanBoot
1277
 
                    ||  cbFileLanBoot > _64K)
 
1302
                if (cbFileLanBoot > _64K - (VBOX_LANBOOT_SEG << 4 & 0xffff))
1278
1303
                    rc = VERR_TOO_MUCH_DATA;
1279
1304
            }
1280
1305
        }
1299
1324
        /*
1300
1325
         * Allocate buffer for the LAN boot ROM data.
1301
1326
         */
1302
 
        pThis->pu8LanBoot = (uint8_t *)PDMDevHlpMMHeapAlloc(pDevIns, cbFileLanBoot);
 
1327
        pThis->pu8LanBoot = (uint8_t *)PDMDevHlpMMHeapAllocZ(pDevIns, cbFileLanBoot);
1303
1328
        if (pThis->pu8LanBoot)
1304
1329
        {
1305
1330
            rc = RTFileRead(FileLanBoot, pThis->pu8LanBoot, cbFileLanBoot, NULL);
1326
1351
     */
1327
1352
    if (pThis->pu8LanBoot == NULL)
1328
1353
    {
 
1354
#ifdef VBOX_WITH_PXE_ROM
1329
1355
        pu8LanBootBinary = g_abNetBiosBinary;
1330
1356
        cbLanBootBinary  = g_cbNetBiosBinary;
 
1357
#endif
1331
1358
    }
1332
1359
    else
1333
1360
    {
1337
1364
 
1338
1365
    /*
1339
1366
     * Map the Network Boot ROM into memory.
1340
 
     * Currently there is a fixed mapping: 0x000c8000 to 0x000cffff contains
1341
 
     * the (up to) 32 kb ROM image.
 
1367
     * Currently there is a fixed mapping: 0x000d2000 to 0x000dffff contains
 
1368
     * the (up to) 56 kb ROM image.  The mapping size is fixed to trouble with
 
1369
     * the saved state (in PGM).
1342
1370
     */
1343
1371
    if (pu8LanBootBinary)
1344
1372
    {
1345
1373
        pThis->cbLanBoot = cbLanBootBinary;
1346
1374
 
1347
 
        rc = PDMDevHlpROMRegister(pDevIns, VBOX_LANBOOT_SEG << 4, cbLanBootBinary, pu8LanBootBinary,
 
1375
        rc = PDMDevHlpROMRegister(pDevIns, VBOX_LANBOOT_SEG << 4,
 
1376
                                  RT_MAX(cbLanBootBinary, _64K - (VBOX_LANBOOT_SEG << 4 & 0xffff)),
 
1377
                                  pu8LanBootBinary, cbLanBootBinary,
1348
1378
                                  PGMPHYS_ROM_FLAGS_SHADOWED, "Net Boot ROM");
1349
 
        if (RT_SUCCESS(rc))
1350
 
        {
1351
 
            rc = PDMDevHlpROMProtectShadow(pDevIns, VBOX_LANBOOT_SEG << 4, cbLanBootBinary, PGMROMPROT_READ_RAM_WRITE_RAM);
1352
 
            AssertRCReturn(rc, rc);
1353
 
            rc = PDMDevHlpPhysWrite(pDevIns, VBOX_LANBOOT_SEG << 4, pu8LanBootBinary, cbLanBootBinary);
1354
 
            AssertRCReturn(rc, rc);
1355
 
        }
 
1379
        AssertRCReturn(rc, rc);
1356
1380
    }
1357
1381
 
1358
1382
    rc = CFGMR3QueryU8Def(pCfg, "DelayBoot", &pThis->uBootDelay, 0);
1362
1386
    if (pThis->uBootDelay > 15)
1363
1387
        pThis->uBootDelay = 15;
1364
1388
 
1365
 
    return rc;
 
1389
    /*
 
1390
     * Call reset plant tables and shadow the PXE ROM.
 
1391
     */
 
1392
    pcbiosReset(pDevIns);
 
1393
 
 
1394
    return VINF_SUCCESS;
1366
1395
}
1367
1396
 
1368
1397