2 * Copyright (C) 2005-2006 Atmel Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 #include <linux/init.h>
9 #include <linux/sysdev.h>
10 #include <linux/seq_file.h>
11 #include <linux/cpu.h>
12 #include <linux/percpu.h>
13 #include <linux/param.h>
14 #include <linux/errno.h>
16 #include <asm/setup.h>
17 #include <asm/sysreg.h>
19 static DEFINE_PER_CPU(struct cpu, cpu_devices);
21 #ifdef CONFIG_PERFORMANCE_COUNTERS
24 * XXX: If/when a SMP-capable implementation of AVR32 will ever be
25 * made, we must make sure that the code executes on the correct CPU.
27 static ssize_t show_pc0event(struct sys_device *dev, char *buf)
31 pccr = sysreg_read(PCCR);
32 return sprintf(buf, "0x%lx\n", (pccr >> 12) & 0x3f);
34 static ssize_t store_pc0event(struct sys_device *dev, const char *buf,
40 val = simple_strtoul(buf, &endp, 0);
41 if (endp == buf || val > 0x3f)
43 val = (val << 12) | (sysreg_read(PCCR) & 0xfffc0fff);
44 sysreg_write(PCCR, val);
47 static ssize_t show_pc0count(struct sys_device *dev, char *buf)
51 pcnt0 = sysreg_read(PCNT0);
52 return sprintf(buf, "%lu\n", pcnt0);
54 static ssize_t store_pc0count(struct sys_device *dev, const char *buf,
60 val = simple_strtoul(buf, &endp, 0);
63 sysreg_write(PCNT0, val);
68 static ssize_t show_pc1event(struct sys_device *dev, char *buf)
72 pccr = sysreg_read(PCCR);
73 return sprintf(buf, "0x%lx\n", (pccr >> 18) & 0x3f);
75 static ssize_t store_pc1event(struct sys_device *dev, const char *buf,
81 val = simple_strtoul(buf, &endp, 0);
82 if (endp == buf || val > 0x3f)
84 val = (val << 18) | (sysreg_read(PCCR) & 0xff03ffff);
85 sysreg_write(PCCR, val);
88 static ssize_t show_pc1count(struct sys_device *dev, char *buf)
92 pcnt1 = sysreg_read(PCNT1);
93 return sprintf(buf, "%lu\n", pcnt1);
95 static ssize_t store_pc1count(struct sys_device *dev, const char *buf,
101 val = simple_strtoul(buf, &endp, 0);
104 sysreg_write(PCNT1, val);
109 static ssize_t show_pccycles(struct sys_device *dev, char *buf)
113 pccnt = sysreg_read(PCCNT);
114 return sprintf(buf, "%lu\n", pccnt);
116 static ssize_t store_pccycles(struct sys_device *dev, const char *buf,
122 val = simple_strtoul(buf, &endp, 0);
125 sysreg_write(PCCNT, val);
130 static ssize_t show_pcenable(struct sys_device *dev, char *buf)
134 pccr = sysreg_read(PCCR);
135 return sprintf(buf, "%c\n", (pccr & 1)?'1':'0');
137 static ssize_t store_pcenable(struct sys_device *dev, const char *buf,
140 unsigned long pccr, val;
143 val = simple_strtoul(buf, &endp, 0);
149 pccr = sysreg_read(PCCR);
150 pccr = (pccr & ~1UL) | val;
151 sysreg_write(PCCR, pccr);
156 static SYSDEV_ATTR(pc0event, 0600, show_pc0event, store_pc0event);
157 static SYSDEV_ATTR(pc0count, 0600, show_pc0count, store_pc0count);
158 static SYSDEV_ATTR(pc1event, 0600, show_pc1event, store_pc1event);
159 static SYSDEV_ATTR(pc1count, 0600, show_pc1count, store_pc1count);
160 static SYSDEV_ATTR(pccycles, 0600, show_pccycles, store_pccycles);
161 static SYSDEV_ATTR(pcenable, 0600, show_pcenable, store_pcenable);
163 #endif /* CONFIG_PERFORMANCE_COUNTERS */
165 static int __init topology_init(void)
169 for_each_possible_cpu(cpu) {
170 struct cpu *c = &per_cpu(cpu_devices, cpu);
172 register_cpu(c, cpu);
174 #ifdef CONFIG_PERFORMANCE_COUNTERS
175 sysdev_create_file(&c->sysdev, &attr_pc0event);
176 sysdev_create_file(&c->sysdev, &attr_pc0count);
177 sysdev_create_file(&c->sysdev, &attr_pc1event);
178 sysdev_create_file(&c->sysdev, &attr_pc1count);
179 sysdev_create_file(&c->sysdev, &attr_pccycles);
180 sysdev_create_file(&c->sysdev, &attr_pcenable);
187 subsys_initcall(topology_init);
189 static const char *cpu_names[] = {
193 #define NR_CPU_NAMES ARRAY_SIZE(cpu_names)
195 static const char *arch_names[] = {
199 #define NR_ARCH_NAMES ARRAY_SIZE(arch_names)
201 static const char *mmu_types[] = {
208 void __init setup_processor(void)
210 unsigned long config0, config1;
211 unsigned cpu_id, cpu_rev, arch_id, arch_rev, mmu_type;
214 config0 = sysreg_read(CONFIG0); /* 0x0000013e; */
215 config1 = sysreg_read(CONFIG1); /* 0x01f689a2; */
216 cpu_id = config0 >> 24;
217 cpu_rev = (config0 >> 16) & 0xff;
218 arch_id = (config0 >> 13) & 0x07;
219 arch_rev = (config0 >> 10) & 0x07;
220 mmu_type = (config0 >> 7) & 0x03;
222 boot_cpu_data.arch_type = arch_id;
223 boot_cpu_data.cpu_type = cpu_id;
224 boot_cpu_data.arch_revision = arch_rev;
225 boot_cpu_data.cpu_revision = cpu_rev;
226 boot_cpu_data.tlb_config = mmu_type;
228 tmp = (config1 >> 13) & 0x07;
230 boot_cpu_data.icache.ways = 1 << ((config1 >> 10) & 0x07);
231 boot_cpu_data.icache.sets = 1 << ((config1 >> 16) & 0x0f);
232 boot_cpu_data.icache.linesz = 1 << (tmp + 1);
234 tmp = (config1 >> 3) & 0x07;
236 boot_cpu_data.dcache.ways = 1 << (config1 & 0x07);
237 boot_cpu_data.dcache.sets = 1 << ((config1 >> 6) & 0x0f);
238 boot_cpu_data.dcache.linesz = 1 << (tmp + 1);
241 if ((cpu_id >= NR_CPU_NAMES) || (arch_id >= NR_ARCH_NAMES)) {
242 printk ("Unknown CPU configuration (ID %02x, arch %02x), "
243 "continuing anyway...\n",
248 printk ("CPU: %s [%02x] revision %d (%s revision %d)\n",
249 cpu_names[cpu_id], cpu_id, cpu_rev,
250 arch_names[arch_id], arch_rev);
251 printk ("CPU: MMU configuration: %s\n", mmu_types[mmu_type]);
252 printk ("CPU: features:");
253 if (config0 & (1 << 6))
255 if (config0 & (1 << 5))
257 if (config0 & (1 << 4))
259 if (config0 & (1 << 3))
264 #ifdef CONFIG_PROC_FS
265 static int c_show(struct seq_file *m, void *v)
267 unsigned int icache_size, dcache_size;
268 unsigned int cpu = smp_processor_id();
270 icache_size = boot_cpu_data.icache.ways *
271 boot_cpu_data.icache.sets *
272 boot_cpu_data.icache.linesz;
273 dcache_size = boot_cpu_data.dcache.ways *
274 boot_cpu_data.dcache.sets *
275 boot_cpu_data.dcache.linesz;
277 seq_printf(m, "processor\t: %d\n", cpu);
279 if (boot_cpu_data.arch_type < NR_ARCH_NAMES)
280 seq_printf(m, "cpu family\t: %s revision %d\n",
281 arch_names[boot_cpu_data.arch_type],
282 boot_cpu_data.arch_revision);
283 if (boot_cpu_data.cpu_type < NR_CPU_NAMES)
284 seq_printf(m, "cpu type\t: %s revision %d\n",
285 cpu_names[boot_cpu_data.cpu_type],
286 boot_cpu_data.cpu_revision);
288 seq_printf(m, "i-cache\t\t: %dK (%u ways x %u sets x %u)\n",
290 boot_cpu_data.icache.ways,
291 boot_cpu_data.icache.sets,
292 boot_cpu_data.icache.linesz);
293 seq_printf(m, "d-cache\t\t: %dK (%u ways x %u sets x %u)\n",
295 boot_cpu_data.dcache.ways,
296 boot_cpu_data.dcache.sets,
297 boot_cpu_data.dcache.linesz);
298 seq_printf(m, "bogomips\t: %lu.%02lu\n",
299 boot_cpu_data.loops_per_jiffy / (500000/HZ),
300 (boot_cpu_data.loops_per_jiffy / (5000/HZ)) % 100);
305 static void *c_start(struct seq_file *m, loff_t *pos)
307 return *pos < 1 ? (void *)1 : NULL;
310 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
316 static void c_stop(struct seq_file *m, void *v)
321 struct seq_operations cpuinfo_op = {
327 #endif /* CONFIG_PROC_FS */