hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/arch/powerpc/platforms/powernv/pci.h
....@@ -2,14 +2,12 @@
22 #ifndef __POWERNV_PCI_H
33 #define __POWERNV_PCI_H
44
5
+#include <linux/compiler.h> /* for __printf */
56 #include <linux/iommu.h>
67 #include <asm/iommu.h>
78 #include <asm/msi_bitmap.h>
89
910 struct pci_dn;
10
-
11
-/* Maximum possible number of ATSD MMIO registers per NPU */
12
-#define NV_NMMU_ATSD_REGS 8
1311
1412 enum pnv_phb_type {
1513 PNV_PHB_IODA1 = 0,
....@@ -34,6 +32,24 @@
3432 #define PNV_IODA_PE_MASTER (1 << 3) /* Master PE in compound case */
3533 #define PNV_IODA_PE_SLAVE (1 << 4) /* Slave PE in compound case */
3634 #define PNV_IODA_PE_VF (1 << 5) /* PE for one VF */
35
+
36
+/*
37
+ * A brief note on PNV_IODA_PE_BUS_ALL
38
+ *
39
+ * This is needed because of the behaviour of PCIe-to-PCI bridges. The PHB uses
40
+ * the Requester ID field of the PCIe request header to determine the device
41
+ * (and PE) that initiated a DMA. In legacy PCI individual memory read/write
42
+ * requests aren't tagged with the RID. To work around this the PCIe-to-PCI
43
+ * bridge will use (secondary_bus_no << 8) | 0x00 as the RID on the PCIe side.
44
+ *
45
+ * PCIe-to-X bridges have a similar issue even though PCI-X requests also have
46
+ * a RID in the transaction header. The PCIe-to-X bridge is permitted to "take
47
+ * ownership" of a transaction by a PCI-X device when forwarding it to the PCIe
48
+ * side of the bridge.
49
+ *
50
+ * To work around these problems we use the BUS_ALL flag since every subordinate
51
+ * bus of the bridge should go into the same PE.
52
+ */
3753
3854 /* Indicates operations are frozen for a PE: MMIO in PESTA & DMA in PESTB. */
3955 #define PNV_IODA_STOPPED_STATE 0x8000000000000000
....@@ -65,12 +81,20 @@
6581
6682 /* "Base" iommu table, ie, 4K TCEs, 32-bit DMA */
6783 struct iommu_table_group table_group;
84
+ struct npu_comp *npucomp;
6885
6986 /* 64-bit TCE bypass region */
7087 bool tce_bypass_enabled;
7188 uint64_t tce_bypass_base;
7289
73
- /* MSIs. MVE index is identical for for 32 and 64 bit MSI
90
+ /*
91
+ * Used to track whether we've done DMA setup for this PE or not. We
92
+ * want to defer allocating TCE tables, etc until we've added a
93
+ * non-bridge device to the PE.
94
+ */
95
+ bool dma_setup_done;
96
+
97
+ /* MSIs. MVE index is identical for 32 and 64 bit MSI
7498 * and -1 if not supported. (It's actually identical to the
7599 * PE number)
76100 */
....@@ -79,9 +103,6 @@
79103 /* PEs in compound case */
80104 struct pnv_ioda_pe *master;
81105 struct list_head slaves;
82
-
83
- /* PCI peer-to-peer*/
84
- int p2p_initiator_count;
85106
86107 /* Link in list of PE#s */
87108 struct list_head list;
....@@ -106,20 +127,13 @@
106127 struct dentry *dbgfs;
107128 #endif
108129
109
-#ifdef CONFIG_PCI_MSI
110130 unsigned int msi_base;
111131 unsigned int msi32_support;
112132 struct msi_bitmap msi_bmp;
113
-#endif
114133 int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
115134 unsigned int hwirq, unsigned int virq,
116135 unsigned int is_64, struct msi_msg *msg);
117
- void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
118
- void (*fixup_phb)(struct pci_controller *hose);
119136 int (*init_m64)(struct pnv_phb *phb);
120
- void (*reserve_m64_pe)(struct pci_bus *bus,
121
- unsigned long *pe_bitmap, bool all);
122
- struct pnv_ioda_pe *(*pick_m64_pe)(struct pci_bus *bus, bool all);
123137 int (*get_pe_state)(struct pnv_phb *phb, int pe_no);
124138 void (*freeze_pe)(struct pnv_phb *phb, int pe_no);
125139 int (*unfreeze_pe)(struct pnv_phb *phb, int pe_no, int opt);
....@@ -129,7 +143,6 @@
129143 unsigned int total_pe_num;
130144 unsigned int reserved_pe_idx;
131145 unsigned int root_pe_idx;
132
- bool root_pe_populated;
133146
134147 /* 32-bit MMIO window */
135148 unsigned int m32_size;
....@@ -141,6 +154,7 @@
141154 unsigned long m64_size;
142155 unsigned long m64_segsize;
143156 unsigned long m64_base;
157
+#define MAX_M64_BARS 64
144158 unsigned long m64_bar_alloc;
145159
146160 /* IO ports */
....@@ -179,22 +193,90 @@
179193 /* PHB and hub diagnostics */
180194 unsigned int diag_data_size;
181195 u8 *diag_data;
182
-
183
- /* Nvlink2 data */
184
- struct npu {
185
- int index;
186
- __be64 *mmio_atsd_regs[NV_NMMU_ATSD_REGS];
187
- unsigned int mmio_atsd_count;
188
-
189
- /* Bitmask for MMIO register usage */
190
- unsigned long mmio_atsd_usage;
191
-
192
- /* Do we need to explicitly flush the nest mmu? */
193
- bool nmmu_flush;
194
- } npu;
195
-
196
- int p2p_target_count;
197196 };
197
+
198
+
199
+/* IODA PE management */
200
+
201
+static inline bool pnv_pci_is_m64(struct pnv_phb *phb, struct resource *r)
202
+{
203
+ /*
204
+ * WARNING: We cannot rely on the resource flags. The Linux PCI
205
+ * allocation code sometimes decides to put a 64-bit prefetchable
206
+ * BAR in the 32-bit window, so we have to compare the addresses.
207
+ *
208
+ * For simplicity we only test resource start.
209
+ */
210
+ return (r->start >= phb->ioda.m64_base &&
211
+ r->start < (phb->ioda.m64_base + phb->ioda.m64_size));
212
+}
213
+
214
+static inline bool pnv_pci_is_m64_flags(unsigned long resource_flags)
215
+{
216
+ unsigned long flags = (IORESOURCE_MEM_64 | IORESOURCE_PREFETCH);
217
+
218
+ return (resource_flags & flags) == flags;
219
+}
220
+
221
+int pnv_ioda_configure_pe(struct pnv_phb *phb, struct pnv_ioda_pe *pe);
222
+int pnv_ioda_deconfigure_pe(struct pnv_phb *phb, struct pnv_ioda_pe *pe);
223
+
224
+void pnv_pci_ioda2_setup_dma_pe(struct pnv_phb *phb, struct pnv_ioda_pe *pe);
225
+void pnv_pci_ioda2_release_pe_dma(struct pnv_ioda_pe *pe);
226
+
227
+struct pnv_ioda_pe *pnv_ioda_alloc_pe(struct pnv_phb *phb, int count);
228
+void pnv_ioda_free_pe(struct pnv_ioda_pe *pe);
229
+
230
+#ifdef CONFIG_PCI_IOV
231
+/*
232
+ * For SR-IOV we want to put each VF's MMIO resource in to a separate PE.
233
+ * This requires a bit of acrobatics with the MMIO -> PE configuration
234
+ * and this structure is used to keep track of it all.
235
+ */
236
+struct pnv_iov_data {
237
+ /* number of VFs enabled */
238
+ u16 num_vfs;
239
+
240
+ /* pointer to the array of VF PEs. num_vfs long*/
241
+ struct pnv_ioda_pe *vf_pe_arr;
242
+
243
+ /* Did we map the VF BAR with single-PE IODA BARs? */
244
+ bool m64_single_mode[PCI_SRIOV_NUM_BARS];
245
+
246
+ /*
247
+ * True if we're using any segmented windows. In that case we need
248
+ * shift the start of the IOV resource the segment corresponding to
249
+ * the allocated PE.
250
+ */
251
+ bool need_shift;
252
+
253
+ /*
254
+ * Bit mask used to track which m64 windows are used to map the
255
+ * SR-IOV BARs for this device.
256
+ */
257
+ DECLARE_BITMAP(used_m64_bar_mask, MAX_M64_BARS);
258
+
259
+ /*
260
+ * If we map the SR-IOV BARs with a segmented window then
261
+ * parts of that window will be "claimed" by other PEs.
262
+ *
263
+ * "holes" here is used to reserve the leading portion
264
+ * of the window that is used by other (non VF) PEs.
265
+ */
266
+ struct resource holes[PCI_SRIOV_NUM_BARS];
267
+};
268
+
269
+static inline struct pnv_iov_data *pnv_iov_get(struct pci_dev *pdev)
270
+{
271
+ return pdev->dev.archdata.iov_data;
272
+}
273
+
274
+void pnv_pci_ioda_fixup_iov(struct pci_dev *pdev);
275
+resource_size_t pnv_pci_iov_resource_alignment(struct pci_dev *pdev, int resno);
276
+
277
+int pnv_pcibios_sriov_enable(struct pci_dev *pdev, u16 num_vfs);
278
+int pnv_pcibios_sriov_disable(struct pci_dev *pdev);
279
+#endif /* CONFIG_PCI_IOV */
198280
199281 extern struct pci_ops pnv_pci_ops;
200282
....@@ -210,18 +292,20 @@
210292 extern void pnv_pci_init_ioda2_phb(struct device_node *np);
211293 extern void pnv_pci_init_npu_phb(struct device_node *np);
212294 extern void pnv_pci_init_npu2_opencapi_phb(struct device_node *np);
295
+extern void pnv_npu2_map_lpar(struct pnv_ioda_pe *gpe, unsigned long msr);
213296 extern void pnv_pci_reset_secondary_bus(struct pci_dev *dev);
214297 extern int pnv_eeh_phb_reset(struct pci_controller *hose, int option);
215298
216
-extern void pnv_pci_dma_dev_setup(struct pci_dev *pdev);
217
-extern void pnv_pci_dma_bus_setup(struct pci_bus *bus);
218299 extern int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type);
219300 extern void pnv_teardown_msi_irqs(struct pci_dev *pdev);
301
+extern struct pnv_ioda_pe *pnv_pci_bdfn_to_pe(struct pnv_phb *phb, u16 bdfn);
220302 extern struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev);
221303 extern void pnv_set_msi_irq_chip(struct pnv_phb *phb, unsigned int virq);
222
-extern void pnv_pci_ioda2_set_bypass(struct pnv_ioda_pe *pe, bool enable);
304
+extern unsigned long pnv_pci_ioda2_get_table_size(__u32 page_shift,
305
+ __u64 window_size, __u32 levels);
223306 extern int pnv_eeh_post_init(void);
224307
308
+__printf(3, 4)
225309 extern void pe_level_printk(const struct pnv_ioda_pe *pe, const char *level,
226310 const char *fmt, ...);
227311 #define pe_err(pe, fmt, ...) \
....@@ -234,13 +318,7 @@
234318 /* Nvlink functions */
235319 extern void pnv_npu_try_dma_set_bypass(struct pci_dev *gpdev, bool bypass);
236320 extern void pnv_pci_ioda2_tce_invalidate_entire(struct pnv_phb *phb, bool rm);
237
-extern struct pnv_ioda_pe *pnv_pci_npu_setup_iommu(struct pnv_ioda_pe *npe);
238
-extern long pnv_npu_set_window(struct pnv_ioda_pe *npe, int num,
239
- struct iommu_table *tbl);
240
-extern long pnv_npu_unset_window(struct pnv_ioda_pe *npe, int num);
241
-extern void pnv_npu_take_ownership(struct pnv_ioda_pe *npe);
242
-extern void pnv_npu_release_ownership(struct pnv_ioda_pe *npe);
243
-extern int pnv_npu2_init(struct pnv_phb *phb);
321
+extern void pnv_pci_npu_setup_iommu_groups(void);
244322
245323 /* pci-ioda-tce.c */
246324 #define POWERNV_IOMMU_DEFAULT_LEVELS 2
....@@ -271,4 +349,16 @@
271349 void *tce_mem, u64 tce_size,
272350 u64 dma_offset, unsigned int page_shift);
273351
352
+extern unsigned long pnv_ioda_parse_tce_sizes(struct pnv_phb *phb);
353
+
354
+static inline struct pnv_phb *pci_bus_to_pnvhb(struct pci_bus *bus)
355
+{
356
+ struct pci_controller *hose = bus->sysdata;
357
+
358
+ if (hose)
359
+ return hose->private_data;
360
+
361
+ return NULL;
362
+}
363
+
274364 #endif /* __POWERNV_PCI_H */