cpu.c 8.4 KB

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