Ejemplo n.º 1
0
status_t
DavicomDevice::Open(uint32 flags)
{
	if (fOpen)
		return B_BUSY;
	if (fRemoved)
		return B_ERROR;
	
	status_t result = StartDevice();
	if (result != B_OK) {
		return result;
	}
	
	// setup state notifications
	result = gUSBModule->queue_interrupt(fNotifyEndpoint, fNotifyBuffer,
		kNotifyBufferSize, _NotifyCallback, this);
	if(result != B_OK) {
		TRACE_ALWAYS("Error of requesting notify interrupt:%#010x\n", result);
		return result;
	}

	fNonBlocking = (flags & O_NONBLOCK) == O_NONBLOCK;
	fOpen = true;
	return result; 
}
Ejemplo n.º 2
0
    void AudioRenderer::EndFlush()
    {
        CAutoLock objectLock(this);

        if (m_device)
        {
            if (m_state == State_Running)
            {
                m_myClock.UnslaveClockFromAudio();
                m_device->Stop();
                m_device->Reset();
                m_sampleCorrection.NewDeviceBuffer();
                InitializeProcessors();
                m_startClockOffset = m_sampleCorrection.GetLastFrameEnd();
                StartDevice();
            }
            else
            {
                m_device->Reset();
                m_sampleCorrection.NewDeviceBuffer();
                InitializeProcessors();
            }
        }

        m_flush.Reset();
    }
Ejemplo n.º 3
0
OMX_ERRORTYPE VideoSource::InstanceInit()
{
    OMX_ERRORTYPE ret = OMX_ErrorNone;

	nFrameInterval = (1000000LL / (sVideoFmt.xFramerate / Q16_SHIFT));
	StartDevice();

    return ret;
}
Ejemplo n.º 4
0
    void AudioRenderer::Play(REFERENCE_TIME startTime)
    {
        CAutoLock objectLock(this);
        assert(m_state != State_Running);
        m_state = State_Running;

        m_startTime = startTime;
        StartDevice();
    }
BOOL ZFXGamepad::EnumPadCallback(const DIDEVICEINSTANCE *pInst)
{
	//try to start up this one
	if (SUCCEEDED(StartDevice(pInst->guidInstance, &c_dfDIJoystick)))
	{
		m_bPadFound = true;
		wcscpy_s((TCHAR*)pInst->tszProductName, sizeof(m_Name), m_Name);
		return DIENUM_STOP;
	}

	return DIENUM_CONTINUE;
}
OMX_ERRORTYPE AudioSource::DoPause2Exec()
{
	OMX_ERRORTYPE ret = OMX_ErrorNone;

	AudioRenderFadeInFadeOut.SetMode(FADEIN);

	printf("Set AudioSource start time.\n");
	ClockSetConfig(OMX_IndexConfigTimeClientStartTime, &StartTime);

	StartDevice();

    return ret;
}
NS_IMETHODIMP MaemoLocationProvider::Startup()
{
  nsresult rv(NS_OK);

  nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
  if (!prefs)
    return NS_ERROR_FAILURE;

  rv = StartControl();
  NS_ENSURE_SUCCESS(rv, rv);

  rv = StartDevice();
  NS_ENSURE_SUCCESS(rv, rv);

  prefs->GetBoolPref("geo.herror.ignore.big", &mIgnoreBigHErr);

  if (mIgnoreBigHErr)
    prefs->GetIntPref("geo.herror.max.value", &mMaxHErr);

  prefs->GetBoolPref("geo.verror.ignore.big", &mIgnoreBigVErr);

  if (mIgnoreBigVErr)
    prefs->GetIntPref("geo.verror.max.value", &mMaxVErr);

  if (mUpdateTimer)
    return NS_OK;

  PRInt32 update = 0; //0 second no timer created
  prefs->GetIntPref("geo.default.update", &update);

  if (!update)
    return NS_OK;

  mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);

  if (NS_FAILED(rv))
    return NS_ERROR_FAILURE;

  if (update)
    mUpdateTimer->InitWithCallback(this, update, nsITimer::TYPE_REPEATING_SLACK);

  return NS_OK;
}
Ejemplo n.º 8
0
HRESULT ZFXMouse::Init()
{
	//clear memory
	memset(m_bPressed, 0, sizeof(bool)* MOUSE_BUTTON_LIMIT);
	memset(m_bReleased, 0, sizeof(bool)*MOUSE_BUTTON_LIMIT);
	m_lX = m_lY = m_lZ = 0;

	if (FAILED(StartDevice(GUID_SysMouse, &c_dfDIMouse)))
	{
		return ZFX_FAIL;
	}

	//event notification
	if (!(m_hEvent = CreateEvent(NULL, FALSE, FALSE, NULL)))
	{
		return ZFX_FAIL;
	}

	if (FAILED(m_pDevice->SetEventNotification(m_hEvent)))
	{
		return ZFX_FAIL;
	}

	//build mouse buffer
	DIPROPDWORD dipdw;
	dipdw.diph.dwSize = sizeof(DIPROPDWORD);
	dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
	dipdw.diph.dwObj = 0;
	dipdw.diph.dwHow = DIPH_DEVICE;
	dipdw.dwData = BUFFER_SIZE;

	if (FAILED(m_pDevice->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph)))
	{
		return ZFX_FAIL;
	}

	m_pDevice->Acquire();
	return ZFX_OK;
}
BOOL CUsbtestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 设置此对话框的图标。  当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO:  在此添加额外的初始化代码

    int devCount = 1;

    if (DEVCTRL_SUCCESS != EnumerateDevices(&devID, &devCount))
    {
        AfxMessageBox(_T("打开USB Slave失败,程序即将关闭!"));
        exit(-1);
    }

    waveSize = 8000;
    waveCount = 100;
    SetWaveParam(devID, waveSize, 1);    

    SendCommand(devID, CMD_SET_TEST, 1);
    SendCommand(devID, CMD_SET_TRIGWAVE_DELAY, 100);

    for (int i = 0; i < 10; i++)
    {
        unsigned char* buf = new unsigned char[waveSize*waveCount];
        AddBuffer(devID, buf, waveSize*waveCount);
    }

    HANDLE h = CreateThread(NULL, 0, ::WaitWaveProc, this, 0, &dwThreadID);

    StartDevice(devID);

	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}
Ejemplo n.º 10
0
NTSTATUS
DispatchPnp(
    __in PDEVICE_OBJECT DeviceObject,
    __in PIRP Irp
    )
{
    PIO_STACK_LOCATION StackLocation;
    PDEVICE_EXTENSION pdx;
    UCHAR MinorFunction;
    NTSTATUS status;

    Warning("Received an IRP.\n");
    StackLocation = IoGetCurrentIrpStackLocation(Irp);
    MinorFunction = StackLocation->MinorFunction;
    pdx = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;

    switch (StackLocation->MinorFunction) {
        case IRP_MN_START_DEVICE:
            Warning("IRP_MN_START_DEVICE IRP received.\n");
            status = StartDevice(DeviceObject, Irp);
            break;
        case IRP_MN_STOP_DEVICE:
            Warning("IRP_MN_STOP_DEVICE IRP received.\n");
            status = StopDevice(DeviceObject, Irp);
            break;
        case IRP_MN_REMOVE_DEVICE:
            Warning("IRP_MN_REMOVE_DEVICE IRP received.\n");
            status = RemoveDevice(DeviceObject, Irp);
            break;
        default:
            Warning("IRP ID = %d.\n", StackLocation->MinorFunction);
            IoSkipCurrentIrpStackLocation(Irp);
            status = IoCallDriver(pdx->LowerDeviceObject, Irp);
            break;
    }

    return status;
}
Ejemplo n.º 11
0
void VellemanOut::outputDMX(quint32 output, const QByteArray& universe)
{
    if (output != 0)
        return;

    if (m_currentlyOpen == false)
    {
        StartDevice();
        m_currentlyOpen = true;
    }

    int32_t channelCount = (int32_t) universe.size();
    SetChannelCount(channelCount);

    int32_t values [512]; //Set up array to pass to SetAllData.
    for (int32_t channelLoop = 0; channelLoop < channelCount; channelLoop++)
    {
        //Write the value to our temporary array.
        values[channelLoop] = (quint32) universe[channelLoop];
    }

    SetAllData(values);
}
Ejemplo n.º 12
0
    void AudioRenderer::CreateDevice()
    {
        CAutoLock objectLock(this);

        assert(!m_device);
        assert(m_inputFormat);

        m_deviceSettingsSerial = m_settings->GetSerial();
        m_defaultDeviceSerial = m_deviceManager.GetDefaultDeviceSerial();
        m_device = m_deviceManager.CreateDevice(m_inputFormat, m_live || m_externalClock, m_settings);

        if (m_device)
        {
            m_sampleCorrection.NewDeviceBuffer();

            InitializeProcessors();

            m_startClockOffset = m_sampleCorrection.GetLastFrameEnd();

            if (m_state == State_Running)
                StartDevice();
        }
    }
Ejemplo n.º 13
0
Archivo: Pnp.c Proyecto: uri247/pmgmt
NTSTATUS
SwdmDispatchPnP(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    )
{
    IO_STACK_LOCATION* pStk;
    DEVICE_EXTENSION* pCtx;
	ULONG MinorCode;
	NTSTATUS Status = STATUS_SUCCESS;

	DbgPrintEx( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "IRP_MJ_PNP Received : Begin\n" );

	pStk = IoGetCurrentIrpStackLocation(Irp);
	pCtx = (DEVICE_EXTENSION*)DeviceObject->DeviceExtension;
	IoAcquireRemoveLock( &pCtx->RemoveLock, Irp);
	MinorCode = pStk->MinorFunction;

    DbgPrintEx( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "Minor code: 0x%x\n", MinorCode );

	switch( MinorCode )
	{
	case IRP_MN_START_DEVICE:
		DbgPrintEx( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "IRP_MN_START_DEVICE Received : Begin\r\n");
		Status = StartDevice( DeviceObject, Irp );
		DbgPrintEx( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "IRP_MN_START_DEVICE Received : End\r\n");
		break;
	case IRP_MN_STOP_DEVICE:
		DbgPrintEx( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "IRP_MN_STOP_DEVICE Received : Begin\r\n");
		Status = StopDevice( DeviceObject, Irp );
		DbgPrintEx( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "IRP_MN_STOP_DEVICE Received : End\r\n");
		break;
	case IRP_MN_REMOVE_DEVICE:
		DbgPrintEx( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "IRP_MN_REMOVE_DEVICE Received : Begin\r\n");
		Status = RemoveDevice( DeviceObject, Irp );
		DbgPrintEx( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "IRP_MN_REMOVE_DEVICE Received : End\r\n");
		break;
	case IRP_MN_QUERY_CAPABILITIES :
		DbgPrintEx( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "IRP_MN_QUERY_CAPABILITIES Received : Begin\r\n");
		Status = QueryCapability(
			DeviceObject,
			Irp
		);
		DbgPrintEx( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "IRP_MN_QUERY_CAPABILITIES Received : End\r\n");
		break;
    case IRP_MN_QUERY_BUS_INFORMATION:
        DbgPrintEx( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "IRP_MN_QUERY_BUS_INFORMATION Received : Begin\n");
        Status = QueryBus( DeviceObject, Irp );
        break;

	default:
		break;
	}
	IoReleaseRemoveLock( &pCtx->RemoveLock, Irp);
	
	if (NT_SUCCESS(Status))
    {
	  CompleteRequest(
		Irp, 
		STATUS_SUCCESS, 
		0);
    }

	DbgPrintEx( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "IRP_MJ_PNP Received : End\r\n");

	return Status;
}
Ejemplo n.º 14
0
void StartCL(CL* cl){
    StartPlatform(cl);
    StartDevice(cl);
    StartContext(cl);
}
Ejemplo n.º 15
0
NTSTATUS NTAPI
FdoDispatchPnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
    NTSTATUS Status;
    PIO_STACK_LOCATION Stack = NULL;
    PCM_PARTIAL_RESOURCE_LIST raw;
    PCM_PARTIAL_RESOURCE_LIST translated;
    ULONG_PTR Information = 0;

    Stack =  IoGetCurrentIrpStackLocation(Irp);

    switch(Stack->MinorFunction)
    {
        case IRP_MN_START_DEVICE:
        {
            DPRINT1("Ehci: START_DEVICE\n");

            Irp->IoStatus.Status = STATUS_SUCCESS;
            Status = ForwardAndWait(DeviceObject, Irp);

            raw = &Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList;
            translated = &Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList;
            Status = StartDevice(DeviceObject, raw, translated);
            break;
        }
        case IRP_MN_QUERY_DEVICE_RELATIONS:
        {
            DPRINT1("Ehci: IRP_MN_QUERY_DEVICE_RELATIONS\n");
            switch(Stack->Parameters.QueryDeviceRelations.Type)
            {
                case BusRelations:
                {
                    PDEVICE_RELATIONS DeviceRelations = NULL;
                    DPRINT1("Ehci: BusRelations\n");
                    Status = FdoQueryBusRelations(DeviceObject, &DeviceRelations);
                    Information = (ULONG_PTR)DeviceRelations;
                    break;
                }
                default:
                {
                    DPRINT1("Ehci: Unknown query device relations type\n");
                    Status = STATUS_NOT_IMPLEMENTED;
                    break;
                }
             }
             break;
        }
        case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
        {
            DPRINT1("Ehci: IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
            return ForwardIrpAndForget(DeviceObject, Irp);
            break;
        }
        case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
        {
            DPRINT1("Ehci: IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n");
        }
        case IRP_MN_QUERY_INTERFACE:
        {
            DPRINT1("Ehci: IRP_MN_QUERY_INTERFACE\n");
            Status = STATUS_SUCCESS;
            Information = 0;
            Status = ForwardIrpAndForget(DeviceObject, Irp);
            return Status;
            break;
        }
        default:
        {
            DPRINT1("Ehci: IRP_MJ_PNP / Unhandled minor function 0x%lx\n", Stack->MinorFunction);
            return ForwardIrpAndForget(DeviceObject, Irp);
        }
    }

    Irp->IoStatus.Information = Information;
    Irp->IoStatus.Status = Status;
    IoCompleteRequest(Irp, IO_NO_INCREMENT);
    return Status;
}
Ejemplo n.º 16
0
int	CLldBdConf::InitATvbBd(int _my_num, void *_my_cnxt)
{
	CBdInit	*lld;
	_BD_CONF_CNXT	*my_cxt;
	int	reg_dta_secur, reg_dta_bd_typ, reg_dta_conf;
	unsigned long 	ret, sts;
	KCMD_ARGS		KCmdInf;

	my_id = _my_num;
	memcpy(MyCnxt(), _my_cnxt, sizeof(_BD_CONF_CNXT));
	my_cxt = MyCnxt();

	lld = (CBdInit *)my_lld;
	lld->DupBdCnxt_Step1((void *)MyCnxt());

	InitMyCifBuf();

	if (my_cxt->_dev_hnd_usb != NULL)		//	lnx. usb type
	{
#ifdef WIN32
#else
		StartDevice((usb_dev_handle *)my_cxt->_dev_hnd_usb);

////////////////////////////////////////////////////////////////
		KCmdInf.dwCmdParm1 = 0x1C;	// 0x70 in byte address
		TLV_DeviceIoControl_usb((usb_dev_handle *)my_cxt->_dev_hnd_usb,
			IOCTL_READ_PCI9054_REG,
			&KCmdInf,
			sizeof(KCmdInf),
			&KCmdInf,
			sizeof(KCmdInf),	
			&ret, 0);
		sts = (unsigned long)(KCmdInf.dwCmdParm2);
		lld->LldPrint_1("[LLD]PCI9054REG:[0x70]", (int)sts);

////////////////////////////////////////////////////////////////
		reg_dta_secur = lld->WDM_Read_TSP_USB(TSP_BOARD_SECURITY);
		reg_dta_bd_typ = lld->WDM_Read_TSP_USB(TSP_BOARD_ID_ADDR);
		reg_dta_conf = lld->WDM_Read_TSP_USB(TSP_BOARD_CONFIG_STATUS);
#endif
	}
	else	//	win or lnx. pci typ
	{
		KCmdInf.dwCmdParm1 = 0x1C;		//	Test to read PCI Register. 0x70 in byte address
		TLV_DeviceIoControl(my_cxt->_dev_hnd,
			IOCTL_READ_PCI9054_REG,
			&KCmdInf,
			sizeof(KCmdInf),
			&KCmdInf,
			sizeof(KCmdInf),	
			&ret, 0);
		sts = (unsigned long)(KCmdInf.dwCmdParm2);
		lld->LldPrint_1("[LLD]PCI9054REG:[0x70]", (int)sts);

////////////////////////////////////////////////////////////////
		reg_dta_secur = lld->WDM_Read_TSP(TSP_BOARD_SECURITY);
		reg_dta_bd_typ = lld->WDM_Read_TSP(TSP_BOARD_ID_ADDR);
		reg_dta_conf = lld->WDM_Read_TSP(TSP_BOARD_CONFIG_STATUS);
	}
	if (InitATvbBd_WinLnx_PciUsb(reg_dta_secur, reg_dta_bd_typ, reg_dta_conf) < 0)
	{
		CloseATvbDev();
		return	-1;
	}
	
////////////////////////////////////////////////////////////////	test interface
	ret = lld->WDM_Check_PCI_Status(0, 0);
	if (ret != TLV_NO_ERR)
	{
		lld->LldPrint_Error("[LLD]Fail to read PCI register", my_id, 0);
		CloseATvbDev();
		return	-1;
	}

	lld->DBG_PRINT_BD_CONF(my_id,
			my_cxt->_bd_typ_id,
			my_cxt->_bd_typ_small_mem_space,
			my_cxt->_bd_revision,
			my_cxt->_bd_use_AMP,
			my_cxt->_bd_revision_tvb595,
			my_cxt->_bd_revision_ext,
			my_cxt->__id__);

	return	TLV_NO_ERR;
}
Ejemplo n.º 17
0
/*******************************************************************************
 *
 * Function   :  AddDevice
 *
 * Description:  Add a new device object to the driver
 *
 ******************************************************************************/
int
AddDevice(
    DRIVER_OBJECT  *pDriverObject,
    struct pci_dev *pPciDev
)
{
#if defined(PLX_DMA_SUPPORT)
    U8                i;
#endif
    int               status;
    U32               RegValue;
    DEVICE_OBJECT    *fdo;
    DEVICE_OBJECT    *pDevice;
    DEVICE_EXTENSION *pdx;


    // Allocate memory for the device object
    fdo =
        kmalloc(
            sizeof(DEVICE_OBJECT),
            GFP_KERNEL
        );

    if (fdo == NULL)
    {
        ErrorPrintf(("ERROR - memory allocation for device object failed\n"));
        return (-ENOMEM);
    }

    // Initialize device object
    RtlZeroMemory( fdo, sizeof(DEVICE_OBJECT) );

    fdo->DriverObject    = pDriverObject;         // Save parent driver object
    fdo->DeviceExtension = &(fdo->DeviceInfo);

    // Enable the device
    if (pci_enable_device( pPciDev ) == 0)
    {
        DebugPrintf(("Enabled PCI device\n"));
    }
    else
    {
        ErrorPrintf(("WARNING - PCI device enable failed\n"));
    }

    // Enable bus mastering
    pci_set_master( pPciDev );

    //
    // Initialize the device extension
    //

    pdx = fdo->DeviceExtension;

    // Clear device extension
    RtlZeroMemory( pdx, sizeof(DEVICE_EXTENSION) );

    // Store parent device object
    pdx->pDeviceObject = fdo;

    // Save the OS-supplied PCI object
    pdx->pPciDevice = pPciDev;

    // Set initial device device state
    pdx->State = PLX_STATE_STOPPED;

    // Set initial power state
    pdx->PowerState = PowerDeviceD0;

    // Store device location information
    pdx->Key.bus          = pPciDev->bus->number;
    pdx->Key.slot         = PCI_SLOT(pPciDev->devfn);
    pdx->Key.function     = PCI_FUNC(pPciDev->devfn);
    pdx->Key.DeviceId     = pPciDev->device;
    pdx->Key.VendorId     = pPciDev->vendor;
    pdx->Key.SubVendorId  = pPciDev->subsystem_vendor;
    pdx->Key.SubDeviceId  = pPciDev->subsystem_device;
    pdx->Key.DeviceNumber = pDriverObject->DeviceCount;

    // Set API access mode
    pdx->Key.ApiMode = PLX_API_MODE_PCI;

    // Update Revision ID
    PLX_PCI_REG_READ(
        pdx,
        0x08,        // PCI Revision ID
        &RegValue
    );

    pdx->Key.Revision = (U8)(RegValue & 0xFF);

    // Build device name
    sprintf(
        pdx->LinkName,
        PLX_DRIVER_NAME "-%d",
        pDriverObject->DeviceCount
    );

    // Initialize work queue for ISR DPC queueing
    PLX_INIT_WORK(
        &(pdx->Task_DpcForIsr),
        DpcForIsr,                // DPC routine
        &(pdx->Task_DpcForIsr)    // DPC parameter (pre-2.6.20 only)
    );

    // Initialize ISR spinlock
    spin_lock_init(
        &(pdx->Lock_Isr)
    );

    // Initialize interrupt wait list
    INIT_LIST_HEAD(
        &(pdx->List_WaitObjects)
    );

    spin_lock_init(
        &(pdx->Lock_WaitObjectsList)
    );

    // Initialize physical memories list
    INIT_LIST_HEAD(
        &(pdx->List_PhysicalMem)
    );

    spin_lock_init(
        &(pdx->Lock_PhysicalMemList)
    );

#if defined(PLX_DMA_SUPPORT)
    /****************************************************************
     * Set the DMA mask
     *
     * Although PLX devices can handle 64-bit DMA addressing through
     * dual cycles, this driver does not support that feature.  As
     * a result, the OS is notified to keep this device's DMA mask
     * to 32-bit, which is the default anyway.
     ***************************************************************/
    Plx_dma_set_mask( pdx, PLX_DMA_BIT_MASK(32) );

    // Set DMA buffer allocation mask.  PLX DMA requires 32-bit for SGL buffers
    if (Plx_dma_set_coherent_mask( pdx, PLX_DMA_BIT_MASK(32) ) != 0)
    {
        ErrorPrintf(("WARNING - Set DMA coherent mask failed\n"));
    }

    // Initialize DMA spinlocks
    for (i = 0; i < NUM_DMA_CHANNELS; i++)
    {
        spin_lock_init(
            &(pdx->Lock_Dma[i])
        );
    }
#endif  // PLX_DMA_SUPPORT


    //
    // Add to driver device list
    //

    // Acquire Device List lock
    spin_lock(
        &(pDriverObject->Lock_DeviceList)
    );

    // Get device list head
    pDevice = pDriverObject->DeviceObject;

    if (pDevice == NULL)
    {
        // Add device as first in list
        pDriverObject->DeviceObject = fdo;
    }
    else
    {
        // Go to end of list
        while (pDevice->NextDevice != NULL)
            pDevice = pDevice->NextDevice;

        // Add device to end of list
        pDevice->NextDevice = fdo;
    }

    // Increment device count
    pDriverObject->DeviceCount++;

    // Release Device List lock
    spin_unlock(
        &(pDriverObject->Lock_DeviceList)
    );

    DebugPrintf((
                    "Created Device (%s)\n",
                    pdx->LinkName
                ));

    // Start the device
    status = StartDevice( fdo );
    if (status != 0)
    {
        RemoveDevice( fdo );
        return status;
    }

    return 0;
}
Ejemplo n.º 18
0
NTSTATUS
DF_DispatchIoctl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
	NTSTATUS				Status;
	PVOID					InputBuffer;
	ULONG					InputLength;
	PVOID					OutputBuffer;
	ULONG					OutputLength;
	PIO_STACK_LOCATION		IrpSp;
	PDF_DEVICE_EXTENSION	DevExt;
	BOOLEAN					Type;
	PAGED_CODE();

	IrpSp = IoGetCurrentIrpStackLocation(Irp);
	DevExt = (PDF_DEVICE_EXTENSION)DeviceObject->DeviceExtension;

	if (DeviceObject == g_pDeviceObject)
	{
		InputBuffer = Irp->AssociatedIrp.SystemBuffer;
		InputLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
		OutputBuffer = Irp->AssociatedIrp.SystemBuffer;
		OutputLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;

		switch (IrpSp->Parameters.DeviceIoControl.IoControlCode)
		{
		// Test IOCTL
		case IOCTL_DF_TEST:
			DBG_PRINT(DBG_TRACE_OPS, ("%s: Test Ioctl\n", __FUNCTION__));
			if (InputLength >= 2*sizeof(ULONG32) && OutputLength >= sizeof(ULONG32))
			{
				*(ULONG32*)OutputBuffer = ((ULONG32*)InputBuffer)[0] + ((ULONG32*)InputBuffer)[1];
				Irp->IoStatus.Information = sizeof(ULONG32);
			}
			else
				Irp->IoStatus.Information = 0;
			Irp->IoStatus.Status = STATUS_SUCCESS;
			IoCompleteRequest(Irp, IO_NO_INCREMENT);
			return Irp->IoStatus.Status;
		// Start or Stop One Filter
		case IOCTL_DF_START:
		case IOCTL_DF_STOP:
			Type = (IOCTL_DF_START == IrpSp->Parameters.DeviceIoControl.IoControlCode);
			DBG_PRINT(DBG_TRACE_OPS, ("%s: %s One Filter\n", __FUNCTION__, Type?"Start":"Stop"));
			DeviceObject = g_pDriverObject->DeviceObject;
			Status = STATUS_UNSUCCESSFUL;
			while (DeviceObject != NULL)
			{
				DevExt = (PDF_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
				if (DeviceObject != g_pDeviceObject &&
					DevExt->bIsStart == TRUE &&
					DevExt->DiskNumber == ((ULONG32*)InputBuffer)[0] &&
					DevExt->PartitionNumber == ((ULONG32*)InputBuffer)[1])
				{
					DBG_PRINT(DBG_TRACE_OPS, ("%s Filter on disk(%u) partition(%u)\n", Type?"Start":"Stop",
						((ULONG32*)InputBuffer)[0], ((ULONG32*)InputBuffer)[1]));
				#ifndef USE_DRAM
					DBG_PRINT(DBG_TRACE_OPS, ("Use disk(%u) partition(%u) as Cache\n",
						((ULONG32*)InputBuffer)[2], ((ULONG32*)InputBuffer)[3]));
				#endif
					Status = STATUS_SUCCESS;
					if (Type == FALSE)
					{
						DevExt->bIsProtected = FALSE;
						// Wait for unfinished Ops in RW Thread
						while (FALSE == IsListEmpty(&DevExt->RwList))
						{
							KeSetEvent(&DevExt->RwThreadStartEvent, IO_NO_INCREMENT, FALSE);
							KeWaitForSingleObject(&DevExt->RwThreadFinishEvent, Executive, KernelMode, FALSE, NULL);
						}
					#ifdef WRITE_BACK_ENABLE
						// Flush Back All Data
						DevExt->CachePool.WbFlushAll = TRUE;
						while (DevExt->CachePool.WbQueue.Used)	
						{
							KeSetEvent(&DevExt->CachePool.WbThreadStartEvent, IO_NO_INCREMENT, FALSE);
							KeWaitForSingleObject(&DevExt->CachePool.WbThreadFinishEvent,
													Executive, KernelMode, FALSE, NULL);
						}
						DevExt->CachePool.WbFlushAll = FALSE;
					#endif
						DevExt->ReadCount = 0;
						DevExt->WriteCount = 0;
						DevExt->CachePool.Size = 0;
						DevExt->CachePool.Used = 0;
						DevExt->CachePool.ReadHit = 0;
						DevExt->CachePool.WriteHit = 0;
						DestroyCachePool(&DevExt->CachePool);
					}
					else if (DevExt->bIsProtected == FALSE)
					{
						if (InitCachePool(&DevExt->CachePool
						#ifndef USE_DRAM
							,((ULONG32*)InputBuffer)[2] ,((ULONG32*)InputBuffer)[3]
						#endif
							) == TRUE
						#ifdef WRITE_BACK_ENABLE
							&& InitQueue(&DevExt->CachePool.WbQueue, (WB_QUEUE_SIZE << 20)/(BLOCK_SIZE)) == TRUE
						#endif
						)
							DevExt->bIsProtected = TRUE;
						else
						{
						#ifdef WRITE_BACK_ENABLE
							DestroyQueue(&DevExt->CachePool.WbQueue);
						#endif
							DestroyCachePool(&DevExt->CachePool);
							DevExt->bIsProtected = FALSE;
							KdPrint(("%s: %d-%d: Init Cache Pool Error\n", __FUNCTION__,
										DevExt->DiskNumber, DevExt->PartitionNumber));
							Status = STATUS_UNSUCCESSFUL;
						}
					}
					break;
				}
				DeviceObject = DeviceObject->NextDevice;
			}
			COMPLETE_IRP(Irp, Status);
			return Irp->IoStatus.Status;
		// Get or Clear Statistic
		case IOCTL_DF_GET_STAT:
		case IOCTL_DF_CLEAR_STAT:
			Type = (IOCTL_DF_GET_STAT == IrpSp->Parameters.DeviceIoControl.IoControlCode);
			DBG_PRINT(DBG_TRACE_OPS, ("%s: %s Statistic\n", __FUNCTION__, Type?"Get":"Clear"));
			DeviceObject = g_pDriverObject->DeviceObject;
			Status = STATUS_UNSUCCESSFUL;
			while (DeviceObject != NULL)
			{
				DevExt = (PDF_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
				if (DeviceObject != g_pDeviceObject &&
					DevExt->bIsStart == TRUE &&
					DevExt->DiskNumber == ((ULONG32*)InputBuffer)[0] &&
					DevExt->PartitionNumber == ((ULONG32*)InputBuffer)[1])
				{
					DBG_PRINT(DBG_TRACE_OPS, ("On disk(%u) partition(%u)\n", DevExt->DiskNumber, DevExt->PartitionNumber));
					if (Type && OutputLength >= 6 * sizeof(ULONG32))
					{
						((ULONG32*)OutputBuffer)[0] = DevExt->CachePool.ReadHit;
						((ULONG32*)OutputBuffer)[1] = DevExt->CachePool.WriteHit;
						((ULONG32*)OutputBuffer)[2] = DevExt->ReadCount;
						((ULONG32*)OutputBuffer)[3] = DevExt->WriteCount;
						((ULONG32*)OutputBuffer)[4] = DevExt->CachePool.Size;
						((ULONG32*)OutputBuffer)[5] = DevExt->CachePool.Used;
						Irp->IoStatus.Information = 6 * sizeof(ULONG32);
					}
					else
					{
						DevExt->CachePool.ReadHit = 0;
						DevExt->CachePool.WriteHit = 0;
						DevExt->ReadCount = 0;
						DevExt->WriteCount = 0;
						Irp->IoStatus.Information = 0;
					}
					Status = STATUS_SUCCESS;
					break;
				}
				DeviceObject = DeviceObject->NextDevice;
			}
			Irp->IoStatus.Status = Status;
			IoCompleteRequest(Irp, IO_NO_INCREMENT);
			return Irp->IoStatus.Status;
		// Setup Output
		case IOCTL_DF_QUIET:
			DBG_PRINT(DBG_TRACE_OPS, ("%s: Quite All Output\n", __FUNCTION__));
			g_TraceFlags = 0;
			COMPLETE_IRP(Irp, STATUS_SUCCESS);
			return Irp->IoStatus.Status;
		case IOCTL_DF_VERBOSE:
			g_TraceFlags = -1;
			DBG_PRINT(DBG_TRACE_OPS, ("%s: Verbose All Output\n", __FUNCTION__));
			COMPLETE_IRP(Irp, STATUS_SUCCESS);
			return Irp->IoStatus.Status;
		// Setup Data Verify
		case IOCTL_DF_VERIFY:
			g_bDataVerify = (g_bDataVerify==TRUE)?FALSE:TRUE;
			DBG_PRINT(DBG_TRACE_OPS, ("%s: %s Data Verify\n", __FUNCTION__, g_bDataVerify?"Start":"Stop"));
			COMPLETE_IRP(Irp, STATUS_SUCCESS);
			return Irp->IoStatus.Status;
		// Unknown Ioctl
		default:
			DBG_PRINT(DBG_TRACE_OPS, ("%s: Unknown User Ioctl\n", __FUNCTION__));
			COMPLETE_IRP(Irp, STATUS_UNSUCCESSFUL);
			return Irp->IoStatus.Status;
		}
	}
	else
	{
		switch (IrpSp->Parameters.DeviceIoControl.IoControlCode)
		{
		case IOCTL_VOLUME_ONLINE:
			DBG_PRINT(DBG_TRACE_OPS, ("%s: IOCTL_VOLUME_ONLINE\n", __FUNCTION__));
			if (IoForwardIrpSynchronously(DevExt->LowerDeviceObject, Irp))
			{
				StartDevice(DeviceObject);
			}
			IoCompleteRequest(Irp, IO_NO_INCREMENT);
			return Irp->IoStatus.Status;
		case IOCTL_VOLUME_OFFLINE:
			DBG_PRINT(DBG_TRACE_OPS, ("%s: IOCTL_VOLUME_OFFLINE\n", __FUNCTION__));
			// ... Flush back Cache
			break;
		case IOCTL_DISK_COPY_DATA:
			DBG_PRINT(DBG_TRACE_OPS, ("%s: IOCTL_DISK_COPY_DATA\n", __FUNCTION__));
			COMPLETE_IRP(Irp, STATUS_UNSUCCESSFUL);
			return Irp->IoStatus.Status;
		default:
			//DBG_PRINT(DBG_TRACE_OPS, ("%s: 0x%X\n", __FUNCTION__, IrpSp->Parameters.DeviceIoControl.IoControlCode));
			break;
		}
	}

	IoSkipCurrentIrpStackLocation(Irp);
	return IoCallDriver(DevExt->LowerDeviceObject, Irp);
}