VirtualBox

Changeset 32189 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Sep 2, 2010 10:10:47 AM (14 years ago)
Author:
vboxsync
Message:

DevACPI/PDMDevHlpVMSuspendSaveAndPowerOff.

Location:
trunk/src/VBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/DevACPI.cpp

    r31963 r32189  
    213213    uint32_t            cbRamLow;
    214214
    215     /** Current ACPI S* state. We support S0 and S5 */
     215    /** Current ACPI S* state. We support S0 and S5. */
    216216    uint32_t            uSleepState;
    217217    uint8_t             au8RSDPPage[0x1000];
     
    248248    /** Which CPU to check for the locked status. */
    249249    uint32_t            idCpuLockCheck;
    250     /** Mask of locked CPUs (used by the guest) */
     250    /** Mask of locked CPUs (used by the guest). */
    251251    VMCPUSET            CpuSetLocked;
    252     /** The CPU event type */
     252    /** The CPU event type. */
    253253    uint32_t            u32CpuEventType;
    254     /** The CPU id affected */
     254    /** The CPU id affected. */
    255255    uint32_t            u32CpuEvent;
    256     /** Flag whether CPU hot plugging is enabled */
     256    /** Flag whether CPU hot plugging is enabled. */
    257257    bool                fCpuHotPlug;
    258     /** Primary NIC PCI address */
     258    /** Primary NIC PCI address. */
    259259    uint32_t            u32NicPciAddress;
    260     /** Primary audio card PCI address */
     260    /** Primary audio card PCI address. */
    261261    uint32_t            u32AudioPciAddress;
    262     /** Flag whether S1 power state is enabled */
     262    /** Flag whether S1 power state is enabled. */
    263263    bool                fS1Enabled;
    264     /** Flag whether S4 power state is enabled */
     264    /** Flag whether S4 power state is enabled. */
    265265    bool                fS4Enabled;
    266     /** Flag whether S1 triggers a state save */
    267     bool                fSuspendToDisk;
    268 //    uint32_t            u32Pad0;
     266    /** Flag whether S1 triggers a state save. */
     267    bool                fSuspendToSavedState;
     268    /** Flag whether to set WAK_STS on resume (restore included). */
     269    bool                fSetWakeupOnResume;
    269270
    270271    /** ACPI port base interface. */
     
    274275    /** Pointer to the device instance. */
    275276    PPDMDEVINSR3        pDevIns;
    276     /** Pointer to the driver base interface */
     277    /** Pointer to the driver base interface. */
    277278    R3PTRTYPE(PPDMIBASE) pDrvBase;
    278     /** Pointer to the driver connector interface */
     279    /** Pointer to the driver connector interface. */
    279280    R3PTRTYPE(PPDMIACPICONNECTOR) pDrv;
    280281
    281     /* Pointer to default PCI config read function */
     282    /** Pointer to default PCI config read function. */
    282283    R3PTRTYPE(PFNPCICONFIGREAD)   pfnAcpiPciConfigRead;
    283     /* Pointer to default PCI config write function */
     284    /** Pointer to default PCI config write function. */
    284285    R3PTRTYPE(PFNPCICONFIGWRITE)  pfnAcpiPciConfigWrite;
    285286} ACPIState;
     
    10521053}
    10531054
    1054 static int acpiSleep(ACPIState *s)
     1055static int acpiSleep(ACPIState *pThis)
    10551056{
    10561057    int rc;
    1057     /* First pause the VM to stop it executing. Note that failures aren't fatal, we can
    1058      * just continue the guest as if it was immediately resumed.
    1059      */
    1060     rc = PDMDevHlpVMSuspend(s->pDevIns);    /* This is VM pause, not really ACPI suspend. */
    1061 
    1062     /* The guest was probably reading the PMSTS register in a loop. The resume flag must
    1063      * be set before continuing in any way - needs to be part of saved state.
    1064      */
    1065     s->pm1a_sts |= WAK_STS;
    1066 
    1067     if (RT_FAILURE(rc))
    1068         AssertMsgFailed(("Could not pause the VM. rc = %Rrc\n", rc));
    1069 
    1070     if (s->fSuspendToDisk) {
    1071 //        rc = PDMDevHlpVMSuspendToDisk(s->pDevIns);
    1072         if (RT_FAILURE(rc))
    1073             AssertMsgFailed(("Could not save VM state. rc = %Rrc\n", rc));       
     1058
     1059    /* We must set WAK_STS on resume (includes restore) so the guest knows that
     1060       we've woken up and can continue executing code.  The guest is probably
     1061       reading the PMSTS register in a loop to check this. */
     1062    pThis->fSetWakeupOnResume = true;
     1063    if (pThis->fSuspendToSavedState)
     1064    {
     1065        rc = PDMDevHlpVMSuspendSaveAndPowerOff(pThis->pDevIns);
     1066        AssertRC(rc);
     1067    }
     1068    else
     1069    {
     1070        rc = PDMDevHlpVMSuspend(pThis->pDevIns);
     1071        AssertRC(rc);
    10741072    }
    10751073    return rc;
     
    20052003};
    20062004
    2007 
    2008 static DECLCALLBACK(int) acpi_save_state(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
    2009 {
    2010     ACPIState *s = PDMINS_2_DATA(pDevIns, ACPIState *);
    2011     return SSMR3PutStruct(pSSMHandle, s, &g_AcpiSavedStateFields5[0]);
    2012 }
    2013 
    2014 static DECLCALLBACK(int) acpi_load_state(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle,
    2015                                          uint32_t uVersion, uint32_t uPass)
    2016 {
    2017     ACPIState *s = PDMINS_2_DATA(pDevIns, ACPIState *);
    2018 
     2005/**
     2006 * Saved state structure description, version 6.
     2007 */
     2008static const SSMFIELD g_AcpiSavedStateFields6[] =
     2009{
     2010    SSMFIELD_ENTRY(ACPIState, pm1a_en),
     2011    SSMFIELD_ENTRY(ACPIState, pm1a_sts),
     2012    SSMFIELD_ENTRY(ACPIState, pm1a_ctl),
     2013    SSMFIELD_ENTRY(ACPIState, pm_timer_initial),
     2014    SSMFIELD_ENTRY(ACPIState, gpe0_en),
     2015    SSMFIELD_ENTRY(ACPIState, gpe0_sts),
     2016    SSMFIELD_ENTRY(ACPIState, uBatteryIndex),
     2017    SSMFIELD_ENTRY(ACPIState, uSystemInfoIndex),
     2018    SSMFIELD_ENTRY(ACPIState, uSleepState),
     2019    SSMFIELD_ENTRY(ACPIState, u8IndexShift),
     2020    SSMFIELD_ENTRY(ACPIState, uPmIoPortBase),
     2021    SSMFIELD_ENTRY(ACPIState, fSuspendToSavedState),
     2022    SSMFIELD_ENTRY_TERM()
     2023};
     2024
     2025
     2026/**
     2027 * @callback_method_impl{FNSSMDEVSAVEEXEC}
     2028 */
     2029static DECLCALLBACK(int) acpiSaveState(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
     2030{
     2031    ACPIState *pThis = PDMINS_2_DATA(pDevIns, ACPIState *);
     2032    return SSMR3PutStruct(pSSMHandle, pThis, &g_AcpiSavedStateFields6[0]);
     2033}
     2034
     2035/**
     2036 * @callback_method_impl{FNSSMDEVLOADEXEC}
     2037 */
     2038static DECLCALLBACK(int) acpiLoadState(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle,
     2039                                       uint32_t uVersion, uint32_t uPass)
     2040{
     2041    ACPIState *pThis = PDMINS_2_DATA(pDevIns, ACPIState *);
    20192042    Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
     2043
    20202044    /*
    2021      * Unregister PM handlers, will register with actual base
    2022      * after state successfully loaded.
     2045     * Unregister PM handlers, will register with actual base after state
     2046     * successfully loaded.
    20232047     */
    2024     int rc = acpiUnregisterPmHandlers(s);
     2048    int rc = acpiUnregisterPmHandlers(pThis);
    20252049    if (RT_FAILURE(rc))
    20262050        return rc;
     
    20292053    {
    20302054        case 4:
    2031             rc = SSMR3GetStruct(pSSMHandle, s, &g_AcpiSavedStateFields4[0]);
    2032             /** @todo Provide saner defaults for fields not found in saved state. */
     2055            rc = SSMR3GetStruct(pSSMHandle, pThis, &g_AcpiSavedStateFields4[0]);
    20332056            break;
    20342057        case 5:
    2035             rc = SSMR3GetStruct(pSSMHandle, s, &g_AcpiSavedStateFields5[0]);
     2058            rc = SSMR3GetStruct(pSSMHandle, pThis, &g_AcpiSavedStateFields5[0]);
     2059            break;
     2060        case 6:
     2061            rc = SSMR3GetStruct(pSSMHandle, pThis, &g_AcpiSavedStateFields6[0]);
    20362062            break;
    20372063        default:
    2038             return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
     2064            rc = VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
     2065            break;
    20392066    }
    20402067    if (RT_SUCCESS(rc))
    20412068    {
    2042         rc = acpiRegisterPmHandlers(s);
     2069        rc = acpiRegisterPmHandlers(pThis);
    20432070        if (RT_FAILURE(rc))
    20442071            return rc;
    2045         rc = acpiFetchBatteryStatus(s);
     2072        rc = acpiFetchBatteryStatus(pThis);
    20462073        if (RT_FAILURE(rc))
    20472074            return rc;
    2048         rc = acpiFetchBatteryInfo(s);
     2075        rc = acpiFetchBatteryInfo(pThis);
    20492076        if (RT_FAILURE(rc))
    20502077            return rc;
    2051         rc = acpiPMTimerReset(s);
     2078        rc = acpiPMTimerReset(pThis);
    20522079        if (RT_FAILURE(rc))
    20532080            return rc;
     
    23512378}
    23522379
     2380/**
     2381 * @interface_method_impl{PDMDEVREG,pfnResume}
     2382 */
     2383static DECLCALLBACK(void) acpiResume(PPDMDEVINS pDevIns)
     2384{
     2385    ACPIState *pThis = PDMINS_2_DATA(pDevIns, ACPIState *);
     2386    if (pThis->fSetWakeupOnResume)
     2387    {
     2388        Log(("acpiResume: setting WAK_STS\n"));
     2389        pThis->fSetWakeupOnResume = false;
     2390        pThis->pm1a_sts |= WAK_STS;
     2391    }
     2392}
     2393
     2394/**
     2395 * @interface_method_impl{PDMDEVREG,pfnReset}
     2396 */
    23532397static DECLCALLBACK(void) acpiReset(PPDMDEVINS pDevIns)
    23542398{
     
    23732417
    23742418/**
    2375  * Relocates the GC pointer members.
     2419 * @interface_method_impl{PDMDEVREG,pfnRelocate}
    23762420 */
    23772421static DECLCALLBACK(void) acpiRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
     
    24812525
    24822526    /* query whether S1 power state should save the VM state */
    2483     rc = CFGMR3QueryBoolDef(pCfg, "EnableSuspendToDisk", &s->fSuspendToDisk, false);
     2527    rc = CFGMR3QueryBoolDef(pCfg, "EnableSuspendToDisk", &s->fSuspendToSavedState, false);
    24842528    if (RT_FAILURE(rc))
    24852529        return PDMDEV_SET_ERROR(pDevIns, rc,
     
    26592703                                   acpiPciConfigWrite, &s->pfnAcpiPciConfigWrite);
    26602704
    2661     rc = PDMDevHlpSSMRegister(pDevIns, 5, sizeof(*s), acpi_save_state, acpi_load_state);
     2705    rc = PDMDevHlpSSMRegister(pDevIns, 6, sizeof(*s), acpiSaveState, acpiLoadState);
    26622706    if (RT_FAILURE(rc))
    26632707        return rc;
     
    27242768    NULL,
    27252769    /* pfnResume */
    2726     NULL,
     2770    acpiResume,
    27272771    /* pfnAttach */
    27282772    acpiAttach,
  • trunk/src/VBox/VMM/PDMDevHlp.cpp

    r30129 r32189  
    28252825
    28262826    LogFlow(("pdmR3DevHlp_VMSuspend: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
     2827    return rc;
     2828}
     2829
     2830
     2831/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspendSaveAndPowerOff} */
     2832static DECLCALLBACK(int) pdmR3DevHlp_VMSuspendSaveAndPowerOff(PPDMDEVINS pDevIns)
     2833{
     2834    int rc;
     2835    PDMDEV_ASSERT_DEVINS(pDevIns);
     2836    PVM pVM = pDevIns->Internal.s.pVMR3;
     2837    VM_ASSERT_EMT(pVM);
     2838    LogFlow(("pdmR3DevHlp_VMSuspendSaveAndPowerOff: caller='%s'/%d:\n",
     2839             pDevIns->pReg->szName, pDevIns->iInstance));
     2840
     2841    /** @todo We'll have to queue a request to avoid deadlock issues. */
     2842    rc = VERR_NOT_IMPLEMENTED;
     2843
     2844    LogFlow(("pdmR3DevHlp_VMSuspendSaveAndPowerOff: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
    28272845    return rc;
    28282846}
     
    29953013    pdmR3DevHlp_VMReset,
    29963014    pdmR3DevHlp_VMSuspend,
     3015    pdmR3DevHlp_VMSuspendSaveAndPowerOff,
    29973016    pdmR3DevHlp_VMPowerOff,
    29983017    pdmR3DevHlp_A20IsEnabled,
     
    30523071/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspend} */
    30533072static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMSuspend(PPDMDEVINS pDevIns)
     3073{
     3074    PDMDEV_ASSERT_DEVINS(pDevIns);
     3075    AssertReleaseMsgFailed(("Untrusted device called trusted helper! '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance));
     3076    return VERR_ACCESS_DENIED;
     3077}
     3078
     3079
     3080/** @interface_method_impl{PDMDEVHLPR3,pfnVMSuspendSaveAndPowerOff} */
     3081static DECLCALLBACK(int) pdmR3DevHlp_Untrusted_VMSuspendSaveAndPowerOff(PPDMDEVINS pDevIns)
    30543082{
    30553083    PDMDEV_ASSERT_DEVINS(pDevIns);
     
    31913219    pdmR3DevHlp_Untrusted_VMReset,
    31923220    pdmR3DevHlp_Untrusted_VMSuspend,
     3221    pdmR3DevHlp_Untrusted_VMSuspendSaveAndPowerOff,
    31933222    pdmR3DevHlp_Untrusted_VMPowerOff,
    31943223    pdmR3DevHlp_Untrusted_A20IsEnabled,
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