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 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 <asm/system.h>
17 #include <asm/sn/sn_sal.h>
18 #include <asm/sn/sn_cpuid.h>
19 #include <asm/sn/sn2/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" },
79 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 /* ============ BEGIN temp til old PROMs are no longer supported =============
98 * The OS should not make direct access to the PROM flash memory. Access to
99 * this region must be serialized with a PROM lock. If SAL on one cpu is
100 * updating the FLASH error log at the same time another cpu is accessing the
101 * PROM, data corruption will occur.
103 * To solve the problem, all flash PROM access has been moved to SAL. Because
104 * not all systems will have instant PROM updates, we need to support a new OS
105 * running on a system with old PROMs.
107 * This code should be deleted after 1 OS/PROM release has occurred & the OS
108 * no longer supports downrev PROMs. (PROM support should be in the 3.50
111 #define SUPPORT_OLD_PROMS
112 #ifdef SUPPORT_OLD_PROMS
115 #define FIT_SIGNATURE 0x2020205f5449465ful
117 /* Sub-regions determined by bits in Node Offset */
118 #define LB_PROM_SPACE 0x0000000700000000ul /* Local LB PROM */
120 /* Offset of PROM banner pointers in SAL A and SAL B */
121 #define SAL_A_BANNER_OFFSET (1 * 16)
122 #define SAL_B_BANNER_OFFSET (3 * 16)
124 /* Architected IA64 firmware space */
125 #define FW_BASE 0x00000000FF000000
126 #define FW_TOP 0x0000000100000000
129 convert_fw_addr(nasid_t nasid, unsigned long addr)
131 /* snag just the node-relative offset */
132 addr &= ~0ul >> (63-35);
133 /* the pointer to SAL A is relative to IA-64 compatibility
134 * space. However, the PROM is mapped at a different offset
135 * in MMR space (both local and global)
138 return GLOBAL_MMR_ADDR(nasid, addr);
142 valid_fw_addr(unsigned long addr)
144 addr &= ~(1ul << 63); /* Clear cached/uncached bit */
145 return (addr >= FW_BASE && addr < FW_TOP);
148 static unsigned long *
149 lookup_fit(int nasid)
152 unsigned long fit_paddr;
153 unsigned long *fit_vaddr;
155 fitp = (void *)GLOBAL_MMR_ADDR(nasid, LB_PROM_SPACE - 32);
156 fit_paddr = readq(fitp);
157 fit_vaddr = (unsigned long *) convert_fw_addr(nasid, fit_paddr);
160 #endif /* SUPPORT_OLD_PROMS */
161 /* ============ END temp til old PROMs are no longer supported ============= */
164 get_fit_entry(unsigned long nasid, int index, unsigned long *fentry,
165 char *banner, int banlen)
169 ret = ia64_sn_get_fit_compt(nasid, index, fentry, banner, banlen);
171 #ifdef SUPPORT_OLD_PROMS
172 /* The following is hack is temporary until PROMs are updated */
173 if (ret == SALRET_NOT_IMPLEMENTED) {
174 unsigned long *fitadr = lookup_fit(nasid);
177 if (readq(fitadr) != FIT_SIGNATURE) {
178 printk(KERN_WARNING "Unrecognized FIT signature");
182 nentries = (unsigned int) (readq(fitadr + 1) & 0xffffff);
183 if (index >= nentries)
186 fentry[0] = readq(fitadr + 2 * index);
187 fentry[1] = readq(fitadr + 2 * index + 1);
190 if (banner && FIT_TYPE(fentry[1]) == FIT_ENTRY_SAL_A) {
191 unsigned long i, qw, *bwp, *qwp;
194 qw = fentry[0]; /* Address of SAL A */
195 if (!valid_fw_addr(qw))
198 qw += SAL_A_BANNER_OFFSET;
199 qw = convert_fw_addr(nasid, qw);
201 qw = readq(qw); /* Address of banner */
202 if (!valid_fw_addr(qw))
204 qw = convert_fw_addr(nasid, qw);
205 qwp = (unsigned long *) qw;
206 bwp = (unsigned long *) banner;
207 for (i=0; i<banlen/8; i++)
211 #endif /* SUPPORT_OLD_PROMS */
217 * These two routines display the FIT table for each node.
220 dump_fit_entry(char *page, unsigned long *fentry)
224 type = FIT_TYPE(fentry[1]);
225 return sprintf(page, "%02x %-25s %x.%02x %016lx %u\n",
228 FIT_MAJOR(fentry[1]), FIT_MINOR(fentry[1]),
230 /* mult by sixteen to get size in bytes */
231 (unsigned)(fentry[1] & 0xffffff) * 16);
236 * We assume that the fit table will be small enough that we can print
237 * the whole thing into one page. (This is true for our default 16kB
238 * pages -- each entry is about 60 chars wide when printed.) I read
239 * somewhere that the maximum size of the FIT is 128 entries, so we're
240 * OK except for 4kB pages (and no one is going to do that on SN
244 dump_fit(char *page, unsigned long nasid)
246 unsigned long fentry[2];
251 for (index=0;;index++) {
252 BUG_ON(index * 60 > PAGE_SIZE);
253 if (get_fit_entry(nasid, index, fentry, NULL, 0))
255 p += dump_fit_entry(p, fentry);
262 dump_version(char *page, unsigned long nasid)
264 unsigned long fentry[2];
269 for (index = 0; ; index++) {
270 if (get_fit_entry(nasid, index, fentry, banner,
273 if (FIT_TYPE(fentry[1]) == FIT_ENTRY_SAL_A)
277 len = sprintf(page, "%x.%02x\n", FIT_MAJOR(fentry[1]),
278 FIT_MINOR(fentry[1]));
282 len += snprintf(page, PAGE_SIZE-len, "%s\n", banner);
287 /* same as in proc_misc.c */
289 proc_calc_metrics(char *page, char **start, off_t off, int count, int *eof,
292 if (len <= off+count) *eof = 1;
295 if (len>count) len = count;
301 read_version_entry(char *page, char **start, off_t off, int count, int *eof,
306 /* data holds the NASID of the node */
307 len = dump_version(page, (unsigned long)data);
308 len = proc_calc_metrics(page, start, off, count, eof, len);
313 read_fit_entry(char *page, char **start, off_t off, int count, int *eof,
318 /* data holds the NASID of the node */
319 len = dump_fit(page, (unsigned long)data);
320 len = proc_calc_metrics(page, start, off, count, eof, len);
325 /* module entry points */
326 int __init prominfo_init(void);
327 void __exit prominfo_exit(void);
329 module_init(prominfo_init);
330 module_exit(prominfo_exit);
332 static struct proc_dir_entry **proc_entries;
333 static struct proc_dir_entry *sgi_prominfo_entry;
335 #define NODE_NAME_LEN 11
340 struct proc_dir_entry **entp;
341 struct proc_dir_entry *p;
344 char name[NODE_NAME_LEN];
346 if (!ia64_platform_is("sn2"))
349 proc_entries = kmalloc(numnodes * sizeof(struct proc_dir_entry *),
352 sgi_prominfo_entry = proc_mkdir("sgi_prominfo", NULL);
354 for (cnodeid = 0, entp = proc_entries;
357 sprintf(name, "node%d", cnodeid);
358 *entp = proc_mkdir(name, sgi_prominfo_entry);
359 nasid = cnodeid_to_nasid(cnodeid);
360 p = create_proc_read_entry(
361 "fit", 0, *entp, read_fit_entry,
364 p->owner = THIS_MODULE;
365 p = create_proc_read_entry(
366 "version", 0, *entp, read_version_entry,
369 p->owner = THIS_MODULE;
378 struct proc_dir_entry **entp;
380 char name[NODE_NAME_LEN];
382 for (cnodeid = 0, entp = proc_entries;
385 remove_proc_entry("fit", *entp);
386 remove_proc_entry("version", *entp);
387 sprintf(name, "node%d", cnodeid);
388 remove_proc_entry(name, sgi_prominfo_entry);
390 remove_proc_entry("sgi_prominfo", NULL);