[Bluetooth] Code cleanup of the drivers source code
[pandora-kernel.git] / kernel / resource.c
index 54835c0..9db38a1 100644 (file)
@@ -7,7 +7,6 @@
  * Arbitrary resource management.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/errno.h>
 
 struct resource ioport_resource = {
        .name   = "PCI IO",
-       .start  = 0x0000,
+       .start  = 0,
        .end    = IO_SPACE_LIMIT,
        .flags  = IORESOURCE_IO,
 };
-
 EXPORT_SYMBOL(ioport_resource);
 
 struct resource iomem_resource = {
        .name   = "PCI mem",
-       .start  = 0UL,
-       .end    = ~0UL,
+       .start  = 0,
+       .end    = -1,
        .flags  = IORESOURCE_MEM,
 };
-
 EXPORT_SYMBOL(iomem_resource);
 
 static DEFINE_RWLOCK(resource_lock);
@@ -232,6 +229,47 @@ int release_resource(struct resource *old)
 
 EXPORT_SYMBOL(release_resource);
 
+#ifdef CONFIG_MEMORY_HOTPLUG
+/*
+ * Finds the lowest memory reosurce exists within [res->start.res->end)
+ * the caller must specify res->start, res->end, res->flags.
+ * If found, returns 0, res is overwritten, if not found, returns -1.
+ */
+int find_next_system_ram(struct resource *res)
+{
+       resource_size_t start, end;
+       struct resource *p;
+
+       BUG_ON(!res);
+
+       start = res->start;
+       end = res->end;
+       BUG_ON(start >= end);
+
+       read_lock(&resource_lock);
+       for (p = iomem_resource.child; p ; p = p->sibling) {
+               /* system ram is just marked as IORESOURCE_MEM */
+               if (p->flags != res->flags)
+                       continue;
+               if (p->start > end) {
+                       p = NULL;
+                       break;
+               }
+               if ((p->end >= start) && (p->start < end))
+                       break;
+       }
+       read_unlock(&resource_lock);
+       if (!p)
+               return -1;
+       /* copy data */
+       if (res->start < p->start)
+               res->start = p->start;
+       if (res->end > p->end)
+               res->end = p->end;
+       return 0;
+}
+#endif
+
 /*
  * Find empty slot in the resource tree given range and alignment.
  */
@@ -306,12 +344,11 @@ EXPORT_SYMBOL(allocate_resource);
  *
  * Returns 0 on success, -EBUSY if the resource can't be inserted.
  *
- * This function is equivalent of request_resource when no conflict
+ * This function is equivalent to request_resource when no conflict
  * happens. If a conflict happens, and the conflicting resources
  * entirely fit within the range of the new resource, then the new
- * resource is inserted and the conflicting resources become childs of
- * the new resource.  Otherwise the new resource becomes the child of
- * the conflicting resource
+ * resource is inserted and the conflicting resources become children of
+ * the new resource.
  */
 int insert_resource(struct resource *parent, struct resource *new)
 {
@@ -319,20 +356,21 @@ int insert_resource(struct resource *parent, struct resource *new)
        struct resource *first, *next;
 
        write_lock(&resource_lock);
- begin:
-       result = 0;
-       first = __request_resource(parent, new);
-       if (!first)
-               goto out;
 
-       result = -EBUSY;
-       if (first == parent)
-               goto out;
+       for (;; parent = first) {
+               result = 0;
+               first = __request_resource(parent, new);
+               if (!first)
+                       goto out;
+
+               result = -EBUSY;
+               if (first == parent)
+                       goto out;
 
-       /* Resource fully contained by the clashing resource? Recurse into it */
-       if (first->start <= new->start && first->end >= new->end) {
-               parent = first;
-               goto begin;
+               if ((first->start > new->start) || (first->end < new->end))
+                       break;
+               if ((first->start == new->start) && (first->end == new->end))
+                       break;
        }
 
        for (next = first; ; next = next->sibling) {
@@ -369,8 +407,6 @@ int insert_resource(struct resource *parent, struct resource *new)
        return result;
 }
 
-EXPORT_SYMBOL(insert_resource);
-
 /*
  * Given an existing resource, change its start and size to match the
  * arguments.  Returns -EBUSY if it can't fit.  Existing children of