UInt32 com_ximeta_driver_NDASPhysicalUnitDevice::maxRequestSectors()
{
	com_ximeta_driver_NDASDeviceController *deviceController;
	
	// Send Command.
	deviceController = OSDynamicCast(com_ximeta_driver_NDASDeviceController, 
									 getParentEntry(gIOServicePlane));
	if (NULL == deviceController) {
		DbgIOLog(DEBUG_MASK_NDAS_ERROR, ("maxRequestSectors: Can't Find controller.\n"));
		
		return 0;		
	}
	
	return deviceController->MaxRequestBlocksOfProvider();
}
bool com_ximeta_driver_NDASLogicalDevice::sendNDASFamilyIOMessage(UInt32 type, void * argument, vm_size_t argSize)
{
	if(!UnitDevice()) {
		return false;
	}
	
	com_ximeta_driver_NDASBusEnumerator	*bus;
	
	bus = OSDynamicCast(com_ximeta_driver_NDASBusEnumerator, getParentEntry(gIOServicePlane));
	
	if (NULL == bus) {
		DbgIOLog(DEBUG_MASK_NDAS_INFO, ("Can't Find bus.\n"));
	} else {
		bus->messageClients(type, argument, argSize);
	}
}	
Exemple #3
0
bool WiFiControllerPCI::startProvider(IOService *provider) {
    bool ret = false;
    
    do {
        // Cache our provider to an instance variable.
        _nub = OSDynamicCast(IOPCIDevice, provider);
        if (_nub == 0) break;

        // Retain provider, released in free().
        _nub->retain();

        // Open our provider.
        if (_nub->open(this) == false) break;

        // Request domain power.
        // Without this, the PCIDevice may be in state 0, and the
        // PCI config space may be invalid if the machine has been
        // sleeping.
        if (_nub->requestPowerDomainState(
        /* power flags */ kIOPMPowerOn,
        /* connection  */ (IOPowerConnection *) getParentEntry(gIOPowerPlane),
        /* spec        */ IOPMLowestState ) != IOPMNoErr ) {
            break;
        }
        
        // Get the virtual address mapping of CSR registers located at
        // Base Address Range 0 (0x10). The size of this range is 4K.
        // This was changed to 32 bytes in 82558 A-Step, though only
        // the first 32 bytes should be accessed, and the other bytes
        // are considered reserved.
        _map = _nub->mapDeviceMemoryWithRegister(kIOPCIConfigBaseAddress0);
        if (_map == 0) break;
        
        _ioBase = _map->getVirtualAddress();

        // Setup our PCI config space.
        if (pciConfigInit(_nub) == false) break;

    	_mbufCursor = IOMbufNaturalMemoryCursor::withSpecification(MAX_FRAGMENT_SIZE, 1);
        if (!_mbufCursor) break;
        
        ret = true;
    } while(false);
    
    return ret;
}
IOReturn IOPMPagingPlexus::setAggressiveness ( unsigned long type, unsigned long )
{
    OSDictionary *	dict;
    OSIterator *	iter;
    OSObject *		next;
    IOService *		candidate = 0;
    IOService *		pagingProvider;

    if( type != kPMMinutesToSleep)
        return IOPMNoErr;
    
    IOLockLock(ourLock);
    if ( systemBooting ) {
        systemBooting = false;
        IOLockUnlock(ourLock);
        dict = IOBSDNameMatching(rootdevice);
        if ( dict ) {
            iter = getMatchingServices(dict);
            if ( iter ) {
                while ( (next = iter->getNextObject()) ) {
                    if ( (candidate = OSDynamicCast(IOService,next)) ) {
                        break;
                    }
                }
                iter->release();
            }
        }
        if ( candidate ) {
            pagingProvider = findProvider(candidate);
            if ( pagingProvider ) {
                processSiblings(pagingProvider);
                pagingProvider->addPowerChild(this);
                getPMRootDomain()->removePowerChild(((IOPowerConnection *)getParentEntry(gIOPowerPlane)));
                processChildren();
            }
        }
    }
    else {
        IOLockUnlock(ourLock);
    }
    return IOPMNoErr;
}
bool com_ximeta_driver_NDASPhysicalUnitDevice::processSRBCommand(com_ximeta_driver_NDASCommand *command)
{
	com_ximeta_driver_NDASDeviceController *deviceController;
	
	// Send Command.
	deviceController = OSDynamicCast(com_ximeta_driver_NDASDeviceController, 
									 getParentEntry(gIOServicePlane));
	if (NULL == deviceController) {
		DbgIOLog(DEBUG_MASK_NDAS_ERROR, ("readSectorsOnce: Can't Find controller.\n"));
		
		return false;		
	}
	
	// Set Target Number.
	command->scsiCommand()->targetNo = unitNumber();
	command->scsiCommand()->device = this;
	
	deviceController->enqueueCommand(command);
	
	return true;
}
Exemple #6
0
bool darwin_iwi3945::start(IOService *provider)
{
	UInt16	reg;
//linking the kext control clone to the driver:
		clone=this;
		firstifup=0;
	do {
				
		if ( super::start(provider) == 0) {
			IOLog("%s ERR: super::start failed\n", getName());
			break;
		}
			
		if ( (fPCIDevice = OSDynamicCast(IOPCIDevice, provider)) == 0) {
			IOLog("%s ERR: fPCIDevice == 0 :(\n", getName());
			break;
		}

		fPCIDevice->retain();
		
		if (fPCIDevice->open(this) == 0) {
			IOLog("%s ERR: fPCIDevice->open(this) failed\n", getName());
			break;
		}
		
		// Request domain power.
        	// Without this, the PCIDevice may be in state 0, and the
        	// PCI config space may be invalid if the machine has been
       		// sleeping.
		if (fPCIDevice->requestPowerDomainState(kIOPMPowerOn, 
			(IOPowerConnection *) getParentEntry(gIOPowerPlane),
			IOPMLowestState ) != IOPMNoErr) {
				IOLog("%s Power thingi failed\n", getName());
				break;
       		}
		
		/*UInt16 reg16;
		reg16 = fPCIDevice->configRead16(kIOPCIConfigCommand);
		reg16 |= (kIOPCICommandBusMaster      |
				  kIOPCICommandMemorySpace    |
				  kIOPCICommandMemWrInvalidate);
		reg16 &= ~kIOPCICommandIOSpace;  // disable I/O space
		fPCIDevice->configWrite16(kIOPCIConfigCommand,reg16);*/
		
		fPCIDevice->setBusMasterEnable(true);
		fPCIDevice->setMemoryEnable(true);
		
		irqNumber = fPCIDevice->configRead8(kIOPCIConfigInterruptLine);
		vendorID = fPCIDevice->configRead16(kIOPCIConfigVendorID);
		deviceID = fPCIDevice->configRead16(kIOPCIConfigDeviceID);		
		pciReg = fPCIDevice->configRead16(kIOPCIConfigRevisionID);

  		map = fPCIDevice->mapDeviceMemoryWithRegister(kIOPCIConfigBaseAddress0, kIOMapInhibitCache);
  		if (map == 0) {
			IOLog("%s map is zero\n", getName());
			break;
		}
		
		ioBase = map->getPhysicalAddress();
		memBase = (UInt16 *)map->getVirtualAddress();
		//memDes = map->getMemoryDescriptor();
		//mem = fPCIDevice->getDeviceMemoryWithRegister(kIOPCIConfigBaseAddress0);
		
		//memDes->initWithPhysicalAddress(ioBase, map->getLength(), kIODirectionOutIn);
					 
		/* We disable the RETRY_TIMEOUT register (0x41) to keep
		 * PCI Tx retries from interfering with C3 CPU state */
		reg = fPCIDevice->configRead16(0x40);
		if((reg & 0x0000ff00) != 0)
			fPCIDevice->configWrite16(0x40, reg & 0xffff00ff);
			

		printf("%s iomemory length: 0x%x @ 0x%x\n", getName(), map->getLength(), ioBase);
		printf("%s virt: 0x%x physical: 0x%x\n", getName(), memBase, ioBase);
		printf("%s IRQ: %d, Vendor ID: %04x, Product ID: %04x\n", getName(), irqNumber, vendorID, deviceID);
		
		fWorkLoop = (IOWorkLoop *) getWorkLoop();
		if (!fWorkLoop) {
			//IOLog("%s ERR: start - getWorkLoop failed\n", getName());
			break;
		}
		fInterruptSrc = IOInterruptEventSource::interruptEventSource(
			this, (IOInterruptEventAction) &darwin_iwi3945::interruptOccurred,
			provider);
		if(!fInterruptSrc || (fWorkLoop->addEventSource(fInterruptSrc) != kIOReturnSuccess)) {
			//IOLog("%s fInterruptSrc error\n", getName());
			break;;
		}
		// This is important. If the interrupt line is shared with other devices,
		// then the interrupt vector will be enabled only if all corresponding
		// interrupt event sources are enabled. To avoid masking interrupts for
		// other devices that are sharing the interrupt line, the event source
		// is enabled immediately.
		fInterruptSrc->enable();
		//mutex=IOLockAlloc();
		
		fTransmitQueue = createOutputQueue();
		if (fTransmitQueue == NULL)
		{
			IWI_ERR("ERR: getOutputQueue()\n");
			break;
		}
		fTransmitQueue->setCapacity(1024);
		

		iwl_pci_probe();
		if (!priv) break;
		iwl_hw_nic_init(priv);
		iwl_hw_nic_reset(priv);

		
		if (attachInterface((IONetworkInterface **) &fNetif, false) == false) {
			//IOLog("%s attach failed\n", getName());
			break;
		}
		setProperty(kIOMinPacketSize,12);
		setProperty(kIOMaxPacketSize, IWL_RX_BUF_SIZE);
		//setProperty(kIOFeatures, kIONetworkFeatureNoBSDWait|kIONetworkFeatureSoftwareVlan);
	
		fNetif->registerOutputHandler(this,getOutputHandler());
		
		fNetif->registerService();
		registerService();
		
		mediumDict = OSDictionary::withCapacity(MEDIUM_TYPE_INVALID + 1);
		addMediumType(kIOMediumIEEE80211None,  0,  MEDIUM_TYPE_NONE);
		addMediumType(kIOMediumIEEE80211Auto,  0,  MEDIUM_TYPE_AUTO);
		publishMediumDictionary(mediumDict);
		setCurrentMedium(mediumTable[MEDIUM_TYPE_AUTO]);
		setSelectedMedium(mediumTable[MEDIUM_TYPE_AUTO]);
		setLinkStatus(kIONetworkLinkValid, mediumTable[MEDIUM_TYPE_AUTO]);
		
		//kext control registration:
		//these functions registers the control which enables
		//the user to interact with the driver
		
		struct kern_ctl_reg		ep_ctl; // Initialize control
		kern_ctl_ref	kctlref;
		bzero(&ep_ctl, sizeof(ep_ctl));
		ep_ctl.ctl_id = 0; 
		ep_ctl.ctl_unit = 0;
		strcpy(ep_ctl.ctl_name,"insanelymac.iwidarwin.control");
		ep_ctl.ctl_flags = 0;
		ep_ctl.ctl_connect = ConnectClient;
		ep_ctl.ctl_disconnect = disconnectClient;
		ep_ctl.ctl_send = setSelectedNetwork;
		ep_ctl.ctl_setopt = configureConnection;
		ep_ctl.ctl_getopt = sendNetworkList;
		errno_t error = ctl_register(&ep_ctl, &kctlref);
		
		//queue_te(12,OSMemberFunctionCast(thread_call_func_t,this,&darwin_iwi3945::check_firstup),NULL,NULL,false);
		//queue_te(12,OSMemberFunctionCast(thread_call_func_t,this,&darwin_iwi3945::check_firstup),priv,1000,true);
		//check_firstup(priv);


		return true;			// end start successfully
	} while (false);
		
	//stop(provider);
	//free();
	return false;			// end start insuccessfully
}
bool com_ximeta_driver_NDASPhysicalUnitDevice::writeSectorsOnce(UInt64 location, UInt32 sectors, char *buffer)
{
	ManagingIOCommand						managingCommand;
	com_ximeta_driver_NDASCommand			*NDASCommand;
	com_ximeta_driver_NDASDeviceController	*deviceController;
	bool									result;
	
	if (false ==IsWritable()) {
		DbgIOLog(DEBUG_MASK_DISK_ERROR, ("writeSectorsOnce: No Write right!\n"));
		
		return false;
	}
	
	managingCommand.device = this;
	managingCommand.command = kNDASManagingIOWriteSectors;
	managingCommand.IsSuccess = false;
	managingCommand.Location = location;
	managingCommand.sectors = sectors;
	managingCommand.buffer = buffer;
	
	// Create NDAS Command.
	NDASCommand = OSDynamicCast(com_ximeta_driver_NDASCommand, 
								OSMetaClass::allocClassWithName(NDAS_COMMAND_CLASS));
	
	if(NDASCommand == NULL || !NDASCommand->init()) {
		DbgIOLog(DEBUG_MASK_NDAS_ERROR, ("writeSectorsOnce: failed to alloc command class\n"));
		if (NDASCommand) {
			NDASCommand->release();
		}
		
		return false;
	}
	
	NDASCommand->setCommand(&managingCommand);
	
	// Send Command.
	deviceController = OSDynamicCast(com_ximeta_driver_NDASDeviceController, 
									 getParentEntry(gIOServicePlane));
	if (NULL == deviceController) {
		DbgIOLog(DEBUG_MASK_NDAS_ERROR, ("writeSectorsOnce: Can't Find controller.\n"));
		
		return false;		
	}
	
	this->retain();
	
	if (false == deviceController->executeAndWaitCommand(NDASCommand)) {
		DbgIOLog(DEBUG_MASK_NDAS_ERROR, ("writeSectorsOnce: Can't execute command.\n"));
		
		return false;
	}
	
	result = NDASCommand->managingIOCommand()->IsSuccess;
	if (false == result) {
		DbgIOLog(DEBUG_MASK_NDAS_ERROR, ("writeSectorsOnce: Managing IO failed.\n"));	
	}
	
	this->release();
	
	NDASCommand->release();
	
	return result;
}