mp-r0drv-nt.cpp revision 254033e746b8975909aa370cf7f17697da804f3e
/* $Id$ */
/** @file
* IPRT - Multiprocessor, Ring-0 Driver, NT.
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "the-nt-kernel.h"
#include "r0drv/mp-r0drv.h"
#include "internal-r0drv-nt.h"
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
typedef enum
{
} RT_NT_CPUID;
/* test a couple of assumption. */
/** @todo
* We cannot do other than assume a 1:1 relationship between the
* the docs. If someone knows a better way to get this done, please
* let bird know.
*/
{
/* WDK upgrade warning: PCR->Number changed from BYTE to WORD. */
return KeGetCurrentProcessorNumber();
}
{
}
{
}
{
/** @todo use KeQueryMaximumProcessorCount on vista+ */
return MAXIMUM_PROCESSORS - 1;
}
{
if (idCpu >= MAXIMUM_PROCESSORS)
return false;
#if 0 /* this isn't safe at all IRQLs (great work guys) */
#else
#endif
}
{
/* Cannot easily distinguish between online and offline cpus. */
* (KeQueryMaximumProcessorCount). */
return RTMpIsCpuOnline(idCpu);
}
{
* (KeQueryMaximumProcessorCount). */
return RTMpGetOnlineSet(pSet);
}
{
* (KeQueryMaximumProcessorCount). */
return RTMpGetOnlineCount();
}
{
#if 0 /* this isn't safe at all IRQLs (great work guys) */
#else
*pSet = g_rtMpNtCpuSet;
return pSet;
#endif
}
{
return RTCpuSetCount(&Set);
}
#if 0
/* Experiment with checking the undocumented KPRCB structure
* 'dt nt!_kprcb 0xaddress' shows the layout
*/
typedef struct
{
volatile ULONG DpcQueueDepth;
} KDPC_DATA, *PKDPC_DATA;
RTDECL(bool) RTMpIsCpuWorkPending(void)
{
_asm {
}
if (pDpcData->DpcQueueDepth)
return true;
pDpcData++;
if (pDpcData->DpcQueueDepth)
return true;
return false;
}
#else
RTDECL(bool) RTMpIsCpuWorkPending(void)
{
/** @todo not implemented */
return false;
}
#endif
/**
* Wrapper between the native nt per-cpu callbacks and PFNRTWORKER
*
* @param Dpc DPC object
* @param DeferredContext Context argument specified by KeInitializeDpc
* @param SystemArgument1 Argument specified by KeInsertQueueDpc
* @param SystemArgument2 Argument specified by KeInsertQueueDpc
*/
static VOID rtmpNtDPCWrapper(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
{
}
/**
* Internal worker for the RTMpOn* APIs.
*
* @returns IPRT status code.
* @param pfnWorker The callback.
* @param pvUser1 User argument 1.
* @param pvUser2 User argument 2.
* @param enmCpuid What to do / is idCpu valid.
* @param idCpu Used if enmCpuid RT_NT_CPUID_SPECIFIC, otherwise ignored.
*/
static int rtMpCall(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2, RT_NT_CPUID enmCpuid, RTCPUID idCpu)
{
#if 0
/* KeFlushQueuedDpcs must be run at IRQL PASSIVE_LEVEL according to MSDN, but the
* driver verifier doesn't complain...
*/
AssertMsg(KeGetCurrentIrql() == PASSIVE_LEVEL, ("%d != %d (PASSIVE_LEVEL)\n", KeGetCurrentIrql(), PASSIVE_LEVEL));
#endif
#ifdef IPRT_TARGET_NT4
/* g_pfnrtNt* are not present on NT anyway. */
return VERR_NOT_SUPPORTED;
#else
#endif
/* KeFlushQueuedDpcs is not present in Windows 2000; import it dynamically so we can just fail this call. */
return VERR_NOT_SUPPORTED;
pArgs = (PRTMPARGS)ExAllocatePoolWithTag(NonPagedPool, MAXIMUM_PROCESSORS*sizeof(KDPC) + sizeof(RTMPARGS), (ULONG)'RTMp');
if (!pArgs)
return VERR_NO_MEMORY;
if (enmCpuid == RT_NT_CPUID_SPECIFIC)
{
}
else
{
for (unsigned i = 0; i < MAXIMUM_PROCESSORS; i++)
{
KeSetTargetProcessorDpc(&paExecCpuDpcs[i], i);
}
}
/* Raise the IRQL to DISPATCH_LEVEL so we can't be rescheduled to another cpu.
* KeInsertQueueDpc must also be executed at IRQL >= DISPATCH_LEVEL.
*/
/*
* We cannot do other than assume a 1:1 relationship between the
* affinity mask and the process despite the warnings in the docs.
* If someone knows a better way to get this done, please let bird know.
*/
if (enmCpuid == RT_NT_CPUID_SPECIFIC)
{
}
else
{
unsigned iSelf = KeGetCurrentProcessorNumber();
for (unsigned i = 0; i < MAXIMUM_PROCESSORS; i++)
{
if ( (i != iSelf)
{
}
}
if (enmCpuid != RT_NT_CPUID_OTHERS)
}
/* Flush all DPCs and wait for completion. (can take long!) */
* stuff (and check for the current cpu above in the specific case). */
return VINF_SUCCESS;
}
{
}
{
}
{
if (!RTMpIsCpuOnline(idCpu))
return !RTMpIsCpuPossible(idCpu)
}
static bool fPokeDPCsInitialized = false;
static VOID rtMpNtPokeCpuDummy(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
{
}
#ifndef IPRT_TARGET_NT4
{
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
}
#endif /* IPRT_TARGET_NT4 */
{
return VERR_NOT_IMPLEMENTED;
}
{
if (!RTMpIsCpuOnline(idCpu))
return !RTMpIsCpuPossible(idCpu)
if (rc == VINF_SUCCESS)
return rc;
/* Fallback. */
if (!fPokeDPCsInitialized)
{
for (unsigned i = 0; i < RT_ELEMENTS(aPokeDpcs); i++)
{
KeSetTargetProcessorDpc(&aPokeDpcs[i], (int)i);
}
fPokeDPCsInitialized = true;
}
/* Raise the IRQL to DISPATCH_LEVEL so we can't be rescheduled to another cpu.
* KeInsertQueueDpc must also be executed at IRQL >= DISPATCH_LEVEL.
*/
/* Assuming here that high importance DPCs will be delivered immediately; or at least an IPI will be sent immediately.
* @note: not true on at least Vista & Windows 7
*/
}
void rtMpPokeCpuClear()
{
/* Remove any pending poke DPC from the queue, so another call to RTMpPokeCpu will send an IPI */
/* Note: assuming this is a cheap operation. */
}