VirtualBox

Changeset 40907 in vbox for trunk/src/VBox/VMM/VMMRC


Ignore:
Timestamp:
Apr 13, 2012 8:50:14 PM (13 years ago)
Author:
vboxsync
Message:

Working on tracking IRQs for tracing and logging purposes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMRC/PDMRCDevice.cpp

    r37410 r40907  
    3434#include <iprt/assert.h>
    3535#include <iprt/string.h>
     36
     37#include "dtrace/VBoxVMM.h"
     38#include "PDMInline.h"
    3639
    3740
     
    5457*   Internal Functions                                                         *
    5558*******************************************************************************/
    56 static void pdmRCIsaSetIrq(PVM pVM, int iIrq, int iLevel);
    57 static void pdmRCIoApicSetIrq(PVM pVM, int iIrq, int iLevel);
    58 static void pdmRCIoApicSendMsi(PVM pVM, RTGCPHYS GCAddr, uint32_t uValue);
     59static bool pdmRCIsaSetIrq(PVM pVM, int iIrq, int iLevel, uint32_t uTagSrc);
     60
    5961
    6062/** @name Raw-Mode Context Device Helpers
     
    7173    PPCIDEVICE  pPciDev = pDevIns->Internal.s.pPciDeviceRC;
    7274    PPDMPCIBUS  pPciBus = pDevIns->Internal.s.pPciBusRC;
     75
     76    pdmLock(pVM);
     77    uint32_t uTagSrc;
     78    if (iLevel & PDM_IRQ_LEVEL_HIGH)
     79    {
     80        pDevIns->Internal.s.uLastIrqTag = uTagSrc = pdmCalcIrqTag(pVM, pDevIns->idTracing);
     81        if (iLevel == PDM_IRQ_LEVEL_HIGH)
     82            VBOXVMM_PDM_IRQ_HIGH(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
     83        else
     84            VBOXVMM_PDM_IRQ_HILO(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
     85    }
     86    else
     87        uTagSrc = pDevIns->Internal.s.uLastIrqTag;
     88
    7389    if (    pPciDev
    7490        &&  pPciBus
    7591        &&  pPciBus->pDevInsRC)
    7692    {
    77         pdmLock(pVM);
    78         pPciBus->pfnSetIrqRC(pPciBus->pDevInsRC, pPciDev, iIrq, iLevel);
     93        pPciBus->pfnSetIrqRC(pPciBus->pDevInsRC, pPciDev, iIrq, iLevel, uTagSrc);
     94
    7995        pdmUnlock(pVM);
     96
     97        if (iLevel == PDM_IRQ_LEVEL_LOW)
     98            VBOXVMM_PDM_IRQ_LOW(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
    8099    }
    81100    else
    82101    {
     102        pdmUnlock(pVM);
     103
    83104        /* queue for ring-3 execution. */
    84105        PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueRC);
    85         if (pTask)
    86         {
    87             pTask->enmOp = PDMDEVHLPTASKOP_PCI_SET_IRQ;
    88             pTask->pDevInsR3 = PDMDEVINS_2_R3PTR(pDevIns);
    89             pTask->u.SetIRQ.iIrq = iIrq;
    90             pTask->u.SetIRQ.iLevel = iLevel;
    91 
    92             PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueRC, &pTask->Core, 0);
    93         }
    94         else
    95             AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
    96     }
    97 
    98     LogFlow(("pdmRCDevHlp_PCISetIrq: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
     106        AssertReturnVoid(pTask);
     107
     108        pTask->enmOp = PDMDEVHLPTASKOP_PCI_SET_IRQ;
     109        pTask->pDevInsR3 = PDMDEVINS_2_R3PTR(pDevIns);
     110        pTask->u.SetIRQ.iIrq = iIrq;
     111        pTask->u.SetIRQ.iLevel = iLevel;
     112        pTask->u.SetIRQ.uTagSrc = uTagSrc;
     113
     114        PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueRC, &pTask->Core, 0);
     115    }
     116
     117    LogFlow(("pdmRCDevHlp_PCISetIrq: caller=%p/%d: returns void; uTagSrc=%#x\n", pDevIns, pDevIns->iInstance, uTagSrc));
    99118}
    100119
     
    105124    PDMDEV_ASSERT_DEVINS(pDevIns);
    106125    LogFlow(("pdmRCDevHlp_ISASetIrq: caller=%p/%d: iIrq=%d iLevel=%d\n", pDevIns, pDevIns->iInstance, iIrq, iLevel));
    107 
    108     pdmRCIsaSetIrq(pDevIns->Internal.s.pVMRC, iIrq, iLevel);
    109 
    110     LogFlow(("pdmRCDevHlp_ISASetIrq: caller=%p/%d: returns void\n", pDevIns, pDevIns->iInstance));
     126    PVM pVM = pDevIns->Internal.s.pVMRC;
     127
     128    pdmLock(pVM);
     129    uint32_t uTagSrc;
     130    if (iLevel & PDM_IRQ_LEVEL_HIGH)
     131    {
     132        pDevIns->Internal.s.uLastIrqTag = uTagSrc = pdmCalcIrqTag(pVM, pDevIns->idTracing);
     133        if (iLevel == PDM_IRQ_LEVEL_HIGH)
     134            VBOXVMM_PDM_IRQ_HIGH(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
     135        else
     136            VBOXVMM_PDM_IRQ_HILO(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
     137    }
     138    else
     139        uTagSrc = pDevIns->Internal.s.uLastIrqTag;
     140
     141    bool fRc = pdmRCIsaSetIrq(pVM, iIrq, iLevel, uTagSrc);
     142
     143    if (iLevel == PDM_IRQ_LEVEL_LOW && fRc)
     144        VBOXVMM_PDM_IRQ_LOW(VMMGetCpu(pVM), RT_LOWORD(uTagSrc), RT_HIWORD(uTagSrc));
     145    pdmUnlock(pVM);
     146    LogFlow(("pdmRCDevHlp_ISASetIrq: caller=%p/%d: returns void; uTagSrc=%#x\n", pDevIns, pDevIns->iInstance, uTagSrc));
    111147}
    112148
     
    531567/** @interface_method_impl{PDMIOAPICHLPRC,pfnApicBusDeliver} */
    532568static DECLCALLBACK(int) pdmRCIoApicHlp_ApicBusDeliver(PPDMDEVINS pDevIns, uint8_t u8Dest, uint8_t u8DestMode, uint8_t u8DeliveryMode,
    533                                                        uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode)
     569                                                       uint8_t iVector, uint8_t u8Polarity, uint8_t u8TriggerMode, uint32_t uTagSrc)
    534570{
    535571    PDMDEV_ASSERT_DEVINS(pDevIns);
    536572    PVM pVM = pDevIns->Internal.s.pVMRC;
    537     LogFlow(("pdmRCIoApicHlp_ApicBusDeliver: caller=%p/%d: u8Dest=%RX8 u8DestMode=%RX8 u8DeliveryMode=%RX8 iVector=%RX8 u8Polarity=%RX8 u8TriggerMode=%RX8\n",
    538              pDevIns, pDevIns->iInstance, u8Dest, u8DestMode, u8DeliveryMode, iVector, u8Polarity, u8TriggerMode));
     573    LogFlow(("pdmRCIoApicHlp_ApicBusDeliver: caller=%p/%d: u8Dest=%RX8 u8DestMode=%RX8 u8DeliveryMode=%RX8 iVector=%RX8 u8Polarity=%RX8 u8TriggerMode=%RX8 uTagSrc=%#x\n",
     574             pDevIns, pDevIns->iInstance, u8Dest, u8DestMode, u8DeliveryMode, iVector, u8Polarity, u8TriggerMode, uTagSrc));
     575    Assert(pVM->pdm.s.Apic.pDevInsRC);
    539576    if (pVM->pdm.s.Apic.pfnBusDeliverRC)
    540         return pVM->pdm.s.Apic.pfnBusDeliverRC(pVM->pdm.s.Apic.pDevInsRC, u8Dest, u8DestMode, u8DeliveryMode, iVector, u8Polarity, u8TriggerMode);
     577        return pVM->pdm.s.Apic.pfnBusDeliverRC(pVM->pdm.s.Apic.pDevInsRC, u8Dest, u8DestMode, u8DeliveryMode, iVector,
     578                                               u8Polarity, u8TriggerMode, uTagSrc);
    541579    return VINF_SUCCESS;
    542580}
     
    581619
    582620/** @interface_method_impl{PDMPCIHLPRC,pfnIsaSetIrq} */
    583 static DECLCALLBACK(void) pdmRCPciHlp_IsaSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
    584 {
    585     PDMDEV_ASSERT_DEVINS(pDevIns);
    586     Log4(("pdmRCPciHlp_IsaSetIrq: iIrq=%d iLevel=%d\n", iIrq, iLevel));
    587     pdmRCIsaSetIrq(pDevIns->Internal.s.pVMRC, iIrq, iLevel);
     621static DECLCALLBACK(void) pdmRCPciHlp_IsaSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc)
     622{
     623    PDMDEV_ASSERT_DEVINS(pDevIns);
     624    Log4(("pdmRCPciHlp_IsaSetIrq: iIrq=%d iLevel=%d uTagSrc=%#x\n", iIrq, iLevel, uTagSrc));
     625    PVM pVM = pDevIns->Internal.s.pVMRC;
     626
     627    pdmLock(pVM);
     628    pdmRCIsaSetIrq(pDevIns->Internal.s.pVMRC, iIrq, iLevel, uTagSrc);
     629    pdmUnlock(pVM);
    588630}
    589631
    590632
    591633/** @interface_method_impl{PDMPCIHLPRC,pfnIoApicSetIrq} */
    592 static DECLCALLBACK(void) pdmRCPciHlp_IoApicSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel)
    593 {
    594     PDMDEV_ASSERT_DEVINS(pDevIns);
    595     Log4(("pdmRCPciHlp_IoApicSetIrq: iIrq=%d iLevel=%d\n", iIrq, iLevel));
    596     pdmRCIoApicSetIrq(pDevIns->Internal.s.pVMRC, iIrq, iLevel);
    597 }
     634static DECLCALLBACK(void) pdmRCPciHlp_IoApicSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc)
     635{
     636    PDMDEV_ASSERT_DEVINS(pDevIns);
     637    Log4(("pdmRCPciHlp_IoApicSetIrq: iIrq=%d iLevel=%d uTagSrc=%#x\n", iIrq, iLevel, uTagSrc));
     638    PVM pVM = pDevIns->Internal.s.pVMRC;
     639
     640    if (pVM->pdm.s.IoApic.pDevInsRC)
     641    {
     642        pdmLock(pVM);
     643        pVM->pdm.s.IoApic.pfnSetIrqRC(pVM->pdm.s.IoApic.pDevInsRC, iIrq, iLevel, uTagSrc);
     644        pdmUnlock(pVM);
     645    }
     646    else if (pVM->pdm.s.IoApic.pDevInsR3)
     647    {
     648        /* queue for ring-3 execution. */
     649        PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueRC);
     650        if (pTask)
     651        {
     652            pTask->enmOp = PDMDEVHLPTASKOP_IOAPIC_SET_IRQ;
     653            pTask->pDevInsR3 = NIL_RTR3PTR; /* not required */
     654            pTask->u.SetIRQ.iIrq = iIrq;
     655            pTask->u.SetIRQ.iLevel = iLevel;
     656            pTask->u.SetIRQ.uTagSrc = uTagSrc;
     657
     658            PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueRC, &pTask->Core, 0);
     659        }
     660        else
     661            AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
     662    }
     663}
     664
    598665
    599666/** @interface_method_impl{PDMPCIHLPRC,pfnIoApicSendMsi} */
    600 static DECLCALLBACK(void) pdmRCPciHlp_IoApicSendMsi(PPDMDEVINS pDevIns, RTGCPHYS GCAddr, uint32_t uValue)
    601 {
    602     PDMDEV_ASSERT_DEVINS(pDevIns);
    603     Log4(("pdmRCPciHlp_IoApicSendMsi: Address=%p Value=%d\n", GCAddr, uValue));
    604     pdmRCIoApicSendMsi(pDevIns->Internal.s.pVMRC, GCAddr, uValue);
     667static DECLCALLBACK(void) pdmRCPciHlp_IoApicSendMsi(PPDMDEVINS pDevIns, RTGCPHYS GCPhys, uint32_t uValue, uint32_t uTagSrc)
     668{
     669    PDMDEV_ASSERT_DEVINS(pDevIns);
     670    Log4(("pdmRCPciHlp_IoApicSendMsi: GCPhys=%p uValue=%d uTagSrc=%#x\n", GCPhys, uValue, uTagSrc));
     671    PVM pVM = pDevIns->Internal.s.pVMRC;
     672
     673    if (pVM->pdm.s.IoApic.pDevInsRC)
     674    {
     675        pdmLock(pVM);
     676        pVM->pdm.s.IoApic.pfnSendMsiRC(pVM->pdm.s.IoApic.pDevInsRC, GCPhys, uValue, uTagSrc);
     677        pdmUnlock(pVM);
     678    }
     679    else
     680    {
     681        AssertFatalMsgFailed(("Lazy bastarts!"));
     682    }
    605683}
    606684
     
    764842
    765843/**
    766  * Sets an irq on the I/O APIC.
     844 * Sets an irq on the PIC and I/O APIC.
    767845 *
    768  * @param   pVM     The VM handle.
    769  * @param   iIrq    The irq.
    770  * @param   iLevel  The new level.
    771  */
    772 static void pdmRCIsaSetIrq(PVM pVM, int iIrq, int iLevel)
    773 {
    774     if (    (   pVM->pdm.s.IoApic.pDevInsRC
    775              || !pVM->pdm.s.IoApic.pDevInsR3)
    776         &&  (   pVM->pdm.s.Pic.pDevInsRC
    777              || !pVM->pdm.s.Pic.pDevInsR3))
    778     {
    779         pdmLock(pVM);
     846 * @returns true if     delivered, false if postponed.
     847 * @param   pVM         The VM handle.
     848 * @param   iIrq        The irq.
     849 * @param   iLevel      The new level.
     850 * @param   uTagSrc     The IRQ tag and source.
     851 *
     852 * @remarks The caller holds the PDM lock.
     853 */
     854static bool pdmRCIsaSetIrq(PVM pVM, int iIrq, int iLevel, uint32_t uTagSrc)
     855{
     856    if (RT_LIKELY(    (   pVM->pdm.s.IoApic.pDevInsRC
     857                       || !pVM->pdm.s.IoApic.pDevInsR3)
     858                  &&  (   pVM->pdm.s.Pic.pDevInsRC
     859                       || !pVM->pdm.s.Pic.pDevInsR3)))
     860    {
    780861        if (pVM->pdm.s.Pic.pDevInsRC)
    781             pVM->pdm.s.Pic.pfnSetIrqRC(pVM->pdm.s.Pic.pDevInsRC, iIrq, iLevel);
     862            pVM->pdm.s.Pic.pfnSetIrqRC(pVM->pdm.s.Pic.pDevInsRC, iIrq, iLevel, uTagSrc);
    782863        if (pVM->pdm.s.IoApic.pDevInsRC)
    783             pVM->pdm.s.IoApic.pfnSetIrqRC(pVM->pdm.s.IoApic.pDevInsRC, iIrq, iLevel);
    784         pdmUnlock(pVM);
    785     }
    786     else
    787     {
    788         /* queue for ring-3 execution. */
    789         PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueRC);
    790         if (pTask)
    791         {
    792             pTask->enmOp = PDMDEVHLPTASKOP_ISA_SET_IRQ;
    793             pTask->pDevInsR3 = NIL_RTR3PTR; /* not required */
    794             pTask->u.SetIRQ.iIrq = iIrq;
    795             pTask->u.SetIRQ.iLevel = iLevel;
    796 
    797             PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueRC, &pTask->Core, 0);
    798         }
    799         else
    800             AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
    801     }
    802 }
    803 
    804 
    805 /**
    806  * Sets an irq on the I/O APIC.
    807  *
    808  * @param   pVM     The VM handle.
    809  * @param   iIrq    The irq.
    810  * @param   iLevel  The new level.
    811  */
    812 static void pdmRCIoApicSetIrq(PVM pVM, int iIrq, int iLevel)
    813 {
    814     if (pVM->pdm.s.IoApic.pDevInsRC)
    815     {
    816         pdmLock(pVM);
    817         pVM->pdm.s.IoApic.pfnSetIrqRC(pVM->pdm.s.IoApic.pDevInsRC, iIrq, iLevel);
    818         pdmUnlock(pVM);
    819     }
    820     else if (pVM->pdm.s.IoApic.pDevInsR3)
    821     {
    822         /* queue for ring-3 execution. */
    823         PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueRC);
    824         if (pTask)
    825         {
    826             pTask->enmOp = PDMDEVHLPTASKOP_IOAPIC_SET_IRQ;
    827             pTask->pDevInsR3 = NIL_RTR3PTR; /* not required */
    828             pTask->u.SetIRQ.iIrq = iIrq;
    829             pTask->u.SetIRQ.iLevel = iLevel;
    830 
    831             PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueRC, &pTask->Core, 0);
    832         }
    833         else
    834             AssertMsgFailed(("We're out of devhlp queue items!!!\n"));
    835     }
    836 }
    837 
    838 
    839 /**
    840  * Sends an MSI to I/O APIC.
    841  *
    842  * @param   pVM     The VM handle.
    843  * @param   GCAddr  Address of the message.
    844  * @param   uValue  Value of the message.
    845  */
    846 static void pdmRCIoApicSendMsi(PVM pVM, RTGCPHYS GCAddr, uint32_t uValue)
    847 {
    848     if (pVM->pdm.s.IoApic.pDevInsRC)
    849     {
    850         pdmLock(pVM);
    851         pVM->pdm.s.IoApic.pfnSendMsiRC(pVM->pdm.s.IoApic.pDevInsRC, GCAddr, uValue);
    852         pdmUnlock(pVM);
    853     }
    854 }
     864            pVM->pdm.s.IoApic.pfnSetIrqRC(pVM->pdm.s.IoApic.pDevInsRC, iIrq, iLevel, uTagSrc);
     865        return true;
     866    }
     867
     868    /* queue for ring-3 execution. */
     869    PPDMDEVHLPTASK pTask = (PPDMDEVHLPTASK)PDMQueueAlloc(pVM->pdm.s.pDevHlpQueueRC);
     870    AssertReturn(pTask, false);
     871
     872    pTask->enmOp = PDMDEVHLPTASKOP_ISA_SET_IRQ;
     873    pTask->pDevInsR3 = NIL_RTR3PTR; /* not required */
     874    pTask->u.SetIRQ.iIrq = iIrq;
     875    pTask->u.SetIRQ.iLevel = iLevel;
     876    pTask->u.SetIRQ.uTagSrc = uTagSrc;
     877
     878    PDMQueueInsertEx(pVM->pdm.s.pDevHlpQueueRC, &pTask->Core, 0);
     879    return false;
     880}
     881
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