pci_bind.c 3.2 KB

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