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/module.h>
12 #include <linux/slab.h>
13 #include <linux/proc_fs.h>
14 #include <linux/nodemask.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)
54 ((unsigned) ((q) >> FIT_TYPE_SHIFT) & FIT_TYPE_MASK)
56 struct fit_type_map_t
{
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"},
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
)
85 if ((type
> FIT_ENTRY_PAL_A
) && (type
< FIT_ENTRY_UNUSED
))
87 if ((type
> FIT_ENTRY_PAL_B
) && (type
< FIT_ENTRY_PAL_A
))
90 return "Unknown type";
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
)
108 type
= FIT_TYPE(fentry
[1]);
109 return sprintf(page
, "%02x %-25s %x.%02x %016lx %u\n",
112 FIT_MAJOR(fentry
[1]), FIT_MINOR(fentry
[1]),
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
128 dump_fit(char *page
, unsigned long nasid
)
130 unsigned long fentry
[2];
135 for (index
=0;;index
++) {
136 BUG_ON(index
* 60 > PAGE_SIZE
);
137 if (get_fit_entry(nasid
, index
, fentry
, NULL
, 0))
139 p
+= dump_fit_entry(p
, fentry
);
146 dump_version(char *page
, unsigned long nasid
)
148 unsigned long fentry
[2];
153 for (index
= 0; ; index
++) {
154 if (get_fit_entry(nasid
, index
, fentry
, banner
,
157 if (FIT_TYPE(fentry
[1]) == FIT_ENTRY_SAL_A
)
161 len
= sprintf(page
, "%x.%02x\n", FIT_MAJOR(fentry
[1]),
162 FIT_MINOR(fentry
[1]));
166 len
+= snprintf(page
, PAGE_SIZE
-len
, "%s\n", banner
);
171 /* same as in proc_misc.c */
173 proc_calc_metrics(char *page
, char **start
, off_t off
, int count
, int *eof
,
176 if (len
<= off
+ count
)
188 read_version_entry(char *page
, char **start
, off_t off
, int count
, int *eof
,
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
);
200 read_fit_entry(char *page
, char **start
, off_t off
, int count
, int *eof
,
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
);
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
;
230 char name
[NODE_NAME_LEN
];
232 if (!ia64_platform_is("sn2"))
235 size
= num_online_nodes() * sizeof(struct proc_dir_entry
*);
236 proc_entries
= kzalloc(size
, GFP_KERNEL
);
240 sgi_prominfo_entry
= proc_mkdir("sgi_prominfo", NULL
);
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
,
249 create_proc_read_entry("version", 0, *entp
,
250 read_version_entry
, (void *)nasid
);
257 void __exit
prominfo_exit(void)
259 struct proc_dir_entry
**entp
;
260 unsigned int cnodeid
;
261 char name
[NODE_NAME_LEN
];
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
);
271 remove_proc_entry("sgi_prominfo", NULL
);