]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/pci/pci.h
scsi: qedi: Fix return code in qedi_ep_connect()
[karo-tx-linux.git] / drivers / pci / pci.h
1 #ifndef DRIVERS_PCI_H
2 #define DRIVERS_PCI_H
3
4 #define PCI_FIND_CAP_TTL        48
5
6 #define PCI_VSEC_ID_INTEL_TBT   0x1234  /* Thunderbolt */
7
8 extern const unsigned char pcie_link_speed[];
9
10 bool pcie_cap_has_lnkctl(const struct pci_dev *dev);
11
12 /* Functions internal to the PCI core code */
13
14 int pci_create_sysfs_dev_files(struct pci_dev *pdev);
15 void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
16 #if !defined(CONFIG_DMI) && !defined(CONFIG_ACPI)
17 static inline void pci_create_firmware_label_files(struct pci_dev *pdev)
18 { return; }
19 static inline void pci_remove_firmware_label_files(struct pci_dev *pdev)
20 { return; }
21 #else
22 void pci_create_firmware_label_files(struct pci_dev *pdev);
23 void pci_remove_firmware_label_files(struct pci_dev *pdev);
24 #endif
25 void pci_cleanup_rom(struct pci_dev *dev);
26
27 enum pci_mmap_api {
28         PCI_MMAP_SYSFS, /* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */
29         PCI_MMAP_PROCFS /* mmap on /proc/bus/pci/<BDF> */
30 };
31 int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai,
32                   enum pci_mmap_api mmap_api);
33
34 int pci_probe_reset_function(struct pci_dev *dev);
35
36 /**
37  * struct pci_platform_pm_ops - Firmware PM callbacks
38  *
39  * @is_manageable: returns 'true' if given device is power manageable by the
40  *                 platform firmware
41  *
42  * @set_state: invokes the platform firmware to set the device's power state
43  *
44  * @get_state: queries the platform firmware for a device's current power state
45  *
46  * @choose_state: returns PCI power state of given device preferred by the
47  *                platform; to be used during system-wide transitions from a
48  *                sleeping state to the working state and vice versa
49  *
50  * @set_wakeup: enables/disables wakeup capability for the device
51  *
52  * @need_resume: returns 'true' if the given device (which is currently
53  *              suspended) needs to be resumed to be configured for system
54  *              wakeup.
55  *
56  * If given platform is generally capable of power managing PCI devices, all of
57  * these callbacks are mandatory.
58  */
59 struct pci_platform_pm_ops {
60         bool (*is_manageable)(struct pci_dev *dev);
61         int (*set_state)(struct pci_dev *dev, pci_power_t state);
62         pci_power_t (*get_state)(struct pci_dev *dev);
63         pci_power_t (*choose_state)(struct pci_dev *dev);
64         int (*set_wakeup)(struct pci_dev *dev, bool enable);
65         bool (*need_resume)(struct pci_dev *dev);
66 };
67
68 int pci_set_platform_pm(const struct pci_platform_pm_ops *ops);
69 void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
70 void pci_power_up(struct pci_dev *dev);
71 void pci_disable_enabled_device(struct pci_dev *dev);
72 int pci_finish_runtime_suspend(struct pci_dev *dev);
73 int __pci_pme_wakeup(struct pci_dev *dev, void *ign);
74 bool pci_dev_keep_suspended(struct pci_dev *dev);
75 void pci_dev_complete_resume(struct pci_dev *pci_dev);
76 void pci_config_pm_runtime_get(struct pci_dev *dev);
77 void pci_config_pm_runtime_put(struct pci_dev *dev);
78 void pci_pm_init(struct pci_dev *dev);
79 void pci_ea_init(struct pci_dev *dev);
80 void pci_allocate_cap_save_buffers(struct pci_dev *dev);
81 void pci_free_cap_save_buffers(struct pci_dev *dev);
82 bool pci_bridge_d3_possible(struct pci_dev *dev);
83 void pci_bridge_d3_update(struct pci_dev *dev);
84
85 static inline void pci_wakeup_event(struct pci_dev *dev)
86 {
87         /* Wait 100 ms before the system can be put into a sleep state. */
88         pm_wakeup_event(&dev->dev, 100);
89 }
90
91 static inline bool pci_has_subordinate(struct pci_dev *pci_dev)
92 {
93         return !!(pci_dev->subordinate);
94 }
95
96 static inline bool pci_power_manageable(struct pci_dev *pci_dev)
97 {
98         /*
99          * Currently we allow normal PCI devices and PCI bridges transition
100          * into D3 if their bridge_d3 is set.
101          */
102         return !pci_has_subordinate(pci_dev) || pci_dev->bridge_d3;
103 }
104
105 struct pci_vpd_ops {
106         ssize_t (*read)(struct pci_dev *dev, loff_t pos, size_t count, void *buf);
107         ssize_t (*write)(struct pci_dev *dev, loff_t pos, size_t count, const void *buf);
108         int (*set_size)(struct pci_dev *dev, size_t len);
109 };
110
111 struct pci_vpd {
112         const struct pci_vpd_ops *ops;
113         struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
114         struct mutex    lock;
115         unsigned int    len;
116         u16             flag;
117         u8              cap;
118         u8              busy:1;
119         u8              valid:1;
120 };
121
122 int pci_vpd_init(struct pci_dev *dev);
123 void pci_vpd_release(struct pci_dev *dev);
124
125 /* PCI /proc functions */
126 #ifdef CONFIG_PROC_FS
127 int pci_proc_attach_device(struct pci_dev *dev);
128 int pci_proc_detach_device(struct pci_dev *dev);
129 int pci_proc_detach_bus(struct pci_bus *bus);
130 #else
131 static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; }
132 static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; }
133 static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
134 #endif
135
136 /* Functions for PCI Hotplug drivers to use */
137 int pci_hp_add_bridge(struct pci_dev *dev);
138
139 #ifdef HAVE_PCI_LEGACY
140 void pci_create_legacy_files(struct pci_bus *bus);
141 void pci_remove_legacy_files(struct pci_bus *bus);
142 #else
143 static inline void pci_create_legacy_files(struct pci_bus *bus) { return; }
144 static inline void pci_remove_legacy_files(struct pci_bus *bus) { return; }
145 #endif
146
147 /* Lock for read/write access to pci device and bus lists */
148 extern struct rw_semaphore pci_bus_sem;
149
150 extern raw_spinlock_t pci_lock;
151
152 extern unsigned int pci_pm_d3_delay;
153
154 #ifdef CONFIG_PCI_MSI
155 void pci_no_msi(void);
156 #else
157 static inline void pci_no_msi(void) { }
158 #endif
159
160 static inline void pci_msi_set_enable(struct pci_dev *dev, int enable)
161 {
162         u16 control;
163
164         pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control);
165         control &= ~PCI_MSI_FLAGS_ENABLE;
166         if (enable)
167                 control |= PCI_MSI_FLAGS_ENABLE;
168         pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control);
169 }
170
171 static inline void pci_msix_clear_and_set_ctrl(struct pci_dev *dev, u16 clear, u16 set)
172 {
173         u16 ctrl;
174
175         pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &ctrl);
176         ctrl &= ~clear;
177         ctrl |= set;
178         pci_write_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, ctrl);
179 }
180
181 void pci_realloc_get_opt(char *);
182
183 static inline int pci_no_d1d2(struct pci_dev *dev)
184 {
185         unsigned int parent_dstates = 0;
186
187         if (dev->bus->self)
188                 parent_dstates = dev->bus->self->no_d1d2;
189         return (dev->no_d1d2 || parent_dstates);
190
191 }
192 extern const struct attribute_group *pci_dev_groups[];
193 extern const struct attribute_group *pcibus_groups[];
194 extern struct device_type pci_dev_type;
195 extern const struct attribute_group *pci_bus_groups[];
196
197
198 /**
199  * pci_match_one_device - Tell if a PCI device structure has a matching
200  *                        PCI device id structure
201  * @id: single PCI device id structure to match
202  * @dev: the PCI device structure to match against
203  *
204  * Returns the matching pci_device_id structure or %NULL if there is no match.
205  */
206 static inline const struct pci_device_id *
207 pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
208 {
209         if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) &&
210             (id->device == PCI_ANY_ID || id->device == dev->device) &&
211             (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
212             (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) &&
213             !((id->class ^ dev->class) & id->class_mask))
214                 return id;
215         return NULL;
216 }
217
218 /* PCI slot sysfs helper code */
219 #define to_pci_slot(s) container_of(s, struct pci_slot, kobj)
220
221 extern struct kset *pci_slots_kset;
222
223 struct pci_slot_attribute {
224         struct attribute attr;
225         ssize_t (*show)(struct pci_slot *, char *);
226         ssize_t (*store)(struct pci_slot *, const char *, size_t);
227 };
228 #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr)
229
230 enum pci_bar_type {
231         pci_bar_unknown,        /* Standard PCI BAR probe */
232         pci_bar_io,             /* An io port BAR */
233         pci_bar_mem32,          /* A 32-bit memory BAR */
234         pci_bar_mem64,          /* A 64-bit memory BAR */
235 };
236
237 bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
238                                 int crs_timeout);
239 int pci_setup_device(struct pci_dev *dev);
240 int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
241                     struct resource *res, unsigned int reg);
242 void pci_configure_ari(struct pci_dev *dev);
243 void __pci_bus_size_bridges(struct pci_bus *bus,
244                         struct list_head *realloc_head);
245 void __pci_bus_assign_resources(const struct pci_bus *bus,
246                                 struct list_head *realloc_head,
247                                 struct list_head *fail_head);
248 bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
249
250 void pci_reassigndev_resource_alignment(struct pci_dev *dev);
251 void pci_disable_bridge_window(struct pci_dev *dev);
252
253 /* Single Root I/O Virtualization */
254 struct pci_sriov {
255         int pos;                /* capability position */
256         int nres;               /* number of resources */
257         u32 cap;                /* SR-IOV Capabilities */
258         u16 ctrl;               /* SR-IOV Control */
259         u16 total_VFs;          /* total VFs associated with the PF */
260         u16 initial_VFs;        /* initial VFs associated with the PF */
261         u16 num_VFs;            /* number of VFs available */
262         u16 offset;             /* first VF Routing ID offset */
263         u16 stride;             /* following VF stride */
264         u32 pgsz;               /* page size for BAR alignment */
265         u8 link;                /* Function Dependency Link */
266         u8 max_VF_buses;        /* max buses consumed by VFs */
267         u16 driver_max_VFs;     /* max num VFs driver supports */
268         struct pci_dev *dev;    /* lowest numbered PF */
269         struct pci_dev *self;   /* this PF */
270         resource_size_t barsz[PCI_SRIOV_NUM_BARS];      /* VF BAR size */
271         bool drivers_autoprobe; /* auto probing of VFs by driver */
272 };
273
274 /* pci_dev priv_flags */
275 #define PCI_DEV_DISCONNECTED 0
276
277 static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused)
278 {
279         set_bit(PCI_DEV_DISCONNECTED, &dev->priv_flags);
280         return 0;
281 }
282
283 static inline bool pci_dev_is_disconnected(const struct pci_dev *dev)
284 {
285         return test_bit(PCI_DEV_DISCONNECTED, &dev->priv_flags);
286 }
287
288 #ifdef CONFIG_PCI_ATS
289 void pci_restore_ats_state(struct pci_dev *dev);
290 #else
291 static inline void pci_restore_ats_state(struct pci_dev *dev)
292 {
293 }
294 #endif /* CONFIG_PCI_ATS */
295
296 #ifdef CONFIG_PCI_IOV
297 int pci_iov_init(struct pci_dev *dev);
298 void pci_iov_release(struct pci_dev *dev);
299 void pci_iov_update_resource(struct pci_dev *dev, int resno);
300 resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
301 void pci_restore_iov_state(struct pci_dev *dev);
302 int pci_iov_bus_range(struct pci_bus *bus);
303
304 #else
305 static inline int pci_iov_init(struct pci_dev *dev)
306 {
307         return -ENODEV;
308 }
309 static inline void pci_iov_release(struct pci_dev *dev)
310
311 {
312 }
313 static inline void pci_restore_iov_state(struct pci_dev *dev)
314 {
315 }
316 static inline int pci_iov_bus_range(struct pci_bus *bus)
317 {
318         return 0;
319 }
320
321 #endif /* CONFIG_PCI_IOV */
322
323 unsigned long pci_cardbus_resource_alignment(struct resource *);
324
325 static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
326                                                      struct resource *res)
327 {
328 #ifdef CONFIG_PCI_IOV
329         int resno = res - dev->resource;
330
331         if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
332                 return pci_sriov_resource_alignment(dev, resno);
333 #endif
334         if (dev->class >> 8  == PCI_CLASS_BRIDGE_CARDBUS)
335                 return pci_cardbus_resource_alignment(res);
336         return resource_alignment(res);
337 }
338
339 void pci_enable_acs(struct pci_dev *dev);
340
341 #ifdef CONFIG_PCIE_PTM
342 void pci_ptm_init(struct pci_dev *dev);
343 #else
344 static inline void pci_ptm_init(struct pci_dev *dev) { }
345 #endif
346
347 struct pci_dev_reset_methods {
348         u16 vendor;
349         u16 device;
350         int (*reset)(struct pci_dev *dev, int probe);
351 };
352
353 #ifdef CONFIG_PCI_QUIRKS
354 int pci_dev_specific_reset(struct pci_dev *dev, int probe);
355 #else
356 static inline int pci_dev_specific_reset(struct pci_dev *dev, int probe)
357 {
358         return -ENOTTY;
359 }
360 #endif
361
362 #if defined(CONFIG_PCI_QUIRKS) && defined(CONFIG_ARM64)
363 int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment,
364                           struct resource *res);
365 #endif
366
367 #endif /* DRIVERS_PCI_H */