| Bjorn Helgaas | 204d49a | 2009-10-26 11:20:47 -0600 | [diff] [blame] | 1 | /* | 
|  | 2 | * IOAPIC/IOxAPIC/IOSAPIC driver | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 2009 Fujitsu Limited. | 
|  | 5 | * (c) Copyright 2009 Hewlett-Packard Development Company, L.P. | 
|  | 6 | * | 
|  | 7 | * This program is free software; you can redistribute it and/or modify | 
|  | 8 | * it under the terms of the GNU General Public License version 2 as | 
|  | 9 | * published by the Free Software Foundation. | 
|  | 10 | */ | 
|  | 11 |  | 
|  | 12 | /* | 
|  | 13 | * This driver manages PCI I/O APICs added by hotplug after boot.  We try to | 
|  | 14 | * claim all I/O APIC PCI devices, but those present at boot were registered | 
|  | 15 | * when we parsed the ACPI MADT, so we'll fail when we try to re-register | 
|  | 16 | * them. | 
|  | 17 | */ | 
|  | 18 |  | 
|  | 19 | #include <linux/pci.h> | 
| Paul Gortmaker | 363c75d | 2011-05-27 09:37:25 -0400 | [diff] [blame] | 20 | #include <linux/export.h> | 
| Bjorn Helgaas | 204d49a | 2009-10-26 11:20:47 -0600 | [diff] [blame] | 21 | #include <linux/acpi.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> | 
| Bjorn Helgaas | 204d49a | 2009-10-26 11:20:47 -0600 | [diff] [blame] | 23 | #include <acpi/acpi_bus.h> | 
|  | 24 |  | 
|  | 25 | struct ioapic { | 
|  | 26 | acpi_handle	handle; | 
|  | 27 | u32		gsi_base; | 
|  | 28 | }; | 
|  | 29 |  | 
|  | 30 | static int ioapic_probe(struct pci_dev *dev, const struct pci_device_id *ent) | 
|  | 31 | { | 
|  | 32 | acpi_handle handle; | 
|  | 33 | acpi_status status; | 
|  | 34 | unsigned long long gsb; | 
|  | 35 | struct ioapic *ioapic; | 
| Bjorn Helgaas | 204d49a | 2009-10-26 11:20:47 -0600 | [diff] [blame] | 36 | int ret; | 
|  | 37 | char *type; | 
| Bjorn Helgaas | e1944c6 | 2010-03-16 15:53:08 -0600 | [diff] [blame] | 38 | struct resource *res; | 
| Bjorn Helgaas | 204d49a | 2009-10-26 11:20:47 -0600 | [diff] [blame] | 39 |  | 
|  | 40 | handle = DEVICE_ACPI_HANDLE(&dev->dev); | 
|  | 41 | if (!handle) | 
|  | 42 | return -EINVAL; | 
|  | 43 |  | 
|  | 44 | status = acpi_evaluate_integer(handle, "_GSB", NULL, &gsb); | 
|  | 45 | if (ACPI_FAILURE(status)) | 
|  | 46 | return -EINVAL; | 
|  | 47 |  | 
|  | 48 | /* | 
|  | 49 | * The previous code in acpiphp evaluated _MAT if _GSB failed, but | 
|  | 50 | * ACPI spec 4.0 sec 6.2.2 requires _GSB for hot-pluggable I/O APICs. | 
|  | 51 | */ | 
|  | 52 |  | 
|  | 53 | ioapic = kzalloc(sizeof(*ioapic), GFP_KERNEL); | 
|  | 54 | if (!ioapic) | 
|  | 55 | return -ENOMEM; | 
|  | 56 |  | 
|  | 57 | ioapic->handle = handle; | 
|  | 58 | ioapic->gsi_base = (u32) gsb; | 
|  | 59 |  | 
|  | 60 | if (dev->class == PCI_CLASS_SYSTEM_PIC_IOAPIC) | 
|  | 61 | type = "IOAPIC"; | 
|  | 62 | else | 
|  | 63 | type = "IOxAPIC"; | 
|  | 64 |  | 
|  | 65 | ret = pci_enable_device(dev); | 
|  | 66 | if (ret < 0) | 
|  | 67 | goto exit_free; | 
|  | 68 |  | 
|  | 69 | pci_set_master(dev); | 
|  | 70 |  | 
|  | 71 | if (pci_request_region(dev, 0, type)) | 
|  | 72 | goto exit_disable; | 
|  | 73 |  | 
| Bjorn Helgaas | e1944c6 | 2010-03-16 15:53:08 -0600 | [diff] [blame] | 74 | res = &dev->resource[0]; | 
|  | 75 | if (acpi_register_ioapic(ioapic->handle, res->start, ioapic->gsi_base)) | 
| Bjorn Helgaas | 204d49a | 2009-10-26 11:20:47 -0600 | [diff] [blame] | 76 | goto exit_release; | 
|  | 77 |  | 
|  | 78 | pci_set_drvdata(dev, ioapic); | 
| Bjorn Helgaas | e1944c6 | 2010-03-16 15:53:08 -0600 | [diff] [blame] | 79 | dev_info(&dev->dev, "%s at %pR, GSI %u\n", type, res, ioapic->gsi_base); | 
| Bjorn Helgaas | 204d49a | 2009-10-26 11:20:47 -0600 | [diff] [blame] | 80 | return 0; | 
|  | 81 |  | 
|  | 82 | exit_release: | 
|  | 83 | pci_release_region(dev, 0); | 
|  | 84 | exit_disable: | 
|  | 85 | pci_disable_device(dev); | 
|  | 86 | exit_free: | 
|  | 87 | kfree(ioapic); | 
|  | 88 | return -ENODEV; | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | static void ioapic_remove(struct pci_dev *dev) | 
|  | 92 | { | 
|  | 93 | struct ioapic *ioapic = pci_get_drvdata(dev); | 
|  | 94 |  | 
|  | 95 | acpi_unregister_ioapic(ioapic->handle, ioapic->gsi_base); | 
|  | 96 | pci_release_region(dev, 0); | 
|  | 97 | pci_disable_device(dev); | 
|  | 98 | kfree(ioapic); | 
|  | 99 | } | 
|  | 100 |  | 
|  | 101 |  | 
|  | 102 | static struct pci_device_id ioapic_devices[] = { | 
|  | 103 | { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, | 
|  | 104 | PCI_CLASS_SYSTEM_PIC_IOAPIC << 8, 0xffff00, }, | 
|  | 105 | { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, | 
|  | 106 | PCI_CLASS_SYSTEM_PIC_IOXAPIC << 8, 0xffff00, }, | 
|  | 107 | { } | 
|  | 108 | }; | 
|  | 109 |  | 
|  | 110 | static struct pci_driver ioapic_driver = { | 
|  | 111 | .name		= "ioapic", | 
|  | 112 | .id_table	= ioapic_devices, | 
|  | 113 | .probe		= ioapic_probe, | 
|  | 114 | .remove		= __devexit_p(ioapic_remove), | 
|  | 115 | }; | 
|  | 116 |  | 
|  | 117 | static int __init ioapic_init(void) | 
|  | 118 | { | 
|  | 119 | return pci_register_driver(&ioapic_driver); | 
|  | 120 | } | 
|  | 121 |  | 
|  | 122 | static void __exit ioapic_exit(void) | 
|  | 123 | { | 
|  | 124 | pci_unregister_driver(&ioapic_driver); | 
|  | 125 | } | 
|  | 126 |  | 
|  | 127 | module_init(ioapic_init); | 
|  | 128 | module_exit(ioapic_exit); |