VirtualBox

Changeset 101597 in vbox


Ignore:
Timestamp:
Oct 26, 2023 9:09:48 AM (11 months ago)
Author:
vboxsync
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

Location:
trunk
Files:
3 edited

Legend:

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

    r99739 r101597  
    14121412{
    14131413    /**
    1414      * Send an ACPI power off event.
    1415      *
    1416      * @returns VBox status code
    1417      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1418      */
    1419     DECLR3CALLBACKMEMBER(int, pfnPowerButtonPress,(PPDMIACPIPORT pInterface));
    1420 
    1421     /**
    1422      * Send an ACPI sleep button event.
    1423      *
    1424      * @returns VBox status code
    1425      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1426      */
    1427     DECLR3CALLBACKMEMBER(int, pfnSleepButtonPress,(PPDMIACPIPORT pInterface));
    1428 
    1429     /**
    1430      * Check if the last power button event was handled by the guest.
    1431      *
    1432      * @returns VBox status code
    1433      * @param   pInterface      Pointer to the interface structure containing the called function pointer.
    1434      * @param   pfHandled       Is set to true if the last power button event was handled, false otherwise.
    1435      */
    1436     DECLR3CALLBACKMEMBER(int, pfnGetPowerButtonHandled,(PPDMIACPIPORT pInterface, bool *pfHandled));
    1437 
    1438     /**
    14391414     * Check if the guest entered the ACPI mode.
    14401415     *
     
    15091484/** PDMIACPICONNECTOR interface ID. */
    15101485#define PDMIACPICONNECTOR_IID                   "5f14bf8d-1edf-4e3a-a1e1-cca9fd08e359"
     1486
     1487
     1488/** Pointer to an event button port interface. */
     1489typedef struct PDMIEVENTBUTTONPORT *PPDMIEVENTBUTTONPORT;
     1490/**
     1491 * Event button port interface (down). Used by both the ACPI/GPIO driver and (grumble) main.
     1492 * Pair with PDMIEVENTBUTTONCONNECTOR.
     1493 */
     1494typedef struct PDMIEVENTBUTTONPORT
     1495{
     1496    /**
     1497     * Check if the guest is able to handle button events.
     1498     *
     1499     * @returns VBox status code
     1500     * @param   pInterface                      Pointer to the interface structure containing the called function pointer.
     1501     * @param   pfCanHandleButtonEvents         Is set to true if the guest is able to handle button events, false otherwise.
     1502     */
     1503    DECLR3CALLBACKMEMBER(int, pfnQueryGuestCanHandleButtonEvents,(PPDMIEVENTBUTTONPORT pInterface, bool *pfCanHandleButtonEvents));
     1504
     1505    /**
     1506     * Send an power off button event.
     1507     *
     1508     * @returns VBox status code
     1509     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1510     */
     1511    DECLR3CALLBACKMEMBER(int, pfnPowerButtonPress,(PPDMIEVENTBUTTONPORT pInterface));
     1512
     1513    /**
     1514     * Send an sleep button event.
     1515     *
     1516     * @returns VBox status code
     1517     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1518     */
     1519    DECLR3CALLBACKMEMBER(int, pfnSleepButtonPress,(PPDMIEVENTBUTTONPORT pInterface));
     1520
     1521    /**
     1522     * Check if the last power button event was handled by the guest.
     1523     *
     1524     * @returns VBox status code
     1525     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1526     * @param   pfHandled       Is set to true if the last power button event was handled, false otherwise.
     1527     */
     1528    DECLR3CALLBACKMEMBER(int, pfnQueryPowerButtonHandled,(PPDMIEVENTBUTTONPORT pInterface, bool *pfHandled));
     1529
     1530} PDMIEVENTBUTTONPORT;
     1531/** PDMIEVENTBUTTONPORT interface ID. */
     1532#define PDMIEVENTBUTTONPORT_IID                 "7aa5ada2-35c7-45be-a757-0398427af7aa"
     1533
     1534
     1535/** Pointer to an event button connector interface. */
     1536typedef struct PDMIEVENTBUTTONCONNECTOR *PPDMIEVENTBUTTONCONNECTOR;
     1537/**
     1538 * Event button connector interface (up).
     1539 * Pair with PDMIEVENTBUTTONPORT.
     1540 */
     1541typedef struct PDMIEVENTBUTTONCONNECTOR
     1542{
     1543    /** Currently empty, so just a dummy value. */
     1544    uint32_t                uDummy;
     1545
     1546} PDMIEVENTBUTTONCONNECTOR;
     1547/** PDMIACPICONNECTOR interface ID. */
     1548#define PDMIEVENTBUTTONCONNECTOR_IID                   "46774d25-a55e-4e63-b70b-8946bcedd4a7"
     1549
    15111550
    15121551struct VMMDevDisplayDef;
  • 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    /*
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r101199 r101597  
    27192719        {
    27202720            Assert(pBase);
    2721             PPDMIACPIPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIACPIPORT);
     2721            PPDMIEVENTBUTTONPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIEVENTBUTTONPORT);
    27222722            if (pPort)
    27232723                vrc = pPort->pfnPowerButtonPress(pPort);
     
    27612761        {
    27622762            Assert(pBase);
    2763             PPDMIACPIPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIACPIPORT);
     2763            PPDMIEVENTBUTTONPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIEVENTBUTTONPORT);
    27642764            if (pPort)
    27652765            {
    27662766                bool fHandled = false;
    2767                 vrc = pPort->pfnGetPowerButtonHandled(pPort, &fHandled);
     2767                vrc = pPort->pfnQueryPowerButtonHandled(pPort, &fHandled);
    27682768                if (RT_SUCCESS(vrc))
    27692769                    *aHandled = fHandled;
     
    28532853        {
    28542854            Assert(pBase);
    2855             PPDMIACPIPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIACPIPORT);
     2855            PPDMIEVENTBUTTONPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIEVENTBUTTONPORT);
    28562856            if (pPort)
    28572857                vrc = pPort->pfnSleepButtonPress(pPort);
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