aerdrv_acpi.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Access ACPI _OSC method
  3. *
  4. * Copyright (C) 2006 Intel Corp.
  5. * Tom Long Nguyen (tom.l.nguyen@intel.com)
  6. * Zhang Yanmin (yanmin.zhang@intel.com)
  7. *
  8. */
  9. #include <linux/module.h>
  10. #include <linux/pci.h>
  11. #include <linux/kernel.h>
  12. #include <linux/errno.h>
  13. #include <linux/pm.h>
  14. #include <linux/suspend.h>
  15. #include <linux/acpi.h>
  16. #include <linux/pci-acpi.h>
  17. #include <linux/delay.h>
  18. #include <acpi/apei.h>
  19. #include "aerdrv.h"
  20. /**
  21. * aer_osc_setup - run ACPI _OSC method
  22. * @pciedev: pcie_device which AER is being enabled on
  23. *
  24. * @return: Zero on success. Nonzero otherwise.
  25. *
  26. * Invoked when PCIe bus loads AER service driver. To avoid conflict with
  27. * BIOS AER support requires BIOS to yield AER control to OS native driver.
  28. **/
  29. int aer_osc_setup(struct pcie_device *pciedev)
  30. {
  31. acpi_status status = AE_NOT_FOUND;
  32. struct pci_dev *pdev = pciedev->port;
  33. acpi_handle handle = NULL;
  34. if (acpi_pci_disabled)
  35. return -1;
  36. handle = acpi_find_root_bridge_handle(pdev);
  37. if (handle) {
  38. status = acpi_pci_osc_control_set(handle,
  39. OSC_PCI_EXPRESS_AER_CONTROL |
  40. OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
  41. }
  42. if (ACPI_FAILURE(status)) {
  43. dev_printk(KERN_DEBUG, &pciedev->device, "AER service couldn't "
  44. "init device: %s\n",
  45. (status == AE_SUPPORT || status == AE_NOT_FOUND) ?
  46. "no _OSC support" : "_OSC failed");
  47. return -1;
  48. }
  49. return 0;
  50. }
  51. #ifdef CONFIG_ACPI_APEI
  52. static inline int hest_match_pci(struct acpi_hest_aer_common *p,
  53. struct pci_dev *pci)
  54. {
  55. return (0 == pci_domain_nr(pci->bus) &&
  56. p->bus == pci->bus->number &&
  57. p->device == PCI_SLOT(pci->devfn) &&
  58. p->function == PCI_FUNC(pci->devfn));
  59. }
  60. struct aer_hest_parse_info {
  61. struct pci_dev *pci_dev;
  62. int firmware_first;
  63. };
  64. static int aer_hest_parse(struct acpi_hest_header *hest_hdr, void *data)
  65. {
  66. struct aer_hest_parse_info *info = data;
  67. struct acpi_hest_aer_common *p;
  68. u8 pcie_type = 0;
  69. u8 bridge = 0;
  70. int ff = 0;
  71. switch (hest_hdr->type) {
  72. case ACPI_HEST_TYPE_AER_ROOT_PORT:
  73. pcie_type = PCI_EXP_TYPE_ROOT_PORT;
  74. break;
  75. case ACPI_HEST_TYPE_AER_ENDPOINT:
  76. pcie_type = PCI_EXP_TYPE_ENDPOINT;
  77. break;
  78. case ACPI_HEST_TYPE_AER_BRIDGE:
  79. if ((info->pci_dev->class >> 16) == PCI_BASE_CLASS_BRIDGE)
  80. bridge = 1;
  81. break;
  82. default:
  83. return 0;
  84. }
  85. p = (struct acpi_hest_aer_common *)(hest_hdr + 1);
  86. if (p->flags & ACPI_HEST_GLOBAL) {
  87. if ((info->pci_dev->is_pcie &&
  88. info->pci_dev->pcie_type == pcie_type) || bridge)
  89. ff = !!(p->flags & ACPI_HEST_FIRMWARE_FIRST);
  90. } else
  91. if (hest_match_pci(p, info->pci_dev))
  92. ff = !!(p->flags & ACPI_HEST_FIRMWARE_FIRST);
  93. info->firmware_first = ff;
  94. return 0;
  95. }
  96. static void aer_set_firmware_first(struct pci_dev *pci_dev)
  97. {
  98. int rc;
  99. struct aer_hest_parse_info info = {
  100. .pci_dev = pci_dev,
  101. .firmware_first = 0,
  102. };
  103. rc = apei_hest_parse(aer_hest_parse, &info);
  104. if (rc)
  105. pci_dev->__aer_firmware_first = 0;
  106. else
  107. pci_dev->__aer_firmware_first = info.firmware_first;
  108. pci_dev->__aer_firmware_first_valid = 1;
  109. }
  110. int pcie_aer_get_firmware_first(struct pci_dev *dev)
  111. {
  112. if (!dev->__aer_firmware_first_valid)
  113. aer_set_firmware_first(dev);
  114. return dev->__aer_firmware_first;
  115. }
  116. #endif