portdrv_acpi.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * PCIe Port Native Services Support, ACPI-Related Part
  3. *
  4. * Copyright (C) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License V2. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/pci.h>
  11. #include <linux/kernel.h>
  12. #include <linux/errno.h>
  13. #include <linux/acpi.h>
  14. #include <linux/pci-acpi.h>
  15. #include <linux/pcieport_if.h>
  16. #include "aer/aerdrv.h"
  17. #include "../pci.h"
  18. /**
  19. * pcie_port_acpi_setup - Request the BIOS to release control of PCIe services.
  20. * @port: PCIe Port service for a root port or event collector.
  21. * @srv_mask: Bit mask of services that can be enabled for @port.
  22. *
  23. * Invoked when @port is identified as a PCIe port device. To avoid conflicts
  24. * with the BIOS PCIe port native services support requires the BIOS to yield
  25. * control of these services to the kernel. The mask of services that the BIOS
  26. * allows to be enabled for @port is written to @srv_mask.
  27. *
  28. * NOTE: It turns out that we cannot do that for individual port services
  29. * separately, because that would make some systems work incorrectly.
  30. */
  31. int pcie_port_acpi_setup(struct pci_dev *port, int *srv_mask)
  32. {
  33. acpi_status status;
  34. acpi_handle handle;
  35. u32 flags;
  36. if (acpi_pci_disabled)
  37. return 0;
  38. handle = acpi_find_root_bridge_handle(port);
  39. if (!handle)
  40. return -EINVAL;
  41. flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL
  42. | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL
  43. | OSC_PCI_EXPRESS_PME_CONTROL;
  44. if (pci_aer_available()) {
  45. if (pcie_aer_get_firmware_first(port))
  46. dev_dbg(&port->dev, "PCIe errors handled by BIOS.\n");
  47. else
  48. flags |= OSC_PCI_EXPRESS_AER_CONTROL;
  49. }
  50. status = acpi_pci_osc_control_set(handle, &flags,
  51. OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
  52. if (ACPI_FAILURE(status)) {
  53. dev_dbg(&port->dev, "ACPI _OSC request failed (code %d)\n",
  54. status);
  55. return -ENODEV;
  56. }
  57. dev_info(&port->dev, "ACPI _OSC control granted for 0x%02x\n", flags);
  58. *srv_mask = PCIE_PORT_SERVICE_VC;
  59. if (flags & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL)
  60. *srv_mask |= PCIE_PORT_SERVICE_HP;
  61. if (flags & OSC_PCI_EXPRESS_PME_CONTROL)
  62. *srv_mask |= PCIE_PORT_SERVICE_PME;
  63. if (flags & OSC_PCI_EXPRESS_AER_CONTROL)
  64. *srv_mask |= PCIE_PORT_SERVICE_AER;
  65. return 0;
  66. }