cosm_debugfs.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Intel MIC Platform Software Stack (MPSS)
  3. *
  4. * Copyright(c) 2015 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License, version 2, as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * The full GNU General Public License is included in this distribution in
  16. * the file called "COPYING".
  17. *
  18. * Intel MIC Coprocessor State Management (COSM) Driver
  19. *
  20. */
  21. #include <linux/debugfs.h>
  22. #include <linux/slab.h>
  23. #include <linux/io.h>
  24. #include "cosm_main.h"
  25. /* Debugfs parent dir */
  26. static struct dentry *cosm_dbg;
  27. /**
  28. * cosm_log_buf_show - Display MIC kernel log buffer
  29. *
  30. * log_buf addr/len is read from System.map by user space
  31. * and populated in sysfs entries.
  32. */
  33. static int cosm_log_buf_show(struct seq_file *s, void *unused)
  34. {
  35. void __iomem *log_buf_va;
  36. int __iomem *log_buf_len_va;
  37. struct cosm_device *cdev = s->private;
  38. void *kva;
  39. int size;
  40. u64 aper_offset;
  41. if (!cdev || !cdev->log_buf_addr || !cdev->log_buf_len)
  42. goto done;
  43. mutex_lock(&cdev->cosm_mutex);
  44. switch (cdev->state) {
  45. case MIC_BOOTING:
  46. case MIC_ONLINE:
  47. case MIC_SHUTTING_DOWN:
  48. break;
  49. default:
  50. goto unlock;
  51. }
  52. /*
  53. * Card kernel will never be relocated and any kernel text/data mapping
  54. * can be translated to phys address by subtracting __START_KERNEL_map.
  55. */
  56. aper_offset = (u64)cdev->log_buf_len - __START_KERNEL_map;
  57. log_buf_len_va = cdev->hw_ops->aper(cdev)->va + aper_offset;
  58. aper_offset = (u64)cdev->log_buf_addr - __START_KERNEL_map;
  59. log_buf_va = cdev->hw_ops->aper(cdev)->va + aper_offset;
  60. size = ioread32(log_buf_len_va);
  61. kva = kmalloc(size, GFP_KERNEL);
  62. if (!kva)
  63. goto unlock;
  64. memcpy_fromio(kva, log_buf_va, size);
  65. seq_write(s, kva, size);
  66. kfree(kva);
  67. unlock:
  68. mutex_unlock(&cdev->cosm_mutex);
  69. done:
  70. return 0;
  71. }
  72. static int cosm_log_buf_open(struct inode *inode, struct file *file)
  73. {
  74. return single_open(file, cosm_log_buf_show, inode->i_private);
  75. }
  76. static const struct file_operations log_buf_ops = {
  77. .owner = THIS_MODULE,
  78. .open = cosm_log_buf_open,
  79. .read = seq_read,
  80. .llseek = seq_lseek,
  81. .release = single_release
  82. };
  83. /**
  84. * cosm_force_reset_show - Force MIC reset
  85. *
  86. * Invokes the force_reset COSM bus op instead of the standard reset
  87. * op in case a force reset of the MIC device is required
  88. */
  89. static int cosm_force_reset_show(struct seq_file *s, void *pos)
  90. {
  91. struct cosm_device *cdev = s->private;
  92. cosm_stop(cdev, true);
  93. return 0;
  94. }
  95. static int cosm_force_reset_debug_open(struct inode *inode, struct file *file)
  96. {
  97. return single_open(file, cosm_force_reset_show, inode->i_private);
  98. }
  99. static const struct file_operations force_reset_ops = {
  100. .owner = THIS_MODULE,
  101. .open = cosm_force_reset_debug_open,
  102. .read = seq_read,
  103. .llseek = seq_lseek,
  104. .release = single_release
  105. };
  106. void cosm_create_debug_dir(struct cosm_device *cdev)
  107. {
  108. char name[16];
  109. if (!cosm_dbg)
  110. return;
  111. scnprintf(name, sizeof(name), "mic%d", cdev->index);
  112. cdev->dbg_dir = debugfs_create_dir(name, cosm_dbg);
  113. if (!cdev->dbg_dir)
  114. return;
  115. debugfs_create_file("log_buf", 0444, cdev->dbg_dir, cdev, &log_buf_ops);
  116. debugfs_create_file("force_reset", 0444, cdev->dbg_dir, cdev,
  117. &force_reset_ops);
  118. }
  119. void cosm_delete_debug_dir(struct cosm_device *cdev)
  120. {
  121. if (!cdev->dbg_dir)
  122. return;
  123. debugfs_remove_recursive(cdev->dbg_dir);
  124. }
  125. void cosm_init_debugfs(void)
  126. {
  127. cosm_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
  128. if (!cosm_dbg)
  129. pr_err("can't create debugfs dir\n");
  130. }
  131. void cosm_exit_debugfs(void)
  132. {
  133. debugfs_remove(cosm_dbg);
  134. }