pci.h 7.2 KB
Newer Older
1 2 3 4 5 6
#ifndef __POWERNV_PCI_H
#define __POWERNV_PCI_H

struct pci_dn;

enum pnv_phb_type {
7 8 9
	PNV_PHB_IODA1	= 0,
	PNV_PHB_IODA2	= 1,
	PNV_PHB_NPU	= 2,
10 11
};

12 13 14 15
/* Precise PHB model for error management */
enum pnv_phb_model {
	PNV_PHB_MODEL_UNKNOWN,
	PNV_PHB_MODEL_P7IOC,
16
	PNV_PHB_MODEL_PHB3,
17
	PNV_PHB_MODEL_NPU,
18 19
};

20
#define PNV_PCI_DIAG_BUF_SIZE	8192
21 22 23
#define PNV_IODA_PE_DEV		(1 << 0)	/* PE has single PCI device	*/
#define PNV_IODA_PE_BUS		(1 << 1)	/* PE has primary PCI bus	*/
#define PNV_IODA_PE_BUS_ALL	(1 << 2)	/* PE has subordinate buses	*/
24 25
#define PNV_IODA_PE_MASTER	(1 << 3)	/* Master PE in compound case	*/
#define PNV_IODA_PE_SLAVE	(1 << 4)	/* Slave PE in compound case	*/
26
#define PNV_IODA_PE_VF		(1 << 5)	/* PE for one VF 		*/
27
#define PNV_IODA_PE_PEER	(1 << 6)	/* PE has peers			*/
28

29
/* Data associated with a PE, including IOMMU tracking etc.. */
30
struct pnv_phb;
31
struct pnv_ioda_pe {
32
	unsigned long		flags;
33
	struct pnv_phb		*phb;
34

35 36 37
#define PNV_IODA_MAX_PEER_PES	8
	struct pnv_ioda_pe	*peers[PNV_IODA_MAX_PEER_PES];

38 39 40 41
	/* A PE can be associated with a single device or an
	 * entire bus (& children). In the former case, pdev
	 * is populated, in the later case, pbus is.
	 */
42 43 44
#ifdef CONFIG_PCI_IOV
	struct pci_dev          *parent_dev;
#endif
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
	struct pci_dev		*pdev;
	struct pci_bus		*pbus;

	/* Effective RID (device RID for a device PE and base bus
	 * RID with devfn 0 for a bus PE)
	 */
	unsigned int		rid;

	/* PE number */
	unsigned int		pe_number;

	/* "Weight" assigned to the PE for the sake of DMA resource
	 * allocations
	 */
	unsigned int		dma_weight;

	/* "Base" iommu table, ie, 4K TCEs, 32-bit DMA */
	int			tce32_seg;
	int			tce32_segcount;
64
	struct iommu_table_group table_group;
65

66 67 68
	/* 64-bit TCE bypass region */
	bool			tce_bypass_enabled;
	uint64_t		tce_bypass_base;
69 70 71 72 73 74 75

	/* MSIs. MVE index is identical for for 32 and 64 bit MSI
	 * and -1 if not supported. (It's actually identical to the
	 * PE number)
	 */
	int			mve_number;

76 77 78 79
	/* PEs in compound case */
	struct pnv_ioda_pe	*master;
	struct list_head	slaves;

80
	/* Link in list of PE#s */
81 82
	struct list_head	dma_link;
	struct list_head	list;
83 84
};

85 86
#define PNV_PHB_FLAG_EEH	(1 << 0)

87 88 89
struct pnv_phb {
	struct pci_controller	*hose;
	enum pnv_phb_type	type;
90
	enum pnv_phb_model	model;
91
	u64			hub_id;
92
	u64			opal_id;
93
	int			flags;
94
	void __iomem		*regs;
95
	int			initialized;
96 97
	spinlock_t		lock;

98
#ifdef CONFIG_DEBUG_FS
99
	int			has_dbgfs;
100 101 102
	struct dentry		*dbgfs;
#endif

103 104 105
#ifdef CONFIG_PCI_MSI
	unsigned int		msi_base;
	unsigned int		msi32_support;
106
	struct msi_bitmap	msi_bmp;
107 108
#endif
	int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
109 110
			 unsigned int hwirq, unsigned int virq,
			 unsigned int is_64, struct msi_msg *msg);
111 112
	void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
	void (*fixup_phb)(struct pci_controller *hose);
113
	int (*init_m64)(struct pnv_phb *phb);
114 115
	void (*reserve_m64_pe)(struct pci_bus *bus,
			       unsigned long *pe_bitmap, bool all);
116
	int (*pick_m64_pe)(struct pci_bus *bus, bool all);
117 118 119
	int (*get_pe_state)(struct pnv_phb *phb, int pe_no);
	void (*freeze_pe)(struct pnv_phb *phb, int pe_no);
	int (*unfreeze_pe)(struct pnv_phb *phb, int pe_no, int opt);
120

121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
	struct {
		/* Global bridge info */
		unsigned int		total_pe;
		unsigned int		reserved_pe;

		/* 32-bit MMIO window */
		unsigned int		m32_size;
		unsigned int		m32_segsize;
		unsigned int		m32_pci_base;

		/* 64-bit MMIO window */
		unsigned int		m64_bar_idx;
		unsigned long		m64_size;
		unsigned long		m64_segsize;
		unsigned long		m64_base;
		unsigned long		m64_bar_alloc;

		/* IO ports */
		unsigned int		io_size;
		unsigned int		io_segsize;
		unsigned int		io_pci_base;

		/* PE allocation bitmap */
		unsigned long		*pe_alloc;
		/* PE allocation mutex */
		struct mutex		pe_alloc_mutex;

		/* M32 & IO segment maps */
		unsigned int		*m32_segmap;
		unsigned int		*io_segmap;
		struct pnv_ioda_pe	*pe_array;

		/* IRQ chip */
		int			irq_chip_init;
		struct irq_chip		irq_chip;

		/* Sorted list of used PE's based
		 * on the sequence of creation
		 */
		struct list_head	pe_list;
		struct mutex            pe_list_mutex;

		/* Reverse map of PEs, will have to extend if
		 * we are to support more than 256 PEs, indexed
		 * bus { bus, devfn }
		 */
		unsigned char		pe_rmap[0x10000];

		/* 32-bit TCE tables allocation */
		unsigned long		tce32_count;

		/* Total "weight" for the sake of DMA resources
		 * allocation
		 */
		unsigned int		dma_weight;
		unsigned int		dma_pe_count;

		/* Sorted list of used PE's, sorted at
		 * boot for resource allocation purposes
		 */
		struct list_head	pe_dma_list;

		/* TCE cache invalidate registers (physical and
		 * remapped)
		 */
		phys_addr_t		tce_inval_reg_phys;
		__be64 __iomem		*tce_inval_reg;
	} ioda;
189

190
	/* PHB and hub status structure */
191 192 193
	union {
		unsigned char			blob[PNV_PCI_DIAG_BUF_SIZE];
		struct OpalIoP7IOCPhbErrorData	p7ioc;
194
		struct OpalIoPhb3ErrorData	phb3;
195
		struct OpalIoP7IOCErrorData 	hub_diag;
196
	} diag;
197

198 199 200
};

extern struct pci_ops pnv_pci_ops;
201 202 203 204
extern int pnv_tce_build(struct iommu_table *tbl, long index, long npages,
		unsigned long uaddr, enum dma_data_direction direction,
		struct dma_attrs *attrs);
extern void pnv_tce_free(struct iommu_table *tbl, long index, long npages);
205 206
extern int pnv_tce_xchg(struct iommu_table *tbl, long index,
		unsigned long *hpa, enum dma_data_direction *direction);
207
extern unsigned long pnv_tce_get(struct iommu_table *tbl, long index);
208

209 210
void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
				unsigned char *log_buff);
211
int pnv_pci_cfg_read(struct pci_dn *pdn,
212
		     int where, int size, u32 *val);
213
int pnv_pci_cfg_write(struct pci_dn *pdn,
214
		      int where, int size, u32 val);
215 216 217 218 219 220 221
extern struct iommu_table *pnv_pci_table_alloc(int nid);

extern long pnv_pci_link_table_and_group(int node, int num,
		struct iommu_table *tbl,
		struct iommu_table_group *table_group);
extern void pnv_pci_unlink_table_and_group(struct iommu_table *tbl,
		struct iommu_table_group *table_group);
222 223
extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
				      void *tce_mem, u64 tce_size,
224
				      u64 dma_offset, unsigned page_shift);
225
extern void pnv_pci_init_ioda_hub(struct device_node *np);
226
extern void pnv_pci_init_ioda2_phb(struct device_node *np);
227
extern void pnv_pci_init_npu_phb(struct device_node *np);
228
extern void pnv_pci_ioda_tce_invalidate(struct iommu_table *tbl,
229
					__be64 *startp, __be64 *endp, bool rm);
230
extern void pnv_pci_reset_secondary_bus(struct pci_dev *dev);
231
extern int pnv_eeh_phb_reset(struct pci_controller *hose, int option);
232

233
extern void pnv_pci_dma_dev_setup(struct pci_dev *pdev);
234
extern void pnv_pci_dma_bus_setup(struct pci_bus *bus);
235 236 237
extern int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type);
extern void pnv_teardown_msi_irqs(struct pci_dev *pdev);

238 239 240 241 242 243 244 245 246 247 248 249
/* Nvlink functions */
extern void pnv_npu_tce_invalidate_entire(struct pnv_ioda_pe *npe);
extern void pnv_npu_tce_invalidate(struct pnv_ioda_pe *npe,
				       struct iommu_table *tbl,
				       unsigned long index,
				       unsigned long npages,
				       bool rm);
extern void pnv_npu_init_dma_pe(struct pnv_ioda_pe *npe);
extern void pnv_npu_setup_dma_pe(struct pnv_ioda_pe *npe);
extern int pnv_npu_dma_set_bypass(struct pnv_ioda_pe *npe, bool enabled);
extern int pnv_npu_dma_set_mask(struct pci_dev *npdev, u64 dma_mask);

250
#endif /* __POWERNV_PCI_H */
新手
引导
客服 返回
顶部