Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
prominfo_proc.c
Go to the documentation of this file.
1 /*
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
4  * for more details.
5  *
6  * Copyright (C) 1999,2001-2004, 2006 Silicon Graphics, Inc. All Rights Reserved.
7  *
8  * Module to export the system's Firmware Interface Tables, including
9  * PROM revision numbers and banners, in /proc
10  */
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 #include <linux/proc_fs.h>
14 #include <linux/nodemask.h>
15 #include <asm/io.h>
16 #include <asm/sn/sn_sal.h>
17 #include <asm/sn/sn_cpuid.h>
18 #include <asm/sn/addrs.h>
19 
20 MODULE_DESCRIPTION("PROM version reporting for /proc");
21 MODULE_AUTHOR("Chad Talbott");
22 MODULE_LICENSE("GPL");
23 
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 */
39 
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)
44 
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)
49 
50 #define FIT_TYPE_SHIFT (32 + 16)
51 #define FIT_TYPE_MASK ((1 << 7) - 1)
52 
53 #define FIT_TYPE(q) \
54  ((unsigned) ((q) >> FIT_TYPE_SHIFT) & FIT_TYPE_MASK)
55 
57  unsigned char type;
58  const char *name;
59 };
60 
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"},
74  {0xff, "Error"},
75 };
76 
77 static const char *fit_type_name(unsigned char type)
78 {
79  struct fit_type_map_t const *mapp;
80 
81  for (mapp = fit_entry_types; mapp->type != 0xff; mapp++)
82  if (type == mapp->type)
83  return mapp->name;
84 
85  if ((type > FIT_ENTRY_PAL_A) && (type < FIT_ENTRY_UNUSED))
86  return "OEM type";
87  if ((type > FIT_ENTRY_PAL_B) && (type < FIT_ENTRY_PAL_A))
88  return "Reserved";
89 
90  return "Unknown type";
91 }
92 
93 static int
94 get_fit_entry(unsigned long nasid, int index, unsigned long *fentry,
95  char *banner, int banlen)
96 {
97  return ia64_sn_get_fit_compt(nasid, index, fentry, banner, banlen);
98 }
99 
100 
101 /*
102  * These two routines display the FIT table for each node.
103  */
104 static int dump_fit_entry(char *page, unsigned long *fentry)
105 {
106  unsigned type;
107 
108  type = FIT_TYPE(fentry[1]);
109  return sprintf(page, "%02x %-25s %x.%02x %016lx %u\n",
110  type,
111  fit_type_name(type),
112  FIT_MAJOR(fentry[1]), FIT_MINOR(fentry[1]),
113  fentry[0],
114  /* mult by sixteen to get size in bytes */
115  (unsigned)(fentry[1] & 0xffffff) * 16);
116 }
117 
118 
119 /*
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
125  * anyway).
126  */
127 static int
128 dump_fit(char *page, unsigned long nasid)
129 {
130  unsigned long fentry[2];
131  int index;
132  char *p;
133 
134  p = page;
135  for (index=0;;index++) {
136  BUG_ON(index * 60 > PAGE_SIZE);
137  if (get_fit_entry(nasid, index, fentry, NULL, 0))
138  break;
139  p += dump_fit_entry(p, fentry);
140  }
141 
142  return p - page;
143 }
144 
145 static int
146 dump_version(char *page, unsigned long nasid)
147 {
148  unsigned long fentry[2];
149  char banner[128];
150  int index;
151  int len;
152 
153  for (index = 0; ; index++) {
154  if (get_fit_entry(nasid, index, fentry, banner,
155  sizeof(banner)))
156  return 0;
157  if (FIT_TYPE(fentry[1]) == FIT_ENTRY_SAL_A)
158  break;
159  }
160 
161  len = sprintf(page, "%x.%02x\n", FIT_MAJOR(fentry[1]),
162  FIT_MINOR(fentry[1]));
163  page += len;
164 
165  if (banner[0])
166  len += snprintf(page, PAGE_SIZE-len, "%s\n", banner);
167 
168  return len;
169 }
170 
171 /* same as in proc_misc.c */
172 static int
173 proc_calc_metrics(char *page, char **start, off_t off, int count, int *eof,
174  int len)
175 {
176  if (len <= off + count)
177  *eof = 1;
178  *start = page + off;
179  len -= off;
180  if (len > count)
181  len = count;
182  if (len < 0)
183  len = 0;
184  return len;
185 }
186 
187 static int
188 read_version_entry(char *page, char **start, off_t off, int count, int *eof,
189  void *data)
190 {
191  int len;
192 
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);
196  return len;
197 }
198 
199 static int
200 read_fit_entry(char *page, char **start, off_t off, int count, int *eof,
201  void *data)
202 {
203  int len;
204 
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);
208 
209  return len;
210 }
211 
212 /* module entry points */
213 int __init prominfo_init(void);
214 void __exit prominfo_exit(void);
215 
218 
219 static struct proc_dir_entry **proc_entries;
220 static struct proc_dir_entry *sgi_prominfo_entry;
221 
222 #define NODE_NAME_LEN 11
223 
225 {
226  struct proc_dir_entry **entp;
227  cnodeid_t cnodeid;
228  unsigned long nasid;
229  int size;
230  char name[NODE_NAME_LEN];
231 
232  if (!ia64_platform_is("sn2"))
233  return 0;
234 
235  size = num_online_nodes() * sizeof(struct proc_dir_entry *);
236  proc_entries = kzalloc(size, GFP_KERNEL);
237  if (!proc_entries)
238  return -ENOMEM;
239 
240  sgi_prominfo_entry = proc_mkdir("sgi_prominfo", NULL);
241 
242  entp = proc_entries;
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,
248  (void *)nasid);
249  create_proc_read_entry("version", 0, *entp,
250  read_version_entry, (void *)nasid);
251  entp++;
252  }
253 
254  return 0;
255 }
256 
258 {
259  struct proc_dir_entry **entp;
260  unsigned int cnodeid;
261  char name[NODE_NAME_LEN];
262 
263  entp = proc_entries;
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);
269  entp++;
270  }
271  remove_proc_entry("sgi_prominfo", NULL);
272  kfree(proc_entries);
273 }