diff -Nau linux-2.6.0-test1/drivers/pci/hotplug/Kconfig linux-2.6.0-test1-bk2-caliban/drivers/pci/hotplug/Kconfig --- linux-2.6.0-test1/drivers/pci/hotplug/Kconfig 2003-07-14 05:33:13.000000000 +0200 +++ linux-2.6.0-test1-bk2-caliban/drivers/pci/hotplug/Kconfig 2003-07-21 18:11:26.000000000 +0200 @@ -46,6 +46,25 @@ When in doubt, say N. +config HOTPLUG_PCI_DUMMY + tristate "Dummy PCI Hotplug driver" + depends on HOTPLUG_PCI + help + Say Y here if you want to use the dummy PCI hotplug driver. It can + be used to simulate PCI hotplug events if even if your system not + hotplug capable. + + Be careful: it claims all PCI slots in the system. There may be + side effects on other hotplug drivers, so only use one hotplug driver + at the same time. + + This code is also available as a module ( = code which can be + inserted in and removed from the running kernel whenever you want). + The module will be called cpqphp. If you want to compile it + as a module, say M here and read . + + When in doubt, say N. + config HOTPLUG_PCI_COMPAQ tristate "Compaq PCI Hotplug driver" depends on HOTPLUG_PCI && X86 diff -Nau linux-2.6.0-test1/drivers/pci/hotplug/Makefile linux-2.6.0-test1-bk2-caliban/drivers/pci/hotplug/Makefile --- linux-2.6.0-test1/drivers/pci/hotplug/Makefile 2003-07-14 05:36:33.000000000 +0200 +++ linux-2.6.0-test1-bk2-caliban/drivers/pci/hotplug/Makefile 2003-07-21 18:11:26.000000000 +0200 @@ -9,6 +9,7 @@ obj-$(CONFIG_HOTPLUG_PCI_ACPI) += acpiphp.o obj-$(CONFIG_HOTPLUG_PCI_CPCI_ZT5550) += cpcihp_zt5550.o obj-$(CONFIG_HOTPLUG_PCI_CPCI_GENERIC) += cpcihp_generic.o +obj-$(CONFIG_HOTPLUG_PCI_DUMMY) += dummyphp.o pci_hotplug-objs := pci_hotplug_core.o @@ -33,6 +34,8 @@ acpiphp_pci.o \ acpiphp_res.o +dummyphp-objs := dummyphp_core.o + ifdef CONFIG_HOTPLUG_PCI_ACPI EXTRA_CFLAGS += -D_LINUX -I$(TOPDIR)/drivers/acpi ifdef CONFIG_ACPI_DEBUG diff -Nau linux-2.6.0-test1/drivers/pci/hotplug/dummyphp_core.c linux-2.6.0-test1-bk2-caliban/drivers/pci/hotplug/dummyphp_core.c --- linux-2.6.0-test1/drivers/pci/hotplug/dummyphp_core.c 1970-01-01 01:00:00.000000000 +0100 +++ linux-2.6.0-test1-bk2-caliban/drivers/pci/hotplug/dummyphp_core.c 2003-07-21 18:11:26.000000000 +0200 @@ -0,0 +1,331 @@ +/* + * Dummy PCI Hot Plug Controller Driver + * + * Copyright (c) 2003 Rolf Eike Beer + * + * Based on code from: + * Vladimir Kondratiev + * Greg Kroah-Hartman + * + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * Send feedback to + */ + +/* + * + * This driver will "emulate" removing PCI devices from the system. If + * the "power" file is written to with "0" then the specified PCI device + * will be completely removed from the kernel. + * + * WARNING, this does NOT turn off the power to the PCI device. This is + * a "logical" removal, not a physical or electrical removal. + * + * Use this module at your own risk, you have been warned! + * + */ +#include +#include +#include +#include +#include +#include "pci_hotplug.h" +#include "../pci.h" + +#ifndef CONFIG_HOTPLUG_PCI_DUMMY_MODULE + #define MY_NAME "dummyphp" +#else + #define MY_NAME THIS_MODULE->name +#endif + +#define dbg(format, arg...) \ + do { \ + if (debug) \ + printk(KERN_DEBUG "%s: " format, \ + MY_NAME , ## arg); \ + } while (0) +#define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME , ## arg) +#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) + +#define DRIVER_AUTHOR "Rolf Eike Beer " +#define DRIVER_DESC "Dummy PCI Hot Plug Controller Driver" + +/* name size which is used for entries in pcihpfs */ +#define SLOT_NAME_SIZE 20 /* DUMMY-{DOMAIN}-{BUS}:{DEV} */ + +struct dummy_slot { + struct list_head node; + struct hotplug_slot *slot; + struct pci_dev *dev; + struct pci_bus *bus; + int devfn; +}; + +static int debug; +static LIST_HEAD(slot_list); + +static int enable_slot (struct hotplug_slot *slot); +static int disable_slot (struct hotplug_slot *slot); + +static struct hotplug_slot_ops dummy_hotplug_slot_ops = { + .owner = THIS_MODULE, + .enable_slot = enable_slot, + .disable_slot = disable_slot, +}; + +/** + * dummy_release - free the memory of a slot + * @slot: slot pointer to remove + */ +static void dummy_release(struct hotplug_slot *slot) +{ + struct dummy_slot *dslot = slot->private; + + list_del(&dslot->node); + kfree(dslot->slot->info); + kfree(dslot->slot); + if (dslot->dev) + pci_dev_put(dslot->dev); + kfree(dslot); +} + +/** + * add_slot - add a new "hotplug" slot + * @dev - a struct pci_dev describing this slot (regardless if + * there is actually a device in this slot or not) + */ +static inline int __init +add_slot(const struct pci_dev *dev) +{ + struct dummy_slot *dslot; + struct hotplug_slot *slot; + struct pci_dev *tmp_dev; + int retval = -ENOMEM; + + slot = kmalloc(sizeof(struct hotplug_slot), GFP_KERNEL); + if (!slot) + goto error; + + memset(slot, 0, sizeof(*slot)); + + slot->info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL); + if (!slot->info) + goto error_slot; + + memset(slot->info, 0, sizeof(struct hotplug_slot_info)); + + slot->info->max_bus_speed = PCI_SPEED_UNKNOWN; + slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN; + + slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); + if (!slot->name) + goto error_info; + dslot = kmalloc(sizeof(struct dummy_slot), GFP_KERNEL); + if (!dslot) + goto error_name; + + dslot->bus = dev->bus; + dslot->devfn = dev->devfn; + + tmp_dev = pci_find_slot(dslot->bus->number, dslot->devfn); + slot->info->power_status = (tmp_dev != NULL); + + slot->ops = &dummy_hotplug_slot_ops; + slot->release = &dummy_release; + slot->private = (void *) dslot; + + snprintf(slot->name, SLOT_NAME_SIZE, "DUMMY-%04x:%02x:%02x", + pci_domain_nr(dev->bus), dslot->bus->number, + PCI_SLOT(dslot->devfn)); + + retval = pci_hp_register(slot); + if (retval) { + err("pci_hp_register failed with error %d\n", retval); + goto error_dslot; + } + + dslot->slot = slot; + if (slot->info->power_status) { + dslot->dev = pci_dev_get(tmp_dev); + } else { + dslot->dev = NULL; + } + list_add(&dslot->node, &slot_list); + + return retval; + +error_dslot: + kfree(dslot); +error_name: + kfree(slot->name); +error_info: + kfree(slot->info); +error_slot: + kfree(slot); +error: + return retval; +} + +/** + * scan_pci_bus - add an entry for every slot on this bus + * @bus: bus to scan + */ +static inline int __init +scan_pci_bus(const struct pci_bus *bus) +{ + int retval; + struct pci_dev dev0; + + memset(&dev0, 0, sizeof(struct pci_dev)); + dev0.bus = (struct pci_bus*) bus; + dev0.sysdata = bus->sysdata; + for (dev0.devfn = 0; dev0.devfn < 0x100; dev0.devfn += 8) { + retval = add_slot(&dev0); + if (retval) + break; + } + return retval; +} + +/** + * enable_slot - power on and enable a slot + * @hotplug_slot: slot to enable + */ +static int +enable_slot(struct hotplug_slot *hotplug_slot) +{ + struct dummy_slot *dslot; + struct pci_dev *dev; + int num; + + if (!hotplug_slot) + return -ENODEV; + + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); + + /* enable the specified slot */ + dslot = (struct dummy_slot *) hotplug_slot->private; + + dev = dslot->dev; + if (dev == NULL) + dev = pci_find_slot(dslot->bus->number, dslot->devfn); + + /* No pci device, we need to create it then */ + if (dev == NULL) { + dbg("INFO: pci_dev still null\n"); + + num = pci_scan_slot(dslot->bus, dslot->devfn); + if (num) + pci_bus_add_devices(dslot->bus); + + dev = pci_find_slot(dslot->bus->number, dslot->devfn); + if (dev == NULL) { + dbg("ERROR: pci_dev still null\n"); + return -ENODEV; + } + dslot->dev = pci_dev_get(dev); + } + + return 0; +} + +/** + * disable_slot - disable any adapter in this slot + * @slot: slot to disable + */ +static int +disable_slot(struct hotplug_slot *slot) +{ + struct dummy_slot *dslot; + + if (!slot) + return -ENODEV; + + dslot = (struct dummy_slot *) slot->private; + + dbg("%s - physical_slot = %s\n", __FUNCTION__, slot->name); + + /* don't disable bridged devices just yet, we can't handle them easily... */ + if (dslot->dev->subordinate) { + err("Can't remove PCI devices with other PCI devices behind it yet.\n"); + return -EPERM; + } + + if (!dslot->dev) { + dbg("No device in slot, exiting"); + return -ENODEV; + } + pci_dev_put(dslot->dev); + + /* remove the device from the pci core */ + info("Slot %s removed\n", pci_name(dslot->dev)); + pci_remove_bus_device(dslot->dev); + + dslot->dev = NULL; + + slot->info->power_status = 0; + + return 0; +} + +/** + * pci_scan_buses - scan this bus and all child buses for slots + * @list: list of buses to scan + */ +static int __init +pci_scan_buses(const struct list_head *list) +{ + int retval; + const struct list_head *l; + + list_for_each(l,list) { + const struct pci_bus *b = pci_bus_b(l); + retval = scan_pci_bus(b); + if (retval) + return retval; + retval = pci_scan_buses(&b->children); + if (retval) + return retval; + } + return 0; +} + +static inline void __exit +cleanup_slots(void) +{ + struct list_head *tmp; + struct list_head *next; + struct dummy_slot *dslot; + + list_for_each_safe (tmp, next, &slot_list) { + dslot = list_entry (tmp, struct dummy_slot, node); + pci_hp_deregister(dslot->slot); + } +} + +static int __init +dummyphp_init(void) +{ + info(DRIVER_DESC "\n"); + + return pci_scan_buses(&pci_root_buses); +} + +static void __exit +dummyphp_exit(void) +{ + cleanup_slots(); +} + +module_init(dummyphp_init); +module_exit(dummyphp_exit); + +MODULE_AUTHOR(DRIVER_AUTHOR); +MODULE_DESCRIPTION(DRIVER_DESC); +MODULE_LICENSE("GPL"); +MODULE_PARM(debug, "i"); +MODULE_PARM_DESC(debug, "Debugging mode enabled or not");