pci_bind.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * pci_bind.c - ACPI PCI Device Binding ($Revision: 2 $)
  3. *
  4. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  5. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  6. *
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or (at
  12. * your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  22. *
  23. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/types.h>
  27. #include <linux/pci.h>
  28. #include <linux/acpi.h>
  29. #include <acpi/acpi_bus.h>
  30. #include <acpi/acpi_drivers.h>
  31. #define _COMPONENT ACPI_PCI_COMPONENT
  32. ACPI_MODULE_NAME("pci_bind");
  33. static int acpi_pci_unbind(struct acpi_device *device)
  34. {
  35. struct pci_dev *dev;
  36. dev = acpi_get_pci_dev(device->handle);
  37. if (!dev || !dev->subordinate)
  38. goto out;
  39. acpi_pci_irq_del_prt(dev->subordinate);
  40. device->ops.bind = NULL;
  41. device->ops.unbind = NULL;
  42. out:
  43. pci_dev_put(dev);
  44. return 0;
  45. }
  46. static int acpi_pci_bind(struct acpi_device *device)
  47. {
  48. acpi_status status;
  49. acpi_handle handle;
  50. struct pci_bus *bus;
  51. struct pci_dev *dev;
  52. dev = acpi_get_pci_dev(device->handle);
  53. if (!dev)
  54. return 0;
  55. /*
  56. * Install the 'bind' function to facilitate callbacks for
  57. * children of the P2P bridge.
  58. */
  59. if (dev->subordinate) {
  60. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  61. "Device %04x:%02x:%02x.%d is a PCI bridge\n",
  62. pci_domain_nr(dev->bus), dev->bus->number,
  63. PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)));
  64. device->ops.bind = acpi_pci_bind;
  65. device->ops.unbind = acpi_pci_unbind;
  66. }
  67. /*
  68. * Evaluate and parse _PRT, if exists. This code allows parsing of
  69. * _PRT objects within the scope of non-bridge devices. Note that
  70. * _PRTs within the scope of a PCI bridge assume the bridge's
  71. * subordinate bus number.
  72. *
  73. * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?
  74. */
  75. status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
  76. if (ACPI_FAILURE(status))
  77. goto out;
  78. if (dev->subordinate)
  79. bus = dev->subordinate;
  80. else
  81. bus = dev->bus;
  82. acpi_pci_irq_add_prt(device->handle, bus);
  83. out:
  84. pci_dev_put(dev);
  85. return 0;
  86. }
  87. int acpi_pci_bind_root(struct acpi_device *device)
  88. {
  89. device->ops.bind = acpi_pci_bind;
  90. device->ops.unbind = acpi_pci_unbind;
  91. return 0;
  92. }