2005-04-17 05:20:36 +07: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 07:46:02 +07:00
|
|
|
#include <linux/mod_devicetable.h>
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/types.h>
|
2008-04-30 03:38:48 +07:00
|
|
|
#include <linux/init.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/list.h>
|
2006-08-15 12:43:17 +07:00
|
|
|
#include <linux/compiler.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/errno.h>
|
2008-06-11 04:28:50 +07:00
|
|
|
#include <linux/kobject.h>
|
2011-07-27 06:09:06 +07:00
|
|
|
#include <linux/atomic.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/device.h>
|
2008-10-22 09:39:55 +07:00
|
|
|
#include <linux/io.h>
|
2015-02-05 12:44:44 +07:00
|
|
|
#include <linux/resource_ext.h>
|
2012-10-13 16:46:48 +07:00
|
|
|
#include <uapi/linux/pci.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-12-20 04:12:07 +07:00
|
|
|
#include <linux/pci_ids.h>
|
|
|
|
|
2013-02-28 07:06:45 +07: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-15 01:28:18 +07:00
|
|
|
*
|
|
|
|
* PCI_DEVFN(), PCI_SLOT(), and PCI_FUNC() are defined in uapi/linux/pci.h.
|
2013-02-28 07:06:45 +07:00
|
|
|
* In the interest of not exposing interfaces to user-space unnecessarily,
|
2013-11-15 01:28:18 +07:00
|
|
|
* the following kernel-only defines are being added here.
|
2013-02-28 07:06:45 +07:00
|
|
|
*/
|
2014-09-06 10:19:10 +07:00
|
|
|
#define PCI_DEVID(bus, devfn) ((((u16)(bus)) << 8) | (devfn))
|
2013-02-28 07:06:45 +07:00
|
|
|
/* return bus from PCI devid = ((u16)bus_number) << 8) | devfn */
|
|
|
|
#define PCI_BUS_NUM(x) (((x) >> 8) & 0xff)
|
|
|
|
|
2008-06-11 04:28:50 +07: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 06:41:07 +07:00
|
|
|
static inline const char *pci_slot_name(const struct pci_slot *slot)
|
|
|
|
{
|
|
|
|
return kobject_name(&slot->kobj);
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* File state for mmap()s on /proc/bus/pci/X/Y */
|
|
|
|
enum pci_mmap_state {
|
|
|
|
pci_mmap_io,
|
|
|
|
pci_mmap_mem
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This defines the direction arg to the DMA mapping routines. */
|
|
|
|
#define PCI_DMA_BIDIRECTIONAL 0
|
|
|
|
#define PCI_DMA_TODEVICE 1
|
|
|
|
#define PCI_DMA_FROMDEVICE 2
|
|
|
|
#define PCI_DMA_NONE 3
|
|
|
|
|
2008-11-22 01:39:32 +07: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 10:25:11 +07: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-22 01:39:32 +07: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 06:49:45 +07:00
|
|
|
DEVICE_COUNT_RESOURCE = PCI_NUM_RESOURCES,
|
2008-11-22 01:39:32 +07:00
|
|
|
};
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
typedef int __bitwise pci_power_t;
|
|
|
|
|
2005-07-29 01:37:33 +07: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 05:20:36 +07:00
|
|
|
#define PCI_D3hot ((pci_power_t __force) 3)
|
|
|
|
#define PCI_D3cold ((pci_power_t __force) 4)
|
2005-08-18 05:32:19 +07:00
|
|
|
#define PCI_UNKNOWN ((pci_power_t __force) 5)
|
2005-04-17 05:25:24 +07:00
|
|
|
#define PCI_POWER_ERROR ((pci_power_t __force) -1)
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-04-28 00:33:16 +07: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)
|
|
|
|
{
|
|
|
|
return pci_power_names[1 + (int) state];
|
|
|
|
}
|
|
|
|
|
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 09:23:51 +07: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-17 03:54:43 +07:00
|
|
|
|
2005-11-17 06:10:41 +07: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 04:39:36 +07: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-15 01:28:18 +07:00
|
|
|
/* Use #PERST to reset PCIe device */
|
2007-04-07 04:39:36 +07:00
|
|
|
pcie_warm_reset = (__force pcie_reset_state_t) 2,
|
|
|
|
|
2013-11-15 01:28:18 +07:00
|
|
|
/* Use PCIe Hot Reset to reset device */
|
2007-04-07 04:39:36 +07:00
|
|
|
pcie_hot_reset = (__force pcie_reset_state_t) 3
|
|
|
|
};
|
|
|
|
|
2007-10-25 15:16:30 +07: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 06:07:36 +07:00
|
|
|
PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG = (__force pci_dev_flags_t) (1 << 0),
|
2008-07-24 23:18:38 +07:00
|
|
|
/* Device configuration is irrevocably lost if disabled into D3 */
|
2014-05-23 06:07:36 +07:00
|
|
|
PCI_DEV_FLAGS_NO_D3 = (__force pci_dev_flags_t) (1 << 1),
|
2011-07-22 12:46:07 +07:00
|
|
|
/* Provide indication device is assigned by a Virtual Machine Manager */
|
2014-05-23 06:07:36 +07:00
|
|
|
PCI_DEV_FLAGS_ASSIGNED = (__force pci_dev_flags_t) (1 << 2),
|
2014-02-04 04:27:39 +07:00
|
|
|
/* Flag for quirk use to store if quirk-specific ACS is enabled */
|
2014-05-23 06:07:36 +07:00
|
|
|
PCI_DEV_FLAGS_ACS_ENABLED_QUIRK = (__force pci_dev_flags_t) (1 << 3),
|
2014-05-23 06:07:43 +07:00
|
|
|
/* Flag to indicate the device uses dma_alias_devfn */
|
|
|
|
PCI_DEV_FLAGS_DMA_ALIAS_DEVFN = (__force pci_dev_flags_t) (1 << 4),
|
2014-05-29 03:57:02 +07: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 07:16:04 +07:00
|
|
|
/* Do not use bus resets for device */
|
|
|
|
PCI_DEV_FLAGS_NO_BUS_RESET = (__force pci_dev_flags_t) (1 << 6),
|
2014-11-22 01:24:08 +07: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-14 01:40:02 +07:00
|
|
|
/* Get VPD from function 0 VPD */
|
|
|
|
PCI_DEV_FLAGS_VPD_REF_F0 = (__force pci_dev_flags_t) (1 << 8),
|
2007-10-25 15:16:30 +07:00
|
|
|
};
|
|
|
|
|
2008-06-11 21:35:17 +07:00
|
|
|
enum pci_irq_reroute_variant {
|
|
|
|
INTEL_IRQ_REROUTE_VARIANT = 1,
|
|
|
|
MAX_IRQ_REROUTE_VARIANTS = 3
|
|
|
|
};
|
|
|
|
|
2006-02-14 23:52:22 +07:00
|
|
|
typedef unsigned short __bitwise pci_bus_flags_t;
|
|
|
|
enum pci_bus_flags {
|
2007-05-15 18:59:13 +07:00
|
|
|
PCI_BUS_FLAGS_NO_MSI = (__force pci_bus_flags_t) 1,
|
|
|
|
PCI_BUS_FLAGS_NO_MMRBC = (__force pci_bus_flags_t) 2,
|
2006-02-14 23:52:22 +07:00
|
|
|
};
|
|
|
|
|
2013-07-31 13:53:21 +07: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 20:11:31 +07: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 20:11:34 +07:00
|
|
|
AGP_UNKNOWN = 0x0c,
|
|
|
|
AGP_1X = 0x0d,
|
|
|
|
AGP_2X = 0x0e,
|
|
|
|
AGP_4X = 0x0f,
|
|
|
|
AGP_8X = 0x10,
|
2009-12-13 20:11:31 +07: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 20:11:35 +07:00
|
|
|
PCIE_SPEED_8_0GT = 0x16,
|
2009-12-13 20:11:31 +07:00
|
|
|
PCI_SPEED_UNKNOWN = 0xff,
|
|
|
|
};
|
|
|
|
|
2011-05-10 23:02:11 +07:00
|
|
|
struct pci_cap_saved_data {
|
2013-12-18 06:43:45 +07:00
|
|
|
u16 cap_nr;
|
|
|
|
bool cap_extended;
|
2011-05-10 23:02:11 +07:00
|
|
|
unsigned int size;
|
2006-02-08 16:11:38 +07:00
|
|
|
u32 data[0];
|
|
|
|
};
|
|
|
|
|
2011-05-10 23:02:11 +07:00
|
|
|
struct pci_cap_saved_state {
|
|
|
|
struct hlist_node next;
|
|
|
|
struct pci_cap_saved_data cap;
|
|
|
|
};
|
|
|
|
|
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 08:46:41 +07:00
|
|
|
struct pcie_link_state;
|
2008-04-29 02:30:35 +07:00
|
|
|
struct pci_vpd;
|
2009-03-20 10:25:11 +07:00
|
|
|
struct pci_sriov;
|
2009-05-18 12:51:32 +07:00
|
|
|
struct pci_ats;
|
2008-04-29 02:30:35 +07:00
|
|
|
|
2005-04-17 05:20:36 +07: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 04:28:50 +07:00
|
|
|
struct pci_slot *slot; /* Physical slot this device is in */
|
2005-04-17 05:20:36 +07: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 05:46:30 +07:00
|
|
|
u8 revision; /* PCI revision, low byte of class word */
|
2005-04-17 05:20:36 +07:00
|
|
|
u8 hdr_type; /* PCI header type (`multi' flag masked out) */
|
2013-11-15 01:28:18 +07:00
|
|
|
u8 pcie_cap; /* PCIe capability offset */
|
2013-04-04 23:54:30 +07:00
|
|
|
u8 msi_cap; /* MSI capability offset */
|
|
|
|
u8 msix_cap; /* MSI-X capability offset */
|
2013-11-15 01:28:18 +07:00
|
|
|
u8 pcie_mpss:3; /* PCIe Max Payload Size Supported */
|
2005-04-17 05:20:36 +07:00
|
|
|
u8 rom_base_reg; /* which config register controls the ROM */
|
2013-11-15 01:28:18 +07:00
|
|
|
u8 pin; /* which interrupt pin this device uses */
|
|
|
|
u16 pcie_flags_reg; /* cached PCIe Capabilities Register */
|
2014-05-23 06:07:43 +07:00
|
|
|
u8 dma_alias_devfn;/* devfn of DMA alias, if any */
|
2005-04-17 05:20:36 +07: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 13:27:55 +07:00
|
|
|
struct device_dma_parameters dma_parms;
|
|
|
|
|
2005-04-17 05:20:36 +07: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 05:57:56 +07:00
|
|
|
u8 pm_cap; /* PM capability offset */
|
2008-07-07 08:36:24 +07:00
|
|
|
unsigned int pme_support:5; /* Bitmask of states from which PME#
|
|
|
|
can be generated */
|
2010-02-18 05:39:08 +07:00
|
|
|
unsigned int pme_interrupt:1;
|
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 04:16:33 +07:00
|
|
|
unsigned int pme_poll:1; /* Poll device's PME status bit */
|
2008-07-07 08:36:24 +07: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 09:23:51 +07:00
|
|
|
unsigned int no_d1d2:1; /* D1 and D2 are forbidden */
|
|
|
|
unsigned int no_d3cold:1; /* D3cold is forbidden */
|
|
|
|
unsigned int d3cold_allowed:1; /* D3cold is allowed by user */
|
2010-07-17 00:19:22 +07:00
|
|
|
unsigned int mmio_always_on:1; /* disallow turning off io/mem
|
|
|
|
decoding during bar sizing */
|
2009-09-09 04:14:49 +07: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 09:23:51 +07: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-11 02:45:01 +07:00
|
|
|
unsigned int ignore_hotplug:1; /* Ignore hotplug events */
|
2009-12-31 18:15:54 +07: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 09:23:51 +07:00
|
|
|
unsigned int d3cold_delay; /* D3cold->D0 transition time in ms */
|
2005-04-17 05:20:36 +07: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 08:46:41 +07:00
|
|
|
#ifdef CONFIG_PCIEASPM
|
2013-11-15 01:28:18 +07: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 08:46:41 +07:00
|
|
|
#endif
|
|
|
|
|
2005-11-17 06:10:41 +07:00
|
|
|
pci_channel_state_t error_state; /* current connectivity state */
|
2005-04-17 05:20:36 +07: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 04:20:51 +07:00
|
|
|
bool match_driver; /* Skip attaching driver */
|
2005-04-17 05:20:36 +07:00
|
|
|
/* These fields are used by common fixups */
|
2013-11-15 01:28:18 +07:00
|
|
|
unsigned int transparent:1; /* Subtractive decode PCI bridge */
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned int multifunction:1;/* Part of multi-function device */
|
|
|
|
/* keep track of device state */
|
2008-02-15 05:56:56 +07:00
|
|
|
unsigned int is_added:1;
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned int is_busmaster:1; /* device is busmaster */
|
2005-08-17 05:15:58 +07:00
|
|
|
unsigned int no_msi:1; /* device may not use msi */
|
2014-10-03 12:13:24 +07:00
|
|
|
unsigned int no_64bit_msi:1; /* device may only use 32-bit MSIs */
|
2011-11-04 15:45:59 +07:00
|
|
|
unsigned int block_cfg_access:1; /* config space access is blocked */
|
2006-05-09 07:06:09 +07:00
|
|
|
unsigned int broken_parity_status:1; /* Device generates false positive parity */
|
2008-06-11 21:35:17 +07:00
|
|
|
unsigned int irq_reroute_variant:2; /* device needs IRQ rerouting variant */
|
2013-11-15 01:28:18 +07:00
|
|
|
unsigned int msi_enabled:1;
|
2006-05-26 09:58:27 +07:00
|
|
|
unsigned int msix_enabled:1;
|
2008-10-14 13:02:53 +07:00
|
|
|
unsigned int ari_enabled:1; /* ARI forwarding */
|
2015-07-18 03:15:19 +07:00
|
|
|
unsigned int ats_enabled:1; /* Address Translation Service */
|
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 14:00:26 +07:00
|
|
|
unsigned int is_managed:1;
|
2009-07-31 05:33:21 +07:00
|
|
|
unsigned int needs_freset:1; /* Dev requires fundamental reset */
|
2009-01-17 03:54:43 +07:00
|
|
|
unsigned int state_saved:1;
|
2009-03-20 10:25:11 +07:00
|
|
|
unsigned int is_physfn:1;
|
2009-03-20 10:25:15 +07:00
|
|
|
unsigned int is_virtfn:1;
|
2009-07-28 03:37:48 +07:00
|
|
|
unsigned int reset_fn:1;
|
2009-09-10 04:09:24 +07:00
|
|
|
unsigned int is_hotplug_bridge:1;
|
2010-05-18 13:35:16 +07:00
|
|
|
unsigned int __aer_firmware_first_valid:1;
|
|
|
|
unsigned int __aer_firmware_first:1;
|
2012-06-17 03:40:22 +07:00
|
|
|
unsigned int broken_intx_masking:1;
|
2012-07-10 02:38:57 +07:00
|
|
|
unsigned int io_window_1k:1; /* Intel P2P bridge 1K I/O windows */
|
2014-10-27 12:21:42 +07: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 14:05:02 +07:00
|
|
|
unsigned int has_secondary_link:1;
|
2007-10-25 15:16:30 +07: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-23 03:40:31 +07:00
|
|
|
atomic_t enable_cnt; /* pci_enable_device has been called */
|
2005-08-17 05:15:58 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
u32 saved_config_space[16]; /* config space saved at suspend time */
|
2006-02-08 16:11:38 +07:00
|
|
|
struct hlist_head saved_cap_space;
|
2005-04-17 05:20:36 +07: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 07:00:22 +07:00
|
|
|
struct bin_attribute *res_attr_wc[DEVICE_COUNT_RESOURCE]; /* sysfs file for WC mapping of resources */
|
2007-01-29 02:42:52 +07:00
|
|
|
#ifdef CONFIG_PCI_MSI
|
2013-12-20 03:30:17 +07:00
|
|
|
const struct attribute_group **msi_irq_groups;
|
2007-01-29 02:42:52 +07:00
|
|
|
#endif
|
2008-03-05 23:52:39 +07:00
|
|
|
struct pci_vpd *vpd;
|
2011-10-30 22:35:08 +07:00
|
|
|
#ifdef CONFIG_PCI_ATS
|
2009-03-20 10:25:15 +07:00
|
|
|
union {
|
|
|
|
struct pci_sriov *sriov; /* SR-IOV capability related */
|
|
|
|
struct pci_dev *physfn; /* the PF this VF is associated with */
|
|
|
|
};
|
2015-07-18 03:27:34 +07:00
|
|
|
u16 ats_cap; /* ATS Capability offset */
|
|
|
|
u8 ats_stu; /* ATS Smallest Translation Unit */
|
2015-07-18 03:15:19 +07:00
|
|
|
atomic_t ats_ref_cnt; /* number of VFs with ATS enabled */
|
2009-03-20 10:25:11 +07:00
|
|
|
#endif
|
2012-12-11 01:24:42 +07:00
|
|
|
phys_addr_t rom; /* Physical address of ROM if it's not from the BAR */
|
2012-12-06 04:33:27 +07: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 21:53:21 +07:00
|
|
|
char *driver_override; /* Driver name to force a match */
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2010-04-09 07:07:55 +07: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 20:48:30 +07:00
|
|
|
struct pci_dev *pci_alloc_dev(struct pci_bus *bus);
|
2007-04-05 14:19:08 +07:00
|
|
|
|
2005-04-17 05:20:36 +07: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 05:55:59 +07:00
|
|
|
static inline int pci_channel_offline(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
return (pdev->error_state != pci_channel_io_normal);
|
|
|
|
}
|
|
|
|
|
2012-02-24 10:18:59 +07:00
|
|
|
struct pci_host_bridge {
|
2012-04-03 08:31:53 +07:00
|
|
|
struct device dev;
|
2012-02-24 10:18:59 +07:00
|
|
|
struct pci_bus *bus; /* root bus */
|
2015-02-05 12:44:44 +07:00
|
|
|
struct list_head windows; /* resource_entry */
|
2012-04-03 08:31:53 +07:00
|
|
|
void (*release_fn)(struct pci_host_bridge *);
|
|
|
|
void *release_data;
|
2015-03-25 13:37:06 +07:00
|
|
|
unsigned int ignore_reset_delay:1; /* for entire hierarchy */
|
2012-02-24 10:18:59 +07:00
|
|
|
};
|
2006-02-08 16:11:38 +07:00
|
|
|
|
2012-04-03 08:31:53 +07:00
|
|
|
#define to_pci_host_bridge(n) container_of(n, struct pci_host_bridge, dev)
|
2012-04-03 08:31:53 +07: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 08:31:53 +07: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 04:33:37 +07:00
|
|
|
int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge);
|
|
|
|
|
2010-02-24 00:24:36 +07: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-29 01:37:33 +07:00
|
|
|
|
|
|
|
#define PCI_REGION_FLAG_MASK 0x0fU /* These bits of resource flags tell us the PCI region flags */
|
2005-04-17 05:20:36 +07: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 16:16:31 +07:00
|
|
|
struct list_head slots; /* list of slots on this bus;
|
|
|
|
protected by pci_slot_mutex */
|
2010-02-24 00:24:36 +07:00
|
|
|
struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
|
|
|
|
struct list_head resources; /* address space routed to this bus */
|
2012-05-18 08:51:11 +07:00
|
|
|
struct resource busn_res; /* bus numbers routed to this bus */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
struct pci_ops *ops; /* configuration access functions */
|
2014-11-12 07:45:45 +07:00
|
|
|
struct msi_controller *msi; /* MSI controller */
|
2005-04-17 05:20:36 +07: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 20:11:32 +07:00
|
|
|
unsigned char max_bus_speed; /* enum pci_bus_speed */
|
|
|
|
unsigned char cur_bus_speed; /* enum pci_bus_speed */
|
2014-09-29 21:29:26 +07:00
|
|
|
#ifdef CONFIG_PCI_DOMAINS_GENERIC
|
|
|
|
int domain_nr;
|
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
char name[48];
|
|
|
|
|
|
|
|
unsigned short bridge_ctl; /* manage NO_ISA/FBB/et al behaviors */
|
2013-11-15 01:28:18 +07:00
|
|
|
pci_bus_flags_t bus_flags; /* inherited by child buses */
|
2005-04-17 05:20:36 +07:00
|
|
|
struct device *bridge;
|
2007-05-23 09:47:54 +07:00
|
|
|
struct device dev;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct bin_attribute *legacy_io; /* legacy I/O for this bus */
|
|
|
|
struct bin_attribute *legacy_mem; /* legacy mem */
|
2008-03-13 11:48:03 +07:00
|
|
|
unsigned int is_added:1;
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2007-05-23 09:47:54 +07:00
|
|
|
#define to_pci_bus(n) container_of(n, struct pci_bus, dev)
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-03-21 03:55:55 +07:00
|
|
|
/*
|
2013-11-15 01:28:18 +07:00
|
|
|
* Returns true if the PCI bus is root (behind host-PCI bridge),
|
2009-03-21 03:55:55 +07:00
|
|
|
* false otherwise
|
2013-09-25 04:14:57 +07: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-21 03:55:55 +07:00
|
|
|
*/
|
|
|
|
static inline bool pci_is_root_bus(struct pci_bus *pbus)
|
|
|
|
{
|
|
|
|
return !(pbus->parent);
|
|
|
|
}
|
|
|
|
|
2014-05-04 11:23:37 +07: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-07 00:11:48 +07: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-04 00:52:11 +07:00
|
|
|
struct device *pci_get_host_bridge_device(struct pci_dev *dev);
|
|
|
|
void pci_put_host_bridge_device(struct device *dev);
|
|
|
|
|
2009-01-05 20:50:27 +07: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 05:20:36 +07: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 12:27:33 +07:00
|
|
|
/*
|
2013-11-15 01:28:18 +07:00
|
|
|
* Translate above to generic errno for passing back through non-PCI code.
|
2012-06-11 12:27:33 +07: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 12:23:30 +07:00
|
|
|
return -ENOTTY;
|
2012-06-11 12:27:33 +07: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 12:23:30 +07:00
|
|
|
return -ERANGE;
|
2012-06-11 12:27:33 +07:00
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Low-level architecture-dependent routines */
|
|
|
|
|
|
|
|
struct pci_ops {
|
2015-01-10 09:34:39 +07:00
|
|
|
void __iomem *(*map_bus)(struct pci_bus *bus, unsigned int devfn, int where);
|
2005-04-17 05:20:36 +07: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 21:45:28 +07: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-13 01:02:59 +07: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 05:20:36 +07: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 07:23:51 +07: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 05:20:36 +07: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 07:23:51 +07:00
|
|
|
pci_bus_addr_t start;
|
|
|
|
pci_bus_addr_t end;
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pci_dynids {
|
|
|
|
spinlock_t lock; /* protects list, index */
|
|
|
|
struct list_head list; /* for IDs added at runtime */
|
|
|
|
};
|
|
|
|
|
2013-11-15 01:28:18 +07: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 06:10:41 +07: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 18:47:18 +07:00
|
|
|
|
|
|
|
/* No AER capabilities registered for the driver */
|
|
|
|
PCI_ERS_RESULT_NO_AER_DRIVER = (__force pci_ers_result_t) 6,
|
2005-11-17 06:10:41 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* PCI bus error event callbacks */
|
2008-01-31 06:21:33 +07:00
|
|
|
struct pci_error_handlers {
|
2005-11-17 06:10:41 +07:00
|
|
|
/* PCI bus error detected on this device */
|
|
|
|
pci_ers_result_t (*error_detected)(struct pci_dev *dev,
|
2008-01-31 06:21:33 +07:00
|
|
|
enum pci_channel_state error);
|
2005-11-17 06:10:41 +07:00
|
|
|
|
|
|
|
/* MMIO has been re-enabled, but not DMA */
|
|
|
|
pci_ers_result_t (*mmio_enabled)(struct pci_dev *dev);
|
|
|
|
|
|
|
|
/* PCI Express link has been reset */
|
|
|
|
pci_ers_result_t (*link_reset)(struct pci_dev *dev);
|
|
|
|
|
|
|
|
/* PCI slot has been reset */
|
|
|
|
pci_ers_result_t (*slot_reset)(struct pci_dev *dev);
|
|
|
|
|
2014-05-02 23:40:42 +07:00
|
|
|
/* PCI function reset prepare or completed */
|
|
|
|
void (*reset_notify)(struct pci_dev *dev, bool prepare);
|
|
|
|
|
2005-11-17 06:10:41 +07:00
|
|
|
/* Device driver may resume normal operations */
|
|
|
|
void (*resume)(struct pci_dev *dev);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
struct module;
|
|
|
|
struct pci_driver {
|
|
|
|
struct list_head node;
|
2010-09-03 04:28:51 +07:00
|
|
|
const char *name;
|
2005-04-17 05:20:36 +07: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 04:50:29 +07:00
|
|
|
int (*suspend_late) (struct pci_dev *dev, pm_message_t state);
|
|
|
|
int (*resume_early) (struct pci_dev *dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
int (*resume) (struct pci_dev *dev); /* Device woken up */
|
2005-04-08 12:53:31 +07:00
|
|
|
void (*shutdown) (struct pci_dev *dev);
|
2012-11-06 03:20:36 +07:00
|
|
|
int (*sriov_configure) (struct pci_dev *dev, int num_vfs); /* PF pdev */
|
2012-09-07 23:33:14 +07:00
|
|
|
const struct pci_error_handlers *err_handler;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct device_driver driver;
|
|
|
|
struct pci_dynids dynids;
|
|
|
|
};
|
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
#define to_pci_driver(drv) container_of(drv, struct pci_driver, driver)
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-02-22 17:02:21 +07:00
|
|
|
/**
|
2008-03-11 01:43:34 +07:00
|
|
|
* DEFINE_PCI_DEVICE_TABLE - macro used to describe a pci device table
|
2008-02-22 17:02:21 +07:00
|
|
|
* @_table: device table name
|
|
|
|
*
|
2013-12-14 01:36:22 +07:00
|
|
|
* This macro is deprecated and should not be used in new code.
|
2008-02-22 17:02:21 +07:00
|
|
|
*/
|
2008-03-11 01:43:34 +07:00
|
|
|
#define DEFINE_PCI_DEVICE_TABLE(_table) \
|
2012-11-22 03:35:00 +07:00
|
|
|
const struct pci_device_id _table[]
|
2008-02-22 17:02:21 +07:00
|
|
|
|
2005-04-17 05:20:36 +07: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 21:44:26 +07: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 05:20:36 +07: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-29 01:37:33 +07:00
|
|
|
* specific PCI class. The vendor, device, subvendor, and subdevice
|
2005-04-17 05:20:36 +07: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 06:14:45 +07:00
|
|
|
/**
|
|
|
|
* PCI_VDEVICE - macro used to describe a specific pci device in short form
|
2014-04-01 04:58:39 +07:00
|
|
|
* @vend: the vendor name
|
|
|
|
* @dev: the 16 bit PCI Device ID
|
2006-12-05 06:14:45 +07: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 04:58:39 +07: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 06:14:45 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* these external functions are only available when PCI support is enabled */
|
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
|
2013-08-22 10:24:44 +07: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 03:20:54 +07: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 20:48:16 +07: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 03:20:54 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
extern enum pcie_bus_config_types pcie_bus_config;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
extern struct bus_type pci_bus_type;
|
|
|
|
|
2013-11-15 01:28:18 +07:00
|
|
|
/* Do NOT directly access these two variables, unless you are arch-specific PCI
|
|
|
|
* code, or PCI core code. */
|
2005-04-17 05:20:36 +07:00
|
|
|
extern struct list_head pci_root_buses; /* list of all known PCI buses */
|
2013-11-15 01:28:18 +07:00
|
|
|
/* Some device drivers need know if PCI is initiated */
|
2013-04-13 01:02:59 +07:00
|
|
|
int no_pci_devices(void);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-11-04 11:39:31 +07:00
|
|
|
void pcibios_resource_survey_bus(struct pci_bus *bus);
|
2013-04-12 12:44:20 +07:00
|
|
|
void pcibios_add_bus(struct pci_bus *bus);
|
|
|
|
void pcibios_remove_bus(struct pci_bus *bus);
|
2005-04-17 05:20:36 +07:00
|
|
|
void pcibios_fixup_bus(struct pci_bus *);
|
2006-08-15 12:43:17 +07:00
|
|
|
int __must_check pcibios_enable_device(struct pci_dev *, int mask);
|
2013-11-15 01:28:18 +07:00
|
|
|
/* Architecture-specific versions may override this (weak) */
|
2008-01-31 06:21:33 +07:00
|
|
|
char *pcibios_setup(char *str);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Used only when drivers/pci/setup.c is used */
|
2010-01-01 23:40:50 +07:00
|
|
|
resource_size_t pcibios_align_resource(void *, const struct resource *,
|
2010-01-01 23:40:49 +07:00
|
|
|
resource_size_t,
|
2006-06-13 07:06:02 +07:00
|
|
|
resource_size_t);
|
2005-04-17 05:20:36 +07:00
|
|
|
void pcibios_update_irq(struct pci_dev *, int irq);
|
|
|
|
|
2009-12-09 13:52:13 +07:00
|
|
|
/* Weak but can be overriden by arch */
|
|
|
|
void pci_fixup_cardbus(struct pci_bus *);
|
|
|
|
|
2005-04-17 05:20:36 +07: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 13:54:40 +07:00
|
|
|
void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
|
2012-02-24 10:19:00 +07: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 13:54:40 +07:00
|
|
|
void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
|
2012-02-24 10:19:00 +07:00
|
|
|
struct pci_bus_region *region);
|
2009-07-11 04:39:53 +07:00
|
|
|
void pcibios_scan_specific_bus(int busn);
|
2013-04-13 01:02:59 +07:00
|
|
|
struct pci_bus *pci_find_bus(int domain, int busnr);
|
2009-02-04 06:45:26 +07:00
|
|
|
void pci_bus_add_devices(const struct pci_bus *bus);
|
2011-10-29 05:25:55 +07:00
|
|
|
struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata);
|
2011-10-29 05:25:45 +07: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-19 00:35:50 +07: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);
|
2015-08-04 09:27:10 +07:00
|
|
|
struct pci_bus *pci_scan_root_bus_msi(struct device *parent, int bus,
|
|
|
|
struct pci_ops *ops, void *sysdata,
|
|
|
|
struct list_head *resources,
|
|
|
|
struct msi_controller *msi);
|
2012-11-22 03:35:00 +07:00
|
|
|
struct pci_bus *pci_scan_root_bus(struct device *parent, int bus,
|
2011-10-29 05:25:50 +07:00
|
|
|
struct pci_ops *ops, void *sysdata,
|
|
|
|
struct list_head *resources);
|
2008-01-31 06:21:33 +07:00
|
|
|
struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev,
|
|
|
|
int busnr);
|
2009-12-13 20:11:32 +07:00
|
|
|
void pcie_update_link_speed(struct pci_bus *bus, u16 link_status);
|
2008-06-11 04:28:50 +07:00
|
|
|
struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
|
2008-10-21 06:40:52 +07:00
|
|
|
const char *name,
|
|
|
|
struct hotplug_slot *hotplug);
|
2008-06-11 04:28:50 +07:00
|
|
|
void pci_destroy_slot(struct pci_slot *slot);
|
2015-07-17 16:16:32 +07: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 05:20:36 +07:00
|
|
|
int pci_scan_slot(struct pci_bus *bus, int devfn);
|
2008-01-31 06:21:33 +07:00
|
|
|
struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn);
|
2005-09-06 06:31:03 +07:00
|
|
|
void pci_device_add(struct pci_dev *dev, struct pci_bus *bus);
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned int pci_scan_child_bus(struct pci_bus *bus);
|
2014-05-30 10:01:03 +07:00
|
|
|
void pci_bus_add_device(struct pci_dev *dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
void pci_read_bridge_bases(struct pci_bus *child);
|
2008-01-31 06:21:33 +07:00
|
|
|
struct resource *pci_find_parent_resource(const struct pci_dev *dev,
|
|
|
|
struct resource *res);
|
2012-04-12 22:33:07 +07:00
|
|
|
u8 pci_swizzle_interrupt_pin(const struct pci_dev *dev, u8 pin);
|
2005-04-17 05:20:36 +07:00
|
|
|
int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge);
|
2008-12-17 11:36:55 +07:00
|
|
|
u8 pci_common_swizzle(struct pci_dev *dev, u8 *pinp);
|
2013-04-13 01:02:59 +07: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 21:22:18 +07:00
|
|
|
void pci_stop_and_remove_bus_device_locked(struct pci_dev *dev);
|
2012-10-31 03:31:38 +07:00
|
|
|
void pci_stop_root_bus(struct pci_bus *bus);
|
|
|
|
void pci_remove_root_bus(struct pci_bus *bus);
|
2005-09-10 03:03:23 +07:00
|
|
|
void pci_setup_cardbus(struct pci_bus *bus);
|
2013-04-13 01:02:59 +07:00
|
|
|
void pci_sort_breadthfirst(void);
|
2010-02-10 08:43:04 +07: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))
|
|
|
|
#define dev_num_vf(d) ((dev_is_pci(d) ? pci_num_vf(to_pci_dev(d)) : 0))
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Generic PCI functions exported to card drivers */
|
|
|
|
|
2008-08-04 01:02:12 +07: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 06:21:33 +07: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 03:24:59 +07:00
|
|
|
int pci_find_next_ext_capability(struct pci_dev *dev, int pos, int cap);
|
2008-01-31 06:21:33 +07: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 06:20:21 +07:00
|
|
|
struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-10-22 00:24:12 +07:00
|
|
|
struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device,
|
|
|
|
struct pci_dev *from);
|
2008-01-31 06:21:33 +07:00
|
|
|
struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device,
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned int ss_vendor, unsigned int ss_device,
|
2008-08-26 22:20:34 +07:00
|
|
|
struct pci_dev *from);
|
2008-01-31 06:21:33 +07:00
|
|
|
struct pci_dev *pci_get_slot(struct pci_bus *bus, unsigned int devfn);
|
2009-10-13 02:14:00 +07: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 06:21:33 +07:00
|
|
|
struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from);
|
2005-04-17 05:20:36 +07:00
|
|
|
int pci_dev_present(const struct pci_device_id *ids);
|
|
|
|
|
2008-01-31 06:21:33 +07: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 09:34:39 +07: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 09:45:17 +07:00
|
|
|
struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-03-19 07:01:09 +07:00
|
|
|
static inline int pci_read_config_byte(const struct pci_dev *dev, int where, u8 *val)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-01-31 06:21:33 +07:00
|
|
|
return pci_bus_read_config_byte(dev->bus, dev->devfn, where, val);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2012-03-19 07:01:09 +07:00
|
|
|
static inline int pci_read_config_word(const struct pci_dev *dev, int where, u16 *val)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-01-31 06:21:33 +07:00
|
|
|
return pci_bus_read_config_word(dev->bus, dev->devfn, where, val);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2012-03-19 07:01:09 +07:00
|
|
|
static inline int pci_read_config_dword(const struct pci_dev *dev, int where,
|
2008-01-31 06:21:33 +07:00
|
|
|
u32 *val)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-01-31 06:21:33 +07:00
|
|
|
return pci_bus_read_config_dword(dev->bus, dev->devfn, where, val);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2012-03-19 07:01:09 +07:00
|
|
|
static inline int pci_write_config_byte(const struct pci_dev *dev, int where, u8 val)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-01-31 06:21:33 +07:00
|
|
|
return pci_bus_write_config_byte(dev->bus, dev->devfn, where, val);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2012-03-19 07:01:09 +07:00
|
|
|
static inline int pci_write_config_word(const struct pci_dev *dev, int where, u16 val)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-01-31 06:21:33 +07:00
|
|
|
return pci_bus_write_config_word(dev->bus, dev->devfn, where, val);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2012-03-19 07:01:09 +07:00
|
|
|
static inline int pci_write_config_dword(const struct pci_dev *dev, int where,
|
2008-01-31 06:21:33 +07:00
|
|
|
u32 val)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-01-31 06:21:33 +07:00
|
|
|
return pci_bus_write_config_dword(dev->bus, dev->devfn, where, val);
|
2005-04-17 05:20:36 +07: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 16:20:05 +07: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 12:27:19 +07: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 12:43:17 +07:00
|
|
|
int __must_check pci_enable_device(struct pci_dev *dev);
|
2007-12-20 11:28:08 +07: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 12:43:35 +07: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 14:00:26 +07:00
|
|
|
int __must_check pcim_enable_device(struct pci_dev *pdev);
|
|
|
|
void pcim_pin_device(struct pci_dev *pdev);
|
|
|
|
|
2009-04-03 14:41:46 +07: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 14:00:26 +07:00
|
|
|
static inline int pci_is_managed(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
return pdev->is_managed;
|
|
|
|
}
|
|
|
|
|
2015-06-10 15:55:00 +07:00
|
|
|
static inline void pci_set_managed_irq(struct pci_dev *pdev, unsigned int irq)
|
|
|
|
{
|
|
|
|
pdev->irq = irq;
|
|
|
|
pdev->irq_managed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void pci_reset_managed_irq(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
pdev->irq = 0;
|
|
|
|
pdev->irq_managed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool pci_has_managed_irq(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
return pdev->irq_managed && pdev->irq > 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
void pci_disable_device(struct pci_dev *dev);
|
2011-10-29 04:48:38 +07:00
|
|
|
|
|
|
|
extern unsigned int pcibios_max_latency;
|
2005-04-17 05:20:36 +07:00
|
|
|
void pci_set_master(struct pci_dev *dev);
|
2008-12-23 10:08:29 +07:00
|
|
|
void pci_clear_master(struct pci_dev *dev);
|
2011-10-29 04:48:38 +07:00
|
|
|
|
2007-04-07 04:39:36 +07:00
|
|
|
int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state);
|
2009-09-22 15:34:48 +07:00
|
|
|
int pci_set_cacheline_size(struct pci_dev *dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
#define HAVE_PCI_SET_MWI
|
2006-08-15 12:43:17 +07:00
|
|
|
int __must_check pci_set_mwi(struct pci_dev *dev);
|
2007-07-10 01:55:54 +07:00
|
|
|
int pci_try_set_mwi(struct pci_dev *dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
void pci_clear_mwi(struct pci_dev *dev);
|
2005-08-16 02:23:41 +07:00
|
|
|
void pci_intx(struct pci_dev *dev, int enable);
|
2011-11-04 15:46:00 +07:00
|
|
|
bool pci_intx_mask_supported(struct pci_dev *dev);
|
|
|
|
bool pci_check_and_mask_intx(struct pci_dev *dev);
|
|
|
|
bool pci_check_and_unmask_intx(struct pci_dev *dev);
|
2008-02-05 13:27:55 +07:00
|
|
|
int pci_set_dma_max_seg_size(struct pci_dev *dev, unsigned int size);
|
2008-02-05 13:28:14 +07:00
|
|
|
int pci_set_dma_seg_boundary(struct pci_dev *dev, unsigned long mask);
|
2013-12-18 06:43:39 +07:00
|
|
|
int pci_wait_for_pending(struct pci_dev *dev, int pos, u16 mask);
|
2013-08-06 17:18:36 +07:00
|
|
|
int pci_wait_for_pending_transaction(struct pci_dev *dev);
|
2007-05-15 18:59:13 +07: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 17:43:48 +07:00
|
|
|
int pcie_get_readrq(struct pci_dev *dev);
|
2007-05-15 18:59:13 +07: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 03:20:54 +07:00
|
|
|
int pcie_get_mps(struct pci_dev *dev);
|
|
|
|
int pcie_set_mps(struct pci_dev *dev, int mps);
|
2013-07-31 13:53:26 +07:00
|
|
|
int pcie_get_minimum_link(struct pci_dev *dev, enum pci_bus_speed *speed,
|
|
|
|
enum pcie_link_width *width);
|
2009-06-13 14:52:13 +07:00
|
|
|
int __pci_reset_function(struct pci_dev *dev);
|
2012-01-05 02:23:56 +07:00
|
|
|
int __pci_reset_function_locked(struct pci_dev *dev);
|
2008-10-21 16:38:25 +07:00
|
|
|
int pci_reset_function(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 05:14:31 +07:00
|
|
|
int pci_try_reset_function(struct pci_dev *dev);
|
2013-08-15 03:06:05 +07:00
|
|
|
int pci_probe_reset_slot(struct pci_slot *slot);
|
2013-08-09 03:09:55 +07: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 05:14:31 +07:00
|
|
|
int pci_try_reset_slot(struct pci_slot *slot);
|
2013-08-15 03:06:05 +07:00
|
|
|
int pci_probe_reset_bus(struct pci_bus *bus);
|
2013-08-09 03:09:55 +07: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 05:14:31 +07:00
|
|
|
int pci_try_reset_bus(struct pci_bus *bus);
|
2014-06-19 14:22:44 +07:00
|
|
|
void pci_reset_secondary_bus(struct pci_dev *dev);
|
|
|
|
void pcibios_reset_secondary_bus(struct pci_dev *dev);
|
2013-08-09 03:09:24 +07:00
|
|
|
void pci_reset_bridge_secondary_bus(struct pci_dev *dev);
|
2008-11-22 01:38:52 +07:00
|
|
|
void pci_update_resource(struct pci_dev *dev, int resno);
|
2006-08-15 12:43:17 +07:00
|
|
|
int __must_check pci_assign_resource(struct pci_dev *dev, int i);
|
2011-07-26 03:08:39 +07: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 08:31:06 +07:00
|
|
|
int pci_select_bars(struct pci_dev *dev, unsigned long flags);
|
2013-12-01 08:34:37 +07:00
|
|
|
bool pci_device_is_present(struct pci_dev *pdev);
|
2015-04-13 21:23:36 +07:00
|
|
|
void pci_ignore_hotplug(struct pci_dev *dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* ROM control related routines */
|
2008-09-23 23:25:10 +07:00
|
|
|
int pci_enable_rom(struct pci_dev *pdev);
|
|
|
|
void pci_disable_rom(struct pci_dev *pdev);
|
2005-08-09 11:20:10 +07:00
|
|
|
void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size);
|
2005-04-17 05:20:36 +07:00
|
|
|
void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom);
|
2009-01-30 02:12:47 +07:00
|
|
|
size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size);
|
2013-03-27 04:25:54 +07:00
|
|
|
void __iomem __must_check *pci_platform_rom(struct pci_dev *pdev, size_t *size);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* Power management related routines */
|
|
|
|
int pci_save_state(struct pci_dev *dev);
|
2010-12-01 06:43:26 +07:00
|
|
|
void pci_restore_state(struct pci_dev *dev);
|
2011-05-10 23:02:27 +07:00
|
|
|
struct pci_saved_state *pci_store_saved_state(struct pci_dev *dev);
|
2014-12-04 04:40:31 +07:00
|
|
|
int pci_load_saved_state(struct pci_dev *dev,
|
|
|
|
struct pci_saved_state *state);
|
2011-05-10 23:02:27 +07:00
|
|
|
int pci_load_and_free_saved_state(struct pci_dev *dev,
|
|
|
|
struct pci_saved_state **state);
|
2013-12-18 06:43:45 +07: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 04:51:40 +07:00
|
|
|
int __pci_complete_power_transition(struct pci_dev *dev, pci_power_t state);
|
2005-09-10 05:43:46 +07: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 19:39:24 +07:00
|
|
|
bool pci_pme_capable(struct pci_dev *dev, pci_power_t state);
|
2008-08-08 05:14:24 +07:00
|
|
|
void pci_pme_active(struct pci_dev *dev, bool enable);
|
2010-02-18 05:44:58 +07:00
|
|
|
int __pci_enable_wake(struct pci_dev *dev, pci_power_t state,
|
|
|
|
bool runtime, bool enable);
|
2008-08-19 02:38:00 +07:00
|
|
|
int pci_wake_from_d3(struct pci_dev *dev, bool enable);
|
2008-07-07 08:35:26 +07:00
|
|
|
int pci_prepare_to_sleep(struct pci_dev *dev);
|
|
|
|
int pci_back_from_sleep(struct pci_dev *dev);
|
2010-02-18 05:44:09 +07:00
|
|
|
bool pci_dev_run_wake(struct pci_dev *dev);
|
2010-10-05 01:22:26 +07:00
|
|
|
bool pci_check_pme_status(struct pci_dev *dev);
|
|
|
|
void pci_pme_wakeup_bus(struct pci_bus *bus);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-02-18 05:44:58 +07:00
|
|
|
static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state,
|
|
|
|
bool enable)
|
|
|
|
{
|
|
|
|
return __pci_enable_wake(dev, state, false, enable);
|
|
|
|
}
|
2005-04-17 05:20:36 +07: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 06:43:51 +07: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 23:53:04 +07:00
|
|
|
|
2010-01-27 00:10:03 +07: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 11:27:10 +07:00
|
|
|
/* Functions for PCI Hotplug drivers to use */
|
2008-01-31 06:21:33 +07:00
|
|
|
int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap);
|
2012-01-21 17:08:22 +07:00
|
|
|
unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge);
|
2009-03-21 03:56:25 +07:00
|
|
|
unsigned int pci_rescan_bus(struct pci_bus *bus);
|
2014-01-10 21:22:18 +07:00
|
|
|
void pci_lock_rescan_remove(void);
|
|
|
|
void pci_unlock_rescan_remove(void);
|
2007-07-17 11:27:10 +07:00
|
|
|
|
2008-12-19 00:17:16 +07: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);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
|
2011-11-22 01:54:13 +07:00
|
|
|
resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx);
|
2009-02-19 01:44:29 +07:00
|
|
|
void pci_bus_assign_resources(const struct pci_bus *bus);
|
2005-04-17 05:20:36 +07: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 05:21:49 +07:00
|
|
|
int pci_claim_bridge_resource(struct pci_dev *bridge, int i);
|
2005-04-17 05:20:36 +07:00
|
|
|
void pci_assign_unassigned_resources(void);
|
2010-01-22 16:02:25 +07:00
|
|
|
void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge);
|
2012-10-31 03:31:10 +07:00
|
|
|
void pci_assign_unassigned_bus_resources(struct pci_bus *bus);
|
2013-07-23 04:37:18 +07:00
|
|
|
void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus);
|
2005-04-17 05:20:36 +07:00
|
|
|
void pdev_enable_device(struct pci_dev *);
|
2008-03-05 01:56:47 +07:00
|
|
|
int pci_enable_resources(struct pci_dev *, int mask);
|
2005-04-17 05:20:36 +07:00
|
|
|
void pci_fixup_irqs(u8 (*)(struct pci_dev *, u8 *),
|
2011-06-10 21:30:21 +07:00
|
|
|
int (*)(const struct pci_dev *, u8, u8));
|
2005-04-17 05:20:36 +07:00
|
|
|
#define HAVE_PCI_REQ_REGIONS 2
|
2006-08-15 12:43:17 +07:00
|
|
|
int __must_check pci_request_regions(struct pci_dev *, const char *);
|
2008-10-23 09:55:31 +07:00
|
|
|
int __must_check pci_request_regions_exclusive(struct pci_dev *, const char *);
|
2005-04-17 05:20:36 +07:00
|
|
|
void pci_release_regions(struct pci_dev *);
|
2006-08-15 12:43:17 +07:00
|
|
|
int __must_check pci_request_region(struct pci_dev *, int, const char *);
|
2008-10-23 09:55:31 +07:00
|
|
|
int __must_check pci_request_region_exclusive(struct pci_dev *, int, const char *);
|
2005-04-17 05:20:36 +07:00
|
|
|
void pci_release_region(struct pci_dev *, int);
|
2006-12-18 08:31:06 +07:00
|
|
|
int pci_request_selected_regions(struct pci_dev *, int, const char *);
|
2008-10-23 09:55:31 +07:00
|
|
|
int pci_request_selected_regions_exclusive(struct pci_dev *, int, const char *);
|
2006-12-18 08:31:06 +07:00
|
|
|
void pci_release_selected_regions(struct pci_dev *, int);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* drivers/pci/bus.c */
|
2013-05-25 20:48:29 +07:00
|
|
|
struct pci_bus *pci_bus_get(struct pci_bus *bus);
|
|
|
|
void pci_bus_put(struct pci_bus *bus);
|
2011-10-29 05:25:35 +07:00
|
|
|
void pci_add_resource(struct list_head *resources, struct resource *res);
|
2012-02-24 10:19:00 +07:00
|
|
|
void pci_add_resource_offset(struct list_head *resources, struct resource *res,
|
|
|
|
resource_size_t offset);
|
2011-10-29 05:25:35 +07:00
|
|
|
void pci_free_resource_list(struct list_head *resources);
|
2010-02-24 00:24:36 +07:00
|
|
|
void pci_bus_add_resource(struct pci_bus *bus, struct resource *res, unsigned int flags);
|
|
|
|
struct resource *pci_bus_resource_n(const struct pci_bus *bus, int n);
|
|
|
|
void pci_bus_remove_resources(struct pci_bus *bus);
|
|
|
|
|
2010-02-24 00:24:31 +07:00
|
|
|
#define pci_bus_for_each_resource(bus, res, i) \
|
2010-02-24 00:24:36 +07:00
|
|
|
for (i = 0; \
|
|
|
|
(res = pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \
|
|
|
|
i++)
|
2010-02-24 00:24:31 +07:00
|
|
|
|
2006-08-15 12:43:17 +07: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 03:51:12 +07:00
|
|
|
unsigned long type_mask,
|
2010-01-01 23:40:50 +07:00
|
|
|
resource_size_t (*alignf)(void *,
|
|
|
|
const struct resource *,
|
2010-01-01 23:40:49 +07:00
|
|
|
resource_size_t,
|
|
|
|
resource_size_t),
|
2006-08-15 12:43:17 +07:00
|
|
|
void *alignf_data);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2014-09-29 21:29:30 +07:00
|
|
|
|
|
|
|
int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr);
|
|
|
|
|
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 07:23:51 +07:00
|
|
|
static inline pci_bus_addr_t pci_bus_address(struct pci_dev *pdev, int bar)
|
2013-12-21 22:33:26 +07:00
|
|
|
{
|
|
|
|
struct pci_bus_region region;
|
|
|
|
|
|
|
|
pcibios_resource_to_bus(pdev->bus, ®ion, &pdev->resource[bar]);
|
|
|
|
return region.start;
|
|
|
|
}
|
|
|
|
|
2005-10-28 04:12:54 +07:00
|
|
|
/* Proper probing supporting hot-pluggable devices */
|
2007-01-16 02:50:02 +07:00
|
|
|
int __must_check __pci_register_driver(struct pci_driver *, struct module *,
|
|
|
|
const char *mod_name);
|
2008-07-31 02:07:04 +07: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 04:12:54 +07:00
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
void pci_unregister_driver(struct pci_driver *dev);
|
2011-11-19 01:12:49 +07: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)
|
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
struct pci_driver *pci_dev_driver(const struct pci_dev *dev);
|
2009-09-03 13:26:36 +07: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 06:21:33 +07: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 05:20:36 +07:00
|
|
|
|
2009-06-16 12:34:38 +07:00
|
|
|
void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
|
2005-08-18 11:33:01 +07:00
|
|
|
void *userdata);
|
2005-12-13 14:09:16 +07:00
|
|
|
int pci_cfg_space_size(struct pci_dev *dev);
|
2008-01-31 06:21:33 +07:00
|
|
|
unsigned char pci_bus_max_busnr(struct pci_bus *bus);
|
2011-09-12 00:08:38 +07:00
|
|
|
void pci_setup_bridge(struct pci_bus *bus);
|
2012-09-12 05:59:45 +07:00
|
|
|
resource_size_t pcibios_window_alignment(struct pci_bus *bus,
|
|
|
|
unsigned long type);
|
2015-03-25 15:23:50 +07:00
|
|
|
resource_size_t pcibios_iov_resource_alignment(struct pci_dev *dev, int resno);
|
2005-08-18 11:33:01 +07:00
|
|
|
|
2010-06-01 12:32:24 +07:00
|
|
|
#define PCI_VGA_STATE_CHANGE_BRIDGE (1 << 0)
|
|
|
|
#define PCI_VGA_STATE_CHANGE_DECODES (1 << 1)
|
|
|
|
|
2009-08-11 12:52:06 +07:00
|
|
|
int pci_set_vga_state(struct pci_dev *pdev, bool decode,
|
2010-06-01 12:32:24 +07:00
|
|
|
unsigned int command_bits, u32 flags);
|
2005-04-17 05:20:36 +07:00
|
|
|
/* kmem_cache style wrapper around pci_alloc_consistent() */
|
|
|
|
|
2010-03-11 06:23:30 +07:00
|
|
|
#include <linux/pci-dma.h>
|
2005-04-17 05:20:36 +07: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 05:02:30 +07:00
|
|
|
#define pci_pool_zalloc(pool, flags, handle) \
|
|
|
|
dma_pool_zalloc(pool, flags, handle)
|
2005-04-17 05:20:36 +07:00
|
|
|
#define pci_pool_free(pool, vaddr, addr) dma_pool_free(pool, vaddr, addr)
|
|
|
|
|
|
|
|
struct msix_entry {
|
2008-08-16 09:36:45 +07:00
|
|
|
u32 vector; /* kernel uses to write allocated vector */
|
2005-04-17 05:20:36 +07:00
|
|
|
u16 entry; /* driver uses to specify entry, OS writes */
|
|
|
|
};
|
|
|
|
|
2015-08-24 19:42:46 +07:00
|
|
|
void pci_msi_setup_pci_dev(struct pci_dev *dev);
|
2006-10-04 16:16:33 +07:00
|
|
|
|
2014-01-14 07:01:11 +07:00
|
|
|
#ifdef CONFIG_PCI_MSI
|
|
|
|
int pci_msi_vec_count(struct pci_dev *dev);
|
2013-04-13 01:02:59 +07:00
|
|
|
void pci_msi_shutdown(struct pci_dev *dev);
|
|
|
|
void pci_disable_msi(struct pci_dev *dev);
|
2014-01-14 07:01:11 +07:00
|
|
|
int pci_msix_vec_count(struct pci_dev *dev);
|
2013-04-13 01:02:59 +07:00
|
|
|
int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec);
|
|
|
|
void pci_msix_shutdown(struct pci_dev *dev);
|
|
|
|
void pci_disable_msix(struct pci_dev *dev);
|
|
|
|
void pci_restore_msi_state(struct pci_dev *dev);
|
|
|
|
int pci_msi_enabled(void);
|
2014-01-14 07:01:11 +07:00
|
|
|
int pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec);
|
2014-02-13 21:25:02 +07:00
|
|
|
static inline int pci_enable_msi_exact(struct pci_dev *dev, int nvec)
|
|
|
|
{
|
|
|
|
int rc = pci_enable_msi_range(dev, nvec, nvec);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
return 0;
|
|
|
|
}
|
2014-01-14 07:01:11 +07:00
|
|
|
int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries,
|
|
|
|
int minvec, int maxvec);
|
2014-02-13 21:25:02 +07: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;
|
|
|
|
}
|
2014-01-14 07:01:11 +07:00
|
|
|
#else
|
2014-01-14 07:15:01 +07:00
|
|
|
static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; }
|
|
|
|
static inline void pci_msi_shutdown(struct pci_dev *dev) { }
|
|
|
|
static inline void pci_disable_msi(struct pci_dev *dev) { }
|
|
|
|
static inline int pci_msix_vec_count(struct pci_dev *dev) { return -ENOSYS; }
|
2008-01-31 06:21:33 +07:00
|
|
|
static inline int pci_enable_msix(struct pci_dev *dev,
|
|
|
|
struct msix_entry *entries, int nvec)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return -ENOSYS; }
|
|
|
|
static inline void pci_msix_shutdown(struct pci_dev *dev) { }
|
|
|
|
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; }
|
2013-12-30 14:28:16 +07:00
|
|
|
static inline int pci_enable_msi_range(struct pci_dev *dev, int minvec,
|
|
|
|
int maxvec)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return -ENOSYS; }
|
2014-02-13 21:25:02 +07:00
|
|
|
static inline int pci_enable_msi_exact(struct pci_dev *dev, int nvec)
|
|
|
|
{ return -ENOSYS; }
|
2013-12-30 14:28:16 +07:00
|
|
|
static inline int pci_enable_msix_range(struct pci_dev *dev,
|
|
|
|
struct msix_entry *entries, int minvec, int maxvec)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return -ENOSYS; }
|
2014-02-13 21:25:02 +07:00
|
|
|
static inline int pci_enable_msix_exact(struct pci_dev *dev,
|
|
|
|
struct msix_entry *entries, int nvec)
|
|
|
|
{ return -ENOSYS; }
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif
|
|
|
|
|
2011-01-15 06:07:22 +07:00
|
|
|
#ifdef CONFIG_PCIEPORTBUS
|
2011-01-07 06:55:09 +07:00
|
|
|
extern bool pcie_ports_disabled;
|
|
|
|
extern bool pcie_ports_auto;
|
2011-01-15 06:07:22 +07:00
|
|
|
#else
|
|
|
|
#define pcie_ports_disabled true
|
|
|
|
#define pcie_ports_auto false
|
|
|
|
#endif
|
2011-01-07 06:55:09 +07:00
|
|
|
|
2014-01-14 07:01:11 +07:00
|
|
|
#ifdef CONFIG_PCIEASPM
|
2013-04-13 01:02:59 +07:00
|
|
|
bool pcie_aspm_support_enabled(void);
|
2014-01-14 07:01:11 +07:00
|
|
|
#else
|
|
|
|
static inline bool pcie_aspm_support_enabled(void) { return false; }
|
2008-11-11 05:30:55 +07:00
|
|
|
#endif
|
|
|
|
|
2011-01-07 06:55:09 +07:00
|
|
|
#ifdef CONFIG_PCIEAER
|
|
|
|
void pci_no_aer(void);
|
|
|
|
bool pci_aer_available(void);
|
|
|
|
#else
|
|
|
|
static inline void pci_no_aer(void) { }
|
|
|
|
static inline bool pci_aer_available(void) { return false; }
|
|
|
|
#endif
|
|
|
|
|
2014-01-14 07:01:11 +07:00
|
|
|
#ifdef CONFIG_PCIE_ECRC
|
2013-04-13 01:02:59 +07:00
|
|
|
void pcie_set_ecrc_checking(struct pci_dev *dev);
|
|
|
|
void pcie_ecrc_get_policy(char *str);
|
2014-01-14 07:01:11 +07:00
|
|
|
#else
|
2014-01-14 07:15:01 +07:00
|
|
|
static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { }
|
|
|
|
static inline void pcie_ecrc_get_policy(char *str) { }
|
2009-04-23 05:52:09 +07:00
|
|
|
#endif
|
|
|
|
|
2014-04-14 20:28:35 +07:00
|
|
|
#define pci_enable_msi(pdev) pci_enable_msi_exact(pdev, 1)
|
2009-03-17 19:54:10 +07:00
|
|
|
|
2006-10-04 16:16:55 +07: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-18 03:05:46 +07:00
|
|
|
#ifdef CONFIG_PCI_ATS
|
|
|
|
/* Address Translation Service */
|
|
|
|
void pci_ats_init(struct pci_dev *dev);
|
2015-07-18 03:55:48 +07: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-18 03:05:46 +07:00
|
|
|
#else
|
2015-07-18 03:55:48 +07: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-18 03:05:46 +07:00
|
|
|
#endif
|
|
|
|
|
2013-04-13 01:02:59 +07: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 15:21:55 +07:00
|
|
|
|
2005-07-29 01:37:33 +07:00
|
|
|
/*
|
|
|
|
* PCI domain support. Sometimes called PCI segment (eg by ACPI),
|
2013-11-15 01:28:18 +07:00
|
|
|
* a PCI domain is defined to be a set of PCI buses which share
|
2005-07-29 01:37:33 +07:00
|
|
|
* configuration space.
|
|
|
|
*/
|
2007-10-12 03:57:27 +07:00
|
|
|
#ifdef CONFIG_PCI_DOMAINS
|
|
|
|
extern int pci_domains_supported;
|
2014-09-29 21:29:27 +07:00
|
|
|
int pci_get_new_domain_nr(void);
|
2007-10-12 03:57:27 +07:00
|
|
|
#else
|
|
|
|
enum { pci_domains_supported = 0 };
|
2014-01-14 07:15:01 +07: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 21:29:27 +07:00
|
|
|
static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }
|
2007-10-12 03:57:27 +07:00
|
|
|
#endif /* CONFIG_PCI_DOMAINS */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2014-09-29 21:29:26 +07: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;
|
|
|
|
}
|
|
|
|
void pci_bus_assign_domain_nr(struct pci_bus *bus, struct device *parent);
|
|
|
|
#else
|
|
|
|
static inline void pci_bus_assign_domain_nr(struct pci_bus *bus,
|
|
|
|
struct device *parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-03 05:38:13 +07: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 12:32:24 +07:00
|
|
|
unsigned int command_bits, u32 flags);
|
2013-04-13 01:02:59 +07:00
|
|
|
void pci_register_set_vga_state(arch_set_vga_state_t func);
|
2010-02-03 05:38:13 +07:00
|
|
|
|
2005-07-29 01:37:33 +07:00
|
|
|
#else /* CONFIG_PCI is not enabled */
|
2005-04-17 05:20:36 +07: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 06:21:33 +07: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 05:20:36 +07:00
|
|
|
{ return PCIBIOS_FUNC_NOT_SUPPORTED; }
|
2008-01-31 06:21:33 +07: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 05:20:36 +07:00
|
|
|
_PCI_NOP_ALL(read, *)
|
|
|
|
_PCI_NOP_ALL(write,)
|
|
|
|
|
2006-10-22 00:24:12 +07:00
|
|
|
static inline struct pci_dev *pci_get_device(unsigned int vendor,
|
2008-01-31 06:21:33 +07:00
|
|
|
unsigned int device,
|
|
|
|
struct pci_dev *from)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return NULL; }
|
2006-10-22 00:24:12 +07:00
|
|
|
|
2008-01-31 06:21:33 +07: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 22:20:34 +07:00
|
|
|
struct pci_dev *from)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return NULL; }
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
static inline struct pci_dev *pci_get_class(unsigned int class,
|
|
|
|
struct pci_dev *from)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return NULL; }
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#define pci_dev_present(ids) (0)
|
2007-07-16 13:39:39 +07:00
|
|
|
#define no_pci_devices() (1)
|
2005-04-17 05:20:36 +07:00
|
|
|
#define pci_dev_put(dev) do { } while (0)
|
|
|
|
|
2014-01-14 07:15:01 +07: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 06:21:33 +07:00
|
|
|
static inline int pci_set_dma_mask(struct pci_dev *dev, u64 mask)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return -EIO; }
|
2008-07-01 01:35:53 +07:00
|
|
|
static inline int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return -EIO; }
|
2008-02-05 13:27:55 +07:00
|
|
|
static inline int pci_set_dma_max_seg_size(struct pci_dev *dev,
|
|
|
|
unsigned int size)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return -EIO; }
|
2008-02-05 13:28:14 +07:00
|
|
|
static inline int pci_set_dma_seg_boundary(struct pci_dev *dev,
|
|
|
|
unsigned long mask)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return -EIO; }
|
2008-01-31 06:21:33 +07:00
|
|
|
static inline int pci_assign_resource(struct pci_dev *dev, int i)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return -EBUSY; }
|
2008-01-31 06:21:33 +07:00
|
|
|
static inline int __pci_register_driver(struct pci_driver *drv,
|
|
|
|
struct module *owner)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return 0; }
|
2008-01-31 06:21:33 +07:00
|
|
|
static inline int pci_register_driver(struct pci_driver *drv)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return 0; }
|
|
|
|
static inline void pci_unregister_driver(struct pci_driver *drv) { }
|
2008-01-31 06:21:33 +07:00
|
|
|
static inline int pci_find_capability(struct pci_dev *dev, int cap)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return 0; }
|
2008-01-31 06:21:33 +07:00
|
|
|
static inline int pci_find_next_capability(struct pci_dev *dev, u8 post,
|
|
|
|
int cap)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return 0; }
|
2008-01-31 06:21:33 +07:00
|
|
|
static inline int pci_find_ext_capability(struct pci_dev *dev, int cap)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return 0; }
|
2008-01-31 06:21:33 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Power management related routines */
|
2014-01-14 07:15:01 +07: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 06:21:33 +07:00
|
|
|
static inline int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return 0; }
|
2011-02-15 03:27:50 +07:00
|
|
|
static inline int pci_wake_from_d3(struct pci_dev *dev, bool enable)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return 0; }
|
2008-01-31 06:21:33 +07:00
|
|
|
static inline pci_power_t pci_choose_state(struct pci_dev *dev,
|
|
|
|
pm_message_t state)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return PCI_D0; }
|
2008-01-31 06:21:33 +07:00
|
|
|
static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state,
|
|
|
|
int enable)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return 0; }
|
2011-01-11 03:46:36 +07:00
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
static inline int pci_request_regions(struct pci_dev *dev, const char *res_name)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return -EIO; }
|
|
|
|
static inline void pci_release_regions(struct pci_dev *dev) { }
|
2007-04-02 00:13:58 +07:00
|
|
|
|
2014-01-14 07:15:01 +07:00
|
|
|
static inline void pci_block_cfg_access(struct pci_dev *dev) { }
|
2011-11-04 15:45:59 +07:00
|
|
|
static inline int pci_block_cfg_access_in_atomic(struct pci_dev *dev)
|
|
|
|
{ return 0; }
|
2014-01-14 07:15:01 +07:00
|
|
|
static inline void pci_unblock_cfg_access(struct pci_dev *dev) { }
|
2005-09-27 15:21:55 +07:00
|
|
|
|
2007-07-02 02:06:37 +07: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 07:15:01 +07: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 21:29:27 +07:00
|
|
|
static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }
|
2012-06-11 12:26:55 +07:00
|
|
|
|
2010-02-10 08:43:04 +07:00
|
|
|
#define dev_is_pci(d) (false)
|
|
|
|
#define dev_is_pf(d) (false)
|
|
|
|
#define dev_num_vf(d) (0)
|
2005-07-29 01:37:33 +07:00
|
|
|
#endif /* CONFIG_PCI */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-07-29 01:37:33 +07:00
|
|
|
/* Include architecture-dependent settings and functions */
|
|
|
|
|
|
|
|
#include <asm/pci.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* these helpers provide future and backwards compatibility
|
|
|
|
* for accessing popular PCI BAR info */
|
2008-01-31 06:21:33 +07: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 05:20:36 +07:00
|
|
|
#define pci_resource_len(dev,bar) \
|
2008-01-31 06:21:33 +07: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 05:20:36 +07: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 06:21:33 +07:00
|
|
|
static inline void *pci_get_drvdata(struct pci_dev *pdev)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
return dev_get_drvdata(&pdev->dev);
|
|
|
|
}
|
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
static inline void pci_set_drvdata(struct pci_dev *pdev, void *data)
|
2005-04-17 05:20:36 +07: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 19:22:30 +07:00
|
|
|
static inline const char *pci_name(const struct pci_dev *pdev)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2008-07-03 23:49:39 +07:00
|
|
|
return dev_name(&pdev->dev);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2005-05-13 14:44:10 +07:00
|
|
|
|
|
|
|
/* Some archs don't want to expose struct resource to userland as-is
|
|
|
|
* in sysfs and /proc
|
|
|
|
*/
|
|
|
|
#ifndef HAVE_ARCH_PCI_RESOURCE_TO_USER
|
|
|
|
static inline void pci_resource_to_user(const struct pci_dev *dev, int bar,
|
2008-01-31 06:21:33 +07:00
|
|
|
const struct resource *rsrc, resource_size_t *start,
|
2006-06-13 07:06:02 +07:00
|
|
|
resource_size_t *end)
|
2005-05-13 14:44:10 +07:00
|
|
|
{
|
|
|
|
*start = rsrc->start;
|
|
|
|
*end = rsrc->end;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_ARCH_PCI_RESOURCE_TO_USER */
|
|
|
|
|
|
|
|
|
2005-04-17 05:20:36 +07: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 14:46:49 +07: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 05:20:36 +07: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-16 02:51:31 +07:00
|
|
|
pci_fixup_resume, /* pci_device_resume() */
|
2014-06-04 03:04:09 +07:00
|
|
|
pci_fixup_suspend, /* pci_device_suspend() */
|
2008-05-16 02:51:31 +07:00
|
|
|
pci_fixup_resume_early, /* pci_device_resume_early() */
|
2014-06-04 03:04:09 +07:00
|
|
|
pci_fixup_suspend_late, /* pci_device_suspend_late() */
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Anonymous variables would be nice... */
|
2012-02-24 14:46:49 +07:00
|
|
|
#define DECLARE_PCI_FIXUP_SECTION(section, name, vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
2013-11-11 20:40:35 +07:00
|
|
|
static const struct pci_fixup __PASTE(__pci_fixup_##name,__LINE__) __used \
|
2012-02-24 14:46:49 +07: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 20:40:35 +07:00
|
|
|
hook, vendor, device, class, class_shift, hook)
|
2012-02-24 14:46:49 +07:00
|
|
|
#define DECLARE_PCI_FIXUP_CLASS_HEADER(vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_header, \
|
2013-11-11 20:40:35 +07:00
|
|
|
hook, vendor, device, class, class_shift, hook)
|
2012-02-24 14:46:49 +07:00
|
|
|
#define DECLARE_PCI_FIXUP_CLASS_FINAL(vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_final, \
|
2013-11-11 20:40:35 +07:00
|
|
|
hook, vendor, device, class, class_shift, hook)
|
2012-02-24 14:46:49 +07:00
|
|
|
#define DECLARE_PCI_FIXUP_CLASS_ENABLE(vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_enable, \
|
2013-11-11 20:40:35 +07:00
|
|
|
hook, vendor, device, class, class_shift, hook)
|
2012-02-24 14:46:49 +07:00
|
|
|
#define DECLARE_PCI_FIXUP_CLASS_RESUME(vendor, device, class, \
|
|
|
|
class_shift, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume, \
|
2013-11-11 20:40:35 +07:00
|
|
|
resume##hook, vendor, device, class, \
|
2012-02-24 14:46:49 +07: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 20:40:35 +07:00
|
|
|
resume_early##hook, vendor, device, \
|
2012-02-24 14:46:49 +07: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 20:40:35 +07:00
|
|
|
suspend##hook, vendor, device, class, \
|
2012-02-24 14:46:49 +07:00
|
|
|
class_shift, hook)
|
2014-06-04 03:04:09 +07: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 14:46:49 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#define DECLARE_PCI_FIXUP_EARLY(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_early, \
|
2013-11-11 20:40:35 +07:00
|
|
|
hook, vendor, device, PCI_ANY_ID, 0, hook)
|
2005-04-17 05:20:36 +07:00
|
|
|
#define DECLARE_PCI_FIXUP_HEADER(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_header, \
|
2013-11-11 20:40:35 +07:00
|
|
|
hook, vendor, device, PCI_ANY_ID, 0, hook)
|
2005-04-17 05:20:36 +07:00
|
|
|
#define DECLARE_PCI_FIXUP_FINAL(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_final, \
|
2013-11-11 20:40:35 +07:00
|
|
|
hook, vendor, device, PCI_ANY_ID, 0, hook)
|
2005-04-17 05:20:36 +07:00
|
|
|
#define DECLARE_PCI_FIXUP_ENABLE(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_enable, \
|
2013-11-11 20:40:35 +07:00
|
|
|
hook, vendor, device, PCI_ANY_ID, 0, hook)
|
2006-12-05 06:14:45 +07:00
|
|
|
#define DECLARE_PCI_FIXUP_RESUME(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume, \
|
2013-11-11 20:40:35 +07:00
|
|
|
resume##hook, vendor, device, \
|
2012-02-24 14:46:49 +07:00
|
|
|
PCI_ANY_ID, 0, hook)
|
2008-05-16 02:51:31 +07:00
|
|
|
#define DECLARE_PCI_FIXUP_RESUME_EARLY(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume_early, \
|
2013-11-11 20:40:35 +07:00
|
|
|
resume_early##hook, vendor, device, \
|
2012-02-24 14:46:49 +07:00
|
|
|
PCI_ANY_ID, 0, hook)
|
2008-05-16 02:51:31 +07:00
|
|
|
#define DECLARE_PCI_FIXUP_SUSPEND(vendor, device, hook) \
|
|
|
|
DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend, \
|
2013-11-11 20:40:35 +07:00
|
|
|
suspend##hook, vendor, device, \
|
2012-02-24 14:46:49 +07:00
|
|
|
PCI_ANY_ID, 0, hook)
|
2014-06-04 03:04:09 +07: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 05:20:36 +07:00
|
|
|
|
2010-01-03 04:57:24 +07:00
|
|
|
#ifdef CONFIG_PCI_QUIRKS
|
2005-04-17 05:20:36 +07:00
|
|
|
void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
|
2012-06-11 12:27:07 +07:00
|
|
|
int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
|
2014-02-04 04:27:33 +07:00
|
|
|
void pci_dev_specific_enable_acs(struct pci_dev *dev);
|
2010-01-03 04:57:24 +07:00
|
|
|
#else
|
|
|
|
static inline void pci_fixup_device(enum pci_fixup_pass pass,
|
2014-01-14 07:15:01 +07:00
|
|
|
struct pci_dev *dev) { }
|
2012-06-11 12:27:07 +07:00
|
|
|
static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
|
|
|
|
u16 acs_flags)
|
|
|
|
{
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
2014-02-04 04:27:33 +07:00
|
|
|
static inline void pci_dev_specific_enable_acs(struct pci_dev *dev) { }
|
2010-01-03 04:57:24 +07:00
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-01-31 06:21:33 +07:00
|
|
|
void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
|
2007-02-11 22:41:31 +07:00
|
|
|
void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr);
|
2008-01-31 06:21:33 +07:00
|
|
|
void __iomem * const *pcim_iomap_table(struct pci_dev *pdev);
|
2012-01-05 06:50:02 +07: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 13:26:34 +07:00
|
|
|
const char *name);
|
2012-01-05 06:50:02 +07:00
|
|
|
void pcim_iounmap_regions(struct pci_dev *pdev, int mask);
|
2007-02-11 22:41:31 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
extern int pci_pci_problems;
|
2006-10-01 13:27:03 +07:00
|
|
|
#define PCIPCI_FAIL 1 /* No PCI PCI DMA */
|
2005-04-17 05:20:36 +07:00
|
|
|
#define PCIPCI_TRITON 2
|
|
|
|
#define PCIPCI_NATOMA 4
|
|
|
|
#define PCIPCI_VIAETBF 8
|
|
|
|
#define PCIPCI_VSFX 16
|
2006-10-01 13:27:03 +07:00
|
|
|
#define PCIPCI_ALIMAGIK 32 /* Need low latency setting */
|
|
|
|
#define PCIAGP_FAIL 64 /* No PCI to AGP DMA */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2007-02-06 07:36:06 +07:00
|
|
|
extern unsigned long pci_cardbus_io_size;
|
|
|
|
extern unsigned long pci_cardbus_mem_size;
|
2012-11-22 03:35:00 +07:00
|
|
|
extern u8 pci_dfl_cache_line_size;
|
2009-10-27 03:20:44 +07:00
|
|
|
extern u8 pci_cache_line_size;
|
2007-02-06 07:36:06 +07:00
|
|
|
|
2009-09-10 04:09:24 +07:00
|
|
|
extern unsigned long pci_hotplug_io_size;
|
|
|
|
extern unsigned long pci_hotplug_mem_size;
|
|
|
|
|
2013-11-15 01:28:18 +07:00
|
|
|
/* Architecture-specific versions may override these (weak) */
|
2008-05-06 01:25:47 +07:00
|
|
|
void pcibios_disable_device(struct pci_dev *dev);
|
2011-10-29 04:47:35 +07:00
|
|
|
void pcibios_set_master(struct pci_dev *dev);
|
2008-05-06 01:25:47 +07:00
|
|
|
int pcibios_set_pcie_reset_state(struct pci_dev *dev,
|
|
|
|
enum pcie_reset_state state);
|
2012-12-06 04:33:27 +07:00
|
|
|
int pcibios_add_device(struct pci_dev *dev);
|
2013-06-05 00:18:14 +07:00
|
|
|
void pcibios_release_device(struct pci_dev *dev);
|
2014-05-06 10:29:52 +07:00
|
|
|
void pcibios_penalize_isa_irq(int irq, int active);
|
2015-06-10 15:54:58 +07:00
|
|
|
int pcibios_alloc_irq(struct pci_dev *dev);
|
|
|
|
void pcibios_free_irq(struct pci_dev *dev);
|
2007-05-08 09:03:07 +07:00
|
|
|
|
2013-08-20 21:41:02 +07:00
|
|
|
#ifdef CONFIG_HIBERNATE_CALLBACKS
|
|
|
|
extern struct dev_pm_ops pcibios_pm_ops;
|
|
|
|
#endif
|
|
|
|
|
2008-02-15 16:27:20 +07:00
|
|
|
#ifdef CONFIG_PCI_MMCONFIG
|
2013-04-13 01:02:59 +07:00
|
|
|
void __init pci_mmcfg_early_init(void);
|
|
|
|
void __init pci_mmcfg_late_init(void);
|
2008-02-15 16:27:20 +07:00
|
|
|
#else
|
2008-02-29 14:56:50 +07:00
|
|
|
static inline void pci_mmcfg_early_init(void) { }
|
2008-02-15 16:27:20 +07:00
|
|
|
static inline void pci_mmcfg_late_init(void) { }
|
|
|
|
#endif
|
|
|
|
|
2012-10-30 13:26:18 +07:00
|
|
|
int pci_ext_cfg_avail(void);
|
2008-11-11 05:30:50 +07:00
|
|
|
|
2008-12-02 05:30:30 +07:00
|
|
|
void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar);
|
2015-08-25 02:13:23 +07:00
|
|
|
void __iomem *pci_ioremap_wc_bar(struct pci_dev *pdev, int bar);
|
2008-09-29 06:36:11 +07:00
|
|
|
|
2009-03-20 10:25:15 +07:00
|
|
|
#ifdef CONFIG_PCI_IOV
|
2015-03-25 15:23:48 +07: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-13 01:02:59 +07:00
|
|
|
int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn);
|
|
|
|
void pci_disable_sriov(struct pci_dev *dev);
|
|
|
|
int pci_num_vf(struct pci_dev *dev);
|
2013-04-25 11:42:29 +07:00
|
|
|
int pci_vfs_assigned(struct pci_dev *dev);
|
2013-04-13 01:02:59 +07:00
|
|
|
int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
|
|
|
|
int pci_sriov_get_totalvfs(struct pci_dev *dev);
|
2015-03-25 15:23:44 +07:00
|
|
|
resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno);
|
2009-03-20 10:25:15 +07:00
|
|
|
#else
|
2015-03-25 15:23:48 +07: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 10:25:15 +07:00
|
|
|
static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return -ENODEV; }
|
|
|
|
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 11:42:29 +07:00
|
|
|
static inline int pci_vfs_assigned(struct pci_dev *dev)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return 0; }
|
2012-11-06 03:20:37 +07:00
|
|
|
static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return 0; }
|
2012-11-06 03:20:37 +07:00
|
|
|
static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
|
2014-01-14 07:15:01 +07:00
|
|
|
{ return 0; }
|
2015-03-25 15:23:44 +07:00
|
|
|
static inline resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno)
|
|
|
|
{ return 0; }
|
2009-03-20 10:25:15 +07:00
|
|
|
#endif
|
|
|
|
|
2009-06-16 09:01:25 +07:00
|
|
|
#if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
|
2013-04-13 01:02:59 +07: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 09:01:25 +07:00
|
|
|
#endif
|
|
|
|
|
2009-11-11 12:29:54 +07: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 12:35:22 +07:00
|
|
|
/**
|
|
|
|
* pci_is_pcie - check if the PCI device is PCI Express capable
|
|
|
|
* @dev: PCI device
|
|
|
|
*
|
2013-09-04 03:31:05 +07:00
|
|
|
* Returns: true if the PCI device is PCI Express capable, false otherwise.
|
2009-11-11 12:35:22 +07:00
|
|
|
*/
|
|
|
|
static inline bool pci_is_pcie(struct pci_dev *dev)
|
|
|
|
{
|
2013-09-04 03:31:05 +07:00
|
|
|
return pci_pcie_cap(dev);
|
2009-11-11 12:35:22 +07:00
|
|
|
}
|
|
|
|
|
2013-01-26 07:55:39 +07: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 16:20:02 +07: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 07:55:45 +07:00
|
|
|
return (pcie_caps_reg(dev) & PCI_EXP_FLAGS_TYPE) >> 4;
|
2012-07-24 16:20:02 +07:00
|
|
|
}
|
|
|
|
|
2009-12-05 03:15:21 +07:00
|
|
|
void pci_request_acs(void);
|
2012-06-11 12:27:07 +07: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 21:04:39 +07:00
|
|
|
|
2010-02-26 21:04:40 +07:00
|
|
|
#define PCI_VPD_LRDT 0x80 /* Large Resource Data Type */
|
2014-09-06 10:19:10 +07:00
|
|
|
#define PCI_VPD_LRDT_ID(x) ((x) | PCI_VPD_LRDT)
|
2010-02-26 21:04:40 +07: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 */
|
|
|
|
#define PCI_VPD_STIN_END 0x78 /* End */
|
|
|
|
|
|
|
|
#define PCI_VPD_SRDT_END PCI_VPD_STIN_END
|
|
|
|
|
|
|
|
#define PCI_VPD_SRDT_TIN_MASK 0x78
|
|
|
|
#define PCI_VPD_SRDT_LEN_MASK 0x07
|
|
|
|
|
|
|
|
#define PCI_VPD_LRDT_TAG_SIZE 3
|
|
|
|
#define PCI_VPD_SRDT_TAG_SIZE 1
|
2010-02-26 21:04:39 +07:00
|
|
|
|
2010-02-26 21:04:42 +07:00
|
|
|
#define PCI_VPD_INFO_FLD_HDR_SIZE 3
|
|
|
|
|
2010-02-26 21:04:43 +07: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 23:58:21 +07:00
|
|
|
#define PCI_VPD_RO_KEYWORD_CHKSUM "RV"
|
2010-02-26 21:04:43 +07:00
|
|
|
|
2010-02-26 21:04:39 +07: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);
|
|
|
|
}
|
|
|
|
|
2010-02-26 21:04:40 +07:00
|
|
|
/**
|
|
|
|
* pci_vpd_srdt_size - Extracts the Small Resource Data Type length
|
|
|
|
* @lrdt: Pointer to the beginning of the Small Resource Data Type tag
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2010-02-26 21:04:42 +07: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 21:04:41 +07: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 21:04:43 +07: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 08:37:07 +07:00
|
|
|
/* PCI <-> OF binding helpers */
|
|
|
|
#ifdef CONFIG_OF
|
|
|
|
struct device_node;
|
2015-07-28 20:46:12 +07:00
|
|
|
struct irq_domain;
|
2013-04-13 01:02:59 +07: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 20:46:12 +07:00
|
|
|
struct irq_domain *pci_host_bridge_of_msi_domain(struct pci_bus *bus);
|
2011-04-11 08:37:07 +07:00
|
|
|
|
|
|
|
/* Arch may override this (weak) */
|
2013-04-17 23:31:34 +07:00
|
|
|
struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
|
2011-04-11 08:37:07 +07:00
|
|
|
|
2012-04-12 22:33:07 +07:00
|
|
|
static inline struct device_node *
|
|
|
|
pci_device_to_OF_node(const struct pci_dev *pdev)
|
2011-04-07 10:09:47 +07:00
|
|
|
{
|
|
|
|
return pdev ? pdev->dev.of_node : NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-11 08:34:33 +07: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 08:37:07 +07: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 22:29:52 +07:00
|
|
|
static inline struct device_node *
|
|
|
|
pci_device_to_OF_node(const struct pci_dev *pdev) { return NULL; }
|
2015-07-28 20:46:12 +07:00
|
|
|
static inline struct irq_domain *
|
|
|
|
pci_host_bridge_of_msi_domain(struct pci_bus *bus) { return NULL; }
|
2011-04-11 08:37:07 +07:00
|
|
|
#endif /* CONFIG_OF */
|
|
|
|
|
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 03:04:04 +07:00
|
|
|
#ifdef CONFIG_EEH
|
|
|
|
static inline struct eeh_dev *pci_dev_to_eeh_dev(struct pci_dev *pdev)
|
|
|
|
{
|
|
|
|
return pdev->dev.archdata.edev;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-23 06:07:30 +07: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 09:21:25 +07: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 04:11:44 +07: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;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif /* LINUX_PCI_H */
|