armada_debugfs.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright (C) 2012 Russell King
  3. * Rewritten from the dovefb driver, and Armada510 manuals.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/ctype.h>
  10. #include <linux/debugfs.h>
  11. #include <linux/module.h>
  12. #include <linux/seq_file.h>
  13. #include <drm/drmP.h>
  14. #include "armada_crtc.h"
  15. #include "armada_drm.h"
  16. static int armada_debugfs_gem_linear_show(struct seq_file *m, void *data)
  17. {
  18. struct drm_info_node *node = m->private;
  19. struct drm_device *dev = node->minor->dev;
  20. struct armada_private *priv = dev->dev_private;
  21. int ret;
  22. mutex_lock(&dev->struct_mutex);
  23. ret = drm_mm_dump_table(m, &priv->linear);
  24. mutex_unlock(&dev->struct_mutex);
  25. return ret;
  26. }
  27. static int armada_debugfs_reg_show(struct seq_file *m, void *data)
  28. {
  29. struct drm_device *dev = m->private;
  30. struct armada_private *priv = dev->dev_private;
  31. int n, i;
  32. if (priv) {
  33. for (n = 0; n < ARRAY_SIZE(priv->dcrtc); n++) {
  34. struct armada_crtc *dcrtc = priv->dcrtc[n];
  35. if (!dcrtc)
  36. continue;
  37. for (i = 0x84; i <= 0x1c4; i += 4) {
  38. uint32_t v = readl_relaxed(dcrtc->base + i);
  39. seq_printf(m, "%u: 0x%04x: 0x%08x\n", n, i, v);
  40. }
  41. }
  42. }
  43. return 0;
  44. }
  45. static int armada_debugfs_reg_r_open(struct inode *inode, struct file *file)
  46. {
  47. return single_open(file, armada_debugfs_reg_show, inode->i_private);
  48. }
  49. static const struct file_operations fops_reg_r = {
  50. .owner = THIS_MODULE,
  51. .open = armada_debugfs_reg_r_open,
  52. .read = seq_read,
  53. .llseek = seq_lseek,
  54. .release = single_release,
  55. };
  56. static int armada_debugfs_write(struct file *file, const char __user *ptr,
  57. size_t len, loff_t *off)
  58. {
  59. struct drm_device *dev = file->private_data;
  60. struct armada_private *priv = dev->dev_private;
  61. struct armada_crtc *dcrtc = priv->dcrtc[0];
  62. char buf[32], *p;
  63. uint32_t reg, val;
  64. int ret;
  65. if (*off != 0)
  66. return 0;
  67. if (len > sizeof(buf) - 1)
  68. len = sizeof(buf) - 1;
  69. ret = strncpy_from_user(buf, ptr, len);
  70. if (ret < 0)
  71. return ret;
  72. buf[len] = '\0';
  73. reg = simple_strtoul(buf, &p, 16);
  74. if (!isspace(*p))
  75. return -EINVAL;
  76. val = simple_strtoul(p + 1, NULL, 16);
  77. if (reg >= 0x84 && reg <= 0x1c4)
  78. writel(val, dcrtc->base + reg);
  79. return len;
  80. }
  81. static int armada_debugfs_reg_w_open(struct inode *inode, struct file *file)
  82. {
  83. file->private_data = inode->i_private;
  84. return 0;
  85. }
  86. static const struct file_operations fops_reg_w = {
  87. .owner = THIS_MODULE,
  88. .open = armada_debugfs_reg_w_open,
  89. .write = armada_debugfs_write,
  90. .llseek = noop_llseek,
  91. };
  92. static struct drm_info_list armada_debugfs_list[] = {
  93. { "gem_linear", armada_debugfs_gem_linear_show, 0 },
  94. };
  95. #define ARMADA_DEBUGFS_ENTRIES ARRAY_SIZE(armada_debugfs_list)
  96. static int drm_add_fake_info_node(struct drm_minor *minor, struct dentry *ent,
  97. const void *key)
  98. {
  99. struct drm_info_node *node;
  100. node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
  101. if (node == NULL) {
  102. debugfs_remove(ent);
  103. return -ENOMEM;
  104. }
  105. node->minor = minor;
  106. node->dent = ent;
  107. node->info_ent = (void *) key;
  108. mutex_lock(&minor->debugfs_lock);
  109. list_add(&node->list, &minor->debugfs_list);
  110. mutex_unlock(&minor->debugfs_lock);
  111. return 0;
  112. }
  113. static int armada_debugfs_create(struct dentry *root, struct drm_minor *minor,
  114. const char *name, umode_t mode, const struct file_operations *fops)
  115. {
  116. struct dentry *de;
  117. de = debugfs_create_file(name, mode, root, minor->dev, fops);
  118. return drm_add_fake_info_node(minor, de, fops);
  119. }
  120. int armada_drm_debugfs_init(struct drm_minor *minor)
  121. {
  122. int ret;
  123. ret = drm_debugfs_create_files(armada_debugfs_list,
  124. ARMADA_DEBUGFS_ENTRIES,
  125. minor->debugfs_root, minor);
  126. if (ret)
  127. return ret;
  128. ret = armada_debugfs_create(minor->debugfs_root, minor,
  129. "reg", S_IFREG | S_IRUSR, &fops_reg_r);
  130. if (ret)
  131. goto err_1;
  132. ret = armada_debugfs_create(minor->debugfs_root, minor,
  133. "reg_wr", S_IFREG | S_IWUSR, &fops_reg_w);
  134. if (ret)
  135. goto err_2;
  136. return ret;
  137. err_2:
  138. drm_debugfs_remove_files((struct drm_info_list *)&fops_reg_r, 1, minor);
  139. err_1:
  140. drm_debugfs_remove_files(armada_debugfs_list, ARMADA_DEBUGFS_ENTRIES,
  141. minor);
  142. return ret;
  143. }
  144. void armada_drm_debugfs_cleanup(struct drm_minor *minor)
  145. {
  146. drm_debugfs_remove_files((struct drm_info_list *)&fops_reg_w, 1, minor);
  147. drm_debugfs_remove_files((struct drm_info_list *)&fops_reg_r, 1, minor);
  148. drm_debugfs_remove_files(armada_debugfs_list, ARMADA_DEBUGFS_ENTRIES,
  149. minor);
  150. }