1 // SPDX-License-Identifier: GPL-2.0+
3 * Compaq Hot Plug Controller Driver
5 * Copyright (C) 1995,2001 Compaq Computer Corporation
6 * Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com)
7 * Copyright (C) 2001 IBM Corp.
11 * Send feedback to <greg@kroah.com>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
18 #include <linux/types.h>
19 #include <linux/proc_fs.h>
20 #include <linux/workqueue.h>
21 #include <linux/pci.h>
22 #include <linux/pci_hotplug.h>
23 #include <linux/mutex.h>
24 #include <linux/debugfs.h>
27 static DEFINE_MUTEX(cpqphp_mutex
);
28 static int show_ctrl(struct controller
*ctrl
, char *buf
)
32 struct pci_resource
*res
;
34 out
+= sprintf(buf
, "Free resources: memory\n");
37 while (res
&& index
--) {
38 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
41 out
+= sprintf(out
, "Free resources: prefetchable memory\n");
43 res
= ctrl
->p_mem_head
;
44 while (res
&& index
--) {
45 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
48 out
+= sprintf(out
, "Free resources: IO\n");
51 while (res
&& index
--) {
52 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
55 out
+= sprintf(out
, "Free resources: bus numbers\n");
58 while (res
&& index
--) {
59 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
66 static int show_dev(struct controller
*ctrl
, char *buf
)
70 struct pci_resource
*res
;
71 struct pci_func
*new_slot
;
77 new_slot
= cpqhp_slot_find(slot
->bus
, slot
->device
, 0);
80 out
+= sprintf(out
, "assigned resources: memory\n");
82 res
= new_slot
->mem_head
;
83 while (res
&& index
--) {
84 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
87 out
+= sprintf(out
, "assigned resources: prefetchable memory\n");
89 res
= new_slot
->p_mem_head
;
90 while (res
&& index
--) {
91 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
94 out
+= sprintf(out
, "assigned resources: IO\n");
96 res
= new_slot
->io_head
;
97 while (res
&& index
--) {
98 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
101 out
+= sprintf(out
, "assigned resources: bus numbers\n");
103 res
= new_slot
->bus_head
;
104 while (res
&& index
--) {
105 out
+= sprintf(out
, "start = %8.8x, length = %8.8x\n", res
->base
, res
->length
);
114 static int spew_debug_info(struct controller
*ctrl
, char *data
, int size
)
118 used
= size
- show_ctrl(ctrl
, data
);
119 used
= (size
- used
) - show_dev(ctrl
, &data
[used
]);
126 struct controller
*ctrl
;
129 #define MAX_OUTPUT (4*PAGE_SIZE)
131 static int open(struct inode
*inode
, struct file
*file
)
133 struct controller
*ctrl
= inode
->i_private
;
134 struct ctrl_dbg
*dbg
;
135 int retval
= -ENOMEM
;
137 mutex_lock(&cpqphp_mutex
);
138 dbg
= kmalloc(sizeof(*dbg
), GFP_KERNEL
);
141 dbg
->data
= kmalloc(MAX_OUTPUT
, GFP_KERNEL
);
146 dbg
->size
= spew_debug_info(ctrl
, dbg
->data
, MAX_OUTPUT
);
147 file
->private_data
= dbg
;
150 mutex_unlock(&cpqphp_mutex
);
154 static loff_t
lseek(struct file
*file
, loff_t off
, int whence
)
156 struct ctrl_dbg
*dbg
= file
->private_data
;
157 return fixed_size_llseek(file
, off
, whence
, dbg
->size
);
160 static ssize_t
read(struct file
*file
, char __user
*buf
,
161 size_t nbytes
, loff_t
*ppos
)
163 struct ctrl_dbg
*dbg
= file
->private_data
;
164 return simple_read_from_buffer(buf
, nbytes
, ppos
, dbg
->data
, dbg
->size
);
167 static int release(struct inode
*inode
, struct file
*file
)
169 struct ctrl_dbg
*dbg
= file
->private_data
;
176 static const struct file_operations debug_ops
= {
177 .owner
= THIS_MODULE
,
184 static struct dentry
*root
;
186 void cpqhp_initialize_debugfs(void)
189 root
= debugfs_create_dir("cpqhp", NULL
);
192 void cpqhp_shutdown_debugfs(void)
194 debugfs_remove(root
);
197 void cpqhp_create_debugfs_files(struct controller
*ctrl
)
199 ctrl
->dentry
= debugfs_create_file(dev_name(&ctrl
->pci_dev
->dev
),
200 S_IRUGO
, root
, ctrl
, &debug_ops
);
203 void cpqhp_remove_debugfs_files(struct controller
*ctrl
)
205 debugfs_remove(ctrl
->dentry
);