cache-debugfs.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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;
  28. unsigned long ccr;
  29. 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_uncached();
  35. ccr = __raw_readl(SH_CCR);
  36. if ((ccr & CCR_CACHE_ENABLE) == 0) {
  37. back_to_cached();
  38. seq_printf(file, "disabled\n");
  39. return 0;
  40. }
  41. if (cache_type == CACHE_TYPE_DCACHE) {
  42. addrstart = CACHE_OC_ADDRESS_ARRAY;
  43. cache = &current_cpu_data.dcache;
  44. } else {
  45. addrstart = CACHE_IC_ADDRESS_ARRAY;
  46. cache = &current_cpu_data.icache;
  47. }
  48. waysize = cache->sets;
  49. /*
  50. * If the OC is already in RAM mode, we only have
  51. * half of the entries to consider..
  52. */
  53. if ((ccr & CCR_CACHE_ORA) && cache_type == CACHE_TYPE_DCACHE)
  54. waysize >>= 1;
  55. waysize <<= cache->entry_shift;
  56. for (way = 0; way < cache->ways; way++) {
  57. unsigned long addr;
  58. unsigned int line;
  59. seq_printf(file, "-----------------------------------------\n");
  60. seq_printf(file, "Way %d\n", way);
  61. seq_printf(file, "-----------------------------------------\n");
  62. for (addr = addrstart, line = 0;
  63. addr < addrstart + waysize;
  64. addr += cache->linesz, line++) {
  65. unsigned long data = __raw_readl(addr);
  66. /* Check the V bit, ignore invalid cachelines */
  67. if ((data & 1) == 0)
  68. continue;
  69. /* U: Dirty, cache tag is 10 bits up */
  70. seq_printf(file, "%3d: %c 0x%lx\n",
  71. line, data & 2 ? 'U' : ' ',
  72. data & 0x1ffffc00);
  73. }
  74. addrstart += cache->way_incr;
  75. }
  76. back_to_cached();
  77. return 0;
  78. }
  79. static int cache_debugfs_open(struct inode *inode, struct file *file)
  80. {
  81. return single_open(file, cache_seq_show, inode->i_private);
  82. }
  83. static const struct file_operations cache_debugfs_fops = {
  84. .owner = THIS_MODULE,
  85. .open = cache_debugfs_open,
  86. .read = seq_read,
  87. .llseek = seq_lseek,
  88. .release = single_release,
  89. };
  90. static int __init cache_debugfs_init(void)
  91. {
  92. struct dentry *dcache_dentry, *icache_dentry;
  93. dcache_dentry = debugfs_create_file("dcache", S_IRUSR, arch_debugfs_dir,
  94. (unsigned int *)CACHE_TYPE_DCACHE,
  95. &cache_debugfs_fops);
  96. if (!dcache_dentry)
  97. return -ENOMEM;
  98. icache_dentry = debugfs_create_file("icache", S_IRUSR, arch_debugfs_dir,
  99. (unsigned int *)CACHE_TYPE_ICACHE,
  100. &cache_debugfs_fops);
  101. if (!icache_dentry) {
  102. debugfs_remove(dcache_dentry);
  103. return -ENOMEM;
  104. }
  105. return 0;
  106. }
  107. module_init(cache_debugfs_init);
  108. MODULE_LICENSE("GPL v2");