Esempio n. 1
0
int ReceiveEventProc( void *user_data , xml *p_req , char *output_buffer , int *p_output_buflen , int *p_output_bufsize )
{
    if( strcmp( p_req->Event , "<![CDATA[subscribe]]>" ) == 0 )
    {
        (*p_output_buflen) += snprintf( output_buffer+(*p_output_buflen) , (*p_output_bufsize)-1 - (*p_output_buflen) ,
                                        "欢迎订阅"
                                      );
    }
    else if( strcmp( p_req->Event , "<![CDATA[unsubscribe]]>" ) == 0 )
    {
        (*p_output_buflen) += snprintf( output_buffer+(*p_output_buflen) , (*p_output_bufsize)-1 - (*p_output_buflen) ,
                                        "再见"
                                      );
    }

    InfoLog( __FILE__ , __LINE__ , "文本编码前[%s]" , output_buffer );
    (*p_output_buflen) = PUBConvCharacterCode( "GB18030" , "UTF-8" , output_buffer , (*p_output_buflen) , (*p_output_bufsize) );
    if( (*p_output_buflen) < 0 )
    {
        ErrorLog( __FILE__ , __LINE__ , "PUBConvCharacterCode failed[%d]" , (*p_output_buflen) );
        return -1;
    }
    InfoLog( __FILE__ , __LINE__ , "文本编码后[%s]" , output_buffer );

    return 0;
}
Esempio n. 2
0
int ReceiveText( struct Weixin4cEnv *penv , char *post_data , int post_data_len , xml *p_req )
{
	xml	rsp ;
	char	output_buffer[ 4096 * 100 ] ;
	int	output_buflen ;
	int	output_bufsize ;
	char	rsp_buffer[ 4096 * 110 ] ;
	int	rsp_buflen ;
	
	int	nret = 0 ;
	
	TakeoffCDATA( p_req->ToUserName );
	TakeoffCDATA( p_req->FromUserName );
	TakeoffCDATA( p_req->Content );
	
	memset( output_buffer , 0x00 , sizeof(output_buffer) );
	output_buflen = 0 ;
	output_bufsize = sizeof(output_buffer) ;
	if( penv->pconf->funcs.pfuncReceiveTextProc )
	{
		SetLogFile( "%s/log/%s_ReceiveTextProc.log" , penv->pconf->home , penv->pconf->project_name );
		nret = penv->pconf->funcs.pfuncReceiveTextProc( penv->pconf->user_data , p_req , output_buffer , & output_buflen , & output_bufsize ) ;
		SetLogFile( "%s/log/%s_weixin4c.log" , penv->pconf->home , penv->pconf->project_name );
		if( nret )
		{
			ErrorLog( __FILE__ , __LINE__ , "pfuncReceiveTextProc failed[%d]" , nret );
		}
		else
		{
			InfoLog( __FILE__ , __LINE__ , "pfuncReceiveTextProc ok" );
		}
	}
	
	memset( & rsp , 0x00 , sizeof(xml) );
	snprintf( rsp.ToUserName , sizeof(rsp.ToUserName)-1 , "<![CDATA[%s]]>" , p_req->FromUserName );
	snprintf( rsp.FromUserName , sizeof(rsp.FromUserName)-1 , "<![CDATA[%s]]>" , p_req->ToUserName );
	rsp.CreateTime = (int)time(NULL) ;
	strcpy( rsp.MsgType , p_req->MsgType );
	snprintf( rsp.Content , sizeof(rsp.Content)-1 , "<![CDATA[%s]]>" , output_buffer );
	strcpy( rsp.MsgId , p_req->MsgId );
	
	memset( rsp_buffer , 0x00 , sizeof(rsp_buffer) );
	rsp_buflen = sizeof(rsp_buffer) - 1 ;
	nret = DSCSERIALIZE_XML_xml( & rsp , "GB18030" , rsp_buffer , & rsp_buflen ) ;
	if( nret )
	{
		ErrorLog( __FILE__ , __LINE__ , "DSCSERIALIZE_XML_xml failed[%d]" , nret );
	}
	else
	{
		InfoLog( __FILE__ , __LINE__ , "DSCSERIALIZE_XML_xml ok" );
		InfoLog( __FILE__ , __LINE__ , "rsp xml[%.*s]" , rsp_buflen-41 , rsp_buffer+41 );
		printf( "%.*s" , rsp_buflen-41 , rsp_buffer+41 );
	}
	
	return 0;
}
IOService* GeforceSensors::probe(IOService *provider, SInt32 *score)
{
  UInt32 vendor_id, device_id, class_id;
	DebugLog("Probing...");
	
	if (super::probe(provider, score) != this) return 0;
	
	InfoLog("GeforceSensors by kozlek (C) 2012");
	s8 ret = 0;
	if (OSDictionary * dictionary = serviceMatching(kGenericPCIDevice)) {
		if (OSIterator * iterator = getMatchingServices(dictionary)) {
			ret = 1;
			IOPCIDevice* device = 0;
			do {
			  device = OSDynamicCast(IOPCIDevice, iterator->getNextObject());
        if (!device) {
          break;
        }
				OSData *data = OSDynamicCast(OSData, device->getProperty(fVendor));
        vendor_id = 0;
				if (data)
					vendor_id = *(UInt32*)data->getBytesNoCopy();
				
        device_id = 0;
				data = OSDynamicCast(OSData, device->getProperty(fDevice));				
				if (data)
					device_id = *(UInt32*)data->getBytesNoCopy();
				
        class_id = 0;
				data = OSDynamicCast(OSData, device->getProperty(fClass));				
				if (data)
					class_id = *(UInt32*)data->getBytesNoCopy();
				
				if ((vendor_id==0x10de) && (class_id == 0x030000)) {
					InfoLog("found %x Nvidia chip", (unsigned int)device_id);
					card.pcidev = device;
          card.device_id = device_id;
					ret = 1; //TODO - count a number of cards
          card.card_index = ret;
					break;
				}
			} while (device);	
		}
	}
	if(ret)
		return this;
	else return 0;
	
	return this;
}
Esempio n. 4
0
int VerifyServer( struct Weixin4cEnv *penv , char *signature , char *timestamp , char *nonce , char *echostr )
{
	char	etc_pathfilename[ 256 + 1 ] ;
	char	*token = NULL ;
	
	char	array[3][64] ;
	
	char	data[ 1024 + 1 ] ;
	char	result[ SHA_DIGEST_LENGTH * 2 + 1 ] ;
	char	result_exp[ SHA_DIGEST_LENGTH * 2 + 1 ] ;
	int	result_exp_len ;
	
	InfoLog( __FILE__ , __LINE__ , "--- plistQuery ---" );
	InfoLog( __FILE__ , __LINE__ , "signature[%s]" , signature );
	InfoLog( __FILE__ , __LINE__ , "timestamp[%s]" , timestamp );
	InfoLog( __FILE__ , __LINE__ , "nonce    [%s]" , nonce );
	InfoLog( __FILE__ , __LINE__ , "echostr  [%s]" , echostr );
	InfoLog( __FILE__ , __LINE__ , "------------------" );
	
	memset( etc_pathfilename , 0x00 , sizeof(etc_pathfilename) );
	snprintf( etc_pathfilename , sizeof(etc_pathfilename)-1 , "%s/etc/%s/Token" , penv->pconf->home , penv->pconf->project_name );
	PUBReadEntireFileSafely( etc_pathfilename , "r" , & token , NULL );
	PUBStringNoEnter( token );
	
	strcpy( array[0] , token );
	strcpy( array[1] , timestamp );
	strcpy( array[2] , nonce );
	qsort( array , 3 , sizeof(array[0]) , sort_strcmp );
	
	memset( data , 0x00 , sizeof(data) );
	snprintf( data , sizeof(data)-1 , "%s%s%s" , array[0] , array[1] , array[2] );
	InfoLog( __FILE__ , __LINE__ , "data[%s]" , data );
	
	memset( result , 0x00 , sizeof(result) );
	SHA1( (unsigned char *)data , strlen(data) , (unsigned char *)result );
	memset( result_exp , 0x00 , sizeof(result_exp) );
	PUBHexExpand( result , SHA_DIGEST_LENGTH , result_exp);
	result_exp_len = strlen(result_exp) ;
	InfoLog( __FILE__ , __LINE__ , "result_exp[%s]" , result_exp );
	
	if( result_exp_len == strlen(signature) && strncmp( result_exp , signature , result_exp_len ) == 0 )
	{
		InfoLog( __FILE__ , __LINE__ , "verify matched" );
		printf( "%s" , echostr );
	}
	else
	{
		ErrorLog( __FILE__ , __LINE__ , "verify not matched" );
	}
	
	free( token );
	
	return 0;
}
Esempio n. 5
0
int test_outputfunc()
{
	LOG		*g = NULL ;
	
	g = CreateLogHandle() ;
	if( g == NULL )
	{
		printf( "创建日志句柄失败errno[%d]\n" , errno );
		return -1;
	}
	else
	{
		printf( "创建日志句柄成功\n" );
	}
	
	SetLogOutput( g , LOG_OUTPUT_CALLBACK , "127.0.0.1:514" , & MyOpenLogFirst , NULL , & MyWriteLog , NULL , NULL , & MyCloseLogFinally );
	SetLogLevel( g , LOG_LEVEL_INFO );
	SetLogStyles( g , LOG_STYLES_LOG , LOG_NO_STYLEFUNC );
	
	DebugLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	InfoLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	WarnLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	ErrorLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	FatalLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	
	DestroyLogHandle( g );
	printf( "销毁日志句柄\n" );
	
	return 0;
}
Esempio n. 6
0
bool PC8739x::probePort()
{	

	UInt8 id = listenPortByte(SUPERIO_CHIP_ID_REGISTER);	
	revision = listenPortByte(NSC_CHIP_REVISION_REGISTER);
	DebugLog("testing NSC id=%04x rev=%04x", id, revision);
	if (id == 0 || id == 0xff || revision == 0 || revision == 0xff)
		return false;
		
	if (id == 0xfc) {
		selectLogicalDevice(NSC_HARDWARE_MONITOR_LDN);
		
		if (!getLogicalDeviceAddress(SUPERIO_BASE_ADDRESS_REGISTER)){
			DebugLog("NSC no getLogicalDeviceAddress");
			//return false;
		}
//		m_Address = ListenPortWord(SUPERIO_BASE_ADDRESS_REGISTER);
		if (!listenPortByte(NSC_LDN_PRESENT)){
			DebugLog(" no NSC_LDN_PRESENT");
			return false;
		}
		
		switch (revision) {
			default:
				model = PC8739xx;
				break;
		}
		InfoLog("NSC: Found supported chip ID=0x%x REVISION=0x%x ", id, revision);
		return true;
	}
	
	return false;
}
Esempio n. 7
0
bool ATICard::getRadeonInfo()
{
	UInt16 devID = chipID & 0xffff;
	RADEONCardInfo *devices = radeon_device_list;
	rinfo = new RADEONCardInfo;
	while (devices->device_id != NULL) {
		//IOLog("check %d/n", devices->device_id ); //Debug
		if ((devices->device_id & 0xffff) == devID ) {
			//			rinfo->device_id = devID;
			rinfo->device_id = devices->device_id;
			rinfo->ChipFamily = devices->ChipFamily;
			family = devices->ChipFamily;
			rinfo->igp = devices->igp;
			rinfo->is_mobility = devices->is_mobility;
			IOLog(" Found ATI Radeon %04lx\n", (long unsigned int)devID);
			return true;
		}
		devices++;
	}
	
/*	
	for (int i=0; radeon_device_list[i].device_id; i++) {
		if (devID == radeon_device_list[i].device_id) {
			rinfo = &radeon_device_list[i];
			family = radeon_device_list[i].ChipFamily;
			return;
		}
	}
	if (!rinfo) {
		InfoLog("your DeviceID is unknown!\n");
	}
 */
	InfoLog("Unknown DeviceID!\n");
	return false;
}
Esempio n. 8
0
static int cgiinit( struct Weixin4cEnv *penv )
{
	int		nret = 0 ;
	
	chdir( "/tmp" );
	
	SetLogFile( "%s/log/%s_weixin4c.log" , penv->pconf->home , penv->pconf->project_name );
	SetLogLevel( LOGLEVEL_DEBUG );
	
	if( penv->pconf->funcs.pfuncInitEnvProc )
	{
		nret = penv->pconf->funcs.pfuncInitEnvProc( penv->pconf->user_data ) ;
		if( nret )
		{
			ErrorLog( __FILE__ , __LINE__ , "pfuncInitEnvProc failed[%d]" , nret );
			return -2;
		}
		else
		{
			InfoLog( __FILE__ , __LINE__ , "pfuncInitEnvProc ok" );
		}
	}
	
	return 0;
}
Esempio n. 9
0
IOService* X3100monitor::probe(IOService *provider, SInt32 *score)
{
	if (super::probe(provider, score) != this) return 0;
	UInt32 vendor_id, device_id;
	if (OSDictionary * dictionary = serviceMatching(kGenericPCIDevice)) {
		if (OSIterator * iterator = getMatchingServices(dictionary)) {
			
			IOPCIDevice* device = 0;
			
			while (device = OSDynamicCast(IOPCIDevice, iterator->getNextObject())) {
				OSData *data = OSDynamicCast(OSData, device->getProperty("vendor-id"));
				if (data)
					vendor_id = *(UInt32*)data->getBytesNoCopy();
				
				data = OSDynamicCast(OSData, device->getProperty("device-id"));				
				if (data)
					device_id = *(UInt32*)data->getBytesNoCopy();
				
				if ((vendor_id==0x8086) && (device_id==0x2a00)){
					InfoLog("found %lx chip", (long unsigned int)device_id);
					VCard = device;
				}
			}
		}
	}	
	return this;
}
Esempio n. 10
0
static int CheckFilterRule( Pm_Hzbat_Batches_Filter *p_batches_filter )
{
	struct tm	tt ;
	
	InfoLog( __FILE__ , __LINE__ , "CheckFilterRule p_batches_filter->batch_name[%s]" , p_batches_filter->batch_name );
	if( STRCMP( p_batches_filter->filter_type , == , "DD" ) )
	{
		char	filter_param[ sizeof(p_batches_filter->filter_param) ] ;
		char	*ptr = NULL ;
		int	day ;
		
		strcpy( filter_param , p_batches_filter->filter_param );
		ptr = strtok( filter_param , "," ) ;
		while( ptr )
		{
			day = atoi(ptr) ;
			if( ( 1 <= day && day <= 31 ) || STRCMP( ptr , == , "MB" ) || STRCMP( ptr , == , "ME" ) )
			{
				;
			}
			else
			{
				ErrorLog( __FILE__ , __LINE__ , "DD参数[%s]不合法" , p_batches_filter->filter_param );
				return -1;
			}
			
			ptr = strtok( NULL , "," ) ;
		}
		if( ptr )
			return 0;
	}
Esempio n. 11
0
bool ACPIMonitor::addSensor(const char* method, const char* key, const char* type, unsigned char size)
{
    if (kIOReturnSuccess == fakeSMC->callPlatformFunction(kFakeSMCAddKeyHandler, false, (void *)key, (void *)type, (void *)size, (void *)this))
        if (sensors->setObject(key, OSString::withCString(method))) {
            InfoLog("%s registered", method);
            return true;
        }

    return false;
}
Esempio n. 12
0
void CCommandLog::returnPressed()
{
	QString text = m_CommandInput->text();
	if (text.isEmpty())
		return;

	std::string cmd = text.toAscii().data();
	ICommand::execute(cmd, InfoLog());

	m_CommandInput->clear();
}
Esempio n. 13
0
IOService* PC8739x::probe(IOService *provider, SInt32 *score)
{
	DebugLog("probing...");
	
	if (super::probe(provider, score) != this) 
		return 0;
	
	InfoLog("slice (C) 2011");
	
	return this;
}
Esempio n. 14
0
void ATICard::setup_Evergreen()
{
	char key[5];
	int id = GetNextUnusedKey(KEY_FORMAT_GPU_DIODE_TEMPERATURE, key);
	if (id == -1) {
		InfoLog("No new GPU SMC key!\n");
		return;
	}
	card_number = id;
	tempSensor = new EverTemperatureSensor(this, id, key, TYPE_SP78, 2);
	Caps = GPU_TEMP_MONITORING;
}
Esempio n. 15
0
int test_press( long count )
{
	LOG		*press = NULL ;
	
	LongToLong	llBegin , llEnd , llDiff ;
	double		dPerf ;
	long		l ;
	
	press = CreateLogHandle() ;
	if( press == NULL )
	{
		printf( "创建press日志句柄失败errno[%d]\n" , errno );
		return -1;
	}
	else
	{
		printf( "创建press日志句柄成功\n" );
	}
	
	/* SetLogOptions( press , LOG_OPTION_OPEN_ONCE ); */
	SetLogOutput( press , LOG_OUTPUT_FILE , "test_press.log" , LOG_NO_OUTPUTFUNC );
	SetLogLevel( press , LOG_LEVEL_INFO );
	SetLogStyles( press , LOG_STYLES_PRESS , LOG_NO_STYLEFUNC );
	SetLogRotateMode( press , LOG_ROTATEMODE_SIZE );
	SetLogRotateSize( press , 10*1024*1024 );
	
	llBegin = GetUnixSecondsExactly() ;
	for( l = 1 ; l <= count ; l++ )
	{
		InfoLog( press , __FILE__ , __LINE__ , "log" );
	}
	llEnd = GetUnixSecondsExactly() ;
	llDiff.high = llEnd.high - llBegin.high ;
	llDiff.low = llEnd.low - llBegin.low ;
	if( llDiff.low < 0 )
	{
		llDiff.low += 1000000 ;
		llDiff.high--;
	}
	dPerf = (double)(count) / ( (double)(llDiff.high) + (double)(llDiff.low) / 1000000 ) ;
	printf( "总耗时[%ld.%03ld] 平均每秒输出行日志[%.2lf]条\n" , llDiff.high , llDiff.low , dPerf );
	
	DestroyLogHandle( press );
	printf( "销毁press句柄环境\n" );
	
	return 0;
}
Esempio n. 16
0
    bool MemoryTrunk::Reload(uint32_t minimum_size)
    {
        if (hashtable->NonEmptyEntryCount == 0)
            return true;

        //! Use pending_flag to notify other threads a high-priority task is ongoing
        defrag_lock.lock(pending_flag);

        HeadGroup temp_head_group;

        hashtable->GetAllEntryLocksExceptArena();

        FlushDecommitBuffer(); //! Before the actual reload, decommit all buffered memory

        temp_head_group.append_head = (uint32_t)ReloadImpl(); // Update hashtable.CellEntries

        InfoLog("Memory trunk {0} reloaded.", TrunkId);

        if (temp_head_group.append_head == 0xFFFFFFFF) //Reload buffer allocation failed!
        {
            hashtable->ReleaseAllEntryLocksExceptArena();
            defrag_lock.unlock();

            Trinity::Diagnostics::FatalError("Trunk: {0}, run out of memory during trunk reloading, buffer allocation failed. \n MemoryTrunk: Reload: Out of memory", TrunkId);
        }

        uint32_t available_space = TrunkLength - temp_head_group.append_head;
        if (available_space < minimum_size)
        {
            hashtable->ReleaseAllEntryLocksExceptArena();
            defrag_lock.unlock();
            Trinity::Diagnostics::FatalError("Trunk: {0}, run out of memory during trunk reloading, available size: {1}, required size: {2}. \n MemoryTrunk: Reload: Out of memory", TrunkId, available_space, minimum_size);
        }

        temp_head_group.committed_head = (temp_head_group.append_head + Memory::PAGE_RANGE) & Memory::PAGE_MASK;
        committed_tail = 0;

        hashtable->ReleaseAllEntryLocksExceptArena();

        head.head_group.store(temp_head_group.head_group);
        //Console.WriteLine("Reloaded: append head: {0} committed_head: {1}", head.append_head, head.committed_head);
        IsAddressTableValid.store(false); //! Reloading will invalidate the address table
        defrag_lock.unlock();
        return true;
    }
Esempio n. 17
0
static int cgiclean( struct Weixin4cEnv *penv )
{
	int		nret = 0 ;
	
	if( penv->pconf->funcs.pfuncCleanEnvProc )
	{
		nret = penv->pconf->funcs.pfuncCleanEnvProc( penv->pconf->user_data ) ;
		if( nret )
		{
			ErrorLog( __FILE__ , __LINE__ , "pfuncCleanEnvProc failed[%d]" , nret );
		}
		else
		{
			InfoLog( __FILE__ , __LINE__ , "pfuncCleanEnvProc ok" );
		}
	}
	
	return 0;
}
Esempio n. 18
0
bool NSC::ProbePort()
{	
//	DebugLog("Probing NSC...");
	UInt16 id = ListenPortByte(SUPERIO_CHIP_ID_REGISTER);	
	UInt8 revision = ListenPortByte(NSC_CHIP_REVISION_REGISTER);
	if (id == 0 || id == 0xff || revision == 0 || revision == 0xff)
		return false;
	if ((id == 0xfc) /* && (revision == 0x66)*/) {
		Select(NSC_HARDWARE_MONITOR_LDN);
		
		m_Address = ListenPortWord(SUPERIO_BASE_ADDRESS_REGISTER); 
		if (!ListenPortByte(NSC_LDN_PRESENT)) {
			return false;
		}
		
		InfoLog("NSC: Found supported chip ID=0x%x REVISION=0x%x on ADDRESS=0x%x", id, revision, m_Address);
		m_Model = PC8739x;
		return true;

	}
		else
	{
//			InfoLog("found unsupported NSC chip ID=0x%x REVISION=0x%x on ADDRESS=0x%x", id, revision, m_Address);
#if 0
			//Slice - registers dump for development purpose
			IOLog("NSC ldn=15 registers dump\n");
			for (UInt16 k=0x0; k<0xff; k+=16) {
				IOLog("%02x: ", k);
				for (UInt16 j=0; j<16; j++) {
					IOLog("%02x ", ListenPortByte(k+j));
				}
				IOLog("\n");
			}
			return true; //Slice - temporarily
			
#endif
			
		return false;
	} 
}
Esempio n. 19
0
void Nin10Edit::OnOpen(wxCommandEvent& event)
{
    EventLog l(__func__);
    std::unique_ptr<wxFileDialog> filedlg(new wxFileDialog(this, _("Open Image"), "", "", wxFileSelectorDefaultWildcardStr,
                                                           wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR | wxFD_PREVIEW | wxFD_OPEN));
    if (filedlg->ShowModal() == wxID_CANCEL)
    {
        WarnLog("No image given");
        return;
    }


    std::string file = filedlg->GetPath().ToStdString();
    InfoLog("Got file: %s", file.c_str());
    images.emplace(file, file);
    ConvertToMode4(images, images8);

    auto* graphics_panel = new GraphicsEditorPanel(graphics_notebook);
	graphics_notebook->AddPage(graphics_panel, file, false);

    graphics_panel->SetImage(&images8[0]);
    palette_panel->SetPalette(images8[0].palette);
}
Esempio n. 20
0
int test_press( long count )
{
	LongToLong	llBegin , llEnd , llDiff ;
	double		dPerf ;
	long		l ;
	
	llBegin = GetUnixSecondsExactly() ;
	for( l = 1 ; l <= count ; l++ )
	{
		InfoLog( __FILE__ , __LINE__ , "log" );
	}
	llEnd = GetUnixSecondsExactly() ;
	llDiff.high = llEnd.high - llBegin.high ;
	llDiff.low = llEnd.low - llBegin.low ;
	if( llDiff.low < 0 )
	{
		llDiff.low += 1000000 ;
		llDiff.high--;
	}
	dPerf = (double)(count) / ( (double)(llDiff.high) + (double)(llDiff.low) / 1000000 ) ;
	/* printf( "总耗时[%ld.%03ld] 平均每秒输出行日志[%.2lf]条\n" , llDiff.high , llDiff.low , dPerf ); */
	
	return 0;
}
IOReturn
IOFWUserLocalIsochPort::userNotify (
		UInt32			notificationType,
		UInt32			numDCLs,
		void *			data,
		IOByteCount		dataSize )
{
	InfoLog("+IOFWUserLocalIsochPort::userNotify, numDCLs=%ld\n", numDCLs ) ;
	if ( __builtin_expect( numDCLs > 64, false ) )
	{
		return kIOReturnBadArgument ;
	}

	IOFWDCL * 			dcls[ numDCLs ] ;
	const OSArray *		program 		= fDCLPool->getProgramRef() ;
	unsigned 			programLength	= program->getCount() ;
	IOReturn			error			= kIOReturnSuccess ;
	
	switch( (IOFWDCLNotificationType)notificationType )
	{
		case kFWNuDCLModifyNotification :
		{
			IOMemoryMap * bufferMap = fProgram->getBufferMap() ;
			for( unsigned index=0; index < numDCLs; ++index )
			{
				unsigned dclIndex = *(unsigned*)data - 1 ;
				if ( dclIndex >= programLength )
				{
					DebugLog("out of range DCL dclIndex=%d, programLength=%d\n", dclIndex, programLength ) ;
					error = kIOReturnBadArgument ;
				}
				else
				{
					dcls[ index ] = (IOFWDCL*)program->getObject( dclIndex ) ;
					
					data = (UInt8*)data + sizeof( unsigned ) ;
					IOByteCount dataSize ;
					
					error = dcls[ index ]->importUserDCL( (UInt8*)data, dataSize, bufferMap, program ) ;

					// if there is no branch set, make sure the DCL "branches" to the 
					// dcl that comes next in the program if there is one...
					if ( dclIndex + 1 < programLength && !dcls[ index ]->getBranch() )
					{
						dcls[ index ]->setBranch( (IOFWDCL*)program->getObject( dclIndex + 1 ) ) ;
					}
					
					data = (UInt8*)data + dataSize ;
				}

				if ( error )
				{
					break ;
				}
			}
			
			break ;
		}
		
		case kFWNuDCLModifyJumpNotification :
		{
			unsigned * dclIndexTable = (unsigned*)data ;
			
			// subtract 1 from each index in our list.
			// when the notification type is kFWNuDCLModifyJumpNotification, the dcl list
			// actually contains pairs of DCL indices. The first is the dcl having its branch modified,
			// the second is the index of the DCL to branch to.
			{
				unsigned index = 0 ;
				unsigned pairIndex = 0 ;

				while( pairIndex < numDCLs )
				{
					--dclIndexTable[ index ] ;
					if ( dclIndexTable[ index ] >= programLength )
					{
						DebugLog("out of range DCL index=%d, dclIndices[ index ]=%d, programLength=%d\n", index, dclIndexTable[ index ], programLength ) ;
						error = kIOReturnBadArgument ;
						break ;
					}

					dcls[ pairIndex ] = (IOFWDCL*)program->getObject( dclIndexTable[ index ] ) ;
					
					++index ;
					
					if (dclIndexTable[ index ])
					{
						--dclIndexTable[ index ] ;
						
						if ( dclIndexTable[ index ] >= programLength )
						{
							DebugLog("out of range DCL index=%d, dclIndices[ index ]=%d, programLength=%d\n", index, dclIndexTable[ index ], programLength ) ;
							error = kIOReturnBadArgument ;
							break ;						
						}
						
						dcls[ pairIndex ]->setBranch( (IOFWDCL*)program->getObject( dclIndexTable[ index ] ) ) ;
					}
					else
					{
						dcls[ pairIndex ]->setBranch( 0 ) ;
					}

					++index ;
					++pairIndex ;
				}
			}

			break ;
		}
		
		case kFWNuDCLUpdateNotification :
		{
			unsigned index = 0 ;
			while ( index < numDCLs )
			{
				unsigned * dclIndices = (unsigned*)data ;
				
				--dclIndices[ index ] ;
				if ( __builtin_expect( dclIndices[ index ] >= programLength, false ) )
				{
					DebugLog("out of range DCL index=%d, dclIndices[ index ]=%d, programLength=%d\n", index, dclIndices[ index ], programLength ) ;
					error = kIOReturnBadArgument ;
					break ;
				}
				
				dcls[ index ] = (IOFWDCL*)program->getObject( dclIndices[ index ] ) ;
				
				++index ;
			}

			break ;
		}
		
		default:
		{
			error = kIOReturnBadArgument ;
			DebugLog("unsupported notification type 0x%08x\n", (uint32_t)notificationType) ;
			break ;
		}
	}
	
	program->release() ;
	
	return error ? error : notify( (IOFWDCLNotificationType)notificationType, (DCLCommand**)dcls, numDCLs ) ;
}
Esempio n. 22
0
bool X3100monitor::start(IOService * provider)
{
	if (!provider || !super::start(provider)) return false;
	
	if (!(fakeSMC = waitForService(serviceMatching(kFakeSMCDeviceService)))) {
		WarningLog("Can't locate fake SMC device, kext will not load");
		return false;
	}
	
	IOMemoryDescriptor *		theDescriptor;
	IOPhysicalAddress bar = (IOPhysicalAddress)((VCard->configRead32(kMCHBAR)) & ~0xf);
	DebugLog("Fx3100: register space=%08lx\n", (long unsigned int)bar);
	theDescriptor = IOMemoryDescriptor::withPhysicalAddress (bar, 0x2000, kIODirectionOutIn); // | kIOMapInhibitCache);
	if(theDescriptor != NULL)
	{
		mmio = theDescriptor->map();
		if(mmio != NULL)
		{
			mmio_base = (volatile UInt8 *)mmio->getVirtualAddress();
#if DEBUG				
			DebugLog(" MCHBAR mapped\n");
			for (int i=0; i<0x2f; i +=16) {
				DebugLog("%04lx: ", (long unsigned int)i+0x1000);
				for (int j=0; j<16; j += 1) {
					DebugLog("%02lx ", (long unsigned int)INVID8(i+j+0x1000));
				}
				DebugLog("\n");
			}
#endif				
		}
		else
		{
			InfoLog(" MCHBAR failed to map\n");
			return -1;
		}			
	}	
	
	char name[5];
	//try to find empty key
	for (int i = 0; i < 0x10; i++) {
						
		snprintf(name, 5, KEY_FORMAT_GPU_DIODE_TEMPERATURE, i); 
			
		UInt8 length = 0;
		void * data = 0;
			
		IOReturn result = fakeSMC->callPlatformFunction(kFakeSMCGetKeyValue, true, (void *)name, (void *)&length, (void *)&data, 0);
			
		if (kIOReturnSuccess == result) {
			continue;
		}
		if (addSensor(name, TYPE_SP78, 2, i)) {
			numCard = i;
			break;
		}
	}
		
	if (kIOReturnSuccess != fakeSMC->callPlatformFunction(kFakeSMCAddKeyHandler, false, (void *)name, (void *)TYPE_SP78, (void *)2, this)) {
		WarningLog("Can't add key to fake SMC device, kext will not load");
		return false;
	}
	
	return true;	
}
Esempio n. 23
0
bool IT87x::start(IOService * provider)
{
	DebugLog("starting ...");
  
	if (!super::start(provider))
		return false;
	
	InfoLog("found ITE %s", getModelName());
  OSDictionary* list = OSDynamicCast(OSDictionary, getProperty("Sensors Configuration"));

  OSDictionary *configuration=NULL; 
  OSData *data;
  IORegistryEntry * rootNode = fromPath("/efi/platform", gIODTPlane);

  if(rootNode) {
    data = OSDynamicCast(OSData, rootNode->getProperty("OEMVendor"));
    if (data) {
      bcopy(data->getBytesNoCopy(), vendor, data->getLength());
      OSString * VendorNick = vendorID(OSString::withCString(vendor));
      if (VendorNick) {
        data = OSDynamicCast(OSData, rootNode->getProperty("OEMBoard"));
        if (!data) {
          WarningLog("no OEMBoard");
          data = OSDynamicCast(OSData, rootNode->getProperty("OEMProduct"));
        }
        if (data) {
          bcopy(data->getBytesNoCopy(), product, data->getLength());
          OSDictionary *link = OSDynamicCast(OSDictionary, list->getObject(VendorNick));
          if (link){
            configuration = OSDynamicCast(OSDictionary, link->getObject(OSString::withCString(product)));
            InfoLog(" mother vendor=%s product=%s", vendor, product);
          }
        }
      } else {
        WarningLog("unknown OEMVendor %s", vendor);
      }
    } else {
      WarningLog("no OEMVendor");
    }
  }
  
  if (list && !configuration) {
    configuration = OSDynamicCast(OSDictionary, list->getObject("Default"));
    WarningLog("set default configuration");
  }
  
  if(configuration) {
    this->setProperty("Current Configuration", configuration);
  }
	
	// Temperature Sensors
	if (configuration) {
		for (int i = 0; i < 3; i++) {
			char key[8];
			
			snprintf(key, 8, "TEMPIN%X", i);
      if(readTemperature(i)<MAX_TEMP_THRESHOLD) { // Need to check if temperature sensor valid
        if (OSString* name = OSDynamicCast(OSString, configuration->getObject(key))) {
          if (name->isEqualTo("CPU")) {
            if (!addSensor(KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, i)) {
              WarningLog("error adding heatsink temperature sensor");
            }
          }
          else if (name->isEqualTo("System")) {
            if (!addSensor(KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor,i)) {
              WarningLog("error adding system temperature sensor");
            }
          }
          else if (name->isEqualTo("Ambient")) {
            if (!addSensor(KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor,i)) {
              WarningLog("error adding Ambient temperature sensor");
            }
          }
        }
      }
		}
	}
	else {
    if(readTemperature(0)<MAX_TEMP_THRESHOLD)  // Need to check if temperature sensor valid
      if (!addSensor(KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 0)) {
        WarningLog("error adding heatsink temperature sensor");
      }
    if(readTemperature(1)<MAX_TEMP_THRESHOLD)  // Need to check if temperature sensor valid
      if (!addSensor(KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 1)) {
        WarningLog("error adding Ambient temperature sensor");
      }
    if(readTemperature(2)<MAX_TEMP_THRESHOLD)  // Need to check if temperature sensor valid
      if (!addSensor(KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 2)) {
        WarningLog("error adding system temperature sensor");
      }
	}
	
	
	// Voltage
  UInt8 tmp = readByte(address, ITE_ADC_CHANNEL_ENABLE);
  DebugLog("ADC Enable register = %X",tmp);
  
  vbat_updates = false;
  if(configuration)
  {
    OSBoolean* smartGuard = OSDynamicCast(OSBoolean, configuration->getObject("VBATNeedUpdates"));
    if(smartGuard && smartGuard->isTrue())
        vbat_updates=true;
  }
  // Refresh VBAT reading on each access to the key
  if(vbat_updates)
    writeByte(address, ITE_CONFIGURATION_REGISTER, readByte(address, ITE_CONFIGURATION_REGISTER) | 0x40);
  
	if (configuration) {
		for (int i = 0; i < 9; i++) {		
			char key[5];
      OSString * name;
      long Ri=0;
      long Rf=1;
      long Vf=0;
			
			snprintf(key, 5, "VIN%X", i);
			
			if (process_sensor_entry(configuration->getObject(key), &name, &Ri, &Rf, &Vf)) {
				if (name->isEqualTo("CPU")) {
					if (!addSensor(KEY_CPU_VRM_SUPPLY0, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf))
						WarningLog("error adding CPU voltage sensor");
				}
				else if (name->isEqualTo("Memory")) {
					if (!addSensor(KEY_MEMORY_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf))
						WarningLog("error adding memory voltage sensor");
				}
        else if (name->isEqualTo("+5VC")) {  
          if (!addSensor(KEY_5VC_VOLTAGE, TYPE_SP4B, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) {
            WarningLog("ERROR Adding AVCC Voltage Sensor!");
          }
        }
        else if (name->isEqualTo("+5VSB")) {  
          if (!addSensor(KEY_5VSB_VOLTAGE, TYPE_SP4B, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) {
            WarningLog("ERROR Adding AVCC Voltage Sensor!");
          }
        }                
        else if (name->isEqualTo("+12VC")) {
          if (!addSensor(KEY_12V_VOLTAGE, TYPE_SP4B, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) {
            WarningLog("ERROR Adding 12V Voltage Sensor!");
          }
        }
        else if (name->isEqualTo("-12VC")) {
          if (!addSensor(KEY_N12VC_VOLTAGE, TYPE_SP4B, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) {
            WarningLog("ERROR Adding 12V Voltage Sensor!");
          }
        }
        else if (name->isEqualTo("3VCC")) {
          if (!addSensor(KEY_3VCC_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) {
            WarningLog("ERROR Adding 3VCC Voltage Sensor!");
          }
        }
        
        else if (name->isEqualTo("3VSB")) {
          if (!addSensor(KEY_3VSB_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) {
            WarningLog("ERROR Adding 3VSB Voltage Sensor!");
          }
        }
        else if (name->isEqualTo("VBAT")) {
          if (!addSensor(KEY_VBAT_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i,Ri,Rf,Vf)) {
            WarningLog("ERROR Adding VBAT Voltage Sensor!");
          }
        }
			}
		}
	}
	
	// Tachometers
	for (int i = 0; i < 5; i++) {
		OSString* name = NULL;
		char key[5];
		if (configuration) {
			char key_temp[7];
			
			snprintf(key_temp, 7, "FANIN%X", i);
			
			name = OSDynamicCast(OSString, configuration->getObject(key_temp));
		}
		
		UInt32 nameLength = name ? (UInt32)strlen(name->getCStringNoCopy()) : 0;
		
		if (readTachometer(i) > 10 || nameLength > 0) {
      // Pff WTF ??? Add tachometer if it doesn't exist in a system but only the name defined in the config???   
       
			if (!addTachometer(i, (nameLength > 0 ? name->getCStringNoCopy() : 0)))
        // Need to look at this a bit later
				WarningLog("error adding tachometer sensor %d", i);      
    }
    
    // Check if this chip support SmartGuardian feature  
    
    hasSmartGuardian=false;
    if(configuration) {
      if(OSBoolean* smartGuard=OSDynamicCast(OSBoolean, configuration->getObject("SmartGuardian")))
        if(smartGuard->isTrue())
          hasSmartGuardian=true;      
    }
    
    if(hasSmartGuardian) {
      // Ugly development hack started for (SuperIOSensorGroup)
      snprintf(key,5,KEY_FORMAT_FAN_TARGET_SPEED,i);
      if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardPWMControl, i))
        WarningLog("error adding PWM fan control");
      
      snprintf(key,5,KEY_FORMAT_FAN_START_TEMP,i);
      if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanStart, i))
        WarningLog("error adding start temp fan control");
      
      snprintf(key,5,KEY_FORMAT_FAN_OFF_TEMP,i);
      if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanStop, i))
        WarningLog("error adding stop temp fan control");
      
      snprintf(key,5,KEY_FORMAT_FAN_FULL_TEMP,i);
      if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanFullOn, i))
        WarningLog("error adding full speed temp fan control");
      
      snprintf(key,5,KEY_FORMAT_FAN_START_PWM,i);
      if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardPWMStart, i))
        WarningLog("error adding start PWM fan control");
      
      snprintf(key,5,KEY_FORMAT_FAN_TEMP_DELTA,i);
      if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanFullOff, i))
        WarningLog("error adding temp full off fan control");
      
      snprintf(key,5,KEY_FORMAT_FAN_CONTROL,i);
      if (!addSensor(key, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardTempFanControl, i))
        WarningLog("error adding register fan control");
    }
	}
  if(hasSmartGuardian) {
    if (!addSensor(KEY_FORMAT_FAN_MAIN_CONTROL, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardMainControl, 0))
      WarningLog("error adding Main fan control"); 
    if (!addSensor(KEY_FORMAT_FAN_REG_CONTROL, TYPE_UI8, 1, (SuperIOSensorGroup)kSuperIOSmartGuardRegControl, 0))
      WarningLog("error adding Main fan control"); 
  }
	
	return true;	
}
Esempio n. 24
0
bool IT87x::start(IOService * provider)
{
	DebugLog("starting...");
	
	if (!super::start(provider)) 
		return false;
	
	InfoLog("found ITE %s", getModelName());
	
	OSDictionary* list = OSDynamicCast(OSDictionary, getProperty("Sensors Configuration"));
    OSDictionary* configuration = OSDynamicCast(OSDictionary, list->getObject(getModelName()));
	
    if (!configuration) 
        configuration = OSDynamicCast(OSDictionary, getProperty("Default"));
    
	// Temperature Sensors
	if (configuration) {
		for (int i = 0; i < 4; i++) 
		{				
			char key[8];
			
			snprintf(key, 8, "TEMPIN%X", i);
			
			if (OSString* name = OSDynamicCast(OSString, configuration->getObject(key)))
				if (name->isEqualTo("Processor")) {
					if (!addSensor(KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, i))
						WarningLog("error adding heatsink temperature sensor");
				}
				else if (name->isEqualTo("System")) {				
					if (!addSensor(KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor,i))
						WarningLog("error adding system temperature sensor");
				}
				else if (name->isEqualTo("Auxiliary")) {				
					if (!addSensor(KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor,i))
						WarningLog("error adding auxiliary temperature sensor");
				}
		}
	}
	else {
		if (!addSensor(KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 0))
			WarningLog("error adding heatsink temperature sensor");
		
		if (!addSensor(KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 1))
			WarningLog("error adding auxiliary temperature sensor");
		
		if (!addSensor(KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 2))
			WarningLog("error adding system temperature sensor");
	}
	
	
	// Voltage
	if (configuration) {
		for (int i = 0; i < 9; i++) //Zorglub
		{				
			char key[5];
			
			snprintf(key, 5, "VIN%X", i);
			
			if (OSString* name = OSDynamicCast(OSString, configuration->getObject(key))) {
				if (name->isEqualTo("Processor")) {
					if (!addSensor(KEY_CPU_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i))
						WarningLog("error adding CPU voltage sensor");
				}
				else if (name->isEqualTo("Memory")) {
					if (!addSensor(KEY_MEMORY_VOLTAGE, TYPE_FP2E, 2, kSuperIOVoltageSensor, i))
						WarningLog("error adding memory voltage sensor");
				}
			}
		}
	}
	
	// Tachometers
	for (int i = 0; i < 5; i++) {
		OSString* name = NULL;
		
		if (configuration) {
			char key[7];
			
			snprintf(key, 7, "FANIN%X", i);
			
			name = OSDynamicCast(OSString, configuration->getObject(key));
		}
		
		UInt64 nameLength = name ? strlen(name->getCStringNoCopy()) : 0;
		
		if (readTachometer(i) > 10 || nameLength > 0)
			if (!addTachometer(i, (nameLength > 0 ? name->getCStringNoCopy() : 0)))
				WarningLog("error adding tachometer sensor %d", i);
	}
	
	return true;	
}
Esempio n. 25
0
bool ACPIMonitor::start(IOService * provider)
{
    if (!super::start(provider))
        return false;

    acpiDevice = (IOACPIPlatformDevice *)provider;

    char key[5];

    //Here is Fan in ACPI
    OSArray* fanNames = OSDynamicCast(OSArray, getProperty("FanNames"));

    for (int i=0; i<10; i++)
    {
        snprintf(key, 5, "FAN%X", i);

        if (kIOReturnSuccess == acpiDevice->validateObject(key)) {
            OSString* name = NULL;

            if (fanNames )
                name = OSDynamicCast(OSString, fanNames->getObject(i));

            if (!addTachometer(key, name ? name->getCStringNoCopy() : 0))
                WarningLog("Can't add tachometer sensor, key %s", key);
        }
        else {
            snprintf(key, 5, "FTN%X", i);
            if (kIOReturnSuccess == acpiDevice->validateObject(key)) {
                OSString* name = NULL;

                if (fanNames )
                    name = OSDynamicCast(OSString, fanNames->getObject(i));

                if (!addTachometer(key, name ? name->getCStringNoCopy() : 0))
                    WarningLog("Can't add tachometer sensor, key %s", key);
            }
            else
                break;
        }
    }

    //Next step - temperature keys
    if (kIOReturnSuccess == acpiDevice->validateObject("TCPU"))
        addSensor("TCPU", KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, 2);

    if (kIOReturnSuccess == acpiDevice->validateObject("TSYS"))
        addSensor("TSYS", KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, 2);

    if (kIOReturnSuccess == acpiDevice->validateObject("TDIM"))
        addSensor("TDIM", KEY_DIMM_TEMPERATURE, TYPE_SP78, 2);

    if (kIOReturnSuccess == acpiDevice->validateObject("TAMB"))
        addSensor("TAMB", KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2);

    if (kIOReturnSuccess == acpiDevice->validateObject("TCPP"))
        addSensor("TCPP", KEY_CPU_PROXIMITY_TEMPERATURE, TYPE_SP78, 2);
    // We should add also GPU reading stuff for those who has no supported plug in but have the value on EC registers



    //Voltage
    if (kIOReturnSuccess == acpiDevice->validateObject("VCPU"))
        addSensor("VSN0", KEY_CPU_VOLTAGE, TYPE_FP2E, 2);

    if (kIOReturnSuccess == acpiDevice->validateObject("VMEM"))
        addSensor("VSN0", KEY_MEMORY_VOLTAGE, TYPE_FP2E, 2);

    if (kIOReturnSuccess == acpiDevice->validateObject("VSN1"))
        addSensor("VSN1", "Vp0C", TYPE_FP2E, 2);

    if (kIOReturnSuccess == acpiDevice->validateObject("VSN2"))
        addSensor("VSN2", "Vp1C", TYPE_FP2E, 2);

    if (kIOReturnSuccess == acpiDevice->validateObject("VSN3"))
        addSensor("VSN3", "Vp2C", TYPE_FP2E, 2);

    //Amperage
    if (kIOReturnSuccess == acpiDevice->validateObject("ISN0"))
        addSensor("ISN0", "ICAC", TYPE_UI16, 2);

    if (kIOReturnSuccess == acpiDevice->validateObject("ISN1"))
        addSensor("ISN1", "Ip0C", TYPE_UI16, 2);

    if (kIOReturnSuccess == acpiDevice->validateObject("ISN2"))
        addSensor("ISN2", "Ip1C", TYPE_UI16, 2);

    if (kIOReturnSuccess == acpiDevice->validateObject("ISN3"))
        addSensor("ISN3", "Ip2C", TYPE_UI16, 2);

    //Power
    if (kIOReturnSuccess == acpiDevice->validateObject("PSN0"))
        addSensor("PSN0", "PC0C", TYPE_UI16, 2);

    if (kIOReturnSuccess == acpiDevice->validateObject("PSN1"))
        addSensor("PSN1", "PC1C", TYPE_UI16, 2);

    // AC Power/Battery
    if (kIOReturnSuccess == acpiDevice->validateObject("ACDC")) // Power Source Read AC/Battery
    {
        addSensor("ACDC", "ACEN", TYPE_UI8, 1);
        addSensor("ACDC", "ACFP", TYPE_FLAG, 1);
        addSensor("ACDC", "ACIN", TYPE_FLAG, 1);
    }
    // TODO real SMC returns ACID only when AC is plugged, if not is zeroed, so hardcoding it in plist is not OK IMHO
    // Same goes for ACIC, but no idea how we can get the AC current value..

    // Here if ACDC returns 0 we need to set the on battery BATP flag

    // Battery stuff, need to implement rest of the keys once i figure those
    if (kIOReturnSuccess == acpiDevice->validateObject("BAK0")) // Battery 0 Current
        addSensor("BAK0", "B0AC", TYPE_SI16, 2);

    if (kIOReturnSuccess == acpiDevice->validateObject("BAK1")) // Battery 0 Voltage
        addSensor("BAK1", "B0AV", TYPE_UI16, 2);

    //Keys from info.plist
    OSString *tmpString = 0;
    OSData   *tmpObj = 0;

//	UInt32 tmpUI32;
//	char tmpCString[7];
    char acpiName[5];
    char aKey[5];

    OSIterator *iter = 0;
    const OSSymbol *dictKey = 0;
    OSDictionary *keysToAdd = 0;

    keysToAdd = OSDynamicCast(OSDictionary, getProperty("keysToAdd"));
    if (keysToAdd) {
        iter = OSCollectionIterator::withCollection(keysToAdd);
        if (iter) {
            while ((dictKey = (const OSSymbol *)iter->getNextObject())) {
                tmpObj = 0;
                snprintf(acpiName, 5, "%s", dictKey->getCStringNoCopy());
                //WarningLog(" Found key %s", acpiName);
                tmpString = OSDynamicCast(OSString, keysToAdd->getObject(dictKey));
                if (tmpString) {
                    snprintf(aKey, 5, "%s", tmpString->getCStringNoCopy());
                    InfoLog("Custom name=%s key=%s", acpiName, aKey);
                    if (kIOReturnSuccess == acpiDevice->validateObject(acpiName)) {
                        if (aKey[0] == 'F') {
                            if (!addTachometer(aKey, acpiName))
                                WarningLog("Can't add tachometer sensor, key %s", aKey);

                        } else {
                            addSensor(acpiName, aKey, TYPE_UI16, 2);
                        }
                    }
                }
                else {
                    WarningLog(" no value for key %s", acpiName);
                }

            }

            iter->release();
        } else {
            WarningLog(" can't interate keysToAdd");
        }

    } else {
        WarningLog(" keysToAdd not found");
    }

    registerService(0);

    return true;
}
Esempio n. 26
0
IOReturn ACPIMonitor::callPlatformFunction(const OSSymbol *functionName, bool waitForFunction, void *param1, void *param2, void *param3, void *param4 )
{
    const char* name = (const char*)param1;
    void * data = param2;
//	UInt64 size = (UInt64)param3;
    OSString* key;
#if __LP64__
    UInt64 value;
#else
    UInt32 value;
#endif
    UInt16 val;

    if (functionName->isEqualTo(kFakeSMCSetValueCallback)) {
        if (name && data) {
            if ((key = OSDynamicCast(OSString, sensors->getObject(name)))) {
                InfoLog("Writing key=%s by method=%s value=%x", name, key->getCStringNoCopy(), *(UInt16*)data);
                OSObject * params[1];
                if (key->getChar(0) == 'F') {
                    val = decode_fpe2(*(UInt16*)data);
                } else {
                    val = *(UInt16*)data;
                }
                params[0] = OSDynamicCast(OSObject, OSNumber::withNumber((unsigned long long)val, 32));
                return acpiDevice->evaluateInteger(key->getCStringNoCopy(), &value, params, 1);

                /*
                 virtual IOReturn evaluateInteger( const OSSymbol * objectName,
                 UInt32 *         resultInt32,
                 OSObject *       params[]   = 0,
                 IOItemCount      paramCount = 0,
                 IOOptionBits     options    = 0 );
                 flags_num = OSNumber::withNumber((unsigned long long)flags, 32);
                 */

            }
            return kIOReturnBadArgument;
        }
        return kIOReturnBadArgument;

    }
    if (functionName->isEqualTo(kFakeSMCGetValueCallback)) {

        if (name && data) {
            if ((key = OSDynamicCast(OSString, sensors->getObject(name)))) {
                if (kIOReturnSuccess == acpiDevice->evaluateInteger(key->getCStringNoCopy(), &value)) {

                    val = 0;

                    if (key->getChar(0) == 'V') {
                        val = encode_fp2e(value);
                    }
                    else if (key->getChar(0) == 'F') {
                        if (key->getChar(1) == 'A') {
                            val = encode_fpe2(value);
                        } else if (key->getChar(1) == 'T') {
                            val = encode_fpe2(MEGA10 / value);
                        } else {
                            val = value;
                        }
                    }
                    else val = value;

                    bcopy(&val, data, 2);
                    return kIOReturnSuccess;
                }
            }

            return kIOReturnBadArgument;
        }

        //DebugLog("bad argument key name or data");

        return kIOReturnBadArgument;
    }

    return super::callPlatformFunction(functionName, waitForFunction, param1, param2, param3, param4);
}
	bool validate(GLuint const & ProgramName)
	{
		bool Error = false;

		// Pipeline object validation
		{
			GLint Status(0);
			GLint LengthMax(0);
			glValidateProgramPipeline(PipelineName);
			glGetProgramPipelineiv(PipelineName, GL_VALIDATE_STATUS, &Status);
			glGetProgramPipelineiv(PipelineName, GL_INFO_LOG_LENGTH, &LengthMax);

			GLsizei LengthQuery(0);
			std::vector<GLchar> InfoLog(LengthMax + 1, '\0');
			glGetProgramPipelineInfoLog(PipelineName, GLsizei(InfoLog.size()), &LengthQuery, &InfoLog[0]);

			glDebugMessageInsertARB(
				GL_DEBUG_SOURCE_APPLICATION_ARB, 
				GL_DEBUG_TYPE_OTHER_ARB, 76,
				GL_DEBUG_SEVERITY_LOW_ARB,
				LengthQuery, 
				&InfoLog[0]);
		}

		GLint ActiveAttributeMaxLength(0);
		GLint ActiveAttribute(0);
		glGetProgramiv(ProgramName, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &ActiveAttributeMaxLength);
		glGetProgramiv(ProgramName, GL_ACTIVE_ATTRIBUTES, &ActiveAttribute);

		GLsizei AttribLength(0);
		GLint AttribSize(0);
		GLenum AttribType(0);
		std::vector<GLchar> AttribName(ActiveAttributeMaxLength, '\0');

		for(GLint i = 0; i < ActiveAttribute; ++i)
		{
			glGetActiveAttrib(ProgramName,
				GLuint(i),
				GLsizei(ActiveAttributeMaxLength),
				&AttribLength,
				&AttribSize,
				&AttribType,
				&AttribName[0]);

			std::string NameString;
			NameString.insert(NameString.begin(), AttribName.begin(), AttribName.end());
			std::vector<GLchar> NameSwap(ActiveAttributeMaxLength, '\0');
			std::swap(AttribName, NameSwap);

			GLint AttribLocation = glGetAttribLocation(ProgramName, NameString.c_str());

			vertexattrib VertexAttrib;
			glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &VertexAttrib.Enabled);
			//glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &VertexAttrib.Binding);
			glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_SIZE, &VertexAttrib.Size);
			glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &VertexAttrib.Stride);
			glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_TYPE, &VertexAttrib.Type);
			glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &VertexAttrib.Normalized);
			glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_INTEGER, &VertexAttrib.Integer);
			glGetVertexAttribiv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_DIVISOR, &VertexAttrib.Divisor);

			glGetVertexAttribPointerv(AttribLocation, GL_VERTEX_ATTRIB_ARRAY_POINTER, &VertexAttrib.Pointer);

			if(GL_VERTEX_ATTRIB_ARRAY_INTEGER == GL_TRUE)
			{
				if(!(
					VertexAttrib.Type == GL_INT ||  
					VertexAttrib.Type == GL_INT_VEC2 || 
					VertexAttrib.Type == GL_INT_VEC3 || 
					VertexAttrib.Type == GL_INT_VEC4 || 
					VertexAttrib.Type == GL_UNSIGNED_INT || 
					VertexAttrib.Type == GL_UNSIGNED_INT_VEC2 || 
					VertexAttrib.Type == GL_UNSIGNED_INT_VEC3 || 
					VertexAttrib.Type == GL_UNSIGNED_INT_VEC4))
					return true;

				if(!(
					VertexAttrib.Type == GL_BYTE || 
					VertexAttrib.Type == GL_UNSIGNED_BYTE || 
					VertexAttrib.Type == GL_SHORT || 
					VertexAttrib.Type == GL_UNSIGNED_SHORT || 
					VertexAttrib.Type == GL_INT || 
					VertexAttrib.Type == GL_UNSIGNED_INT))
					return true;

				//if(AttribSize > 1)
				//GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT, GL_FLOAT, and GL_DOUBLE
			}
			else if(VertexAttrib.Long == GL_TRUE) // OpenGL Spec bug 
			{
				if( VertexAttrib.Type == GL_DOUBLE || 
					VertexAttrib.Type == GL_DOUBLE_VEC2 || 
					VertexAttrib.Type == GL_DOUBLE_VEC3 || 
					VertexAttrib.Type == GL_DOUBLE_VEC4 || 
					VertexAttrib.Type == GL_DOUBLE_MAT2 || 
					VertexAttrib.Type == GL_DOUBLE_MAT3 || 
					VertexAttrib.Type == GL_DOUBLE_MAT4 || 
					VertexAttrib.Type == GL_DOUBLE_MAT2x3 || 
					VertexAttrib.Type == GL_DOUBLE_MAT2x4 || 
					VertexAttrib.Type == GL_DOUBLE_MAT3x2 ||
					VertexAttrib.Type == GL_DOUBLE_MAT3x4 || 
					VertexAttrib.Type == GL_DOUBLE_MAT4x2 || 
					VertexAttrib.Type == GL_DOUBLE_MAT4x3)
				{
					if(VertexAttrib.Type != GL_DOUBLE)
						return true;
				}
				else// if((VertexAttrib.Normalized == GL_TRUE) || (GL_VERTEX_ATTRIB_ARRAY_FLOAT == GL_TRUE))
				{
					if(!(
						VertexAttrib.Type == GL_FLOAT ||  
						VertexAttrib.Type == GL_FLOAT_VEC2 || 
						VertexAttrib.Type == GL_FLOAT_VEC3 || 
						VertexAttrib.Type == GL_FLOAT_VEC4 || 
						VertexAttrib.Type == GL_FLOAT_MAT2 || 
						VertexAttrib.Type == GL_FLOAT_MAT3 || 
						VertexAttrib.Type == GL_FLOAT_MAT4 || 
						VertexAttrib.Type == GL_FLOAT_MAT2x3 || 
						VertexAttrib.Type == GL_FLOAT_MAT2x4 || 
						VertexAttrib.Type == GL_FLOAT_MAT3x2 || 
						VertexAttrib.Type == GL_FLOAT_MAT3x4 || 
						VertexAttrib.Type == GL_FLOAT_MAT4x2 || 
						VertexAttrib.Type == GL_FLOAT_MAT4x3))
						return true;

					// It could be any vertex array attribute type
				}
			}

			printf("glGetActiveAttrib(\n\t%d, \n\t%d, \n\t%d, \n\t%d, \n\t%d, \n\t%s)\n", 
				i, AttribLocation, AttribLength, AttribSize, AttribType, NameString.c_str());
		}

		return Error;
	}
bool
IOFWUserLocalIsochPort::initWithUserDCLProgram ( 
		AllocateParams * 			params,
		IOFireWireUserClient & 		userclient,
		IOFireWireController &		controller )
{
	// sanity checking
	if ( params->programExportBytes == 0 )
	{
		ErrorLog ( "No program!" ) ;
		return false ;
	}
	
	fLock = IORecursiveLockAlloc () ;
	if ( ! fLock )
	{
		ErrorLog ( "Couldn't allocate recursive lock\n" ) ;
		return false ;
	}

// init easy params

	fUserObj = params->userObj ;
	fUserClient = & userclient ;
	fDCLPool = NULL ;
	fProgramCount = 0;
	fStarted = false ;

	IOReturn error = kIOReturnSuccess ;
	
// get user program ranges:

	IOAddressRange * bufferRanges = new IOAddressRange[ params->bufferRangeCount ] ;
	if ( !bufferRanges )
	{
		error = kIOReturnNoMemory ;
	}
	
	if ( !error )
	{
		error = fUserClient->copyUserData(params->bufferRanges,(mach_vm_address_t)bufferRanges, sizeof ( IOAddressRange ) * params->bufferRangeCount ) ;
	}

// create descriptor for program buffers

	IOMemoryDescriptor * bufferDesc = NULL ;
	if ( ! error )
	{
		IOByteCount length = 0 ;
		for ( unsigned index = 0; index < params->bufferRangeCount; ++index )
		{
			length += bufferRanges[ index ].length ;
		}			
	
		bufferDesc = IOMemoryDescriptor::withAddressRanges (	bufferRanges, params->bufferRangeCount, kIODirectionOutIn, 
															fUserClient->getOwningTask() ) ;
		if ( ! bufferDesc )
		{
			error = kIOReturnNoMemory ;
		}
		else
		{
		
			// IOLog( "IOFWUserLocalIsochPort::initWithUserDCLProgram - checkMemoryInRange status 0x%08lx\n", checkMemoryInRange( bufferDesc, 0x000000001FFFFFFF ) );
		
			error = bufferDesc->prepare( kIODirectionPrepareToPhys32 ) ;
			
			FWTrace( kFWTIsoch, kTPIsochPortUserInitWithUserDCLProgram, (uintptr_t)(fUserClient->getOwner()->getController()->getLink()), error, length, 0 );
			
			// IOLog( "IOFWUserLocalIsochPort::initWithUserDCLProgram - prep 32 checkMemoryInRange status 0x%08lx\n", checkMemoryInRange( bufferDesc, 0x000000001FFFFFFF ) );
			
		}
	}
	
// create map for buffers; we will need to get a virtual address for them

	IOMemoryMap * bufferMap = NULL ;
	if ( !error )
	{
		bufferMap = bufferDesc->map() ;
		if ( !bufferMap )
		{
			DebugLog( "Couldn't map program buffers\n" ) ;
			error = kIOReturnVMError ;
		}
		
		bufferDesc->release() ;
	}
	
	IOMemoryDescriptor * userProgramExportDesc = NULL ;
	if ( !error )
	{
		userProgramExportDesc = IOMemoryDescriptor::withAddressRange( 
																	 params->programData, 
																	 params->programExportBytes, 
																	 kIODirectionOut, 
																	 fUserClient->getOwningTask() ) ;
	
	}

	// get map of program export data
	if ( userProgramExportDesc )
	{
		error = userProgramExportDesc->prepare() ;
	}
	
	if ( !error )	
	{
		DCLCommand * opcodes = NULL ;
		switch ( params->version )
		{
			case kDCLExportDataLegacyVersion :

				error = importUserProgram( userProgramExportDesc, params->bufferRangeCount, bufferRanges, bufferMap ) ;
				ErrorLogCond( error, "importUserProgram returned %x\n", error ) ;

				if ( ! error )
				{
					opcodes = (DCLCommand*)fProgramBuffer ;
				}
				
				break ;

			case kDCLExportDataNuDCLRosettaVersion :

				fDCLPool = fUserClient->getOwner()->getBus()->createDCLPool() ;
				
				if ( ! fDCLPool )
				{
					error = kIOReturnNoMemory ;
				}

				if ( !error )
				{
					error = fDCLPool->importUserProgram( userProgramExportDesc, params->bufferRangeCount, bufferRanges, bufferMap ) ;
				}
				
				fProgramBuffer = new UInt8[ sizeof( DCLNuDCLLeader ) ] ;
				{
					DCLNuDCLLeader * leader = (DCLNuDCLLeader*)fProgramBuffer ;
					{
						leader->pNextDCLCommand = NULL ;	// unused - always NULL
						leader->opcode = kDCLNuDCLLeaderOp ;
						leader->program = fDCLPool ;
					}
					
					opcodes = (DCLCommand*)leader ;
				}
				
				break ;
			
			default :
			
				ErrorLog ( "unsupported DCL program type\n" ) ;
				error = kIOReturnBadArgument ;
				
				break ;
		}
		
		ErrorLogCond( !opcodes, "Couldn't get opcodes\n" ) ;
		
		IODCLProgram * program = NULL ;
		
		if ( opcodes )
		{
//			IOFWLocalIsochPort::printDCLProgram( opcodes ) ;
		
			IOFireWireBus::DCLTaskInfoAux	infoAux ;
			{
				infoAux.version = 2 ;

				infoAux.u.v2.bufferMemoryMap = bufferMap ;
				infoAux.u.v2.workloop = params->options & kFWIsochPortUseSeparateKernelThread ? createRealtimeThread() : NULL ;
				infoAux.u.v2.options = (IOFWIsochPortOptions)params->options ;
			}
						
			IOFireWireBus::DCLTaskInfo info = { 0, 0, 0, 0, 0, 0, & infoAux } ;
			
			program = fUserClient->getOwner()->getController()->getLink()->createDCLProgram(	params->talking,
																								opcodes,
																								& info,
																								params->startEvent, 
																								params->startState,
																								params->startMask ) ;

			bufferMap->release() ;		// retained by DCL program
			bufferMap = NULL ;
			
			if (  infoAux.u.v2.workloop )
			{
				// If we created a custom workloop, it will be retained by the program...
				// We can release our reference...
				infoAux.u.v2.workloop->release() ;
			}
			
			DebugLogCond( !program, "createDCLProgram returned nil\n" ) ;
		}

		if ( program )
		{
			if ( ! super::init( program, & controller ) )
			{
				ErrorLog ( "IOFWUserIsochPort::init failed\n" ) ;
				error = kIOReturnError ;
			}
		}
		else
		{
			DebugLog ( "Couldn't create DCL program\n" ) ;
			error = kIOReturnNoMemory ;
		}
		
		userProgramExportDesc->complete() ;
		userProgramExportDesc->release() ;
		userProgramExportDesc = NULL ;
	}
	
	delete [] bufferRanges ;
	
	InfoLog( "-IOFWUserLocalIsochPort::initWithUserDCLProgram error=%x (build date "__TIME__" "__DATE__")\n", error ) ;

	return ( ! error ) ;
}
IOReturn
IOFWUserLocalIsochPort::importUserProgram (
		IOMemoryDescriptor *		userExportDesc,
		unsigned 					userBufferRangeCount, 
		IOAddressRange				userBufferRanges[],
		IOMemoryMap *				bufferMap )
{	
	IOReturn error = kIOReturnSuccess ;
	UInt8 *pUserImportProgramBuffer;
	
	// Allocate a temporary buffer to hold user-space exported program.
	if ( ! error )
	{
		pUserImportProgramBuffer = new UInt8[ userExportDesc->getLength() ] ;
		if ( !pUserImportProgramBuffer )
		{
			error = kIOReturnNoMemory ;
		}
	}
	
	// copy user program to kernel buffer:
	if ( !error )
	{
		unsigned byteCount = userExportDesc->readBytes( 0, (void*)pUserImportProgramBuffer, userExportDesc->getLength() ) ;
		if ( byteCount < userExportDesc->getLength() )
		{
			error = kIOReturnVMError ;
		}
	}
	
	// Allocate the buffer for the "real" kernel DCL program.
	if ( ! error )
	{
		fProgramBuffer = new UInt8[ userExportDesc->getLength() ] ;
		if ( !fProgramBuffer )
		{
			error = kIOReturnNoMemory ;
		}
	}
	
	DCLCommand *pCurrentDCL;
	UserExportDCLCommand *pExportDCL;
	UInt32 nextUserExportDCLOffset = 0;
	DCLCommand *pLastDCL = NULL;
	unsigned size; 
	do
	{
		pExportDCL = (UserExportDCLCommand*)(pUserImportProgramBuffer + nextUserExportDCLOffset);
		pCurrentDCL = (DCLCommand*)(fProgramBuffer + nextUserExportDCLOffset);
		
		UInt32 opcode = pExportDCL->opcode & ~kFWDCLOpFlagMask;
		
		// Sanity check
		if ( opcode > 15 && opcode != 20 )
		{
			DebugLog("found invalid DCL in export data\n") ;
			error = kIOFireWireBogusDCLProgram ;
			break ;
		}
		
		size = getDCLSize( pExportDCL ) ;

		// Set the "next" pointer in the previous DCL
		if (pLastDCL != NULL)
			pLastDCL->pNextDCLCommand = pCurrentDCL;
		pLastDCL = pCurrentDCL;
		
		switch ( opcode )
		{
			
			case kDCLSendPacketStartOp:
			//case kDCLSendPacketWithHeaderStartOp:
			case kDCLSendPacketOp:
			case kDCLReceivePacketStartOp:
			case kDCLReceivePacketOp:
				{
					DCLTransferPacket *pDCLTransferPacket = (DCLTransferPacket*) pCurrentDCL; 
					pDCLTransferPacket->opcode = pExportDCL->opcode;
					pDCLTransferPacket->compilerData = 0;
					//pDCLTransferPacket->buffer - handled by calls to getDCLDataBuffer/setDCLDataBuffer, below!
					//pDCLTransferPacket->size - handled by calls to getDCLDataBuffer/setDCLDataBuffer, below!
				}
				break ;
			
			case kDCLSendBufferOp:
			case kDCLReceiveBufferOp:
				{
					DCLTransferBuffer *pDCLTransferBuffer = (DCLTransferBuffer*) pCurrentDCL; 
					pDCLTransferBuffer->opcode = pExportDCL->opcode;
					pDCLTransferBuffer->compilerData = 0;
					//pDCLTransferBuffer->buffer - handled by calls to getDCLDataBuffer/setDCLDataBuffer, below!
					//pDCLTransferBuffer->size - handled by calls to getDCLDataBuffer/setDCLDataBuffer, below!
					pDCLTransferBuffer->packetSize = ((UserExportDCLTransferBuffer*)pExportDCL)->packetSize;
					pDCLTransferBuffer->reserved = ((UserExportDCLTransferBuffer*)pExportDCL)->reserved;
					pDCLTransferBuffer->bufferOffset = ((UserExportDCLTransferBuffer*)pExportDCL)->bufferOffset;
				}
				break ;
			
			case kDCLCallProcOp:
				{
					DCLCallProc *pDCLCallProc = (DCLCallProc*) pCurrentDCL; 
					pDCLCallProc->opcode = pExportDCL->opcode;
					pDCLCallProc->compilerData = 0;
					//pDCLCallProc->proc - handled by call to convertToKernelDCL, below
					//pDCLCallProc->procData - handled by call to convertToKernelDCL, below
					size += sizeof( uint64_t[kOSAsyncRef64Count] ) ;
					error = convertToKernelDCL( ((UserExportDCLCallProc*)pExportDCL), pDCLCallProc ) ;
				}
				break ;
			
			case kDCLLabelOp:
				{
					DCLLabel *pDCLLabel = (DCLLabel*) pCurrentDCL; 
					pDCLLabel->opcode = pExportDCL->opcode;
					pDCLLabel->compilerData = 0;
				}
				break ;
			
			case kDCLJumpOp:
				{
					DCLJump *pDCLJump = (DCLJump*) pCurrentDCL; 
					pDCLJump->opcode = pExportDCL->opcode;
					pDCLJump->compilerData = 0;
					//pDCLJump->pJumpDCLLabel - handled by call to convertToKernelDCL, below
					error = convertToKernelDCL( ((UserExportDCLJump*)pExportDCL), pDCLJump ) ;
				}
				break ;
			
			case kDCLSetTagSyncBitsOp:
				{
					DCLSetTagSyncBits *pDCLSetTagSyncBits = (DCLSetTagSyncBits*) pCurrentDCL; 
					pDCLSetTagSyncBits->opcode = pExportDCL->opcode;
					pDCLSetTagSyncBits->compilerData = 0;
					pDCLSetTagSyncBits->tagBits = ((UserExportDCLSetTagSyncBits*)pExportDCL)->tagBits;
					pDCLSetTagSyncBits->syncBits = ((UserExportDCLSetTagSyncBits*)pExportDCL)->syncBits;
				}
				break ;
			
			case kDCLUpdateDCLListOp:
				{
					DCLUpdateDCLList *pDCLUpdateDCLList = (DCLUpdateDCLList*) pCurrentDCL; 
					pDCLUpdateDCLList->opcode = pExportDCL->opcode;
					pDCLUpdateDCLList->compilerData = 0;
					//pDCLUpdateDCLList->dclCommandList - handled by call to convertToKernelDCL, below
					pDCLUpdateDCLList->numDCLCommands = ((UserExportDCLUpdateDCLList*)pExportDCL)->numDCLCommands;
					size += sizeof( mach_vm_address_t ) * ((UserExportDCLUpdateDCLList*)pExportDCL)->numDCLCommands ;
					error = convertToKernelDCL( ((UserExportDCLUpdateDCLList*)pExportDCL), pDCLUpdateDCLList ) ;
				}
				break ;
			
			case kDCLPtrTimeStampOp:
				{
					DCLPtrTimeStamp *pDCLPtrTimeStamp = (DCLPtrTimeStamp*) pCurrentDCL; 
					pDCLPtrTimeStamp->opcode = pExportDCL->opcode;
					pDCLPtrTimeStamp->compilerData = 0;
					//pDCLPtrTimeStamp->timeStampPtr - handled by calls to getDCLDataBuffer/setDCLDataBuffer, below!
				}
				break ;
			
			case kDCLSkipCycleOp:
				{
					DCLCommand *pDCLCommand = (DCLCommand*) pCurrentDCL; 
					pDCLCommand->opcode = pExportDCL->opcode;
					pDCLCommand->compilerData = 0;
					pDCLCommand->operands[0] = ((UserExportDCLCommand*)pExportDCL)->operands[0];
				}
				break ;
		}
		
		// Break out of the loop if we got an error!
		if (error)
			break;
		
		// Convert the DCL data pointers from user space to kernel space:
		// (new style programs will have this step performed automatically when the program
		// is imported to the kernel...)
		IOAddressRange tempRange ;
		tempRange.address = 0;		// supress warning
		tempRange.length = 0;		// supress warning
		if ( getDCLDataBuffer ( pExportDCL, tempRange.address, tempRange.length ) )
		{
			if ( tempRange.address != NULL && tempRange.length > 0 )
			{
				IOByteCount offset ;
				if ( ! findOffsetInRanges (	tempRange.address, userBufferRangeCount, userBufferRanges, offset ) )
				{
					DebugLog( "IOFWUserLocalIsochPort::initWithUserDCLProgram: couldn't find DCL data buffer in buffer ranges") ;
					error = kIOReturnError;
					break;
				}
				
				// set DCL's data pointer to point to same memory in kernel address space
				setDCLDataBuffer ( pCurrentDCL, bufferMap->getVirtualAddress() + offset, tempRange.length ) ;					
			}
		}
		
		// increment the count of DCLs
		++fProgramCount ;			
		
		// Break out of this loop if we found the end.
		if (pExportDCL->pNextDCLCommand == NULL)
			break;
		else
			nextUserExportDCLOffset += size;
		
		// Sanity Check
		if (nextUserExportDCLOffset >= userExportDesc->getLength())
		{
			error = kIOReturnError;
			break;
		}
	}while(1);
	
	if ( ! error )
	{
		// Set the "next" pointer in the last DCL to NULL
		pLastDCL->pNextDCLCommand = NULL;
		
		fDCLTable = new DCLCommand*[ fProgramCount ] ;
		
		InfoLog( "made DCL table, %d entries\n", fProgramCount ) ;
		
		if ( !fDCLTable )
			error = kIOReturnNoMemory ;
		
		if ( !error )
		{
			unsigned index = 0 ;
			for( DCLCommand * dcl = (DCLCommand*)fProgramBuffer; dcl != NULL; dcl = dcl->pNextDCLCommand )
			{
				if ( index >= fProgramCount )
					panic("dcl table out of bounds\n") ;
					
				fDCLTable[ index++ ] = dcl ;
			}
		}
	}

	// Need to delete the pUserImportProgramBuffer!
	if (pUserImportProgramBuffer)
		delete [] pUserImportProgramBuffer;
	
	return error ;
}
Esempio n. 30
0
bool PC8739x::start(IOService * provider)
{
	DebugLog("starting...");
	
	if (!super::start(provider)) 
		return false;
		
	InfoLog("found NSC %s, revision 0x%x", getModelName(), revision);
	
	OSDictionary* configuration = OSDynamicCast(OSDictionary, getProperty("Sensors Configuration"));
	
	UInt32 adr = 
		(listenPortByte(NSC_MEM) & 0xff) + 
		((listenPortByte(NSC_MEM + 1) << 8) & 0xff00) +
		((listenPortByte(NSC_MEM + 2) & 0xff) << 16) + 
		((listenPortByte(NSC_MEM + 3) & 0xff) << 24);
	
	IOPhysicalAddress bar = (IOPhysicalAddress)(adr & ~0xf);	
	
	if(IOMemoryDescriptor *theDescriptor = IOMemoryDescriptor::withPhysicalAddress(bar, 0x200, kIODirectionOutIn))
		if(mmio = theDescriptor->map()){
			mmioBase = (volatile UInt8 *)mmio->getVirtualAddress();
		}
		else {
			WarningLog("MCHBAR failed to map");
			return false;
		}			
	
	// Heatsink
	if (!addSensor(KEY_CPU_HEATSINK_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 2))
		WarningLog("error adding heatsink temperature sensor");

	// Northbridge
	if (!addSensor(KEY_NORTHBRIDGE_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 0))
		WarningLog("error adding system temperature sensor");
	
	// DIMM
	if (!addSensor(KEY_DIMM_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 1))
		WarningLog("error adding DIMM temperature sensor");
	
	// AUX
	if (!addSensor(KEY_AMBIENT_TEMPERATURE, TYPE_SP78, 2, kSuperIOTemperatureSensor, 3))
		WarningLog("error adding AUX temperature sensor");
	
	// Tachometers
//	for (int i = 0; i < 5; i++) {  //only one
		OSString* name = 0;
	int i=0;
		if (configuration) {
			char key[7];
			
			snprintf(key, 7, "FANIN%X", i);
			
			name = OSDynamicCast(OSString, configuration->getObject(key));
		}
		
		UInt32 nameLength = name ? name->getLength() : 0;
		
		if (readTachometer(i) > 10 || nameLength > 0)
			if (!addTachometer(i, (nameLength > 0 ? name->getCStringNoCopy() : 0)))
				WarningLog("error adding tachometer sensor %d", i);
//	}	
	
	return true;
}