crypto: api - Add fips_enable flag
[safe/jmp/linux-2.6] / kernel / resource.c
index 7b9a497..f5b518e 100644 (file)
@@ -8,7 +8,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/sched.h>
 #include <linux/errno.h>
 #include <linux/ioport.h>
 #include <linux/init.h>
@@ -17,6 +16,7 @@
 #include <linux/fs.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/device.h>
 #include <asm/io.h>
 
 
@@ -131,14 +131,8 @@ static const struct file_operations proc_iomem_operations = {
 
 static int __init ioresources_init(void)
 {
-       struct proc_dir_entry *entry;
-
-       entry = create_proc_entry("ioports", 0, NULL);
-       if (entry)
-               entry->proc_fops = &proc_ioports_operations;
-       entry = create_proc_entry("iomem", 0, NULL);
-       if (entry)
-               entry->proc_fops = &proc_iomem_operations;
+       proc_create("ioports", 0, NULL, &proc_ioports_operations);
+       proc_create("iomem", 0, NULL, &proc_iomem_operations);
        return 0;
 }
 __initcall(ioresources_init);
@@ -213,27 +207,6 @@ int request_resource(struct resource *root, struct resource *new)
 EXPORT_SYMBOL(request_resource);
 
 /**
- * ____request_resource - reserve a resource, with resource conflict returned
- * @root: root resource descriptor
- * @new: resource descriptor desired by caller
- *
- * Returns:
- * On success, NULL is returned.
- * On error, a pointer to the conflicting resource is returned.
- */
-struct resource *____request_resource(struct resource *root, struct resource *new)
-{
-       struct resource *conflict;
-
-       write_lock(&resource_lock);
-       conflict = __request_resource(root, new);
-       write_unlock(&resource_lock);
-       return conflict;
-}
-
-EXPORT_SYMBOL(____request_resource);
-
-/**
  * release_resource - release a previously reserved resource
  * @old: resource pointer
  */
@@ -249,13 +222,13 @@ int release_resource(struct resource *old)
 
 EXPORT_SYMBOL(release_resource);
 
-#ifdef CONFIG_MEMORY_HOTPLUG
+#if defined(CONFIG_MEMORY_HOTPLUG) && !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
 /*
  * 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)
+static int find_next_system_ram(struct resource *res)
 {
        resource_size_t start, end;
        struct resource *p;
@@ -288,6 +261,30 @@ int find_next_system_ram(struct resource *res)
                res->end = p->end;
        return 0;
 }
+int
+walk_memory_resource(unsigned long start_pfn, unsigned long nr_pages, void *arg,
+                       int (*func)(unsigned long, unsigned long, void *))
+{
+       struct resource res;
+       unsigned long pfn, len;
+       u64 orig_end;
+       int ret = -1;
+       res.start = (u64) start_pfn << PAGE_SHIFT;
+       res.end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1;
+       res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+       orig_end = res.end;
+       while ((res.start < res.end) && (find_next_system_ram(&res) >= 0)) {
+               pfn = (unsigned long)(res.start >> PAGE_SHIFT);
+               len = (unsigned long)((res.end + 1 - res.start) >> PAGE_SHIFT);
+               ret = (*func)(pfn, len, arg);
+               if (ret)
+                       break;
+               res.start = res.end + 1;
+               res.end = orig_end;
+       }
+       return ret;
+}
+
 #endif
 
 /*
@@ -483,6 +480,24 @@ int adjust_resource(struct resource *res, resource_size_t start, resource_size_t
 
 EXPORT_SYMBOL(adjust_resource);
 
+/**
+ * resource_alignment - calculate resource's alignment
+ * @res: resource pointer
+ *
+ * Returns alignment on success, 0 (invalid alignment) on failure.
+ */
+resource_size_t resource_alignment(struct resource *res)
+{
+       switch (res->flags & (IORESOURCE_SIZEALIGN | IORESOURCE_STARTALIGN)) {
+       case IORESOURCE_SIZEALIGN:
+               return resource_size(res);
+       case IORESOURCE_STARTALIGN:
+               return res->start;
+       default:
+               return 0;
+       }
+}
+
 /*
  * This is compatibility stuff for IO resources.
  *
@@ -618,6 +633,67 @@ void __release_region(struct resource *parent, resource_size_t start,
 EXPORT_SYMBOL(__release_region);
 
 /*
+ * Managed region resource
+ */
+struct region_devres {
+       struct resource *parent;
+       resource_size_t start;
+       resource_size_t n;
+};
+
+static void devm_region_release(struct device *dev, void *res)
+{
+       struct region_devres *this = res;
+
+       __release_region(this->parent, this->start, this->n);
+}
+
+static int devm_region_match(struct device *dev, void *res, void *match_data)
+{
+       struct region_devres *this = res, *match = match_data;
+
+       return this->parent == match->parent &&
+               this->start == match->start && this->n == match->n;
+}
+
+struct resource * __devm_request_region(struct device *dev,
+                               struct resource *parent, resource_size_t start,
+                               resource_size_t n, const char *name)
+{
+       struct region_devres *dr = NULL;
+       struct resource *res;
+
+       dr = devres_alloc(devm_region_release, sizeof(struct region_devres),
+                         GFP_KERNEL);
+       if (!dr)
+               return NULL;
+
+       dr->parent = parent;
+       dr->start = start;
+       dr->n = n;
+
+       res = __request_region(parent, start, n, name);
+       if (res)
+               devres_add(dev, dr);
+       else
+               devres_free(dr);
+
+       return res;
+}
+EXPORT_SYMBOL(__devm_request_region);
+
+void __devm_release_region(struct device *dev, struct resource *parent,
+                          resource_size_t start, resource_size_t n)
+{
+       struct region_devres match_data = { parent, start, n };
+
+       __release_region(parent, start, n);
+       WARN_ON(devres_destroy(dev, devm_region_release, devm_region_match,
+                              &match_data));
+}
+EXPORT_SYMBOL(__devm_release_region);
+
+/*
  * Called from init/main.c to reserve IO ports.
  */
 #define MAXRESERVE 4