blob: 115725198038da862a19ef634a0ec38adf23b76f [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;
Srinivas KANDAGATLA298c48a2011-06-02 10:30:44 +000029 unsigned int waysize, way;
30 unsigned long ccr;
31 unsigned long addrstart = 0;
Paul Mundt15f57a22006-09-27 17:51:01 +090032
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) {
Srinivas KANDAGATLA298c48a2011-06-02 10:30:44 +000048 addrstart = 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 {
Srinivas KANDAGATLA298c48a2011-06-02 10:30:44 +000051 addrstart = 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
Paul Mundt15f57a22006-09-27 17:51:01 +090055 waysize = cache->sets;
56
57 /*
58 * If the OC is already in RAM mode, we only have
59 * half of the entries to consider..
60 */
61 if ((ccr & CCR_CACHE_ORA) && cache_type == CACHE_TYPE_DCACHE)
62 waysize >>= 1;
63
64 waysize <<= cache->entry_shift;
65
66 for (way = 0; way < cache->ways; way++) {
67 unsigned long addr;
68 unsigned int line;
69
70 seq_printf(file, "-----------------------------------------\n");
71 seq_printf(file, "Way %d\n", way);
72 seq_printf(file, "-----------------------------------------\n");
73
74 for (addr = addrstart, line = 0;
75 addr < addrstart + waysize;
76 addr += cache->linesz, line++) {
Paul Mundt9d56dd32010-01-26 12:58:40 +090077 unsigned long data = __raw_readl(addr);
Paul Mundt15f57a22006-09-27 17:51:01 +090078
79 /* Check the V bit, ignore invalid cachelines */
80 if ((data & 1) == 0)
81 continue;
82
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
89 addrstart += cache->way_incr;
90 }
91
Stuart Menefycbaa1182007-11-30 17:06:36 +090092 back_to_cached();
Paul Mundt15f57a22006-09-27 17:51:01 +090093
94 return 0;
95}
96
97static int cache_debugfs_open(struct inode *inode, struct file *file)
98{
Paul Mundt711fa802006-10-03 13:14:04 +090099 return single_open(file, cache_seq_show, inode->i_private);
Paul Mundt15f57a22006-09-27 17:51:01 +0900100}
101
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800102static const struct file_operations cache_debugfs_fops = {
Paul Mundt15f57a22006-09-27 17:51:01 +0900103 .owner = THIS_MODULE,
104 .open = cache_debugfs_open,
105 .read = seq_read,
106 .llseek = seq_lseek,
Li Zefan45dabf12008-06-24 13:30:23 +0800107 .release = single_release,
Paul Mundt15f57a22006-09-27 17:51:01 +0900108};
109
110static int __init cache_debugfs_init(void)
111{
112 struct dentry *dcache_dentry, *icache_dentry;
113
Paul Mundt3f224f42010-09-24 04:04:26 +0900114 dcache_dentry = debugfs_create_file("dcache", S_IRUSR, arch_debugfs_dir,
Paul Mundt15f57a22006-09-27 17:51:01 +0900115 (unsigned int *)CACHE_TYPE_DCACHE,
116 &cache_debugfs_fops);
Zhaolei25627c72008-10-17 19:25:09 +0800117 if (!dcache_dentry)
118 return -ENOMEM;
Paul Mundt15f57a22006-09-27 17:51:01 +0900119
Paul Mundt3f224f42010-09-24 04:04:26 +0900120 icache_dentry = debugfs_create_file("icache", S_IRUSR, arch_debugfs_dir,
Paul Mundt15f57a22006-09-27 17:51:01 +0900121 (unsigned int *)CACHE_TYPE_ICACHE,
122 &cache_debugfs_fops);
Zhaolei25627c72008-10-17 19:25:09 +0800123 if (!icache_dentry) {
124 debugfs_remove(dcache_dentry);
125 return -ENOMEM;
126 }
Paul Mundt15f57a22006-09-27 17:51:01 +0900127
128 return 0;
129}
130module_init(cache_debugfs_init);
131
132MODULE_LICENSE("GPL v2");