edac_module.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * edac_module.c
  3. *
  4. * (C) 2007 www.softwarebitmaker.com
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. *
  10. * Author: Doug Thompson <dougthompson@xmission.com>
  11. *
  12. */
  13. #include <linux/edac.h>
  14. #include "edac_core.h"
  15. #include "edac_module.h"
  16. #define EDAC_VERSION "Ver: 3.0.0"
  17. #ifdef CONFIG_EDAC_DEBUG
  18. static int edac_set_debug_level(const char *buf, struct kernel_param *kp)
  19. {
  20. unsigned long val;
  21. int ret;
  22. ret = kstrtoul(buf, 0, &val);
  23. if (ret)
  24. return ret;
  25. if (val > 4)
  26. return -EINVAL;
  27. return param_set_int(buf, kp);
  28. }
  29. /* Values of 0 to 4 will generate output */
  30. int edac_debug_level = 2;
  31. EXPORT_SYMBOL_GPL(edac_debug_level);
  32. module_param_call(edac_debug_level, edac_set_debug_level, param_get_int,
  33. &edac_debug_level, 0644);
  34. MODULE_PARM_DESC(edac_debug_level, "EDAC debug level: [0-4], default: 2");
  35. #endif
  36. /*
  37. * edac_op_state_to_string()
  38. */
  39. char *edac_op_state_to_string(int opstate)
  40. {
  41. if (opstate == OP_RUNNING_POLL)
  42. return "POLLED";
  43. else if (opstate == OP_RUNNING_INTERRUPT)
  44. return "INTERRUPT";
  45. else if (opstate == OP_RUNNING_POLL_INTR)
  46. return "POLL-INTR";
  47. else if (opstate == OP_ALLOC)
  48. return "ALLOC";
  49. else if (opstate == OP_OFFLINE)
  50. return "OFFLINE";
  51. return "UNKNOWN";
  52. }
  53. /*
  54. * sysfs object: /sys/devices/system/edac
  55. * need to export to other files
  56. */
  57. static struct bus_type edac_subsys = {
  58. .name = "edac",
  59. .dev_name = "edac",
  60. };
  61. static int edac_subsys_init(void)
  62. {
  63. int err;
  64. /* create the /sys/devices/system/edac directory */
  65. err = subsys_system_register(&edac_subsys, NULL);
  66. if (err)
  67. printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");
  68. return err;
  69. }
  70. static void edac_subsys_exit(void)
  71. {
  72. bus_unregister(&edac_subsys);
  73. }
  74. /* return pointer to the 'edac' node in sysfs */
  75. struct bus_type *edac_get_sysfs_subsys(void)
  76. {
  77. return &edac_subsys;
  78. }
  79. EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
  80. /*
  81. * edac_init
  82. * module initialization entry point
  83. */
  84. static int __init edac_init(void)
  85. {
  86. int err = 0;
  87. edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n");
  88. err = edac_subsys_init();
  89. if (err)
  90. return err;
  91. /*
  92. * Harvest and clear any boot/initialization PCI parity errors
  93. *
  94. * FIXME: This only clears errors logged by devices present at time of
  95. * module initialization. We should also do an initial clear
  96. * of each newly hotplugged device.
  97. */
  98. edac_pci_clear_parity_errors();
  99. err = edac_mc_sysfs_init();
  100. if (err)
  101. goto err_sysfs;
  102. edac_debugfs_init();
  103. err = edac_workqueue_setup();
  104. if (err) {
  105. edac_printk(KERN_ERR, EDAC_MC, "Failure initializing workqueue\n");
  106. goto err_wq;
  107. }
  108. return 0;
  109. err_wq:
  110. edac_debugfs_exit();
  111. edac_mc_sysfs_exit();
  112. err_sysfs:
  113. edac_subsys_exit();
  114. return err;
  115. }
  116. /*
  117. * edac_exit()
  118. * module exit/termination function
  119. */
  120. static void __exit edac_exit(void)
  121. {
  122. edac_dbg(0, "\n");
  123. /* tear down the various subsystems */
  124. edac_workqueue_teardown();
  125. edac_mc_sysfs_exit();
  126. edac_debugfs_exit();
  127. edac_subsys_exit();
  128. }
  129. /*
  130. * Inform the kernel of our entry and exit points
  131. */
  132. subsys_initcall(edac_init);
  133. module_exit(edac_exit);
  134. MODULE_LICENSE("GPL");
  135. MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
  136. MODULE_DESCRIPTION("Core library routines for EDAC reporting");