2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* pci.h
|
|
|
|
*
|
|
|
|
* PCI defines and function prototypes
|
|
|
|
* Copyright 1994, Drew Eckhardt
|
|
|
|
* Copyright 1997--1999 Martin Mares <mj@ucw.cz>
|
|
|
|
*
|
|
|
|
* For more information, please consult the following manuals (look at
|
|
|
|
* http://www.pcisig.com/ for how to get them):
|
|
|
|
*
|
|
|
|
* PCI BIOS Specification
|
|
|
|
* PCI Local Bus Specification
|
|
|
|
* PCI to PCI Bridge Specification
|
|
|
|
* PCI System Design Guide
|
|
|
|
*/
|
|
|
|
#ifndef LINUX_PCI_H
|
|
|
|
#define LINUX_PCI_H
|
|
|
|
|
|
|
|
|
2006-04-29 04:46:02 +04:00
|
|
|
#include <linux/mod_devicetable.h>
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/types.h>
|
2008-04-30 00:38:48 +04:00
|
|
|
#include <linux/init.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/list.h>
|
2006-08-15 09:43:17 +04:00
|
|
|
#include <linux/compiler.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/errno.h>
|
2008-06-11 01:28:50 +04:00
|
|
|
#include <linux/kobject.h>
|
2011-07-27 03:09:06 +04:00
|
|
|
#include <linux/atomic.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/device.h>
|
2017-04-13 10:06:42 +03:00
|
|
|
#include <linux/interrupt.h>
|
2008-10-22 06:39:55 +04:00
|
|
|
#include <linux/io.h>
|
2015-02-05 08:44:44 +03:00
|
|
|
#include <linux/resource_ext.h>
|
2012-10-13 13:46:48 +04:00
|
|
|
#include <uapi/linux/pci.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-12-20 00:12:07 +03:00
|
|
|
#include <linux/pci_ids.h>
|
|
|
|
|
2013-02-28 04:06:45 +04:00
|
|
|
/*
|
|
|
|
* The PCI interface treats multi-function devices as independent
|
|
|
|
* devices. The slot/function address of each device is encoded
|
|
|
|
* in a single byte as follows:
|
|
|
|
*
|
|
|
|
* 7:3 = slot
|
|
|
|
* 2:0 = function
|
2013-11-14 22:28:18 +04:00
|
|
|
*
|
|
|
|
* PCI_DEVFN(), PCI_SLOT(), and PCI_FUNC() are defined in uapi/linux/pci.h.
|
2013-02-28 04:06:45 +04:00
|
|
|
* In the interest of not exposing interfaces to user-space unnecessarily,
|
2013-11-14 22:28:18 +04:00
|
|
|
* the following kernel-only defines are being added here.
|
2013-02-28 04:06:45 +04:00
|
|
|
*/
|
2014-09-06 07:19:10 +04:00
|
|
|
#define PCI_DEVID(bus, devfn) ((((u16)(bus)) << 8) | (devfn))
|
2013-02-28 04:06:45 +04:00
|
|
|
/* return bus from PCI devid = ((u16)bus_number) << 8) | devfn */
|
|
|
|
#define PCI_BUS_NUM(x) (((x) >> 8) & 0xff)
|
|
|
|
|
2008-06-11 01:28:50 +04:00
|
|
|
/* pci_slot represents a physical slot */
|
|
|
|
struct pci_slot {
|
|
|
|
struct pci_bus *bus; /* The bus this slot is on */
|
|
|
|
struct list_head list; /* node in list of slots on this bus */
|
|
|
|
struct hotplug_slot *hotplug; /* Hotplug info (migrate over time) */
|
|
|
|
unsigned char number; /* PCI_SLOT(pci_dev->devfn) */
|
|
|
|
struct kobject kobj;
|
|
|
|
};
|
|
|
|
|
2008-10-21 03:41:07 +04:00
|
|
|
static inline const char *pci_slot_name(const struct pci_slot *slot)
|
|
|
|
{
|
|
|
|
return kobject_name(&slot->kobj);
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* File state for mmap()s on /proc/bus/pci/X/Y */
|
|
|
|
enum pci_mmap_state {
|
|
|
|
pci_mmap_io,
|
|
|
|
pci_mmap_mem
|
|
|
|
};
|
|
|
|
|
2008-11-21 21:39:32 +03:00
|
|
|
/*
|
|
|
|
* For PCI devices, the region numbers are assigned this way:
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
/* #0-5: standard PCI resources */
|
|
|
|
PCI_STD_RESOURCES,
|
|
|
|
PCI_STD_RESOURCE_END = 5,
|
|
|
|
|
|
|
|
/* #6: expansion ROM resource */
|
|
|
|
PCI_ROM_RESOURCE,
|
|
|
|
|
2009-03-20 06:25:11 +03:00
|
|
|
/* device specific resources */
|
|
|
|
#ifdef CONFIG_PCI_IOV
|
|
|
|
PCI_IOV_RESOURCES,
|
|
|
|
PCI_IOV_RESOURCE_END = PCI_IOV_RESOURCES + PCI_SRIOV_NUM_BARS - 1,
|
|
|
|
#endif
|
|
|
|
|
2008-11-21 21:39:32 +03:00
|
|
|
/* resources assigned to buses behind the bridge */
|
|
|
|
#define PCI_BRIDGE_RESOURCE_NUM 4
|
|
|
|
|
|
|
|
PCI_BRIDGE_RESOURCES,
|
|
|
|
PCI_BRIDGE_RESOURCE_END = PCI_BRIDGE_RESOURCES +
|
|
|
|
PCI_BRIDGE_RESOURCE_NUM - 1,
|
|
|
|
|
|
|
|
/* total resources associated with a PCI device */
|
|
|
|
PCI_NUM_RESOURCES,
|
|
|
|
|
|
|
|
/* preserve this for compatibility */
|
2012-01-05 03:49:45 +04:00
|
|
|
DEVICE_COUNT_RESOURCE = PCI_NUM_RESOURCES,
|
2008-11-21 21:39:32 +03:00
|
|
|
};
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2017-08-15 22:02:16 +03:00
|
|
|
/**
|
|
|
|
* enum pci_interrupt_pin - PCI INTx interrupt values
|
|
|
|
* @PCI_INTERRUPT_UNKNOWN: Unknown or unassigned interrupt
|
|
|
|
* @PCI_INTERRUPT_INTA: PCI INTA pin
|
|
|
|
* @PCI_INTERRUPT_INTB: PCI INTB pin
|
|
|
|
* @PCI_INTERRUPT_INTC: PCI INTC pin
|
|
|
|
* @PCI_INTERRUPT_INTD: PCI INTD pin
|
|
|
|
*
|
|
|
|
* Corresponds to values for legacy PCI INTx interrupts, as can be found in the
|
|
|
|
* PCI_INTERRUPT_PIN register.
|
|
|
|
*/
|
|
|
|
enum pci_interrupt_pin {
|
|
|
|
PCI_INTERRUPT_UNKNOWN,
|
|
|
|
PCI_INTERRUPT_INTA,
|
|
|
|
PCI_INTERRUPT_INTB,
|
|
|
|
PCI_INTERRUPT_INTC,
|
|
|
|
PCI_INTERRUPT_INTD,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The number of legacy PCI INTx interrupts */
|
|
|
|
#define PCI_NUM_INTX 4
|
|
|
|
|
2016-06-17 23:23:52 +03:00
|
|
|
/*
|
|
|
|
* pci_power_t values must match the bits in the Capabilities PME_Support
|
|
|
|
* and Control/Status PowerState fields in the Power Management capability.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
typedef int __bitwise pci_power_t;
|
|
|
|
|
2005-07-28 22:37:33 +04:00
|
|
|
#define PCI_D0 ((pci_power_t __force) 0)
|
|
|
|
#define PCI_D1 ((pci_power_t __force) 1)
|
|
|
|
#define PCI_D2 ((pci_power_t __force) 2)
|
2005-04-17 02:20:36 +04:00
|
|
|
#define PCI_D3hot ((pci_power_t __force) 3)
|
|
|
|
#define PCI_D3cold ((pci_power_t __force) 4)
|
2005-08-18 02:32:19 +04:00
|
|
|
#define PCI_UNKNOWN ((pci_power_t __force) 5)
|
2005-04-17 02:25:24 +04:00
|
|
|
#define PCI_POWER_ERROR ((pci_power_t __force) -1)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-04-27 21:33:16 +04:00
|
|
|
/* Remember to update this when the list above changes! */
|
|
|
|
extern const char *pci_power_names[];
|
|
|
|
|
|
|
|
static inline const char *pci_power_name(pci_power_t state)
|
|
|
|
{
|
2016-06-07 20:48:33 +03:00
|
|
|
return pci_power_names[1 + (__force int) state];
|
2009-04-27 21:33:16 +04:00
|
|
|
}
|
|
|
|
|
PCI/PM: add PCIe runtime D3cold support
This patch adds runtime D3cold support and corresponding ACPI platform
support. This patch only enables runtime D3cold support; it does not
enable D3cold support during system suspend/hibernate.
D3cold is the deepest power saving state for a PCIe device, where its main
power is removed. While it is in D3cold, you can't access the device at
all, not even its configuration space (which is still accessible in D3hot).
Therefore the PCI PM registers can not be used to transition into/out of
the D3cold state; that must be done by platform logic such as ACPI _PR3.
To support wakeup from D3cold, a system may provide auxiliary power, which
allows a device to request wakeup using a Beacon or the sideband WAKE#
signal. WAKE# is usually connected to platform logic such as ACPI GPE.
This is quite different from other power saving states, where devices
request wakeup via a PME message on the PCIe link.
Some devices, such as those in plug-in slots, have no direct platform
logic. For example, there is usually no ACPI _PR3 for them. D3cold
support for these devices can be done via the PCIe Downstream Port leading
to the device. When the PCIe port is powered on/off, the device is powered
on/off too. Wakeup events from the device will be notified to the
corresponding PCIe port.
For more information about PCIe D3cold and corresponding ACPI support,
please refer to:
- PCI Express Base Specification Revision 2.0
- Advanced Configuration and Power Interface Specification Revision 5.0
[bhelgaas: changelog]
Reviewed-by: Rafael J. Wysocki <rjw@sisk.pl>
Originally-by: Zheng Yan <zheng.z.yan@intel.com>
Signed-off-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2012-06-23 06:23:51 +04:00
|
|
|
#define PCI_PM_D2_DELAY 200
|
|
|
|
#define PCI_PM_D3_WAIT 10
|
|
|
|
#define PCI_PM_D3COLD_WAIT 100
|
|
|
|
#define PCI_PM_BUS_WAIT 50
|
2009-01-16 23:54:43 +03:00
|
|
|
|
2005-11-17 02:10:41 +03:00
|
|
|
/** The pci_channel state describes connectivity between the CPU and
|
|
|
|
* the pci device. If some PCI bus between here and the pci device
|
|
|
|
* has crashed or locked up, this info is reflected here.
|
|
|
|
*/
|
|
|
|
typedef unsigned int __bitwise pci_channel_state_t;
|
|
|
|
|
|
|
|
enum pci_channel_state {
|
|
|
|
/* I/O channel is in normal state */
|
|
|
|
pci_channel_io_normal = (__force pci_channel_state_t) 1,
|
|
|
|
|
|
|
|
/* I/O to channel is blocked */
|
|
|
|
pci_channel_io_frozen = (__force pci_channel_state_t) 2,
|
|
|
|
|
|
|
|
/* PCI card is dead */
|
|
|
|
pci_channel_io_perm_failure = (__force pci_channel_state_t) 3,
|
|
|
|
};
|
|
|
|
|
2007-04-07 01:39:36 +04:00
|
|
|
typedef unsigned int __bitwise pcie_reset_state_t;
|
|
|
|
|
|
|
|
enum pcie_reset_state {
|
|
|
|
/* Reset is NOT asserted (Use to deassert reset) */
|
|
|
|
pcie_deassert_reset = (__force pcie_reset_state_t) 1,
|
|
|
|
|
2013-11-14 22:28:18 +04:00
|
|
|
/* Use #PERST to reset PCIe device */
|
2007-04-07 01:39:36 +04:00
|
|
|
pcie_warm_reset = (__force pcie_reset_state_t) 2,
|
|
|
|
|
2013-11-14 22:28:18 +04:00
|
|
|
/* Use PCIe Hot Reset to reset device */
|
2007-04-07 01:39:36 +04:00
|
|
|
pcie_hot_reset = (__force pcie_reset_state_t) 3
|
|
|
|
};
|
|
|
|
|
2007-10-25 12:16:30 +04:00
|
|
|
typedef unsigned short __bitwise pci_dev_flags_t;
|
|
|
|
enum pci_dev_flags {
|
|
|
|
/* INTX_DISABLE in PCI_COMMAND register disables MSI
|
|
|
|
* generation too.
|
|
|
|
*/
|
2014-05-23 03:07:36 +04:00
|
|
|
PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG = (__force pci_dev_flags_t) (1 << 0),
|
2008-07-24 20:18:38 +04:00
|
|
|
/* Device configuration is irrevocably lost if disabled into D3 */
|
2014-05-23 03:07:36 +04:00
|
|
|
PCI_DEV_FLAGS_NO_D3 = (__force pci_dev_flags_t) (1 << 1),
|
2011-07-22 09:46:07 +04:00
|
|
|
/* Provide indication device is assigned by a Virtual Machine Manager */
|
2014-05-23 03:07:36 +04:00
|
|
|
PCI_DEV_FLAGS_ASSIGNED = (__force pci_dev_flags_t) (1 << 2),
|
2014-02-04 01:27:39 +04:00
|
|
|
/* Flag for quirk use to store if quirk-specific ACS is enabled */
|
2014-05-23 03:07:36 +04:00
|
|
|
PCI_DEV_FLAGS_ACS_ENABLED_QUIRK = (__force pci_dev_flags_t) (1 << 3),
|
2014-05-29 00:57:02 +04:00
|
|
|
/* Use a PCIe-to-PCI bridge alias even if !pci_is_pcie */
|
|
|
|
PCI_DEV_FLAG_PCIE_BRIDGE_ALIAS = (__force pci_dev_flags_t) (1 << 5),
|
2015-01-16 03:16:04 +03:00
|
|
|
/* Do not use bus resets for device */
|
|
|
|
PCI_DEV_FLAGS_NO_BUS_RESET = (__force pci_dev_flags_t) (1 << 6),
|
2014-11-21 21:24:08 +03:00
|
|
|
/* Do not use PM reset even if device advertises NoSoftRst- */
|
|
|
|
PCI_DEV_FLAGS_NO_PM_RESET = (__force pci_dev_flags_t) (1 << 7),
|
2015-07-13 21:40:02 +03:00
|
|
|
/* Get VPD from function 0 VPD */
|
|
|
|
PCI_DEV_FLAGS_VPD_REF_F0 = (__force pci_dev_flags_t) (1 << 8),
|
2017-04-13 23:30:44 +03:00
|
|
|
/* a non-root bridge where translation occurs, stop alias search here */
|
|
|
|
PCI_DEV_FLAGS_BRIDGE_XLATE_ROOT = (__force pci_dev_flags_t) (1 << 9),
|
2017-04-04 00:02:50 +03:00
|
|
|
/* Do not use FLR even if device advertises PCI_AF_CAP */
|
|
|
|
PCI_DEV_FLAGS_NO_FLR_RESET = (__force pci_dev_flags_t) (1 << 10),
|
2017-05-23 22:18:17 +03:00
|
|
|
/*
|
|
|
|
* Resume before calling the driver's system suspend hooks, disabling
|
|
|
|
* the direct_complete optimization.
|
|
|
|
*/
|
|
|
|
PCI_DEV_FLAGS_NEEDS_RESUME = (__force pci_dev_flags_t) (1 << 11),
|
2017-08-15 06:23:23 +03:00
|
|
|
/* Don't use Relaxed Ordering for TLPs directed at this device */
|
|
|
|
PCI_DEV_FLAGS_NO_RELAXED_ORDERING = (__force pci_dev_flags_t) (1 << 12),
|
2007-10-25 12:16:30 +04:00
|
|
|
};
|
|
|
|
|
2008-06-11 18:35:17 +04:00
|
|
|
enum pci_irq_reroute_variant {
|
|
|
|
INTEL_IRQ_REROUTE_VARIANT = 1,
|
|
|
|
MAX_IRQ_REROUTE_VARIANTS = 3
|
|
|
|
};
|
|
|
|
|
2006-02-14 19:52:22 +03:00
|
|
|
typedef unsigned short __bitwise pci_bus_flags_t;
|
|
|
|
enum pci_bus_flags {
|
2016-08-26 02:26:10 +03:00
|
|
|
PCI_BUS_FLAGS_NO_MSI = (__force pci_bus_flags_t) 1,
|
|
|
|
PCI_BUS_FLAGS_NO_MMRBC = (__force pci_bus_flags_t) 2,
|
|
|
|
PCI_BUS_FLAGS_NO_AERSID = (__force pci_bus_flags_t) 4,
|
2006-02-14 19:52:22 +03:00
|
|
|
};
|
|
|
|
|
2013-07-31 10:53:21 +04:00
|
|
|
/* These values come from the PCI Express Spec */
|
|
|
|
enum pcie_link_width {
|
|
|
|
PCIE_LNK_WIDTH_RESRV = 0x00,
|
|
|
|
PCIE_LNK_X1 = 0x01,
|
|
|
|
PCIE_LNK_X2 = 0x02,
|
|
|
|
PCIE_LNK_X4 = 0x04,
|
|
|
|
PCIE_LNK_X8 = 0x08,
|
|
|
|
PCIE_LNK_X12 = 0x0C,
|
|
|
|
PCIE_LNK_X16 = 0x10,
|
|
|
|
PCIE_LNK_X32 = 0x20,
|
|
|
|
PCIE_LNK_WIDTH_UNKNOWN = 0xFF,
|
|
|
|
};
|
|
|
|
|
2009-12-13 16:11:31 +03:00
|
|
|
/* Based on the PCI Hotplug Spec, but some values are made up by us */
|
|
|
|
enum pci_bus_speed {
|
|
|
|
PCI_SPEED_33MHz = 0x00,
|
|
|
|
PCI_SPEED_66MHz = 0x01,
|
|
|
|
PCI_SPEED_66MHz_PCIX = 0x02,
|
|
|
|
PCI_SPEED_100MHz_PCIX = 0x03,
|
|
|
|
PCI_SPEED_133MHz_PCIX = 0x04,
|
|
|
|
PCI_SPEED_66MHz_PCIX_ECC = 0x05,
|
|
|
|
PCI_SPEED_100MHz_PCIX_ECC = 0x06,
|
|
|
|
PCI_SPEED_133MHz_PCIX_ECC = 0x07,
|
|
|
|
PCI_SPEED_66MHz_PCIX_266 = 0x09,
|
|
|
|
PCI_SPEED_100MHz_PCIX_266 = 0x0a,
|
|
|
|
PCI_SPEED_133MHz_PCIX_266 = 0x0b,
|
2009-12-13 16:11:34 +03:00
|
|
|
AGP_UNKNOWN = 0x0c,
|
|
|
|
AGP_1X = 0x0d,
|
|
|
|
AGP_2X = 0x0e,
|
|
|
|
AGP_4X = 0x0f,
|
|
|
|
AGP_8X = 0x10,
|
2009-12-13 16:11:31 +03:00
|
|
|
PCI_SPEED_66MHz_PCIX_533 = 0x11,
|
|
|
|
PCI_SPEED_100MHz_PCIX_533 = 0x12,
|
|
|
|
PCI_SPEED_133MHz_PCIX_533 = 0x13,
|
|
|
|
PCIE_SPEED_2_5GT = 0x14,
|
|
|
|
PCIE_SPEED_5_0GT = 0x15,
|
2009-12-13 16:11:35 +03:00
|
|
|
PCIE_SPEED_8_0GT = 0x16,
|
2009-12-13 16:11:31 +03:00
|
|
|
PCI_SPEED_UNKNOWN = 0xff,
|
|
|
|
};
|
|
|
|
|
2011-05-10 20:02:11 +04:00
|
|
|
struct pci_cap_saved_data {
|
2013-12-18 03:43:45 +04:00
|
|
|
u16 cap_nr;
|
|
|
|
bool cap_extended;
|
2011-05-10 20:02:11 +04:00
|
|
|
unsigned int size;
|
2006-02-08 12:11:38 +03:00
|
|
|
u32 data[0];
|
|
|
|
};
|
|
|
|
|
2011-05-10 20:02:11 +04:00
|
|
|
struct pci_cap_saved_state {
|
|
|
|
struct hlist_node next;
|
|
|
|
struct pci_cap_saved_data cap;
|
|
|
|
};
|
|
|
|
|
2016-11-09 04:15:05 +03:00
|
|
|
struct irq_affinity;
|
PCI: add PCI Express ASPM support
PCI Express ASPM defines a protocol for PCI Express components in the D0
state to reduce Link power by placing their Links into a low power state
and instructing the other end of the Link to do likewise. This
capability allows hardware-autonomous, dynamic Link power reduction
beyond what is achievable by software-only controlled power management.
However, The device should be configured by software appropriately.
Enabling ASPM will save power, but will introduce device latency.
This patch adds ASPM support in Linux. It introduces a global policy for
ASPM, a sysfs file /sys/module/pcie_aspm/parameters/policy can control
it. The interface can be used as a boot option too. Currently we have
below setting:
-default, BIOS default setting
-powersave, highest power saving mode, enable all available ASPM
state and clock power management
-performance, highest performance, disable ASPM and clock power
management
By default, the 'default' policy is used currently.
In my test, power difference between powersave mode and performance mode
is about 1.3w in a system with 3 PCIE links.
Note: some devices might not work well with aspm, either because chipset
issue or device issue. The patch provide API (pci_disable_link_state),
driver can disable ASPM for specific device.
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-02-25 04:46:41 +03:00
|
|
|
struct pcie_link_state;
|
2008-04-28 23:30:35 +04:00
|
|
|
struct pci_vpd;
|
2009-03-20 06:25:11 +03:00
|
|
|
struct pci_sriov;
|
2009-05-18 09:51:32 +04:00
|
|
|
struct pci_ats;
|
2008-04-28 23:30:35 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* The pci_dev structure is used to describe PCI devices.
|
|
|
|
*/
|
|
|
|
struct pci_dev {
|
|
|
|
struct list_head bus_list; /* node in per-bus list */
|
|
|
|
struct pci_bus *bus; /* bus this device is on */
|
|
|
|
struct pci_bus *subordinate; /* bus this device bridges to */
|
|
|
|
|
|
|
|
void *sysdata; /* hook for sys-specific extension */
|
|
|
|
struct proc_dir_entry *procent; /* device entry in /proc/bus/pci */
|
2008-06-11 01:28:50 +04:00
|
|
|
struct pci_slot *slot; /* Physical slot this device is in */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
unsigned int devfn; /* encoded device & function index */
|
|
|
|
unsigned short vendor;
|
|
|
|
unsigned short device;
|
|
|
|
unsigned short subsystem_vendor;
|
|
|
|
unsigned short subsystem_device;
|
|
|
|
unsigned int class; /* 3 bytes: (base,sub,prog-if) */
|
2007-06-09 02:46:30 +04:00
|
|
|
u8 revision; /* PCI revision, low byte of class word */
|
2005-04-17 02:20:36 +04:00
|
|
|
u8 hdr_type; /* PCI header type (`multi' flag masked out) */
|
2016-09-27 23:23:34 +03:00
|
|
|
#ifdef CONFIG_PCIEAER
|
|
|
|
u16 aer_cap; /* AER capability offset */
|
|
|
|
#endif
|
2013-11-14 22:28:18 +04:00
|
|
|
u8 pcie_cap; /* PCIe capability offset */
|
2013-04-04 20:54:30 +04:00
|
|
|
u8 msi_cap; /* MSI capability offset */
|
|
|
|
u8 msix_cap; /* MSI-X capability offset */
|
2013-11-14 22:28:18 +04:00
|
|
|
u8 pcie_mpss:3; /* PCIe Max Payload Size Supported */
|
2005-04-17 02:20:36 +04:00
|
|
|
u8 rom_base_reg; /* which config register controls the ROM */
|
2013-11-14 22:28:18 +04:00
|
|
|
u8 pin; /* which interrupt pin this device uses */
|
|
|
|
u16 pcie_flags_reg; /* cached PCIe Capabilities Register */
|
2016-03-03 17:38:02 +03:00
|
|
|
unsigned long *dma_alias_mask;/* mask of enabled devfn aliases */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
struct pci_driver *driver; /* which driver has allocated this device */
|
|
|
|
u64 dma_mask; /* Mask of the bits of bus address this
|
|
|
|
device implements. Normally this is
|
|
|
|
0xffffffff. You only need to change
|
|
|
|
this if your device has broken DMA
|
|
|
|
or supports 64-bit transfers. */
|
|
|
|
|
2008-02-05 09:27:55 +03:00
|
|
|
struct device_dma_parameters dma_parms;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
pci_power_t current_state; /* Current operating state. In ACPI-speak,
|
|
|
|
this is D0-D3, D0 being fully functional,
|
|
|
|
and D3 being off. */
|
2013-04-18 02:57:56 +04:00
|
|
|
u8 pm_cap; /* PM capability offset */
|
2008-07-07 05:36:24 +04:00
|
|
|
unsigned int pme_support:5; /* Bitmask of states from which PME#
|
|
|
|
can be generated */
|
PCI / PM: Extend PME polling to all PCI devices
The land of PCI power management is a land of sorrow and ugliness,
especially in the area of signaling events by devices. There are
devices that set their PME Status bits, but don't really bother
to send a PME message or assert PME#. There are hardware vendors
who don't connect PME# lines to the system core logic (they know
who they are). There are PCI Express Root Ports that don't bother
to trigger interrupts when they receive PME messages from the devices
below. There are ACPI BIOSes that forget to provide _PRW methods for
devices capable of signaling wakeup. Finally, there are BIOSes that
do provide _PRW methods for such devices, but then don't bother to
call Notify() for those devices from the corresponding _Lxx/_Exx
GPE-handling methods. In all of these cases the kernel doesn't have
a chance to receive a proper notification that it should wake up a
device, so devices stay in low-power states forever. Worse yet, in
some cases they continuously send PME Messages that are silently
ignored, because the kernel simply doesn't know that it should clear
the device's PME Status bit.
This problem was first observed for "parallel" (non-Express) PCI
devices on add-on cards and Matthew Garrett addressed it by adding
code that polls PME Status bits of such devices, if they are enabled
to signal PME, to the kernel. Recently, however, it has turned out
that PCI Express devices are also affected by this issue and that it
is not limited to add-on devices, so it seems necessary to extend
the PME polling to all PCI devices, including PCI Express and planar
ones. Still, it would be wasteful to poll the PME Status bits of
devices that are known to receive proper PME notifications, so make
the kernel (1) poll the PME Status bits of all PCI and PCIe devices
enabled to signal PME and (2) disable the PME Status polling for
devices for which correct PME notifications are received.
Tested-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2011-10-04 01:16:33 +04:00
|
|
|
unsigned int pme_poll:1; /* Poll device's PME status bit */
|
2008-07-07 05:36:24 +04:00
|
|
|
unsigned int d1_support:1; /* Low power state D1 is supported */
|
|
|
|
unsigned int d2_support:1; /* Low power state D2 is supported */
|
PCI/PM: add PCIe runtime D3cold support
This patch adds runtime D3cold support and corresponding ACPI platform
support. This patch only enables runtime D3cold support; it does not
enable D3cold support during system suspend/hibernate.
D3cold is the deepest power saving state for a PCIe device, where its main
power is removed. While it is in D3cold, you can't access the device at
all, not even its configuration space (which is still accessible in D3hot).
Therefore the PCI PM registers can not be used to transition into/out of
the D3cold state; that must be done by platform logic such as ACPI _PR3.
To support wakeup from D3cold, a system may provide auxiliary power, which
allows a device to request wakeup using a Beacon or the sideband WAKE#
signal. WAKE# is usually connected to platform logic such as ACPI GPE.
This is quite different from other power saving states, where devices
request wakeup via a PME message on the PCIe link.
Some devices, such as those in plug-in slots, have no direct platform
logic. For example, there is usually no ACPI _PR3 for them. D3cold
support for these devices can be done via the PCIe Downstream Port leading
to the device. When the PCIe port is powered on/off, the device is powered
on/off too. Wakeup events from the device will be notified to the
corresponding PCIe port.
For more information about PCIe D3cold and corresponding ACPI support,
please refer to:
- PCI Express Base Specification Revision 2.0
- Advanced Configuration and Power Interface Specification Revision 5.0
[bhelgaas: changelog]
Reviewed-by: Rafael J. Wysocki <rjw@sisk.pl>
Originally-by: Zheng Yan <zheng.z.yan@intel.com>
Signed-off-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2012-06-23 06:23:51 +04:00
|
|
|
unsigned int no_d1d2:1; /* D1 and D2 are forbidden */
|
|
|
|
unsigned int no_d3cold:1; /* D3cold is forbidden */
|
2016-06-02 11:17:12 +03:00
|
|
|
unsigned int bridge_d3:1; /* Allow D3 for bridge */
|
PCI/PM: add PCIe runtime D3cold support
This patch adds runtime D3cold support and corresponding ACPI platform
support. This patch only enables runtime D3cold support; it does not
enable D3cold support during system suspend/hibernate.
D3cold is the deepest power saving state for a PCIe device, where its main
power is removed. While it is in D3cold, you can't access the device at
all, not even its configuration space (which is still accessible in D3hot).
Therefore the PCI PM registers can not be used to transition into/out of
the D3cold state; that must be done by platform logic such as ACPI _PR3.
To support wakeup from D3cold, a system may provide auxiliary power, which
allows a device to request wakeup using a Beacon or the sideband WAKE#
signal. WAKE# is usually connected to platform logic such as ACPI GPE.
This is quite different from other power saving states, where devices
request wakeup via a PME message on the PCIe link.
Some devices, such as those in plug-in slots, have no direct platform
logic. For example, there is usually no ACPI _PR3 for them. D3cold
support for these devices can be done via the PCIe Downstream Port leading
to the device. When the PCIe port is powered on/off, the device is powered
on/off too. Wakeup events from the device will be notified to the
corresponding PCIe port.
For more information about PCIe D3cold and corresponding ACPI support,
please refer to:
- PCI Express Base Specification Revision 2.0
- Advanced Configuration and Power Interface Specification Revision 5.0
[bhelgaas: changelog]
Reviewed-by: Rafael J. Wysocki <rjw@sisk.pl>
Originally-by: Zheng Yan <zheng.z.yan@intel.com>
Signed-off-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2012-06-23 06:23:51 +04:00
|
|
|
unsigned int d3cold_allowed:1; /* D3cold is allowed by user */
|
2010-07-16 21:19:22 +04:00
|
|
|
unsigned int mmio_always_on:1; /* disallow turning off io/mem
|
|
|
|
decoding during bar sizing */
|
2009-09-09 01:14:49 +04:00
|
|
|
unsigned int wakeup_prepared:1;
|
PCI/PM: add PCIe runtime D3cold support
This patch adds runtime D3cold support and corresponding ACPI platform
support. This patch only enables runtime D3cold support; it does not
enable D3cold support during system suspend/hibernate.
D3cold is the deepest power saving state for a PCIe device, where its main
power is removed. While it is in D3cold, you can't access the device at
all, not even its configuration space (which is still accessible in D3hot).
Therefore the PCI PM registers can not be used to transition into/out of
the D3cold state; that must be done by platform logic such as ACPI _PR3.
To support wakeup from D3cold, a system may provide auxiliary power, which
allows a device to request wakeup using a Beacon or the sideband WAKE#
signal. WAKE# is usually connected to platform logic such as ACPI GPE.
This is quite different from other power saving states, where devices
request wakeup via a PME message on the PCIe link.
Some devices, such as those in plug-in slots, have no direct platform
logic. For example, there is usually no ACPI _PR3 for them. D3cold
support for these devices can be done via the PCIe Downstream Port leading
to the device. When the PCIe port is powered on/off, the device is powered
on/off too. Wakeup events from the device will be notified to the
corresponding PCIe port.
For more information about PCIe D3cold and corresponding ACPI support,
please refer to:
- PCI Express Base Specification Revision 2.0
- Advanced Configuration and Power Interface Specification Revision 5.0
[bhelgaas: changelog]
Reviewed-by: Rafael J. Wysocki <rjw@sisk.pl>
Originally-by: Zheng Yan <zheng.z.yan@intel.com>
Signed-off-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2012-06-23 06:23:51 +04:00
|
|
|
unsigned int runtime_d3cold:1; /* whether go through runtime
|
|
|
|
D3cold, not set for devices
|
|
|
|
powered on/off by the
|
|
|
|
corresponding bridge */
|
PCI: Add pci_ignore_hotplug() to ignore hotplug events for a device
Powering off a hot-pluggable device, e.g., with pci_set_power_state(D3cold),
normally generates a hot-remove event that unbinds the driver.
Some drivers expect to remain bound to a device even while they power it
off and back on again. This can be dangerous, because if the device is
removed or replaced while it is powered off, the driver doesn't know that
anything changed. But some drivers accept that risk.
Add pci_ignore_hotplug() for use by drivers that know their device cannot
be removed. Using pci_ignore_hotplug() tells the PCI core that hot-plug
events for the device should be ignored.
The radeon and nouveau drivers use this to switch between a low-power,
integrated GPU and a higher-power, higher-performance discrete GPU. They
power off the unused GPU, but they want to remain bound to it.
This is a reimplementation of f244d8b623da ("ACPIPHP / radeon / nouveau:
Fix VGA switcheroo problem related to hotplug") but extends it to work with
both acpiphp and pciehp.
This fixes a problem where systems with dual GPUs using the radeon drivers
become unusable, freezing every few seconds (see bugzillas below). The
resume of the radeon device may also fail, e.g.,
This fixes problems on dual GPU systems where the radeon driver becomes
unusable because of problems while suspending the device, as in bug 79701:
[drm] radeon: finishing device.
radeon 0000:01:00.0: Userspace still has active objects !
radeon 0000:01:00.0: ffff8800cb4ec288 ffff8800cb4ec000 16384 4294967297 force free
...
WARNING: CPU: 0 PID: 67 at /home/apw/COD/linux/drivers/gpu/drm/radeon/radeon_gart.c:234 radeon_gart_unbind+0xd2/0xe0 [radeon]()
trying to unbind memory from uninitialized GART !
or while resuming it, as in bug 77261:
radeon 0000:01:00.0: ring 0 stalled for more than 10158msec
radeon 0000:01:00.0: GPU lockup ...
radeon 0000:01:00.0: GPU pci config reset
pciehp 0000:00:01.0:pcie04: Card not present on Slot(1-1)
radeon 0000:01:00.0: GPU reset succeeded, trying to resume
*ERROR* radeon: dpm resume failed
radeon 0000:01:00.0: Wait for MC idle timedout !
Link: https://bugzilla.kernel.org/show_bug.cgi?id=77261
Link: https://bugzilla.kernel.org/show_bug.cgi?id=79701
Reported-by: Shawn Starr <shawn.starr@rogers.com>
Reported-by: Jose P. <lbdkmjdf@sharklasers.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Acked-by: Rajat Jain <rajatxjain@gmail.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Dave Airlie <airlied@redhat.com>
CC: stable@vger.kernel.org # v3.15+
2014-09-10 23:45:01 +04:00
|
|
|
unsigned int ignore_hotplug:1; /* Ignore hotplug events */
|
PCI: pciehp: Allow exclusive userspace control of indicators
PCIe hotplug supports optional Attention and Power Indicators, which are
used internally by pciehp. Users can't control the Power Indicator, but
they can control the Attention Indicator by writing to a sysfs "attention"
file.
The Slot Control register has two bits for each indicator, and the PCIe
spec defines the encodings for each as (Reserved/On/Blinking/Off). For
sysfs "attention" writes, pciehp_set_attention_status() maps into these
encodings, so the only useful write values are 0 (Off), 1 (On), and 2
(Blinking).
However, some platforms use all four bits for platform-specific indicators,
and they need to allow direct user control of them while preventing pciehp
from using them at all.
Add a "hotplug_user_indicators" flag to the pci_dev structure. When set,
pciehp does not use either the Attention Indicator or the Power Indicator,
and the low four bits (values 0x0 - 0xf) of sysfs "attention" write values
are written directly to the Attention Indicator Control and Power Indicator
Control fields.
[bhelgaas: changelog, rename flag and accessors to s/attention/indicator/]
Signed-off-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2016-09-13 19:31:59 +03:00
|
|
|
unsigned int hotplug_user_indicators:1; /* SlotCtl indicators
|
|
|
|
controlled exclusively by
|
|
|
|
user sysfs */
|
2009-12-31 14:15:54 +03:00
|
|
|
unsigned int d3_delay; /* D3->D0 transition time in ms */
|
PCI/PM: add PCIe runtime D3cold support
This patch adds runtime D3cold support and corresponding ACPI platform
support. This patch only enables runtime D3cold support; it does not
enable D3cold support during system suspend/hibernate.
D3cold is the deepest power saving state for a PCIe device, where its main
power is removed. While it is in D3cold, you can't access the device at
all, not even its configuration space (which is still accessible in D3hot).
Therefore the PCI PM registers can not be used to transition into/out of
the D3cold state; that must be done by platform logic such as ACPI _PR3.
To support wakeup from D3cold, a system may provide auxiliary power, which
allows a device to request wakeup using a Beacon or the sideband WAKE#
signal. WAKE# is usually connected to platform logic such as ACPI GPE.
This is quite different from other power saving states, where devices
request wakeup via a PME message on the PCIe link.
Some devices, such as those in plug-in slots, have no direct platform
logic. For example, there is usually no ACPI _PR3 for them. D3cold
support for these devices can be done via the PCIe Downstream Port leading
to the device. When the PCIe port is powered on/off, the device is powered
on/off too. Wakeup events from the device will be notified to the
corresponding PCIe port.
For more information about PCIe D3cold and corresponding ACPI support,
please refer to:
- PCI Express Base Specification Revision 2.0
- Advanced Configuration and Power Interface Specification Revision 5.0
[bhelgaas: changelog]
Reviewed-by: Rafael J. Wysocki <rjw@sisk.pl>
Originally-by: Zheng Yan <zheng.z.yan@intel.com>
Signed-off-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2012-06-23 06:23:51 +04:00
|
|
|
unsigned int d3cold_delay; /* D3cold->D0 transition time in ms */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
PCI: add PCI Express ASPM support
PCI Express ASPM defines a protocol for PCI Express components in the D0
state to reduce Link power by placing their Links into a low power state
and instructing the other end of the Link to do likewise. This
capability allows hardware-autonomous, dynamic Link power reduction
beyond what is achievable by software-only controlled power management.
However, The device should be configured by software appropriately.
Enabling ASPM will save power, but will introduce device latency.
This patch adds ASPM support in Linux. It introduces a global policy for
ASPM, a sysfs file /sys/module/pcie_aspm/parameters/policy can control
it. The interface can be used as a boot option too. Currently we have
below setting:
-default, BIOS default setting
-powersave, highest power saving mode, enable all available ASPM
state and clock power management
-performance, highest performance, disable ASPM and clock power
management
By default, the 'default' policy is used currently.
In my test, power difference between powersave mode and performance mode
is about 1.3w in a system with 3 PCIE links.
Note: some devices might not work well with aspm, either because chipset
issue or device issue. The patch provide API (pci_disable_link_state),
driver can disable ASPM for specific device.
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-02-25 04:46:41 +03:00
|
|
|
#ifdef CONFIG_PCIEASPM
|
2013-11-14 22:28:18 +04:00
|
|
|
struct pcie_link_state *link_state; /* ASPM link state */
|
PCI: add PCI Express ASPM support
PCI Express ASPM defines a protocol for PCI Express components in the D0
state to reduce Link power by placing their Links into a low power state
and instructing the other end of the Link to do likewise. This
capability allows hardware-autonomous, dynamic Link power reduction
beyond what is achievable by software-only controlled power management.
However, The device should be configured by software appropriately.
Enabling ASPM will save power, but will introduce device latency.
This patch adds ASPM support in Linux. It introduces a global policy for
ASPM, a sysfs file /sys/module/pcie_aspm/parameters/policy can control
it. The interface can be used as a boot option too. Currently we have
below setting:
-default, BIOS default setting
-powersave, highest power saving mode, enable all available ASPM
state and clock power management
-performance, highest performance, disable ASPM and clock power
management
By default, the 'default' policy is used currently.
In my test, power difference between powersave mode and performance mode
is about 1.3w in a system with 3 PCIE links.
Note: some devices might not work well with aspm, either because chipset
issue or device issue. The patch provide API (pci_disable_link_state),
driver can disable ASPM for specific device.
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-02-25 04:46:41 +03:00
|
|
|
#endif
|
|
|
|
|
2005-11-17 02:10:41 +03:00
|
|
|
pci_channel_state_t error_state; /* current connectivity state */
|
2005-04-17 02:20:36 +04:00
|
|
|
struct device dev; /* Generic device interface */
|
|
|
|
|
|
|
|
int cfg_size; /* Size of configuration space */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Instead of touching interrupt line and base address registers
|
|
|
|
* directly, use the values stored here. They might be different!
|
|
|
|
*/
|
|
|
|
unsigned int irq;
|
|
|
|
struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */
|
|
|
|
|
2013-01-22 01:20:51 +04:00
|
|
|
bool match_driver; /* Skip attaching driver */
|
2005-04-17 02:20:36 +04:00
|
|
|
/* These fields are used by common fixups */
|
2013-11-14 22:28:18 +04:00
|
|
|
unsigned int transparent:1; /* Subtractive decode PCI bridge */
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int multifunction:1;/* Part of multi-function device */
|
|
|
|
/* keep track of device state */
|
2008-02-15 01:56:56 +03:00
|
|
|
unsigned int is_added:1;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int is_busmaster:1; /* device is busmaster */
|
2005-08-17 02:15:58 +04:00
|
|
|
unsigned int no_msi:1; /* device may not use msi */
|
2014-10-03 09:13:24 +04:00
|
|
|
unsigned int no_64bit_msi:1; /* device may only use 32-bit MSIs */
|
2011-11-04 12:45:59 +04:00
|
|
|
unsigned int block_cfg_access:1; /* config space access is blocked */
|
2006-05-09 04:06:09 +04:00
|
|
|
unsigned int broken_parity_status:1; /* Device generates false positive parity */
|
2008-06-11 18:35:17 +04:00
|
|
|
unsigned int irq_reroute_variant:2; /* device needs IRQ rerouting variant */
|
2013-11-14 22:28:18 +04:00
|
|
|
unsigned int msi_enabled:1;
|
2006-05-26 06:58:27 +04:00
|
|
|
unsigned int msix_enabled:1;
|
2008-10-14 10:02:53 +04:00
|
|
|
unsigned int ari_enabled:1; /* ARI forwarding */
|
2015-07-17 23:15:19 +03:00
|
|
|
unsigned int ats_enabled:1; /* Address Translation Service */
|
2017-05-30 19:25:48 +03:00
|
|
|
unsigned int pasid_enabled:1; /* Process Address Space ID */
|
|
|
|
unsigned int pri_enabled:1; /* Page Request Interface */
|
devres: device resource management
Implement device resource management, in short, devres. A device
driver can allocate arbirary size of devres data which is associated
with a release function. On driver detach, release function is
invoked on the devres data, then, devres data is freed.
devreses are typed by associated release functions. Some devreses are
better represented by single instance of the type while others need
multiple instances sharing the same release function. Both usages are
supported.
devreses can be grouped using devres group such that a device driver
can easily release acquired resources halfway through initialization
or selectively release resources (e.g. resources for port 1 out of 4
ports).
This patch adds devres core including documentation and the following
managed interfaces.
* alloc/free : devm_kzalloc(), devm_kzfree()
* IO region : devm_request_region(), devm_release_region()
* IRQ : devm_request_irq(), devm_free_irq()
* DMA : dmam_alloc_coherent(), dmam_free_coherent(),
dmam_declare_coherent_memory(), dmam_pool_create(),
dmam_pool_destroy()
* PCI : pcim_enable_device(), pcim_pin_device(), pci_is_managed()
* iomap : devm_ioport_map(), devm_ioport_unmap(), devm_ioremap(),
devm_ioremap_nocache(), devm_iounmap(), pcim_iomap_table(),
pcim_iomap(), pcim_iounmap()
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
2007-01-20 10:00:26 +03:00
|
|
|
unsigned int is_managed:1;
|
2009-07-31 02:33:21 +04:00
|
|
|
unsigned int needs_freset:1; /* Dev requires fundamental reset */
|
2009-01-16 23:54:43 +03:00
|
|
|
unsigned int state_saved:1;
|
2009-03-20 06:25:11 +03:00
|
|
|
unsigned int is_physfn:1;
|
2009-03-20 06:25:15 +03:00
|
|
|
unsigned int is_virtfn:1;
|
2009-07-28 00:37:48 +04:00
|
|
|
unsigned int reset_fn:1;
|
2009-09-10 01:09:24 +04:00
|
|
|
unsigned int is_hotplug_bridge:1;
|
PCI: Recognize Thunderbolt devices
Detect on probe whether a PCI device is part of a Thunderbolt controller.
Intel uses a Vendor-Specific Extended Capability (VSEC) with ID 0x1234
on such devices. Detect presence of this VSEC and cache it in a newly
added is_thunderbolt bit in struct pci_dev.
Also, add a helper to check whether a given PCI device is situated on a
Thunderbolt daisy chain (i.e., below a PCI device with is_thunderbolt
set).
The necessity arises from the following:
* If an external Thunderbolt GPU is connected to a dual GPU laptop,
that GPU is currently registered with vga_switcheroo even though it
can neither drive the laptop's panel nor be powered off by the
platform. To vga_switcheroo it will appear as if two discrete
GPUs are present. As a result, when the external GPU is runtime
suspended, vga_switcheroo will cut power to the internal discrete GPU
which may not be runtime suspended at all at this moment. The
solution is to not register external GPUs with vga_switcheroo, which
necessitates a way to recognize if they're on a Thunderbolt daisy
chain.
* Dual GPU MacBook Pros introduced 2011+ can no longer switch external
DisplayPort ports between GPUs. (They're no longer just used for DP
but have become combined DP/Thunderbolt ports.) The driver to switch
the ports, drivers/platform/x86/apple-gmux.c, needs to detect presence
of a Thunderbolt controller and, if found, keep external ports
permanently switched to the discrete GPU.
v2: Make kerneldoc for pci_is_thunderbolt_attached() more precise,
drop portion of commit message pertaining to separate series.
(Bjorn Helgaas)
Cc: Andreas Noever <andreas.noever@gmail.com>
Cc: Michael Jamet <michael.jamet@intel.com>
Cc: Tomas Winkler <tomas.winkler@intel.com>
Cc: Amir Levy <amir.jer.levy@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Link: http://patchwork.freedesktop.org/patch/msgid/0ab165a4a35c0b60f29d4c306c653ead14fcd8f9.1489145162.git.lukas@wunner.de
2017-03-10 23:23:45 +03:00
|
|
|
unsigned int is_thunderbolt:1; /* Thunderbolt controller */
|
2010-05-18 10:35:16 +04:00
|
|
|
unsigned int __aer_firmware_first_valid:1;
|
|
|
|
unsigned int __aer_firmware_first:1;
|
2017-05-27 00:02:25 +03:00
|
|
|
unsigned int broken_intx_masking:1; /* INTx masking can't be used */
|
2012-07-09 23:38:57 +04:00
|
|
|
unsigned int io_window_1k:1; /* Intel P2P bridge 1K I/O windows */
|
2014-10-27 08:21:42 +03:00
|
|
|
unsigned int irq_managed:1;
|
PCI: Add dev->has_secondary_link to track downstream PCIe links
A PCIe Port is an interface to a Link. A Root Port is a PCI-PCI bridge in
a Root Complex and has a Link on its secondary (downstream) side. For
other Ports, the Link may be on either the upstream (closer to the Root
Complex) or downstream side of the Port.
The usual topology has a Root Port connected to an Upstream Port. We
previously assumed this was the only possible topology, and that a
Downstream Port's Link was always on its downstream side, like this:
+---------------------+
+------+ | Downstream |
| Root | | Upstream Port +--Link--
| Port +--Link--+ Port |
+------+ | Downstream |
| Port +--Link--
+---------------------+
But systems do exist (see URL below) where the Root Port is connected to a
Downstream Port. In this case, a Downstream Port's Link may be on either
the upstream or downstream side:
+---------------------+
+------+ | Upstream |
| Root | | Downstream Port +--Link--
| Port +--Link--+ Port |
+------+ | Downstream |
| Port +--Link--
+---------------------+
We can't use the Port type to determine which side the Link is on, so add a
bit in struct pci_dev to keep track.
A Root Port's Link is always on the Port's secondary side. A component
(Endpoint or Port) on the other end of the Link obviously has the Link on
its upstream side. If that component is a Port, it is part of a Switch or
a Bridge. A Bridge has a PCI or PCI-X bus on its secondary side, not a
Link. The internal bus of a Switch connects the Port to another Port whose
Link is on the downstream side.
[bhelgaas: changelog, comment, cache "type", use if/else]
Link: http://lkml.kernel.org/r/54EB81B2.4050904@pobox.com
Link: https://bugzilla.kernel.org/show_bug.cgi?id=94361
Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2015-05-21 10:05:02 +03:00
|
|
|
unsigned int has_secondary_link:1;
|
2016-02-25 23:35:57 +03:00
|
|
|
unsigned int non_compliant_bars:1; /* broken BARs; ignore them */
|
2017-05-24 11:15:32 +03:00
|
|
|
unsigned int is_probed:1; /* device probing in progress */
|
2007-10-25 12:16:30 +04:00
|
|
|
pci_dev_flags_t dev_flags;
|
PCI: switch pci_{enable,disable}_device() to be nestable
Changes the pci_{enable,disable}_device() functions to work in a
nested basis, so that eg, three calls to enable_device() require three
calls to disable_device().
The reason for this is to simplify PCI drivers for
multi-interface/capability devices. These are devices that cram more
than one interface in a single function. A relevant example of that is
the Wireless [USB] Host Controller Interface (similar to EHCI) [see
http://www.intel.com/technology/comms/wusb/whci.htm].
In these kind of devices, multiple interfaces are accessed through a
single bar and IRQ line. For that, the drivers map only the smallest
area of the bar to access their register banks and use shared IRQ
handlers.
However, because the order at which those drivers load cannot be known
ahead of time, the sequence in which the calls to pci_enable_device()
and pci_disable_device() cannot be predicted. Thus:
1. driverA starts pci_enable_device()
2. driverB starts pci_enable_device()
3. driverA shutdown pci_disable_device()
4. driverB shutdown pci_disable_device()
between steps 3 and 4, driver B would loose access to it's device,
even if it didn't intend to.
By using this modification, the device won't be disabled until all the
callers to enable() have called disable().
This is implemented by replacing 'struct pci_dev->is_enabled' from a
bitfield to an atomic use count. Each caller to enable increments it,
each caller to disable decrements it. When the count increments from 0
to 1, __pci_enable_device() is called to actually enable the
device. When it drops to zero, pci_disable_device() actually does the
disabling.
We keep the backend __pci_enable_device() for pci_default_resume() to
use and also change the sysfs method implementation, so that userspace
enabling/disabling the device doesn't disable it one time too much.
Signed-off-by: Inaky Perez-Gonzalez <inaky@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2006-11-22 23:40:31 +03:00
|
|
|
atomic_t enable_cnt; /* pci_enable_device has been called */
|
2005-08-17 02:15:58 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
u32 saved_config_space[16]; /* config space saved at suspend time */
|
2006-02-08 12:11:38 +03:00
|
|
|
struct hlist_head saved_cap_space;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct bin_attribute *rom_attr; /* attribute descriptor for sysfs ROM entry */
|
|
|
|
int rom_attr_enabled; /* has display of the rom attribute been enabled? */
|
|
|
|
struct bin_attribute *res_attr[DEVICE_COUNT_RESOURCE]; /* sysfs file for resources */
|
2008-03-19 03:00:22 +03:00
|
|
|
struct bin_attribute *res_attr_wc[DEVICE_COUNT_RESOURCE]; /* sysfs file for WC mapping of resources */
|
2016-06-11 22:13:38 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_PCIE_PTM
|
|
|
|
unsigned int ptm_root:1;
|
|
|
|
unsigned int ptm_enabled:1;
|
2016-06-13 00:26:40 +03:00
|
|
|
u8 ptm_granularity;
|
2016-06-11 22:13:38 +03:00
|
|
|
#endif
|
2007-01-28 22:42:52 +03:00
|
|
|
#ifdef CONFIG_PCI_MSI
|
2013-12-20 00:30:17 +04:00
|
|
|
const struct attribute_group **msi_irq_groups;
|
2007-01-28 22:42:52 +03:00
|
|
|
#endif
|
2008-03-05 19:52:39 +03:00
|
|
|
struct pci_vpd *vpd;
|
2011-10-30 19:35:08 +04:00
|
|
|
#ifdef CONFIG_PCI_ATS
|
2009-03-20 06:25:15 +03:00
|
|
|
union {
|
|
|
|
struct pci_sriov *sriov; /* SR-IOV capability related */
|
|
|
|
struct pci_dev *physfn; /* the PF this VF is associated with */
|
|
|
|
};
|
2015-07-17 23:27:34 +03:00
|
|
|
u16 ats_cap; /* ATS Capability offset */
|
|
|
|
u8 ats_stu; /* ATS Smallest Translation Unit */
|
2015-07-17 23:15:19 +03:00
|
|
|
atomic_t ats_ref_cnt; /* number of VFs with ATS enabled */
|
2017-05-30 19:25:49 +03:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PCI_PRI
|
|
|
|
u32 pri_reqs_alloc; /* Number of PRI requests allocated */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PCI_PASID
|
|
|
|
u16 pasid_features;
|
2009-03-20 06:25:11 +03:00
|
|
|
#endif
|
2012-12-10 22:24:42 +04:00
|
|
|
phys_addr_t rom; /* Physical address of ROM if it's not from the BAR */
|
2012-12-06 01:33:27 +04:00
|
|
|
size_t romlen; /* Length of ROM if it's not from the BAR */
|
PCI: Introduce new device binding path using pci_dev.driver_override
The driver_override field allows us to specify the driver for a device
rather than relying on the driver to provide a positive match of the
device. This shortcuts the existing process of looking up the vendor and
device ID, adding them to the driver new_id, binding the device, then
removing the ID, but it also provides a couple advantages.
First, the above existing process allows the driver to bind to any device
matching the new_id for the window where it's enabled. This is often not
desired, such as the case of trying to bind a single device to a meta
driver like pci-stub or vfio-pci. Using driver_override we can do this
deterministically using:
echo pci-stub > /sys/bus/pci/devices/0000:03:00.0/driver_override
echo 0000:03:00.0 > /sys/bus/pci/devices/0000:03:00.0/driver/unbind
echo 0000:03:00.0 > /sys/bus/pci/drivers_probe
Previously we could not invoke drivers_probe after adding a device to
new_id for a driver as we get non-deterministic behavior whether the driver
we intend or the standard driver will claim the device. Now it becomes a
deterministic process, only the driver matching driver_override will probe
the device.
To return the device to the standard driver, we simply clear the
driver_override and reprobe the device:
echo > /sys/bus/pci/devices/0000:03:00.0/driver_override
echo 0000:03:00.0 > /sys/bus/pci/devices/0000:03:00.0/driver/unbind
echo 0000:03:00.0 > /sys/bus/pci/drivers_probe
Another advantage to this approach is that we can specify a driver override
to force a specific binding or prevent any binding. For instance when an
IOMMU group is exposed to userspace through VFIO we require that all
devices within that group are owned by VFIO. However, devices can be
hot-added into an IOMMU group, in which case we want to prevent the device
from binding to any driver (override driver = "none") or perhaps have it
automatically bind to vfio-pci. With driver_override it's a simple matter
for this field to be set internally when the device is first discovered to
prevent driver matches.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Alexander Graf <agraf@suse.de>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-05-20 18:53:21 +04:00
|
|
|
char *driver_override; /* Driver name to force a match */
|
2017-03-30 06:48:59 +03:00
|
|
|
|
|
|
|
unsigned long priv_flags; /* Private flags for the pci driver */
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2010-04-09 04:07:55 +04:00
|
|
|
static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_PCI_IOV
|
|
|
|
if (dev->is_virtfn)
|
|
|
|
dev = dev->physfn;
|
|
|
|
#endif
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2013-05-25 17:48:30 +04:00
|
|
|
struct pci_dev *pci_alloc_dev(struct pci_bus *bus);
|
2007-04-05 11:19:08 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#define to_pci_dev(n) container_of(n, struct pci_dev, dev)
|
|
|
|
#define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
|
|
|
|
|
2006-12-13 01:55:59 +03:00
|
|
|
static inline int pci_channel_offline(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
return (pdev->error_state != pci_channel_io_normal);
|
|
|
|
}
|
|
|
|
|
2012-02-24 07:18:59 +04:00
|
|
|
struct pci_host_bridge {
|
2012-04-03 05:31:53 +04:00
|
|
|
struct device dev;
|
2012-02-24 07:18:59 +04:00
|
|
|
struct pci_bus *bus; /* root bus */
|
2016-11-25 13:57:09 +03:00
|
|
|
struct pci_ops *ops;
|
|
|
|
void *sysdata;
|
|
|
|
int busnr;
|
2015-02-05 08:44:44 +03:00
|
|
|
struct list_head windows; /* resource_entry */
|
2017-06-28 23:14:02 +03:00
|
|
|
u8 (*swizzle_irq)(struct pci_dev *, u8 *); /* platform IRQ swizzler */
|
|
|
|
int (*map_irq)(const struct pci_dev *, u8, u8);
|
2012-04-03 05:31:53 +04:00
|
|
|
void (*release_fn)(struct pci_host_bridge *);
|
|
|
|
void *release_data;
|
2016-11-25 13:57:09 +03:00
|
|
|
struct msi_controller *msi;
|
2015-03-25 09:37:06 +03:00
|
|
|
unsigned int ignore_reset_delay:1; /* for entire hierarchy */
|
2017-07-12 07:04:14 +03:00
|
|
|
unsigned int no_ext_tags:1; /* no Extended Tags */
|
2015-11-11 04:12:25 +03:00
|
|
|
/* Resource alignment requirements */
|
|
|
|
resource_size_t (*align_resource)(struct pci_dev *dev,
|
|
|
|
const struct resource *res,
|
|
|
|
resource_size_t start,
|
|
|
|
resource_size_t size,
|
|
|
|
resource_size_t align);
|
2016-11-25 13:57:10 +03:00
|
|
|
unsigned long private[0] ____cacheline_aligned;
|
2012-02-24 07:18:59 +04:00
|
|
|
};
|
2006-02-08 12:11:38 +03:00
|
|
|
|
2012-04-03 05:31:53 +04:00
|
|
|
#define to_pci_host_bridge(n) container_of(n, struct pci_host_bridge, dev)
|
2015-11-11 04:12:25 +03:00
|
|
|
|
2016-11-25 13:57:10 +03:00
|
|
|
static inline void *pci_host_bridge_priv(struct pci_host_bridge *bridge)
|
|
|
|
{
|
|
|
|
return (void *)bridge->private;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct pci_host_bridge *pci_host_bridge_from_priv(void *priv)
|
|
|
|
{
|
|
|
|
return container_of(priv, struct pci_host_bridge, private);
|
|
|
|
}
|
|
|
|
|
2016-11-25 13:57:11 +03:00
|
|
|
struct pci_host_bridge *pci_alloc_host_bridge(size_t priv);
|
2017-06-28 23:13:53 +03:00
|
|
|
struct pci_host_bridge *devm_pci_alloc_host_bridge(struct device *dev,
|
|
|
|
size_t priv);
|
2017-06-28 23:13:52 +03:00
|
|
|
void pci_free_host_bridge(struct pci_host_bridge *bridge);
|
2015-11-11 04:12:25 +03:00
|
|
|
struct pci_host_bridge *pci_find_host_bridge(struct pci_bus *bus);
|
|
|
|
|
2012-04-03 05:31:53 +04:00
|
|
|
void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
|
|
|
|
void (*release_fn)(struct pci_host_bridge *),
|
|
|
|
void *release_data);
|
2012-04-03 05:31:53 +04:00
|
|
|
|
ACPI / PCI: Set root bridge ACPI handle in advance
The ACPI handles of PCI root bridges need to be known to
acpi_bind_one(), so that it can create the appropriate
"firmware_node" and "physical_node" files for them, but currently
the way it gets to know those handles is not exactly straightforward
(to put it lightly).
This is how it works, roughly:
1. acpi_bus_scan() finds the handle of a PCI root bridge,
creates a struct acpi_device object for it and passes that
object to acpi_pci_root_add().
2. acpi_pci_root_add() creates a struct acpi_pci_root object,
populates its "device" field with its argument's address
(device->handle is the ACPI handle found in step 1).
3. The struct acpi_pci_root object created in step 2 is passed
to pci_acpi_scan_root() and used to get resources that are
passed to pci_create_root_bus().
4. pci_create_root_bus() creates a struct pci_host_bridge object
and passes its "dev" member to device_register().
5. platform_notify(), which for systems with ACPI is set to
acpi_platform_notify(), is called.
So far, so good. Now it starts to be "interesting".
6. acpi_find_bridge_device() is used to find the ACPI handle of
the given device (which is the PCI root bridge) and executes
acpi_pci_find_root_bridge(), among other things, for the
given device object.
7. acpi_pci_find_root_bridge() uses the name (sic!) of the given
device object to extract the segment and bus numbers of the PCI
root bridge and passes them to acpi_get_pci_rootbridge_handle().
8. acpi_get_pci_rootbridge_handle() browses the list of ACPI PCI
root bridges and finds the one that matches the given segment
and bus numbers. Its handle is then used to initialize the
ACPI handle of the PCI root bridge's device object by
acpi_bind_one(). However, this is *exactly* the ACPI handle we
started with in step 1.
Needless to say, this is quite embarassing, but it may be avoided
thanks to commit f3fd0c8 (ACPI: Allow ACPI handles of devices to be
initialized in advance), which makes it possible to initialize the
ACPI handle of a device before passing it to device_register().
Accordingly, add a new __weak routine, pcibios_root_bridge_prepare(),
defaulting to an empty implementation that can be replaced by the
interested architecutres (x86 and ia64 at the moment) with functions
that will set the root bridge's ACPI handle before its dev member is
passed to device_register(). Make both x86 and ia64 provide such
implementations of pcibios_root_bridge_prepare() and remove
acpi_pci_find_root_bridge() and acpi_get_pci_rootbridge_handle() that
aren't necessary any more.
Included is a fix for breakage on systems with non-ACPI PCI host
bridges from Bjorn Helgaas.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-01-10 01:33:37 +04:00
|
|
|
int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge);
|
|
|
|
|
2010-02-23 20:24:36 +03:00
|
|
|
/*
|
|
|
|
* The first PCI_BRIDGE_RESOURCE_NUM PCI bus resources (those that correspond
|
|
|
|
* to P2P or CardBus bridge windows) go in a table. Additional ones (for
|
|
|
|
* buses below host bridges or subtractive decode bridges) go in the list.
|
|
|
|
* Use pci_bus_for_each_resource() to iterate through all the resources.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PCI_SUBTRACTIVE_DECODE means the bridge forwards the window implicitly
|
|
|
|
* and there's no way to program the bridge with the details of the window.
|
|
|
|
* This does not apply to ACPI _CRS windows, even with the _DEC subtractive-
|
|
|
|
* decode bit set, because they are explicit and can be programmed with _SRS.
|
|
|
|
*/
|
|
|
|
#define PCI_SUBTRACTIVE_DECODE 0x1
|
|
|
|
|
|
|
|
struct pci_bus_resource {
|
|
|
|
struct list_head list;
|
|
|
|
struct resource *res;
|
|
|
|
unsigned int flags;
|
|
|
|
};
|
2005-07-28 22:37:33 +04:00
|
|
|
|
|
|
|
#define PCI_REGION_FLAG_MASK 0x0fU /* These bits of resource flags tell us the PCI region flags */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
struct pci_bus {
|
|
|
|
struct list_head node; /* node in list of buses */
|
|
|
|
struct pci_bus *parent; /* parent bus this bridge is on */
|
|
|
|
struct list_head children; /* list of child buses */
|
|
|
|
struct list_head devices; /* list of devices on this bus */
|
|
|
|
struct pci_dev *self; /* bridge device as seen by parent */
|
2015-07-17 12:16:31 +03:00
|
|
|
struct list_head slots; /* list of slots on this bus;
|
|
|
|
protected by pci_slot_mutex */
|
2010-02-23 20:24:36 +03:00
|
|
|
struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
|
|
|
|
struct list_head resources; /* address space routed to this bus */
|
2012-05-18 05:51:11 +04:00
|
|
|
struct resource busn_res; /* bus numbers routed to this bus */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
struct pci_ops *ops; /* configuration access functions */
|
2014-11-12 03:45:45 +03:00
|
|
|
struct msi_controller *msi; /* MSI controller */
|
2005-04-17 02:20:36 +04:00
|
|
|
void *sysdata; /* hook for sys-specific extension */
|
|
|
|
struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */
|
|
|
|
|
|
|
|
unsigned char number; /* bus number */
|
|
|
|
unsigned char primary; /* number of primary bridge */
|
2009-12-13 16:11:32 +03:00
|
|
|
unsigned char max_bus_speed; /* enum pci_bus_speed */
|
|
|
|
unsigned char cur_bus_speed; /* enum pci_bus_speed */
|
2014-09-29 18:29:26 +04:00
|
|
|
#ifdef CONFIG_PCI_DOMAINS_GENERIC
|
|
|
|
int domain_nr;
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
char name[48];
|
|
|
|
|
|
|
|
unsigned short bridge_ctl; /* manage NO_ISA/FBB/et al behaviors */
|
2013-11-14 22:28:18 +04:00
|
|
|
pci_bus_flags_t bus_flags; /* inherited by child buses */
|
2005-04-17 02:20:36 +04:00
|
|
|
struct device *bridge;
|
2007-05-23 06:47:54 +04:00
|
|
|
struct device dev;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct bin_attribute *legacy_io; /* legacy I/O for this bus */
|
|
|
|
struct bin_attribute *legacy_mem; /* legacy mem */
|
2008-03-13 07:48:03 +03:00
|
|
|
unsigned int is_added:1;
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2007-05-23 06:47:54 +04:00
|
|
|
#define to_pci_bus(n) container_of(n, struct pci_bus, dev)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-03-20 23:55:55 +03:00
|
|
|
/*
|
2013-11-14 22:28:18 +04:00
|
|
|
* Returns true if the PCI bus is root (behind host-PCI bridge),
|
2009-03-20 23:55:55 +03:00
|
|
|
* false otherwise
|
2013-09-25 01:14:57 +04:00
|
|
|
*
|
|
|
|
* Some code assumes that "bus->self == NULL" means that bus is a root bus.
|
|
|
|
* This is incorrect because "virtual" buses added for SR-IOV (via
|
|
|
|
* virtfn_add_bus()) have "bus->self == NULL" but are not root buses.
|
2009-03-20 23:55:55 +03:00
|
|
|
*/
|
|
|
|
static inline bool pci_is_root_bus(struct pci_bus *pbus)
|
|
|
|
{
|
|
|
|
return !(pbus->parent);
|
|
|
|
}
|
|
|
|
|
2014-05-04 08:23:37 +04:00
|
|
|
/**
|
|
|
|
* pci_is_bridge - check if the PCI device is a bridge
|
|
|
|
* @dev: PCI device
|
|
|
|
*
|
|
|
|
* Return true if the PCI device is bridge whether it has subordinate
|
|
|
|
* or not.
|
|
|
|
*/
|
|
|
|
static inline bool pci_is_bridge(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
return dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
|
|
|
|
dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
|
|
|
|
}
|
|
|
|
|
2013-11-06 21:11:48 +04:00
|
|
|
static inline struct pci_dev *pci_upstream_bridge(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
dev = pci_physfn(dev);
|
|
|
|
if (pci_is_root_bus(dev->bus))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return dev->bus->self;
|
|
|
|
}
|
|
|
|
|
2015-03-03 20:52:11 +03:00
|
|
|
struct device *pci_get_host_bridge_device(struct pci_dev *dev);
|
|
|
|
void pci_put_host_bridge_device(struct device *dev);
|
|
|
|
|
2009-01-05 16:50:27 +03:00
|
|
|
#ifdef CONFIG_PCI_MSI
|
|
|
|
static inline bool pci_dev_msi_enabled(struct pci_dev *pci_dev)
|
|
|
|
{
|
|
|
|
return pci_dev->msi_enabled || pci_dev->msix_enabled;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline bool pci_dev_msi_enabled(struct pci_dev *pci_dev) { return false; }
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* Error values that may be returned by PCI functions.
|
|
|
|
*/
|
|
|
|
#define PCIBIOS_SUCCESSFUL 0x00
|
|
|
|
#define PCIBIOS_FUNC_NOT_SUPPORTED 0x81
|
|
|
|
#define PCIBIOS_BAD_VENDOR_ID 0x83
|
|
|
|
#define PCIBIOS_DEVICE_NOT_FOUND 0x86
|
|
|
|
#define PCIBIOS_BAD_REGISTER_NUMBER 0x87
|
|
|
|
#define PCIBIOS_SET_FAILED 0x88
|
|
|
|
#define PCIBIOS_BUFFER_TOO_SMALL 0x89
|
|
|
|
|
2012-06-11 09:27:33 +04:00
|
|
|
/*
|
2013-11-14 22:28:18 +04:00
|
|
|
* Translate above to generic errno for passing back through non-PCI code.
|
2012-06-11 09:27:33 +04:00
|
|
|
*/
|
|
|
|
static inline int pcibios_err_to_errno(int err)
|
|
|
|
{
|
|
|
|
if (err <= PCIBIOS_SUCCESSFUL)
|
|
|
|
return err; /* Assume already errno */
|
|
|
|
|
|
|
|
switch (err) {
|
|
|
|
case PCIBIOS_FUNC_NOT_SUPPORTED:
|
|
|
|
return -ENOENT;
|
|
|
|
case PCIBIOS_BAD_VENDOR_ID:
|
2014-05-21 09:23:30 +04:00
|
|
|
return -ENOTTY;
|
2012-06-11 09:27:33 +04:00
|
|
|
case PCIBIOS_DEVICE_NOT_FOUND:
|
|
|
|
return -ENODEV;
|
|
|
|
case PCIBIOS_BAD_REGISTER_NUMBER:
|
|
|
|
return -EFAULT;
|
|
|
|
case PCIBIOS_SET_FAILED:
|
|
|
|
return -EIO;
|
|
|
|
case PCIBIOS_BUFFER_TOO_SMALL:
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
2014-05-21 09:23:30 +04:00
|
|
|
return -ERANGE;
|
2012-06-11 09:27:33 +04:00
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Low-level architecture-dependent routines */
|
|
|
|
|
|
|
|
struct pci_ops {
|
2016-02-09 17:30:47 +03:00
|
|
|
int (*add_bus)(struct pci_bus *bus);
|
|
|
|
void (*remove_bus)(struct pci_bus *bus);
|
2015-01-10 05:34:39 +03:00
|
|
|
void __iomem *(*map_bus)(struct pci_bus *bus, unsigned int devfn, int where);
|
2005-04-17 02:20:36 +04:00
|
|
|
int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val);
|
|
|
|
int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val);
|
|
|
|
};
|
|
|
|
|
2008-02-10 17:45:28 +03:00
|
|
|
/*
|
|
|
|
* ACPI needs to be able to access PCI config space before we've done a
|
|
|
|
* PCI bus scan and created pci_bus structures.
|
|
|
|
*/
|
2013-04-12 22:02:59 +04:00
|
|
|
int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
|
|
|
|
int reg, int len, u32 *val);
|
|
|
|
int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
|
|
|
|
int reg, int len, u32 val);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
PCI: Add pci_bus_addr_t
David Ahern reported that d63e2e1f3df9 ("sparc/PCI: Clip bridge windows
to fit in upstream windows") fails to boot on sparc/T5-8:
pci 0000:06:00.0: reg 0x184: can't handle BAR above 4GB (bus address 0x110204000)
The problem is that sparc64 assumed that dma_addr_t only needed to hold DMA
addresses, i.e., bus addresses returned via the DMA API (dma_map_single(),
etc.), while the PCI core assumed dma_addr_t could hold *any* bus address,
including raw BAR values. On sparc64, all DMA addresses fit in 32 bits, so
dma_addr_t is a 32-bit type. However, BAR values can be 64 bits wide, so
they don't fit in a dma_addr_t. d63e2e1f3df9 added new checking that
tripped over this mismatch.
Add pci_bus_addr_t, which is wide enough to hold any PCI bus address,
including both raw BAR values and DMA addresses. This will be 64 bits
on 64-bit platforms and on platforms with a 64-bit dma_addr_t. Then
dma_addr_t only needs to be wide enough to hold addresses from the DMA API.
[bhelgaas: changelog, bugzilla, Kconfig to ensure pci_bus_addr_t is at
least as wide as dma_addr_t, documentation]
Fixes: d63e2e1f3df9 ("sparc/PCI: Clip bridge windows to fit in upstream windows")
Fixes: 23b13bc76f35 ("PCI: Fail safely if we can't handle BARs larger than 4GB")
Link: http://lkml.kernel.org/r/CAE9FiQU1gJY1LYrxs+ma5LCTEEe4xmtjRG0aXJ9K_Tsu+m9Wuw@mail.gmail.com
Link: http://lkml.kernel.org/r/1427857069-6789-1-git-send-email-yinghai@kernel.org
Link: https://bugzilla.kernel.org/show_bug.cgi?id=96231
Reported-by: David Ahern <david.ahern@oracle.com>
Tested-by: David Ahern <david.ahern@oracle.com>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: David S. Miller <davem@davemloft.net>
CC: stable@vger.kernel.org # v3.19+
2015-05-28 03:23:51 +03:00
|
|
|
#ifdef CONFIG_PCI_BUS_ADDR_T_64BIT
|
|
|
|
typedef u64 pci_bus_addr_t;
|
|
|
|
#else
|
|
|
|
typedef u32 pci_bus_addr_t;
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
struct pci_bus_region {
|
PCI: Add pci_bus_addr_t
David Ahern reported that d63e2e1f3df9 ("sparc/PCI: Clip bridge windows
to fit in upstream windows") fails to boot on sparc/T5-8:
pci 0000:06:00.0: reg 0x184: can't handle BAR above 4GB (bus address 0x110204000)
The problem is that sparc64 assumed that dma_addr_t only needed to hold DMA
addresses, i.e., bus addresses returned via the DMA API (dma_map_single(),
etc.), while the PCI core assumed dma_addr_t could hold *any* bus address,
including raw BAR values. On sparc64, all DMA addresses fit in 32 bits, so
dma_addr_t is a 32-bit type. However, BAR values can be 64 bits wide, so
they don't fit in a dma_addr_t. d63e2e1f3df9 added new checking that
tripped over this mismatch.
Add pci_bus_addr_t, which is wide enough to hold any PCI bus address,
including both raw BAR values and DMA addresses. This will be 64 bits
on 64-bit platforms and on platforms with a 64-bit dma_addr_t. Then
dma_addr_t only needs to be wide enough to hold addresses from the DMA API.
[bhelgaas: changelog, bugzilla, Kconfig to ensure pci_bus_addr_t is at
least as wide as dma_addr_t, documentation]
Fixes: d63e2e1f3df9 ("sparc/PCI: Clip bridge windows to fit in upstream windows")
Fixes: 23b13bc76f35 ("PCI: Fail safely if we can't handle BARs larger than 4GB")
Link: http://lkml.kernel.org/r/CAE9FiQU1gJY1LYrxs+ma5LCTEEe4xmtjRG0aXJ9K_Tsu+m9Wuw@mail.gmail.com
Link: http://lkml.kernel.org/r/1427857069-6789-1-git-send-email-yinghai@kernel.org
Link: https://bugzilla.kernel.org/show_bug.cgi?id=96231
Reported-by: David Ahern <david.ahern@oracle.com>
Tested-by: David Ahern <david.ahern@oracle.com>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: David S. Miller <davem@davemloft.net>
CC: stable@vger.kernel.org # v3.19+
2015-05-28 03:23:51 +03:00
|
|
|
pci_bus_addr_t start;
|
|
|
|
pci_bus_addr_t end;
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pci_dynids {
|
|
|
|
spinlock_t lock; /* protects list, index */
|
|
|
|
struct list_head list; /* for IDs added at runtime */
|
|
|
|
};
|
|
|
|
|
2013-11-14 22:28:18 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PCI Error Recovery System (PCI-ERS). If a PCI device driver provides
|
|
|
|
* a set of callbacks in struct pci_error_handlers, that device driver
|
|
|
|
* will be notified of PCI bus errors, and will be driven to recovery
|
|
|
|
* when an error occurs.
|
2005-11-17 02:10:41 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
typedef unsigned int __bitwise pci_ers_result_t;
|
|
|
|
|
|
|
|
enum pci_ers_result {
|
|
|
|
/* no result/none/not supported in device driver */
|
|
|
|
PCI_ERS_RESULT_NONE = (__force pci_ers_result_t) 1,
|
|
|
|
|
|
|
|
/* Device driver can recover without slot reset */
|
|
|
|
PCI_ERS_RESULT_CAN_RECOVER = (__force pci_ers_result_t) 2,
|
|
|
|
|
|
|
|
/* Device driver wants slot to be reset. */
|
|
|
|
PCI_ERS_RESULT_NEED_RESET = (__force pci_ers_result_t) 3,
|
|
|
|
|
|
|
|
/* Device has completely failed, is unrecoverable */
|
|
|
|
PCI_ERS_RESULT_DISCONNECT = (__force pci_ers_result_t) 4,
|
|
|
|
|
|
|
|
/* Device driver is fully recovered and operational */
|
|
|
|
PCI_ERS_RESULT_RECOVERED = (__force pci_ers_result_t) 5,
|
2012-11-17 15:47:18 +04:00
|
|
|
|
|
|
|
/* No AER capabilities registered for the driver */
|
|
|
|
PCI_ERS_RESULT_NO_AER_DRIVER = (__force pci_ers_result_t) 6,
|
2005-11-17 02:10:41 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* PCI bus error event callbacks */
|
2008-01-31 02:21:33 +03:00
|
|
|
struct pci_error_handlers {
|
2005-11-17 02:10:41 +03:00
|
|
|
/* PCI bus error detected on this device */
|
|
|
|
pci_ers_result_t (*error_detected)(struct pci_dev *dev,
|
2008-01-31 02:21:33 +03:00
|
|
|
enum pci_channel_state error);
|
2005-11-17 02:10:41 +03:00
|
|
|
|
|
|
|
/* MMIO has been re-enabled, but not DMA */
|
|
|
|
pci_ers_result_t (*mmio_enabled)(struct pci_dev *dev);
|
|
|
|
|
|
|
|
/* PCI slot has been reset */
|
|
|
|
pci_ers_result_t (*slot_reset)(struct pci_dev *dev);
|
|
|
|
|
2014-05-02 20:40:42 +04:00
|
|
|
/* PCI function reset prepare or completed */
|
2017-06-01 14:10:38 +03:00
|
|
|
void (*reset_prepare)(struct pci_dev *dev);
|
|
|
|
void (*reset_done)(struct pci_dev *dev);
|
2014-05-02 20:40:42 +04:00
|
|
|
|
2005-11-17 02:10:41 +03:00
|
|
|
/* Device driver may resume normal operations */
|
|
|
|
void (*resume)(struct pci_dev *dev);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
struct module;
|
|
|
|
struct pci_driver {
|
|
|
|
struct list_head node;
|
2010-09-03 01:28:51 +04:00
|
|
|
const char *name;
|
2005-04-17 02:20:36 +04:00
|
|
|
const struct pci_device_id *id_table; /* must be non-NULL for probe to be called */
|
|
|
|
int (*probe) (struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
|
|
|
|
void (*remove) (struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */
|
|
|
|
int (*suspend) (struct pci_dev *dev, pm_message_t state); /* Device suspended */
|
2006-06-25 01:50:29 +04:00
|
|
|
int (*suspend_late) (struct pci_dev *dev, pm_message_t state);
|
|
|
|
int (*resume_early) (struct pci_dev *dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
int (*resume) (struct pci_dev *dev); /* Device woken up */
|
2005-04-08 09:53:31 +04:00
|
|
|
void (*shutdown) (struct pci_dev *dev);
|
2012-11-06 00:20:36 +04:00
|
|
|
int (*sriov_configure) (struct pci_dev *dev, int num_vfs); /* PF pdev */
|
2012-09-07 20:33:14 +04:00
|
|
|
const struct pci_error_handlers *err_handler;
|
2017-07-19 16:01:06 +03:00
|
|
|
const struct attribute_group **groups;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct device_driver driver;
|
|
|
|
struct pci_dynids dynids;
|
|
|
|
};
|
|
|
|
|
2008-01-31 02:21:33 +03:00
|
|
|
#define to_pci_driver(drv) container_of(drv, struct pci_driver, driver)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* PCI_DEVICE - macro used to describe a specific pci device
|
|
|
|
* @vend: the 16 bit PCI Vendor ID
|
|
|
|
* @dev: the 16 bit PCI Device ID
|
|
|
|
*
|
|
|
|
* This macro is used to create a struct pci_device_id that matches a
|
|
|
|
* specific device. The subvendor and subdevice fields will be set to
|
|
|
|
* PCI_ANY_ID.
|
|
|
|
*/
|
|
|
|
#define PCI_DEVICE(vend,dev) \
|
|
|
|
.vendor = (vend), .device = (dev), \
|
|
|
|
.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
|
|
|
|
|
2012-11-14 18:44:26 +04:00
|
|
|
/**
|
|
|
|
* PCI_DEVICE_SUB - macro used to describe a specific pci device with subsystem
|
|
|
|
* @vend: the 16 bit PCI Vendor ID
|
|
|
|
* @dev: the 16 bit PCI Device ID
|
|
|
|
* @subvend: the 16 bit PCI Subvendor ID
|
|
|
|
* @subdev: the 16 bit PCI Subdevice ID
|
|
|
|
*
|
|
|
|
* This macro is used to create a struct pci_device_id that matches a
|
|
|
|
* specific device with subsystem information.
|
|
|
|
*/
|
|
|
|
#define PCI_DEVICE_SUB(vend, dev, subvend, subdev) \
|
|
|
|
.vendor = (vend), .device = (dev), \
|
|
|
|
.subvendor = (subvend), .subdevice = (subdev)
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/**
|
|
|
|
* PCI_DEVICE_CLASS - macro used to describe a specific pci device class
|
|
|
|
* @dev_class: the class, subclass, prog-if triple for this device
|
|
|
|
* @dev_class_mask: the class mask for this device
|
|
|
|
*
|
|
|
|
* This macro is used to create a struct pci_device_id that matches a
|
2005-07-28 22:37:33 +04:00
|
|
|
* specific PCI class. The vendor, device, subvendor, and subdevice
|
2005-04-17 02:20:36 +04:00
|
|
|
* fields will be set to PCI_ANY_ID.
|
|
|
|
*/
|
|
|
|
#define PCI_DEVICE_CLASS(dev_class,dev_class_mask) \
|
|
|
|
.class = (dev_class), .class_mask = (dev_class_mask), \
|
|
|
|
.vendor = PCI_ANY_ID, .device = PCI_ANY_ID, \
|
|
|
|
.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
|
|
|
|
|
2006-12-05 02:14:45 +03:00
|
|
|
/**
|
|
|
|
* PCI_VDEVICE - macro used to describe a specific pci device in short form
|
2014-04-01 01:58:39 +04:00
|
|
|
* @vend: the vendor name
|
|
|
|
* @dev: the 16 bit PCI Device ID
|
2006-12-05 02:14:45 +03:00
|
|
|
*
|
|
|
|
* This macro is used to create a struct pci_device_id that matches a
|
|
|
|
* specific PCI device. The subvendor, and subdevice fields will be set
|
|
|
|
* to PCI_ANY_ID. The macro allows the next field to follow as the device
|
|
|
|
* private data.
|
|
|
|
*/
|
|
|
|
|
2014-04-01 01:58:39 +04:00
|
|
|
#define PCI_VDEVICE(vend, dev) \
|
|
|
|
.vendor = PCI_VENDOR_ID_##vend, .device = (dev), \
|
|
|
|
.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, 0, 0
|
2006-12-05 02:14:45 +03:00
|
|
|
|
2016-02-05 23:57:47 +03:00
|
|
|
enum {
|
|
|
|
PCI_REASSIGN_ALL_RSRC = 0x00000001, /* ignore firmware setup */
|
|
|
|
PCI_REASSIGN_ALL_BUS = 0x00000002, /* reassign all bus numbers */
|
|
|
|
PCI_PROBE_ONLY = 0x00000004, /* use existing setup */
|
|
|
|
PCI_CAN_SKIP_ISA_ALIGN = 0x00000008, /* don't do ISA alignment */
|
|
|
|
PCI_ENABLE_PROC_DOMAINS = 0x00000010, /* enable domains in /proc */
|
|
|
|
PCI_COMPAT_DOMAIN_0 = 0x00000020, /* ... except domain 0 */
|
|
|
|
PCI_SCAN_ALL_PCIE_DEVS = 0x00000040, /* scan all, not just dev 0 */
|
|
|
|
};
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* these external functions are only available when PCI support is enabled */
|
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
|
2016-02-05 23:57:47 +03:00
|
|
|
extern unsigned int pci_flags;
|
|
|
|
|
|
|
|
static inline void pci_set_flags(int flags) { pci_flags = flags; }
|
|
|
|
static inline void pci_add_flags(int flags) { pci_flags |= flags; }
|
|
|
|
static inline void pci_clear_flags(int flags) { pci_flags &= ~flags; }
|
|
|
|
static inline int pci_has_flag(int flag) { return pci_flags & flag; }
|
|
|
|
|
2013-08-22 07:24:44 +04:00
|
|
|
void pcie_bus_configure_settings(struct pci_bus *bus);
|
PCI: Set PCI-E Max Payload Size on fabric
On a given PCI-E fabric, each device, bridge, and root port can have a
different PCI-E maximum payload size. There is a sizable performance
boost for having the largest possible maximum payload size on each PCI-E
device. However, if improperly configured, fatal bus errors can occur.
Thus, it is important to ensure that PCI-E payloads sends by a device
are never larger than the MPS setting of all devices on the way to the
destination.
This can be achieved two ways:
- A conservative approach is to use the smallest common denominator of
the entire tree below a root complex for every device on that fabric.
This means for example that having a 128 bytes MPS USB controller on one
leg of a switch will dramatically reduce performances of a video card or
10GE adapter on another leg of that same switch.
It also means that any hierarchy supporting hotplug slots (including
expresscard or thunderbolt I suppose, dbl check that) will have to be
entirely clamped to 128 bytes since we cannot predict what will be
plugged into those slots, and we cannot change the MPS on a "live"
system.
- A more optimal way is possible, if it falls within a couple of
constraints:
* The top-level host bridge will never generate packets larger than the
smallest TLP (or if it can be controlled independently from its MPS at
least)
* The device will never generate packets larger than MPS (which can be
configured via MRRS)
* No support of direct PCI-E <-> PCI-E transfers between devices without
some additional code to specifically deal with that case
Then we can use an approach that basically ignores downstream requests
and focuses exclusively on upstream requests. In that case, all we need
to care about is that a device MPS is no larger than its parent MPS,
which allows us to keep all switches/bridges to the max MPS supported by
their parent and eventually the PHB.
In this case, your USB controller would no longer "starve" your 10GE
Ethernet and your hotplug slots won't affect your global MPS.
Additionally, the hotplugged devices themselves can be configured to a
larger MPS up to the value configured in the hotplug bridge.
To choose between the two available options, two PCI kernel boot args
have been added to the PCI calls. "pcie_bus_safe" will provide the
former behavior, while "pcie_bus_perf" will perform the latter behavior.
By default, the latter behavior is used.
NOTE: due to the location of the enablement, each arch will need to add
calls to this function. This patch only enables x86.
This patch includes a number of changes recommended by Benjamin
Herrenschmidt.
Tested-by: Jordan_Hargrave@dell.com
Signed-off-by: Jon Mason <mason@myri.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2011-07-21 00:20:54 +04:00
|
|
|
|
|
|
|
enum pcie_bus_config_types {
|
PCI: Set MPS to match upstream bridge
Firmware typically configures the PCIe fabric with a consistent Max Payload
Size setting based on the devices present at boot. A hot-added device
typically has the power-on default MPS setting (128 bytes), which may not
match the fabric.
The previous Linux default, in the absence of any "pci=pcie_bus_*" options,
was PCIE_BUS_TUNE_OFF, in which we never touch MPS, even for hot-added
devices.
Add a new default setting, PCIE_BUS_DEFAULT, in which we make sure every
device's MPS setting matches the upstream bridge. This makes it more
likely that a hot-added device will work in a system with optimized MPS
configuration.
Note that if we hot-add a device that only supports 128-byte MPS, it still
likely won't work because we don't reconfigure the rest of the fabric.
Booting with "pci=pcie_bus_peer2peer" is a workaround for this because it
sets MPS to 128 for everything.
[bhelgaas: changelog, new default, rework for pci_configure_device() path]
Tested-by: Keith Busch <keith.busch@intel.com>
Tested-by: Jordan Hargrave <jharg93@gmail.com>
Signed-off-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
2015-08-24 16:48:16 +03:00
|
|
|
PCIE_BUS_TUNE_OFF, /* don't touch MPS at all */
|
|
|
|
PCIE_BUS_DEFAULT, /* ensure MPS matches upstream bridge */
|
|
|
|
PCIE_BUS_SAFE, /* use largest MPS boot-time devices support */
|
|
|
|
PCIE_BUS_PERFORMANCE, /* use MPS and MRRS for best performance */
|
|
|
|
PCIE_BUS_PEER2PEER, /* set MPS = 128 for all devices */
|
PCI: Set PCI-E Max Payload Size on fabric
On a given PCI-E fabric, each device, bridge, and root port can have a
different PCI-E maximum payload size. There is a sizable performance
boost for having the largest possible maximum payload size on each PCI-E
device. However, if improperly configured, fatal bus errors can occur.
Thus, it is important to ensure that PCI-E payloads sends by a device
are never larger than the MPS setting of all devices on the way to the
destination.
This can be achieved two ways:
- A conservative approach is to use the smallest common denominator of
the entire tree below a root complex for every device on that fabric.
This means for example that having a 128 bytes MPS USB controller on one
leg of a switch will dramatically reduce performances of a video card or
10GE adapter on another leg of that same switch.
It also means that any hierarchy supporting hotplug slots (including
expresscard or thunderbolt I suppose, dbl check that) will have to be
entirely clamped to 128 bytes since we cannot predict what will be
plugged into those slots, and we cannot change the MPS on a "live"
system.
- A more optimal way is possible, if it falls within a couple of
constraints:
* The top-level host bridge will never generate packets larger than the
smallest TLP (or if it can be controlled independently from its MPS at
least)
* The device will never generate packets larger than MPS (which can be
configured via MRRS)
* No support of direct PCI-E <-> PCI-E transfers between devices without
some additional code to specifically deal with that case
Then we can use an approach that basically ignores downstream requests
and focuses exclusively on upstream requests. In that case, all we need
to care about is that a device MPS is no larger than its parent MPS,
which allows us to keep all switches/bridges to the max MPS supported by
their parent and eventually the PHB.
In this case, your USB controller would no longer "starve" your 10GE
Ethernet and your hotplug slots won't affect your global MPS.
Additionally, the hotplugged devices themselves can be configured to a
larger MPS up to the value configured in the hotplug bridge.
To choose between the two available options, two PCI kernel boot args
have been added to the PCI calls. "pcie_bus_safe" will provide the
former behavior, while "pcie_bus_perf" will perform the latter behavior.
By default, the latter behavior is used.
NOTE: due to the location of the enablement, each arch will need to add
calls to this function. This patch only enables x86.
This patch includes a number of changes recommended by Benjamin
Herrenschmidt.
Tested-by: Jordan_Hargrave@dell.com
Signed-off-by: Jon Mason <mason@myri.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2011-07-21 00:20:54 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
extern enum pcie_bus_config_types pcie_bus_config;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
extern struct bus_type pci_bus_type;
|
|
|
|
|
2013-11-14 22:28:18 +04:00
|
|
|
/* Do NOT directly access these two variables, unless you are arch-specific PCI
|
|
|
|
* code, or PCI core code. */
|
2005-04-17 02:20:36 +04:00
|
|
|
extern struct list_head pci_root_buses; /* list of all known PCI buses */
|
2013-11-14 22:28:18 +04:00
|
|
|
/* Some device drivers need know if PCI is initiated */
|
2013-04-12 22:02:59 +04:00
|
|
|
int no_pci_devices(void);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-11-04 08:39:31 +04:00
|
|
|
void pcibios_resource_survey_bus(struct pci_bus *bus);
|
2016-03-04 02:53:04 +03:00
|
|
|
void pcibios_bus_add_device(struct pci_dev *pdev);
|
2013-04-12 09:44:20 +04:00
|
|
|
void pcibios_add_bus(struct pci_bus *bus);
|
|
|
|
void pcibios_remove_bus(struct pci_bus *bus);
|
2005-04-17 02:20:36 +04:00
|
|
|
void pcibios_fixup_bus(struct pci_bus *);
|
2006-08-15 09:43:17 +04:00
|
|
|
int __must_check pcibios_enable_device(struct pci_dev *, int mask);
|
2013-11-14 22:28:18 +04:00
|
|
|
/* Architecture-specific versions may override this (weak) */
|
2008-01-31 02:21:33 +03:00
|
|
|
char *pcibios_setup(char *str);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Used only when drivers/pci/setup.c is used */
|
2010-01-01 19:40:50 +03:00
|
|
|
resource_size_t pcibios_align_resource(void *, const struct resource *,
|
2010-01-01 19:40:49 +03:00
|
|
|
resource_size_t,
|
2006-06-13 04:06:02 +04:00
|
|
|
resource_size_t);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-12-09 09:52:13 +03:00
|
|
|
/* Weak but can be overriden by arch */
|
|
|
|
void pci_fixup_cardbus(struct pci_bus *);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Generic PCI functions used internally */
|
|
|
|
|
PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev
These interfaces:
pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region)
took a pci_dev, but they really depend only on the pci_bus. And we want to
use them in resource allocation paths where we have the bus but not a
device, so this patch converts them to take the pci_bus instead of the
pci_dev:
pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region)
In fact, with standard PCI-PCI bridges, they only depend on the host
bridge, because that's the only place address translation occurs, but
we aren't going that far yet.
[bhelgaas: changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-10 10:54:40 +04:00
|
|
|
void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
|
2012-02-24 07:19:00 +04:00
|
|
|
struct resource *res);
|
PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev
These interfaces:
pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region)
took a pci_dev, but they really depend only on the pci_bus. And we want to
use them in resource allocation paths where we have the bus but not a
device, so this patch converts them to take the pci_bus instead of the
pci_dev:
pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region)
In fact, with standard PCI-PCI bridges, they only depend on the host
bridge, because that's the only place address translation occurs, but
we aren't going that far yet.
[bhelgaas: changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-10 10:54:40 +04:00
|
|
|
void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
|
2012-02-24 07:19:00 +04:00
|
|
|
struct pci_bus_region *region);
|
2009-07-11 01:39:53 +04:00
|
|
|
void pcibios_scan_specific_bus(int busn);
|
2013-04-12 22:02:59 +04:00
|
|
|
struct pci_bus *pci_find_bus(int domain, int busnr);
|
2009-02-04 02:45:26 +03:00
|
|
|
void pci_bus_add_devices(const struct pci_bus *bus);
|
2011-10-29 02:25:55 +04:00
|
|
|
struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata);
|
2011-10-29 02:25:45 +04:00
|
|
|
struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
|
|
|
|
struct pci_ops *ops, void *sysdata,
|
|
|
|
struct list_head *resources);
|
2012-05-18 21:35:50 +04:00
|
|
|
int pci_bus_insert_busn_res(struct pci_bus *b, int bus, int busmax);
|
|
|
|
int pci_bus_update_busn_res_end(struct pci_bus *b, int busmax);
|
|
|
|
void pci_bus_release_busn_res(struct pci_bus *b);
|
2012-11-22 00:35:00 +04:00
|
|
|
struct pci_bus *pci_scan_root_bus(struct device *parent, int bus,
|
2011-10-29 02:25:50 +04:00
|
|
|
struct pci_ops *ops, void *sysdata,
|
|
|
|
struct list_head *resources);
|
2017-06-28 23:13:55 +03:00
|
|
|
int pci_scan_root_bus_bridge(struct pci_host_bridge *bridge);
|
2008-01-31 02:21:33 +03:00
|
|
|
struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev,
|
|
|
|
int busnr);
|
2009-12-13 16:11:32 +03:00
|
|
|
void pcie_update_link_speed(struct pci_bus *bus, u16 link_status);
|
2008-06-11 01:28:50 +04:00
|
|
|
struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
|
2008-10-21 03:40:52 +04:00
|
|
|
const char *name,
|
|
|
|
struct hotplug_slot *hotplug);
|
2008-06-11 01:28:50 +04:00
|
|
|
void pci_destroy_slot(struct pci_slot *slot);
|
2015-07-17 12:16:32 +03:00
|
|
|
#ifdef CONFIG_SYSFS
|
|
|
|
void pci_dev_assign_slot(struct pci_dev *dev);
|
|
|
|
#else
|
|
|
|
static inline void pci_dev_assign_slot(struct pci_dev *dev) { }
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
int pci_scan_slot(struct pci_bus *bus, int devfn);
|
2008-01-31 02:21:33 +03:00
|
|
|
struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn);
|
2005-09-06 03:31:03 +04:00
|
|
|
void pci_device_add(struct pci_dev *dev, struct pci_bus *bus);
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int pci_scan_child_bus(struct pci_bus *bus);
|
2014-05-30 07:01:03 +04:00
|
|
|
void pci_bus_add_device(struct pci_dev *dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
void pci_read_bridge_bases(struct pci_bus *child);
|
2008-01-31 02:21:33 +03:00
|
|
|
struct resource *pci_find_parent_resource(const struct pci_dev *dev,
|
|
|
|
struct resource *res);
|
PCI: Turn off Request Attributes to avoid Chelsio T5 Completion erratum
The Chelsio T5 has a PCIe compliance erratum that causes Malformed TLP or
Unexpected Completion errors in some systems, which may cause device access
timeouts.
Per PCIe r3.0, sec 2.2.9, "Completion headers must supply the same values
for the Attribute as were supplied in the header of the corresponding
Request, except as explicitly allowed when IDO is used."
Instead of copying the Attributes from the Request to the Completion, the
T5 always generates Completions with zero Attributes. The receiver of a
Completion whose Attributes don't match the Request may accept it (which
itself seems non-compliant based on sec 2.3.2), or it may handle it as a
Malformed TLP or an Unexpected Completion, which will probably lead to a
device access timeout.
Work around this by disabling "Relaxed Ordering" and "No Snoop" in the Root
Port so it always generate Requests with zero Attributes.
This does affect all other devices which are downstream of that Root Port,
but these are performance optimizations that should not make a functional
difference.
Note that Configuration Space accesses are never supposed to have TLP
Attributes, so we're safe waiting till after any Configuration Space
accesses to do the Root Port "fixup".
Based on original work by Casey Leedom <leedom@chelsio.com>
[bhelgaas: changelog, comments, rename to pci_find_pcie_root_port(), rework
to use pci_upstream_bridge() and check for Root Port device type, edit
diagnostics to clarify intent and devices affected]
Signed-off-by: Hariprasad Shenai <hariprasad@chelsio.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2015-10-18 17:25:04 +03:00
|
|
|
struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev);
|
2012-04-12 19:33:07 +04:00
|
|
|
u8 pci_swizzle_interrupt_pin(const struct pci_dev *dev, u8 pin);
|
2005-04-17 02:20:36 +04:00
|
|
|
int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge);
|
2008-12-17 07:36:55 +03:00
|
|
|
u8 pci_common_swizzle(struct pci_dev *dev, u8 *pinp);
|
2013-04-12 22:02:59 +04:00
|
|
|
struct pci_dev *pci_dev_get(struct pci_dev *dev);
|
|
|
|
void pci_dev_put(struct pci_dev *dev);
|
|
|
|
void pci_remove_bus(struct pci_bus *b);
|
|
|
|
void pci_stop_and_remove_bus_device(struct pci_dev *dev);
|
2014-01-10 18:22:18 +04:00
|
|
|
void pci_stop_and_remove_bus_device_locked(struct pci_dev *dev);
|
2012-10-31 00:31:38 +04:00
|
|
|
void pci_stop_root_bus(struct pci_bus *bus);
|
|
|
|
void pci_remove_root_bus(struct pci_bus *bus);
|
2005-09-10 00:03:23 +04:00
|
|
|
void pci_setup_cardbus(struct pci_bus *bus);
|
2016-05-20 09:41:25 +03:00
|
|
|
void pcibios_setup_bridge(struct pci_bus *bus, unsigned long type);
|
2013-04-12 22:02:59 +04:00
|
|
|
void pci_sort_breadthfirst(void);
|
2010-02-10 04:43:04 +03:00
|
|
|
#define dev_is_pci(d) ((d)->bus == &pci_bus_type)
|
|
|
|
#define dev_is_pf(d) ((dev_is_pci(d) ? to_pci_dev(d)->is_physfn : false))
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Generic PCI functions exported to card drivers */
|
|
|
|
|
2008-08-03 22:02:12 +04:00
|
|
|
enum pci_lost_interrupt_reason {
|
|
|
|
PCI_LOST_IRQ_NO_INFORMATION = 0,
|
|
|
|
PCI_LOST_IRQ_DISABLE_MSI,
|
|
|
|
PCI_LOST_IRQ_DISABLE_MSIX,
|
|
|
|
PCI_LOST_IRQ_DISABLE_ACPI,
|
|
|
|
};
|
|
|
|
enum pci_lost_interrupt_reason pci_lost_interrupt(struct pci_dev *dev);
|
2008-01-31 02:21:33 +03:00
|
|
|
int pci_find_capability(struct pci_dev *dev, int cap);
|
|
|
|
int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap);
|
|
|
|
int pci_find_ext_capability(struct pci_dev *dev, int cap);
|
2012-07-14 00:24:59 +04:00
|
|
|
int pci_find_next_ext_capability(struct pci_dev *dev, int pos, int cap);
|
2008-01-31 02:21:33 +03:00
|
|
|
int pci_find_ht_capability(struct pci_dev *dev, int ht_cap);
|
|
|
|
int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap);
|
2006-10-17 03:20:21 +04:00
|
|
|
struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-10-21 21:24:12 +04:00
|
|
|
struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device,
|
|
|
|
struct pci_dev *from);
|
2008-01-31 02:21:33 +03:00
|
|
|
struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device,
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int ss_vendor, unsigned int ss_device,
|
2008-08-26 19:20:34 +04:00
|
|
|
struct pci_dev *from);
|
2008-01-31 02:21:33 +03:00
|
|
|
struct pci_dev *pci_get_slot(struct pci_bus *bus, unsigned int devfn);
|
2009-10-12 23:14:00 +04:00
|
|
|
struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int bus,
|
|
|
|
unsigned int devfn);
|
|
|
|
static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus,
|
|
|
|
unsigned int devfn)
|
|
|
|
{
|
|
|
|
return pci_get_domain_bus_and_slot(0, bus, devfn);
|
|
|
|
}
|
2008-01-31 02:21:33 +03:00
|
|
|
struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from);
|
2005-04-17 02:20:36 +04:00
|
|
|
int pci_dev_present(const struct pci_device_id *ids);
|
|
|
|
|
2008-01-31 02:21:33 +03:00
|
|
|
int pci_bus_read_config_byte(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where, u8 *val);
|
|
|
|
int pci_bus_read_config_word(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where, u16 *val);
|
|
|
|
int pci_bus_read_config_dword(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where, u32 *val);
|
|
|
|
int pci_bus_write_config_byte(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where, u8 val);
|
|
|
|
int pci_bus_write_config_word(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where, u16 val);
|
|
|
|
int pci_bus_write_config_dword(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where, u32 val);
|
2015-01-10 05:34:39 +03:00
|
|
|
|
|
|
|
int pci_generic_config_read(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where, int size, u32 *val);
|
|
|
|
int pci_generic_config_write(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where, int size, u32 val);
|
|
|
|
int pci_generic_config_read32(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where, int size, u32 *val);
|
|
|
|
int pci_generic_config_write32(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where, int size, u32 val);
|
|
|
|
|
2009-04-24 06:45:17 +04:00
|
|
|
struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2017-02-07 22:32:33 +03:00
|
|
|
int pci_read_config_byte(const struct pci_dev *dev, int where, u8 *val);
|
|
|
|
int pci_read_config_word(const struct pci_dev *dev, int where, u16 *val);
|
|
|
|
int pci_read_config_dword(const struct pci_dev *dev, int where, u32 *val);
|
|
|
|
int pci_write_config_byte(const struct pci_dev *dev, int where, u8 val);
|
|
|
|
int pci_write_config_word(const struct pci_dev *dev, int where, u16 val);
|
|
|
|
int pci_write_config_dword(const struct pci_dev *dev, int where, u32 val);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
PCI: Add accessors for PCI Express Capability
The PCI Express Capability (PCIe spec r3.0, sec 7.8) comes in two
versions, v1 and v2. In v1 Capability structures (PCIe spec r1.0 and
r1.1), some fields are optional, so the structure size depends on the
device type.
This patch adds functions to access this capability so drivers don't
have to be aware of the differences between v1 and v2. Note that these
new functions apply only to the "PCI Express Capability," not to any of
the other "PCI Express Extended Capabilities" (AER, VC, ACS, MFVC, etc.)
Function pcie_capability_read_word/dword() reads the PCIe Capabilities
register and returns the value in the reference parameter "val". If
the PCIe Capabilities register is not implemented on the PCIe device,
"val" is set to 0.
Function pcie_capability_write_word/dword() writes the value to the
specified PCIe Capability register.
Function pcie_capability_clear_and_set_word/dword() sets and/or clears bits
of a PCIe Capability register.
[bhelgaas: changelog, drop "pci_" prefixes, don't export
pcie_capability_reg_implemented()]
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2012-07-24 13:20:05 +04:00
|
|
|
int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val);
|
|
|
|
int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val);
|
|
|
|
int pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val);
|
|
|
|
int pcie_capability_write_dword(struct pci_dev *dev, int pos, u32 val);
|
|
|
|
int pcie_capability_clear_and_set_word(struct pci_dev *dev, int pos,
|
|
|
|
u16 clear, u16 set);
|
|
|
|
int pcie_capability_clear_and_set_dword(struct pci_dev *dev, int pos,
|
|
|
|
u32 clear, u32 set);
|
|
|
|
|
|
|
|
static inline int pcie_capability_set_word(struct pci_dev *dev, int pos,
|
|
|
|
u16 set)
|
|
|
|
{
|
|
|
|
return pcie_capability_clear_and_set_word(dev, pos, 0, set);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pcie_capability_set_dword(struct pci_dev *dev, int pos,
|
|
|
|
u32 set)
|
|
|
|
{
|
|
|
|
return pcie_capability_clear_and_set_dword(dev, pos, 0, set);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pcie_capability_clear_word(struct pci_dev *dev, int pos,
|
|
|
|
u16 clear)
|
|
|
|
{
|
|
|
|
return pcie_capability_clear_and_set_word(dev, pos, clear, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pcie_capability_clear_dword(struct pci_dev *dev, int pos,
|
|
|
|
u32 clear)
|
|
|
|
{
|
|
|
|
return pcie_capability_clear_and_set_dword(dev, pos, clear, 0);
|
|
|
|
}
|
|
|
|
|
2012-06-11 09:27:19 +04:00
|
|
|
/* user-space driven config access */
|
|
|
|
int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
|
|
|
|
int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
|
|
|
|
int pci_user_read_config_dword(struct pci_dev *dev, int where, u32 *val);
|
|
|
|
int pci_user_write_config_byte(struct pci_dev *dev, int where, u8 val);
|
|
|
|
int pci_user_write_config_word(struct pci_dev *dev, int where, u16 val);
|
|
|
|
int pci_user_write_config_dword(struct pci_dev *dev, int where, u32 val);
|
|
|
|
|
2006-08-15 09:43:17 +04:00
|
|
|
int __must_check pci_enable_device(struct pci_dev *dev);
|
2007-12-20 07:28:08 +03:00
|
|
|
int __must_check pci_enable_device_io(struct pci_dev *dev);
|
|
|
|
int __must_check pci_enable_device_mem(struct pci_dev *dev);
|
2007-07-27 09:43:35 +04:00
|
|
|
int __must_check pci_reenable_device(struct pci_dev *);
|
devres: device resource management
Implement device resource management, in short, devres. A device
driver can allocate arbirary size of devres data which is associated
with a release function. On driver detach, release function is
invoked on the devres data, then, devres data is freed.
devreses are typed by associated release functions. Some devreses are
better represented by single instance of the type while others need
multiple instances sharing the same release function. Both usages are
supported.
devreses can be grouped using devres group such that a device driver
can easily release acquired resources halfway through initialization
or selectively release resources (e.g. resources for port 1 out of 4
ports).
This patch adds devres core including documentation and the following
managed interfaces.
* alloc/free : devm_kzalloc(), devm_kzfree()
* IO region : devm_request_region(), devm_release_region()
* IRQ : devm_request_irq(), devm_free_irq()
* DMA : dmam_alloc_coherent(), dmam_free_coherent(),
dmam_declare_coherent_memory(), dmam_pool_create(),
dmam_pool_destroy()
* PCI : pcim_enable_device(), pcim_pin_device(), pci_is_managed()
* iomap : devm_ioport_map(), devm_ioport_unmap(), devm_ioremap(),
devm_ioremap_nocache(), devm_iounmap(), pcim_iomap_table(),
pcim_iomap(), pcim_iounmap()
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
2007-01-20 10:00:26 +03:00
|
|
|
int __must_check pcim_enable_device(struct pci_dev *pdev);
|
|
|
|
void pcim_pin_device(struct pci_dev *pdev);
|
|
|
|
|
2017-05-27 00:02:25 +03:00
|
|
|
static inline bool pci_intx_mask_supported(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* INTx masking is supported if PCI_COMMAND_INTX_DISABLE is
|
|
|
|
* writable and no quirk has marked the feature broken.
|
|
|
|
*/
|
|
|
|
return !pdev->broken_intx_masking;
|
|
|
|
}
|
|
|
|
|
2009-04-03 11:41:46 +04:00
|
|
|
static inline int pci_is_enabled(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
return (atomic_read(&pdev->enable_cnt) > 0);
|
|
|
|
}
|
|
|
|
|
devres: device resource management
Implement device resource management, in short, devres. A device
driver can allocate arbirary size of devres data which is associated
with a release function. On driver detach, release function is
invoked on the devres data, then, devres data is freed.
devreses are typed by associated release functions. Some devreses are
better represented by single instance of the type while others need
multiple instances sharing the same release function. Both usages are
supported.
devreses can be grouped using devres group such that a device driver
can easily release acquired resources halfway through initialization
or selectively release resources (e.g. resources for port 1 out of 4
ports).
This patch adds devres core including documentation and the following
managed interfaces.
* alloc/free : devm_kzalloc(), devm_kzfree()
* IO region : devm_request_region(), devm_release_region()
* IRQ : devm_request_irq(), devm_free_irq()
* DMA : dmam_alloc_coherent(), dmam_free_coherent(),
dmam_declare_coherent_memory(), dmam_pool_create(),
dmam_pool_destroy()
* PCI : pcim_enable_device(), pcim_pin_device(), pci_is_managed()
* iomap : devm_ioport_map(), devm_ioport_unmap(), devm_ioremap(),
devm_ioremap_nocache(), devm_iounmap(), pcim_iomap_table(),
pcim_iomap(), pcim_iounmap()
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
2007-01-20 10:00:26 +03:00
|
|
|
static inline int pci_is_managed(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
return pdev->is_managed;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
void pci_disable_device(struct pci_dev *dev);
|
2011-10-29 01:48:38 +04:00
|
|
|
|
|
|
|
extern unsigned int pcibios_max_latency;
|
2005-04-17 02:20:36 +04:00
|
|
|
void pci_set_master(struct pci_dev *dev);
|
2008-12-23 06:08:29 +03:00
|
|
|
void pci_clear_master(struct pci_dev *dev);
|
2011-10-29 01:48:38 +04:00
|
|
|
|
2007-04-07 01:39:36 +04:00
|
|
|
int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state);
|
2009-09-22 12:34:48 +04:00
|
|
|
int pci_set_cacheline_size(struct pci_dev *dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
#define HAVE_PCI_SET_MWI
|
2006-08-15 09:43:17 +04:00
|
|
|
int __must_check pci_set_mwi(struct pci_dev *dev);
|
2007-07-09 22:55:54 +04:00
|
|
|
int pci_try_set_mwi(struct pci_dev *dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
void pci_clear_mwi(struct pci_dev *dev);
|
2005-08-15 23:23:41 +04:00
|
|
|
void pci_intx(struct pci_dev *dev, int enable);
|
2011-11-04 12:46:00 +04:00
|
|
|
bool pci_check_and_mask_intx(struct pci_dev *dev);
|
|
|
|
bool pci_check_and_unmask_intx(struct pci_dev *dev);
|
2013-12-18 03:43:39 +04:00
|
|
|
int pci_wait_for_pending(struct pci_dev *dev, int pos, u16 mask);
|
2013-08-06 14:18:36 +04:00
|
|
|
int pci_wait_for_pending_transaction(struct pci_dev *dev);
|
2007-05-15 15:59:13 +04:00
|
|
|
int pcix_get_max_mmrbc(struct pci_dev *dev);
|
|
|
|
int pcix_get_mmrbc(struct pci_dev *dev);
|
|
|
|
int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc);
|
2007-08-14 14:43:48 +04:00
|
|
|
int pcie_get_readrq(struct pci_dev *dev);
|
2007-05-15 15:59:13 +04:00
|
|
|
int pcie_set_readrq(struct pci_dev *dev, int rq);
|
PCI: Set PCI-E Max Payload Size on fabric
On a given PCI-E fabric, each device, bridge, and root port can have a
different PCI-E maximum payload size. There is a sizable performance
boost for having the largest possible maximum payload size on each PCI-E
device. However, if improperly configured, fatal bus errors can occur.
Thus, it is important to ensure that PCI-E payloads sends by a device
are never larger than the MPS setting of all devices on the way to the
destination.
This can be achieved two ways:
- A conservative approach is to use the smallest common denominator of
the entire tree below a root complex for every device on that fabric.
This means for example that having a 128 bytes MPS USB controller on one
leg of a switch will dramatically reduce performances of a video card or
10GE adapter on another leg of that same switch.
It also means that any hierarchy supporting hotplug slots (including
expresscard or thunderbolt I suppose, dbl check that) will have to be
entirely clamped to 128 bytes since we cannot predict what will be
plugged into those slots, and we cannot change the MPS on a "live"
system.
- A more optimal way is possible, if it falls within a couple of
constraints:
* The top-level host bridge will never generate packets larger than the
smallest TLP (or if it can be controlled independently from its MPS at
least)
* The device will never generate packets larger than MPS (which can be
configured via MRRS)
* No support of direct PCI-E <-> PCI-E transfers between devices without
some additional code to specifically deal with that case
Then we can use an approach that basically ignores downstream requests
and focuses exclusively on upstream requests. In that case, all we need
to care about is that a device MPS is no larger than its parent MPS,
which allows us to keep all switches/bridges to the max MPS supported by
their parent and eventually the PHB.
In this case, your USB controller would no longer "starve" your 10GE
Ethernet and your hotplug slots won't affect your global MPS.
Additionally, the hotplugged devices themselves can be configured to a
larger MPS up to the value configured in the hotplug bridge.
To choose between the two available options, two PCI kernel boot args
have been added to the PCI calls. "pcie_bus_safe" will provide the
former behavior, while "pcie_bus_perf" will perform the latter behavior.
By default, the latter behavior is used.
NOTE: due to the location of the enablement, each arch will need to add
calls to this function. This patch only enables x86.
This patch includes a number of changes recommended by Benjamin
Herrenschmidt.
Tested-by: Jordan_Hargrave@dell.com
Signed-off-by: Jon Mason <mason@myri.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
2011-07-21 00:20:54 +04:00
|
|
|
int pcie_get_mps(struct pci_dev *dev);
|
|
|
|
int pcie_set_mps(struct pci_dev *dev, int mps);
|
2013-07-31 10:53:26 +04:00
|
|
|
int pcie_get_minimum_link(struct pci_dev *dev, enum pci_bus_speed *speed,
|
|
|
|
enum pcie_link_width *width);
|
2017-04-14 22:11:25 +03:00
|
|
|
void pcie_flr(struct pci_dev *dev);
|
2009-06-13 11:52:13 +04:00
|
|
|
int __pci_reset_function(struct pci_dev *dev);
|
2012-01-04 23:23:56 +04:00
|
|
|
int __pci_reset_function_locked(struct pci_dev *dev);
|
2008-10-21 13:38:25 +04:00
|
|
|
int pci_reset_function(struct pci_dev *dev);
|
2017-08-02 04:11:02 +03:00
|
|
|
int pci_reset_function_locked(struct pci_dev *dev);
|
PCI: Add pci_try_reset_function(), pci_try_reset_slot(), pci_try_reset_bus()
When doing a function/slot/bus reset PCI grabs the device_lock for each
device to block things like suspend and driver probes, but call paths exist
where this lock may already be held. This creates an opportunity for
deadlock. For instance, vfio allows userspace to issue resets so long as
it owns the device(s). If a driver unbind .remove callback races with
userspace issuing a reset, we have a deadlock as userspace gets stuck
waiting on device_lock while another thread has device_lock and waits for
.remove to complete. To resolve this, we can make a version of the reset
interfaces which use trylock. With this, we can safely attempt a reset and
return error to userspace if there is contention.
[bhelgaas: the deadlock happens when A (userspace) has a file descriptor for
the device, and B waits in this path:
driver_detach
device_lock # take device_lock
__device_release_driver
pci_device_remove # pci_bus_type.remove
vfio_pci_remove # pci_driver .remove
vfio_del_group_dev
wait_event(vfio.release_q, !vfio_dev_present) # wait (holding device_lock)
Now B is stuck until A gives up the file descriptor. If A tries to acquire
device_lock for any reason, we deadlock because A is waiting for B to release
the lock, and B is waiting for A to release the file descriptor.]
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-17 02:14:31 +04:00
|
|
|
int pci_try_reset_function(struct pci_dev *dev);
|
2013-08-15 00:06:05 +04:00
|
|
|
int pci_probe_reset_slot(struct pci_slot *slot);
|
2013-08-09 00:09:55 +04:00
|
|
|
int pci_reset_slot(struct pci_slot *slot);
|
PCI: Add pci_try_reset_function(), pci_try_reset_slot(), pci_try_reset_bus()
When doing a function/slot/bus reset PCI grabs the device_lock for each
device to block things like suspend and driver probes, but call paths exist
where this lock may already be held. This creates an opportunity for
deadlock. For instance, vfio allows userspace to issue resets so long as
it owns the device(s). If a driver unbind .remove callback races with
userspace issuing a reset, we have a deadlock as userspace gets stuck
waiting on device_lock while another thread has device_lock and waits for
.remove to complete. To resolve this, we can make a version of the reset
interfaces which use trylock. With this, we can safely attempt a reset and
return error to userspace if there is contention.
[bhelgaas: the deadlock happens when A (userspace) has a file descriptor for
the device, and B waits in this path:
driver_detach
device_lock # take device_lock
__device_release_driver
pci_device_remove # pci_bus_type.remove
vfio_pci_remove # pci_driver .remove
vfio_del_group_dev
wait_event(vfio.release_q, !vfio_dev_present) # wait (holding device_lock)
Now B is stuck until A gives up the file descriptor. If A tries to acquire
device_lock for any reason, we deadlock because A is waiting for B to release
the lock, and B is waiting for A to release the file descriptor.]
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-17 02:14:31 +04:00
|
|
|
int pci_try_reset_slot(struct pci_slot *slot);
|
2013-08-15 00:06:05 +04:00
|
|
|
int pci_probe_reset_bus(struct pci_bus *bus);
|
2013-08-09 00:09:55 +04:00
|
|
|
int pci_reset_bus(struct pci_bus *bus);
|
PCI: Add pci_try_reset_function(), pci_try_reset_slot(), pci_try_reset_bus()
When doing a function/slot/bus reset PCI grabs the device_lock for each
device to block things like suspend and driver probes, but call paths exist
where this lock may already be held. This creates an opportunity for
deadlock. For instance, vfio allows userspace to issue resets so long as
it owns the device(s). If a driver unbind .remove callback races with
userspace issuing a reset, we have a deadlock as userspace gets stuck
waiting on device_lock while another thread has device_lock and waits for
.remove to complete. To resolve this, we can make a version of the reset
interfaces which use trylock. With this, we can safely attempt a reset and
return error to userspace if there is contention.
[bhelgaas: the deadlock happens when A (userspace) has a file descriptor for
the device, and B waits in this path:
driver_detach
device_lock # take device_lock
__device_release_driver
pci_device_remove # pci_bus_type.remove
vfio_pci_remove # pci_driver .remove
vfio_del_group_dev
wait_event(vfio.release_q, !vfio_dev_present) # wait (holding device_lock)
Now B is stuck until A gives up the file descriptor. If A tries to acquire
device_lock for any reason, we deadlock because A is waiting for B to release
the lock, and B is waiting for A to release the file descriptor.]
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-17 02:14:31 +04:00
|
|
|
int pci_try_reset_bus(struct pci_bus *bus);
|
2014-06-19 11:22:44 +04:00
|
|
|
void pci_reset_secondary_bus(struct pci_dev *dev);
|
|
|
|
void pcibios_reset_secondary_bus(struct pci_dev *dev);
|
2013-08-09 00:09:24 +04:00
|
|
|
void pci_reset_bridge_secondary_bus(struct pci_dev *dev);
|
2008-11-21 21:38:52 +03:00
|
|
|
void pci_update_resource(struct pci_dev *dev, int resno);
|
2006-08-15 09:43:17 +04:00
|
|
|
int __must_check pci_assign_resource(struct pci_dev *dev, int i);
|
2011-07-26 00:08:39 +04:00
|
|
|
int __must_check pci_reassign_resource(struct pci_dev *dev, int i, resource_size_t add_size, resource_size_t align);
|
2006-12-18 04:31:06 +03:00
|
|
|
int pci_select_bars(struct pci_dev *dev, unsigned long flags);
|
2013-12-01 05:34:37 +04:00
|
|
|
bool pci_device_is_present(struct pci_dev *pdev);
|
2015-04-13 17:23:36 +03:00
|
|
|
void pci_ignore_hotplug(struct pci_dev *dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2017-04-13 10:06:42 +03:00
|
|
|
int __printf(6, 7) pci_request_irq(struct pci_dev *dev, unsigned int nr,
|
|
|
|
irq_handler_t handler, irq_handler_t thread_fn, void *dev_id,
|
|
|
|
const char *fmt, ...);
|
|
|
|
void pci_free_irq(struct pci_dev *dev, unsigned int nr, void *dev_id);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* ROM control related routines */
|
2008-09-23 20:25:10 +04:00
|
|
|
int pci_enable_rom(struct pci_dev *pdev);
|
|
|
|
void pci_disable_rom(struct pci_dev *pdev);
|
2005-08-09 08:20:10 +04:00
|
|
|
void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size);
|
2005-04-17 02:20:36 +04:00
|
|
|
void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom);
|
2009-01-29 22:12:47 +03:00
|
|
|
size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size);
|
2013-03-27 01:25:54 +04:00
|
|
|
void __iomem __must_check *pci_platform_rom(struct pci_dev *pdev, size_t *size);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Power management related routines */
|
|
|
|
int pci_save_state(struct pci_dev *dev);
|
2010-12-01 02:43:26 +03:00
|
|
|
void pci_restore_state(struct pci_dev *dev);
|
2011-05-10 20:02:27 +04:00
|
|
|
struct pci_saved_state *pci_store_saved_state(struct pci_dev *dev);
|
2014-12-04 00:40:31 +03:00
|
|
|
int pci_load_saved_state(struct pci_dev *dev,
|
|
|
|
struct pci_saved_state *state);
|
2011-05-10 20:02:27 +04:00
|
|
|
int pci_load_and_free_saved_state(struct pci_dev *dev,
|
|
|
|
struct pci_saved_state **state);
|
2013-12-18 03:43:45 +04:00
|
|
|
struct pci_cap_saved_state *pci_find_saved_cap(struct pci_dev *dev, char cap);
|
|
|
|
struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev,
|
|
|
|
u16 cap);
|
|
|
|
int pci_add_cap_save_buffer(struct pci_dev *dev, char cap, unsigned int size);
|
|
|
|
int pci_add_ext_cap_save_buffer(struct pci_dev *dev,
|
|
|
|
u16 cap, unsigned int size);
|
2009-03-27 00:51:40 +03:00
|
|
|
int __pci_complete_power_transition(struct pci_dev *dev, pci_power_t state);
|
2005-09-10 02:43:46 +04:00
|
|
|
int pci_set_power_state(struct pci_dev *dev, pci_power_t state);
|
|
|
|
pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state);
|
2008-07-19 16:39:24 +04:00
|
|
|
bool pci_pme_capable(struct pci_dev *dev, pci_power_t state);
|
2008-08-08 02:14:24 +04:00
|
|
|
void pci_pme_active(struct pci_dev *dev, bool enable);
|
2017-06-24 02:57:35 +03:00
|
|
|
int pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable);
|
2008-08-18 23:38:00 +04:00
|
|
|
int pci_wake_from_d3(struct pci_dev *dev, bool enable);
|
2008-07-07 05:35:26 +04:00
|
|
|
int pci_prepare_to_sleep(struct pci_dev *dev);
|
|
|
|
int pci_back_from_sleep(struct pci_dev *dev);
|
2010-02-18 01:44:09 +03:00
|
|
|
bool pci_dev_run_wake(struct pci_dev *dev);
|
2010-10-04 22:22:26 +04:00
|
|
|
bool pci_check_pme_status(struct pci_dev *dev);
|
|
|
|
void pci_pme_wakeup_bus(struct pci_bus *bus);
|
2016-06-02 11:17:12 +03:00
|
|
|
void pci_d3cold_enable(struct pci_dev *dev);
|
|
|
|
void pci_d3cold_disable(struct pci_dev *dev);
|
2017-08-15 06:23:23 +03:00
|
|
|
bool pcie_relaxed_ordering_enabled(struct pci_dev *dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
PCI: Add Virtual Channel to save/restore support
While we don't really have any infrastructure for making use of VC
support, the system BIOS can configure the topology to non-default
VC values prior to boot. This may be due to silicon bugs, desire to
reserve traffic classes, or perhaps just BIOS bugs. When we reset
devices, the VC configuration may return to default values, which can
be incompatible with devices upstream. For instance, Nvidia GRID
cards provide a PCIe switch and some number of GPUs, all supporting
VC. The power-on default for VC is to support TC0-7 across VC0,
however some platforms will only enable TC0/VC0 mapping across the
topology. When we do a secondary bus reset on the downstream switch
port, the GPU is reset to a TC0-7/VC0 mapping while the opposite end
of the link only enables TC0/VC0. If the GPU attempts to use TC1-7,
it fails.
This patch attempts to provide complete support for VC save/restore,
even beyond the minimally required use case above. This includes
save/restore and reload of the arbitration table, save/restore and
reload of the port arbitration tables, and re-enabling of the
channels for VC, VC9, and MFVC capabilities.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-18 03:43:51 +04:00
|
|
|
/* PCI Virtual Channel */
|
|
|
|
int pci_save_vc_state(struct pci_dev *dev);
|
|
|
|
void pci_restore_vc_state(struct pci_dev *dev);
|
|
|
|
void pci_allocate_vc_save_buffers(struct pci_dev *dev);
|
2011-01-14 19:53:04 +03:00
|
|
|
|
2010-01-26 20:10:03 +03:00
|
|
|
/* For use by arch with custom probe code */
|
|
|
|
void set_pcie_port_type(struct pci_dev *pdev);
|
|
|
|
void set_pcie_hotplug_bridge(struct pci_dev *pdev);
|
|
|
|
|
2007-07-17 08:27:10 +04:00
|
|
|
/* Functions for PCI Hotplug drivers to use */
|
2008-01-31 02:21:33 +03:00
|
|
|
int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap);
|
2012-01-21 14:08:22 +04:00
|
|
|
unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge);
|
2009-03-20 23:56:25 +03:00
|
|
|
unsigned int pci_rescan_bus(struct pci_bus *bus);
|
2014-01-10 18:22:18 +04:00
|
|
|
void pci_lock_rescan_remove(void);
|
|
|
|
void pci_unlock_rescan_remove(void);
|
2007-07-17 08:27:10 +04:00
|
|
|
|
2008-12-18 20:17:16 +03:00
|
|
|
/* Vital product data routines */
|
|
|
|
ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf);
|
|
|
|
ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf);
|
2016-04-15 21:00:11 +03:00
|
|
|
int pci_set_vpd_size(struct pci_dev *dev, size_t len);
|
2008-12-18 20:17:16 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
|
2011-11-21 22:54:13 +04:00
|
|
|
resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx);
|
2009-02-18 21:44:29 +03:00
|
|
|
void pci_bus_assign_resources(const struct pci_bus *bus);
|
2016-06-08 14:04:47 +03:00
|
|
|
void pci_bus_claim_resources(struct pci_bus *bus);
|
2005-04-17 02:20:36 +04:00
|
|
|
void pci_bus_size_bridges(struct pci_bus *bus);
|
|
|
|
int pci_claim_resource(struct pci_dev *, int);
|
PCI: Add pci_claim_bridge_resource() to clip window if necessary
Add pci_claim_bridge_resource() to claim a PCI-PCI bridge window. This is
like regular pci_claim_resource(), except that if we fail to claim the
window, we check to see if we can reduce the size of the window and try
again.
This is for scenarios like this:
pci_bus 0000:00: root bus resource [mem 0xc0000000-0xffffffff]
pci 0000:00:01.0: bridge window [mem 0xbdf00000-0xddefffff 64bit pref]
pci 0000:01:00.0: reg 0x10: [mem 0xc0000000-0xcfffffff pref]
The 00:01.0 window is illegal: it starts before the host bridge window, so
we have to assume the [0xbdf00000-0xbfffffff] region is inaccessible. We
can make it legal by clipping it to [mem 0xc0000000-0xddefffff 64bit pref].
Previously we discarded the 00:01.0 window and tried to reassign that part
of the hierarchy from scratch. That is a problem because Linux doesn't
always assign things optimally. For example, in this case, BIOS put the
01:00.0 device in a prefetchable window below 4GB, but after 5b28541552ef,
Linux puts the prefetchable window above 4GB where the 32-bit 01:00.0
device can't use it.
Clipping the 00:01.0 window is less intrusive than completely reassigning
things and is sufficient to let us use most of the BIOS configuration. Of
course, it's possible that devices below 00:01.0 will no longer fit. If
that's the case, we'll have to reassign things. But that's a separate
problem.
[bhelgaas: changelog, split into separate patch]
Link: https://bugzilla.kernel.org/show_bug.cgi?id=85491
Reported-by: Marek Kordik <kordikmarek@gmail.com>
Fixes: 5b28541552ef ("PCI: Restrict 64-bit prefetchable bridge windows to 64-bit resources")
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
CC: stable@vger.kernel.org # v3.16+
2015-01-16 01:21:49 +03:00
|
|
|
int pci_claim_bridge_resource(struct pci_dev *bridge, int i);
|
2005-04-17 02:20:36 +04:00
|
|
|
void pci_assign_unassigned_resources(void);
|
2010-01-22 12:02:25 +03:00
|
|
|
void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge);
|
2012-10-31 00:31:10 +04:00
|
|
|
void pci_assign_unassigned_bus_resources(struct pci_bus *bus);
|
2013-07-23 01:37:18 +04:00
|
|
|
void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus);
|
2005-04-17 02:20:36 +04:00
|
|
|
void pdev_enable_device(struct pci_dev *);
|
2008-03-04 21:56:47 +03:00
|
|
|
int pci_enable_resources(struct pci_dev *, int mask);
|
2017-06-28 23:14:02 +03:00
|
|
|
void pci_assign_irq(struct pci_dev *dev);
|
2016-09-15 11:07:03 +03:00
|
|
|
struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res);
|
2005-04-17 02:20:36 +04:00
|
|
|
#define HAVE_PCI_REQ_REGIONS 2
|
2006-08-15 09:43:17 +04:00
|
|
|
int __must_check pci_request_regions(struct pci_dev *, const char *);
|
2008-10-23 06:55:31 +04:00
|
|
|
int __must_check pci_request_regions_exclusive(struct pci_dev *, const char *);
|
2005-04-17 02:20:36 +04:00
|
|
|
void pci_release_regions(struct pci_dev *);
|
2006-08-15 09:43:17 +04:00
|
|
|
int __must_check pci_request_region(struct pci_dev *, int, const char *);
|
2008-10-23 06:55:31 +04:00
|
|
|
int __must_check pci_request_region_exclusive(struct pci_dev *, int, const char *);
|
2005-04-17 02:20:36 +04:00
|
|
|
void pci_release_region(struct pci_dev *, int);
|
2006-12-18 04:31:06 +03:00
|
|
|
int pci_request_selected_regions(struct pci_dev *, int, const char *);
|
2008-10-23 06:55:31 +04:00
|
|
|
int pci_request_selected_regions_exclusive(struct pci_dev *, int, const char *);
|
2006-12-18 04:31:06 +03:00
|
|
|
void pci_release_selected_regions(struct pci_dev *, int);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* drivers/pci/bus.c */
|
2013-05-25 17:48:29 +04:00
|
|
|
struct pci_bus *pci_bus_get(struct pci_bus *bus);
|
|
|
|
void pci_bus_put(struct pci_bus *bus);
|
2011-10-29 02:25:35 +04:00
|
|
|
void pci_add_resource(struct list_head *resources, struct resource *res);
|
2012-02-24 07:19:00 +04:00
|
|
|
void pci_add_resource_offset(struct list_head *resources, struct resource *res,
|
|
|
|
resource_size_t offset);
|
2011-10-29 02:25:35 +04:00
|
|
|
void pci_free_resource_list(struct list_head *resources);
|
2016-05-29 02:09:16 +03:00
|
|
|
void pci_bus_add_resource(struct pci_bus *bus, struct resource *res,
|
|
|
|
unsigned int flags);
|
2010-02-23 20:24:36 +03:00
|
|
|
struct resource *pci_bus_resource_n(const struct pci_bus *bus, int n);
|
|
|
|
void pci_bus_remove_resources(struct pci_bus *bus);
|
2016-05-29 02:09:16 +03:00
|
|
|
int devm_request_pci_bus_resources(struct device *dev,
|
|
|
|
struct list_head *resources);
|
2010-02-23 20:24:36 +03:00
|
|
|
|
2010-02-23 20:24:31 +03:00
|
|
|
#define pci_bus_for_each_resource(bus, res, i) \
|
2010-02-23 20:24:36 +03:00
|
|
|
for (i = 0; \
|
|
|
|
(res = pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \
|
|
|
|
i++)
|
2010-02-23 20:24:31 +03:00
|
|
|
|
2006-08-15 09:43:17 +04:00
|
|
|
int __must_check pci_bus_alloc_resource(struct pci_bus *bus,
|
|
|
|
struct resource *res, resource_size_t size,
|
|
|
|
resource_size_t align, resource_size_t min,
|
2014-03-08 00:51:12 +04:00
|
|
|
unsigned long type_mask,
|
2010-01-01 19:40:50 +03:00
|
|
|
resource_size_t (*alignf)(void *,
|
|
|
|
const struct resource *,
|
2010-01-01 19:40:49 +03:00
|
|
|
resource_size_t,
|
|
|
|
resource_size_t),
|
2006-08-15 09:43:17 +04:00
|
|
|
void *alignf_data);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-09-29 18:29:30 +04:00
|
|
|
|
2016-05-12 01:34:51 +03:00
|
|
|
int pci_register_io_range(phys_addr_t addr, resource_size_t size);
|
|
|
|
unsigned long pci_address_to_pio(phys_addr_t addr);
|
|
|
|
phys_addr_t pci_pio_to_address(unsigned long pio);
|
2014-09-29 18:29:30 +04:00
|
|
|
int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr);
|
2016-06-10 22:55:11 +03:00
|
|
|
void pci_unmap_iospace(struct resource *res);
|
2017-04-19 19:48:55 +03:00
|
|
|
void __iomem *devm_pci_remap_cfgspace(struct device *dev,
|
|
|
|
resource_size_t offset,
|
|
|
|
resource_size_t size);
|
|
|
|
void __iomem *devm_pci_remap_cfg_resource(struct device *dev,
|
|
|
|
struct resource *res);
|
2014-09-29 18:29:30 +04:00
|
|
|
|
PCI: Add pci_bus_addr_t
David Ahern reported that d63e2e1f3df9 ("sparc/PCI: Clip bridge windows
to fit in upstream windows") fails to boot on sparc/T5-8:
pci 0000:06:00.0: reg 0x184: can't handle BAR above 4GB (bus address 0x110204000)
The problem is that sparc64 assumed that dma_addr_t only needed to hold DMA
addresses, i.e., bus addresses returned via the DMA API (dma_map_single(),
etc.), while the PCI core assumed dma_addr_t could hold *any* bus address,
including raw BAR values. On sparc64, all DMA addresses fit in 32 bits, so
dma_addr_t is a 32-bit type. However, BAR values can be 64 bits wide, so
they don't fit in a dma_addr_t. d63e2e1f3df9 added new checking that
tripped over this mismatch.
Add pci_bus_addr_t, which is wide enough to hold any PCI bus address,
including both raw BAR values and DMA addresses. This will be 64 bits
on 64-bit platforms and on platforms with a 64-bit dma_addr_t. Then
dma_addr_t only needs to be wide enough to hold addresses from the DMA API.
[bhelgaas: changelog, bugzilla, Kconfig to ensure pci_bus_addr_t is at
least as wide as dma_addr_t, documentation]
Fixes: d63e2e1f3df9 ("sparc/PCI: Clip bridge windows to fit in upstream windows")
Fixes: 23b13bc76f35 ("PCI: Fail safely if we can't handle BARs larger than 4GB")
Link: http://lkml.kernel.org/r/CAE9FiQU1gJY1LYrxs+ma5LCTEEe4xmtjRG0aXJ9K_Tsu+m9Wuw@mail.gmail.com
Link: http://lkml.kernel.org/r/1427857069-6789-1-git-send-email-yinghai@kernel.org
Link: https://bugzilla.kernel.org/show_bug.cgi?id=96231
Reported-by: David Ahern <david.ahern@oracle.com>
Tested-by: David Ahern <david.ahern@oracle.com>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: David S. Miller <davem@davemloft.net>
CC: stable@vger.kernel.org # v3.19+
2015-05-28 03:23:51 +03:00
|
|
|
static inline pci_bus_addr_t pci_bus_address(struct pci_dev *pdev, int bar)
|
2013-12-21 19:33:26 +04:00
|
|
|
{
|
|
|
|
struct pci_bus_region region;
|
|
|
|
|
|
|
|
pcibios_resource_to_bus(pdev->bus, ®ion, &pdev->resource[bar]);
|
|
|
|
return region.start;
|
|
|
|
}
|
|
|
|
|
2005-10-28 01:12:54 +04:00
|
|
|
/* Proper probing supporting hot-pluggable devices */
|
2007-01-15 22:50:02 +03:00
|
|
|
int __must_check __pci_register_driver(struct pci_driver *, struct module *,
|
|
|
|
const char *mod_name);
|
2008-07-30 23:07:04 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* pci_register_driver must be a macro so that KBUILD_MODNAME can be expanded
|
|
|
|
*/
|
|
|
|
#define pci_register_driver(driver) \
|
|
|
|
__pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
|
2005-10-28 01:12:54 +04:00
|
|
|
|
2008-01-31 02:21:33 +03:00
|
|
|
void pci_unregister_driver(struct pci_driver *dev);
|
2011-11-18 22:12:49 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* module_pci_driver() - Helper macro for registering a PCI driver
|
|
|
|
* @__pci_driver: pci_driver struct
|
|
|
|
*
|
|
|
|
* Helper macro for PCI drivers which do not do anything special in module
|
|
|
|
* init/exit. This eliminates a lot of boilerplate. Each module may only
|
|
|
|
* use this macro once, and calling it replaces module_init() and module_exit()
|
|
|
|
*/
|
|
|
|
#define module_pci_driver(__pci_driver) \
|
|
|
|
module_driver(__pci_driver, pci_register_driver, \
|
|
|
|
pci_unregister_driver)
|
|
|
|
|
2015-08-26 03:25:37 +03:00
|
|
|
/**
|
|
|
|
* builtin_pci_driver() - Helper macro for registering a PCI driver
|
|
|
|
* @__pci_driver: pci_driver struct
|
|
|
|
*
|
|
|
|
* Helper macro for PCI drivers which do not do anything special in their
|
|
|
|
* init code. This eliminates a lot of boilerplate. Each driver may only
|
|
|
|
* use this macro once, and calling it replaces device_initcall(...)
|
|
|
|
*/
|
|
|
|
#define builtin_pci_driver(__pci_driver) \
|
|
|
|
builtin_driver(__pci_driver, pci_register_driver)
|
|
|
|
|
2008-01-31 02:21:33 +03:00
|
|
|
struct pci_driver *pci_dev_driver(const struct pci_dev *dev);
|
2009-09-03 10:26:36 +04:00
|
|
|
int pci_add_dynid(struct pci_driver *drv,
|
|
|
|
unsigned int vendor, unsigned int device,
|
|
|
|
unsigned int subvendor, unsigned int subdevice,
|
|
|
|
unsigned int class, unsigned int class_mask,
|
|
|
|
unsigned long driver_data);
|
2008-01-31 02:21:33 +03:00
|
|
|
const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
|
|
|
|
struct pci_dev *dev);
|
|
|
|
int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
|
|
|
|
int pass);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-06-16 09:34:38 +04:00
|
|
|
void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
|
2005-08-18 08:33:01 +04:00
|
|
|
void *userdata);
|
2005-12-13 10:09:16 +03:00
|
|
|
int pci_cfg_space_size(struct pci_dev *dev);
|
2008-01-31 02:21:33 +03:00
|
|
|
unsigned char pci_bus_max_busnr(struct pci_bus *bus);
|
2011-09-11 21:08:38 +04:00
|
|
|
void pci_setup_bridge(struct pci_bus *bus);
|
2012-09-12 02:59:45 +04:00
|
|
|
resource_size_t pcibios_window_alignment(struct pci_bus *bus,
|
|
|
|
unsigned long type);
|
2015-03-25 11:23:50 +03:00
|
|
|
resource_size_t pcibios_iov_resource_alignment(struct pci_dev *dev, int resno);
|
2005-08-18 08:33:01 +04:00
|
|
|
|
2010-06-01 09:32:24 +04:00
|
|
|
#define PCI_VGA_STATE_CHANGE_BRIDGE (1 << 0)
|
|
|
|
#define PCI_VGA_STATE_CHANGE_DECODES (1 << 1)
|
|
|
|
|
2009-08-11 09:52:06 +04:00
|
|
|
int pci_set_vga_state(struct pci_dev *pdev, bool decode,
|
2010-06-01 09:32:24 +04:00
|
|
|
unsigned int command_bits, u32 flags);
|
2016-03-07 20:39:16 +03:00
|
|
|
|
2016-08-11 17:11:04 +03:00
|
|
|
#define PCI_IRQ_LEGACY (1 << 0) /* allow legacy interrupts */
|
|
|
|
#define PCI_IRQ_MSI (1 << 1) /* allow MSI interrupts */
|
|
|
|
#define PCI_IRQ_MSIX (1 << 2) /* allow MSI-X interrupts */
|
|
|
|
#define PCI_IRQ_AFFINITY (1 << 3) /* auto-assign affinity */
|
|
|
|
#define PCI_IRQ_ALL_TYPES \
|
|
|
|
(PCI_IRQ_LEGACY | PCI_IRQ_MSI | PCI_IRQ_MSIX)
|
2016-07-12 12:20:17 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* kmem_cache style wrapper around pci_alloc_consistent() */
|
|
|
|
|
2010-03-11 02:23:30 +03:00
|
|
|
#include <linux/pci-dma.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/dmapool.h>
|
|
|
|
|
|
|
|
#define pci_pool dma_pool
|
|
|
|
#define pci_pool_create(name, pdev, size, align, allocation) \
|
|
|
|
dma_pool_create(name, &pdev->dev, size, align, allocation)
|
|
|
|
#define pci_pool_destroy(pool) dma_pool_destroy(pool)
|
|
|
|
#define pci_pool_alloc(pool, flags, handle) dma_pool_alloc(pool, flags, handle)
|
2015-09-09 01:02:30 +03:00
|
|
|
#define pci_pool_zalloc(pool, flags, handle) \
|
|
|
|
dma_pool_zalloc(pool, flags, handle)
|
2005-04-17 02:20:36 +04:00
|
|
|
#define pci_pool_free(pool, vaddr, addr) dma_pool_free(pool, vaddr, addr)
|
|
|
|
|
|
|
|
struct msix_entry {
|
2008-08-16 06:36:45 +04:00
|
|
|
u32 vector; /* kernel uses to write allocated vector */
|
2005-04-17 02:20:36 +04:00
|
|
|
u16 entry; /* driver uses to specify entry, OS writes */
|
|
|
|
};
|
|
|
|
|
2014-01-14 04:01:11 +04:00
|
|
|
#ifdef CONFIG_PCI_MSI
|
|
|
|
int pci_msi_vec_count(struct pci_dev *dev);
|
2013-04-12 22:02:59 +04:00
|
|
|
void pci_disable_msi(struct pci_dev *dev);
|
2014-01-14 04:01:11 +04:00
|
|
|
int pci_msix_vec_count(struct pci_dev *dev);
|
2013-04-12 22:02:59 +04:00
|
|
|
void pci_disable_msix(struct pci_dev *dev);
|
|
|
|
void pci_restore_msi_state(struct pci_dev *dev);
|
|
|
|
int pci_msi_enabled(void);
|
2017-01-09 23:37:40 +03:00
|
|
|
int pci_enable_msi(struct pci_dev *dev);
|
2014-01-14 04:01:11 +04:00
|
|
|
int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries,
|
|
|
|
int minvec, int maxvec);
|
2014-02-13 18:25:02 +04:00
|
|
|
static inline int pci_enable_msix_exact(struct pci_dev *dev,
|
|
|
|
struct msix_entry *entries, int nvec)
|
|
|
|
{
|
|
|
|
int rc = pci_enable_msix_range(dev, entries, nvec, nvec);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
return 0;
|
|
|
|
}
|
2016-11-09 04:15:05 +03:00
|
|
|
int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
|
|
|
|
unsigned int max_vecs, unsigned int flags,
|
|
|
|
const struct irq_affinity *affd);
|
|
|
|
|
2016-07-12 12:20:17 +03:00
|
|
|
void pci_free_irq_vectors(struct pci_dev *dev);
|
|
|
|
int pci_irq_vector(struct pci_dev *dev, unsigned int nr);
|
2016-09-14 17:18:51 +03:00
|
|
|
const struct cpumask *pci_irq_get_affinity(struct pci_dev *pdev, int vec);
|
2017-02-01 20:53:15 +03:00
|
|
|
int pci_irq_get_node(struct pci_dev *pdev, int vec);
|
2016-07-12 12:20:17 +03:00
|
|
|
|
2014-01-14 04:01:11 +04:00
|
|
|
#else
|
2014-01-14 04:15:01 +04:00
|
|
|
static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; }
|
|
|
|
static inline void pci_disable_msi(struct pci_dev *dev) { }
|
|
|
|
static inline int pci_msix_vec_count(struct pci_dev *dev) { return -ENOSYS; }
|
|
|
|
static inline void pci_disable_msix(struct pci_dev *dev) { }
|
|
|
|
static inline void pci_restore_msi_state(struct pci_dev *dev) { }
|
|
|
|
static inline int pci_msi_enabled(void) { return 0; }
|
2017-01-09 23:37:40 +03:00
|
|
|
static inline int pci_enable_msi(struct pci_dev *dev)
|
2014-02-13 18:25:02 +04:00
|
|
|
{ return -ENOSYS; }
|
2013-12-30 11:28:16 +04:00
|
|
|
static inline int pci_enable_msix_range(struct pci_dev *dev,
|
|
|
|
struct msix_entry *entries, int minvec, int maxvec)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return -ENOSYS; }
|
2014-02-13 18:25:02 +04:00
|
|
|
static inline int pci_enable_msix_exact(struct pci_dev *dev,
|
|
|
|
struct msix_entry *entries, int nvec)
|
|
|
|
{ return -ENOSYS; }
|
2016-11-09 04:15:05 +03:00
|
|
|
|
|
|
|
static inline int
|
|
|
|
pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
|
|
|
|
unsigned int max_vecs, unsigned int flags,
|
|
|
|
const struct irq_affinity *aff_desc)
|
2016-07-12 12:20:17 +03:00
|
|
|
{
|
2017-05-20 19:59:54 +03:00
|
|
|
if ((flags & PCI_IRQ_LEGACY) && min_vecs == 1 && dev->irq)
|
|
|
|
return 1;
|
|
|
|
return -ENOSPC;
|
2016-07-12 12:20:17 +03:00
|
|
|
}
|
2016-11-09 04:15:05 +03:00
|
|
|
|
2016-07-12 12:20:17 +03:00
|
|
|
static inline void pci_free_irq_vectors(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pci_irq_vector(struct pci_dev *dev, unsigned int nr)
|
|
|
|
{
|
|
|
|
if (WARN_ON_ONCE(nr > 0))
|
|
|
|
return -EINVAL;
|
|
|
|
return dev->irq;
|
|
|
|
}
|
2016-09-14 17:18:51 +03:00
|
|
|
static inline const struct cpumask *pci_irq_get_affinity(struct pci_dev *pdev,
|
|
|
|
int vec)
|
|
|
|
{
|
|
|
|
return cpu_possible_mask;
|
|
|
|
}
|
2017-02-01 20:53:15 +03:00
|
|
|
|
|
|
|
static inline int pci_irq_get_node(struct pci_dev *pdev, int vec)
|
|
|
|
{
|
|
|
|
return first_online_node;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
|
|
|
|
2016-11-09 04:15:05 +03:00
|
|
|
static inline int
|
|
|
|
pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs,
|
|
|
|
unsigned int max_vecs, unsigned int flags)
|
|
|
|
{
|
|
|
|
return pci_alloc_irq_vectors_affinity(dev, min_vecs, max_vecs, flags,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2017-08-15 22:02:17 +03:00
|
|
|
/**
|
|
|
|
* pci_irqd_intx_xlate() - Translate PCI INTx value to an IRQ domain hwirq
|
|
|
|
* @d: the INTx IRQ domain
|
|
|
|
* @node: the DT node for the device whose interrupt we're translating
|
|
|
|
* @intspec: the interrupt specifier data from the DT
|
|
|
|
* @intsize: the number of entries in @intspec
|
|
|
|
* @out_hwirq: pointer at which to write the hwirq number
|
|
|
|
* @out_type: pointer at which to write the interrupt type
|
|
|
|
*
|
|
|
|
* Translate a PCI INTx interrupt number from device tree in the range 1-4, as
|
|
|
|
* stored in the standard PCI_INTERRUPT_PIN register, to a value in the range
|
|
|
|
* 0-3 suitable for use in a 4 entry IRQ domain. That is, subtract one from the
|
|
|
|
* INTx value to obtain the hwirq number.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, or -EINVAL if the interrupt specifier is out of range.
|
|
|
|
*/
|
|
|
|
static inline int pci_irqd_intx_xlate(struct irq_domain *d,
|
|
|
|
struct device_node *node,
|
|
|
|
const u32 *intspec,
|
|
|
|
unsigned int intsize,
|
|
|
|
unsigned long *out_hwirq,
|
|
|
|
unsigned int *out_type)
|
|
|
|
{
|
|
|
|
const u32 intx = intspec[0];
|
|
|
|
|
|
|
|
if (intx < PCI_INTERRUPT_INTA || intx > PCI_INTERRUPT_INTD)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
*out_hwirq = intx - PCI_INTERRUPT_INTA;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-15 02:07:22 +03:00
|
|
|
#ifdef CONFIG_PCIEPORTBUS
|
2011-01-07 02:55:09 +03:00
|
|
|
extern bool pcie_ports_disabled;
|
|
|
|
extern bool pcie_ports_auto;
|
2011-01-15 02:07:22 +03:00
|
|
|
#else
|
|
|
|
#define pcie_ports_disabled true
|
|
|
|
#define pcie_ports_auto false
|
|
|
|
#endif
|
2011-01-07 02:55:09 +03:00
|
|
|
|
2014-01-14 04:01:11 +04:00
|
|
|
#ifdef CONFIG_PCIEASPM
|
2013-04-12 22:02:59 +04:00
|
|
|
bool pcie_aspm_support_enabled(void);
|
2014-01-14 04:01:11 +04:00
|
|
|
#else
|
|
|
|
static inline bool pcie_aspm_support_enabled(void) { return false; }
|
2008-11-11 01:30:55 +03:00
|
|
|
#endif
|
|
|
|
|
2011-01-07 02:55:09 +03:00
|
|
|
#ifdef CONFIG_PCIEAER
|
|
|
|
void pci_no_aer(void);
|
|
|
|
bool pci_aer_available(void);
|
2016-09-27 23:23:34 +03:00
|
|
|
int pci_aer_init(struct pci_dev *dev);
|
2011-01-07 02:55:09 +03:00
|
|
|
#else
|
|
|
|
static inline void pci_no_aer(void) { }
|
|
|
|
static inline bool pci_aer_available(void) { return false; }
|
2016-09-27 23:23:34 +03:00
|
|
|
static inline int pci_aer_init(struct pci_dev *d) { return -ENODEV; }
|
2011-01-07 02:55:09 +03:00
|
|
|
#endif
|
|
|
|
|
2014-01-14 04:01:11 +04:00
|
|
|
#ifdef CONFIG_PCIE_ECRC
|
2013-04-12 22:02:59 +04:00
|
|
|
void pcie_set_ecrc_checking(struct pci_dev *dev);
|
|
|
|
void pcie_ecrc_get_policy(char *str);
|
2014-01-14 04:01:11 +04:00
|
|
|
#else
|
2014-01-14 04:15:01 +04:00
|
|
|
static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { }
|
|
|
|
static inline void pcie_ecrc_get_policy(char *str) { }
|
2009-04-23 02:52:09 +04:00
|
|
|
#endif
|
|
|
|
|
2006-10-04 13:16:55 +04:00
|
|
|
#ifdef CONFIG_HT_IRQ
|
|
|
|
/* The functions a driver should call */
|
|
|
|
int ht_create_irq(struct pci_dev *dev, int idx);
|
|
|
|
void ht_destroy_irq(unsigned int irq);
|
|
|
|
#endif /* CONFIG_HT_IRQ */
|
|
|
|
|
2015-07-17 23:05:46 +03:00
|
|
|
#ifdef CONFIG_PCI_ATS
|
|
|
|
/* Address Translation Service */
|
|
|
|
void pci_ats_init(struct pci_dev *dev);
|
2015-07-17 23:55:48 +03:00
|
|
|
int pci_enable_ats(struct pci_dev *dev, int ps);
|
|
|
|
void pci_disable_ats(struct pci_dev *dev);
|
|
|
|
int pci_ats_queue_depth(struct pci_dev *dev);
|
2015-07-17 23:05:46 +03:00
|
|
|
#else
|
2015-07-17 23:55:48 +03:00
|
|
|
static inline void pci_ats_init(struct pci_dev *d) { }
|
|
|
|
static inline int pci_enable_ats(struct pci_dev *d, int ps) { return -ENODEV; }
|
|
|
|
static inline void pci_disable_ats(struct pci_dev *d) { }
|
|
|
|
static inline int pci_ats_queue_depth(struct pci_dev *d) { return -ENODEV; }
|
2015-07-17 23:05:46 +03:00
|
|
|
#endif
|
|
|
|
|
2016-06-13 19:01:51 +03:00
|
|
|
#ifdef CONFIG_PCIE_PTM
|
|
|
|
int pci_enable_ptm(struct pci_dev *dev, u8 *granularity);
|
|
|
|
#else
|
|
|
|
static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity)
|
|
|
|
{ return -EINVAL; }
|
|
|
|
#endif
|
|
|
|
|
2013-04-12 22:02:59 +04:00
|
|
|
void pci_cfg_access_lock(struct pci_dev *dev);
|
|
|
|
bool pci_cfg_access_trylock(struct pci_dev *dev);
|
|
|
|
void pci_cfg_access_unlock(struct pci_dev *dev);
|
2005-09-27 12:21:55 +04:00
|
|
|
|
2005-07-28 22:37:33 +04:00
|
|
|
/*
|
|
|
|
* PCI domain support. Sometimes called PCI segment (eg by ACPI),
|
2013-11-14 22:28:18 +04:00
|
|
|
* a PCI domain is defined to be a set of PCI buses which share
|
2005-07-28 22:37:33 +04:00
|
|
|
* configuration space.
|
|
|
|
*/
|
2007-10-12 00:57:27 +04:00
|
|
|
#ifdef CONFIG_PCI_DOMAINS
|
|
|
|
extern int pci_domains_supported;
|
2014-09-29 18:29:27 +04:00
|
|
|
int pci_get_new_domain_nr(void);
|
2007-10-12 00:57:27 +04:00
|
|
|
#else
|
|
|
|
enum { pci_domains_supported = 0 };
|
2014-01-14 04:15:01 +04:00
|
|
|
static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
|
|
|
|
static inline int pci_proc_domain(struct pci_bus *bus) { return 0; }
|
2014-09-29 18:29:27 +04:00
|
|
|
static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }
|
2007-10-12 00:57:27 +04:00
|
|
|
#endif /* CONFIG_PCI_DOMAINS */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-09-29 18:29:26 +04:00
|
|
|
/*
|
|
|
|
* Generic implementation for PCI domain support. If your
|
|
|
|
* architecture does not need custom management of PCI
|
|
|
|
* domains then this implementation will be used
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_PCI_DOMAINS_GENERIC
|
|
|
|
static inline int pci_domain_nr(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
return bus->domain_nr;
|
|
|
|
}
|
2016-06-10 23:36:26 +03:00
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
int acpi_pci_bus_find_domain_nr(struct pci_bus *bus);
|
2014-09-29 18:29:26 +04:00
|
|
|
#else
|
2016-06-10 23:36:26 +03:00
|
|
|
static inline int acpi_pci_bus_find_domain_nr(struct pci_bus *bus)
|
|
|
|
{ return 0; }
|
|
|
|
#endif
|
2016-06-10 22:55:14 +03:00
|
|
|
int pci_bus_find_domain_nr(struct pci_bus *bus, struct device *parent);
|
2014-09-29 18:29:26 +04:00
|
|
|
#endif
|
|
|
|
|
2010-02-03 01:38:13 +03:00
|
|
|
/* some architectures require additional setup to direct VGA traffic */
|
|
|
|
typedef int (*arch_set_vga_state_t)(struct pci_dev *pdev, bool decode,
|
2010-06-01 09:32:24 +04:00
|
|
|
unsigned int command_bits, u32 flags);
|
2013-04-12 22:02:59 +04:00
|
|
|
void pci_register_set_vga_state(arch_set_vga_state_t func);
|
2010-02-03 01:38:13 +03:00
|
|
|
|
2016-06-07 10:44:01 +03:00
|
|
|
static inline int
|
|
|
|
pci_request_io_regions(struct pci_dev *pdev, const char *name)
|
|
|
|
{
|
|
|
|
return pci_request_selected_regions(pdev,
|
|
|
|
pci_select_bars(pdev, IORESOURCE_IO), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
pci_release_io_regions(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
return pci_release_selected_regions(pdev,
|
|
|
|
pci_select_bars(pdev, IORESOURCE_IO));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
pci_request_mem_regions(struct pci_dev *pdev, const char *name)
|
|
|
|
{
|
|
|
|
return pci_request_selected_regions(pdev,
|
|
|
|
pci_select_bars(pdev, IORESOURCE_MEM), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
pci_release_mem_regions(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
return pci_release_selected_regions(pdev,
|
|
|
|
pci_select_bars(pdev, IORESOURCE_MEM));
|
|
|
|
}
|
|
|
|
|
2005-07-28 22:37:33 +04:00
|
|
|
#else /* CONFIG_PCI is not enabled */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2016-02-05 23:57:47 +03:00
|
|
|
static inline void pci_set_flags(int flags) { }
|
|
|
|
static inline void pci_add_flags(int flags) { }
|
|
|
|
static inline void pci_clear_flags(int flags) { }
|
|
|
|
static inline int pci_has_flag(int flag) { return 0; }
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* If the system does not have PCI, clearly these return errors. Define
|
|
|
|
* these as simple inline functions to avoid hair in drivers.
|
|
|
|
*/
|
|
|
|
|
2008-01-31 02:21:33 +03:00
|
|
|
#define _PCI_NOP(o, s, t) \
|
|
|
|
static inline int pci_##o##_config_##s(struct pci_dev *dev, \
|
|
|
|
int where, t val) \
|
2005-04-17 02:20:36 +04:00
|
|
|
{ return PCIBIOS_FUNC_NOT_SUPPORTED; }
|
2008-01-31 02:21:33 +03:00
|
|
|
|
|
|
|
#define _PCI_NOP_ALL(o, x) _PCI_NOP(o, byte, u8 x) \
|
|
|
|
_PCI_NOP(o, word, u16 x) \
|
|
|
|
_PCI_NOP(o, dword, u32 x)
|
2005-04-17 02:20:36 +04:00
|
|
|
_PCI_NOP_ALL(read, *)
|
|
|
|
_PCI_NOP_ALL(write,)
|
|
|
|
|
2006-10-21 21:24:12 +04:00
|
|
|
static inline struct pci_dev *pci_get_device(unsigned int vendor,
|
2008-01-31 02:21:33 +03:00
|
|
|
unsigned int device,
|
|
|
|
struct pci_dev *from)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return NULL; }
|
2006-10-21 21:24:12 +04:00
|
|
|
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline struct pci_dev *pci_get_subsys(unsigned int vendor,
|
|
|
|
unsigned int device,
|
|
|
|
unsigned int ss_vendor,
|
|
|
|
unsigned int ss_device,
|
2008-08-26 19:20:34 +04:00
|
|
|
struct pci_dev *from)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return NULL; }
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline struct pci_dev *pci_get_class(unsigned int class,
|
|
|
|
struct pci_dev *from)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return NULL; }
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#define pci_dev_present(ids) (0)
|
2007-07-16 10:39:39 +04:00
|
|
|
#define no_pci_devices() (1)
|
2005-04-17 02:20:36 +04:00
|
|
|
#define pci_dev_put(dev) do { } while (0)
|
|
|
|
|
2014-01-14 04:15:01 +04:00
|
|
|
static inline void pci_set_master(struct pci_dev *dev) { }
|
|
|
|
static inline int pci_enable_device(struct pci_dev *dev) { return -EIO; }
|
|
|
|
static inline void pci_disable_device(struct pci_dev *dev) { }
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline int pci_assign_resource(struct pci_dev *dev, int i)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return -EBUSY; }
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline int __pci_register_driver(struct pci_driver *drv,
|
|
|
|
struct module *owner)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return 0; }
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline int pci_register_driver(struct pci_driver *drv)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return 0; }
|
|
|
|
static inline void pci_unregister_driver(struct pci_driver *drv) { }
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline int pci_find_capability(struct pci_dev *dev, int cap)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return 0; }
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline int pci_find_next_capability(struct pci_dev *dev, u8 post,
|
|
|
|
int cap)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return 0; }
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline int pci_find_ext_capability(struct pci_dev *dev, int cap)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return 0; }
|
2008-01-31 02:21:33 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Power management related routines */
|
2014-01-14 04:15:01 +04:00
|
|
|
static inline int pci_save_state(struct pci_dev *dev) { return 0; }
|
|
|
|
static inline void pci_restore_state(struct pci_dev *dev) { }
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return 0; }
|
2011-02-14 23:27:50 +03:00
|
|
|
static inline int pci_wake_from_d3(struct pci_dev *dev, bool enable)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return 0; }
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline pci_power_t pci_choose_state(struct pci_dev *dev,
|
|
|
|
pm_message_t state)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return PCI_D0; }
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state,
|
|
|
|
int enable)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return 0; }
|
2011-01-10 23:46:36 +03:00
|
|
|
|
2016-09-15 11:07:03 +03:00
|
|
|
static inline struct resource *pci_find_resource(struct pci_dev *dev,
|
|
|
|
struct resource *res)
|
|
|
|
{ return NULL; }
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline int pci_request_regions(struct pci_dev *dev, const char *res_name)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return -EIO; }
|
|
|
|
static inline void pci_release_regions(struct pci_dev *dev) { }
|
2007-04-01 21:13:58 +04:00
|
|
|
|
2016-05-12 01:34:51 +03:00
|
|
|
static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; }
|
|
|
|
|
2014-01-14 04:15:01 +04:00
|
|
|
static inline void pci_block_cfg_access(struct pci_dev *dev) { }
|
2011-11-04 12:45:59 +04:00
|
|
|
static inline int pci_block_cfg_access_in_atomic(struct pci_dev *dev)
|
|
|
|
{ return 0; }
|
2014-01-14 04:15:01 +04:00
|
|
|
static inline void pci_unblock_cfg_access(struct pci_dev *dev) { }
|
2005-09-27 12:21:55 +04:00
|
|
|
|
2007-07-01 23:06:37 +04:00
|
|
|
static inline struct pci_bus *pci_find_next_bus(const struct pci_bus *from)
|
|
|
|
{ return NULL; }
|
|
|
|
static inline struct pci_dev *pci_get_slot(struct pci_bus *bus,
|
|
|
|
unsigned int devfn)
|
|
|
|
{ return NULL; }
|
|
|
|
static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus,
|
|
|
|
unsigned int devfn)
|
|
|
|
{ return NULL; }
|
|
|
|
|
2014-01-14 04:15:01 +04:00
|
|
|
static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
|
|
|
|
static inline struct pci_dev *pci_dev_get(struct pci_dev *dev) { return NULL; }
|
2014-09-29 18:29:27 +04:00
|
|
|
static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }
|
2012-06-11 09:26:55 +04:00
|
|
|
|
2010-02-10 04:43:04 +03:00
|
|
|
#define dev_is_pci(d) (false)
|
|
|
|
#define dev_is_pf(d) (false)
|
2005-07-28 22:37:33 +04:00
|
|
|
#endif /* CONFIG_PCI */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-07-28 22:37:33 +04:00
|
|
|
/* Include architecture-dependent settings and functions */
|
|
|
|
|
|
|
|
#include <asm/pci.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2017-04-12 15:25:59 +03:00
|
|
|
/* These two functions provide almost identical functionality. Depennding
|
|
|
|
* on the architecture, one will be implemented as a wrapper around the
|
|
|
|
* other (in drivers/pci/mmap.c).
|
|
|
|
*
|
|
|
|
* pci_mmap_resource_range() maps a specific BAR, and vm->vm_pgoff
|
|
|
|
* is expected to be an offset within that region.
|
|
|
|
*
|
|
|
|
* pci_mmap_page_range() is the legacy architecture-specific interface,
|
|
|
|
* which accepts a "user visible" resource address converted by
|
|
|
|
* pci_resource_to_user(), as used in the legacy mmap() interface in
|
|
|
|
* /proc/bus/pci/.
|
|
|
|
*/
|
|
|
|
int pci_mmap_resource_range(struct pci_dev *dev, int bar,
|
|
|
|
struct vm_area_struct *vma,
|
|
|
|
enum pci_mmap_state mmap_state, int write_combine);
|
2017-04-12 15:25:58 +03:00
|
|
|
int pci_mmap_page_range(struct pci_dev *pdev, int bar,
|
|
|
|
struct vm_area_struct *vma,
|
2017-04-12 15:25:55 +03:00
|
|
|
enum pci_mmap_state mmap_state, int write_combine);
|
|
|
|
|
2017-04-12 15:25:54 +03:00
|
|
|
#ifndef arch_can_pci_mmap_wc
|
|
|
|
#define arch_can_pci_mmap_wc() 0
|
|
|
|
#endif
|
2017-04-12 15:26:08 +03:00
|
|
|
|
2017-04-12 15:25:56 +03:00
|
|
|
#ifndef arch_can_pci_mmap_io
|
|
|
|
#define arch_can_pci_mmap_io() 0
|
2017-04-12 15:26:08 +03:00
|
|
|
#define pci_iobar_pfn(pdev, bar, vma) (-EINVAL)
|
|
|
|
#else
|
|
|
|
int pci_iobar_pfn(struct pci_dev *pdev, int bar, struct vm_area_struct *vma);
|
2017-04-12 15:25:56 +03:00
|
|
|
#endif
|
2017-04-12 15:25:54 +03:00
|
|
|
|
2016-02-17 00:56:21 +03:00
|
|
|
#ifndef pci_root_bus_fwnode
|
|
|
|
#define pci_root_bus_fwnode(bus) NULL
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* these helpers provide future and backwards compatibility
|
|
|
|
* for accessing popular PCI BAR info */
|
2008-01-31 02:21:33 +03:00
|
|
|
#define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
|
|
|
|
#define pci_resource_end(dev, bar) ((dev)->resource[(bar)].end)
|
|
|
|
#define pci_resource_flags(dev, bar) ((dev)->resource[(bar)].flags)
|
2005-04-17 02:20:36 +04:00
|
|
|
#define pci_resource_len(dev,bar) \
|
2008-01-31 02:21:33 +03:00
|
|
|
((pci_resource_start((dev), (bar)) == 0 && \
|
|
|
|
pci_resource_end((dev), (bar)) == \
|
|
|
|
pci_resource_start((dev), (bar))) ? 0 : \
|
|
|
|
\
|
|
|
|
(pci_resource_end((dev), (bar)) - \
|
|
|
|
pci_resource_start((dev), (bar)) + 1))
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Similar to the helpers above, these manipulate per-pci_dev
|
|
|
|
* driver-specific data. They are really just a wrapper around
|
|
|
|
* the generic device structure functions of these calls.
|
|
|
|
*/
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline void *pci_get_drvdata(struct pci_dev *pdev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
return dev_get_drvdata(&pdev->dev);
|
|
|
|
}
|
|
|
|
|
2008-01-31 02:21:33 +03:00
|
|
|
static inline void pci_set_drvdata(struct pci_dev *pdev, void *data)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
dev_set_drvdata(&pdev->dev, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If you want to know what to call your pci_dev, ask this function.
|
|
|
|
* Again, it's a wrapper around the generic device.
|
|
|
|
*/
|
2009-06-24 16:22:30 +04:00
|
|
|
static inline const char *pci_name(const struct pci_dev *pdev)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-07-03 20:49:39 +04:00
|
|
|
return dev_name(&pdev->dev);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-05-13 11:44:10 +04:00
|
|
|
|
|
|
|
/* Some archs don't want to expose struct resource to userland as-is
|
|
|
|
* in sysfs and /proc
|
|
|
|
*/
|
2016-06-17 22:43:34 +03:00
|
|
|
#ifdef HAVE_ARCH_PCI_RESOURCE_TO_USER
|
|
|
|
void pci_resource_to_user(const struct pci_dev *dev, int bar,
|
|
|
|
const struct resource *rsrc,
|
|
|
|
resource_size_t *start, resource_size_t *end);
|
|
|
|
#else
|
2005-05-13 11:44:10 +04:00
|
|
|
static inline void pci_resource_to_user(const struct pci_dev *dev, int bar,
|
2008-01-31 02:21:33 +03:00
|
|
|
const struct resource *rsrc, resource_size_t *start,
|
2006-06-13 04:06:02 +04:00
|
|
|
resource_size_t *end)
|
2005-05-13 11:44:10 +04:00
|
|
|
{
|
|
|
|
*start = rsrc->start;
|
|
|
|
*end = rsrc->end;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_ARCH_PCI_RESOURCE_TO_USER */
|
|
|
|
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* The world is not perfect and supplies us with broken PCI devices.
|
|
|
|
* For at least a part of these bugs we need a work-around, so both
|
|
|
|
* generic (drivers/pci/quirks.c) and per-architecture code can define
|
|
|
|
* fixup hooks to be called for particular buggy devices.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct pci_fixup {
|
2012-02-24 11:46:49 +04:00
|
|
|
u16 vendor; /* You can use PCI_ANY_ID here of course */
|
|
|
|
u16 device; /* You can use PCI_ANY_ID here of course */
|
|
|
|
u32 class; /* You can use PCI_ANY_ID here too */
|
|
|
|
unsigned int class_shift; /* should be 0, 8, 16 */
|
2005-04-17 02:20:36 +04:00
|
|
|
void (*hook)(struct pci_dev *dev);
|
|
|
|
};
|
|
|
|
|
|
|
|
enum pci_fixup_pass {
|
|
|
|
pci_fixup_early, /* Before probing BARs */
|
|
|
|
pci_fixup_header, /* After reading configuration header */
|
|
|
|
pci_fixup_final, /* Final phase of device fixups */
|
|
|
|
pci_fixup_enable, /* pci_enable_device() time */
|
2008-05-15 23:51:31 +04:00
|
|
|
pci_fixup_resume, /* pci_device_resume() */
|
2014-06-04 00:04:09 +04:00
|
|
|
pci_fixup_suspend, /* pci_device_suspend() */
|
2008-05-15 23:51:31 +04:00
|
|
|
pci_fixup_resume_early, /* pci_device_resume_early() */
|
2014-06-04 00:04:09 +04:00
|
|
|
pci_fixup_suspend_late, /* pci_device_suspend_late() */
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Anonymous variables would be nice... */
|
2012-02-24 11:46:49 +04:00
|
|
|
#define DECLARE_PCI_FIXUP_SECTION(section, name, vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
2013-11-11 17:40:35 +04:00
|
|
|
static const struct pci_fixup __PASTE(__pci_fixup_##name,__LINE__) __used \
|
2012-02-24 11:46:49 +04:00
|
|
|
__attribute__((__section__(#section), aligned((sizeof(void *))))) \
|
|
|
|
= { vendor, device, class, class_shift, hook };
|
|
|
|
|
|
|
|
#define DECLARE_PCI_FIXUP_CLASS_EARLY(vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_early, \
|
2013-11-11 17:40:35 +04:00
|
|
|
hook, vendor, device, class, class_shift, hook)
|
2012-02-24 11:46:49 +04:00
|
|
|
#define DECLARE_PCI_FIXUP_CLASS_HEADER(vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_header, \
|
2013-11-11 17:40:35 +04:00
|
|
|
hook, vendor, device, class, class_shift, hook)
|
2012-02-24 11:46:49 +04:00
|
|
|
#define DECLARE_PCI_FIXUP_CLASS_FINAL(vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_final, \
|
2013-11-11 17:40:35 +04:00
|
|
|
hook, vendor, device, class, class_shift, hook)
|
2012-02-24 11:46:49 +04:00
|
|
|
#define DECLARE_PCI_FIXUP_CLASS_ENABLE(vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_enable, \
|
2013-11-11 17:40:35 +04:00
|
|
|
hook, vendor, device, class, class_shift, hook)
|
2012-02-24 11:46:49 +04:00
|
|
|
#define DECLARE_PCI_FIXUP_CLASS_RESUME(vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume, \
|
2013-11-11 17:40:35 +04:00
|
|
|
resume##hook, vendor, device, class, \
|
2012-02-24 11:46:49 +04:00
|
|
|
class_shift, hook)
|
|
|
|
#define DECLARE_PCI_FIXUP_CLASS_RESUME_EARLY(vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume_early, \
|
2013-11-11 17:40:35 +04:00
|
|
|
resume_early##hook, vendor, device, \
|
2012-02-24 11:46:49 +04:00
|
|
|
class, class_shift, hook)
|
|
|
|
#define DECLARE_PCI_FIXUP_CLASS_SUSPEND(vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend, \
|
2013-11-11 17:40:35 +04:00
|
|
|
suspend##hook, vendor, device, class, \
|
2012-02-24 11:46:49 +04:00
|
|
|
class_shift, hook)
|
2014-06-04 00:04:09 +04:00
|
|
|
#define DECLARE_PCI_FIXUP_CLASS_SUSPEND_LATE(vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend_late, \
|
|
|
|
suspend_late##hook, vendor, device, \
|
|
|
|
class, class_shift, hook)
|
2012-02-24 11:46:49 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#define DECLARE_PCI_FIXUP_EARLY(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_early, \
|
2013-11-11 17:40:35 +04:00
|
|
|
hook, vendor, device, PCI_ANY_ID, 0, hook)
|
2005-04-17 02:20:36 +04:00
|
|
|
#define DECLARE_PCI_FIXUP_HEADER(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_header, \
|
2013-11-11 17:40:35 +04:00
|
|
|
hook, vendor, device, PCI_ANY_ID, 0, hook)
|
2005-04-17 02:20:36 +04:00
|
|
|
#define DECLARE_PCI_FIXUP_FINAL(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_final, \
|
2013-11-11 17:40:35 +04:00
|
|
|
hook, vendor, device, PCI_ANY_ID, 0, hook)
|
2005-04-17 02:20:36 +04:00
|
|
|
#define DECLARE_PCI_FIXUP_ENABLE(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_enable, \
|
2013-11-11 17:40:35 +04:00
|
|
|
hook, vendor, device, PCI_ANY_ID, 0, hook)
|
2006-12-05 02:14:45 +03:00
|
|
|
#define DECLARE_PCI_FIXUP_RESUME(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume, \
|
2013-11-11 17:40:35 +04:00
|
|
|
resume##hook, vendor, device, \
|
2012-02-24 11:46:49 +04:00
|
|
|
PCI_ANY_ID, 0, hook)
|
2008-05-15 23:51:31 +04:00
|
|
|
#define DECLARE_PCI_FIXUP_RESUME_EARLY(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume_early, \
|
2013-11-11 17:40:35 +04:00
|
|
|
resume_early##hook, vendor, device, \
|
2012-02-24 11:46:49 +04:00
|
|
|
PCI_ANY_ID, 0, hook)
|
2008-05-15 23:51:31 +04:00
|
|
|
#define DECLARE_PCI_FIXUP_SUSPEND(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend, \
|
2013-11-11 17:40:35 +04:00
|
|
|
suspend##hook, vendor, device, \
|
2012-02-24 11:46:49 +04:00
|
|
|
PCI_ANY_ID, 0, hook)
|
2014-06-04 00:04:09 +04:00
|
|
|
#define DECLARE_PCI_FIXUP_SUSPEND_LATE(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend_late, \
|
|
|
|
suspend_late##hook, vendor, device, \
|
|
|
|
PCI_ANY_ID, 0, hook)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-01-03 00:57:24 +03:00
|
|
|
#ifdef CONFIG_PCI_QUIRKS
|
2005-04-17 02:20:36 +04:00
|
|
|
void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
|
2012-06-11 09:27:07 +04:00
|
|
|
int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
|
2016-04-01 01:34:32 +03:00
|
|
|
int pci_dev_specific_enable_acs(struct pci_dev *dev);
|
2010-01-03 00:57:24 +03:00
|
|
|
#else
|
|
|
|
static inline void pci_fixup_device(enum pci_fixup_pass pass,
|
2014-01-14 04:15:01 +04:00
|
|
|
struct pci_dev *dev) { }
|
2012-06-11 09:27:07 +04:00
|
|
|
static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
|
|
|
|
u16 acs_flags)
|
|
|
|
{
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
2016-04-01 01:34:32 +03:00
|
|
|
static inline int pci_dev_specific_enable_acs(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
2010-01-03 00:57:24 +03:00
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-01-31 02:21:33 +03:00
|
|
|
void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
|
2007-02-11 18:41:31 +03:00
|
|
|
void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr);
|
2008-01-31 02:21:33 +03:00
|
|
|
void __iomem * const *pcim_iomap_table(struct pci_dev *pdev);
|
2012-01-05 03:50:02 +04:00
|
|
|
int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name);
|
|
|
|
int pcim_iomap_regions_request_all(struct pci_dev *pdev, int mask,
|
2008-03-12 09:26:34 +03:00
|
|
|
const char *name);
|
2012-01-05 03:50:02 +04:00
|
|
|
void pcim_iounmap_regions(struct pci_dev *pdev, int mask);
|
2007-02-11 18:41:31 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
extern int pci_pci_problems;
|
2006-10-01 10:27:03 +04:00
|
|
|
#define PCIPCI_FAIL 1 /* No PCI PCI DMA */
|
2005-04-17 02:20:36 +04:00
|
|
|
#define PCIPCI_TRITON 2
|
|
|
|
#define PCIPCI_NATOMA 4
|
|
|
|
#define PCIPCI_VIAETBF 8
|
|
|
|
#define PCIPCI_VSFX 16
|
2006-10-01 10:27:03 +04:00
|
|
|
#define PCIPCI_ALIMAGIK 32 /* Need low latency setting */
|
|
|
|
#define PCIAGP_FAIL 64 /* No PCI to AGP DMA */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-02-06 03:36:06 +03:00
|
|
|
extern unsigned long pci_cardbus_io_size;
|
|
|
|
extern unsigned long pci_cardbus_mem_size;
|
2012-11-22 00:35:00 +04:00
|
|
|
extern u8 pci_dfl_cache_line_size;
|
2009-10-26 23:20:44 +03:00
|
|
|
extern u8 pci_cache_line_size;
|
2007-02-06 03:36:06 +03:00
|
|
|
|
2009-09-10 01:09:24 +04:00
|
|
|
extern unsigned long pci_hotplug_io_size;
|
|
|
|
extern unsigned long pci_hotplug_mem_size;
|
2016-07-22 06:40:28 +03:00
|
|
|
extern unsigned long pci_hotplug_bus_size;
|
2009-09-10 01:09:24 +04:00
|
|
|
|
2013-11-14 22:28:18 +04:00
|
|
|
/* Architecture-specific versions may override these (weak) */
|
2008-05-05 22:25:47 +04:00
|
|
|
void pcibios_disable_device(struct pci_dev *dev);
|
2011-10-29 01:47:35 +04:00
|
|
|
void pcibios_set_master(struct pci_dev *dev);
|
2008-05-05 22:25:47 +04:00
|
|
|
int pcibios_set_pcie_reset_state(struct pci_dev *dev,
|
|
|
|
enum pcie_reset_state state);
|
2012-12-06 01:33:27 +04:00
|
|
|
int pcibios_add_device(struct pci_dev *dev);
|
2013-06-04 21:18:14 +04:00
|
|
|
void pcibios_release_device(struct pci_dev *dev);
|
2014-05-06 07:29:52 +04:00
|
|
|
void pcibios_penalize_isa_irq(int irq, int active);
|
2015-06-10 11:54:58 +03:00
|
|
|
int pcibios_alloc_irq(struct pci_dev *dev);
|
|
|
|
void pcibios_free_irq(struct pci_dev *dev);
|
2007-05-08 06:03:07 +04:00
|
|
|
|
2013-08-20 18:41:02 +04:00
|
|
|
#ifdef CONFIG_HIBERNATE_CALLBACKS
|
|
|
|
extern struct dev_pm_ops pcibios_pm_ops;
|
|
|
|
#endif
|
|
|
|
|
2016-06-10 22:55:13 +03:00
|
|
|
#if defined(CONFIG_PCI_MMCONFIG) || defined(CONFIG_ACPI_MCFG)
|
2013-04-12 22:02:59 +04:00
|
|
|
void __init pci_mmcfg_early_init(void);
|
|
|
|
void __init pci_mmcfg_late_init(void);
|
2008-02-15 12:27:20 +03:00
|
|
|
#else
|
2008-02-29 10:56:50 +03:00
|
|
|
static inline void pci_mmcfg_early_init(void) { }
|
2008-02-15 12:27:20 +03:00
|
|
|
static inline void pci_mmcfg_late_init(void) { }
|
|
|
|
#endif
|
|
|
|
|
2012-10-30 10:26:18 +04:00
|
|
|
int pci_ext_cfg_avail(void);
|
2008-11-11 01:30:50 +03:00
|
|
|
|
2008-12-02 01:30:30 +03:00
|
|
|
void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar);
|
2015-08-24 22:13:23 +03:00
|
|
|
void __iomem *pci_ioremap_wc_bar(struct pci_dev *pdev, int bar);
|
2008-09-29 03:36:11 +04:00
|
|
|
|
2009-03-20 06:25:15 +03:00
|
|
|
#ifdef CONFIG_PCI_IOV
|
2015-03-25 11:23:48 +03:00
|
|
|
int pci_iov_virtfn_bus(struct pci_dev *dev, int id);
|
|
|
|
int pci_iov_virtfn_devfn(struct pci_dev *dev, int id);
|
|
|
|
|
2013-04-12 22:02:59 +04:00
|
|
|
int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn);
|
|
|
|
void pci_disable_sriov(struct pci_dev *dev);
|
2016-03-04 02:53:03 +03:00
|
|
|
int pci_iov_add_virtfn(struct pci_dev *dev, int id, int reset);
|
|
|
|
void pci_iov_remove_virtfn(struct pci_dev *dev, int id, int reset);
|
2013-04-12 22:02:59 +04:00
|
|
|
int pci_num_vf(struct pci_dev *dev);
|
2013-04-25 08:42:29 +04:00
|
|
|
int pci_vfs_assigned(struct pci_dev *dev);
|
2013-04-12 22:02:59 +04:00
|
|
|
int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
|
|
|
|
int pci_sriov_get_totalvfs(struct pci_dev *dev);
|
2015-03-25 11:23:44 +03:00
|
|
|
resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno);
|
2009-03-20 06:25:15 +03:00
|
|
|
#else
|
2015-03-25 11:23:48 +03:00
|
|
|
static inline int pci_iov_virtfn_bus(struct pci_dev *dev, int id)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
static inline int pci_iov_virtfn_devfn(struct pci_dev *dev, int id)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
2009-03-20 06:25:15 +03:00
|
|
|
static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return -ENODEV; }
|
2016-03-04 02:53:03 +03:00
|
|
|
static inline int pci_iov_add_virtfn(struct pci_dev *dev, int id, int reset)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
static inline void pci_iov_remove_virtfn(struct pci_dev *dev,
|
|
|
|
int id, int reset) { }
|
2014-01-14 04:15:01 +04:00
|
|
|
static inline void pci_disable_sriov(struct pci_dev *dev) { }
|
|
|
|
static inline int pci_num_vf(struct pci_dev *dev) { return 0; }
|
2013-04-25 08:42:29 +04:00
|
|
|
static inline int pci_vfs_assigned(struct pci_dev *dev)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return 0; }
|
2012-11-06 00:20:37 +04:00
|
|
|
static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return 0; }
|
2012-11-06 00:20:37 +04:00
|
|
|
static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
|
2014-01-14 04:15:01 +04:00
|
|
|
{ return 0; }
|
2015-03-25 11:23:44 +03:00
|
|
|
static inline resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno)
|
|
|
|
{ return 0; }
|
2009-03-20 06:25:15 +03:00
|
|
|
#endif
|
|
|
|
|
2009-06-16 06:01:25 +04:00
|
|
|
#if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
|
2013-04-12 22:02:59 +04:00
|
|
|
void pci_hp_create_module_link(struct pci_slot *pci_slot);
|
|
|
|
void pci_hp_remove_module_link(struct pci_slot *pci_slot);
|
2009-06-16 06:01:25 +04:00
|
|
|
#endif
|
|
|
|
|
2009-11-11 08:29:54 +03:00
|
|
|
/**
|
|
|
|
* pci_pcie_cap - get the saved PCIe capability offset
|
|
|
|
* @dev: PCI device
|
|
|
|
*
|
|
|
|
* PCIe capability offset is calculated at PCI device initialization
|
|
|
|
* time and saved in the data structure. This function returns saved
|
|
|
|
* PCIe capability offset. Using this instead of pci_find_capability()
|
|
|
|
* reduces unnecessary search in the PCI configuration space. If you
|
|
|
|
* need to calculate PCIe capability offset from raw device for some
|
|
|
|
* reasons, please use pci_find_capability() instead.
|
|
|
|
*/
|
|
|
|
static inline int pci_pcie_cap(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
return dev->pcie_cap;
|
|
|
|
}
|
|
|
|
|
2009-11-11 08:35:22 +03:00
|
|
|
/**
|
|
|
|
* pci_is_pcie - check if the PCI device is PCI Express capable
|
|
|
|
* @dev: PCI device
|
|
|
|
*
|
2013-09-04 00:31:05 +04:00
|
|
|
* Returns: true if the PCI device is PCI Express capable, false otherwise.
|
2009-11-11 08:35:22 +03:00
|
|
|
*/
|
|
|
|
static inline bool pci_is_pcie(struct pci_dev *dev)
|
|
|
|
{
|
2013-09-04 00:31:05 +04:00
|
|
|
return pci_pcie_cap(dev);
|
2009-11-11 08:35:22 +03:00
|
|
|
}
|
|
|
|
|
2013-01-26 04:55:39 +04:00
|
|
|
/**
|
|
|
|
* pcie_caps_reg - get the PCIe Capabilities Register
|
|
|
|
* @dev: PCI device
|
|
|
|
*/
|
|
|
|
static inline u16 pcie_caps_reg(const struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
return dev->pcie_flags_reg;
|
|
|
|
}
|
|
|
|
|
2012-07-24 13:20:02 +04:00
|
|
|
/**
|
|
|
|
* pci_pcie_type - get the PCIe device/port type
|
|
|
|
* @dev: PCI device
|
|
|
|
*/
|
|
|
|
static inline int pci_pcie_type(const struct pci_dev *dev)
|
|
|
|
{
|
2013-01-26 04:55:45 +04:00
|
|
|
return (pcie_caps_reg(dev) & PCI_EXP_FLAGS_TYPE) >> 4;
|
2012-07-24 13:20:02 +04:00
|
|
|
}
|
|
|
|
|
2016-11-03 01:35:51 +03:00
|
|
|
static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
while (1) {
|
|
|
|
if (!pci_is_pcie(dev))
|
|
|
|
break;
|
|
|
|
if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
|
|
|
|
return dev;
|
|
|
|
if (!dev->bus->self)
|
|
|
|
break;
|
|
|
|
dev = dev->bus->self;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-04 23:15:21 +03:00
|
|
|
void pci_request_acs(void);
|
2012-06-11 09:27:07 +04:00
|
|
|
bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags);
|
|
|
|
bool pci_acs_path_enabled(struct pci_dev *start,
|
|
|
|
struct pci_dev *end, u16 acs_flags);
|
2010-02-26 17:04:39 +03:00
|
|
|
|
2010-02-26 17:04:40 +03:00
|
|
|
#define PCI_VPD_LRDT 0x80 /* Large Resource Data Type */
|
2014-09-06 07:19:10 +04:00
|
|
|
#define PCI_VPD_LRDT_ID(x) ((x) | PCI_VPD_LRDT)
|
2010-02-26 17:04:40 +03:00
|
|
|
|
|
|
|
/* Large Resource Data Type Tag Item Names */
|
|
|
|
#define PCI_VPD_LTIN_ID_STRING 0x02 /* Identifier String */
|
|
|
|
#define PCI_VPD_LTIN_RO_DATA 0x10 /* Read-Only Data */
|
|
|
|
#define PCI_VPD_LTIN_RW_DATA 0x11 /* Read-Write Data */
|
|
|
|
|
|
|
|
#define PCI_VPD_LRDT_ID_STRING PCI_VPD_LRDT_ID(PCI_VPD_LTIN_ID_STRING)
|
|
|
|
#define PCI_VPD_LRDT_RO_DATA PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RO_DATA)
|
|
|
|
#define PCI_VPD_LRDT_RW_DATA PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RW_DATA)
|
|
|
|
|
|
|
|
/* Small Resource Data Type Tag Item Names */
|
2016-02-15 11:41:59 +03:00
|
|
|
#define PCI_VPD_STIN_END 0x0f /* End */
|
2010-02-26 17:04:40 +03:00
|
|
|
|
2016-02-15 11:41:59 +03:00
|
|
|
#define PCI_VPD_SRDT_END (PCI_VPD_STIN_END << 3)
|
2010-02-26 17:04:40 +03:00
|
|
|
|
|
|
|
#define PCI_VPD_SRDT_TIN_MASK 0x78
|
|
|
|
#define PCI_VPD_SRDT_LEN_MASK 0x07
|
2016-02-15 11:41:59 +03:00
|
|
|
#define PCI_VPD_LRDT_TIN_MASK 0x7f
|
2010-02-26 17:04:40 +03:00
|
|
|
|
|
|
|
#define PCI_VPD_LRDT_TAG_SIZE 3
|
|
|
|
#define PCI_VPD_SRDT_TAG_SIZE 1
|
2010-02-26 17:04:39 +03:00
|
|
|
|
2010-02-26 17:04:42 +03:00
|
|
|
#define PCI_VPD_INFO_FLD_HDR_SIZE 3
|
|
|
|
|
2010-02-26 17:04:43 +03:00
|
|
|
#define PCI_VPD_RO_KEYWORD_PARTNO "PN"
|
|
|
|
#define PCI_VPD_RO_KEYWORD_MFR_ID "MN"
|
|
|
|
#define PCI_VPD_RO_KEYWORD_VENDOR0 "V0"
|
2011-03-09 19:58:21 +03:00
|
|
|
#define PCI_VPD_RO_KEYWORD_CHKSUM "RV"
|
2010-02-26 17:04:43 +03:00
|
|
|
|
2010-02-26 17:04:39 +03:00
|
|
|
/**
|
|
|
|
* pci_vpd_lrdt_size - Extracts the Large Resource Data Type length
|
|
|
|
* @lrdt: Pointer to the beginning of the Large Resource Data Type tag
|
|
|
|
*
|
|
|
|
* Returns the extracted Large Resource Data Type length.
|
|
|
|
*/
|
|
|
|
static inline u16 pci_vpd_lrdt_size(const u8 *lrdt)
|
|
|
|
{
|
|
|
|
return (u16)lrdt[1] + ((u16)lrdt[2] << 8);
|
|
|
|
}
|
|
|
|
|
2016-02-15 11:41:59 +03:00
|
|
|
/**
|
|
|
|
* pci_vpd_lrdt_tag - Extracts the Large Resource Data Type Tag Item
|
|
|
|
* @lrdt: Pointer to the beginning of the Large Resource Data Type tag
|
|
|
|
*
|
|
|
|
* Returns the extracted Large Resource Data Type Tag item.
|
|
|
|
*/
|
|
|
|
static inline u16 pci_vpd_lrdt_tag(const u8 *lrdt)
|
|
|
|
{
|
|
|
|
return (u16)(lrdt[0] & PCI_VPD_LRDT_TIN_MASK);
|
|
|
|
}
|
|
|
|
|
2010-02-26 17:04:40 +03:00
|
|
|
/**
|
|
|
|
* pci_vpd_srdt_size - Extracts the Small Resource Data Type length
|
2017-09-02 00:35:20 +03:00
|
|
|
* @srdt: Pointer to the beginning of the Small Resource Data Type tag
|
2010-02-26 17:04:40 +03:00
|
|
|
*
|
|
|
|
* Returns the extracted Small Resource Data Type length.
|
|
|
|
*/
|
|
|
|
static inline u8 pci_vpd_srdt_size(const u8 *srdt)
|
|
|
|
{
|
|
|
|
return (*srdt) & PCI_VPD_SRDT_LEN_MASK;
|
|
|
|
}
|
|
|
|
|
2016-02-15 11:41:59 +03:00
|
|
|
/**
|
|
|
|
* pci_vpd_srdt_tag - Extracts the Small Resource Data Type Tag Item
|
2017-09-02 00:35:20 +03:00
|
|
|
* @srdt: Pointer to the beginning of the Small Resource Data Type tag
|
2016-02-15 11:41:59 +03:00
|
|
|
*
|
|
|
|
* Returns the extracted Small Resource Data Type Tag Item.
|
|
|
|
*/
|
|
|
|
static inline u8 pci_vpd_srdt_tag(const u8 *srdt)
|
|
|
|
{
|
|
|
|
return ((*srdt) & PCI_VPD_SRDT_TIN_MASK) >> 3;
|
|
|
|
}
|
|
|
|
|
2010-02-26 17:04:42 +03:00
|
|
|
/**
|
|
|
|
* pci_vpd_info_field_size - Extracts the information field length
|
|
|
|
* @lrdt: Pointer to the beginning of an information field header
|
|
|
|
*
|
|
|
|
* Returns the extracted information field length.
|
|
|
|
*/
|
|
|
|
static inline u8 pci_vpd_info_field_size(const u8 *info_field)
|
|
|
|
{
|
|
|
|
return info_field[2];
|
|
|
|
}
|
|
|
|
|
2010-02-26 17:04:41 +03:00
|
|
|
/**
|
|
|
|
* pci_vpd_find_tag - Locates the Resource Data Type tag provided
|
|
|
|
* @buf: Pointer to buffered vpd data
|
|
|
|
* @off: The offset into the buffer at which to begin the search
|
|
|
|
* @len: The length of the vpd buffer
|
|
|
|
* @rdt: The Resource Data Type to search for
|
|
|
|
*
|
|
|
|
* Returns the index where the Resource Data Type was found or
|
|
|
|
* -ENOENT otherwise.
|
|
|
|
*/
|
|
|
|
int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt);
|
|
|
|
|
2010-02-26 17:04:43 +03:00
|
|
|
/**
|
|
|
|
* pci_vpd_find_info_keyword - Locates an information field keyword in the VPD
|
|
|
|
* @buf: Pointer to buffered vpd data
|
|
|
|
* @off: The offset into the buffer at which to begin the search
|
|
|
|
* @len: The length of the buffer area, relative to off, in which to search
|
|
|
|
* @kw: The keyword to search for
|
|
|
|
*
|
|
|
|
* Returns the index where the information field keyword was found or
|
|
|
|
* -ENOENT otherwise.
|
|
|
|
*/
|
|
|
|
int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
|
|
|
|
unsigned int len, const char *kw);
|
|
|
|
|
2011-04-11 05:37:07 +04:00
|
|
|
/* PCI <-> OF binding helpers */
|
|
|
|
#ifdef CONFIG_OF
|
|
|
|
struct device_node;
|
2015-07-28 16:46:12 +03:00
|
|
|
struct irq_domain;
|
2013-04-12 22:02:59 +04:00
|
|
|
void pci_set_of_node(struct pci_dev *dev);
|
|
|
|
void pci_release_of_node(struct pci_dev *dev);
|
|
|
|
void pci_set_bus_of_node(struct pci_bus *bus);
|
|
|
|
void pci_release_bus_of_node(struct pci_bus *bus);
|
2015-07-28 16:46:12 +03:00
|
|
|
struct irq_domain *pci_host_bridge_of_msi_domain(struct pci_bus *bus);
|
2011-04-11 05:37:07 +04:00
|
|
|
|
|
|
|
/* Arch may override this (weak) */
|
2013-04-17 20:31:34 +04:00
|
|
|
struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
|
2011-04-11 05:37:07 +04:00
|
|
|
|
2012-04-12 19:33:07 +04:00
|
|
|
static inline struct device_node *
|
|
|
|
pci_device_to_OF_node(const struct pci_dev *pdev)
|
2011-04-07 07:09:47 +04:00
|
|
|
{
|
|
|
|
return pdev ? pdev->dev.of_node : NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-11 05:34:33 +04:00
|
|
|
static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
return bus ? bus->dev.of_node : NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-11 05:37:07 +04:00
|
|
|
#else /* CONFIG_OF */
|
|
|
|
static inline void pci_set_of_node(struct pci_dev *dev) { }
|
|
|
|
static inline void pci_release_of_node(struct pci_dev *dev) { }
|
|
|
|
static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
|
|
|
|
static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
|
2015-02-03 18:29:52 +03:00
|
|
|
static inline struct device_node *
|
|
|
|
pci_device_to_OF_node(const struct pci_dev *pdev) { return NULL; }
|
2015-07-28 16:46:12 +03:00
|
|
|
static inline struct irq_domain *
|
|
|
|
pci_host_bridge_of_msi_domain(struct pci_bus *bus) { return NULL; }
|
2011-04-11 05:37:07 +04:00
|
|
|
#endif /* CONFIG_OF */
|
|
|
|
|
2015-12-10 19:55:27 +03:00
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
struct irq_domain *pci_host_bridge_acpi_msi_domain(struct pci_bus *bus);
|
|
|
|
|
|
|
|
void
|
|
|
|
pci_msi_register_fwnode_provider(struct fwnode_handle *(*fn)(struct device *));
|
|
|
|
#else
|
|
|
|
static inline struct irq_domain *
|
|
|
|
pci_host_bridge_acpi_msi_domain(struct pci_bus *bus) { return NULL; }
|
|
|
|
#endif
|
|
|
|
|
powerpc/eeh: Introduce EEH device
Original EEH implementation depends on struct pci_dn heavily. However,
EEH shouldn't depend on that actually because EEH needn't share much
information with other PCI components. That's to say, EEH should have
worked independently.
The patch introduces struct eeh_dev so that EEH core components needn't
be working based on struct pci_dn in future. Also, struct pci_dn, struct
eeh_dev instances are created in dynamic fasion and the binding with EEH
device, OF node, PCI device is implemented as well.
The EEH devices are created after PHBs are detected and initialized, but
PCI emunation hasn't started yet. Apart from that, PHB might be created
dynamically through DLPAR component and the EEH devices should be creatd
as well. Another case might be OF node is created dynamically by DR
(Dynamic Reconfiguration), which has been defined by PAPR. For those OF
nodes created by DR, EEH devices should be also created accordingly. The
binding between EEH device and OF node is done while the EEH device is
initially created.
The binding between EEH device and PCI device should be done after PCI
emunation is done. Besides, PCI hotplug also needs the binding so that
the EEH devices could be traced from the newly coming PCI buses or PCI
devices.
Signed-off-by: Gavin Shan <shangw@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2012-02-28 00:04:04 +04:00
|
|
|
#ifdef CONFIG_EEH
|
|
|
|
static inline struct eeh_dev *pci_dev_to_eeh_dev(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
return pdev->dev.archdata.edev;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-24 22:43:45 +03:00
|
|
|
void pci_add_dma_alias(struct pci_dev *dev, u8 devfn);
|
2016-03-03 17:38:02 +03:00
|
|
|
bool pci_devs_are_dma_aliases(struct pci_dev *dev1, struct pci_dev *dev2);
|
2014-05-23 03:07:30 +04:00
|
|
|
int pci_for_each_dma_alias(struct pci_dev *pdev,
|
|
|
|
int (*fn)(struct pci_dev *pdev,
|
|
|
|
u16 alias, void *data), void *data);
|
|
|
|
|
2014-09-09 06:21:25 +04:00
|
|
|
/* helper functions for operation of device flag */
|
|
|
|
static inline void pci_set_dev_assigned(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
|
|
|
|
}
|
|
|
|
static inline void pci_clear_dev_assigned(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
|
|
|
|
}
|
|
|
|
static inline bool pci_is_dev_assigned(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
return (pdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED) == PCI_DEV_FLAGS_ASSIGNED;
|
|
|
|
}
|
2015-05-27 00:11:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* pci_ari_enabled - query ARI forwarding status
|
|
|
|
* @bus: the PCI bus
|
|
|
|
*
|
|
|
|
* Returns true if ARI forwarding is enabled.
|
|
|
|
*/
|
|
|
|
static inline bool pci_ari_enabled(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
return bus->self && bus->self->ari_enabled;
|
|
|
|
}
|
2016-03-07 19:40:02 +03:00
|
|
|
|
PCI: Recognize Thunderbolt devices
Detect on probe whether a PCI device is part of a Thunderbolt controller.
Intel uses a Vendor-Specific Extended Capability (VSEC) with ID 0x1234
on such devices. Detect presence of this VSEC and cache it in a newly
added is_thunderbolt bit in struct pci_dev.
Also, add a helper to check whether a given PCI device is situated on a
Thunderbolt daisy chain (i.e., below a PCI device with is_thunderbolt
set).
The necessity arises from the following:
* If an external Thunderbolt GPU is connected to a dual GPU laptop,
that GPU is currently registered with vga_switcheroo even though it
can neither drive the laptop's panel nor be powered off by the
platform. To vga_switcheroo it will appear as if two discrete
GPUs are present. As a result, when the external GPU is runtime
suspended, vga_switcheroo will cut power to the internal discrete GPU
which may not be runtime suspended at all at this moment. The
solution is to not register external GPUs with vga_switcheroo, which
necessitates a way to recognize if they're on a Thunderbolt daisy
chain.
* Dual GPU MacBook Pros introduced 2011+ can no longer switch external
DisplayPort ports between GPUs. (They're no longer just used for DP
but have become combined DP/Thunderbolt ports.) The driver to switch
the ports, drivers/platform/x86/apple-gmux.c, needs to detect presence
of a Thunderbolt controller and, if found, keep external ports
permanently switched to the discrete GPU.
v2: Make kerneldoc for pci_is_thunderbolt_attached() more precise,
drop portion of commit message pertaining to separate series.
(Bjorn Helgaas)
Cc: Andreas Noever <andreas.noever@gmail.com>
Cc: Michael Jamet <michael.jamet@intel.com>
Cc: Tomas Winkler <tomas.winkler@intel.com>
Cc: Amir Levy <amir.jer.levy@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Link: http://patchwork.freedesktop.org/patch/msgid/0ab165a4a35c0b60f29d4c306c653ead14fcd8f9.1489145162.git.lukas@wunner.de
2017-03-10 23:23:45 +03:00
|
|
|
/**
|
|
|
|
* pci_is_thunderbolt_attached - whether device is on a Thunderbolt daisy chain
|
|
|
|
* @pdev: PCI device to check
|
|
|
|
*
|
|
|
|
* Walk upwards from @pdev and check for each encountered bridge if it's part
|
|
|
|
* of a Thunderbolt controller. Reaching the host bridge means @pdev is not
|
|
|
|
* Thunderbolt-attached. (But rather soldered to the mainboard usually.)
|
|
|
|
*/
|
|
|
|
static inline bool pci_is_thunderbolt_attached(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
struct pci_dev *parent = pdev;
|
|
|
|
|
|
|
|
if (pdev->is_thunderbolt)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
while ((parent = pci_upstream_bridge(parent)))
|
|
|
|
if (parent->is_thunderbolt)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-07 19:40:02 +03:00
|
|
|
/* provide the legacy pci_dma_* API */
|
|
|
|
#include <linux/pci-dma-compat.h>
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif /* LINUX_PCI_H */
|