Merge branch 'fix/pcm-hwptr' into for-linus
[linux/fpc-iii.git] / drivers / pci / hotplug / cpqphp_sysfs.c
blobe6089bdb6e5bddbc2b08e09c9419d26056e543e7
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/smp_lock.h>
37 #include <linux/debugfs.h>
38 #include "cpqphp.h"
40 static int show_ctrl (struct controller *ctrl, char *buf)
42 char *out = buf;
43 int index;
44 struct pci_resource *res;
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;
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;
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;
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;
75 return out - buf;
78 static int show_dev (struct controller *ctrl, char *buf)
80 char * out = buf;
81 int index;
82 struct pci_resource *res;
83 struct pci_func *new_slot;
84 struct slot *slot;
86 slot = ctrl->slot;
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;
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;
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;
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;
120 slot=slot->next;
123 return out - buf;
126 static int spew_debug_info(struct controller *ctrl, char *data, int size)
128 int used;
130 used = size - show_ctrl(ctrl, data);
131 used = (size - used) - show_dev(ctrl, &data[used]);
132 return used;
135 struct ctrl_dbg {
136 int size;
137 char *data;
138 struct controller *ctrl;
141 #define MAX_OUTPUT (4*PAGE_SIZE)
143 static int open(struct inode *inode, struct file *file)
145 struct controller *ctrl = inode->i_private;
146 struct ctrl_dbg *dbg;
147 int retval = -ENOMEM;
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;
158 dbg->size = spew_debug_info(ctrl, dbg->data, MAX_OUTPUT);
159 file->private_data = dbg;
160 retval = 0;
161 exit:
162 unlock_kernel();
163 return retval;
166 static loff_t lseek(struct file *file, loff_t off, int whence)
168 struct ctrl_dbg *dbg;
169 loff_t new = -1;
171 lock_kernel();
172 dbg = file->private_data;
174 switch (whence) {
175 case 0:
176 new = off;
177 break;
178 case 1:
179 new = file->f_pos + off;
180 break;
182 if (new < 0 || new > dbg->size) {
183 unlock_kernel();
184 return -EINVAL;
186 unlock_kernel();
187 return (file->f_pos = new);
190 static ssize_t read(struct file *file, char __user *buf,
191 size_t nbytes, loff_t *ppos)
193 struct ctrl_dbg *dbg = file->private_data;
194 return simple_read_from_buffer(buf, nbytes, ppos, dbg->data, dbg->size);
197 static int release(struct inode *inode, struct file *file)
199 struct ctrl_dbg *dbg = file->private_data;
201 kfree(dbg->data);
202 kfree(dbg);
203 return 0;
206 static const struct file_operations debug_ops = {
207 .owner = THIS_MODULE,
208 .open = open,
209 .llseek = lseek,
210 .read = read,
211 .release = release,
214 static struct dentry *root;
216 void cpqhp_initialize_debugfs(void)
218 if (!root)
219 root = debugfs_create_dir("cpqhp", NULL);
222 void cpqhp_shutdown_debugfs(void)
224 debugfs_remove(root);
227 void cpqhp_create_debugfs_files(struct controller *ctrl)
229 ctrl->dentry = debugfs_create_file(dev_name(&ctrl->pci_dev->dev),
230 S_IRUGO, root, ctrl, &debug_ops);
233 void cpqhp_remove_debugfs_files(struct controller *ctrl)
235 if (ctrl->dentry)
236 debugfs_remove(ctrl->dentry);
237 ctrl->dentry = NULL;