Пример #1
0
PhysicalAddressSpace::PhysicalAddressSpace( Device& inUserClient, UserObjectHandle inKernPhysicalAddrSpaceRef,
        UInt32 inSize, void* inBackingStore, UInt32 inFlags)
    : IOFireWireIUnknown( reinterpret_cast<const IUnknownVTbl &>( sInterface ) ),
      mUserClient(inUserClient),
      mKernPhysicalAddrSpaceRef(inKernPhysicalAddrSpaceRef),
      mSize(inSize),
      mBackingStore(inBackingStore),
      mSegments( NULL ),
      mSegmentCount(0)
{
    inUserClient.AddRef() ;

    if (!mKernPhysicalAddrSpaceRef)
        throw kIOReturnNoMemory ;

    uint32_t outputCnt = 1;
    uint64_t outputVal = 0;
    IOReturn error = IOConnectCallScalarMethod( mUserClient.GetUserClientConnection(),
                     mUserClient.MakeSelectorWithObject( kPhysicalAddrSpace_GetSegmentCount_d, mKernPhysicalAddrSpaceRef ),
                     NULL,0,
                     &outputVal,&outputCnt);
    mSegmentCount = outputVal & 0xFFFFFFFF;

    if ( error || mSegmentCount == 0)
        throw error ;

    mSegments = new FWPhysicalSegment32[mSegmentCount] ;
    if (!mSegments)
    {
        throw kIOReturnNoMemory ;
    }

    outputCnt = 1;
    outputVal = 0;
    const uint64_t inputs[3] = {(const uint64_t)mKernPhysicalAddrSpaceRef, mSegmentCount, (const uint64_t)mSegments};
    error = IOConnectCallScalarMethod( mUserClient.GetUserClientConnection(),
                                       kPhysicalAddrSpace_GetSegments,
                                       inputs,3,
                                       &outputVal,&outputCnt);
    mSegmentCount = outputVal & 0xFFFFFFFF;

    if (error)
    {
        throw error ;
    }

#ifndef __LP64__
    ROSETTA_ONLY(
    {
        UInt32 i;
        for( i = 0; i < mSegmentCount; i++ )
        {
            mSegments[i].location = OSSwapInt32( mSegments[i].location );
            mSegments[i].length = OSSwapInt32( mSegments[i].length );
        }
    }
    );
IOReturn IOAccelCreateAccelID(IOOptionBits options, IOAccelID * identifier)
{
    IOReturn err;

    if (!idConnect)
    {
        io_service_t
        service = IORegistryEntryFromPath(kIOMasterPortDefault, 
                                        kIOServicePlane ":/IOResources/IODisplayWrangler");
        if (service) 
        {
            err = IOServiceOpen(service, mach_task_self(), 0, &idConnect);
            IOObjectRelease(service);
        }
    }

    if (!idConnect)
        return (kIOReturnNotReady);

    uint64_t inData[] = { options, *identifier };
    uint64_t outData;
    uint32_t outLen = 1;
    err = IOConnectCallScalarMethod(idConnect, kAlloc,
                                 inData,   arrayCnt(inData),
                                &outData,  &outLen);
    *identifier = (IOAccelID) outData;

    return (err);
}
void getLightSensors(float *left, float *right)
{
    uint64_t inputValues[0];
  uint32_t inputCount = 0;

    uint64_t outputValues[2];
  uint32_t outputCount = 2;

  kern_return_t kr;

    kr = IOConnectCallScalarMethod(getDataPort(),
    kGetSensorReadingID,
    inputValues,
    inputCount,
    outputValues,
    &outputCount);

  if (kr != KERN_SUCCESS)
  {
    //printf("error getting light sensor values\n");
    return;
  }

  *left = outputValues[0];
  *right = outputValues[1];

  *left  /= 2000;
  *right /= 2000;
}
Пример #4
0
PHYPacketListener::PHYPacketListener( Device & userClient, UInt32 queue_count )
    :	IOFireWireIUnknown( reinterpret_cast<const IUnknownVTbl &>( sInterface ) ),
      mUserClient( userClient ),
      mKernelRef( 0 ),
      mQueueCount( queue_count ),
      mRefCon( NULL ),
      mCallback( NULL ),
      mSkippedCallback( NULL ),
      mFlags( 0 ),
      mNotifyIsOn( false )
{
    mUserClient.AddRef();

    // input data
    const uint64_t inputs[1]= { (const uint64_t)mQueueCount };

    // output data
    uint64_t kernel_ref = 0;
    uint32_t outputCnt = 1;

    // send it down
    IOReturn status = IOConnectCallScalarMethod(	mUserClient.GetUserClientConnection(),
                      kPHYPacketListenerCreate,
                      inputs, 1,
                      &kernel_ref, &outputCnt );
    if( status != kIOReturnSuccess )
    {
        throw status;
    }

    mKernelRef = kernel_ref;
}
IOReturn
SATSMARTClient::SMARTReturnStatus ( Boolean * exceededCondition )
{

    IOReturn status          = kIOReturnSuccess;
    uint64_t condition       = 0;
    uint32_t  outputCnt = 1;

    PRINT ( ( "SATSMARTClient::SMARTReturnStatus called\n" ) );

    status = IOConnectCallScalarMethod ( fConnection,
        kIOATASMARTReturnStatus,
        0, 0, 
        &condition, &outputCnt);

    if ( status == kIOReturnSuccess )
    {

        *exceededCondition = ( condition != 0 );
        PRINT ( ( "exceededCondition = %ld\n", (long)condition ) );

    }

    PRINT ( ( "SATSMARTClient::SMARTReturnStatus status = %d outputCnt = %d\n", status, (int)outputCnt ) );

    return status;

}
Пример #6
0
static int foohid_destroy(const char *name, int name_len)
{
    char *deviceName;

    if (name_len == 0) {
        printf("Invalid name value\n");
        return -1;
    }

    io_connect_t conn;
    if (foohid_connect(&conn)) {
        printf("Unable to open %s service\n", FoohidService);
        return -2;
    }

    uint32_t output_count = 1;
    uint64_t output = 0;

    uint64_t input[2];
    // the name needs to be allocated on the heap, in order to be accessible from the kernel driver
    deviceName = strdup(name);
    input[0] = (uint64_t) deviceName;
    input[1] = (uint64_t) name_len;

    kern_return_t ret = IOConnectCallScalarMethod(conn, FOOHID_DESTROY, input, 2, &output, &output_count);
    free(deviceName);
    foohid_close(conn);

    if (ret != KERN_SUCCESS || output != 0) {
        printf("unable to destroy device, name: %s\n", name);
        return -3;
    }

    return 0;
}
Пример #7
0
uint32_t PCIDriver_write64(uint32_t addr, uint64_t val)
{
	if (!PCIDriver_connect) {
		if (PCIDriver_setupDriver() != KERN_SUCCESS) {
			return KERN_FAILURE;
		}
	}
	
	kern_return_t result;
	uint64_t input[] = { (uint64_t)addr, val & 0xffffffff };
	result  = IOConnectCallScalarMethod(PCIDriver_connect, kWrite, input, 2, NULL, 0);
	input[0] = (uint64_t)addr + 4;
	input[1] = val >> 32;
	result |= IOConnectCallScalarMethod(PCIDriver_connect, kWrite, input, 2, NULL, 0);
	return result;
}
IOReturn IOAccelCreateSurface( io_service_t accelerator, UInt32 wID, eIOAccelSurfaceModeBits modebits,
                                IOAccelConnect *connect )
{
        IOReturn        kr;
        io_connect_t    window = MACH_PORT_NULL;

        *connect = NULL;

        /* Create a context */
        kr = IOServiceOpen( accelerator,
                    mach_task_self(),
                    kIOAccelSurfaceClientType,
                    &window );

        if( kr != kIOReturnSuccess)
        {
                return kr;
        }

        /* Set the window id */
        uint64_t data[] = { wID, modebits };
        kr = IOConnectCallScalarMethod(window, kIOAccelSurfaceSetIDMode,
                                   data, arrayCnt(data), NULL, NULL);
        if(kr != kIOReturnSuccess)
        {
                IOServiceClose(window);
                return kr;
        }

        *connect = (IOAccelConnect) (uintptr_t) window;

        return kIOReturnSuccess;
}
IOReturn IOFireWireSBP2LibORB::init( io_connect_t connection, mach_port_t asyncPort )
{
	IOReturn status = kIOReturnSuccess;

	fConnection = connection;
	fAsyncPort = asyncPort;
	
	FWLOG(( "IOFireWireSBP2LibORB : fConnection %d, fAsyncPort %d\n", 
												fConnection, fAsyncPort ));
	
	if( !fConnection || !fAsyncPort )
		status = kIOReturnError;
		
	if( status == kIOReturnSuccess )
	{
		uint32_t len = 1;
		status = IOConnectCallScalarMethod( connection, kIOFWSBP2UserClientCreateORB, 
											NULL, 0, &fORBRef, &len );
		if( status != kIOReturnSuccess )
			fORBRef = 0; // just to make sure
													
		FWLOG(( "IOFireWireSBP2LibORB :  status = 0x%08x = fORBRef 0x%08lx\n",
																	status, fORBRef ));
	}
			
	return status;
}
float getKeyboardBrightness(void)
{
  float f;
  kern_return_t kr;

  uint64_t inputCount = 1;
    uint64_t inputValues[1] = {0};

    uint32_t outputCount = 1;
    uint64_t outputValues[1];

    uint32_t out_brightness;

  kr = IOConnectCallScalarMethod(getDataPort(),
      kGetLEDBrightnessID,
    inputValues,
    inputCount,
    outputValues,
    &outputCount);

    out_brightness = outputValues[0];

  if (kr != KERN_SUCCESS)
  {
    printf("getKeyboardBrightness() error\n");
    return 0;
  }

  f = out_brightness;
  f /= 0xfff;
  return (float)f;
}
void setKeyboardBrightness(float in)
{
  // static io_connect_t dp = 0; // shared?
  kern_return_t kr;

  uint64_t inputCount  = 2;
    uint64_t inputValues[2];
    uint64_t in_unknown = 0;
    uint64_t in_brightness = in * 0xfff;

    inputValues[0] = in_unknown;
    inputValues[1] = in_brightness;

    uint32_t outputCount = 1;
    uint64_t outputValues[1];

    uint32_t out_brightness;

  //kr = IOConnectMethodScalarIScalarO(dp, kSetLEDBrightnessID,
  kr = IOConnectCallScalarMethod(getDataPort(),
      kSetLEDBrightnessID,
    inputValues,
    inputCount,
    outputValues,
    &outputCount);

    out_brightness = outputValues[0];

  if (kr != KERN_SUCCESS)
  {
    printf("setKeyboardBrightness() error\n");
    return;
  }
}
Пример #12
0
uint32_t PCIDriver_readMemory64(uint8_t* address, uint64_t* val)
{
	if (!PCIDriver_connect) {
		if (PCIDriver_setupDriver() != KERN_SUCCESS) {
			return KERN_FAILURE;
		}
	}
	kern_return_t result;
	uint64_t input[] = { (uint64_t)address };
	uint64_t lo = 0;
	uint64_t hi = 0;
	uint32_t outputCnt = 1;
	result  = IOConnectCallScalarMethod(PCIDriver_connect, kReadMemory, input, 1, &lo, &outputCnt);
	input[0] = (uint64_t)address + 4;
	result |= IOConnectCallScalarMethod(PCIDriver_connect, kReadMemory, input, 1, &hi, &outputCnt);
	*val = (hi << 32) | lo;
	return result;
}
Пример #13
0
void reset_baseband() {
    printf("Resetting baseband\n");
    io_connect_t connect = 0;
    CFMutableDictionaryRef match = IOServiceMatching("AppleBaseband");
    io_service_t service = IOServiceGetMatchingService(0, match);
    IOServiceOpen(service, mach_task_self(), 0, &connect);
    IOConnectCallScalarMethod(connect, 0, 0, 0, 0, 0);
    IOServiceClose(connect);
    sleep(1);
}
void IOFireWireSBP2LibORB::setToDummy( void )
{
	IOReturn status = kIOReturnSuccess;
	
	FWLOG(( "IOFireWireSBP2LibORB : setToDummy\n" ));
		
	uint32_t len = 0;
	status = IOConnectCallScalarMethod( fConnection, 	
										kIOFWSBP2UserClientSetToDummy, 
										&fORBRef, 1, NULL, &len );
}
Пример #15
0
uint32_t PCIDriver_write32(uint32_t addr, uint32_t val)
{
	if (!PCIDriver_connect) {
		if (PCIDriver_setupDriver() != KERN_SUCCESS) {
			return KERN_FAILURE;
		}
	}
	
	uint64_t input[] = { (uint64_t)addr, (uint64_t)val };
	return IOConnectCallScalarMethod(PCIDriver_connect, kWrite, input, 2, NULL, 0);
}
IOReturn IONetworkResetData(io_connect_t con, IONDHandle dataHandle)
{
    IOReturn               kr;

    uint64_t data = dataHandle;
    kr = IOConnectCallScalarMethod(con,   kIONUCResetNetworkDataIndex,
			       &data, 1,	// input[], inputCount
			       NULL,  NULL);

    return kr;
}
Пример #17
0
void resetBaseband() {
    LOG(LOGLEVEL_INFO, "Resetting baseband...\n");
    mach_port_t masterPort;
    kern_return_t result = IOMasterPort(MACH_PORT_NULL, &masterPort);
    CFMutableDictionaryRef matchingDict = IOServiceMatching("AppleBaseband");
    io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
    io_connect_t conn;
    result = IOServiceOpen(service, mach_task_self(), 0, &conn);
    result = IOConnectCallScalarMethod(conn, 0, 0, 0, 0, 0);
    IOServiceClose(conn);
}
Пример #18
0
void IOFireWireSBP2LibLUN::close( void )
{
    if( !fConnection )
        return;

    FWLOG(( "IOFireWireSBP2LUN : close\n" ));

    uint32_t len = 0;
    IOConnectCallScalarMethod(	fConnection, kIOFWSBP2UserClientClose,
                                NULL, 0, NULL, &len );

}
Пример #19
0
IOReturn IOPMSleepSystem ( io_connect_t fb )
{
    uint64_t rtn = 0;
    uint32_t len = 1;
    kern_return_t err = IOConnectCallScalarMethod(fb, kPMSleepSystem,
                NULL, 0, &rtn, &len);

    if (err)
    return kIOReturnError;
    else
    return (IOReturn) rtn;
}
Пример #20
0
/*! Releases an iSCSI session, including all connections associated with that
 *  session.
 *  @param sessionId the session qualifier part of the ISID.
 *  @return error code indicating result of operation. */
errno_t iSCSIKernelReleaseSession(SID sessionId)
{
    // Check parameters
    if(sessionId == kiSCSIInvalidSessionId)
        return EINVAL;

    // Tell the kernel to drop this session and all of its related resources
    const UInt32 inputCnt = 1;
    UInt64 input = sessionId;
    
    return IOReturnToErrno(IOConnectCallScalarMethod(connection,kiSCSIReleaseSession,&input,inputCnt,0,0));
}
Пример #21
0
/*! Frees a given iSCSI connection associated with a given session.
 *  The session should be logged out using the appropriate PDUs.
 *  @return error code indicating result of operation. */
errno_t iSCSIKernelReleaseConnection(SID sessionId,CID connectionId)
{
    // Check parameters
    if(sessionId == kiSCSIInvalidSessionId || connectionId == kiSCSIInvalidConnectionId)
        return EINVAL;

    // Tell kernel to drop this connection
    const UInt32 inputCnt = 2;
    UInt64 inputs[] = {sessionId,connectionId};
    
    return IOReturnToErrno(IOConnectCallScalarMethod(connection,kiSCSIReleaseConnection,inputs,inputCnt,0,0));
}
Пример #22
0
/*! Dectivates all iSCSI sessions associated with a session.
 *  @param sessionId session associated with connections to deactivate.
 *  @return error code inidicating result of operation. */
errno_t iSCSIKernelDeactivateAllConnections(SID sessionId)
{
    // Check parameters
    if(sessionId == kiSCSIInvalidSessionId)
        return EINVAL;
    
    const UInt32 inputCnt = 1;
    UInt64 input = sessionId;
    
    return IOReturnToErrno(IOConnectCallScalarMethod(connection,kiSCSIDeactivateAllConnections,
                                                     &input,inputCnt,NULL,NULL));
}
IOFireWireSBP2LibORB::~IOFireWireSBP2LibORB()
{
	if( fORBRef ) 
	{
		IOReturn status = kIOReturnSuccess;
		
		uint32_t len = 0;
		status = IOConnectCallScalarMethod( fConnection, 	
											kIOFWSBP2UserClientReleaseORB, 
											&fORBRef, 1, NULL, &len );
		FWLOG(( "IOFireWireSBP2LibORB : release orb status = 0x%08x\n", status ));
	}
}
IOReturn IOAccelDestroyAccelID(IOOptionBits options, IOAccelID identifier)
{
    IOReturn err;

    if (!idConnect)
        return (kIOReturnNotReady);

    uint64_t inData[] = { options, identifier };
    err = IOConnectCallScalarMethod(idConnect, kFree,
                                 inData, arrayCnt(inData), NULL, NULL);

    return (err);
}
IOReturn IOAccelSurfaceControl( IOAccelConnect connect,
                                    UInt32 selector, UInt32 arg, UInt32 * result) 
{
        uint64_t inData[] = { selector, arg };
        uint64_t outData;
        uint32_t outSize = 1;

        IOReturn err =  IOConnectCallScalarMethod((io_connect_t) (uintptr_t)connect, kIOAccelSurfaceControl,
                inData, arrayCnt(inData), &outData, &outSize);
        *result = (UInt32) outData;
    
        return( err );
}
Пример #26
0
IOReturn IOCancelPowerChange ( io_connect_t kernelPort, intptr_t notificationID )
{
    uint64_t inData = notificationID;
    kern_return_t err = IOConnectCallScalarMethod(
                                kernelPort, kPMCancelPowerChange,
                                &inData, 1, NULL, NULL);

    if (err) {
        return kIOReturnError;
    } else {
        return err;
    }
}
Пример #27
0
void switcherClose() {
    kern_return_t kernResult;
    if (switcherConnect == IO_OBJECT_NULL) return;
    
    kernResult = IOConnectCallScalarMethod(switcherConnect, kClose, NULL, 0, NULL, NULL);
    if (kernResult != KERN_SUCCESS) printf("IOConnectCallScalarMethod returned 0x%08x.\n", kernResult);
    
    kernResult = IOServiceClose(switcherConnect);
    if (kernResult != KERN_SUCCESS) printf("IOServiceClose returned 0x%08x.\n", kernResult);
    
    switcherConnect = IO_OBJECT_NULL;
    printf("Driver connection closed.");
}
void IOFireWireSBP2LibORB::setCommandGeneration( UInt32 generation )
{
	FWLOG(( "IOFireWireSBP2LibORB : setCommandGeneration = %ld\n", generation ));
		
	uint32_t len = 0;
	uint64_t params[2];
	
	params[0] = fORBRef;
	params[1] = generation;
	
	IOConnectCallScalarMethod(	fConnection, 	
								kIOFWSBP2UserClientSetCommandGeneration, 
								params, 2, NULL, &len );
}
void IOFireWireSBP2LibORB::setCommandTimeout( UInt32 timeout )
{
	FWLOG(( "IOFireWireSBP2LibORB : setCommandTimeout = %ld\n", timeout ));
		
	uint32_t len = 0;
	uint64_t params[2];
	
	params[0] = fORBRef;
	params[1] = timeout;
	
	IOConnectCallScalarMethod(	fConnection, 	
								kIOFWSBP2UserClientSetCommandTimeout, 
								params, 2, NULL, &len );
}
void IOFireWireSBP2LibORB::setMaxORBPayloadSize( UInt32 size )
{
	FWLOG(( "IOFireWireSBP2LibORB : setMaxORBPayloadSize = %ld\n", size ));
		
	uint32_t len = 0;
	uint64_t params[2];
	
	params[0] = fORBRef;
	params[1] = size;
	
	IOConnectCallScalarMethod( fConnection, 	
									   kIOFWSBP2UserClientSetMaxORBPayloadSize, 
									   params, 2, NULL, &len );
}