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>
15 #include <asm/system.h>
17 #include <asm/sn/sn_sal.h>
18 #include <asm/sn/sn_cpuid.h>
19 #include <asm/sn/addrs.h>
21 MODULE_DESCRIPTION("PROM version reporting for /proc");
22 MODULE_AUTHOR("Chad Talbott");
23 MODULE_LICENSE("GPL");
25 /* Standard Intel FIT entry types */
26 #define FIT_ENTRY_FIT_HEADER 0x00 /* FIT header entry */
27 #define FIT_ENTRY_PAL_B 0x01 /* PAL_B entry */
28 /* Entries 0x02 through 0x0D reserved by Intel */
29 #define FIT_ENTRY_PAL_A_PROC 0x0E /* Processor-specific PAL_A entry */
30 #define FIT_ENTRY_PAL_A 0x0F /* PAL_A entry, same as... */
31 #define FIT_ENTRY_PAL_A_GEN 0x0F /* ...Generic PAL_A entry */
32 #define FIT_ENTRY_UNUSED 0x7F /* Unused (reserved by Intel?) */
33 /* OEM-defined entries range from 0x10 to 0x7E. */
34 #define FIT_ENTRY_SAL_A 0x10 /* SAL_A entry */
35 #define FIT_ENTRY_SAL_B 0x11 /* SAL_B entry */
36 #define FIT_ENTRY_SALRUNTIME 0x12 /* SAL runtime entry */
37 #define FIT_ENTRY_EFI 0x1F /* EFI entry */
38 #define FIT_ENTRY_FPSWA 0x20 /* embedded fpswa entry */
39 #define FIT_ENTRY_VMLINUX 0x21 /* embedded vmlinux entry */
41 #define FIT_MAJOR_SHIFT (32 + 8)
42 #define FIT_MAJOR_MASK ((1 << 8) - 1)
43 #define FIT_MINOR_SHIFT 32
44 #define FIT_MINOR_MASK ((1 << 8) - 1)
46 #define FIT_MAJOR(q) \
47 ((unsigned) ((q) >> FIT_MAJOR_SHIFT) & FIT_MAJOR_MASK)
48 #define FIT_MINOR(q) \
49 ((unsigned) ((q) >> FIT_MINOR_SHIFT) & FIT_MINOR_MASK)
51 #define FIT_TYPE_SHIFT (32 + 16)
52 #define FIT_TYPE_MASK ((1 << 7) - 1)
55 ((unsigned) ((q) >> FIT_TYPE_SHIFT) & FIT_TYPE_MASK)
57 struct fit_type_map_t
{
62 static const struct fit_type_map_t fit_entry_types
[] = {
63 {FIT_ENTRY_FIT_HEADER
, "FIT Header"},
64 {FIT_ENTRY_PAL_A_GEN
, "Generic PAL_A"},
65 {FIT_ENTRY_PAL_A_PROC
, "Processor-specific PAL_A"},
66 {FIT_ENTRY_PAL_A
, "PAL_A"},
67 {FIT_ENTRY_PAL_B
, "PAL_B"},
68 {FIT_ENTRY_SAL_A
, "SAL_A"},
69 {FIT_ENTRY_SAL_B
, "SAL_B"},
70 {FIT_ENTRY_SALRUNTIME
, "SAL runtime"},
71 {FIT_ENTRY_EFI
, "EFI"},
72 {FIT_ENTRY_VMLINUX
, "Embedded Linux"},
73 {FIT_ENTRY_FPSWA
, "Embedded FPSWA"},
74 {FIT_ENTRY_UNUSED
, "Unused"},
78 static const char *fit_type_name(unsigned char type
)
80 struct fit_type_map_t
const *mapp
;
82 for (mapp
= fit_entry_types
; mapp
->type
!= 0xff; mapp
++)
83 if (type
== mapp
->type
)
86 if ((type
> FIT_ENTRY_PAL_A
) && (type
< FIT_ENTRY_UNUSED
))
88 if ((type
> FIT_ENTRY_PAL_B
) && (type
< FIT_ENTRY_PAL_A
))
91 return "Unknown type";
95 get_fit_entry(unsigned long nasid
, int index
, unsigned long *fentry
,
96 char *banner
, int banlen
)
98 return ia64_sn_get_fit_compt(nasid
, index
, fentry
, banner
, banlen
);
103 * These two routines display the FIT table for each node.
105 static int dump_fit_entry(char *page
, unsigned long *fentry
)
109 type
= FIT_TYPE(fentry
[1]);
110 return sprintf(page
, "%02x %-25s %x.%02x %016lx %u\n",
113 FIT_MAJOR(fentry
[1]), FIT_MINOR(fentry
[1]),
115 /* mult by sixteen to get size in bytes */
116 (unsigned)(fentry
[1] & 0xffffff) * 16);
121 * We assume that the fit table will be small enough that we can print
122 * the whole thing into one page. (This is true for our default 16kB
123 * pages -- each entry is about 60 chars wide when printed.) I read
124 * somewhere that the maximum size of the FIT is 128 entries, so we're
125 * OK except for 4kB pages (and no one is going to do that on SN
129 dump_fit(char *page
, unsigned long nasid
)
131 unsigned long fentry
[2];
136 for (index
=0;;index
++) {
137 BUG_ON(index
* 60 > PAGE_SIZE
);
138 if (get_fit_entry(nasid
, index
, fentry
, NULL
, 0))
140 p
+= dump_fit_entry(p
, fentry
);
147 dump_version(char *page
, unsigned long nasid
)
149 unsigned long fentry
[2];
154 for (index
= 0; ; index
++) {
155 if (get_fit_entry(nasid
, index
, fentry
, banner
,
158 if (FIT_TYPE(fentry
[1]) == FIT_ENTRY_SAL_A
)
162 len
= sprintf(page
, "%x.%02x\n", FIT_MAJOR(fentry
[1]),
163 FIT_MINOR(fentry
[1]));
167 len
+= snprintf(page
, PAGE_SIZE
-len
, "%s\n", banner
);
172 /* same as in proc_misc.c */
174 proc_calc_metrics(char *page
, char **start
, off_t off
, int count
, int *eof
,
177 if (len
<= off
+ count
)
189 read_version_entry(char *page
, char **start
, off_t off
, int count
, int *eof
,
194 /* data holds the NASID of the node */
195 len
= dump_version(page
, (unsigned long)data
);
196 len
= proc_calc_metrics(page
, start
, off
, count
, eof
, len
);
201 read_fit_entry(char *page
, char **start
, off_t off
, int count
, int *eof
,
206 /* data holds the NASID of the node */
207 len
= dump_fit(page
, (unsigned long)data
);
208 len
= proc_calc_metrics(page
, start
, off
, count
, eof
, len
);
213 /* module entry points */
214 int __init
prominfo_init(void);
215 void __exit
prominfo_exit(void);
217 module_init(prominfo_init
);
218 module_exit(prominfo_exit
);
220 static struct proc_dir_entry
**proc_entries
;
221 static struct proc_dir_entry
*sgi_prominfo_entry
;
223 #define NODE_NAME_LEN 11
225 int __init
prominfo_init(void)
227 struct proc_dir_entry
**entp
;
231 char name
[NODE_NAME_LEN
];
233 if (!ia64_platform_is("sn2"))
236 size
= num_online_nodes() * sizeof(struct proc_dir_entry
*);
237 proc_entries
= kzalloc(size
, GFP_KERNEL
);
241 sgi_prominfo_entry
= proc_mkdir("sgi_prominfo", NULL
);
244 for_each_online_node(cnodeid
) {
245 sprintf(name
, "node%d", cnodeid
);
246 *entp
= proc_mkdir(name
, sgi_prominfo_entry
);
247 nasid
= cnodeid_to_nasid(cnodeid
);
248 create_proc_read_entry("fit", 0, *entp
, read_fit_entry
,
250 create_proc_read_entry("version", 0, *entp
,
251 read_version_entry
, (void *)nasid
);
258 void __exit
prominfo_exit(void)
260 struct proc_dir_entry
**entp
;
261 unsigned int cnodeid
;
262 char name
[NODE_NAME_LEN
];
265 for_each_online_node(cnodeid
) {
266 remove_proc_entry("fit", *entp
);
267 remove_proc_entry("version", *entp
);
268 sprintf(name
, "node%d", cnodeid
);
269 remove_proc_entry(name
, sgi_prominfo_entry
);
272 remove_proc_entry("sgi_prominfo", NULL
);