debugfs.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include "edac_module.h"
  2. static struct dentry *edac_debugfs;
  3. static ssize_t edac_fake_inject_write(struct file *file,
  4. const char __user *data,
  5. size_t count, loff_t *ppos)
  6. {
  7. struct device *dev = file->private_data;
  8. struct mem_ctl_info *mci = to_mci(dev);
  9. static enum hw_event_mc_err_type type;
  10. u16 errcount = mci->fake_inject_count;
  11. if (!errcount)
  12. errcount = 1;
  13. type = mci->fake_inject_ue ? HW_EVENT_ERR_UNCORRECTED
  14. : HW_EVENT_ERR_CORRECTED;
  15. printk(KERN_DEBUG
  16. "Generating %d %s fake error%s to %d.%d.%d to test core handling. NOTE: this won't test the driver-specific decoding logic.\n",
  17. errcount,
  18. (type == HW_EVENT_ERR_UNCORRECTED) ? "UE" : "CE",
  19. errcount > 1 ? "s" : "",
  20. mci->fake_inject_layer[0],
  21. mci->fake_inject_layer[1],
  22. mci->fake_inject_layer[2]
  23. );
  24. edac_mc_handle_error(type, mci, errcount, 0, 0, 0,
  25. mci->fake_inject_layer[0],
  26. mci->fake_inject_layer[1],
  27. mci->fake_inject_layer[2],
  28. "FAKE ERROR", "for EDAC testing only");
  29. return count;
  30. }
  31. static const struct file_operations debug_fake_inject_fops = {
  32. .open = simple_open,
  33. .write = edac_fake_inject_write,
  34. .llseek = generic_file_llseek,
  35. };
  36. int __init edac_debugfs_init(void)
  37. {
  38. edac_debugfs = debugfs_create_dir("edac", NULL);
  39. if (IS_ERR(edac_debugfs)) {
  40. edac_debugfs = NULL;
  41. return -ENOMEM;
  42. }
  43. return 0;
  44. }
  45. void edac_debugfs_exit(void)
  46. {
  47. debugfs_remove(edac_debugfs);
  48. }
  49. int edac_create_debugfs_nodes(struct mem_ctl_info *mci)
  50. {
  51. struct dentry *d, *parent;
  52. char name[80];
  53. int i;
  54. if (!edac_debugfs)
  55. return -ENODEV;
  56. d = debugfs_create_dir(mci->dev.kobj.name, edac_debugfs);
  57. if (!d)
  58. return -ENOMEM;
  59. parent = d;
  60. for (i = 0; i < mci->n_layers; i++) {
  61. sprintf(name, "fake_inject_%s",
  62. edac_layer_name[mci->layers[i].type]);
  63. d = debugfs_create_u8(name, S_IRUGO | S_IWUSR, parent,
  64. &mci->fake_inject_layer[i]);
  65. if (!d)
  66. goto nomem;
  67. }
  68. d = debugfs_create_bool("fake_inject_ue", S_IRUGO | S_IWUSR, parent,
  69. &mci->fake_inject_ue);
  70. if (!d)
  71. goto nomem;
  72. d = debugfs_create_u16("fake_inject_count", S_IRUGO | S_IWUSR, parent,
  73. &mci->fake_inject_count);
  74. if (!d)
  75. goto nomem;
  76. d = debugfs_create_file("fake_inject", S_IWUSR, parent,
  77. &mci->dev,
  78. &debug_fake_inject_fops);
  79. if (!d)
  80. goto nomem;
  81. mci->debugfs = parent;
  82. return 0;
  83. nomem:
  84. edac_debugfs_remove_recursive(mci->debugfs);
  85. return -ENOMEM;
  86. }
  87. /* Create a toplevel dir under EDAC's debugfs hierarchy */
  88. struct dentry *edac_debugfs_create_dir(const char *dirname)
  89. {
  90. if (!edac_debugfs)
  91. return NULL;
  92. return debugfs_create_dir(dirname, edac_debugfs);
  93. }
  94. EXPORT_SYMBOL_GPL(edac_debugfs_create_dir);
  95. /* Create a toplevel dir under EDAC's debugfs hierarchy with parent @parent */
  96. struct dentry *
  97. edac_debugfs_create_dir_at(const char *dirname, struct dentry *parent)
  98. {
  99. return debugfs_create_dir(dirname, parent);
  100. }
  101. EXPORT_SYMBOL_GPL(edac_debugfs_create_dir_at);
  102. /*
  103. * Create a file under EDAC's hierarchy or a sub-hierarchy:
  104. *
  105. * @name: file name
  106. * @mode: file permissions
  107. * @parent: parent dentry. If NULL, it becomes the toplevel EDAC dir
  108. * @data: private data of caller
  109. * @fops: file operations of this file
  110. */
  111. struct dentry *
  112. edac_debugfs_create_file(const char *name, umode_t mode, struct dentry *parent,
  113. void *data, const struct file_operations *fops)
  114. {
  115. if (!parent)
  116. parent = edac_debugfs;
  117. return debugfs_create_file(name, mode, parent, data, fops);
  118. }
  119. EXPORT_SYMBOL_GPL(edac_debugfs_create_file);
  120. /* Wrapper for debugfs_create_x8() */
  121. struct dentry *edac_debugfs_create_x8(const char *name, umode_t mode,
  122. struct dentry *parent, u8 *value)
  123. {
  124. if (!parent)
  125. parent = edac_debugfs;
  126. return debugfs_create_x8(name, mode, parent, value);
  127. }
  128. EXPORT_SYMBOL_GPL(edac_debugfs_create_x8);
  129. /* Wrapper for debugfs_create_x16() */
  130. struct dentry *edac_debugfs_create_x16(const char *name, umode_t mode,
  131. struct dentry *parent, u16 *value)
  132. {
  133. if (!parent)
  134. parent = edac_debugfs;
  135. return debugfs_create_x16(name, mode, parent, value);
  136. }
  137. EXPORT_SYMBOL_GPL(edac_debugfs_create_x16);