[AVR32] Add missing #include <linux/module.h>
[linux-2.6/openmoko-kernel.git] / arch / avr32 / kernel / cpu.c
blob2e72fd2699dfc4aaf83d7437ddbb028be8046a46
1 /*
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.
7 */
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)
30 unsigned long pccr;
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,
36 size_t count)
38 unsigned long val;
39 char *endp;
41 val = simple_strtoul(buf, &endp, 0);
42 if (endp == buf || val > 0x3f)
43 return -EINVAL;
44 val = (val << 12) | (sysreg_read(PCCR) & 0xfffc0fff);
45 sysreg_write(PCCR, val);
46 return count;
48 static ssize_t show_pc0count(struct sys_device *dev, char *buf)
50 unsigned long pcnt0;
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,
56 size_t count)
58 unsigned long val;
59 char *endp;
61 val = simple_strtoul(buf, &endp, 0);
62 if (endp == buf)
63 return -EINVAL;
64 sysreg_write(PCNT0, val);
66 return count;
69 static ssize_t show_pc1event(struct sys_device *dev, char *buf)
71 unsigned long pccr;
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,
77 size_t count)
79 unsigned long val;
80 char *endp;
82 val = simple_strtoul(buf, &endp, 0);
83 if (endp == buf || val > 0x3f)
84 return -EINVAL;
85 val = (val << 18) | (sysreg_read(PCCR) & 0xff03ffff);
86 sysreg_write(PCCR, val);
87 return count;
89 static ssize_t show_pc1count(struct sys_device *dev, char *buf)
91 unsigned long pcnt1;
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,
97 size_t count)
99 unsigned long val;
100 char *endp;
102 val = simple_strtoul(buf, &endp, 0);
103 if (endp == buf)
104 return -EINVAL;
105 sysreg_write(PCNT1, val);
107 return count;
110 static ssize_t show_pccycles(struct sys_device *dev, char *buf)
112 unsigned long pccnt;
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,
118 size_t count)
120 unsigned long val;
121 char *endp;
123 val = simple_strtoul(buf, &endp, 0);
124 if (endp == buf)
125 return -EINVAL;
126 sysreg_write(PCCNT, val);
128 return count;
131 static ssize_t show_pcenable(struct sys_device *dev, char *buf)
133 unsigned long pccr;
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,
139 size_t count)
141 unsigned long pccr, val;
142 char *endp;
144 val = simple_strtoul(buf, &endp, 0);
145 if (endp == buf)
146 return -EINVAL;
147 if (val)
148 val = 1;
150 pccr = sysreg_read(PCCR);
151 pccr = (pccr & ~1UL) | val;
152 sysreg_write(PCCR, pccr);
154 return count;
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)
168 int cpu;
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);
182 #endif
185 return 0;
188 subsys_initcall(topology_init);
190 static const char *cpu_names[] = {
191 "Morgan",
192 "AP7000",
194 #define NR_CPU_NAMES ARRAY_SIZE(cpu_names)
196 static const char *arch_names[] = {
197 "AVR32A",
198 "AVR32B",
200 #define NR_ARCH_NAMES ARRAY_SIZE(arch_names)
202 static const char *mmu_types[] = {
203 "No MMU",
204 "ITLB and DTLB",
205 "Shared TLB",
206 "MPU"
209 void __init setup_processor(void)
211 unsigned long config0, config1;
212 unsigned cpu_id, cpu_rev, arch_id, arch_rev, mmu_type;
213 unsigned tmp;
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;
230 if (tmp) {
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;
236 if (tmp) {
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",
245 cpu_id, arch_id);
246 return;
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))
255 printk(" fpu");
256 if (config0 & (1 << 5))
257 printk(" java");
258 if (config0 & (1 << 4))
259 printk(" perfctr");
260 if (config0 & (1 << 3))
261 printk(" ocd");
262 printk("\n");
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",
290 icache_size >> 10,
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",
295 dcache_size >> 10,
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);
303 return 0;
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)
313 ++*pos;
314 return NULL;
317 static void c_stop(struct seq_file *m, void *v)
322 struct seq_operations cpuinfo_op = {
323 .start = c_start,
324 .next = c_next,
325 .stop = c_stop,
326 .show = c_show
328 #endif /* CONFIG_PROC_FS */