void ofw_init(void *_args) { struct boot_args *args = _args; char *first_avail; char *tree = (char *) args->deviceTreeBuffer; device_node_t *list = NULL; /* Check to make sure the boot loader actually did pass in something */ if (args->Version < kBootHaveOFWVersion || args->deviceTreeSize == 0) return; /* Guru MkLinux note - * * If the booter could not construct a device tree, * then the flatten tree will not be traversed * due to a property count of zero on the first * entry. (This assumes the booter did the * right thing and zeroed the flatten tree) */ /* Init Apple style of OFW */ DTInit((void *) args->deviceTreeBuffer); ofw_first_avail = (char *) ((args->first_avail+3) & ~3); ofw_construct_node(&tree, NULL, &ofw_root_node, &list, 0); args->first_avail = ( ( ( (unsigned int) ofw_first_avail )+3) & ~3); powermac_scan_bridges(&args->first_avail); }
// // Iterates over kexts loaded by booter // and calls PatchKext() for each. // VOID PatchLoadedKexts ( VOID ) { DTEntry MMEntry; _BooterKextFileInfo *KextFileInfo; CHAR8 *PropName; _DeviceTreeBuffer *PropEntry; CHAR8 SavedValue; CHAR8 *InfoPlist; struct OpaqueDTPropertyIterator OPropIter; DTPropertyIterator PropIter = &OPropIter; if (!dtRoot) { return; } DTInit(dtRoot); if (DTLookupEntry(NULL,"/chosen/memory-map", &MMEntry) == kSuccess) { if (DTCreatePropertyIteratorNoAlloc(MMEntry, PropIter) == kSuccess) { while (DTIterateProperties(PropIter, &PropName) == kSuccess) { if (AsciiStrStr(PropName,"Driver-")) { PropEntry = (_DeviceTreeBuffer*)(((UINT8*)PropIter->currentProperty) + sizeof(DeviceTreeNodeProperty)); KextFileInfo = (_BooterKextFileInfo *)(UINTN)PropEntry->paddr; // Info.plist should be terminated with 0, but will also do it just in case InfoPlist = (CHAR8*)(UINTN)KextFileInfo->infoDictPhysAddr; SavedValue = InfoPlist[KextFileInfo->infoDictLength]; InfoPlist[KextFileInfo->infoDictLength] = '\0'; PatchKext( (UINT8*)(UINTN)KextFileInfo->executablePhysAddr, KextFileInfo->executableLength, InfoPlist, KextFileInfo->infoDictLength ); InfoPlist[KextFileInfo->infoDictLength] = SavedValue; } } } } }
void PE_init_platform(boolean_t vm_initialized, void * _args) { boot_args *args = (boot_args *)_args; if (PE_state.initialized == FALSE) { PE_state.initialized = TRUE; // New EFI-style PE_state.bootArgs = _args; PE_state.deviceTreeHead = (void *) ml_static_ptovirt(args->deviceTreeP); PE_state.video.v_baseAddr = args->Video.v_baseAddr; // remains physical address PE_state.video.v_rowBytes = args->Video.v_rowBytes; PE_state.video.v_width = args->Video.v_width; PE_state.video.v_height = args->Video.v_height; PE_state.video.v_depth = args->Video.v_depth; PE_state.video.v_display = args->Video.v_display; PE_state.video.v_scale = (kBootArgsFlagHiDPI & args->flags) ? 2 : 1; strlcpy(PE_state.video.v_pixelFormat, "PPPPPPPP", sizeof(PE_state.video.v_pixelFormat)); #ifdef kBootArgsFlagHiDPI if (args->flags & kBootArgsFlagHiDPI) PE_state.video.v_scale = kPEScaleFactor2x; else PE_state.video.v_scale = kPEScaleFactor1x; #else PE_state.video.v_scale = kPEScaleFactor1x; #endif } if (!vm_initialized) { if (PE_state.deviceTreeHead) { DTInit(PE_state.deviceTreeHead); } pe_identify_machine(args); } else { pe_init_debug(); } }
/** * PE_init_platform * * Initialize the platform expert for ARM. */ void PE_init_platform(boolean_t vm_initialized, void * _args) { boot_args *args = (boot_args *)_args; if (PE_state.initialized == FALSE) { PE_early_puts("PE_init_platform: My name is Macintosh.\n"); PE_early_puts("PE_init_platform: Initializing for the first time.\n"); PE_state.initialized = TRUE; PE_state.bootArgs = _args; PE_state.deviceTreeHead = args->deviceTreeP; PE_state.video.v_baseAddr = args->Video.v_baseAddr; PE_state.video.v_rowBytes = args->Video.v_rowBytes; PE_state.video.v_width = args->Video.v_width; PE_state.video.v_height = args->Video.v_height; PE_state.video.v_depth = args->Video.v_depth; PE_state.video.v_display = args->Video.v_display; strcpy(PE_state.video.v_pixelFormat, "PPPPPPPP"); } if (!vm_initialized) { /* Initialize the device tree crap. */ PE_early_puts("PE_init_platform: Initializing device tree\n"); DTInit(PE_state.deviceTreeHead); PE_early_puts("PE_init_platform: Calling pe_identify_machine\n"); pe_identify_machine(NULL); } else { kprintf("PE_init_platform: It sure is great to get out of that bag.\n"); PE_init_SocSupport(); pe_arm_init_interrupts(NULL); } }
int main(int argc, char **argv) { DTEntry dtEntry; DTPropertyIterator propIter; DTEntryIterator entryIter; void *prop; int propSize; char *name; void *flatTree; uint32_t flatSize; Node *node; node = AddChild(NULL, "device-tree"); AddProperty(node, "potato", 4, "foo"); AddProperty(node, "chemistry", 4, "bar"); AddProperty(node, "physics", 4, "baz"); node = AddChild(node, "dev"); AddProperty(node, "one", 4, "one"); AddProperty(node, "two", 4, "two"); AddProperty(node, "three", 6, "three"); node = AddChild(rootNode, "foo"); AddProperty(node, "aaa", 4, "aab"); AddProperty(node, "bbb", 4, "bbc"); AddProperty(node, "cccc", 6, "ccccd"); node = FindNode("/this/is/a/test", 1); AddProperty(node, "dddd", 12, "abcdefghijk"); printf("In-memory tree:\n\n"); PrintTree(rootNode); FlattenDeviceTree(&flatTree, &flatSize); printf("Flat tree = %p, size %d\n", flatTree, flatSize); dtEntry = (DTEntry)flatTree; printf("\n\nPrinting flat tree\n\n"); DTInit(dtEntry); PrintFlattenedTree((DTEntry)flatTree); #if 0 printf("=== Entry %p ===\n", dtEntry); if (kSuccess != DTCreatePropertyIterator(dtEntry, &propIter)) { printf("Couldn't create property iterator\n"); return 1; } while( kSuccess == DTIterateProperties( propIter, &name)) { if( kSuccess != DTGetProperty( dtEntry, name, &prop, &propSize )) continue; printf(" Property %s = %s\n", name, prop); } DTDisposePropertyIterator(propIter); printf("========\n"); if (kSuccess != DTCreateEntryIterator(dtEntry, &entryIter)) { printf("Couldn't create entry iterator\n"); return 1; } while (kSuccess == DTIterateEntries( entryIter, &dtEntry )) { printf("=== Entry %p ===\n", dtEntry); if (kSuccess != DTCreatePropertyIterator(dtEntry, &propIter)) { printf("Couldn't create property iterator\n"); return 1; } while( kSuccess == DTIterateProperties( propIter, &name)) { if( kSuccess != DTGetProperty( dtEntry, name, &prop, &propSize )) continue; printf(" Property %s = %s\n", name, prop); } DTDisposePropertyIterator(propIter); printf("========\n"); } DTDisposeEntryIterator(entryIter); #endif return 0; }
IORegistryEntry * IODeviceTreeAlloc( void * dtTop ) { IORegistryEntry * parent; IORegistryEntry * child; IORegistryIterator * regIter; DTEntryIterator iter; DTEntry dtChild; DTEntry mapEntry; OSArray * stack; OSData * prop; OSDictionary * allInts; vm_offset_t * dtMap; unsigned int propSize; bool intMap; bool freeDT; gIODTPlane = IORegistryEntry::makePlane( kIODeviceTreePlane ); gIODTNameKey = OSSymbol::withCStringNoCopy( "name" ); gIODTUnitKey = OSSymbol::withCStringNoCopy( "AAPL,unit-string" ); gIODTCompatibleKey = OSSymbol::withCStringNoCopy( "compatible" ); gIODTTypeKey = OSSymbol::withCStringNoCopy( "device_type" ); gIODTModelKey = OSSymbol::withCStringNoCopy( "model" ); gIODTSizeCellKey = OSSymbol::withCStringNoCopy( "#size-cells" ); gIODTAddressCellKey = OSSymbol::withCStringNoCopy( "#address-cells" ); gIODTRangeKey = OSSymbol::withCStringNoCopy( "ranges" ); gIODTPersistKey = OSSymbol::withCStringNoCopy( "IODTPersist" ); assert( gIODTPlane && gIODTCompatibleKey && gIODTTypeKey && gIODTModelKey && gIODTSizeCellKey && gIODTAddressCellKey && gIODTRangeKey && gIODTPersistKey ); gIODTDefaultInterruptController = OSSymbol::withCStringNoCopy("IOPrimaryInterruptController"); gIODTNWInterruptMappingKey = OSSymbol::withCStringNoCopy("IONWInterrupts"); gIODTAAPLInterruptsKey = OSSymbol::withCStringNoCopy("AAPL,interrupts"); gIODTPHandleKey = OSSymbol::withCStringNoCopy("AAPL,phandle"); gIODTInterruptParentKey = OSSymbol::withCStringNoCopy("interrupt-parent"); gIODTPHandles = OSArray::withCapacity( 1 ); gIODTPHandleMap = OSArray::withCapacity( 1 ); gIODTInterruptCellKey = OSSymbol::withCStringNoCopy("#interrupt-cells"); assert( gIODTDefaultInterruptController && gIODTNWInterruptMappingKey && gIODTAAPLInterruptsKey && gIODTPHandleKey && gIODTInterruptParentKey && gIODTPHandles && gIODTPHandleMap && gIODTInterruptCellKey ); freeDT = (kSuccess == DTLookupEntry( 0, "/chosen/memory-map", &mapEntry )) && (kSuccess == DTGetProperty( mapEntry, "DeviceTree", (void **) &dtMap, &propSize )) && ((2 * sizeof(uint32_t)) == propSize); parent = MakeReferenceTable( (DTEntry)dtTop, freeDT ); stack = OSArray::withObjects( (const OSObject **) &parent, 1, 10 ); DTCreateEntryIterator( (DTEntry)dtTop, &iter ); do { parent = (IORegistryEntry *)stack->getObject( stack->getCount() - 1); //parent->release(); stack->removeObject( stack->getCount() - 1); while( kSuccess == DTIterateEntries( iter, &dtChild) ) { child = MakeReferenceTable( dtChild, freeDT ); child->attachToParent( parent, gIODTPlane); AddPHandle( child ); if( kSuccess == DTEnterEntry( iter, dtChild)) { stack->setObject( parent); parent = child; } // only registry holds retain child->release(); } } while( stack->getCount() && (kSuccess == DTExitEntry( iter, &dtChild))); stack->release(); DTDisposeEntryIterator( iter); // parent is now root of the created tree // make root name first compatible entry (purely cosmetic) if( (prop = (OSData *) parent->getProperty( gIODTCompatibleKey))) { parent->setName( parent->getName(), gIODTPlane ); parent->setName( (const char *) prop->getBytesNoCopy() ); } // attach tree to meta root parent->attachToParent( IORegistryEntry::getRegistryRoot(), gIODTPlane); parent->release(); if( freeDT ) { // free original device tree DTInit(0); IODTFreeLoaderInfo( "DeviceTree", (void *)dtMap[0], (int) round_page(dtMap[1]) ); } // adjust tree gIODTSharedInterrupts = OSDictionary::withCapacity(4); allInts = OSDictionary::withCapacity(4); intMap = false; regIter = IORegistryIterator::iterateOver( gIODTPlane, kIORegistryIterateRecursively ); assert( regIter && allInts && gIODTSharedInterrupts ); if( regIter && allInts && gIODTSharedInterrupts ) { while( (child = regIter->getNextObject())) { IODTMapInterruptsSharing( child, allInts ); if( !intMap && child->getProperty( gIODTInterruptParentKey)) intMap = true; } regIter->release(); } #if IODTSUPPORTDEBUG parent->setProperty("allInts", allInts); parent->setProperty("sharedInts", gIODTSharedInterrupts); regIter = IORegistryIterator::iterateOver( gIODTPlane, kIORegistryIterateRecursively ); if (regIter) { while( (child = regIter->getNextObject())) { OSArray * array = OSDynamicCast(OSArray, child->getProperty( gIOInterruptSpecifiersKey )); for( UInt32 i = 0; array && (i < array->getCount()); i++) { IOOptionBits options; IOReturn ret = IODTGetInterruptOptions( child, i, &options ); if( (ret != kIOReturnSuccess) || options) IOLog("%s[%ld] %ld (%x)\n", child->getName(), i, options, ret); } } regIter->release(); } #endif allInts->release(); if( intMap) // set a key in the root to indicate we found NW interrupt mapping parent->setProperty( gIODTNWInterruptMappingKey, (OSObject *) gIODTNWInterruptMappingKey ); return( parent); }
/** * PE_init_platform * * Initialize the platform expert for ARM. */ void PE_init_platform(boolean_t vm_initialized, void * _args) { boot_args *args = (boot_args *)_args; if (PE_state.initialized == FALSE) { PE_early_puts("PE_init_platform: My name is Macintosh.\n"); PE_early_puts("PE_init_platform: Initializing for the first time.\n"); PE_state.initialized = TRUE; PE_state.bootArgs = _args; PE_state.deviceTreeHead = args->deviceTreeP; PE_state.video.v_baseAddr = args->Video.v_baseAddr; PE_state.video.v_rowBytes = args->Video.v_rowBytes; PE_state.video.v_width = args->Video.v_width; PE_state.video.v_height = args->Video.v_height; PE_state.video.v_depth = args->Video.v_depth; PE_state.video.v_display = args->Video.v_display; strcpy(PE_state.video.v_pixelFormat, "PPPPPPPP"); } if (!vm_initialized) { /* Initialize the device tree crap. */ PE_early_puts("PE_init_platform: Initializing device tree\n"); DTInit(PE_state.deviceTreeHead); PE_early_puts("PE_init_platform: Calling pe_identify_machine\n"); pe_identify_machine(NULL); } else { DTEntry entry; char* fversion, map; unsigned int size; pe_initialized = 1; kprintf("PE_init_platform: It sure is great to get out of that bag.\n"); PE_init_SocSupport(); /* Reset kputc. */ PE_kputc = gPESocDispatch.uart_putc; /* XXX: Real iOS kernel does iBoot/debug-enabled init after the DTInit call. */ if( kSuccess == DTLookupEntry(NULL, "/chosen", &entry)) { /* What's the iBoot version on this bad boy? */ if( kSuccess == DTGetProperty(entry, "firmware-version", (void **) &fversion, &size)) { if(fversion && (strlen(fversion) <= 32)) { ovbcopy((void*)fversion, (void*)firmware_version, strlen(fversion)); } } /* Is the SoC debug-enabled? */ if( kSuccess == DTGetProperty(entry, "debug-enabled", (void **) &map, &size)) { debug_enabled = 1; } } pe_arm_init_interrupts(NULL); } }