1 /*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15 #include <linux/smp.h>
16 #include <linux/seq_file.h>
17 #include <linux/threads.h>
18 #include <linux/cpumask.h>
19 #include <linux/timex.h>
20 #include <linux/delay.h>
21 #include <linux/fs.h>
22 #include <linux/proc_fs.h>
23 #include <linux/sysctl.h>
24 #include <linux/hardirq.h>
25 #include <linux/mman.h>
26 #include <asm/unaligned.h>
27 #include <asm/pgtable.h>
28 #include <asm/processor.h>
29 #include <asm/sections.h>
30 #include <asm/homecache.h>
31 #include <asm/hardwall.h>
32 #include <arch/chip.h>
33
34
35 /*
36 * Support /proc/cpuinfo
37 */
38
39 #define cpu_to_ptr(n) ((void *)((long)(n)+1))
40 #define ptr_to_cpu(p) ((long)(p) - 1)
41
show_cpuinfo(struct seq_file * m,void * v)42 static int show_cpuinfo(struct seq_file *m, void *v)
43 {
44 int n = ptr_to_cpu(v);
45
46 if (n == 0) {
47 char buf[NR_CPUS*5];
48 cpulist_scnprintf(buf, sizeof(buf), cpu_online_mask);
49 seq_printf(m, "cpu count\t: %d\n", num_online_cpus());
50 seq_printf(m, "cpu list\t: %s\n", buf);
51 seq_printf(m, "model name\t: %s\n", chip_model);
52 seq_printf(m, "flags\t\t:\n"); /* nothing for now */
53 seq_printf(m, "cpu MHz\t\t: %llu.%06llu\n",
54 get_clock_rate() / 1000000,
55 (get_clock_rate() % 1000000));
56 seq_printf(m, "bogomips\t: %lu.%02lu\n\n",
57 loops_per_jiffy/(500000/HZ),
58 (loops_per_jiffy/(5000/HZ)) % 100);
59 }
60
61 #ifdef CONFIG_SMP
62 if (!cpu_online(n))
63 return 0;
64 #endif
65
66 seq_printf(m, "processor\t: %d\n", n);
67
68 /* Print only num_online_cpus() blank lines total. */
69 if (cpumask_next(n, cpu_online_mask) < nr_cpu_ids)
70 seq_printf(m, "\n");
71
72 return 0;
73 }
74
c_start(struct seq_file * m,loff_t * pos)75 static void *c_start(struct seq_file *m, loff_t *pos)
76 {
77 return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
78 }
c_next(struct seq_file * m,void * v,loff_t * pos)79 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
80 {
81 ++*pos;
82 return c_start(m, pos);
83 }
c_stop(struct seq_file * m,void * v)84 static void c_stop(struct seq_file *m, void *v)
85 {
86 }
87 const struct seq_operations cpuinfo_op = {
88 .start = c_start,
89 .next = c_next,
90 .stop = c_stop,
91 .show = show_cpuinfo,
92 };
93
94 /*
95 * Support /proc/tile directory
96 */
97
proc_tile_init(void)98 static int __init proc_tile_init(void)
99 {
100 struct proc_dir_entry *root = proc_mkdir("tile", NULL);
101 if (root == NULL)
102 return 0;
103
104 proc_tile_hardwall_init(root);
105
106 return 0;
107 }
108
109 arch_initcall(proc_tile_init);
110
111 /*
112 * Support /proc/sys/tile directory
113 */
114
115 #ifndef __tilegx__ /* FIXME: GX: no support for unaligned access yet */
116 static ctl_table unaligned_subtable[] = {
117 {
118 .procname = "enabled",
119 .data = &unaligned_fixup,
120 .maxlen = sizeof(int),
121 .mode = 0644,
122 .proc_handler = &proc_dointvec
123 },
124 {
125 .procname = "printk",
126 .data = &unaligned_printk,
127 .maxlen = sizeof(int),
128 .mode = 0644,
129 .proc_handler = &proc_dointvec
130 },
131 {
132 .procname = "count",
133 .data = &unaligned_fixup_count,
134 .maxlen = sizeof(int),
135 .mode = 0644,
136 .proc_handler = &proc_dointvec
137 },
138 {}
139 };
140
141 static ctl_table unaligned_table[] = {
142 {
143 .procname = "unaligned_fixup",
144 .mode = 0555,
145 .child = unaligned_subtable
146 },
147 {}
148 };
149
150 static struct ctl_path tile_path[] = {
151 { .procname = "tile" },
152 { }
153 };
154
proc_sys_tile_init(void)155 static int __init proc_sys_tile_init(void)
156 {
157 register_sysctl_paths(tile_path, unaligned_table);
158 return 0;
159 }
160
161 arch_initcall(proc_sys_tile_init);
162 #endif
163