shpchprm_acpi.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * SHPCHPRM 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 <asm/uaccess.h>
  35. #include <asm/system.h>
  36. #include <acpi/acpi.h>
  37. #include <acpi/acpi_bus.h>
  38. #include <acpi/actypes.h>
  39. #include "shpchp.h"
  40. #define METHOD_NAME__SUN "_SUN"
  41. #define METHOD_NAME__HPP "_HPP"
  42. #define METHOD_NAME_OSHP "OSHP"
  43. static u8 * acpi_path_name( acpi_handle handle)
  44. {
  45. acpi_status status;
  46. static u8 path_name[ACPI_PATHNAME_MAX];
  47. struct acpi_buffer ret_buf = { ACPI_PATHNAME_MAX, path_name };
  48. memset(path_name, 0, sizeof (path_name));
  49. status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &ret_buf);
  50. if (ACPI_FAILURE(status))
  51. return NULL;
  52. else
  53. return path_name;
  54. }
  55. static acpi_status
  56. acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
  57. {
  58. acpi_status status;
  59. u8 nui[4];
  60. struct acpi_buffer ret_buf = { 0, NULL};
  61. union acpi_object *ext_obj, *package;
  62. u8 *path_name = acpi_path_name(handle);
  63. int i, len = 0;
  64. /* get _hpp */
  65. status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
  66. switch (status) {
  67. case AE_BUFFER_OVERFLOW:
  68. ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
  69. if (!ret_buf.pointer) {
  70. err ("%s:%s alloc for _HPP fail\n", __FUNCTION__,
  71. path_name);
  72. return AE_NO_MEMORY;
  73. }
  74. status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
  75. NULL, &ret_buf);
  76. if (ACPI_SUCCESS(status))
  77. break;
  78. default:
  79. if (ACPI_FAILURE(status)) {
  80. dbg("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
  81. path_name, status);
  82. return status;
  83. }
  84. }
  85. ext_obj = (union acpi_object *) ret_buf.pointer;
  86. if (ext_obj->type != ACPI_TYPE_PACKAGE) {
  87. err ("%s:%s _HPP obj not a package\n", __FUNCTION__,
  88. path_name);
  89. status = AE_ERROR;
  90. goto free_and_return;
  91. }
  92. len = ext_obj->package.count;
  93. package = (union acpi_object *) ret_buf.pointer;
  94. for ( i = 0; (i < len) || (i < 4); i++) {
  95. ext_obj = (union acpi_object *) &package->package.elements[i];
  96. switch (ext_obj->type) {
  97. case ACPI_TYPE_INTEGER:
  98. nui[i] = (u8)ext_obj->integer.value;
  99. break;
  100. default:
  101. err ("%s:%s _HPP obj type incorrect\n", __FUNCTION__,
  102. path_name);
  103. status = AE_ERROR;
  104. goto free_and_return;
  105. }
  106. }
  107. hpp->cache_line_size = nui[0];
  108. hpp->latency_timer = nui[1];
  109. hpp->enable_serr = nui[2];
  110. hpp->enable_perr = nui[3];
  111. dbg(" _HPP: cache_line_size=0x%x\n", hpp->cache_line_size);
  112. dbg(" _HPP: latency timer =0x%x\n", hpp->latency_timer);
  113. dbg(" _HPP: enable SERR =0x%x\n", hpp->enable_serr);
  114. dbg(" _HPP: enable PERR =0x%x\n", hpp->enable_perr);
  115. free_and_return:
  116. kfree(ret_buf.pointer);
  117. return status;
  118. }
  119. static void acpi_run_oshp(acpi_handle handle)
  120. {
  121. acpi_status status;
  122. u8 *path_name = acpi_path_name(handle);
  123. /* run OSHP */
  124. status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
  125. if (ACPI_FAILURE(status)) {
  126. err("%s:%s OSHP fails=0x%x\n", __FUNCTION__, path_name,
  127. status);
  128. } else {
  129. dbg("%s:%s OSHP passes\n", __FUNCTION__, path_name);
  130. }
  131. }
  132. int shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun, u8 busnum, u8 devnum)
  133. {
  134. int offset = devnum - ctrl->slot_device_offset;
  135. dbg("%s: ctrl->slot_num_inc %d, offset %d\n", __FUNCTION__, ctrl->slot_num_inc, offset);
  136. *sun = (u8) (ctrl->first_slot + ctrl->slot_num_inc *offset);
  137. return 0;
  138. }
  139. void get_hp_hw_control_from_firmware(struct pci_dev *dev)
  140. {
  141. /*
  142. * OSHP is an optional ACPI firmware control method. If present,
  143. * we need to run it to inform BIOS that we will control SHPC
  144. * hardware from now on.
  145. */
  146. acpi_handle handle = DEVICE_ACPI_HANDLE(&(dev->dev));
  147. if (!handle)
  148. return;
  149. acpi_run_oshp(handle);
  150. }
  151. void get_hp_params_from_firmware(struct pci_dev *dev,
  152. struct hotplug_params *hpp)
  153. {
  154. acpi_status status = AE_NOT_FOUND;
  155. struct pci_dev *pdev = dev;
  156. /*
  157. * _HPP settings apply to all child buses, until another _HPP is
  158. * encountered. If we don't find an _HPP for the input pci dev,
  159. * look for it in the parent device scope since that would apply to
  160. * this pci dev. If we don't find any _HPP, use hardcoded defaults
  161. */
  162. while (pdev && (ACPI_FAILURE(status))) {
  163. acpi_handle handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
  164. if (!handle)
  165. break;
  166. status = acpi_run_hpp(handle, hpp);
  167. if (!(pdev->bus->parent))
  168. break;
  169. /* Check if a parent object supports _HPP */
  170. pdev = pdev->bus->parent->self;
  171. }
  172. }