pci.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef DRIVERS_PCI_H
  3. #define DRIVERS_PCI_H
  4. #define PCI_FIND_CAP_TTL 48
  5. #define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */
  6. extern const unsigned char pcie_link_speed[];
  7. extern bool pci_early_dump;
  8. bool pcie_cap_has_lnkctl(const struct pci_dev *dev);
  9. /* Functions internal to the PCI core code */
  10. int pci_create_sysfs_dev_files(struct pci_dev *pdev);
  11. void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
  12. #if !defined(CONFIG_DMI) && !defined(CONFIG_ACPI)
  13. static inline void pci_create_firmware_label_files(struct pci_dev *pdev)
  14. { return; }
  15. static inline void pci_remove_firmware_label_files(struct pci_dev *pdev)
  16. { return; }
  17. #else
  18. void pci_create_firmware_label_files(struct pci_dev *pdev);
  19. void pci_remove_firmware_label_files(struct pci_dev *pdev);
  20. #endif
  21. void pci_cleanup_rom(struct pci_dev *dev);
  22. enum pci_mmap_api {
  23. PCI_MMAP_SYSFS, /* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */
  24. PCI_MMAP_PROCFS /* mmap on /proc/bus/pci/<BDF> */
  25. };
  26. int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai,
  27. enum pci_mmap_api mmap_api);
  28. int pci_probe_reset_function(struct pci_dev *dev);
  29. int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
  30. int pci_bus_error_reset(struct pci_dev *dev);
  31. /**
  32. * struct pci_platform_pm_ops - Firmware PM callbacks
  33. *
  34. * @bridge_d3: Does the bridge allow entering into D3
  35. *
  36. * @is_manageable: returns 'true' if given device is power manageable by the
  37. * platform firmware
  38. *
  39. * @set_state: invokes the platform firmware to set the device's power state
  40. *
  41. * @get_state: queries the platform firmware for a device's current power state
  42. *
  43. * @choose_state: returns PCI power state of given device preferred by the
  44. * platform; to be used during system-wide transitions from a
  45. * sleeping state to the working state and vice versa
  46. *
  47. * @set_wakeup: enables/disables wakeup capability for the device
  48. *
  49. * @need_resume: returns 'true' if the given device (which is currently
  50. * suspended) needs to be resumed to be configured for system
  51. * wakeup.
  52. *
  53. * If given platform is generally capable of power managing PCI devices, all of
  54. * these callbacks are mandatory.
  55. */
  56. struct pci_platform_pm_ops {
  57. bool (*bridge_d3)(struct pci_dev *dev);
  58. bool (*is_manageable)(struct pci_dev *dev);
  59. int (*set_state)(struct pci_dev *dev, pci_power_t state);
  60. pci_power_t (*get_state)(struct pci_dev *dev);
  61. pci_power_t (*choose_state)(struct pci_dev *dev);
  62. int (*set_wakeup)(struct pci_dev *dev, bool enable);
  63. bool (*need_resume)(struct pci_dev *dev);
  64. };
  65. int pci_set_platform_pm(const struct pci_platform_pm_ops *ops);
  66. void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
  67. void pci_power_up(struct pci_dev *dev);
  68. void pci_disable_enabled_device(struct pci_dev *dev);
  69. int pci_finish_runtime_suspend(struct pci_dev *dev);
  70. void pcie_clear_root_pme_status(struct pci_dev *dev);
  71. int __pci_pme_wakeup(struct pci_dev *dev, void *ign);
  72. void pci_pme_restore(struct pci_dev *dev);
  73. bool pci_dev_keep_suspended(struct pci_dev *dev);
  74. void pci_dev_complete_resume(struct pci_dev *pci_dev);
  75. void pci_config_pm_runtime_get(struct pci_dev *dev);
  76. void pci_config_pm_runtime_put(struct pci_dev *dev);
  77. void pci_pm_init(struct pci_dev *dev);
  78. void pci_ea_init(struct pci_dev *dev);
  79. void pci_allocate_cap_save_buffers(struct pci_dev *dev);
  80. void pci_free_cap_save_buffers(struct pci_dev *dev);
  81. bool pci_bridge_d3_possible(struct pci_dev *dev);
  82. void pci_bridge_d3_update(struct pci_dev *dev);
  83. static inline void pci_wakeup_event(struct pci_dev *dev)
  84. {
  85. /* Wait 100 ms before the system can be put into a sleep state. */
  86. pm_wakeup_event(&dev->dev, 100);
  87. }
  88. static inline bool pci_has_subordinate(struct pci_dev *pci_dev)
  89. {
  90. return !!(pci_dev->subordinate);
  91. }
  92. static inline bool pci_power_manageable(struct pci_dev *pci_dev)
  93. {
  94. /*
  95. * Currently we allow normal PCI devices and PCI bridges transition
  96. * into D3 if their bridge_d3 is set.
  97. */
  98. return !pci_has_subordinate(pci_dev) || pci_dev->bridge_d3;
  99. }
  100. int pci_vpd_init(struct pci_dev *dev);
  101. void pci_vpd_release(struct pci_dev *dev);
  102. void pcie_vpd_create_sysfs_dev_files(struct pci_dev *dev);
  103. void pcie_vpd_remove_sysfs_dev_files(struct pci_dev *dev);
  104. /* PCI /proc functions */
  105. #ifdef CONFIG_PROC_FS
  106. int pci_proc_attach_device(struct pci_dev *dev);
  107. int pci_proc_detach_device(struct pci_dev *dev);
  108. int pci_proc_detach_bus(struct pci_bus *bus);
  109. #else
  110. static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; }
  111. static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; }
  112. static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
  113. #endif
  114. /* Functions for PCI Hotplug drivers to use */
  115. int pci_hp_add_bridge(struct pci_dev *dev);
  116. #ifdef HAVE_PCI_LEGACY
  117. void pci_create_legacy_files(struct pci_bus *bus);
  118. void pci_remove_legacy_files(struct pci_bus *bus);
  119. #else
  120. static inline void pci_create_legacy_files(struct pci_bus *bus) { return; }
  121. static inline void pci_remove_legacy_files(struct pci_bus *bus) { return; }
  122. #endif
  123. /* Lock for read/write access to pci device and bus lists */
  124. extern struct rw_semaphore pci_bus_sem;
  125. extern struct mutex pci_slot_mutex;
  126. extern raw_spinlock_t pci_lock;
  127. extern unsigned int pci_pm_d3_delay;
  128. #ifdef CONFIG_PCI_MSI
  129. void pci_no_msi(void);
  130. #else
  131. static inline void pci_no_msi(void) { }
  132. #endif
  133. static inline void pci_msi_set_enable(struct pci_dev *dev, int enable)
  134. {
  135. u16 control;
  136. pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control);
  137. control &= ~PCI_MSI_FLAGS_ENABLE;
  138. if (enable)
  139. control |= PCI_MSI_FLAGS_ENABLE;
  140. pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control);
  141. }
  142. static inline void pci_msix_clear_and_set_ctrl(struct pci_dev *dev, u16 clear, u16 set)
  143. {
  144. u16 ctrl;
  145. pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
  146. ctrl &= ~clear;
  147. ctrl |= set;
  148. pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, ctrl);
  149. }
  150. void pci_realloc_get_opt(char *);
  151. static inline int pci_no_d1d2(struct pci_dev *dev)
  152. {
  153. unsigned int parent_dstates = 0;
  154. if (dev->bus->self)
  155. parent_dstates = dev->bus->self->no_d1d2;
  156. return (dev->no_d1d2 || parent_dstates);
  157. }
  158. extern const struct attribute_group *pci_dev_groups[];
  159. extern const struct attribute_group *pcibus_groups[];
  160. extern const struct device_type pci_dev_type;
  161. extern const struct attribute_group *pci_bus_groups[];
  162. /**
  163. * pci_match_one_device - Tell if a PCI device structure has a matching
  164. * PCI device id structure
  165. * @id: single PCI device id structure to match
  166. * @dev: the PCI device structure to match against
  167. *
  168. * Returns the matching pci_device_id structure or %NULL if there is no match.
  169. */
  170. static inline const struct pci_device_id *
  171. pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
  172. {
  173. if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) &&
  174. (id->device == PCI_ANY_ID || id->device == dev->device) &&
  175. (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
  176. (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) &&
  177. !((id->class ^ dev->class) & id->class_mask))
  178. return id;
  179. return NULL;
  180. }
  181. /* PCI slot sysfs helper code */
  182. #define to_pci_slot(s) container_of(s, struct pci_slot, kobj)
  183. extern struct kset *pci_slots_kset;
  184. struct pci_slot_attribute {
  185. struct attribute attr;
  186. ssize_t (*show)(struct pci_slot *, char *);
  187. ssize_t (*store)(struct pci_slot *, const char *, size_t);
  188. };
  189. #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr)
  190. enum pci_bar_type {
  191. pci_bar_unknown, /* Standard PCI BAR probe */
  192. pci_bar_io, /* An I/O port BAR */
  193. pci_bar_mem32, /* A 32-bit memory BAR */
  194. pci_bar_mem64, /* A 64-bit memory BAR */
  195. };
  196. int pci_configure_extended_tags(struct pci_dev *dev, void *ign);
  197. bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
  198. int crs_timeout);
  199. bool pci_bus_generic_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
  200. int crs_timeout);
  201. int pci_idt_bus_quirk(struct pci_bus *bus, int devfn, u32 *pl, int crs_timeout);
  202. int pci_setup_device(struct pci_dev *dev);
  203. int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
  204. struct resource *res, unsigned int reg);
  205. void pci_configure_ari(struct pci_dev *dev);
  206. void __pci_bus_size_bridges(struct pci_bus *bus,
  207. struct list_head *realloc_head);
  208. void __pci_bus_assign_resources(const struct pci_bus *bus,
  209. struct list_head *realloc_head,
  210. struct list_head *fail_head);
  211. bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
  212. void pci_reassigndev_resource_alignment(struct pci_dev *dev);
  213. void pci_disable_bridge_window(struct pci_dev *dev);
  214. /* PCIe link information */
  215. #define PCIE_SPEED2STR(speed) \
  216. ((speed) == PCIE_SPEED_16_0GT ? "16 GT/s" : \
  217. (speed) == PCIE_SPEED_8_0GT ? "8 GT/s" : \
  218. (speed) == PCIE_SPEED_5_0GT ? "5 GT/s" : \
  219. (speed) == PCIE_SPEED_2_5GT ? "2.5 GT/s" : \
  220. "Unknown speed")
  221. /* PCIe speed to Mb/s reduced by encoding overhead */
  222. #define PCIE_SPEED2MBS_ENC(speed) \
  223. ((speed) == PCIE_SPEED_16_0GT ? 16000*128/130 : \
  224. (speed) == PCIE_SPEED_8_0GT ? 8000*128/130 : \
  225. (speed) == PCIE_SPEED_5_0GT ? 5000*8/10 : \
  226. (speed) == PCIE_SPEED_2_5GT ? 2500*8/10 : \
  227. 0)
  228. enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev);
  229. enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev);
  230. u32 pcie_bandwidth_capable(struct pci_dev *dev, enum pci_bus_speed *speed,
  231. enum pcie_link_width *width);
  232. void __pcie_print_link_status(struct pci_dev *dev, bool verbose);
  233. /* Single Root I/O Virtualization */
  234. struct pci_sriov {
  235. int pos; /* Capability position */
  236. int nres; /* Number of resources */
  237. u32 cap; /* SR-IOV Capabilities */
  238. u16 ctrl; /* SR-IOV Control */
  239. u16 total_VFs; /* Total VFs associated with the PF */
  240. u16 initial_VFs; /* Initial VFs associated with the PF */
  241. u16 num_VFs; /* Number of VFs available */
  242. u16 offset; /* First VF Routing ID offset */
  243. u16 stride; /* Following VF stride */
  244. u16 vf_device; /* VF device ID */
  245. u32 pgsz; /* Page size for BAR alignment */
  246. u8 link; /* Function Dependency Link */
  247. u8 max_VF_buses; /* Max buses consumed by VFs */
  248. u16 driver_max_VFs; /* Max num VFs driver supports */
  249. struct pci_dev *dev; /* Lowest numbered PF */
  250. struct pci_dev *self; /* This PF */
  251. u32 cfg_size; /* VF config space size */
  252. u32 class; /* VF device */
  253. u8 hdr_type; /* VF header type */
  254. u16 subsystem_vendor; /* VF subsystem vendor */
  255. u16 subsystem_device; /* VF subsystem device */
  256. resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */
  257. bool drivers_autoprobe; /* Auto probing of VFs by driver */
  258. };
  259. /**
  260. * pci_dev_set_io_state - Set the new error state if possible.
  261. *
  262. * @dev - pci device to set new error_state
  263. * @new - the state we want dev to be in
  264. *
  265. * Must be called with device_lock held.
  266. *
  267. * Returns true if state has been changed to the requested state.
  268. */
  269. static inline bool pci_dev_set_io_state(struct pci_dev *dev,
  270. pci_channel_state_t new)
  271. {
  272. bool changed = false;
  273. device_lock_assert(&dev->dev);
  274. switch (new) {
  275. case pci_channel_io_perm_failure:
  276. switch (dev->error_state) {
  277. case pci_channel_io_frozen:
  278. case pci_channel_io_normal:
  279. case pci_channel_io_perm_failure:
  280. changed = true;
  281. break;
  282. }
  283. break;
  284. case pci_channel_io_frozen:
  285. switch (dev->error_state) {
  286. case pci_channel_io_frozen:
  287. case pci_channel_io_normal:
  288. changed = true;
  289. break;
  290. }
  291. break;
  292. case pci_channel_io_normal:
  293. switch (dev->error_state) {
  294. case pci_channel_io_frozen:
  295. case pci_channel_io_normal:
  296. changed = true;
  297. break;
  298. }
  299. break;
  300. }
  301. if (changed)
  302. dev->error_state = new;
  303. return changed;
  304. }
  305. static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused)
  306. {
  307. device_lock(&dev->dev);
  308. pci_dev_set_io_state(dev, pci_channel_io_perm_failure);
  309. device_unlock(&dev->dev);
  310. return 0;
  311. }
  312. static inline bool pci_dev_is_disconnected(const struct pci_dev *dev)
  313. {
  314. return dev->error_state == pci_channel_io_perm_failure;
  315. }
  316. /* pci_dev priv_flags */
  317. #define PCI_DEV_ADDED 0
  318. static inline void pci_dev_assign_added(struct pci_dev *dev, bool added)
  319. {
  320. assign_bit(PCI_DEV_ADDED, &dev->priv_flags, added);
  321. }
  322. static inline bool pci_dev_is_added(const struct pci_dev *dev)
  323. {
  324. return test_bit(PCI_DEV_ADDED, &dev->priv_flags);
  325. }
  326. #ifdef CONFIG_PCIEAER
  327. #include <linux/aer.h>
  328. #define AER_MAX_MULTI_ERR_DEVICES 5 /* Not likely to have more */
  329. struct aer_err_info {
  330. struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES];
  331. int error_dev_num;
  332. unsigned int id:16;
  333. unsigned int severity:2; /* 0:NONFATAL | 1:FATAL | 2:COR */
  334. unsigned int __pad1:5;
  335. unsigned int multi_error_valid:1;
  336. unsigned int first_error:5;
  337. unsigned int __pad2:2;
  338. unsigned int tlp_header_valid:1;
  339. unsigned int status; /* COR/UNCOR Error Status */
  340. unsigned int mask; /* COR/UNCOR Error Mask */
  341. struct aer_header_log_regs tlp; /* TLP Header */
  342. };
  343. int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info);
  344. void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
  345. #endif /* CONFIG_PCIEAER */
  346. #ifdef CONFIG_PCIE_DPC
  347. void pci_save_dpc_state(struct pci_dev *dev);
  348. void pci_restore_dpc_state(struct pci_dev *dev);
  349. #else
  350. static inline void pci_save_dpc_state(struct pci_dev *dev) {}
  351. static inline void pci_restore_dpc_state(struct pci_dev *dev) {}
  352. #endif
  353. #ifdef CONFIG_PCI_ATS
  354. void pci_restore_ats_state(struct pci_dev *dev);
  355. #else
  356. static inline void pci_restore_ats_state(struct pci_dev *dev)
  357. {
  358. }
  359. #endif /* CONFIG_PCI_ATS */
  360. #ifdef CONFIG_PCI_IOV
  361. int pci_iov_init(struct pci_dev *dev);
  362. void pci_iov_release(struct pci_dev *dev);
  363. void pci_iov_remove(struct pci_dev *dev);
  364. void pci_iov_update_resource(struct pci_dev *dev, int resno);
  365. resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
  366. void pci_restore_iov_state(struct pci_dev *dev);
  367. int pci_iov_bus_range(struct pci_bus *bus);
  368. #else
  369. static inline int pci_iov_init(struct pci_dev *dev)
  370. {
  371. return -ENODEV;
  372. }
  373. static inline void pci_iov_release(struct pci_dev *dev)
  374. {
  375. }
  376. static inline void pci_iov_remove(struct pci_dev *dev)
  377. {
  378. }
  379. static inline void pci_restore_iov_state(struct pci_dev *dev)
  380. {
  381. }
  382. static inline int pci_iov_bus_range(struct pci_bus *bus)
  383. {
  384. return 0;
  385. }
  386. #endif /* CONFIG_PCI_IOV */
  387. unsigned long pci_cardbus_resource_alignment(struct resource *);
  388. static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
  389. struct resource *res)
  390. {
  391. #ifdef CONFIG_PCI_IOV
  392. int resno = res - dev->resource;
  393. if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
  394. return pci_sriov_resource_alignment(dev, resno);
  395. #endif
  396. if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS)
  397. return pci_cardbus_resource_alignment(res);
  398. return resource_alignment(res);
  399. }
  400. void pci_enable_acs(struct pci_dev *dev);
  401. #ifdef CONFIG_PCI_QUIRKS
  402. int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
  403. int pci_dev_specific_enable_acs(struct pci_dev *dev);
  404. int pci_dev_specific_disable_acs_redir(struct pci_dev *dev);
  405. #else
  406. static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
  407. u16 acs_flags)
  408. {
  409. return -ENOTTY;
  410. }
  411. static inline int pci_dev_specific_enable_acs(struct pci_dev *dev)
  412. {
  413. return -ENOTTY;
  414. }
  415. static inline int pci_dev_specific_disable_acs_redir(struct pci_dev *dev)
  416. {
  417. return -ENOTTY;
  418. }
  419. #endif
  420. /* PCI error reporting and recovery */
  421. void pcie_do_recovery(struct pci_dev *dev, enum pci_channel_state state,
  422. u32 service);
  423. bool pcie_wait_for_link(struct pci_dev *pdev, bool active);
  424. #ifdef CONFIG_PCIEASPM
  425. void pcie_aspm_init_link_state(struct pci_dev *pdev);
  426. void pcie_aspm_exit_link_state(struct pci_dev *pdev);
  427. void pcie_aspm_pm_state_change(struct pci_dev *pdev);
  428. void pcie_aspm_powersave_config_link(struct pci_dev *pdev);
  429. #else
  430. static inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { }
  431. static inline void pcie_aspm_exit_link_state(struct pci_dev *pdev) { }
  432. static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev) { }
  433. static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { }
  434. #endif
  435. #ifdef CONFIG_PCIEASPM_DEBUG
  436. void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev);
  437. void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev);
  438. #else
  439. static inline void pcie_aspm_create_sysfs_dev_files(struct pci_dev *pdev) { }
  440. static inline void pcie_aspm_remove_sysfs_dev_files(struct pci_dev *pdev) { }
  441. #endif
  442. #ifdef CONFIG_PCIE_PTM
  443. void pci_ptm_init(struct pci_dev *dev);
  444. #else
  445. static inline void pci_ptm_init(struct pci_dev *dev) { }
  446. #endif
  447. struct pci_dev_reset_methods {
  448. u16 vendor;
  449. u16 device;
  450. int (*reset)(struct pci_dev *dev, int probe);
  451. };
  452. #ifdef CONFIG_PCI_QUIRKS
  453. int pci_dev_specific_reset(struct pci_dev *dev, int probe);
  454. #else
  455. static inline int pci_dev_specific_reset(struct pci_dev *dev, int probe)
  456. {
  457. return -ENOTTY;
  458. }
  459. #endif
  460. #if defined(CONFIG_PCI_QUIRKS) && defined(CONFIG_ARM64)
  461. int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment,
  462. struct resource *res);
  463. #endif
  464. u32 pci_rebar_get_possible_sizes(struct pci_dev *pdev, int bar);
  465. int pci_rebar_get_current_size(struct pci_dev *pdev, int bar);
  466. int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size);
  467. static inline u64 pci_rebar_size_to_bytes(int size)
  468. {
  469. return 1ULL << (size + 20);
  470. }
  471. struct device_node;
  472. #ifdef CONFIG_OF
  473. int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
  474. int of_get_pci_domain_nr(struct device_node *node);
  475. int of_pci_get_max_link_speed(struct device_node *node);
  476. #else
  477. static inline int
  478. of_pci_parse_bus_range(struct device_node *node, struct resource *res)
  479. {
  480. return -EINVAL;
  481. }
  482. static inline int
  483. of_get_pci_domain_nr(struct device_node *node)
  484. {
  485. return -1;
  486. }
  487. static inline int
  488. of_pci_get_max_link_speed(struct device_node *node)
  489. {
  490. return -EINVAL;
  491. }
  492. #endif /* CONFIG_OF */
  493. #if defined(CONFIG_OF_ADDRESS)
  494. int devm_of_pci_get_host_bridge_resources(struct device *dev,
  495. unsigned char busno, unsigned char bus_max,
  496. struct list_head *resources, resource_size_t *io_base);
  497. #else
  498. static inline int devm_of_pci_get_host_bridge_resources(struct device *dev,
  499. unsigned char busno, unsigned char bus_max,
  500. struct list_head *resources, resource_size_t *io_base)
  501. {
  502. return -EINVAL;
  503. }
  504. #endif
  505. #ifdef CONFIG_PCIEAER
  506. void pci_no_aer(void);
  507. void pci_aer_init(struct pci_dev *dev);
  508. void pci_aer_exit(struct pci_dev *dev);
  509. extern const struct attribute_group aer_stats_attr_group;
  510. void pci_aer_clear_fatal_status(struct pci_dev *dev);
  511. void pci_aer_clear_device_status(struct pci_dev *dev);
  512. #else
  513. static inline void pci_no_aer(void) { }
  514. static inline int pci_aer_init(struct pci_dev *d) { return -ENODEV; }
  515. static inline void pci_aer_exit(struct pci_dev *d) { }
  516. static inline void pci_aer_clear_fatal_status(struct pci_dev *dev) { }
  517. static inline void pci_aer_clear_device_status(struct pci_dev *dev) { }
  518. #endif
  519. #endif /* DRIVERS_PCI_H */