예제 #1
0
BOOL CPCIDiskAndCD::SterilizeCdRomReadRequest(
    PCDROM_READ* ppSafe,
    LPDWORD      lpcbSafe,
    PCDROM_READ  pUnsafe,
    DWORD        cbUnsafe,
    DWORD        dwArgType,
    OUT PUCHAR * saveoldptrs
    )
{
    DWORD       i = 0, mappedbuffers;
    PCDROM_READ pSafe = NULL;
    DWORD       cbSafe = 0;
    PUCHAR      ptemp;

    // ppSafe, lpcSafeSgX, and pUnsafe are required.  However, *ppSafe may
    // be NULL.
    if ((NULL == ppSafe)|| (NULL == lpcbSafe) || (NULL == pUnsafe)) {
        return FALSE;
    }
    // Extract args so we don't have to continually dereference.
    pSafe = *ppSafe;
    cbSafe = *lpcbSafe;
    // Is unsafe request smaller than minimum?
    if (cbUnsafe < sizeof(CDROM_READ)) {
        return FALSE;
    }
    // Is unsafe request correctly sized?
    if (cbUnsafe < (sizeof(CDROM_READ) + (sizeof(SGX_BUF) * (pUnsafe->sgcount - 1)))) {
        return FALSE;
    }
    // Is unsafe request larger than safe request container?
    if (cbUnsafe > cbSafe) {
        // Deallocate safe request container, if applicable.
        if (NULL != pSafe) {
            LocalFree((HLOCAL)pSafe);
            pSafe = NULL;
        }
        // Reallocate safe request container.
        pSafe = (PCDROM_READ)LocalAlloc(LPTR, cbUnsafe);
        if (NULL == pSafe) {
            // Failed to reallocate safe request container.  Fail.
            *ppSafe = NULL;
            *lpcbSafe = 0;
            return FALSE;
        }
        // Update safe request container.
        *ppSafe = pSafe;
        *lpcbSafe = cbUnsafe;
        // Update extracted size arg.
        cbSafe = cbUnsafe;
    }
    // Safely copy unsafe request to safe request.
    if (0 == CeSafeCopyMemory((LPVOID)pSafe, (LPVOID)pUnsafe, cbUnsafe)) {
        return FALSE;
    }

    // Map unsafe embedded pointers to safe request.
    for (i = 0; i < pSafe->sgcount; i += 1) {

        if (
            (NULL == pSafe->sglist[i].sb_buf) ||
            (0 == pSafe->sglist[i].sb_len)
        ) {
            goto CleanUpLeak;
        }

        // Verify embedded pointer access and map user mode pointers

        if (FAILED(CeOpenCallerBuffer(
                    (PVOID *)&ptemp,
                    (LPVOID)pSafe->sglist[i].sb_buf,
                    pSafe->sglist[i].sb_len,
                    dwArgType,
                    FALSE)))
        {
            goto CleanUpLeak;
        }

        ASSERT(ptemp);
        saveoldptrs[i] = pSafe->sglist[i].sb_buf;
        pSafe->sglist[i].sb_buf = ptemp;
    }
    return TRUE;

CleanUpLeak:

    mappedbuffers = i;
    for (i = 0; i < mappedbuffers; i++) {

        ASSERT((NULL != pSafe->sglist[i].sb_buf) &&
               (0 == pSafe->sglist[i].sb_len));

        // Close previously mapped pointers

        if (FAILED(CeCloseCallerBuffer(
                    (LPVOID)pSafe->sglist[i].sb_buf,
                    (LPVOID)saveoldptrs[i],
                    pSafe->sglist[i].sb_len,
                    dwArgType)))
        {
            ASSERT(!"Cleanup call to CeCloseCallerBuffer failed unexpectedly");
            return FALSE;
        }
    }

    return FALSE;
}
예제 #2
0
EXTERN_C
BOOL
PIN_IOControl(
    DWORD  dwContext,
    DWORD  Ioctl,
    PUCHAR pInBufUnmapped,
    DWORD  InBufLen, 
    PUCHAR pOutBufUnmapped,
    DWORD  OutBufLen,
    PDWORD pdwBytesTransferred
   )
{
    DEBUGMSG(ZONE_FUNCTION, ( _T("PIN_IOControl(%08x): IOCTL:0x%x, InBuf:0x%x, InBufLen:%d, OutBuf:0x%x, OutBufLen:0x%x)\r\n"), dwContext, Ioctl, pInBufUnmapped, InBufLen, pOutBufUnmapped, OutBufLen ) );

    DWORD      dwErr      = ERROR_INVALID_PARAMETER;
    BOOL       bRc        = FALSE;
    PPINDEVICE pPinDevice = reinterpret_cast<PPINDEVICE>( dwContext );
    UCHAR * pInBuf = NULL;
    UCHAR * pOutBuf = NULL;

    pInBuf = pInBufUnmapped;    

    pOutBuf = pOutBufUnmapped;
       
    switch ( Ioctl )
    {
    case IOCTL_CS_PROPERTY:
        DEBUGMSG( ZONE_IOCTL, ( _T("PIN_IOControl(%08x): IOCTL_CS_PROPERTY\r\n"), dwContext ) );

        __try 
        {
            CSPROPERTY csProp = {0};

            if ( ( NULL == pInBuf )
                 || ( InBufLen < sizeof ( CSPROPERTY ) )
                 || ( NULL == pdwBytesTransferred ) )
            {
                break;
            }
            
            if( !CeSafeCopyMemory( &csProp, pInBuf, sizeof( CSPROPERTY )))
            {
                break;
            }
            
            dwErr = pPinDevice->PinHandleCustomRequests( pInBuf,InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred );
            if ( ERROR_NOT_SUPPORTED == dwErr )
            {
                if ( TRUE == IsEqualGUID( csProp.Set, CSPROPSETID_Connection ) )
                {   
                    dwErr = pPinDevice->PinHandleConnectionRequests( &csProp, pOutBuf, OutBufLen, pdwBytesTransferred );
                }
            }
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            DEBUGMSG( ZONE_IOCTL, ( _T("PIN_IOControl(%08x):Exception in IOCTL_CS_PROPERTY"), dwContext ) );
        }

        break;


    case IOCTL_CS_BUFFERS:
        DEBUGMSG( ZONE_IOCTL, ( _T("PIN_IOControl(%08x): IOCTL_CS_BUFFERS\r\n"), dwContext ) );

        __try
        {
            CSBUFFER_INFO  csBufferInfo;

            if( ( NULL == pInBuf ) ||
                ( InBufLen  < sizeof( CSBUFFER_INFO )) ||
                ( !CeSafeCopyMemory( &csBufferInfo, pInBuf, sizeof( csBufferInfo ))))
            {
                if( pdwBytesTransferred )
                {
                    *pdwBytesTransferred = 0;
                }

                DEBUGMSG( ZONE_IOCTL|ZONE_ERROR, ( _T("PIN_IOControl(%08x): IOCTL_CS_BUFFERS. Invalid parameters\r\n"), dwContext ) );
                break;
            }

            dwErr = pPinDevice->PinHandleBufferRequest( csBufferInfo, pOutBuf, OutBufLen, pdwBytesTransferred );
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            DEBUGMSG( ZONE_IOCTL, ( _T("PIN_IOControl(%08x):Exception in IOCTL_CS_BUFFERS"), dwContext ) );
        }

        break;


    case IOCTL_STREAM_INSTANTIATE:
        __try 
        {
            DEBUGMSG( ZONE_IOCTL, ( _T("PIN_IOControl(%08x): IOCTL_STREAM_INSTANTIATE\r\n"), dwContext ) );

            CSPROPERTY_STREAMEX_S csPropStreamEx = {0};
            
            if ( ( NULL == pInBuf )
                 || ( InBufLen < sizeof ( CSPROPERTY_STREAMEX_S ) )
                 || ( NULL == pdwBytesTransferred ) )
            {
                DEBUGMSG( ZONE_IOCTL|ZONE_ERROR, ( _T("PIN_IOControl(%08x): IOCTL_STREAM_INSTANTIATE. Insufficient buffer\r\n"), dwContext ) );
                break;
            }
            
            CeSafeCopyMemory( &csPropStreamEx, pInBuf, sizeof( CSPROPERTY_STREAMEX_S ));

            if ( TRUE == IsEqualGUID( csPropStreamEx.CsPin.Property.Set, CSPROPSETID_StreamEx ) )
            {
                switch ( csPropStreamEx.CsPin.Property.Id )
                {
                case CSPROPERTY_STREAMEX_INIT:
                    dwErr = pPinDevice->StreamInstantiate( &csPropStreamEx, pOutBuf, OutBufLen, pdwBytesTransferred );
                    break;

                default:
                    DEBUGMSG( ZONE_IOCTL|ZONE_ERROR, ( _T("PIN_IOControl(%08x): Invalid Request\r\n"), dwContext ) );
                    break;
                }
            }
            else
            {
                DEBUGMSG( ZONE_IOCTL, ( _T("PIN_IOControl(%08x): Unsupported PropertySet Request for IOCTL_STREAM_INSTANTIATE%u\r\n"), dwContext, csPropStreamEx.CsPin.Property.Set ) );
                dwErr = ERROR_NOT_SUPPORTED;
            }
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            DEBUGMSG( ZONE_IOCTL|ZONE_ERROR, ( _T("PIN_IOControl(%08x):Exception in IOCTL_STREAM_INSTANTIATE"), dwContext ) );
        }

        break;
    
    default:
        DEBUGMSG( ZONE_IOCTL|ZONE_ERROR, ( _T("PIN_IOControl(%08x): Unsupported IOCTL code %u\r\n"), dwContext, Ioctl ) );
        dwErr = ERROR_NOT_SUPPORTED;
        break;
    }

    // pass back appropriate response codes
    SetLastError(dwErr);
    return ( ( dwErr == ERROR_SUCCESS ) ? TRUE : FALSE );
}
예제 #3
0
/*----------------------------------------------------------------------------
*Function: CMM_IOControl

*Parameters:         OpenHandle        :
                    dwIoControlCode    :
*Return Value:        True/False
*Implementation Notes: JPEG_IOControl sends commands to initiate different
*                       operations like Init,Decode and Deinit.The test 
*                       application uses the DeviceIOControl function to 
*                       specify an operation to perform 
-----------------------------------------------------------------------------*/
BOOL
CMM_IOControl(
    DWORD OpenHandle,
    DWORD dwIoControlCode,
    PBYTE pInBuf,
    DWORD nInBufSize,
    PBYTE pOutBuf,
    DWORD nOutBufSize,
    PDWORD pBytesReturned
    )
{
    CODEC_MEM_CTX       *CodecMem;
    BOOL                result = TRUE;
    DWORD               ret;
    UINT8               *u_addr;
    ALLOC_MEM_T         *node;
    CMM_ALLOC_PRAM_T    allocParam;
    
    CodecMem = (CODEC_MEM_CTX *)OpenHandle;

    if(!CodecMem){
        RETAILMSG(1, (TEXT("[CMM_IOControl] CMM Invalid Input Handle\r\n")));
        return FALSE;
    }

    if ((pInBuf == NULL) || (nInBufSize == 0)){
        RETAILMSG(1, (TEXT("[CMM_IOControl] Invalid Input buffer or size\r\n")));
        return FALSE;
    }

    ret = LockCMMMutex();
    if(!ret){
        RETAILMSG(1, (TEXT("[CMM_IOControl] CMM Mutex Lock Fail\r\n")));
        return FALSE;
    }

    switch ( dwIoControlCode ) {

    case IOCTL_CODEC_MEM_ALLOC:
        
        printD("\n[%d][CMM_IOControl] IOCTL_CODEC_MEM_ALLOC\n", CodecMem->inst_no);
        if ((pInBuf == NULL) || 
            (nInBufSize < sizeof(CMM_ALLOC_PRAM_T)) ||
            (pOutBuf == NULL) ||
            (nOutBufSize < sizeof(UINT)))
        {
            RETAILMSG(1, (TEXT("[CMM_IOControl] IOCTL_CODEC_MEM_ALLOC Invalid parameters\r\n")));
            result = FALSE;
            break;
        }

        // Create a local copy of the input buffer first.
        if (!CeSafeCopyMemory(&allocParam, pInBuf, sizeof(CMM_ALLOC_PRAM_T)))// Copies memory inside a __try/__except block
        {
            result = FALSE;
            break;
        }  

        if((allocParam.size) & (0xFFF)) // For 4K alignment
        {
            allocParam.size = (allocParam.size & 0xFFFFF000) + 0x1000;    
        }
    
        printD("[IOCTL_CODEC_MEM_ALLOC] buffSize : %ld\n", allocParam.size);

        if((node = GetCodecVirAddr(CodecMem->inst_no, &allocParam)) == NULL){
            result = FALSE;
            break;
        }

        CodecMem->callerProcess = (HANDLE) GetDirectCallerProcessId();
        node->u_addr = (PBYTE)VirtualAllocEx(CodecMem->callerProcess, 
                                            NULL, 
                                            node->size, 
                                            MEM_RESERVE, 
                                            PAGE_NOACCESS);
        if (node->u_addr == NULL)
        {
            RETAILMSG(1, (_T("[CMM_IOControl]: Memory VirtualAlloc Fail.  Error = %d\r\n"), GetLastError()));
            result = FALSE;
        }
        else
        {
            if (!VirtualCopyEx(CodecMem->callerProcess,           
                                node->u_addr,
                                (HANDLE) GetCurrentProcessId(),
                                node->v_addr,    
                                node->size, 
                                allocParam.cacheFlag ? PAGE_READWRITE : (PAGE_READWRITE | PAGE_NOCACHE)))
            {
                RETAILMSG(1, (_T("[CMM_IOControl]: Memory VirtualCopyEx Fail. Error = %d\r\n"), GetLastError()));
                result = FALSE;
            }
        }

        __try
        {
            if (result)
            {
                *((UINT *)pOutBuf) = (UINT) node->u_addr;
            }
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            RETAILMSG( 1, ( _T("[CMM_IOControl]: exception in IOCTL_CODEC_MEM_ALLOC \r\n")) );
            result = FALSE;
        }

        if (!result)
        {
            // free alloc node
            ReleaseAllocMem(node, CodecMem);
        }        

        break;

    case IOCTL_CODEC_MEM_FREE:
        printD("\n[%d][CMM_IOControl] IOCTL_CODEC_MEM_FREE\n", CodecMem->inst_no);
        u_addr = (UINT8 *)pInBuf;
        printD("[CMM_IOControl] free adder : 0x%x \n", u_addr);

        for(node = AllocMemHead; node != AllocMemTail; node = node->next)
        {
            if(node->u_addr == u_addr)
                break;
        }

        if(node  == AllocMemTail)
        {
            RETAILMSG(1, (TEXT("[CMM_IOControl] invalid virtual address(0x%x)\r\n"), u_addr));
            result = FALSE;
            break;
        }
        // free alloc node
        ReleaseAllocMem(node, CodecMem);
        break;

    case IOCTL_CODEC_CACHE_INVALIDATE:
        printD("\n[CMM_IOControl] IOCTL_CODEC_CACHE_INVALIDATE\n");
        u_addr = (UINT8 *)pInBuf;
        printD("[CMM_IOControl] flush adder : 0x%x \n", u_addr);

        for(node = AllocMemHead; node != AllocMemTail; node = node->next)
        {
            if(node->u_addr == u_addr)
                break;
        }

        if(node  == AllocMemTail){
            RETAILMSG(1, (TEXT("[%d][CMM_IOControl] invalid virtual address(0x%x)\r\n"), CodecMem->inst_no, u_addr));
            result = FALSE;
            break;
        }

        InvalidateCacheRange((PBYTE) node->v_addr, 
            (PBYTE) node->v_addr + node->size);
        break;

    case IOCTL_CODEC_CACHE_CLEAN:
        printD("\n[CMM_IOControl] IOCTL_CODEC_CACHE_CLEAN\n");
        u_addr = (UINT8 *)pInBuf;
        printD("[CMM_IOControl] flush adder : 0x%x \n", u_addr);

        for(node = AllocMemHead; node != AllocMemTail; node = node->next)
        {
            if(node->u_addr == u_addr)
                break;
        }

        if(node  == AllocMemTail){
            RETAILMSG(1, (TEXT("[%d][CMM_IOControl] invalid virtual address(0x%x)\r\n"), CodecMem->inst_no, u_addr));
            result = FALSE;
            break;
        }

        CleanCacheRange((PBYTE) node->v_addr, 
            (PBYTE) node->v_addr + node->size);
        break;


        // IOCTL_CODEC_CACHE_FLUSH is same as IOCTL_CODEC_CACHE_CLEAN_INVALIDATE.
        // This is remained for backward capability
    case IOCTL_CODEC_CACHE_FLUSH: 
    case IOCTL_CODEC_CACHE_CLEAN_INVALIDATE:
        printD("\n[CMM_IOControl] IOCTL_CODEC_CACHE_CLEAN_INVALIDATE\n");
        u_addr = (UINT8 *)pInBuf;
        printD("[CMM_IOControl] flush adder : 0x%x \n", u_addr);

        for(node = AllocMemHead; node != AllocMemTail; node = node->next)
        {
            if(node->u_addr == u_addr)
                break;
        }

        if(node  == AllocMemTail){
            RETAILMSG(1, (TEXT("[%d][CMM_IOControl] invalid virtual address(0x%x)\r\n"), CodecMem->inst_no, u_addr));
            result = FALSE;
            break;
        }

        CleanInvalidateCacheRange((PBYTE) node->v_addr, 
            (PBYTE) node->v_addr + node->size);
        break;


    case IOCTL_CODEC_GET_PHY_ADDR:
        u_addr  = (UINT8 *)pInBuf;
        for(node = AllocMemHead; node != AllocMemTail; node = node->next)
        {
            if(node->u_addr == u_addr)
                break;
        }

        if(node  == AllocMemTail){
            RETAILMSG(1, (TEXT("[CMM_IOControl] invalid virtual address(0x%x)\r\n"), u_addr));
            result = FALSE;
            break;
        }
        
        if ((pOutBuf == NULL) || (nOutBufSize < sizeof(UINT8 *)))
        {
            RETAILMSG(1, (TEXT("[CMM_IOControl] IOCTL_CODEC_GET_PHY_ADDR Invalid Output buffer or size\r\n")));
            result = FALSE;
            break;
        }

        __try
        {
            *((UINT *)pOutBuf) = (UINT) node->cached_p_addr;
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            RETAILMSG( 1, ( _T("[CMM_IOControl]: exception in IOCTL_CODEC_GET_PHY_ADDR \r\n")) );
            result = FALSE;
        }

        break;


    default : RETAILMSG(1, (TEXT("[CMM_IOControl] CMM Invalid IOControl\r\n")));
    }


    UnlockCMMMutex();
    return result;
}
예제 #4
0
///////////////////////////////////////////////////////////////////////////////
//  SMC_IOControl - the I/O control entry point for the memory driver
//  Input:  Handle - the context returned from SMC_Open
//          IoctlCode - the ioctl code
//          pInBuf - the input buffer from the user
//          InBufSize - the length of the input buffer
//          pOutBuf - the output buffer from the user
//          InBufSize - the length of the output buffer
//          pBytesReturned - the size of the transfer
//  Output:
//  Return:  TRUE if ioctl was handled
//  Notes:
///////////////////////////////////////////////////////////////////////////////
extern "C" BOOL WINAPI SMC_IOControl(
    DWORD   Handle,
    DWORD   IoctlCode,
    PBYTE   pInBuf,
    DWORD   InBufSize,
    PBYTE   pOutBuf,
    DWORD   OutBufSize,
    PDWORD  pBytesReturned
)
{
    DWORD            Status = ERROR_SUCCESS;             // win32 status
    PSD_MEMCARD_INFO pHandle = (PSD_MEMCARD_INFO)Handle; // memcard info
    PSG_REQ          pSG;                                // scatter gather buffer
    SD_API_STATUS    sdStatus;                           // SD API status
    DWORD            SafeBytesReturned = 0;              // safe copy of pBytesReturned
    DWORD             dwStartTicks = 0;

    DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDMemory: +SMC_IOControl\r\n")));

    // any of these IOCTLs can access the device instance or card handle so we
    // must protect it from being freed from XXX_Deinit; Windows CE does not
    // synchronize the  callback from Deinit
    AcquireRemovalLock(pHandle);

    if (pHandle->fPreDeinitCalled) {
        Status = ERROR_INVALID_HANDLE;
        goto ErrorStatusReturn;
    }

    sdStatus = RequestPrologue(pHandle, IoctlCode);

    if (!SD_API_SUCCESS(sdStatus)) {
        ReleaseRemovalLock(pHandle);
        SetLastError(SDAPIStatusToErrorCode(sdStatus));
        return FALSE;
    }

    DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("SMC_IOControl: Recevied IOCTL %d ="), IoctlCode));
    switch(IoctlCode) {
    case IOCTL_DISK_READ:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_READ\r\n")));
        break;
    case DISK_IOCTL_READ:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("DISK_IOCTL_READ\r\n")));
        break;
    case IOCTL_DISK_WRITE:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_WRITE\r\n")));
        break;
    case DISK_IOCTL_WRITE:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("DISK_IOCTL_WRITE\r\n")));
        break;
    case IOCTL_DISK_GETINFO:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_GETINFO\r\n")));
        break;
    case DISK_IOCTL_GETINFO:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("DISK_IOCTL_GETINFO\r\n")));
        break;
    case IOCTL_DISK_SETINFO:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_SETINFO\r\n")));
        break;
    case DISK_IOCTL_INITIALIZED:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("DISK_IOCTL_INITIALIZED\r\n")));
        break;
    case IOCTL_DISK_INITIALIZED:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_INITIALIZED\r\n")));
        break;
    case IOCTL_DISK_GETNAME:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_GETNAME\r\n")));
        break;
    case DISK_IOCTL_GETNAME:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("DISK_IOCTL_GETNAME\r\n")));
        break;
    case IOCTL_DISK_GET_STORAGEID:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_GET_STORAGEID\r\n")));
        break;
    case IOCTL_DISK_FORMAT_MEDIA:
    case DISK_IOCTL_FORMAT_MEDIA:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_FORMAT_MEDIA\r\n")));
        break;
    case IOCTL_DISK_DEVICE_INFO:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_DEVICE_INFO\r\n")));
        break;
    case IOCTL_DISK_DELETE_SECTORS:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("IOCTL_DISK_DELETE_SECTORS\r\n")));
        break;
    default:
        DEBUGMSG(SDCARD_ZONE_INFO, (TEXT("**UNKNOWN**\r\n")));
        break;
    }

    // validate parameters
    switch(IoctlCode) {

    case IOCTL_DISK_READ:
    case DISK_IOCTL_READ:
    case IOCTL_DISK_WRITE:
    case DISK_IOCTL_WRITE:
        if (pInBuf == NULL || InBufSize < sizeof(SG_REQ) || InBufSize > (sizeof(SG_REQ) + ((MAX_SG_BUF - 1) * sizeof(SG_BUF)))) {
            Status = ERROR_INVALID_PARAMETER;
        }
        break;

    case DISK_IOCTL_GETINFO:
    case IOCTL_DISK_SETINFO:
        if (NULL == pInBuf || InBufSize != sizeof(DISK_INFO)) {
            Status = ERROR_INVALID_PARAMETER;
        }
        break;

    case IOCTL_DISK_DELETE_SECTORS:
        if (pInBuf == NULL || InBufSize != sizeof(DELETE_SECTOR_INFO)) {
            Status = ERROR_INVALID_PARAMETER;
        }
        break;

    case IOCTL_DISK_GETINFO:
        if (pOutBuf == NULL || OutBufSize != sizeof(DISK_INFO)) {
            Status = ERROR_INVALID_PARAMETER;
        }
        break;

    case IOCTL_DISK_GET_STORAGEID:
        // the identification data is stored after the struct, so the out
        // buffer must be at least the size of the struct.
        if (pOutBuf == NULL || OutBufSize < sizeof(STORAGE_IDENTIFICATION)) {
            Status = ERROR_INVALID_PARAMETER;
        }
        break;

    case IOCTL_DISK_FORMAT_MEDIA:
    case DISK_IOCTL_FORMAT_MEDIA:
        break;

    case IOCTL_DISK_DEVICE_INFO:
        if (NULL == pInBuf || (InBufSize != sizeof(STORAGEDEVICEINFO))) {
            Status = ERROR_INVALID_PARAMETER;
        }
        break;

    case IOCTL_POWER_CAPABILITIES:
        if (!pOutBuf || OutBufSize < sizeof(POWER_CAPABILITIES) || !pBytesReturned) {
            Status = ERROR_INVALID_PARAMETER;
        }
        break;

    case IOCTL_POWER_SET:
        if (!pOutBuf || OutBufSize < sizeof(CEDEVICE_POWER_STATE) || !pBytesReturned) {
            Status = ERROR_INVALID_PARAMETER;
        }
        break;

    default:
        Status = ERROR_INVALID_PARAMETER;
    }

    if (Status != ERROR_SUCCESS) {
        goto ErrorStatusReturn;
    }

    // execute the IOCTL
    switch(IoctlCode) {

    case IOCTL_DISK_READ:
    case DISK_IOCTL_READ:
        pSG = (PSG_REQ)pInBuf;
        if (0 == CeSafeCopyMemory((LPVOID)pHandle->pSterileIoRequest, (LPVOID)pSG, InBufSize)) {
            Status = ERROR_INVALID_PARAMETER;
            break;
        }
        Status = SDMemRead(pHandle, pHandle->pSterileIoRequest);
        __try {
            pSG->sr_status = Status;
            if (pBytesReturned && (ERROR_SUCCESS == Status)) {
                *pBytesReturned = (pHandle->pSterileIoRequest->sr_num_sec * SD_BLOCK_SIZE);
            }
        }
        __except(EXCEPTION_EXECUTE_HANDLER) {
            Status = ERROR_INVALID_PARAMETER;
        }
        break;

    case IOCTL_DISK_WRITE:
    case DISK_IOCTL_WRITE:
        pSG = (PSG_REQ)pInBuf;
        if (0 == CeSafeCopyMemory((LPVOID)pHandle->pSterileIoRequest, (LPVOID)pSG, InBufSize)) {
            Status = ERROR_INVALID_PARAMETER;
            break;
        }
        Status = SDMemWrite(pHandle, pHandle->pSterileIoRequest);
        __try {
            pSG->sr_status = Status;
            if (pBytesReturned && (ERROR_SUCCESS == Status)) {
                *pBytesReturned = (pHandle->pSterileIoRequest->sr_num_sec * SD_BLOCK_SIZE);
            }
        }
        __except(EXCEPTION_EXECUTE_HANDLER) {
            Status = ERROR_INVALID_PARAMETER;
        }
        break;

    case IOCTL_DISK_GETINFO:
    {
        DISK_INFO SafeDiskInfo = {0};
        SafeBytesReturned = sizeof(DISK_INFO);
        Status = GetDiskInfo(pHandle, &SafeDiskInfo);
        if (0 == CeSafeCopyMemory((LPVOID)pOutBuf, (LPVOID)&SafeDiskInfo, sizeof(DISK_INFO))) {
            Status = ERROR_INVALID_PARAMETER;
            break;
        }
        if (pBytesReturned) {
            if (0 == CeSafeCopyMemory((LPVOID)pBytesReturned, (LPVOID)&SafeBytesReturned, sizeof(DWORD))) {
                Status = ERROR_INVALID_PARAMETER;
                break;
            }
        }
    }
    break;

    case DISK_IOCTL_GETINFO:
    {
        DISK_INFO SafeDiskInfo = {0};
        SafeBytesReturned = sizeof(DISK_INFO);
        Status = GetDiskInfo(pHandle, &SafeDiskInfo);
        if (0 == CeSafeCopyMemory((LPVOID)pInBuf, (LPVOID)&SafeDiskInfo, sizeof(DISK_INFO))) {
            Status = ERROR_INVALID_PARAMETER;
            break;
        }
        if (pBytesReturned) {
            if (0 == CeSafeCopyMemory((LPVOID)pBytesReturned, (LPVOID)&SafeBytesReturned, sizeof(DWORD))) {
                Status = ERROR_INVALID_PARAMETER;
                break;
            }
        }
    }
    break;

    case IOCTL_DISK_SETINFO:
    {
        DISK_INFO SafeDiskInfo = {0};
        if (0 == CeSafeCopyMemory((LPVOID)&SafeDiskInfo, (LPVOID)pInBuf, sizeof(DISK_INFO))) {
            Status = ERROR_INVALID_PARAMETER;
            break;
        }
        Status = SetDiskInfo(pHandle, &SafeDiskInfo);
    }
    break;

    case IOCTL_DISK_FORMAT_MEDIA:
    case DISK_IOCTL_FORMAT_MEDIA:
        Status = ERROR_SUCCESS;
        break;

    case IOCTL_DISK_GET_STORAGEID:
    {
        __try {
            Status = GetStorageID(
                         pHandle,
                         (PSTORAGE_IDENTIFICATION)pOutBuf,
                         OutBufSize,
                         pBytesReturned);
        }
        __except(EXCEPTION_EXECUTE_HANDLER) {
            Status = ERROR_INVALID_PARAMETER;
        }
    }
    break;

    case IOCTL_DISK_DEVICE_INFO:
    {
        STORAGEDEVICEINFO SafeStorageDeviceInfo = {0};
        SafeBytesReturned = sizeof(STORAGEDEVICEINFO);
        if (!GetDeviceInfo(pHandle, &SafeStorageDeviceInfo)) {
            Status = ERROR_GEN_FAILURE;
            break;
        }
        if (0 == CeSafeCopyMemory((LPVOID)pInBuf, (LPVOID)&SafeStorageDeviceInfo, sizeof(STORAGEDEVICEINFO))) {
            Status = ERROR_INVALID_PARAMETER;
            break;
        }
        Status = ERROR_SUCCESS;
        if (pBytesReturned) {
            if (0 == CeSafeCopyMemory((LPVOID)pBytesReturned, (LPVOID)&SafeBytesReturned, sizeof(DWORD))) {
                Status = ERROR_INVALID_PARAMETER;
            }
        }
    }
    break;

    case IOCTL_DISK_DELETE_SECTORS:
    {
        DELETE_SECTOR_INFO SafeDeleteSectorInfo = {0};
        if (0 == CeSafeCopyMemory((LPVOID)&SafeDeleteSectorInfo, (LPVOID)pInBuf, sizeof(DELETE_SECTOR_INFO))) {
            Status = ERROR_INVALID_PARAMETER;
            break;
        }
        Status = SDMemErase(pHandle, &SafeDeleteSectorInfo);
    }
    break;

    case IOCTL_POWER_CAPABILITIES:
    {
        POWER_CAPABILITIES SafePowerCapabilities = {0};
        SafeBytesReturned = sizeof(POWER_CAPABILITIES);

        // support D0 + PowerStateForIdle (D2, by default)
        SafePowerCapabilities.DeviceDx = DX_MASK(D0) | DX_MASK(pHandle->PowerStateForIdle);

        SafePowerCapabilities.Power[D0] = PwrDeviceUnspecified;
        SafePowerCapabilities.Power[D1] = PwrDeviceUnspecified;
        SafePowerCapabilities.Power[D2] = PwrDeviceUnspecified;
        SafePowerCapabilities.Power[D3] = PwrDeviceUnspecified;
        SafePowerCapabilities.Power[D4] = PwrDeviceUnspecified;

        SafePowerCapabilities.Latency[D0] = 0;
        SafePowerCapabilities.Latency[D1] = 0;
        SafePowerCapabilities.Latency[D2] = 0;
        SafePowerCapabilities.Latency[D3] = 0;
        SafePowerCapabilities.Latency[D4] = 1000;

        // no device wake
        SafePowerCapabilities.WakeFromDx = 0;
        // no inrush
        SafePowerCapabilities.InrushDx = 0;

        if (0 == CeSafeCopyMemory((LPVOID)pOutBuf, (LPVOID)&SafePowerCapabilities, sizeof(POWER_CAPABILITIES))) {
            Status = ERROR_INVALID_PARAMETER;
            break;
        }
        Status = ERROR_SUCCESS;
        if (pBytesReturned) {
            if (0 == CeSafeCopyMemory((LPVOID)pBytesReturned, (LPVOID)&SafeBytesReturned, sizeof(DWORD))) {
                Status = ERROR_INVALID_PARAMETER;
            }
        }
    }
    break;

    case IOCTL_POWER_SET:
    {
        // pOutBuf is a pointer to CEDEVICE_POWER_STATE; this is the device
        // state incd .. which to put the device; if the driver does not support
        // the requested power state, then we return the adjusted power
        // state
        CEDEVICE_POWER_STATE SafeCeDevicePowerState;
        SafeBytesReturned = sizeof(CEDEVICE_POWER_STATE);
        if (0 == CeSafeCopyMemory((LPVOID)&SafeCeDevicePowerState, (LPVOID)pOutBuf, sizeof(CEDEVICE_POWER_STATE))) {
            Status = ERROR_INVALID_PARAMETER;
            break;
        }
        Status = ERROR_SUCCESS;
        HandleIoctlPowerSet(pHandle, &SafeCeDevicePowerState);
        // return the adjusted power state
        if (0 == CeSafeCopyMemory((LPVOID)pOutBuf, (LPVOID)&SafeCeDevicePowerState, sizeof(CEDEVICE_POWER_STATE))) {
            Status = ERROR_INVALID_PARAMETER;
            break;
        }
        if (pBytesReturned) {
            if (0 == CeSafeCopyMemory((LPVOID)pBytesReturned, (LPVOID)&SafeBytesReturned, sizeof(DWORD))) {
                Status = ERROR_INVALID_PARAMETER;
            }
        }
    }
    break;

    default:
        Status = ERROR_INVALID_PARAMETER;
        break;
    }

    RequestEnd(pHandle);

ErrorStatusReturn:

    ReleaseRemovalLock(pHandle);

    DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDMemory: -SMC_IOControl returning %d\n"),Status == ERROR_SUCCESS));

    if (Status != ERROR_SUCCESS) {
        SetLastError(Status);
    }

    return (ERROR_SUCCESS == Status);
}
예제 #5
0
///////////////////////////////////////////////////////////////////////////////
//  SDMemWrite       - Write data to card from pSG scatter gather buffers
//  Input:  pMemCard - SD memory card structure
//          pSG      - Scatter Gather buffer structure from FATFS
//  Output:
//  Return: Status   - windows status code
//  Notes:  Writes to the card are split into groups of size TransferBlockSize
//          This is controlled by a registry entry for the driver.
///////////////////////////////////////////////////////////////////////////////
DWORD SDMemWrite( PSD_MEMCARD_INFO pMemCard, PSG_REQ pSG )
{
    DWORD  NumBlocks;
    DWORD  StartBlock;
    PUCHAR pBlockBuffer = NULL, pCardDataPtr = NULL;
    PUCHAR pSGBuffer = NULL;
    DWORD  status = ERROR_SUCCESS;
    DWORD  SGBufNum, SGBufLen, SGBufRemaining;
    DWORD  PartialStartBlock;
    DWORD  CardDataRemaining;

    DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDMemory: +SDMemWrite\r\n")));

    PREFAST_DEBUGCHK(pSG);

    // pSG is a sterile SG_REQ copy of the callers's SG_REQ; we can map the
    // embedded pointers back into it

    // validate the embedded sb_bufs
    for (ULONG ul = 0; ul < pSG->sr_num_sg; ul += 1) {
        if (
            (NULL == pSG->sr_sglist[ul].sb_buf) ||
            (0 == pSG->sr_sglist[ul].sb_buf)
        ) {
            status = ERROR_INVALID_PARAMETER;
            goto statusReturn;
        }
        pSG->sr_sglist[ul].sb_buf = (PUCHAR)MapCallerPtr(
            (LPVOID)pSG->sr_sglist[ul].sb_buf,
            pSG->sr_sglist[ul].sb_len);
        if (pSG->sr_sglist[ul].sb_buf == NULL) {
            status = ERROR_INVALID_PARAMETER;
            goto statusReturn;
        }
    }

    // validate the I/O request
    if ((pSG->sr_start > pSG->sr_start + pSG->sr_num_sec) 
        ||(pSG->sr_start + pSG->sr_num_sec) > pMemCard->DiskInfo.di_total_sectors) {
        status = ERROR_INVALID_PARAMETER;
        goto statusReturn;
    }

    // check card write protect status
    if (pMemCard->WriteProtected) {
        DEBUGMSG(SDMEM_ZONE_DISK_IO, (TEXT("SDMemWrite: Card is write protected\r\n")));
        status = ERROR_WRITE_PROTECT;
        goto statusReturn;
    }

    // get number of sectors
    StartBlock = pSG->sr_start;
    NumBlocks = pSG->sr_num_sec;

    DEBUGMSG(SDMEM_ZONE_DISK_IO, (TEXT("SDMemWrite: Writing blocks %d-%d\r\n"),
        StartBlock,
        StartBlock+NumBlocks-1));

    // calculate total buffer space of scatter gather buffers
    SGBufLen = 0;
    for (SGBufNum = 0; SGBufNum < pSG->sr_num_sg; SGBufNum++) {
        SGBufLen += pSG->sr_sglist[SGBufNum].sb_len;
    }

    // check total SG buffer space is enough for reqeusted transfer size
    if(SGBufLen < NumBlocks * SD_BLOCK_SIZE) {
        DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDMemWrite: SG Buffer space %d bytes less than block write size %d bytes\r\n"),
            SGBufLen,
            NumBlocks * SD_BLOCK_SIZE));
        status = ERROR_GEN_FAILURE;
        goto statusReturn;
    }

    // get block transfer buffer
    pBlockBuffer = (PUCHAR)SDAllocateFromMemList(pMemCard->hBufferList);

    // initialize some variables used in data copy
    SGBufNum = 0;
    SGBufRemaining = pSG->sr_sglist[SGBufNum].sb_len;
    pSGBuffer = pSG->sr_sglist[SGBufNum].sb_buf;

    // split the writes into groups of TransferBlockSize in size to avoid
    // hogging the SD Bus with large writes
    for(PartialStartBlock = StartBlock; PartialStartBlock < StartBlock+NumBlocks; PartialStartBlock += pMemCard->BlockTransferSize) {

        // some variables just used for copying
        DWORD PartialTransferSize;
        DWORD CopySize;

        pCardDataPtr = pBlockBuffer;

        PartialTransferSize = MIN(
            pMemCard->BlockTransferSize,
            StartBlock+NumBlocks-PartialStartBlock);

        // copy from pSG buffers to pBlockArray
        CardDataRemaining = PartialTransferSize*SD_BLOCK_SIZE;

        while (CardDataRemaining) {

            // get minimum of remaining size in SG buf and data left in pBlockBuffer
            CopySize = MIN(SGBufRemaining, CardDataRemaining);

            // copy that much data to block buffer
            if (0 == CeSafeCopyMemory(pCardDataPtr, pSGBuffer, CopySize)) {
                status = ERROR_INVALID_PARAMETER;
                goto statusReturn;
            }

            // update pointers and counts
            pSGBuffer += CopySize;
            pCardDataPtr += CopySize;
            CardDataRemaining -= CopySize;
            SGBufRemaining -= CopySize;

            // get the next SG Buffer if needed
            if (!SGBufRemaining && CardDataRemaining) {
                SGBufNum++;
                SGBufRemaining = pSG->sr_sglist[SGBufNum].sb_len;
                pSGBuffer = pSG->sr_sglist[SGBufNum].sb_buf;
            }
        }

        // write the data to the SD Card
        status = SDMemWriteMultiple(
            pMemCard,
            PartialStartBlock,
            PartialTransferSize,
            pBlockBuffer);

        if (status != ERROR_SUCCESS) {
            break;
        }
    }
statusReturn:

    // free the allocated block buffer
    if (pBlockBuffer) {
        SDFreeToMemList(pMemCard->hBufferList, pBlockBuffer);
    }

    // FATFS wants the status returned in the SG buffers also
    pSG->sr_status = status;

    DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDMemory: -SDMemWrite\r\n")));

    return status;
}
예제 #6
0
//------------------------------------------------------------------------------
// process_PowerManagementMessage, all messages not handled by the other message
//  handlers
//
BOOL
CAudioManager::process_PowerManagementMessage(
    DWORD dwCode,
    PBYTE pBufIn,
    DWORD dwLenIn,
    PBYTE pBufOut,
    DWORD dwLenOut,
    PDWORD pdwActualOut
)
{
    UNREFERENCED_PARAMETER(dwLenIn);
    UNREFERENCED_PARAMETER(pBufIn);

    DEBUGMSG(ZONE_FUNCTION,
             (L"WAV:+process_PowerManagementMessage(dwCode=%d)\r\n", dwCode)
            );

    BOOL bResult = FALSE;
    POWER_CAPABILITIES powerCaps;
    CEDEVICE_POWER_STATE dxState;
    switch (dwCode)
    {
    // Return device specific power capabilities.
    case IOCTL_POWER_CAPABILITIES:
        DEBUGMSG(ZONE_PM, (L"WAV:IOCTL_POWER_CAPABILITIES\r\n"));

        // Check arguments.
        //
        if ( pBufOut == NULL || dwLenOut < sizeof(POWER_CAPABILITIES))
        {
            RETAILMSG(ZONE_WARN, (L"WAV: Invalid parameter.\r\n"));
            break;
        }

        // Clear capabilities structure.
        //
        memset(&powerCaps, 0, sizeof(POWER_CAPABILITIES));

        // Set power capabilities. Supports D0 and D4.
        //
        powerCaps.DeviceDx = DX_MASK(D0)|DX_MASK(D4);

        DEBUGMSG(ZONE_PM,
                 (L"WAV:IOCTL_POWER_CAPABILITIES = 0x%x\r\n", powerCaps.DeviceDx)
                );

        if (CeSafeCopyMemory(pBufOut, &powerCaps,
                             sizeof(POWER_CAPABILITIES))
           )
        {
            bResult = TRUE;
            if (pdwActualOut)
            {
                *pdwActualOut = sizeof(POWER_CAPABILITIES);
            }
        }
        break;

    // Indicate if the device is ready to enter a new device power state.
    case IOCTL_POWER_QUERY:
        DEBUGMSG(ZONE_PM,
                 (L"WAV:IOCTL_POWER_QUERY = %d\r\n", m_CurPowerState));

        // Check arguments.
        //
        if (pBufOut == NULL || dwLenOut < sizeof(CEDEVICE_POWER_STATE))
        {
            RETAILMSG(ZONE_WARN, (L"WAV: Invalid parameter.\r\n"));
            break;
        }

        if (CeSafeCopyMemory(pBufOut, &m_CurPowerState, sizeof(CEDEVICE_POWER_STATE)) == 0)
        {
            break;
        }

        if (!VALID_DX(m_CurPowerState))
        {
            RETAILMSG(ZONE_ERROR,
                      (L"WAV:IOCTL_POWER_QUERY invalid power state.\r\n"));
            break;
        }

        if (pdwActualOut)
        {
            *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
        }

        bResult = TRUE;
        break;

    // Request a change from one device power state to another.
    //
    case IOCTL_POWER_SET:

        DEBUGMSG(ZONE_PM, (L"WAV:IOCTL_POWER_QUERY\r\n"));

        // Check arguments.
        if (pBufOut == NULL || dwLenOut < sizeof(CEDEVICE_POWER_STATE))
        {
            RETAILMSG(ZONE_ERROR, (L"WAVE: Invalid parameter.\r\n"));
            break;
        }

        if (CeSafeCopyMemory(&dxState, pBufOut, sizeof(dxState)) == 0)
        {
            break;
        }

        DEBUGMSG(ZONE_PM, (L"WAV:IOCTL_POWER_SET = %d.\r\n", dxState));
        RETAILMSG(!VALID_DX(dxState),
                  (L"WAV:!ERROR - Setting to invalid power state(%d)", dxState)
                 );

        if (dxState == D4)
        {
            m_bSuspend = TRUE;
        }

        if (D0==dxState)
        {
            m_bSuspend = FALSE;
        }

        // Check for any valid power state.
        if (VALID_DX(dxState))
        {
            m_CurPowerState = dxState;
            get_HardwareAudioBridge()->request_PowerState(dxState);
            bResult = TRUE;
        }
        break;

    // Return the current device power state.
    case IOCTL_POWER_GET:
        DEBUGMSG(ZONE_PM, (L"WAV:IOCTL_POWER_GET\r\n"));

        dxState = get_HardwareAudioBridge()->get_CurrentPowerState();

        // Check input parameters
        if (pdwActualOut != NULL)
        {
            *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
        }

        if (pBufOut == NULL || dwLenOut < sizeof(dxState) ||
                !CeSafeCopyMemory(pBufOut, &dxState, sizeof(dxState)))
        {
            SetLastError(ERROR_INVALID_PARAMETER);
            break;
        }

        DEBUGMSG(ZONE_PM,
                 (L"WAV:IOCTL_POWER_GET=%d (%d).\r\n",
                  dxState, m_CurPowerState));

        bResult = TRUE;
    }

    DEBUGMSG(ZONE_FUNCTION,
             (L"WAV:-process_PowerManagementMessage(bResult=%d)\r\n", bResult)
            );
    return bResult;
}
예제 #7
0
//------------------------------------------------------------------------------
//
//  Function:  ADC_IOControl
//
//  This function sends a command to a device.
//
BOOL
ADC_IOControl(
    DWORD context, DWORD code, 
    UCHAR *pInBuffer, DWORD inSize, 
    UCHAR *pOutBuffer, DWORD outSize, 
    DWORD *pOutSize
    )
{
    BOOL rc = FALSE;
    DEVICE_IFC_MADC ifc;
    IOCTL_MADC_CONVERTTOVOLTS_IN *pConvertToVolts;
    Device_t *pDevice = (Device_t*)context;

    DEBUGMSG(ZONE_FUNCTION, (
        L"+ADC_IOControl(0x%08x, 0x%08x, 0x%08x, %d, 0x%08x, %d, 0x%08x)\r\n",
        context, code, pInBuffer, inSize, pOutBuffer, outSize, pOutSize
        ));

    // Check if we get correct context
    if ((pDevice == NULL) || (pDevice->cookie != MADC_DEVICE_COOKIE))
        {
        DEBUGMSG(ZONE_ERROR, (L"ERROR: ADC_IOControl: "
            L"Incorrect context parameter\r\n"
            ));
        goto cleanUp;
        }

    switch (code)
        {
        case IOCTL_DDK_GET_DRIVER_IFC:
            // We can give interface only to our peer in device process
            if (GetCurrentProcessId() != (DWORD)GetCallerProcess())
                {
                DEBUGMSG(ZONE_ERROR, (L"ERROR: ADC_IOControl: "
                    L"IOCTL_DDK_GET_DRIVER_IFC can be called only from "
                    L"device process (caller process id 0x%08x)\r\n",
                    GetCallerProcess()
                    ));
                SetLastError(ERROR_ACCESS_DENIED);
                break;
                }
            // Check input parameters
            if ((pInBuffer == NULL) || (inSize < sizeof(GUID)))
                {
                SetLastError(ERROR_INVALID_PARAMETER);
                break;
                }
            if (IsEqualGUID(*(GUID*)pInBuffer, DEVICE_IFC_MADC_GUID))
                {
                if (pOutSize != NULL) *pOutSize = sizeof(DEVICE_IFC_MADC);
                if (pOutBuffer == NULL || outSize < sizeof(DEVICE_IFC_MADC))
                    {
                    SetLastError(ERROR_INVALID_PARAMETER);
                    break;
                    }
                ifc.context = context;
                ifc.pfnReadValue = ReadValue;
                ifc.pfnConvertToVolts = ConvertToVolts;
                if (!CeSafeCopyMemory(pOutBuffer, &ifc, sizeof(DEVICE_IFC_MADC)))
                    {
                    SetLastError(ERROR_INVALID_PARAMETER);
                    break;
                    }
                rc = TRUE;
                break;
                }
            SetLastError(ERROR_INVALID_PARAMETER);
            break;

        case IOCTL_MADC_READVALUE:
            if (pInBuffer == NULL || pOutBuffer == NULL || 
                inSize != sizeof(DWORD) || outSize < sizeof(DWORD))
                {
                DEBUGMSG(ZONE_ERROR, (L"ERROR: ADC_IOControl: "
                    L"Invalid parameters for IOCTL_MADC_READVOLTS\r\n"
                    ));
                SetLastError(ERROR_INVALID_PARAMETER);
                break;
                }

            *pOutSize = ReadValue(context, *(DWORD*)pInBuffer, (DWORD*)pOutBuffer, 
                            outSize/sizeof(DWORD));

            if (*pOutSize == 0 && *(DWORD*)pInBuffer)
                {
                DEBUGMSG(ZONE_ERROR, (L"ERROR: ADC_IOControl: "
                    L"Failed to retrieve voltage readings\r\n"
                    ));
                break;
                }
            *pOutSize *= sizeof(DWORD);
            rc = TRUE;
            break;

        case IOCTL_MADC_CONVERTTOVOLTS:
            if (pInBuffer == NULL || pOutBuffer == NULL || 
                inSize != sizeof(IOCTL_MADC_CONVERTTOVOLTS_IN))
                {
                DEBUGMSG(ZONE_ERROR, (L"ERROR: ADC_IOControl: "
                    L"Invalid parameters for IOCTL_MADC_CONVERTTOVOLTS\r\n"
                    ));
                SetLastError(ERROR_INVALID_PARAMETER);
                break;
                }

            pConvertToVolts = (IOCTL_MADC_CONVERTTOVOLTS_IN*)pInBuffer;

            if (pConvertToVolts->count * sizeof(DWORD) != outSize)
                {
                DEBUGMSG(ZONE_ERROR, (L"ERROR: ADC_IOControl: "
                    L"Invalid parameters for IOCTL_MADC_CONVERTTOVOLTS\r\n"
                    ));
                SetLastError(ERROR_INVALID_PARAMETER);
                break;
                }

            *pOutSize = ConvertToVolts(context, pConvertToVolts->mask,
                            pConvertToVolts->pdwValues, (DWORD*)pOutBuffer, 
                            pConvertToVolts->count);
            *pOutSize *= sizeof(DWORD);
            rc = TRUE;
            break;
        }

cleanUp:

    DEBUGMSG(ZONE_FUNCTION, (L"-ADC_IOControl(rc = %d)\r\n", rc));
    return rc;
}
예제 #8
0
BOOL
VDE_IOControl(
    DWORD hOpenContext,
    DWORD dwCode,
    PBYTE pBufIn,
    DWORD dwLenIn,
    PBYTE pBufOut,
    DWORD dwLenOut,
    PDWORD pdwActualOut
    )
{
    SVEngineContext *pCtxt;
    BOOL bRet = TRUE;
    BYTE LocalBuffer[SVEARG_MAX_SIZE];
    PBYTE pBufInLocal = (PBYTE)&LocalBuffer;

    pCtxt = SVE_get_context();

    DEBUGMSG(VDE_ZONE_ENTER, (_T("[VDE] VDE_IOControl(0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x)\r\n"),
                hOpenContext, dwCode, pBufIn, dwLenIn, pBufOut, dwLenOut, pdwActualOut));

    memset(pBufInLocal, 0, SVEARG_MAX_SIZE);
    if (dwLenIn > SVEARG_MAX_SIZE ||
        !CeSafeCopyMemory(pBufInLocal, pBufIn, dwLenIn))
    {
        RETAILMSG(ZONEMASK_ERROR, (_T("VDE_IOControl: Failed to create a local copy of parameters.\r\n")) );
        return FALSE;        
    }

    EnterCriticalSection(&pCtxt->csProc);

    switch(dwCode)
    {
    case IOCTL_POWER_CAPABILITIES:
    case IOCTL_POWER_GET:
    case IOCTL_POWER_QUERY:
    case IOCTL_POWER_SET:
    case IOCTL_REGISTER_POWER_RELATIONSHIP:
        break;
    case IOCTL_SVE_PM_SET_POWER_ON:
        SVE_video_engine_power_on();
        break;

    case IOCTL_SVE_PM_SET_POWER_OFF:
        //if caller is not kernel mode, do not allow setting power state to off
        if (GetDirectCallerProcessId() != GetCurrentProcessId()){
            return FALSE;
        }
        SVE_video_engine_power_off();
        break;
        
    case IOCTL_SVE_RSC_REQUEST_FIMD_INTERFACE:
    case IOCTL_SVE_RSC_RELEASE_FIMD_INTERFACE:
    case IOCTL_SVE_RSC_REQUEST_FIMD_WIN0:
    case IOCTL_SVE_RSC_RELEASE_FIMD_WIN0:
    case IOCTL_SVE_RSC_REQUEST_FIMD_WIN1:
    case IOCTL_SVE_RSC_RELEASE_FIMD_WIN1:
    case IOCTL_SVE_RSC_REQUEST_FIMD_WIN2:
    case IOCTL_SVE_RSC_RELEASE_FIMD_WIN2:
    case IOCTL_SVE_RSC_REQUEST_FIMD_WIN3:
    case IOCTL_SVE_RSC_RELEASE_FIMD_WIN3:
    case IOCTL_SVE_RSC_REQUEST_FIMD_WIN4:
    case IOCTL_SVE_RSC_RELEASE_FIMD_WIN4:
    case IOCTL_SVE_RSC_REQUEST_POST:
    case IOCTL_SVE_RSC_RELEASE_POST:
    case IOCTL_SVE_RSC_REQUEST_ROTATOR:
    case IOCTL_SVE_RSC_RELEASE_ROTATOR:
    case IOCTL_SVE_RSC_REQUEST_TVSCALER_TVENCODER:
    case IOCTL_SVE_RSC_RELEASE_TVSCALER_TVENCODER:
        __try
        {
            bRet = SVE_Resource_API_Proc(hOpenContext, SVE_get_api_function_code(dwCode), pBufInLocal, dwLenIn, pBufOut, dwLenOut, pdwActualOut);
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            RETAILMSG( 1, ( _T("VDE_IOControl: exception in IOCTL_SVE_RSC_REQUEST_FIMD_INTERFACE\n")) );
            LeaveCriticalSection(&pCtxt->csProc);
            return FALSE;
        }
        break;

    case IOCTL_SVE_FIMD_SET_INTERFACE_PARAM:
    case IOCTL_SVE_FIMD_SET_OUTPUT_RGBIF:
    case IOCTL_SVE_FIMD_SET_OUTPUT_TV:
    case IOCTL_SVE_FIMD_SET_OUTPUT_ENABLE:
    case IOCTL_SVE_FIMD_SET_OUTPUT_DISABLE:
    case IOCTL_SVE_FIMD_SET_WINDOW_MODE:
    case IOCTL_SVE_FIMD_SET_WINDOW_POSITION:
    case IOCTL_SVE_FIMD_SET_WINDOW_FRAMEBUFFER:
    case IOCTL_SVE_FIMD_SET_WINDOW_COLORMAP:
    case IOCTL_SVE_FIMD_SET_WINDOW_ENABLE:
    case IOCTL_SVE_FIMD_SET_WINDOW_DISABLE:
    case IOCTL_SVE_FIMD_SET_WINDOW_BLEND_DISABLE:
    case IOCTL_SVE_FIMD_SET_WINDOW_BLEND_COLORKEY:
    case IOCTL_SVE_FIMD_SET_WINDOW_BLEND_ALPHA:
    case IOCTL_SVE_FIMD_WAIT_FRAME_INTERRUPT:
    case IOCTL_SVE_FIMD_GET_OUTPUT_STATUS:
    case IOCTL_SVE_FIMD_GET_WINDOW_STATUS:
        __try
        {
            bRet = SVE_DispCon_API_Proc(hOpenContext, SVE_get_api_function_code(dwCode), pBufInLocal, dwLenIn, pBufOut, dwLenOut, pdwActualOut);
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            RETAILMSG( 1, ( _T("VDE_IOControl: exception in IOCTL_SVE_RSC_REQUEST_FIMD_INTERFACE\n")) );
            LeaveCriticalSection(&pCtxt->csProc);
            return FALSE;
        }
        break;

    case IOCTL_SVE_POST_SET_PROCESSING_PARAM:
    case IOCTL_SVE_POST_SET_SOURCE_BUFFER:
    case IOCTL_SVE_POST_SET_NEXT_SOURCE_BUFFER:
    case IOCTL_SVE_POST_SET_DESTINATION_BUFFER:
    case IOCTL_SVE_POST_SET_NEXT_DESTINATION_BUFFER:
    case IOCTL_SVE_POST_SET_PROCESSING_START:
    case IOCTL_SVE_POST_SET_PROCESSING_STOP:
    case IOCTL_SVE_POST_WAIT_PROCESSING_DONE:
    case IOCTL_SVE_POST_GET_PROCESSING_STATUS:
        __try
        {
            bRet = SVE_Post_API_Proc(hOpenContext, SVE_get_api_function_code(dwCode), pBufInLocal, dwLenIn, pBufOut, dwLenOut, pdwActualOut);
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            RETAILMSG( 1, ( _T("VDE_IOControl: exception in IOCTL_SVE_RSC_REQUEST_FIMD_INTERFACE\n")) );
            LeaveCriticalSection(&pCtxt->csProc);
            return FALSE;
        }
        break;


    case IOCTL_SVE_LOCALPATH_SET_WIN0_START:
    case IOCTL_SVE_LOCALPATH_SET_WIN0_STOP:
    case IOCTL_SVE_LOCALPATH_SET_WIN1_START:
    case IOCTL_SVE_LOCALPATH_SET_WIN1_STOP:
    case IOCTL_SVE_LOCALPATH_SET_WIN2_START:
    case IOCTL_SVE_LOCALPATH_SET_WIN2_STOP:
        __try
        {
            bRet = SVE_LocalPath_API_Proc(hOpenContext, SVE_get_api_function_code(dwCode), pBufInLocal, dwLenIn, pBufOut, dwLenOut, pdwActualOut);
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            RETAILMSG( 1, ( _T("VDE_IOControl: exception in IOCTL_SVE_RSC_REQUEST_FIMD_INTERFACE\n")) );
            LeaveCriticalSection(&pCtxt->csProc);
            return FALSE;
        }
        break;

    case IOCTL_SVE_ROTATOR_SET_OPERATION_PARAM:
    case IOCTL_SVE_ROTATOR_SET_SOURCE_BUFFER:
    case IOCTL_SVE_ROTATOR_SET_DESTINATION_BUFFER:
    case IOCTL_SVE_ROTATOR_SET_OPERATION_START:
    case IOCTL_SVE_ROTATOR_SET_OPERATION_STOP:
    case IOCTL_SVE_ROTATOR_WAIT_OPERATION_DONE:
    case IOCTL_SVE_ROTATOR_GET_STATUS:
        __try
        {
            bRet = SVE_Rotator_API_Proc(hOpenContext, SVE_get_api_function_code(dwCode), pBufInLocal, dwLenIn, pBufOut, dwLenOut, pdwActualOut);
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            RETAILMSG( 1, ( _T("VDE_IOControl: exception in IOCTL_SVE_RSC_REQUEST_FIMD_INTERFACE\n")) );
            LeaveCriticalSection(&pCtxt->csProc);
            return FALSE;
        }
        break;

    case IOCTL_SVE_TVSC_SET_PROCESSING_PARAM:
    case IOCTL_SVE_TVSC_SET_SOURCE_BUFFER:
    case IOCTL_SVE_TVSC_SET_NEXT_SOURCE_BUFFER:
    case IOCTL_SVE_TVSC_SET_DESTINATION_BUFFER:
    case IOCTL_SVE_TVSC_SET_NEXT_DESTINATION_BUFFER:
    case IOCTL_SVE_TVSC_SET_PROCESSING_START:
    case IOCTL_SVE_TVSC_SET_PROCESSING_STOP:
    case IOCTL_SVE_TVSC_WAIT_PROCESSING_DONE:
    case IOCTL_SVE_TVSC_GET_PROCESSING_STATUS:
        __try
        {
            bRet = SVE_TVScaler_API_Proc(hOpenContext, SVE_get_api_function_code(dwCode), pBufInLocal, dwLenIn, pBufOut, dwLenOut, pdwActualOut);
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            RETAILMSG( 1, ( _T("VDE_IOControl: exception in IOCTL_SVE_RSC_REQUEST_FIMD_INTERFACE\n")) );
            LeaveCriticalSection(&pCtxt->csProc);
            return FALSE;
        }
        break;

    case IOCTL_SVE_TVENC_SET_INTERFACE_PARAM:
    case IOCTL_SVE_TVENC_SET_ENCODER_ON:
    case IOCTL_SVE_TVENC_SET_ENCODER_OFF:
    case IOCTL_SVE_TVENC_GET_INTERFACE_STATUS:
        __try
        {
            bRet = SVE_TVEncoder_API_Proc(hOpenContext, SVE_get_api_function_code(dwCode), pBufInLocal, dwLenIn, pBufOut, dwLenOut, pdwActualOut);
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            RETAILMSG( 1, ( _T("VDE_IOControl: exception in IOCTL_SVE_RSC_REQUEST_FIMD_INTERFACE\n")) );
            LeaveCriticalSection(&pCtxt->csProc);
            return FALSE;
        }
        break;
    case IOCTL_SVE_FIMD_VSYNC_ENABLE:

        __try
        {
            Disp_VSync_Enable();
            bRet=TRUE;
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            RETAILMSG( 1, ( _T("VDE_IOControl: exception in IOCTL_SVE_FIMD_VSYNC_ENABLE\n")) );
            LeaveCriticalSection(&pCtxt->csProc);
            return FALSE;
        }
        break;


    case IOCTL_SVE_FIMD_GET_FLIPSTATUS:

        __try
        {
            if(Disp_GetFlipStatus())
            {
                bRet=TRUE;
            }
            else
            {
                bRet=FALSE;
            }
        }
        __except ( EXCEPTION_EXECUTE_HANDLER )
        {
            RETAILMSG( 1, ( _T("VDE_IOControl: exception in IOCTL_SVE_FIMD_GET_FLIPSTATUS\n")) );
            LeaveCriticalSection(&pCtxt->csProc);
            return FALSE;
        }
        break;


    case IOCTL_SVE_PM_GET_POWER_STATUS:

    default:
        VDE_ERR((_T("[VDE:ERR] VDE_IOControl() : Unknown IOCTL [0x%08x]\r\n"), dwCode));
        SetLastError (ERROR_INVALID_ACCESS);
        bRet = FALSE;
        break;
    }

    LeaveCriticalSection(&pCtxt->csProc);

    DEBUGMSG(VDE_ZONE_ENTER, (_T("[VDE] --VDE_IOControl()\r\n")));

    return bRet;
}