cache-debugfs.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * debugfs ops for the L1 cache
  3. *
  4. * Copyright (C) 2006 Paul Mundt
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/module.h>
  12. #include <linux/debugfs.h>
  13. #include <linux/seq_file.h>
  14. #include <asm/processor.h>
  15. #include <asm/uaccess.h>
  16. #include <asm/cache.h>
  17. #include <asm/io.h>
  18. enum cache_type {
  19. CACHE_TYPE_ICACHE,
  20. CACHE_TYPE_DCACHE,
  21. CACHE_TYPE_UNIFIED,
  22. };
  23. static int cache_seq_show(struct seq_file *file, void *iter)
  24. {
  25. unsigned int cache_type = (unsigned int)file->private;
  26. struct cache_info *cache;
  27. unsigned int waysize, way, cache_size;
  28. unsigned long ccr, base;
  29. static unsigned long addrstart = 0;
  30. /*
  31. * Go uncached immediately so we don't skew the results any
  32. * more than we already are..
  33. */
  34. jump_to_P2();
  35. ccr = ctrl_inl(CCR);
  36. if ((ccr & CCR_CACHE_ENABLE) == 0) {
  37. back_to_P1();
  38. seq_printf(file, "disabled\n");
  39. return 0;
  40. }
  41. if (cache_type == CACHE_TYPE_DCACHE) {
  42. base = CACHE_OC_ADDRESS_ARRAY;
  43. cache = &current_cpu_data.dcache;
  44. } else {
  45. base = CACHE_IC_ADDRESS_ARRAY;
  46. cache = &current_cpu_data.icache;
  47. }
  48. /*
  49. * Due to the amount of data written out (depending on the cache size),
  50. * we may be iterated over multiple times. In this case, keep track of
  51. * the entry position in addrstart, and rewind it when we've hit the
  52. * end of the cache.
  53. *
  54. * Likewise, the same code is used for multiple caches, so care must
  55. * be taken for bouncing addrstart back and forth so the appropriate
  56. * cache is hit.
  57. */
  58. cache_size = cache->ways * cache->sets * cache->linesz;
  59. if (((addrstart & 0xff000000) != base) ||
  60. (addrstart & 0x00ffffff) > cache_size)
  61. addrstart = base;
  62. waysize = cache->sets;
  63. /*
  64. * If the OC is already in RAM mode, we only have
  65. * half of the entries to consider..
  66. */
  67. if ((ccr & CCR_CACHE_ORA) && cache_type == CACHE_TYPE_DCACHE)
  68. waysize >>= 1;
  69. waysize <<= cache->entry_shift;
  70. for (way = 0; way < cache->ways; way++) {
  71. unsigned long addr;
  72. unsigned int line;
  73. seq_printf(file, "-----------------------------------------\n");
  74. seq_printf(file, "Way %d\n", way);
  75. seq_printf(file, "-----------------------------------------\n");
  76. for (addr = addrstart, line = 0;
  77. addr < addrstart + waysize;
  78. addr += cache->linesz, line++) {
  79. unsigned long data = ctrl_inl(addr);
  80. /* Check the V bit, ignore invalid cachelines */
  81. if ((data & 1) == 0)
  82. continue;
  83. /* U: Dirty, cache tag is 10 bits up */
  84. seq_printf(file, "%3d: %c 0x%lx\n",
  85. line, data & 2 ? 'U' : ' ',
  86. data & 0x1ffffc00);
  87. }
  88. addrstart += cache->way_incr;
  89. }
  90. back_to_P1();
  91. return 0;
  92. }
  93. static int cache_debugfs_open(struct inode *inode, struct file *file)
  94. {
  95. return single_open(file, cache_seq_show, inode->i_private);
  96. }
  97. static const struct file_operations cache_debugfs_fops = {
  98. .owner = THIS_MODULE,
  99. .open = cache_debugfs_open,
  100. .read = seq_read,
  101. .llseek = seq_lseek,
  102. .release = seq_release,
  103. };
  104. static int __init cache_debugfs_init(void)
  105. {
  106. struct dentry *dcache_dentry, *icache_dentry;
  107. dcache_dentry = debugfs_create_file("dcache", S_IRUSR, NULL,
  108. (unsigned int *)CACHE_TYPE_DCACHE,
  109. &cache_debugfs_fops);
  110. if (IS_ERR(dcache_dentry))
  111. return PTR_ERR(dcache_dentry);
  112. icache_dentry = debugfs_create_file("icache", S_IRUSR, NULL,
  113. (unsigned int *)CACHE_TYPE_ICACHE,
  114. &cache_debugfs_fops);
  115. if (IS_ERR(icache_dentry)) {
  116. debugfs_remove(dcache_dentry);
  117. return PTR_ERR(icache_dentry);
  118. }
  119. return 0;
  120. }
  121. module_init(cache_debugfs_init);
  122. MODULE_LICENSE("GPL v2");