debugfs.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright 2014 IBM Corp.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <linux/debugfs.h>
  10. #include <linux/kernel.h>
  11. #include <linux/slab.h>
  12. #include "cxl.h"
  13. static struct dentry *cxl_debugfs;
  14. /* Helpers to export CXL mmaped IO registers via debugfs */
  15. static int debugfs_io_u64_get(void *data, u64 *val)
  16. {
  17. *val = in_be64((u64 __iomem *)data);
  18. return 0;
  19. }
  20. static int debugfs_io_u64_set(void *data, u64 val)
  21. {
  22. out_be64((u64 __iomem *)data, val);
  23. return 0;
  24. }
  25. DEFINE_DEBUGFS_ATTRIBUTE(fops_io_x64, debugfs_io_u64_get, debugfs_io_u64_set,
  26. "0x%016llx\n");
  27. static struct dentry *debugfs_create_io_x64(const char *name, umode_t mode,
  28. struct dentry *parent, u64 __iomem *value)
  29. {
  30. return debugfs_create_file_unsafe(name, mode, parent,
  31. (void __force *)value, &fops_io_x64);
  32. }
  33. void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir)
  34. {
  35. debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR1));
  36. debugfs_create_io_x64("fir_mask", 0400, dir,
  37. _cxl_p1_addr(adapter, CXL_PSL9_FIR_MASK));
  38. debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_FIR_CNTL));
  39. debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL9_TRACECFG));
  40. debugfs_create_io_x64("debug", 0600, dir,
  41. _cxl_p1_addr(adapter, CXL_PSL9_DEBUG));
  42. debugfs_create_io_x64("xsl-debug", 0600, dir,
  43. _cxl_p1_addr(adapter, CXL_XSL9_DBG));
  44. }
  45. void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir)
  46. {
  47. debugfs_create_io_x64("fir1", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR1));
  48. debugfs_create_io_x64("fir2", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR2));
  49. debugfs_create_io_x64("fir_cntl", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_FIR_CNTL));
  50. debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_TRACE));
  51. }
  52. int cxl_debugfs_adapter_add(struct cxl *adapter)
  53. {
  54. struct dentry *dir;
  55. char buf[32];
  56. if (!cxl_debugfs)
  57. return -ENODEV;
  58. snprintf(buf, 32, "card%i", adapter->adapter_num);
  59. dir = debugfs_create_dir(buf, cxl_debugfs);
  60. if (IS_ERR(dir))
  61. return PTR_ERR(dir);
  62. adapter->debugfs = dir;
  63. debugfs_create_io_x64("err_ivte", S_IRUSR, dir, _cxl_p1_addr(adapter, CXL_PSL_ErrIVTE));
  64. if (adapter->native->sl_ops->debugfs_add_adapter_regs)
  65. adapter->native->sl_ops->debugfs_add_adapter_regs(adapter, dir);
  66. return 0;
  67. }
  68. void cxl_debugfs_adapter_remove(struct cxl *adapter)
  69. {
  70. debugfs_remove_recursive(adapter->debugfs);
  71. }
  72. void cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir)
  73. {
  74. debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
  75. }
  76. void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
  77. {
  78. debugfs_create_io_x64("sstp0", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP0_An));
  79. debugfs_create_io_x64("sstp1", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_SSTP1_An));
  80. debugfs_create_io_x64("fir", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_FIR_SLICE_An));
  81. debugfs_create_io_x64("serr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SERR_An));
  82. debugfs_create_io_x64("afu_debug", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_AFU_DEBUG_An));
  83. debugfs_create_io_x64("trace", S_IRUSR | S_IWUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SLICE_TRACE));
  84. }
  85. int cxl_debugfs_afu_add(struct cxl_afu *afu)
  86. {
  87. struct dentry *dir;
  88. char buf[32];
  89. if (!afu->adapter->debugfs)
  90. return -ENODEV;
  91. snprintf(buf, 32, "psl%i.%i", afu->adapter->adapter_num, afu->slice);
  92. dir = debugfs_create_dir(buf, afu->adapter->debugfs);
  93. if (IS_ERR(dir))
  94. return PTR_ERR(dir);
  95. afu->debugfs = dir;
  96. debugfs_create_io_x64("sr", S_IRUSR, dir, _cxl_p1n_addr(afu, CXL_PSL_SR_An));
  97. debugfs_create_io_x64("dsisr", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DSISR_An));
  98. debugfs_create_io_x64("dar", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_DAR_An));
  99. debugfs_create_io_x64("err_status", S_IRUSR, dir, _cxl_p2n_addr(afu, CXL_PSL_ErrStat_An));
  100. if (afu->adapter->native->sl_ops->debugfs_add_afu_regs)
  101. afu->adapter->native->sl_ops->debugfs_add_afu_regs(afu, dir);
  102. return 0;
  103. }
  104. void cxl_debugfs_afu_remove(struct cxl_afu *afu)
  105. {
  106. debugfs_remove_recursive(afu->debugfs);
  107. }
  108. int __init cxl_debugfs_init(void)
  109. {
  110. struct dentry *ent;
  111. if (!cpu_has_feature(CPU_FTR_HVMODE))
  112. return 0;
  113. ent = debugfs_create_dir("cxl", NULL);
  114. if (IS_ERR(ent))
  115. return PTR_ERR(ent);
  116. cxl_debugfs = ent;
  117. return 0;
  118. }
  119. void cxl_debugfs_exit(void)
  120. {
  121. debugfs_remove_recursive(cxl_debugfs);
  122. }