Merge branch 'v3.19-next/pm-samsung-2' of http://git.kernel.org/pub/scm/linux/kernel...
[cascardo/linux.git] / kernel / resource.c
index 4632201..0bcebff 100644 (file)
@@ -491,6 +491,42 @@ int __weak page_is_ram(unsigned long pfn)
 }
 EXPORT_SYMBOL_GPL(page_is_ram);
 
+/*
+ * Search for a resouce entry that fully contains the specified region.
+ * If found, return 1 if it is RAM, 0 if not.
+ * If not found, or region is not fully contained, return -1
+ *
+ * Used by the ioremap functions to ensure the user is not remapping RAM and is
+ * a vast speed up over walking through the resource table page by page.
+ */
+int region_is_ram(resource_size_t start, unsigned long size)
+{
+       struct resource *p;
+       resource_size_t end = start + size - 1;
+       int flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+       const char *name = "System RAM";
+       int ret = -1;
+
+       read_lock(&resource_lock);
+       for (p = iomem_resource.child; p ; p = p->sibling) {
+               if (end < p->start)
+                       continue;
+
+               if (p->start <= start && end <= p->end) {
+                       /* resource fully contains region */
+                       if ((p->flags != flags) || strcmp(p->name, name))
+                               ret = 0;
+                       else
+                               ret = 1;
+                       break;
+               }
+               if (p->end < start)
+                       break;  /* not found */
+       }
+       read_unlock(&resource_lock);
+       return ret;
+}
+
 void __weak arch_remove_reservations(struct resource *avail)
 {
 }