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/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>
40 static int show_ctrl (struct controller
*ctrl
, char *buf
)
44 struct pci_resource
*res
;
46 out
+= sprintf(buf
, "Free resources: memory\n");
49 while (res
&& index
--) {
50 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
53 out
+= sprintf(out
, "Free resources: prefetchable memory\n");
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
);
60 out
+= sprintf(out
, "Free resources: IO\n");
63 while (res
&& index
--) {
64 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
67 out
+= sprintf(out
, "Free resources: bus numbers\n");
70 while (res
&& index
--) {
71 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
78 static int show_dev (struct controller
*ctrl
, char *buf
)
82 struct pci_resource
*res
;
83 struct pci_func
*new_slot
;
89 new_slot
= cpqhp_slot_find(slot
->bus
, slot
->device
, 0);
92 out
+= sprintf(out
, "assigned resources: memory\n");
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
);
99 out
+= sprintf(out
, "assigned resources: prefetchable memory\n");
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
);
106 out
+= sprintf(out
, "assigned resources: IO\n");
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
);
113 out
+= sprintf(out
, "assigned resources: bus numbers\n");
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
);
126 static int spew_debug_info(struct controller
*ctrl
, char *data
, int size
)
130 used
= size
- show_ctrl(ctrl
, data
);
131 used
= (size
- used
) - show_dev(ctrl
, &data
[used
]);
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
;
150 dbg
= kmalloc(sizeof(*dbg
), GFP_KERNEL
);
153 dbg
->data
= kmalloc(MAX_OUTPUT
, GFP_KERNEL
);
158 dbg
->size
= spew_debug_info(ctrl
, dbg
->data
, MAX_OUTPUT
);
159 file
->private_data
= dbg
;
166 static loff_t
lseek(struct file
*file
, loff_t off
, int whence
)
168 struct ctrl_dbg
*dbg
;
172 dbg
= file
->private_data
;
179 new = file
->f_pos
+ off
;
182 if (new < 0 || new > dbg
->size
) {
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
;
206 static const struct file_operations debug_ops
= {
207 .owner
= THIS_MODULE
,
214 static struct dentry
*root
;
216 void cpqhp_initialize_debugfs(void)
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
)
236 debugfs_remove(ctrl
->dentry
);