acpi_pcihp.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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/moduleparam.h>
  28. #include <linux/kernel.h>
  29. #include <linux/types.h>
  30. #include <linux/pci.h>
  31. #include <acpi/acpi.h>
  32. #include <acpi/acpi_bus.h>
  33. #include <acpi/actypes.h>
  34. #include "pci_hotplug.h"
  35. #define MY_NAME "acpi_pcihp"
  36. #define dbg(fmt, arg...) do { if (debug_acpi) printk(KERN_DEBUG "%s: %s: " fmt , MY_NAME , __FUNCTION__ , ## arg); } while (0)
  37. #define err(format, arg...) printk(KERN_ERR "%s: " format , MY_NAME , ## arg)
  38. #define info(format, arg...) printk(KERN_INFO "%s: " format , MY_NAME , ## arg)
  39. #define warn(format, arg...) printk(KERN_WARNING "%s: " format , MY_NAME , ## arg)
  40. #define METHOD_NAME__SUN "_SUN"
  41. #define METHOD_NAME__HPP "_HPP"
  42. #define METHOD_NAME_OSHP "OSHP"
  43. static int debug_acpi;
  44. static acpi_status
  45. acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
  46. {
  47. acpi_status status;
  48. u8 nui[4];
  49. struct acpi_buffer ret_buf = { 0, NULL};
  50. struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
  51. union acpi_object *ext_obj, *package;
  52. int i, len = 0;
  53. acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
  54. /* get _hpp */
  55. status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
  56. switch (status) {
  57. case AE_BUFFER_OVERFLOW:
  58. ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
  59. if (!ret_buf.pointer) {
  60. printk(KERN_ERR "%s:%s alloc for _HPP fail\n",
  61. __FUNCTION__, (char *)string.pointer);
  62. kfree(string.pointer);
  63. return AE_NO_MEMORY;
  64. }
  65. status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
  66. NULL, &ret_buf);
  67. if (ACPI_SUCCESS(status))
  68. break;
  69. default:
  70. if (ACPI_FAILURE(status)) {
  71. pr_debug("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
  72. (char *)string.pointer, status);
  73. kfree(string.pointer);
  74. return status;
  75. }
  76. }
  77. ext_obj = (union acpi_object *) ret_buf.pointer;
  78. if (ext_obj->type != ACPI_TYPE_PACKAGE) {
  79. printk(KERN_ERR "%s:%s _HPP obj not a package\n", __FUNCTION__,
  80. (char *)string.pointer);
  81. status = AE_ERROR;
  82. goto free_and_return;
  83. }
  84. len = ext_obj->package.count;
  85. package = (union acpi_object *) ret_buf.pointer;
  86. for ( i = 0; (i < len) || (i < 4); i++) {
  87. ext_obj = (union acpi_object *) &package->package.elements[i];
  88. switch (ext_obj->type) {
  89. case ACPI_TYPE_INTEGER:
  90. nui[i] = (u8)ext_obj->integer.value;
  91. break;
  92. default:
  93. printk(KERN_ERR "%s:%s _HPP obj type incorrect\n",
  94. __FUNCTION__, (char *)string.pointer);
  95. status = AE_ERROR;
  96. goto free_and_return;
  97. }
  98. }
  99. hpp->cache_line_size = nui[0];
  100. hpp->latency_timer = nui[1];
  101. hpp->enable_serr = nui[2];
  102. hpp->enable_perr = nui[3];
  103. pr_debug(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size);
  104. pr_debug(" _HPP: latency timer =0x%x\n", hpp->latency_timer);
  105. pr_debug(" _HPP: enable SERR =0x%x\n", hpp->enable_serr);
  106. pr_debug(" _HPP: enable PERR =0x%x\n", hpp->enable_perr);
  107. free_and_return:
  108. kfree(string.pointer);
  109. kfree(ret_buf.pointer);
  110. return status;
  111. }
  112. /* acpi_run_oshp - get control of hotplug from the firmware
  113. *
  114. * @handle - the handle of the hotplug controller.
  115. */
  116. acpi_status acpi_run_oshp(acpi_handle handle)
  117. {
  118. acpi_status status;
  119. struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
  120. acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
  121. /* run OSHP */
  122. status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
  123. if (ACPI_FAILURE(status))
  124. if (status != AE_NOT_FOUND)
  125. printk(KERN_ERR "%s:%s OSHP fails=0x%x\n",
  126. __FUNCTION__, (char *)string.pointer, status);
  127. else
  128. dbg("%s:%s OSHP not found\n",
  129. __FUNCTION__, (char *)string.pointer);
  130. else
  131. pr_debug("%s:%s OSHP passes\n", __FUNCTION__,
  132. (char *)string.pointer);
  133. kfree(string.pointer);
  134. return status;
  135. }
  136. EXPORT_SYMBOL_GPL(acpi_run_oshp);
  137. /* acpi_get_hp_params_from_firmware
  138. *
  139. * @bus - the pci_bus of the bus on which the device is newly added
  140. * @hpp - allocated by the caller
  141. */
  142. acpi_status acpi_get_hp_params_from_firmware(struct pci_bus *bus,
  143. struct hotplug_params *hpp)
  144. {
  145. acpi_status status = AE_NOT_FOUND;
  146. acpi_handle handle, phandle;
  147. struct pci_bus *pbus = bus;
  148. struct pci_dev *pdev;
  149. do {
  150. pdev = pbus->self;
  151. if (!pdev) {
  152. handle = acpi_get_pci_rootbridge_handle(
  153. pci_domain_nr(pbus), pbus->number);
  154. break;
  155. }
  156. handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
  157. pbus = pbus->parent;
  158. } while (!handle);
  159. /*
  160. * _HPP settings apply to all child buses, until another _HPP is
  161. * encountered. If we don't find an _HPP for the input pci dev,
  162. * look for it in the parent device scope since that would apply to
  163. * this pci dev. If we don't find any _HPP, use hardcoded defaults
  164. */
  165. while (handle) {
  166. status = acpi_run_hpp(handle, hpp);
  167. if (ACPI_SUCCESS(status))
  168. break;
  169. if (acpi_root_bridge(handle))
  170. break;
  171. status = acpi_get_parent(handle, &phandle);
  172. if (ACPI_FAILURE(status))
  173. break;
  174. handle = phandle;
  175. }
  176. return status;
  177. }
  178. EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware);
  179. /* acpi_root_bridge - check to see if this acpi object is a root bridge
  180. *
  181. * @handle - the acpi object in question.
  182. */
  183. int acpi_root_bridge(acpi_handle handle)
  184. {
  185. acpi_status status;
  186. struct acpi_device_info *info;
  187. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  188. int i;
  189. status = acpi_get_object_info(handle, &buffer);
  190. if (ACPI_SUCCESS(status)) {
  191. info = buffer.pointer;
  192. if ((info->valid & ACPI_VALID_HID) &&
  193. !strcmp(PCI_ROOT_HID_STRING,
  194. info->hardware_id.value)) {
  195. kfree(buffer.pointer);
  196. return 1;
  197. }
  198. if (info->valid & ACPI_VALID_CID) {
  199. for (i=0; i < info->compatibility_id.count; i++) {
  200. if (!strcmp(PCI_ROOT_HID_STRING,
  201. info->compatibility_id.id[i].value)) {
  202. kfree(buffer.pointer);
  203. return 1;
  204. }
  205. }
  206. }
  207. kfree(buffer.pointer);
  208. }
  209. return 0;
  210. }
  211. EXPORT_SYMBOL_GPL(acpi_root_bridge);
  212. module_param(debug_acpi, bool, 0644);
  213. MODULE_PARM_DESC(debug_acpi, "Debugging mode for ACPI enabled or not");