Example #1
0
IOReturn IOFireWireSBP2LibLUN::addIODispatcherToRunLoop( CFRunLoopRef cfRunLoopRef )
{
    IOReturn 				status = kIOReturnSuccess;

    FWLOG(( "IOFireWireSBP2LibLUN : addIODispatcherToRunLoop\n" ));

    if( !fConnection )
        return kIOReturnNoDevice;

    if( status == kIOReturnSuccess )
    {
        CFMachPortContext context;
        Boolean	shouldFreeInfo; // zzz what's this for?

        context.version = 1;
        context.info = this;
        context.retain = NULL;
        context.release = NULL;
        context.copyDescription = NULL;

        fCFAsyncPort = CFMachPortCreateWithPort( kCFAllocatorDefault, fAsyncPort,
                       (CFMachPortCallBack) IODispatchCalloutFromMessage,
                       &context, &shouldFreeInfo );
        if( !fCFAsyncPort )
            status = kIOReturnNoMemory;
    }

    if( status == kIOReturnSuccess )
    {
        fCFRunLoopSource = CFMachPortCreateRunLoopSource( kCFAllocatorDefault, fCFAsyncPort, 0 );
        if( !fCFRunLoopSource )
            status = kIOReturnNoMemory;
    }

    if( status == kIOReturnSuccess )
    {
        fCFRunLoop = cfRunLoopRef;
        CFRunLoopAddSource( fCFRunLoop, fCFRunLoopSource, kCFRunLoopCommonModes );
    }

    if( status == kIOReturnSuccess )
    {
        io_async_ref64_t asyncRef;
        mach_msg_type_number_t	size = 0;

        asyncRef[kIOAsyncCalloutFuncIndex] = (uint64_t)&IOFireWireSBP2LibLUN::staticMessageCallback;
        asyncRef[kIOAsyncCalloutRefconIndex] = (uint64_t)this;

        status = IOConnectCallAsyncScalarMethod( fConnection, kIOFWSBP2UserClientSetMessageCallback, fAsyncPort, asyncRef, kOSAsyncRef64Count, NULL, 0, NULL, &size  );
    }

    return status;
}
	IOReturn
	VectorCommand::Submit()
	{
		IOReturn status = kIOReturnSuccess;
		
		if( mInflightCount != 0 )
		{ 
			status = kIOReturnNotReady;
		}
		
		CFIndex count = 0;
		if( status == kIOReturnSuccess )
		{
			count = CFArrayGetCount( mCommandArray );
			status = EnsureCapacity( count );
		}

		if( status == kIOReturnSuccess )
		{
			// reset vector status
			mStatus = kIOReturnSuccess;
			
			for( CFIndex index = 0; (status == kIOReturnSuccess) && (index < count); index++ )
			{
				IOFireWireLibCommandRef command = (IOFireWireLibCommandRef)CFArrayGetValueAtIndex( mCommandArray, index );
			
				Cmd * cmd = IOFireWireIUnknown::InterfaceMap<Cmd>::GetThis(command);
				
				status = cmd->PrepareForVectorSubmit( &mSubmitBuffer[index] );
			}
		}

		if( status == kIOReturnSuccess )
		{
			// send the requests to the kernel

			// async ref
			uint64_t async_ref[kOSAsyncRef64Count];
			async_ref[kIOAsyncCalloutFuncIndex] = (uint64_t) 0;
			async_ref[kIOAsyncCalloutRefconIndex] = (unsigned long) 0;

			// inputs
			const uint64_t inputs[2] = { (const uint64_t)&SVectorCompletionHandler,
										 (const uint64_t)this };
			// outputs
			uint32_t output_count = 0;

			status = IOConnectCallAsyncScalarMethod( mUserClient.GetUserClientConnection(),
												  mUserClient.MakeSelectorWithObject( kVectorCommandSubmit, mKernCommandRef ),
												  mUserClient.GetAsyncPort(),
												  async_ref, kOSAsyncRef64Count,
												  inputs, 2,
												  NULL, &output_count);

			mInflightCount = count;
			
//			printf( "VectorCommand::Submit - IOConnectCallAsyncStructMethod status = 0x%08lx\n", status );
		}

		if( status == kIOReturnSuccess )
		{
			for( CFIndex index = 0; (status == kIOReturnSuccess) && (index < count); index++ )
			{
				IOFireWireLibCommandRef command = (IOFireWireLibCommandRef)CFArrayGetValueAtIndex( mCommandArray, index );
			
				Cmd * cmd = IOFireWireIUnknown::InterfaceMap<Cmd>::GetThis(command);
				
				cmd->VectorIsExecuting();				
			}			
		}
		
#if 0						
		if( status == kIOReturnSuccess )
		{
			// reset vector status
			mStatus = kIOReturnSuccess;
			
			for( CFIndex index = 0; index < count; index++ )
			{
				IOFireWireLibCommandRef command = (IOFireWireLibCommandRef)CFArrayGetValueAtIndex( mCommandArray, index );
				mInflightCount++;
				(*command)->Submit( command );
				// our commands seem to call the completion handler on error
				// so pretend all was success
			}
		}
#endif
		
//		printf( "VectorCommand::Submit - status = 0x%08lx\n", status );
		
		return status;
	}
Example #3
0
void PHYPacketListener::TurnOffNotification( IOFireWireLibPHYPacketListenerRef self )
{
    IOReturn status = kIOReturnSuccess;

    if( !mNotifyIsOn )
        status = kIOReturnNotPermitted;

    io_connect_t connection = NULL;
    if( status == kIOReturnSuccess )
    {
        connection = mUserClient.GetUserClientConnection();
        if( connection == 0 )
        {
            status = kIOReturnNoDevice;
        }
    }

    if( status == kIOReturnSuccess )
    {
        uint64_t refrncData[kOSAsyncRef64Count];
        refrncData[kIOAsyncCalloutFuncIndex] = (uint64_t) 0;
        refrncData[kIOAsyncCalloutRefconIndex] = (unsigned long) 0;
        const uint64_t inputs[2] = {
            (const uint64_t)0,
            (const uint64_t)self
        };
        uint32_t outputCnt = 0;
        status = IOConnectCallAsyncScalarMethod(	connection,
                 mUserClient.MakeSelectorWithObject( kPHYPacketListenerSetPacketCallback, mKernelRef ),
                 mUserClient.GetAsyncPort(),
                 refrncData, kOSAsyncRef64Count,
                 inputs, 2,
                 NULL, &outputCnt);
    }

    if( status == kIOReturnSuccess )
    {
        uint64_t refrncData[kOSAsyncRef64Count];
        refrncData[kIOAsyncCalloutFuncIndex] = (uint64_t) 0;
        refrncData[kIOAsyncCalloutRefconIndex] = (unsigned long) 0;
        const uint64_t inputs[2] = {
            (const uint64_t)0,
            (const uint64_t)self
        };
        uint32_t outputCnt = 0;
        status = IOConnectCallAsyncScalarMethod(	connection,
                 mUserClient.MakeSelectorWithObject( kPHYPacketListenerSetSkippedCallback, mKernelRef ),
                 mUserClient.GetAsyncPort(),
                 refrncData, kOSAsyncRef64Count,
                 inputs, 2,
                 NULL, &outputCnt);
    }

    if( status == kIOReturnSuccess )
    {
        uint32_t outputCnt = 0;
        status = IOConnectCallScalarMethod(	connection,
                                            mUserClient.MakeSelectorWithObject( kPHYPacketListenerDeactivate, mKernelRef ),
                                            NULL, 0,
                                            NULL, &outputCnt );
    }

    mNotifyIsOn = false;
}