From: Kenji Kaneshige Architecture dependent IRQ resources such as interrupt vector for PCI devices are allocated at pci_enable_device() time on i386, x86-64 and ia64 platform. Today, however, these IRQ resources are never deallocated even if they are no longer used. The following set of patches adds supports to deallocate IRQ resources at pci_disable_device() time. The motivation of the set of patches is as follows: - IRQ resources such as interrupt vectors should be freed if they are no longer used because the amount of these resources are limited. By deallocating IRQ resources, we can recycle them. - I think some hardwares will support hot-pluggable I/O units with I/O xAPICs in the near future. So I/O xAPIC hot-plug support by OS will be needed soon. IRQ resouces deallocation will be one of the most important stuff for I/O xAPIC hot-plug. For now, the following set of patches has ia64 implementation only. i386 and x86_64 implementations are TBD. This patch is ACPI portion of IRQ deallocation. This patch defines the following new interface. The implementation of this interface depends on each platform. o void acpi_unregister_gsi(u32 gsi) This is a opposite portion of acpi_register_gsi(). This has a responsibility for deallocating IRQ resources associated with the specified GSI number. We need to consider the case of shared interrupt. In the case of shared interrupt, acpi_register_gsi() is called multiple times for one gsi. That is, registrations and unregistrations can be nested. This function undoes the effect of one call to acpi_register_gsi(). If this matches the last registration, IRQ resources associated with the specified GSI number are freed. This patch also adds the following new function. o void acpi_pci_irq_disable (struct pci_dev *dev) This function is a opposite portion of acpi_pci_enable_irq(). It clears the device's linux IRQ number and calls acpi_unregister_gsi() to deallocate IRQ resources. Signed-off-by: Kenji Kaneshige Signed-off-by: Andrew Morton --- 25-akpm/drivers/acpi/pci_irq.c | 52 +++++++++++++++++++++++++++++++++++++++++ 25-akpm/include/linux/acpi.h | 13 ++++++++++ 2 files changed, 65 insertions(+) diff -puN drivers/acpi/pci_irq.c~irq-resource-deallocation-acpi drivers/acpi/pci_irq.c --- 25/drivers/acpi/pci_irq.c~irq-resource-deallocation-acpi 2004-12-09 22:40:07.646190880 -0800 +++ 25-akpm/drivers/acpi/pci_irq.c 2004-12-09 22:40:07.652189968 -0800 @@ -453,3 +453,55 @@ acpi_pci_irq_enable ( } EXPORT_SYMBOL(acpi_pci_irq_enable); + +#ifdef CONFIG_ACPI_DEALLOCATE_IRQ +void +acpi_pci_irq_disable ( + struct pci_dev *dev) +{ + u32 gsi = 0; + u8 pin = 0; + int edge_level = ACPI_LEVEL_SENSITIVE; + int active_high_low = ACPI_ACTIVE_LOW; + + ACPI_FUNCTION_TRACE("acpi_pci_irq_disable"); + + if (!dev) + return_VOID; + + pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); + if (!pin) + return_VOID; + pin--; + + if (!dev->bus) + return_VOID; + + /* + * First we check the PCI IRQ routing table (PRT) for an IRQ. + */ + gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin, + &edge_level, &active_high_low); + /* + * If no PRT entry was found, we'll try to derive an IRQ from the + * device's parent bridge. + */ + if (!gsi) + gsi = acpi_pci_irq_derive(dev, pin, + &edge_level, &active_high_low); + if (!gsi) + return_VOID; + + /* + * TBD: It might be worth clearing dev->irq by magic constant + * (e.g. PCI_UNDEFINED_IRQ). + */ + + printk(KERN_INFO PREFIX "PCI interrupt for device %s disabled\n", + pci_name(dev)); + + acpi_unregister_gsi(gsi); + + return_VOID; +} +#endif /* CONFIG_ACPI_DEALLOCATE_IRQ */ diff -puN include/linux/acpi.h~irq-resource-deallocation-acpi include/linux/acpi.h --- 25/include/linux/acpi.h~irq-resource-deallocation-acpi 2004-12-09 22:40:07.647190728 -0800 +++ 25-akpm/include/linux/acpi.h 2004-12-09 22:40:07.653189816 -0800 @@ -428,6 +428,15 @@ static inline int acpi_boot_table_init(v unsigned int acpi_register_gsi (u32 gsi, int edge_level, int active_high_low); int acpi_gsi_to_irq (u32 gsi, unsigned int *irq); +/* + * This function undoes the effect of one call to acpi_register_gsi(). + * If this matches the last registration, any IRQ resources for gsi + * are freed. + */ +#ifdef CONFIG_ACPI_DEALLOCATE_IRQ +void acpi_unregister_gsi (u32 gsi); +#endif + #ifdef CONFIG_ACPI_PCI struct acpi_prt_entry { @@ -453,6 +462,10 @@ struct pci_dev; int acpi_pci_irq_enable (struct pci_dev *dev); void acpi_penalize_isa_irq(int irq); +#ifdef CONFIG_ACPI_DEALLOCATE_IRQ +void acpi_pci_irq_disable (struct pci_dev *dev); +#endif + struct acpi_pci_driver { struct acpi_pci_driver *next; int (*add)(acpi_handle handle); _