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.
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
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>
41 static int show_ctrl (struct controller
*ctrl
, char *buf
)
45 struct pci_resource
*res
;
47 out
+= sprintf(buf
, "Free resources: memory\n");
50 while (res
&& index
--) {
51 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
54 out
+= sprintf(out
, "Free resources: prefetchable memory\n");
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
);
61 out
+= sprintf(out
, "Free resources: IO\n");
64 while (res
&& index
--) {
65 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
68 out
+= sprintf(out
, "Free resources: bus numbers\n");
71 while (res
&& index
--) {
72 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
79 static int show_dev (struct controller
*ctrl
, char *buf
)
83 struct pci_resource
*res
;
84 struct pci_func
*new_slot
;
90 new_slot
= cpqhp_slot_find(slot
->bus
, slot
->device
, 0);
93 out
+= sprintf(out
, "assigned resources: memory\n");
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
);
100 out
+= sprintf(out
, "assigned resources: prefetchable memory\n");
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
);
107 out
+= sprintf(out
, "assigned resources: IO\n");
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
);
114 out
+= sprintf(out
, "assigned resources: bus numbers\n");
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
);
127 static int spew_debug_info(struct controller
*ctrl
, char *data
, int size
)
131 used
= size
- show_ctrl(ctrl
, data
);
132 used
= (size
- used
) - show_dev(ctrl
, &data
[used
]);
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
;
151 dbg
= kmalloc(sizeof(*dbg
), GFP_KERNEL
);
154 dbg
->data
= kmalloc(MAX_OUTPUT
, GFP_KERNEL
);
159 dbg
->size
= spew_debug_info(ctrl
, dbg
->data
, MAX_OUTPUT
);
160 file
->private_data
= dbg
;
167 static loff_t
lseek(struct file
*file
, loff_t off
, int whence
)
169 struct ctrl_dbg
*dbg
;
173 dbg
= file
->private_data
;
180 new = file
->f_pos
+ off
;
183 if (new < 0 || new > dbg
->size
) {
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
;
207 static const struct file_operations debug_ops
= {
208 .owner
= THIS_MODULE
,
215 static struct dentry
*root
;
217 void cpqhp_initialize_debugfs(void)
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
)
237 debugfs_remove(ctrl
->dentry
);