acpi_pcihp.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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 <linux/pci_hotplug.h>
  32. #include <acpi/acpi.h>
  33. #include <acpi/acpi_bus.h>
  34. #include <acpi/actypes.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. decode_type0_hpx_record(union acpi_object *record, struct hotplug_params *hpx)
  46. {
  47. int i;
  48. union acpi_object *fields = record->package.elements;
  49. u32 revision = fields[1].integer.value;
  50. switch (revision) {
  51. case 1:
  52. if (record->package.count != 6)
  53. return AE_ERROR;
  54. for (i = 2; i < 6; i++)
  55. if (fields[i].type != ACPI_TYPE_INTEGER)
  56. return AE_ERROR;
  57. hpx->t0 = &hpx->type0_data;
  58. hpx->t0->revision = revision;
  59. hpx->t0->cache_line_size = fields[2].integer.value;
  60. hpx->t0->latency_timer = fields[3].integer.value;
  61. hpx->t0->enable_serr = fields[4].integer.value;
  62. hpx->t0->enable_perr = fields[5].integer.value;
  63. break;
  64. default:
  65. printk(KERN_WARNING
  66. "%s: Type 0 Revision %d record not supported\n",
  67. __FUNCTION__, revision);
  68. return AE_ERROR;
  69. }
  70. return AE_OK;
  71. }
  72. static acpi_status
  73. decode_type1_hpx_record(union acpi_object *record, struct hotplug_params *hpx)
  74. {
  75. int i;
  76. union acpi_object *fields = record->package.elements;
  77. u32 revision = fields[1].integer.value;
  78. switch (revision) {
  79. case 1:
  80. if (record->package.count != 5)
  81. return AE_ERROR;
  82. for (i = 2; i < 5; i++)
  83. if (fields[i].type != ACPI_TYPE_INTEGER)
  84. return AE_ERROR;
  85. hpx->t1 = &hpx->type1_data;
  86. hpx->t1->revision = revision;
  87. hpx->t1->max_mem_read = fields[2].integer.value;
  88. hpx->t1->avg_max_split = fields[3].integer.value;
  89. hpx->t1->tot_max_split = fields[4].integer.value;
  90. break;
  91. default:
  92. printk(KERN_WARNING
  93. "%s: Type 1 Revision %d record not supported\n",
  94. __FUNCTION__, revision);
  95. return AE_ERROR;
  96. }
  97. return AE_OK;
  98. }
  99. static acpi_status
  100. decode_type2_hpx_record(union acpi_object *record, struct hotplug_params *hpx)
  101. {
  102. int i;
  103. union acpi_object *fields = record->package.elements;
  104. u32 revision = fields[1].integer.value;
  105. switch (revision) {
  106. case 1:
  107. if (record->package.count != 18)
  108. return AE_ERROR;
  109. for (i = 2; i < 18; i++)
  110. if (fields[i].type != ACPI_TYPE_INTEGER)
  111. return AE_ERROR;
  112. hpx->t2 = &hpx->type2_data;
  113. hpx->t2->revision = revision;
  114. hpx->t2->unc_err_mask_and = fields[2].integer.value;
  115. hpx->t2->unc_err_mask_or = fields[3].integer.value;
  116. hpx->t2->unc_err_sever_and = fields[4].integer.value;
  117. hpx->t2->unc_err_sever_or = fields[5].integer.value;
  118. hpx->t2->cor_err_mask_and = fields[6].integer.value;
  119. hpx->t2->cor_err_mask_or = fields[7].integer.value;
  120. hpx->t2->adv_err_cap_and = fields[8].integer.value;
  121. hpx->t2->adv_err_cap_or = fields[9].integer.value;
  122. hpx->t2->pci_exp_devctl_and = fields[10].integer.value;
  123. hpx->t2->pci_exp_devctl_or = fields[11].integer.value;
  124. hpx->t2->pci_exp_lnkctl_and = fields[12].integer.value;
  125. hpx->t2->pci_exp_lnkctl_or = fields[13].integer.value;
  126. hpx->t2->sec_unc_err_sever_and = fields[14].integer.value;
  127. hpx->t2->sec_unc_err_sever_or = fields[15].integer.value;
  128. hpx->t2->sec_unc_err_mask_and = fields[16].integer.value;
  129. hpx->t2->sec_unc_err_mask_or = fields[17].integer.value;
  130. break;
  131. default:
  132. printk(KERN_WARNING
  133. "%s: Type 2 Revision %d record not supported\n",
  134. __FUNCTION__, revision);
  135. return AE_ERROR;
  136. }
  137. return AE_OK;
  138. }
  139. static acpi_status
  140. acpi_run_hpx(acpi_handle handle, struct hotplug_params *hpx)
  141. {
  142. acpi_status status;
  143. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  144. union acpi_object *package, *record, *fields;
  145. u32 type;
  146. int i;
  147. /* Clear the return buffer with zeros */
  148. memset(hpx, 0, sizeof(struct hotplug_params));
  149. status = acpi_evaluate_object(handle, "_HPX", NULL, &buffer);
  150. if (ACPI_FAILURE(status))
  151. return status;
  152. package = (union acpi_object *)buffer.pointer;
  153. if (package->type != ACPI_TYPE_PACKAGE) {
  154. status = AE_ERROR;
  155. goto exit;
  156. }
  157. for (i = 0; i < package->package.count; i++) {
  158. record = &package->package.elements[i];
  159. if (record->type != ACPI_TYPE_PACKAGE) {
  160. status = AE_ERROR;
  161. goto exit;
  162. }
  163. fields = record->package.elements;
  164. if (fields[0].type != ACPI_TYPE_INTEGER ||
  165. fields[1].type != ACPI_TYPE_INTEGER) {
  166. status = AE_ERROR;
  167. goto exit;
  168. }
  169. type = fields[0].integer.value;
  170. switch (type) {
  171. case 0:
  172. status = decode_type0_hpx_record(record, hpx);
  173. if (ACPI_FAILURE(status))
  174. goto exit;
  175. break;
  176. case 1:
  177. status = decode_type1_hpx_record(record, hpx);
  178. if (ACPI_FAILURE(status))
  179. goto exit;
  180. break;
  181. case 2:
  182. status = decode_type2_hpx_record(record, hpx);
  183. if (ACPI_FAILURE(status))
  184. goto exit;
  185. break;
  186. default:
  187. printk(KERN_ERR "%s: Type %d record not supported\n",
  188. __FUNCTION__, type);
  189. status = AE_ERROR;
  190. goto exit;
  191. }
  192. }
  193. exit:
  194. kfree(buffer.pointer);
  195. return status;
  196. }
  197. static acpi_status
  198. acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
  199. {
  200. acpi_status status;
  201. u8 nui[4];
  202. struct acpi_buffer ret_buf = { 0, NULL};
  203. struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
  204. union acpi_object *ext_obj, *package;
  205. int i, len = 0;
  206. acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
  207. /* Clear the return buffer with zeros */
  208. memset(hpp, 0, sizeof(struct hotplug_params));
  209. /* get _hpp */
  210. status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
  211. switch (status) {
  212. case AE_BUFFER_OVERFLOW:
  213. ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
  214. if (!ret_buf.pointer) {
  215. printk(KERN_ERR "%s:%s alloc for _HPP fail\n",
  216. __FUNCTION__, (char *)string.pointer);
  217. kfree(string.pointer);
  218. return AE_NO_MEMORY;
  219. }
  220. status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
  221. NULL, &ret_buf);
  222. if (ACPI_SUCCESS(status))
  223. break;
  224. default:
  225. if (ACPI_FAILURE(status)) {
  226. pr_debug("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
  227. (char *)string.pointer, status);
  228. kfree(string.pointer);
  229. return status;
  230. }
  231. }
  232. ext_obj = (union acpi_object *) ret_buf.pointer;
  233. if (ext_obj->type != ACPI_TYPE_PACKAGE) {
  234. printk(KERN_ERR "%s:%s _HPP obj not a package\n", __FUNCTION__,
  235. (char *)string.pointer);
  236. status = AE_ERROR;
  237. goto free_and_return;
  238. }
  239. len = ext_obj->package.count;
  240. package = (union acpi_object *) ret_buf.pointer;
  241. for ( i = 0; (i < len) || (i < 4); i++) {
  242. ext_obj = (union acpi_object *) &package->package.elements[i];
  243. switch (ext_obj->type) {
  244. case ACPI_TYPE_INTEGER:
  245. nui[i] = (u8)ext_obj->integer.value;
  246. break;
  247. default:
  248. printk(KERN_ERR "%s:%s _HPP obj type incorrect\n",
  249. __FUNCTION__, (char *)string.pointer);
  250. status = AE_ERROR;
  251. goto free_and_return;
  252. }
  253. }
  254. hpp->t0 = &hpp->type0_data;
  255. hpp->t0->cache_line_size = nui[0];
  256. hpp->t0->latency_timer = nui[1];
  257. hpp->t0->enable_serr = nui[2];
  258. hpp->t0->enable_perr = nui[3];
  259. pr_debug(" _HPP: cache_line_size=0x%x\n", hpp->t0->cache_line_size);
  260. pr_debug(" _HPP: latency timer =0x%x\n", hpp->t0->latency_timer);
  261. pr_debug(" _HPP: enable SERR =0x%x\n", hpp->t0->enable_serr);
  262. pr_debug(" _HPP: enable PERR =0x%x\n", hpp->t0->enable_perr);
  263. free_and_return:
  264. kfree(string.pointer);
  265. kfree(ret_buf.pointer);
  266. return status;
  267. }
  268. /* acpi_run_oshp - get control of hotplug from the firmware
  269. *
  270. * @handle - the handle of the hotplug controller.
  271. */
  272. acpi_status acpi_run_oshp(acpi_handle handle)
  273. {
  274. acpi_status status;
  275. struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
  276. acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
  277. /* run OSHP */
  278. status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
  279. if (ACPI_FAILURE(status))
  280. if (status != AE_NOT_FOUND)
  281. printk(KERN_ERR "%s:%s OSHP fails=0x%x\n",
  282. __FUNCTION__, (char *)string.pointer, status);
  283. else
  284. dbg("%s:%s OSHP not found\n",
  285. __FUNCTION__, (char *)string.pointer);
  286. else
  287. pr_debug("%s:%s OSHP passes\n", __FUNCTION__,
  288. (char *)string.pointer);
  289. kfree(string.pointer);
  290. return status;
  291. }
  292. EXPORT_SYMBOL_GPL(acpi_run_oshp);
  293. /* acpi_get_hp_params_from_firmware
  294. *
  295. * @bus - the pci_bus of the bus on which the device is newly added
  296. * @hpp - allocated by the caller
  297. */
  298. acpi_status acpi_get_hp_params_from_firmware(struct pci_bus *bus,
  299. struct hotplug_params *hpp)
  300. {
  301. acpi_status status = AE_NOT_FOUND;
  302. acpi_handle handle, phandle;
  303. struct pci_bus *pbus = bus;
  304. struct pci_dev *pdev;
  305. do {
  306. pdev = pbus->self;
  307. if (!pdev) {
  308. handle = acpi_get_pci_rootbridge_handle(
  309. pci_domain_nr(pbus), pbus->number);
  310. break;
  311. }
  312. handle = DEVICE_ACPI_HANDLE(&(pdev->dev));
  313. pbus = pbus->parent;
  314. } while (!handle);
  315. /*
  316. * _HPP settings apply to all child buses, until another _HPP is
  317. * encountered. If we don't find an _HPP for the input pci dev,
  318. * look for it in the parent device scope since that would apply to
  319. * this pci dev. If we don't find any _HPP, use hardcoded defaults
  320. */
  321. while (handle) {
  322. status = acpi_run_hpx(handle, hpp);
  323. if (ACPI_SUCCESS(status))
  324. break;
  325. status = acpi_run_hpp(handle, hpp);
  326. if (ACPI_SUCCESS(status))
  327. break;
  328. if (acpi_root_bridge(handle))
  329. break;
  330. status = acpi_get_parent(handle, &phandle);
  331. if (ACPI_FAILURE(status))
  332. break;
  333. handle = phandle;
  334. }
  335. return status;
  336. }
  337. EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware);
  338. /* acpi_root_bridge - check to see if this acpi object is a root bridge
  339. *
  340. * @handle - the acpi object in question.
  341. */
  342. int acpi_root_bridge(acpi_handle handle)
  343. {
  344. acpi_status status;
  345. struct acpi_device_info *info;
  346. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  347. int i;
  348. status = acpi_get_object_info(handle, &buffer);
  349. if (ACPI_SUCCESS(status)) {
  350. info = buffer.pointer;
  351. if ((info->valid & ACPI_VALID_HID) &&
  352. !strcmp(PCI_ROOT_HID_STRING,
  353. info->hardware_id.value)) {
  354. kfree(buffer.pointer);
  355. return 1;
  356. }
  357. if (info->valid & ACPI_VALID_CID) {
  358. for (i=0; i < info->compatibility_id.count; i++) {
  359. if (!strcmp(PCI_ROOT_HID_STRING,
  360. info->compatibility_id.id[i].value)) {
  361. kfree(buffer.pointer);
  362. return 1;
  363. }
  364. }
  365. }
  366. kfree(buffer.pointer);
  367. }
  368. return 0;
  369. }
  370. EXPORT_SYMBOL_GPL(acpi_root_bridge);
  371. module_param(debug_acpi, bool, 0644);
  372. MODULE_PARM_DESC(debug_acpi, "Debugging mode for ACPI enabled or not");