aerdrv_acpi.c 2.9 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. 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 ((info->pci_dev->is_pcie &&
  57. info->pci_dev->pcie_type == pcie_type) || bridge)
  58. ff = !!(p->flags & ACPI_HEST_FIRMWARE_FIRST);
  59. } else
  60. if (hest_match_pci(p, info->pci_dev))
  61. ff = !!(p->flags & ACPI_HEST_FIRMWARE_FIRST);
  62. info->firmware_first = ff;
  63. return 0;
  64. }
  65. static void aer_set_firmware_first(struct pci_dev *pci_dev)
  66. {
  67. int rc;
  68. struct aer_hest_parse_info info = {
  69. .pci_dev = pci_dev,
  70. .firmware_first = 0,
  71. };
  72. rc = apei_hest_parse(aer_hest_parse, &info);
  73. if (rc)
  74. pci_dev->__aer_firmware_first = 0;
  75. else
  76. pci_dev->__aer_firmware_first = info.firmware_first;
  77. pci_dev->__aer_firmware_first_valid = 1;
  78. }
  79. int pcie_aer_get_firmware_first(struct pci_dev *dev)
  80. {
  81. if (!dev->__aer_firmware_first_valid)
  82. aer_set_firmware_first(dev);
  83. return dev->__aer_firmware_first;
  84. }
  85. static bool aer_firmware_first;
  86. static int aer_hest_parse_aff(struct acpi_hest_header *hest_hdr, void *data)
  87. {
  88. struct acpi_hest_aer_common *p;
  89. if (aer_firmware_first)
  90. return 0;
  91. switch (hest_hdr->type) {
  92. case ACPI_HEST_TYPE_AER_ROOT_PORT:
  93. case ACPI_HEST_TYPE_AER_ENDPOINT:
  94. case ACPI_HEST_TYPE_AER_BRIDGE:
  95. p = (struct acpi_hest_aer_common *)(hest_hdr + 1);
  96. aer_firmware_first = !!(p->flags & ACPI_HEST_FIRMWARE_FIRST);
  97. default:
  98. return 0;
  99. }
  100. }
  101. /**
  102. * aer_acpi_firmware_first - Check if APEI should control AER.
  103. */
  104. bool aer_acpi_firmware_first(void)
  105. {
  106. static bool parsed = false;
  107. if (!parsed) {
  108. apei_hest_parse(aer_hest_parse_aff, NULL);
  109. parsed = true;
  110. }
  111. return aer_firmware_first;
  112. }
  113. #endif