pci_bind.c 3.3 KB

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