aerdrv_acpi.c 3.0 KB

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