22 #include <linux/types.h>
25 #include <linux/list.h>
26 #include <linux/compiler.h>
27 #include <linux/errno.h>
30 #include <linux/device.h>
47 static inline const char *pci_slot_name(
const struct pci_slot *
slot)
49 return kobject_name(&slot->
kobj);
59 #define PCI_DMA_BIDIRECTIONAL 0
60 #define PCI_DMA_TODEVICE 1
61 #define PCI_DMA_FROMDEVICE 2
62 #define PCI_DMA_NONE 3
82 #define PCI_BRIDGE_RESOURCE_NUM 4
97 #define PCI_D0 ((pci_power_t __force) 0)
98 #define PCI_D1 ((pci_power_t __force) 1)
99 #define PCI_D2 ((pci_power_t __force) 2)
100 #define PCI_D3hot ((pci_power_t __force) 3)
101 #define PCI_D3cold ((pci_power_t __force) 4)
102 #define PCI_UNKNOWN ((pci_power_t __force) 5)
103 #define PCI_POWER_ERROR ((pci_power_t __force) -1)
113 #define PCI_PM_D2_DELAY 200
114 #define PCI_PM_D3_WAIT 10
115 #define PCI_PM_D3COLD_WAIT 100
116 #define PCI_PM_BUS_WAIT 50
273 #ifdef CONFIG_PCIEASPM
324 #ifdef CONFIG_PCI_MSI
326 struct kset *msi_kset;
329 #ifdef CONFIG_PCI_ATS
340 #ifdef CONFIG_PCI_IOV
350 #define to_pci_dev(n) container_of(n, struct pci_dev, dev)
351 #define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
353 static inline int pci_channel_offline(
struct pci_dev *pdev)
374 #define to_pci_host_bridge(n) container_of(n, struct pci_host_bridge, dev)
392 #define PCI_SUBTRACTIVE_DECODE 0x1
400 #define PCI_REGION_FLAG_MASK 0x0fU
433 #define pci_bus_b(n) list_entry(n, struct pci_bus, node)
434 #define to_pci_bus(n) container_of(n, struct pci_bus, dev)
440 static inline bool pci_is_root_bus(
struct pci_bus *pbus)
445 #ifdef CONFIG_PCI_MSI
451 static inline bool pci_dev_msi_enabled(
struct pci_dev *
pci_dev) {
return false; }
457 #define PCIBIOS_SUCCESSFUL 0x00
458 #define PCIBIOS_FUNC_NOT_SUPPORTED 0x81
459 #define PCIBIOS_BAD_VENDOR_ID 0x83
460 #define PCIBIOS_DEVICE_NOT_FOUND 0x86
461 #define PCIBIOS_BAD_REGISTER_NUMBER 0x87
462 #define PCIBIOS_SET_FAILED 0x88
463 #define PCIBIOS_BUFFER_TOO_SMALL 0x89
468 static inline int pcibios_err_to_errno(
int err)
581 #define to_pci_driver(drv) container_of(drv, struct pci_driver, driver)
590 #define DEFINE_PCI_DEVICE_TABLE(_table) \
591 const struct pci_device_id _table[] __devinitconst
602 #define PCI_DEVICE(vend,dev) \
603 .vendor = (vend), .device = (dev), \
604 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
615 #define PCI_DEVICE_CLASS(dev_class,dev_class_mask) \
616 .class = (dev_class), .class_mask = (dev_class_mask), \
617 .vendor = PCI_ANY_ID, .device = PCI_ANY_ID, \
618 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
631 #define PCI_VDEVICE(vendor, device) \
632 PCI_VENDOR_ID_##vendor, (device), \
633 PCI_ANY_ID, PCI_ANY_ID, 0, 0
640 enum pcie_bus_config_types {
643 PCIE_BUS_PERFORMANCE,
717 #define dev_is_pci(d) ((d)->bus == &pci_bus_type)
718 #define dev_is_pf(d) ((dev_is_pci(d) ? to_pci_dev(d)->is_physfn : false))
719 #define dev_num_vf(d) ((dev_is_pci(d) ? pci_num_vf(to_pci_dev(d)) : 0))
723 enum pci_lost_interrupt_reason {
724 PCI_LOST_IRQ_NO_INFORMATION = 0,
725 PCI_LOST_IRQ_DISABLE_MSI,
726 PCI_LOST_IRQ_DISABLE_MSIX,
727 PCI_LOST_IRQ_DISABLE_ACPI,
741 unsigned int ss_vendor,
unsigned int ss_device,
764 int pci_bus_write_config_dword(
struct pci_bus *
bus,
unsigned int devfn,
768 static inline int pci_read_config_byte(
const struct pci_dev *dev,
int where,
u8 *
val)
770 return pci_bus_read_config_byte(dev->
bus, dev->
devfn, where, val);
772 static inline int pci_read_config_word(
const struct pci_dev *dev,
int where,
u16 *
val)
774 return pci_bus_read_config_word(dev->
bus, dev->
devfn, where, val);
776 static inline int pci_read_config_dword(
const struct pci_dev *dev,
int where,
779 return pci_bus_read_config_dword(dev->
bus, dev->
devfn, where, val);
781 static inline int pci_write_config_byte(
const struct pci_dev *dev,
int where,
u8 val)
783 return pci_bus_write_config_byte(dev->
bus, dev->
devfn, where, val);
785 static inline int pci_write_config_word(
const struct pci_dev *dev,
int where,
u16 val)
787 return pci_bus_write_config_word(dev->
bus, dev->
devfn, where, val);
789 static inline int pci_write_config_dword(
const struct pci_dev *dev,
int where,
792 return pci_bus_write_config_dword(dev->
bus, dev->
devfn, where, val);
804 static inline int pcie_capability_set_word(
struct pci_dev *dev,
int pos,
810 static inline int pcie_capability_set_dword(
struct pci_dev *dev,
int pos,
816 static inline int pcie_capability_clear_word(
struct pci_dev *dev,
int pos,
822 static inline int pcie_capability_clear_dword(
struct pci_dev *dev,
int pos,
829 int pci_user_read_config_byte(
struct pci_dev *dev,
int where,
u8 *
val);
830 int pci_user_read_config_word(
struct pci_dev *dev,
int where,
u16 *
val);
831 int pci_user_read_config_dword(
struct pci_dev *dev,
int where,
u32 *
val);
832 int pci_user_write_config_byte(
struct pci_dev *dev,
int where,
u8 val);
833 int pci_user_write_config_word(
struct pci_dev *dev,
int where,
u16 val);
834 int pci_user_write_config_dword(
struct pci_dev *dev,
int where,
u32 val);
843 static inline int pci_is_enabled(
struct pci_dev *pdev)
848 static inline int pci_is_managed(
struct pci_dev *pdev)
861 #define HAVE_PCI_SET_MWI
907 bool runtime,
bool enable);
922 #define PCI_EXP_IDO_REQUEST (1<<0)
923 #define PCI_EXP_IDO_COMPLETION (1<<1)
927 enum pci_obff_signal_type {
928 PCI_EXP_OBFF_SIGNAL_L0 = 0,
929 PCI_EXP_OBFF_SIGNAL_ALWAYS = 1,
944 #ifdef CONFIG_HOTPLUG
945 unsigned int pci_rescan_bus_bridge_resize(
struct pci_dev *bridge);
946 unsigned int pci_rescan_bus(
struct pci_bus *
bus);
961 void pdev_enable_device(
struct pci_dev *);
965 #define HAVE_PCI_REQ_REGIONS 2
985 #define pci_bus_for_each_resource(bus, res, i) \
987 (res = pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \
1003 const char *mod_name);
1008 #define pci_register_driver(driver) \
1009 __pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
1021 #define module_pci_driver(__pci_driver) \
1022 module_driver(__pci_driver, pci_register_driver, \
1023 pci_unregister_driver)
1029 unsigned int class,
unsigned int class_mask,
1043 unsigned long type);
1045 #define PCI_VGA_STATE_CHANGE_BRIDGE (1 << 0)
1046 #define PCI_VGA_STATE_CHANGE_DECODES (1 << 1)
1049 unsigned int command_bits,
u32 flags);
1055 #define pci_pool dma_pool
1056 #define pci_pool_create(name, pdev, size, align, allocation) \
1057 dma_pool_create(name, &pdev->dev, size, align, allocation)
1058 #define pci_pool_destroy(pool) dma_pool_destroy(pool)
1059 #define pci_pool_alloc(pool, flags, handle) dma_pool_alloc(pool, flags, handle)
1060 #define pci_pool_free(pool, vaddr, addr) dma_pool_free(pool, vaddr, addr)
1062 enum pci_dma_burst_strategy {
1063 PCI_DMA_BURST_INFINITY,
1065 PCI_DMA_BURST_BOUNDARY,
1067 PCI_DMA_BURST_MULTIPLE,
1077 #ifndef CONFIG_PCI_MSI
1093 struct msix_entry *
entries,
int nvec)
1118 struct msix_entry *
entries,
int nvec);
1126 #ifdef CONFIG_PCIEPORTBUS
1130 #define pcie_ports_disabled true
1131 #define pcie_ports_auto false
1134 #ifndef CONFIG_PCIEASPM
1142 #ifdef CONFIG_PCIEAER
1150 #ifndef CONFIG_PCIE_ECRC
1161 #define pci_enable_msi(pdev) pci_enable_msi_block(pdev, 1)
1163 #ifdef CONFIG_HT_IRQ
1178 #ifdef CONFIG_PCI_DOMAINS
1179 extern int pci_domains_supported;
1181 enum { pci_domains_supported = 0 };
1194 typedef int (*arch_set_vga_state_t)(
struct pci_dev *pdev,
bool decode,
1195 unsigned int command_bits,
u32 flags);
1205 #define _PCI_NOP(o, s, t) \
1206 static inline int pci_##o##_config_##s(struct pci_dev *dev, \
1208 { return PCIBIOS_FUNC_NOT_SUPPORTED; }
1210 #define _PCI_NOP_ALL(o, x) _PCI_NOP(o, byte, u8 x) \
1211 _PCI_NOP(o, word, u16 x) \
1212 _PCI_NOP(o, dword, u32 x)
1225 unsigned int ss_vendor,
1226 unsigned int ss_device,
1238 #define pci_dev_present(ids) (0)
1239 #define no_pci_devices() (1)
1240 #define pci_dev_put(dev) do { } while (0)
1253 static inline int pci_set_dma_mask(
struct pci_dev *dev,
u64 mask)
1258 static inline int pci_set_consistent_dma_mask(
struct pci_dev *dev,
u64 mask)
1286 static inline int pci_register_driver(
struct pci_driver *drv)
1366 #define pci_dma_burst_advice(pdev, strat, strategy_parameter) do { } while (0)
1368 static inline void pci_block_cfg_access(
struct pci_dev *dev)
1371 static inline int pci_block_cfg_access_in_atomic(
struct pci_dev *dev)
1374 static inline void pci_unblock_cfg_access(
struct pci_dev *dev)
1394 #define dev_is_pci(d) (false)
1395 #define dev_is_pf(d) (false)
1396 #define dev_num_vf(d) (0)
1401 #include <asm/pci.h>
1403 #ifndef PCIBIOS_MAX_MEM_32
1404 #define PCIBIOS_MAX_MEM_32 (-1)
1409 #define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
1410 #define pci_resource_end(dev, bar) ((dev)->resource[(bar)].end)
1411 #define pci_resource_flags(dev, bar) ((dev)->resource[(bar)].flags)
1412 #define pci_resource_len(dev,bar) \
1413 ((pci_resource_start((dev), (bar)) == 0 && \
1414 pci_resource_end((dev), (bar)) == \
1415 pci_resource_start((dev), (bar))) ? 0 : \
1417 (pci_resource_end((dev), (bar)) - \
1418 pci_resource_start((dev), (bar)) + 1))
1424 static inline void *pci_get_drvdata(
struct pci_dev *pdev)
1429 static inline void pci_set_drvdata(
struct pci_dev *pdev,
void *
data)
1437 static inline const char *pci_name(
const struct pci_dev *pdev)
1439 return dev_name(&pdev->
dev);
1446 #ifndef HAVE_ARCH_PCI_RESOURCE_TO_USER
1451 *start = rsrc->
start;
1483 #define DECLARE_PCI_FIXUP_SECTION(section, name, vendor, device, class, \
1484 class_shift, hook) \
1485 static const struct pci_fixup __pci_fixup_##name __used \
1486 __attribute__((__section__(#section), aligned((sizeof(void *))))) \
1487 = { vendor, device, class, class_shift, hook };
1489 #define DECLARE_PCI_FIXUP_CLASS_EARLY(vendor, device, class, \
1490 class_shift, hook) \
1491 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_early, \
1492 vendor##device##hook, vendor, device, class, class_shift, hook)
1493 #define DECLARE_PCI_FIXUP_CLASS_HEADER(vendor, device, class, \
1494 class_shift, hook) \
1495 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_header, \
1496 vendor##device##hook, vendor, device, class, class_shift, hook)
1497 #define DECLARE_PCI_FIXUP_CLASS_FINAL(vendor, device, class, \
1498 class_shift, hook) \
1499 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_final, \
1500 vendor##device##hook, vendor, device, class, class_shift, hook)
1501 #define DECLARE_PCI_FIXUP_CLASS_ENABLE(vendor, device, class, \
1502 class_shift, hook) \
1503 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_enable, \
1504 vendor##device##hook, vendor, device, class, class_shift, hook)
1505 #define DECLARE_PCI_FIXUP_CLASS_RESUME(vendor, device, class, \
1506 class_shift, hook) \
1507 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume, \
1508 resume##vendor##device##hook, vendor, device, class, \
1510 #define DECLARE_PCI_FIXUP_CLASS_RESUME_EARLY(vendor, device, class, \
1511 class_shift, hook) \
1512 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume_early, \
1513 resume_early##vendor##device##hook, vendor, device, \
1514 class, class_shift, hook)
1515 #define DECLARE_PCI_FIXUP_CLASS_SUSPEND(vendor, device, class, \
1516 class_shift, hook) \
1517 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend, \
1518 suspend##vendor##device##hook, vendor, device, class, \
1521 #define DECLARE_PCI_FIXUP_EARLY(vendor, device, hook) \
1522 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_early, \
1523 vendor##device##hook, vendor, device, PCI_ANY_ID, 0, hook)
1524 #define DECLARE_PCI_FIXUP_HEADER(vendor, device, hook) \
1525 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_header, \
1526 vendor##device##hook, vendor, device, PCI_ANY_ID, 0, hook)
1527 #define DECLARE_PCI_FIXUP_FINAL(vendor, device, hook) \
1528 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_final, \
1529 vendor##device##hook, vendor, device, PCI_ANY_ID, 0, hook)
1530 #define DECLARE_PCI_FIXUP_ENABLE(vendor, device, hook) \
1531 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_enable, \
1532 vendor##device##hook, vendor, device, PCI_ANY_ID, 0, hook)
1533 #define DECLARE_PCI_FIXUP_RESUME(vendor, device, hook) \
1534 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume, \
1535 resume##vendor##device##hook, vendor, device, \
1536 PCI_ANY_ID, 0, hook)
1537 #define DECLARE_PCI_FIXUP_RESUME_EARLY(vendor, device, hook) \
1538 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume_early, \
1539 resume_early##vendor##device##hook, vendor, device, \
1540 PCI_ANY_ID, 0, hook)
1541 #define DECLARE_PCI_FIXUP_SUSPEND(vendor, device, hook) \
1542 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend, \
1543 suspend##vendor##device##hook, vendor, device, \
1544 PCI_ANY_ID, 0, hook)
1546 #ifdef CONFIG_PCI_QUIRKS
1573 #define PCIPCI_FAIL 1
1574 #define PCIPCI_TRITON 2
1575 #define PCIPCI_NATOMA 4
1576 #define PCIPCI_VIAETBF 8
1577 #define PCIPCI_VSFX 16
1578 #define PCIPCI_ALIMAGIK 32
1579 #define PCIAGP_FAIL 64
1596 #ifdef CONFIG_PCI_MMCONFIG
1608 #ifdef CONFIG_PCI_IOV
1631 #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
1647 static inline int pci_pcie_cap(
struct pci_dev *dev)
1658 static inline bool pci_is_pcie(
struct pci_dev *dev)
1660 return !!pci_pcie_cap(dev);
1667 static inline int pci_pcie_type(
const struct pci_dev *dev)
1677 #define PCI_VPD_LRDT 0x80
1678 #define PCI_VPD_LRDT_ID(x) (x | PCI_VPD_LRDT)
1681 #define PCI_VPD_LTIN_ID_STRING 0x02
1682 #define PCI_VPD_LTIN_RO_DATA 0x10
1683 #define PCI_VPD_LTIN_RW_DATA 0x11
1685 #define PCI_VPD_LRDT_ID_STRING PCI_VPD_LRDT_ID(PCI_VPD_LTIN_ID_STRING)
1686 #define PCI_VPD_LRDT_RO_DATA PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RO_DATA)
1687 #define PCI_VPD_LRDT_RW_DATA PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RW_DATA)
1690 #define PCI_VPD_STIN_END 0x78
1692 #define PCI_VPD_SRDT_END PCI_VPD_STIN_END
1694 #define PCI_VPD_SRDT_TIN_MASK 0x78
1695 #define PCI_VPD_SRDT_LEN_MASK 0x07
1697 #define PCI_VPD_LRDT_TAG_SIZE 3
1698 #define PCI_VPD_SRDT_TAG_SIZE 1
1700 #define PCI_VPD_INFO_FLD_HDR_SIZE 3
1702 #define PCI_VPD_RO_KEYWORD_PARTNO "PN"
1703 #define PCI_VPD_RO_KEYWORD_MFR_ID "MN"
1704 #define PCI_VPD_RO_KEYWORD_VENDOR0 "V0"
1705 #define PCI_VPD_RO_KEYWORD_CHKSUM "RV"
1713 static inline u16 pci_vpd_lrdt_size(
const u8 *lrdt)
1715 return (
u16)lrdt[1] + ((
u16)lrdt[2] << 8);
1724 static inline u8 pci_vpd_srdt_size(
const u8 *srdt)
1735 static inline u8 pci_vpd_info_field_size(
const u8 *info_field)
1737 return info_field[2];
1763 unsigned int len,
const char *kw);
1777 pci_device_to_OF_node(
const struct pci_dev *pdev)
1779 return pdev ? pdev->
dev.of_node :
NULL;
1784 return bus ? bus->
dev.of_node :
NULL;
1795 static inline struct eeh_dev *pci_dev_to_eeh_dev(
struct pci_dev *pdev)
1797 return pdev->
dev.archdata.edev;