blob: 690ed010d00207251f8104ea119bda948849323c [file] [log] [blame]
Paul Mundt15f57a22006-09-27 17:51:01 +09001/*
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
19enum cache_type {
20 CACHE_TYPE_ICACHE,
21 CACHE_TYPE_DCACHE,
22 CACHE_TYPE_UNIFIED,
23};
24
Paul Mundt2dc2f8e2010-01-21 16:05:25 +090025static int cache_seq_show(struct seq_file *file, void *iter)
Paul Mundt15f57a22006-09-27 17:51:01 +090026{
27 unsigned int cache_type = (unsigned int)file->private;
28 struct cache_info *cache;
29 unsigned int waysize, way, cache_size;
30 unsigned long ccr, base;
31 static unsigned long addrstart = 0;
32
33 /*
34 * Go uncached immediately so we don't skew the results any
35 * more than we already are..
36 */
Stuart Menefycbaa1182007-11-30 17:06:36 +090037 jump_to_uncached();
Paul Mundt15f57a22006-09-27 17:51:01 +090038
Paul Mundt9d56dd32010-01-26 12:58:40 +090039 ccr = __raw_readl(CCR);
Paul Mundt15f57a22006-09-27 17:51:01 +090040 if ((ccr & CCR_CACHE_ENABLE) == 0) {
Stuart Menefycbaa1182007-11-30 17:06:36 +090041 back_to_cached();
Paul Mundt15f57a22006-09-27 17:51:01 +090042
43 seq_printf(file, "disabled\n");
44 return 0;
45 }
46
47 if (cache_type == CACHE_TYPE_DCACHE) {
48 base = CACHE_OC_ADDRESS_ARRAY;
Paul Mundt11c19652006-12-25 10:19:56 +090049 cache = &current_cpu_data.dcache;
Paul Mundt15f57a22006-09-27 17:51:01 +090050 } else {
51 base = CACHE_IC_ADDRESS_ARRAY;
Paul Mundt11c19652006-12-25 10:19:56 +090052 cache = &current_cpu_data.icache;
Paul Mundt15f57a22006-09-27 17:51:01 +090053 }
54
55 /*
56 * Due to the amount of data written out (depending on the cache size),
57 * we may be iterated over multiple times. In this case, keep track of
58 * the entry position in addrstart, and rewind it when we've hit the
59 * end of the cache.
60 *
61 * Likewise, the same code is used for multiple caches, so care must
62 * be taken for bouncing addrstart back and forth so the appropriate
63 * cache is hit.
64 */
65 cache_size = cache->ways * cache->sets * cache->linesz;
66 if (((addrstart & 0xff000000) != base) ||
67 (addrstart & 0x00ffffff) > cache_size)
68 addrstart = base;
69
70 waysize = cache->sets;
71
72 /*
73 * If the OC is already in RAM mode, we only have
74 * half of the entries to consider..
75 */
76 if ((ccr & CCR_CACHE_ORA) && cache_type == CACHE_TYPE_DCACHE)
77 waysize >>= 1;
78
79 waysize <<= cache->entry_shift;
80
81 for (way = 0; way < cache->ways; way++) {
82 unsigned long addr;
83 unsigned int line;
84
85 seq_printf(file, "-----------------------------------------\n");
86 seq_printf(file, "Way %d\n", way);
87 seq_printf(file, "-----------------------------------------\n");
88
89 for (addr = addrstart, line = 0;
90 addr < addrstart + waysize;
91 addr += cache->linesz, line++) {
Paul Mundt9d56dd32010-01-26 12:58:40 +090092 unsigned long data = __raw_readl(addr);
Paul Mundt15f57a22006-09-27 17:51:01 +090093
94 /* Check the V bit, ignore invalid cachelines */
95 if ((data & 1) == 0)
96 continue;
97
98 /* U: Dirty, cache tag is 10 bits up */
99 seq_printf(file, "%3d: %c 0x%lx\n",
100 line, data & 2 ? 'U' : ' ',
101 data & 0x1ffffc00);
102 }
103
104 addrstart += cache->way_incr;
105 }
106
Stuart Menefycbaa1182007-11-30 17:06:36 +0900107 back_to_cached();
Paul Mundt15f57a22006-09-27 17:51:01 +0900108
109 return 0;
110}
111
112static int cache_debugfs_open(struct inode *inode, struct file *file)
113{
Paul Mundt711fa802006-10-03 13:14:04 +0900114 return single_open(file, cache_seq_show, inode->i_private);
Paul Mundt15f57a22006-09-27 17:51:01 +0900115}
116
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800117static const struct file_operations cache_debugfs_fops = {
Paul Mundt15f57a22006-09-27 17:51:01 +0900118 .owner = THIS_MODULE,
119 .open = cache_debugfs_open,
120 .read = seq_read,
121 .llseek = seq_lseek,
Li Zefan45dabf12008-06-24 13:30:23 +0800122 .release = single_release,
Paul Mundt15f57a22006-09-27 17:51:01 +0900123};
124
125static int __init cache_debugfs_init(void)
126{
127 struct dentry *dcache_dentry, *icache_dentry;
128
Paul Mundtb9e393c2008-03-07 17:19:58 +0900129 dcache_dentry = debugfs_create_file("dcache", S_IRUSR, sh_debugfs_root,
Paul Mundt15f57a22006-09-27 17:51:01 +0900130 (unsigned int *)CACHE_TYPE_DCACHE,
131 &cache_debugfs_fops);
Zhaolei25627c72008-10-17 19:25:09 +0800132 if (!dcache_dentry)
133 return -ENOMEM;
Paul Mundt15f57a22006-09-27 17:51:01 +0900134 if (IS_ERR(dcache_dentry))
135 return PTR_ERR(dcache_dentry);
136
Paul Mundtb9e393c2008-03-07 17:19:58 +0900137 icache_dentry = debugfs_create_file("icache", S_IRUSR, sh_debugfs_root,
Paul Mundt15f57a22006-09-27 17:51:01 +0900138 (unsigned int *)CACHE_TYPE_ICACHE,
139 &cache_debugfs_fops);
Zhaolei25627c72008-10-17 19:25:09 +0800140 if (!icache_dentry) {
141 debugfs_remove(dcache_dentry);
142 return -ENOMEM;
143 }
Paul Mundt15f57a22006-09-27 17:51:01 +0900144 if (IS_ERR(icache_dentry)) {
145 debugfs_remove(dcache_dentry);
146 return PTR_ERR(icache_dentry);
147 }
148
149 return 0;
150}
151module_init(cache_debugfs_init);
152
153MODULE_LICENSE("GPL v2");