PDMAll.cpp revision 675f16ba1814ff54bdf00391a6d126a25963f88a
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * PDM Critical Sections
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * available from http://www.virtualbox.org. This file is free software;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * you can redistribute it and/or modify it under the terms of the GNU
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * General Public License (GPL) as published by the Free Software
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * additional information or have any questions.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/*******************************************************************************
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync* Header Files *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync*******************************************************************************/
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Gets the pending interrupt.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @returns VBox status code.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pVM VM handle.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pu8Interrupt Where to store the interrupt on success.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncPDMDECL(int) PDMGetInterrupt(PVM pVM, uint8_t *pu8Interrupt)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * The local APIC has a higer priority than the PIC.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pfnGetInterrupt));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync int i = pVM->pdm.s.Apic.CTXALLSUFF(pfnGetInterrupt)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (i >= 0)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Check the PIC.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pdm.s.Pic.CTXALLSUFF(pfnGetInterrupt));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync int i = pVM->pdm.s.Pic.CTXALLSUFF(pfnGetInterrupt)(pVM->pdm.s.Pic.CTXALLSUFF(pDevIns));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (i >= 0)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /** @todo Figure out exactly why we can get here without anything being set. (REM) */
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync * Sets the pending interrupt.
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync * @returns VBox status code.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pVM VM handle.
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync * @param u8Irq The IRQ line.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param u8Level The new level.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncPDMDECL(int) PDMIsaSetIrq(PVM pVM, uint8_t u8Irq, uint8_t u8Level)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pVM->pdm.s.Pic.CTXALLSUFF(pfnSetIrq)(pVM->pdm.s.Pic.CTXALLSUFF(pDevIns), u8Irq, u8Level);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pVM->pdm.s.IoApic.CTXALLSUFF(pfnSetIrq)(pVM->pdm.s.IoApic.CTXALLSUFF(pDevIns), u8Irq, u8Level);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Sets the pending I/O APIC interrupt.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @returns VBox status code.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pVM VM handle.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param u8Irq The IRQ line.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param u8Level The new level.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncPDMDECL(int) PDMIoApicSetIrq(PVM pVM, uint8_t u8Irq, uint8_t u8Level)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pVM->pdm.s.IoApic.CTXALLSUFF(pfnSetIrq)(pVM->pdm.s.IoApic.CTXALLSUFF(pDevIns), u8Irq, u8Level);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Set the APIC base.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @returns VBox status code.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pVM VM handle.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param u64Base The new base.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncPDMDECL(int) PDMApicSetBase(PVM pVM, uint64_t u64Base)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pVM->pdm.s.Apic.CTXALLSUFF(pfnSetBase)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns), u64Base);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Get the APIC base.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @returns VBox status code.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pVM VM handle.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pu64Base Where to store the APIC base.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncPDMDECL(int) PDMApicGetBase(PVM pVM, uint64_t *pu64Base)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *pu64Base = pVM->pdm.s.Apic.CTXALLSUFF(pfnGetBase)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Check if the APIC has a pending interrupt/if a TPR change would active one
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @returns Pending interrupt yes/no
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pDevIns Device instance of the APIC.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pfPending Pending state (out)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncPDMDECL(int) PDMApicHasPendingIrq(PVM pVM, bool *pfPending)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *pfPending = pVM->pdm.s.Apic.CTXALLSUFF(pfnHasPendingIrq)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Set the TPR (task priority register?).
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @returns VBox status code.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pVM VM handle.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param u8TPR The new TPR.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pVM->pdm.s.Apic.CTXALLSUFF(pfnSetTPR)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns), u8TPR);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Get the TPR (task priority register?).
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @returns The current TPR.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pVM VM handle.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pu8TPR Where to store the TRP.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncPDMDECL(int) PDMApicGetTPR(PVM pVM, uint8_t *pu8TPR)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *pu8TPR = pVM->pdm.s.Apic.CTXALLSUFF(pfnGetTPR)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Locks PDM.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * This might call back to Ring-3 in order to deal with lock contention in GC and R3.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pVM The VM handle.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync int rc = PDMCritSectEnter(&pVM->pdm.s.CritSect, VERR_INTERNAL_ERROR);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync int rc = PDMCritSectEnter(&pVM->pdm.s.CritSect, VERR_GENERAL_FAILURE);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Locks PDM but don't go to ring-3 if it's owned by someone.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @returns VINF_SUCCESS on success.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @returns rc if we're in GC or R0 and can't get the lock.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pVM The VM handle.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param rc The RC to return in GC or R0 when we can't get the lock.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Unlocks PDM.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pVM The VM handle.