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