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/module.h>
13 #include <linux/percpu.h>
14 #include <linux/param.h>
15 #include <linux/errno.h>
17 #include <asm/setup.h>
18 #include <asm/sysreg.h>
20 static DEFINE_PER_CPU(struct cpu, cpu_devices);
22 #ifdef CONFIG_PERFORMANCE_COUNTERS
25 * XXX: If/when a SMP-capable implementation of AVR32 will ever be
26 * made, we must make sure that the code executes on the correct CPU.
28 static ssize_t show_pc0event(struct sys_device *dev, char *buf)
32 pccr = sysreg_read(PCCR);
33 return sprintf(buf, "0x%lx\n", (pccr >> 12) & 0x3f);
35 static ssize_t store_pc0event(struct sys_device *dev, const char *buf,
41 val = simple_strtoul(buf, &endp, 0);
42 if (endp == buf || val > 0x3f)
44 val = (val << 12) | (sysreg_read(PCCR) & 0xfffc0fff);
45 sysreg_write(PCCR, val);
48 static ssize_t show_pc0count(struct sys_device *dev, char *buf)
52 pcnt0 = sysreg_read(PCNT0);
53 return sprintf(buf, "%lu\n", pcnt0);
55 static ssize_t store_pc0count(struct sys_device *dev, const char *buf,
61 val = simple_strtoul(buf, &endp, 0);
64 sysreg_write(PCNT0, val);
69 static ssize_t show_pc1event(struct sys_device *dev, char *buf)
73 pccr = sysreg_read(PCCR);
74 return sprintf(buf, "0x%lx\n", (pccr >> 18) & 0x3f);
76 static ssize_t store_pc1event(struct sys_device *dev, const char *buf,
82 val = simple_strtoul(buf, &endp, 0);
83 if (endp == buf || val > 0x3f)
85 val = (val << 18) | (sysreg_read(PCCR) & 0xff03ffff);
86 sysreg_write(PCCR, val);
89 static ssize_t show_pc1count(struct sys_device *dev, char *buf)
93 pcnt1 = sysreg_read(PCNT1);
94 return sprintf(buf, "%lu\n", pcnt1);
96 static ssize_t store_pc1count(struct sys_device *dev, const char *buf,
102 val = simple_strtoul(buf, &endp, 0);
105 sysreg_write(PCNT1, val);
110 static ssize_t show_pccycles(struct sys_device *dev, char *buf)
114 pccnt = sysreg_read(PCCNT);
115 return sprintf(buf, "%lu\n", pccnt);
117 static ssize_t store_pccycles(struct sys_device *dev, const char *buf,
123 val = simple_strtoul(buf, &endp, 0);
126 sysreg_write(PCCNT, val);
131 static ssize_t show_pcenable(struct sys_device *dev, char *buf)
135 pccr = sysreg_read(PCCR);
136 return sprintf(buf, "%c\n", (pccr & 1)?'1':'0');
138 static ssize_t store_pcenable(struct sys_device *dev, const char *buf,
141 unsigned long pccr, val;
144 val = simple_strtoul(buf, &endp, 0);
150 pccr = sysreg_read(PCCR);
151 pccr = (pccr & ~1UL) | val;
152 sysreg_write(PCCR, pccr);
157 static SYSDEV_ATTR(pc0event, 0600, show_pc0event, store_pc0event);
158 static SYSDEV_ATTR(pc0count, 0600, show_pc0count, store_pc0count);
159 static SYSDEV_ATTR(pc1event, 0600, show_pc1event, store_pc1event);
160 static SYSDEV_ATTR(pc1count, 0600, show_pc1count, store_pc1count);
161 static SYSDEV_ATTR(pccycles, 0600, show_pccycles, store_pccycles);
162 static SYSDEV_ATTR(pcenable, 0600, show_pcenable, store_pcenable);
164 #endif /* CONFIG_PERFORMANCE_COUNTERS */
166 static int __init topology_init(void)
170 for_each_possible_cpu(cpu) {
171 struct cpu *c = &per_cpu(cpu_devices, cpu);
173 register_cpu(c, cpu);
175 #ifdef CONFIG_PERFORMANCE_COUNTERS
176 sysdev_create_file(&c->sysdev, &attr_pc0event);
177 sysdev_create_file(&c->sysdev, &attr_pc0count);
178 sysdev_create_file(&c->sysdev, &attr_pc1event);
179 sysdev_create_file(&c->sysdev, &attr_pc1count);
180 sysdev_create_file(&c->sysdev, &attr_pccycles);
181 sysdev_create_file(&c->sysdev, &attr_pcenable);
188 subsys_initcall(topology_init);
190 static const char *cpu_names[] = {
194 #define NR_CPU_NAMES ARRAY_SIZE(cpu_names)
196 static const char *arch_names[] = {
200 #define NR_ARCH_NAMES ARRAY_SIZE(arch_names)
202 static const char *mmu_types[] = {
209 void __init setup_processor(void)
211 unsigned long config0, config1;
212 unsigned cpu_id, cpu_rev, arch_id, arch_rev, mmu_type;
215 config0 = sysreg_read(CONFIG0); /* 0x0000013e; */
216 config1 = sysreg_read(CONFIG1); /* 0x01f689a2; */
217 cpu_id = config0 >> 24;
218 cpu_rev = (config0 >> 16) & 0xff;
219 arch_id = (config0 >> 13) & 0x07;
220 arch_rev = (config0 >> 10) & 0x07;
221 mmu_type = (config0 >> 7) & 0x03;
223 boot_cpu_data.arch_type = arch_id;
224 boot_cpu_data.cpu_type = cpu_id;
225 boot_cpu_data.arch_revision = arch_rev;
226 boot_cpu_data.cpu_revision = cpu_rev;
227 boot_cpu_data.tlb_config = mmu_type;
229 tmp = (config1 >> 13) & 0x07;
231 boot_cpu_data.icache.ways = 1 << ((config1 >> 10) & 0x07);
232 boot_cpu_data.icache.sets = 1 << ((config1 >> 16) & 0x0f);
233 boot_cpu_data.icache.linesz = 1 << (tmp + 1);
235 tmp = (config1 >> 3) & 0x07;
237 boot_cpu_data.dcache.ways = 1 << (config1 & 0x07);
238 boot_cpu_data.dcache.sets = 1 << ((config1 >> 6) & 0x0f);
239 boot_cpu_data.dcache.linesz = 1 << (tmp + 1);
242 if ((cpu_id >= NR_CPU_NAMES) || (arch_id >= NR_ARCH_NAMES)) {
243 printk ("Unknown CPU configuration (ID %02x, arch %02x), "
244 "continuing anyway...\n",
249 printk ("CPU: %s [%02x] revision %d (%s revision %d)\n",
250 cpu_names[cpu_id], cpu_id, cpu_rev,
251 arch_names[arch_id], arch_rev);
252 printk ("CPU: MMU configuration: %s\n", mmu_types[mmu_type]);
253 printk ("CPU: features:");
254 if (config0 & (1 << 6))
256 if (config0 & (1 << 5))
258 if (config0 & (1 << 4))
260 if (config0 & (1 << 3))
265 #ifdef CONFIG_PROC_FS
266 static int c_show(struct seq_file *m, void *v)
268 unsigned int icache_size, dcache_size;
269 unsigned int cpu = smp_processor_id();
271 icache_size = boot_cpu_data.icache.ways *
272 boot_cpu_data.icache.sets *
273 boot_cpu_data.icache.linesz;
274 dcache_size = boot_cpu_data.dcache.ways *
275 boot_cpu_data.dcache.sets *
276 boot_cpu_data.dcache.linesz;
278 seq_printf(m, "processor\t: %d\n", cpu);
280 if (boot_cpu_data.arch_type < NR_ARCH_NAMES)
281 seq_printf(m, "cpu family\t: %s revision %d\n",
282 arch_names[boot_cpu_data.arch_type],
283 boot_cpu_data.arch_revision);
284 if (boot_cpu_data.cpu_type < NR_CPU_NAMES)
285 seq_printf(m, "cpu type\t: %s revision %d\n",
286 cpu_names[boot_cpu_data.cpu_type],
287 boot_cpu_data.cpu_revision);
289 seq_printf(m, "i-cache\t\t: %dK (%u ways x %u sets x %u)\n",
291 boot_cpu_data.icache.ways,
292 boot_cpu_data.icache.sets,
293 boot_cpu_data.icache.linesz);
294 seq_printf(m, "d-cache\t\t: %dK (%u ways x %u sets x %u)\n",
296 boot_cpu_data.dcache.ways,
297 boot_cpu_data.dcache.sets,
298 boot_cpu_data.dcache.linesz);
299 seq_printf(m, "bogomips\t: %lu.%02lu\n",
300 boot_cpu_data.loops_per_jiffy / (500000/HZ),
301 (boot_cpu_data.loops_per_jiffy / (5000/HZ)) % 100);
306 static void *c_start(struct seq_file *m, loff_t *pos)
308 return *pos < 1 ? (void *)1 : NULL;
311 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
317 static void c_stop(struct seq_file *m, void *v)
322 struct seq_operations cpuinfo_op = {
328 #endif /* CONFIG_PROC_FS */