aerdrv_acpi.c 2.9 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. #ifdef CONFIG_ACPI_APEI
  21. static inline int hest_match_pci(struct acpi_hest_aer_common *p,
  22. struct pci_dev *pci)
  23. {
  24. return (0 == pci_domain_nr(pci->bus) &&
  25. p->bus == pci->bus->number &&
  26. p->device == PCI_SLOT(pci->devfn) &&
  27. p->function == PCI_FUNC(pci->devfn));
  28. }
  29. struct aer_hest_parse_info {
  30. struct pci_dev *pci_dev;
  31. int firmware_first;
  32. };
  33. static int aer_hest_parse(struct acpi_hest_header *hest_hdr, void *data)
  34. {
  35. struct aer_hest_parse_info *info = data;
  36. struct acpi_hest_aer_common *p;
  37. u8 pcie_type = 0;
  38. u8 bridge = 0;
  39. int ff = 0;
  40. switch (hest_hdr->type) {
  41. case ACPI_HEST_TYPE_AER_ROOT_PORT:
  42. pcie_type = PCI_EXP_TYPE_ROOT_PORT;
  43. break;
  44. case ACPI_HEST_TYPE_AER_ENDPOINT:
  45. pcie_type = PCI_EXP_TYPE_ENDPOINT;
  46. break;
  47. case ACPI_HEST_TYPE_AER_BRIDGE:
  48. if ((info->pci_dev->class >> 16) == PCI_BASE_CLASS_BRIDGE)
  49. bridge = 1;
  50. break;
  51. default:
  52. return 0;
  53. }
  54. p = (struct acpi_hest_aer_common *)(hest_hdr + 1);
  55. if (p->flags & ACPI_HEST_GLOBAL) {
  56. if ((pci_pcie_type(info->pci_dev) == pcie_type) || bridge)
  57. ff = !!(p->flags & ACPI_HEST_FIRMWARE_FIRST);
  58. } else
  59. if (hest_match_pci(p, info->pci_dev))
  60. ff = !!(p->flags & ACPI_HEST_FIRMWARE_FIRST);
  61. info->firmware_first = ff;
  62. return 0;
  63. }
  64. static void aer_set_firmware_first(struct pci_dev *pci_dev)
  65. {
  66. int rc;
  67. struct aer_hest_parse_info info = {
  68. .pci_dev = pci_dev,
  69. .firmware_first = 0,
  70. };
  71. rc = apei_hest_parse(aer_hest_parse, &info);
  72. if (rc)
  73. pci_dev->__aer_firmware_first = 0;
  74. else
  75. pci_dev->__aer_firmware_first = info.firmware_first;
  76. pci_dev->__aer_firmware_first_valid = 1;
  77. }
  78. int pcie_aer_get_firmware_first(struct pci_dev *dev)
  79. {
  80. if (!pci_is_pcie(dev))
  81. return 0;
  82. if (!dev->__aer_firmware_first_valid)
  83. aer_set_firmware_first(dev);
  84. return dev->__aer_firmware_first;
  85. }
  86. static bool aer_firmware_first;
  87. static int aer_hest_parse_aff(struct acpi_hest_header *hest_hdr, void *data)
  88. {
  89. struct acpi_hest_aer_common *p;
  90. if (aer_firmware_first)
  91. return 0;
  92. switch (hest_hdr->type) {
  93. case ACPI_HEST_TYPE_AER_ROOT_PORT:
  94. case ACPI_HEST_TYPE_AER_ENDPOINT:
  95. case ACPI_HEST_TYPE_AER_BRIDGE:
  96. p = (struct acpi_hest_aer_common *)(hest_hdr + 1);
  97. aer_firmware_first = !!(p->flags & ACPI_HEST_FIRMWARE_FIRST);
  98. default:
  99. return 0;
  100. }
  101. }
  102. /**
  103. * aer_acpi_firmware_first - Check if APEI should control AER.
  104. */
  105. bool aer_acpi_firmware_first(void)
  106. {
  107. static bool parsed = false;
  108. if (!parsed) {
  109. apei_hest_parse(aer_hest_parse_aff, NULL);
  110. parsed = true;
  111. }
  112. return aer_firmware_first;
  113. }
  114. #endif