const: constify remaining dev_pm_ops
[safe/jmp/linux-2.6] / drivers / s390 / block / xpram.c
index 0391698..118de39 100644 (file)
@@ -25,6 +25,9 @@
  *   generic hard disk support to replace ad-hoc partitioning
  */
 
+#define KMSG_COMPONENT "xpram"
+#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
+
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/ctype.h>  /* isdigit, isxdigit */
 #include <linux/hdreg.h>  /* HDIO_GETGEO */
 #include <linux/sysdev.h>
 #include <linux/bio.h>
+#include <linux/suspend.h>
+#include <linux/platform_device.h>
 #include <asm/uaccess.h>
 
 #define XPRAM_NAME     "xpram"
 #define XPRAM_DEVS     1       /* one partition */
 #define XPRAM_MAX_DEVS 32      /* maximal number of devices (partitions) */
 
-#define PRINT_DEBUG(x...)      printk(KERN_DEBUG XPRAM_NAME " debug:" x)
-#define PRINT_INFO(x...)       printk(KERN_INFO XPRAM_NAME " info:" x)
-#define PRINT_WARN(x...)       printk(KERN_WARNING XPRAM_NAME " warning:" x)
-#define PRINT_ERR(x...)                printk(KERN_ERR XPRAM_NAME " error:" x)
-
-
 typedef struct {
        unsigned int    size;           /* size of xpram segment in pages */
        unsigned int    offset;         /* start page of xpram segment */
@@ -141,7 +140,7 @@ static long xpram_page_out (unsigned long page_addr, unsigned int xpage_index)
 /*
  * Check if xpram is available.
  */
-static int __init xpram_present(void)
+static int xpram_present(void)
 {
        unsigned long mem_page;
        int rc;
@@ -157,7 +156,7 @@ static int __init xpram_present(void)
 /*
  * Return index of the last available xpram page.
  */
-static unsigned long __init xpram_highest_page_index(void)
+static unsigned long xpram_highest_page_index(void)
 {
        unsigned int page_index, add_bit;
        unsigned long mem_page;
@@ -245,7 +244,7 @@ static int xpram_getgeo(struct block_device *bdev, struct hd_geometry *geo)
        return 0;
 }
 
-static struct block_device_operations xpram_devops =
+static const struct block_device_operations xpram_devops =
 {
        .owner  = THIS_MODULE,
        .getgeo = xpram_getgeo,
@@ -264,7 +263,7 @@ static int __init xpram_setup_sizes(unsigned long pages)
 
        /* Check number of devices. */
        if (devs <= 0 || devs > XPRAM_MAX_DEVS) {
-               PRINT_ERR("invalid number %d of devices\n",devs);
+               pr_err("%d is not a valid number of XPRAM devices\n",devs);
                return -EINVAL;
        }
        xpram_devs = devs;
@@ -295,22 +294,22 @@ static int __init xpram_setup_sizes(unsigned long pages)
                        mem_auto_no++;
        }
        
-       PRINT_INFO("  number of devices (partitions): %d \n", xpram_devs);
+       pr_info("  number of devices (partitions): %d \n", xpram_devs);
        for (i = 0; i < xpram_devs; i++) {
                if (xpram_sizes[i])
-                       PRINT_INFO("  size of partition %d: %u kB\n",
-                                  i, xpram_sizes[i]);
+                       pr_info("  size of partition %d: %u kB\n",
+                               i, xpram_sizes[i]);
                else
-                       PRINT_INFO("  size of partition %d to be set "
-                                  "automatically\n",i);
+                       pr_info("  size of partition %d to be set "
+                               "automatically\n",i);
        }
-       PRINT_DEBUG("  memory needed (for sized partitions): %lu kB\n",
-                   mem_needed);
-       PRINT_DEBUG("  partitions to be sized automatically: %d\n",
-                   mem_auto_no);
+       pr_info("  memory needed (for sized partitions): %lu kB\n",
+               mem_needed);
+       pr_info("  partitions to be sized automatically: %d\n",
+               mem_auto_no);
 
        if (mem_needed > pages * 4) {
-               PRINT_ERR("Not enough expanded memory available\n");
+               pr_err("Not enough expanded memory available\n");
                return -EINVAL;
        }
 
@@ -322,8 +321,8 @@ static int __init xpram_setup_sizes(unsigned long pages)
         */
        if (mem_auto_no) {
                mem_auto = ((pages - mem_needed / 4) / mem_auto_no) * 4;
-               PRINT_INFO("  automatically determined "
-                          "partition size: %lu kB\n", mem_auto);
+               pr_info("  automatically determined "
+                       "partition size: %lu kB\n", mem_auto);
                for (i = 0; i < xpram_devs; i++)
                        if (xpram_sizes[i] == 0)
                                xpram_sizes[i] = mem_auto;
@@ -346,7 +345,7 @@ static int __init xpram_setup_blkdev(void)
                        goto out;
                }
                blk_queue_make_request(xpram_queues[i], xpram_make_request);
-               blk_queue_hardsect_size(xpram_queues[i], 4096);
+               blk_queue_logical_block_size(xpram_queues[i], 4096);
        }
 
        /*
@@ -386,6 +385,43 @@ out:
 }
 
 /*
+ * Resume failed: Print error message and call panic.
+ */
+static void xpram_resume_error(const char *message)
+{
+       pr_err("Resuming the system failed: %s\n", message);
+       panic("xpram resume error\n");
+}
+
+/*
+ * Check if xpram setup changed between suspend and resume.
+ */
+static int xpram_restore(struct device *dev)
+{
+       if (!xpram_pages)
+               return 0;
+       if (xpram_present() != 0)
+               xpram_resume_error("xpram disappeared");
+       if (xpram_pages != xpram_highest_page_index() + 1)
+               xpram_resume_error("Size of xpram changed");
+       return 0;
+}
+
+static const struct dev_pm_ops xpram_pm_ops = {
+       .restore        = xpram_restore,
+};
+
+static struct platform_driver xpram_pdrv = {
+       .driver = {
+               .name   = XPRAM_NAME,
+               .owner  = THIS_MODULE,
+               .pm     = &xpram_pm_ops,
+       },
+};
+
+static struct platform_device *xpram_pdev;
+
+/*
  * Finally, the init/exit functions.
  */
 static void __exit xpram_exit(void)
@@ -397,6 +433,8 @@ static void __exit xpram_exit(void)
                put_disk(xpram_disks[i]);
        }
        unregister_blkdev(XPRAM_MAJOR, XPRAM_NAME);
+       platform_device_unregister(xpram_pdev);
+       platform_driver_unregister(&xpram_pdrv);
 }
 
 static int __init xpram_init(void)
@@ -405,16 +443,33 @@ static int __init xpram_init(void)
 
        /* Find out size of expanded memory. */
        if (xpram_present() != 0) {
-               PRINT_WARN("No expanded memory available\n");
+               pr_err("No expanded memory available\n");
                return -ENODEV;
        }
        xpram_pages = xpram_highest_page_index() + 1;
-       PRINT_INFO("  %u pages expanded memory found (%lu KB).\n",
-                  xpram_pages, (unsigned long) xpram_pages*4);
+       pr_info("  %u pages expanded memory found (%lu KB).\n",
+               xpram_pages, (unsigned long) xpram_pages*4);
        rc = xpram_setup_sizes(xpram_pages);
        if (rc)
                return rc;
-       return xpram_setup_blkdev();
+       rc = platform_driver_register(&xpram_pdrv);
+       if (rc)
+               return rc;
+       xpram_pdev = platform_device_register_simple(XPRAM_NAME, -1, NULL, 0);
+       if (IS_ERR(xpram_pdev)) {
+               rc = PTR_ERR(xpram_pdev);
+               goto fail_platform_driver_unregister;
+       }
+       rc = xpram_setup_blkdev();
+       if (rc)
+               goto fail_platform_device_unregister;
+       return 0;
+
+fail_platform_device_unregister:
+       platform_device_unregister(xpram_pdev);
+fail_platform_driver_unregister:
+       platform_driver_unregister(&xpram_pdrv);
+       return rc;
 }
 
 module_init(xpram_init);