acpi_pcihp.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Common ACPI functions for hot plug platforms
  3. *
  4. * Copyright (C) 2006 Intel Corporation
  5. *
  6. * All rights reserved.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  16. * NON INFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. *
  23. * Send feedback to <kristen.c.accardi@intel.com>
  24. *
  25. */
  26. #include <linux/module.h>
  27. #include <linux/kernel.h>
  28. #include <linux/types.h>
  29. #include <linux/pci.h>
  30. #include <acpi/acpi.h>
  31. #include <acpi/acpi_bus.h>
  32. #include <acpi/actypes.h>
  33. #include "pci_hotplug.h"
  34. #define METHOD_NAME__SUN "_SUN"
  35. #define METHOD_NAME__HPP "_HPP"
  36. #define METHOD_NAME_OSHP "OSHP"
  37. static acpi_status
  38. acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
  39. {
  40. acpi_status status;
  41. u8 nui[4];
  42. struct acpi_buffer ret_buf = { 0, NULL};
  43. struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
  44. union acpi_object *ext_obj, *package;
  45. int i, len = 0;
  46. acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
  47. /* get _hpp */
  48. status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
  49. switch (status) {
  50. case AE_BUFFER_OVERFLOW:
  51. ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
  52. if (!ret_buf.pointer) {
  53. printk(KERN_ERR "%s:%s alloc for _HPP fail\n",
  54. __FUNCTION__, (char *)string.pointer);
  55. acpi_os_free(string.pointer);
  56. return AE_NO_MEMORY;
  57. }
  58. status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
  59. NULL, &ret_buf);
  60. if (ACPI_SUCCESS(status))
  61. break;
  62. default:
  63. if (ACPI_FAILURE(status)) {
  64. pr_debug("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
  65. (char *)string.pointer, status);
  66. acpi_os_free(string.pointer);
  67. return status;
  68. }
  69. }
  70. ext_obj = (union acpi_object *) ret_buf.pointer;
  71. if (ext_obj->type != ACPI_TYPE_PACKAGE) {
  72. printk(KERN_ERR "%s:%s _HPP obj not a package\n", __FUNCTION__,
  73. (char *)string.pointer);
  74. status = AE_ERROR;
  75. goto free_and_return;
  76. }
  77. len = ext_obj->package.count;
  78. package = (union acpi_object *) ret_buf.pointer;
  79. for ( i = 0; (i < len) || (i < 4); i++) {
  80. ext_obj = (union acpi_object *) &package->package.elements[i];
  81. switch (ext_obj->type) {
  82. case ACPI_TYPE_INTEGER:
  83. nui[i] = (u8)ext_obj->integer.value;
  84. break;
  85. default:
  86. printk(KERN_ERR "%s:%s _HPP obj type incorrect\n",
  87. __FUNCTION__, (char *)string.pointer);
  88. status = AE_ERROR;
  89. goto free_and_return;
  90. }
  91. }
  92. hpp->cache_line_size = nui[0];
  93. hpp->latency_timer = nui[1];
  94. hpp->enable_serr = nui[2];
  95. hpp->enable_perr = nui[3];
  96. pr_debug(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size);
  97. pr_debug(" _HPP: latency timer =0x%x\n", hpp->latency_timer);
  98. pr_debug(" _HPP: enable SERR =0x%x\n", hpp->enable_serr);
  99. pr_debug(" _HPP: enable PERR =0x%x\n", hpp->enable_perr);
  100. free_and_return:
  101. acpi_os_free(string.pointer);
  102. acpi_os_free(ret_buf.pointer);
  103. return status;
  104. }
  105. /* acpi_run_oshp - get control of hotplug from the firmware
  106. *
  107. * @handle - the handle of the hotplug controller.
  108. */
  109. acpi_status acpi_run_oshp(acpi_handle handle)
  110. {
  111. acpi_status status;
  112. struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
  113. acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
  114. /* run OSHP */
  115. status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
  116. if (ACPI_FAILURE(status))
  117. printk(KERN_ERR "%s:%s OSHP fails=0x%x\n", __FUNCTION__,
  118. (char *)string.pointer, status);
  119. else
  120. pr_debug("%s:%s OSHP passes\n", __FUNCTION__,
  121. (char *)string.pointer);
  122. acpi_os_free(string.pointer);
  123. return status;
  124. }
  125. EXPORT_SYMBOL_GPL(acpi_run_oshp);
  126. /* acpi_get_hp_params_from_firmware
  127. *
  128. * @dev - the pci_dev of the newly added device
  129. * @hpp - allocated by the caller
  130. */
  131. acpi_status acpi_get_hp_params_from_firmware(struct pci_dev *dev,
  132. struct hotplug_params *hpp)
  133. {
  134. acpi_status status = AE_NOT_FOUND;
  135. struct pci_dev *pdev = dev;
  136. /*
  137. * _HPP settings apply to all child buses, until another _HPP is
  138. * encountered. If we don't find an _HPP for the input pci dev,
  139. * look for it in the parent device scope since that would apply to
  140. * this pci dev. If we don't find any _HPP, use hardcoded defaults
  141. */
  142. while (pdev && (ACPI_FAILURE(status))) {
  143. acpi_handle handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
  144. if (!handle)
  145. break;
  146. status = acpi_run_hpp(handle, hpp);
  147. if (!(pdev->bus->parent))
  148. break;
  149. /* Check if a parent object supports _HPP */
  150. pdev = pdev->bus->parent->self;
  151. }
  152. return status;
  153. }
  154. EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware);
  155. /* acpi_root_bridge - check to see if this acpi object is a root bridge
  156. *
  157. * @handle - the acpi object in question.
  158. */
  159. int acpi_root_bridge(acpi_handle handle)
  160. {
  161. acpi_status status;
  162. struct acpi_device_info *info;
  163. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  164. int i;
  165. status = acpi_get_object_info(handle, &buffer);
  166. if (ACPI_SUCCESS(status)) {
  167. info = buffer.pointer;
  168. if ((info->valid & ACPI_VALID_HID) &&
  169. !strcmp(PCI_ROOT_HID_STRING,
  170. info->hardware_id.value)) {
  171. acpi_os_free(buffer.pointer);
  172. return 1;
  173. }
  174. if (info->valid & ACPI_VALID_CID) {
  175. for (i=0; i < info->compatibility_id.count; i++) {
  176. if (!strcmp(PCI_ROOT_HID_STRING,
  177. info->compatibility_id.id[i].value)) {
  178. acpi_os_free(buffer.pointer);
  179. return 1;
  180. }
  181. }
  182. }
  183. acpi_os_free(buffer.pointer);
  184. }
  185. return 0;
  186. }
  187. EXPORT_SYMBOL_GPL(acpi_root_bridge);