pci.h 5.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 {
G
Gavin Shan 已提交
7 8 9
	PNV_PHB_P5IOC2	= 0,
	PNV_PHB_IODA1	= 1,
	PNV_PHB_IODA2	= 2,
10 11
};

12 13 14 15 16
/* Precise PHB model for error management */
enum pnv_phb_model {
	PNV_PHB_MODEL_UNKNOWN,
	PNV_PHB_MODEL_P5IOC2,
	PNV_PHB_MODEL_P7IOC,
G
Gavin Shan 已提交
17
	PNV_PHB_MODEL_PHB3,
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
/* Data associated with a PE, including IOMMU tracking etc.. */
26
struct pnv_phb;
27
struct pnv_ioda_pe {
28
	unsigned long		flags;
29
	struct pnv_phb		*phb;
30

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
	/* 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.
	 */
	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;
	struct iommu_table	tce32_table;
55
	phys_addr_t		tce_inval_reg_phys;
56

57 58 59
	/* 64-bit TCE bypass region */
	bool			tce_bypass_enabled;
	uint64_t		tce_bypass_base;
60 61 62 63 64 65 66 67

	/* 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;

	/* Link in list of PE#s */
68 69
	struct list_head	dma_link;
	struct list_head	list;
70 71
};

G
Gavin Shan 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85
/* IOC dependent EEH operations */
#ifdef CONFIG_EEH
struct pnv_eeh_ops {
	int (*post_init)(struct pci_controller *hose);
	int (*set_option)(struct eeh_pe *pe, int option);
	int (*get_state)(struct eeh_pe *pe);
	int (*reset)(struct eeh_pe *pe, int option);
	int (*get_log)(struct eeh_pe *pe, int severity,
		       char *drv_log, unsigned long len);
	int (*configure_bridge)(struct eeh_pe *pe);
	int (*next_error)(struct eeh_pe **pe);
};
#endif /* CONFIG_EEH */

86 87
#define PNV_PHB_FLAG_EEH	(1 << 0)

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

G
Gavin Shan 已提交
99 100 101 102
#ifdef CONFIG_EEH
	struct pnv_eeh_ops	*eeh_ops;
#endif

103
#ifdef CONFIG_DEBUG_FS
G
Gavin Shan 已提交
104
	int			has_dbgfs;
105 106 107
	struct dentry		*dbgfs;
#endif

108 109 110
#ifdef CONFIG_PCI_MSI
	unsigned int		msi_base;
	unsigned int		msi32_support;
111
	struct msi_bitmap	msi_bmp;
112 113
#endif
	int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
114 115
			 unsigned int hwirq, unsigned int virq,
			 unsigned int is_64, struct msi_msg *msg);
116
	void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
117 118
	int (*dma_set_mask)(struct pnv_phb *phb, struct pci_dev *pdev,
			    u64 dma_mask);
119 120
	void (*fixup_phb)(struct pci_controller *hose);
	u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn);
121
	void (*shutdown)(struct pnv_phb *phb);
122 123 124 125 126

	union {
		struct {
			struct iommu_table iommu_table;
		} p5ioc2;
127 128 129 130

		struct {
			/* Global bridge info */
			unsigned int		total_pe;
131
			unsigned int		reserved_pe;
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
			unsigned int		m32_size;
			unsigned int		m32_segsize;
			unsigned int		m32_pci_base;
			unsigned int		io_size;
			unsigned int		io_segsize;
			unsigned int		io_pci_base;

			/* PE allocation bitmap */
			unsigned long		*pe_alloc;

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

147 148 149 150
			/* IRQ chip */
			int			irq_chip_init;
			struct irq_chip		irq_chip;

151 152 153 154 155
			/* Sorted list of used PE's based
			 * on the sequence of creation
			 */
			struct list_head	pe_list;

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
			/* 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
			 */
174
			struct list_head	pe_dma_list;
175
		} ioda;
176
	};
177

178
	/* PHB and hub status structure */
179 180 181
	union {
		unsigned char			blob[PNV_PCI_DIAG_BUF_SIZE];
		struct OpalIoP7IOCPhbErrorData	p7ioc;
182
		struct OpalIoPhb3ErrorData	phb3;
183
		struct OpalIoP7IOCErrorData 	hub_diag;
184
	} diag;
185

186 187 188
};

extern struct pci_ops pnv_pci_ops;
G
Gavin Shan 已提交
189 190 191
#ifdef CONFIG_EEH
extern struct pnv_eeh_ops ioda_eeh_ops;
#endif
192

193 194
void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
				unsigned char *log_buff);
195 196 197 198
int pnv_pci_cfg_read(struct device_node *dn,
		     int where, int size, u32 *val);
int pnv_pci_cfg_write(struct device_node *dn,
		      int where, int size, u32 val);
199 200 201 202
extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
				      void *tce_mem, u64 tce_size,
				      u64 dma_offset);
extern void pnv_pci_init_p5ioc2_hub(struct device_node *np);
203
extern void pnv_pci_init_ioda_hub(struct device_node *np);
G
Gavin Shan 已提交
204
extern void pnv_pci_init_ioda2_phb(struct device_node *np);
205
extern void pnv_pci_ioda_tce_invalidate(struct iommu_table *tbl,
206
					__be64 *startp, __be64 *endp, bool rm);
207

208
#endif /* __POWERNV_PCI_H */