staging:iio:adc:ad7606 move to info_mask_(shared_by_type/separate)
[linux/fpc-iii.git] / arch / ia64 / sn / kernel / sn2 / prominfo_proc.c
blob20b88cb1881a93e87b57d4d7b3e04e0c907eaa74
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
6 * Copyright (C) 1999,2001-2004, 2006 Silicon Graphics, Inc. All Rights Reserved.
8 * Module to export the system's Firmware Interface Tables, including
9 * PROM revision numbers and banners, in /proc
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/proc_fs.h>
14 #include <linux/nodemask.h>
15 #include <asm/io.h>
16 #include <asm/sn/sn_sal.h>
17 #include <asm/sn/sn_cpuid.h>
18 #include <asm/sn/addrs.h>
20 MODULE_DESCRIPTION("PROM version reporting for /proc");
21 MODULE_AUTHOR("Chad Talbott");
22 MODULE_LICENSE("GPL");
24 /* Standard Intel FIT entry types */
25 #define FIT_ENTRY_FIT_HEADER 0x00 /* FIT header entry */
26 #define FIT_ENTRY_PAL_B 0x01 /* PAL_B entry */
27 /* Entries 0x02 through 0x0D reserved by Intel */
28 #define FIT_ENTRY_PAL_A_PROC 0x0E /* Processor-specific PAL_A entry */
29 #define FIT_ENTRY_PAL_A 0x0F /* PAL_A entry, same as... */
30 #define FIT_ENTRY_PAL_A_GEN 0x0F /* ...Generic PAL_A entry */
31 #define FIT_ENTRY_UNUSED 0x7F /* Unused (reserved by Intel?) */
32 /* OEM-defined entries range from 0x10 to 0x7E. */
33 #define FIT_ENTRY_SAL_A 0x10 /* SAL_A entry */
34 #define FIT_ENTRY_SAL_B 0x11 /* SAL_B entry */
35 #define FIT_ENTRY_SALRUNTIME 0x12 /* SAL runtime entry */
36 #define FIT_ENTRY_EFI 0x1F /* EFI entry */
37 #define FIT_ENTRY_FPSWA 0x20 /* embedded fpswa entry */
38 #define FIT_ENTRY_VMLINUX 0x21 /* embedded vmlinux entry */
40 #define FIT_MAJOR_SHIFT (32 + 8)
41 #define FIT_MAJOR_MASK ((1 << 8) - 1)
42 #define FIT_MINOR_SHIFT 32
43 #define FIT_MINOR_MASK ((1 << 8) - 1)
45 #define FIT_MAJOR(q) \
46 ((unsigned) ((q) >> FIT_MAJOR_SHIFT) & FIT_MAJOR_MASK)
47 #define FIT_MINOR(q) \
48 ((unsigned) ((q) >> FIT_MINOR_SHIFT) & FIT_MINOR_MASK)
50 #define FIT_TYPE_SHIFT (32 + 16)
51 #define FIT_TYPE_MASK ((1 << 7) - 1)
53 #define FIT_TYPE(q) \
54 ((unsigned) ((q) >> FIT_TYPE_SHIFT) & FIT_TYPE_MASK)
56 struct fit_type_map_t {
57 unsigned char type;
58 const char *name;
61 static const struct fit_type_map_t fit_entry_types[] = {
62 {FIT_ENTRY_FIT_HEADER, "FIT Header"},
63 {FIT_ENTRY_PAL_A_GEN, "Generic PAL_A"},
64 {FIT_ENTRY_PAL_A_PROC, "Processor-specific PAL_A"},
65 {FIT_ENTRY_PAL_A, "PAL_A"},
66 {FIT_ENTRY_PAL_B, "PAL_B"},
67 {FIT_ENTRY_SAL_A, "SAL_A"},
68 {FIT_ENTRY_SAL_B, "SAL_B"},
69 {FIT_ENTRY_SALRUNTIME, "SAL runtime"},
70 {FIT_ENTRY_EFI, "EFI"},
71 {FIT_ENTRY_VMLINUX, "Embedded Linux"},
72 {FIT_ENTRY_FPSWA, "Embedded FPSWA"},
73 {FIT_ENTRY_UNUSED, "Unused"},
74 {0xff, "Error"},
77 static const char *fit_type_name(unsigned char type)
79 struct fit_type_map_t const *mapp;
81 for (mapp = fit_entry_types; mapp->type != 0xff; mapp++)
82 if (type == mapp->type)
83 return mapp->name;
85 if ((type > FIT_ENTRY_PAL_A) && (type < FIT_ENTRY_UNUSED))
86 return "OEM type";
87 if ((type > FIT_ENTRY_PAL_B) && (type < FIT_ENTRY_PAL_A))
88 return "Reserved";
90 return "Unknown type";
93 static int
94 get_fit_entry(unsigned long nasid, int index, unsigned long *fentry,
95 char *banner, int banlen)
97 return ia64_sn_get_fit_compt(nasid, index, fentry, banner, banlen);
102 * These two routines display the FIT table for each node.
104 static int dump_fit_entry(char *page, unsigned long *fentry)
106 unsigned type;
108 type = FIT_TYPE(fentry[1]);
109 return sprintf(page, "%02x %-25s %x.%02x %016lx %u\n",
110 type,
111 fit_type_name(type),
112 FIT_MAJOR(fentry[1]), FIT_MINOR(fentry[1]),
113 fentry[0],
114 /* mult by sixteen to get size in bytes */
115 (unsigned)(fentry[1] & 0xffffff) * 16);
120 * We assume that the fit table will be small enough that we can print
121 * the whole thing into one page. (This is true for our default 16kB
122 * pages -- each entry is about 60 chars wide when printed.) I read
123 * somewhere that the maximum size of the FIT is 128 entries, so we're
124 * OK except for 4kB pages (and no one is going to do that on SN
125 * anyway).
127 static int
128 dump_fit(char *page, unsigned long nasid)
130 unsigned long fentry[2];
131 int index;
132 char *p;
134 p = page;
135 for (index=0;;index++) {
136 BUG_ON(index * 60 > PAGE_SIZE);
137 if (get_fit_entry(nasid, index, fentry, NULL, 0))
138 break;
139 p += dump_fit_entry(p, fentry);
142 return p - page;
145 static int
146 dump_version(char *page, unsigned long nasid)
148 unsigned long fentry[2];
149 char banner[128];
150 int index;
151 int len;
153 for (index = 0; ; index++) {
154 if (get_fit_entry(nasid, index, fentry, banner,
155 sizeof(banner)))
156 return 0;
157 if (FIT_TYPE(fentry[1]) == FIT_ENTRY_SAL_A)
158 break;
161 len = sprintf(page, "%x.%02x\n", FIT_MAJOR(fentry[1]),
162 FIT_MINOR(fentry[1]));
163 page += len;
165 if (banner[0])
166 len += snprintf(page, PAGE_SIZE-len, "%s\n", banner);
168 return len;
171 /* same as in proc_misc.c */
172 static int
173 proc_calc_metrics(char *page, char **start, off_t off, int count, int *eof,
174 int len)
176 if (len <= off + count)
177 *eof = 1;
178 *start = page + off;
179 len -= off;
180 if (len > count)
181 len = count;
182 if (len < 0)
183 len = 0;
184 return len;
187 static int
188 read_version_entry(char *page, char **start, off_t off, int count, int *eof,
189 void *data)
191 int len;
193 /* data holds the NASID of the node */
194 len = dump_version(page, (unsigned long)data);
195 len = proc_calc_metrics(page, start, off, count, eof, len);
196 return len;
199 static int
200 read_fit_entry(char *page, char **start, off_t off, int count, int *eof,
201 void *data)
203 int len;
205 /* data holds the NASID of the node */
206 len = dump_fit(page, (unsigned long)data);
207 len = proc_calc_metrics(page, start, off, count, eof, len);
209 return len;
212 /* module entry points */
213 int __init prominfo_init(void);
214 void __exit prominfo_exit(void);
216 module_init(prominfo_init);
217 module_exit(prominfo_exit);
219 static struct proc_dir_entry **proc_entries;
220 static struct proc_dir_entry *sgi_prominfo_entry;
222 #define NODE_NAME_LEN 11
224 int __init prominfo_init(void)
226 struct proc_dir_entry **entp;
227 cnodeid_t cnodeid;
228 unsigned long nasid;
229 int size;
230 char name[NODE_NAME_LEN];
232 if (!ia64_platform_is("sn2"))
233 return 0;
235 size = num_online_nodes() * sizeof(struct proc_dir_entry *);
236 proc_entries = kzalloc(size, GFP_KERNEL);
237 if (!proc_entries)
238 return -ENOMEM;
240 sgi_prominfo_entry = proc_mkdir("sgi_prominfo", NULL);
242 entp = proc_entries;
243 for_each_online_node(cnodeid) {
244 sprintf(name, "node%d", cnodeid);
245 *entp = proc_mkdir(name, sgi_prominfo_entry);
246 nasid = cnodeid_to_nasid(cnodeid);
247 create_proc_read_entry("fit", 0, *entp, read_fit_entry,
248 (void *)nasid);
249 create_proc_read_entry("version", 0, *entp,
250 read_version_entry, (void *)nasid);
251 entp++;
254 return 0;
257 void __exit prominfo_exit(void)
259 struct proc_dir_entry **entp;
260 unsigned int cnodeid;
261 char name[NODE_NAME_LEN];
263 entp = proc_entries;
264 for_each_online_node(cnodeid) {
265 remove_proc_entry("fit", *entp);
266 remove_proc_entry("version", *entp);
267 sprintf(name, "node%d", cnodeid);
268 remove_proc_entry(name, sgi_prominfo_entry);
269 entp++;
271 remove_proc_entry("sgi_prominfo", NULL);
272 kfree(proc_entries);