VirtualBox

Changeset 101597 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Oct 26, 2023 9:09:48 AM (17 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
159681
Message:

pdmifs.h,DevACPI.cpp,ConsoleImpl.cpp: Move the power button events out of the ACPI port interface into a separate one so it can be re-used elsewhere, bugref:10538

File:
1 edited

Legend:

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

    r98103 r101597  
    571571    /** ACPI port interface. */
    572572    PDMIACPIPORT        IACPIPort;
     573    /** The button event interface for power button events. */
     574    PDMIEVENTBUTTONPORT IButtonEventPort;
    573575    /** Pointer to the device instance so we can get our bearings from
    574576     *  interface functions. */
     
    11611163
    11621164/**
    1163  * @interface_method_impl{PDMIACPIPORT,pfnPowerButtonPress}
    1164  */
    1165 static DECLCALLBACK(int) acpiR3Port_PowerButtonPress(PPDMIACPIPORT pInterface)
     1165 * @interface_method_impl{PDMIACPIPORT,pfnGetGuestEnteredACPIMode, Check if the
     1166 *                       Guest entered into G0 (working) or G1 (sleeping)}
     1167 */
     1168static DECLCALLBACK(int) acpiR3Port_GetGuestEnteredACPIMode(PPDMIACPIPORT pInterface, bool *pfEntered)
    11661169{
    11671170    PACPISTATER3 pThisCC = RT_FROM_MEMBER(pInterface, ACPISTATER3, IACPIPort);
     
    11701173    DEVACPI_LOCK_R3(pDevIns, pThis);
    11711174
    1172     Log(("acpiR3Port_PowerButtonPress: handled=%d status=%x\n", pThis->fPowerButtonHandled, pThis->pm1a_sts));
    1173     pThis->fPowerButtonHandled = false;
    1174     acpiUpdatePm1a(pDevIns, pThis, pThis->pm1a_sts | PWRBTN_STS, pThis->pm1a_en);
     1175    *pfEntered = (pThis->pm1a_ctl & SCI_EN) != 0;
    11751176
    11761177    DEVACPI_UNLOCK(pDevIns, pThis);
     
    11791180
    11801181/**
    1181  * @interface_method_impl{PDMIACPIPORT,pfnGetPowerButtonHandled}
    1182  */
    1183 static DECLCALLBACK(int) acpiR3Port_GetPowerButtonHandled(PPDMIACPIPORT pInterface, bool *pfHandled)
     1182 * @interface_method_impl{PDMIACPIPORT,pfnGetCpuStatus}
     1183 */
     1184static DECLCALLBACK(int) acpiR3Port_GetCpuStatus(PPDMIACPIPORT pInterface, unsigned uCpu, bool *pfLocked)
    11841185{
    11851186    PACPISTATER3 pThisCC = RT_FROM_MEMBER(pInterface, ACPISTATER3, IACPIPort);
     
    11881189    DEVACPI_LOCK_R3(pDevIns, pThis);
    11891190
    1190     *pfHandled = pThis->fPowerButtonHandled;
     1191    *pfLocked = VMCPUSET_IS_PRESENT(&pThis->CpuSetLocked, uCpu);
    11911192
    11921193    DEVACPI_UNLOCK(pDevIns, pThis);
     
    11941195}
    11951196
    1196 /**
    1197  * @interface_method_impl{PDMIACPIPORT,pfnGetGuestEnteredACPIMode, Check if the
    1198  *                       Guest entered into G0 (working) or G1 (sleeping)}
    1199  */
    1200 static DECLCALLBACK(int) acpiR3Port_GetGuestEnteredACPIMode(PPDMIACPIPORT pInterface, bool *pfEntered)
    1201 {
    1202     PACPISTATER3 pThisCC = RT_FROM_MEMBER(pInterface, ACPISTATER3, IACPIPort);
    1203     PPDMDEVINS   pDevIns = pThisCC->pDevIns;
    1204     PACPISTATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PACPISTATE);
    1205     DEVACPI_LOCK_R3(pDevIns, pThis);
    1206 
    1207     *pfEntered = (pThis->pm1a_ctl & SCI_EN) != 0;
    1208 
    1209     DEVACPI_UNLOCK(pDevIns, pThis);
    1210     return VINF_SUCCESS;
    1211 }
    1212 
    1213 /**
    1214  * @interface_method_impl{PDMIACPIPORT,pfnGetCpuStatus}
    1215  */
    1216 static DECLCALLBACK(int) acpiR3Port_GetCpuStatus(PPDMIACPIPORT pInterface, unsigned uCpu, bool *pfLocked)
    1217 {
    1218     PACPISTATER3 pThisCC = RT_FROM_MEMBER(pInterface, ACPISTATER3, IACPIPort);
    1219     PPDMDEVINS   pDevIns = pThisCC->pDevIns;
    1220     PACPISTATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PACPISTATE);
    1221     DEVACPI_LOCK_R3(pDevIns, pThis);
    1222 
    1223     *pfLocked = VMCPUSET_IS_PRESENT(&pThis->CpuSetLocked, uCpu);
    1224 
    1225     DEVACPI_UNLOCK(pDevIns, pThis);
    1226     return VINF_SUCCESS;
    1227 }
    1228 
    1229 /**
    1230  * Send an ACPI sleep button event.
    1231  *
    1232  * @returns VBox status code
    1233  * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1234  */
    1235 static DECLCALLBACK(int) acpiR3Port_SleepButtonPress(PPDMIACPIPORT pInterface)
    1236 {
    1237     PACPISTATER3 pThisCC = RT_FROM_MEMBER(pInterface, ACPISTATER3, IACPIPort);
    1238     PPDMDEVINS   pDevIns = pThisCC->pDevIns;
    1239     PACPISTATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PACPISTATE);
    1240     DEVACPI_LOCK_R3(pDevIns, pThis);
    1241 
    1242     acpiUpdatePm1a(pDevIns, pThis, pThis->pm1a_sts | SLPBTN_STS, pThis->pm1a_en);
    1243 
    1244     DEVACPI_UNLOCK(pDevIns, pThis);
    1245     return VINF_SUCCESS;
    1246 }
    12471197
    12481198/**
     
    12851235    return VINF_SUCCESS;
    12861236}
     1237
     1238
     1239/**
     1240 * @interface_method_impl{PDMIACPIPORT,pfnQueryGuestCanHandleButtonEvents}
     1241 */
     1242static DECLCALLBACK(int) acpiR3Port_QueryGuestCanHandleButtonEvents(PPDMIEVENTBUTTONPORT pInterface, bool *pfCanHandleButtonEvents)
     1243{
     1244    PACPISTATER3 pThisCC = RT_FROM_MEMBER(pInterface, ACPISTATER3, IButtonEventPort);
     1245    PPDMDEVINS   pDevIns = pThisCC->pDevIns;
     1246    PACPISTATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PACPISTATE);
     1247    DEVACPI_LOCK_R3(pDevIns, pThis);
     1248
     1249    /* Just checks whether the guest has entered ACPI mode. */
     1250    *pfCanHandleButtonEvents = (pThis->pm1a_ctl & SCI_EN) != 0;
     1251
     1252    DEVACPI_UNLOCK(pDevIns, pThis);
     1253    return VINF_SUCCESS;
     1254}
     1255
     1256
     1257/**
     1258 * @interface_method_impl{PDMIEVENTBUTTONPORT,pfnPowerButtonPress}
     1259 */
     1260static DECLCALLBACK(int) acpiR3Port_PowerButtonPress(PPDMIEVENTBUTTONPORT pInterface)
     1261{
     1262    PACPISTATER3 pThisCC = RT_FROM_MEMBER(pInterface, ACPISTATER3, IButtonEventPort);
     1263    PPDMDEVINS   pDevIns = pThisCC->pDevIns;
     1264    PACPISTATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PACPISTATE);
     1265    DEVACPI_LOCK_R3(pDevIns, pThis);
     1266
     1267    Log(("acpiR3Port_PowerButtonPress: handled=%d status=%x\n", pThis->fPowerButtonHandled, pThis->pm1a_sts));
     1268    pThis->fPowerButtonHandled = false;
     1269    acpiUpdatePm1a(pDevIns, pThis, pThis->pm1a_sts | PWRBTN_STS, pThis->pm1a_en);
     1270
     1271    DEVACPI_UNLOCK(pDevIns, pThis);
     1272    return VINF_SUCCESS;
     1273}
     1274
     1275
     1276/**
     1277 * @interface_method_impl{PDMIEVENTBUTTONPORT,pfnSleepButtonPress}
     1278 */
     1279static DECLCALLBACK(int) acpiR3Port_SleepButtonPress(PPDMIEVENTBUTTONPORT pInterface)
     1280{
     1281    PACPISTATER3 pThisCC = RT_FROM_MEMBER(pInterface, ACPISTATER3, IButtonEventPort);
     1282    PPDMDEVINS   pDevIns = pThisCC->pDevIns;
     1283    PACPISTATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PACPISTATE);
     1284    DEVACPI_LOCK_R3(pDevIns, pThis);
     1285
     1286    acpiUpdatePm1a(pDevIns, pThis, pThis->pm1a_sts | SLPBTN_STS, pThis->pm1a_en);
     1287
     1288    DEVACPI_UNLOCK(pDevIns, pThis);
     1289    return VINF_SUCCESS;
     1290}
     1291
     1292
     1293/**
     1294 * @interface_method_impl{PDMIEVENTBUTTONPORT,pfnQueryPowerButtonHandled}
     1295 */
     1296static DECLCALLBACK(int) acpiR3Port_QueryPowerButtonHandled(PPDMIEVENTBUTTONPORT pInterface, bool *pfHandled)
     1297{
     1298    PACPISTATER3 pThisCC = RT_FROM_MEMBER(pInterface, ACPISTATER3, IButtonEventPort);
     1299    PPDMDEVINS   pDevIns = pThisCC->pDevIns;
     1300    PACPISTATE   pThis   = PDMDEVINS_2_DATA(pDevIns, PACPISTATE);
     1301    DEVACPI_LOCK_R3(pDevIns, pThis);
     1302
     1303    *pfHandled = pThis->fPowerButtonHandled;
     1304
     1305    DEVACPI_UNLOCK(pDevIns, pThis);
     1306    return VINF_SUCCESS;
     1307}
     1308
    12871309
    12881310/**
     
    28482870    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThisCC->IBase);
    28492871    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIACPIPORT, &pThisCC->IACPIPort);
     2872    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIEVENTBUTTONPORT, &pThisCC->IButtonEventPort);
    28502873    return NULL;
    28512874}
     
    42654288
    42664289    /* IBase */
    4267     pThisCC->IBase.pfnQueryInterface               = acpiR3QueryInterface;
     4290    pThisCC->IBase.pfnQueryInterface                             = acpiR3QueryInterface;
    42684291    /* IACPIPort */
    4269     pThisCC->IACPIPort.pfnSleepButtonPress         = acpiR3Port_SleepButtonPress;
    4270     pThisCC->IACPIPort.pfnPowerButtonPress         = acpiR3Port_PowerButtonPress;
    4271     pThisCC->IACPIPort.pfnGetPowerButtonHandled    = acpiR3Port_GetPowerButtonHandled;
    4272     pThisCC->IACPIPort.pfnGetGuestEnteredACPIMode  = acpiR3Port_GetGuestEnteredACPIMode;
    4273     pThisCC->IACPIPort.pfnGetCpuStatus             = acpiR3Port_GetCpuStatus;
    4274     pThisCC->IACPIPort.pfnMonitorHotPlugEvent      = acpiR3Port_MonitorHotPlugEvent;
    4275     pThisCC->IACPIPort.pfnBatteryStatusChangeEvent = acpiR3Port_BatteryStatusChangeEvent;
     4292    pThisCC->IACPIPort.pfnGetGuestEnteredACPIMode                = acpiR3Port_GetGuestEnteredACPIMode;
     4293    pThisCC->IACPIPort.pfnGetCpuStatus                           = acpiR3Port_GetCpuStatus;
     4294    pThisCC->IACPIPort.pfnMonitorHotPlugEvent                    = acpiR3Port_MonitorHotPlugEvent;
     4295    pThisCC->IACPIPort.pfnBatteryStatusChangeEvent               = acpiR3Port_BatteryStatusChangeEvent;
     4296    /* IButtonEventPort */
     4297    pThisCC->IButtonEventPort.pfnSleepButtonPress                = acpiR3Port_SleepButtonPress;
     4298    pThisCC->IButtonEventPort.pfnPowerButtonPress                = acpiR3Port_PowerButtonPress;
     4299    pThisCC->IButtonEventPort.pfnQueryPowerButtonHandled         = acpiR3Port_QueryPowerButtonHandled;
     4300    pThisCC->IButtonEventPort.pfnQueryGuestCanHandleButtonEvents = acpiR3Port_QueryGuestCanHandleButtonEvents;
    42764301
    42774302    /*
Note: See TracChangeset for help on using the changeset viewer.

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