18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef DRIVERS_PCI_H 38c2ecf20Sopenharmony_ci#define DRIVERS_PCI_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/pci.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci/* Number of possible devfns: 0.0 to 1f.7 inclusive */ 88c2ecf20Sopenharmony_ci#define MAX_NR_DEVFNS 256 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#define PCI_FIND_CAP_TTL 48 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ciextern const unsigned char pcie_link_speed[]; 158c2ecf20Sopenharmony_ciextern bool pci_early_dump; 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cibool pcie_cap_has_lnkctl(const struct pci_dev *dev); 188c2ecf20Sopenharmony_cibool pcie_cap_has_rtctl(const struct pci_dev *dev); 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/* Functions internal to the PCI core code */ 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ciint pci_create_sysfs_dev_files(struct pci_dev *pdev); 238c2ecf20Sopenharmony_civoid pci_remove_sysfs_dev_files(struct pci_dev *pdev); 248c2ecf20Sopenharmony_ci#if !defined(CONFIG_DMI) && !defined(CONFIG_ACPI) 258c2ecf20Sopenharmony_cistatic inline void pci_create_firmware_label_files(struct pci_dev *pdev) 268c2ecf20Sopenharmony_ci{ return; } 278c2ecf20Sopenharmony_cistatic inline void pci_remove_firmware_label_files(struct pci_dev *pdev) 288c2ecf20Sopenharmony_ci{ return; } 298c2ecf20Sopenharmony_ci#else 308c2ecf20Sopenharmony_civoid pci_create_firmware_label_files(struct pci_dev *pdev); 318c2ecf20Sopenharmony_civoid pci_remove_firmware_label_files(struct pci_dev *pdev); 328c2ecf20Sopenharmony_ci#endif 338c2ecf20Sopenharmony_civoid pci_cleanup_rom(struct pci_dev *dev); 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cienum pci_mmap_api { 368c2ecf20Sopenharmony_ci PCI_MMAP_SYSFS, /* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */ 378c2ecf20Sopenharmony_ci PCI_MMAP_PROCFS /* mmap on /proc/bus/pci/<BDF> */ 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ciint pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai, 408c2ecf20Sopenharmony_ci enum pci_mmap_api mmap_api); 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ciint pci_probe_reset_function(struct pci_dev *dev); 438c2ecf20Sopenharmony_ciint pci_bridge_secondary_bus_reset(struct pci_dev *dev); 448c2ecf20Sopenharmony_ciint pci_bus_error_reset(struct pci_dev *dev); 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define PCI_PM_D2_DELAY 200 /* usec; see PCIe r4.0, sec 5.9.1 */ 478c2ecf20Sopenharmony_ci#define PCI_PM_D3HOT_WAIT 10 /* msec */ 488c2ecf20Sopenharmony_ci#define PCI_PM_D3COLD_WAIT 100 /* msec */ 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* 518c2ecf20Sopenharmony_ci * Following exit from Conventional Reset, devices must be ready within 1 sec 528c2ecf20Sopenharmony_ci * (PCIe r6.0 sec 6.6.1). A D3cold to D0 transition implies a Conventional 538c2ecf20Sopenharmony_ci * Reset (PCIe r6.0 sec 5.8). 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_ci#define PCI_RESET_WAIT 1000 /* msec */ 568c2ecf20Sopenharmony_ci/* 578c2ecf20Sopenharmony_ci * Devices may extend the 1 sec period through Request Retry Status completions 588c2ecf20Sopenharmony_ci * (PCIe r6.0 sec 2.3.1). The spec does not provide an upper limit, but 60 sec 598c2ecf20Sopenharmony_ci * ought to be enough for any device to become responsive. 608c2ecf20Sopenharmony_ci */ 618c2ecf20Sopenharmony_ci#define PCIE_RESET_READY_POLL_MS 60000 /* msec */ 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/** 648c2ecf20Sopenharmony_ci * struct pci_platform_pm_ops - Firmware PM callbacks 658c2ecf20Sopenharmony_ci * 668c2ecf20Sopenharmony_ci * @bridge_d3: Does the bridge allow entering into D3 678c2ecf20Sopenharmony_ci * 688c2ecf20Sopenharmony_ci * @is_manageable: returns 'true' if given device is power manageable by the 698c2ecf20Sopenharmony_ci * platform firmware 708c2ecf20Sopenharmony_ci * 718c2ecf20Sopenharmony_ci * @set_state: invokes the platform firmware to set the device's power state 728c2ecf20Sopenharmony_ci * 738c2ecf20Sopenharmony_ci * @get_state: queries the platform firmware for a device's current power state 748c2ecf20Sopenharmony_ci * 758c2ecf20Sopenharmony_ci * @refresh_state: asks the platform to refresh the device's power state data 768c2ecf20Sopenharmony_ci * 778c2ecf20Sopenharmony_ci * @choose_state: returns PCI power state of given device preferred by the 788c2ecf20Sopenharmony_ci * platform; to be used during system-wide transitions from a 798c2ecf20Sopenharmony_ci * sleeping state to the working state and vice versa 808c2ecf20Sopenharmony_ci * 818c2ecf20Sopenharmony_ci * @set_wakeup: enables/disables wakeup capability for the device 828c2ecf20Sopenharmony_ci * 838c2ecf20Sopenharmony_ci * @need_resume: returns 'true' if the given device (which is currently 848c2ecf20Sopenharmony_ci * suspended) needs to be resumed to be configured for system 858c2ecf20Sopenharmony_ci * wakeup. 868c2ecf20Sopenharmony_ci * 878c2ecf20Sopenharmony_ci * If given platform is generally capable of power managing PCI devices, all of 888c2ecf20Sopenharmony_ci * these callbacks are mandatory. 898c2ecf20Sopenharmony_ci */ 908c2ecf20Sopenharmony_cistruct pci_platform_pm_ops { 918c2ecf20Sopenharmony_ci bool (*bridge_d3)(struct pci_dev *dev); 928c2ecf20Sopenharmony_ci bool (*is_manageable)(struct pci_dev *dev); 938c2ecf20Sopenharmony_ci int (*set_state)(struct pci_dev *dev, pci_power_t state); 948c2ecf20Sopenharmony_ci pci_power_t (*get_state)(struct pci_dev *dev); 958c2ecf20Sopenharmony_ci void (*refresh_state)(struct pci_dev *dev); 968c2ecf20Sopenharmony_ci pci_power_t (*choose_state)(struct pci_dev *dev); 978c2ecf20Sopenharmony_ci int (*set_wakeup)(struct pci_dev *dev, bool enable); 988c2ecf20Sopenharmony_ci bool (*need_resume)(struct pci_dev *dev); 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ciint pci_set_platform_pm(const struct pci_platform_pm_ops *ops); 1028c2ecf20Sopenharmony_civoid pci_update_current_state(struct pci_dev *dev, pci_power_t state); 1038c2ecf20Sopenharmony_civoid pci_refresh_power_state(struct pci_dev *dev); 1048c2ecf20Sopenharmony_ciint pci_power_up(struct pci_dev *dev); 1058c2ecf20Sopenharmony_civoid pci_disable_enabled_device(struct pci_dev *dev); 1068c2ecf20Sopenharmony_ciint pci_finish_runtime_suspend(struct pci_dev *dev); 1078c2ecf20Sopenharmony_civoid pcie_clear_device_status(struct pci_dev *dev); 1088c2ecf20Sopenharmony_civoid pcie_clear_root_pme_status(struct pci_dev *dev); 1098c2ecf20Sopenharmony_cibool pci_check_pme_status(struct pci_dev *dev); 1108c2ecf20Sopenharmony_civoid pci_pme_wakeup_bus(struct pci_bus *bus); 1118c2ecf20Sopenharmony_ciint __pci_pme_wakeup(struct pci_dev *dev, void *ign); 1128c2ecf20Sopenharmony_civoid pci_pme_restore(struct pci_dev *dev); 1138c2ecf20Sopenharmony_cibool pci_dev_need_resume(struct pci_dev *dev); 1148c2ecf20Sopenharmony_civoid pci_dev_adjust_pme(struct pci_dev *dev); 1158c2ecf20Sopenharmony_civoid pci_dev_complete_resume(struct pci_dev *pci_dev); 1168c2ecf20Sopenharmony_civoid pci_config_pm_runtime_get(struct pci_dev *dev); 1178c2ecf20Sopenharmony_civoid pci_config_pm_runtime_put(struct pci_dev *dev); 1188c2ecf20Sopenharmony_civoid pci_pm_init(struct pci_dev *dev); 1198c2ecf20Sopenharmony_civoid pci_ea_init(struct pci_dev *dev); 1208c2ecf20Sopenharmony_civoid pci_allocate_cap_save_buffers(struct pci_dev *dev); 1218c2ecf20Sopenharmony_civoid pci_free_cap_save_buffers(struct pci_dev *dev); 1228c2ecf20Sopenharmony_cibool pci_bridge_d3_possible(struct pci_dev *dev); 1238c2ecf20Sopenharmony_civoid pci_bridge_d3_update(struct pci_dev *dev); 1248c2ecf20Sopenharmony_ciint pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type, 1258c2ecf20Sopenharmony_ci int timeout); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistatic inline void pci_wakeup_event(struct pci_dev *dev) 1288c2ecf20Sopenharmony_ci{ 1298c2ecf20Sopenharmony_ci /* Wait 100 ms before the system can be put into a sleep state. */ 1308c2ecf20Sopenharmony_ci pm_wakeup_event(&dev->dev, 100); 1318c2ecf20Sopenharmony_ci} 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_cistatic inline bool pci_has_subordinate(struct pci_dev *pci_dev) 1348c2ecf20Sopenharmony_ci{ 1358c2ecf20Sopenharmony_ci return !!(pci_dev->subordinate); 1368c2ecf20Sopenharmony_ci} 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_cistatic inline bool pci_power_manageable(struct pci_dev *pci_dev) 1398c2ecf20Sopenharmony_ci{ 1408c2ecf20Sopenharmony_ci /* 1418c2ecf20Sopenharmony_ci * Currently we allow normal PCI devices and PCI bridges transition 1428c2ecf20Sopenharmony_ci * into D3 if their bridge_d3 is set. 1438c2ecf20Sopenharmony_ci */ 1448c2ecf20Sopenharmony_ci return !pci_has_subordinate(pci_dev) || pci_dev->bridge_d3; 1458c2ecf20Sopenharmony_ci} 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_cistatic inline bool pcie_downstream_port(const struct pci_dev *dev) 1488c2ecf20Sopenharmony_ci{ 1498c2ecf20Sopenharmony_ci int type = pci_pcie_type(dev); 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci return type == PCI_EXP_TYPE_ROOT_PORT || 1528c2ecf20Sopenharmony_ci type == PCI_EXP_TYPE_DOWNSTREAM || 1538c2ecf20Sopenharmony_ci type == PCI_EXP_TYPE_PCIE_BRIDGE; 1548c2ecf20Sopenharmony_ci} 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ciint pci_vpd_init(struct pci_dev *dev); 1578c2ecf20Sopenharmony_civoid pci_vpd_release(struct pci_dev *dev); 1588c2ecf20Sopenharmony_civoid pcie_vpd_create_sysfs_dev_files(struct pci_dev *dev); 1598c2ecf20Sopenharmony_civoid pcie_vpd_remove_sysfs_dev_files(struct pci_dev *dev); 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci/* PCI Virtual Channel */ 1628c2ecf20Sopenharmony_ciint pci_save_vc_state(struct pci_dev *dev); 1638c2ecf20Sopenharmony_civoid pci_restore_vc_state(struct pci_dev *dev); 1648c2ecf20Sopenharmony_civoid pci_allocate_vc_save_buffers(struct pci_dev *dev); 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci/* PCI /proc functions */ 1678c2ecf20Sopenharmony_ci#ifdef CONFIG_PROC_FS 1688c2ecf20Sopenharmony_ciint pci_proc_attach_device(struct pci_dev *dev); 1698c2ecf20Sopenharmony_ciint pci_proc_detach_device(struct pci_dev *dev); 1708c2ecf20Sopenharmony_ciint pci_proc_detach_bus(struct pci_bus *bus); 1718c2ecf20Sopenharmony_ci#else 1728c2ecf20Sopenharmony_cistatic inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; } 1738c2ecf20Sopenharmony_cistatic inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; } 1748c2ecf20Sopenharmony_cistatic inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; } 1758c2ecf20Sopenharmony_ci#endif 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci/* Functions for PCI Hotplug drivers to use */ 1788c2ecf20Sopenharmony_ciint pci_hp_add_bridge(struct pci_dev *dev); 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci#ifdef HAVE_PCI_LEGACY 1818c2ecf20Sopenharmony_civoid pci_create_legacy_files(struct pci_bus *bus); 1828c2ecf20Sopenharmony_civoid pci_remove_legacy_files(struct pci_bus *bus); 1838c2ecf20Sopenharmony_ci#else 1848c2ecf20Sopenharmony_cistatic inline void pci_create_legacy_files(struct pci_bus *bus) { return; } 1858c2ecf20Sopenharmony_cistatic inline void pci_remove_legacy_files(struct pci_bus *bus) { return; } 1868c2ecf20Sopenharmony_ci#endif 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci/* Lock for read/write access to pci device and bus lists */ 1898c2ecf20Sopenharmony_ciextern struct rw_semaphore pci_bus_sem; 1908c2ecf20Sopenharmony_ciextern struct mutex pci_slot_mutex; 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ciextern raw_spinlock_t pci_lock; 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ciextern unsigned int pci_pm_d3hot_delay; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI_MSI 1978c2ecf20Sopenharmony_civoid pci_no_msi(void); 1988c2ecf20Sopenharmony_ci#else 1998c2ecf20Sopenharmony_cistatic inline void pci_no_msi(void) { } 2008c2ecf20Sopenharmony_ci#endif 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_cistatic inline void pci_msi_set_enable(struct pci_dev *dev, int enable) 2038c2ecf20Sopenharmony_ci{ 2048c2ecf20Sopenharmony_ci u16 control; 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control); 2078c2ecf20Sopenharmony_ci control &= ~PCI_MSI_FLAGS_ENABLE; 2088c2ecf20Sopenharmony_ci if (enable) 2098c2ecf20Sopenharmony_ci control |= PCI_MSI_FLAGS_ENABLE; 2108c2ecf20Sopenharmony_ci pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control); 2118c2ecf20Sopenharmony_ci} 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_cistatic inline void pci_msix_clear_and_set_ctrl(struct pci_dev *dev, u16 clear, u16 set) 2148c2ecf20Sopenharmony_ci{ 2158c2ecf20Sopenharmony_ci u16 ctrl; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &ctrl); 2188c2ecf20Sopenharmony_ci ctrl &= ~clear; 2198c2ecf20Sopenharmony_ci ctrl |= set; 2208c2ecf20Sopenharmony_ci pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, ctrl); 2218c2ecf20Sopenharmony_ci} 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_civoid pci_realloc_get_opt(char *); 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_cistatic inline int pci_no_d1d2(struct pci_dev *dev) 2268c2ecf20Sopenharmony_ci{ 2278c2ecf20Sopenharmony_ci unsigned int parent_dstates = 0; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci if (dev->bus->self) 2308c2ecf20Sopenharmony_ci parent_dstates = dev->bus->self->no_d1d2; 2318c2ecf20Sopenharmony_ci return (dev->no_d1d2 || parent_dstates); 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci} 2348c2ecf20Sopenharmony_ciextern const struct attribute_group *pci_dev_groups[]; 2358c2ecf20Sopenharmony_ciextern const struct attribute_group *pcibus_groups[]; 2368c2ecf20Sopenharmony_ciextern const struct device_type pci_dev_type; 2378c2ecf20Sopenharmony_ciextern const struct attribute_group *pci_bus_groups[]; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ciextern unsigned long pci_hotplug_io_size; 2408c2ecf20Sopenharmony_ciextern unsigned long pci_hotplug_mmio_size; 2418c2ecf20Sopenharmony_ciextern unsigned long pci_hotplug_mmio_pref_size; 2428c2ecf20Sopenharmony_ciextern unsigned long pci_hotplug_bus_size; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci/** 2458c2ecf20Sopenharmony_ci * pci_match_one_device - Tell if a PCI device structure has a matching 2468c2ecf20Sopenharmony_ci * PCI device id structure 2478c2ecf20Sopenharmony_ci * @id: single PCI device id structure to match 2488c2ecf20Sopenharmony_ci * @dev: the PCI device structure to match against 2498c2ecf20Sopenharmony_ci * 2508c2ecf20Sopenharmony_ci * Returns the matching pci_device_id structure or %NULL if there is no match. 2518c2ecf20Sopenharmony_ci */ 2528c2ecf20Sopenharmony_cistatic inline const struct pci_device_id * 2538c2ecf20Sopenharmony_cipci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev) 2548c2ecf20Sopenharmony_ci{ 2558c2ecf20Sopenharmony_ci if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) && 2568c2ecf20Sopenharmony_ci (id->device == PCI_ANY_ID || id->device == dev->device) && 2578c2ecf20Sopenharmony_ci (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) && 2588c2ecf20Sopenharmony_ci (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) && 2598c2ecf20Sopenharmony_ci !((id->class ^ dev->class) & id->class_mask)) 2608c2ecf20Sopenharmony_ci return id; 2618c2ecf20Sopenharmony_ci return NULL; 2628c2ecf20Sopenharmony_ci} 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci/* PCI slot sysfs helper code */ 2658c2ecf20Sopenharmony_ci#define to_pci_slot(s) container_of(s, struct pci_slot, kobj) 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ciextern struct kset *pci_slots_kset; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_cistruct pci_slot_attribute { 2708c2ecf20Sopenharmony_ci struct attribute attr; 2718c2ecf20Sopenharmony_ci ssize_t (*show)(struct pci_slot *, char *); 2728c2ecf20Sopenharmony_ci ssize_t (*store)(struct pci_slot *, const char *, size_t); 2738c2ecf20Sopenharmony_ci}; 2748c2ecf20Sopenharmony_ci#define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr) 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_cienum pci_bar_type { 2778c2ecf20Sopenharmony_ci pci_bar_unknown, /* Standard PCI BAR probe */ 2788c2ecf20Sopenharmony_ci pci_bar_io, /* An I/O port BAR */ 2798c2ecf20Sopenharmony_ci pci_bar_mem32, /* A 32-bit memory BAR */ 2808c2ecf20Sopenharmony_ci pci_bar_mem64, /* A 64-bit memory BAR */ 2818c2ecf20Sopenharmony_ci}; 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_cistruct device *pci_get_host_bridge_device(struct pci_dev *dev); 2848c2ecf20Sopenharmony_civoid pci_put_host_bridge_device(struct device *dev); 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ciint pci_configure_extended_tags(struct pci_dev *dev, void *ign); 2878c2ecf20Sopenharmony_cibool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl, 2888c2ecf20Sopenharmony_ci int crs_timeout); 2898c2ecf20Sopenharmony_cibool pci_bus_generic_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl, 2908c2ecf20Sopenharmony_ci int crs_timeout); 2918c2ecf20Sopenharmony_ciint pci_idt_bus_quirk(struct pci_bus *bus, int devfn, u32 *pl, int crs_timeout); 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ciint pci_setup_device(struct pci_dev *dev); 2948c2ecf20Sopenharmony_ciint __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, 2958c2ecf20Sopenharmony_ci struct resource *res, unsigned int reg); 2968c2ecf20Sopenharmony_civoid pci_configure_ari(struct pci_dev *dev); 2978c2ecf20Sopenharmony_civoid __pci_bus_size_bridges(struct pci_bus *bus, 2988c2ecf20Sopenharmony_ci struct list_head *realloc_head); 2998c2ecf20Sopenharmony_civoid __pci_bus_assign_resources(const struct pci_bus *bus, 3008c2ecf20Sopenharmony_ci struct list_head *realloc_head, 3018c2ecf20Sopenharmony_ci struct list_head *fail_head); 3028c2ecf20Sopenharmony_cibool pci_bus_clip_resource(struct pci_dev *dev, int idx); 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_civoid pci_reassigndev_resource_alignment(struct pci_dev *dev); 3058c2ecf20Sopenharmony_civoid pci_disable_bridge_window(struct pci_dev *dev); 3068c2ecf20Sopenharmony_cistruct pci_bus *pci_bus_get(struct pci_bus *bus); 3078c2ecf20Sopenharmony_civoid pci_bus_put(struct pci_bus *bus); 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci/* PCIe link information from Link Capabilities 2 */ 3108c2ecf20Sopenharmony_ci#define PCIE_LNKCAP2_SLS2SPEED(lnkcap2) \ 3118c2ecf20Sopenharmony_ci ((lnkcap2) & PCI_EXP_LNKCAP2_SLS_32_0GB ? PCIE_SPEED_32_0GT : \ 3128c2ecf20Sopenharmony_ci (lnkcap2) & PCI_EXP_LNKCAP2_SLS_16_0GB ? PCIE_SPEED_16_0GT : \ 3138c2ecf20Sopenharmony_ci (lnkcap2) & PCI_EXP_LNKCAP2_SLS_8_0GB ? PCIE_SPEED_8_0GT : \ 3148c2ecf20Sopenharmony_ci (lnkcap2) & PCI_EXP_LNKCAP2_SLS_5_0GB ? PCIE_SPEED_5_0GT : \ 3158c2ecf20Sopenharmony_ci (lnkcap2) & PCI_EXP_LNKCAP2_SLS_2_5GB ? PCIE_SPEED_2_5GT : \ 3168c2ecf20Sopenharmony_ci PCI_SPEED_UNKNOWN) 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci/* PCIe speed to Mb/s reduced by encoding overhead */ 3198c2ecf20Sopenharmony_ci#define PCIE_SPEED2MBS_ENC(speed) \ 3208c2ecf20Sopenharmony_ci ((speed) == PCIE_SPEED_32_0GT ? 32000*128/130 : \ 3218c2ecf20Sopenharmony_ci (speed) == PCIE_SPEED_16_0GT ? 16000*128/130 : \ 3228c2ecf20Sopenharmony_ci (speed) == PCIE_SPEED_8_0GT ? 8000*128/130 : \ 3238c2ecf20Sopenharmony_ci (speed) == PCIE_SPEED_5_0GT ? 5000*8/10 : \ 3248c2ecf20Sopenharmony_ci (speed) == PCIE_SPEED_2_5GT ? 2500*8/10 : \ 3258c2ecf20Sopenharmony_ci 0) 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ciconst char *pci_speed_string(enum pci_bus_speed speed); 3288c2ecf20Sopenharmony_cienum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev); 3298c2ecf20Sopenharmony_cienum pcie_link_width pcie_get_width_cap(struct pci_dev *dev); 3308c2ecf20Sopenharmony_ciu32 pcie_bandwidth_capable(struct pci_dev *dev, enum pci_bus_speed *speed, 3318c2ecf20Sopenharmony_ci enum pcie_link_width *width); 3328c2ecf20Sopenharmony_civoid __pcie_print_link_status(struct pci_dev *dev, bool verbose); 3338c2ecf20Sopenharmony_civoid pcie_report_downtraining(struct pci_dev *dev); 3348c2ecf20Sopenharmony_civoid pcie_update_link_speed(struct pci_bus *bus, u16 link_status); 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci/* Single Root I/O Virtualization */ 3378c2ecf20Sopenharmony_cistruct pci_sriov { 3388c2ecf20Sopenharmony_ci int pos; /* Capability position */ 3398c2ecf20Sopenharmony_ci int nres; /* Number of resources */ 3408c2ecf20Sopenharmony_ci u32 cap; /* SR-IOV Capabilities */ 3418c2ecf20Sopenharmony_ci u16 ctrl; /* SR-IOV Control */ 3428c2ecf20Sopenharmony_ci u16 total_VFs; /* Total VFs associated with the PF */ 3438c2ecf20Sopenharmony_ci u16 initial_VFs; /* Initial VFs associated with the PF */ 3448c2ecf20Sopenharmony_ci u16 num_VFs; /* Number of VFs available */ 3458c2ecf20Sopenharmony_ci u16 offset; /* First VF Routing ID offset */ 3468c2ecf20Sopenharmony_ci u16 stride; /* Following VF stride */ 3478c2ecf20Sopenharmony_ci u16 vf_device; /* VF device ID */ 3488c2ecf20Sopenharmony_ci u32 pgsz; /* Page size for BAR alignment */ 3498c2ecf20Sopenharmony_ci u8 link; /* Function Dependency Link */ 3508c2ecf20Sopenharmony_ci u8 max_VF_buses; /* Max buses consumed by VFs */ 3518c2ecf20Sopenharmony_ci u16 driver_max_VFs; /* Max num VFs driver supports */ 3528c2ecf20Sopenharmony_ci struct pci_dev *dev; /* Lowest numbered PF */ 3538c2ecf20Sopenharmony_ci struct pci_dev *self; /* This PF */ 3548c2ecf20Sopenharmony_ci u32 class; /* VF device */ 3558c2ecf20Sopenharmony_ci u8 hdr_type; /* VF header type */ 3568c2ecf20Sopenharmony_ci u16 subsystem_vendor; /* VF subsystem vendor */ 3578c2ecf20Sopenharmony_ci u16 subsystem_device; /* VF subsystem device */ 3588c2ecf20Sopenharmony_ci resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */ 3598c2ecf20Sopenharmony_ci bool drivers_autoprobe; /* Auto probing of VFs by driver */ 3608c2ecf20Sopenharmony_ci}; 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci/** 3638c2ecf20Sopenharmony_ci * pci_dev_set_io_state - Set the new error state if possible. 3648c2ecf20Sopenharmony_ci * 3658c2ecf20Sopenharmony_ci * @dev - pci device to set new error_state 3668c2ecf20Sopenharmony_ci * @new - the state we want dev to be in 3678c2ecf20Sopenharmony_ci * 3688c2ecf20Sopenharmony_ci * If the device is experiencing perm_failure, it has to remain in that state. 3698c2ecf20Sopenharmony_ci * Any other transition is allowed. 3708c2ecf20Sopenharmony_ci * 3718c2ecf20Sopenharmony_ci * Returns true if state has been changed to the requested state. 3728c2ecf20Sopenharmony_ci */ 3738c2ecf20Sopenharmony_cistatic inline bool pci_dev_set_io_state(struct pci_dev *dev, 3748c2ecf20Sopenharmony_ci pci_channel_state_t new) 3758c2ecf20Sopenharmony_ci{ 3768c2ecf20Sopenharmony_ci pci_channel_state_t old; 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci switch (new) { 3798c2ecf20Sopenharmony_ci case pci_channel_io_perm_failure: 3808c2ecf20Sopenharmony_ci xchg(&dev->error_state, pci_channel_io_perm_failure); 3818c2ecf20Sopenharmony_ci return true; 3828c2ecf20Sopenharmony_ci case pci_channel_io_frozen: 3838c2ecf20Sopenharmony_ci old = cmpxchg(&dev->error_state, pci_channel_io_normal, 3848c2ecf20Sopenharmony_ci pci_channel_io_frozen); 3858c2ecf20Sopenharmony_ci return old != pci_channel_io_perm_failure; 3868c2ecf20Sopenharmony_ci case pci_channel_io_normal: 3878c2ecf20Sopenharmony_ci old = cmpxchg(&dev->error_state, pci_channel_io_frozen, 3888c2ecf20Sopenharmony_ci pci_channel_io_normal); 3898c2ecf20Sopenharmony_ci return old != pci_channel_io_perm_failure; 3908c2ecf20Sopenharmony_ci default: 3918c2ecf20Sopenharmony_ci return false; 3928c2ecf20Sopenharmony_ci } 3938c2ecf20Sopenharmony_ci} 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_cistatic inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused) 3968c2ecf20Sopenharmony_ci{ 3978c2ecf20Sopenharmony_ci pci_dev_set_io_state(dev, pci_channel_io_perm_failure); 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci return 0; 4008c2ecf20Sopenharmony_ci} 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_cistatic inline bool pci_dev_is_disconnected(const struct pci_dev *dev) 4038c2ecf20Sopenharmony_ci{ 4048c2ecf20Sopenharmony_ci return dev->error_state == pci_channel_io_perm_failure; 4058c2ecf20Sopenharmony_ci} 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci/* pci_dev priv_flags */ 4088c2ecf20Sopenharmony_ci#define PCI_DEV_ADDED 0 4098c2ecf20Sopenharmony_ci#define PCI_DPC_RECOVERED 1 4108c2ecf20Sopenharmony_ci#define PCI_DPC_RECOVERING 2 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_cistatic inline void pci_dev_assign_added(struct pci_dev *dev, bool added) 4138c2ecf20Sopenharmony_ci{ 4148c2ecf20Sopenharmony_ci assign_bit(PCI_DEV_ADDED, &dev->priv_flags, added); 4158c2ecf20Sopenharmony_ci} 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_cistatic inline bool pci_dev_is_added(const struct pci_dev *dev) 4188c2ecf20Sopenharmony_ci{ 4198c2ecf20Sopenharmony_ci return test_bit(PCI_DEV_ADDED, &dev->priv_flags); 4208c2ecf20Sopenharmony_ci} 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci#ifdef CONFIG_PCIEAER 4238c2ecf20Sopenharmony_ci#include <linux/aer.h> 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci#define AER_MAX_MULTI_ERR_DEVICES 5 /* Not likely to have more */ 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_cistruct aer_err_info { 4288c2ecf20Sopenharmony_ci struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES]; 4298c2ecf20Sopenharmony_ci int error_dev_num; 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci unsigned int id:16; 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci unsigned int severity:2; /* 0:NONFATAL | 1:FATAL | 2:COR */ 4348c2ecf20Sopenharmony_ci unsigned int __pad1:5; 4358c2ecf20Sopenharmony_ci unsigned int multi_error_valid:1; 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci unsigned int first_error:5; 4388c2ecf20Sopenharmony_ci unsigned int __pad2:2; 4398c2ecf20Sopenharmony_ci unsigned int tlp_header_valid:1; 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci unsigned int status; /* COR/UNCOR Error Status */ 4428c2ecf20Sopenharmony_ci unsigned int mask; /* COR/UNCOR Error Mask */ 4438c2ecf20Sopenharmony_ci struct aer_header_log_regs tlp; /* TLP Header */ 4448c2ecf20Sopenharmony_ci}; 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ciint aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info); 4478c2ecf20Sopenharmony_civoid aer_print_error(struct pci_dev *dev, struct aer_err_info *info); 4488c2ecf20Sopenharmony_ci#endif /* CONFIG_PCIEAER */ 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci#ifdef CONFIG_PCIE_DPC 4518c2ecf20Sopenharmony_civoid pci_save_dpc_state(struct pci_dev *dev); 4528c2ecf20Sopenharmony_civoid pci_restore_dpc_state(struct pci_dev *dev); 4538c2ecf20Sopenharmony_civoid pci_dpc_init(struct pci_dev *pdev); 4548c2ecf20Sopenharmony_civoid dpc_process_error(struct pci_dev *pdev); 4558c2ecf20Sopenharmony_cipci_ers_result_t dpc_reset_link(struct pci_dev *pdev); 4568c2ecf20Sopenharmony_cibool pci_dpc_recovered(struct pci_dev *pdev); 4578c2ecf20Sopenharmony_ci#else 4588c2ecf20Sopenharmony_cistatic inline void pci_save_dpc_state(struct pci_dev *dev) {} 4598c2ecf20Sopenharmony_cistatic inline void pci_restore_dpc_state(struct pci_dev *dev) {} 4608c2ecf20Sopenharmony_cistatic inline void pci_dpc_init(struct pci_dev *pdev) {} 4618c2ecf20Sopenharmony_cistatic inline bool pci_dpc_recovered(struct pci_dev *pdev) { return false; } 4628c2ecf20Sopenharmony_ci#endif 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI_ATS 4658c2ecf20Sopenharmony_ci/* Address Translation Service */ 4668c2ecf20Sopenharmony_civoid pci_ats_init(struct pci_dev *dev); 4678c2ecf20Sopenharmony_civoid pci_restore_ats_state(struct pci_dev *dev); 4688c2ecf20Sopenharmony_ci#else 4698c2ecf20Sopenharmony_cistatic inline void pci_ats_init(struct pci_dev *d) { } 4708c2ecf20Sopenharmony_cistatic inline void pci_restore_ats_state(struct pci_dev *dev) { } 4718c2ecf20Sopenharmony_ci#endif /* CONFIG_PCI_ATS */ 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI_PRI 4748c2ecf20Sopenharmony_civoid pci_pri_init(struct pci_dev *dev); 4758c2ecf20Sopenharmony_civoid pci_restore_pri_state(struct pci_dev *pdev); 4768c2ecf20Sopenharmony_ci#else 4778c2ecf20Sopenharmony_cistatic inline void pci_pri_init(struct pci_dev *dev) { } 4788c2ecf20Sopenharmony_cistatic inline void pci_restore_pri_state(struct pci_dev *pdev) { } 4798c2ecf20Sopenharmony_ci#endif 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI_PASID 4828c2ecf20Sopenharmony_civoid pci_pasid_init(struct pci_dev *dev); 4838c2ecf20Sopenharmony_civoid pci_restore_pasid_state(struct pci_dev *pdev); 4848c2ecf20Sopenharmony_ci#else 4858c2ecf20Sopenharmony_cistatic inline void pci_pasid_init(struct pci_dev *dev) { } 4868c2ecf20Sopenharmony_cistatic inline void pci_restore_pasid_state(struct pci_dev *pdev) { } 4878c2ecf20Sopenharmony_ci#endif 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI_IOV 4908c2ecf20Sopenharmony_ciint pci_iov_init(struct pci_dev *dev); 4918c2ecf20Sopenharmony_civoid pci_iov_release(struct pci_dev *dev); 4928c2ecf20Sopenharmony_civoid pci_iov_remove(struct pci_dev *dev); 4938c2ecf20Sopenharmony_civoid pci_iov_update_resource(struct pci_dev *dev, int resno); 4948c2ecf20Sopenharmony_ciresource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno); 4958c2ecf20Sopenharmony_civoid pci_restore_iov_state(struct pci_dev *dev); 4968c2ecf20Sopenharmony_ciint pci_iov_bus_range(struct pci_bus *bus); 4978c2ecf20Sopenharmony_ciextern const struct attribute_group sriov_dev_attr_group; 4988c2ecf20Sopenharmony_ci#else 4998c2ecf20Sopenharmony_cistatic inline int pci_iov_init(struct pci_dev *dev) 5008c2ecf20Sopenharmony_ci{ 5018c2ecf20Sopenharmony_ci return -ENODEV; 5028c2ecf20Sopenharmony_ci} 5038c2ecf20Sopenharmony_cistatic inline void pci_iov_release(struct pci_dev *dev) 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci{ 5068c2ecf20Sopenharmony_ci} 5078c2ecf20Sopenharmony_cistatic inline void pci_iov_remove(struct pci_dev *dev) 5088c2ecf20Sopenharmony_ci{ 5098c2ecf20Sopenharmony_ci} 5108c2ecf20Sopenharmony_cistatic inline void pci_restore_iov_state(struct pci_dev *dev) 5118c2ecf20Sopenharmony_ci{ 5128c2ecf20Sopenharmony_ci} 5138c2ecf20Sopenharmony_cistatic inline int pci_iov_bus_range(struct pci_bus *bus) 5148c2ecf20Sopenharmony_ci{ 5158c2ecf20Sopenharmony_ci return 0; 5168c2ecf20Sopenharmony_ci} 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci#endif /* CONFIG_PCI_IOV */ 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ciunsigned long pci_cardbus_resource_alignment(struct resource *); 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_cistatic inline resource_size_t pci_resource_alignment(struct pci_dev *dev, 5238c2ecf20Sopenharmony_ci struct resource *res) 5248c2ecf20Sopenharmony_ci{ 5258c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI_IOV 5268c2ecf20Sopenharmony_ci int resno = res - dev->resource; 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END) 5298c2ecf20Sopenharmony_ci return pci_sriov_resource_alignment(dev, resno); 5308c2ecf20Sopenharmony_ci#endif 5318c2ecf20Sopenharmony_ci if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS) 5328c2ecf20Sopenharmony_ci return pci_cardbus_resource_alignment(res); 5338c2ecf20Sopenharmony_ci return resource_alignment(res); 5348c2ecf20Sopenharmony_ci} 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_civoid pci_acs_init(struct pci_dev *dev); 5378c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI_QUIRKS 5388c2ecf20Sopenharmony_ciint pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags); 5398c2ecf20Sopenharmony_ciint pci_dev_specific_enable_acs(struct pci_dev *dev); 5408c2ecf20Sopenharmony_ciint pci_dev_specific_disable_acs_redir(struct pci_dev *dev); 5418c2ecf20Sopenharmony_ci#else 5428c2ecf20Sopenharmony_cistatic inline int pci_dev_specific_acs_enabled(struct pci_dev *dev, 5438c2ecf20Sopenharmony_ci u16 acs_flags) 5448c2ecf20Sopenharmony_ci{ 5458c2ecf20Sopenharmony_ci return -ENOTTY; 5468c2ecf20Sopenharmony_ci} 5478c2ecf20Sopenharmony_cistatic inline int pci_dev_specific_enable_acs(struct pci_dev *dev) 5488c2ecf20Sopenharmony_ci{ 5498c2ecf20Sopenharmony_ci return -ENOTTY; 5508c2ecf20Sopenharmony_ci} 5518c2ecf20Sopenharmony_cistatic inline int pci_dev_specific_disable_acs_redir(struct pci_dev *dev) 5528c2ecf20Sopenharmony_ci{ 5538c2ecf20Sopenharmony_ci return -ENOTTY; 5548c2ecf20Sopenharmony_ci} 5558c2ecf20Sopenharmony_ci#endif 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci/* PCI error reporting and recovery */ 5588c2ecf20Sopenharmony_cipci_ers_result_t pcie_do_recovery(struct pci_dev *dev, 5598c2ecf20Sopenharmony_ci pci_channel_state_t state, 5608c2ecf20Sopenharmony_ci pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev)); 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_cibool pcie_wait_for_link(struct pci_dev *pdev, bool active); 5638c2ecf20Sopenharmony_ci#ifdef CONFIG_PCIEASPM 5648c2ecf20Sopenharmony_civoid pcie_aspm_init_link_state(struct pci_dev *pdev); 5658c2ecf20Sopenharmony_civoid pcie_aspm_exit_link_state(struct pci_dev *pdev); 5668c2ecf20Sopenharmony_civoid pcie_aspm_pm_state_change(struct pci_dev *pdev); 5678c2ecf20Sopenharmony_civoid pcie_aspm_powersave_config_link(struct pci_dev *pdev); 5688c2ecf20Sopenharmony_ci#else 5698c2ecf20Sopenharmony_cistatic inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { } 5708c2ecf20Sopenharmony_cistatic inline void pcie_aspm_exit_link_state(struct pci_dev *pdev) { } 5718c2ecf20Sopenharmony_cistatic inline void pcie_aspm_pm_state_change(struct pci_dev *pdev) { } 5728c2ecf20Sopenharmony_cistatic inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { } 5738c2ecf20Sopenharmony_ci#endif 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci#ifdef CONFIG_PCIE_ECRC 5768c2ecf20Sopenharmony_civoid pcie_set_ecrc_checking(struct pci_dev *dev); 5778c2ecf20Sopenharmony_civoid pcie_ecrc_get_policy(char *str); 5788c2ecf20Sopenharmony_ci#else 5798c2ecf20Sopenharmony_cistatic inline void pcie_set_ecrc_checking(struct pci_dev *dev) { } 5808c2ecf20Sopenharmony_cistatic inline void pcie_ecrc_get_policy(char *str) { } 5818c2ecf20Sopenharmony_ci#endif 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_ci#ifdef CONFIG_PCIE_PTM 5848c2ecf20Sopenharmony_civoid pci_ptm_init(struct pci_dev *dev); 5858c2ecf20Sopenharmony_ci#else 5868c2ecf20Sopenharmony_cistatic inline void pci_ptm_init(struct pci_dev *dev) { } 5878c2ecf20Sopenharmony_ci#endif 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_cistruct pci_dev_reset_methods { 5908c2ecf20Sopenharmony_ci u16 vendor; 5918c2ecf20Sopenharmony_ci u16 device; 5928c2ecf20Sopenharmony_ci int (*reset)(struct pci_dev *dev, int probe); 5938c2ecf20Sopenharmony_ci}; 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI_QUIRKS 5968c2ecf20Sopenharmony_ciint pci_dev_specific_reset(struct pci_dev *dev, int probe); 5978c2ecf20Sopenharmony_ci#else 5988c2ecf20Sopenharmony_cistatic inline int pci_dev_specific_reset(struct pci_dev *dev, int probe) 5998c2ecf20Sopenharmony_ci{ 6008c2ecf20Sopenharmony_ci return -ENOTTY; 6018c2ecf20Sopenharmony_ci} 6028c2ecf20Sopenharmony_ci#endif 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci#if defined(CONFIG_PCI_QUIRKS) && defined(CONFIG_ARM64) 6058c2ecf20Sopenharmony_ciint acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment, 6068c2ecf20Sopenharmony_ci struct resource *res); 6078c2ecf20Sopenharmony_ci#else 6088c2ecf20Sopenharmony_cistatic inline int acpi_get_rc_resources(struct device *dev, const char *hid, 6098c2ecf20Sopenharmony_ci u16 segment, struct resource *res) 6108c2ecf20Sopenharmony_ci{ 6118c2ecf20Sopenharmony_ci return -ENODEV; 6128c2ecf20Sopenharmony_ci} 6138c2ecf20Sopenharmony_ci#endif 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ciu32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar); 6168c2ecf20Sopenharmony_ciint pci_rebar_get_current_size(struct pci_dev *pdev, int bar); 6178c2ecf20Sopenharmony_ciint pci_rebar_set_size(struct pci_dev *pdev, int bar, int size); 6188c2ecf20Sopenharmony_cistatic inline u64 pci_rebar_size_to_bytes(int size) 6198c2ecf20Sopenharmony_ci{ 6208c2ecf20Sopenharmony_ci return 1ULL << (size + 20); 6218c2ecf20Sopenharmony_ci} 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_cistruct device_node; 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci#ifdef CONFIG_OF 6268c2ecf20Sopenharmony_ciint of_pci_parse_bus_range(struct device_node *node, struct resource *res); 6278c2ecf20Sopenharmony_ciint of_get_pci_domain_nr(struct device_node *node); 6288c2ecf20Sopenharmony_ciint of_pci_get_max_link_speed(struct device_node *node); 6298c2ecf20Sopenharmony_civoid pci_set_of_node(struct pci_dev *dev); 6308c2ecf20Sopenharmony_civoid pci_release_of_node(struct pci_dev *dev); 6318c2ecf20Sopenharmony_civoid pci_set_bus_of_node(struct pci_bus *bus); 6328c2ecf20Sopenharmony_civoid pci_release_bus_of_node(struct pci_bus *bus); 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_ciint devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge); 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ci#else 6378c2ecf20Sopenharmony_cistatic inline int 6388c2ecf20Sopenharmony_ciof_pci_parse_bus_range(struct device_node *node, struct resource *res) 6398c2ecf20Sopenharmony_ci{ 6408c2ecf20Sopenharmony_ci return -EINVAL; 6418c2ecf20Sopenharmony_ci} 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_cistatic inline int 6448c2ecf20Sopenharmony_ciof_get_pci_domain_nr(struct device_node *node) 6458c2ecf20Sopenharmony_ci{ 6468c2ecf20Sopenharmony_ci return -1; 6478c2ecf20Sopenharmony_ci} 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_cistatic inline int 6508c2ecf20Sopenharmony_ciof_pci_get_max_link_speed(struct device_node *node) 6518c2ecf20Sopenharmony_ci{ 6528c2ecf20Sopenharmony_ci return -EINVAL; 6538c2ecf20Sopenharmony_ci} 6548c2ecf20Sopenharmony_ci 6558c2ecf20Sopenharmony_cistatic inline void pci_set_of_node(struct pci_dev *dev) { } 6568c2ecf20Sopenharmony_cistatic inline void pci_release_of_node(struct pci_dev *dev) { } 6578c2ecf20Sopenharmony_cistatic inline void pci_set_bus_of_node(struct pci_bus *bus) { } 6588c2ecf20Sopenharmony_cistatic inline void pci_release_bus_of_node(struct pci_bus *bus) { } 6598c2ecf20Sopenharmony_ci 6608c2ecf20Sopenharmony_cistatic inline int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge) 6618c2ecf20Sopenharmony_ci{ 6628c2ecf20Sopenharmony_ci return 0; 6638c2ecf20Sopenharmony_ci} 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci#endif /* CONFIG_OF */ 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci#ifdef CONFIG_PCIEAER 6688c2ecf20Sopenharmony_civoid pci_no_aer(void); 6698c2ecf20Sopenharmony_civoid pci_aer_init(struct pci_dev *dev); 6708c2ecf20Sopenharmony_civoid pci_aer_exit(struct pci_dev *dev); 6718c2ecf20Sopenharmony_ciextern const struct attribute_group aer_stats_attr_group; 6728c2ecf20Sopenharmony_civoid pci_aer_clear_fatal_status(struct pci_dev *dev); 6738c2ecf20Sopenharmony_ciint pci_aer_clear_status(struct pci_dev *dev); 6748c2ecf20Sopenharmony_ciint pci_aer_raw_clear_status(struct pci_dev *dev); 6758c2ecf20Sopenharmony_ci#else 6768c2ecf20Sopenharmony_cistatic inline void pci_no_aer(void) { } 6778c2ecf20Sopenharmony_cistatic inline void pci_aer_init(struct pci_dev *d) { } 6788c2ecf20Sopenharmony_cistatic inline void pci_aer_exit(struct pci_dev *d) { } 6798c2ecf20Sopenharmony_cistatic inline void pci_aer_clear_fatal_status(struct pci_dev *dev) { } 6808c2ecf20Sopenharmony_cistatic inline int pci_aer_clear_status(struct pci_dev *dev) { return -EINVAL; } 6818c2ecf20Sopenharmony_cistatic inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL; } 6828c2ecf20Sopenharmony_ci#endif 6838c2ecf20Sopenharmony_ci 6848c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI 6858c2ecf20Sopenharmony_ciint pci_acpi_program_hp_params(struct pci_dev *dev); 6868c2ecf20Sopenharmony_ci#else 6878c2ecf20Sopenharmony_cistatic inline int pci_acpi_program_hp_params(struct pci_dev *dev) 6888c2ecf20Sopenharmony_ci{ 6898c2ecf20Sopenharmony_ci return -ENODEV; 6908c2ecf20Sopenharmony_ci} 6918c2ecf20Sopenharmony_ci#endif 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci#ifdef CONFIG_PCIEASPM 6948c2ecf20Sopenharmony_ciextern const struct attribute_group aspm_ctrl_attr_group; 6958c2ecf20Sopenharmony_ci#endif 6968c2ecf20Sopenharmony_ci 6978c2ecf20Sopenharmony_ci#endif /* DRIVERS_PCI_H */ 698