xref: /xnu-10063.121.3/iokit/Kernel/IODeviceTreeSupport.cpp (revision 2c2f96dc2b9a4408a43d3150ae9c105355ca3daa)
1*2c2f96dcSApple OSS Distributions /*
2*2c2f96dcSApple OSS Distributions  * Copyright (c) 1998-2006 Apple Computer, Inc. All rights reserved.
3*2c2f96dcSApple OSS Distributions  *
4*2c2f96dcSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*2c2f96dcSApple OSS Distributions  *
6*2c2f96dcSApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*2c2f96dcSApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*2c2f96dcSApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*2c2f96dcSApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*2c2f96dcSApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*2c2f96dcSApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*2c2f96dcSApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*2c2f96dcSApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*2c2f96dcSApple OSS Distributions  *
15*2c2f96dcSApple OSS Distributions  * Please obtain a copy of the License at
16*2c2f96dcSApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*2c2f96dcSApple OSS Distributions  *
18*2c2f96dcSApple OSS Distributions  * The Original Code and all software distributed under the License are
19*2c2f96dcSApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*2c2f96dcSApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*2c2f96dcSApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*2c2f96dcSApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*2c2f96dcSApple OSS Distributions  * Please see the License for the specific language governing rights and
24*2c2f96dcSApple OSS Distributions  * limitations under the License.
25*2c2f96dcSApple OSS Distributions  *
26*2c2f96dcSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*2c2f96dcSApple OSS Distributions  */
28*2c2f96dcSApple OSS Distributions 
29*2c2f96dcSApple OSS Distributions #include <IOKit/IODeviceTreeSupport.h>
30*2c2f96dcSApple OSS Distributions #include <libkern/c++/OSContainers.h>
31*2c2f96dcSApple OSS Distributions #include <libkern/c++/OSSharedPtr.h>
32*2c2f96dcSApple OSS Distributions #include <IOKit/IODeviceMemory.h>
33*2c2f96dcSApple OSS Distributions #include <IOKit/IOService.h>
34*2c2f96dcSApple OSS Distributions #include <IOKit/IOCatalogue.h>
35*2c2f96dcSApple OSS Distributions 
36*2c2f96dcSApple OSS Distributions #include <IOKit/IOLib.h>
37*2c2f96dcSApple OSS Distributions #include <IOKit/IOKitKeys.h>
38*2c2f96dcSApple OSS Distributions 
39*2c2f96dcSApple OSS Distributions #include <pexpert/device_tree.h>
40*2c2f96dcSApple OSS Distributions 
41*2c2f96dcSApple OSS Distributions #if __arm64__
42*2c2f96dcSApple OSS Distributions typedef UInt64  dtptr_t;
43*2c2f96dcSApple OSS Distributions #else
44*2c2f96dcSApple OSS Distributions typedef UInt32  dtptr_t;
45*2c2f96dcSApple OSS Distributions #endif
46*2c2f96dcSApple OSS Distributions 
47*2c2f96dcSApple OSS Distributions #include <machine/machine_routines.h>
48*2c2f96dcSApple OSS Distributions 
49*2c2f96dcSApple OSS Distributions extern "C" {
50*2c2f96dcSApple OSS Distributions int IODTGetLoaderInfo( const char *key, void **infoAddr, int *infosize );
51*2c2f96dcSApple OSS Distributions void IODTFreeLoaderInfo( const char *key, void *infoAddr, int infoSize );
52*2c2f96dcSApple OSS Distributions int IODTGetDefault(const char *key, void *infoAddr, unsigned int infoSize );
53*2c2f96dcSApple OSS Distributions }
54*2c2f96dcSApple OSS Distributions 
55*2c2f96dcSApple OSS Distributions #include <IOKit/assert.h>
56*2c2f96dcSApple OSS Distributions 
57*2c2f96dcSApple OSS Distributions #define IODTSUPPORTDEBUG 0
58*2c2f96dcSApple OSS Distributions 
59*2c2f96dcSApple OSS Distributions struct IODTPersistent {
60*2c2f96dcSApple OSS Distributions 	IODTCompareAddressCellFunc  compareFunc;
61*2c2f96dcSApple OSS Distributions };
62*2c2f96dcSApple OSS Distributions 
63*2c2f96dcSApple OSS Distributions struct IODTResolvers {
64*2c2f96dcSApple OSS Distributions 	unsigned int     alloc;
65*2c2f96dcSApple OSS Distributions 	unsigned int     count;
66*2c2f96dcSApple OSS Distributions 	IOLock         * lock;
67*2c2f96dcSApple OSS Distributions 	IODTPersistent * resolvers;
68*2c2f96dcSApple OSS Distributions };
69*2c2f96dcSApple OSS Distributions 
70*2c2f96dcSApple OSS Distributions const IORegistryPlane * gIODTPlane;
71*2c2f96dcSApple OSS Distributions 
72*2c2f96dcSApple OSS Distributions static OSArray *    gIODTPHandles;
73*2c2f96dcSApple OSS Distributions static OSArray *    gIODTPHandleMap;
74*2c2f96dcSApple OSS Distributions 
75*2c2f96dcSApple OSS Distributions static IODTResolvers *  gIODTResolvers;
76*2c2f96dcSApple OSS Distributions 
77*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTNameKey;
78*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTUnitKey;
79*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTCompatibleKey;
80*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTTypeKey;
81*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTModelKey;
82*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTBridgeModelKey;
83*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTTargetTypeKey;
84*2c2f96dcSApple OSS Distributions 
85*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTSizeCellKey;
86*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTAddressCellKey;
87*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTRangeKey;
88*2c2f96dcSApple OSS Distributions 
89*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTPersistKey;
90*2c2f96dcSApple OSS Distributions 
91*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTDefaultInterruptController;
92*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTAAPLInterruptsKey;
93*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTPHandleKey;
94*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTInterruptCellKey;
95*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTInterruptParentKey;
96*2c2f96dcSApple OSS Distributions const OSSymbol *        gIODTNWInterruptMappingKey;
97*2c2f96dcSApple OSS Distributions 
98*2c2f96dcSApple OSS Distributions const OSData *          gIODTAssociatedServiceKey;
99*2c2f96dcSApple OSS Distributions 
100*2c2f96dcSApple OSS Distributions OSDictionary   *        gIODTSharedInterrupts;
101*2c2f96dcSApple OSS Distributions 
102*2c2f96dcSApple OSS Distributions static IORegistryEntry * MakeReferenceTable( DTEntry dtEntry, bool copy );
103*2c2f96dcSApple OSS Distributions static void AddPHandle( IORegistryEntry * regEntry );
104*2c2f96dcSApple OSS Distributions static void FreePhysicalMemory( vm_offset_t * range );
105*2c2f96dcSApple OSS Distributions static bool IODTMapInterruptsSharing( IORegistryEntry * regEntry, OSDictionary * allInts );
106*2c2f96dcSApple OSS Distributions 
107*2c2f96dcSApple OSS Distributions // FIXME: Implementation of this function is hidden from the static analyzer.
108*2c2f96dcSApple OSS Distributions // The analyzer doesn't know that the registry holds retains, and gets confused
109*2c2f96dcSApple OSS Distributions // about releases after calls to 'attachToParent'.
110*2c2f96dcSApple OSS Distributions // Feel free to remove the #ifndef and address the warning!
111*2c2f96dcSApple OSS Distributions #ifndef __clang_analyzer__
112*2c2f96dcSApple OSS Distributions IORegistryEntry *
IODeviceTreeAlloc(void * dtTop)113*2c2f96dcSApple OSS Distributions IODeviceTreeAlloc( void * dtTop )
114*2c2f96dcSApple OSS Distributions {
115*2c2f96dcSApple OSS Distributions 	IORegistryEntry *           parent;
116*2c2f96dcSApple OSS Distributions 	IORegistryEntry *           child;
117*2c2f96dcSApple OSS Distributions 	IORegistryIterator *        regIter;
118*2c2f96dcSApple OSS Distributions 	OpaqueDTEntryIterator       iter;
119*2c2f96dcSApple OSS Distributions 	DTEntry                     dtChild;
120*2c2f96dcSApple OSS Distributions 	DTEntry                     mapEntry;
121*2c2f96dcSApple OSS Distributions 	OSArray *                   stack;
122*2c2f96dcSApple OSS Distributions 	OSData *                    prop;
123*2c2f96dcSApple OSS Distributions 	OSDictionary *              allInts;
124*2c2f96dcSApple OSS Distributions 	vm_offset_t *               dtMap;
125*2c2f96dcSApple OSS Distributions 	unsigned int                propSize;
126*2c2f96dcSApple OSS Distributions 	bool                        intMap;
127*2c2f96dcSApple OSS Distributions 	bool                        foundDTNode;
128*2c2f96dcSApple OSS Distributions 	bool                        freeDT;
129*2c2f96dcSApple OSS Distributions 	char                        exBootArg[64];
130*2c2f96dcSApple OSS Distributions 	const char *                found;
131*2c2f96dcSApple OSS Distributions 
132*2c2f96dcSApple OSS Distributions 	gIODTPlane = IORegistryEntry::makePlane( kIODeviceTreePlane );
133*2c2f96dcSApple OSS Distributions 
134*2c2f96dcSApple OSS Distributions 	gIODTNameKey                = OSSymbol::withCStringNoCopy( "name" );
135*2c2f96dcSApple OSS Distributions 	gIODTUnitKey                = OSSymbol::withCStringNoCopy( "AAPL,unit-string" );
136*2c2f96dcSApple OSS Distributions 	gIODTCompatibleKey  = OSSymbol::withCStringNoCopy( "compatible" );
137*2c2f96dcSApple OSS Distributions 	gIODTTypeKey                = OSSymbol::withCStringNoCopy( "device_type" );
138*2c2f96dcSApple OSS Distributions 	gIODTModelKey               = OSSymbol::withCStringNoCopy( "model" );
139*2c2f96dcSApple OSS Distributions 	gIODTBridgeModelKey         = OSSymbol::withCStringNoCopy( "bridge-model" );
140*2c2f96dcSApple OSS Distributions 	gIODTTargetTypeKey          = OSSymbol::withCStringNoCopy( "target-type" );
141*2c2f96dcSApple OSS Distributions 	gIODTSizeCellKey    = OSSymbol::withCStringNoCopy( "#size-cells" );
142*2c2f96dcSApple OSS Distributions 	gIODTAddressCellKey = OSSymbol::withCStringNoCopy( "#address-cells" );
143*2c2f96dcSApple OSS Distributions 	gIODTRangeKey               = OSSymbol::withCStringNoCopy( "ranges" );
144*2c2f96dcSApple OSS Distributions 	gIODTPersistKey             = OSSymbol::withCStringNoCopy( "IODTPersist" );
145*2c2f96dcSApple OSS Distributions 	gIODTAssociatedServiceKey   = OSData::withBytesNoCopy((void *) kIODTAssociatedServiceKey, sizeof(kIODTAssociatedServiceKey));
146*2c2f96dcSApple OSS Distributions 
147*2c2f96dcSApple OSS Distributions 
148*2c2f96dcSApple OSS Distributions 	assert(    gIODTPlane && gIODTCompatibleKey
149*2c2f96dcSApple OSS Distributions 	    && gIODTTypeKey && gIODTModelKey
150*2c2f96dcSApple OSS Distributions 	    && gIODTSizeCellKey && gIODTAddressCellKey && gIODTRangeKey
151*2c2f96dcSApple OSS Distributions 	    && gIODTPersistKey );
152*2c2f96dcSApple OSS Distributions 
153*2c2f96dcSApple OSS Distributions 	gIODTDefaultInterruptController
154*2c2f96dcSApple OSS Distributions 	        = OSSymbol::withCStringNoCopy("IOPrimaryInterruptController");
155*2c2f96dcSApple OSS Distributions 	gIODTNWInterruptMappingKey
156*2c2f96dcSApple OSS Distributions 	        = OSSymbol::withCStringNoCopy("IONWInterrupts");
157*2c2f96dcSApple OSS Distributions 
158*2c2f96dcSApple OSS Distributions 	gIODTAAPLInterruptsKey
159*2c2f96dcSApple OSS Distributions 	        = OSSymbol::withCStringNoCopy("AAPL,interrupts");
160*2c2f96dcSApple OSS Distributions 	gIODTPHandleKey
161*2c2f96dcSApple OSS Distributions 	        = OSSymbol::withCStringNoCopy("AAPL,phandle");
162*2c2f96dcSApple OSS Distributions 
163*2c2f96dcSApple OSS Distributions 	gIODTInterruptParentKey
164*2c2f96dcSApple OSS Distributions 	        = OSSymbol::withCStringNoCopy("interrupt-parent");
165*2c2f96dcSApple OSS Distributions 
166*2c2f96dcSApple OSS Distributions 	gIODTPHandles       = OSArray::withCapacity( 1 );
167*2c2f96dcSApple OSS Distributions 	gIODTPHandleMap     = OSArray::withCapacity( 1 );
168*2c2f96dcSApple OSS Distributions 
169*2c2f96dcSApple OSS Distributions 	gIODTResolvers            = zalloc_permanent_type(IODTResolvers);
170*2c2f96dcSApple OSS Distributions 	gIODTResolvers->count     = 0;
171*2c2f96dcSApple OSS Distributions 	gIODTResolvers->alloc     = 2;
172*2c2f96dcSApple OSS Distributions 	gIODTResolvers->resolvers = IONewZero(IODTPersistent, gIODTResolvers->alloc);
173*2c2f96dcSApple OSS Distributions 	gIODTResolvers->lock      = IOLockAlloc();
174*2c2f96dcSApple OSS Distributions 
175*2c2f96dcSApple OSS Distributions 	if (!PE_parse_boot_argn("exp", exBootArg, sizeof(exBootArg))) {
176*2c2f96dcSApple OSS Distributions 		exBootArg[0] = '\0';
177*2c2f96dcSApple OSS Distributions 	}
178*2c2f96dcSApple OSS Distributions 
179*2c2f96dcSApple OSS Distributions 	gIODTInterruptCellKey
180*2c2f96dcSApple OSS Distributions 	        = OSSymbol::withCStringNoCopy("#interrupt-cells");
181*2c2f96dcSApple OSS Distributions 
182*2c2f96dcSApple OSS Distributions 	assert(    gIODTDefaultInterruptController && gIODTNWInterruptMappingKey
183*2c2f96dcSApple OSS Distributions 	    && gIODTAAPLInterruptsKey
184*2c2f96dcSApple OSS Distributions 	    && gIODTPHandleKey && gIODTInterruptParentKey
185*2c2f96dcSApple OSS Distributions 	    && gIODTPHandles && gIODTPHandleMap && gIODTInterruptCellKey
186*2c2f96dcSApple OSS Distributions 	    && gIODTResolvers && gIODTResolvers->lock && gIODTResolvers->resolvers
187*2c2f96dcSApple OSS Distributions 	    );
188*2c2f96dcSApple OSS Distributions 
189*2c2f96dcSApple OSS Distributions 	foundDTNode = (kSuccess == SecureDTLookupEntry( NULL, "/chosen/memory-map", &mapEntry ))
190*2c2f96dcSApple OSS Distributions 	    && (kSuccess == SecureDTGetProperty( mapEntry,
191*2c2f96dcSApple OSS Distributions 	    "DeviceTree", (void const **) &dtMap, &propSize ))
192*2c2f96dcSApple OSS Distributions 	    && ((2 * sizeof(uint32_t)) == propSize);
193*2c2f96dcSApple OSS Distributions 
194*2c2f96dcSApple OSS Distributions 	freeDT = foundDTNode && !SecureDTIsLockedDown();
195*2c2f96dcSApple OSS Distributions 
196*2c2f96dcSApple OSS Distributions 	parent = MakeReferenceTable((DTEntry)dtTop, freeDT );
197*2c2f96dcSApple OSS Distributions 
198*2c2f96dcSApple OSS Distributions 	stack = OSArray::withObjects((const OSObject **) &parent, 1, 10 );
199*2c2f96dcSApple OSS Distributions 	SecureDTInitEntryIterator((DTEntry)dtTop, &iter );
200*2c2f96dcSApple OSS Distributions 
201*2c2f96dcSApple OSS Distributions 	do {
202*2c2f96dcSApple OSS Distributions 		parent = (IORegistryEntry *)stack->getObject( stack->getCount() - 1);
203*2c2f96dcSApple OSS Distributions 		//parent->release();
204*2c2f96dcSApple OSS Distributions 		stack->removeObject( stack->getCount() - 1);
205*2c2f96dcSApple OSS Distributions 
206*2c2f96dcSApple OSS Distributions 		while (kSuccess == SecureDTIterateEntries( &iter, &dtChild)) {
207*2c2f96dcSApple OSS Distributions 			child = MakeReferenceTable( dtChild, freeDT );
208*2c2f96dcSApple OSS Distributions 			child->attachToParent( parent, gIODTPlane);
209*2c2f96dcSApple OSS Distributions 
210*2c2f96dcSApple OSS Distributions 			AddPHandle( child );
211*2c2f96dcSApple OSS Distributions 			// E.g. exp=sgx:3 or exp=sgx:3,5
212*2c2f96dcSApple OSS Distributions 			if ((found = strnstr(exBootArg, child->getName(), sizeof(exBootArg)))) {
213*2c2f96dcSApple OSS Distributions 				child->setProperty(gIOExclaveAssignedKey, kOSBooleanTrue);
214*2c2f96dcSApple OSS Distributions 				uint32_t ep = 0;
215*2c2f96dcSApple OSS Distributions 				uint32_t edk_ep = 0;
216*2c2f96dcSApple OSS Distributions 				found += strlen(child->getName());
217*2c2f96dcSApple OSS Distributions 				if (':' == *found) {
218*2c2f96dcSApple OSS Distributions 					char *end;
219*2c2f96dcSApple OSS Distributions 					ep = (uint32_t) strtol(found + 1, &end, 0);
220*2c2f96dcSApple OSS Distributions 					// Check for optional edk endpoint
221*2c2f96dcSApple OSS Distributions 					if (',' == *end) {
222*2c2f96dcSApple OSS Distributions 						edk_ep = (uint32_t) strtol(end + 1, &end, 0);
223*2c2f96dcSApple OSS Distributions 						child->setProperty("exclave-edk-endpoint", &edk_ep, sizeof(edk_ep));
224*2c2f96dcSApple OSS Distributions 					}
225*2c2f96dcSApple OSS Distributions 				}
226*2c2f96dcSApple OSS Distributions 				child->setProperty("exclave-endpoint", &ep, sizeof(ep));
227*2c2f96dcSApple OSS Distributions 			}
228*2c2f96dcSApple OSS Distributions 
229*2c2f96dcSApple OSS Distributions 			if (kSuccess == SecureDTEnterEntry( &iter, dtChild)) {
230*2c2f96dcSApple OSS Distributions 				stack->setObject( parent);
231*2c2f96dcSApple OSS Distributions 				parent = child;
232*2c2f96dcSApple OSS Distributions 			}
233*2c2f96dcSApple OSS Distributions 			// only registry holds retain
234*2c2f96dcSApple OSS Distributions 			child->release();
235*2c2f96dcSApple OSS Distributions 		}
236*2c2f96dcSApple OSS Distributions 	} while (stack->getCount()
237*2c2f96dcSApple OSS Distributions 	    && (kSuccess == SecureDTExitEntry( &iter, &dtChild)));
238*2c2f96dcSApple OSS Distributions 
239*2c2f96dcSApple OSS Distributions 	stack->release();
240*2c2f96dcSApple OSS Distributions 	assert(kSuccess != SecureDTExitEntry(&iter, &dtChild));
241*2c2f96dcSApple OSS Distributions 
242*2c2f96dcSApple OSS Distributions 	// parent is now root of the created tree
243*2c2f96dcSApple OSS Distributions 
244*2c2f96dcSApple OSS Distributions 	// make root name first compatible entry (purely cosmetic)
245*2c2f96dcSApple OSS Distributions 	if ((prop = (OSData *) parent->getProperty( gIODTCompatibleKey))) {
246*2c2f96dcSApple OSS Distributions 		parent->setName( parent->getName(), gIODTPlane );
247*2c2f96dcSApple OSS Distributions 		parent->setName((const char *) prop->getBytesNoCopy());
248*2c2f96dcSApple OSS Distributions 	}
249*2c2f96dcSApple OSS Distributions 
250*2c2f96dcSApple OSS Distributions 	// attach tree to meta root
251*2c2f96dcSApple OSS Distributions 	parent->attachToParent( IORegistryEntry::getRegistryRoot(), gIODTPlane);
252*2c2f96dcSApple OSS Distributions 	parent->release();
253*2c2f96dcSApple OSS Distributions 
254*2c2f96dcSApple OSS Distributions 	if (freeDT) {
255*2c2f96dcSApple OSS Distributions 		// free original device tree
256*2c2f96dcSApple OSS Distributions 		SecureDTInit(NULL, 0);
257*2c2f96dcSApple OSS Distributions 		IODTFreeLoaderInfo( "DeviceTree",
258*2c2f96dcSApple OSS Distributions 		    (void *)dtMap[0], (int) round_page(dtMap[1]));
259*2c2f96dcSApple OSS Distributions 	}
260*2c2f96dcSApple OSS Distributions 
261*2c2f96dcSApple OSS Distributions 	// adjust tree
262*2c2f96dcSApple OSS Distributions 
263*2c2f96dcSApple OSS Distributions 	gIODTSharedInterrupts = OSDictionary::withCapacity(4);
264*2c2f96dcSApple OSS Distributions 	allInts = OSDictionary::withCapacity(4);
265*2c2f96dcSApple OSS Distributions 	intMap = false;
266*2c2f96dcSApple OSS Distributions 	regIter = IORegistryIterator::iterateOver( gIODTPlane,
267*2c2f96dcSApple OSS Distributions 	    kIORegistryIterateRecursively );
268*2c2f96dcSApple OSS Distributions 	assert( regIter && allInts && gIODTSharedInterrupts );
269*2c2f96dcSApple OSS Distributions 	if (regIter && allInts && gIODTSharedInterrupts) {
270*2c2f96dcSApple OSS Distributions 		while ((child = regIter->getNextObject())) {
271*2c2f96dcSApple OSS Distributions 			IODTMapInterruptsSharing( child, allInts );
272*2c2f96dcSApple OSS Distributions 			if (!intMap && child->getProperty( gIODTInterruptParentKey)) {
273*2c2f96dcSApple OSS Distributions 				intMap = true;
274*2c2f96dcSApple OSS Distributions 			}
275*2c2f96dcSApple OSS Distributions 			if (!strcmp("sep", child->getName())
276*2c2f96dcSApple OSS Distributions 			    || !strcmp("aop", child->getName())
277*2c2f96dcSApple OSS Distributions 			    || !strcmp("disp0", child->getName())) {
278*2c2f96dcSApple OSS Distributions 				uint32_t aotFlags = 1;
279*2c2f96dcSApple OSS Distributions 				child->setProperty("aot-power", &aotFlags, sizeof(aotFlags));
280*2c2f96dcSApple OSS Distributions 			}
281*2c2f96dcSApple OSS Distributions 		}
282*2c2f96dcSApple OSS Distributions 		regIter->release();
283*2c2f96dcSApple OSS Distributions 	}
284*2c2f96dcSApple OSS Distributions 
285*2c2f96dcSApple OSS Distributions #if IODTSUPPORTDEBUG
286*2c2f96dcSApple OSS Distributions 	parent->setProperty("allInts", allInts);
287*2c2f96dcSApple OSS Distributions 	parent->setProperty("sharedInts", gIODTSharedInterrupts);
288*2c2f96dcSApple OSS Distributions 
289*2c2f96dcSApple OSS Distributions 	regIter = IORegistryIterator::iterateOver( gIODTPlane,
290*2c2f96dcSApple OSS Distributions 	    kIORegistryIterateRecursively );
291*2c2f96dcSApple OSS Distributions 	if (regIter) {
292*2c2f96dcSApple OSS Distributions 		while ((child = regIter->getNextObject())) {
293*2c2f96dcSApple OSS Distributions 			OSArray *
294*2c2f96dcSApple OSS Distributions 			    array = OSDynamicCast(OSArray, child->getProperty( gIOInterruptSpecifiersKey ));
295*2c2f96dcSApple OSS Distributions 			for (UInt32 i = 0; array && (i < array->getCount()); i++) {
296*2c2f96dcSApple OSS Distributions 				IOOptionBits options;
297*2c2f96dcSApple OSS Distributions 				IOReturn ret = IODTGetInterruptOptions( child, i, &options );
298*2c2f96dcSApple OSS Distributions 				if ((ret != kIOReturnSuccess) || options) {
299*2c2f96dcSApple OSS Distributions 					IOLog("%s[%ld] %ld (%x)\n", child->getName(), i, options, ret);
300*2c2f96dcSApple OSS Distributions 				}
301*2c2f96dcSApple OSS Distributions 			}
302*2c2f96dcSApple OSS Distributions 		}
303*2c2f96dcSApple OSS Distributions 		regIter->release();
304*2c2f96dcSApple OSS Distributions 	}
305*2c2f96dcSApple OSS Distributions #endif
306*2c2f96dcSApple OSS Distributions 
307*2c2f96dcSApple OSS Distributions 	allInts->release();
308*2c2f96dcSApple OSS Distributions 
309*2c2f96dcSApple OSS Distributions 	if (intMap) {
310*2c2f96dcSApple OSS Distributions 		// set a key in the root to indicate we found NW interrupt mapping
311*2c2f96dcSApple OSS Distributions 		parent->setProperty( gIODTNWInterruptMappingKey,
312*2c2f96dcSApple OSS Distributions 		    (OSObject *) gIODTNWInterruptMappingKey );
313*2c2f96dcSApple OSS Distributions 	}
314*2c2f96dcSApple OSS Distributions 
315*2c2f96dcSApple OSS Distributions 	return parent;
316*2c2f96dcSApple OSS Distributions }
317*2c2f96dcSApple OSS Distributions #endif
318*2c2f96dcSApple OSS Distributions 
319*2c2f96dcSApple OSS Distributions int
IODTGetLoaderInfo(const char * key,void ** infoAddr,int * infoSize)320*2c2f96dcSApple OSS Distributions IODTGetLoaderInfo( const char *key, void **infoAddr, int *infoSize )
321*2c2f96dcSApple OSS Distributions {
322*2c2f96dcSApple OSS Distributions 	IORegistryEntry             *chosen;
323*2c2f96dcSApple OSS Distributions 	OSData                              *propObj;
324*2c2f96dcSApple OSS Distributions 	dtptr_t                             *propPtr;
325*2c2f96dcSApple OSS Distributions 	unsigned int                propSize;
326*2c2f96dcSApple OSS Distributions 	int ret = -1;
327*2c2f96dcSApple OSS Distributions 
328*2c2f96dcSApple OSS Distributions 	chosen = IORegistryEntry::fromPath( "/chosen/memory-map", gIODTPlane );
329*2c2f96dcSApple OSS Distributions 	if (chosen == NULL) {
330*2c2f96dcSApple OSS Distributions 		return -1;
331*2c2f96dcSApple OSS Distributions 	}
332*2c2f96dcSApple OSS Distributions 
333*2c2f96dcSApple OSS Distributions 	propObj = OSDynamicCast( OSData, chosen->getProperty(key));
334*2c2f96dcSApple OSS Distributions 	if (propObj == NULL) {
335*2c2f96dcSApple OSS Distributions 		goto cleanup;
336*2c2f96dcSApple OSS Distributions 	}
337*2c2f96dcSApple OSS Distributions 
338*2c2f96dcSApple OSS Distributions 	propSize = propObj->getLength();
339*2c2f96dcSApple OSS Distributions 	if (propSize != (2 * sizeof(dtptr_t))) {
340*2c2f96dcSApple OSS Distributions 		goto cleanup;
341*2c2f96dcSApple OSS Distributions 	}
342*2c2f96dcSApple OSS Distributions 
343*2c2f96dcSApple OSS Distributions 	propPtr = (dtptr_t *)propObj->getBytesNoCopy();
344*2c2f96dcSApple OSS Distributions 	if (propPtr == NULL) {
345*2c2f96dcSApple OSS Distributions 		goto cleanup;
346*2c2f96dcSApple OSS Distributions 	}
347*2c2f96dcSApple OSS Distributions 
348*2c2f96dcSApple OSS Distributions 	*infoAddr = (void *)(uintptr_t) (propPtr[0]);
349*2c2f96dcSApple OSS Distributions 	*infoSize = (int)               (propPtr[1]);
350*2c2f96dcSApple OSS Distributions 
351*2c2f96dcSApple OSS Distributions 	ret = 0;
352*2c2f96dcSApple OSS Distributions 
353*2c2f96dcSApple OSS Distributions cleanup:
354*2c2f96dcSApple OSS Distributions 	chosen->release();
355*2c2f96dcSApple OSS Distributions 
356*2c2f96dcSApple OSS Distributions 	return ret;
357*2c2f96dcSApple OSS Distributions }
358*2c2f96dcSApple OSS Distributions 
359*2c2f96dcSApple OSS Distributions void
IODTFreeLoaderInfo(const char * key,void * infoAddr,int infoSize)360*2c2f96dcSApple OSS Distributions IODTFreeLoaderInfo( const char *key, void *infoAddr, int infoSize )
361*2c2f96dcSApple OSS Distributions {
362*2c2f96dcSApple OSS Distributions 	vm_offset_t                 range[2];
363*2c2f96dcSApple OSS Distributions 	IORegistryEntry             *chosen;
364*2c2f96dcSApple OSS Distributions 
365*2c2f96dcSApple OSS Distributions 	range[0] = (vm_offset_t)infoAddr;
366*2c2f96dcSApple OSS Distributions 	range[1] = (vm_offset_t)infoSize;
367*2c2f96dcSApple OSS Distributions 	FreePhysicalMemory( range );
368*2c2f96dcSApple OSS Distributions 
369*2c2f96dcSApple OSS Distributions 	if (key != NULL) {
370*2c2f96dcSApple OSS Distributions 		chosen = IORegistryEntry::fromPath( "/chosen/memory-map", gIODTPlane );
371*2c2f96dcSApple OSS Distributions 		if (chosen != NULL) {
372*2c2f96dcSApple OSS Distributions 			chosen->removeProperty(key);
373*2c2f96dcSApple OSS Distributions 			chosen->release();
374*2c2f96dcSApple OSS Distributions 		}
375*2c2f96dcSApple OSS Distributions 	}
376*2c2f96dcSApple OSS Distributions }
377*2c2f96dcSApple OSS Distributions 
378*2c2f96dcSApple OSS Distributions int
IODTGetDefault(const char * key,void * infoAddr,unsigned int infoSize)379*2c2f96dcSApple OSS Distributions IODTGetDefault(const char *key, void *infoAddr, unsigned int infoSize )
380*2c2f96dcSApple OSS Distributions {
381*2c2f96dcSApple OSS Distributions 	IORegistryEntry             *defaults;
382*2c2f96dcSApple OSS Distributions 	OSData                      *defaultObj;
383*2c2f96dcSApple OSS Distributions 	unsigned int                defaultSize;
384*2c2f96dcSApple OSS Distributions 
385*2c2f96dcSApple OSS Distributions 	defaults = IORegistryEntry::fromPath( "/defaults", gIODTPlane );
386*2c2f96dcSApple OSS Distributions 	if (defaults == NULL) {
387*2c2f96dcSApple OSS Distributions 		return -1;
388*2c2f96dcSApple OSS Distributions 	}
389*2c2f96dcSApple OSS Distributions 
390*2c2f96dcSApple OSS Distributions 	defaultObj = OSDynamicCast( OSData, defaults->getProperty(key));
391*2c2f96dcSApple OSS Distributions 
392*2c2f96dcSApple OSS Distributions 	if (defaultObj == NULL) {
393*2c2f96dcSApple OSS Distributions 		defaults->release();
394*2c2f96dcSApple OSS Distributions 		return -1;
395*2c2f96dcSApple OSS Distributions 	}
396*2c2f96dcSApple OSS Distributions 
397*2c2f96dcSApple OSS Distributions 	defaultSize = defaultObj->getLength();
398*2c2f96dcSApple OSS Distributions 	if (defaultSize > infoSize) {
399*2c2f96dcSApple OSS Distributions 		defaults->release();
400*2c2f96dcSApple OSS Distributions 		return -1;
401*2c2f96dcSApple OSS Distributions 	}
402*2c2f96dcSApple OSS Distributions 
403*2c2f96dcSApple OSS Distributions 	memcpy( infoAddr, defaultObj->getBytesNoCopy(), defaultSize );
404*2c2f96dcSApple OSS Distributions 
405*2c2f96dcSApple OSS Distributions 	defaults->release();
406*2c2f96dcSApple OSS Distributions 	return 0;
407*2c2f96dcSApple OSS Distributions }
408*2c2f96dcSApple OSS Distributions 
409*2c2f96dcSApple OSS Distributions static void
FreePhysicalMemory(vm_offset_t * range)410*2c2f96dcSApple OSS Distributions FreePhysicalMemory( vm_offset_t * range )
411*2c2f96dcSApple OSS Distributions {
412*2c2f96dcSApple OSS Distributions 	vm_offset_t virt;
413*2c2f96dcSApple OSS Distributions 
414*2c2f96dcSApple OSS Distributions 	virt = ml_static_ptovirt( range[0] );
415*2c2f96dcSApple OSS Distributions 	if (virt) {
416*2c2f96dcSApple OSS Distributions 		ml_static_mfree( virt, range[1] );
417*2c2f96dcSApple OSS Distributions 	}
418*2c2f96dcSApple OSS Distributions }
419*2c2f96dcSApple OSS Distributions 
420*2c2f96dcSApple OSS Distributions static IORegistryEntry *
MakeReferenceTable(DTEntry dtEntry,bool copy)421*2c2f96dcSApple OSS Distributions MakeReferenceTable( DTEntry dtEntry, bool copy )
422*2c2f96dcSApple OSS Distributions {
423*2c2f96dcSApple OSS Distributions 	IORegistryEntry             *regEntry;
424*2c2f96dcSApple OSS Distributions 	OSDictionary                *propTable;
425*2c2f96dcSApple OSS Distributions 	const OSSymbol              *nameKey;
426*2c2f96dcSApple OSS Distributions 	OSData                              *data;
427*2c2f96dcSApple OSS Distributions 	const OSSymbol              *sym;
428*2c2f96dcSApple OSS Distributions 	OpaqueDTPropertyIterator    dtIter;
429*2c2f96dcSApple OSS Distributions 	void const                  *prop;
430*2c2f96dcSApple OSS Distributions 	unsigned int                propSize;
431*2c2f96dcSApple OSS Distributions 	char const                                      *name;
432*2c2f96dcSApple OSS Distributions 	char                                location[32];
433*2c2f96dcSApple OSS Distributions 	bool                                noLocation = true;
434*2c2f96dcSApple OSS Distributions 	bool                                kernelOnly;
435*2c2f96dcSApple OSS Distributions 
436*2c2f96dcSApple OSS Distributions 	regEntry = new IOService;
437*2c2f96dcSApple OSS Distributions 
438*2c2f96dcSApple OSS Distributions 	if (regEntry && (false == regEntry->init())) {
439*2c2f96dcSApple OSS Distributions 		regEntry->release();
440*2c2f96dcSApple OSS Distributions 		regEntry = NULL;
441*2c2f96dcSApple OSS Distributions 	}
442*2c2f96dcSApple OSS Distributions 
443*2c2f96dcSApple OSS Distributions 	if (regEntry &&
444*2c2f96dcSApple OSS Distributions 	    (kSuccess == SecureDTInitPropertyIterator( dtEntry, &dtIter))) {
445*2c2f96dcSApple OSS Distributions 		kernelOnly = (kSuccess == SecureDTGetProperty(dtEntry, "kernel-only", &prop, &propSize));
446*2c2f96dcSApple OSS Distributions 		propTable = regEntry->getPropertyTable();
447*2c2f96dcSApple OSS Distributions 
448*2c2f96dcSApple OSS Distributions 		while (kSuccess == SecureDTIterateProperties( &dtIter, &name)) {
449*2c2f96dcSApple OSS Distributions 			if (kSuccess != SecureDTGetProperty( dtEntry, name, &prop, &propSize )) {
450*2c2f96dcSApple OSS Distributions 				continue;
451*2c2f96dcSApple OSS Distributions 			}
452*2c2f96dcSApple OSS Distributions 
453*2c2f96dcSApple OSS Distributions 			if (copy) {
454*2c2f96dcSApple OSS Distributions 				nameKey = OSSymbol::withCString(name);
455*2c2f96dcSApple OSS Distributions 				data = OSData::withBytes(prop, propSize);
456*2c2f96dcSApple OSS Distributions 			} else {
457*2c2f96dcSApple OSS Distributions 				nameKey = OSSymbol::withCStringNoCopy(name);
458*2c2f96dcSApple OSS Distributions 				/* There is no OSDataConst or other way to indicate
459*2c2f96dcSApple OSS Distributions 				 * that the OSData is actually immutable. But CTRR
460*2c2f96dcSApple OSS Distributions 				 * will catch any write attempts. */
461*2c2f96dcSApple OSS Distributions 				data = OSData::withBytesNoCopy((void**)(uintptr_t)prop, propSize);
462*2c2f96dcSApple OSS Distributions 			}
463*2c2f96dcSApple OSS Distributions 			assert( nameKey && data );
464*2c2f96dcSApple OSS Distributions 
465*2c2f96dcSApple OSS Distributions #if DEVELOPMENT || DEBUG
466*2c2f96dcSApple OSS Distributions #pragma unused(kernelOnly)
467*2c2f96dcSApple OSS Distributions #else
468*2c2f96dcSApple OSS Distributions 			if (kernelOnly) {
469*2c2f96dcSApple OSS Distributions 				data->setSerializable(false);
470*2c2f96dcSApple OSS Distributions 			}
471*2c2f96dcSApple OSS Distributions #endif
472*2c2f96dcSApple OSS Distributions 
473*2c2f96dcSApple OSS Distributions 			propTable->setObject( nameKey, data);
474*2c2f96dcSApple OSS Distributions 			data->release();
475*2c2f96dcSApple OSS Distributions 			nameKey->release();
476*2c2f96dcSApple OSS Distributions 
477*2c2f96dcSApple OSS Distributions 			if (nameKey == gIODTNameKey) {
478*2c2f96dcSApple OSS Distributions 				if (copy) {
479*2c2f96dcSApple OSS Distributions 					sym = OSSymbol::withCString((const char *) prop);
480*2c2f96dcSApple OSS Distributions 				} else {
481*2c2f96dcSApple OSS Distributions 					sym = OSSymbol::withCStringNoCopy((const char *) prop);
482*2c2f96dcSApple OSS Distributions 				}
483*2c2f96dcSApple OSS Distributions 				regEntry->setName( sym );
484*2c2f96dcSApple OSS Distributions 				sym->release();
485*2c2f96dcSApple OSS Distributions 			} else if (nameKey == gIODTUnitKey) {
486*2c2f96dcSApple OSS Distributions 				// all OF strings are null terminated... except this one
487*2c2f96dcSApple OSS Distributions 				if (propSize >= (int) sizeof(location)) {
488*2c2f96dcSApple OSS Distributions 					propSize = sizeof(location) - 1;
489*2c2f96dcSApple OSS Distributions 				}
490*2c2f96dcSApple OSS Distributions 				strncpy( location, (const char *) prop, propSize );
491*2c2f96dcSApple OSS Distributions 				location[propSize] = 0;
492*2c2f96dcSApple OSS Distributions 				regEntry->setLocation( location );
493*2c2f96dcSApple OSS Distributions 				propTable->removeObject( gIODTUnitKey );
494*2c2f96dcSApple OSS Distributions 				noLocation = false;
495*2c2f96dcSApple OSS Distributions 			} else if (noLocation && (!strncmp(name, "reg", sizeof("reg")))) {
496*2c2f96dcSApple OSS Distributions 				// default location - override later
497*2c2f96dcSApple OSS Distributions 				snprintf(location, sizeof(location), "%X", *((uint32_t *) prop));
498*2c2f96dcSApple OSS Distributions 				regEntry->setLocation( location );
499*2c2f96dcSApple OSS Distributions 			}
500*2c2f96dcSApple OSS Distributions 		}
501*2c2f96dcSApple OSS Distributions 	}
502*2c2f96dcSApple OSS Distributions 
503*2c2f96dcSApple OSS Distributions 	return regEntry;
504*2c2f96dcSApple OSS Distributions }
505*2c2f96dcSApple OSS Distributions 
506*2c2f96dcSApple OSS Distributions static void
AddPHandle(IORegistryEntry * regEntry)507*2c2f96dcSApple OSS Distributions AddPHandle( IORegistryEntry * regEntry )
508*2c2f96dcSApple OSS Distributions {
509*2c2f96dcSApple OSS Distributions 	OSData *    data;
510*2c2f96dcSApple OSS Distributions 
511*2c2f96dcSApple OSS Distributions 	if (regEntry->getProperty( gIODTInterruptCellKey)
512*2c2f96dcSApple OSS Distributions 	    && (data = OSDynamicCast( OSData, regEntry->getProperty( gIODTPHandleKey )))) {
513*2c2f96dcSApple OSS Distributions 		// a possible interrupt-parent
514*2c2f96dcSApple OSS Distributions 		gIODTPHandles->setObject( data );
515*2c2f96dcSApple OSS Distributions 		gIODTPHandleMap->setObject( regEntry );
516*2c2f96dcSApple OSS Distributions 	}
517*2c2f96dcSApple OSS Distributions }
518*2c2f96dcSApple OSS Distributions 
519*2c2f96dcSApple OSS Distributions static LIBKERN_RETURNS_NOT_RETAINED IORegistryEntry *
FindPHandle(UInt32 phandle)520*2c2f96dcSApple OSS Distributions FindPHandle( UInt32 phandle )
521*2c2f96dcSApple OSS Distributions {
522*2c2f96dcSApple OSS Distributions 	OSData                      *data;
523*2c2f96dcSApple OSS Distributions 	IORegistryEntry *regEntry = NULL;
524*2c2f96dcSApple OSS Distributions 	int                         i;
525*2c2f96dcSApple OSS Distributions 
526*2c2f96dcSApple OSS Distributions 	for (i = 0; (data = (OSData *)gIODTPHandles->getObject( i )); i++) {
527*2c2f96dcSApple OSS Distributions 		if (phandle == *((UInt32 *)data->getBytesNoCopy())) {
528*2c2f96dcSApple OSS Distributions 			regEntry = (IORegistryEntry *)
529*2c2f96dcSApple OSS Distributions 			    gIODTPHandleMap->getObject( i );
530*2c2f96dcSApple OSS Distributions 			break;
531*2c2f96dcSApple OSS Distributions 		}
532*2c2f96dcSApple OSS Distributions 	}
533*2c2f96dcSApple OSS Distributions 
534*2c2f96dcSApple OSS Distributions 	return regEntry;
535*2c2f96dcSApple OSS Distributions }
536*2c2f96dcSApple OSS Distributions 
537*2c2f96dcSApple OSS Distributions static bool
GetUInt32(IORegistryEntry * regEntry,const OSSymbol * name,UInt32 * value)538*2c2f96dcSApple OSS Distributions GetUInt32( IORegistryEntry * regEntry, const OSSymbol * name,
539*2c2f96dcSApple OSS Distributions     UInt32 * value )
540*2c2f96dcSApple OSS Distributions {
541*2c2f96dcSApple OSS Distributions 	OSObject * obj;
542*2c2f96dcSApple OSS Distributions 	OSData   * data;
543*2c2f96dcSApple OSS Distributions 	bool       result;
544*2c2f96dcSApple OSS Distributions 
545*2c2f96dcSApple OSS Distributions 	if (!(obj = regEntry->copyProperty(name))) {
546*2c2f96dcSApple OSS Distributions 		return false;
547*2c2f96dcSApple OSS Distributions 	}
548*2c2f96dcSApple OSS Distributions 
549*2c2f96dcSApple OSS Distributions 	result = ((data = OSDynamicCast(OSData, obj)) && (sizeof(UInt32) == data->getLength()));
550*2c2f96dcSApple OSS Distributions 	if (result) {
551*2c2f96dcSApple OSS Distributions 		*value = *((UInt32 *) data->getBytesNoCopy());
552*2c2f96dcSApple OSS Distributions 	}
553*2c2f96dcSApple OSS Distributions 
554*2c2f96dcSApple OSS Distributions 	obj->release();
555*2c2f96dcSApple OSS Distributions 	return result;
556*2c2f96dcSApple OSS Distributions }
557*2c2f96dcSApple OSS Distributions 
558*2c2f96dcSApple OSS Distributions static IORegistryEntry *
IODTFindInterruptParent(IORegistryEntry * regEntry,IOItemCount index)559*2c2f96dcSApple OSS Distributions IODTFindInterruptParent( IORegistryEntry * regEntry, IOItemCount index )
560*2c2f96dcSApple OSS Distributions {
561*2c2f96dcSApple OSS Distributions 	IORegistryEntry *   parent;
562*2c2f96dcSApple OSS Distributions 	UInt32              phandle;
563*2c2f96dcSApple OSS Distributions 	OSData          *   data;
564*2c2f96dcSApple OSS Distributions 	unsigned int        len;
565*2c2f96dcSApple OSS Distributions 
566*2c2f96dcSApple OSS Distributions 	if ((data = OSDynamicCast( OSData, regEntry->getProperty( gIODTInterruptParentKey )))
567*2c2f96dcSApple OSS Distributions 	    && (sizeof(UInt32) <= (len = data->getLength()))) {
568*2c2f96dcSApple OSS Distributions 		if (((index + 1) * sizeof(UInt32)) > len) {
569*2c2f96dcSApple OSS Distributions 			index = 0;
570*2c2f96dcSApple OSS Distributions 		}
571*2c2f96dcSApple OSS Distributions 		phandle = ((UInt32 *) data->getBytesNoCopy())[index];
572*2c2f96dcSApple OSS Distributions 		parent = FindPHandle( phandle );
573*2c2f96dcSApple OSS Distributions 	} else if (NULL == regEntry->getProperty( "interrupt-controller")) {
574*2c2f96dcSApple OSS Distributions 		parent = regEntry->getParentEntry( gIODTPlane);
575*2c2f96dcSApple OSS Distributions 	} else {
576*2c2f96dcSApple OSS Distributions 		parent = NULL;
577*2c2f96dcSApple OSS Distributions 	}
578*2c2f96dcSApple OSS Distributions 
579*2c2f96dcSApple OSS Distributions 	return parent;
580*2c2f96dcSApple OSS Distributions }
581*2c2f96dcSApple OSS Distributions 
582*2c2f96dcSApple OSS Distributions const OSSymbol *
IODTInterruptControllerName(IORegistryEntry * regEntry)583*2c2f96dcSApple OSS Distributions IODTInterruptControllerName( IORegistryEntry * regEntry )
584*2c2f96dcSApple OSS Distributions {
585*2c2f96dcSApple OSS Distributions 	const OSSymbol      *sym;
586*2c2f96dcSApple OSS Distributions 	UInt32              phandle;
587*2c2f96dcSApple OSS Distributions 	bool                ok;
588*2c2f96dcSApple OSS Distributions 	char                buf[48];
589*2c2f96dcSApple OSS Distributions 
590*2c2f96dcSApple OSS Distributions 	ok = GetUInt32( regEntry, gIODTPHandleKey, &phandle);
591*2c2f96dcSApple OSS Distributions 	assert( ok );
592*2c2f96dcSApple OSS Distributions 
593*2c2f96dcSApple OSS Distributions 	if (ok) {
594*2c2f96dcSApple OSS Distributions 		snprintf(buf, sizeof(buf), "IOInterruptController%08X", (uint32_t)phandle);
595*2c2f96dcSApple OSS Distributions 		sym = OSSymbol::withCString( buf );
596*2c2f96dcSApple OSS Distributions 	} else {
597*2c2f96dcSApple OSS Distributions 		sym = NULL;
598*2c2f96dcSApple OSS Distributions 	}
599*2c2f96dcSApple OSS Distributions 
600*2c2f96dcSApple OSS Distributions 	return sym;
601*2c2f96dcSApple OSS Distributions }
602*2c2f96dcSApple OSS Distributions 
603*2c2f96dcSApple OSS Distributions #define unexpected(a) { kprintf("unexpected %s:%d\n", __FILE__, __LINE__); a; }
604*2c2f96dcSApple OSS Distributions 
605*2c2f96dcSApple OSS Distributions static void
IODTGetICellCounts(IORegistryEntry * regEntry,UInt32 * iCellCount,UInt32 * aCellCount)606*2c2f96dcSApple OSS Distributions IODTGetICellCounts( IORegistryEntry * regEntry,
607*2c2f96dcSApple OSS Distributions     UInt32 * iCellCount, UInt32 * aCellCount)
608*2c2f96dcSApple OSS Distributions {
609*2c2f96dcSApple OSS Distributions 	if (!GetUInt32( regEntry, gIODTInterruptCellKey, iCellCount)) {
610*2c2f96dcSApple OSS Distributions 		unexpected( *iCellCount = 1 );
611*2c2f96dcSApple OSS Distributions 	}
612*2c2f96dcSApple OSS Distributions 	if (!GetUInt32( regEntry, gIODTAddressCellKey, aCellCount)) {
613*2c2f96dcSApple OSS Distributions 		*aCellCount = 0;
614*2c2f96dcSApple OSS Distributions 	}
615*2c2f96dcSApple OSS Distributions }
616*2c2f96dcSApple OSS Distributions 
617*2c2f96dcSApple OSS Distributions static UInt32
IODTMapOneInterrupt(IORegistryEntry * regEntry,UInt32 * intSpec,UInt32 index,LIBKERN_RETURNS_RETAINED OSData ** spec,LIBKERN_RETURNS_RETAINED const OSSymbol ** controller)618*2c2f96dcSApple OSS Distributions IODTMapOneInterrupt( IORegistryEntry * regEntry, UInt32 * intSpec, UInt32 index,
619*2c2f96dcSApple OSS Distributions     LIBKERN_RETURNS_RETAINED OSData ** spec,
620*2c2f96dcSApple OSS Distributions     LIBKERN_RETURNS_RETAINED const OSSymbol ** controller )
621*2c2f96dcSApple OSS Distributions {
622*2c2f96dcSApple OSS Distributions 	IORegistryEntry *parent = NULL;
623*2c2f96dcSApple OSS Distributions 	OSData                      *data;
624*2c2f96dcSApple OSS Distributions 	UInt32                      *addrCmp;
625*2c2f96dcSApple OSS Distributions 	UInt32                      *maskCmp;
626*2c2f96dcSApple OSS Distributions 	UInt32                      *map;
627*2c2f96dcSApple OSS Distributions 	UInt32                      *endMap;
628*2c2f96dcSApple OSS Distributions 	UInt32                      acells, icells, pacells, picells, cell;
629*2c2f96dcSApple OSS Distributions 	UInt32                      i, original_icells;
630*2c2f96dcSApple OSS Distributions 	bool                        cmp, ok = false;
631*2c2f96dcSApple OSS Distributions 
632*2c2f96dcSApple OSS Distributions 	parent = IODTFindInterruptParent( regEntry, index );
633*2c2f96dcSApple OSS Distributions 	IODTGetICellCounts( parent, &icells, &acells );
634*2c2f96dcSApple OSS Distributions 	addrCmp = NULL;
635*2c2f96dcSApple OSS Distributions 	if (acells) {
636*2c2f96dcSApple OSS Distributions 		data = OSDynamicCast( OSData, regEntry->getProperty( "reg" ));
637*2c2f96dcSApple OSS Distributions 		if (data && (data->getLength() >= (acells * sizeof(UInt32)))) {
638*2c2f96dcSApple OSS Distributions 			addrCmp = (UInt32 *) data->getBytesNoCopy();
639*2c2f96dcSApple OSS Distributions 		}
640*2c2f96dcSApple OSS Distributions 	}
641*2c2f96dcSApple OSS Distributions 	original_icells = icells;
642*2c2f96dcSApple OSS Distributions 	regEntry = parent;
643*2c2f96dcSApple OSS Distributions 
644*2c2f96dcSApple OSS Distributions 	do {
645*2c2f96dcSApple OSS Distributions #if IODTSUPPORTDEBUG
646*2c2f96dcSApple OSS Distributions 		kprintf("IODTMapOneInterrupt: current regEntry name %s\n", regEntry->getName());
647*2c2f96dcSApple OSS Distributions 		kprintf("acells - icells: ");
648*2c2f96dcSApple OSS Distributions 		for (i = 0; i < acells; i++) {
649*2c2f96dcSApple OSS Distributions 			kprintf("0x%08X ", addrCmp[i]);
650*2c2f96dcSApple OSS Distributions 		}
651*2c2f96dcSApple OSS Distributions 		kprintf("- ");
652*2c2f96dcSApple OSS Distributions 		for (i = 0; i < icells; i++) {
653*2c2f96dcSApple OSS Distributions 			kprintf("0x%08X ", intSpec[i]);
654*2c2f96dcSApple OSS Distributions 		}
655*2c2f96dcSApple OSS Distributions 		kprintf("\n");
656*2c2f96dcSApple OSS Distributions #endif
657*2c2f96dcSApple OSS Distributions 
658*2c2f96dcSApple OSS Distributions 		if (parent && (data = OSDynamicCast( OSData,
659*2c2f96dcSApple OSS Distributions 		    regEntry->getProperty( "interrupt-controller")))) {
660*2c2f96dcSApple OSS Distributions 			// found a controller - don't want to follow cascaded controllers
661*2c2f96dcSApple OSS Distributions 			parent = NULL;
662*2c2f96dcSApple OSS Distributions 			*spec = OSData::withBytesNoCopy((void *) intSpec,
663*2c2f96dcSApple OSS Distributions 			    icells * sizeof(UInt32));
664*2c2f96dcSApple OSS Distributions 			*controller = IODTInterruptControllerName( regEntry );
665*2c2f96dcSApple OSS Distributions 			ok = (*spec && *controller);
666*2c2f96dcSApple OSS Distributions 		} else if (parent && (data = OSDynamicCast( OSData,
667*2c2f96dcSApple OSS Distributions 		    regEntry->getProperty( "interrupt-map")))) {
668*2c2f96dcSApple OSS Distributions 			// interrupt-map
669*2c2f96dcSApple OSS Distributions 			map = (UInt32 *) data->getBytesNoCopy();
670*2c2f96dcSApple OSS Distributions 			endMap = map + (data->getLength() / sizeof(UInt32));
671*2c2f96dcSApple OSS Distributions 			data = OSDynamicCast( OSData, regEntry->getProperty( "interrupt-map-mask" ));
672*2c2f96dcSApple OSS Distributions 			if (data && (data->getLength() >= ((acells + icells) * sizeof(UInt32)))) {
673*2c2f96dcSApple OSS Distributions 				maskCmp = (UInt32 *) data->getBytesNoCopy();
674*2c2f96dcSApple OSS Distributions 			} else {
675*2c2f96dcSApple OSS Distributions 				maskCmp = NULL;
676*2c2f96dcSApple OSS Distributions 			}
677*2c2f96dcSApple OSS Distributions 
678*2c2f96dcSApple OSS Distributions #if IODTSUPPORTDEBUG
679*2c2f96dcSApple OSS Distributions 			if (maskCmp) {
680*2c2f96dcSApple OSS Distributions 				kprintf("        maskCmp: ");
681*2c2f96dcSApple OSS Distributions 				for (i = 0; i < acells + icells; i++) {
682*2c2f96dcSApple OSS Distributions 					if (i == acells) {
683*2c2f96dcSApple OSS Distributions 						kprintf("- ");
684*2c2f96dcSApple OSS Distributions 					}
685*2c2f96dcSApple OSS Distributions 					kprintf("0x%08X ", maskCmp[i]);
686*2c2f96dcSApple OSS Distributions 				}
687*2c2f96dcSApple OSS Distributions 				kprintf("\n");
688*2c2f96dcSApple OSS Distributions 				kprintf("         masked: ");
689*2c2f96dcSApple OSS Distributions 				for (i = 0; i < acells + icells; i++) {
690*2c2f96dcSApple OSS Distributions 					if (i == acells) {
691*2c2f96dcSApple OSS Distributions 						kprintf("- ");
692*2c2f96dcSApple OSS Distributions 					}
693*2c2f96dcSApple OSS Distributions 					kprintf("0x%08X ", ((i < acells) ? addrCmp[i] : intSpec[i - acells]) & maskCmp[i]);
694*2c2f96dcSApple OSS Distributions 				}
695*2c2f96dcSApple OSS Distributions 				kprintf("\n");
696*2c2f96dcSApple OSS Distributions 			} else {
697*2c2f96dcSApple OSS Distributions 				kprintf("no maskCmp\n");
698*2c2f96dcSApple OSS Distributions 			}
699*2c2f96dcSApple OSS Distributions #endif
700*2c2f96dcSApple OSS Distributions 			do {
701*2c2f96dcSApple OSS Distributions #if IODTSUPPORTDEBUG
702*2c2f96dcSApple OSS Distributions 				kprintf("            map: ");
703*2c2f96dcSApple OSS Distributions 				for (i = 0; i < acells + icells; i++) {
704*2c2f96dcSApple OSS Distributions 					if (i == acells) {
705*2c2f96dcSApple OSS Distributions 						kprintf("- ");
706*2c2f96dcSApple OSS Distributions 					}
707*2c2f96dcSApple OSS Distributions 					kprintf("0x%08X ", map[i]);
708*2c2f96dcSApple OSS Distributions 				}
709*2c2f96dcSApple OSS Distributions 				kprintf("\n");
710*2c2f96dcSApple OSS Distributions #endif
711*2c2f96dcSApple OSS Distributions 				for (i = 0, cmp = true; cmp && (i < (acells + icells)); i++) {
712*2c2f96dcSApple OSS Distributions 					cell = (i < acells) ? addrCmp[i] : intSpec[i - acells];
713*2c2f96dcSApple OSS Distributions 					if (maskCmp) {
714*2c2f96dcSApple OSS Distributions 						cell &= maskCmp[i];
715*2c2f96dcSApple OSS Distributions 					}
716*2c2f96dcSApple OSS Distributions 					cmp = (cell == map[i]);
717*2c2f96dcSApple OSS Distributions 				}
718*2c2f96dcSApple OSS Distributions 
719*2c2f96dcSApple OSS Distributions 				map += acells + icells;
720*2c2f96dcSApple OSS Distributions 				if (NULL == (parent = FindPHandle( *(map++)))) {
721*2c2f96dcSApple OSS Distributions 					unexpected(break);
722*2c2f96dcSApple OSS Distributions 				}
723*2c2f96dcSApple OSS Distributions 
724*2c2f96dcSApple OSS Distributions 				IODTGetICellCounts( parent, &picells, &pacells );
725*2c2f96dcSApple OSS Distributions 				if (cmp) {
726*2c2f96dcSApple OSS Distributions 					addrCmp = map;
727*2c2f96dcSApple OSS Distributions 					intSpec = map + pacells;
728*2c2f96dcSApple OSS Distributions 					regEntry = parent;
729*2c2f96dcSApple OSS Distributions 				} else {
730*2c2f96dcSApple OSS Distributions 					map += pacells + picells;
731*2c2f96dcSApple OSS Distributions 				}
732*2c2f96dcSApple OSS Distributions 			} while (!cmp && (map < endMap));
733*2c2f96dcSApple OSS Distributions 			if (!cmp) {
734*2c2f96dcSApple OSS Distributions 				parent = NULL;
735*2c2f96dcSApple OSS Distributions 			}
736*2c2f96dcSApple OSS Distributions 		}
737*2c2f96dcSApple OSS Distributions 
738*2c2f96dcSApple OSS Distributions 		if (parent) {
739*2c2f96dcSApple OSS Distributions 			IODTGetICellCounts( parent, &icells, &acells );
740*2c2f96dcSApple OSS Distributions 			regEntry = parent;
741*2c2f96dcSApple OSS Distributions 		}
742*2c2f96dcSApple OSS Distributions 	} while (parent);
743*2c2f96dcSApple OSS Distributions 
744*2c2f96dcSApple OSS Distributions 	return ok ? original_icells : 0;
745*2c2f96dcSApple OSS Distributions }
746*2c2f96dcSApple OSS Distributions 
747*2c2f96dcSApple OSS Distributions IOReturn
IODTGetInterruptOptions(IORegistryEntry * regEntry,int source,IOOptionBits * options)748*2c2f96dcSApple OSS Distributions IODTGetInterruptOptions( IORegistryEntry * regEntry, int source, IOOptionBits * options )
749*2c2f96dcSApple OSS Distributions {
750*2c2f96dcSApple OSS Distributions 	OSArray *   controllers;
751*2c2f96dcSApple OSS Distributions 	OSArray *   specifiers;
752*2c2f96dcSApple OSS Distributions 	OSArray *   shared;
753*2c2f96dcSApple OSS Distributions 	OSObject *  spec;
754*2c2f96dcSApple OSS Distributions 	OSObject *  oneSpec;
755*2c2f96dcSApple OSS Distributions 
756*2c2f96dcSApple OSS Distributions 	*options = 0;
757*2c2f96dcSApple OSS Distributions 
758*2c2f96dcSApple OSS Distributions 	controllers = OSDynamicCast(OSArray, regEntry->getProperty(gIOInterruptControllersKey));
759*2c2f96dcSApple OSS Distributions 	specifiers  = OSDynamicCast(OSArray, regEntry->getProperty(gIOInterruptSpecifiersKey));
760*2c2f96dcSApple OSS Distributions 
761*2c2f96dcSApple OSS Distributions 	if (!controllers || !specifiers) {
762*2c2f96dcSApple OSS Distributions 		return kIOReturnNoInterrupt;
763*2c2f96dcSApple OSS Distributions 	}
764*2c2f96dcSApple OSS Distributions 
765*2c2f96dcSApple OSS Distributions 	shared = (OSArray *) gIODTSharedInterrupts->getObject(
766*2c2f96dcSApple OSS Distributions 		(const OSSymbol *) controllers->getObject(source));
767*2c2f96dcSApple OSS Distributions 	if (!shared) {
768*2c2f96dcSApple OSS Distributions 		return kIOReturnSuccess;
769*2c2f96dcSApple OSS Distributions 	}
770*2c2f96dcSApple OSS Distributions 
771*2c2f96dcSApple OSS Distributions 	spec = specifiers->getObject(source);
772*2c2f96dcSApple OSS Distributions 	if (!spec) {
773*2c2f96dcSApple OSS Distributions 		return kIOReturnNoInterrupt;
774*2c2f96dcSApple OSS Distributions 	}
775*2c2f96dcSApple OSS Distributions 
776*2c2f96dcSApple OSS Distributions 	for (unsigned int i = 0;
777*2c2f96dcSApple OSS Distributions 	    (oneSpec = shared->getObject(i))
778*2c2f96dcSApple OSS Distributions 	    && (!oneSpec->isEqualTo(spec));
779*2c2f96dcSApple OSS Distributions 	    i++) {
780*2c2f96dcSApple OSS Distributions 	}
781*2c2f96dcSApple OSS Distributions 
782*2c2f96dcSApple OSS Distributions 	if (oneSpec) {
783*2c2f96dcSApple OSS Distributions 		*options = kIODTInterruptShared;
784*2c2f96dcSApple OSS Distributions 	}
785*2c2f96dcSApple OSS Distributions 
786*2c2f96dcSApple OSS Distributions 	return kIOReturnSuccess;
787*2c2f96dcSApple OSS Distributions }
788*2c2f96dcSApple OSS Distributions 
789*2c2f96dcSApple OSS Distributions static bool
IODTMapInterruptsSharing(IORegistryEntry * regEntry,OSDictionary * allInts)790*2c2f96dcSApple OSS Distributions IODTMapInterruptsSharing( IORegistryEntry * regEntry, OSDictionary * allInts )
791*2c2f96dcSApple OSS Distributions {
792*2c2f96dcSApple OSS Distributions 	IORegistryEntry *   parent;
793*2c2f96dcSApple OSS Distributions 	OSData *            local;
794*2c2f96dcSApple OSS Distributions 	OSData *            local2;
795*2c2f96dcSApple OSS Distributions 	UInt32 *            localBits;
796*2c2f96dcSApple OSS Distributions 	UInt32 *            localEnd;
797*2c2f96dcSApple OSS Distributions 	IOItemCount         index;
798*2c2f96dcSApple OSS Distributions 	OSData *            map = NULL;
799*2c2f96dcSApple OSS Distributions 	OSObject *          oneMap;
800*2c2f96dcSApple OSS Distributions 	OSArray *           mapped;
801*2c2f96dcSApple OSS Distributions 	OSArray *           controllerInts;
802*2c2f96dcSApple OSS Distributions 	const OSSymbol *    controller = NULL;
803*2c2f96dcSApple OSS Distributions 	OSArray *           controllers;
804*2c2f96dcSApple OSS Distributions 	UInt32              skip = 1;
805*2c2f96dcSApple OSS Distributions 	bool                ok, nw;
806*2c2f96dcSApple OSS Distributions 
807*2c2f96dcSApple OSS Distributions 	nw = (NULL == (local = OSDynamicCast( OSData,
808*2c2f96dcSApple OSS Distributions 	    regEntry->getProperty( gIODTAAPLInterruptsKey))));
809*2c2f96dcSApple OSS Distributions 	if (nw && (NULL == (local = OSDynamicCast( OSData,
810*2c2f96dcSApple OSS Distributions 	    regEntry->getProperty( "interrupts"))))) {
811*2c2f96dcSApple OSS Distributions 		return true;  // nothing to see here
812*2c2f96dcSApple OSS Distributions 	}
813*2c2f96dcSApple OSS Distributions 	if (nw && (parent = regEntry->getParentEntry( gIODTPlane))) {
814*2c2f96dcSApple OSS Distributions 		// check for bridges on old world
815*2c2f96dcSApple OSS Distributions 		if ((local2 = OSDynamicCast( OSData,
816*2c2f96dcSApple OSS Distributions 		    parent->getProperty( gIODTAAPLInterruptsKey)))) {
817*2c2f96dcSApple OSS Distributions 			local = local2;
818*2c2f96dcSApple OSS Distributions 			nw = false;
819*2c2f96dcSApple OSS Distributions 		}
820*2c2f96dcSApple OSS Distributions 	}
821*2c2f96dcSApple OSS Distributions 
822*2c2f96dcSApple OSS Distributions 	localBits = (UInt32 *) local->getBytesNoCopy();
823*2c2f96dcSApple OSS Distributions 	localEnd = localBits + (local->getLength() / sizeof(UInt32));
824*2c2f96dcSApple OSS Distributions 	index = 0;
825*2c2f96dcSApple OSS Distributions 	mapped = OSArray::withCapacity( 1 );
826*2c2f96dcSApple OSS Distributions 	controllers = OSArray::withCapacity( 1 );
827*2c2f96dcSApple OSS Distributions 
828*2c2f96dcSApple OSS Distributions 	ok = (mapped && controllers);
829*2c2f96dcSApple OSS Distributions 
830*2c2f96dcSApple OSS Distributions 	if (ok) {
831*2c2f96dcSApple OSS Distributions 		do {
832*2c2f96dcSApple OSS Distributions 			if (nw) {
833*2c2f96dcSApple OSS Distributions 				skip = IODTMapOneInterrupt( regEntry, localBits, index, &map, &controller );
834*2c2f96dcSApple OSS Distributions 				if (0 == skip) {
835*2c2f96dcSApple OSS Distributions 					IOLog("%s: error mapping interrupt[%d]\n",
836*2c2f96dcSApple OSS Distributions 					    regEntry->getName(), mapped->getCount());
837*2c2f96dcSApple OSS Distributions 					OSSafeReleaseNULL(map);
838*2c2f96dcSApple OSS Distributions 					OSSafeReleaseNULL(controller);
839*2c2f96dcSApple OSS Distributions 					break;
840*2c2f96dcSApple OSS Distributions 				}
841*2c2f96dcSApple OSS Distributions 			} else {
842*2c2f96dcSApple OSS Distributions 				map = OSData::withData( local, mapped->getCount() * sizeof(UInt32),
843*2c2f96dcSApple OSS Distributions 				    sizeof(UInt32));
844*2c2f96dcSApple OSS Distributions 				controller = gIODTDefaultInterruptController;
845*2c2f96dcSApple OSS Distributions 				controller->retain();
846*2c2f96dcSApple OSS Distributions 			}
847*2c2f96dcSApple OSS Distributions 
848*2c2f96dcSApple OSS Distributions 			index++;
849*2c2f96dcSApple OSS Distributions 			localBits += skip;
850*2c2f96dcSApple OSS Distributions 			mapped->setObject( map );
851*2c2f96dcSApple OSS Distributions 			controllers->setObject( controller );
852*2c2f96dcSApple OSS Distributions 
853*2c2f96dcSApple OSS Distributions 			if (allInts) {
854*2c2f96dcSApple OSS Distributions 				controllerInts = (OSArray *) allInts->getObject( controller );
855*2c2f96dcSApple OSS Distributions 				if (controllerInts) {
856*2c2f96dcSApple OSS Distributions 					for (unsigned int i = 0; (oneMap = controllerInts->getObject(i)); i++) {
857*2c2f96dcSApple OSS Distributions 						if (map->isEqualTo(oneMap)) {
858*2c2f96dcSApple OSS Distributions 							controllerInts = (OSArray *) gIODTSharedInterrupts->getObject( controller );
859*2c2f96dcSApple OSS Distributions 							if (controllerInts) {
860*2c2f96dcSApple OSS Distributions 								controllerInts->setObject(map);
861*2c2f96dcSApple OSS Distributions 							} else {
862*2c2f96dcSApple OSS Distributions 								controllerInts = OSArray::withObjects((const OSObject **) &map, 1, 4 );
863*2c2f96dcSApple OSS Distributions 								if (controllerInts) {
864*2c2f96dcSApple OSS Distributions 									gIODTSharedInterrupts->setObject( controller, controllerInts );
865*2c2f96dcSApple OSS Distributions 									controllerInts->release();
866*2c2f96dcSApple OSS Distributions 								}
867*2c2f96dcSApple OSS Distributions 							}
868*2c2f96dcSApple OSS Distributions 							break;
869*2c2f96dcSApple OSS Distributions 						}
870*2c2f96dcSApple OSS Distributions 					}
871*2c2f96dcSApple OSS Distributions 					if (!oneMap) {
872*2c2f96dcSApple OSS Distributions 						controllerInts->setObject(map);
873*2c2f96dcSApple OSS Distributions 					}
874*2c2f96dcSApple OSS Distributions 				} else {
875*2c2f96dcSApple OSS Distributions 					controllerInts = OSArray::withObjects((const OSObject **) &map, 1, 16 );
876*2c2f96dcSApple OSS Distributions 					if (controllerInts) {
877*2c2f96dcSApple OSS Distributions 						allInts->setObject( controller, controllerInts );
878*2c2f96dcSApple OSS Distributions 						controllerInts->release();
879*2c2f96dcSApple OSS Distributions 					}
880*2c2f96dcSApple OSS Distributions 				}
881*2c2f96dcSApple OSS Distributions 			}
882*2c2f96dcSApple OSS Distributions 
883*2c2f96dcSApple OSS Distributions 			OSSafeReleaseNULL(map);
884*2c2f96dcSApple OSS Distributions 			OSSafeReleaseNULL(controller);
885*2c2f96dcSApple OSS Distributions 		} while (localBits < localEnd);
886*2c2f96dcSApple OSS Distributions 	}
887*2c2f96dcSApple OSS Distributions 
888*2c2f96dcSApple OSS Distributions 	ok &= (localBits == localEnd);
889*2c2f96dcSApple OSS Distributions 
890*2c2f96dcSApple OSS Distributions 	if (ok) {
891*2c2f96dcSApple OSS Distributions 		// store results
892*2c2f96dcSApple OSS Distributions 		ok  = regEntry->setProperty( gIOInterruptControllersKey, controllers);
893*2c2f96dcSApple OSS Distributions 		ok &= regEntry->setProperty( gIOInterruptSpecifiersKey, mapped);
894*2c2f96dcSApple OSS Distributions 	}
895*2c2f96dcSApple OSS Distributions 
896*2c2f96dcSApple OSS Distributions 	if (controllers) {
897*2c2f96dcSApple OSS Distributions 		controllers->release();
898*2c2f96dcSApple OSS Distributions 	}
899*2c2f96dcSApple OSS Distributions 	if (mapped) {
900*2c2f96dcSApple OSS Distributions 		mapped->release();
901*2c2f96dcSApple OSS Distributions 	}
902*2c2f96dcSApple OSS Distributions 
903*2c2f96dcSApple OSS Distributions 	return ok;
904*2c2f96dcSApple OSS Distributions }
905*2c2f96dcSApple OSS Distributions 
906*2c2f96dcSApple OSS Distributions bool
IODTMapInterrupts(IORegistryEntry * regEntry)907*2c2f96dcSApple OSS Distributions IODTMapInterrupts( IORegistryEntry * regEntry )
908*2c2f96dcSApple OSS Distributions {
909*2c2f96dcSApple OSS Distributions 	return IODTMapInterruptsSharing( regEntry, NULL );
910*2c2f96dcSApple OSS Distributions }
911*2c2f96dcSApple OSS Distributions 
912*2c2f96dcSApple OSS Distributions /*
913*2c2f96dcSApple OSS Distributions  */
914*2c2f96dcSApple OSS Distributions 
915*2c2f96dcSApple OSS Distributions static bool
CompareKey(OSString * key,const IORegistryEntry * table,const OSSymbol * propName,LIBKERN_RETURNS_RETAINED OSString ** matchingName)916*2c2f96dcSApple OSS Distributions CompareKey( OSString * key,
917*2c2f96dcSApple OSS Distributions     const IORegistryEntry * table, const OSSymbol * propName,
918*2c2f96dcSApple OSS Distributions     LIBKERN_RETURNS_RETAINED OSString ** matchingName )
919*2c2f96dcSApple OSS Distributions {
920*2c2f96dcSApple OSS Distributions 	OSObject            *prop;
921*2c2f96dcSApple OSS Distributions 	OSData                      *data;
922*2c2f96dcSApple OSS Distributions 	OSString            *string;
923*2c2f96dcSApple OSS Distributions 	const char          *ckey;
924*2c2f96dcSApple OSS Distributions 	UInt32                      keyLen;
925*2c2f96dcSApple OSS Distributions 	UInt32          nlen;
926*2c2f96dcSApple OSS Distributions 	const char          *names;
927*2c2f96dcSApple OSS Distributions 	const char          *lastName;
928*2c2f96dcSApple OSS Distributions 	bool                        wild;
929*2c2f96dcSApple OSS Distributions 	bool                        matched;
930*2c2f96dcSApple OSS Distributions 	const char          *result = NULL;
931*2c2f96dcSApple OSS Distributions 
932*2c2f96dcSApple OSS Distributions 	if (NULL == (prop = table->copyProperty( propName ))) {
933*2c2f96dcSApple OSS Distributions 		return 0;
934*2c2f96dcSApple OSS Distributions 	}
935*2c2f96dcSApple OSS Distributions 
936*2c2f96dcSApple OSS Distributions 	if ((data = OSDynamicCast( OSData, prop ))) {
937*2c2f96dcSApple OSS Distributions 		names = (const char *) data->getBytesNoCopy();
938*2c2f96dcSApple OSS Distributions 		lastName = names + data->getLength();
939*2c2f96dcSApple OSS Distributions 	} else if ((string = OSDynamicCast( OSString, prop ))) {
940*2c2f96dcSApple OSS Distributions 		names = string->getCStringNoCopy();
941*2c2f96dcSApple OSS Distributions 		lastName = names + string->getLength() + 1;
942*2c2f96dcSApple OSS Distributions 	} else {
943*2c2f96dcSApple OSS Distributions 		names = NULL;
944*2c2f96dcSApple OSS Distributions 	}
945*2c2f96dcSApple OSS Distributions 
946*2c2f96dcSApple OSS Distributions 	if (names) {
947*2c2f96dcSApple OSS Distributions 		ckey = key->getCStringNoCopy();
948*2c2f96dcSApple OSS Distributions 		keyLen = key->getLength();
949*2c2f96dcSApple OSS Distributions 		wild = ('*' == key->getChar( keyLen - 1 ));
950*2c2f96dcSApple OSS Distributions 
951*2c2f96dcSApple OSS Distributions 		do {
952*2c2f96dcSApple OSS Distributions 			// for each name in the property
953*2c2f96dcSApple OSS Distributions 			nlen = (unsigned int) strnlen(names, lastName - names);
954*2c2f96dcSApple OSS Distributions 			if (wild) {
955*2c2f96dcSApple OSS Distributions 				matched = ((nlen >= (keyLen - 1)) && (0 == strncmp(ckey, names, keyLen - 1)));
956*2c2f96dcSApple OSS Distributions 			} else {
957*2c2f96dcSApple OSS Distributions 				matched = (keyLen == nlen) && (0 == strncmp(ckey, names, keyLen));
958*2c2f96dcSApple OSS Distributions 			}
959*2c2f96dcSApple OSS Distributions 
960*2c2f96dcSApple OSS Distributions 			if (matched) {
961*2c2f96dcSApple OSS Distributions 				result = names;
962*2c2f96dcSApple OSS Distributions 			}
963*2c2f96dcSApple OSS Distributions 
964*2c2f96dcSApple OSS Distributions 			names = names + nlen + 1;
965*2c2f96dcSApple OSS Distributions 		} while ((names < lastName) && (false == matched));
966*2c2f96dcSApple OSS Distributions 	}
967*2c2f96dcSApple OSS Distributions 
968*2c2f96dcSApple OSS Distributions 	if (result && matchingName) {
969*2c2f96dcSApple OSS Distributions 		*matchingName = OSString::withCString( result );
970*2c2f96dcSApple OSS Distributions 	}
971*2c2f96dcSApple OSS Distributions 
972*2c2f96dcSApple OSS Distributions 	if (prop) {
973*2c2f96dcSApple OSS Distributions 		prop->release();
974*2c2f96dcSApple OSS Distributions 	}
975*2c2f96dcSApple OSS Distributions 
976*2c2f96dcSApple OSS Distributions 	return result != NULL;
977*2c2f96dcSApple OSS Distributions }
978*2c2f96dcSApple OSS Distributions 
979*2c2f96dcSApple OSS Distributions 
980*2c2f96dcSApple OSS Distributions bool
IODTCompareNubName(const IORegistryEntry * regEntry,OSString * name,OSString ** matchingName)981*2c2f96dcSApple OSS Distributions IODTCompareNubName( const IORegistryEntry * regEntry,
982*2c2f96dcSApple OSS Distributions     OSString * name, OSString ** matchingName )
983*2c2f96dcSApple OSS Distributions {
984*2c2f96dcSApple OSS Distributions 	bool matched;
985*2c2f96dcSApple OSS Distributions 
986*2c2f96dcSApple OSS Distributions 	matched = CompareKey( name, regEntry, gIODTNameKey, matchingName)
987*2c2f96dcSApple OSS Distributions 	    || CompareKey( name, regEntry, gIODTCompatibleKey, matchingName)
988*2c2f96dcSApple OSS Distributions 	    || CompareKey( name, regEntry, gIODTTypeKey, matchingName)
989*2c2f96dcSApple OSS Distributions 	    || CompareKey( name, regEntry, gIODTModelKey, matchingName);
990*2c2f96dcSApple OSS Distributions 
991*2c2f96dcSApple OSS Distributions 	return matched;
992*2c2f96dcSApple OSS Distributions }
993*2c2f96dcSApple OSS Distributions 
994*2c2f96dcSApple OSS Distributions bool
IODTCompareNubName(const IORegistryEntry * regEntry,OSString * name,OSSharedPtr<OSString> & matchingName)995*2c2f96dcSApple OSS Distributions IODTCompareNubName( const IORegistryEntry * regEntry,
996*2c2f96dcSApple OSS Distributions     OSString * name, OSSharedPtr<OSString>& matchingName )
997*2c2f96dcSApple OSS Distributions {
998*2c2f96dcSApple OSS Distributions 	OSString* matchingNameRaw = NULL;
999*2c2f96dcSApple OSS Distributions 	bool result = IODTCompareNubName(regEntry, name, &matchingNameRaw);
1000*2c2f96dcSApple OSS Distributions 	matchingName.reset(matchingNameRaw, OSNoRetain);
1001*2c2f96dcSApple OSS Distributions 	return result;
1002*2c2f96dcSApple OSS Distributions }
1003*2c2f96dcSApple OSS Distributions 
1004*2c2f96dcSApple OSS Distributions bool
IODTMatchNubWithKeys(IORegistryEntry * regEntry,const char * keys)1005*2c2f96dcSApple OSS Distributions IODTMatchNubWithKeys( IORegistryEntry * regEntry,
1006*2c2f96dcSApple OSS Distributions     const char * keys )
1007*2c2f96dcSApple OSS Distributions {
1008*2c2f96dcSApple OSS Distributions 	OSObject    *obj;
1009*2c2f96dcSApple OSS Distributions 	bool                result = false;
1010*2c2f96dcSApple OSS Distributions 
1011*2c2f96dcSApple OSS Distributions 	obj = OSUnserialize( keys, NULL );
1012*2c2f96dcSApple OSS Distributions 
1013*2c2f96dcSApple OSS Distributions 	if (obj) {
1014*2c2f96dcSApple OSS Distributions 		result = regEntry->compareNames( obj );
1015*2c2f96dcSApple OSS Distributions 		obj->release();
1016*2c2f96dcSApple OSS Distributions 	}
1017*2c2f96dcSApple OSS Distributions #if DEBUG
1018*2c2f96dcSApple OSS Distributions 	else {
1019*2c2f96dcSApple OSS Distributions 		IOLog("Couldn't unserialize %s\n", keys );
1020*2c2f96dcSApple OSS Distributions 	}
1021*2c2f96dcSApple OSS Distributions #endif
1022*2c2f96dcSApple OSS Distributions 
1023*2c2f96dcSApple OSS Distributions 	return result;
1024*2c2f96dcSApple OSS Distributions }
1025*2c2f96dcSApple OSS Distributions 
1026*2c2f96dcSApple OSS Distributions LIBKERN_RETURNS_RETAINED OSCollectionIterator *
IODTFindMatchingEntries(IORegistryEntry * from,IOOptionBits options,const char * keys)1027*2c2f96dcSApple OSS Distributions IODTFindMatchingEntries( IORegistryEntry * from,
1028*2c2f96dcSApple OSS Distributions     IOOptionBits options, const char * keys )
1029*2c2f96dcSApple OSS Distributions {
1030*2c2f96dcSApple OSS Distributions 	OSSet                                       *result = NULL;
1031*2c2f96dcSApple OSS Distributions 	IORegistryEntry                     *next;
1032*2c2f96dcSApple OSS Distributions 	IORegistryIterator          *iter;
1033*2c2f96dcSApple OSS Distributions 	OSCollectionIterator        *cIter;
1034*2c2f96dcSApple OSS Distributions 	bool                                        cmp;
1035*2c2f96dcSApple OSS Distributions 	bool                                        minus = options & kIODTExclusive;
1036*2c2f96dcSApple OSS Distributions 
1037*2c2f96dcSApple OSS Distributions 
1038*2c2f96dcSApple OSS Distributions 	iter = IORegistryIterator::iterateOver( from, gIODTPlane,
1039*2c2f96dcSApple OSS Distributions 	    (options & kIODTRecursive) ? kIORegistryIterateRecursively : 0 );
1040*2c2f96dcSApple OSS Distributions 	if (iter) {
1041*2c2f96dcSApple OSS Distributions 		do {
1042*2c2f96dcSApple OSS Distributions 			if (result) {
1043*2c2f96dcSApple OSS Distributions 				result->release();
1044*2c2f96dcSApple OSS Distributions 			}
1045*2c2f96dcSApple OSS Distributions 			result = OSSet::withCapacity( 3 );
1046*2c2f96dcSApple OSS Distributions 			if (!result) {
1047*2c2f96dcSApple OSS Distributions 				break;
1048*2c2f96dcSApple OSS Distributions 			}
1049*2c2f96dcSApple OSS Distributions 
1050*2c2f96dcSApple OSS Distributions 			iter->reset();
1051*2c2f96dcSApple OSS Distributions 			while ((next = iter->getNextObject())) {
1052*2c2f96dcSApple OSS Distributions 				// Look for existence of a debug property to skip
1053*2c2f96dcSApple OSS Distributions 				if (next->propertyExists("AAPL,ignore")) {
1054*2c2f96dcSApple OSS Distributions 					continue;
1055*2c2f96dcSApple OSS Distributions 				}
1056*2c2f96dcSApple OSS Distributions 				if (next->propertyHasValue(gIODTTypeKey, gIODTAssociatedServiceKey)) {
1057*2c2f96dcSApple OSS Distributions 					continue;
1058*2c2f96dcSApple OSS Distributions 				}
1059*2c2f96dcSApple OSS Distributions 				if (keys) {
1060*2c2f96dcSApple OSS Distributions 					cmp = IODTMatchNubWithKeys( next, keys );
1061*2c2f96dcSApple OSS Distributions 					if ((minus && (false == cmp))
1062*2c2f96dcSApple OSS Distributions 					    || ((false == minus) && (false != cmp))) {
1063*2c2f96dcSApple OSS Distributions 						result->setObject( next);
1064*2c2f96dcSApple OSS Distributions 					}
1065*2c2f96dcSApple OSS Distributions 				} else {
1066*2c2f96dcSApple OSS Distributions 					result->setObject( next);
1067*2c2f96dcSApple OSS Distributions 				}
1068*2c2f96dcSApple OSS Distributions 			}
1069*2c2f96dcSApple OSS Distributions 		} while (!iter->isValid());
1070*2c2f96dcSApple OSS Distributions 
1071*2c2f96dcSApple OSS Distributions 		iter->release();
1072*2c2f96dcSApple OSS Distributions 	}
1073*2c2f96dcSApple OSS Distributions 
1074*2c2f96dcSApple OSS Distributions 	cIter = OSCollectionIterator::withCollection( result);
1075*2c2f96dcSApple OSS Distributions 	if (result) {
1076*2c2f96dcSApple OSS Distributions 		result->release();
1077*2c2f96dcSApple OSS Distributions 	}
1078*2c2f96dcSApple OSS Distributions 
1079*2c2f96dcSApple OSS Distributions 	return cIter;
1080*2c2f96dcSApple OSS Distributions }
1081*2c2f96dcSApple OSS Distributions 
1082*2c2f96dcSApple OSS Distributions 
1083*2c2f96dcSApple OSS Distributions void
IODTSetResolving(IORegistryEntry * regEntry,IODTCompareAddressCellFunc compareFunc,IODTNVLocationFunc locationFunc __unused)1084*2c2f96dcSApple OSS Distributions IODTSetResolving( IORegistryEntry *        regEntry,
1085*2c2f96dcSApple OSS Distributions     IODTCompareAddressCellFunc      compareFunc,
1086*2c2f96dcSApple OSS Distributions     IODTNVLocationFunc              locationFunc __unused )
1087*2c2f96dcSApple OSS Distributions {
1088*2c2f96dcSApple OSS Distributions 	IODTPersistent * entry;
1089*2c2f96dcSApple OSS Distributions 	IODTPersistent * newResolvers;
1090*2c2f96dcSApple OSS Distributions 	OSNumber       * num;
1091*2c2f96dcSApple OSS Distributions 	unsigned int     index;
1092*2c2f96dcSApple OSS Distributions 
1093*2c2f96dcSApple OSS Distributions 	IOLockLock(gIODTResolvers->lock);
1094*2c2f96dcSApple OSS Distributions 
1095*2c2f96dcSApple OSS Distributions 	entry = gIODTResolvers->resolvers;
1096*2c2f96dcSApple OSS Distributions 	for (index = 0; index < gIODTResolvers->count; index++) {
1097*2c2f96dcSApple OSS Distributions 		if (compareFunc == entry->compareFunc) {
1098*2c2f96dcSApple OSS Distributions 			break;
1099*2c2f96dcSApple OSS Distributions 		}
1100*2c2f96dcSApple OSS Distributions 		entry++;
1101*2c2f96dcSApple OSS Distributions 	}
1102*2c2f96dcSApple OSS Distributions 
1103*2c2f96dcSApple OSS Distributions 	if (index == gIODTResolvers->count) {
1104*2c2f96dcSApple OSS Distributions 		if (gIODTResolvers->alloc == gIODTResolvers->count) {
1105*2c2f96dcSApple OSS Distributions 			if (__improbable(os_mul_overflow(gIODTResolvers->alloc, 2,
1106*2c2f96dcSApple OSS Distributions 			    &gIODTResolvers->alloc))) {
1107*2c2f96dcSApple OSS Distributions 				panic("IODTSetResolving - gIODTResolvers alloc overflows");
1108*2c2f96dcSApple OSS Distributions 			}
1109*2c2f96dcSApple OSS Distributions 
1110*2c2f96dcSApple OSS Distributions 			newResolvers = IONewZero(IODTPersistent, gIODTResolvers->alloc);
1111*2c2f96dcSApple OSS Distributions 			if (__improbable(!newResolvers)) {
1112*2c2f96dcSApple OSS Distributions 				panic("IODTSetResolving - could not allocate new resolvers");
1113*2c2f96dcSApple OSS Distributions 			}
1114*2c2f96dcSApple OSS Distributions 
1115*2c2f96dcSApple OSS Distributions 			bcopy(gIODTResolvers->resolvers, newResolvers,
1116*2c2f96dcSApple OSS Distributions 			    sizeof(gIODTResolvers->resolvers[0]) * gIODTResolvers->count);
1117*2c2f96dcSApple OSS Distributions 
1118*2c2f96dcSApple OSS Distributions 			IODelete(gIODTResolvers->resolvers, IODTPersistent,
1119*2c2f96dcSApple OSS Distributions 			    gIODTResolvers->count);
1120*2c2f96dcSApple OSS Distributions 			gIODTResolvers->resolvers = newResolvers;
1121*2c2f96dcSApple OSS Distributions 		}
1122*2c2f96dcSApple OSS Distributions 
1123*2c2f96dcSApple OSS Distributions 		entry = &gIODTResolvers->resolvers[gIODTResolvers->count];
1124*2c2f96dcSApple OSS Distributions 		entry->compareFunc = compareFunc;
1125*2c2f96dcSApple OSS Distributions 		gIODTResolvers->count++;
1126*2c2f96dcSApple OSS Distributions 	}
1127*2c2f96dcSApple OSS Distributions 
1128*2c2f96dcSApple OSS Distributions 	IOLockUnlock(gIODTResolvers->lock);
1129*2c2f96dcSApple OSS Distributions 
1130*2c2f96dcSApple OSS Distributions 	num = OSNumber::withNumber(index, 32);
1131*2c2f96dcSApple OSS Distributions 	regEntry->setProperty(gIODTPersistKey, num);
1132*2c2f96dcSApple OSS Distributions 	OSSafeReleaseNULL(num);
1133*2c2f96dcSApple OSS Distributions 
1134*2c2f96dcSApple OSS Distributions 	return;
1135*2c2f96dcSApple OSS Distributions }
1136*2c2f96dcSApple OSS Distributions 
1137*2c2f96dcSApple OSS Distributions #if  defined(__arm64__)
1138*2c2f96dcSApple OSS Distributions static SInt64
DefaultCompare(UInt32 cellCount,UInt32 left[],UInt32 right[])1139*2c2f96dcSApple OSS Distributions DefaultCompare( UInt32 cellCount, UInt32 left[], UInt32 right[] )
1140*2c2f96dcSApple OSS Distributions {
1141*2c2f96dcSApple OSS Distributions 	SInt64 diff = 0;
1142*2c2f96dcSApple OSS Distributions 
1143*2c2f96dcSApple OSS Distributions 	if (cellCount == 2) {
1144*2c2f96dcSApple OSS Distributions 		diff = IOPhysical32(left[1], left[0]) - IOPhysical32(right[1], right[0]);
1145*2c2f96dcSApple OSS Distributions 	} else if (cellCount == 1) {
1146*2c2f96dcSApple OSS Distributions 		diff = (left[0] - right[0]);
1147*2c2f96dcSApple OSS Distributions 	} else {
1148*2c2f96dcSApple OSS Distributions 		panic("DefaultCompare only knows how to handle 1 or 2 cells.");
1149*2c2f96dcSApple OSS Distributions 	}
1150*2c2f96dcSApple OSS Distributions 
1151*2c2f96dcSApple OSS Distributions 	return diff;
1152*2c2f96dcSApple OSS Distributions }
1153*2c2f96dcSApple OSS Distributions #elif defined(__i386__) || defined(__x86_64__)
1154*2c2f96dcSApple OSS Distributions static SInt32
DefaultCompare(UInt32 cellCount,UInt32 left[],UInt32 right[])1155*2c2f96dcSApple OSS Distributions DefaultCompare( UInt32 cellCount, UInt32 left[], UInt32 right[] )
1156*2c2f96dcSApple OSS Distributions {
1157*2c2f96dcSApple OSS Distributions 	cellCount--;
1158*2c2f96dcSApple OSS Distributions 	return left[cellCount] - right[cellCount];
1159*2c2f96dcSApple OSS Distributions }
1160*2c2f96dcSApple OSS Distributions #else
1161*2c2f96dcSApple OSS Distributions #error Unknown architecture.
1162*2c2f96dcSApple OSS Distributions #endif
1163*2c2f96dcSApple OSS Distributions 
1164*2c2f96dcSApple OSS Distributions static void
AddLengthToCells(UInt32 numCells,UInt32 * cells,UInt64 offset)1165*2c2f96dcSApple OSS Distributions AddLengthToCells( UInt32 numCells, UInt32 *cells, UInt64 offset)
1166*2c2f96dcSApple OSS Distributions {
1167*2c2f96dcSApple OSS Distributions 	if (numCells == 1) {
1168*2c2f96dcSApple OSS Distributions 		cells[0] += (UInt32)offset;
1169*2c2f96dcSApple OSS Distributions 	} else {
1170*2c2f96dcSApple OSS Distributions #if defined(__arm64__)
1171*2c2f96dcSApple OSS Distributions 		UInt64 sum = cells[numCells - 2] + offset;
1172*2c2f96dcSApple OSS Distributions 		cells[numCells - 2] = (UInt32)sum;
1173*2c2f96dcSApple OSS Distributions 		if (sum > UINT32_MAX) {
1174*2c2f96dcSApple OSS Distributions 			cells[numCells - 1] += (UInt32)(sum >> 32);
1175*2c2f96dcSApple OSS Distributions 		}
1176*2c2f96dcSApple OSS Distributions #else
1177*2c2f96dcSApple OSS Distributions 		UInt64 sum = cells[numCells - 1] + offset;
1178*2c2f96dcSApple OSS Distributions 		cells[numCells - 1] = (UInt32)sum;
1179*2c2f96dcSApple OSS Distributions 		if (sum > UINT32_MAX) {
1180*2c2f96dcSApple OSS Distributions 			cells[numCells - 2] += (UInt32)(sum >> 32);
1181*2c2f96dcSApple OSS Distributions 		}
1182*2c2f96dcSApple OSS Distributions #endif
1183*2c2f96dcSApple OSS Distributions 	}
1184*2c2f96dcSApple OSS Distributions }
1185*2c2f96dcSApple OSS Distributions 
1186*2c2f96dcSApple OSS Distributions static IOPhysicalAddress
CellsValue(UInt32 numCells,UInt32 * cells)1187*2c2f96dcSApple OSS Distributions CellsValue( UInt32 numCells, UInt32 *cells)
1188*2c2f96dcSApple OSS Distributions {
1189*2c2f96dcSApple OSS Distributions 	if (numCells == 1) {
1190*2c2f96dcSApple OSS Distributions 		return IOPhysical32( 0, cells[0] );
1191*2c2f96dcSApple OSS Distributions 	} else {
1192*2c2f96dcSApple OSS Distributions #if defined(__arm64__) || defined(arm)
1193*2c2f96dcSApple OSS Distributions 		return IOPhysical32( cells[numCells - 1], cells[numCells - 2] );
1194*2c2f96dcSApple OSS Distributions #else
1195*2c2f96dcSApple OSS Distributions 		return IOPhysical32( cells[numCells - 2], cells[numCells - 1] );
1196*2c2f96dcSApple OSS Distributions #endif
1197*2c2f96dcSApple OSS Distributions 	}
1198*2c2f96dcSApple OSS Distributions }
1199*2c2f96dcSApple OSS Distributions 
1200*2c2f96dcSApple OSS Distributions void
IODTGetCellCounts(IORegistryEntry * regEntry,UInt32 * sizeCount,UInt32 * addressCount)1201*2c2f96dcSApple OSS Distributions IODTGetCellCounts( IORegistryEntry * regEntry,
1202*2c2f96dcSApple OSS Distributions     UInt32 * sizeCount, UInt32 * addressCount)
1203*2c2f96dcSApple OSS Distributions {
1204*2c2f96dcSApple OSS Distributions 	if (!GetUInt32( regEntry, gIODTSizeCellKey, sizeCount)) {
1205*2c2f96dcSApple OSS Distributions 		*sizeCount = 1;
1206*2c2f96dcSApple OSS Distributions 	}
1207*2c2f96dcSApple OSS Distributions 	if (!GetUInt32( regEntry, gIODTAddressCellKey, addressCount)) {
1208*2c2f96dcSApple OSS Distributions 		*addressCount = 2;
1209*2c2f96dcSApple OSS Distributions 	}
1210*2c2f96dcSApple OSS Distributions 	return;
1211*2c2f96dcSApple OSS Distributions }
1212*2c2f96dcSApple OSS Distributions 
1213*2c2f96dcSApple OSS Distributions // Given addr & len cells from our child, find it in our ranges property, then
1214*2c2f96dcSApple OSS Distributions // look in our parent to resolve the base of the range for us.
1215*2c2f96dcSApple OSS Distributions 
1216*2c2f96dcSApple OSS Distributions // Range[]: child-addr  our-addr  child-len
1217*2c2f96dcSApple OSS Distributions // #cells:    child       ours     child
1218*2c2f96dcSApple OSS Distributions 
1219*2c2f96dcSApple OSS Distributions bool
IODTResolveAddressCell(IORegistryEntry * startEntry,UInt32 cellsIn[],IOPhysicalAddress * phys,IOPhysicalLength * lenOut)1220*2c2f96dcSApple OSS Distributions IODTResolveAddressCell( IORegistryEntry * startEntry,
1221*2c2f96dcSApple OSS Distributions     UInt32 cellsIn[],
1222*2c2f96dcSApple OSS Distributions     IOPhysicalAddress * phys, IOPhysicalLength * lenOut )
1223*2c2f96dcSApple OSS Distributions {
1224*2c2f96dcSApple OSS Distributions 	IORegistryEntry     * parent = NULL;
1225*2c2f96dcSApple OSS Distributions 	IORegistryEntry * regEntry;
1226*2c2f96dcSApple OSS Distributions 	OSData          * prop;
1227*2c2f96dcSApple OSS Distributions 	OSNumber    * num;
1228*2c2f96dcSApple OSS Distributions 	unsigned int  index;
1229*2c2f96dcSApple OSS Distributions 	// cells in addresses at regEntry
1230*2c2f96dcSApple OSS Distributions 	UInt32              sizeCells, addressCells;
1231*2c2f96dcSApple OSS Distributions 	// cells in addresses below regEntry
1232*2c2f96dcSApple OSS Distributions 	UInt32              childSizeCells, childAddressCells;
1233*2c2f96dcSApple OSS Distributions 	UInt32              childCells;
1234*2c2f96dcSApple OSS Distributions 	UInt32              cell[8], propLen;
1235*2c2f96dcSApple OSS Distributions 	UInt64              offset = 0;
1236*2c2f96dcSApple OSS Distributions 	UInt32              endCell[8];
1237*2c2f96dcSApple OSS Distributions 	UInt32              *range;
1238*2c2f96dcSApple OSS Distributions 	UInt32              *lookRange;
1239*2c2f96dcSApple OSS Distributions 	UInt32              *startRange;
1240*2c2f96dcSApple OSS Distributions 	UInt32              *endRanges;
1241*2c2f96dcSApple OSS Distributions 	bool                ok = true;
1242*2c2f96dcSApple OSS Distributions 	SInt64              diff, diff2, endDiff;
1243*2c2f96dcSApple OSS Distributions 	UInt64              len, rangeLen;
1244*2c2f96dcSApple OSS Distributions 
1245*2c2f96dcSApple OSS Distributions 	IODTCompareAddressCellFunc  compare;
1246*2c2f96dcSApple OSS Distributions 
1247*2c2f96dcSApple OSS Distributions 	regEntry = startEntry;
1248*2c2f96dcSApple OSS Distributions 	regEntry->retain();
1249*2c2f96dcSApple OSS Distributions 	IODTGetCellCounts( regEntry, &childSizeCells, &childAddressCells );
1250*2c2f96dcSApple OSS Distributions 	childCells = childAddressCells + childSizeCells;
1251*2c2f96dcSApple OSS Distributions 
1252*2c2f96dcSApple OSS Distributions 	if (childCells > sizeof(cell) / sizeof(cell[0])) {
1253*2c2f96dcSApple OSS Distributions 		panic("IODTResolveAddressCell: Invalid device tree (%u,%u)", (uint32_t)childAddressCells, (uint32_t)childSizeCells);
1254*2c2f96dcSApple OSS Distributions 	}
1255*2c2f96dcSApple OSS Distributions 
1256*2c2f96dcSApple OSS Distributions 	bcopy( cellsIn, cell, sizeof(UInt32) * childCells );
1257*2c2f96dcSApple OSS Distributions 	*lenOut = CellsValue( childSizeCells, cellsIn + childAddressCells );
1258*2c2f96dcSApple OSS Distributions 
1259*2c2f96dcSApple OSS Distributions 	do{
1260*2c2f96dcSApple OSS Distributions 		prop = OSDynamicCast( OSData, regEntry->getProperty( gIODTRangeKey ));
1261*2c2f96dcSApple OSS Distributions 		if (NULL == prop) {
1262*2c2f96dcSApple OSS Distributions 			/* end of the road */
1263*2c2f96dcSApple OSS Distributions 			*phys = CellsValue( childAddressCells, cell );
1264*2c2f96dcSApple OSS Distributions 			*phys += offset;
1265*2c2f96dcSApple OSS Distributions 			break;
1266*2c2f96dcSApple OSS Distributions 		}
1267*2c2f96dcSApple OSS Distributions 
1268*2c2f96dcSApple OSS Distributions 		parent = regEntry->copyParentEntry( gIODTPlane );
1269*2c2f96dcSApple OSS Distributions 		IODTGetCellCounts( parent, &sizeCells, &addressCells );
1270*2c2f96dcSApple OSS Distributions 
1271*2c2f96dcSApple OSS Distributions 		if ((propLen = prop->getLength())) {
1272*2c2f96dcSApple OSS Distributions 			// search
1273*2c2f96dcSApple OSS Distributions 			startRange = (UInt32 *) prop->getBytesNoCopy();
1274*2c2f96dcSApple OSS Distributions 			range = startRange;
1275*2c2f96dcSApple OSS Distributions 			endRanges = range + (propLen / sizeof(UInt32));
1276*2c2f96dcSApple OSS Distributions 
1277*2c2f96dcSApple OSS Distributions 			compare = NULL;
1278*2c2f96dcSApple OSS Distributions 			num = OSDynamicCast(OSNumber, regEntry->getProperty(gIODTPersistKey));
1279*2c2f96dcSApple OSS Distributions 			if (num) {
1280*2c2f96dcSApple OSS Distributions 				IOLockLock(gIODTResolvers->lock);
1281*2c2f96dcSApple OSS Distributions 				index = num->unsigned32BitValue();
1282*2c2f96dcSApple OSS Distributions 				if (index < gIODTResolvers->count) {
1283*2c2f96dcSApple OSS Distributions 					compare = gIODTResolvers->resolvers[index].compareFunc;
1284*2c2f96dcSApple OSS Distributions 				}
1285*2c2f96dcSApple OSS Distributions 				IOLockUnlock(gIODTResolvers->lock);
1286*2c2f96dcSApple OSS Distributions 			}
1287*2c2f96dcSApple OSS Distributions 
1288*2c2f96dcSApple OSS Distributions 			if (!compare && (addressCells == childAddressCells)) {
1289*2c2f96dcSApple OSS Distributions 				compare = DefaultCompare;
1290*2c2f96dcSApple OSS Distributions 			}
1291*2c2f96dcSApple OSS Distributions 			if (!compare) {
1292*2c2f96dcSApple OSS Distributions 				panic("There is no mixed comparison function yet...");
1293*2c2f96dcSApple OSS Distributions 			}
1294*2c2f96dcSApple OSS Distributions 
1295*2c2f96dcSApple OSS Distributions 			for (ok = false;
1296*2c2f96dcSApple OSS Distributions 			    range < endRanges;
1297*2c2f96dcSApple OSS Distributions 			    range += (childCells + addressCells)) {
1298*2c2f96dcSApple OSS Distributions 				// is cell start within range?
1299*2c2f96dcSApple OSS Distributions 				diff = (*compare)( childAddressCells, cell, range );
1300*2c2f96dcSApple OSS Distributions 
1301*2c2f96dcSApple OSS Distributions 				if (childAddressCells > sizeof(endCell) / sizeof(endCell[0])) {
1302*2c2f96dcSApple OSS Distributions 					panic("IODTResolveAddressCell: Invalid device tree (%u)", (uint32_t)childAddressCells);
1303*2c2f96dcSApple OSS Distributions 				}
1304*2c2f96dcSApple OSS Distributions 
1305*2c2f96dcSApple OSS Distributions 				bcopy(range, endCell, childAddressCells * sizeof(UInt32));
1306*2c2f96dcSApple OSS Distributions 
1307*2c2f96dcSApple OSS Distributions 				rangeLen = CellsValue(childSizeCells, range + childAddressCells + addressCells);
1308*2c2f96dcSApple OSS Distributions 				AddLengthToCells(childAddressCells, endCell, rangeLen);
1309*2c2f96dcSApple OSS Distributions 
1310*2c2f96dcSApple OSS Distributions 				diff2 = (*compare)( childAddressCells, cell, endCell );
1311*2c2f96dcSApple OSS Distributions 
1312*2c2f96dcSApple OSS Distributions 				// if start of cell < start of range, or end of range >= start of cell, skip
1313*2c2f96dcSApple OSS Distributions 				if ((diff < 0) || (diff2 >= 0)) {
1314*2c2f96dcSApple OSS Distributions 					continue;
1315*2c2f96dcSApple OSS Distributions 				}
1316*2c2f96dcSApple OSS Distributions 
1317*2c2f96dcSApple OSS Distributions 				len = CellsValue(childSizeCells, cell + childAddressCells);
1318*2c2f96dcSApple OSS Distributions 				ok = (0 == len);
1319*2c2f96dcSApple OSS Distributions 
1320*2c2f96dcSApple OSS Distributions 				if (!ok) {
1321*2c2f96dcSApple OSS Distributions 					// search for cell end
1322*2c2f96dcSApple OSS Distributions 					bcopy(cell, endCell, childAddressCells * sizeof(UInt32));
1323*2c2f96dcSApple OSS Distributions 
1324*2c2f96dcSApple OSS Distributions 					AddLengthToCells(childAddressCells, endCell, len - 1);
1325*2c2f96dcSApple OSS Distributions 
1326*2c2f96dcSApple OSS Distributions 					for (lookRange = startRange;
1327*2c2f96dcSApple OSS Distributions 					    lookRange < endRanges;
1328*2c2f96dcSApple OSS Distributions 					    lookRange += (childCells + addressCells)) {
1329*2c2f96dcSApple OSS Distributions 						// make sure end of cell >= range start
1330*2c2f96dcSApple OSS Distributions 						endDiff = (*compare)( childAddressCells, endCell, lookRange );
1331*2c2f96dcSApple OSS Distributions 						if (endDiff < 0) {
1332*2c2f96dcSApple OSS Distributions 							continue;
1333*2c2f96dcSApple OSS Distributions 						}
1334*2c2f96dcSApple OSS Distributions 
1335*2c2f96dcSApple OSS Distributions 						UInt64 rangeStart = CellsValue(addressCells, range + childAddressCells);
1336*2c2f96dcSApple OSS Distributions 						UInt64 lookRangeStart = CellsValue(addressCells, lookRange + childAddressCells);
1337*2c2f96dcSApple OSS Distributions 						if ((endDiff - len + 1 + lookRangeStart) == (diff + rangeStart)) {
1338*2c2f96dcSApple OSS Distributions 							ok = true;
1339*2c2f96dcSApple OSS Distributions 							break;
1340*2c2f96dcSApple OSS Distributions 						}
1341*2c2f96dcSApple OSS Distributions 					}
1342*2c2f96dcSApple OSS Distributions 					if (!ok) {
1343*2c2f96dcSApple OSS Distributions 						continue;
1344*2c2f96dcSApple OSS Distributions 					}
1345*2c2f96dcSApple OSS Distributions 				}
1346*2c2f96dcSApple OSS Distributions 				offset += diff;
1347*2c2f96dcSApple OSS Distributions 				break;
1348*2c2f96dcSApple OSS Distributions 			}
1349*2c2f96dcSApple OSS Distributions 
1350*2c2f96dcSApple OSS Distributions 			if (addressCells + sizeCells > sizeof(cell) / sizeof(cell[0])) {
1351*2c2f96dcSApple OSS Distributions 				panic("IODTResolveAddressCell: Invalid device tree (%u, %u)", (uint32_t)addressCells, (uint32_t)sizeCells);
1352*2c2f96dcSApple OSS Distributions 			}
1353*2c2f96dcSApple OSS Distributions 
1354*2c2f96dcSApple OSS Distributions 			// Get the physical start of the range from our parent
1355*2c2f96dcSApple OSS Distributions 			bcopy( range + childAddressCells, cell, sizeof(UInt32) * addressCells );
1356*2c2f96dcSApple OSS Distributions 			bzero( cell + addressCells, sizeof(UInt32) * sizeCells );
1357*2c2f96dcSApple OSS Distributions 		} /* else zero length range => pass thru to parent */
1358*2c2f96dcSApple OSS Distributions 
1359*2c2f96dcSApple OSS Distributions 		OSSafeReleaseNULL(regEntry);
1360*2c2f96dcSApple OSS Distributions 		regEntry                = parent;
1361*2c2f96dcSApple OSS Distributions 		parent = NULL;
1362*2c2f96dcSApple OSS Distributions 		childSizeCells          = sizeCells;
1363*2c2f96dcSApple OSS Distributions 		childAddressCells       = addressCells;
1364*2c2f96dcSApple OSS Distributions 		childCells              = childAddressCells + childSizeCells;
1365*2c2f96dcSApple OSS Distributions 	}while (ok && regEntry);
1366*2c2f96dcSApple OSS Distributions 
1367*2c2f96dcSApple OSS Distributions 	OSSafeReleaseNULL(regEntry);
1368*2c2f96dcSApple OSS Distributions 
1369*2c2f96dcSApple OSS Distributions 	return ok;
1370*2c2f96dcSApple OSS Distributions }
1371*2c2f96dcSApple OSS Distributions 
1372*2c2f96dcSApple OSS Distributions 
1373*2c2f96dcSApple OSS Distributions OSArray *
IODTResolveAddressing(IORegistryEntry * regEntry,const char * addressPropertyName,IODeviceMemory * parent)1374*2c2f96dcSApple OSS Distributions IODTResolveAddressing( IORegistryEntry * regEntry,
1375*2c2f96dcSApple OSS Distributions     const char * addressPropertyName,
1376*2c2f96dcSApple OSS Distributions     IODeviceMemory * parent )
1377*2c2f96dcSApple OSS Distributions {
1378*2c2f96dcSApple OSS Distributions 	IORegistryEntry             *parentEntry;
1379*2c2f96dcSApple OSS Distributions 	OSData                              *addressProperty;
1380*2c2f96dcSApple OSS Distributions 	UInt32                              sizeCells, addressCells, cells;
1381*2c2f96dcSApple OSS Distributions 	int                                 i, num;
1382*2c2f96dcSApple OSS Distributions 	UInt32                              *reg;
1383*2c2f96dcSApple OSS Distributions 	IOPhysicalAddress   phys;
1384*2c2f96dcSApple OSS Distributions 	IOPhysicalLength    len;
1385*2c2f96dcSApple OSS Distributions 	OSArray                             *array;
1386*2c2f96dcSApple OSS Distributions 
1387*2c2f96dcSApple OSS Distributions 	array = NULL;
1388*2c2f96dcSApple OSS Distributions 	do{
1389*2c2f96dcSApple OSS Distributions 		parentEntry = regEntry->copyParentEntry( gIODTPlane );
1390*2c2f96dcSApple OSS Distributions 		addressProperty = (OSData *) regEntry->getProperty( addressPropertyName );
1391*2c2f96dcSApple OSS Distributions 		if ((NULL == addressProperty) || (NULL == parentEntry)) {
1392*2c2f96dcSApple OSS Distributions 			break;
1393*2c2f96dcSApple OSS Distributions 		}
1394*2c2f96dcSApple OSS Distributions 
1395*2c2f96dcSApple OSS Distributions 		IODTGetCellCounts( parentEntry, &sizeCells, &addressCells );
1396*2c2f96dcSApple OSS Distributions 		if (0 == sizeCells) {
1397*2c2f96dcSApple OSS Distributions 			break;
1398*2c2f96dcSApple OSS Distributions 		}
1399*2c2f96dcSApple OSS Distributions 
1400*2c2f96dcSApple OSS Distributions 		cells = sizeCells + addressCells;
1401*2c2f96dcSApple OSS Distributions 		reg = (UInt32 *) addressProperty->getBytesNoCopy();
1402*2c2f96dcSApple OSS Distributions 		num = addressProperty->getLength() / (4 * cells);
1403*2c2f96dcSApple OSS Distributions 
1404*2c2f96dcSApple OSS Distributions 		array = OSArray::withCapacity( 1 );
1405*2c2f96dcSApple OSS Distributions 		if (NULL == array) {
1406*2c2f96dcSApple OSS Distributions 			break;
1407*2c2f96dcSApple OSS Distributions 		}
1408*2c2f96dcSApple OSS Distributions 
1409*2c2f96dcSApple OSS Distributions 		for (i = 0; i < num; i++) {
1410*2c2f96dcSApple OSS Distributions 			if (IODTResolveAddressCell( parentEntry, reg, &phys, &len )) {
1411*2c2f96dcSApple OSS Distributions 				IODeviceMemory *range;
1412*2c2f96dcSApple OSS Distributions 				range = NULL;
1413*2c2f96dcSApple OSS Distributions 				if (parent) {
1414*2c2f96dcSApple OSS Distributions 					range = IODeviceMemory::withSubRange( parent,
1415*2c2f96dcSApple OSS Distributions 					    phys - parent->getPhysicalSegment(0, NULL, kIOMemoryMapperNone), len );
1416*2c2f96dcSApple OSS Distributions 				}
1417*2c2f96dcSApple OSS Distributions 				if (NULL == range) {
1418*2c2f96dcSApple OSS Distributions 					range = IODeviceMemory::withRange( phys, len );
1419*2c2f96dcSApple OSS Distributions 				}
1420*2c2f96dcSApple OSS Distributions 				if (range) {
1421*2c2f96dcSApple OSS Distributions 					array->setObject( range );
1422*2c2f96dcSApple OSS Distributions 					OSSafeReleaseNULL(range);
1423*2c2f96dcSApple OSS Distributions 				}
1424*2c2f96dcSApple OSS Distributions 			}
1425*2c2f96dcSApple OSS Distributions 			reg += cells;
1426*2c2f96dcSApple OSS Distributions 		}
1427*2c2f96dcSApple OSS Distributions 
1428*2c2f96dcSApple OSS Distributions 		regEntry->setProperty( gIODeviceMemoryKey, array);
1429*2c2f96dcSApple OSS Distributions 		array->release(); /* ??? */
1430*2c2f96dcSApple OSS Distributions 	}while (false);
1431*2c2f96dcSApple OSS Distributions 
1432*2c2f96dcSApple OSS Distributions 	OSSafeReleaseNULL(parentEntry);
1433*2c2f96dcSApple OSS Distributions 
1434*2c2f96dcSApple OSS Distributions 	return array;
1435*2c2f96dcSApple OSS Distributions }
1436*2c2f96dcSApple OSS Distributions 
1437*2c2f96dcSApple OSS Distributions OSData *
IODTFindSlotName(IORegistryEntry * regEntry,UInt32 deviceNumber)1438*2c2f96dcSApple OSS Distributions IODTFindSlotName( IORegistryEntry * regEntry, UInt32 deviceNumber )
1439*2c2f96dcSApple OSS Distributions {
1440*2c2f96dcSApple OSS Distributions 	IORegistryEntry             *parent;
1441*2c2f96dcSApple OSS Distributions 	OSData                              *data;
1442*2c2f96dcSApple OSS Distributions 	OSData                              *ret = NULL;
1443*2c2f96dcSApple OSS Distributions 	UInt32                              *bits;
1444*2c2f96dcSApple OSS Distributions 	UInt32                              i;
1445*2c2f96dcSApple OSS Distributions 	UInt32              nlen;
1446*2c2f96dcSApple OSS Distributions 	char                                *names;
1447*2c2f96dcSApple OSS Distributions 	char                                *lastName;
1448*2c2f96dcSApple OSS Distributions 	UInt32                              mask;
1449*2c2f96dcSApple OSS Distributions 
1450*2c2f96dcSApple OSS Distributions 	data = (OSData *) regEntry->getProperty("AAPL,slot-name");
1451*2c2f96dcSApple OSS Distributions 	if (data) {
1452*2c2f96dcSApple OSS Distributions 		return data;
1453*2c2f96dcSApple OSS Distributions 	}
1454*2c2f96dcSApple OSS Distributions 
1455*2c2f96dcSApple OSS Distributions 	do{
1456*2c2f96dcSApple OSS Distributions 		parent = regEntry->copyParentEntry( gIODTPlane );
1457*2c2f96dcSApple OSS Distributions 		if (!parent) {
1458*2c2f96dcSApple OSS Distributions 			break;
1459*2c2f96dcSApple OSS Distributions 		}
1460*2c2f96dcSApple OSS Distributions 
1461*2c2f96dcSApple OSS Distributions 		data = OSDynamicCast( OSData, parent->getProperty("slot-names"));
1462*2c2f96dcSApple OSS Distributions 		if (!data) {
1463*2c2f96dcSApple OSS Distributions 			break;
1464*2c2f96dcSApple OSS Distributions 		}
1465*2c2f96dcSApple OSS Distributions 		if (data->getLength() <= 4) {
1466*2c2f96dcSApple OSS Distributions 			break;
1467*2c2f96dcSApple OSS Distributions 		}
1468*2c2f96dcSApple OSS Distributions 
1469*2c2f96dcSApple OSS Distributions 		bits = (UInt32 *) data->getBytesNoCopy();
1470*2c2f96dcSApple OSS Distributions 		mask = *bits;
1471*2c2f96dcSApple OSS Distributions 		if ((0 == (mask & (1 << deviceNumber)))) {
1472*2c2f96dcSApple OSS Distributions 			break;
1473*2c2f96dcSApple OSS Distributions 		}
1474*2c2f96dcSApple OSS Distributions 
1475*2c2f96dcSApple OSS Distributions 		names = (char *)(bits + 1);
1476*2c2f96dcSApple OSS Distributions 		lastName = names + (data->getLength() - 4);
1477*2c2f96dcSApple OSS Distributions 
1478*2c2f96dcSApple OSS Distributions 		for (i = 0; (i <= deviceNumber) && (names < lastName); i++) {
1479*2c2f96dcSApple OSS Distributions 			if (mask & (1 << i)) {
1480*2c2f96dcSApple OSS Distributions 				nlen = 1 + ((unsigned int) strnlen(names, lastName - names));
1481*2c2f96dcSApple OSS Distributions 				if (i == deviceNumber) {
1482*2c2f96dcSApple OSS Distributions 					data = OSData::withBytesNoCopy(names, nlen);
1483*2c2f96dcSApple OSS Distributions 					if (data) {
1484*2c2f96dcSApple OSS Distributions 						regEntry->setProperty("AAPL,slot-name", data);
1485*2c2f96dcSApple OSS Distributions 						ret = data;
1486*2c2f96dcSApple OSS Distributions 						data->release();
1487*2c2f96dcSApple OSS Distributions 					}
1488*2c2f96dcSApple OSS Distributions 				} else {
1489*2c2f96dcSApple OSS Distributions 					names += nlen;
1490*2c2f96dcSApple OSS Distributions 				}
1491*2c2f96dcSApple OSS Distributions 			}
1492*2c2f96dcSApple OSS Distributions 		}
1493*2c2f96dcSApple OSS Distributions 	}while (false);
1494*2c2f96dcSApple OSS Distributions 
1495*2c2f96dcSApple OSS Distributions 	OSSafeReleaseNULL(parent);
1496*2c2f96dcSApple OSS Distributions 
1497*2c2f96dcSApple OSS Distributions 	return ret;
1498*2c2f96dcSApple OSS Distributions }
1499*2c2f96dcSApple OSS Distributions 
1500*2c2f96dcSApple OSS Distributions extern "C" IOReturn
IONDRVLibrariesInitialize(IOService * provider)1501*2c2f96dcSApple OSS Distributions IONDRVLibrariesInitialize( IOService * provider )
1502*2c2f96dcSApple OSS Distributions {
1503*2c2f96dcSApple OSS Distributions 	return kIOReturnUnsupported;
1504*2c2f96dcSApple OSS Distributions }
1505