Loading...
iokit/bsddev/IOKitBSDInit.cpp xnu-344 xnu-124.13
--- xnu/xnu-344/iokit/bsddev/IOKitBSDInit.cpp
+++ xnu/xnu-124.13/iokit/bsddev/IOKitBSDInit.cpp
@@ -24,6 +24,9 @@
 #include <IOKit/IOService.h>
 #include <IOKit/IODeviceTreeSupport.h>
 #include <IOKit/IOKitKeys.h>
+#include <IOKit/storage/IOMedia.h>
+#include <IOKit/network/IONetworkStack.h>
+#include <IOKit/network/IONetworkInterface.h>
 #include <IOKit/IOPlatformExpert.h>
 
 #include <sys/disklabel.h>
@@ -73,28 +76,6 @@
 	str->release();
 
     return( 0 );
-}
-
-OSDictionary * IOCDMatching( const char * name )
-{
-    OSDictionary *	dict;
-    const OSSymbol *	str;
-
-	dict = IOService::serviceMatching( "IOMedia" );
-	if( dict == 0 ) {
-	   IOLog("Unable to find IOMedia\n");
-	   return 0;
-	} 
-
-	str = OSSymbol::withCString( "CD_ROM_Mode_1" );
-	if( str == 0 ) {
-	    dict->release();
-	    return 0;
-	}
-
-	dict->setObject( "Content", (OSObject *)str );
-	str->release();
-        return( dict );
 }
 
 OSDictionary * IONetworkMatching(  const char * path,
@@ -171,7 +152,7 @@
         if ( str == 0 )
             continue;
 
-        propDict->setObject( "IOInterfaceNamePrefix", (OSObject *) str );
+        propDict->setObject( kIOInterfaceNamePrefix, (OSObject *) str );
         str->release();
         str = 0;
 
@@ -193,57 +174,26 @@
     return( 0 );
 }
 
-static bool IORegisterNetworkInterface( IOService * netif )
-{
-    // A network interface is typically named and registered
-    // with BSD after receiving a request from a user space
-    // "namer". However, for cases when the system needs to
-    // root from the network, this registration task must be
-    // done inside the kernel and completed before the root
-    // device is handed to BSD.
-
-    IOService *    stack;
-    OSNumber *     zero    = 0;
-    OSString *     path    = 0;
-    OSDictionary * dict    = 0;
-    char *         pathBuf = 0;
-    int            len;
-    enum { kMaxPathLen = 512 };
-
-    do {
-        stack = IOService::waitForService(
-                IOService::serviceMatching("IONetworkStack") );
-        if ( stack == 0 ) break;
-
-        dict = OSDictionary::withCapacity(3);
-        if ( dict == 0 ) break;
-
-        zero = OSNumber::withNumber((UInt64) 0, 32);
-        if ( zero == 0 ) break;
-
-        pathBuf = (char *) IOMalloc( kMaxPathLen );
-        if ( pathBuf == 0 ) break;
-
-        len = kMaxPathLen;
-        if ( netif->getPath( pathBuf, &len, gIOServicePlane )
-             == false ) break;
-
-        path = OSString::withCStringNoCopy( pathBuf );
-        if ( path == 0 ) break;
-
-        dict->setObject( "IOInterfaceUnit", zero );
-        dict->setObject( kIOPathMatchKey,   path );
-
-        stack->setProperties( dict );
-    }
-    while ( false );
-
-    if ( zero ) zero->release();
-    if ( path ) path->release();
-    if ( dict ) dict->release();
-    if ( pathBuf ) IOFree(pathBuf, kMaxPathLen);
+static bool IORegisterNetworkInterface( IONetworkInterface * netif )
+{
+    IONetworkStack * stack;
+
+    if (( stack = IONetworkStack::getNetworkStack() ))
+    {
+        stack->registerInterface( netif, netif->getNamePrefix() );
+    }
 
 	return ( netif->getProperty( kIOBSDNameKey ) != 0 );
+}
+
+static void IORegisterPrimaryNetworkInterface()
+{
+    IONetworkStack * stack;
+
+    if (( stack = IONetworkStack::getNetworkStack() ))
+    {
+        stack->registerPrimaryInterface( true );
+    }    
 }
 
 OSDictionary * IODiskMatching( const char * path, char * buf, int maxLen )
@@ -343,7 +293,6 @@
     const char *	look = 0;
     int			len;
     bool		forceNet = false;
-    bool		debugInfoPrintedOnce = false;
 
     static int		mountAttempts = 0;
 
@@ -391,11 +340,10 @@
 	// from OpenFirmware path
 	IOLog("From path: \"%s\", ", look);
 
-	if( forceNet || (0 == strncmp( look, "enet", strlen( "enet" ))) ) {
-            matching = IONetworkMatching( look, str, kMaxPathBuf );
-        } else {
+	if( forceNet || (0 == strncmp( look, "enet", strlen( "enet" ))) )
+           matching = IONetworkMatching( look, str, kMaxPathBuf );
+        else
             matching = IODiskMatching( look, str, kMaxPathBuf );
-        }
     }
 
     if( (!matching) && rdBootVar[0] ) {
@@ -404,13 +352,10 @@
 	if( look[0] == '*')
 	    look++;
     
-	if ( strncmp( look, "en", strlen( "en" )) == 0 ) {
-	    matching = IONetworkNamePrefixMatching( "en" );
-	} else if ( strncmp( look, "cdrom", strlen( "cdrom" )) == 0 ) { 
-	    matching = IOCDMatching( look );
-	} else {
-	    matching = IOBSDNameMatching( look );
-	}
+    if ( strncmp( look, "en", strlen( "en" )) == 0 )
+        matching = IONetworkNamePrefixMatching( "en" );
+    else
+        matching = IOBSDNameMatching( look );
     }
 
     if( !matching) {
@@ -419,7 +364,7 @@
         matching = IOService::serviceMatching( "IOMedia" );
         astring = OSString::withCStringNoCopy("Apple_UFS");
         if ( astring ) {
-            matching->setObject("Content", astring);
+            matching->setObject(kIOMediaContentKey, astring);
             astring->release();
         }
     }
@@ -432,6 +377,8 @@
             s->release();
         }
     }
+
+    IOService::waitForService(IOService::serviceMatching("IOMediaBSDClient"));
 
     do {
         t.tv_sec = ROOTDEVICETIMEOUT;
@@ -441,20 +388,6 @@
 	if( (!service) || (mountAttempts == 10)) {
             PE_display_icon( 0, "noroot");
             IOLog( "Still waiting for root device\n" );
-
-            if( !debugInfoPrintedOnce) {
-                debugInfoPrintedOnce = true;
-                if( gIOKitDebug & kIOLogDTree) {
-                    IOLog("\nDT plane:\n");
-                    IOPrintPlane( gIODTPlane );
-                }
-                if( gIOKitDebug & kIOLogServiceTree) {
-                    IOLog("\nService plane:\n");
-                    IOPrintPlane( gIOServicePlane );
-                }
-                if( gIOKitDebug & kIOLogMemory)
-                    IOPrintMemory();
-            }
 	}
     } while( !service);
     matching->release();
@@ -468,10 +401,11 @@
 
     if ( service
     &&   service->metaCast( "IONetworkInterface" )
-    &&   !IORegisterNetworkInterface( service ) )
+    &&   !IORegisterNetworkInterface( (IONetworkInterface *) service ) )
     {
         service = 0;
     }
+    IORegisterPrimaryNetworkInterface();
 
     if( service) {
 
@@ -510,9 +444,10 @@
 
     IOFree( str,  kMaxPathBuf + kMaxBootVar );
 
-    if( (gIOKitDebug & (kIOLogDTree | kIOLogServiceTree | kIOLogMemory)) && !debugInfoPrintedOnce) {
-
-	IOService::getPlatform()->waitQuiet();
+    if( gIOKitDebug & (kIOLogDTree | kIOLogServiceTree | kIOLogMemory)) {
+
+	IOSleep(10 * 1000);
+//	IOService::getPlatform()->waitQuiet();
         if( gIOKitDebug & kIOLogDTree) {
             IOLog("\nDT plane:\n");
             IOPrintPlane( gIODTPlane );
@@ -528,35 +463,4 @@
     return( kIOReturnSuccess );
 }
 
-void *
-IOBSDRegistryEntryForDeviceTree(char * path)
-{
-    return (IORegistryEntry::fromPath(path, gIODTPlane));
-}
-
-void
-IOBSDRegistryEntryRelease(void * entry)
-{
-    IORegistryEntry * regEntry = (IORegistryEntry *)entry;
-
-    if (regEntry)
-	regEntry->release();
-    return;
-}
-
-const void *
-IOBSDRegistryEntryGetData(void * entry, char * property_name, 
-			  int * packet_length)
-{
-    OSData *		data;
-    IORegistryEntry * 	regEntry = (IORegistryEntry *)entry;
-
-    data = (OSData *) regEntry->getProperty(property_name);
-    if (data) {
-	*packet_length = data->getLength();
-        return (data->getBytesNoCopy());
-    }
-    return (NULL);
-}
-
 } /* extern "C" */