Merge branch 'pci/aspm'
[linux-2.6-microblaze.git] / drivers / pci / pcie / portdrv_acpi.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * PCIe Port Native Services Support, ACPI-Related Part
4  *
5  * Copyright (C) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
6  */
7
8 #include <linux/pci.h>
9 #include <linux/kernel.h>
10 #include <linux/errno.h>
11 #include <linux/acpi.h>
12 #include <linux/pci-acpi.h>
13 #include <linux/pcieport_if.h>
14
15 #include "aer/aerdrv.h"
16 #include "../pci.h"
17 #include "portdrv.h"
18
19 /**
20  * pcie_port_acpi_setup - Request the BIOS to release control of PCIe services.
21  * @port: PCIe Port service for a root port or event collector.
22  * @srv_mask: Bit mask of services that can be enabled for @port.
23  *
24  * Invoked when @port is identified as a PCIe port device.  To avoid conflicts
25  * with the BIOS PCIe port native services support requires the BIOS to yield
26  * control of these services to the kernel.  The mask of services that the BIOS
27  * allows to be enabled for @port is written to @srv_mask.
28  *
29  * NOTE: It turns out that we cannot do that for individual port services
30  * separately, because that would make some systems work incorrectly.
31  */
32 void pcie_port_acpi_setup(struct pci_dev *port, int *srv_mask)
33 {
34         struct acpi_pci_root *root;
35         acpi_handle handle;
36         u32 flags;
37
38         if (acpi_pci_disabled)
39                 return;
40
41         handle = acpi_find_root_bridge_handle(port);
42         if (!handle)
43                 return;
44
45         root = acpi_pci_find_root(handle);
46         if (!root)
47                 return;
48
49         flags = root->osc_control_set;
50
51         *srv_mask = PCIE_PORT_SERVICE_VC | PCIE_PORT_SERVICE_DPC;
52         if (flags & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL)
53                 *srv_mask |= PCIE_PORT_SERVICE_HP;
54         if (flags & OSC_PCI_EXPRESS_PME_CONTROL)
55                 *srv_mask |= PCIE_PORT_SERVICE_PME;
56         if (flags & OSC_PCI_EXPRESS_AER_CONTROL)
57                 *srv_mask |= PCIE_PORT_SERVICE_AER;
58 }