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