PDMAll.cpp revision 06bff04f33aeff5331b664c379f31b4969efc6fc
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/* $Id$ */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/** @file
d6aa6429f99fb7648883eb612f8a52b9aaf3bff4vboxsync * PDM Critical Sections
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *
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.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *
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
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync/*******************************************************************************
aba0e602e244ae7c4f11b50fc6d2440f5a762038vboxsync* Header Files *
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync*******************************************************************************/
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#define LOG_GROUP LOG_GROUP_PDM
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include "PDMInternal.h"
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <VBox/pdm.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <VBox/mm.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <VBox/vm.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <VBox/err.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#include <VBox/log.h>
b8f36a8f77f0140f48170d5b3cd9ee9ea1c14294vboxsync#include <iprt/asm.h>
5debbbcc37114f1dbecaecfc66c81ea2fbda6140vboxsync#include <iprt/assert.h>
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/**
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Gets the pending interrupt.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *
208aaecb51db539a2f7f3d25f38dd2efd0f014a3vboxsync * @returns VBox status code.
208aaecb51db539a2f7f3d25f38dd2efd0f014a3vboxsync * @param pVM VM handle.
208aaecb51db539a2f7f3d25f38dd2efd0f014a3vboxsync * @param pu8Interrupt Where to store the interrupt on success.
208aaecb51db539a2f7f3d25f38dd2efd0f014a3vboxsync */
208aaecb51db539a2f7f3d25f38dd2efd0f014a3vboxsyncPDMDECL(int) PDMGetInterrupt(PVM pVM, uint8_t *pu8Interrupt)
208aaecb51db539a2f7f3d25f38dd2efd0f014a3vboxsync{
208aaecb51db539a2f7f3d25f38dd2efd0f014a3vboxsync pdmLock(pVM);
208aaecb51db539a2f7f3d25f38dd2efd0f014a3vboxsync
208aaecb51db539a2f7f3d25f38dd2efd0f014a3vboxsync /*
208aaecb51db539a2f7f3d25f38dd2efd0f014a3vboxsync * The local APIC has a higer priority than the PIC.
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync */
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync if (VM_FF_ISSET(pVM, VM_FF_INTERRUPT_APIC))
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync {
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_APIC);
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pfnGetInterrupt));
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync int i = pVM->pdm.s.Apic.CTXALLSUFF(pfnGetInterrupt)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
d6aa6429f99fb7648883eb612f8a52b9aaf3bff4vboxsync AssertMsg(i <= 255 && i >= 0, ("i=%d\n", i));
d6aa6429f99fb7648883eb612f8a52b9aaf3bff4vboxsync if (i >= 0)
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync {
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync pdmUnlock(pVM);
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync *pu8Interrupt = (uint8_t)i;
1f6b1f68eb26f8af1f9a4b5ffd00df66ad7af1devboxsync return VINF_SUCCESS;
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync }
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync }
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync /*
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync * Check the PIC.
d44cb80e1d772854c10ef9ae03daba8dcf61d389vboxsync */
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync if (VM_FF_ISSET(pVM, VM_FF_INTERRUPT_PIC))
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_PIC);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync Assert(pVM->pdm.s.Pic.CTXALLSUFF(pDevIns));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync Assert(pVM->pdm.s.Pic.CTXALLSUFF(pfnGetInterrupt));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync int i = pVM->pdm.s.Pic.CTXALLSUFF(pfnGetInterrupt)(pVM->pdm.s.Pic.CTXALLSUFF(pDevIns));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync AssertMsg(i <= 255 && i >= 0, ("i=%d\n", i));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (i >= 0)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pdmUnlock(pVM);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *pu8Interrupt = (uint8_t)i;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return VINF_SUCCESS;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
afdf6eaa7e1a0e25a511d96598400f812a5296e3vboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync /** @todo Figure out exactly why we can get here without anything being set. (REM) */
48d832e07616531bbb720d9c98103c83b561ebb6vboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pdmUnlock(pVM);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return VERR_NO_DATA;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync}
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/**
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Sets the pending interrupt.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @returns VBox status code.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @param pVM VM handle.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @param u8Irq The IRQ line.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @param u8Level The new level.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsyncPDMDECL(int) PDMIsaSetIrq(PVM pVM, uint8_t u8Irq, uint8_t u8Level)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync{
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pdmLock(pVM);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync int rc = VERR_PDM_NO_PIC_INSTANCE;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (pVM->pdm.s.Pic.CTXALLSUFF(pDevIns))
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync Assert(pVM->pdm.s.Pic.CTXALLSUFF(pfnSetIrq));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pVM->pdm.s.Pic.CTXALLSUFF(pfnSetIrq)(pVM->pdm.s.Pic.CTXALLSUFF(pDevIns), u8Irq, u8Level);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync rc = VINF_SUCCESS;
afdf6eaa7e1a0e25a511d96598400f812a5296e3vboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (pVM->pdm.s.IoApic.CTXALLSUFF(pDevIns))
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync Assert(pVM->pdm.s.IoApic.CTXALLSUFF(pfnSetIrq));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pVM->pdm.s.IoApic.CTXALLSUFF(pfnSetIrq)(pVM->pdm.s.IoApic.CTXALLSUFF(pDevIns), u8Irq, u8Level);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync rc = VINF_SUCCESS;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pdmUnlock(pVM);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return rc;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync}
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/**
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Sets the pending I/O APIC interrupt.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @returns VBox status code.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @param pVM VM handle.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @param u8Irq The IRQ line.
e7e60b177e688900656c04404c5123f1dfa1d02cvboxsync * @param u8Level The new level.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsyncPDMDECL(int) PDMIoApicSetIrq(PVM pVM, uint8_t u8Irq, uint8_t u8Level)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync{
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (pVM->pdm.s.IoApic.CTXALLSUFF(pDevIns))
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync Assert(pVM->pdm.s.IoApic.CTXALLSUFF(pfnSetIrq));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pdmLock(pVM);
afdf6eaa7e1a0e25a511d96598400f812a5296e3vboxsync pVM->pdm.s.IoApic.CTXALLSUFF(pfnSetIrq)(pVM->pdm.s.IoApic.CTXALLSUFF(pDevIns), u8Irq, u8Level);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pdmUnlock(pVM);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return VINF_SUCCESS;
ada022f71e6728d4f2b15e643d35aa94992656c7vboxsync }
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync return VERR_PDM_NO_PIC_INSTANCE;
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync}
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/**
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Set the APIC base.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @returns VBox status code.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @param pVM VM handle.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @param u64Base The new base.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync */
afdf6eaa7e1a0e25a511d96598400f812a5296e3vboxsyncPDMDECL(int) PDMApicSetBase(PVM pVM, uint64_t u64Base)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync{
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (pVM->pdm.s.Apic.CTXALLSUFF(pDevIns))
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pfnSetBase));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pdmLock(pVM);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pVM->pdm.s.Apic.CTXALLSUFF(pfnSetBase)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns), u64Base);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pdmUnlock(pVM);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return VINF_SUCCESS;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return VERR_PDM_NO_APIC_INSTANCE;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync}
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/**
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Get the APIC base.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync * @returns VBox status code.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @param pVM VM handle.
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync * @param pu64Base Where to store the APIC base.
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync */
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsyncPDMDECL(int) PDMApicGetBase(PVM pVM, uint64_t *pu64Base)
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync{
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (pVM->pdm.s.Apic.CTXALLSUFF(pDevIns))
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pfnGetBase));
e7e60b177e688900656c04404c5123f1dfa1d02cvboxsync pdmLock(pVM);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *pu64Base = pVM->pdm.s.Apic.CTXALLSUFF(pfnGetBase)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pdmUnlock(pVM);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return VINF_SUCCESS;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *pu64Base = 0;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return VERR_PDM_NO_APIC_INSTANCE;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync}
afdf6eaa7e1a0e25a511d96598400f812a5296e3vboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/**
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Check if the APIC has a pending interrupt/if a TPR change would active one.
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync *
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync * @returns VINF_SUCCESS or VERR_PDM_NO_APIC_INSTANCE.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @param pDevIns Device instance of the APIC.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @param pfPending Pending state (out).
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsyncPDMDECL(int) PDMApicHasPendingIrq(PVM pVM, bool *pfPending)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync{
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (pVM->pdm.s.Apic.CTXALLSUFF(pDevIns))
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pfnSetTPR));
afdf6eaa7e1a0e25a511d96598400f812a5296e3vboxsync pdmLock(pVM);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *pfPending = pVM->pdm.s.Apic.CTXALLSUFF(pfnHasPendingIrq)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync pdmUnlock(pVM);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return VINF_SUCCESS;
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync return VERR_PDM_NO_APIC_INSTANCE;
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync}
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/**
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Set the TPR (task priority register?).
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *
208aaecb51db539a2f7f3d25f38dd2efd0f014a3vboxsync * @returns VBox status code.
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync * @param pVM VM handle.
9f9eff04f209bd905529ee3b76076e55568db917vboxsync * @param u8TPR The new TPR.
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync */
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsyncPDMDECL(int) PDMApicSetTPR(PVM pVM, uint8_t u8TPR)
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync{
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync if (pVM->pdm.s.Apic.CTXALLSUFF(pDevIns))
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync {
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pfnSetTPR));
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync pdmLock(pVM);
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync pVM->pdm.s.Apic.CTXALLSUFF(pfnSetTPR)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns), u8TPR);
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync pdmUnlock(pVM);
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync return VINF_SUCCESS;
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync }
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync return VERR_PDM_NO_APIC_INSTANCE;
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync}
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync
33f11b53cd8c54c594fb6117dc4413e05bd7a3cdvboxsync/**
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync * Get the TPR (task priority register).
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync *
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).
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync*/
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsyncPDMDECL(int) PDMApicGetTPR(PVM pVM, uint8_t *pu8TPR, bool *pfPending)
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync{
9f9eff04f209bd905529ee3b76076e55568db917vboxsync if (pVM->pdm.s.Apic.CTXALLSUFF(pDevIns))
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync {
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pfnGetTPR));
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync pdmLock(pVM);
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync *pu8TPR = pVM->pdm.s.Apic.CTXALLSUFF(pfnGetTPR)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync if (pfPending)
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync *pfPending = pVM->pdm.s.Apic.CTXALLSUFF(pfnHasPendingIrq)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync pdmUnlock(pVM);
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync return VINF_SUCCESS;
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync }
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync *pu8TPR = 0;
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync return VERR_PDM_NO_APIC_INSTANCE;
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync}
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync/**
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync * Locks PDM.
208aaecb51db539a2f7f3d25f38dd2efd0f014a3vboxsync * This might call back to Ring-3 in order to deal with lock contention in GC and R3.
a2d53f020c57ede4a469a06d8ef8f735c7a46596vboxsync *
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @param pVM The VM handle.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsyncvoid pdmLock(PVM pVM)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync{
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#ifdef IN_RING3
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync int rc = PDMCritSectEnter(&pVM->pdm.s.CritSect, VERR_INTERNAL_ERROR);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#else
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync int rc = PDMCritSectEnter(&pVM->pdm.s.CritSect, VERR_GENERAL_FAILURE);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync if (rc == VERR_GENERAL_FAILURE)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync {
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync# ifdef IN_GC
714655059cb50166bd78a8b4fc9fe2d4b29ef4afvboxsync rc = VMMGCCallHost(pVM, VMMCALLHOST_PDM_LOCK, 0);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync# else
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync rc = VMMR0CallHost(pVM, VMMCALLHOST_PDM_LOCK, 0);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync# endif
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync }
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync#endif
397a09203bcbe5348def6093e6c855c43d4ad98fvboxsync AssertRC(rc);
3c0e6e6c131cfdaeaeaea598603f6ef6ab10e781vboxsync}
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync/**
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Locks PDM but don't go to ring-3 if it's owned by someone.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *
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 */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsyncint pdmLockEx(PVM pVM, int rc)
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync{
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync return PDMCritSectEnter(&pVM->pdm.s.CritSect, rc);
70142706c9117b6c1befe7a5be768d25c699ead5vboxsync}
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
afdf6eaa7e1a0e25a511d96598400f812a5296e3vboxsync/**
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * Unlocks PDM.
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync *
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync * @param pVM The VM handle.
bf4de0c2965291e927412f708c6c27eeeb5825d4vboxsync */
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsyncvoid pdmUnlock(PVM pVM)
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync{
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync PDMCritSectLeave(&pVM->pdm.s.CritSect);
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync}
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync
3c3a5ab35783f4d31cb5d3a15db9daadeb804daavboxsync