diff -Naur linux-2.4.26/drivers/hotplug/Config.in /mnt/misc/kernel/linux-2.4.26/drivers/hotplug/Config.in --- a/drivers/hotplug/Config.in 2004-05-11 23:02:12.070627992 +0200 +++ b/drivers/hotplug/Config.in 2004-05-07 15:50:55.000000000 +0200 @@ -6,6 +6,8 @@ dep_tristate 'Support for PCI Hotplug (EXPERIMENTAL)' CONFIG_HOTPLUG_PCI $CONFIG_EXPERIMENTAL $CONFIG_PCI +dep_tristate ' Dummy PCI Hotplug driver' CONFIG_HOTPLUG_PCI_DUMMY $CONFIG_HOTPLUG_PCI + dep_tristate ' Compaq PCI Hotplug driver' CONFIG_HOTPLUG_PCI_COMPAQ $CONFIG_HOTPLUG_PCI $CONFIG_X86 dep_mbool ' Save configuration into NVRAM on Compaq servers' CONFIG_HOTPLUG_PCI_COMPAQ_NVRAM $CONFIG_HOTPLUG_PCI_COMPAQ if [ "$CONFIG_X86_IO_APIC" = "y" ]; then diff -Naur linux-2.4.26/drivers/hotplug/Makefile /mnt/misc/kernel/linux-2.4.26/drivers/hotplug/Makefile --- a/drivers/hotplug/Makefile 2004-05-11 23:02:12.101623280 +0200 +++ b/drivers/hotplug/Makefile 2004-05-07 15:52:56.000000000 +0200 @@ -4,11 +4,12 @@ O_TARGET := vmlinux-obj.o -list-multi := cpqphp.o pci_hotplug.o ibmphp.o acpiphp.o shpchp.o pciehp.o +list-multi := cpqphp.o pci_hotplug.o ibmphp.o acpiphp.o shpchp.o pciehp.o dummyphp.o export-objs := pci_hotplug_core.o pci_hotplug_util.o obj-$(CONFIG_HOTPLUG_PCI) += pci_hotplug.o +obj-$(CONFIG_HOTPLUG_PCI_DUMMY) += dummyphp.o obj-$(CONFIG_HOTPLUG_PCI_COMPAQ) += cpqphp.o obj-$(CONFIG_HOTPLUG_PCI_IBM) += ibmphp.o obj-$(CONFIG_HOTPLUG_PCI_ACPI) += acpiphp.o @@ -34,6 +35,8 @@ acpiphp_pci.o \ acpiphp_res.o +dummyphp_objs := dummyphp_core.o + pciehp-objs := pciehp_core.o \ pciehp_ctrl.o \ pciehp_hpc.o \ @@ -84,3 +87,5 @@ shpchp.o: $(shpchp-objs) $(LD) -r -o $@ $(shpchp-objs) +dummyphp.o: $(dummyphp_objs) + $(LD) -r -o $@ $(dummyphp_objs) diff -Naur linux-2.4.26/drivers/hotplug/dummyphp_core.c /mnt/misc/kernel/linux-2.4.26/drivers/hotplug/dummyphp_core.c --- a/drivers/hotplug/dummyphp_core.c 1970-01-01 01:00:00.000000000 +0100 +++ b/drivers/hotplug/dummyphp_core.c 2004-05-11 22:59:45.000000000 +0200 @@ -0,0 +1,395 @@ +/* + * 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" + +#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) + +/* name size which is used for entries in pcihpfs */ +#define SLOT_NAME_SIZE 16 /* DUMMY-{BUS}:{DEV} */ + +struct dummy_slot { + struct list_head node; + struct pci_bus *bus; + int devfn; + struct pci_dev *dev; + struct hotplug_slot *slot; +}; + +#define MY_NAME "dummyphp" + +static int debug; +static int showall; +static LIST_HEAD(slot_list); + +#define DRIVER_VERSION "0.1" +#define DRIVER_AUTHOR "Rolf Eike Beer " +#define DRIVER_DESC "Dummy Hot Plug PCI Controller Driver" + +MODULE_AUTHOR(DRIVER_AUTHOR); +MODULE_DESCRIPTION(DRIVER_DESC); +MODULE_LICENSE("GPL"); +MODULE_PARM(debug, "i"); +MODULE_PARM_DESC(debug, "Debugging mode enabled or not"); +MODULE_PARM(showall, "i"); +MODULE_PARM_DESC(showall, "Show all PCI slots, even those without devices in it"); + +static int enable_slot (struct hotplug_slot *slot); +static int disable_slot (struct hotplug_slot *slot); +static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value); + +static struct hotplug_slot_ops dummy_hotplug_slot_ops = { + .owner = THIS_MODULE, + .enable_slot = enable_slot, + .disable_slot = disable_slot, + .get_adapter_status = get_adapter_status +}; + +/** + * get_adapter_status - look if adapter is present in slot + * @hotplug_slot: slot to test value + * @value: status of the adapter + */ +static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value) +{ + struct dummy_slot *dslot = hotplug_slot->private; + struct pci_dev dev0; + + dev0.bus = dslot->bus; + dev0.devfn = dslot->devfn; + dev0.sysdata = dslot->bus->sysdata; + + *value = (pci_scan_slot(&dev0) != NULL); + hotplug_slot->info->adapter_status = *value; + + return 0; +} + +/** + * configure_visit_pci_dev - callback to configure new discovered devices + * @wrapped_dev: the device + * @wrapped_bus: the bus of the device + */ +static int configure_visit_pci_dev (struct pci_dev_wrapped *wrapped_dev, + struct pci_bus_wrapped *wrapped_bus) +{ + struct pci_dev* dev = wrapped_dev->dev; + + /* Create /proc/bus/pci proc entry for this device and bus device is on + Notify the drivers of the change */ + dbg("%s - starting\n", __FUNCTION__); + if (dev) { + pci_proc_attach_device(dev); + pci_announce_device_to_drivers(dev); + } + + return 0; +} + +static struct pci_visit configure_functions = { + visit_pci_dev: configure_visit_pci_dev, +}; + +/** + * enable_slot - power on and enable a slot + * @hotplug_slot: slot to enable + */ +static int +enable_slot(struct hotplug_slot *hotplug_slot) +{ + struct pci_dev dev0; + struct dummy_slot *slot = hotplug_slot->private; + struct pci_bus *child; + unsigned char bus; + struct pci_dev_wrapped wrapped_dev; + struct pci_bus_wrapped wrapped_bus; + int rc = 0; + + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); + + /* enable the specified slot */ + slot->dev = pci_find_slot(slot->bus->number, slot->devfn); + + /* Still NULL ? Well then scan for it ! */ + if (slot->dev == NULL) { + memset(&dev0, 0, sizeof(struct pci_dev)); + dev0.bus = slot->bus; + dev0.devfn = slot->devfn; + dev0.sysdata = slot->bus->sysdata; + + /* this will generate pci_dev structures for all functions, + but we will only call this case when lookup fails */ + slot->dev = pci_scan_slot(&dev0); + hotplug_slot->info->adapter_status = (slot->dev != NULL); + if (! hotplug_slot->info->adapter_status) { + dbg("ERROR: pci_dev still null\n"); + return -ENODEV; + } + } + + if (slot->dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { + pci_read_config_byte(slot->dev, PCI_SECONDARY_BUS, &bus); + child = (struct pci_bus*) pci_add_new_bus(slot->dev->bus, + (slot->dev), bus); + pci_do_scan_bus(child); + } + + if (slot->dev) { + memset(&wrapped_dev, 0, sizeof(struct pci_dev_wrapped)); + memset(&wrapped_bus, 0, sizeof(struct pci_bus_wrapped)); + wrapped_dev.dev = slot->dev; + wrapped_bus.bus = slot->dev->bus; + rc = pci_visit_dev(&configure_functions, &wrapped_dev, + &wrapped_bus); + } + return rc; +} + +/** + * is_pci_dev_in_use - check if a driver uses a pci device + * @dev: the device to check + */ +static int +is_pci_dev_in_use(struct pci_dev* dev) +{ + /* + * dev->driver will be set if the device is in use by a new-style + * driver -- otherwise, check the device's regions to see if any + * driver has claimed them + */ + + int i, inuse = 0; + + for (i = 0; !dev->driver && !inuse && (i < 6); i++) { + if (!pci_resource_start(dev, i)) + continue; + + if (pci_resource_flags(dev, i) & IORESOURCE_IO) + inuse = check_region(pci_resource_start(dev, i), + pci_resource_len(dev, i)); + else if (pci_resource_flags(dev, i) & IORESOURCE_MEM) + inuse = check_mem_region(pci_resource_start(dev, i), + pci_resource_len(dev, i)); + } + + return inuse; + +} + +/** + * disable_slot - disable any adapter in this slot + * @hotplug_slot: slot to disable + */ +static int +disable_slot(struct hotplug_slot *hotplug_slot) +{ + struct pci_dev* old_dev; + int func; + struct dummy_slot *slot = hotplug_slot->private; + + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); + + /* assume the driver feels responsible if dev->driver is set */ + if (slot->dev->driver) { + if (slot->dev->driver->remove) { + slot->dev->driver->remove(slot->dev); + slot->dev->driver = NULL; + } else { + err("Can't disable slot %x:%x, driver %s still holds reference to it!", + slot->bus->number, PCI_SLOT(slot->devfn), + slot->dev->driver->name); + } + } else if (is_pci_dev_in_use(slot->dev)) { + err("Can't disable slot %x:%x, a driver still holds reference to it!", + slot->bus->number, PCI_SLOT(slot->devfn)); + return -EBUSY; + } + + /* disable the specified slot */ + + for (func = 0; func < 8; func++) { + old_dev = pci_find_slot(slot->bus->number, slot->devfn+func); + if (old_dev) { + printk(KERN_INFO "Slot %s Removed <%s>\n", + old_dev->slot_name, old_dev->name); + pci_remove_device(old_dev); + } + } + hotplug_slot->info->power_status = 0; + slot->dev = NULL; + + return 0; +} + +/** + * scan_pci_bus - add an entry for every slot on this bus + * @bus: bus to scan + */ +static int __init +scan_pci_bus(struct pci_bus *bus) +{ + struct dummy_slot *dslot = NULL; /* this is just to shut up gcc. It will never be used uninitialized */ + struct hotplug_slot *hp; + int retval = -ENOMEM; + unsigned int devfn; + struct pci_dev dev0; + int reuse = 0; + + memset(&dev0, 0, sizeof(dev0)); + dev0.bus = (struct pci_bus*)bus; + dev0.sysdata = bus->sysdata; + for (devfn = 0; devfn < 0x100; devfn += 8) { + if (!reuse) { + dslot = kmalloc(sizeof(*dslot), GFP_KERNEL); + if (!dslot) + goto error; + memset(dslot, 0, sizeof(*dslot)); + } + + dslot->dev = pci_find_slot(bus->number, devfn); + + /* this is to avoid to kmalloc, kfree and kmalloc again */ + reuse = !(dslot->dev || showall); + if (reuse) + continue; + + hp = kmalloc(sizeof(*hp), GFP_KERNEL); + if (!hp) + goto error_dslot; + + memset(hp, 0, sizeof(*hp)); + + hp->info = kmalloc(sizeof(*hp->info), + GFP_KERNEL); + if (!hp->info) + goto error_hp; + + memset(hp->info, 0, sizeof(*hp->info)); + + hp->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); + if ( !hp->name ) + goto error_info; + + dslot->bus = bus; + dslot->devfn = devfn; + dslot->slot = hp; + + hp->ops = &dummy_hotplug_slot_ops; + hp->private = dslot; + + hp->info->power_status = (dslot->dev != NULL); + + hp->info->cur_bus_speed = PCI_SPEED_UNKNOWN; + hp->info->max_bus_speed = PCI_SPEED_UNKNOWN; + + snprintf(hp->name, SLOT_NAME_SIZE, "DUMMY-%02x:%02x", + dslot->bus->number, PCI_SLOT(dslot->devfn)); + + retval = pci_hp_register(hp); + if (retval) { + err("pci_hp_register failed with error %d\n", retval); + goto error_name; + } + list_add(&dslot->node, &slot_list); + } + if (reuse) + kfree(dslot); + return 0; + +error_name: + kfree(hp->name); +error_info: + kfree(hp->info); +error_hp: + kfree(hp); +error_dslot: + kfree(dslot); +error: + return retval; +} + +/** + * scan_pci_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) { + 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 int __init +dummyphp_init(void) +{ + info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); + + return pci_scan_buses(&pci_root_buses); +} + + +static void __exit +dummyphp_exit(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); + } +} + +module_init(dummyphp_init); +module_exit(dummyphp_exit);