PDMAll.cpp revision 675f16ba1814ff54bdf00391a6d126a25963f88a
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/* $Id$ */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/** @file
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * PDM Critical Sections
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/*
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *
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 *
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
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/*******************************************************************************
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync* Header Files *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync*******************************************************************************/
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#define LOG_GROUP LOG_GROUP_PDM
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include "PDMInternal.h"
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include <VBox/pdm.h>
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include <VBox/mm.h>
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include <VBox/vm.h>
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include <VBox/err.h>
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include <VBox/log.h>
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include <iprt/asm.h>
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include <iprt/assert.h>
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/**
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Gets the pending interrupt.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @returns VBox status code.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pVM VM handle.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pu8Interrupt Where to store the interrupt on success.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncPDMDECL(int) PDMGetInterrupt(PVM pVM, uint8_t *pu8Interrupt)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync{
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pdmLock(pVM);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /*
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * The local APIC has a higer priority than the PIC.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (VM_FF_ISSET(pVM, VM_FF_INTERRUPT_APIC))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_APIC);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pfnGetInterrupt));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync int i = pVM->pdm.s.Apic.CTXALLSUFF(pfnGetInterrupt)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync AssertMsg(i <= 255 && i >= 0, ("i=%d\n", i));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (i >= 0)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pdmUnlock(pVM);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *pu8Interrupt = (uint8_t)i;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return VINF_SUCCESS;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /*
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Check the PIC.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (VM_FF_ISSET(pVM, VM_FF_INTERRUPT_PIC))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync VM_FF_CLEAR(pVM, VM_FF_INTERRUPT_PIC);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pdm.s.Pic.CTXALLSUFF(pDevIns));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pdm.s.Pic.CTXALLSUFF(pfnGetInterrupt));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync int i = pVM->pdm.s.Pic.CTXALLSUFF(pfnGetInterrupt)(pVM->pdm.s.Pic.CTXALLSUFF(pDevIns));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync AssertMsg(i <= 255 && i >= 0, ("i=%d\n", i));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (i >= 0)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pdmUnlock(pVM);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *pu8Interrupt = (uint8_t)i;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return VINF_SUCCESS;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /** @todo Figure out exactly why we can get here without anything being set. (REM) */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pdmUnlock(pVM);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return VERR_NO_DATA;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync}
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync/**
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync * Sets the pending interrupt.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync * @returns VBox status code.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pVM VM handle.
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync * @param u8Irq The IRQ line.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param u8Level The new level.
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncPDMDECL(int) PDMIsaSetIrq(PVM pVM, uint8_t u8Irq, uint8_t u8Level)
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync{
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pdmLock(pVM);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync int rc = VERR_PDM_NO_PIC_INSTANCE;
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync if (pVM->pdm.s.Pic.CTXALLSUFF(pDevIns))
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pdm.s.Pic.CTXALLSUFF(pfnSetIrq));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pVM->pdm.s.Pic.CTXALLSUFF(pfnSetIrq)(pVM->pdm.s.Pic.CTXALLSUFF(pDevIns), u8Irq, u8Level);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync rc = VINF_SUCCESS;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (pVM->pdm.s.IoApic.CTXALLSUFF(pDevIns))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pdm.s.IoApic.CTXALLSUFF(pfnSetIrq));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pVM->pdm.s.IoApic.CTXALLSUFF(pfnSetIrq)(pVM->pdm.s.IoApic.CTXALLSUFF(pDevIns), u8Irq, u8Level);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync rc = VINF_SUCCESS;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
dc45a8f3e936581748c248e00ce572cfe3ea331evboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pdmUnlock(pVM);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return rc;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync}
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/**
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Sets the pending I/O APIC interrupt.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @returns VBox status code.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pVM VM handle.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param u8Irq The IRQ line.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param u8Level The new level.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncPDMDECL(int) PDMIoApicSetIrq(PVM pVM, uint8_t u8Irq, uint8_t u8Level)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync{
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (pVM->pdm.s.IoApic.CTXALLSUFF(pDevIns))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pdm.s.IoApic.CTXALLSUFF(pfnSetIrq));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pdmLock(pVM);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pVM->pdm.s.IoApic.CTXALLSUFF(pfnSetIrq)(pVM->pdm.s.IoApic.CTXALLSUFF(pDevIns), u8Irq, u8Level);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pdmUnlock(pVM);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return VINF_SUCCESS;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return VERR_PDM_NO_PIC_INSTANCE;
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync}
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync/**
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Set the APIC base.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @returns VBox status code.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pVM VM handle.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param u64Base The new base.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncPDMDECL(int) PDMApicSetBase(PVM pVM, uint64_t u64Base)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync{
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (pVM->pdm.s.Apic.CTXALLSUFF(pDevIns))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pfnSetBase));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pdmLock(pVM);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pVM->pdm.s.Apic.CTXALLSUFF(pfnSetBase)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns), u64Base);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pdmUnlock(pVM);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return VINF_SUCCESS;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync }
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return VERR_PDM_NO_APIC_INSTANCE;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync}
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync/**
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Get the APIC base.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @returns VBox status code.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pVM VM handle.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pu64Base Where to store the APIC base.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncPDMDECL(int) PDMApicGetBase(PVM pVM, uint64_t *pu64Base)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync{
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (pVM->pdm.s.Apic.CTXALLSUFF(pDevIns))
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync {
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pfnGetBase));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pdmLock(pVM);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *pu64Base = pVM->pdm.s.Apic.CTXALLSUFF(pfnGetBase)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pdmUnlock(pVM);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return VINF_SUCCESS;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync }
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *pu64Base = 0;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return VERR_PDM_NO_APIC_INSTANCE;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync}
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync/**
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Check if the APIC has a pending interrupt/if a TPR change would active one
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @returns Pending interrupt yes/no
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pDevIns Device instance of the APIC.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pfPending Pending state (out)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncPDMDECL(int) PDMApicHasPendingIrq(PVM pVM, bool *pfPending)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync{
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (pVM->pdm.s.Apic.CTXALLSUFF(pDevIns))
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync {
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pfnSetTPR));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pdmLock(pVM);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *pfPending = pVM->pdm.s.Apic.CTXALLSUFF(pfnHasPendingIrq)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pdmUnlock(pVM);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return VINF_SUCCESS;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync }
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return VERR_PDM_NO_APIC_INSTANCE;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync}
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync/**
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Set the TPR (task priority register?).
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @returns VBox status code.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pVM VM handle.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param u8TPR The new TPR.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncPDMDECL(int) PDMApicSetTPR(PVM pVM, uint8_t u8TPR)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync{
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (pVM->pdm.s.Apic.CTXALLSUFF(pDevIns))
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync {
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pfnSetTPR));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pdmLock(pVM);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pVM->pdm.s.Apic.CTXALLSUFF(pfnSetTPR)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns), u8TPR);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pdmUnlock(pVM);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return VINF_SUCCESS;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync }
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return VERR_PDM_NO_APIC_INSTANCE;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync}
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync/**
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Get the TPR (task priority register?).
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @returns The current TPR.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pVM VM handle.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pu8TPR Where to store the TRP.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncPDMDECL(int) PDMApicGetTPR(PVM pVM, uint8_t *pu8TPR)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync{
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (pVM->pdm.s.Apic.CTXALLSUFF(pDevIns))
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync {
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync Assert(pVM->pdm.s.Apic.CTXALLSUFF(pfnGetTPR));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pdmLock(pVM);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *pu8TPR = pVM->pdm.s.Apic.CTXALLSUFF(pfnGetTPR)(pVM->pdm.s.Apic.CTXALLSUFF(pDevIns));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync pdmUnlock(pVM);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return VINF_SUCCESS;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync }
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *pu8TPR = 0;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return VERR_PDM_NO_APIC_INSTANCE;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync}
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync/**
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Locks PDM.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * This might call back to Ring-3 in order to deal with lock contention in GC and R3.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pVM The VM handle.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncvoid pdmLock(PVM pVM)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync{
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#ifdef IN_RING3
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync int rc = PDMCritSectEnter(&pVM->pdm.s.CritSect, VERR_INTERNAL_ERROR);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#else
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync int rc = PDMCritSectEnter(&pVM->pdm.s.CritSect, VERR_GENERAL_FAILURE);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (rc == VERR_GENERAL_FAILURE)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync# ifdef IN_GC
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync rc = VMMGCCallHost(pVM, VMMCALLHOST_PDM_LOCK, 0);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync# else
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync rc = VMMR0CallHost(pVM, VMMCALLHOST_PDM_LOCK, 0);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync# endif
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync AssertRC(rc);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync}
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/**
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Locks PDM but don't go to ring-3 if it's owned by someone.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *
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 */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncint pdmLockEx(PVM pVM, int rc)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync{
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return PDMCritSectEnter(&pVM->pdm.s.CritSect, rc);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync}
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/**
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Unlocks PDM.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pVM The VM handle.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncvoid pdmUnlock(PVM pVM)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync{
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync PDMCritSectLeave(&pVM->pdm.s.CritSect);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync}
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync