armada_debugfs.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 const struct file_operations fops_reg_w = {
  82. .owner = THIS_MODULE,
  83. .open = simple_open,
  84. .write = armada_debugfs_write,
  85. .llseek = noop_llseek,
  86. };
  87. static struct drm_info_list armada_debugfs_list[] = {
  88. { "gem_linear", armada_debugfs_gem_linear_show, 0 },
  89. };
  90. #define ARMADA_DEBUGFS_ENTRIES ARRAY_SIZE(armada_debugfs_list)
  91. static int drm_add_fake_info_node(struct drm_minor *minor, struct dentry *ent,
  92. const void *key)
  93. {
  94. struct drm_info_node *node;
  95. node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
  96. if (node == NULL) {
  97. debugfs_remove(ent);
  98. return -ENOMEM;
  99. }
  100. node->minor = minor;
  101. node->dent = ent;
  102. node->info_ent = (void *) key;
  103. mutex_lock(&minor->debugfs_lock);
  104. list_add(&node->list, &minor->debugfs_list);
  105. mutex_unlock(&minor->debugfs_lock);
  106. return 0;
  107. }
  108. static int armada_debugfs_create(struct dentry *root, struct drm_minor *minor,
  109. const char *name, umode_t mode, const struct file_operations *fops)
  110. {
  111. struct dentry *de;
  112. de = debugfs_create_file(name, mode, root, minor->dev, fops);
  113. return drm_add_fake_info_node(minor, de, fops);
  114. }
  115. int armada_drm_debugfs_init(struct drm_minor *minor)
  116. {
  117. int ret;
  118. ret = drm_debugfs_create_files(armada_debugfs_list,
  119. ARMADA_DEBUGFS_ENTRIES,
  120. minor->debugfs_root, minor);
  121. if (ret)
  122. return ret;
  123. ret = armada_debugfs_create(minor->debugfs_root, minor,
  124. "reg", S_IFREG | S_IRUSR, &fops_reg_r);
  125. if (ret)
  126. goto err_1;
  127. ret = armada_debugfs_create(minor->debugfs_root, minor,
  128. "reg_wr", S_IFREG | S_IWUSR, &fops_reg_w);
  129. if (ret)
  130. goto err_2;
  131. return ret;
  132. err_2:
  133. drm_debugfs_remove_files((struct drm_info_list *)&fops_reg_r, 1, minor);
  134. err_1:
  135. drm_debugfs_remove_files(armada_debugfs_list, ARMADA_DEBUGFS_ENTRIES,
  136. minor);
  137. return ret;
  138. }
  139. void armada_drm_debugfs_cleanup(struct drm_minor *minor)
  140. {
  141. drm_debugfs_remove_files((struct drm_info_list *)&fops_reg_w, 1, minor);
  142. drm_debugfs_remove_files((struct drm_info_list *)&fops_reg_r, 1, minor);
  143. drm_debugfs_remove_files(armada_debugfs_list, ARMADA_DEBUGFS_ENTRIES,
  144. minor);
  145. }