Pull novell-bugzilla-156426 into release branch
[pandora-kernel.git] / arch / ia64 / sn / kernel / sn2 / sn_proc_fs.c
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) 2000-2005 Silicon Graphics, Inc. All rights reserved.
7  */
8 #include <linux/config.h>
9
10 #ifdef CONFIG_PROC_FS
11 #include <linux/proc_fs.h>
12 #include <linux/seq_file.h>
13 #include <asm/uaccess.h>
14 #include <asm/sn/sn_sal.h>
15
16 static int partition_id_show(struct seq_file *s, void *p)
17 {
18         seq_printf(s, "%d\n", sn_partition_id);
19         return 0;
20 }
21
22 static int partition_id_open(struct inode *inode, struct file *file)
23 {
24         return single_open(file, partition_id_show, NULL);
25 }
26
27 static int system_serial_number_show(struct seq_file *s, void *p)
28 {
29         seq_printf(s, "%s\n", sn_system_serial_number());
30         return 0;
31 }
32
33 static int system_serial_number_open(struct inode *inode, struct file *file)
34 {
35         return single_open(file, system_serial_number_show, NULL);
36 }
37
38 static int licenseID_show(struct seq_file *s, void *p)
39 {
40         seq_printf(s, "0x%lx\n", sn_partition_serial_number_val());
41         return 0;
42 }
43
44 static int licenseID_open(struct inode *inode, struct file *file)
45 {
46         return single_open(file, licenseID_show, NULL);
47 }
48
49 /*
50  * Enable forced interrupt by default.
51  * When set, the sn interrupt handler writes the force interrupt register on
52  * the bridge chip.  The hardware will then send an interrupt message if the
53  * interrupt line is active.  This mimics a level sensitive interrupt.
54  */
55 extern int sn_force_interrupt_flag;
56
57 static int sn_force_interrupt_show(struct seq_file *s, void *p)
58 {
59         seq_printf(s, "Force interrupt is %s\n",
60                 sn_force_interrupt_flag ? "enabled" : "disabled");
61         return 0;
62 }
63
64 static ssize_t sn_force_interrupt_write_proc(struct file *file,
65                 const char __user *buffer, size_t count, loff_t *data)
66 {
67         char val;
68
69         if (copy_from_user(&val, buffer, 1))
70                 return -EFAULT;
71
72         sn_force_interrupt_flag = (val == '0') ? 0 : 1;
73         return count;
74 }
75
76 static int sn_force_interrupt_open(struct inode *inode, struct file *file)
77 {
78         return single_open(file, sn_force_interrupt_show, NULL);
79 }
80
81 static int coherence_id_show(struct seq_file *s, void *p)
82 {
83         seq_printf(s, "%d\n", partition_coherence_id());
84
85         return 0;
86 }
87
88 static int coherence_id_open(struct inode *inode, struct file *file)
89 {
90         return single_open(file, coherence_id_show, NULL);
91 }
92
93 static struct proc_dir_entry
94 *sn_procfs_create_entry(const char *name, struct proc_dir_entry *parent,
95                         int (*openfunc)(struct inode *, struct file *),
96         int (*releasefunc)(struct inode *, struct file *),
97         ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *))
98 {
99         struct proc_dir_entry *e = create_proc_entry(name, 0444, parent);
100
101         if (e) {
102                 struct file_operations *f;
103
104                 f = kzalloc(sizeof(*f), GFP_KERNEL);
105                 if (f) {
106                         f->open = openfunc;
107                         f->read = seq_read;
108                         f->llseek = seq_lseek;
109                         f->release = releasefunc;
110                         f->write = write;
111                         e->proc_fops = f;
112                 }
113         }
114
115         return e;
116 }
117
118 /* /proc/sgi_sn/sn_topology uses seq_file, see sn_hwperf.c */
119 extern int sn_topology_open(struct inode *, struct file *);
120 extern int sn_topology_release(struct inode *, struct file *);
121
122 void register_sn_procfs(void)
123 {
124         static struct proc_dir_entry *sgi_proc_dir = NULL;
125
126         BUG_ON(sgi_proc_dir != NULL);
127         if (!(sgi_proc_dir = proc_mkdir("sgi_sn", NULL)))
128                 return;
129
130         sn_procfs_create_entry("partition_id", sgi_proc_dir,
131                 partition_id_open, single_release, NULL);
132
133         sn_procfs_create_entry("system_serial_number", sgi_proc_dir,
134                 system_serial_number_open, single_release, NULL);
135
136         sn_procfs_create_entry("licenseID", sgi_proc_dir, 
137                 licenseID_open, single_release, NULL);
138
139         sn_procfs_create_entry("sn_force_interrupt", sgi_proc_dir,
140                 sn_force_interrupt_open, single_release,
141                 sn_force_interrupt_write_proc);
142
143         sn_procfs_create_entry("coherence_id", sgi_proc_dir, 
144                 coherence_id_open, single_release, NULL);
145         
146         sn_procfs_create_entry("sn_topology", sgi_proc_dir,
147                 sn_topology_open, sn_topology_release, NULL);
148 }
149
150 #endif /* CONFIG_PROC_FS */