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
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/config.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/proc_fs.h>
15 #include <linux/nodemask.h>
16 #include <asm/system.h>
18 #include <asm/sn/sn_sal.h>
19 #include <asm/sn/sn_cpuid.h>
20 #include <asm/sn/addrs.h>
22 MODULE_DESCRIPTION("PROM version reporting for /proc");
23 MODULE_AUTHOR("Chad Talbott");
24 MODULE_LICENSE("GPL");
26 /* Standard Intel FIT entry types */
27 #define FIT_ENTRY_FIT_HEADER 0x00 /* FIT header entry */
28 #define FIT_ENTRY_PAL_B 0x01 /* PAL_B entry */
29 /* Entries 0x02 through 0x0D reserved by Intel */
30 #define FIT_ENTRY_PAL_A_PROC 0x0E /* Processor-specific PAL_A entry */
31 #define FIT_ENTRY_PAL_A 0x0F /* PAL_A entry, same as... */
32 #define FIT_ENTRY_PAL_A_GEN 0x0F /* ...Generic PAL_A entry */
33 #define FIT_ENTRY_UNUSED 0x7F /* Unused (reserved by Intel?) */
34 /* OEM-defined entries range from 0x10 to 0x7E. */
35 #define FIT_ENTRY_SAL_A 0x10 /* SAL_A entry */
36 #define FIT_ENTRY_SAL_B 0x11 /* SAL_B entry */
37 #define FIT_ENTRY_SALRUNTIME 0x12 /* SAL runtime entry */
38 #define FIT_ENTRY_EFI 0x1F /* EFI entry */
39 #define FIT_ENTRY_FPSWA 0x20 /* embedded fpswa entry */
40 #define FIT_ENTRY_VMLINUX 0x21 /* embedded vmlinux entry */
42 #define FIT_MAJOR_SHIFT (32 + 8)
43 #define FIT_MAJOR_MASK ((1 << 8) - 1)
44 #define FIT_MINOR_SHIFT 32
45 #define FIT_MINOR_MASK ((1 << 8) - 1)
47 #define FIT_MAJOR(q) \
48 ((unsigned) ((q) >> FIT_MAJOR_SHIFT) & FIT_MAJOR_MASK)
49 #define FIT_MINOR(q) \
50 ((unsigned) ((q) >> FIT_MINOR_SHIFT) & FIT_MINOR_MASK)
52 #define FIT_TYPE_SHIFT (32 + 16)
53 #define FIT_TYPE_MASK ((1 << 7) - 1)
56 ((unsigned) ((q) >> FIT_TYPE_SHIFT) & FIT_TYPE_MASK)
58 struct fit_type_map_t {
63 static const struct fit_type_map_t fit_entry_types[] = {
64 {FIT_ENTRY_FIT_HEADER, "FIT Header"},
65 {FIT_ENTRY_PAL_A_GEN, "Generic PAL_A"},
66 {FIT_ENTRY_PAL_A_PROC, "Processor-specific PAL_A"},
67 {FIT_ENTRY_PAL_A, "PAL_A"},
68 {FIT_ENTRY_PAL_B, "PAL_B"},
69 {FIT_ENTRY_SAL_A, "SAL_A"},
70 {FIT_ENTRY_SAL_B, "SAL_B"},
71 {FIT_ENTRY_SALRUNTIME, "SAL runtime"},
72 {FIT_ENTRY_EFI, "EFI"},
73 {FIT_ENTRY_VMLINUX, "Embedded Linux"},
74 {FIT_ENTRY_FPSWA, "Embedded FPSWA"},
75 {FIT_ENTRY_UNUSED, "Unused"},
79 static const char *fit_type_name(unsigned char type)
81 struct fit_type_map_t const *mapp;
83 for (mapp = fit_entry_types; mapp->type != 0xff; mapp++)
84 if (type == mapp->type)
87 if ((type > FIT_ENTRY_PAL_A) && (type < FIT_ENTRY_UNUSED))
89 if ((type > FIT_ENTRY_PAL_B) && (type < FIT_ENTRY_PAL_A))
92 return "Unknown type";
96 get_fit_entry(unsigned long nasid, int index, unsigned long *fentry,
97 char *banner, int banlen)
99 return ia64_sn_get_fit_compt(nasid, index, fentry, banner, banlen);
104 * These two routines display the FIT table for each node.
106 static int dump_fit_entry(char *page, unsigned long *fentry)
110 type = FIT_TYPE(fentry[1]);
111 return sprintf(page, "%02x %-25s %x.%02x %016lx %u\n",
114 FIT_MAJOR(fentry[1]), FIT_MINOR(fentry[1]),
116 /* mult by sixteen to get size in bytes */
117 (unsigned)(fentry[1] & 0xffffff) * 16);
122 * We assume that the fit table will be small enough that we can print
123 * the whole thing into one page. (This is true for our default 16kB
124 * pages -- each entry is about 60 chars wide when printed.) I read
125 * somewhere that the maximum size of the FIT is 128 entries, so we're
126 * OK except for 4kB pages (and no one is going to do that on SN
130 dump_fit(char *page, unsigned long nasid)
132 unsigned long fentry[2];
137 for (index=0;;index++) {
138 BUG_ON(index * 60 > PAGE_SIZE);
139 if (get_fit_entry(nasid, index, fentry, NULL, 0))
141 p += dump_fit_entry(p, fentry);
148 dump_version(char *page, unsigned long nasid)
150 unsigned long fentry[2];
155 for (index = 0; ; index++) {
156 if (get_fit_entry(nasid, index, fentry, banner,
159 if (FIT_TYPE(fentry[1]) == FIT_ENTRY_SAL_A)
163 len = sprintf(page, "%x.%02x\n", FIT_MAJOR(fentry[1]),
164 FIT_MINOR(fentry[1]));
168 len += snprintf(page, PAGE_SIZE-len, "%s\n", banner);
173 /* same as in proc_misc.c */
175 proc_calc_metrics(char *page, char **start, off_t off, int count, int *eof,
178 if (len <= off + count)
190 read_version_entry(char *page, char **start, off_t off, int count, int *eof,
195 /* data holds the NASID of the node */
196 len = dump_version(page, (unsigned long)data);
197 len = proc_calc_metrics(page, start, off, count, eof, len);
202 read_fit_entry(char *page, char **start, off_t off, int count, int *eof,
207 /* data holds the NASID of the node */
208 len = dump_fit(page, (unsigned long)data);
209 len = proc_calc_metrics(page, start, off, count, eof, len);
214 /* module entry points */
215 int __init prominfo_init(void);
216 void __exit prominfo_exit(void);
218 module_init(prominfo_init);
219 module_exit(prominfo_exit);
221 static struct proc_dir_entry **proc_entries;
222 static struct proc_dir_entry *sgi_prominfo_entry;
224 #define NODE_NAME_LEN 11
226 int __init prominfo_init(void)
228 struct proc_dir_entry **entp;
229 struct proc_dir_entry *p;
233 char name[NODE_NAME_LEN];
235 if (!ia64_platform_is("sn2"))
238 size = num_online_nodes() * sizeof(struct proc_dir_entry *);
239 proc_entries = kzalloc(size, GFP_KERNEL);
243 sgi_prominfo_entry = proc_mkdir("sgi_prominfo", NULL);
246 for_each_online_node(cnodeid) {
247 sprintf(name, "node%d", cnodeid);
248 *entp = proc_mkdir(name, sgi_prominfo_entry);
249 nasid = cnodeid_to_nasid(cnodeid);
250 p = create_proc_read_entry("fit", 0, *entp, read_fit_entry,
253 p->owner = THIS_MODULE;
254 p = create_proc_read_entry("version", 0, *entp,
255 read_version_entry, (void *)nasid);
257 p->owner = THIS_MODULE;
264 void __exit prominfo_exit(void)
266 struct proc_dir_entry **entp;
267 unsigned int cnodeid;
268 char name[NODE_NAME_LEN];
271 for_each_online_node(cnodeid) {
272 remove_proc_entry("fit", *entp);
273 remove_proc_entry("version", *entp);
274 sprintf(name, "node%d", cnodeid);
275 remove_proc_entry(name, sgi_prominfo_entry);
278 remove_proc_entry("sgi_prominfo", NULL);