pciehprm_acpi.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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/config.h>
  27. #include <linux/module.h>
  28. #include <linux/kernel.h>
  29. #include <linux/types.h>
  30. #include <linux/pci.h>
  31. #include <linux/init.h>
  32. #include <linux/acpi.h>
  33. #include <linux/efi.h>
  34. #include <linux/pci-acpi.h>
  35. #include <asm/uaccess.h>
  36. #include <asm/system.h>
  37. #include <acpi/acpi.h>
  38. #include <acpi/acpi_bus.h>
  39. #include <acpi/actypes.h>
  40. #include "pciehp.h"
  41. #define METHOD_NAME__SUN "_SUN"
  42. #define METHOD_NAME__HPP "_HPP"
  43. #define METHOD_NAME_OSHP "OSHP"
  44. static u8 * acpi_path_name( acpi_handle handle)
  45. {
  46. acpi_status status;
  47. static u8 path_name[ACPI_PATHNAME_MAX];
  48. struct acpi_buffer ret_buf = { ACPI_PATHNAME_MAX, path_name };
  49. memset(path_name, 0, sizeof (path_name));
  50. status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &ret_buf);
  51. if (ACPI_FAILURE(status))
  52. return NULL;
  53. else
  54. return path_name;
  55. }
  56. static acpi_status
  57. acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
  58. {
  59. acpi_status status;
  60. u8 nui[4];
  61. struct acpi_buffer ret_buf = { 0, NULL};
  62. union acpi_object *ext_obj, *package;
  63. u8 *path_name = acpi_path_name(handle);
  64. int i, len = 0;
  65. /* get _hpp */
  66. status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
  67. switch (status) {
  68. case AE_BUFFER_OVERFLOW:
  69. ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
  70. if (!ret_buf.pointer) {
  71. err ("%s:%s alloc for _HPP fail\n", __FUNCTION__,
  72. path_name);
  73. return AE_NO_MEMORY;
  74. }
  75. status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
  76. NULL, &ret_buf);
  77. if (ACPI_SUCCESS(status))
  78. break;
  79. default:
  80. if (ACPI_FAILURE(status)) {
  81. dbg("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
  82. path_name, status);
  83. return status;
  84. }
  85. }
  86. ext_obj = (union acpi_object *) ret_buf.pointer;
  87. if (ext_obj->type != ACPI_TYPE_PACKAGE) {
  88. err ("%s:%s _HPP obj not a package\n", __FUNCTION__,
  89. path_name);
  90. status = AE_ERROR;
  91. goto free_and_return;
  92. }
  93. len = ext_obj->package.count;
  94. package = (union acpi_object *) ret_buf.pointer;
  95. for ( i = 0; (i < len) || (i < 4); i++) {
  96. ext_obj = (union acpi_object *) &package->package.elements[i];
  97. switch (ext_obj->type) {
  98. case ACPI_TYPE_INTEGER:
  99. nui[i] = (u8)ext_obj->integer.value;
  100. break;
  101. default:
  102. err ("%s:%s _HPP obj type incorrect\n", __FUNCTION__,
  103. path_name);
  104. status = AE_ERROR;
  105. goto free_and_return;
  106. }
  107. }
  108. hpp->cache_line_size = nui[0];
  109. hpp->latency_timer = nui[1];
  110. hpp->enable_serr = nui[2];
  111. hpp->enable_perr = nui[3];
  112. dbg(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size);
  113. dbg(" _HPP: latency timer =0x%x\n", hpp->latency_timer);
  114. dbg(" _HPP: enable SERR =0x%x\n", hpp->enable_serr);
  115. dbg(" _HPP: enable PERR =0x%x\n", hpp->enable_perr);
  116. free_and_return:
  117. kfree(ret_buf.pointer);
  118. return status;
  119. }
  120. static acpi_status acpi_run_oshp(acpi_handle handle)
  121. {
  122. acpi_status status;
  123. u8 *path_name = acpi_path_name(handle);
  124. /* run OSHP */
  125. status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
  126. if (ACPI_FAILURE(status)) {
  127. err("%s:%s OSHP fails=0x%x\n", __FUNCTION__, path_name,
  128. status);
  129. } else {
  130. dbg("%s:%s OSHP passes\n", __FUNCTION__, path_name);
  131. }
  132. return status;
  133. }
  134. int get_hp_hw_control_from_firmware(struct pci_dev *dev)
  135. {
  136. acpi_status status;
  137. /*
  138. * Per PCI firmware specification, we should run the ACPI _OSC
  139. * method to get control of hotplug hardware before using it
  140. */
  141. /* Fixme: run _OSC for a specific host bridge, not all of them */
  142. status = pci_osc_control_set(OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
  143. /* Fixme: fail native hotplug if _OSC does not exist for root ports */
  144. if (status == AE_NOT_FOUND) {
  145. /*
  146. * Some older BIOS's don't support _OSC but support
  147. * OSHP to do the same thing
  148. */
  149. acpi_handle handle = DEVICE_ACPI_HANDLE(&(dev->dev));
  150. if (handle)
  151. status = acpi_run_oshp(handle);
  152. }
  153. if (ACPI_FAILURE(status)) {
  154. err("Cannot get control of hotplug hardware\n");
  155. return -1;
  156. }
  157. dbg("Sucess getting control of hotplug hardware\n");
  158. return 0;
  159. }
  160. void get_hp_params_from_firmware(struct pci_dev *dev,
  161. struct hotplug_params *hpp)
  162. {
  163. acpi_status status = AE_NOT_FOUND;
  164. struct pci_dev *pdev = dev;
  165. /*
  166. * _HPP settings apply to all child buses, until another _HPP is
  167. * encountered. If we don't find an _HPP for the input pci dev,
  168. * look for it in the parent device scope since that would apply to
  169. * this pci dev. If we don't find any _HPP, use hardcoded defaults
  170. */
  171. while (pdev && (ACPI_FAILURE(status))) {
  172. acpi_handle handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
  173. if (!handle)
  174. break;
  175. status = acpi_run_hpp(handle, hpp);
  176. if (!(pdev->bus->parent))
  177. break;
  178. /* Check if a parent object supports _HPP */
  179. pdev = pdev->bus->parent->self;
  180. }
  181. }