Exemple #1
0
bool CLASS::start( IOService * provider )
{
    bool success    = false;
    bool superStart = false;

    do {
        // Start our superclass first.

        if (false == super::start(provider))
            break;

        superStart = true;

        // Save a reference to our provider.

        fPCINub = OSDynamicCast(IOPCIDevice, provider);
        if (!fPCINub)
            break;

        // Retain provider, released in free().

        fPCINub->retain();

        // Open our provider.

        if (false == fPCINub->open(this))
            break;

        // Allocate mbuf cursors and other support objects.

        if (false == allocateSupportObjects(provider))
            break;

        // Initialize our harwdare's PCI config space.

        initPCIConfigSpace(fPCINub);

        // Get the virtual address mapping of registers located at
        // Base Address Range 1 (offset 0x14 - memory range).

        fRegMap = fPCINub->mapDeviceMemoryWithRegister(
                           kIOPCIConfigBaseAddress1);
        if (0 == fRegMap)
            break;

        fRegBase = (volatile void *) fRegMap->getVirtualAddress();

        // Detect the hardware type.

        if (probeHardware() == false)
        {
            ERROR_LOG("%s: probeHardware() failed\n", getName());
            break;
        }

        // Publish our media capabilities.

        phyProbeCapability();

        success = true;
    }
    while ( false );

    // Stop super on failure.

    if (!success && superStart)
    {
        super::stop(provider);
    }

    // Close our provider, it will be re-opened on demand when
    // our enable() is called by a client.

    if (fPCINub) fPCINub->close(this);
    
    do {
        if (false == success) break;
        success = false;

        // Allocate and attach an IOEthernetInterface instance.

        if (false == attachInterface((IONetworkInterface **)&fNetif, false))
            break;

        // Optional: this driver supports kernel debugging.
        // Reserved a copy buffer memory used during kernel debugging,
        // and resolve its physical address. Use mbuf for convenience.

        fKDPMbuf = allocatePacket(kIOEthernetMaxPacketSize);
        if (fKDPMbuf &&
            fRxMbufCursor->getPhysicalSegments(fKDPMbuf, &fKDPMbufSeg) == 1)
        {
            attachDebuggerClient(&fKDPNub);
        }

        // Start matching clients of netif.

        fNetif->registerService();

        success = true;
    }
    while ( false );
    
    return success;
}
bool RTL8139::start( IOService *provider )
{
	OSObject	*builtinProperty;

    bool success = false;
    
	ELG( IOThreadSelf(), provider, 'Strt', "RTL8139::start - this, provider." );
    DEBUG_LOG( "start() ===>\n" );

    do
	{
        if ( false == super::start( provider ) )	// Start our superclass first
            break;

			// Save a reference to our provider.

        pciNub = OSDynamicCast( IOPCIDevice, provider );
        if ( 0 == pciNub )
            break;

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

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

		fBuiltin = false;
		builtinProperty = provider->getProperty( "built-in" );
	    if ( builtinProperty )
	    {
	    	fBuiltin = true;
			ELG( 0, 0, 'b-in', "RTL8139::start - found built-in property." );

		}

        if ( false == initEventSources( provider ) )
            break;

			// Allocate memory for descriptors. This function will leak memory
			// if called more than once. So don't do it.

        if ( false == allocateDescriptorMemory() )
            break;

			// Get the virtual address mapping of CSR registers located at
			// Base Address Range 0 (0x10).

        csrMap = pciNub->mapDeviceMemoryWithRegister( kIOPCIConfigBaseAddress1 );
        if ( 0 == csrMap )
            break;

        csrBase = (volatile void*)csrMap->getVirtualAddress();

			// Init PCI config space:

        if ( false == initPCIConfigSpace( pciNub ) )
            break;

			// Reset chip to bring it to a known state.

        if ( initAdapter( kResetChip ) == false )
        {
            IOLog( "%s: initAdapter() failed\n", getName() );
            break;
        }

		registerEEPROM();

			// Publish our media capabilities:

        phyProbeMediaCapability();
        if ( false == publishMediumDictionary( mediumDict ) )
			break;

        success = true;
	} while ( false );

		// Close our provider, it will be re-opened on demand when
		// our enable() is called by a client.

    if ( pciNub )
		 pciNub->close( this );
    
    do
	{
        if ( false == success )
            break;

        success = false;

			// Allocate and attach an IOEthernetInterface instance.

        if ( false == attachInterface( (IONetworkInterface**)&netif, false) )
            break;

			// Optional: this driver supports kernel debugging.

        attachDebuggerClient( &debugger );

			// Trigger matching for clients of netif.

        netif->registerService();
        success = true;
    }
    while ( false );

    DEBUG_LOG( "start() <===\n" );
    return success;
}/* end start */