pandora: update defconfig
[pandora-kernel.git] / drivers / edac / edac_module.c
index 8db0471..7e1374a 100644 (file)
+/*
+ * edac_module.c
+ *
+ * (C) 2007 www.softwarebitmaker.com
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ *
+ * Author: Doug Thompson <dougthompson@xmission.com>
+ *
+ */
+#include <linux/edac.h>
 
-#include <linux/freezer.h>
-#include <linux/kthread.h>
-
-#include "edac_mc.h"
+#include "edac_core.h"
 #include "edac_module.h"
 
-#define EDAC_MC_VERSION "Ver: 2.0.3" __DATE__
+#define EDAC_VERSION "Ver: 2.1.0 " __DATE__
 
 #ifdef CONFIG_EDAC_DEBUG
 /* Values of 0 to 4 will generate output */
-int edac_debug_level = 1;
+int edac_debug_level = 2;
 EXPORT_SYMBOL_GPL(edac_debug_level);
 #endif
 
-static struct task_struct *edac_thread;
+/* scope is to module level only */
+struct workqueue_struct *edac_workqueue;
 
 /*
- * Check MC status every edac_get_poll_msec().
- * Check PCI status every edac_get_poll_msec() as well.
- *
- * This where the work gets done for edac.
+ * sysfs object: /sys/devices/system/edac
+ *     need to export to other files in this modules
+ */
+static struct sysdev_class edac_class = {
+       .name = "edac",
+};
+static int edac_class_valid;
+
+/*
+ * edac_op_state_to_string()
+ */
+char *edac_op_state_to_string(int opstate)
+{
+       if (opstate == OP_RUNNING_POLL)
+               return "POLLED";
+       else if (opstate == OP_RUNNING_INTERRUPT)
+               return "INTERRUPT";
+       else if (opstate == OP_RUNNING_POLL_INTR)
+               return "POLL-INTR";
+       else if (opstate == OP_ALLOC)
+               return "ALLOC";
+       else if (opstate == OP_OFFLINE)
+               return "OFFLINE";
+
+       return "UNKNOWN";
+}
+
+/*
+ * edac_get_edac_class()
  *
- * SMP safe, doesn't use NMI, and auto-rate-limits.
+ *     return pointer to the edac class of 'edac'
  */
-static void do_edac_check(void)
+struct sysdev_class *edac_get_edac_class(void)
 {
-       debugf3("%s()\n", __func__);
+       struct sysdev_class *classptr = NULL;
+
+       if (edac_class_valid)
+               classptr = &edac_class;
 
-       /* perform the poll activities */
-       edac_check_mc_devices();
-       edac_pci_do_parity_check();
+       return classptr;
 }
 
 /*
- * Action thread for EDAC to perform the POLL operations
+ * edac_register_sysfs_edac_name()
+ *
+ *     register the 'edac' into /sys/devices/system
+ *
+ * return:
+ *     0  success
+ *     !0 error
  */
-static int edac_kernel_thread(void *arg)
+static int edac_register_sysfs_edac_name(void)
 {
-       int msec;
-
-       while (!kthread_should_stop()) {
+       int err;
 
-               do_edac_check();
+       /* create the /sys/devices/system/edac directory */
+       err = sysdev_class_register(&edac_class);
 
-               /* goto sleep for the interval */
-               msec = (HZ * edac_get_poll_msec()) / 1000;
-               schedule_timeout_interruptible(msec);
-               try_to_freeze();
+       if (err) {
+               debugf1("%s() error=%d\n", __func__, err);
+               return err;
        }
 
+       edac_class_valid = 1;
        return 0;
 }
 
+/*
+ * sysdev_class_unregister()
+ *
+ *     unregister the 'edac' from /sys/devices/system
+ */
+static void edac_unregister_sysfs_edac_name(void)
+{
+       /* only if currently registered, then unregister it */
+       if (edac_class_valid)
+               sysdev_class_unregister(&edac_class);
+
+       edac_class_valid = 0;
+}
+
+/*
+ * edac_workqueue_setup
+ *     initialize the edac work queue for polling operations
+ */
+static int edac_workqueue_setup(void)
+{
+       edac_workqueue = create_singlethread_workqueue("edac-poller");
+       if (edac_workqueue == NULL)
+               return -ENODEV;
+       else
+               return 0;
+}
+
+/*
+ * edac_workqueue_teardown
+ *     teardown the edac workqueue
+ */
+static void edac_workqueue_teardown(void)
+{
+       if (edac_workqueue) {
+               flush_workqueue(edac_workqueue);
+               destroy_workqueue(edac_workqueue);
+               edac_workqueue = NULL;
+       }
+}
+
 /*
  * edac_init
  *      module initialization entry point
  */
 static int __init edac_init(void)
 {
-       edac_printk(KERN_INFO, EDAC_MC, EDAC_MC_VERSION "\n");
+       int err = 0;
+
+       edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n");
 
        /*
         * Harvest and clear any boot/initialization PCI parity errors
         *
         * FIXME: This only clears errors logged by devices present at time of
-        *      module initialization.  We should also do an initial clear
-        *      of each newly hotplugged device.
+        *      module initialization.  We should also do an initial clear
+        *      of each newly hotplugged device.
         */
        edac_pci_clear_parity_errors();
 
-       /* Create the MC sysfs entries */
-       if (edac_sysfs_memctrl_setup()) {
+       /*
+        * perform the registration of the /sys/devices/system/edac class object
+        */
+       if (edac_register_sysfs_edac_name()) {
                edac_printk(KERN_ERR, EDAC_MC,
-                       "Error initializing sysfs code\n");
-               return -ENODEV;
+                       "Error initializing 'edac' kobject\n");
+               err = -ENODEV;
+               goto error;
        }
 
-       /* Create the PCI parity sysfs entries */
-       if (edac_sysfs_pci_setup()) {
-               edac_sysfs_memctrl_teardown();
-               edac_printk(KERN_ERR, EDAC_MC,
-                       "PCI: Error initializing sysfs code\n");
-               return -ENODEV;
+       /*
+        * now set up the mc_kset under the edac class object
+        */
+       err = edac_sysfs_setup_mc_kset();
+       if (err)
+               goto sysfs_setup_fail;
+
+       /* Setup/Initialize the workq for this core */
+       err = edac_workqueue_setup();
+       if (err) {
+               edac_printk(KERN_ERR, EDAC_MC, "init WorkQueue failure\n");
+               goto workq_fail;
        }
 
-       /* create our kernel thread */
-       edac_thread = kthread_run(edac_kernel_thread, NULL, "kedac");
+       return 0;
 
-       if (IS_ERR(edac_thread)) {
-               /* remove the sysfs entries */
-               edac_sysfs_memctrl_teardown();
-               edac_sysfs_pci_teardown();
-               return PTR_ERR(edac_thread);
-       }
+       /* Error teardown stack */
+workq_fail:
+       edac_sysfs_teardown_mc_kset();
 
-       return 0;
+sysfs_setup_fail:
+       edac_unregister_sysfs_edac_name();
+
+error:
+       return err;
 }
 
 /*
@@ -104,11 +197,11 @@ static int __init edac_init(void)
 static void __exit edac_exit(void)
 {
        debugf0("%s()\n", __func__);
-       kthread_stop(edac_thread);
 
-       /* tear down the sysfs device */
-       edac_sysfs_memctrl_teardown();
-       edac_sysfs_pci_teardown();
+       /* tear down the various subsystems */
+       edac_workqueue_teardown();
+       edac_sysfs_teardown_mc_kset();
+       edac_unregister_sysfs_edac_name();
 }
 
 /*
@@ -127,4 +220,3 @@ MODULE_DESCRIPTION("Core library routines for EDAC reporting");
 module_param(edac_debug_level, int, 0644);
 MODULE_PARM_DESC(edac_debug_level, "Debug level");
 #endif
-