VirtualBox

Changeset 61675 in vbox


Ignore:
Timestamp:
Jun 13, 2016 12:39:34 PM (9 years ago)
Author:
vboxsync
Message:

Devices/ACPI: Notify the guest by sending a battery status change event by calling the GPE bit 0 handler. Also tell the guest to re-evaluate _BST (battery dynamic state) and _PSR (AC adapter status). I don't think that the guest needs to re-evaluate _BIF (battery info) at this time. Thanks Dennis Wassenberg / secunet!

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmifs.h

    r60905 r61675  
    14691469     */
    14701470    DECLR3CALLBACKMEMBER(int, pfnMonitorHotPlugEvent,(PPDMIACPIPORT pInterface));
     1471
     1472    /**
     1473     * Send a battery status change event.
     1474     *
     1475     * @returns VBox status code
     1476     * @param   pInterface      Pointer to the interface structure containing
     1477     *                          the called function pointer.
     1478     */
     1479    DECLR3CALLBACKMEMBER(int, pfnBatteryStatusChangeEvent,(PPDMIACPIPORT pInterface));
    14711480} PDMIACPIPORT;
    14721481/** PDMIACPIPORT interface ID. */
     
    15051514} PDMIACPICONNECTOR;
    15061515/** PDMIACPICONNECTOR interface ID. */
    1507 #define PDMIACPICONNECTOR_IID                   "5f14bf8d-1edf-4e3a-a1e1-cca9fd08e359"
     1516#define PDMIACPICONNECTOR_IID                   "19c7de73-5ae0-4841-a106-21825f43b206"
    15081517
    15091518
  • trunk/src/VBox/Devices/PC/DevACPI.cpp

    r60404 r61675  
    902902
    903903/**
     904 * Send an ACPI battery status change event.
     905 *
     906 * @returns VBox status code
     907 * @param   pInterface      Pointer to the interface structure containing the
     908 *                          called function pointer.
     909 */
     910static DECLCALLBACK(int) acpiR3Port_BatteryStatusChangeEvent(PPDMIACPIPORT pInterface)
     911{
     912    ACPIState *pThis = RT_FROM_MEMBER(pInterface, ACPIState, IACPIPort);
     913    DEVACPI_LOCK_R3(pThis);
     914
     915    apicR3UpdateGpe0(pThis, pThis->gpe0_sts | 0x1, pThis->gpe0_en);
     916
     917    DEVACPI_UNLOCK(pThis);
     918    return VINF_SUCCESS;
     919}
     920
     921/**
    904922 * Used by acpiR3PmTimer to re-arm the PM timer.
    905923 *
     
    30443062
    30453063    /* IBase */
    3046     pThis->IBase.pfnQueryInterface              = acpiR3QueryInterface;
     3064    pThis->IBase.pfnQueryInterface               = acpiR3QueryInterface;
    30473065    /* IACPIPort */
    3048     pThis->IACPIPort.pfnSleepButtonPress        = acpiR3Port_SleepButtonPress;
    3049     pThis->IACPIPort.pfnPowerButtonPress        = acpiR3Port_PowerButtonPress;
    3050     pThis->IACPIPort.pfnGetPowerButtonHandled   = acpiR3Port_GetPowerButtonHandled;
    3051     pThis->IACPIPort.pfnGetGuestEnteredACPIMode = acpiR3Port_GetGuestEnteredACPIMode;
    3052     pThis->IACPIPort.pfnGetCpuStatus            = acpiR3Port_GetCpuStatus;
    3053     pThis->IACPIPort.pfnMonitorHotPlugEvent     = acpiR3Port_MonitorHotPlugEvent;
     3066    pThis->IACPIPort.pfnSleepButtonPress         = acpiR3Port_SleepButtonPress;
     3067    pThis->IACPIPort.pfnPowerButtonPress         = acpiR3Port_PowerButtonPress;
     3068    pThis->IACPIPort.pfnGetPowerButtonHandled    = acpiR3Port_GetPowerButtonHandled;
     3069    pThis->IACPIPort.pfnGetGuestEnteredACPIMode  = acpiR3Port_GetGuestEnteredACPIMode;
     3070    pThis->IACPIPort.pfnGetCpuStatus             = acpiR3Port_GetCpuStatus;
     3071    pThis->IACPIPort.pfnMonitorHotPlugEvent      = acpiR3Port_MonitorHotPlugEvent;
     3072    pThis->IACPIPort.pfnBatteryStatusChangeEvent = acpiR3Port_BatteryStatusChangeEvent;
    30543073
    30553074    /*
  • trunk/src/VBox/Devices/PC/DrvACPI.cpp

    r60956 r61675  
    234234 */
    235235static DECLCALLBACK(int) drvACPIQueryBatteryStatus(PPDMIACPICONNECTOR pInterface, bool *pfPresent,
    236         PPDMACPIBATCAPACITY penmRemainingCapacity,
    237         PPDMACPIBATSTATE penmBatteryState,
    238         uint32_t *pu32PresentRate)
     236                                                   PPDMACPIBATCAPACITY penmRemainingCapacity,
     237                                                   PPDMACPIBATSTATE penmBatteryState,
     238                                                   uint32_t *pu32PresentRate)
    239239{
    240240    /* default return values for all architectures */
     
    534534        bool       fDischarging = false;        /* one or more batteries discharging */
    535535        bool       fCritical = false;           /* one or more batteries in critical state */
     536        bool       fDataChanged;                /* if battery status data changed during last poll */
    536537        int32_t    maxCapacityTotal = 0;        /* total capacity of all batteries */
    537538        int32_t    currentCapacityTotal = 0;    /* total current capacity of all batteries */
    538539        int32_t    presentRateTotal = 0;        /* total present (dis)charging rate of all batts */
     540        PDMACPIBATCAPACITY enmBatteryRemainingCapacity; /* total remaining capacity of vbox batt */
     541        uint32_t u32BatteryPresentRate;         /* total present (dis)charging rate of vbox batt */
    539542
    540543        int rc = RTDirOpen(&pDir, "/sys/class/power_supply/");
     
    856859        /* atomic update of the state */
    857860        RTCritSectEnter(&pThis->CritSect);
    858         pThis->enmPowerSource = enmPowerSource;
    859         pThis->fBatteryPresent = fBatteryPresent;
    860861
    861862        /* charging/discharging bits are mutual exclusive */
     
    867868        if (fCritical)
    868869            uBs |= PDM_ACPI_BAT_STATE_CRITICAL;
    869         pThis->enmBatteryState = (PDMACPIBATSTATE)uBs;
    870870
    871871        if (maxCapacityTotal > 0 && currentCapacityTotal > 0)
     
    875875
    876876            /* calculate the percentage */
    877             pThis->enmBatteryRemainingCapacity =
     877
     878            enmBatteryRemainingCapacity =
    878879                                 (PDMACPIBATCAPACITY)( (  (float)currentCapacityTotal
    879880                                                        / (float)maxCapacityTotal)
    880881                                                      * PDM_ACPI_BAT_CAPACITY_MAX);
    881             pThis->u32BatteryPresentRate =
     882            u32BatteryPresentRate =
    882883                                 (uint32_t)((  (float)presentRateTotal
    883884                                             / (float)maxCapacityTotal) * 1000);
     
    886887        {
    887888            /* unknown capacity / state */
    888             pThis->enmBatteryRemainingCapacity = PDM_ACPI_BAT_CAPACITY_UNKNOWN;
    889             pThis->u32BatteryPresentRate = ~0;
    890         }
     889            enmBatteryRemainingCapacity = PDM_ACPI_BAT_CAPACITY_UNKNOWN;
     890            u32BatteryPresentRate = ~0;
     891        }
     892
     893        if (   pThis->enmPowerSource  == enmPowerSource
     894            && pThis->fBatteryPresent == fBatteryPresent
     895            && pThis->enmBatteryState == (PDMACPIBATSTATE) uBs
     896            && pThis->enmBatteryRemainingCapacity == enmBatteryRemainingCapacity
     897            && pThis->u32BatteryPresentRate == u32BatteryPresentRate)
     898        {
     899            fDataChanged = false;
     900        }
     901        else
     902        {
     903            fDataChanged = true;
     904
     905            pThis->enmPowerSource = enmPowerSource;
     906            pThis->fBatteryPresent = fBatteryPresent;
     907            pThis->enmBatteryState = (PDMACPIBATSTATE)uBs;
     908            pThis->enmBatteryRemainingCapacity = enmBatteryRemainingCapacity;
     909            pThis->u32BatteryPresentRate = u32BatteryPresentRate;
     910        }
     911
    891912        RTCritSectLeave(&pThis->CritSect);
     913
     914        if (fDataChanged)
     915            pThis->pPort->pfnBatteryStatusChangeEvent(pThis->pPort);
    892916
    893917        /* wait a bit (e.g. Ubuntu/GNOME polls every 30 seconds) */
  • trunk/src/VBox/Devices/PC/vbox.dsl

    r60618 r61675  
    13621362                {
    13631363                    // GPE bit 0 handler
    1364                     // GPE.0 must be set and SCI raised when
    1365                     // battery info changed and _BIF must be
    1366                     // re-evaluated
    1367                     Method (_L00, 0, NotSerialized)
    1368                     {
    1369                             Notify (\_SB.PCI0.BAT0, 0x81)
     1364                    // GPE.0 must be set and SCI raised when battery info
     1365                    // changed. Do NOT re-evaluate _BIF (battery info, never
     1366                    // changes) but DO re-evaluate _BST (dynamic state). Also
     1367                    // re-evaluate the AC adapter status.
     1368                    Method (_L00, 0, NotSerialized).
     1369                    {
     1370                        // _BST must be re-evaluated (battery state)
     1371                        Notify (\_SB.PCI0.BAT0, 0x80)
     1372                        // _PSR must be re-evaluated (AC adapter status)
     1373                        Notify (\_SB.PCI0.AC, 0x80)
    13701374                    }
    13711375                }
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