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-2003 Silicon Graphics, Inc. All Rights Reserved.
8 * Module to export the system's Firmware Interface Tables, including
9 * PROM revision numbers, 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/sn2/addrs.h>
18 #include <asm/sn/simulator.h>
20 /* to lookup nasids */
21 #include <asm/sn/sn_cpuid.h>
23 MODULE_DESCRIPTION("PROM version reporting for /proc");
24 MODULE_AUTHOR("Chad Talbott");
25 MODULE_LICENSE("GPL");
29 #define TRACE_PROMINFO
31 #if defined(DEBUG_PROMINFO)
32 # define DPRINTK(x...) printk(KERN_DEBUG x)
34 # define DPRINTK(x...)
37 #if defined(TRACE_PROMINFO) && defined(DEBUG_PROMINFO)
38 # if defined(__GNUC__)
39 # define TRACE() printk(KERN_DEBUG "%s:%d:%s\n", \
40 __FILE__, __LINE__, __FUNCTION__)
42 # define TRACE() printk(KERN_DEBUG "%s:%d\n", __LINE__, __FILE__)
48 /* Sub-regions determined by bits in Node Offset */
49 #define LB_PROM_SPACE 0x0000000700000000ul /* Local LB PROM */
51 #define FIT_SIGNATURE 0x2020205f5449465ful
52 /* Standard Intel FIT entry types */
53 #define FIT_ENTRY_FIT_HEADER 0x00 /* FIT header entry */
54 #define FIT_ENTRY_PAL_B 0x01 /* PAL_B entry */
55 /* Entries 0x02 through 0x0D reserved by Intel */
56 #define FIT_ENTRY_PAL_A_PROC 0x0E /* Processor-specific PAL_A entry */
57 #define FIT_ENTRY_PAL_A 0x0F /* PAL_A entry, same as... */
58 #define FIT_ENTRY_PAL_A_GEN 0x0F /* ...Generic PAL_A entry */
59 #define FIT_ENTRY_UNUSED 0x7F /* Unused (reserved by Intel?) */
60 /* OEM-defined entries range from 0x10 to 0x7E. */
61 #define FIT_ENTRY_SAL_A 0x10 /* SAL_A entry */
62 #define FIT_ENTRY_SAL_B 0x11 /* SAL_B entry */
63 #define FIT_ENTRY_SALRUNTIME 0x12 /* SAL runtime entry */
64 #define FIT_ENTRY_EFI 0x1F /* EFI entry */
65 #define FIT_ENTRY_FPSWA 0x20 /* embedded fpswa entry */
66 #define FIT_ENTRY_VMLINUX 0x21 /* embedded vmlinux entry */
68 #define FIT_MAJOR_SHIFT (32 + 8)
69 #define FIT_MAJOR_MASK ((1 << 8) - 1)
70 #define FIT_MINOR_SHIFT 32
71 #define FIT_MINOR_MASK ((1 << 8) - 1)
73 #define FIT_MAJOR(q) \
74 ((unsigned) ((q) >> FIT_MAJOR_SHIFT) & FIT_MAJOR_MASK)
75 #define FIT_MINOR(q) \
76 ((unsigned) ((q) >> FIT_MINOR_SHIFT) & FIT_MINOR_MASK)
78 #define FIT_TYPE_SHIFT (32 + 16)
79 #define FIT_TYPE_MASK ((1 << 7) - 1)
82 ((unsigned) ((q) >> FIT_TYPE_SHIFT) & FIT_TYPE_MASK)
84 #define FIT_ENTRY(type, maj, min, size) \
85 ((((unsigned long)(maj) & FIT_MAJOR_MASK) << FIT_MAJOR_SHIFT) | \
86 (((unsigned long)(min) & FIT_MINOR_MASK) << FIT_MINOR_SHIFT) | \
87 (((unsigned long)(type) & FIT_TYPE_MASK) << FIT_TYPE_SHIFT) | \
90 struct fit_type_map_t {
95 static const struct fit_type_map_t fit_entry_types[] = {
96 { FIT_ENTRY_FIT_HEADER, "FIT Header" },
97 { FIT_ENTRY_PAL_A_GEN, "Generic PAL_A" },
98 { FIT_ENTRY_PAL_A_PROC, "Processor-specific PAL_A" },
99 { FIT_ENTRY_PAL_A, "PAL_A" },
100 { FIT_ENTRY_PAL_B, "PAL_B" },
101 { FIT_ENTRY_SAL_A, "SAL_A" },
102 { FIT_ENTRY_SAL_B, "SAL_B" },
103 { FIT_ENTRY_SALRUNTIME, "SAL runtime" },
104 { FIT_ENTRY_EFI, "EFI" },
105 { FIT_ENTRY_VMLINUX, "Embedded Linux" },
106 { FIT_ENTRY_FPSWA, "Embedded FPSWA" },
107 { FIT_ENTRY_UNUSED, "Unused" },
112 fit_type_name(unsigned char type)
114 struct fit_type_map_t const*mapp;
116 for (mapp = fit_entry_types; mapp->type != 0xff; mapp++)
117 if (type == mapp->type)
120 if ((type > FIT_ENTRY_PAL_A) && (type < FIT_ENTRY_UNUSED))
122 if ((type > FIT_ENTRY_PAL_B) && (type < FIT_ENTRY_PAL_A))
125 return "Unknown type";
128 /* These two routines read the FIT table directly from the FLASH PROM
129 * on a specific node. The PROM can only be accessed using aligned 64
130 * bit reads, so we do that and then shift and mask the result to get
134 dump_fit_entry(char *page, unsigned long *fentry)
136 unsigned long q1, q2;
142 q2 = readq(fentry + 1);
144 return sprintf(page, "%02x %-25s %x.%02x %016lx %u\n",
147 FIT_MAJOR(q2), FIT_MINOR(q2),
149 /* mult by sixteen to get size in bytes */
153 /* We assume that the fit table will be small enough that we can print
154 * the whole thing into one page. (This is true for our default 16kB
155 * pages -- each entry is about 60 chars wide when printed.) I read
156 * somewhere that the maximum size of the FIT is 128 entries, so we're
157 * OK except for 4kB pages (and no one is going to do that on SN
161 dump_fit(char *page, unsigned long *fit)
170 DPRINTK("dumping fit from %p\n", (void *)fit);
173 DPRINTK("FIT signature: %016lx (%.8s)\n", qw, (char *)&qw);
174 if (qw != FIT_SIGNATURE)
175 printk(KERN_WARNING "Unrecognized FIT signature");
178 nentries = (unsigned)qw;
179 DPRINTK("number of fit entries: %u\n", nentries);
180 /* check that we won't overflow the page -- see comment above */
181 BUG_ON(nentries * 60 > PAGE_SIZE);
184 for (fentry = 0; fentry < nentries; fentry++)
185 /* each FIT entry is two 64 bit words */
186 p += dump_fit_entry(p, fit + 2 * fentry);
192 dump_version(char *page, unsigned long *fit)
200 nentries = (unsigned)readq(fit + 1);
201 BUG_ON(nentries * 60 > PAGE_SIZE);
203 for (fentry = 0; fentry < nentries; fentry++) {
204 qw = readq(fit + 2 * fentry + 1);
205 if (FIT_TYPE(qw) == FIT_ENTRY_SAL_A)
206 return sprintf(page, "%x.%02x\n",
207 FIT_MAJOR(qw), FIT_MINOR(qw));
212 /* same as in proc_misc.c */
214 proc_calc_metrics(char *page, char **start, off_t off, int count, int *eof,
217 if (len <= off+count) *eof = 1;
220 if (len>count) len = count;
226 read_version_entry(char *page, char **start, off_t off, int count, int *eof,
231 /* data holds the pointer to this node's FIT */
232 len = dump_version(page, (unsigned long *)data);
233 len = proc_calc_metrics(page, start, off, count, eof, len);
238 read_fit_entry(char *page, char **start, off_t off, int count, int *eof,
243 /* data holds the pointer to this node's FIT */
244 len = dump_fit(page, (unsigned long *)data);
245 len = proc_calc_metrics(page, start, off, count, eof, len);
250 /* this is a fake FIT that's used on the medusa simulator which
251 * doesn't usually run a complete PROM.
253 #ifdef CONFIG_IA64_SGI_SN_SIM
254 static unsigned long fakefit[] = {
255 /* this is all we need to satisfy the code below */
257 FIT_ENTRY(FIT_ENTRY_FIT_HEADER, 0x02, 0x60, 2),
258 /* dump something arbitrary for
259 * /proc/sgi_prominfo/nodeX/version */
260 0xbadbeef00fa3ef17ul,
261 FIT_ENTRY(FIT_ENTRY_SAL_A, 0, 0x99, 0x100)
265 static unsigned long *
266 lookup_fit(int nasid)
269 unsigned long fit_paddr;
270 unsigned long *fit_vaddr;
272 #ifdef CONFIG_IA64_SGI_SN_SIM
273 if (IS_RUNNING_ON_SIMULATOR())
277 fitp = (void *)GLOBAL_MMR_ADDR(nasid, LB_PROM_SPACE - 32);
278 DPRINTK("pointer to fit at %p\n", (void *)fitp);
279 fit_paddr = readq(fitp);
280 DPRINTK("fit pointer contains %lx\n", fit_paddr);
281 /* snag just the node-relative offset */
282 fit_paddr &= ~0ul >> (63-35);
283 /* the pointer to the FIT is relative to IA-64 compatibility
284 * space. However, the PROM is mapped at a different offset
285 * in MMR space (both local and global)
287 fit_paddr += 0x700000000;
288 fit_vaddr = (void *)GLOBAL_MMR_ADDR(nasid, fit_paddr);
289 DPRINTK("fit at %p\n", (void *)fit_vaddr);
293 /* module entry points */
294 int __init prominfo_init(void);
295 void __exit prominfo_exit(void);
297 module_init(prominfo_init);
298 module_exit(prominfo_exit);
300 static struct proc_dir_entry **proc_entries;
301 static struct proc_dir_entry *sgi_prominfo_entry;
303 #define NODE_NAME_LEN 11
308 struct proc_dir_entry **entp;
309 struct proc_dir_entry *p;
312 char name[NODE_NAME_LEN];
314 if (!ia64_platform_is("sn2"))
319 DPRINTK("running on cpu %d\n", smp_processor_id());
320 DPRINTK("numnodes %d\n", numnodes);
322 proc_entries = kmalloc(numnodes * sizeof(struct proc_dir_entry *),
325 sgi_prominfo_entry = proc_mkdir("sgi_prominfo", NULL);
327 for (cnodeid = 0, entp = proc_entries;
330 sprintf(name, "node%d", cnodeid);
331 *entp = proc_mkdir(name, sgi_prominfo_entry);
332 nasid = cnodeid_to_nasid(cnodeid);
333 p = create_proc_read_entry(
334 "fit", 0, *entp, read_fit_entry,
337 p->owner = THIS_MODULE;
338 p = create_proc_read_entry(
339 "version", 0, *entp, read_version_entry,
342 p->owner = THIS_MODULE;
351 struct proc_dir_entry **entp;
353 char name[NODE_NAME_LEN];
357 for (cnodeid = 0, entp = proc_entries;
360 remove_proc_entry("fit", *entp);
361 remove_proc_entry("version", *entp);
362 sprintf(name, "node%d", cnodeid);
363 remove_proc_entry(name, sgi_prominfo_entry);
365 remove_proc_entry("sgi_prominfo", NULL);