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