edac_module.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * edac_module.c
  3. *
  4. * (C) 2007 www.douglaskthompson.com
  5. * This file is licensed under the terms of the GNU General Public
  6. * License version 2. This program is licensed "as is" without any
  7. * warranty of any kind, whether express or implied.
  8. *
  9. * Author: Doug Thompson <norsk5@xmission.com>
  10. *
  11. */
  12. #include <linux/edac.h>
  13. #include "edac_core.h"
  14. #include "edac_module.h"
  15. #define EDAC_MC_VERSION "Ver: 2.0.4 " __DATE__
  16. #ifdef CONFIG_EDAC_DEBUG
  17. /* Values of 0 to 4 will generate output */
  18. int edac_debug_level = 1;
  19. EXPORT_SYMBOL_GPL(edac_debug_level);
  20. #endif
  21. /* scope is to module level only */
  22. struct workqueue_struct *edac_workqueue;
  23. /*
  24. * sysfs object: /sys/devices/system/edac
  25. * need to export to other files in this modules
  26. */
  27. static struct sysdev_class edac_class = {
  28. set_kset_name("edac"),
  29. };
  30. static int edac_class_valid = 0;
  31. /*
  32. * edac_get_edac_class()
  33. *
  34. * return pointer to the edac class of 'edac'
  35. */
  36. struct sysdev_class *edac_get_edac_class(void)
  37. {
  38. struct sysdev_class *classptr=NULL;
  39. if (edac_class_valid)
  40. classptr = &edac_class;
  41. return classptr;
  42. }
  43. /*
  44. * edac_register_sysfs_edac_name()
  45. *
  46. * register the 'edac' into /sys/devices/system
  47. *
  48. * return:
  49. * 0 success
  50. * !0 error
  51. */
  52. static int edac_register_sysfs_edac_name(void)
  53. {
  54. int err;
  55. /* create the /sys/devices/system/edac directory */
  56. err = sysdev_class_register(&edac_class);
  57. if (err) {
  58. debugf1("%s() error=%d\n", __func__, err);
  59. return err;
  60. }
  61. edac_class_valid = 1;
  62. return 0;
  63. }
  64. /*
  65. * sysdev_class_unregister()
  66. *
  67. * unregister the 'edac' from /sys/devices/system
  68. */
  69. static void edac_unregister_sysfs_edac_name(void)
  70. {
  71. /* only if currently registered, then unregister it */
  72. if (edac_class_valid)
  73. sysdev_class_unregister(&edac_class);
  74. edac_class_valid = 0;
  75. }
  76. /*
  77. * edac_workqueue_setup
  78. * initialize the edac work queue for polling operations
  79. */
  80. static int edac_workqueue_setup(void)
  81. {
  82. edac_workqueue = create_singlethread_workqueue("edac-poller");
  83. if (edac_workqueue == NULL)
  84. return -ENODEV;
  85. else
  86. return 0;
  87. }
  88. /*
  89. * edac_workqueue_teardown
  90. * teardown the edac workqueue
  91. */
  92. static void edac_workqueue_teardown(void)
  93. {
  94. if (edac_workqueue) {
  95. flush_workqueue(edac_workqueue);
  96. destroy_workqueue(edac_workqueue);
  97. edac_workqueue = NULL;
  98. }
  99. }
  100. /*
  101. * edac_init
  102. * module initialization entry point
  103. */
  104. static int __init edac_init(void)
  105. {
  106. int err = 0;
  107. edac_printk(KERN_INFO, EDAC_MC, EDAC_MC_VERSION "\n");
  108. /*
  109. * Harvest and clear any boot/initialization PCI parity errors
  110. *
  111. * FIXME: This only clears errors logged by devices present at time of
  112. * module initialization. We should also do an initial clear
  113. * of each newly hotplugged device.
  114. */
  115. edac_pci_clear_parity_errors();
  116. /*
  117. * perform the registration of the /sys/devices/system/edac object
  118. */
  119. if (edac_register_sysfs_edac_name()) {
  120. edac_printk(KERN_ERR, EDAC_MC,
  121. "Error initializing 'edac' kobject\n");
  122. err = -ENODEV;
  123. goto error;
  124. }
  125. /* Create the MC sysfs entries, must be first
  126. */
  127. if (edac_sysfs_memctrl_setup()) {
  128. edac_printk(KERN_ERR, EDAC_MC,
  129. "Error initializing sysfs code\n");
  130. err = -ENODEV;
  131. goto error_sysfs;
  132. }
  133. /* Create the PCI parity sysfs entries */
  134. if (edac_sysfs_pci_setup()) {
  135. edac_printk(KERN_ERR, EDAC_MC,
  136. "PCI: Error initializing sysfs code\n");
  137. err = -ENODEV;
  138. goto error_mem;
  139. }
  140. /* Setup/Initialize the edac_device system */
  141. err = edac_workqueue_setup();
  142. if (err) {
  143. edac_printk(KERN_ERR, EDAC_MC, "init WorkQueue failure\n");
  144. goto error_pci;
  145. }
  146. return 0;
  147. /* Error teardown stack */
  148. error_pci:
  149. edac_sysfs_pci_teardown();
  150. error_mem:
  151. edac_sysfs_memctrl_teardown();
  152. error_sysfs:
  153. edac_unregister_sysfs_edac_name();
  154. error:
  155. return err;
  156. }
  157. /*
  158. * edac_exit()
  159. * module exit/termination function
  160. */
  161. static void __exit edac_exit(void)
  162. {
  163. debugf0("%s()\n", __func__);
  164. /* tear down the various subsystems*/
  165. edac_workqueue_teardown();
  166. edac_sysfs_memctrl_teardown();
  167. edac_sysfs_pci_teardown();
  168. edac_unregister_sysfs_edac_name();
  169. }
  170. /*
  171. * Inform the kernel of our entry and exit points
  172. */
  173. module_init(edac_init);
  174. module_exit(edac_exit);
  175. MODULE_LICENSE("GPL");
  176. MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
  177. MODULE_DESCRIPTION("Core library routines for EDAC reporting");
  178. /* refer to *_sysfs.c files for parameters that are exported via sysfs */
  179. #ifdef CONFIG_EDAC_DEBUG
  180. module_param(edac_debug_level, int, 0644);
  181. MODULE_PARM_DESC(edac_debug_level, "Debug level");
  182. #endif