]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOMapper.cpp
xnu-2422.1.72.tar.gz
[apple/xnu.git] / iokit / Kernel / IOMapper.cpp
index 6abcb5d1aef0ae53bb18efd85dfa7ab5d445cec6..294e1382205fced90097059ddf53f1bfa51d9f47 100644 (file)
@@ -142,28 +142,47 @@ void IOMapper::waitForSystemMapper()
 
 IOMapper * IOMapper::copyMapperForDevice(IOService * device)
 {
+    return copyMapperForDeviceWithIndex(device, 0);
+}
+
+IOMapper * IOMapper::copyMapperForDeviceWithIndex(IOService * device, unsigned int index)
+{
+    OSData *data;
     OSObject * obj;
-    IOMapper * mapper;
+    IOMapper * mapper = NULL;
     OSDictionary * matching;
     
     obj = device->copyProperty("iommu-parent");
     if (!obj)
-       return (NULL);
+        return (NULL);
 
     if ((mapper = OSDynamicCast(IOMapper, obj)))
-       return (mapper);
+        return (mapper);
 
-    matching = IOService::propertyMatching(gIOMapperIDKey, obj);
-    if (matching)
+    if ((data = OSDynamicCast(OSData, obj)))
     {
-       mapper = OSDynamicCast(IOMapper, IOService::waitForMatchingService(matching));
-       matching->release();
+        if (index >= data->getLength() / sizeof(UInt32))
+            goto done;
+        
+        data = OSData::withBytesNoCopy((UInt32 *)data->getBytesNoCopy() + index, sizeof(UInt32));
+        if (!data)
+            goto done;
+
+        matching = IOService::propertyMatching(gIOMapperIDKey, data);
+        data->release();
     }
-    if (mapper)
-       device->setProperty("iommu-parent", mapper);
     else
-       obj->release();
-    
+        matching = IOService::propertyMatching(gIOMapperIDKey, obj);
+
+    if (matching)
+    {
+        mapper = OSDynamicCast(IOMapper, IOService::waitForMatchingService(matching));
+            matching->release();
+    }
+
+done:
+    if (obj)
+            obj->release();
     return (mapper);
 }