VirtualBox

Changeset 25838 in vbox


Ignore:
Timestamp:
Jan 14, 2010 4:55:55 PM (15 years ago)
Author:
vboxsync
Message:

Address todos (changes the protocol for CPU ejection) and make it possible to load a ACPI DSDT from an external AML file

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmapi.h

    r25825 r25838  
    407407VMMR3DECL(RTNATIVETHREAD)   VMR3GetVMCPUNativeThread(PVM pVM);
    408408VMMR3DECL(RTNATIVETHREAD)   VMR3GetVMCPUNativeThreadU(PUVM pUVM);
    409 VMMR3DECL(int)              VMR3GetCPUCoreAndPackageIdFromCPUId(PVM pVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage);
    410 VMMR3DECL(int)              VMR3HotunplugCPU(PVM pVM, VMCPUID idCpu);
    411 VMMR3DECL(int)              VMR3HotplugCPU(PVM pVM, VMCPUID idCpu);
     409VMMR3DECL(int)              VMR3GetCpuCoreAndPackageIdFromCpuId(PVM pVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage);
     410VMMR3DECL(int)              VMR3HotUnplugCpu(PVM pVM, VMCPUID idCpu);
     411VMMR3DECL(int)              VMR3HotPlugCpu(PVM pVM, VMCPUID idCpu);
    412412
    413413/** @} */
  • trunk/src/VBox/Devices/Makefile.kmk

    r25825 r25838  
    471471 vboxaml.hex:: $$(PATH_DevicesR3)/vboxaml.hex
    472472
    473  # CPU hot-plug version
    474  DevicesR3_CLEAN        += $(PATH_DevicesR3)/vboxaml-cpuhotplug.hex $(PATH_DevicesR3)/vboxaml-cpuhotplug.hex.tmp $(PATH_DevicesR3)/vboxaml-cpuhotplug.aml
    475  PC/ACPI/VBoxAcpi.cpp_DEPS += $(PATH_DevicesR3)/vboxaml-cpuhotplug.hex
    476 
    477  $$(PATH_DevicesR3)/vboxaml-cpuhotplug.hex: $(PATH_SUB_CURRENT)/PC/vbox-cpuhotplug.dsl | $$(dir $$@)
    478         $(call MSG_TOOL,iasl,DevicesR3,$<,$@)
    479         $(QUIET)$(RM) -f $@ [email protected]
    480         $(QUIET)$(VBOX_IASLCMD) -tc -vs -p $@ $<
    481         $(QUIET)$(MV) -f $@ [email protected]
    482         $(QUIET)$(SED) -e 's/AmlCode/AmlCodeCpuHotplug/' \
    483                 --output $@ [email protected]
    484         $(QUIET)$(RM) -f [email protected]
    485 
    486 
    487  vboxaml-cpuhotplug.hex:: $$(PATH_DevicesR3)/vboxaml-cpuhotplug.hex
    488 
    489473endif # !VBOX_WITH_DYNAMIC_DSDT
    490474PC/ACPI/VBoxAcpi.cpp_INCS = $(PATH_DevicesR3)
  • trunk/src/VBox/Devices/PC/ACPI/VBoxAcpi.cpp

    r25825 r25838  
    3030#include <VBox/param.h>
    3131#include <VBox/cfgm.h>
     32#include <VBox/mm.h>
    3233#include <iprt/assert.h>
    3334#include <iprt/alloc.h>
    3435#include <iprt/string.h>
     36#include <iprt/file.h>
    3537
    3638#ifdef VBOX_WITH_DYNAMIC_DSDT
     
    4042/* Statically compiled AML */
    4143# include <vboxaml.hex>
    42 # include <vboxaml-cpuhotplug.hex>
    4344#endif
    4445
     
    142143    return prepareDynamicDsdt(pDevIns, ppPtr, puDsdtLen);
    143144#else
    144     unsigned char *pbAmlCode = NULL;
     145    uint8_t *pbAmlCode = NULL;
    145146    size_t cbAmlCode = 0;
    146     bool fCpuHotPlug = false;
    147     int rc = CFGMR3QueryBoolDef(pDevIns->pCfgHandle, "CpuHotplug", &fCpuHotPlug, false); /** @todo r=bird: Rename to CpuHotPlug. */
    148     if (RT_FAILURE(rc))
     147    char *pszAmlFilePath = NULL;
     148    int rc = CFGMR3QueryStringAlloc(pDevIns->pCfgHandle, "AmlFilePath", &pszAmlFilePath);
     149    if (RT_SUCCESS(rc))
     150    {
     151        /* Load from file. */
     152        RTFILE FileAml = NIL_RTFILE;
     153
     154        rc = RTFileOpen(&FileAml, pszAmlFilePath, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE);
     155        if (RT_SUCCESS(rc))
     156        {
     157            /*
     158             * An AML file contains the raw DSDT thus the size of the file
     159             * is equal to the size of the DSDT.
     160             */
     161            uint64_t cbAmlFile = 0;
     162            rc = RTFileGetSize(FileAml, &cbAmlFile);
     163
     164            cbAmlCode = (size_t)cbAmlFile;
     165
     166            /* Don't use AML files over 4GB ;) */
     167            if (   RT_SUCCESS(rc)
     168                && ((uint64_t)cbAmlCode == cbAmlFile))
     169            {
     170                pbAmlCode = (uint8_t *)RTMemAllocZ(cbAmlCode);
     171                if (pbAmlCode)
     172                {
     173                    rc = RTFileReadAt(FileAml, 0, pbAmlCode, cbAmlCode, NULL);
     174
     175                    /*
     176                     * We fail if reading failed or the identifier at the
     177                     * beginning is wrong.
     178                     */
     179                    if (   RT_FAILURE(rc)
     180                        || strncmp((const char *)pbAmlCode, "DSDT", 4))
     181                    {
     182                        RTMemFree(pbAmlCode);
     183                        pbAmlCode = NULL;
     184
     185                        /* Return error if file header check failed */
     186                        if (RT_SUCCESS(rc))
     187                            rc = VERR_PARSE_ERROR;
     188                    }
     189                }
     190                else
     191                    rc = VERR_NO_MEMORY;
     192            }
     193
     194            RTFileClose(FileAml);
     195        }
     196        MMR3HeapFree(pszAmlFilePath);
     197    }
     198    else if (rc == VERR_CFGM_VALUE_NOT_FOUND)
     199    {
     200        rc = VINF_SUCCESS;
     201
     202        /* Use the compiled in AML code */
     203        cbAmlCode = sizeof(AmlCode);
     204        pbAmlCode = (uint8_t *)RTMemAllocZ(cbAmlCode);
     205        if (pbAmlCode)
     206            memcpy(pbAmlCode, AmlCode, cbAmlCode);
     207        else
     208            rc = VERR_NO_MEMORY;
     209    }
     210    else if (RT_FAILURE(rc))
    149211        return PDMDEV_SET_ERROR(pDevIns, rc,
    150                                 N_("Configuration error: Failed to read \"CpuHotplug\""));
    151 
    152     if (fCpuHotPlug)
    153     {
    154         pbAmlCode = AmlCodeCpuHotplug;
    155         cbAmlCode = sizeof(AmlCodeCpuHotplug);
    156     }
    157     else
    158     {
    159         pbAmlCode = AmlCode;
    160         cbAmlCode = sizeof(AmlCode);
    161     }
    162 
    163     patchAml(pDevIns, pbAmlCode, cbAmlCode);
    164     *ppPtr = pbAmlCode;
    165     *puDsdtLen = cbAmlCode;
    166     return 0;
     212                                N_("Configuration error: Failed to read \"AmlFilePath\""));
     213
     214    if (RT_SUCCESS(rc))
     215    {
     216        patchAml(pDevIns, pbAmlCode, cbAmlCode);
     217        *ppPtr = pbAmlCode;
     218        *puDsdtLen = cbAmlCode;
     219    }
     220    return rc;
    167221#endif
    168222}
     
    173227    return cleanupDynamicDsdt(pDevIns, pPtr);
    174228#else
    175     /* Do nothing */
    176     return 0;
    177 #endif
    178 }
    179 
     229    if (pPtr)
     230        RTMemFree(pPtr);
     231    return VINF_SUCCESS;
     232#endif
     233}
     234
  • trunk/src/VBox/Devices/PC/DevACPI.cpp

    r25825 r25838  
    150150    SYSTEM_INFO_INDEX_RTC_STATUS        = 10,
    151151    SYSTEM_INFO_INDEX_CPU_LOCKED        = 11,
    152     SYSTEM_INFO_INDEX_MADT_ADDR         = 12,
    153     SYSTEM_INFO_INDEX_MADT_SIZE         = 13,
    154     SYSTEM_INFO_INDEX_END               = 14,
     152    SYSTEM_INFO_INDEX_CPU_LOCK_CHECK    = 12,
     153    SYSTEM_INFO_INDEX_MADT_ADDR         = 13,
     154    SYSTEM_INFO_INDEX_MADT_SIZE         = 14,
     155    SYSTEM_INFO_INDEX_END               = 15,
    155156    SYSTEM_INFO_INDEX_INVALID           = 0x80,
    156157    SYSTEM_INFO_INDEX_VALID             = 0x200
     
    238239    uint32_t            cbMADT;
    239240    /** Array of flags of attached CPUs */
    240     bool                afCpuAttached[VMM_MAX_CPU_COUNT]; /**< @todo use VMCPUSET.  */
     241    VMCPUSET            CpuSetAttached;
     242    /** Which CPU to check for the locked status. */
     243    uint32_t            idCpuLockCheck;
    241244    /** Mask of locked CPUs (used by the guest) */
    242     uint32_t            uCpusLocked;                      /**< @todo use VMCPUSET. */
     245    VMCPUSET            CpuSetLocked;
    243246    /** Flag whether CPU hot plugging is enabled */
    244247    bool                fCpuHotPlug;
     
    847850        lapic->u8ProcId    = i;
    848851        lapic->u8ApicId    = i;
    849         lapic->u32Flags    = s->afCpuAttached[i] ? RT_H2LE_U32(LAPIC_ENABLED) : 0;
     852        lapic->u32Flags    = VMCPUSET_IS_PRESENT(&s->CpuSetAttached, i) ? RT_H2LE_U32(LAPIC_ENABLED) : 0;
    850853        lapic++;
    851854    }
     
    986989{
    987990    ACPIState *s = IACPIPORT_2_ACPISTATE(pInterface);
    988     *pfLocked = (s->uCpusLocked & RT_BIT(uCpu)) != 0;
     991    *pfLocked = VMCPUSET_IS_PRESENT(&s->CpuSetLocked, uCpu);
    989992    return VINF_SUCCESS;
    990993}
     
    14061409                  *pu32 = s->fShowCpu
    14071410                    && s->uSystemInfoIndex - SYSTEM_INFO_INDEX_CPU0_STATUS < s->cCpus
    1408                     && s->afCpuAttached[s->uSystemInfoIndex - SYSTEM_INFO_INDEX_CPU0_STATUS]
     1411                    && VMCPUSET_IS_PRESENT(&s->CpuSetAttached, s->uSystemInfoIndex - SYSTEM_INFO_INDEX_CPU0_STATUS)
    14091412                    ?
    14101413                      STA_DEVICE_PRESENT_MASK
     
    14241427                case SYSTEM_INFO_INDEX_CPU_LOCKED:
    14251428                {
    1426                     *pu32 = s->uCpusLocked;
     1429                    if (s->idCpuLockCheck != UINT32_C(0xffffffff))
     1430                    {
     1431                        *pu32 = VMCPUSET_IS_PRESENT(&s->CpuSetLocked, s->idCpuLockCheck) ? 1 : 0;
     1432                        s->idCpuLockCheck = UINT32_C(0xffffffff); /* Make the entry invalid */
     1433                    }
     1434                    else
     1435                    {
     1436                        AssertMsgFailed(("ACPI: CPU lock check protocol violation\n"));
     1437                        /* Always return locked status just to be safe */
     1438                        *pu32 = 1;
     1439                    }
    14271440                    break;
    14281441                }
     
    14791492                break;
    14801493
     1494            case SYSTEM_INFO_INDEX_CPU_LOCK_CHECK:
     1495                if (u32 < s->cCpus)
     1496                    s->idCpuLockCheck = u32;
     1497                else
     1498                    LogRel(("ACPI: CPU %u does not exist\n", u32));
    14811499            case SYSTEM_INFO_INDEX_CPU_LOCKED:
    1482                 s->uCpusLocked &= ~u32; /* Unlock the CPU */
     1500                if (u32 < s->cCpus)
     1501                    VMCPUSET_DEL(&s->CpuSetLocked, u32); /* Unlock the CPU */
     1502                else
     1503                    LogRel(("ACPI: CPU %u does not exist\n", u32));
    14831504                break;
    14841505
     
    20802101
    20812102    /* Check if it was already attached */
    2082     if (s->afCpuAttached[iLUN])
     2103    if (VMCPUSET_IS_PRESENT(&s->CpuSetAttached, iLUN))
    20832104        return VINF_SUCCESS;
    20842105
     
    20892110    {
    20902111        /* Enable the CPU */
    2091         s->afCpuAttached[iLUN] = true;
    2092 
    2093         /* Enable the lapic */
    2094         acpiSetupMADT(s, s->GCPhysMADTBase);
     2112        VMCPUSET_ADD(&s->CpuSetAttached, iLUN);
     2113
    20952114        /*
    20962115         * Lock the CPU because we don't know if the guest will use it or not.
    20972116         * Prevents ejection while the CPU is still used
    20982117         */
    2099         s->uCpusLocked |= RT_BIT(iLUN);
     2118        VMCPUSET_ADD(&s->CpuSetLocked, iLUN);
     2119
     2120        /* Enable the lapic */
     2121        acpiSetupMADT(s, s->GCPhysMADTBase);
    21002122
    21012123        /* Notify the guest */
     
    21192141
    21202142    /* Check if it was already detached */
    2121     if (s->afCpuAttached[iLUN])
    2122     {
     2143    if (VMCPUSET_IS_PRESENT(&s->CpuSetAttached, iLUN))
     2144    {
     2145        AssertMsgReturnVoid(!(VMCPUSET_IS_PRESENT(&s->CpuSetLocked, iLUN)), ("CPU is still locked by the guest\n"));
     2146
    21232147        /* Disable the CPU */
    2124         s->afCpuAttached[iLUN] = false;
    2125 
    2126         AssertMsg(!(s->uCpusLocked & RT_BIT(iLUN)), ("CPU is still locked by the guest\n"));
     2148        VMCPUSET_DEL(&s->CpuSetAttached, iLUN);
    21272149
    21282150        /* Update the lapic state */
     
    21952217                              "ShowRtc\0"
    21962218                              "ShowCpu\0"
    2197                               "CpuHotplug\0" /** @todo r=bird: Rename to CpuHotPlug. */
     2219                              "CpuHotPlug\0"
     2220                              "AmlFilePath\0"
    21982221                              ))
    21992222        return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
     
    22432266
    22442267    /* query whether we are allow CPU hot plugging */
    2245     rc = CFGMR3QueryBoolDef(pCfgHandle, "CpuHotplug", &s->fCpuHotPlug, false); /** @todo r=bird: Rename to CpuHotPlug. */
     2268    rc = CFGMR3QueryBoolDef(pCfgHandle, "CpuHotPlug", &s->fCpuHotPlug, false);
    22462269    if (RT_FAILURE(rc))
    22472270        return PDMDEV_SET_ERROR(pDevIns, rc,
    2248                                 N_("Configuration error: Failed to read \"CpuHotplug\""));
     2271                                N_("Configuration error: Failed to read \"CpuHotPlug\""));
    22492272
    22502273    rc = CFGMR3QueryBool(pCfgHandle, "GCEnabled", &s->fGCEnabled);
     
    22742297    s->IACPIPort.pfnGetCpuStatus            = acpiGetCpuStatus;
    22752298
     2299    VMCPUSET_EMPTY(&s->CpuSetAttached);
     2300    VMCPUSET_EMPTY(&s->CpuSetLocked);
     2301    s->idCpuLockCheck = UINT32_C(0xffffffff);
     2302
    22762303    /* The first CPU can't be attached/detached */
    2277     s->afCpuAttached[0] = true;
    2278     s->uCpusLocked |= RT_BIT(0);
     2304    VMCPUSET_ADD(&s->CpuSetAttached, 0);
     2305    VMCPUSET_ADD(&s->CpuSetLocked, 0);
    22792306
    22802307    /* Try to attach the other CPUs */
     
    22882315            if (RT_SUCCESS(rc))
    22892316            {
    2290                 s->afCpuAttached[i] = true;
    2291                 s->uCpusLocked |= RT_BIT(i);
     2317                VMCPUSET_ADD(&s->CpuSetAttached, i);
     2318                VMCPUSET_ADD(&s->CpuSetLocked, i);
    22922319                Log(("acpi: Attached CPU %u\n", i));
    22932320            }
    22942321            else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
    2295             {
    22962322                Log(("acpi: CPU %u not attached yet\n", i));
    2297                 s->afCpuAttached[i] = false;
    2298             }
    22992323            else
    23002324                return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to attach CPU object\n"));
     
    23032327        {
    23042328            /* CPU is always attached if hot-plug is not enabled. */
    2305             s->afCpuAttached[i] = true;
    2306             s->uCpusLocked |= RT_BIT(i);
     2329            VMCPUSET_ADD(&s->CpuSetAttached, i);
     2330            VMCPUSET_ADD(&s->CpuSetLocked, i);
    23072331        }
    23082332    }
  • trunk/src/VBox/Devices/testcase/tstDeviceStructSizeGC.cpp

    r25825 r25838  
    466466    GEN_CHECK_OFF(ACPIState, fUseSmc);
    467467    GEN_CHECK_OFF(ACPIState, GCPhysMADTBase);
    468     GEN_CHECK_OFF(ACPIState, afCpuAttached);
    469     GEN_CHECK_OFF(ACPIState, uCpusLocked);
     468    GEN_CHECK_OFF(ACPIState, CpuSetAttached);
     469    GEN_CHECK_OFF(ACPIState, idCpuLockCheck);
     470    GEN_CHECK_OFF(ACPIState, CpuSetLocked);
    470471    GEN_CHECK_OFF(ACPIState, fCpuHotPlug);
    471472    GEN_CHECK_OFF(ACPIState, IBase);
  • trunk/src/VBox/VMM/VM.cpp

    r25825 r25838  
    40524052 * @param   pidCpuPackage    Where to store the package ID of the virtual CPU.
    40534053 *
    4054  * @todo    r=bird: Rename to VMR3GetCpuCoreAndPackageIdFromCpuId. We currently
    4055  *          try avoid holding down the shift key, so 'Cpu' is favored over 'CPU'
    4056  *          now.
    4057  */
    4058 VMMR3DECL(int) VMR3GetCPUCoreAndPackageIdFromCPUId(PVM pVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage)
     4054 */
     4055VMMR3DECL(int) VMR3GetCpuCoreAndPackageIdFromCpuId(PVM pVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage)
    40594056{
    40604057    if (idCpu >= pVM->cCpus)
     
    41094106 * @param   pVM     The VM to operate on.
    41104107 * @param   idCpu   Virtual CPU to perform the hot unplugging operation on.
    4111  * @todo r=bird:  Rename to VMR3HotUnplugCpu.
    4112  */
    4113 VMMR3DECL(int) VMR3HotunplugCPU(PVM pVM, VMCPUID idCpu)
     4108 */
     4109VMMR3DECL(int) VMR3HotUnplugCpu(PVM pVM, VMCPUID idCpu)
    41144110{
    41154111    AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID);
    41164112
    4117     /** @todo Destroy EMT and not needed resources. */
    41184113    /** @todo r=bird: Don't destroy the EMT, it'll break VMMR3EmtRendezvous and
    41194114     *        broadcast requests.  Just note down somewhere that the CPU is
     
    41304125 * @param   pVM     The VM to operate on.
    41314126 * @param   idCpu   Virtual CPU to perform the hot plugging operation on.
    4132  * @todo r=bird: Rename to VMR3HotPlugCpu.
    4133  */
    4134 VMMR3DECL(int) VMR3HotplugCPU(PVM pVM, VMCPUID idCpu)
     4127 */
     4128VMMR3DECL(int) VMR3HotPlugCpu(PVM pVM, VMCPUID idCpu)
    41354129{
    41364130    AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID);
    41374131
    4138     /** @todo start EMT and allocate needed resources. */
    41394132    /** @todo r-bird: Just mark it online and make sure it waits on SPIP. */
    41404133    return VINF_SUCCESS;
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