VirtualBox

Changeset 81996 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 19, 2019 2:41:07 PM (5 years ago)
Author:
vboxsync
Message:

DevACPI: Converted the timer pointers to a handle and eliminated the pDevInsR* members. bugref:9218

File:
1 edited

Legend:

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

    r81994 r81996  
    293293    /** Number of logical CPUs in guest */
    294294    uint16_t            cCpus;
     295
    295296    uint64_t            u64PmTimerInitial;
    296     PTMTIMERR3          pPmTimerR3;
    297     PTMTIMERR0          pPmTimerR0;
    298     PTMTIMERRC          pPmTimerRC;
    299 
     297    /** The PM timer. */
     298    TMTIMERHANDLE       hPmTimer;
    300299    /* PM Timer last calculated value */
    301300    uint32_t            uPmTimerVal;
     
    422421    PPDMDEVINSR3        pDevIns;
    423422
    424     /** Pointer to the device instance. */
    425     PPDMDEVINSR3        pDevInsR3;
    426     PPDMDEVINSR0        pDevInsR0;
    427     PPDMDEVINSRC        pDevInsRC;
    428 
    429     uint32_t            Alignment3;
    430423    /** Pointer to the driver base interface. */
    431424    R3PTRTYPE(PPDMIBASE) pDrvBase;
     
    777770RT_C_DECLS_END
    778771#ifdef IN_RING3
    779 static int acpiR3PlantTables(ACPIState *pThis);
     772static int acpiR3PlantTables(PPDMDEVINS pDevIns, ACPIState *pThis);
    780773#endif
    781774
    782775/* SCI, usually IRQ9 */
    783 DECLINLINE(void) acpiSetIrq(ACPIState *pThis, int level)
    784 {
    785     PDMDevHlpPCISetIrq(pThis->CTX_SUFF(pDevIns), 0, level);
     776DECLINLINE(void) acpiSetIrq(PPDMDEVINS pDevIns, int level)
     777{
     778    PDMDevHlpPCISetIrq(pDevIns, 0, level);
    786779}
    787780
     
    836829
    837830    if (new_level != old_level)
    838         acpiSetIrq(pThis, new_level);
     831        acpiSetIrq(pDevIns, new_level);
    839832}
    840833
     
    864857
    865858    if (new_level != old_level)
    866         acpiSetIrq(pThis, new_level);
     859        acpiSetIrq(pDevIns, new_level);
    867860}
    868861
     
    870863 * Used by acpiR3PM1aCtlWrite to power off the VM.
    871864 *
     865 * @param   pDevIns     The device instance.
     866 * @returns Strict VBox status code.
     867 */
     868static int acpiR3DoPowerOff(PPDMDEVINS pDevIns)
     869{
     870    int rc = PDMDevHlpVMPowerOff(pDevIns);
     871    AssertRC(rc);
     872    return rc;
     873}
     874
     875/**
     876 * Used by acpiR3PM1aCtlWrite to put the VM to sleep.
     877 *
     878 * @param   pDevIns     The device instance.
    872879 * @param   pThis   The ACPI shared instance data.
    873880 * @returns Strict VBox status code.
    874881 */
    875 static int acpiR3DoPowerOff(ACPIState *pThis)
    876 {
    877     int rc = PDMDevHlpVMPowerOff(pThis->pDevInsR3);
    878     if (RT_FAILURE(rc))
    879         AssertMsgFailed(("Could not power down the VM. rc = %Rrc\n", rc));
    880     return rc;
    881 }
    882 
    883 /**
    884  * Used by acpiR3PM1aCtlWrite to put the VM to sleep.
    885  *
    886  * @param   pThis   The ACPI shared instance data.
    887  * @returns Strict VBox status code.
    888  */
    889 static int acpiR3DoSleep(ACPIState *pThis)
     882static int acpiR3DoSleep(PPDMDEVINS pDevIns, ACPIState *pThis)
    890883{
    891884    /* We must set WAK_STS on resume (includes restore) so the guest knows that
     
    896889    if (pThis->fSuspendToSavedState)
    897890    {
    898         rc = PDMDevHlpVMSuspendSaveAndPowerOff(pThis->pDevInsR3);
     891        rc = PDMDevHlpVMSuspendSaveAndPowerOff(pDevIns);
    899892        if (rc != VERR_NOT_SUPPORTED)
    900893            AssertRC(rc);
     
    902895        {
    903896            LogRel(("ACPI: PDMDevHlpVMSuspendSaveAndPowerOff is not supported, falling back to suspend-only\n"));
    904             rc = PDMDevHlpVMSuspend(pThis->pDevInsR3);
     897            rc = PDMDevHlpVMSuspend(pDevIns);
    905898            AssertRC(rc);
    906899        }
     
    908901    else
    909902    {
    910         rc = PDMDevHlpVMSuspend(pThis->pDevInsR3);
     903        rc = PDMDevHlpVMSuspend(pDevIns);
    911904        AssertRC(rc);
    912905    }
     
    10401033 * the VM is resetting or loading state.
    10411034 *
    1042  * @param   pThis               The ACPI shared instance data.
    1043  * @param   uNow                The current time.
    1044  */
    1045 static void acpiR3PmTimerReset(ACPIState *pThis, uint64_t uNow)
    1046 {
    1047     uint64_t uTimerFreq = TMTimerGetFreq(pThis->CTX_SUFF(pPmTimer));
     1035 * @param   pDevIns     The device instance.
     1036 * @param   pThis       The ACPI shared instance data.
     1037 * @param   uNow        The current time.
     1038 */
     1039static void acpiR3PmTimerReset(PPDMDEVINS pDevIns, ACPIState *pThis, uint64_t uNow)
     1040{
     1041    uint64_t uTimerFreq = PDMDevHlpTimerGetFreq(pDevIns, pThis->hPmTimer);
    10481042    uint32_t uPmTmrCyclesToRollover = TMR_VAL_MSB - (pThis->uPmTimerVal & (TMR_VAL_MSB - 1));
    10491043    uint64_t uInterval  = ASMMultU64ByU32DivByU32(uPmTmrCyclesToRollover, uTimerFreq, PM_TMR_FREQ);
    1050     TMTimerSet(pThis->pPmTimerR3, uNow + uInterval + 1);
     1044    PDMDevHlpTimerSet(pDevIns, pThis->hPmTimer, uNow + uInterval + 1);
    10511045    Log(("acpi: uInterval = %RU64\n", uInterval));
    10521046}
     
    10681062    uint32_t msb = pThis->uPmTimerVal & TMR_VAL_MSB;
    10691063    uint64_t u64Elapsed = u64Now - pThis->u64PmTimerInitial;
    1070     Assert(TMTimerIsLockOwner(pThis->CTX_SUFF(pPmTimer)));
    1071 
    1072     pThis->uPmTimerVal = ASMMultU64ByU32DivByU32(u64Elapsed, PM_TMR_FREQ, TMTimerGetFreq(pThis->CTX_SUFF(pPmTimer))) & TMR_VAL_MASK;
     1064    Assert(PDMDevHlpTimerIsLockOwner(pDevIns, pThis->hPmTimer));
     1065
     1066    pThis->uPmTimerVal = ASMMultU64ByU32DivByU32(u64Elapsed, PM_TMR_FREQ,
     1067                                                 PDMDevHlpTimerGetFreq(pDevIns, pThis->hPmTimer))
     1068                       & TMR_VAL_MASK;
    10731069
    10741070    if ( (pThis->uPmTimerVal & TMR_VAL_MSB) != msb)
     
    10841080{
    10851081    PACPISTATE pThis = PDMDEVINS_2_DATA(pDevIns, PACPISTATE);
    1086     Assert(TMTimerIsLockOwner(pTimer));
    1087     RT_NOREF(pvUser);
     1082    Assert(PDMDevHlpTimerIsLockOwner(pDevIns, pThis->hPmTimer));
     1083    RT_NOREF(pTimer, pvUser);
    10881084
    10891085    DEVACPI_LOCK_R3(pDevIns, pThis);
     
    10911087         pThis->pm1a_sts, (pThis->pm1a_sts & TMR_STS) != 0,
    10921088         pThis->pm1a_en, (pThis->pm1a_en & TMR_EN) != 0));
    1093     uint64_t u64Now = TMTimerGet(pTimer);
     1089    uint64_t u64Now = PDMDevHlpTimerGet(pDevIns, pThis->hPmTimer);
    10941090    acpiPmTimerUpdate(pDevIns, pThis, u64Now);
    10951091    DEVACPI_UNLOCK(pDevIns, pThis);
    10961092
    1097     acpiR3PmTimerReset(pThis, u64Now);
     1093    acpiR3PmTimerReset(pDevIns, pThis, u64Now);
    10981094}
    10991095
     
    16931689                {
    16941690                    LogRel(("ACPI: Entering S1 power state (powered-on suspend)\n"));
    1695                     rc = acpiR3DoSleep(pThis);
     1691                    rc = acpiR3DoSleep(pDevIns, pThis);
    16961692                    break;
    16971693                }
     
    17031699                {
    17041700                    LogRel(("ACPI: Entering S4 power state (suspend to disk)\n"));
    1705                     rc = acpiR3DoPowerOff(pThis);/* Same behavior as S5 */
     1701                    rc = acpiR3DoPowerOff(pDevIns);/* Same behavior as S5 */
    17061702                    break;
    17071703                }
     
    17111707            case 0x05:                  /* S5 */
    17121708                LogRel(("ACPI: Entering S5 power state (power down)\n"));
    1713                 rc = acpiR3DoPowerOff(pThis);
     1709                rc = acpiR3DoPowerOff(pDevIns);
    17141710                break;
    17151711
     
    17451741     */
    17461742
    1747     int rc = TMTimerLock(pThis->CTX_SUFF(pPmTimer), VINF_IOM_R3_IOPORT_READ);
    1748     if (rc != VINF_SUCCESS)
    1749         return rc;
    1750 
    1751     rc = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VINF_IOM_R3_IOPORT_READ);
    1752     if (rc != VINF_SUCCESS)
    1753     {
    1754         TMTimerUnlock(pThis->CTX_SUFF(pPmTimer));
    1755         return rc;
    1756     }
    1757 
    1758     uint64_t u64Now = TMTimerGet(pThis->CTX_SUFF(pPmTimer));
    1759     acpiPmTimerUpdate(pDevIns, pThis, u64Now);
    1760     *pu32 = pThis->uPmTimerVal;
    1761 
    1762     DEVACPI_UNLOCK(pDevIns, pThis);
    1763     TMTimerUnlock(pThis->CTX_SUFF(pPmTimer));
    1764 
    1765     DBGFTRACE_PDM_U64_TAG(pDevIns, u64Now, "acpi");
    1766     Log(("acpi: acpiPMTmrRead -> %#x\n", *pu32));
     1743    int rc = PDMDevHlpTimerLock(pDevIns, pThis->hPmTimer, VINF_IOM_R3_IOPORT_READ);
     1744    if (rc == VINF_SUCCESS)
     1745    {
     1746        rc = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VINF_IOM_R3_IOPORT_READ);
     1747        if (rc == VINF_SUCCESS)
     1748        {
     1749            uint64_t u64Now = PDMDevHlpTimerGet(pDevIns, pThis->hPmTimer);
     1750            acpiPmTimerUpdate(pDevIns, pThis, u64Now);
     1751            *pu32 = pThis->uPmTimerVal;
     1752
     1753            DEVACPI_UNLOCK(pDevIns, pThis);
     1754            PDMDevHlpTimerUnlock(pDevIns, pThis->hPmTimer);
     1755
     1756            DBGFTRACE_PDM_U64_TAG(pDevIns, u64Now, "acpi");
     1757            Log(("acpi: acpiPMTmrRead -> %#x\n", *pu32));
    17671758
    17681759#if 0
    1769     /** @todo temporary: sanity check against running backwards */
    1770     uint32_t uOld = ASMAtomicXchgU32(&pThis->uPmTimeOld, *pu32);
    1771     if (*pu32 - uOld >= 0x10000000)
    1772     {
     1760            /** @todo temporary: sanity check against running backwards */
     1761            uint32_t uOld = ASMAtomicXchgU32(&pThis->uPmTimeOld, *pu32);
     1762            if (*pu32 - uOld >= 0x10000000)
     1763            {
    17731764# if defined(IN_RING0)
    1774         pThis->uPmTimeA = uOld;
    1775         pThis->uPmTimeB = *pu32;
    1776         return VERR_TM_TIMER_BAD_CLOCK;
     1765                pThis->uPmTimeA = uOld;
     1766                pThis->uPmTimeB = *pu32;
     1767                return VERR_TM_TIMER_BAD_CLOCK;
    17771768# elif defined(IN_RING3)
    1778         AssertReleaseMsgFailed(("acpiPMTmrRead: old=%08RX32, current=%08RX32\n", uOld, *pu32));
     1769                AssertReleaseMsgFailed(("acpiPMTmrRead: old=%08RX32, current=%08RX32\n", uOld, *pu32));
    17791770# endif
    1780     }
     1771            }
    17811772#endif
    1782 
     1773        }
     1774        else
     1775            PDMDevHlpTimerUnlock(pDevIns, pThis->hPmTimer);
     1776    }
    17831777    NOREF(pvUser); NOREF(Port);
    17841778    return rc;
     
    20112005#define R(offset, cnt, writer, reader, description) \
    20122006    do { \
    2013         int rc = PDMDevHlpIOPortRegister(pThis->pDevInsR3, acpiR3CalcPmPort(pThis, offset), cnt, pThis, writer, reader, \
     2007        int rc = PDMDevHlpIOPortRegister(pDevIns, acpiR3CalcPmPort(pThis, offset), cnt, pThis, writer, reader, \
    20142008                                         NULL, NULL, description); \
    20152009        if (RT_FAILURE(rc)) \
     
    20302024    if (pDevIns->fRCEnabled)
    20312025    {
    2032         int rc = PDMDevHlpIOPortRegisterRC(pThis->pDevInsR3, acpiR3CalcPmPort(pThis, PM_TMR_OFFSET),
     2026        int rc = PDMDevHlpIOPortRegisterRC(pDevIns, acpiR3CalcPmPort(pThis, PM_TMR_OFFSET),
    20332027                                           1, 0, NULL, "acpiPMTmrRead",
    20342028                                           NULL, NULL, "ACPI PM Timer");
     
    20392033    if (pDevIns->fR0Enabled)
    20402034    {
    2041         int rc = PDMDevHlpIOPortRegisterR0(pThis->pDevInsR3, acpiR3CalcPmPort(pThis, PM_TMR_OFFSET),
     2035        int rc = PDMDevHlpIOPortRegisterR0(pDevIns, acpiR3CalcPmPort(pThis, PM_TMR_OFFSET),
    20422036                                           1, 0, NULL, "acpiPMTmrRead",
    20432037                                           NULL, NULL, "ACPI PM Timer");
     
    20532047 *
    20542048 * @returns VBox status code.
    2055  * @param   pThis           The ACPI shared instance data.
    2056  */
    2057 static int acpiR3UnregisterPmHandlers(ACPIState *pThis)
     2049 * @param   pDevIns     The device instance.
     2050 * @param   pThis       The ACPI shared instance data.
     2051 */
     2052static int acpiR3UnregisterPmHandlers(PPDMDEVINS pDevIns, ACPIState *pThis)
    20582053{
    20592054    if (pThis->uPmIoPortBase == 0)
     
    20622057#define U(offset, cnt) \
    20632058    do { \
    2064         int rc = PDMDevHlpIOPortDeregister(pThis->pDevInsR3, acpiR3CalcPmPort(pThis, offset), cnt); \
     2059        int rc = PDMDevHlpIOPortDeregister(pDevIns, acpiR3CalcPmPort(pThis, offset), cnt); \
    20652060        AssertRCReturn(rc, rc); \
    20662061    } while (0)
     
    20942089    if (NewIoPortBase != pThis->uPmIoPortBase)
    20952090    {
    2096         int rc = acpiR3UnregisterPmHandlers(pThis);
     2091        int rc = acpiR3UnregisterPmHandlers(pDevIns, pThis);
    20972092        if (RT_FAILURE(rc))
    20982093            return rc;
     
    21052100
    21062101        /* We have to update FADT table acccording to the new base */
    2107         rc = acpiR3PlantTables(pThis);
     2102        rc = acpiR3PlantTables(pDevIns, pThis);
    21082103        AssertRC(rc);
    21092104        if (RT_FAILURE(rc))
     
    21612156             * needs to be implemented later if it ever becomes relevant. */
    21622157            if (new_level != old_level)
    2163                 acpiSetIrq(pThis, new_level);
     2158                acpiSetIrq(pDevIns, new_level);
    21642159            break;
    21652160        }
     
    23152310 *
    23162311 * @returns VBox status code.
    2317  * @param   pThis           The ACPI shared instance data.
    2318  */
    2319 static int acpiR3RegisterSMBusHandlers(ACPIState *pThis)
    2320 {
    2321     int   rc = VINF_SUCCESS;
    2322 
     2312 * @param   pDevIns     The device instance.
     2313 * @param   pThis       The ACPI shared instance data.
     2314 */
     2315static int acpiR3RegisterSMBusHandlers(PPDMDEVINS pDevIns, ACPIState *pThis)
     2316{
    23232317    if (pThis->uSMBusIoPortBase == 0)
    23242318        return VINF_SUCCESS;
    23252319
    2326     rc = PDMDevHlpIOPortRegister(pThis->pDevInsR3, pThis->uSMBusIoPortBase, 16, pThis, acpiR3SMBusWrite, acpiR3SMBusRead, NULL, NULL, "SMBus");
     2320    int rc = PDMDevHlpIOPortRegister(pDevIns, pThis->uSMBusIoPortBase, 16, pThis, acpiR3SMBusWrite, acpiR3SMBusRead, NULL, NULL, "SMBus");
    23272321    if (RT_FAILURE(rc))
    23282322        return rc;
     
    23352329 *
    23362330 * @returns VBox status code.
    2337  * @param   pThis           The ACPI shared instance data.
    2338  */
    2339 static int acpiR3UnregisterSMBusHandlers(ACPIState *pThis)
     2331 * @param   pDevIns     The device instance.
     2332 * @param   pThis       The ACPI shared instance data.
     2333 */
     2334static int acpiR3UnregisterSMBusHandlers(PPDMDEVINS pDevIns, ACPIState *pThis)
    23402335{
    23412336    if (pThis->uSMBusIoPortBase == 0)
    23422337        return VINF_SUCCESS;
    23432338
    2344     int rc = PDMDevHlpIOPortDeregister(pThis->pDevInsR3, pThis->uSMBusIoPortBase, 16);
     2339    int rc = PDMDevHlpIOPortDeregister(pDevIns, pThis->uSMBusIoPortBase, 16);
    23452340    AssertRCReturn(rc, rc);
    23462341
     
    23542349 * @returns VBox status code.
    23552350 *
     2351 * @param   pDevIns         The device instance.
    23562352 * @param   pThis           The ACPI shared instance data.
    23572353 * @param   NewIoPortBase   The new base address of the I/O ports.
    23582354 */
    2359 static int acpiR3UpdateSMBusHandlers(ACPIState *pThis, RTIOPORT NewIoPortBase)
     2355static int acpiR3UpdateSMBusHandlers(PPDMDEVINS pDevIns, ACPIState *pThis, RTIOPORT NewIoPortBase)
    23602356{
    23612357    Log(("acpi: rebasing SMBus 0x%x -> 0x%x\n", pThis->uSMBusIoPortBase, NewIoPortBase));
    23622358    if (NewIoPortBase != pThis->uSMBusIoPortBase)
    23632359    {
    2364         int rc = acpiR3UnregisterSMBusHandlers(pThis);
     2360        int rc = acpiR3UnregisterSMBusHandlers(pDevIns, pThis);
    23652361        if (RT_FAILURE(rc))
    23662362            return rc;
     
    23682364        pThis->uSMBusIoPortBase = NewIoPortBase;
    23692365
    2370         rc = acpiR3RegisterSMBusHandlers(pThis);
     2366        rc = acpiR3RegisterSMBusHandlers(pDevIns, pThis);
    23712367        if (RT_FAILURE(rc))
    23722368            return rc;
     
    25232519     * successfully loaded.
    25242520     */
    2525     int rc = acpiR3UnregisterPmHandlers(pThis);
     2521    int rc = acpiR3UnregisterPmHandlers(pDevIns, pThis);
    25262522    if (RT_FAILURE(rc))
    25272523        return rc;
     
    25312527     * successfully loaded.
    25322528     */
    2533     rc = acpiR3UnregisterSMBusHandlers(pThis);
     2529    rc = acpiR3UnregisterSMBusHandlers(pDevIns, pThis);
    25342530    if (RT_FAILURE(rc))
    25352531        return rc;
     
    25642560        if (RT_FAILURE(rc))
    25652561            return rc;
    2566         rc = acpiR3RegisterSMBusHandlers(pThis);
     2562        rc = acpiR3RegisterSMBusHandlers(pDevIns, pThis);
    25672563        if (RT_FAILURE(rc))
    25682564            return rc;
     
    25732569        if (RT_FAILURE(rc))
    25742570            return rc;
    2575         TMTimerLock(pThis->pPmTimerR3, VERR_IGNORED);
     2571        PDMDevHlpTimerLock(pDevIns, pThis->hPmTimer, VERR_IGNORED);
    25762572        DEVACPI_LOCK_R3(pDevIns, pThis);
    2577         uint64_t u64Now = TMTimerGet(pThis->pPmTimerR3);
     2573        uint64_t u64Now = PDMDevHlpTimerGet(pDevIns, pThis->hPmTimer);
    25782574        /* The interrupt may be incorrectly re-generated if the state is restored from versions < 7. */
    25792575        acpiPmTimerUpdate(pDevIns, pThis, u64Now);
    2580         acpiR3PmTimerReset(pThis, u64Now);
     2576        acpiR3PmTimerReset(pDevIns, pThis, u64Now);
    25812577        DEVACPI_UNLOCK(pDevIns, pThis);
    2582         TMTimerUnlock(pThis->pPmTimerR3);
     2578        PDMDevHlpTimerUnlock(pDevIns, pThis->hPmTimer);
    25832579    }
    25842580    return rc;
     
    26492645 * Wrapper around PDMDevHlpPhysWrite used when planting ACPI tables.
    26502646 */
    2651 DECLINLINE(void) acpiR3PhysCopy(ACPIState *pThis, RTGCPHYS32 GCPhys32Dst, const void *pvSrc, size_t cbToCopy)
    2652 {
    2653     PDMDevHlpPhysWrite(pThis->pDevInsR3, GCPhys32Dst, pvSrc, cbToCopy);
     2647DECLINLINE(void) acpiR3PhysCopy(PPDMDEVINS pDevIns, RTGCPHYS32 GCPhys32Dst, const void *pvSrc, size_t cbToCopy)
     2648{
     2649    PDMDevHlpPhysWrite(pDevIns, GCPhys32Dst, pvSrc, cbToCopy);
    26542650}
    26552651
     
    26572653 * Plant the Differentiated System Description Table (DSDT).
    26582654 */
    2659 static void acpiR3SetupDsdt(ACPIState *pThis, RTGCPHYS32 GCPhys32, void *pvPtr, size_t cbDsdt)
    2660 {
    2661     acpiR3PhysCopy(pThis, GCPhys32, pvPtr, cbDsdt);
    2662 }
    2663 
    2664 /**
    2665  * Plan the Secondary System Description Table (SSDT).
    2666  */
    2667 static void acpiR3SetupSsdt(ACPIState *pThis, RTGCPHYS32 addr,
    2668                             void* pPtr, size_t uSsdtLen)
    2669 {
    2670     acpiR3PhysCopy(pThis, addr, pPtr, uSsdtLen);
     2655static void acpiR3SetupDsdt(PPDMDEVINS pDevIns, RTGCPHYS32 GCPhys32, void const *pvSrc, size_t cbDsdt)
     2656{
     2657    acpiR3PhysCopy(pDevIns, GCPhys32, pvSrc, cbDsdt);
     2658}
     2659
     2660/**
     2661 * Plant the Secondary System Description Table (SSDT).
     2662 */
     2663static void acpiR3SetupSsdt(PPDMDEVINS pDevIns, RTGCPHYS32 addr, void const *pvSrc, size_t uSsdtLen)
     2664{
     2665    acpiR3PhysCopy(pDevIns, addr, pvSrc, uSsdtLen);
    26712666}
    26722667
     
    26742669 * Plant the Firmware ACPI Control Structure (FACS).
    26752670 */
    2676 static void acpiR3SetupFacs(ACPIState *pThis, RTGCPHYS32 addr)
     2671static void acpiR3SetupFacs(PPDMDEVINS pDevIns, RTGCPHYS32 addr)
    26772672{
    26782673    ACPITBLFACS facs;
     
    26882683    facs.u8Version            = 1;
    26892684
    2690     acpiR3PhysCopy(pThis, addr, (const uint8_t *)&facs, sizeof(facs));
     2685    acpiR3PhysCopy(pDevIns, addr, (const uint8_t *)&facs, sizeof(facs));
    26912686}
    26922687
     
    26942689 * Plant the Fixed ACPI Description Table (FADT aka FACP).
    26952690 */
    2696 static void acpiR3SetupFadt(ACPIState *pThis, RTGCPHYS32 GCPhysAcpi1, RTGCPHYS32 GCPhysAcpi2,
     2691static void acpiR3SetupFadt(PPDMDEVINS pDevIns, ACPIState *pThis, RTGCPHYS32 GCPhysAcpi1, RTGCPHYS32 GCPhysAcpi2,
    26972692                            RTGCPHYS32 GCPhysFacs, RTGCPHYS GCPhysDsdt)
    26982693{
     
    27612756    acpiR3WriteGenericAddr(&fadt.X_GPE1BLK,    0,  0, 0, 0, acpiR3CalcPmPort(pThis, GPE1_OFFSET));
    27622757    fadt.header.u8Checksum    = acpiR3Checksum(&fadt, sizeof(fadt));
    2763     acpiR3PhysCopy(pThis, GCPhysAcpi2, &fadt, sizeof(fadt));
     2758    acpiR3PhysCopy(pDevIns, GCPhysAcpi2, &fadt, sizeof(fadt));
    27642759
    27652760    /* Now the ACPI 1.0 version. */
     
    27682763    fadt.header.u8Checksum    = 0;  /* Must be zeroed before recalculating checksum! */
    27692764    fadt.header.u8Checksum    = acpiR3Checksum(&fadt, ACPITBLFADT_VERSION1_SIZE);
    2770     acpiR3PhysCopy(pThis, GCPhysAcpi1, &fadt, ACPITBLFADT_VERSION1_SIZE);
     2765    acpiR3PhysCopy(pDevIns, GCPhysAcpi1, &fadt, ACPITBLFADT_VERSION1_SIZE);
    27712766}
    27722767
     
    27782773 * ACPI 2.0 and up.
    27792774 */
    2780 static int acpiR3SetupRsdt(ACPIState *pThis, RTGCPHYS32 addr, unsigned int nb_entries, uint32_t *addrs)
     2775static int acpiR3SetupRsdt(PPDMDEVINS pDevIns, ACPIState *pThis, RTGCPHYS32 addr, unsigned int nb_entries, uint32_t *addrs)
    27812776{
    27822777    ACPITBLRSDT *rsdt;
     
    27852780    rsdt = (ACPITBLRSDT*)RTMemAllocZ(size);
    27862781    if (!rsdt)
    2787         return PDMDEV_SET_ERROR(pThis->pDevInsR3, VERR_NO_TMP_MEMORY, N_("Cannot allocate RSDT"));
     2782        return PDMDEV_SET_ERROR(pDevIns, VERR_NO_TMP_MEMORY, N_("Cannot allocate RSDT"));
    27882783
    27892784    acpiR3PrepareHeader(pThis, &rsdt->header, "RSDT", (uint32_t)size, 1);
     
    27942789    }
    27952790    rsdt->header.u8Checksum = acpiR3Checksum(rsdt, size);
    2796     acpiR3PhysCopy(pThis, addr, rsdt, size);
     2791    acpiR3PhysCopy(pDevIns, addr, rsdt, size);
    27972792    RTMemFree(rsdt);
    27982793    return VINF_SUCCESS;
     
    28022797 * Plant the Extended System Description Table.
    28032798 */
    2804 static int acpiR3SetupXsdt(ACPIState *pThis, RTGCPHYS32 addr, unsigned int nb_entries, uint32_t *addrs)
     2799static int acpiR3SetupXsdt(PPDMDEVINS pDevIns, ACPIState *pThis, RTGCPHYS32 addr, unsigned int nb_entries, uint32_t *addrs)
    28052800{
    28062801    ACPITBLXSDT *xsdt;
     
    28222817    }
    28232818    xsdt->header.u8Checksum = acpiR3Checksum(xsdt, size);
    2824     acpiR3PhysCopy(pThis, addr, xsdt, size);
     2819    acpiR3PhysCopy(pDevIns, addr, xsdt, size);
    28252820    RTMemFree(xsdt);
    28262821    return VINF_SUCCESS;
     
    29712966 * @todo    All hardcoded, should set this up based on the actual VM config!!!!!
    29722967 */
    2973 static void acpiR3SetupMadt(ACPIState *pThis, RTGCPHYS32 addr)
     2968static void acpiR3SetupMadt(PPDMDEVINS pDevIns, ACPIState *pThis, RTGCPHYS32 addr)
    29742969{
    29752970    uint16_t cpus = pThis->cCpus;
     
    30363031
    30373032    madt.header_addr()->u8Checksum = acpiR3Checksum(madt.data(), madt.size());
    3038     acpiR3PhysCopy(pThis, addr, madt.data(), madt.size());
     3033    acpiR3PhysCopy(pDevIns, addr, madt.data(), madt.size());
    30393034}
    30403035
     
    30423037 * Plant the High Performance Event Timer (HPET) descriptor.
    30433038 */
    3044 static void acpiR3SetupHpet(ACPIState *pThis, RTGCPHYS32 addr)
     3039static void acpiR3SetupHpet(PPDMDEVINS pDevIns, ACPIState *pThis, RTGCPHYS32 addr)
    30453040{
    30463041    ACPITBLHPET hpet;
     
    30643059    hpet.aHeader.u8Checksum = acpiR3Checksum(&hpet, sizeof(hpet));
    30653060
    3066     acpiR3PhysCopy(pThis, addr, (const uint8_t *)&hpet, sizeof(hpet));
     3061    acpiR3PhysCopy(pDevIns, addr, (const uint8_t *)&hpet, sizeof(hpet));
    30673062}
    30683063
     
    30753070 * @param   GCPhysDst   Where to plant it.
    30763071 */
    3077 static void acpiR3SetupMcfg(ACPIState *pThis, RTGCPHYS32 GCPhysDst)
     3072static void acpiR3SetupMcfg(PPDMDEVINS pDevIns, ACPIState *pThis, RTGCPHYS32 GCPhysDst)
    30783073{
    30793074    struct
     
    30953090    tbl.hdr.aHeader.u8Checksum = acpiR3Checksum(&tbl, sizeof(tbl));
    30963091
    3097     acpiR3PhysCopy(pThis, GCPhysDst, (const uint8_t *)&tbl, sizeof(tbl));
     3092    acpiR3PhysCopy(pDevIns, GCPhysDst, (const uint8_t *)&tbl, sizeof(tbl));
    30983093}
    30993094
     
    31613156 * Create the ACPI tables in guest memory.
    31623157 */
    3163 static int acpiR3PlantTables(ACPIState *pThis)
     3158static int acpiR3PlantTables(PPDMDEVINS pDevIns, ACPIState *pThis)
    31643159{
    31653160    int        rc;
     
    32103205     * The latter starts never below 4G.
    32113206     */
    3212     PVM pVM                    = PDMDevHlpGetVM(pThis->pDevInsR3);
     3207    PVM pVM                    = PDMDevHlpGetVM(pDevIns);
    32133208    uint32_t        cbBelow4GB = MMR3PhysGetRamSizeBelow4GB(pVM);
    32143209    uint64_t const  cbAbove4GB = MMR3PhysGetRamSizeAbove4GB(pVM);
     
    32783273    void  *pvSsdtCode = NULL;
    32793274    size_t cbSsdt = 0;
    3280     rc = acpiPrepareSsdt(pThis->pDevInsR3, &pvSsdtCode, &cbSsdt);
     3275    rc = acpiPrepareSsdt(pDevIns, &pvSsdtCode, &cbSsdt);
    32813276    if (RT_FAILURE(rc))
    32823277        return rc;
     
    32893284    void  *pvDsdtCode = NULL;
    32903285    size_t cbDsdt = 0;
    3291     rc = acpiPrepareDsdt(pThis->pDevInsR3, &pvDsdtCode, &cbDsdt);
     3286    rc = acpiPrepareDsdt(pDevIns, &pvDsdtCode, &cbDsdt);
    32923287    if (RT_FAILURE(rc))
    32933288        return rc;
     
    32963291
    32973292    if (GCPhysCur > 0x10000)
    3298         return PDMDEV_SET_ERROR(pThis->pDevInsR3, VERR_TOO_MUCH_DATA,
     3293        return PDMDEV_SET_ERROR(pDevIns, VERR_TOO_MUCH_DATA,
    32993294                                N_("Error: ACPI tables bigger than 64KB"));
    33003295
     
    33163311
    33173312    acpiR3SetupRsdp(pThis, (ACPITBLRSDP *)pThis->au8RSDPPage, GCPhysRsdt + addend, GCPhysXsdt + addend);
    3318     acpiR3SetupDsdt(pThis, GCPhysDsdt + addend, pvDsdtCode, cbDsdt);
    3319     acpiCleanupDsdt(pThis->pDevInsR3, pvDsdtCode);
    3320     acpiR3SetupFacs(pThis, GCPhysFacs + addend);
    3321     acpiR3SetupFadt(pThis, GCPhysFadtAcpi1 + addend, GCPhysFadtAcpi2 + addend, GCPhysFacs + addend, GCPhysDsdt + addend);
     3313    acpiR3SetupDsdt(pDevIns, GCPhysDsdt + addend, pvDsdtCode, cbDsdt);
     3314    acpiCleanupDsdt(pDevIns, pvDsdtCode);
     3315    acpiR3SetupFacs(pDevIns, GCPhysFacs + addend);
     3316    acpiR3SetupFadt(pDevIns, pThis, GCPhysFadtAcpi1 + addend, GCPhysFadtAcpi2 + addend, GCPhysFacs + addend, GCPhysDsdt + addend);
    33223317
    33233318    aGCPhysRsdt[0] = GCPhysFadtAcpi1 + addend;
     
    33253320    if (pThis->u8UseIOApic)
    33263321    {
    3327         acpiR3SetupMadt(pThis, GCPhysApic + addend);
     3322        acpiR3SetupMadt(pDevIns, pThis, GCPhysApic + addend);
    33283323        aGCPhysRsdt[iMadt] = GCPhysApic + addend;
    33293324        aGCPhysXsdt[iMadt] = GCPhysApic + addend;
     
    33313326    if (pThis->fUseHpet)
    33323327    {
    3333         acpiR3SetupHpet(pThis, GCPhysHpet + addend);
     3328        acpiR3SetupHpet(pDevIns, pThis, GCPhysHpet + addend);
    33343329        aGCPhysRsdt[iHpet] = GCPhysHpet + addend;
    33353330        aGCPhysXsdt[iHpet] = GCPhysHpet + addend;
     
    33373332    if (pThis->fUseMcfg)
    33383333    {
    3339         acpiR3SetupMcfg(pThis, GCPhysMcfg + addend);
     3334        acpiR3SetupMcfg(pDevIns, pThis, GCPhysMcfg + addend);
    33403335        aGCPhysRsdt[iMcfg] = GCPhysMcfg + addend;
    33413336        aGCPhysXsdt[iMcfg] = GCPhysMcfg + addend;
     
    33443339    {
    33453340        Assert(i < MAX_CUST_TABLES);
    3346         acpiR3PhysCopy(pThis, aGCPhysCust[i] + addend, pThis->apu8CustBin[i], pThis->acbCustBin[i]);
     3341        acpiR3PhysCopy(pDevIns, aGCPhysCust[i] + addend, pThis->apu8CustBin[i], pThis->acbCustBin[i]);
    33473342        aGCPhysRsdt[iCust + i] = aGCPhysCust[i] + addend;
    33483343        aGCPhysXsdt[iCust + i] = aGCPhysCust[i] + addend;
     
    33523347    }
    33533348
    3354     acpiR3SetupSsdt(pThis, GCPhysSsdt + addend, pvSsdtCode, cbSsdt);
    3355     acpiCleanupSsdt(pThis->pDevInsR3, pvSsdtCode);
     3349    acpiR3SetupSsdt(pDevIns, GCPhysSsdt + addend, pvSsdtCode, cbSsdt);
     3350    acpiCleanupSsdt(pDevIns, pvSsdtCode);
    33563351    aGCPhysRsdt[iSsdt] = GCPhysSsdt + addend;
    33573352    aGCPhysXsdt[iSsdt] = GCPhysSsdt + addend;
    33583353
    3359     rc = acpiR3SetupRsdt(pThis, GCPhysRsdt + addend, cAddr, aGCPhysRsdt);
     3354    rc = acpiR3SetupRsdt(pDevIns, pThis, GCPhysRsdt + addend, cAddr, aGCPhysRsdt);
    33603355    if (RT_FAILURE(rc))
    33613356        return rc;
    3362     return acpiR3SetupXsdt(pThis, GCPhysXsdt + addend, cAddr, aGCPhysXsdt);
     3357    return acpiR3SetupXsdt(pDevIns, pThis, GCPhysXsdt + addend, cAddr, aGCPhysXsdt);
    33633358}
    33643359
     
    34213416        }
    34223417
    3423         int rc = acpiR3UpdateSMBusHandlers(pThis, NewIoPortBase);
     3418        int rc = acpiR3UpdateSMBusHandlers(pDevIns, pThis, NewIoPortBase);
    34243419        AssertRC(rc);
    34253420    }
     
    35343529    RT_NOREF1(enmCtx);
    35353530    PACPISTATE pThis = PDMDEVINS_2_DATA(pDevIns, PACPISTATE);
    3536     acpiR3PlantTables(pThis);
     3531    acpiR3PlantTables(pDevIns, pThis);
    35373532}
    35383533
     
    35453540
    35463541    /* Play safe: make sure that the IRQ isn't stuck after a reset. */
    3547     acpiSetIrq(pThis, 0);
    3548 
    3549     TMTimerLock(pThis->pPmTimerR3, VERR_IGNORED);
     3542    acpiSetIrq(pDevIns, 0);
     3543
     3544    PDMDevHlpTimerLock(pDevIns, pThis->hPmTimer, VERR_IGNORED);
    35503545    pThis->pm1a_en           = 0;
    35513546    pThis->pm1a_sts          = 0;
    35523547    pThis->pm1a_ctl          = 0;
    3553     pThis->u64PmTimerInitial = TMTimerGet(pThis->pPmTimerR3);
     3548    pThis->u64PmTimerInitial = PDMDevHlpTimerGet(pDevIns, pThis->hPmTimer);
    35543549    pThis->uPmTimerVal       = 0;
    3555     acpiR3PmTimerReset(pThis, pThis->u64PmTimerInitial);
     3550    acpiR3PmTimerReset(pDevIns, pThis, pThis->u64PmTimerInitial);
    35563551    pThis->uPmTimeOld        = pThis->uPmTimerVal;
    35573552    pThis->uBatteryIndex     = 0;
     
    35603555    pThis->gpe0_sts          = 0;
    35613556    pThis->uSleepState       = 0;
    3562     TMTimerUnlock(pThis->pPmTimerR3);
     3557    PDMDevHlpTimerUnlock(pDevIns, pThis->hPmTimer);
    35633558
    35643559    /* Real device behavior is resetting only the PM controller state,
     
    35703565     * state. Real device behavior is only the SMBus controller state reset,
    35713566     * but we're additionally doing the job of the BIOS. */
    3572     acpiR3UpdateSMBusHandlers(pThis, SMB_PORT_BASE);
     3567    acpiR3UpdateSMBusHandlers(pDevIns, pThis, SMB_PORT_BASE);
    35733568    acpiR3SMBusPCIBIOSFake(pDevIns, pThis);
    35743569    acpiR3SMBusResetDevice(pThis);
    3575 }
    3576 
    3577 /**
    3578  * @interface_method_impl{PDMDEVREG,pfnRelocate}
    3579  */
    3580 static DECLCALLBACK(void) acpiR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
    3581 {
    3582     PACPISTATE pThis = PDMDEVINS_2_DATA(pDevIns, PACPISTATE);
    3583     pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
    3584     pThis->pPmTimerRC = TMTimerRCPtr(pThis->pPmTimerR3);
    3585     NOREF(offDelta);
    35863570}
    35873571
     
    36183602    /** @todo move more of the code up! */
    36193603
    3620     pThis->pDevIns   = pDevIns;
    3621     pThis->pDevInsR3 = pDevIns;
    3622     pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
    3623     pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
     3604    pThis->pDevIns         = pDevIns;
    36243605    VMCPUSET_EMPTY(&pThis->CpuSetAttached);
    36253606    VMCPUSET_EMPTY(&pThis->CpuSetLocked);
     
    39873968    RTGCPHYS32 GCPhysRsdp = apicR3FindRsdpSpace();
    39883969    if (!GCPhysRsdp)
    3989         return PDMDEV_SET_ERROR(pDevIns, VERR_NO_MEMORY,
    3990                                 N_("Can not find space for RSDP. ACPI is disabled"));
    3991 
    3992     rc = acpiR3PlantTables(pThis);
     3970        return PDMDEV_SET_ERROR(pDevIns, VERR_NO_MEMORY, N_("Can not find space for RSDP. ACPI is disabled"));
     3971
     3972    rc = acpiR3PlantTables(pDevIns, pThis);
    39933973    AssertRCReturn(rc, rc);
    39943974
     
    40033983    AssertRCReturn(rc, rc);
    40043984
    4005     rc = acpiR3RegisterSMBusHandlers(pThis);
     3985    rc = acpiR3RegisterSMBusHandlers(pDevIns, pThis);
    40063986    AssertRCReturn(rc, rc);
    40073987
     
    40264006     * Create the PM timer.
    40274007     */
    4028     PTMTIMER pTimer;
    4029     rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, acpiR3PmTimer, NULL /*pvUser*/,
    4030                                 TMTIMER_FLAGS_NO_CRIT_SECT, "ACPI PM Timer", &pTimer);
     4008    rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, acpiR3PmTimer, NULL /*pvUser*/,
     4009                              TMTIMER_FLAGS_NO_CRIT_SECT, "ACPI PM Timer", &pThis->hPmTimer);
    40314010    AssertRCReturn(rc, rc);
    4032     pThis->pPmTimerR3 = pTimer;
    4033     pThis->pPmTimerR0 = TMTimerR0Ptr(pTimer);
    4034     pThis->pPmTimerRC = TMTimerRCPtr(pTimer);
    4035 
    4036     rc = TMTimerLock(pTimer, VERR_IGNORED);
     4011
     4012    rc = PDMDevHlpTimerLock(pDevIns, pThis->hPmTimer, VERR_IGNORED);
    40374013    AssertRCReturn(rc, rc);
    4038     pThis->u64PmTimerInitial = TMTimerGet(pTimer);
    4039     acpiR3PmTimerReset(pThis, pThis->u64PmTimerInitial);
    4040     TMTimerUnlock(pTimer);
     4014    pThis->u64PmTimerInitial = PDMDevHlpTimerGet(pDevIns, pThis->hPmTimer);
     4015    acpiR3PmTimerReset(pDevIns, pThis, pThis->u64PmTimerInitial);
     4016    PDMDevHlpTimerUnlock(pDevIns, pThis->hPmTimer);
    40414017
    40424018    /*
     
    41534129    /* .pfnConstruct = */           acpiR3Construct,
    41544130    /* .pfnDestruct = */            acpiR3Destruct,
    4155     /* .pfnRelocate = */            acpiR3Relocate,
     4131    /* .pfnRelocate = */            NULL,
    41564132    /* .pfnMemSetup = */            acpiR3MemSetup,
    41574133    /* .pfnPowerOn = */             NULL,
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