Example #1
0
STDMETHODIMP CMPEGFilter::Stop()
{
	TraceVerbose("Entered CMPEGFilter::Stop\n");
    CAutoLock cObjectLock(m_pLock);
	HRESULT hr = m_pMPEGObj->Stop();
    hr = CBaseFilter::Stop();
	TraceVerbose("Exited CMPEGFilter::Stop\n");
	return hr;
}
Example #2
0
// Pass down Idle notification request to lower driver
//
NTSTATUS HidFx2SendIdleNotification(_In_ WDFREQUEST hRequest)
{
    NTSTATUS                   status = STATUS_SUCCESS;
    WDF_REQUEST_SEND_OPTIONS   options;
    WDFIOTARGET                hNextLowerDriver;
    WDFDEVICE                  hDevice;
    PIO_STACK_LOCATION         pCurrentIrpStack = NULL;
    IO_STACK_LOCATION          nextIrpStack;

    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Entry\n");

    hDevice = WdfIoQueueGetDevice(WdfRequestGetIoQueue(hRequest));
    pCurrentIrpStack = IoGetCurrentIrpStackLocation(WdfRequestWdmGetIrp(hRequest));

    // Convert the request to corresponding USB Idle notification request
    if (pCurrentIrpStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(HID_SUBMIT_IDLE_NOTIFICATION_CALLBACK_INFO))
    {
        ASSERT(sizeof(HID_SUBMIT_IDLE_NOTIFICATION_CALLBACK_INFO) == sizeof(USB_IDLE_CALLBACK_INFO));
        #pragma warning(suppress :4127)  // conditional expression is constant warning
        if (sizeof(HID_SUBMIT_IDLE_NOTIFICATION_CALLBACK_INFO) == sizeof(USB_IDLE_CALLBACK_INFO))
        {
            // prepare next stack location
            RtlZeroMemory(&nextIrpStack, sizeof(IO_STACK_LOCATION));
            nextIrpStack.MajorFunction = pCurrentIrpStack->MajorFunction;
            nextIrpStack.Parameters.DeviceIoControl.InputBufferLength = pCurrentIrpStack->Parameters.DeviceIoControl.InputBufferLength;
            nextIrpStack.Parameters.DeviceIoControl.Type3InputBuffer = pCurrentIrpStack->Parameters.DeviceIoControl.Type3InputBuffer;
            nextIrpStack.Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION;
            nextIrpStack.DeviceObject = WdfIoTargetWdmGetTargetDeviceObject(WdfDeviceGetIoTarget(hDevice));

            // Format the I/O request for the driver's local I/O target by using the contents of the specified WDM I/O stack location structure.
            WdfRequestWdmFormatUsingStackLocation(hRequest, &nextIrpStack);

            // Send the request down using Fire and forget option.
            WDF_REQUEST_SEND_OPTIONS_INIT(&options, WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET);
            hNextLowerDriver = WdfDeviceGetIoTarget(hDevice);
            if (WdfRequestSend(hRequest, hNextLowerDriver, &options) == FALSE)
            {
                status = STATUS_UNSUCCESSFUL;
            }
        }
        else // Incorrect DeviceIoControl.InputBufferLength
        {
            status = STATUS_INFO_LENGTH_MISMATCH;
            TraceErr(DBG_IOCTL, "(%!FUNC!) Incorrect DeviceIoControl.InputBufferLength, %!STATUS!\n", status);
            return status;
        }
    }
    else // DeviceIoControl.InputBufferLength too small
    {
        status = STATUS_BUFFER_TOO_SMALL;
        TraceErr(DBG_IOCTL, "(%!FUNC!) DeviceIoControl.InputBufferLength too small, %!STATUS!\n", status);
        return status;
    }

    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Exit = %!STATUS!\n", status);
    return status;
}
Example #3
0
static VOID NTAPI
V4vDriverUnload(PDRIVER_OBJECT driverObject)
{
    UNREFERENCED_PARAMETER(driverObject);
	
    TraceVerbose(("====> '%s'.\n", __FUNCTION__));

    TraceVerbose(("<==== '%s'.\n", __FUNCTION__));
}
Example #4
0
static VOID
close_frontend(struct scsifilt *sf, SUSPEND_TOKEN token)
{
    XENBUS_STATE frontend_state;
    XENBUS_STATE backend_state;
    NTSTATUS status;

    TraceNotice(("target %d: closing frontend...\n", sf->target_id));

    // Get initial frontend state
    status = xenbus_read_state(XBT_NIL, sf->frontend_path, "state", &frontend_state);
    if (!NT_SUCCESS(status))
        frontend_state = null_XENBUS_STATE();

    // Wait for the backend to stabilise
    backend_state = null_XENBUS_STATE();
    do {
        backend_state = XenbusWaitForBackendStateChange(sf->backend_path, backend_state,
                                                        NULL, token);
    } while (same_XENBUS_STATE(backend_state, XENBUS_STATE_INITIALISING));

    TraceVerbose(("%s: target %d: backend state = %s, frontend state = %s\n",
                  __FUNCTION__, sf->target_id,
                  XenbusStateName(backend_state),
                  XenbusStateName(frontend_state)));

    frontend_state = XENBUS_STATE_CLOSING;
    while (!same_XENBUS_STATE(backend_state, XENBUS_STATE_CLOSING) &&
           !same_XENBUS_STATE(backend_state, XENBUS_STATE_CLOSED) &&
           !is_null_XENBUS_STATE(backend_state)) {
        xenbus_change_state(XBT_NIL, sf->frontend_path, "state", frontend_state);
        backend_state = XenbusWaitForBackendStateChange(sf->backend_path, backend_state,
                                                        NULL, token);
    }

    TraceVerbose(("%s: target %d: backend state = %s, frontend state = %s\n",
                  __FUNCTION__, sf->target_id,
                  XenbusStateName(backend_state),
                  XenbusStateName(frontend_state)));

    frontend_state = XENBUS_STATE_CLOSED;
    while (!same_XENBUS_STATE(backend_state, XENBUS_STATE_CLOSED) &&
           !is_null_XENBUS_STATE(backend_state)) {
        xenbus_change_state(XBT_NIL, sf->frontend_path, "state", frontend_state);
        backend_state = XenbusWaitForBackendStateChange(sf->backend_path, backend_state,
                                                        NULL, token);
    }

    TraceVerbose(("%s: target %d: backend state = %s, frontend state = %s\n",
                  __FUNCTION__, sf->target_id,
                  XenbusStateName(backend_state),
                  XenbusStateName(frontend_state)));

    TraceNotice(("target %d: backend closed\n", sf->target_id));
}
Example #5
0
static NTSTATUS
V4vStartDeviceIoCompletion(PDEVICE_OBJECT fdo, PIRP irp, PVOID context)
{
    UNREFERENCED_PARAMETER(fdo);
    UNREFERENCED_PARAMETER(irp);

    TraceVerbose(("====> '%s'.\n", __FUNCTION__));
    KeSetEvent((PKEVENT)context, IO_NO_INCREMENT, FALSE);
    TraceVerbose(("<==== '%s'.\n", __FUNCTION__));
    return STATUS_MORE_PROCESSING_REQUIRED;
}
Example #6
0
BOOLEAN NTAPI XenGfxVbeGetEdid(UCHAR *pChildDescriptor, ULONG Length)
{
    ULONG Addr;
    PHYSICAL_ADDRESS PhysAddr = {0};
    UCHAR *pVirtAddr;
    USHORT XRes, YRes;

    TraceVerbose(("====> '%s'.\n", __FUNCTION__));

    if (!g_VbeInfoInitialized) {
        return FALSE;
    }

    if ((pChildDescriptor == NULL)||(Length < VBE_EDID_SIZE)) {
        return FALSE;
    }

    // Find the EDID and map it in. The spinlock is not needed since the 
    // EDID is a static/ro chunk (after initialization).
    Addr = ((ULONG)g_VbeTable.EdidSeg & (0x0000FFFF));
    Addr = Addr << 4;
    Addr = Addr | ((ULONG)g_VbeTable.EdidAddr & (0x0000FFFF));
    PhysAddr.LowPart = Addr;
    pVirtAddr = (UCHAR*)MmMapIoSpace(PhysAddr, VBE_EDID_SIZE, MmNonCached);
    if (pVirtAddr == NULL) {
        TraceError(("Could not MAP in EDID virtual address!\n"));
        return FALSE;
    }

    RtlCopyMemory(pChildDescriptor, pVirtAddr, VBE_EDID_SIZE);
    MmUnmapIoSpace(pVirtAddr, VBE_EDID_SIZE);

    // Fix up EDID with resolution on this system.
    WRITE_PORT_USHORT((USHORT*)VBE_PORT_INDEX, VBE_DISPI_INDEX_EDID_XRES);
    XRes = READ_PORT_USHORT((USHORT*)VBE_PORT_DATA);

    WRITE_PORT_USHORT((USHORT*)VBE_PORT_INDEX, VBE_DISPI_INDEX_EDID_YRES);
    YRes = READ_PORT_USHORT((USHORT*)VBE_PORT_DATA);

    *(pChildDescriptor + 0x38) = (UCHAR)(XRes & 0x00FF);
    *(pChildDescriptor + 0x3A) = (UCHAR)(((XRes >> 8) & 0x000F) << 4);
    *(pChildDescriptor + 0x3B) = (UCHAR)(YRes & 0x00FF);
    *(pChildDescriptor + 0x3D) = (UCHAR)(((YRes >> 8) & 0x000F) << 4);

    TraceVerbose(("<==== '%s'.\n", __FUNCTION__));

    return TRUE;
}
Example #7
0
// This function gets the switch state of the USB device directly from the hardware
//
NTSTATUS HidFx2GetSwitchState(_In_ WDFDEVICE hDevice, _Out_ unsigned char *pbSwitchState)
{
    PDEVICE_EXTENSION            pDevContext = NULL;
    NTSTATUS                     status = STATUS_SUCCESS;
    WDF_MEMORY_DESCRIPTOR        memDesc;
    WDF_USB_CONTROL_SETUP_PACKET controlSetupPacket;
    ULONG                        cBytesTransferred = 0;

    if(pbSwitchState != NULL)
    {
        *pbSwitchState = 0;
    }

    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Entry\n");

    pDevContext = GetDeviceContext(hDevice);

    // set the segment state on the USB device
    WDF_USB_CONTROL_SETUP_PACKET_INIT_VENDOR(&controlSetupPacket,
                                             BmRequestDeviceToHost,
                                             BmRequestToDevice,
                                             HIDFX2_READ_SWITCH_STATE, // Request
                                             0, // Value
                                             0); // Index

    WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&memDesc, pbSwitchState, sizeof(*pbSwitchState));

    status = WdfUsbTargetDeviceSendControlTransferSynchronously(pDevContext->hUsbDevice,
                                                                NULL, // Optional WDFREQUEST
                                                                NULL, // PWDF_REQUEST_SEND_OPTIONS
                                                                &controlSetupPacket,
                                                                &memDesc,
                                                                &cBytesTransferred);

    if (!NT_SUCCESS(status))
    {
        TraceErr(DBG_IOCTL, "(%!FUNC!) Failed to read switch state - %!STATUS! \n", status);
    }
    else
    {
        TraceVerbose(DBG_IOCTL, "(%!FUNC!) Switch state is 0x%x\n", *pbSwitchState);
        *pbSwitchState = ~(*pbSwitchState);     // switchs are inverted on hardware boards
        TraceVerbose(DBG_IOCTL, "(%!FUNC!) Switch state is 0x%x\n", *pbSwitchState);
    }

    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Exit, status: %!STATUS!\n", status);
    return status;
}
Example #8
0
static BOOLEAN
BalloonPopulatePfnArray(
    IN  ULONG                   Requested,
    OUT PULONG                  pPopulated
    )
{
    xen_memory_reservation_t    reservation;
    LARGE_INTEGER               Start;
    LARGE_INTEGER               End;
    ULONGLONG                   TimeDelta;
    BOOLEAN                     Slow;
    ULONG                       Populated;

    XM_ASSERT(Requested <= BALLOON_PFN_ARRAY_SIZE);

    KeQuerySystemTime(&Start);

    RangeSetPopMany(&(Balloon.PfnsBalloonedOut),
                    &(Balloon.PfnArray[0]),
                    Requested);

    SET_XEN_GUEST_HANDLE(reservation.extent_start, Balloon.PfnArray);
    reservation.extent_order = 0;
    reservation.mem_flags = 0;   // unused
    reservation.domid = DOMID_SELF;
    reservation.nr_extents = Requested;

    Populated = HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation);
    if (Populated < Requested) {
        Balloon.PartialPopulate++;

        // This should not fail as we're simply handing back part of a range we'd previously popped.
        RangeSetAddItems(&(Balloon.PfnsBalloonedOut),
                         &(Balloon.PfnArray[Populated]),
                         Requested - Populated);
    } else if (Populated > Requested) {
        XM_BUG();
    }

    RangeSetDropRseCache(&(Balloon.PfnsBalloonedOut));

    TraceVerbose(("%s: %d page(s)\n", __FUNCTION__, Populated));

    KeQuerySystemTime(&End);
    TimeDelta = (End.QuadPart - Start.QuadPart) / 10000ull;

    Slow = FALSE;
    if (TimeDelta != 0) {
        ULONGLONG   Rate;

        Rate = (ULONGLONG)(Populated * 1000) / TimeDelta;
        if (Rate < MIN_PAGES_PER_S) {
            TraceWarning(("%s: ran for more than %dms\n", __FUNCTION__, TimeDelta));
            Slow = TRUE;
        }
    }

    *pPopulated = Populated;
    return Slow;
}
Example #9
0
//Installable driver initialization entry point. This entry point is called directly by the I/O system.
//
NTSTATUS DriverEntry (_In_ PDRIVER_OBJECT pDriverObject, _In_ PUNICODE_STRING pszRegistryPath)
{
    NTSTATUS               status = STATUS_SUCCESS;
    WDF_DRIVER_CONFIG      config;
    WDF_OBJECT_ATTRIBUTES  attributes;


    // Initialize WPP Tracing
    WPP_INIT_TRACING(pDriverObject, pszRegistryPath);

    TraceInfo(DBG_INIT, "(%!FUNC!) Enter -Sample Built %s %s\n", __DATE__, __TIME__);

    WDF_DRIVER_CONFIG_INIT(&config, HidFx2EvtDeviceAdd);

    // Register a cleanup callback so that we can call WPP_CLEANUP when  the framework driver object is deleted during driver unload.
    WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
    attributes.EvtCleanupCallback = HidFx2EvtDriverContextCleanup;

    // Create a framework driver object to represent our driver.
    status = WdfDriverCreate(pDriverObject,
                             pszRegistryPath,
                             &attributes,      // Driver Attributes
                             &config,          // Driver Config Info
                             WDF_NO_HANDLE
                            );
    if (!NT_SUCCESS(status)) 
    {
        TraceErr(DBG_INIT, "(%!FUNC!)WdfDriverCreate failed with status %!STATUS!\n", status);
        WPP_CLEANUP(pDriverObject);
    }

    TraceVerbose(DBG_INIT, "(%!FUNC!) Exit\n");
    return status;
}
Example #10
0
static NTSTATUS
V4vCtrlDisconnect(XENV4V_EXTENSION *pde, XENV4V_CONTEXT *ctx)
{
    LONG val;

    val = InterlockedExchangeAdd(&ctx->state, 0);
    if ((val & (XENV4V_STATE_CONNECTED|XENV4V_STATE_ACCEPTED)) == 0) {
        // Drop the warning - it is fine if a client calls disconnect event though it did not connect.
        TraceVerbose(("state not CONNECTED or ACCEPTED, cannot complete disconnect request\n"));
        return STATUS_INVALID_DEVICE_REQUEST;
    }

    // Send a RST write. This may go out immediately or get queued.
    V4vSendReset(pde, ctx, (uint32_t)ctx->connId, &ctx->sdst, FALSE);

    // Flush any queued inbound data
    if (val == XENV4V_STATE_ACCEPTED) {
        V4vFlushAccepterQueueData(ctx);
    }
    
    // Disconnect our side. Note that if the client is doing an orderly shutdown
    // then it does not need to be signaled and presumably has canceled all its
    // IO to. Worst case any IO will be cleaned up in the final release of the 
    // context so just transition the state.
    InterlockedExchange(&ctx->state, XENV4V_STATE_DISCONNECTED);

    return STATUS_SUCCESS;
}
Example #11
0
static VOID
ReceiverInitializeConfiguration(PRECEIVER Receiver)
{
    PKEY_VALUE_PARTIAL_INFORMATION pInfo;
    NTSTATUS status;

    status = XenReadRegistryValue(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services\\xennet\\Parameters",
                                  L"LowResources",
                                  &pInfo);
    if (!NT_SUCCESS(status)) {
        TraceVerbose(("LowResources switch: not present\n"));
        goto done;
    }

    if (pInfo->Type != REG_DWORD) {
        TraceError(("LowResources switch: wrong type\n"));
        ExFreePool(pInfo);
        goto done;
    }

    Receiver->LowResources = *(DWORD *)pInfo->Data;
    ExFreePool(pInfo);

done:
    TraceInfo(("LowResources: %08x\n", Receiver->LowResources));
}
Example #12
0
NTSTATUS
_XenQueueWork(
    IN  const CHAR          *Caller,
    IN  const CHAR          *Name,
    IN  XEN_WORK_CALLBACK   Work,
    IN  VOID                *Context
    )
{
    XEN_WORKITEM            *Item;
    KIRQL                   Irql;

    Item = XmAllocateZeroedMemory(sizeof(XEN_WORKITEM));
    if (!Item) {
        TraceError(("%s: %s() failed to queue %s\n", __FUNCTION__, Caller, Name));
        return STATUS_NO_MEMORY;
    }
    TraceVerbose(("%s: %s() queueing '%s'\n", __FUNCTION__, Caller, Name));

    Item->Magic = WORKITEM_MAGIC;
    Item->Name = Name;
    Item->Work = Work;
    Item->Context = Context;

    Irql = acquire_irqsafe_lock(&WorkItemDispatchLock);
    InsertTailList(&PendingWorkItems, &Item->List);
    release_irqsafe_lock(&WorkItemDispatchLock, Irql);

    KeSetEvent(&WorkItemThread->event, IO_NO_INCREMENT, FALSE);

    return STATUS_SUCCESS;
}
Example #13
0
/*
This routine undoes anything done in EvtDeviceD0Entry.  It is called  whenever the device leaves the D0 state, which happens when the device is
stopped, when it is removed, and when it is powered off.

The device is still in D0 when this callback is invoked, which means that  the driver can still touch hardware in this routine.

EvtDeviceD0Exit event callback must perform any operations that are necessary before the specified device is moved out of the D0 state.  
If the  driver needs to save hardware state before the device is powered down, then that should be done here.

This function runs at PASSIVE_LEVEL, though it is generally not paged.  A  driver can optionally make this function pageable if DO_POWER_PAGABLE is set.

Even if DO_POWER_PAGABLE isn't set, this function still runs at PASSIVE_LEVEL.
In this case, though, the function absolutely must not do anything that will cause a page fault.
*/
NTSTATUS HidFx2EvtDeviceD0Exit(_In_ WDFDEVICE hDevice, _In_ WDF_POWER_DEVICE_STATE targetState)
{
    PDEVICE_EXTENSION         pDevContext;

    PAGED_CODE();

    TraceVerbose(DBG_PNP, "(%!FUNC!) Enter- moving to %S\n", DbgDevicePowerString(targetState));

    pDevContext = GetDeviceContext(hDevice);

    WdfIoTargetStop(WdfUsbTargetPipeGetIoTarget(pDevContext->hInterruptPipe), WdfIoTargetCancelSentIo);

    TraceVerbose(DBG_PNP, "(%!FUNC!) Exit\n");

    return STATUS_SUCCESS;
}
Example #14
0
//This routine sets the state of the Feature: in this case Segment Display on the USB FX2 board.
NTSTATUS SendVendorCommand(_In_ WDFDEVICE hDevice, _In_ unsigned char bVendorCommand, _In_ unsigned char bCommandData)
{
    NTSTATUS                     status = STATUS_SUCCESS;
    ULONG                        cBytesTransferred = 0;
    PDEVICE_EXTENSION            pDevContext = NULL;
    WDF_MEMORY_DESCRIPTOR        memDesc;
    WDF_USB_CONTROL_SETUP_PACKET controlSetupPacket;
    WDF_REQUEST_SEND_OPTIONS     sendOptions;

    PAGED_CODE();

    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Enter\n");

    pDevContext = GetDeviceContext(hDevice);

    TraceInfo(DBG_IOCTL, "(%!FUNC!): Command:0x%x, data: 0x%x\n", bVendorCommand, bCommandData);

    // Send the I/O with a timeout.
    // We do that because we send the I/O in the context of the user thread and if it gets stuck, it would prevent the user process from existing.
    WDF_REQUEST_SEND_OPTIONS_INIT(&sendOptions, WDF_REQUEST_SEND_OPTION_TIMEOUT);

    WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&sendOptions, WDF_REL_TIMEOUT_IN_SEC(5));

    WDF_USB_CONTROL_SETUP_PACKET_INIT_VENDOR(&controlSetupPacket,
                                             BmRequestHostToDevice,
                                             BmRequestToDevice,
                                             bVendorCommand,    // Request
                                             0,                 // Value
                                             0);                // Index

    WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&memDesc, &bCommandData, sizeof(bCommandData));

    status = WdfUsbTargetDeviceSendControlTransferSynchronously(pDevContext->hUsbDevice,
                                                                WDF_NO_HANDLE,      // Optional WDFREQUEST
                                                                &sendOptions,       // PWDF_REQUEST_SEND_OPTIONS
                                                                &controlSetupPacket,
                                                                &memDesc,
                                                                &cBytesTransferred);
    if (!NT_SUCCESS(status))
    {
        TraceErr(DBG_IOCTL, "(%!FUNC!): Failed to set Segment Display state - %!STATUS!\n", status);
    }

    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Exit\n");

    return status;
}
Example #15
0
//Free resources allocated in DriverEntry that are not automatically cleaned up framework.
//
void HidFx2EvtDriverContextCleanup(_In_ WDFOBJECT hDriver)
{
    PAGED_CODE ();

    TraceVerbose(DBG_INIT, "(%!FUNC!) Enter/Exit\n");

    WPP_CLEANUP(WdfDriverWdmGetDriverObject(hDriver));
}
Example #16
0
BOOLEAN NTAPI XenGfxVbeGetModeInfo(USHORT ModeNumber, VBE_MODE_INFO* pVbeModeInfo)
{
    const MODE_INFO_ITEM *pCurrentMode;
    BOOLEAN UsingLFB;

    TraceVerbose(("====> '%s'.\n", __FUNCTION__));

    if (!g_VbeInfoInitialized) {
        return FALSE;
    }

    if (pVbeModeInfo == NULL) {
        return FALSE;
    }

    RtlZeroMemory(pVbeModeInfo, sizeof(VBE_MODE_INFO));

    UsingLFB = ((ModeNumber & VBE_MODE_LINEAR_FRAME_BUFFER) == VBE_MODE_LINEAR_FRAME_BUFFER) ? TRUE : FALSE;
    ModeNumber &= 0x1ff;

    // The spinlock is not needed since this routine just reads values from the
    // local mode table or from vbe ports.

    pCurrentMode = XenGfxFindMode(ModeNumber, UsingLFB);
    if (pCurrentMode == NULL) {
        TraceWarning(("VBE mode %04x NOT FOUND??\n", ModeNumber));
        return FALSE;
    }

    TraceVerbose(("Found VBE mode 0x%04x\n", ModeNumber));
    RtlCopyMemory(pVbeModeInfo, &pCurrentMode->ModeInfo, sizeof(VBE_MODE_INFO));

    // Fix it up a bit. Setting WinFuncPtr for VBE_WINDOW_ATTRIBUTE_RELOCATABLE is probably not so useful...
    if (UsingLFB) {
        pVbeModeInfo->NumberOfBanks = 1;
    }

    WRITE_PORT_USHORT((USHORT*)VBE_PORT_INDEX, VBE_DISPI_INDEX_LFB_ADDRESS_H);
    pVbeModeInfo->PhysBasePtr = READ_PORT_USHORT((USHORT*)VBE_PORT_DATA);
    pVbeModeInfo->PhysBasePtr = pVbeModeInfo->PhysBasePtr << 16;
        
    TraceVerbose(("<==== '%s'.\n", __FUNCTION__));

    return TRUE;
}
VOID
DefaultQueue_EvtIoDeviceControl(
    _In_ WDFQUEUE Queue,
    _In_ WDFREQUEST Request,
    _In_ size_t OutputBufferLength,
    _In_ size_t InputBufferLength,
    _In_ ULONG IoControlCode
    )
/*++

Routine Description:

    EvtIoDeviceControl handler for the default Queue

Arguments:

    Queue -  Handle to the framework queue object that is associated with the
             I/O request.

    Request - Handle to a framework request object.

    OutputBufferLength - Size of the output buffer in bytes

    InputBufferLength - Size of the input buffer in bytes

    IoControlCode - I/O control code.

--*/
{
    WDFDEVICE WdfDevice;
    PCONTROLLER_CONTEXT ControllerContext;
    BOOLEAN HandledbyUfx;   

    TraceEntry();

    TraceVerbose("Queue 0x%p, Request 0x%p, OutputBufferLength %d, "
                  "InputBufferLength %d, IoControlCode %d",
                  Queue, Request, (int) OutputBufferLength, 
                  (int) InputBufferLength, IoControlCode);
    
    WdfDevice = WdfIoQueueGetDevice(Queue);
    ControllerContext = DeviceGetControllerContext(WdfDevice);

    HandledbyUfx = UfxDeviceIoControl(
                        ControllerContext->UfxDevice,
                        Request,
                        OutputBufferLength,
                        InputBufferLength,
                        IoControlCode);

    if (!HandledbyUfx) {
        TraceError("Recieved an unsupported IOCTL");
        WdfRequestComplete(Request, STATUS_INVALID_DEVICE_REQUEST);
    }

    TraceExit();
}
Example #18
0
STDMETHODIMP CMPEGFilter::Pause()
{
	TraceVerbose("Entered CMPEGFilter::Pause\n");

	// Lock any other app thread functions from entering
	CAutoLock cObjectLock(m_pLock);

	 // Pause the base filter class
    HRESULT hr = CBaseFilter::Pause();
    if (FAILED(hr)) {
        NOTE("Pause failed");
        return hr;
    }

	m_pMPEGObj->Pause();	

	TraceVerbose("Exiting CMPEGFilter::Pause\n");
    return S_OK;
}
Example #19
0
BOOLEAN NTAPI XenGfxVbeInitialize(UCHAR *pShadowPortBase)
{
    ULONG Addr;
    PHYSICAL_ADDRESS PhysAddr = {0};
    UCHAR *pVirtAddr;

    TraceVerbose(("====> '%s'.\n", __FUNCTION__));

    if (g_VbeInfoInitialized) {
        TraceVerbose(("VBE support already initialized?\n"));
        return FALSE;
    }

    // Pull up the VBE table information from the VBE BIOS area.
    Addr = (READ_PORT_USHORT((USHORT*)(pShadowPortBase + VGA_PORT_VBE_XVTSEG)) & (0x0000FFFF)) << 4;
    Addr = Addr | (READ_PORT_USHORT((USHORT*)(pShadowPortBase + VGA_PORT_VBE_XVTADDR)) & (0x0000FFFF));
    PhysAddr.LowPart = Addr;
    pVirtAddr = (UCHAR*)MmMapIoSpace(PhysAddr, sizeof(VBE_XENVESA_TABLE), MmNonCached);
    if (pVirtAddr == NULL) {
        TraceError(("Could not MAP in VBE info table!\n"));
        return FALSE;
    }
    RtlCopyMemory(&g_VbeTable, pVirtAddr, sizeof(VBE_XENVESA_TABLE));
    MmUnmapIoSpace(pVirtAddr, sizeof(VBE_XENVESA_TABLE));

    // Sanity check the tag for the table
    if (RtlCompareMemory(g_VbeTable.Tag, VBE_XENVESA_TAG, sizeof(g_VbeTable.Tag)) != sizeof(g_VbeTable.Tag)) {
        TraceError(("Invalid VBE info tag?? Tag value: %.*s\n", sizeof(g_VbeTable.Tag) - 1, g_VbeTable.Tag));
        return FALSE;
    }

    // Pull up the Vesa mode information once up front.
    if (!XenGfxPullUpModeInfo()) {
        // Errors traced in call
        return FALSE;
    }

    g_VbeInfoInitialized = TRUE;

    TraceVerbose(("<==== '%s'.\n", __FUNCTION__));
    return TRUE;
}
Example #20
0
VOID
_XenGfxEnter(const char *pFunction, ULONG Level)
{
    TraceVerbose(("====> '%s'.\n", pFunction));
    if (Level == 1)
        g_EnterCounter1++;
    else if (Level == 2)
        g_EnterCounter2++;
    else
        g_EnterCounter3++;
}
Example #21
0
STDMETHODIMP CMPEGFilter::Run(REFERENCE_TIME tStart)
{
	TraceVerbose("Entered CMPEGFilter::Run\n");

	CAutoLock cObjectLock(m_pLock);

	ASSERT(m_State != State_Stopped);
	if (m_State != State_Running)
	{
		HRESULT hr = m_pMPEGObj->Run();
		if (FAILED(hr))
		{
			CBaseFilter::Run(tStart);
			return hr;
		}
	}

	HRESULT hr = CBaseFilter::Run(tStart);
	
	TraceVerbose("Exiting CMPEGFilter::Run\n");
    return hr;
}
Example #22
0
NTSTATUS NTAPI
DriverEntry(PDRIVER_OBJECT driverObject,
			PUNICODE_STRING registryPath)
{
    UNREFERENCED_PARAMETER(registryPath);	

    TraceVerbose(("====> '%s'.\n", __FUNCTION__));

    PsGetVersion(&g_osMajorVersion, &g_osMinorVersion, NULL, NULL);

    if ((g_osMajorVersion < 5)||((g_osMajorVersion == 5)&&(g_osMinorVersion < 1))) {
        TraceWarning(("Windows XP or later operating systems supported!\n"));
        return STATUS_UNSUCCESSFUL;
    }

    TraceInfo(("Starting driver...\n"));

    driverObject->DriverUnload = V4vDriverUnload;
    driverObject->DriverExtension->AddDevice = V4vAddDevice;
	
    driverObject->MajorFunction[IRP_MJ_CREATE]         = V4vDispatchCreate;
    driverObject->MajorFunction[IRP_MJ_CLEANUP]        = V4vDispatchCleanup;
    driverObject->MajorFunction[IRP_MJ_CLOSE]          = V4vDispatchClose;
    driverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = V4vDispatchDeviceControl;
    driverObject->MajorFunction[IRP_MJ_READ]           = V4vDispatchRead;
    driverObject->MajorFunction[IRP_MJ_WRITE]          = V4vDispatchWrite;
    driverObject->MajorFunction[IRP_MJ_PNP]            = V4vDispatchPnP;
    driverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = V4vDispatchWmi;
    driverObject->MajorFunction[IRP_MJ_POWER]          = V4vDispatchPower;
    // The rest can be handled by the system not supported routine

    TraceVerbose(("DriverEntry returning successfully\n"));

    TraceVerbose(("<==== '%s'.\n", __FUNCTION__));

    return STATUS_SUCCESS;
}
Example #23
0
// This routine configures a continuous reader on the interrupt endpoint. It's called from the PrepareHarware event.
//
NTSTATUS HidFx2ConfigContReaderForInterruptEndPoint(PDEVICE_EXTENSION pDeviceContext)
{
    WDF_USB_CONTINUOUS_READER_CONFIG    contReaderConfig;
    NTSTATUS                            status = STATUS_SUCCESS;

    PAGED_CODE ();

    TraceVerbose(DBG_INIT, "(%!FUNC!) Enter\n");

    WDF_USB_CONTINUOUS_READER_CONFIG_INIT(&contReaderConfig,
                                          HidFx2EvtUsbInterruptPipeReadComplete,
                                          pDeviceContext,    // Context
                                          sizeof(UCHAR));   // TransferLength

    status = WdfUsbTargetPipeConfigContinuousReader(pDeviceContext->hInterruptPipe, &contReaderConfig);
    if (!NT_SUCCESS(status))
    {
        TraceErr(DBG_INIT, "(%!FUNC!) failed %!STATUS!\n", status);
    }

    TraceVerbose(DBG_INIT, "(%!FUNC!) Exit, status: %!STATUS!\n", status);

    return status;
}
Example #24
0
VOID
HandleUSBLinkStateChange (
    WDFDEVICE WdfDevice
    )
/*++

Routine Description:

    Handles a link change event from the controller.

Arguments:

    WdfDevice - WDFDEVICE object representing the controller.

--*/
{
    PCONTROLLER_CONTEXT ControllerContext;
    ULONG UsbLinkEvent;

    TraceEntry();

    ControllerContext = DeviceGetControllerContext(WdfDevice);
    
    //
    // #### TODO: Add code to read link state from controller ####
    // 
    // For sample purposes use U0.
    UsbLinkEvent = USB_LINK_STATE_U0;

    if (UsbLinkEvent == USB_LINK_STATE_U0) { 

        if(ControllerContext->Suspended) {
            ControllerContext->Suspended = FALSE;
            UfxDeviceNotifyResume(ControllerContext->UfxDevice);    
        }

        ControllerContext->RemoteWakeupRequested = FALSE;

    } else {
        TraceVerbose("Ignoring link state change event: 0X%X", UsbLinkEvent);
    }

    TraceExit();
}
Example #25
0
/* Wait for NDIS to return any outstanding packets.  The caller must
   already have taken some appropriate measures to make sure that no
   more packets arrive in the meantime. */
void
ReceiverWaitForPacketReturn(PRECEIVER Receiver)
{
    LARGE_INTEGER interval;

    interval.QuadPart = -100000; /* 100ms in units of 100ns */

    NdisAcquireSpinLock(&Receiver->Common.Lock);
    while (Receiver->nRxInNdis) {
        TraceVerbose (("%d rx.\n", Receiver->nRxInNdis));

        NdisReleaseSpinLock(&Receiver->Common.Lock);
        KeDelayExecutionThread(KernelMode, FALSE, &interval);
        NdisAcquireSpinLock(&Receiver->Common.Lock);

        ReceiverSwizzle(Receiver);
    }
    NdisReleaseSpinLock(&Receiver->Common.Lock);
}
Example #26
0
void EbrDebugLogShim(const char* format, ...) {
#ifdef _DEBUG
    va_list va;

    va_start(va, format);
    char buf[c_bufferCount];
    int len = vsnprintf_s(buf, _countof(buf), _TRUNCATE, format, va);
    va_end(va);

    // Trim off newline for EBR debug.
    if ((len > 0) && (len < (c_bufferCount - 1)) && (buf[len - 1] == '\n')) {
        buf[len - 1] = '\0';
    }
    wchar_t wbuf[c_bufferCount];
    size_t wlen;
    mbstowcs_s(&wlen, wbuf, _countof(wbuf), buf, _TRUNCATE);
    TraceVerbose(L"EbrDebugLog", wbuf);
#endif
}
Example #27
0
static NTSTATUS
XenWorkItemDispatch(
    IN  struct xm_thread    *pSelf,
    IN  VOID                *Argument
    )
{
    KIRQL                   Irql;

    UNREFERENCED_PARAMETER(Argument);

    while (XmThreadWait(pSelf) >= 0) {
        Irql = acquire_irqsafe_lock(&WorkItemDispatchLock);
        while (!IsListEmpty(&PendingWorkItems)) {
            PLIST_ENTRY Head;
            XEN_WORKITEM *Item;

            Head = RemoveHeadList(&PendingWorkItems);
            Item = CurrentItem = CONTAINING_RECORD(Head, XEN_WORKITEM, List);
            release_irqsafe_lock(&WorkItemDispatchLock, Irql);

            XM_ASSERT(CurrentItem->Magic == WORKITEM_MAGIC);

            KeQuerySystemTime(&Item->Start);

            TraceVerbose(("%s: invoking '%s'\n", __FUNCTION__, CurrentItem->Name));
            CurrentItem->Work(CurrentItem->Context);

            Irql = acquire_irqsafe_lock(&WorkItemDispatchLock);
            CurrentItem = NULL;
            release_irqsafe_lock(&WorkItemDispatchLock, Irql);

            XmFreeMemory(Item);

            Irql = acquire_irqsafe_lock(&WorkItemDispatchLock);
        }
        release_irqsafe_lock(&WorkItemDispatchLock, Irql);
    }

    TraceWarning(("%s: terminating.\n", __FUNCTION__));
    return STATUS_SUCCESS;
}
Example #28
0
bool EbrRemove(const char* path) {
    struct stat s;
    if (EbrStat(path, &s) == 0) {
        if (s.st_mode & S_IFREG) {
            if (EbrUnlink(path)) {
                return true;
            } else {
                TraceError(TAG, L"Failed to unlink file %hs", path);
                return false;
            }
        } else if (s.st_mode & S_IFDIR) {
            EbrDir* dir = EbrOpenDir(path);
            if (dir) {
                EbrDirEnt ent;
                while (EbrReadDir(dir, &ent)) {
                    if (strcmp(ent.fileName, ".") == 0 || strcmp(ent.fileName, "..") == 0)
                        continue;

                    char fullPath[4096]; // max path?
                    sprintf_s(fullPath, sizeof(fullPath), "%s%s%s", path, PATH_SEPARATOR, ent.fileName);
                    if (!EbrRemove(fullPath)) {
                        EbrCloseDir(dir);
                        return false;
                    }
                }
                EbrCloseDir(dir);
            }

            return EbrRemoveEmptyDir(path);
        } else {
            TraceVerbose(TAG, L"Unrecognized file type: %d", s.st_mode);
            return false;
        }
    }
    return false;
}
Example #29
0
long CTimestamps::GetFrameRepeatCount(LONGLONG llStartTime, LONGLONG llEndTime)
{
	// This function tells us if this frame is to be
	// duplicated, or if it is to be dropped
	
	// retrieve target framerate

	// how many times will we encode this very sample?
	// default is one time
	static bool bLastFrameWasDropped = false;
	int nTimesToEncodeThisFrame = 1; 
	if (m_bFramebalance == true)
	{
		 // All time values are represented in integer 100 millisecond units

		 // First we need the average time for one output frame (in units)
		 LONGLONG llTimePerOutputFrame = (LONGLONG)((1.0f / m_dFramerate) * UNITS);

		 // if we were to encode this video sample, it would actually
		 // be displayed at time llDisplayTime in the output mpeg file
		 LONGLONG llDisplayTime = m_nOutputFrameCount * llTimePerOutputFrame;

		 
		 // llStartTime is when the sample sent in should start
		 // displaying in the mpeg output file. llStopTime is when
		 // the sample should stop displaying

		 // The frame we 
		 // There is a time offset between those two that is 
		 LONGLONG llTimeOffset = llDisplayTime - llStartTime;
		
		 // How many frames does the display frame span? We will
		 // add this to the number of times the frame should be repeated
		 // How many mpeg output frames are covered by the start and end 
		 // time of this particular frame that we are looking at? This value is
		 // the number of "span frames", i.e, the number of frames it spans. 
		 // Each of the output frames it spans is the same as this particular frame,
		 // so every one of them is going to be this frame, but repeated

		 LONGLONG nSpanFrames = (llEndTime - llStartTime) / llTimePerOutputFrame;
		 // _ASSERT(nSpanFrames == 0);

		 // this offset could be positive or negative

		 // -- At our current framerate, how many frames would fit into
		 // this time offset?
		 // We divide by the remaining time to get the number of frames that
		 // would fit into that space
		__int64 iFramesTillDisplayTime = llTimeOffset / llTimePerOutputFrame;

        if (iFramesTillDisplayTime >= 1)
		{
		//	_ASSERT(bLastFrameWasDropped != true);
            nTimesToEncodeThisFrame = 0; // drop frame
			bLastFrameWasDropped = true;
		}
        else if (iFramesTillDisplayTime <= -1)
		{
            nTimesToEncodeThisFrame = (long)(fabs((double)iFramesTillDisplayTime) + 1.0); //more than 1 frame
		}

		// if (nSpanFrames >= 0)
		nTimesToEncodeThisFrame += (int)(nSpanFrames /*- 1*/); // the -1 because there is already 1 encode

		_ASSERT(nTimesToEncodeThisFrame >= 0);

		TraceVerbose("Target Display Time For Frame: %I64d - %I64d\n", llDisplayTime, llDisplayTime + llTimePerOutputFrame);
		TraceVerbose("Actual Display Time For Frame: %I64d - %I64d\n", llStartTime, llEndTime);

		if (nTimesToEncodeThisFrame == 0)
			TraceVerbose("FRAMEDROP\n");
		else
			bLastFrameWasDropped = false;
	}

	return nTimesToEncodeThisFrame;
}
Example #30
0
// Finds the Report descriptor and copies it into the buffer provided by the Request.
//
NTSTATUS HidFx2GetReportDescriptor(_In_ WDFDEVICE hDevice, _In_ WDFREQUEST hRequest)
{
    NTSTATUS                status = STATUS_SUCCESS;
    WDFMEMORY               memory;
    PDEVICE_EXTENSION       pDevContext = NULL;
    PVOID                   pBuffer = (PVOID)c_ButtonDescriptor;
    size_t                  cBytesToCopy = sizeof(c_ButtonDescriptor);


    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Entry\n");

    status = WdfRequestRetrieveOutputMemory(hRequest, &memory);
    if (NT_SUCCESS(status))
    {
        pDevContext = GetDeviceContext(hDevice);
        if (pDevContext != NULL)
        {
           // Select a non default report descriptor
            switch (pDevContext->driverMode)
            {
            case DM_BUTTON_AND_LED:
                pBuffer = (PVOID)c_ButtonWithLedDescriptor;
                cBytesToCopy = sizeof(c_ButtonWithLedDescriptor);
                break;
            case DM_SLIDER_SWITCH:
                pBuffer = (PVOID)c_SliderSwitchDescriptor;
                cBytesToCopy = sizeof(c_SliderSwitchDescriptor);
                break;
            case DM_SLIDER_SWITCH_AND_LED:
                pBuffer = (PVOID)c_SliderSwitchWithLedDescriptor;
                cBytesToCopy = sizeof(c_SliderSwitchWithLedDescriptor);
                break;
            case DM_LED_ONLY:
                pBuffer = (PVOID)c_LedOnlyDescriptor;
                cBytesToCopy = sizeof(c_LedOnlyDescriptor);
                break;
            default:
                break;
            }
        }
        if (cBytesToCopy != 0)
        {
            status = WdfMemoryCopyFromBuffer(memory, 0, pBuffer, cBytesToCopy);
            if (NT_SUCCESS(status))
            {
                // Report how many bytes were copied
                WdfRequestSetInformation(hRequest, cBytesToCopy);
            }
            else // WdfMemoryCopyFromBuffer failed
            {
                TraceErr(DBG_IOCTL, "(%!FUNC!) WdfMemoryCopyFromBuffer failed %!STATUS!\n", status);
            }
        }
        else // report length is zero
        {
            status = STATUS_INVALID_DEVICE_STATE;
            TraceErr(DBG_IOCTL, "(%!FUNC!) c_DefaultHidDescriptor's reportLength is zero, %!STATUS!\n", status);
        }
    }
    else // WdfRequestRetrieveOutputMemory failed
    {
        TraceErr(DBG_IOCTL, "(%!FUNC!)WdfRequestRetrieveOutputMemory failed %!STATUS!\n", status);

    }

    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Exit = %!STATUS!\n", status);
    return status;
}