VOID
SimSensorExpiredRequestTimer (
    WDFTIMER Timer
    )

/*++

Routine Description:

    This routine is invoked when a request timer expires. A scan of the pending
    queue to complete expired and satisfied requests is initiated.

Arguments:

    Timer - Supplies a handle to the timer which expired.

--*/

{

    PFDO_DATA DevExt;
    WDFDEVICE Device;

    DebugEnter();
    PAGED_CODE();

    Device = (WDFDEVICE)WdfTimerGetParentObject(Timer);
    DevExt = GetDeviceExtension(Device);
    WdfWaitLockAcquire(DevExt->QueueLock, NULL);
    SimSensorScanPendingQueue(Device);
    WdfWaitLockRelease(DevExt->QueueLock);

    DebugExit();
}
VOID
SimSensorIoInternalDeviceControl (
    WDFQUEUE Queue,
    WDFREQUEST Request,
    size_t OutputBufferLength,
    size_t InputBufferLength,
    ULONG IoControlCode)

/*++

Description:

    The system uses IoInternalDeviceControl requests to communicate with the
    ACPI driver on the device stack. For proper operation of thermal zones,
    these requests must be forwarded unless the driver knows how to handle
    them.

--*/

{
    WDF_REQUEST_SEND_OPTIONS RequestSendOptions;
    BOOLEAN Return;
    NTSTATUS Status;

    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);
    UNREFERENCED_PARAMETER(IoControlCode);

    DebugEnter();

    WdfRequestFormatRequestUsingCurrentType(Request);

    WDF_REQUEST_SEND_OPTIONS_INIT(
        &RequestSendOptions,
        WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET);

    Return = WdfRequestSend(
                Request,
                WdfDeviceGetIoTarget(WdfIoQueueGetDevice(Queue)),
                &RequestSendOptions);

    if (Return == FALSE) {
        Status = WdfRequestGetStatus(Request);
        DebugPrint(SIMSENSOR_WARN,
                   "WdfRequestSend() Failed. Request Status=0x%x\n",
                   Status);

        WdfRequestComplete(Request, Status);
    }

    DebugExit();
}
Example #3
0
VOID
SimTcEngagePassiveCooling (
    _Inout_opt_ PVOID Context,
    _In_        ULONG Percentage
    )

/*++

Routine Description:

    SimTcEngagePassiveCooling is called by the device's clients to set the
    device's passive cooling state.

Arguments:

    Context - Supplies a handle to the target device.

    Percentage - Supplies the new thermal level in percent.

Return Value:

    None

--*/

{
    PFDO_DATA DevExt;
    ULONG PreviousThermalLevel;

    DebugEnter();
    PAGED_CODE();

    _Analysis_assume_(Context != NULL);
    NT_ASSERT(Context != NULL);
    DevExt = GetDeviceExtension((WDFDEVICE)Context);

    PreviousThermalLevel = DevExt->ThermalLevel;
    DevExt->ThermalLevel = Percentage;

    DebugPrint(SIMTC_TRACE,
               "Thermal level was %lu, now %lu.\n",
               PreviousThermalLevel,
               Percentage);

    DebugExit();
}
Example #4
0
VOID
SimTcEngageActiveCooling(
    _Inout_opt_ PVOID Context,
    _In_        BOOLEAN Engaged
    )

/*++

Routine Description:

    SimTcEngageActiveCooling is called by the device's clients to set the
    device's active cooling state.

Arguments:

    Context - Supplies a handle to the target device.

    Engaged - Supplies the new cooling state.

Return Value:

    None

--*/

{
    PFDO_DATA DevExt;
    BOOLEAN PreviousActiveCoolingState;

    DebugEnter();
    PAGED_CODE();

    _Analysis_assume_(Context != NULL);
    NT_ASSERT(Context != NULL);
    DevExt = GetDeviceExtension((WDFDEVICE)Context);

    PreviousActiveCoolingState = DevExt->ActiveCoolingEngaged;
    DevExt->ActiveCoolingEngaged = Engaged;

    DebugPrint(SIMTC_TRACE,
               "Active cooling state was %s, now %s.\n",
               (PreviousActiveCoolingState != FALSE) ? "on" : "off",
               (Engaged != FALSE) ? "on" : "off");

    DebugExit();
}
Example #5
0
void ProcQuit( void )
{
    ReqEOC();
    DebugExit();
}
VOID
SimSensorCheckQueuedRequest (
    _In_ WDFDEVICE Device,
    _In_ ULONG Temperature,
    _Inout_ PULONG LowerBound,
    _Inout_ PULONG UpperBound,
    _In_ WDFREQUEST Request
    )

/*++

Routine Description:

    Examines a request and performs one of the following actions:

    * Retires the request if it is satisfied (the sensor temperature has
      exceeded the bounds specified in the request)

    * Retires the request if it is expired (the timer due time is in the past)

    * Tightens the upper and lower bounds if the request remains in the queue.

Arguments:

    Device - Supplies a handle to the device which owns this request.

    Temperature - Supplies the current thermal zone temperature.

    LowerBound - Supplies the lower bound threshold to adjust.

    UpperBound - Supplies the upper bound threshold to adjust.

    Request - Supplies a handle to the request.

--*/

{
    ULONG BytesReturned;
    LARGE_INTEGER CurrentTime;
    PFDO_DATA DevExt;
    size_t Length;
    PREAD_REQUEST_CONTEXT Context;
    WDFREQUEST RetrievedRequest;
    PULONG RequestTemperature;
    NTSTATUS Status;

    DebugEnter();
    PAGED_CODE();

    KeQuerySystemTime(&CurrentTime);
    DevExt = GetDeviceExtension(Device);
    Context = WdfObjectGetTypedContext(Request, READ_REQUEST_CONTEXT);

    RetrievedRequest = NULL;

    //
    // Complete the request if:
    //
    // 1. The temperature has exceeded one of the request thresholds.
    // 2. The request timeout is in the past (but not negative).
    //

    if (SimSensorAreConstraintsSatisfied(Temperature,
                                         Context->LowTemperature,
                                         Context->HighTemperature,
                                         Context->ExpirationTime)) {

        Status = WdfIoQueueRetrieveFoundRequest(DevExt->PendingRequestQueue,
                                                Request,
                                                &RetrievedRequest);

        if(!NT_SUCCESS(Status)) {
            DebugPrint(SIMSENSOR_ERROR,
                       "WdfIoQueueRetrieveFoundRequest() Failed. 0x%x",
                       Status);

            //
            // Bail, likely because the request disappeared from the
            // queue.
            //

            goto CheckQueuedRequestEnd;
        }

        Status = WdfRequestRetrieveOutputBuffer(RetrievedRequest,
                                                sizeof(ULONG),
                                                &RequestTemperature,
                                                &Length);

        if(NT_SUCCESS(Status) && (Length == sizeof(ULONG))) {
            *RequestTemperature = Temperature;
            BytesReturned = sizeof(ULONG);

        } else {

            //
            // The request's return buffer is malformed.
            //

            BytesReturned = 0;
            Status = STATUS_INVALID_PARAMETER;
            DebugPrint(SIMSENSOR_ERROR,
                       "WdfRequestRetrieveOutputBuffer() Failed. 0x%x",
                        Status);

        }

        WdfRequestCompleteWithInformation(RetrievedRequest,
                                          Status,
                                          BytesReturned);

    } else {

        //
        // The request will remain in the queue. Update the bounds accordingly.
        //

        if (*LowerBound < Context->LowTemperature) {
            *LowerBound = Context->LowTemperature;
        }

        if (*UpperBound > Context->HighTemperature) {
            *UpperBound = Context->HighTemperature;
        }
    }

CheckQueuedRequestEnd:
    DebugExit();
    return;
}