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>
16 #include <asm/sn/simulator.h>
18 /* to lookup nasids */
19 #include <asm/sn/sn_cpuid.h>
21 MODULE_DESCRIPTION("PROM version reporting for /proc");
22 MODULE_AUTHOR("Chad Talbott");
23 MODULE_LICENSE("GPL");
27 #define TRACE_PROMINFO
29 #if defined(DEBUG_PROMINFO)
30 # define DPRINTK(x...) printk(KERN_DEBUG x)
32 # define DPRINTK(x...)
35 #if defined(TRACE_PROMINFO) && defined(DEBUG_PROMINFO)
36 # if defined(__GNUC__)
37 # define TRACE() printk(KERN_DEBUG "%s:%d:%s\n", \
38 __FILE__, __LINE__, __FUNCTION__)
40 # define TRACE() printk(KERN_DEBUG "%s:%d\n", __LINE__, __FILE__)
46 /* Sub-regions determined by bits in Node Offset */
47 #define LB_PROM_SPACE 0x0000000700000000ul /* Local LB PROM */
49 #define FIT_SIGNATURE 0x2020205f5449465ful
50 /* Standard Intel FIT entry types */
51 #define FIT_ENTRY_FIT_HEADER 0x00 /* FIT header entry */
52 #define FIT_ENTRY_PAL_B 0x01 /* PAL_B entry */
53 /* Entries 0x02 through 0x0D reserved by Intel */
54 #define FIT_ENTRY_PAL_A_PROC 0x0E /* Processor-specific PAL_A entry */
55 #define FIT_ENTRY_PAL_A 0x0F /* PAL_A entry, same as... */
56 #define FIT_ENTRY_PAL_A_GEN 0x0F /* ...Generic PAL_A entry */
57 #define FIT_ENTRY_UNUSED 0x7F /* Unused (reserved by Intel?) */
58 /* OEM-defined entries range from 0x10 to 0x7E. */
59 #define FIT_ENTRY_SAL_A 0x10 /* SAL_A entry */
60 #define FIT_ENTRY_SAL_B 0x11 /* SAL_B entry */
61 #define FIT_ENTRY_SALRUNTIME 0x12 /* SAL runtime entry */
62 #define FIT_ENTRY_EFI 0x1F /* EFI entry */
63 #define FIT_ENTRY_FPSWA 0x20 /* embedded fpswa entry */
64 #define FIT_ENTRY_VMLINUX 0x21 /* embedded vmlinux entry */
66 #define FIT_MAJOR_SHIFT (32 + 8)
67 #define FIT_MAJOR_MASK ((1 << 8) - 1)
68 #define FIT_MINOR_SHIFT 32
69 #define FIT_MINOR_MASK ((1 << 8) - 1)
71 #define FIT_MAJOR(q) \
72 ((unsigned) ((q) >> FIT_MAJOR_SHIFT) & FIT_MAJOR_MASK)
73 #define FIT_MINOR(q) \
74 ((unsigned) ((q) >> FIT_MINOR_SHIFT) & FIT_MINOR_MASK)
76 #define FIT_TYPE_SHIFT (32 + 16)
77 #define FIT_TYPE_MASK ((1 << 7) - 1)
80 ((unsigned) ((q) >> FIT_TYPE_SHIFT) & FIT_TYPE_MASK)
82 #define FIT_ENTRY(type, maj, min, size) \
83 ((((unsigned long)(maj) & FIT_MAJOR_MASK) << FIT_MAJOR_SHIFT) | \
84 (((unsigned long)(min) & FIT_MINOR_MASK) << FIT_MINOR_SHIFT) | \
85 (((unsigned long)(type) & FIT_TYPE_MASK) << FIT_TYPE_SHIFT) | \
88 struct fit_type_map_t {
93 static const struct fit_type_map_t fit_entry_types[] = {
94 { FIT_ENTRY_FIT_HEADER, "FIT Header" },
95 { FIT_ENTRY_PAL_A_GEN, "Generic PAL_A" },
96 { FIT_ENTRY_PAL_A_PROC, "Processor-specific PAL_A" },
97 { FIT_ENTRY_PAL_A, "PAL_A" },
98 { FIT_ENTRY_PAL_B, "PAL_B" },
99 { FIT_ENTRY_SAL_A, "SAL_A" },
100 { FIT_ENTRY_SAL_B, "SAL_B" },
101 { FIT_ENTRY_SALRUNTIME, "SAL runtime" },
102 { FIT_ENTRY_EFI, "EFI" },
103 { FIT_ENTRY_VMLINUX, "Embedded Linux" },
104 { FIT_ENTRY_FPSWA, "Embedded FPSWA" },
105 { FIT_ENTRY_UNUSED, "Unused" },
110 fit_type_name(unsigned char type)
112 struct fit_type_map_t const*mapp;
114 for (mapp = fit_entry_types; mapp->type != 0xff; mapp++)
115 if (type == mapp->type)
118 if ((type > FIT_ENTRY_PAL_A) && (type < FIT_ENTRY_UNUSED))
120 if ((type > FIT_ENTRY_PAL_B) && (type < FIT_ENTRY_PAL_A))
123 return "Unknown type";
126 /* These two routines read the FIT table directly from the FLASH PROM
127 * on a specific node. The PROM can only be accessed using aligned 64
128 * bit reads, so we do that and then shift and mask the result to get
132 dump_fit_entry(char *page, unsigned long *fentry)
134 unsigned long q1, q2;
140 q2 = readq(fentry + 1);
142 return sprintf(page, "%02x %-25s %x.%02x %016lx %u\n",
145 FIT_MAJOR(q2), FIT_MINOR(q2),
147 /* mult by sixteen to get size in bytes */
151 /* We assume that the fit table will be small enough that we can print
152 * the whole thing into one page. (This is true for our default 16kB
153 * pages -- each entry is about 60 chars wide when printed.) I read
154 * somewhere that the maximum size of the FIT is 128 entries, so we're
155 * OK except for 4kB pages (and no one is going to do that on SN
159 dump_fit(char *page, unsigned long *fit)
168 DPRINTK("dumping fit from %p\n", (void *)fit);
171 DPRINTK("FIT signature: %016lx (%.8s)\n", qw, (char *)&qw);
172 if (qw != FIT_SIGNATURE)
173 printk(KERN_WARNING "Unrecognized FIT signature");
176 nentries = (unsigned)qw;
177 DPRINTK("number of fit entries: %u\n", nentries);
178 /* check that we won't overflow the page -- see comment above */
179 BUG_ON(nentries * 60 > PAGE_SIZE);
182 for (fentry = 0; fentry < nentries; fentry++)
183 /* each FIT entry is two 64 bit words */
184 p += dump_fit_entry(p, fit + 2 * fentry);
190 dump_version(char *page, unsigned long *fit)
198 nentries = (unsigned)readq(fit + 1);
199 BUG_ON(nentries * 60 > PAGE_SIZE);
201 for (fentry = 0; fentry < nentries; fentry++) {
202 qw = readq(fit + 2 * fentry + 1);
203 if (FIT_TYPE(qw) == FIT_ENTRY_SAL_A)
204 return sprintf(page, "%x.%02x\n",
205 FIT_MAJOR(qw), FIT_MINOR(qw));
210 /* same as in proc_misc.c */
212 proc_calc_metrics(char *page, char **start, off_t off, int count, int *eof,
215 if (len <= off+count) *eof = 1;
218 if (len>count) len = count;
224 read_version_entry(char *page, char **start, off_t off, int count, int *eof,
230 /* data holds the pointer to this node's FIT */
231 len = dump_version(page, (unsigned long *)data);
232 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,
244 /* data holds the pointer to this node's FIT */
245 len = dump_fit(page, (unsigned long *)data);
246 len = proc_calc_metrics(page, start, off, count, eof, len);
252 /* this is a fake FIT that's used on the medusa simulator which
253 * doesn't usually run a complete PROM.
255 #ifdef CONFIG_IA64_SGI_SN_SIM
256 static unsigned long fakefit[] = {
257 /* this is all we need to satisfy the code below */
259 FIT_ENTRY(FIT_ENTRY_FIT_HEADER, 0x02, 0x60, 2),
260 /* dump something arbitrary for
261 * /proc/sgi_prominfo/nodeX/version */
262 0xbadbeef00fa3ef17ul,
263 FIT_ENTRY(FIT_ENTRY_SAL_A, 0, 0x99, 0x100)
267 static unsigned long *
268 lookup_fit(int nasid)
271 unsigned long fit_paddr;
272 unsigned long *fit_vaddr;
274 #ifdef CONFIG_IA64_SGI_SN_SIM
275 if (IS_RUNNING_ON_SIMULATOR())
279 fitp = (void *)GLOBAL_MMR_ADDR(nasid, LB_PROM_SPACE - 32);
280 DPRINTK("pointer to fit at %p\n", (void *)fitp);
281 fit_paddr = readq(fitp);
282 DPRINTK("fit pointer contains %lx\n", fit_paddr);
283 /* snag just the node-relative offset */
284 fit_paddr &= ~0ul >> (63-35);
285 /* the pointer to the FIT is relative to IA-64 compatibility
286 * space. However, the PROM is mapped at a different offset
287 * in MMR space (both local and global)
289 fit_paddr += 0x700000000;
290 fit_vaddr = (void *)GLOBAL_MMR_ADDR(nasid, fit_paddr);
291 DPRINTK("fit at %p\n", (void *)fit_vaddr);
295 /* module entry points */
296 int __init prominfo_init(void);
297 void __exit prominfo_exit(void);
299 module_init(prominfo_init);
300 module_exit(prominfo_exit);
302 static struct proc_dir_entry **proc_entries;
303 static struct proc_dir_entry *sgi_prominfo_entry;
305 #define NODE_NAME_LEN 11
310 struct proc_dir_entry **entp;
313 char name[NODE_NAME_LEN];
317 DPRINTK("running on cpu %d\n", smp_processor_id());
318 DPRINTK("numnodes %d\n", numnodes);
320 proc_entries = kmalloc(numnodes * sizeof(struct proc_dir_entry *),
323 sgi_prominfo_entry = proc_mkdir("sgi_prominfo", NULL);
325 for (cnodeid = 0, entp = proc_entries;
328 sprintf(name, "node%d", cnodeid);
329 *entp = proc_mkdir(name, sgi_prominfo_entry);
330 nasid = cnodeid_to_nasid(cnodeid);
331 create_proc_read_entry(
332 "fit", 0, *entp, read_fit_entry,
334 create_proc_read_entry(
335 "version", 0, *entp, read_version_entry,
345 struct proc_dir_entry **entp;
347 char name[NODE_NAME_LEN];
351 for (cnodeid = 0, entp = proc_entries;
354 remove_proc_entry("fit", *entp);
355 remove_proc_entry("version", *entp);
356 sprintf(name, "node%d", cnodeid);
357 remove_proc_entry(name, sgi_prominfo_entry);
359 remove_proc_entry("sgi_prominfo", NULL);