pciehp_acpi.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * ACPI related functions for PCI Express Hot Plug driver.
  3. *
  4. * Copyright (C) 2008 Kenji Kaneshige
  5. * Copyright (C) 2008 Fujitsu Limited.
  6. *
  7. * All rights reserved.
  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, GOOD TITLE or
  17. * NON INFRINGEMENT. See the GNU General Public License for more
  18. * details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include <linux/acpi.h>
  26. #include <linux/pci.h>
  27. #include <linux/pci_hotplug.h>
  28. #include "pciehp.h"
  29. #define PCIEHP_DETECT_PCIE (0)
  30. #define PCIEHP_DETECT_ACPI (1)
  31. #define PCIEHP_DETECT_AUTO (2)
  32. #define PCIEHP_DETECT_DEFAULT PCIEHP_DETECT_AUTO
  33. struct dummy_slot {
  34. u32 number;
  35. struct list_head list;
  36. };
  37. static int slot_detection_mode;
  38. static char *pciehp_detect_mode;
  39. module_param(pciehp_detect_mode, charp, 0444);
  40. MODULE_PARM_DESC(pciehp_detect_mode,
  41. "Slot detection mode: pcie, acpi, auto\n"
  42. " pcie - Use PCIe based slot detection\n"
  43. " acpi - Use ACPI for slot detection\n"
  44. " auto(default) - Auto select mode. Use acpi option if duplicate\n"
  45. " slot ids are found. Otherwise, use pcie option\n");
  46. int pciehp_acpi_slot_detection_check(struct pci_dev *dev)
  47. {
  48. if (slot_detection_mode != PCIEHP_DETECT_ACPI)
  49. return 0;
  50. if (acpi_pci_detect_ejectable(DEVICE_ACPI_HANDLE(&dev->dev)))
  51. return 0;
  52. return -ENODEV;
  53. }
  54. static int __init parse_detect_mode(void)
  55. {
  56. if (!pciehp_detect_mode)
  57. return PCIEHP_DETECT_DEFAULT;
  58. if (!strcmp(pciehp_detect_mode, "pcie"))
  59. return PCIEHP_DETECT_PCIE;
  60. if (!strcmp(pciehp_detect_mode, "acpi"))
  61. return PCIEHP_DETECT_ACPI;
  62. if (!strcmp(pciehp_detect_mode, "auto"))
  63. return PCIEHP_DETECT_AUTO;
  64. warn("bad specifier '%s' for pciehp_detect_mode. Use default\n",
  65. pciehp_detect_mode);
  66. return PCIEHP_DETECT_DEFAULT;
  67. }
  68. static int __initdata dup_slot_id;
  69. static int __initdata acpi_slot_detected;
  70. static struct list_head __initdata dummy_slots = LIST_HEAD_INIT(dummy_slots);
  71. /* Dummy driver for dumplicate name detection */
  72. static int __init dummy_probe(struct pcie_device *dev)
  73. {
  74. int pos;
  75. u32 slot_cap;
  76. acpi_handle handle;
  77. struct dummy_slot *slot, *tmp;
  78. struct pci_dev *pdev = dev->port;
  79. /* Note: pciehp_detect_mode != PCIEHP_DETECT_ACPI here */
  80. if (pciehp_get_hp_hw_control_from_firmware(pdev))
  81. return -ENODEV;
  82. pos = pci_pcie_cap(pdev);
  83. if (!pos)
  84. return -ENODEV;
  85. pci_read_config_dword(pdev, pos + PCI_EXP_SLTCAP, &slot_cap);
  86. slot = kzalloc(sizeof(*slot), GFP_KERNEL);
  87. if (!slot)
  88. return -ENOMEM;
  89. slot->number = slot_cap >> 19;
  90. list_for_each_entry(tmp, &dummy_slots, list) {
  91. if (tmp->number == slot->number)
  92. dup_slot_id++;
  93. }
  94. list_add_tail(&slot->list, &dummy_slots);
  95. handle = DEVICE_ACPI_HANDLE(&pdev->dev);
  96. if (!acpi_slot_detected && acpi_pci_detect_ejectable(handle))
  97. acpi_slot_detected = 1;
  98. return -ENODEV; /* dummy driver always returns error */
  99. }
  100. static struct pcie_port_service_driver __initdata dummy_driver = {
  101. .name = "pciehp_dummy",
  102. .port_type = PCIE_ANY_PORT,
  103. .service = PCIE_PORT_SERVICE_HP,
  104. .probe = dummy_probe,
  105. };
  106. static int __init select_detection_mode(void)
  107. {
  108. struct dummy_slot *slot, *tmp;
  109. pcie_port_service_register(&dummy_driver);
  110. pcie_port_service_unregister(&dummy_driver);
  111. list_for_each_entry_safe(slot, tmp, &dummy_slots, list) {
  112. list_del(&slot->list);
  113. kfree(slot);
  114. }
  115. if (acpi_slot_detected && dup_slot_id)
  116. return PCIEHP_DETECT_ACPI;
  117. return PCIEHP_DETECT_PCIE;
  118. }
  119. void __init pciehp_acpi_slot_detection_init(void)
  120. {
  121. slot_detection_mode = parse_detect_mode();
  122. if (slot_detection_mode != PCIEHP_DETECT_AUTO)
  123. goto out;
  124. slot_detection_mode = select_detection_mode();
  125. out:
  126. if (slot_detection_mode == PCIEHP_DETECT_ACPI)
  127. info("Using ACPI for slot detection.\n");
  128. }