GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / pci / hotplug / cpqphp_sysfs.c
blob512f0b448f64c4400e77a13c309f2412e8f315fa
1 /*
2 * Compaq Hot Plug Controller Driver
4 * Copyright (C) 1995,2001 Compaq Computer Corporation
5 * Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2001 IBM Corp.
8 * All rights reserved.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
18 * NON INFRINGEMENT. See the GNU General Public License for more
19 * details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * Send feedback to <greg@kroah.com>
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/slab.h>
32 #include <linux/types.h>
33 #include <linux/proc_fs.h>
34 #include <linux/workqueue.h>
35 #include <linux/pci.h>
36 #include <linux/pci_hotplug.h>
37 #include <linux/smp_lock.h>
38 #include <linux/debugfs.h>
39 #include "cpqphp.h"
41 static int show_ctrl (struct controller *ctrl, char *buf)
43 char *out = buf;
44 int index;
45 struct pci_resource *res;
47 out += sprintf(buf, "Free resources: memory\n");
48 index = 11;
49 res = ctrl->mem_head;
50 while (res && index--) {
51 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
52 res = res->next;
54 out += sprintf(out, "Free resources: prefetchable memory\n");
55 index = 11;
56 res = ctrl->p_mem_head;
57 while (res && index--) {
58 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
59 res = res->next;
61 out += sprintf(out, "Free resources: IO\n");
62 index = 11;
63 res = ctrl->io_head;
64 while (res && index--) {
65 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
66 res = res->next;
68 out += sprintf(out, "Free resources: bus numbers\n");
69 index = 11;
70 res = ctrl->bus_head;
71 while (res && index--) {
72 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
73 res = res->next;
76 return out - buf;
79 static int show_dev (struct controller *ctrl, char *buf)
81 char * out = buf;
82 int index;
83 struct pci_resource *res;
84 struct pci_func *new_slot;
85 struct slot *slot;
87 slot = ctrl->slot;
89 while (slot) {
90 new_slot = cpqhp_slot_find(slot->bus, slot->device, 0);
91 if (!new_slot)
92 break;
93 out += sprintf(out, "assigned resources: memory\n");
94 index = 11;
95 res = new_slot->mem_head;
96 while (res && index--) {
97 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
98 res = res->next;
100 out += sprintf(out, "assigned resources: prefetchable memory\n");
101 index = 11;
102 res = new_slot->p_mem_head;
103 while (res && index--) {
104 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
105 res = res->next;
107 out += sprintf(out, "assigned resources: IO\n");
108 index = 11;
109 res = new_slot->io_head;
110 while (res && index--) {
111 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
112 res = res->next;
114 out += sprintf(out, "assigned resources: bus numbers\n");
115 index = 11;
116 res = new_slot->bus_head;
117 while (res && index--) {
118 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
119 res = res->next;
121 slot=slot->next;
124 return out - buf;
127 static int spew_debug_info(struct controller *ctrl, char *data, int size)
129 int used;
131 used = size - show_ctrl(ctrl, data);
132 used = (size - used) - show_dev(ctrl, &data[used]);
133 return used;
136 struct ctrl_dbg {
137 int size;
138 char *data;
139 struct controller *ctrl;
142 #define MAX_OUTPUT (4*PAGE_SIZE)
144 static int open(struct inode *inode, struct file *file)
146 struct controller *ctrl = inode->i_private;
147 struct ctrl_dbg *dbg;
148 int retval = -ENOMEM;
150 lock_kernel();
151 dbg = kmalloc(sizeof(*dbg), GFP_KERNEL);
152 if (!dbg)
153 goto exit;
154 dbg->data = kmalloc(MAX_OUTPUT, GFP_KERNEL);
155 if (!dbg->data) {
156 kfree(dbg);
157 goto exit;
159 dbg->size = spew_debug_info(ctrl, dbg->data, MAX_OUTPUT);
160 file->private_data = dbg;
161 retval = 0;
162 exit:
163 unlock_kernel();
164 return retval;
167 static loff_t lseek(struct file *file, loff_t off, int whence)
169 struct ctrl_dbg *dbg;
170 loff_t new = -1;
172 lock_kernel();
173 dbg = file->private_data;
175 switch (whence) {
176 case 0:
177 new = off;
178 break;
179 case 1:
180 new = file->f_pos + off;
181 break;
183 if (new < 0 || new > dbg->size) {
184 unlock_kernel();
185 return -EINVAL;
187 unlock_kernel();
188 return (file->f_pos = new);
191 static ssize_t read(struct file *file, char __user *buf,
192 size_t nbytes, loff_t *ppos)
194 struct ctrl_dbg *dbg = file->private_data;
195 return simple_read_from_buffer(buf, nbytes, ppos, dbg->data, dbg->size);
198 static int release(struct inode *inode, struct file *file)
200 struct ctrl_dbg *dbg = file->private_data;
202 kfree(dbg->data);
203 kfree(dbg);
204 return 0;
207 static const struct file_operations debug_ops = {
208 .owner = THIS_MODULE,
209 .open = open,
210 .llseek = lseek,
211 .read = read,
212 .release = release,
215 static struct dentry *root;
217 void cpqhp_initialize_debugfs(void)
219 if (!root)
220 root = debugfs_create_dir("cpqhp", NULL);
223 void cpqhp_shutdown_debugfs(void)
225 debugfs_remove(root);
228 void cpqhp_create_debugfs_files(struct controller *ctrl)
230 ctrl->dentry = debugfs_create_file(dev_name(&ctrl->pci_dev->dev),
231 S_IRUGO, root, ctrl, &debug_ops);
234 void cpqhp_remove_debugfs_files(struct controller *ctrl)
236 if (ctrl->dentry)
237 debugfs_remove(ctrl->dentry);
238 ctrl->dentry = NULL;