pciehprm_acpi.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * PCIEHPRM ACPI: PHP Resource Manager for ACPI platform
  3. *
  4. * Copyright (C) 2003-2004 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 <linux/acpi.h>
  31. #include <linux/pci-acpi.h>
  32. #include <acpi/acpi_bus.h>
  33. #include <acpi/actypes.h>
  34. #include "pciehp.h"
  35. #define METHOD_NAME__SUN "_SUN"
  36. #define METHOD_NAME__HPP "_HPP"
  37. #define METHOD_NAME_OSHP "OSHP"
  38. static u8 * acpi_path_name( acpi_handle handle)
  39. {
  40. acpi_status status;
  41. static u8 path_name[ACPI_PATHNAME_MAX];
  42. struct acpi_buffer ret_buf = { ACPI_PATHNAME_MAX, path_name };
  43. memset(path_name, 0, sizeof (path_name));
  44. status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &ret_buf);
  45. if (ACPI_FAILURE(status))
  46. return NULL;
  47. else
  48. return path_name;
  49. }
  50. static acpi_status
  51. acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
  52. {
  53. acpi_status status;
  54. u8 nui[4];
  55. struct acpi_buffer ret_buf = { 0, NULL};
  56. union acpi_object *ext_obj, *package;
  57. u8 *path_name = acpi_path_name(handle);
  58. int i, len = 0;
  59. /* get _hpp */
  60. status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
  61. switch (status) {
  62. case AE_BUFFER_OVERFLOW:
  63. ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
  64. if (!ret_buf.pointer) {
  65. err ("%s:%s alloc for _HPP fail\n", __FUNCTION__,
  66. path_name);
  67. return AE_NO_MEMORY;
  68. }
  69. status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
  70. NULL, &ret_buf);
  71. if (ACPI_SUCCESS(status))
  72. break;
  73. default:
  74. if (ACPI_FAILURE(status)) {
  75. dbg("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
  76. path_name, status);
  77. return status;
  78. }
  79. }
  80. ext_obj = (union acpi_object *) ret_buf.pointer;
  81. if (ext_obj->type != ACPI_TYPE_PACKAGE) {
  82. err ("%s:%s _HPP obj not a package\n", __FUNCTION__,
  83. path_name);
  84. status = AE_ERROR;
  85. goto free_and_return;
  86. }
  87. len = ext_obj->package.count;
  88. package = (union acpi_object *) ret_buf.pointer;
  89. for ( i = 0; (i < len) || (i < 4); i++) {
  90. ext_obj = (union acpi_object *) &package->package.elements[i];
  91. switch (ext_obj->type) {
  92. case ACPI_TYPE_INTEGER:
  93. nui[i] = (u8)ext_obj->integer.value;
  94. break;
  95. default:
  96. err ("%s:%s _HPP obj type incorrect\n", __FUNCTION__,
  97. path_name);
  98. status = AE_ERROR;
  99. goto free_and_return;
  100. }
  101. }
  102. hpp->cache_line_size = nui[0];
  103. hpp->latency_timer = nui[1];
  104. hpp->enable_serr = nui[2];
  105. hpp->enable_perr = nui[3];
  106. dbg(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size);
  107. dbg(" _HPP: latency timer =0x%x\n", hpp->latency_timer);
  108. dbg(" _HPP: enable SERR =0x%x\n", hpp->enable_serr);
  109. dbg(" _HPP: enable PERR =0x%x\n", hpp->enable_perr);
  110. free_and_return:
  111. kfree(ret_buf.pointer);
  112. return status;
  113. }
  114. static acpi_status acpi_run_oshp(acpi_handle handle)
  115. {
  116. acpi_status status;
  117. u8 *path_name = acpi_path_name(handle);
  118. /* run OSHP */
  119. status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
  120. if (ACPI_FAILURE(status)) {
  121. dbg("%s:%s OSHP fails=0x%x\n", __FUNCTION__, path_name,
  122. status);
  123. } else {
  124. dbg("%s:%s OSHP passes\n", __FUNCTION__, path_name);
  125. }
  126. return status;
  127. }
  128. static int is_root_bridge(acpi_handle handle)
  129. {
  130. acpi_status status;
  131. struct acpi_device_info *info;
  132. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  133. int i;
  134. status = acpi_get_object_info(handle, &buffer);
  135. if (ACPI_SUCCESS(status)) {
  136. info = buffer.pointer;
  137. if ((info->valid & ACPI_VALID_HID) &&
  138. !strcmp(PCI_ROOT_HID_STRING,
  139. info->hardware_id.value)) {
  140. acpi_os_free(buffer.pointer);
  141. return 1;
  142. }
  143. if (info->valid & ACPI_VALID_CID) {
  144. for (i=0; i < info->compatibility_id.count; i++) {
  145. if (!strcmp(PCI_ROOT_HID_STRING,
  146. info->compatibility_id.id[i].value)) {
  147. acpi_os_free(buffer.pointer);
  148. return 1;
  149. }
  150. }
  151. }
  152. }
  153. return 0;
  154. }
  155. int pciehp_get_hp_hw_control_from_firmware(struct pci_dev *dev)
  156. {
  157. acpi_status status;
  158. acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
  159. struct pci_dev *pdev = dev;
  160. struct pci_bus *parent;
  161. u8 *path_name;
  162. /*
  163. * Per PCI firmware specification, we should run the ACPI _OSC
  164. * method to get control of hotplug hardware before using it.
  165. * If an _OSC is missing, we look for an OSHP to do the same thing.
  166. * To handle different BIOS behavior, we look for _OSC and OSHP
  167. * within the scope of the hotplug controller and its parents, upto
  168. * the host bridge under which this controller exists.
  169. */
  170. while (!handle) {
  171. /*
  172. * This hotplug controller was not listed in the ACPI name
  173. * space at all. Try to get acpi handle of parent pci bus.
  174. */
  175. if (!pdev || !pdev->bus->parent)
  176. break;
  177. parent = pdev->bus->parent;
  178. dbg("Could not find %s in acpi namespace, trying parent\n",
  179. pci_name(pdev));
  180. if (!parent->self)
  181. /* Parent must be a host bridge */
  182. handle = acpi_get_pci_rootbridge_handle(
  183. pci_domain_nr(parent),
  184. parent->number);
  185. else
  186. handle = DEVICE_ACPI_HANDLE(
  187. &(parent->self->dev));
  188. pdev = parent->self;
  189. }
  190. while (handle) {
  191. path_name = acpi_path_name(handle);
  192. dbg("Trying to get hotplug control for %s \n", path_name);
  193. status = pci_osc_control_set(handle,
  194. OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
  195. if (status == AE_NOT_FOUND)
  196. status = acpi_run_oshp(handle);
  197. if (ACPI_SUCCESS(status)) {
  198. dbg("Gained control for hotplug HW for pci %s (%s)\n",
  199. pci_name(dev), path_name);
  200. return 0;
  201. }
  202. if (is_root_bridge(handle))
  203. break;
  204. chandle = handle;
  205. status = acpi_get_parent(chandle, &handle);
  206. if (ACPI_FAILURE(status))
  207. break;
  208. }
  209. err("Cannot get control of hotplug hardware for pci %s\n",
  210. pci_name(dev));
  211. return -1;
  212. }
  213. void pciehp_get_hp_params_from_firmware(struct pci_dev *dev,
  214. struct hotplug_params *hpp)
  215. {
  216. acpi_status status = AE_NOT_FOUND;
  217. struct pci_dev *pdev = dev;
  218. /*
  219. * _HPP settings apply to all child buses, until another _HPP is
  220. * encountered. If we don't find an _HPP for the input pci dev,
  221. * look for it in the parent device scope since that would apply to
  222. * this pci dev. If we don't find any _HPP, use hardcoded defaults
  223. */
  224. while (pdev && (ACPI_FAILURE(status))) {
  225. acpi_handle handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
  226. if (!handle)
  227. break;
  228. status = acpi_run_hpp(handle, hpp);
  229. if (!(pdev->bus->parent))
  230. break;
  231. /* Check if a parent object supports _HPP */
  232. pdev = pdev->bus->parent->self;
  233. }
  234. }