pci_bind.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/pci-acpi.h>
  29. #include <linux/acpi.h>
  30. #include <linux/pm_runtime.h>
  31. #include <acpi/acpi_bus.h>
  32. #include <acpi/acpi_drivers.h>
  33. #define _COMPONENT ACPI_PCI_COMPONENT
  34. ACPI_MODULE_NAME("pci_bind");
  35. static int acpi_pci_unbind(struct acpi_device *device)
  36. {
  37. struct pci_dev *dev;
  38. dev = acpi_get_pci_dev(device->handle);
  39. if (!dev)
  40. goto out;
  41. device_set_run_wake(&dev->dev, false);
  42. pci_acpi_remove_pm_notifier(device);
  43. if (!dev->subordinate)
  44. goto out;
  45. acpi_pci_irq_del_prt(dev->subordinate);
  46. device->ops.bind = NULL;
  47. device->ops.unbind = NULL;
  48. out:
  49. pci_dev_put(dev);
  50. return 0;
  51. }
  52. static int acpi_pci_bind(struct acpi_device *device)
  53. {
  54. acpi_status status;
  55. acpi_handle handle;
  56. struct pci_bus *bus;
  57. struct pci_dev *dev;
  58. dev = acpi_get_pci_dev(device->handle);
  59. if (!dev)
  60. return 0;
  61. pci_acpi_add_pm_notifier(device, dev);
  62. if (device->wakeup.flags.run_wake)
  63. device_set_run_wake(&dev->dev, true);
  64. /*
  65. * Install the 'bind' function to facilitate callbacks for
  66. * children of the P2P bridge.
  67. */
  68. if (dev->subordinate) {
  69. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  70. "Device %04x:%02x:%02x.%d is a PCI bridge\n",
  71. pci_domain_nr(dev->bus), dev->bus->number,
  72. PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)));
  73. device->ops.bind = acpi_pci_bind;
  74. device->ops.unbind = acpi_pci_unbind;
  75. }
  76. /*
  77. * Evaluate and parse _PRT, if exists. This code allows parsing of
  78. * _PRT objects within the scope of non-bridge devices. Note that
  79. * _PRTs within the scope of a PCI bridge assume the bridge's
  80. * subordinate bus number.
  81. *
  82. * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?
  83. */
  84. status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
  85. if (ACPI_FAILURE(status))
  86. goto out;
  87. if (dev->subordinate)
  88. bus = dev->subordinate;
  89. else
  90. bus = dev->bus;
  91. acpi_pci_irq_add_prt(device->handle, bus);
  92. out:
  93. pci_dev_put(dev);
  94. return 0;
  95. }
  96. int acpi_pci_bind_root(struct acpi_device *device)
  97. {
  98. device->ops.bind = acpi_pci_bind;
  99. device->ops.unbind = acpi_pci_unbind;
  100. return 0;
  101. }