- parent = regEntry->getParentEntry( gIODTPlane );
- IODTGetCellCounts( parent, &sizeCells, &addressCells );
-
- if( (length = prop->getLength())) {
- // search
- startRange = (UInt32 *) prop->getBytesNoCopy();
- range = startRange;
- endRanges = range + (length / 4);
-
- prop = (OSData *) regEntry->getProperty( gIODTPersistKey );
- if( prop) {
- persist = (IODTPersistent *) prop->getBytesNoCopy();
- compare = persist->compareFunc;
- } else
- compare = DefaultCompare;
-
- for( ok = false;
- range < endRanges;
- range += (childCells + addressCells) ) {
-
- // is cell start >= range start?
- diff = (*compare)( childAddressCells, cell, range );
- if( diff < 0)
- continue;
-
- ok = (0 == cell[childCells - 1]);
- if (!ok)
- {
- // search for cell end
- bcopy(cell, endCell, childAddressCells * sizeof(UInt32));
- endCell[childAddressCells - 1] += cell[childCells - 1] - 1;
- lookRange = startRange;
- for( ;
- lookRange < endRanges;
- lookRange += (childCells + addressCells) )
- {
- // is cell >= range start?
- endDiff = (*compare)( childAddressCells, endCell, lookRange );
- if( endDiff < 0)
- continue;
- if ((endDiff - cell[childCells - 1] + 1 + lookRange[childAddressCells + addressCells - 1])
- == (diff + range[childAddressCells + addressCells - 1]))
- {
- ok = true;
- break;
- }
- }
- if (!ok)
- continue;
- }
- offset += diff;
- break;
- }
+ parent = regEntry->getParentEntry( gIODTPlane );
+ IODTGetCellCounts( parent, &sizeCells, &addressCells );
+
+ if( (propLen = prop->getLength())) {
+ // search
+ startRange = (UInt32 *) prop->getBytesNoCopy();
+ range = startRange;
+ endRanges = range + (propLen / sizeof(UInt32));
+
+ prop = (OSData *) regEntry->getProperty( gIODTPersistKey );
+ if( prop) {
+ persist = (IODTPersistent *) prop->getBytesNoCopy();
+ compare = persist->compareFunc;
+ } else if (addressCells == childAddressCells) {
+ compare = DefaultCompare;
+ } else {
+ panic("There is no mixed comparison function yet...");
+ }
+
+ for( ok = false;
+ range < endRanges;
+ range += (childCells + addressCells) ) {
+
+ // is cell start within range?
+ diff = (*compare)( childAddressCells, cell, range );
+
+ if (childAddressCells > sizeof(endCell)/sizeof(endCell[0]))
+ panic("IODTResolveAddressCell: Invalid device tree (%u)", (uint32_t)childAddressCells);
+
+ bcopy(range, endCell, childAddressCells * sizeof(UInt32));
+
+ rangeLen = CellsValue(childSizeCells, range + childAddressCells + addressCells);
+ AddLengthToCells(childAddressCells, endCell, rangeLen);
+
+ diff2 = (*compare)( childAddressCells, cell, endCell );
+
+ // if start of cell < start of range, or end of range >= start of cell, skip
+ if ((diff < 0) || (diff2 >= 0))
+ continue;
+
+ len = CellsValue(childSizeCells, cell + childAddressCells);
+ ok = (0 == len);
+
+ if (!ok)
+ {
+ // search for cell end
+ bcopy(cell, endCell, childAddressCells * sizeof(UInt32));
+
+ AddLengthToCells(childAddressCells, endCell, len - 1);
+
+ for( lookRange = startRange;
+ lookRange < endRanges;
+ lookRange += (childCells + addressCells) )
+ {
+ // make sure end of cell >= range start
+ endDiff = (*compare)( childAddressCells, endCell, lookRange );
+ if( endDiff < 0)
+ continue;
+
+ UInt64 rangeStart = CellsValue(addressCells, range + childAddressCells);
+ UInt64 lookRangeStart = CellsValue(addressCells, lookRange + childAddressCells);
+ if ((endDiff - len + 1 + lookRangeStart) == (diff + rangeStart))
+ {
+ ok = true;
+ break;
+ }
+ }
+ if (!ok)
+ continue;
+ }
+ offset += diff;
+ break;
+ }
+
+ if (addressCells + sizeCells > sizeof(cell)/sizeof(cell[0]))
+ panic("IODTResolveAddressCell: Invalid device tree (%u, %u)", (uint32_t)addressCells, (uint32_t)sizeCells);