]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/pci/hotplug/cpqphp_sysfs.c
headers: smp_lock.h redux
[net-next-2.6.git] / drivers / pci / hotplug / cpqphp_sysfs.c
CommitLineData
1da177e4
LT
1/*
2 * Compaq Hot Plug Controller Driver
3 *
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.
7 *
8 * All rights reserved.
9 *
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.
14 *
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.
20 *
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.
24 *
25 * Send feedback to <greg@kroah.com>
26 *
27 */
28
1da177e4
LT
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>
7a54f25c 35#include <linux/pci_hotplug.h>
405f5571 36#include <linux/smp_lock.h>
9f3f4681 37#include <linux/debugfs.h>
1da177e4
LT
38#include "cpqphp.h"
39
9f3f4681 40static int show_ctrl (struct controller *ctrl, char *buf)
1da177e4 41{
9f3f4681 42 char *out = buf;
1da177e4
LT
43 int index;
44 struct pci_resource *res;
45
1da177e4
LT
46 out += sprintf(buf, "Free resources: memory\n");
47 index = 11;
48 res = ctrl->mem_head;
49 while (res && index--) {
50 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
51 res = res->next;
52 }
53 out += sprintf(out, "Free resources: prefetchable memory\n");
54 index = 11;
55 res = ctrl->p_mem_head;
56 while (res && index--) {
57 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
58 res = res->next;
59 }
60 out += sprintf(out, "Free resources: IO\n");
61 index = 11;
62 res = ctrl->io_head;
63 while (res && index--) {
64 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
65 res = res->next;
66 }
67 out += sprintf(out, "Free resources: bus numbers\n");
68 index = 11;
69 res = ctrl->bus_head;
70 while (res && index--) {
71 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
72 res = res->next;
73 }
74
75 return out - buf;
76}
1da177e4 77
9f3f4681 78static int show_dev (struct controller *ctrl, char *buf)
1da177e4 79{
1da177e4
LT
80 char * out = buf;
81 int index;
82 struct pci_resource *res;
83 struct pci_func *new_slot;
84 struct slot *slot;
85
9f3f4681 86 slot = ctrl->slot;
1da177e4
LT
87
88 while (slot) {
89 new_slot = cpqhp_slot_find(slot->bus, slot->device, 0);
90 if (!new_slot)
91 break;
92 out += sprintf(out, "assigned resources: memory\n");
93 index = 11;
94 res = new_slot->mem_head;
95 while (res && index--) {
96 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
97 res = res->next;
98 }
99 out += sprintf(out, "assigned resources: prefetchable memory\n");
100 index = 11;
101 res = new_slot->p_mem_head;
102 while (res && index--) {
103 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
104 res = res->next;
105 }
106 out += sprintf(out, "assigned resources: IO\n");
107 index = 11;
108 res = new_slot->io_head;
109 while (res && index--) {
110 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
111 res = res->next;
112 }
113 out += sprintf(out, "assigned resources: bus numbers\n");
114 index = 11;
115 res = new_slot->bus_head;
116 while (res && index--) {
117 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
118 res = res->next;
119 }
120 slot=slot->next;
121 }
122
123 return out - buf;
124}
1da177e4 125
9f3f4681 126static int spew_debug_info(struct controller *ctrl, char *data, int size)
1da177e4 127{
9f3f4681
GKH
128 int used;
129
130 used = size - show_ctrl(ctrl, data);
131 used = (size - used) - show_dev(ctrl, &data[used]);
132 return used;
133}
134
135struct ctrl_dbg {
136 int size;
137 char *data;
138 struct controller *ctrl;
139};
140
141#define MAX_OUTPUT (4*PAGE_SIZE)
142
143static int open(struct inode *inode, struct file *file)
144{
8e18e294 145 struct controller *ctrl = inode->i_private;
9f3f4681
GKH
146 struct ctrl_dbg *dbg;
147 int retval = -ENOMEM;
148
149 lock_kernel();
150 dbg = kmalloc(sizeof(*dbg), GFP_KERNEL);
151 if (!dbg)
152 goto exit;
153 dbg->data = kmalloc(MAX_OUTPUT, GFP_KERNEL);
154 if (!dbg->data) {
155 kfree(dbg);
156 goto exit;
157 }
158 dbg->size = spew_debug_info(ctrl, dbg->data, MAX_OUTPUT);
159 file->private_data = dbg;
160 retval = 0;
161exit:
162 unlock_kernel();
163 return retval;
164}
165
166static loff_t lseek(struct file *file, loff_t off, int whence)
167{
168 struct ctrl_dbg *dbg;
169 loff_t new = -1;
170
171 lock_kernel();
172 dbg = file->private_data;
173
174 switch (whence) {
175 case 0:
176 new = off;
177 break;
178 case 1:
179 new = file->f_pos + off;
180 break;
181 }
182 if (new < 0 || new > dbg->size) {
183 unlock_kernel();
184 return -EINVAL;
185 }
186 unlock_kernel();
187 return (file->f_pos = new);
1da177e4 188}
9f3f4681
GKH
189
190static ssize_t read(struct file *file, char __user *buf,
191 size_t nbytes, loff_t *ppos)
192{
193 struct ctrl_dbg *dbg = file->private_data;
194 return simple_read_from_buffer(buf, nbytes, ppos, dbg->data, dbg->size);
195}
196
197static int release(struct inode *inode, struct file *file)
198{
199 struct ctrl_dbg *dbg = file->private_data;
200
201 kfree(dbg->data);
202 kfree(dbg);
203 return 0;
204}
205
d54b1fdb 206static const struct file_operations debug_ops = {
9f3f4681
GKH
207 .owner = THIS_MODULE,
208 .open = open,
209 .llseek = lseek,
210 .read = read,
211 .release = release,
212};
213
214static struct dentry *root;
215
216void cpqhp_initialize_debugfs(void)
217{
218 if (!root)
219 root = debugfs_create_dir("cpqhp", NULL);
220}
221
222void cpqhp_shutdown_debugfs(void)
223{
224 debugfs_remove(root);
225}
226
227void cpqhp_create_debugfs_files(struct controller *ctrl)
228{
54cc6954
KS
229 ctrl->dentry = debugfs_create_file(dev_name(&ctrl->pci_dev->dev),
230 S_IRUGO, root, ctrl, &debug_ops);
9f3f4681
GKH
231}
232
233void cpqhp_remove_debugfs_files(struct controller *ctrl)
234{
235 if (ctrl->dentry)
236 debugfs_remove(ctrl->dentry);
237 ctrl->dentry = NULL;
238}
239