1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef DRIVERS_PCI_H
3 #define DRIVERS_PCI_H
4
5 #include <linux/pci.h>
6
7 struct pcie_tlp_log;
8
9 /* Number of possible devfns: 0.0 to 1f.7 inclusive */
10 #define MAX_NR_DEVFNS 256
11
12 #define PCI_FIND_CAP_TTL 48
13
14 #define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */
15
16 #define PCIE_LINK_RETRAIN_TIMEOUT_MS 1000
17
18 /*
19 * Power stable to PERST# inactive.
20 *
21 * See the "Power Sequencing and Reset Signal Timings" table of the PCI Express
22 * Card Electromechanical Specification, Revision 5.1, Section 2.9.2, Symbol
23 * "T_PVPERL".
24 */
25 #define PCIE_T_PVPERL_MS 100
26
27 /*
28 * REFCLK stable before PERST# inactive.
29 *
30 * See the "Power Sequencing and Reset Signal Timings" table of the PCI Express
31 * Card Electromechanical Specification, Revision 5.1, Section 2.9.2, Symbol
32 * "T_PERST-CLK".
33 */
34 #define PCIE_T_PERST_CLK_US 100
35
36 /*
37 * End of conventional reset (PERST# de-asserted) to first configuration
38 * request (device able to respond with a "Request Retry Status" completion),
39 * from PCIe r6.0, sec 6.6.1.
40 */
41 #define PCIE_T_RRS_READY_MS 100
42
43 /*
44 * PCIe r6.0, sec 5.3.3.2.1 <PME Synchronization>
45 * Recommends 1ms to 10ms timeout to check L2 ready.
46 */
47 #define PCIE_PME_TO_L2_TIMEOUT_US 10000
48
49 /*
50 * PCIe r6.0, sec 6.6.1 <Conventional Reset>
51 *
52 * - "With a Downstream Port that does not support Link speeds greater
53 * than 5.0 GT/s, software must wait a minimum of 100 ms following exit
54 * from a Conventional Reset before sending a Configuration Request to
55 * the device immediately below that Port."
56 *
57 * - "With a Downstream Port that supports Link speeds greater than
58 * 5.0 GT/s, software must wait a minimum of 100 ms after Link training
59 * completes before sending a Configuration Request to the device
60 * immediately below that Port."
61 */
62 #define PCIE_RESET_CONFIG_DEVICE_WAIT_MS 100
63
64 /* Message Routing (r[2:0]); PCIe r6.0, sec 2.2.8 */
65 #define PCIE_MSG_TYPE_R_RC 0
66 #define PCIE_MSG_TYPE_R_ADDR 1
67 #define PCIE_MSG_TYPE_R_ID 2
68 #define PCIE_MSG_TYPE_R_BC 3
69 #define PCIE_MSG_TYPE_R_LOCAL 4
70 #define PCIE_MSG_TYPE_R_GATHER 5
71
72 /* Power Management Messages; PCIe r6.0, sec 2.2.8.2 */
73 #define PCIE_MSG_CODE_PME_TURN_OFF 0x19
74
75 /* INTx Mechanism Messages; PCIe r6.0, sec 2.2.8.1 */
76 #define PCIE_MSG_CODE_ASSERT_INTA 0x20
77 #define PCIE_MSG_CODE_ASSERT_INTB 0x21
78 #define PCIE_MSG_CODE_ASSERT_INTC 0x22
79 #define PCIE_MSG_CODE_ASSERT_INTD 0x23
80 #define PCIE_MSG_CODE_DEASSERT_INTA 0x24
81 #define PCIE_MSG_CODE_DEASSERT_INTB 0x25
82 #define PCIE_MSG_CODE_DEASSERT_INTC 0x26
83 #define PCIE_MSG_CODE_DEASSERT_INTD 0x27
84
85 extern const unsigned char pcie_link_speed[];
86 extern bool pci_early_dump;
87
88 bool pcie_cap_has_lnkctl(const struct pci_dev *dev);
89 bool pcie_cap_has_lnkctl2(const struct pci_dev *dev);
90 bool pcie_cap_has_rtctl(const struct pci_dev *dev);
91
92 /* Functions internal to the PCI core code */
93
94 #ifdef CONFIG_DMI
95 extern const struct attribute_group pci_dev_smbios_attr_group;
96 #endif
97
98 enum pci_mmap_api {
99 PCI_MMAP_SYSFS, /* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */
100 PCI_MMAP_PROCFS /* mmap on /proc/bus/pci/<BDF> */
101 };
102 int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai,
103 enum pci_mmap_api mmap_api);
104
105 bool pci_reset_supported(struct pci_dev *dev);
106 void pci_init_reset_methods(struct pci_dev *dev);
107 int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
108 int pci_bus_error_reset(struct pci_dev *dev);
109 int __pci_reset_bus(struct pci_bus *bus);
110
111 struct pci_cap_saved_data {
112 u16 cap_nr;
113 bool cap_extended;
114 unsigned int size;
115 u32 data[];
116 };
117
118 struct pci_cap_saved_state {
119 struct hlist_node next;
120 struct pci_cap_saved_data cap;
121 };
122
123 void pci_allocate_cap_save_buffers(struct pci_dev *dev);
124 void pci_free_cap_save_buffers(struct pci_dev *dev);
125 int pci_add_cap_save_buffer(struct pci_dev *dev, char cap, unsigned int size);
126 int pci_add_ext_cap_save_buffer(struct pci_dev *dev,
127 u16 cap, unsigned int size);
128 struct pci_cap_saved_state *pci_find_saved_cap(struct pci_dev *dev, char cap);
129 struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev,
130 u16 cap);
131
132 #define PCI_PM_D2_DELAY 200 /* usec; see PCIe r4.0, sec 5.9.1 */
133 #define PCI_PM_D3HOT_WAIT 10 /* msec */
134 #define PCI_PM_D3COLD_WAIT 100 /* msec */
135
136 void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
137 void pci_refresh_power_state(struct pci_dev *dev);
138 int pci_power_up(struct pci_dev *dev);
139 void pci_disable_enabled_device(struct pci_dev *dev);
140 int pci_finish_runtime_suspend(struct pci_dev *dev);
141 void pcie_clear_device_status(struct pci_dev *dev);
142 void pcie_clear_root_pme_status(struct pci_dev *dev);
143 bool pci_check_pme_status(struct pci_dev *dev);
144 void pci_pme_wakeup_bus(struct pci_bus *bus);
145 void pci_pme_restore(struct pci_dev *dev);
146 bool pci_dev_need_resume(struct pci_dev *dev);
147 void pci_dev_adjust_pme(struct pci_dev *dev);
148 void pci_dev_complete_resume(struct pci_dev *pci_dev);
149 void pci_config_pm_runtime_get(struct pci_dev *dev);
150 void pci_config_pm_runtime_put(struct pci_dev *dev);
151 void pci_pm_init(struct pci_dev *dev);
152 void pci_ea_init(struct pci_dev *dev);
153 void pci_msi_init(struct pci_dev *dev);
154 void pci_msix_init(struct pci_dev *dev);
155 bool pci_bridge_d3_possible(struct pci_dev *dev);
156 void pci_bridge_d3_update(struct pci_dev *dev);
157 int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type);
158
pci_bus_rrs_vendor_id(u32 l)159 static inline bool pci_bus_rrs_vendor_id(u32 l)
160 {
161 return (l & 0xffff) == PCI_VENDOR_ID_PCI_SIG;
162 }
163
pci_wakeup_event(struct pci_dev * dev)164 static inline void pci_wakeup_event(struct pci_dev *dev)
165 {
166 /* Wait 100 ms before the system can be put into a sleep state. */
167 pm_wakeup_event(&dev->dev, 100);
168 }
169
170 /**
171 * pci_bar_index_is_valid - Check whether a BAR index is within valid range
172 * @bar: BAR index
173 *
174 * Protects against overflowing &struct pci_dev.resource array.
175 *
176 * Return: true for valid index, false otherwise.
177 */
pci_bar_index_is_valid(int bar)178 static inline bool pci_bar_index_is_valid(int bar)
179 {
180 if (bar >= 0 && bar < PCI_NUM_RESOURCES)
181 return true;
182
183 return false;
184 }
185
pci_has_subordinate(struct pci_dev * pci_dev)186 static inline bool pci_has_subordinate(struct pci_dev *pci_dev)
187 {
188 return !!(pci_dev->subordinate);
189 }
190
pci_power_manageable(struct pci_dev * pci_dev)191 static inline bool pci_power_manageable(struct pci_dev *pci_dev)
192 {
193 /*
194 * Currently we allow normal PCI devices and PCI bridges transition
195 * into D3 if their bridge_d3 is set.
196 */
197 return !pci_has_subordinate(pci_dev) || pci_dev->bridge_d3;
198 }
199
pcie_downstream_port(const struct pci_dev * dev)200 static inline bool pcie_downstream_port(const struct pci_dev *dev)
201 {
202 int type = pci_pcie_type(dev);
203
204 return type == PCI_EXP_TYPE_ROOT_PORT ||
205 type == PCI_EXP_TYPE_DOWNSTREAM ||
206 type == PCI_EXP_TYPE_PCIE_BRIDGE;
207 }
208
209 void pci_vpd_init(struct pci_dev *dev);
210 extern const struct attribute_group pci_dev_vpd_attr_group;
211
212 /* PCI Virtual Channel */
213 int pci_save_vc_state(struct pci_dev *dev);
214 void pci_restore_vc_state(struct pci_dev *dev);
215 void pci_allocate_vc_save_buffers(struct pci_dev *dev);
216
217 /* PCI /proc functions */
218 #ifdef CONFIG_PROC_FS
219 int pci_proc_attach_device(struct pci_dev *dev);
220 int pci_proc_detach_device(struct pci_dev *dev);
221 int pci_proc_detach_bus(struct pci_bus *bus);
222 #else
pci_proc_attach_device(struct pci_dev * dev)223 static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; }
pci_proc_detach_device(struct pci_dev * dev)224 static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; }
pci_proc_detach_bus(struct pci_bus * bus)225 static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
226 #endif
227
228 /* Functions for PCI Hotplug drivers to use */
229 int pci_hp_add_bridge(struct pci_dev *dev);
230
231 #if defined(CONFIG_SYSFS) && defined(HAVE_PCI_LEGACY)
232 void pci_create_legacy_files(struct pci_bus *bus);
233 void pci_remove_legacy_files(struct pci_bus *bus);
234 #else
pci_create_legacy_files(struct pci_bus * bus)235 static inline void pci_create_legacy_files(struct pci_bus *bus) { }
pci_remove_legacy_files(struct pci_bus * bus)236 static inline void pci_remove_legacy_files(struct pci_bus *bus) { }
237 #endif
238
239 /* Lock for read/write access to pci device and bus lists */
240 extern struct rw_semaphore pci_bus_sem;
241 extern struct mutex pci_slot_mutex;
242
243 extern raw_spinlock_t pci_lock;
244
245 extern unsigned int pci_pm_d3hot_delay;
246
247 #ifdef CONFIG_PCI_MSI
248 void pci_no_msi(void);
249 #else
pci_no_msi(void)250 static inline void pci_no_msi(void) { }
251 #endif
252
253 void pci_realloc_get_opt(char *);
254
pci_no_d1d2(struct pci_dev * dev)255 static inline int pci_no_d1d2(struct pci_dev *dev)
256 {
257 unsigned int parent_dstates = 0;
258
259 if (dev->bus->self)
260 parent_dstates = dev->bus->self->no_d1d2;
261 return (dev->no_d1d2 || parent_dstates);
262
263 }
264
265 #ifdef CONFIG_SYSFS
266 int pci_create_sysfs_dev_files(struct pci_dev *pdev);
267 void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
268 extern const struct attribute_group *pci_dev_groups[];
269 extern const struct attribute_group *pci_dev_attr_groups[];
270 extern const struct attribute_group *pcibus_groups[];
271 extern const struct attribute_group *pci_bus_groups[];
272 #else
pci_create_sysfs_dev_files(struct pci_dev * pdev)273 static inline int pci_create_sysfs_dev_files(struct pci_dev *pdev) { return 0; }
pci_remove_sysfs_dev_files(struct pci_dev * pdev)274 static inline void pci_remove_sysfs_dev_files(struct pci_dev *pdev) { }
275 #define pci_dev_groups NULL
276 #define pci_dev_attr_groups NULL
277 #define pcibus_groups NULL
278 #define pci_bus_groups NULL
279 #endif
280
281 extern unsigned long pci_hotplug_io_size;
282 extern unsigned long pci_hotplug_mmio_size;
283 extern unsigned long pci_hotplug_mmio_pref_size;
284 extern unsigned long pci_hotplug_bus_size;
285
286 /**
287 * pci_match_one_device - Tell if a PCI device structure has a matching
288 * PCI device id structure
289 * @id: single PCI device id structure to match
290 * @dev: the PCI device structure to match against
291 *
292 * Returns the matching pci_device_id structure or %NULL if there is no match.
293 */
294 static inline const struct pci_device_id *
pci_match_one_device(const struct pci_device_id * id,const struct pci_dev * dev)295 pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
296 {
297 if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) &&
298 (id->device == PCI_ANY_ID || id->device == dev->device) &&
299 (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
300 (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) &&
301 !((id->class ^ dev->class) & id->class_mask))
302 return id;
303 return NULL;
304 }
305
306 /* PCI slot sysfs helper code */
307 #define to_pci_slot(s) container_of(s, struct pci_slot, kobj)
308
309 extern struct kset *pci_slots_kset;
310
311 struct pci_slot_attribute {
312 struct attribute attr;
313 ssize_t (*show)(struct pci_slot *, char *);
314 ssize_t (*store)(struct pci_slot *, const char *, size_t);
315 };
316 #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr)
317
318 enum pci_bar_type {
319 pci_bar_unknown, /* Standard PCI BAR probe */
320 pci_bar_io, /* An I/O port BAR */
321 pci_bar_mem32, /* A 32-bit memory BAR */
322 pci_bar_mem64, /* A 64-bit memory BAR */
323 };
324
325 struct device *pci_get_host_bridge_device(struct pci_dev *dev);
326 void pci_put_host_bridge_device(struct device *dev);
327
328 int pci_configure_extended_tags(struct pci_dev *dev, void *ign);
329 bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
330 int rrs_timeout);
331 bool pci_bus_generic_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
332 int rrs_timeout);
333 int pci_idt_bus_quirk(struct pci_bus *bus, int devfn, u32 *pl, int rrs_timeout);
334
335 int pci_setup_device(struct pci_dev *dev);
336 void __pci_size_stdbars(struct pci_dev *dev, int count,
337 unsigned int pos, u32 *sizes);
338 int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
339 struct resource *res, unsigned int reg, u32 *sizes);
340 void pci_configure_ari(struct pci_dev *dev);
341 void __pci_bus_size_bridges(struct pci_bus *bus,
342 struct list_head *realloc_head);
343 void __pci_bus_assign_resources(const struct pci_bus *bus,
344 struct list_head *realloc_head,
345 struct list_head *fail_head);
346 bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
347 void pci_walk_bus_locked(struct pci_bus *top,
348 int (*cb)(struct pci_dev *, void *),
349 void *userdata);
350
351 const char *pci_resource_name(struct pci_dev *dev, unsigned int i);
352
353 void pci_reassigndev_resource_alignment(struct pci_dev *dev);
354 void pci_disable_bridge_window(struct pci_dev *dev);
355 struct pci_bus *pci_bus_get(struct pci_bus *bus);
356 void pci_bus_put(struct pci_bus *bus);
357
358 #define PCIE_LNKCAP_SLS2SPEED(lnkcap) \
359 ({ \
360 ((lnkcap) == PCI_EXP_LNKCAP_SLS_64_0GB ? PCIE_SPEED_64_0GT : \
361 (lnkcap) == PCI_EXP_LNKCAP_SLS_32_0GB ? PCIE_SPEED_32_0GT : \
362 (lnkcap) == PCI_EXP_LNKCAP_SLS_16_0GB ? PCIE_SPEED_16_0GT : \
363 (lnkcap) == PCI_EXP_LNKCAP_SLS_8_0GB ? PCIE_SPEED_8_0GT : \
364 (lnkcap) == PCI_EXP_LNKCAP_SLS_5_0GB ? PCIE_SPEED_5_0GT : \
365 (lnkcap) == PCI_EXP_LNKCAP_SLS_2_5GB ? PCIE_SPEED_2_5GT : \
366 PCI_SPEED_UNKNOWN); \
367 })
368
369 /* PCIe link information from Link Capabilities 2 */
370 #define PCIE_LNKCAP2_SLS2SPEED(lnkcap2) \
371 ((lnkcap2) & PCI_EXP_LNKCAP2_SLS_64_0GB ? PCIE_SPEED_64_0GT : \
372 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_32_0GB ? PCIE_SPEED_32_0GT : \
373 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_16_0GB ? PCIE_SPEED_16_0GT : \
374 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_8_0GB ? PCIE_SPEED_8_0GT : \
375 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_5_0GB ? PCIE_SPEED_5_0GT : \
376 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_2_5GB ? PCIE_SPEED_2_5GT : \
377 PCI_SPEED_UNKNOWN)
378
379 #define PCIE_LNKCTL2_TLS2SPEED(lnkctl2) \
380 ((lnkctl2) == PCI_EXP_LNKCTL2_TLS_64_0GT ? PCIE_SPEED_64_0GT : \
381 (lnkctl2) == PCI_EXP_LNKCTL2_TLS_32_0GT ? PCIE_SPEED_32_0GT : \
382 (lnkctl2) == PCI_EXP_LNKCTL2_TLS_16_0GT ? PCIE_SPEED_16_0GT : \
383 (lnkctl2) == PCI_EXP_LNKCTL2_TLS_8_0GT ? PCIE_SPEED_8_0GT : \
384 (lnkctl2) == PCI_EXP_LNKCTL2_TLS_5_0GT ? PCIE_SPEED_5_0GT : \
385 (lnkctl2) == PCI_EXP_LNKCTL2_TLS_2_5GT ? PCIE_SPEED_2_5GT : \
386 PCI_SPEED_UNKNOWN)
387
388 /* PCIe speed to Mb/s reduced by encoding overhead */
389 #define PCIE_SPEED2MBS_ENC(speed) \
390 ((speed) == PCIE_SPEED_64_0GT ? 64000*1/1 : \
391 (speed) == PCIE_SPEED_32_0GT ? 32000*128/130 : \
392 (speed) == PCIE_SPEED_16_0GT ? 16000*128/130 : \
393 (speed) == PCIE_SPEED_8_0GT ? 8000*128/130 : \
394 (speed) == PCIE_SPEED_5_0GT ? 5000*8/10 : \
395 (speed) == PCIE_SPEED_2_5GT ? 2500*8/10 : \
396 0)
397
pcie_dev_speed_mbps(enum pci_bus_speed speed)398 static inline int pcie_dev_speed_mbps(enum pci_bus_speed speed)
399 {
400 switch (speed) {
401 case PCIE_SPEED_2_5GT:
402 return 2500;
403 case PCIE_SPEED_5_0GT:
404 return 5000;
405 case PCIE_SPEED_8_0GT:
406 return 8000;
407 case PCIE_SPEED_16_0GT:
408 return 16000;
409 case PCIE_SPEED_32_0GT:
410 return 32000;
411 case PCIE_SPEED_64_0GT:
412 return 64000;
413 default:
414 break;
415 }
416
417 return -EINVAL;
418 }
419
420 u8 pcie_get_supported_speeds(struct pci_dev *dev);
421 const char *pci_speed_string(enum pci_bus_speed speed);
422 void __pcie_print_link_status(struct pci_dev *dev, bool verbose);
423 void pcie_report_downtraining(struct pci_dev *dev);
424
__pcie_update_link_speed(struct pci_bus * bus,u16 linksta)425 static inline void __pcie_update_link_speed(struct pci_bus *bus, u16 linksta)
426 {
427 bus->cur_bus_speed = pcie_link_speed[linksta & PCI_EXP_LNKSTA_CLS];
428 }
429 void pcie_update_link_speed(struct pci_bus *bus);
430
431 /* Single Root I/O Virtualization */
432 struct pci_sriov {
433 int pos; /* Capability position */
434 int nres; /* Number of resources */
435 u32 cap; /* SR-IOV Capabilities */
436 u16 ctrl; /* SR-IOV Control */
437 u16 total_VFs; /* Total VFs associated with the PF */
438 u16 initial_VFs; /* Initial VFs associated with the PF */
439 u16 num_VFs; /* Number of VFs available */
440 u16 offset; /* First VF Routing ID offset */
441 u16 stride; /* Following VF stride */
442 u16 vf_device; /* VF device ID */
443 u32 pgsz; /* Page size for BAR alignment */
444 u8 link; /* Function Dependency Link */
445 u8 max_VF_buses; /* Max buses consumed by VFs */
446 u16 driver_max_VFs; /* Max num VFs driver supports */
447 struct pci_dev *dev; /* Lowest numbered PF */
448 struct pci_dev *self; /* This PF */
449 u32 class; /* VF device */
450 u8 hdr_type; /* VF header type */
451 u16 subsystem_vendor; /* VF subsystem vendor */
452 u16 subsystem_device; /* VF subsystem device */
453 resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */
454 bool drivers_autoprobe; /* Auto probing of VFs by driver */
455 };
456
457 #ifdef CONFIG_PCI_DOE
458 void pci_doe_init(struct pci_dev *pdev);
459 void pci_doe_destroy(struct pci_dev *pdev);
460 void pci_doe_disconnected(struct pci_dev *pdev);
461 #else
pci_doe_init(struct pci_dev * pdev)462 static inline void pci_doe_init(struct pci_dev *pdev) { }
pci_doe_destroy(struct pci_dev * pdev)463 static inline void pci_doe_destroy(struct pci_dev *pdev) { }
pci_doe_disconnected(struct pci_dev * pdev)464 static inline void pci_doe_disconnected(struct pci_dev *pdev) { }
465 #endif
466
467 #ifdef CONFIG_PCI_NPEM
468 void pci_npem_create(struct pci_dev *dev);
469 void pci_npem_remove(struct pci_dev *dev);
470 #else
pci_npem_create(struct pci_dev * dev)471 static inline void pci_npem_create(struct pci_dev *dev) { }
pci_npem_remove(struct pci_dev * dev)472 static inline void pci_npem_remove(struct pci_dev *dev) { }
473 #endif
474
475 /**
476 * pci_dev_set_io_state - Set the new error state if possible.
477 *
478 * @dev: PCI device to set new error_state
479 * @new: the state we want dev to be in
480 *
481 * If the device is experiencing perm_failure, it has to remain in that state.
482 * Any other transition is allowed.
483 *
484 * Returns true if state has been changed to the requested state.
485 */
pci_dev_set_io_state(struct pci_dev * dev,pci_channel_state_t new)486 static inline bool pci_dev_set_io_state(struct pci_dev *dev,
487 pci_channel_state_t new)
488 {
489 pci_channel_state_t old;
490
491 switch (new) {
492 case pci_channel_io_perm_failure:
493 xchg(&dev->error_state, pci_channel_io_perm_failure);
494 return true;
495 case pci_channel_io_frozen:
496 old = cmpxchg(&dev->error_state, pci_channel_io_normal,
497 pci_channel_io_frozen);
498 return old != pci_channel_io_perm_failure;
499 case pci_channel_io_normal:
500 old = cmpxchg(&dev->error_state, pci_channel_io_frozen,
501 pci_channel_io_normal);
502 return old != pci_channel_io_perm_failure;
503 default:
504 return false;
505 }
506 }
507
pci_dev_set_disconnected(struct pci_dev * dev,void * unused)508 static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused)
509 {
510 pci_dev_set_io_state(dev, pci_channel_io_perm_failure);
511 pci_doe_disconnected(dev);
512
513 return 0;
514 }
515
516 /* pci_dev priv_flags */
517 #define PCI_DEV_ADDED 0
518 #define PCI_DPC_RECOVERED 1
519 #define PCI_DPC_RECOVERING 2
520 #define PCI_DEV_REMOVED 3
521
pci_dev_assign_added(struct pci_dev * dev)522 static inline void pci_dev_assign_added(struct pci_dev *dev)
523 {
524 smp_mb__before_atomic();
525 set_bit(PCI_DEV_ADDED, &dev->priv_flags);
526 smp_mb__after_atomic();
527 }
528
pci_dev_test_and_clear_added(struct pci_dev * dev)529 static inline bool pci_dev_test_and_clear_added(struct pci_dev *dev)
530 {
531 return test_and_clear_bit(PCI_DEV_ADDED, &dev->priv_flags);
532 }
533
pci_dev_is_added(const struct pci_dev * dev)534 static inline bool pci_dev_is_added(const struct pci_dev *dev)
535 {
536 return test_bit(PCI_DEV_ADDED, &dev->priv_flags);
537 }
538
pci_dev_test_and_set_removed(struct pci_dev * dev)539 static inline bool pci_dev_test_and_set_removed(struct pci_dev *dev)
540 {
541 return test_and_set_bit(PCI_DEV_REMOVED, &dev->priv_flags);
542 }
543
544 #ifdef CONFIG_PCIEAER
545 #include <linux/aer.h>
546
547 #define AER_MAX_MULTI_ERR_DEVICES 5 /* Not likely to have more */
548
549 struct aer_err_info {
550 struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES];
551 int error_dev_num;
552
553 unsigned int id:16;
554
555 unsigned int severity:2; /* 0:NONFATAL | 1:FATAL | 2:COR */
556 unsigned int __pad1:5;
557 unsigned int multi_error_valid:1;
558
559 unsigned int first_error:5;
560 unsigned int __pad2:2;
561 unsigned int tlp_header_valid:1;
562
563 unsigned int status; /* COR/UNCOR Error Status */
564 unsigned int mask; /* COR/UNCOR Error Mask */
565 struct pcie_tlp_log tlp; /* TLP Header */
566 };
567
568 int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info);
569 void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
570
571 int pcie_read_tlp_log(struct pci_dev *dev, int where, int where2,
572 unsigned int tlp_len, struct pcie_tlp_log *log);
573 unsigned int aer_tlp_log_len(struct pci_dev *dev, u32 aercc);
574 void pcie_print_tlp_log(const struct pci_dev *dev,
575 const struct pcie_tlp_log *log, const char *pfx);
576 #endif /* CONFIG_PCIEAER */
577
578 #ifdef CONFIG_PCIEPORTBUS
579 /* Cached RCEC Endpoint Association */
580 struct rcec_ea {
581 u8 nextbusn;
582 u8 lastbusn;
583 u32 bitmap;
584 };
585 #endif
586
587 #ifdef CONFIG_PCIE_DPC
588 void pci_save_dpc_state(struct pci_dev *dev);
589 void pci_restore_dpc_state(struct pci_dev *dev);
590 void pci_dpc_init(struct pci_dev *pdev);
591 void dpc_process_error(struct pci_dev *pdev);
592 pci_ers_result_t dpc_reset_link(struct pci_dev *pdev);
593 bool pci_dpc_recovered(struct pci_dev *pdev);
594 unsigned int dpc_tlp_log_len(struct pci_dev *dev);
595 #else
pci_save_dpc_state(struct pci_dev * dev)596 static inline void pci_save_dpc_state(struct pci_dev *dev) { }
pci_restore_dpc_state(struct pci_dev * dev)597 static inline void pci_restore_dpc_state(struct pci_dev *dev) { }
pci_dpc_init(struct pci_dev * pdev)598 static inline void pci_dpc_init(struct pci_dev *pdev) { }
pci_dpc_recovered(struct pci_dev * pdev)599 static inline bool pci_dpc_recovered(struct pci_dev *pdev) { return false; }
600 #endif
601
602 #ifdef CONFIG_PCIEPORTBUS
603 void pci_rcec_init(struct pci_dev *dev);
604 void pci_rcec_exit(struct pci_dev *dev);
605 void pcie_link_rcec(struct pci_dev *rcec);
606 void pcie_walk_rcec(struct pci_dev *rcec,
607 int (*cb)(struct pci_dev *, void *),
608 void *userdata);
609 #else
pci_rcec_init(struct pci_dev * dev)610 static inline void pci_rcec_init(struct pci_dev *dev) { }
pci_rcec_exit(struct pci_dev * dev)611 static inline void pci_rcec_exit(struct pci_dev *dev) { }
pcie_link_rcec(struct pci_dev * rcec)612 static inline void pcie_link_rcec(struct pci_dev *rcec) { }
pcie_walk_rcec(struct pci_dev * rcec,int (* cb)(struct pci_dev *,void *),void * userdata)613 static inline void pcie_walk_rcec(struct pci_dev *rcec,
614 int (*cb)(struct pci_dev *, void *),
615 void *userdata) { }
616 #endif
617
618 #ifdef CONFIG_PCI_ATS
619 /* Address Translation Service */
620 void pci_ats_init(struct pci_dev *dev);
621 void pci_restore_ats_state(struct pci_dev *dev);
622 #else
pci_ats_init(struct pci_dev * d)623 static inline void pci_ats_init(struct pci_dev *d) { }
pci_restore_ats_state(struct pci_dev * dev)624 static inline void pci_restore_ats_state(struct pci_dev *dev) { }
625 #endif /* CONFIG_PCI_ATS */
626
627 #ifdef CONFIG_PCI_PRI
628 void pci_pri_init(struct pci_dev *dev);
629 void pci_restore_pri_state(struct pci_dev *pdev);
630 #else
pci_pri_init(struct pci_dev * dev)631 static inline void pci_pri_init(struct pci_dev *dev) { }
pci_restore_pri_state(struct pci_dev * pdev)632 static inline void pci_restore_pri_state(struct pci_dev *pdev) { }
633 #endif
634
635 #ifdef CONFIG_PCI_PASID
636 void pci_pasid_init(struct pci_dev *dev);
637 void pci_restore_pasid_state(struct pci_dev *pdev);
638 #else
pci_pasid_init(struct pci_dev * dev)639 static inline void pci_pasid_init(struct pci_dev *dev) { }
pci_restore_pasid_state(struct pci_dev * pdev)640 static inline void pci_restore_pasid_state(struct pci_dev *pdev) { }
641 #endif
642
643 #ifdef CONFIG_PCI_IOV
644 int pci_iov_init(struct pci_dev *dev);
645 void pci_iov_release(struct pci_dev *dev);
646 void pci_iov_remove(struct pci_dev *dev);
647 void pci_iov_update_resource(struct pci_dev *dev, int resno);
648 resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
649 void pci_restore_iov_state(struct pci_dev *dev);
650 int pci_iov_bus_range(struct pci_bus *bus);
651 extern const struct attribute_group sriov_pf_dev_attr_group;
652 extern const struct attribute_group sriov_vf_dev_attr_group;
653 #else
pci_iov_init(struct pci_dev * dev)654 static inline int pci_iov_init(struct pci_dev *dev)
655 {
656 return -ENODEV;
657 }
pci_iov_release(struct pci_dev * dev)658 static inline void pci_iov_release(struct pci_dev *dev) { }
pci_iov_remove(struct pci_dev * dev)659 static inline void pci_iov_remove(struct pci_dev *dev) { }
pci_restore_iov_state(struct pci_dev * dev)660 static inline void pci_restore_iov_state(struct pci_dev *dev) { }
pci_iov_bus_range(struct pci_bus * bus)661 static inline int pci_iov_bus_range(struct pci_bus *bus)
662 {
663 return 0;
664 }
665
666 #endif /* CONFIG_PCI_IOV */
667
668 #ifdef CONFIG_PCIE_TPH
669 void pci_restore_tph_state(struct pci_dev *dev);
670 void pci_save_tph_state(struct pci_dev *dev);
671 void pci_no_tph(void);
672 void pci_tph_init(struct pci_dev *dev);
673 #else
pci_restore_tph_state(struct pci_dev * dev)674 static inline void pci_restore_tph_state(struct pci_dev *dev) { }
pci_save_tph_state(struct pci_dev * dev)675 static inline void pci_save_tph_state(struct pci_dev *dev) { }
pci_no_tph(void)676 static inline void pci_no_tph(void) { }
pci_tph_init(struct pci_dev * dev)677 static inline void pci_tph_init(struct pci_dev *dev) { }
678 #endif
679
680 #ifdef CONFIG_PCIE_PTM
681 void pci_ptm_init(struct pci_dev *dev);
682 void pci_save_ptm_state(struct pci_dev *dev);
683 void pci_restore_ptm_state(struct pci_dev *dev);
684 void pci_suspend_ptm(struct pci_dev *dev);
685 void pci_resume_ptm(struct pci_dev *dev);
686 #else
pci_ptm_init(struct pci_dev * dev)687 static inline void pci_ptm_init(struct pci_dev *dev) { }
pci_save_ptm_state(struct pci_dev * dev)688 static inline void pci_save_ptm_state(struct pci_dev *dev) { }
pci_restore_ptm_state(struct pci_dev * dev)689 static inline void pci_restore_ptm_state(struct pci_dev *dev) { }
pci_suspend_ptm(struct pci_dev * dev)690 static inline void pci_suspend_ptm(struct pci_dev *dev) { }
pci_resume_ptm(struct pci_dev * dev)691 static inline void pci_resume_ptm(struct pci_dev *dev) { }
692 #endif
693
694 unsigned long pci_cardbus_resource_alignment(struct resource *);
695
pci_resource_alignment(struct pci_dev * dev,struct resource * res)696 static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
697 struct resource *res)
698 {
699 #ifdef CONFIG_PCI_IOV
700 int resno = res - dev->resource;
701
702 if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
703 return pci_sriov_resource_alignment(dev, resno);
704 #endif
705 if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS)
706 return pci_cardbus_resource_alignment(res);
707 return resource_alignment(res);
708 }
709
710 void pci_acs_init(struct pci_dev *dev);
711 #ifdef CONFIG_PCI_QUIRKS
712 int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
713 int pci_dev_specific_enable_acs(struct pci_dev *dev);
714 int pci_dev_specific_disable_acs_redir(struct pci_dev *dev);
715 int pcie_failed_link_retrain(struct pci_dev *dev);
716 #else
pci_dev_specific_acs_enabled(struct pci_dev * dev,u16 acs_flags)717 static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
718 u16 acs_flags)
719 {
720 return -ENOTTY;
721 }
pci_dev_specific_enable_acs(struct pci_dev * dev)722 static inline int pci_dev_specific_enable_acs(struct pci_dev *dev)
723 {
724 return -ENOTTY;
725 }
pci_dev_specific_disable_acs_redir(struct pci_dev * dev)726 static inline int pci_dev_specific_disable_acs_redir(struct pci_dev *dev)
727 {
728 return -ENOTTY;
729 }
pcie_failed_link_retrain(struct pci_dev * dev)730 static inline int pcie_failed_link_retrain(struct pci_dev *dev)
731 {
732 return -ENOTTY;
733 }
734 #endif
735
736 /* PCI error reporting and recovery */
737 pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
738 pci_channel_state_t state,
739 pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev));
740
741 bool pcie_wait_for_link(struct pci_dev *pdev, bool active);
742 int pcie_retrain_link(struct pci_dev *pdev, bool use_lt);
743
744 /* ASPM-related functionality we need even without CONFIG_PCIEASPM */
745 void pci_save_ltr_state(struct pci_dev *dev);
746 void pci_restore_ltr_state(struct pci_dev *dev);
747 void pci_configure_aspm_l1ss(struct pci_dev *dev);
748 void pci_save_aspm_l1ss_state(struct pci_dev *dev);
749 void pci_restore_aspm_l1ss_state(struct pci_dev *dev);
750
751 #ifdef CONFIG_PCIEASPM
752 void pcie_aspm_init_link_state(struct pci_dev *pdev);
753 void pcie_aspm_exit_link_state(struct pci_dev *pdev);
754 void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked);
755 void pcie_aspm_powersave_config_link(struct pci_dev *pdev);
756 void pci_configure_ltr(struct pci_dev *pdev);
757 void pci_bridge_reconfigure_ltr(struct pci_dev *pdev);
758 #else
pcie_aspm_init_link_state(struct pci_dev * pdev)759 static inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { }
pcie_aspm_exit_link_state(struct pci_dev * pdev)760 static inline void pcie_aspm_exit_link_state(struct pci_dev *pdev) { }
pcie_aspm_pm_state_change(struct pci_dev * pdev,bool locked)761 static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked) { }
pcie_aspm_powersave_config_link(struct pci_dev * pdev)762 static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { }
pci_configure_ltr(struct pci_dev * pdev)763 static inline void pci_configure_ltr(struct pci_dev *pdev) { }
pci_bridge_reconfigure_ltr(struct pci_dev * pdev)764 static inline void pci_bridge_reconfigure_ltr(struct pci_dev *pdev) { }
765 #endif
766
767 #ifdef CONFIG_PCIE_ECRC
768 void pcie_set_ecrc_checking(struct pci_dev *dev);
769 void pcie_ecrc_get_policy(char *str);
770 #else
pcie_set_ecrc_checking(struct pci_dev * dev)771 static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { }
pcie_ecrc_get_policy(char * str)772 static inline void pcie_ecrc_get_policy(char *str) { }
773 #endif
774
775 #ifdef CONFIG_PCIEPORTBUS
776 void pcie_reset_lbms_count(struct pci_dev *port);
777 int pcie_lbms_count(struct pci_dev *port, unsigned long *val);
778 #else
pcie_reset_lbms_count(struct pci_dev * port)779 static inline void pcie_reset_lbms_count(struct pci_dev *port) {}
pcie_lbms_count(struct pci_dev * port,unsigned long * val)780 static inline int pcie_lbms_count(struct pci_dev *port, unsigned long *val)
781 {
782 return -EOPNOTSUPP;
783 }
784 #endif
785
786 struct pci_dev_reset_methods {
787 u16 vendor;
788 u16 device;
789 int (*reset)(struct pci_dev *dev, bool probe);
790 };
791
792 struct pci_reset_fn_method {
793 int (*reset_fn)(struct pci_dev *pdev, bool probe);
794 char *name;
795 };
796 extern const struct pci_reset_fn_method pci_reset_fn_methods[];
797
798 #ifdef CONFIG_PCI_QUIRKS
799 int pci_dev_specific_reset(struct pci_dev *dev, bool probe);
800 #else
pci_dev_specific_reset(struct pci_dev * dev,bool probe)801 static inline int pci_dev_specific_reset(struct pci_dev *dev, bool probe)
802 {
803 return -ENOTTY;
804 }
805 #endif
806
807 #if defined(CONFIG_PCI_QUIRKS) && defined(CONFIG_ARM64)
808 int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment,
809 struct resource *res);
810 #else
acpi_get_rc_resources(struct device * dev,const char * hid,u16 segment,struct resource * res)811 static inline int acpi_get_rc_resources(struct device *dev, const char *hid,
812 u16 segment, struct resource *res)
813 {
814 return -ENODEV;
815 }
816 #endif
817
818 int pci_rebar_get_current_size(struct pci_dev *pdev, int bar);
819 int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size);
pci_rebar_size_to_bytes(int size)820 static inline u64 pci_rebar_size_to_bytes(int size)
821 {
822 return 1ULL << (size + 20);
823 }
824
825 struct device_node;
826
827 #ifdef CONFIG_OF
828 int of_get_pci_domain_nr(struct device_node *node);
829 int of_pci_get_max_link_speed(struct device_node *node);
830 u32 of_pci_get_slot_power_limit(struct device_node *node,
831 u8 *slot_power_limit_value,
832 u8 *slot_power_limit_scale);
833 bool of_pci_preserve_config(struct device_node *node);
834 int pci_set_of_node(struct pci_dev *dev);
835 void pci_release_of_node(struct pci_dev *dev);
836 void pci_set_bus_of_node(struct pci_bus *bus);
837 void pci_release_bus_of_node(struct pci_bus *bus);
838
839 int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge);
840 bool of_pci_supply_present(struct device_node *np);
841
842 #else
843 static inline int
of_get_pci_domain_nr(struct device_node * node)844 of_get_pci_domain_nr(struct device_node *node)
845 {
846 return -1;
847 }
848
849 static inline int
of_pci_get_max_link_speed(struct device_node * node)850 of_pci_get_max_link_speed(struct device_node *node)
851 {
852 return -EINVAL;
853 }
854
855 static inline u32
of_pci_get_slot_power_limit(struct device_node * node,u8 * slot_power_limit_value,u8 * slot_power_limit_scale)856 of_pci_get_slot_power_limit(struct device_node *node,
857 u8 *slot_power_limit_value,
858 u8 *slot_power_limit_scale)
859 {
860 if (slot_power_limit_value)
861 *slot_power_limit_value = 0;
862 if (slot_power_limit_scale)
863 *slot_power_limit_scale = 0;
864 return 0;
865 }
866
of_pci_preserve_config(struct device_node * node)867 static inline bool of_pci_preserve_config(struct device_node *node)
868 {
869 return false;
870 }
871
pci_set_of_node(struct pci_dev * dev)872 static inline int pci_set_of_node(struct pci_dev *dev) { return 0; }
pci_release_of_node(struct pci_dev * dev)873 static inline void pci_release_of_node(struct pci_dev *dev) { }
pci_set_bus_of_node(struct pci_bus * bus)874 static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
pci_release_bus_of_node(struct pci_bus * bus)875 static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
876
devm_of_pci_bridge_init(struct device * dev,struct pci_host_bridge * bridge)877 static inline int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge)
878 {
879 return 0;
880 }
881
of_pci_supply_present(struct device_node * np)882 static inline bool of_pci_supply_present(struct device_node *np)
883 {
884 return false;
885 }
886 #endif /* CONFIG_OF */
887
888 struct of_changeset;
889
890 #ifdef CONFIG_PCI_DYNAMIC_OF_NODES
891 void of_pci_make_dev_node(struct pci_dev *pdev);
892 void of_pci_remove_node(struct pci_dev *pdev);
893 int of_pci_add_properties(struct pci_dev *pdev, struct of_changeset *ocs,
894 struct device_node *np);
895 #else
of_pci_make_dev_node(struct pci_dev * pdev)896 static inline void of_pci_make_dev_node(struct pci_dev *pdev) { }
of_pci_remove_node(struct pci_dev * pdev)897 static inline void of_pci_remove_node(struct pci_dev *pdev) { }
898 #endif
899
900 #ifdef CONFIG_PCIEAER
901 void pci_no_aer(void);
902 void pci_aer_init(struct pci_dev *dev);
903 void pci_aer_exit(struct pci_dev *dev);
904 extern const struct attribute_group aer_stats_attr_group;
905 void pci_aer_clear_fatal_status(struct pci_dev *dev);
906 int pci_aer_clear_status(struct pci_dev *dev);
907 int pci_aer_raw_clear_status(struct pci_dev *dev);
908 void pci_save_aer_state(struct pci_dev *dev);
909 void pci_restore_aer_state(struct pci_dev *dev);
910 #else
pci_no_aer(void)911 static inline void pci_no_aer(void) { }
pci_aer_init(struct pci_dev * d)912 static inline void pci_aer_init(struct pci_dev *d) { }
pci_aer_exit(struct pci_dev * d)913 static inline void pci_aer_exit(struct pci_dev *d) { }
pci_aer_clear_fatal_status(struct pci_dev * dev)914 static inline void pci_aer_clear_fatal_status(struct pci_dev *dev) { }
pci_aer_clear_status(struct pci_dev * dev)915 static inline int pci_aer_clear_status(struct pci_dev *dev) { return -EINVAL; }
pci_aer_raw_clear_status(struct pci_dev * dev)916 static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL; }
pci_save_aer_state(struct pci_dev * dev)917 static inline void pci_save_aer_state(struct pci_dev *dev) { }
pci_restore_aer_state(struct pci_dev * dev)918 static inline void pci_restore_aer_state(struct pci_dev *dev) { }
919 #endif
920
921 #ifdef CONFIG_ACPI
922 bool pci_acpi_preserve_config(struct pci_host_bridge *bridge);
923 int pci_acpi_program_hp_params(struct pci_dev *dev);
924 extern const struct attribute_group pci_dev_acpi_attr_group;
925 void pci_set_acpi_fwnode(struct pci_dev *dev);
926 int pci_dev_acpi_reset(struct pci_dev *dev, bool probe);
927 bool acpi_pci_power_manageable(struct pci_dev *dev);
928 bool acpi_pci_bridge_d3(struct pci_dev *dev);
929 int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state);
930 pci_power_t acpi_pci_get_power_state(struct pci_dev *dev);
931 void acpi_pci_refresh_power_state(struct pci_dev *dev);
932 int acpi_pci_wakeup(struct pci_dev *dev, bool enable);
933 bool acpi_pci_need_resume(struct pci_dev *dev);
934 pci_power_t acpi_pci_choose_state(struct pci_dev *pdev);
935 #else
pci_acpi_preserve_config(struct pci_host_bridge * bridge)936 static inline bool pci_acpi_preserve_config(struct pci_host_bridge *bridge)
937 {
938 return false;
939 }
pci_dev_acpi_reset(struct pci_dev * dev,bool probe)940 static inline int pci_dev_acpi_reset(struct pci_dev *dev, bool probe)
941 {
942 return -ENOTTY;
943 }
pci_set_acpi_fwnode(struct pci_dev * dev)944 static inline void pci_set_acpi_fwnode(struct pci_dev *dev) { }
pci_acpi_program_hp_params(struct pci_dev * dev)945 static inline int pci_acpi_program_hp_params(struct pci_dev *dev)
946 {
947 return -ENODEV;
948 }
acpi_pci_power_manageable(struct pci_dev * dev)949 static inline bool acpi_pci_power_manageable(struct pci_dev *dev)
950 {
951 return false;
952 }
acpi_pci_bridge_d3(struct pci_dev * dev)953 static inline bool acpi_pci_bridge_d3(struct pci_dev *dev)
954 {
955 return false;
956 }
acpi_pci_set_power_state(struct pci_dev * dev,pci_power_t state)957 static inline int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
958 {
959 return -ENODEV;
960 }
acpi_pci_get_power_state(struct pci_dev * dev)961 static inline pci_power_t acpi_pci_get_power_state(struct pci_dev *dev)
962 {
963 return PCI_UNKNOWN;
964 }
acpi_pci_refresh_power_state(struct pci_dev * dev)965 static inline void acpi_pci_refresh_power_state(struct pci_dev *dev) { }
acpi_pci_wakeup(struct pci_dev * dev,bool enable)966 static inline int acpi_pci_wakeup(struct pci_dev *dev, bool enable)
967 {
968 return -ENODEV;
969 }
acpi_pci_need_resume(struct pci_dev * dev)970 static inline bool acpi_pci_need_resume(struct pci_dev *dev)
971 {
972 return false;
973 }
acpi_pci_choose_state(struct pci_dev * pdev)974 static inline pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
975 {
976 return PCI_POWER_ERROR;
977 }
978 #endif
979
980 #ifdef CONFIG_PCIEASPM
981 extern const struct attribute_group aspm_ctrl_attr_group;
982 #endif
983
984 #ifdef CONFIG_X86_INTEL_MID
985 bool pci_use_mid_pm(void);
986 int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state);
987 pci_power_t mid_pci_get_power_state(struct pci_dev *pdev);
988 #else
pci_use_mid_pm(void)989 static inline bool pci_use_mid_pm(void)
990 {
991 return false;
992 }
mid_pci_set_power_state(struct pci_dev * pdev,pci_power_t state)993 static inline int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state)
994 {
995 return -ENODEV;
996 }
mid_pci_get_power_state(struct pci_dev * pdev)997 static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev)
998 {
999 return PCI_UNKNOWN;
1000 }
1001 #endif
1002
1003 int pcim_intx(struct pci_dev *dev, int enable);
1004 int pcim_request_region_exclusive(struct pci_dev *pdev, int bar,
1005 const char *name);
1006 void pcim_release_region(struct pci_dev *pdev, int bar);
1007
1008 /*
1009 * Config Address for PCI Configuration Mechanism #1
1010 *
1011 * See PCI Local Bus Specification, Revision 3.0,
1012 * Section 3.2.2.3.2, Figure 3-2, p. 50.
1013 */
1014
1015 #define PCI_CONF1_BUS_SHIFT 16 /* Bus number */
1016 #define PCI_CONF1_DEV_SHIFT 11 /* Device number */
1017 #define PCI_CONF1_FUNC_SHIFT 8 /* Function number */
1018
1019 #define PCI_CONF1_BUS_MASK 0xff
1020 #define PCI_CONF1_DEV_MASK 0x1f
1021 #define PCI_CONF1_FUNC_MASK 0x7
1022 #define PCI_CONF1_REG_MASK 0xfc /* Limit aligned offset to a maximum of 256B */
1023
1024 #define PCI_CONF1_ENABLE BIT(31)
1025 #define PCI_CONF1_BUS(x) (((x) & PCI_CONF1_BUS_MASK) << PCI_CONF1_BUS_SHIFT)
1026 #define PCI_CONF1_DEV(x) (((x) & PCI_CONF1_DEV_MASK) << PCI_CONF1_DEV_SHIFT)
1027 #define PCI_CONF1_FUNC(x) (((x) & PCI_CONF1_FUNC_MASK) << PCI_CONF1_FUNC_SHIFT)
1028 #define PCI_CONF1_REG(x) ((x) & PCI_CONF1_REG_MASK)
1029
1030 #define PCI_CONF1_ADDRESS(bus, dev, func, reg) \
1031 (PCI_CONF1_ENABLE | \
1032 PCI_CONF1_BUS(bus) | \
1033 PCI_CONF1_DEV(dev) | \
1034 PCI_CONF1_FUNC(func) | \
1035 PCI_CONF1_REG(reg))
1036
1037 /*
1038 * Extension of PCI Config Address for accessing extended PCIe registers
1039 *
1040 * No standardized specification, but used on lot of non-ECAM-compliant ARM SoCs
1041 * or on AMD Barcelona and new CPUs. Reserved bits [27:24] of PCI Config Address
1042 * are used for specifying additional 4 high bits of PCI Express register.
1043 */
1044
1045 #define PCI_CONF1_EXT_REG_SHIFT 16
1046 #define PCI_CONF1_EXT_REG_MASK 0xf00
1047 #define PCI_CONF1_EXT_REG(x) (((x) & PCI_CONF1_EXT_REG_MASK) << PCI_CONF1_EXT_REG_SHIFT)
1048
1049 #define PCI_CONF1_EXT_ADDRESS(bus, dev, func, reg) \
1050 (PCI_CONF1_ADDRESS(bus, dev, func, reg) | \
1051 PCI_CONF1_EXT_REG(reg))
1052
1053 #endif /* DRIVERS_PCI_H */
1054