/**
 * PROJECT:         ExectOS
 * COPYRIGHT:       See COPYING.md in the top level directory
 * FILE:            xtoskrnl/po/idle.cc
 * DESCRIPTION:     Processor idle functionality support
 * DEVELOPERS:      Rafal Kupiec <belliash@codingworkshop.eu.org>
 */

#include <xtos.hh>


/**
 * Initializes Processor Control Block's (PRCB) power state structures.
 *
 * @param Prcb
 *        Supplies a pointer to the PRCB being initialized.
 *
 * @return This routine does not return any value.
 *
 * @since XT 1.0
 */
XTAPI
VOID
PO::Idle::InitializeProcessorIdleState(IN OUT PKPROCESSOR_CONTROL_BLOCK Prcb)
{
    /* Zero memory */
    RTL::Memory::ZeroMemory(&Prcb->PowerState, sizeof(Prcb->PowerState));

    /* Initialize default power state */
    Prcb->PowerState.Idle0TimeLimit = 0xFFFFFFFF;
    Prcb->PowerState.CurrentThrottle = 100;
    Prcb->PowerState.CurrentThrottleIndex = 0;
    Prcb->PowerState.IdleFunction = Idle0Function;

    /* Initialize DPC and Timer */
    KE::Dpc::InitializeDpc(&Prcb->PowerState.PerfDpc, PerfIdleDpc, Prcb);
    KE::Dpc::SetTargetProcessor(&Prcb->PowerState.PerfDpc, Prcb->CpuNumber);
    KE::Timer::InitializeTimer(&Prcb->PowerState.PerfTimer, SynchronizationTimer);
}

/**
 * Processor idle loop routine.
 *
 * @param PowerState
 *        Supplies a pointer to the structere containing current processor power state.
 *
 * @return This routine does not return any value.
 *
 * @since XT 1.0
 */
XTFASTCALL
VOID
PO::Idle::Idle0Function(IN PPROCESSOR_POWER_STATE PowerState)
{
    UNIMPLEMENTED;
}

/**
 * Switches CPU between different performance levels.
 *
 * @param PowerState
 *        Supplies a pointer to the structure containing IDLE processor power state.
 *
 * @return This routine does not return any value.
 *
 * @since NT 5.1
 */
XTAPI
VOID
PO::Idle::PerfIdle(PPROCESSOR_POWER_STATE PowerState)
{
    UNIMPLEMENTED;
}

/**
 * Checks if CPU is running at the maximum (performance) frequency.
 *
 * @param Dpc
 *        Supplies a pointer to the DPC object.
 *
 * @param DeferredContext
 *        Supplies a pointer to memory area containing current CPU's PRCB.
 *
 * @param SystemArgument1
 *        Supplies a pointer to an unused system argument.
 *
 * @param SystemArgument2
 *        Supplies a pointer to an unused system argument.
 *
 * @return This routine does not return any value.
 *
 * @since NT 5.1
 */
XTAPI
VOID
PO::Idle::PerfIdleDpc(IN PKDPC Dpc,
                      IN PVOID DeferredContext,
                      IN PVOID SystemArgument1,
                      IN PVOID SystemArgument2)
{
    UNIMPLEMENTED;
}
