MIB: add struct net to UDP6_INC_STATS_BH
[linux/fpc-iii.git] / drivers / pci / hotplug / cpqphp_sysfs.c
bloba13abf55d7844adba846c7c99c2e23d376e05fec
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/types.h>
32 #include <linux/proc_fs.h>
33 #include <linux/workqueue.h>
34 #include <linux/pci.h>
35 #include <linux/pci_hotplug.h>
36 #include <linux/debugfs.h>
37 #include "cpqphp.h"
39 static int show_ctrl (struct controller *ctrl, char *buf)
41 char *out = buf;
42 int index;
43 struct pci_resource *res;
45 out += sprintf(buf, "Free resources: memory\n");
46 index = 11;
47 res = ctrl->mem_head;
48 while (res && index--) {
49 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
50 res = res->next;
52 out += sprintf(out, "Free resources: prefetchable memory\n");
53 index = 11;
54 res = ctrl->p_mem_head;
55 while (res && index--) {
56 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
57 res = res->next;
59 out += sprintf(out, "Free resources: IO\n");
60 index = 11;
61 res = ctrl->io_head;
62 while (res && index--) {
63 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
64 res = res->next;
66 out += sprintf(out, "Free resources: bus numbers\n");
67 index = 11;
68 res = ctrl->bus_head;
69 while (res && index--) {
70 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
71 res = res->next;
74 return out - buf;
77 static int show_dev (struct controller *ctrl, char *buf)
79 char * out = buf;
80 int index;
81 struct pci_resource *res;
82 struct pci_func *new_slot;
83 struct slot *slot;
85 slot = ctrl->slot;
87 while (slot) {
88 new_slot = cpqhp_slot_find(slot->bus, slot->device, 0);
89 if (!new_slot)
90 break;
91 out += sprintf(out, "assigned resources: memory\n");
92 index = 11;
93 res = new_slot->mem_head;
94 while (res && index--) {
95 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
96 res = res->next;
98 out += sprintf(out, "assigned resources: prefetchable memory\n");
99 index = 11;
100 res = new_slot->p_mem_head;
101 while (res && index--) {
102 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
103 res = res->next;
105 out += sprintf(out, "assigned resources: IO\n");
106 index = 11;
107 res = new_slot->io_head;
108 while (res && index--) {
109 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
110 res = res->next;
112 out += sprintf(out, "assigned resources: bus numbers\n");
113 index = 11;
114 res = new_slot->bus_head;
115 while (res && index--) {
116 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
117 res = res->next;
119 slot=slot->next;
122 return out - buf;
125 static int spew_debug_info(struct controller *ctrl, char *data, int size)
127 int used;
129 used = size - show_ctrl(ctrl, data);
130 used = (size - used) - show_dev(ctrl, &data[used]);
131 return used;
134 struct ctrl_dbg {
135 int size;
136 char *data;
137 struct controller *ctrl;
140 #define MAX_OUTPUT (4*PAGE_SIZE)
142 static int open(struct inode *inode, struct file *file)
144 struct controller *ctrl = inode->i_private;
145 struct ctrl_dbg *dbg;
146 int retval = -ENOMEM;
148 lock_kernel();
149 dbg = kmalloc(sizeof(*dbg), GFP_KERNEL);
150 if (!dbg)
151 goto exit;
152 dbg->data = kmalloc(MAX_OUTPUT, GFP_KERNEL);
153 if (!dbg->data) {
154 kfree(dbg);
155 goto exit;
157 dbg->size = spew_debug_info(ctrl, dbg->data, MAX_OUTPUT);
158 file->private_data = dbg;
159 retval = 0;
160 exit:
161 unlock_kernel();
162 return retval;
165 static loff_t lseek(struct file *file, loff_t off, int whence)
167 struct ctrl_dbg *dbg;
168 loff_t new = -1;
170 lock_kernel();
171 dbg = file->private_data;
173 switch (whence) {
174 case 0:
175 new = off;
176 break;
177 case 1:
178 new = file->f_pos + off;
179 break;
181 if (new < 0 || new > dbg->size) {
182 unlock_kernel();
183 return -EINVAL;
185 unlock_kernel();
186 return (file->f_pos = new);
189 static ssize_t read(struct file *file, char __user *buf,
190 size_t nbytes, loff_t *ppos)
192 struct ctrl_dbg *dbg = file->private_data;
193 return simple_read_from_buffer(buf, nbytes, ppos, dbg->data, dbg->size);
196 static int release(struct inode *inode, struct file *file)
198 struct ctrl_dbg *dbg = file->private_data;
200 kfree(dbg->data);
201 kfree(dbg);
202 return 0;
205 static const struct file_operations debug_ops = {
206 .owner = THIS_MODULE,
207 .open = open,
208 .llseek = lseek,
209 .read = read,
210 .release = release,
213 static struct dentry *root;
215 void cpqhp_initialize_debugfs(void)
217 if (!root)
218 root = debugfs_create_dir("cpqhp", NULL);
221 void cpqhp_shutdown_debugfs(void)
223 debugfs_remove(root);
226 void cpqhp_create_debugfs_files(struct controller *ctrl)
228 ctrl->dentry = debugfs_create_file(ctrl->pci_dev->dev.bus_id, S_IRUGO, root, ctrl, &debug_ops);
231 void cpqhp_remove_debugfs_files(struct controller *ctrl)
233 if (ctrl->dentry)
234 debugfs_remove(ctrl->dentry);
235 ctrl->dentry = NULL;