bool IOEthernetInterface::initIfnetParams(struct ifnet_init_params *params)
{
	OSData *uniqueID;
	//get the default values
    super::initIfnetParams( params );
		
    uniqueID = OSDynamicCast(OSData, getProvider()->getProperty(kIOMACAddress));
    if ( (uniqueID == 0) || (uniqueID->getLength() != ETHER_ADDR_LEN) )
    {
        DLOG("%s: kIOMACAddress property access error (len %d)\n",
             getName(), uniqueID ? uniqueID->getLength() : 0);
        return false;
    }
	
	// fill in ethernet specific values
	params->uniqueid = uniqueID->getBytesNoCopy();
	params->uniqueid_len = uniqueID->getLength();
	params->family = APPLE_IF_FAM_ETHERNET;
	params->demux = ether_demux;
	params->add_proto = ether_add_proto;
	params->del_proto = ether_del_proto;
	params->framer = ether_frameout;
	params->check_multi = ether_check_multi;
	params->broadcast_addr = ether_broadcast_addr;
	params->broadcast_len = sizeof(ether_broadcast_addr);
    return true;
}
//====================================================================================================
// IOHIDEventService::handleServicePublicationGated
//====================================================================================================
void IOHIDEventSystem::handleServicePublicationGated(IOService * service)
{
    IOLog("IOHIDEventSystem::handleServicePublicationGated\n");

    EventServiceInfo    tempEventServiceInfo;
    OSData *            tempData;
    IOHIDEventService * eventService;
    
    if ( !(eventService = OSDynamicCast(IOHIDEventService, service)) )
        return;
    
    attach( eventService );

    tempEventServiceInfo.service = eventService;
    
    tempData = OSData::withBytes(&tempEventServiceInfo, sizeof(EventServiceInfo));
    
    if ( tempData )
    {
        _eventServiceInfoArray->setObject(tempData);
        tempData->release();
    }
    
    if ( _eventsOpen )
        registerEventSource( eventService );
        
}
/* pass in a NULL value if you just want to figure out the len */
boolean_t PEReadNVRAMProperty(const char *symbol, void *value,
                              unsigned int *len)
{
    OSObject  *obj;
    OSData *data;
    unsigned int vlen;

    if (!symbol || !len)
        goto err;

    if (init_gIOOptionsEntry() < 0)
        goto err;

    vlen = *len;
    *len = 0;

    obj = gIOOptionsEntry->getProperty(symbol);
    if (!obj)
        goto err;

    /* convert to data */
    data = OSDynamicCast(OSData, obj);
    if (!data) 
        goto err;

    *len  = data->getLength();
    vlen  = min(vlen, *len);
    if (value && vlen)
        memcpy((void *) value, data->getBytesNoCopy(), vlen);

    return TRUE;

err:
    return FALSE;
}
Exemple #4
0
OSObject* FileNVRAM::cast(const OSSymbol* key, OSObject* obj)
{
	const char* legacy[] = {
		"boot-args",
		"boot-script",
	};

	OSString* str = OSDynamicCast(OSString, key);

	if (str)
	{
		for (int i = 0; i < sizeof(legacy)/sizeof(char*); i++)
		{
			if (str->isEqualTo(legacy[i]))
			{
				LOG(NOTICE, "Found legacy key %s\n", str->getCStringNoCopy());

				// add null char, convert to OSString
				OSData* data = OSDynamicCast(OSData, obj);

				if (data)
				{
					data->appendByte(0x00, 1);

					return OSString::withCString((const char*)data->getBytesNoCopy());
				}
			}
		}
	}

	return obj;
}
IOReturn IOSharedInterruptController::disableInterrupt(IOService *nub,
						       int source)
{
  IOInterruptSource *interruptSources;
  long              vectorNumber;
  IOInterruptVector *vector;
  OSData            *vectorData;
  IOInterruptState  interruptState;
  
  interruptSources = nub->_interruptSources;
  vectorData = interruptSources[source].vectorData;
  vectorNumber = *(long *)vectorData->getBytesNoCopy();
  vector = &vectors[vectorNumber];
  
  interruptState = IOSimpleLockLockDisableInterrupt(controllerLock); 
  if (!vector->interruptDisabledSoft) {
    vector->interruptDisabledSoft = 1;
#if __ppc__
    sync();
    isync();
#endif
    vectorsEnabled--;
  }
  IOSimpleLockUnlockEnableInterrupt(controllerLock, interruptState);
  
  if (!getPlatform()->atInterruptLevel()) {
    while (vector->interruptActive);
#if __ppc__
    isync();
#endif
  }
  
  return kIOReturnSuccess;
}
bool IODTPlatformExpert::getModelName( char * name, int maxLength )
{
    OSData *		prop;
    const char *	str;
    int			len;
    char		c;
    bool		ok = false;

    maxLength--;

    prop = (OSData *) getProvider()->getProperty( gIODTCompatibleKey );
    if( prop ) {
	str = (const char *) prop->getBytesNoCopy();

	if( 0 == strncmp( str, "AAPL,", strlen( "AAPL," ) ))
	    str += strlen( "AAPL," );

	len = 0;
	while( (c = *str++)) {
	    if( (c == '/') || (c == ' '))
		c = '-';

	    name[ len++ ] = c;
	    if( len >= maxLength)
		break;
	}

	name[ len ] = 0;
	ok = true;
    }
    return( ok );
}
boolean_t PEWriteNVRAMProperty(const char *symbol, const void *value, 
                               const unsigned int len)
{
    const OSSymbol *sym;
    OSData *data;
    bool ret = false;

    if (!symbol || !value || !len)
        goto err;

    if (init_gIOOptionsEntry() < 0)
        goto err;

    sym = OSSymbol::withCStringNoCopy(symbol);
    if (!sym)
        goto err;

    data = OSData::withBytes((void *) value, len);
    if (!data)
        goto sym_done;

    ret = gIOOptionsEntry->setProperty(sym, data);
    data->release();

sym_done:
    sym->release();

    if (ret == true) {
        gIOOptionsEntry->sync();
        return TRUE;
    }

err:
    return FALSE;
}
IOReturn IOInterruptController::enableInterrupt(IOService *nub, int source)
{
  IOInterruptSource *interruptSources;
  IOInterruptVectorNumber vectorNumber;
  IOInterruptVector *vector;
  OSData            *vectorData;
  
  interruptSources = nub->_interruptSources;
  vectorData = interruptSources[source].vectorData;
  vectorNumber = *(IOInterruptVectorNumber *)vectorData->getBytesNoCopy();
  vector = &vectors[vectorNumber];
  
  if (vector->interruptDisabledSoft) {
    vector->interruptDisabledSoft = 0;
#if !defined(__i386__) && !defined(__x86_64__)
    OSMemoryBarrier();
#endif

    if (!getPlatform()->atInterruptLevel()) {
      while (vector->interruptActive)
	{}
    }
    if (vector->interruptDisabledHard) {
      vector->interruptDisabledHard = 0;
      
      enableVector(vectorNumber, vector);
    }
  }
  
  return kIOReturnSuccess;
}
IOService* 
OHareATA::probe(IOService* provider,	SInt32*	score)
{

    OSData		*compatibleEntry;
	
	DLOG("OHareATA starting probe\n");


	compatibleEntry  = OSDynamicCast( OSData, provider->getProperty( "compatible" ) );
	if ( compatibleEntry == 0 ) 
	{
		// error unknown controller type.

		DLOG("OHareATA failed getting compatible property\n");
		return 0;

	}

	
	// test the compatible property for a match to the controller type name.
	if ( compatibleEntry->isEqualTo( kCompatibleString, sizeof(kCompatibleString)-1 ) == false ) 
	{
		// not our type of controller		
		DLOG("OHareATA compatible property doesn't match\n");
		return 0;
		
	}

	// ok, it is the type of cell we control
	
	return this;


}
Exemple #10
0
bool FakeSMC::init(OSDictionary *properties)
{	
	if (!super::init(properties))
		return false;
    
    IOLog("FakeSMC v%s Copyright %d netkas, slice, usr-sse2, kozlek, navi, THe KiNG, RehabMan. All rights reserved.\n", HWSENSORS_VERSION_STRING, HWSENSORS_LASTYEAR);

    if (IORegistryEntry *efi = IORegistryEntry::fromPath("/efi", gIODTPlane)) {
        if (OSData *vendor = OSDynamicCast(OSData, efi->getProperty("firmware-vendor"))) { // firmware-vendor is in EFI node
            OSData *buffer = OSData::withCapacity(128);
            const unsigned char* data = static_cast<const unsigned char*>(vendor->getBytesNoCopy());
            
            for (unsigned int index = 0; index < vendor->getLength(); index += 2) {
                buffer->appendByte(data[index], 1);
            }
            
            OSString *name = OSString::withCString(static_cast<const char *>(buffer->getBytesNoCopy()));
            
            setProperty(kFakeSMCFirmwareVendor, name);
            
            //OSSafeRelease(vendor);
            //OSSafeRelease(name);
            OSSafeRelease(buffer);
        }
        
        OSSafeRelease(efi);
    }
		
	return true;
}
IOReturn IOSharedInterruptController::enableInterrupt(IOService *nub,
						      int source)
{
  IOInterruptSource *interruptSources;
  IOInterruptVectorNumber vectorNumber;
  IOInterruptVector *vector;
  OSData            *vectorData;
  IOInterruptState  interruptState;
  
  interruptSources = nub->_interruptSources;
  vectorData = interruptSources[source].vectorData;
  vectorNumber = *(IOInterruptVectorNumber *)vectorData->getBytesNoCopy();
  vector = &vectors[vectorNumber];
  
  interruptState = IOSimpleLockLockDisableInterrupt(controllerLock);
  if (!vector->interruptDisabledSoft) {
    IOSimpleLockUnlockEnableInterrupt(controllerLock, interruptState);
    return kIOReturnSuccess;
  }
  
  vector->interruptDisabledSoft = 0;
  vectorsEnabled++;
  IOSimpleLockUnlockEnableInterrupt(controllerLock, interruptState);
  
  if (controllerDisabled && (vectorsEnabled == vectorsRegistered)) {
    controllerDisabled = 0;
    provider->enableInterrupt(0);
  }
  
  return kIOReturnSuccess;
}
IOReturn IOSharedInterruptController::disableInterrupt(IOService *nub,
						       int source)
{
  IOInterruptSource *interruptSources;
  IOInterruptVectorNumber vectorNumber;
  IOInterruptVector *vector;
  OSData            *vectorData;
  IOInterruptState  interruptState;
  
  interruptSources = nub->_interruptSources;
  vectorData = interruptSources[source].vectorData;
  vectorNumber = *(IOInterruptVectorNumber *)vectorData->getBytesNoCopy();
  vector = &vectors[vectorNumber];
  
  interruptState = IOSimpleLockLockDisableInterrupt(controllerLock); 
  if (!vector->interruptDisabledSoft) {
    vector->interruptDisabledSoft = 1;
#if !defined(__i386__) && !defined(__x86_64__)
    OSMemoryBarrier();
#endif

    vectorsEnabled--;
  }
  IOSimpleLockUnlockEnableInterrupt(controllerLock, interruptState);
  
  if (!getPlatform()->atInterruptLevel()) {
    while (vector->interruptActive)
	{}
  }
  
  return kIOReturnSuccess;
}
Exemple #13
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;
}
OSReturn NoSleepExtension::writeNVRAM(UInt8 value)
{
#ifdef DEBUG
    IOLog("%s: writing nvram, value: 0x%02x\n", getName(), value);
#endif
    
    bool ret;
    IORegistryEntry *entry = IORegistryEntry::fromPath( "/options", gIODTPlane );
    if ( entry )
    {
        OSData *dataToSave = OSData::withBytes(&value, 1);
        
        ret = entry->setProperty(IORegistrySleepSuppressionMode, dataToSave);
        
        dataToSave->release();
        entry->release();
#ifdef DEBUG
        IOLog("%s: writing nvram, result: %s\n", getName(), ret?"true":"false");
#endif
    } else {
        return kOSReturnError;
    }
    
    return ret?kOSReturnSuccess:kOSReturnError;
}
bool NullEthernet::init(OSDictionary *properties)
{
    DebugLog("init() ===>\n");

    if (!super::init(properties))
    {
        DebugLog("super::init failed\n");
        return false;
    }

    m_pProvider = NULL;
    m_netif = NULL;
    m_isEnabled = false;
    unitNumber = 0;

    // load default MAC address (can be overridden in DSDT)
    static unsigned char rgDefault[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
    bcopy(rgDefault, m_rgMacAddr, kIOEthernetAddressSize);
    if (properties)
    {
        OSData* pData = OSDynamicCast(OSData, properties->getObject("MAC-address"));
        if (pData && pData->getLength() == kIOEthernetAddressSize)
            bcopy(pData->getBytesNoCopy(), m_rgMacAddr, kIOEthernetAddressSize);
    }

    DebugLog("init() <===>\n");
    return true;
}
IOReturn IOInterruptController::disableInterrupt(IOService *nub, int source)
{
  IOInterruptSource *interruptSources;
  long              vectorNumber;
  IOInterruptVector *vector;
  OSData            *vectorData;
  
  interruptSources = nub->_interruptSources;
  vectorData = interruptSources[source].vectorData;
  vectorNumber = *(long *)vectorData->getBytesNoCopy();
  vector = &vectors[vectorNumber];
  
  vector->interruptDisabledSoft = 1;
#if __ppc__
  sync();
  isync();
#endif
  
  if (!getPlatform()->atInterruptLevel()) {
    while (vector->interruptActive);
#if __ppc__
    isync();
#endif
  }
  
  return kIOReturnSuccess;
}
UInt32 PCIDeviceStub_XHCIMux::getUInt32Property(const char* name)
{
    UInt32 result = 0;
    OSData* data = OSDynamicCast(OSData, getProperty(name));
    if (data && data->getLength() == 4)
        result = *static_cast<const UInt32*>(data->getBytesNoCopy());
    return result;
}
bool PCIDeviceStub_XHCIMux::getBoolProperty(const char* name, bool defValue)
{
    bool result = defValue;
    OSData* data = OSDynamicCast(OSData, getProperty(name));
    if (data && data->getLength() == 1)
        result = *static_cast<const UInt8*>(data->getBytesNoCopy());
    return result;
}
bool IOEthernetInterface::controllerDidOpen(IONetworkController * ctr)
{
    bool                 ret = false;
    OSData *             addrData;
    IOEthernetAddress *  addr;

    do {
        // Call the controllerDidOpen() in superclass first.

        if ( (ctr == 0) || (super::controllerDidOpen(ctr) == false) )
             break;

        // If the controller supports some form of multicast filtering,
        // then set the ifnet IFF_MULTICAST flag.

        if ( GET_SUPPORTED_FILTERS(gIONetworkFilterGroup) &
             (kIOPacketFilterMulticast | kIOPacketFilterMulticastAll) )
        {
            setFlags(IFF_MULTICAST);
        }

        // Advertise Wake on Magic Packet feature if supported.
        
        if ( _supportedWakeFilters & kIOEthernetWakeOnMagicPacket )
        {
            IOPMrootDomain * root = getPMRootDomain();
            if ( root ) root->publishFeature( kWOMPFeatureKey,
                             kIOPMSupportedOnAC | kIOPMSupportedOnUPS, 
                             (uint32_t *)&_publishedFeatureID);
        }

        // Get the controller's MAC/Ethernet address.

        addrData = OSDynamicCast(OSData, ctr->getProperty(kIOMACAddress));
        if ( (addrData == 0) || (addrData->getLength() != ETHER_ADDR_LEN) )
        {
            DLOG("%s: kIOMACAddress property access error (len %d)\n",
                 getName(), addrData ? addrData->getLength() : 0);
            break;
        }

        addr = (IOEthernetAddress *) addrData->getBytesNoCopy();

        DLOG("%s: Ethernet address %02x:%02x:%02x:%02x:%02x:%02x\n",
              ctr->getName(),
              addr->bytes[0],
              addr->bytes[1],
              addr->bytes[2],
              addr->bytes[3],
              addr->bytes[4],
              addr->bytes[5]);

        ret = true;
    }
    while (0);

    return ret;
}
bool IOPlatformExpert::start( IOService * provider )
{
    IORangeAllocator *	physicalRanges;
    OSData *		busFrequency;
    
    if (!super::start(provider))
      return false;

    // Register the presence or lack thereof a system 
    // PCI address mapper with the IOMapper class

#if 1
    IORegistryEntry * regEntry = IORegistryEntry::fromPath("/u3/dart", gIODTPlane);
    if (!regEntry)
	regEntry = IORegistryEntry::fromPath("/dart", gIODTPlane);
    if (regEntry) {
	int debugFlags;
	if (!PE_parse_boot_arg("dart", &debugFlags) || debugFlags)
	    setProperty(kIOPlatformMapperPresentKey, kOSBooleanTrue);
	regEntry->release();
    }
#endif

    IOMapper::setMapperRequired(0 != getProperty(kIOPlatformMapperPresentKey));
    
    gIOInterruptControllers = OSDictionary::withCapacity(1);
    gIOInterruptControllersLock = IOLockAlloc();
    
    // Correct the bus frequency in the device tree.
    busFrequency = OSData::withBytesNoCopy((void *)&gPEClockFrequencyInfo.bus_clock_rate_hz, 4);
    provider->setProperty("clock-frequency", busFrequency);
    busFrequency->release();
    
    gPlatformInterruptControllerName = (OSSymbol *)OSSymbol::withCStringNoCopy("IOPlatformInterruptController");
    
    physicalRanges = IORangeAllocator::withRange(0xffffffff, 1, 16,
						 IORangeAllocator::kLocking);
    assert(physicalRanges);
    setProperty("Platform Memory Ranges", physicalRanges);
    
    setPlatform( this );
    gIOPlatform = this;
    
    PMInstantiatePowerDomains();
    
    // Parse the serial-number data and publish a user-readable string
    OSData* mydata = (OSData*) (provider->getProperty("serial-number"));
    if (mydata != NULL) {
        OSString *serNoString = createSystemSerialNumberString(mydata);
        if (serNoString != NULL) {
            provider->setProperty(kIOPlatformSerialNumberKey, serNoString);
            serNoString->release();
        }
    }
    
    return( configure(provider) );
}
Exemple #21
0
// TODO: is it safe to make the data in here static?  It would speed things up slightly.
IOReturn com_veltrop_taylor_driver_virtualhid::setProperties( OSObject * properties )
{
	//IOLog("set properties to driver!!\n");
	OSData* data = OSDynamicCast(OSData, properties);
	if (data) {
		//	int length = data->getLength();	// passing a Hacked/Broken OSData object to this could make us unreliable, lets manually set 3 below, and later only explicitly access known memory!
		const UInt8* button_vector = (const UInt8*)data->getBytesNoCopy(0,3);
		// button_vector[0] -> button number / joystick number
		// button_vector[1] -> button state / button data
		// button_vector[2] -> button data 2
		
		if (_myReportBufferDescInternal) {
			UInt8 target = button_vector[0];
			if (target == hid_XYZ) {
				_myReportBufferDescInternal[0] = button_vector[1];
				_myReportBufferDescInternal[1] = button_vector[2];
			}
			else if (target == hid_rXYZ) {
				_myReportBufferDescInternal[2] = button_vector[1];
				_myReportBufferDescInternal[3] = button_vector[2];
			}
			else if (target == WiiRemoteUpButton || target == WiiRemoteDownButton) {	// swap x with y, the wii mote is probably rotated. > make this an option and do it from the wiiji side
				_myReportBufferDescInternal[0] = button_vector[1] * ((target == WiiRemoteDownButton)*(127) - (target == WiiRemoteUpButton)*(127)); 	// make sure these values stay exclusive
			}
			else if (target == WiiRemoteRightButton || target == WiiRemoteLeftButton) {
				_myReportBufferDescInternal[1] = button_vector[1] * ((target == WiiRemoteLeftButton)*(127) - (target == WiiRemoteRightButton)*(127));
			}
			else {				
				if (target >= WiiRemoteUpButton)	// compensate for the unused dpad button inputs (we route it to x/y right now)
					target -= 4;
				
				int bitoffset = target % 8;
				int octet     = target / 8 + 4;
				UInt8 action  = 0x0001 << bitoffset;
			
				if (octet >= myReportDescSize)
					return kIOReturnError;
			
				if (button_vector[1]) {
					_myReportBufferDescInternal[octet] = _myReportBufferDescInternal[octet] | action;
				}
				else {
					_myReportBufferDescInternal[octet] = _myReportBufferDescInternal[octet] & ~action;
				}
			} 
			
			if (handleReport(_myReportBufferDesc) != kIOReturnSuccess) {
				IOLog("com_veltrop_taylor_driver_virtualhid: handleReport failed in setProperties");
				return kIOReturnError;
			}
			
			return kIOReturnSuccess;
		}
	}
	
	return kIOReturnError;
}
Exemple #22
0
IOMapper * IOMapper::copyMapperForDeviceWithIndex(IOService * device, unsigned int index)
{
    OSData *data;
    OSObject * obj;
    IOMapper * mapper = NULL;
    OSDictionary * matching;
    
    obj = device->copyProperty("iommu-parent");
    if (!obj) return (NULL);

    if ((mapper = OSDynamicCast(IOMapper, obj))) goto found;

    if ((data = OSDynamicCast(OSData, obj)))
    {
        if (index >= data->getLength() / sizeof(UInt32)) goto done;
        
        data = OSData::withBytesNoCopy((UInt32 *)data->getBytesNoCopy() + index, sizeof(UInt32));
        if (!data) goto done;

        matching = IOService::propertyMatching(gIOMapperIDKey, data);
        data->release();
    }
    else
        matching = IOService::propertyMatching(gIOMapperIDKey, obj);

    if (matching)
    {
        mapper = OSDynamicCast(IOMapper, IOService::waitForMatchingService(matching));
        matching->release();
    }

done:
    if (obj) obj->release();
found:
    if (mapper)
    {
        if (!mapper->fAllocName)
        {
            char name[MACH_ZONE_NAME_MAX_LEN];
            char kmodname[KMOD_MAX_NAME];
            vm_tag_t tag;
            uint32_t kmodid;

            tag = IOMemoryTag(kernel_map);
            if (!(kmodid = vm_tag_get_kext(tag, &kmodname[0], KMOD_MAX_NAME)))
            {
                snprintf(kmodname, sizeof(kmodname), "%d", tag);
            }
            snprintf(name, sizeof(name), "%s.DMA.%s", kmodname, device->getName());
            mapper->fAllocName = kern_allocation_name_allocate(name, 16);
        }
    }

    return (mapper);
}
static bool GetUInt32( IORegistryEntry * regEntry, const OSSymbol * name,
			UInt32 * value )
{
    OSData	*data;

    if( (data = OSDynamicCast( OSData, regEntry->getProperty( name )))
      && (4 == data->getLength())) {
        *value = *((UInt32 *) data->getBytesNoCopy());
        return( true );
    } else
        return( false );
}
Exemple #24
0
void MacRISC2CPU::haltCPU(void)
{
	OSIterator 		*childIterator;
	IORegistryEntry *childEntry, *childDriver;
	IOPCIBridge		*pciDriver;
	OSData			*deviceTypeString;
	UInt32			i;

  
    setCPUState(kIOCPUStateStopped);
  
    if (bootCPU)
    {
		// Some systems require special handling of Ultra-ATA at sleep.
		// Call UniN to prepare for that, if necessary
		uniN->callPlatformFunction ("setupUATAforSleep", false, (void *)0, (void *)0, (void *)0, (void *)0);

		// Notify our pci children to save their state
		if (!topLevelPCIBridgeCount) {
			// First build list of top level bridges - only need to do once as these don't change
			if ((childIterator = macRISC2PE->getChildIterator (gIOServicePlane)) != NULL) {
				while ((childEntry = (IORegistryEntry *)(childIterator->getNextObject ())) != NULL) {
					deviceTypeString = OSDynamicCast( OSData, childEntry->getProperty( "device_type" ));
					if (deviceTypeString) {
						if (!strcmp((const char *)deviceTypeString->getBytesNoCopy(), "pci")) {
							childDriver = childEntry->copyChildEntry(gIOServicePlane);
							if (childDriver) {
								pciDriver = OSDynamicCast( IOPCIBridge, childDriver );
								if (pciDriver)
									if (topLevelPCIBridgeCount < kMaxPCIBridges)
										// Remember this driver
										topLevelPCIBridges[topLevelPCIBridgeCount++] = pciDriver;
									else
										kprintf ("MacRISC2CPU::haltCPU - warning, more than %d PCI bridges - cannot save/restore them all\n", kMaxPCIBridges);
								childDriver->release();
							}
						}
					}
				}
				childIterator->release();
			}
		}
		for (i = 0; i < topLevelPCIBridgeCount; i++)
			if (pciDriver = topLevelPCIBridges[i]) {
				// Got the driver - send the message
				pciDriver->setDevicePowerState (NULL, 2);
			}
    }

   kprintf("MacRISC2CPU::haltCPU %ld Here!\n", getCPUNumber());

   processor_exit(machProcessor);
}
//----------------------------------------------------------------------------------------------------
// IOHIDUserDevice::newReportDescriptor
//----------------------------------------------------------------------------------------------------
IOReturn IOHIDUserDevice::newReportDescriptor(IOMemoryDescriptor ** descriptor ) const
{
    OSData *                    data;
    
    data = OSDynamicCast(OSData, _properties->getObject(kIOHIDReportDescriptorKey));
    if ( !data )
        return kIOReturnError;
            
	*descriptor = IOBufferMemoryDescriptor::withBytes(data->getBytesNoCopy(), data->getLength(), kIODirectionNone);

	return kIOReturnSuccess;
}
bool NullEthernet::initMACfromProvider()
{
    bool result = false;
    OSData* pData = OSDynamicCast(OSData, m_pProvider->getProperty("RM,MAC-address"));
    if (pData && pData->getLength() == kIOEthernetAddressSize)
    {
        bcopy(pData->getBytesNoCopy(), m_rgMacAddr, kIOEthernetAddressSize);
        AlwaysLog("Using MAC address from provider: %02x:%02x:%02x:%02x:%02x:%02x\n", m_rgMacAddr[0], m_rgMacAddr[1], m_rgMacAddr[2], m_rgMacAddr[3], m_rgMacAddr[4], m_rgMacAddr[5]);
        result = true;
    }
    return result;
}
Exemple #27
0
void IODMAController::registerDMAController(IOOptionBits options)
{
    OSData *phandleData;

    phandleData = OSDynamicCast(OSData, _provider->getProperty("AAPL,phandle"));

    _dmaControllerName = createControllerName(*(UInt32 *)phandleData->getBytesNoCopy());

    setName(_dmaControllerName);

    registerService(options | ((options & kIOServiceAsynchronous) ? 0 : kIOServiceSynchronous));
}
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;
}
bool IODTPlatformExpert::getMachineName( char * name, int maxLength )
{
    OSData *		prop;
    bool		ok = false;

    maxLength--;
    prop = (OSData *) getProvider()->getProperty( gIODTModelKey );
    ok = (0 != prop);

    if( ok )
	strncpy( name, (const char *) prop->getBytesNoCopy(), maxLength );

    return( ok );
}
int VoodooI2CHIDDevice::i2c_get_slave_address(I2CDevice* hid_device){
    OSObject* result = NULL;
    
    hid_device->provider->evaluateObject("_CRS", &result);
    
    OSData* data = OSDynamicCast(OSData, result);
    
    hid_device->addr = *(int*)data->getBytesNoCopy(16,1) & 0xFF;

    data->release();
    
    return 0;
    
}