VirtualBox

Changeset 65850 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 23, 2017 10:16:04 AM (8 years ago)
Author:
vboxsync
Message:

Devices/Main: don't set RamSize and RamHole explicitly for DevACPI, DevEFI, DevPcBios and VMMDev but use the MMR3Phys* API for that. This simplifies and unifies the calculation of RAM below 4GB and RAM above 4GB. Also renamed PciPref64Limit to PciPref64LimitGB to show that the limit is in GB.

Location:
trunk/src/VBox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/DevEFI.cpp

    r65714 r65850  
    191191    /** Number of virtual CPUs. (Config) */
    192192    uint32_t                cCpus;
    193     /** RAM below 4GB (in bytes). (Config) */
    194     uint32_t                cbBelow4GB;
    195     /** RAM above 4GB (in bytes). (Config) */
    196     uint64_t                cbAbove4GB;
    197     /** The total amount of memory. */
    198     uint64_t                cbRam;
    199     /** The size of the RAM hole below 4GB. */
    200     uint64_t                cbRamHole;
    201193
    202194    /** The size of the DMI tables. */
     
    17441736    PDEVEFI pThis = PDMINS_2_DATA(pDevIns, PDEVEFI);
    17451737
     1738    PVM pVM                    = PDMDevHlpGetVM(pDevIns);
     1739    uint64_t const  cbRamSize  = MMR3PhysGetRamSize(pVM);
     1740    uint32_t const  cbBelow4GB = MMR3PhysGetRamSizeBelow4GB(pVM);
     1741    uint64_t const  cbAbove4GB = MMR3PhysGetRamSizeAbove4GB(pVM);
     1742    NOREF(cbAbove4GB);
     1743
    17461744    /*
    17471745     * Memory sizes.
    17481746     */
    1749     uint64_t const offRamHole = _4G - pThis->cbRamHole;
    17501747    uint32_t u32Low = 0;
    17511748    uint32_t u32Chunks = 0;
    1752     if (pThis->cbRam > 16 * _1M)
    1753     {
    1754         u32Low = (uint32_t)RT_MIN(RT_MIN(pThis->cbRam, offRamHole), UINT32_C(0xffe00000));
     1749    if (cbRamSize > 16 * _1M)
     1750    {
     1751        u32Low = RT_MIN(cbBelow4GB, UINT32_C(0xffe00000));
    17551752        u32Chunks = (u32Low - 16U * _1M) / _64K;
    17561753    }
     
    17581755    cmosWrite(pDevIns, 0x35, RT_BYTE2(u32Chunks));
    17591756
    1760     if (u32Low < pThis->cbRam)
    1761     {
    1762         uint64_t u64 = pThis->cbRam - u32Low;
     1757    if (u32Low < cbRamSize)
     1758    {
     1759        uint64_t u64 = cbRamSize - u32Low;
    17631760        u32Chunks = (uint32_t)(u64 / _64K);
    17641761        cmosWrite(pDevIns, 0x5b, RT_BYTE1(u32Chunks));
     
    21422139    if (!CFGMR3AreValuesValid(pCfg,
    21432140                              "EfiRom\0"
    2144                               "RamSize\0"
    2145                               "RamHoleSize\0"
    21462141                              "NumCPUs\0"
    21472142                              "UUID\0"
     
    22212216    uuid.Gen.u16TimeHiAndVersion = RT_H2BE_U16(uuid.Gen.u16TimeHiAndVersion);
    22222217    memcpy(&pThis->aUuid, &uuid, sizeof pThis->aUuid);
    2223 
    2224     /*
    2225      * RAM sizes
    2226      */
    2227     rc = CFGMR3QueryU64(pCfg, "RamSize", &pThis->cbRam);
    2228     AssertLogRelRCReturn(rc, rc);
    2229     rc = CFGMR3QueryU64(pCfg, "RamHoleSize", &pThis->cbRamHole);
    2230     AssertLogRelRCReturn(rc, rc);
    2231     pThis->cbBelow4GB = RT_MIN(pThis->cbRam, _4G - pThis->cbRamHole);
    2232     pThis->cbAbove4GB = pThis->cbRam - pThis->cbBelow4GB;
    22332218
    22342219    /*
  • trunk/src/VBox/Devices/PC/DevACPI.cpp

    r65843 r65850  
    13371337            *pu32 = pThis->u64PciPref64Max >> 16; /* 64KB units */
    13381338            Assert(((uint64_t)*pu32 << 16) == pThis->u64PciPref64Max);
    1339             LogRel(("MAX\n"));
    13401339            break;
    13411340
     
    31283127    cbXsdt += cAddr*sizeof(uint64_t);  /* each entry: 64 bits phys. address. */
    31293128
    3130     rc = CFGMR3QueryU64(pThis->pDevInsR3->pCfg, "RamSize", &pThis->u64RamSize);
    3131     if (RT_FAILURE(rc))
    3132         return PDMDEV_SET_ERROR(pThis->pDevInsR3, rc,
    3133                                 N_("Configuration error: Querying \"RamSize\" as integer failed"));
    3134 
    3135     uint32_t cbRamHole;
    3136     rc = CFGMR3QueryU32Def(pThis->pDevInsR3->pCfg, "RamHoleSize", &cbRamHole, MM_RAM_HOLE_SIZE_DEFAULT);
    3137     if (RT_FAILURE(rc))
    3138         return PDMDEV_SET_ERROR(pThis->pDevInsR3, rc,
    3139                                 N_("Configuration error: Querying \"RamHoleSize\" as integer failed"));
    3140 
    31413129    /*
    31423130     * Calculate the sizes for the low region and for the 64-bit prefetchable memory.
    3143      * The latter starts never below 4G and is 1G-aligned.
     3131     * The latter starts never below 4G.
    31443132     */
    3145     const uint64_t offRamHole = _4G - cbRamHole;
     3133    PVM pVM                    = PDMDevHlpGetVM(pThis->pDevInsR3);
     3134    uint32_t        cbBelow4GB = MMR3PhysGetRamSizeBelow4GB(pVM);
     3135    uint64_t const  cbAbove4GB = MMR3PhysGetRamSizeAbove4GB(pVM);
     3136
     3137    pThis->u64RamSize = MMR3PhysGetRamSize(pVM);
    31463138    if (pThis->fPciPref64Enabled)
    31473139    {
    3148         /* Activate MEM4 */
    3149         if (pThis->u64RamSize > offRamHole)
    3150             pThis->u64PciPref64Min = RT_ALIGN_64(pThis->u64RamSize + cbRamHole, _1M);
    3151         else
    3152             pThis->u64PciPref64Min = _4G;
    3153     }
    3154     uint64_t cbRamLow = pThis->u64RamSize > offRamHole ? offRamHole : pThis->u64RamSize;
    3155     if (cbRamLow > UINT32_C(0xffe00000)) /* See MEM3. */
     3140        /* Activate MEM4. See also DevPciIch9.cpp / ich9pciFakePCIBIOS() / uPciBiosMmio64 */
     3141        pThis->u64PciPref64Min = _4G + cbAbove4GB;
     3142        LogRel(("ACPI: enabling 64-bit prefetch root bus resource %#018RX64..%#018RX64\n",
     3143               pThis->u64PciPref64Min, pThis->u64PciPref64Max-1));
     3144    }
     3145    if (cbBelow4GB > UINT32_C(0xffe00000)) /* See MEM3. */
    31563146    {
    31573147        /* Note: This is also enforced by DevPcBios.cpp. */
    3158         LogRel(("ACPI: Clipping cbRamLow=%#RX64 down to 0xffe00000.\n", cbRamLow));
    3159         cbRamLow = UINT32_C(0xffe00000);
    3160     }
    3161     pThis->cbRamLow = (uint32_t)cbRamLow;
     3148        LogRel(("ACPI: Clipping cbRamLow=%#RX64 down to 0xffe00000.\n", cbBelow4GB));
     3149        cbBelow4GB = UINT32_C(0xffe00000);
     3150    }
     3151    pThis->cbRamLow = cbBelow4GB;
    31623152
    31633153    GCPhysCur = 0;
     
    35673557     */
    35683558    if (!CFGMR3AreValuesValid(pCfg,
    3569                               "RamSize\0"
    3570                               "RamHoleSize\0"
    35713559                              "IOAPIC\0"
    35723560                              "NumCPUs\0"
     
    35783566                              "McfgLength\0"
    35793567                              "PciPref64Enabled\0"
    3580                               "PciPref64Limit\0"
     3568                              "PciPref64LimitGB\0"
    35813569                              "SmcEnabled\0"
    35823570                              "FdcEnabled\0"
     
    36533641
    36543642    /* query the limit of the the 64-bit prefetchable memory window */
    3655     rc = CFGMR3QueryU64Def(pCfg, "PciPref64Limit", &pThis->u64PciPref64Max, _1G64*64);
     3643    uint64_t u64PciPref64MaxGB;
     3644    rc = CFGMR3QueryU64Def(pCfg, "PciPref64LimitGB", &u64PciPref64MaxGB, 64);
    36563645    if (RT_FAILURE(rc))
    36573646        return PDMDEV_SET_ERROR(pDevIns, rc,
    3658                                 N_("Configuration error: Failed to read \"PciPref64Limit\""));
     3647                                N_("Configuration error: Failed to read \"PciPref64LimitGB\""));
     3648    pThis->u64PciPref64Max = _1G64 * u64PciPref64MaxGB;
    36593649
    36603650    /* query whether we are supposed to present custom table */
  • trunk/src/VBox/Devices/PC/DevFwCommon.cpp

    r64369 r65850  
    820820         * DMI Physical Memory Array (Type 16) *
    821821         ***************************************/
    822         uint64_t u64RamSize;
    823         rc = CFGMR3QueryU64(pCfg, "RamSize", &u64RamSize);
    824         if (RT_FAILURE (rc))
    825             return PDMDEV_SET_ERROR(pDevIns, rc,
    826                                     N_("Configuration error: Failed to read \"RamSize\""));
     822        uint64_t const  cbRamSize = MMR3PhysGetRamSize(PDMDevHlpGetVM(pDevIns));
    827823
    828824        PDMIRAMARRAY pMemArray = (PDMIRAMARRAY)pszStr;
     
    838834        pMemArray->u8Use                 = 0x03;   /* System memory */
    839835        pMemArray->u8MemErrorCorrection  = 0x01;   /* Other */
    840         pMemArray->u32MaxCapacity        = (uint32_t)(u64RamSize / _1K); /* RAM size in K */
     836        if (cbRamSize / _1K > INT32_MAX)
     837        {
     838            /** @todo 2TB-1K limit. In such cases we probably need to provide multiple type-16 descriptors.
     839             * Or use 0x8000'0000 = 'capacity unknown'? */
     840            AssertLogRelMsgFailed(("DMI: RAM size %#RX64 does not fit into type-16 descriptor, clipping to %#RX64\n",
     841                                   cbRamSize, (uint64_t)INT32_MAX * _1K));
     842            pMemArray->u32MaxCapacity    = INT32_MAX;
     843        }
     844        else
     845            pMemArray->u32MaxCapacity    = (int32_t)(cbRamSize / _1K); /* RAM size in K */
    841846        pMemArray->u16MemErrorHandle     = 0xfffe; /* No error info structure */
    842847        pMemArray->u16NumberOfMemDevices = 1;
     
    859864        pMemDev->u16TotalWidth           = 0xffff; /* Unknown */
    860865        pMemDev->u16DataWidth            = 0xffff; /* Unknown */
    861         int16_t u16RamSizeM = (uint16_t)(u64RamSize / _1M);
     866        int16_t u16RamSizeM;
     867        if (cbRamSize / _1M > INT16_MAX)
     868        {
     869            /** @todo 32G-1M limit. Provide multiple type-17 descriptors.
     870             * The highest bit of u16Size must be 0 to specify 'GB' units / 1 would be 'KB' */
     871            AssertLogRelMsgFailed(("DMI: RAM size %#RX64 too big for one type-17 descriptor, clipping to %#RX64\n",
     872                                   cbRamSize, (uint64_t)INT16_MAX * _1M));
     873            u16RamSizeM = INT16_MAX;
     874        }
     875        else
     876            u16RamSizeM = (uint16_t)(cbRamSize / _1M);
    862877        if (u16RamSizeM == 0)
    863878            u16RamSizeM = 0x400; /* 1G */
  • trunk/src/VBox/Devices/PC/DevPcBios.cpp

    r65711 r65850  
    155155    /** Boot devices (ordered). */
    156156    DEVPCBIOSBOOT   aenmBootDevice[4];
    157     /** RAM size (in bytes). */
    158     uint64_t        cbRam;
    159     /** RAM hole size (in bytes). */
    160     uint32_t        cbRamHole;
    161157    /** Bochs shutdown index. */
    162158    uint32_t        iShutdown;
     
    621617    LogFlow(("pcbiosInitComplete:\n"));
    622618
     619    PVM pVM                    = PDMDevHlpGetVM(pDevIns);
     620    uint64_t const  cbRamSize  = MMR3PhysGetRamSize(pVM);
     621    uint32_t const  cbBelow4GB = MMR3PhysGetRamSizeBelow4GB(pVM);
     622    uint64_t const  cbAbove4GB = MMR3PhysGetRamSizeAbove4GB(pVM);
     623
    623624    /*
    624625     * Memory sizes.
    625626     */
    626627    /* base memory. */
    627     u32 = pThis->cbRam > 640 ? 640 : (uint32_t)pThis->cbRam / _1K; /* <-- this test is wrong, but it doesn't matter since we never assign less than 1MB */
    628     pcbiosCmosWrite(pDevIns, 0x15, u32 & 0xff);                                 /* 15h - Base Memory in K, Low Byte */
    629     pcbiosCmosWrite(pDevIns, 0x16, u32 >> 8);                                   /* 16h - Base Memory in K, High Byte */
     628    u32 = cbRamSize > 640 ? 640 : (uint32_t)cbRamSize / _1K; /* <-- this test is wrong, but it doesn't matter since we never assign less than 1MB */
     629    pcbiosCmosWrite(pDevIns, 0x15, u32 & 0xff);     /* 15h - Base Memory in K, Low Byte */
     630    pcbiosCmosWrite(pDevIns, 0x16, u32 >> 8);       /* 16h - Base Memory in K, High Byte */
    630631
    631632    /* Extended memory, up to 65MB */
    632     u32 = pThis->cbRam >= 65 * _1M ? 0xffff : ((uint32_t)pThis->cbRam - _1M) / _1K;
    633     pcbiosCmosWrite(pDevIns, 0x17, u32 & 0xff);                                 /* 17h - Extended Memory in K, Low Byte */
    634     pcbiosCmosWrite(pDevIns, 0x18, u32 >> 8);                                   /* 18h - Extended Memory in K, High Byte */
    635     pcbiosCmosWrite(pDevIns, 0x30, u32 & 0xff);                                 /* 30h - Extended Memory in K, Low Byte */
    636     pcbiosCmosWrite(pDevIns, 0x31, u32 >> 8);                                   /* 31h - Extended Memory in K, High Byte */
     633    u32 = cbRamSize >= 65 * _1M ? 0xffff : ((uint32_t)cbRamSize - _1M) / _1K;
     634    pcbiosCmosWrite(pDevIns, 0x17, u32 & 0xff);     /* 17h - Extended Memory in K, Low Byte */
     635    pcbiosCmosWrite(pDevIns, 0x18, u32 >> 8);       /* 18h - Extended Memory in K, High Byte */
     636    pcbiosCmosWrite(pDevIns, 0x30, u32 & 0xff);     /* 30h - Extended Memory in K, Low Byte */
     637    pcbiosCmosWrite(pDevIns, 0x31, u32 >> 8);       /* 31h - Extended Memory in K, High Byte */
    637638
    638639    /* Bochs BIOS specific? Anyway, it's the amount of memory above 16MB
     
    641642       be adjusted, we still have to chop it at 0xfffc0000 or it'll conflict
    642643       with the high BIOS mapping.) */
    643     uint64_t const offRamHole = _4G - pThis->cbRamHole;
    644     if (pThis->cbRam > 16 * _1M)
    645         u32 = (uint32_t)( (RT_MIN(RT_MIN(pThis->cbRam, offRamHole), UINT32_C(0xffe00000)) - 16U * _1M) / _64K );
     644    if (cbRamSize > 16 * _1M)
     645        u32 = (RT_MIN(cbBelow4GB, UINT32_C(0xffe00000)) - 16U * _1M) / _64K;
    646646    else
    647647        u32 = 0;
     
    652652       Bochs got these in a different location which we've already used for SATA,
    653653       it also lacks the last two. */
    654     uint64_t c64KBAbove4GB;
    655     if (pThis->cbRam <= offRamHole)
    656         c64KBAbove4GB = 0;
    657     else
    658     {
    659         c64KBAbove4GB = (pThis->cbRam - offRamHole) / _64K;
    660         /* Make sure it doesn't hit the limits of the current BIOS code. */
    661         AssertLogRelMsgReturn((c64KBAbove4GB >> (3 * 8)) < 255, ("%#RX64\n", c64KBAbove4GB), VERR_OUT_OF_RANGE);
    662     }
     654    uint64_t c64KBAbove4GB = cbAbove4GB / _64K;
     655    /* Make sure it doesn't hit the limits of the current BIOS code (RAM limit of ~255TB). */
     656    AssertLogRelMsgReturn((c64KBAbove4GB >> (3 * 8)) < 255, ("%#RX64\n", c64KBAbove4GB), VERR_OUT_OF_RANGE);
    663657    pcbiosCmosWrite(pDevIns, 0x61,  c64KBAbove4GB        & 0xff);
    664658    pcbiosCmosWrite(pDevIns, 0x62, (c64KBAbove4GB >>  8) & 0xff);
     
    10971091                              "BootDevice2\0"
    10981092                              "BootDevice3\0"
    1099                               "RamSize\0"
    1100                               "RamHoleSize\0"
    11011093                              "HardDiskDevice\0"
    11021094                              "SataHardDiskDevice\0"
     
    11631155     * Init the data.
    11641156     */
    1165     rc = CFGMR3QueryU64(pCfg, "RamSize", &pThis->cbRam);
    1166     if (RT_FAILURE(rc))
    1167         return PDMDEV_SET_ERROR(pDevIns, rc,
    1168                                 N_("Configuration error: Querying \"RamSize\" as integer failed"));
    1169 
    1170     rc = CFGMR3QueryU32Def(pCfg, "RamHoleSize", &pThis->cbRamHole, MM_RAM_HOLE_SIZE_DEFAULT);
    1171     if (RT_FAILURE(rc))
    1172         return PDMDEV_SET_ERROR(pDevIns, rc,
    1173                                 N_("Configuration error: Querying \"RamHoleSize\" as integer failed"));
    1174 
    11751157    rc = CFGMR3QueryU16Def(pCfg, "NumCPUs", &pThis->cCpus, 1);
    11761158    if (RT_FAILURE(rc))
  • trunk/src/VBox/Devices/VMMDev/VMMDev.cpp

    r65712 r65850  
    40184018                                  "KeepCredentials|"
    40194019                                  "HeapEnabled|"
    4020                                   "RamSize|"
    40214020                                  "RZEnabled|"
    40224021                                  "GuestCoreDumpEnabled|"
     
    40304029                                  ,
    40314030                                  "");
    4032 
    4033     rc = CFGMR3QueryU64(pCfg, "RamSize", &pThis->cbGuestRAM);
    4034     if (RT_FAILURE(rc))
    4035         return PDMDEV_SET_ERROR(pDevIns, rc,
    4036                                 N_("Configuration error: Failed querying \"RamSize\" as a 64-bit unsigned integer"));
    40374031
    40384032    rc = CFGMR3QueryBoolDef(pCfg, "GetHostTimeDisabled", &pThis->fGetHostTimeDisabled, false);
     
    41154109    /** @todo image-to-load-filename? */
    41164110#endif
     4111
     4112    pThis->cbGuestRAM = MMR3PhysGetRamSize(PDMDevHlpGetVM(pDevIns));
    41174113
    41184114    /*
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r65843 r65850  
    16841684            InsertConfigInteger(pInst, "Trusted",              1); /* boolean */
    16851685            InsertConfigNode(pInst,    "Config", &pBiosCfg);
    1686             InsertConfigInteger(pBiosCfg,  "RamSize",              cbRam);
    1687             InsertConfigInteger(pBiosCfg,  "RamHoleSize",          cbRamHole);
    16881686            InsertConfigInteger(pBiosCfg,  "NumCPUs",              cCpus);
    16891687            InsertConfigString(pBiosCfg,   "HardDiskDevice",       "piix3ide");
     
    17881786            InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
    17891787            InsertConfigNode(pInst,    "Config", &pCfg);
    1790             InsertConfigInteger(pCfg,  "RamSize",          cbRam);
    1791             InsertConfigInteger(pCfg,  "RamHoleSize",      cbRamHole);
    17921788            InsertConfigInteger(pCfg,  "NumCPUs",          cCpus);
    17931789            InsertConfigString(pCfg,   "EfiRom",           efiRomFile);
     
    27652761        Bstr hwVersion;
    27662762        hrc = pMachine->COMGETTER(HardwareVersion)(hwVersion.asOutParam());                 H();
    2767         InsertConfigInteger(pCfg, "RamSize",              cbRam);
    27682763        if (hwVersion.compare(Bstr("1").raw()) == 0) /* <= 2.0.x */
    27692764            InsertConfigInteger(pCfg, "HeapEnabled", 0);
     
    31993194            hrc = pBusMgr->assignPCIDevice("acpi", pInst);                                  H();
    32003195
    3201             InsertConfigInteger(pCfg,  "RamSize",          cbRam);
    3202             InsertConfigInteger(pCfg,  "RamHoleSize",      cbRamHole);
    32033196            InsertConfigInteger(pCfg,  "NumCPUs",          cCpus);
    32043197
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette