11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Compaq Hot Plug Controller Driver 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 1995,2001 Compaq Computer Corporation 51da177e4SLinus Torvalds * Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com) 61da177e4SLinus Torvalds * Copyright (C) 2001 IBM Corp. 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * All rights reserved. 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 111da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 121da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or (at 131da177e4SLinus Torvalds * your option) any later version. 141da177e4SLinus Torvalds * 151da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, but 161da177e4SLinus Torvalds * WITHOUT ANY WARRANTY; without even the implied warranty of 171da177e4SLinus Torvalds * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or 181da177e4SLinus Torvalds * NON INFRINGEMENT. See the GNU General Public License for more 191da177e4SLinus Torvalds * details. 201da177e4SLinus Torvalds * 211da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 221da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 231da177e4SLinus Torvalds * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 241da177e4SLinus Torvalds * 251da177e4SLinus Torvalds * Send feedback to <greg@kroah.com> 261da177e4SLinus Torvalds * 271da177e4SLinus Torvalds */ 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds #include <linux/config.h> 301da177e4SLinus Torvalds #include <linux/module.h> 311da177e4SLinus Torvalds #include <linux/kernel.h> 321da177e4SLinus Torvalds #include <linux/types.h> 331da177e4SLinus Torvalds #include <linux/proc_fs.h> 341da177e4SLinus Torvalds #include <linux/workqueue.h> 351da177e4SLinus Torvalds #include <linux/pci.h> 36*9f3f4681SGreg Kroah-Hartman #include <linux/debugfs.h> 371da177e4SLinus Torvalds #include "cpqphp.h" 381da177e4SLinus Torvalds 39*9f3f4681SGreg Kroah-Hartman static int show_ctrl (struct controller *ctrl, char *buf) 401da177e4SLinus Torvalds { 411da177e4SLinus Torvalds char *out = buf; 421da177e4SLinus Torvalds int index; 431da177e4SLinus Torvalds struct pci_resource *res; 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds out += sprintf(buf, "Free resources: memory\n"); 461da177e4SLinus Torvalds index = 11; 471da177e4SLinus Torvalds res = ctrl->mem_head; 481da177e4SLinus Torvalds while (res && index--) { 491da177e4SLinus Torvalds out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length); 501da177e4SLinus Torvalds res = res->next; 511da177e4SLinus Torvalds } 521da177e4SLinus Torvalds out += sprintf(out, "Free resources: prefetchable memory\n"); 531da177e4SLinus Torvalds index = 11; 541da177e4SLinus Torvalds res = ctrl->p_mem_head; 551da177e4SLinus Torvalds while (res && index--) { 561da177e4SLinus Torvalds out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length); 571da177e4SLinus Torvalds res = res->next; 581da177e4SLinus Torvalds } 591da177e4SLinus Torvalds out += sprintf(out, "Free resources: IO\n"); 601da177e4SLinus Torvalds index = 11; 611da177e4SLinus Torvalds res = ctrl->io_head; 621da177e4SLinus Torvalds while (res && index--) { 631da177e4SLinus Torvalds out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length); 641da177e4SLinus Torvalds res = res->next; 651da177e4SLinus Torvalds } 661da177e4SLinus Torvalds out += sprintf(out, "Free resources: bus numbers\n"); 671da177e4SLinus Torvalds index = 11; 681da177e4SLinus Torvalds res = ctrl->bus_head; 691da177e4SLinus Torvalds while (res && index--) { 701da177e4SLinus Torvalds out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length); 711da177e4SLinus Torvalds res = res->next; 721da177e4SLinus Torvalds } 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds return out - buf; 751da177e4SLinus Torvalds } 761da177e4SLinus Torvalds 77*9f3f4681SGreg Kroah-Hartman static int show_dev (struct controller *ctrl, char *buf) 781da177e4SLinus Torvalds { 791da177e4SLinus Torvalds char * out = buf; 801da177e4SLinus Torvalds int index; 811da177e4SLinus Torvalds struct pci_resource *res; 821da177e4SLinus Torvalds struct pci_func *new_slot; 831da177e4SLinus Torvalds struct slot *slot; 841da177e4SLinus Torvalds 851da177e4SLinus Torvalds slot = ctrl->slot; 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds while (slot) { 881da177e4SLinus Torvalds new_slot = cpqhp_slot_find(slot->bus, slot->device, 0); 891da177e4SLinus Torvalds if (!new_slot) 901da177e4SLinus Torvalds break; 911da177e4SLinus Torvalds out += sprintf(out, "assigned resources: memory\n"); 921da177e4SLinus Torvalds index = 11; 931da177e4SLinus Torvalds res = new_slot->mem_head; 941da177e4SLinus Torvalds while (res && index--) { 951da177e4SLinus Torvalds out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length); 961da177e4SLinus Torvalds res = res->next; 971da177e4SLinus Torvalds } 981da177e4SLinus Torvalds out += sprintf(out, "assigned resources: prefetchable memory\n"); 991da177e4SLinus Torvalds index = 11; 1001da177e4SLinus Torvalds res = new_slot->p_mem_head; 1011da177e4SLinus Torvalds while (res && index--) { 1021da177e4SLinus Torvalds out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length); 1031da177e4SLinus Torvalds res = res->next; 1041da177e4SLinus Torvalds } 1051da177e4SLinus Torvalds out += sprintf(out, "assigned resources: IO\n"); 1061da177e4SLinus Torvalds index = 11; 1071da177e4SLinus Torvalds res = new_slot->io_head; 1081da177e4SLinus Torvalds while (res && index--) { 1091da177e4SLinus Torvalds out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length); 1101da177e4SLinus Torvalds res = res->next; 1111da177e4SLinus Torvalds } 1121da177e4SLinus Torvalds out += sprintf(out, "assigned resources: bus numbers\n"); 1131da177e4SLinus Torvalds index = 11; 1141da177e4SLinus Torvalds res = new_slot->bus_head; 1151da177e4SLinus Torvalds while (res && index--) { 1161da177e4SLinus Torvalds out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length); 1171da177e4SLinus Torvalds res = res->next; 1181da177e4SLinus Torvalds } 1191da177e4SLinus Torvalds slot=slot->next; 1201da177e4SLinus Torvalds } 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds return out - buf; 1231da177e4SLinus Torvalds } 1241da177e4SLinus Torvalds 125*9f3f4681SGreg Kroah-Hartman static int spew_debug_info(struct controller *ctrl, char *data, int size) 1261da177e4SLinus Torvalds { 127*9f3f4681SGreg Kroah-Hartman int used; 128*9f3f4681SGreg Kroah-Hartman 129*9f3f4681SGreg Kroah-Hartman used = size - show_ctrl(ctrl, data); 130*9f3f4681SGreg Kroah-Hartman used = (size - used) - show_dev(ctrl, &data[used]); 131*9f3f4681SGreg Kroah-Hartman return used; 1321da177e4SLinus Torvalds } 133*9f3f4681SGreg Kroah-Hartman 134*9f3f4681SGreg Kroah-Hartman struct ctrl_dbg { 135*9f3f4681SGreg Kroah-Hartman int size; 136*9f3f4681SGreg Kroah-Hartman char *data; 137*9f3f4681SGreg Kroah-Hartman struct controller *ctrl; 138*9f3f4681SGreg Kroah-Hartman }; 139*9f3f4681SGreg Kroah-Hartman 140*9f3f4681SGreg Kroah-Hartman #define MAX_OUTPUT (4*PAGE_SIZE) 141*9f3f4681SGreg Kroah-Hartman 142*9f3f4681SGreg Kroah-Hartman static int open(struct inode *inode, struct file *file) 143*9f3f4681SGreg Kroah-Hartman { 144*9f3f4681SGreg Kroah-Hartman struct controller *ctrl = inode->u.generic_ip; 145*9f3f4681SGreg Kroah-Hartman struct ctrl_dbg *dbg; 146*9f3f4681SGreg Kroah-Hartman int retval = -ENOMEM; 147*9f3f4681SGreg Kroah-Hartman 148*9f3f4681SGreg Kroah-Hartman lock_kernel(); 149*9f3f4681SGreg Kroah-Hartman dbg = kmalloc(sizeof(*dbg), GFP_KERNEL); 150*9f3f4681SGreg Kroah-Hartman if (!dbg) 151*9f3f4681SGreg Kroah-Hartman goto exit; 152*9f3f4681SGreg Kroah-Hartman dbg->data = kmalloc(MAX_OUTPUT, GFP_KERNEL); 153*9f3f4681SGreg Kroah-Hartman if (!dbg->data) { 154*9f3f4681SGreg Kroah-Hartman kfree(dbg); 155*9f3f4681SGreg Kroah-Hartman goto exit; 156*9f3f4681SGreg Kroah-Hartman } 157*9f3f4681SGreg Kroah-Hartman dbg->size = spew_debug_info(ctrl, dbg->data, MAX_OUTPUT); 158*9f3f4681SGreg Kroah-Hartman file->private_data = dbg; 159*9f3f4681SGreg Kroah-Hartman retval = 0; 160*9f3f4681SGreg Kroah-Hartman exit: 161*9f3f4681SGreg Kroah-Hartman unlock_kernel(); 162*9f3f4681SGreg Kroah-Hartman return retval; 163*9f3f4681SGreg Kroah-Hartman } 164*9f3f4681SGreg Kroah-Hartman 165*9f3f4681SGreg Kroah-Hartman static loff_t lseek(struct file *file, loff_t off, int whence) 166*9f3f4681SGreg Kroah-Hartman { 167*9f3f4681SGreg Kroah-Hartman struct ctrl_dbg *dbg; 168*9f3f4681SGreg Kroah-Hartman loff_t new = -1; 169*9f3f4681SGreg Kroah-Hartman 170*9f3f4681SGreg Kroah-Hartman lock_kernel(); 171*9f3f4681SGreg Kroah-Hartman dbg = file->private_data; 172*9f3f4681SGreg Kroah-Hartman 173*9f3f4681SGreg Kroah-Hartman switch (whence) { 174*9f3f4681SGreg Kroah-Hartman case 0: 175*9f3f4681SGreg Kroah-Hartman new = off; 176*9f3f4681SGreg Kroah-Hartman break; 177*9f3f4681SGreg Kroah-Hartman case 1: 178*9f3f4681SGreg Kroah-Hartman new = file->f_pos + off; 179*9f3f4681SGreg Kroah-Hartman break; 180*9f3f4681SGreg Kroah-Hartman } 181*9f3f4681SGreg Kroah-Hartman if (new < 0 || new > dbg->size) { 182*9f3f4681SGreg Kroah-Hartman unlock_kernel(); 183*9f3f4681SGreg Kroah-Hartman return -EINVAL; 184*9f3f4681SGreg Kroah-Hartman } 185*9f3f4681SGreg Kroah-Hartman unlock_kernel(); 186*9f3f4681SGreg Kroah-Hartman return (file->f_pos = new); 187*9f3f4681SGreg Kroah-Hartman } 188*9f3f4681SGreg Kroah-Hartman 189*9f3f4681SGreg Kroah-Hartman static ssize_t read(struct file *file, char __user *buf, 190*9f3f4681SGreg Kroah-Hartman size_t nbytes, loff_t *ppos) 191*9f3f4681SGreg Kroah-Hartman { 192*9f3f4681SGreg Kroah-Hartman struct ctrl_dbg *dbg = file->private_data; 193*9f3f4681SGreg Kroah-Hartman return simple_read_from_buffer(buf, nbytes, ppos, dbg->data, dbg->size); 194*9f3f4681SGreg Kroah-Hartman } 195*9f3f4681SGreg Kroah-Hartman 196*9f3f4681SGreg Kroah-Hartman static int release(struct inode *inode, struct file *file) 197*9f3f4681SGreg Kroah-Hartman { 198*9f3f4681SGreg Kroah-Hartman struct ctrl_dbg *dbg = file->private_data; 199*9f3f4681SGreg Kroah-Hartman 200*9f3f4681SGreg Kroah-Hartman kfree(dbg->data); 201*9f3f4681SGreg Kroah-Hartman kfree(dbg); 202*9f3f4681SGreg Kroah-Hartman return 0; 203*9f3f4681SGreg Kroah-Hartman } 204*9f3f4681SGreg Kroah-Hartman 205*9f3f4681SGreg Kroah-Hartman static struct file_operations debug_ops = { 206*9f3f4681SGreg Kroah-Hartman .owner = THIS_MODULE, 207*9f3f4681SGreg Kroah-Hartman .open = open, 208*9f3f4681SGreg Kroah-Hartman .llseek = lseek, 209*9f3f4681SGreg Kroah-Hartman .read = read, 210*9f3f4681SGreg Kroah-Hartman .release = release, 211*9f3f4681SGreg Kroah-Hartman }; 212*9f3f4681SGreg Kroah-Hartman 213*9f3f4681SGreg Kroah-Hartman static struct dentry *root; 214*9f3f4681SGreg Kroah-Hartman 215*9f3f4681SGreg Kroah-Hartman void cpqhp_initialize_debugfs(void) 216*9f3f4681SGreg Kroah-Hartman { 217*9f3f4681SGreg Kroah-Hartman if (!root) 218*9f3f4681SGreg Kroah-Hartman root = debugfs_create_dir("cpqhp", NULL); 219*9f3f4681SGreg Kroah-Hartman } 220*9f3f4681SGreg Kroah-Hartman 221*9f3f4681SGreg Kroah-Hartman void cpqhp_shutdown_debugfs(void) 222*9f3f4681SGreg Kroah-Hartman { 223*9f3f4681SGreg Kroah-Hartman debugfs_remove(root); 224*9f3f4681SGreg Kroah-Hartman } 225*9f3f4681SGreg Kroah-Hartman 226*9f3f4681SGreg Kroah-Hartman void cpqhp_create_debugfs_files(struct controller *ctrl) 227*9f3f4681SGreg Kroah-Hartman { 228*9f3f4681SGreg Kroah-Hartman ctrl->dentry = debugfs_create_file(ctrl->pci_dev->dev.bus_id, S_IRUGO, root, ctrl, &debug_ops); 229*9f3f4681SGreg Kroah-Hartman } 230*9f3f4681SGreg Kroah-Hartman 231*9f3f4681SGreg Kroah-Hartman void cpqhp_remove_debugfs_files(struct controller *ctrl) 232*9f3f4681SGreg Kroah-Hartman { 233*9f3f4681SGreg Kroah-Hartman if (ctrl->dentry) 234*9f3f4681SGreg Kroah-Hartman debugfs_remove(ctrl->dentry); 235*9f3f4681SGreg Kroah-Hartman ctrl->dentry = NULL; 236*9f3f4681SGreg Kroah-Hartman } 237*9f3f4681SGreg Kroah-Hartman 238