]> err.no Git - linux-2.6/blobdiff - lib/lmb.c
BKL: revert back to the old spinlock implementation
[linux-2.6] / lib / lmb.c
index 5b2a739bc3d558654c7019f9516a643d3da98573..83287d3869a3d8e52129982f85af166c5b1246fc 100644 (file)
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -474,3 +474,36 @@ int __init lmb_is_reserved(u64 addr)
        }
        return 0;
 }
+
+/*
+ * Given a <base, len>, find which memory regions belong to this range.
+ * Adjust the request and return a contiguous chunk.
+ */
+int lmb_find(struct lmb_property *res)
+{
+       int i;
+       u64 rstart, rend;
+
+       rstart = res->base;
+       rend = rstart + res->size - 1;
+
+       for (i = 0; i < lmb.memory.cnt; i++) {
+               u64 start = lmb.memory.region[i].base;
+               u64 end = start + lmb.memory.region[i].size - 1;
+
+               if (start > rend)
+                       return -1;
+
+               if ((end >= rstart) && (start < rend)) {
+                       /* adjust the request */
+                       if (rstart < start)
+                               rstart = start;
+                       if (rend > end)
+                               rend = end;
+                       res->base = rstart;
+                       res->size = rend - rstart + 1;
+                       return 0;
+               }
+       }
+       return -1;
+}