cpu.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. * Copyright (C) 2005-2006 Atmel Corporation
  3. *
  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/percpu.h>
  13. #include <linux/param.h>
  14. #include <linux/errno.h>
  15. #include <asm/setup.h>
  16. #include <asm/sysreg.h>
  17. static DEFINE_PER_CPU(struct cpu, cpu_devices);
  18. #ifdef CONFIG_PERFORMANCE_COUNTERS
  19. /*
  20. * XXX: If/when a SMP-capable implementation of AVR32 will ever be
  21. * made, we must make sure that the code executes on the correct CPU.
  22. */
  23. static ssize_t show_pc0event(struct sys_device *dev, char *buf)
  24. {
  25. unsigned long pccr;
  26. pccr = sysreg_read(PCCR);
  27. return sprintf(buf, "0x%lx\n", (pccr >> 12) & 0x3f);
  28. }
  29. static ssize_t store_pc0event(struct sys_device *dev, const char *buf,
  30. size_t count)
  31. {
  32. unsigned long val;
  33. char *endp;
  34. val = simple_strtoul(buf, &endp, 0);
  35. if (endp == buf || val > 0x3f)
  36. return -EINVAL;
  37. val = (val << 12) | (sysreg_read(PCCR) & 0xfffc0fff);
  38. sysreg_write(PCCR, val);
  39. return count;
  40. }
  41. static ssize_t show_pc0count(struct sys_device *dev, char *buf)
  42. {
  43. unsigned long pcnt0;
  44. pcnt0 = sysreg_read(PCNT0);
  45. return sprintf(buf, "%lu\n", pcnt0);
  46. }
  47. static ssize_t store_pc0count(struct sys_device *dev, const char *buf,
  48. size_t count)
  49. {
  50. unsigned long val;
  51. char *endp;
  52. val = simple_strtoul(buf, &endp, 0);
  53. if (endp == buf)
  54. return -EINVAL;
  55. sysreg_write(PCNT0, val);
  56. return count;
  57. }
  58. static ssize_t show_pc1event(struct sys_device *dev, char *buf)
  59. {
  60. unsigned long pccr;
  61. pccr = sysreg_read(PCCR);
  62. return sprintf(buf, "0x%lx\n", (pccr >> 18) & 0x3f);
  63. }
  64. static ssize_t store_pc1event(struct sys_device *dev, const char *buf,
  65. size_t count)
  66. {
  67. unsigned long val;
  68. char *endp;
  69. val = simple_strtoul(buf, &endp, 0);
  70. if (endp == buf || val > 0x3f)
  71. return -EINVAL;
  72. val = (val << 18) | (sysreg_read(PCCR) & 0xff03ffff);
  73. sysreg_write(PCCR, val);
  74. return count;
  75. }
  76. static ssize_t show_pc1count(struct sys_device *dev, char *buf)
  77. {
  78. unsigned long pcnt1;
  79. pcnt1 = sysreg_read(PCNT1);
  80. return sprintf(buf, "%lu\n", pcnt1);
  81. }
  82. static ssize_t store_pc1count(struct sys_device *dev, const char *buf,
  83. size_t count)
  84. {
  85. unsigned long val;
  86. char *endp;
  87. val = simple_strtoul(buf, &endp, 0);
  88. if (endp == buf)
  89. return -EINVAL;
  90. sysreg_write(PCNT1, val);
  91. return count;
  92. }
  93. static ssize_t show_pccycles(struct sys_device *dev, char *buf)
  94. {
  95. unsigned long pccnt;
  96. pccnt = sysreg_read(PCCNT);
  97. return sprintf(buf, "%lu\n", pccnt);
  98. }
  99. static ssize_t store_pccycles(struct sys_device *dev, const char *buf,
  100. size_t count)
  101. {
  102. unsigned long val;
  103. char *endp;
  104. val = simple_strtoul(buf, &endp, 0);
  105. if (endp == buf)
  106. return -EINVAL;
  107. sysreg_write(PCCNT, val);
  108. return count;
  109. }
  110. static ssize_t show_pcenable(struct sys_device *dev, char *buf)
  111. {
  112. unsigned long pccr;
  113. pccr = sysreg_read(PCCR);
  114. return sprintf(buf, "%c\n", (pccr & 1)?'1':'0');
  115. }
  116. static ssize_t store_pcenable(struct sys_device *dev, const char *buf,
  117. size_t count)
  118. {
  119. unsigned long pccr, val;
  120. char *endp;
  121. val = simple_strtoul(buf, &endp, 0);
  122. if (endp == buf)
  123. return -EINVAL;
  124. if (val)
  125. val = 1;
  126. pccr = sysreg_read(PCCR);
  127. pccr = (pccr & ~1UL) | val;
  128. sysreg_write(PCCR, pccr);
  129. return count;
  130. }
  131. static SYSDEV_ATTR(pc0event, 0600, show_pc0event, store_pc0event);
  132. static SYSDEV_ATTR(pc0count, 0600, show_pc0count, store_pc0count);
  133. static SYSDEV_ATTR(pc1event, 0600, show_pc1event, store_pc1event);
  134. static SYSDEV_ATTR(pc1count, 0600, show_pc1count, store_pc1count);
  135. static SYSDEV_ATTR(pccycles, 0600, show_pccycles, store_pccycles);
  136. static SYSDEV_ATTR(pcenable, 0600, show_pcenable, store_pcenable);
  137. #endif /* CONFIG_PERFORMANCE_COUNTERS */
  138. static int __init topology_init(void)
  139. {
  140. int cpu;
  141. for_each_possible_cpu(cpu) {
  142. struct cpu *c = &per_cpu(cpu_devices, cpu);
  143. register_cpu(c, cpu);
  144. #ifdef CONFIG_PERFORMANCE_COUNTERS
  145. sysdev_create_file(&c->sysdev, &attr_pc0event);
  146. sysdev_create_file(&c->sysdev, &attr_pc0count);
  147. sysdev_create_file(&c->sysdev, &attr_pc1event);
  148. sysdev_create_file(&c->sysdev, &attr_pc1count);
  149. sysdev_create_file(&c->sysdev, &attr_pccycles);
  150. sysdev_create_file(&c->sysdev, &attr_pcenable);
  151. #endif
  152. }
  153. return 0;
  154. }
  155. subsys_initcall(topology_init);
  156. static const char *cpu_names[] = {
  157. "Morgan",
  158. "AP7000",
  159. };
  160. #define NR_CPU_NAMES ARRAY_SIZE(cpu_names)
  161. static const char *arch_names[] = {
  162. "AVR32A",
  163. "AVR32B",
  164. };
  165. #define NR_ARCH_NAMES ARRAY_SIZE(arch_names)
  166. static const char *mmu_types[] = {
  167. "No MMU",
  168. "ITLB and DTLB",
  169. "Shared TLB",
  170. "MPU"
  171. };
  172. void __init setup_processor(void)
  173. {
  174. unsigned long config0, config1;
  175. unsigned cpu_id, cpu_rev, arch_id, arch_rev, mmu_type;
  176. unsigned tmp;
  177. config0 = sysreg_read(CONFIG0); /* 0x0000013e; */
  178. config1 = sysreg_read(CONFIG1); /* 0x01f689a2; */
  179. cpu_id = config0 >> 24;
  180. cpu_rev = (config0 >> 16) & 0xff;
  181. arch_id = (config0 >> 13) & 0x07;
  182. arch_rev = (config0 >> 10) & 0x07;
  183. mmu_type = (config0 >> 7) & 0x03;
  184. boot_cpu_data.arch_type = arch_id;
  185. boot_cpu_data.cpu_type = cpu_id;
  186. boot_cpu_data.arch_revision = arch_rev;
  187. boot_cpu_data.cpu_revision = cpu_rev;
  188. boot_cpu_data.tlb_config = mmu_type;
  189. tmp = (config1 >> 13) & 0x07;
  190. if (tmp) {
  191. boot_cpu_data.icache.ways = 1 << ((config1 >> 10) & 0x07);
  192. boot_cpu_data.icache.sets = 1 << ((config1 >> 16) & 0x0f);
  193. boot_cpu_data.icache.linesz = 1 << (tmp + 1);
  194. }
  195. tmp = (config1 >> 3) & 0x07;
  196. if (tmp) {
  197. boot_cpu_data.dcache.ways = 1 << (config1 & 0x07);
  198. boot_cpu_data.dcache.sets = 1 << ((config1 >> 6) & 0x0f);
  199. boot_cpu_data.dcache.linesz = 1 << (tmp + 1);
  200. }
  201. if ((cpu_id >= NR_CPU_NAMES) || (arch_id >= NR_ARCH_NAMES)) {
  202. printk ("Unknown CPU configuration (ID %02x, arch %02x), "
  203. "continuing anyway...\n",
  204. cpu_id, arch_id);
  205. return;
  206. }
  207. printk ("CPU: %s [%02x] revision %d (%s revision %d)\n",
  208. cpu_names[cpu_id], cpu_id, cpu_rev,
  209. arch_names[arch_id], arch_rev);
  210. printk ("CPU: MMU configuration: %s\n", mmu_types[mmu_type]);
  211. printk ("CPU: features:");
  212. if (config0 & (1 << 6))
  213. printk(" fpu");
  214. if (config0 & (1 << 5))
  215. printk(" java");
  216. if (config0 & (1 << 4))
  217. printk(" perfctr");
  218. if (config0 & (1 << 3))
  219. printk(" ocd");
  220. printk("\n");
  221. }
  222. #ifdef CONFIG_PROC_FS
  223. static int c_show(struct seq_file *m, void *v)
  224. {
  225. unsigned int icache_size, dcache_size;
  226. unsigned int cpu = smp_processor_id();
  227. icache_size = boot_cpu_data.icache.ways *
  228. boot_cpu_data.icache.sets *
  229. boot_cpu_data.icache.linesz;
  230. dcache_size = boot_cpu_data.dcache.ways *
  231. boot_cpu_data.dcache.sets *
  232. boot_cpu_data.dcache.linesz;
  233. seq_printf(m, "processor\t: %d\n", cpu);
  234. if (boot_cpu_data.arch_type < NR_ARCH_NAMES)
  235. seq_printf(m, "cpu family\t: %s revision %d\n",
  236. arch_names[boot_cpu_data.arch_type],
  237. boot_cpu_data.arch_revision);
  238. if (boot_cpu_data.cpu_type < NR_CPU_NAMES)
  239. seq_printf(m, "cpu type\t: %s revision %d\n",
  240. cpu_names[boot_cpu_data.cpu_type],
  241. boot_cpu_data.cpu_revision);
  242. seq_printf(m, "i-cache\t\t: %dK (%u ways x %u sets x %u)\n",
  243. icache_size >> 10,
  244. boot_cpu_data.icache.ways,
  245. boot_cpu_data.icache.sets,
  246. boot_cpu_data.icache.linesz);
  247. seq_printf(m, "d-cache\t\t: %dK (%u ways x %u sets x %u)\n",
  248. dcache_size >> 10,
  249. boot_cpu_data.dcache.ways,
  250. boot_cpu_data.dcache.sets,
  251. boot_cpu_data.dcache.linesz);
  252. seq_printf(m, "bogomips\t: %lu.%02lu\n",
  253. boot_cpu_data.loops_per_jiffy / (500000/HZ),
  254. (boot_cpu_data.loops_per_jiffy / (5000/HZ)) % 100);
  255. return 0;
  256. }
  257. static void *c_start(struct seq_file *m, loff_t *pos)
  258. {
  259. return *pos < 1 ? (void *)1 : NULL;
  260. }
  261. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  262. {
  263. ++*pos;
  264. return NULL;
  265. }
  266. static void c_stop(struct seq_file *m, void *v)
  267. {
  268. }
  269. struct seq_operations cpuinfo_op = {
  270. .start = c_start,
  271. .next = c_next,
  272. .stop = c_stop,
  273. .show = c_show
  274. };
  275. #endif /* CONFIG_PROC_FS */