^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Compaq Hot Plug Controller Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1995,2001 Compaq Computer Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2001,2003 Greg Kroah-Hartman (greg@kroah.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2001 IBM Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Send feedback to <greg@kroah.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/pci_hotplug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "cpqphp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static DEFINE_MUTEX(cpqphp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static int show_ctrl(struct controller *ctrl, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) char *out = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct pci_resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) out += sprintf(buf, "Free resources: memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) index = 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) res = ctrl->mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) while (res && index--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) res = res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) out += sprintf(out, "Free resources: prefetchable memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) index = 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) res = ctrl->p_mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) while (res && index--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) res = res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) out += sprintf(out, "Free resources: IO\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) index = 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) res = ctrl->io_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) while (res && index--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) res = res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) out += sprintf(out, "Free resources: bus numbers\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) index = 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) res = ctrl->bus_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) while (res && index--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) res = res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return out - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static int show_dev(struct controller *ctrl, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) char *out = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct pci_resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct pci_func *new_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct slot *slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) slot = ctrl->slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) while (slot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) new_slot = cpqhp_slot_find(slot->bus, slot->device, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (!new_slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) out += sprintf(out, "assigned resources: memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) index = 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) res = new_slot->mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) while (res && index--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) res = res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) out += sprintf(out, "assigned resources: prefetchable memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) index = 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) res = new_slot->p_mem_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) while (res && index--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) res = res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) out += sprintf(out, "assigned resources: IO\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) index = 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) res = new_slot->io_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) while (res && index--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) res = res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) out += sprintf(out, "assigned resources: bus numbers\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) index = 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) res = new_slot->bus_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) while (res && index--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) res = res->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) slot = slot->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return out - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int spew_debug_info(struct controller *ctrl, char *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) used = size - show_ctrl(ctrl, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) used = (size - used) - show_dev(ctrl, &data[used]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct ctrl_dbg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) char *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct controller *ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #define MAX_OUTPUT (4*PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static int open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct controller *ctrl = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct ctrl_dbg *dbg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) mutex_lock(&cpqphp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) dbg = kmalloc(sizeof(*dbg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!dbg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) dbg->data = kmalloc(MAX_OUTPUT, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (!dbg->data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) kfree(dbg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) dbg->size = spew_debug_info(ctrl, dbg->data, MAX_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) file->private_data = dbg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) mutex_unlock(&cpqphp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static loff_t lseek(struct file *file, loff_t off, int whence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct ctrl_dbg *dbg = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return fixed_size_llseek(file, off, whence, dbg->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static ssize_t read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) size_t nbytes, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct ctrl_dbg *dbg = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return simple_read_from_buffer(buf, nbytes, ppos, dbg->data, dbg->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static int release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct ctrl_dbg *dbg = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) kfree(dbg->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) kfree(dbg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static const struct file_operations debug_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .open = open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) .llseek = lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) .read = read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .release = release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static struct dentry *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) void cpqhp_initialize_debugfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (!root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) root = debugfs_create_dir("cpqhp", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) void cpqhp_shutdown_debugfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) debugfs_remove(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) void cpqhp_create_debugfs_files(struct controller *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ctrl->dentry = debugfs_create_file(dev_name(&ctrl->pci_dev->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) S_IRUGO, root, ctrl, &debug_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) void cpqhp_remove_debugfs_files(struct controller *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) debugfs_remove(ctrl->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) ctrl->dentry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)