pci_bind.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. struct acpi_pci_data {
  34. struct acpi_pci_id id;
  35. struct pci_bus *bus;
  36. struct pci_dev *dev;
  37. };
  38. static int acpi_pci_bind(struct acpi_device *device);
  39. static int acpi_pci_unbind(struct acpi_device *device);
  40. static void acpi_pci_data_handler(acpi_handle handle, u32 function,
  41. void *context)
  42. {
  43. /* TBD: Anything we need to do here? */
  44. return;
  45. }
  46. /**
  47. * acpi_get_pci_id
  48. * ------------------
  49. * This function is used by the ACPI Interpreter (a.k.a. Core Subsystem)
  50. * to resolve PCI information for ACPI-PCI devices defined in the namespace.
  51. * This typically occurs when resolving PCI operation region information.
  52. */
  53. acpi_status acpi_get_pci_id(acpi_handle handle, struct acpi_pci_id *id)
  54. {
  55. int result = 0;
  56. acpi_status status = AE_OK;
  57. struct acpi_device *device = NULL;
  58. struct acpi_pci_data *data = NULL;
  59. if (!id)
  60. return AE_BAD_PARAMETER;
  61. result = acpi_bus_get_device(handle, &device);
  62. if (result) {
  63. printk(KERN_ERR PREFIX
  64. "Invalid ACPI Bus context for device %s\n",
  65. acpi_device_bid(device));
  66. return AE_NOT_EXIST;
  67. }
  68. status = acpi_get_data(handle, acpi_pci_data_handler, (void **)&data);
  69. if (ACPI_FAILURE(status) || !data) {
  70. ACPI_EXCEPTION((AE_INFO, status,
  71. "Invalid ACPI-PCI context for device %s",
  72. acpi_device_bid(device)));
  73. return status;
  74. }
  75. *id = data->id;
  76. /*
  77. id->segment = data->id.segment;
  78. id->bus = data->id.bus;
  79. id->device = data->id.device;
  80. id->function = data->id.function;
  81. */
  82. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  83. "Device %s has PCI address %04x:%02x:%02x.%d\n",
  84. acpi_device_bid(device), id->segment, id->bus,
  85. id->device, id->function));
  86. return AE_OK;
  87. }
  88. EXPORT_SYMBOL(acpi_get_pci_id);
  89. static int acpi_pci_unbind(struct acpi_device *device)
  90. {
  91. struct pci_dev *dev;
  92. dev = acpi_get_pci_dev(device->handle);
  93. if (!dev)
  94. return 0;
  95. if (dev->subordinate)
  96. acpi_pci_irq_del_prt(pci_domain_nr(dev->bus),
  97. dev->subordinate->number);
  98. pci_dev_put(dev);
  99. return 0;
  100. }
  101. static int acpi_pci_bind(struct acpi_device *device)
  102. {
  103. acpi_status status;
  104. acpi_handle handle;
  105. unsigned char bus;
  106. struct pci_dev *dev;
  107. dev = acpi_get_pci_dev(device->handle);
  108. if (!dev)
  109. return 0;
  110. /*
  111. * Install the 'bind' function to facilitate callbacks for
  112. * children of the P2P bridge.
  113. */
  114. if (dev->subordinate) {
  115. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  116. "Device %04x:%02x:%02x.%d is a PCI bridge\n",
  117. pci_domain_nr(dev->bus), dev->bus->number,
  118. PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)));
  119. device->ops.bind = acpi_pci_bind;
  120. device->ops.unbind = acpi_pci_unbind;
  121. }
  122. /*
  123. * Evaluate and parse _PRT, if exists. This code allows parsing of
  124. * _PRT objects within the scope of non-bridge devices. Note that
  125. * _PRTs within the scope of a PCI bridge assume the bridge's
  126. * subordinate bus number.
  127. *
  128. * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?
  129. */
  130. status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
  131. if (ACPI_FAILURE(status))
  132. goto out;
  133. if (dev->subordinate)
  134. bus = dev->subordinate->number;
  135. else
  136. bus = dev->bus->number;
  137. acpi_pci_irq_add_prt(device->handle, pci_domain_nr(dev->bus), bus);
  138. out:
  139. pci_dev_put(dev);
  140. return 0;
  141. }
  142. int acpi_pci_bind_root(struct acpi_device *device)
  143. {
  144. device->ops.bind = acpi_pci_bind;
  145. device->ops.unbind = acpi_pci_unbind;
  146. return 0;
  147. }