VirtualBox

Changeset 12634 in vbox for trunk/src/VBox/Devices/PC


Ignore:
Timestamp:
Sep 22, 2008 12:42:33 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
36916
Message:

DevAPIC: Added usage note and assertion to APIC_LOCK_VOID and update the docs of the other lock macros.

File:
1 edited

Legend:

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

    r12626 r12634  
    5555
    5656/** @def APIC_LOCK
    57  * Acquires the PDM lock. This is a NOP if locking is disabled. */
     57 * Acquires the PDM lock. */
     58#define APIC_LOCK(pThis, rc) \
     59    do { \
     60        int rc2 = (pThis)->CTX_SUFF(pApicHlp)->pfnLock((pThis)->CTX_SUFF(pDevIns), rc); \
     61        if (rc2 != VINF_SUCCESS) \
     62            return rc2; \
     63    } while (0)
     64
     65/** @def APIC_LOCK_VOID
     66 * Acquires the PDM lock and does not expect failure (i.e. ring-3 only!). */
     67#define APIC_LOCK_VOID(pThis, rc) \
     68    do { \
     69        int rc2 = (pThis)->CTX_SUFF(pApicHlp)->pfnLock((pThis)->CTX_SUFF(pDevIns), rc); \
     70        AssertLogRelRCReturnVoid(rc2); \
     71    } while (0)
     72
    5873/** @def APIC_UNLOCK
    59  * Releases the PDM lock. This is a NOP if locking is disabled. */
     74 * Releases the PDM lock. */
     75#define APIC_UNLOCK(pThis) \
     76    (pThis)->CTX_SUFF(pApicHlp)->pfnUnlock((pThis)->CTX_SUFF(pDevIns))
     77
    6078/** @def IOAPIC_LOCK
    61  * Acquires the PDM lock. This is a NOP if locking is disabled. */
    62 /** @def IOAPIC_UNLOCK
    63  * Releases the PDM lock. This is a NOP if locking is disabled. */
    64 #define APIC_LOCK(pThis, rc)                                            \
    65     do {                                                                \
    66         int rc2 = (pThis)->CTX_SUFF(pApicHlp)->pfnLock((pThis)->CTX_SUFF(pDevIns), rc); \
    67         if (rc2 != VINF_SUCCESS)                                        \
    68             return rc2;                                                 \
    69     } while (0)
    70 #define APIC_LOCK_VOID(pThis, rc)                                       \
    71     do {                                                                \
    72         int rc2 = (pThis)->CTX_SUFF(pApicHlp)->pfnLock((pThis)->CTX_SUFF(pDevIns), rc); \
    73         if (rc2 != VINF_SUCCESS)                                        \
    74             return;                                                     \
    75     } while (0)
    76 #define APIC_UNLOCK(pThis)                                              \
    77     (pThis)->CTX_SUFF(pApicHlp)->pfnUnlock((pThis)->CTX_SUFF(pDevIns))
     79 * Acquires the PDM lock. */
    7880#define IOAPIC_LOCK(pThis, rc) \
    7981    do { \
     
    8284            return rc2; \
    8385    } while (0)
     86
     87/** @def IOAPIC_UNLOCK
     88 * Releases the PDM lock. */
    8489#define IOAPIC_UNLOCK(pThis) (pThis)->CTX_SUFF(pIoApicHlp)->pfnUnlock((pThis)->CTX_SUFF(pDevIns))
    8590
    8691/**  @def LAPIC_BASE
    87  * Return address of first LAPIC state. */ 
     92 * Return address of first LAPIC state. */
    8893#define LAPIC_BASE(pThis) ((APICState*)(pThis)->CTX_SUFF(pLapics))
    8994
     
    100105            apic++;                                       \
    101106        }                                                 \
    102     } while (0) 
     107    } while (0)
    103108
    104109# define set_bit(pvBitmap, iBit)    ASMBitSet(pvBitmap, iBit)
     
    212217     /** The APIC timer - R3 Ptr. */
    213218    PTMTIMERR3      pTimerR3;
    214    
     219
    215220    /** The APIC timer - R0 Ptr. */
    216221    PTMTIMERR0      pTimerR0;
    217    
     222
    218223    /** The APIC timer - RC Ptr. */
    219224    PTMTIMERRC      pTimerRC;
    220    
     225
    221226    /** Alignment */
    222227    uint32_t Alignment1;
     
    268273    PCPDMAPICHLPR3  pApicHlpR3;
    269274    /** LAPICs states - R3 Ptr */
    270     RTR3PTR         pLapicsR3; 
     275    RTR3PTR         pLapicsR3;
    271276
    272277    /** The device instance - R0 Ptr. */
     
    275280    PCPDMAPICHLPR0  pApicHlpR0;
    276281    /** LAPICs states - R0 Ptr */
    277     RTR0PTR         pLapicsR0; 
     282    RTR0PTR         pLapicsR0;
    278283
    279284    /** The device instance - RC Ptr. */
     
    282287    PCPDMAPICHLPRC  pApicHlpRC;
    283288    /** LAPICs states - RC Ptr */
    284     RTRCPTR         pLapicsRC; 
    285    
     289    RTRCPTR         pLapicsRC;
     290
    286291    /** Alignment */
    287292    uint32_t Alignment0;
     
    289294    /** Number of attempts made to optimize TPR accesses. */
    290295    uint32_t        ulTPRPatchAttempts;
    291    
     296
    292297    /** Number of CPUs on the system (same as LAPIC count). */
    293298    uint32_t        cCpus;
     
    374379            if (deliver_bitmask)
    375380                d = ffs_bit(deliver_bitmask);
    376             if (d >= 0) 
     381            if (d >= 0)
    377382            {
    378383                APICState* apic = LAPIC_BASE(dev) + d;
     
    453458    APICState *s = getLapic(dev);
    454459    Log(("cpu_set_apic_base: %016RX64\n", val));
    455    
     460
    456461    /** @todo: do we need to lock here ? */
    457462    /* APIC_LOCK_VOID(dev, VERR_INTERNAL_ERROR); */
     
    657662        return false;
    658663    APICState *s = getLapic(dev);
    659    
     664
    660665    /*
    661666     * All our callbacks now come from single IOAPIC, thus locking
    662      * seems to be excessive now (@todo: check) 
     667     * seems to be excessive now (@todo: check)
    663668     */
    664669    irrv = get_highest_priority_int(s->irr);
     
    725730    uint32_t mask = 0;
    726731
    727     if (dest_mode == 0) 
     732    if (dest_mode == 0)
    728733    {
    729         if (dest == 0xff) 
     734        if (dest == 0xff)
    730735            mask = 0xff;
    731         else 
     736        else
    732737            mask = 1 << dest;
    733     } 
    734     else 
     738    }
     739    else
    735740    {
    736741        APICState *apic = LAPIC_BASE(dev);
    737742        uint32_t i;
    738        
     743
    739744        /* XXX: cluster mode */
    740         for(i = 0; i < dev->cCpus; i++) 
     745        for(i = 0; i < dev->cCpus; i++)
    741746        {
    742             if (apic->dest_mode == 0xf) 
     747            if (apic->dest_mode == 0xf)
    743748            {
    744749                if (dest & apic->log_dest)
    745750                    mask |= (1 << apic->id);
    746             } 
    747             else if (apic->dest_mode == 0x0) 
     751            }
     752            else if (apic->dest_mode == 0x0)
    748753            {
    749                 if ((dest & 0xf0) == (apic->log_dest & 0xf0) 
     754                if ((dest & 0xf0) == (apic->log_dest & 0xf0)
    750755                    &&
    751                     (dest & apic->log_dest & 0x0f)) 
     756                    (dest & apic->log_dest & 0x0f))
    752757                {
    753758                    mask |= (1 << i);
     
    802807#endif
    803808}
    804 static void apic_deliver(APICDeviceInfo* dev, APICState *s, 
     809static void apic_deliver(APICDeviceInfo* dev, APICState *s,
    805810                         uint8_t dest, uint8_t dest_mode,
    806811                         uint8_t delivery_mode, uint8_t vector_num,
     
    814819
    815820    LogFlow(("apic_deliver dest=%x dest_mode=%x delivery_mode=%x vector_num=%x polarity=%x trigger_mode=%x\n", dest, dest_mode, delivery_mode, vector_num, polarity, trigger_mode));
    816    
     821
    817822    switch (dest_shorthand) {
    818823        case 0:
     
    833838            break;
    834839    }
    835    
     840
    836841    switch (delivery_mode) {
    837842        case APIC_DM_LOWPRI:
     
    16661671#endif
    16671672
    1668     /** @todo: add LAPIC range validity checks (different LAPICs can theoretically have 
     1673    /** @todo: add LAPIC range validity checks (different LAPICs can theoretically have
    16691674               different physical addresses, see #3092) */
    16701675
     
    17201725#endif
    17211726
    1722     /** @todo: add LAPIC range validity checks (multiple LAPICs can theoretically have 
     1727    /** @todo: add LAPIC range validity checks (multiple LAPICs can theoretically have
    17231728               different physical addresses, see #3092) */
    17241729
     
    17691774    APICDeviceInfo *dev = PDMINS_2_DATA(pDevIns, APICDeviceInfo *);
    17701775    /* load all APICs data, @todo: is it correct? */
    1771     foreach_apic(dev, 0xffffffff, 
     1776    foreach_apic(dev, 0xffffffff,
    17721777                 if (apic_load(pSSMHandle, apic, u32Version))
    17731778                 {
     
    18101815    APICDeviceInfo *dev = PDMINS_2_DATA(pDevIns, APICDeviceInfo *);
    18111816#ifdef VBOX_WITH_SMP_GUESTS
    1812     LogRel(("[SMP]: relocate apic on %llx\n", offDelta));   
     1817    LogRel(("[SMP]: relocate apic on %llx\n", offDelta));
    18131818#endif
    18141819    dev->pDevInsRC  = PDMDEVINS_2_RCPTR(pDevIns);
     
    18451850    APICState       *apic;
    18461851
    1847     /* 
     1852    /*
    18481853     * Only single device instance.
    18491854     */
     
    18531858     * Validate configuration.
    18541859     */
    1855     if (!CFGMR3AreValuesValid(pCfgHandle, 
    1856                               "IOAPIC\0" 
    1857                               "GCEnabled\0" 
     1860    if (!CFGMR3AreValuesValid(pCfgHandle,
     1861                              "IOAPIC\0"
     1862                              "GCEnabled\0"
    18581863                              "R0Enabled\0"
    18591864                              "NumCPUs\0"))
     
    18741879        return PDMDEV_SET_ERROR(pDevIns, rc,
    18751880                                N_("Configuration error: Failed to query boolean value \"R0Enabled\""));
    1876    
     1881
    18771882    rc = CFGMR3QueryU32Def(pCfgHandle, "NumCPUs", &cCpus, 1);
    18781883    if (RT_FAILURE(rc))
     
    18911896
    18921897    PVM pVM = PDMDevHlpGetVM(pDevIns);
    1893     /* 
     1898    /*
    18941899     * We are not freeing this memory, as it's automatically released when guest exits.
    18951900     */
     
    18991904    pThis->pLapicsR0 = MMHyperR3ToR0(pVM, pThis->pLapicsR3);
    19001905    pThis->pLapicsRC = MMHyperR3ToRC(pVM, pThis->pLapicsR3);
    1901    
     1906
    19021907    for (i = 0, apic = LAPIC_BASE(pThis); i < cCpus; i++)
    19031908    {
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