Path: blob/master/arch/ia64/sn/kernel/sn2/prominfo_proc.c
17604 views
/*1* This file is subject to the terms and conditions of the GNU General Public2* License. See the file "COPYING" in the main directory of this archive3* for more details.4*5* Copyright (C) 1999,2001-2004, 2006 Silicon Graphics, Inc. All Rights Reserved.6*7* Module to export the system's Firmware Interface Tables, including8* PROM revision numbers and banners, in /proc9*/10#include <linux/module.h>11#include <linux/slab.h>12#include <linux/proc_fs.h>13#include <linux/nodemask.h>14#include <asm/system.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>1920MODULE_DESCRIPTION("PROM version reporting for /proc");21MODULE_AUTHOR("Chad Talbott");22MODULE_LICENSE("GPL");2324/* 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 */3940#define FIT_MAJOR_SHIFT (32 + 8)41#define FIT_MAJOR_MASK ((1 << 8) - 1)42#define FIT_MINOR_SHIFT 3243#define FIT_MINOR_MASK ((1 << 8) - 1)4445#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)4950#define FIT_TYPE_SHIFT (32 + 16)51#define FIT_TYPE_MASK ((1 << 7) - 1)5253#define FIT_TYPE(q) \54((unsigned) ((q) >> FIT_TYPE_SHIFT) & FIT_TYPE_MASK)5556struct fit_type_map_t {57unsigned char type;58const char *name;59};6061static 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};7677static const char *fit_type_name(unsigned char type)78{79struct fit_type_map_t const *mapp;8081for (mapp = fit_entry_types; mapp->type != 0xff; mapp++)82if (type == mapp->type)83return mapp->name;8485if ((type > FIT_ENTRY_PAL_A) && (type < FIT_ENTRY_UNUSED))86return "OEM type";87if ((type > FIT_ENTRY_PAL_B) && (type < FIT_ENTRY_PAL_A))88return "Reserved";8990return "Unknown type";91}9293static int94get_fit_entry(unsigned long nasid, int index, unsigned long *fentry,95char *banner, int banlen)96{97return ia64_sn_get_fit_compt(nasid, index, fentry, banner, banlen);98}99100101/*102* These two routines display the FIT table for each node.103*/104static int dump_fit_entry(char *page, unsigned long *fentry)105{106unsigned type;107108type = FIT_TYPE(fentry[1]);109return sprintf(page, "%02x %-25s %x.%02x %016lx %u\n",110type,111fit_type_name(type),112FIT_MAJOR(fentry[1]), FIT_MINOR(fentry[1]),113fentry[0],114/* mult by sixteen to get size in bytes */115(unsigned)(fentry[1] & 0xffffff) * 16);116}117118119/*120* We assume that the fit table will be small enough that we can print121* the whole thing into one page. (This is true for our default 16kB122* pages -- each entry is about 60 chars wide when printed.) I read123* somewhere that the maximum size of the FIT is 128 entries, so we're124* OK except for 4kB pages (and no one is going to do that on SN125* anyway).126*/127static int128dump_fit(char *page, unsigned long nasid)129{130unsigned long fentry[2];131int index;132char *p;133134p = page;135for (index=0;;index++) {136BUG_ON(index * 60 > PAGE_SIZE);137if (get_fit_entry(nasid, index, fentry, NULL, 0))138break;139p += dump_fit_entry(p, fentry);140}141142return p - page;143}144145static int146dump_version(char *page, unsigned long nasid)147{148unsigned long fentry[2];149char banner[128];150int index;151int len;152153for (index = 0; ; index++) {154if (get_fit_entry(nasid, index, fentry, banner,155sizeof(banner)))156return 0;157if (FIT_TYPE(fentry[1]) == FIT_ENTRY_SAL_A)158break;159}160161len = sprintf(page, "%x.%02x\n", FIT_MAJOR(fentry[1]),162FIT_MINOR(fentry[1]));163page += len;164165if (banner[0])166len += snprintf(page, PAGE_SIZE-len, "%s\n", banner);167168return len;169}170171/* same as in proc_misc.c */172static int173proc_calc_metrics(char *page, char **start, off_t off, int count, int *eof,174int len)175{176if (len <= off + count)177*eof = 1;178*start = page + off;179len -= off;180if (len > count)181len = count;182if (len < 0)183len = 0;184return len;185}186187static int188read_version_entry(char *page, char **start, off_t off, int count, int *eof,189void *data)190{191int len;192193/* data holds the NASID of the node */194len = dump_version(page, (unsigned long)data);195len = proc_calc_metrics(page, start, off, count, eof, len);196return len;197}198199static int200read_fit_entry(char *page, char **start, off_t off, int count, int *eof,201void *data)202{203int len;204205/* data holds the NASID of the node */206len = dump_fit(page, (unsigned long)data);207len = proc_calc_metrics(page, start, off, count, eof, len);208209return len;210}211212/* module entry points */213int __init prominfo_init(void);214void __exit prominfo_exit(void);215216module_init(prominfo_init);217module_exit(prominfo_exit);218219static struct proc_dir_entry **proc_entries;220static struct proc_dir_entry *sgi_prominfo_entry;221222#define NODE_NAME_LEN 11223224int __init prominfo_init(void)225{226struct proc_dir_entry **entp;227cnodeid_t cnodeid;228unsigned long nasid;229int size;230char name[NODE_NAME_LEN];231232if (!ia64_platform_is("sn2"))233return 0;234235size = num_online_nodes() * sizeof(struct proc_dir_entry *);236proc_entries = kzalloc(size, GFP_KERNEL);237if (!proc_entries)238return -ENOMEM;239240sgi_prominfo_entry = proc_mkdir("sgi_prominfo", NULL);241242entp = proc_entries;243for_each_online_node(cnodeid) {244sprintf(name, "node%d", cnodeid);245*entp = proc_mkdir(name, sgi_prominfo_entry);246nasid = cnodeid_to_nasid(cnodeid);247create_proc_read_entry("fit", 0, *entp, read_fit_entry,248(void *)nasid);249create_proc_read_entry("version", 0, *entp,250read_version_entry, (void *)nasid);251entp++;252}253254return 0;255}256257void __exit prominfo_exit(void)258{259struct proc_dir_entry **entp;260unsigned int cnodeid;261char name[NODE_NAME_LEN];262263entp = proc_entries;264for_each_online_node(cnodeid) {265remove_proc_entry("fit", *entp);266remove_proc_entry("version", *entp);267sprintf(name, "node%d", cnodeid);268remove_proc_entry(name, sgi_prominfo_entry);269entp++;270}271remove_proc_entry("sgi_prominfo", NULL);272kfree(proc_entries);273}274275276