예제 #1
0
bool FakePCIID::hookProvider(IOService *provider)
{
    if (mDeviceVtable)
        return true;  // already hooked

    IOPCIDevice *device = OSDynamicCast(IOPCIDevice, provider);
    if (!device)
    {
        AlwaysLog("provider is not a IOPCIDevice: %s\n", provider->getMetaClass()->getClassName());
        return false;
    }

    // merge FakeProperties into the provider (only properties that do not exist)
    mergeFakeProperties(provider, "FakeProperties", false);
    mergeFakeProperties(provider, "FakeProperties-Forced", true);

    // hook provider IOPCIDevice vtable on attach/start
    mProvider = device;
    device->retain();

    mDeviceVtable = getVTable(device);
    setVTable(device, mStubVtable);

    return true;
}
예제 #2
0
파일: X3100.cpp 프로젝트: Beshuta/HWSensors
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;
}
예제 #3
0
IOService * AppleIntelPIIXATARoot::probe( IOService * provider,
                                          SInt32 *    score )
{
    IOPCIDevice * pciDevice;

    // Let our superclass probe first.

    if ( super::probe( provider, score ) == 0 )
    {
        return 0;
    }

    // Verify the provider type.

    pciDevice = OSDynamicCast( IOPCIDevice, provider );
    if ( pciDevice == 0 )
    {
        return 0;
    }

    // BIOS did not enable I/O space decoding.
    // For now assume the ATA controller is disabled.

    if ( (pciDevice->configRead16( kIOPCIConfigCommand ) &
          kIOPCICommandIOSpace) == 0 )
    {
        return 0;
    }

    return this;
}
IOService * AppleNForceATARoot::probe( IOService * provider, SInt32 * score )
{
    IOPCIDevice * pciDevice;

    // Let superclass probe first.

    if (super::probe( provider, score ) == 0)
    {
        return 0;
    }

    // Verify the provider is an IOPCIDevice.

    pciDevice = OSDynamicCast( IOPCIDevice, provider );
    if (pciDevice == 0)
    {
        return 0;
    }

    // Fail if I/O space decoding is disabled.

    if ((pciDevice->configRead16( kIOPCIConfigCommand ) &
         kIOPCICommandIOSpace) == 0)
    {
        return 0;
    }

    return this;
}
예제 #5
0
kern_return_t pmem_iokit_enumerate_pci(pmem_pci_callback_t callback,
                                       void *ctx) {
    kern_return_t error = KERN_FAILURE;
    OSObject *obj = nullptr;
    OSDictionary *search = nullptr;
    OSIterator *iter = nullptr;
    IOPCIDevice *dev = nullptr;
    IODeviceMemory *mem = nullptr;
    IOItemCount mem_count = 0;
    int cmp;

    search = IOService::serviceMatching("IOPCIDevice");
    iter = IOService::getMatchingServices(search);
    if (!iter) {
        pmem_error("Couldn't find any PCI devices.");
        goto bail;
    }

    while ((obj = iter->getNextObject())) {
        cmp = strncmp("IOPCIDevice",
                      obj->getMetaClass()->getClassName(),
                      strlen("IOPCIDevice"));
        if (cmp != 0) {
            // I haven't seen the above return anything other than
            // PCI devices, but Apple's documentation is sparse (which
            // is a nice word for what it is) and doesn't actually
            // say anything about what's guaranteed to be returned.
            // I'd just as well rather not chance it.
            pmem_warn("Expected IOPCIDevice but got %s - skipping.",
                      obj->getMetaClass()->getClassName());
            continue;
        }
        dev = (IOPCIDevice *)obj;
        mem_count = dev->getDeviceMemoryCount();
        pmem_debug("Found PCI device %s", dev->getName());

        for (unsigned idx = 0; idx < mem_count; ++idx) {
            pmem_debug("Memory segment %d found.", idx);
            mem = dev->getDeviceMemoryWithIndex(idx);
            pmem_signal_t signal = callback(dev, mem, idx, ctx);
            if (signal == pmem_Stop) {
                error = KERN_FAILURE;
                goto bail;
            }
        }
    }

    error = KERN_SUCCESS;

bail:
    if (iter) {
        iter->release();
    }

    if (search) {
        search->release();
    }

    return error;
}
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 AppleNForceATARoot::isaBridgePublished( void *      target,
                                          void *      param,
                                          IOService * service )
{
    IOPCIDevice *         bridge;
    AppleNForceATARoot *     root = (AppleNForceATARoot *) target;
    const ISABridgeInfo * info;
    UInt16                bridgeDID;
    UInt16                bridgeSubDID;
    //UInt8                 bridgeRev;

    if (root == 0)
        return false;

    bridge = OSDynamicCast( IOPCIDevice, service );
    if (bridge == 0)
        return false;

    bridgeDID = bridge->configRead16(kIOPCIConfigDeviceID);
	bridgeSubDID = bridge->configRead16(kIOPCIConfigSubSystemVendorID);
    //bridgeRev = bridge->configRead8(kIOPCIConfigRevisionID);
	
	DEBUG_LOG( "AppleNForceATARoot::%s( %p, %p, %p ) device/subdevice id: 0x%04x - 0x%04x.\n",
		__FUNCTION__, target, param, service, bridgeDID, bridgeSubDID );

    info = &gISABridges[0];
    while (info->deviceID)
    {
        if ( bridgeDID == info->deviceID || bridgeSubDID == info->deviceID )
            break;
        info++;
    }

    root->setProperty(kHardwareNameKey, info->name);
    root->fHardwareType  = info->hwType;
    root->fHardwareFlags = info->hwFlags;
    root->applyToClients( registerClientApplier, 0 );

    if (root->fISABridgeNotifier)
        root->fISABridgeNotifier->disable();

    return false;
}
예제 #8
0
파일: AppleMacIO.cpp 프로젝트: Algozjb/xnu
bool AppleMacIO::start( IOService * provider )
{
    IOPCIDevice *pciNub = (IOPCIDevice *)provider;

    if( !super::start( provider))
	return( false);

    // Make sure memory space is on.
    pciNub->setMemoryEnable(true);

    fNub = provider;
    fMemory = provider->mapDeviceMemoryWithIndex( 0 );
    if( 0 == fMemory)
	IOLog("%s: unexpected ranges\n", getName());
    else if( !selfTest())
	IOLog("Warning: AppleMacIO self test fails\n");
    PMinit();		// initialize for power management
    temporaryPowerClampOn();	// hold power on till we get children
    return( true);
}
IOReturn IntelMausi::setPowerStateWakeAction(OSObject *owner, void *arg1, void *arg2, void *arg3, void *arg4)
{
    IntelMausi *ethCtlr = OSDynamicCast(IntelMausi, owner);
    IOPCIDevice *dev;
    UInt16 val16;
    UInt8 offset;
    
    if (ethCtlr) {
        dev = ethCtlr->pciDevice;
        offset = ethCtlr->pciPMCtrlOffset;
        
        val16 = dev->configRead16(offset);
        
        val16 &= ~(kPCIPMCSPowerStateMask | kPCIPMCSPMEStatus | kPCIPMCSPMEEnable);
        val16 |= kPCIPMCSPowerStateD0;
        
        dev->configWrite16(offset, val16);
        
        /* Restore the PCI Command register. */
        ethCtlr->intelEnablePCIDevice(dev);
    }
    return kIOReturnSuccess;
}
IOReturn IntelMausi::setPowerStateSleepAction(OSObject *owner, void *arg1, void *arg2, void *arg3, void *arg4)
{
    IntelMausi *ethCtlr = OSDynamicCast(IntelMausi, owner);
    IOPCIDevice *dev;
    UInt16 val16;
    UInt8 offset;
    
    if (ethCtlr) {
        dev = ethCtlr->pciDevice;
        offset = ethCtlr->pciPMCtrlOffset;
        
        val16 = dev->configRead16(offset);
        
        val16 &= ~(kPCIPMCSPowerStateMask | kPCIPMCSPMEStatus | kPCIPMCSPMEEnable);
        
        if (ethCtlr->wolActive)
            val16 |= (kPCIPMCSPMEStatus | kPCIPMCSPMEEnable | kPCIPMCSPowerStateD3);
        else
            val16 |= kPCIPMCSPowerStateD3;
        
        dev->configWrite16(offset, val16);
    }
    return kIOReturnSuccess;
}
예제 #11
0
bool org_virtualbox_VBoxGuest::isVmmDev(IOPCIDevice *pIOPCIDevice)
{
    UInt16 uVendorId, uDeviceId;

    if (!pIOPCIDevice)
        return false;

    uVendorId = m_pIOPCIDevice->configRead16(kIOPCIConfigVendorID);
    uDeviceId = m_pIOPCIDevice->configRead16(kIOPCIConfigDeviceID);

    if (uVendorId == VMMDEV_VENDORID && uDeviceId == VMMDEV_DEVICEID)
        return true;

    return true;
}
예제 #12
0
파일: at_main.cpp 프로젝트: aelam/iats
int 
at_sw_init(at_adapter *adapter)
{
    at_hw *hw = &adapter->hw;
    IOPCIDevice *pdev = adapter->pdev;

    /* PCI config space info */

    hw->vendor_id = pdev->configRead16(kIOPCIConfigVendorID);
    hw->device_id = pdev->configRead16(kIOPCIConfigDeviceID);
    hw->subsystem_vendor_id = pdev->configRead16(kIOPCIConfigSubSystemVendorID);
    hw->subsystem_id = pdev->configRead16(kIOPCIConfigSubSystemID);

	hw->revision_id = pdev->configRead8(kIOPCIConfigRevisionID);
	hw->pci_cmd_word = pdev->configRead16(kIOPCIConfigCommand);

    adapter->wol = 0;

    adapter->ict = 50000;  // 100ms
    
    adapter->link_speed = SPEED_0;   // hardware init
    adapter->link_duplex = FULL_DUPLEX; //

  
    hw->phy_configured = false;
    hw->preamble_len = 7;
    hw->ipgt = 0x60;
    hw->min_ifg = 0x50;
    hw->ipgr1 = 0x40;
    hw->ipgr2 = 0x60;
    hw->retry_buf = 2;
    
    hw->max_retry = 0xf;
    hw->lcol = 0x37;
    hw->jam_ipg = 7;
    
    hw->fc_rxd_hi = 0;
    hw->fc_rxd_lo = 0; 
    
    hw->max_frame_size = 1500;
    
    atomic_set(&adapter->irq_sem, 1);
    adapter->stats_lock = IOSimpleLockAlloc();
    adapter->tx_lock = IOSimpleLockAlloc();
    

	
    return 0;
}
bool IntelBacklightHandler::start(IOService *provider)
{
    if (!super::start(provider))
        return false;

    IOPCIDevice* pci = OSDynamicCast(IOPCIDevice, provider);
    if (!pci)
    {
        IOLog("IntelBacklightHandler is not an IOPCIDevice... aborting\n");
        return false;
    }

    // setup for direct access
    IOService* service = waitForMatchingService(serviceMatching("ACPIBacklightPanel"), 2000UL*1000UL*1000UL);
    if (!service)
    {
        IOLog("ACPIBacklightPanel not found... aborting\n");
        return false;
    }
    ACPIBacklightPanel* panel = OSDynamicCast(ACPIBacklightPanel, service);
    if (!panel)
    {
        IOLog("Backlight service was not ACPIBacklightPanel\n");
        return false;
    }

    // setup BAR1 address...
    _baseMap = pci->mapDeviceMemoryWithRegister(kIOPCIConfigBaseAddress0);
    if (!_baseMap)
    {
        IOLog("unable to map BAR1... aborting\n");
        return false;
    }
    _baseAddr = reinterpret_cast<volatile void *>(_baseMap->getVirtualAddress());
    if (!_baseAddr)
    {
        IOLog("unable to get virtual address for BAR1... aborting\n");
        return false;
    }

    OSNumber* num = OSDynamicCast(OSNumber, getProperty("kFrameBufferType"));
    if (num == NULL)
    {
        IOLog("unable to get framebuffer type\n");
        return false;
    }
    _fbtype = num->unsigned32BitValue();

    // now register with ACPIBacklight
    if (!panel->setBacklightHandler(this, &_params))
    {
        // setBacklightHandler will return false for old PNLF patches
        _baseMap->release();
        return false;
    }
    _panel = panel;
    panel->retain();

    // register service so ACPIBacklightPanel can proceed...
    registerService();

    return true;
}
예제 #14
0
/**
 * at_probe - Device Initialization Routine
 * @pdev: PCI device information struct
 * @ent: entry in at_pci_tbl
 *
 * Returns 0 on success, negative on failure
 *
 * at_probe initializes an adapter identified by a pci_dev structure.
 * The OS initialization, configuring of the adapter private structure,
 * and a hardware reset occur.
 **/
bool AtherosL1Ethernet::atProbe()
{
    u16  vendorId, deviceId;
    at_adapter *adapter=&adapter_;
    
    IOPCIDevice *pdev = adapter_.pdev;
    pdev->setBusMasterEnable(true);
    pdev->setMemoryEnable(true);
    pdev->setIOEnable(true);
    vendorId = pdev->configRead16(kIOPCIConfigVendorID);
    deviceId = pdev->configRead16(kIOPCIConfigDeviceID);

    DbgPrint("Vendor ID %x, device ID %x\n", vendorId, deviceId);
    DbgPrint("MMR0 address %x\n", (u32)pdev->configRead32(kIOPCIConfigBaseAddress0));

    pdev->enablePCIPowerManagement();

    hw_addr_ = pdev->mapDeviceMemoryWithRegister(kIOPCIConfigBaseAddress0);
    if (hw_addr_ == NULL)
    {
        ErrPrint("Couldn't map io regs\n");
        return false;
    }

    DbgPrint("Memory mapped at bus address %x, virtual address %x, length %d\n", (u32)hw_addr_->getPhysicalAddress(),
                    (u32)hw_addr_->getVirtualAddress(), (u32)hw_addr_->getLength());
    
    
    hw_addr_->retain();

    adapter->hw.mmr_base = reinterpret_cast<char *>(hw_addr_->getVirtualAddress());

    DbgPrint("REG_VPD_CAP = %x\n", OSReadLittleInt32(adapter->hw.mmr_base, REG_VPD_CAP));
    DbgPrint("REG_PCIE_CAP_LIST = %x\n", OSReadLittleInt32(adapter->hw.mmr_base, REG_PCIE_CAP_LIST));
    DbgPrint("REG_MASTER_CTRL = %x\n", OSReadLittleInt32(adapter->hw.mmr_base, REG_MASTER_CTRL));
    
    at_setup_pcicmd(pdev);
    
    /* get user settings */
    at_check_options(adapter);
    
    /* setup the private structure */
    if(at_sw_init(adapter))
    {
        ErrPrint("Couldn't init software\n");
        return false;
    }

    /* Init GPHY as early as possible due to power saving issue  */
    at_phy_init(&adapter->hw);

    /* reset the controller to 
     * put the device in a known good starting state */
    if (at_reset_hw(&adapter->hw))
    {
        ErrPrint("Couldn't reset hardware\n");
        return false;           //TO-DO: Uncomment
    }

    /* copy the MAC address out of the EEPROM */
    at_read_mac_addr(&adapter->hw);

    return true;
}
예제 #15
0
/**
 * Start this service.
 */
bool org_virtualbox_VBoxGuest::start(IOService *pProvider)
{
    if (!IOService::start(pProvider))
        return false;

    /* Low level initialization should be performed only once */
    if (!ASMAtomicCmpXchgBool(&g_fInstantiated, true, false))
    {
        IOService::stop(pProvider);
        return false;
    }

    m_pIOPCIDevice = OSDynamicCast(IOPCIDevice, pProvider);
    if (m_pIOPCIDevice)
    {
        if (isVmmDev(m_pIOPCIDevice))
        {
            /* Enable memory response from VMM device */
            m_pIOPCIDevice->setMemoryEnable(true);
            m_pIOPCIDevice->setIOEnable(true);

            IOMemoryDescriptor *pMem = m_pIOPCIDevice->getDeviceMemoryWithIndex(0);
            if (pMem)
            {
                IOPhysicalAddress IOPortBasePhys = pMem->getPhysicalAddress();
                /* Check that returned value is from I/O port range (at least it is 16-bit lenght) */
                if((IOPortBasePhys >> 16) == 0)
                {

                    RTIOPORT IOPortBase = (RTIOPORT)IOPortBasePhys;
                    void    *pvMMIOBase = NULL;
                    uint32_t cbMMIO     = 0;
                    m_pMap = m_pIOPCIDevice->mapDeviceMemoryWithIndex(1);
                    if (m_pMap)
                    {
                        pvMMIOBase = (void *)m_pMap->getVirtualAddress();
                        cbMMIO     = m_pMap->getLength();
                    }

                    int rc = VBoxGuestInitDevExt(&g_DevExt,
                                                 IOPortBase,
                                                 pvMMIOBase,
                                                 cbMMIO,
#if ARCH_BITS == 64
                                                 VBOXOSTYPE_MacOS_x64,
#else
                                                 VBOXOSTYPE_MacOS,
#endif
                                                 0);
                    if (RT_SUCCESS(rc))
                    {
                        rc = VbgdDarwinCharDevInit();
                        if (rc == KMOD_RETURN_SUCCESS)
                        {
                            if (setupVmmDevInterrupts(pProvider))
                            {
                                /* register the service. */
                                registerService();
                                LogRel(("VBoxGuest: IOService started\n"));
                                return true;
                            }

                            LogRel(("VBoxGuest: Failed to set up interrupts\n"));
                            VbgdDarwinCharDevRemove();
                        }
                        else
                            LogRel(("VBoxGuest: Failed to initialize character device (rc=%d).\n", rc));

                        VBoxGuestDeleteDevExt(&g_DevExt);
                    }
                    else
                        LogRel(("VBoxGuest: Failed to initialize common code (rc=%d).\n", rc));

                    if (m_pMap)
                    {
                        m_pMap->release();
                        m_pMap = NULL;
                    }
                }
            }
            else
                LogRel(("VBoxGuest: The device missing is the I/O port range (#0).\n"));
        }
        else