1 #ifndef __POWERNV_PCI_H
2 #define __POWERNV_PCI_H
3 
4 struct pci_dn;
5 
6 enum pnv_phb_type {
7 	PNV_PHB_P5IOC2	= 0,
8 	PNV_PHB_IODA1	= 1,
9 	PNV_PHB_IODA2	= 2,
10 };
11 
12 /* Precise PHB model for error management */
13 enum pnv_phb_model {
14 	PNV_PHB_MODEL_UNKNOWN,
15 	PNV_PHB_MODEL_P5IOC2,
16 	PNV_PHB_MODEL_P7IOC,
17 	PNV_PHB_MODEL_PHB3,
18 };
19 
20 #define PNV_PCI_DIAG_BUF_SIZE	8192
21 #define PNV_IODA_PE_DEV		(1 << 0)	/* PE has single PCI device	*/
22 #define PNV_IODA_PE_BUS		(1 << 1)	/* PE has primary PCI bus	*/
23 #define PNV_IODA_PE_BUS_ALL	(1 << 2)	/* PE has subordinate buses	*/
24 #define PNV_IODA_PE_MASTER	(1 << 3)	/* Master PE in compound case	*/
25 #define PNV_IODA_PE_SLAVE	(1 << 4)	/* Slave PE in compound case	*/
26 
27 /* Data associated with a PE, including IOMMU tracking etc.. */
28 struct pnv_phb;
29 struct pnv_ioda_pe {
30 	unsigned long		flags;
31 	struct pnv_phb		*phb;
32 
33 	/* A PE can be associated with a single device or an
34 	 * entire bus (& children). In the former case, pdev
35 	 * is populated, in the later case, pbus is.
36 	 */
37 	struct pci_dev		*pdev;
38 	struct pci_bus		*pbus;
39 
40 	/* Effective RID (device RID for a device PE and base bus
41 	 * RID with devfn 0 for a bus PE)
42 	 */
43 	unsigned int		rid;
44 
45 	/* PE number */
46 	unsigned int		pe_number;
47 
48 	/* "Weight" assigned to the PE for the sake of DMA resource
49 	 * allocations
50 	 */
51 	unsigned int		dma_weight;
52 
53 	/* "Base" iommu table, ie, 4K TCEs, 32-bit DMA */
54 	int			tce32_seg;
55 	int			tce32_segcount;
56 	struct iommu_table	tce32_table;
57 	phys_addr_t		tce_inval_reg_phys;
58 
59 	/* 64-bit TCE bypass region */
60 	bool			tce_bypass_enabled;
61 	uint64_t		tce_bypass_base;
62 
63 	/* MSIs. MVE index is identical for for 32 and 64 bit MSI
64 	 * and -1 if not supported. (It's actually identical to the
65 	 * PE number)
66 	 */
67 	int			mve_number;
68 
69 	/* PEs in compound case */
70 	struct pnv_ioda_pe	*master;
71 	struct list_head	slaves;
72 
73 	/* Link in list of PE#s */
74 	struct list_head	dma_link;
75 	struct list_head	list;
76 };
77 
78 /* IOC dependent EEH operations */
79 #ifdef CONFIG_EEH
80 struct pnv_eeh_ops {
81 	int (*get_state)(struct eeh_pe *pe);
82 	int (*reset)(struct eeh_pe *pe, int option);
83 	int (*next_error)(struct eeh_pe **pe);
84 };
85 #endif /* CONFIG_EEH */
86 
87 #define PNV_PHB_FLAG_EEH	(1 << 0)
88 
89 struct pnv_phb {
90 	struct pci_controller	*hose;
91 	enum pnv_phb_type	type;
92 	enum pnv_phb_model	model;
93 	u64			hub_id;
94 	u64			opal_id;
95 	int			flags;
96 	void __iomem		*regs;
97 	int			initialized;
98 	spinlock_t		lock;
99 
100 #ifdef CONFIG_EEH
101 	struct pnv_eeh_ops	*eeh_ops;
102 #endif
103 
104 #ifdef CONFIG_DEBUG_FS
105 	int			has_dbgfs;
106 	struct dentry		*dbgfs;
107 #endif
108 
109 #ifdef CONFIG_PCI_MSI
110 	unsigned int		msi_base;
111 	unsigned int		msi32_support;
112 	struct msi_bitmap	msi_bmp;
113 #endif
114 	int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
115 			 unsigned int hwirq, unsigned int virq,
116 			 unsigned int is_64, struct msi_msg *msg);
117 	void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
118 	int (*dma_set_mask)(struct pnv_phb *phb, struct pci_dev *pdev,
119 			    u64 dma_mask);
120 	u64 (*dma_get_required_mask)(struct pnv_phb *phb,
121 				     struct pci_dev *pdev);
122 	void (*fixup_phb)(struct pci_controller *hose);
123 	u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn);
124 	void (*shutdown)(struct pnv_phb *phb);
125 	int (*init_m64)(struct pnv_phb *phb);
126 	void (*reserve_m64_pe)(struct pnv_phb *phb);
127 	int (*pick_m64_pe)(struct pnv_phb *phb, struct pci_bus *bus, int all);
128 	int (*get_pe_state)(struct pnv_phb *phb, int pe_no);
129 	void (*freeze_pe)(struct pnv_phb *phb, int pe_no);
130 	int (*unfreeze_pe)(struct pnv_phb *phb, int pe_no, int opt);
131 
132 	union {
133 		struct {
134 			struct iommu_table iommu_table;
135 		} p5ioc2;
136 
137 		struct {
138 			/* Global bridge info */
139 			unsigned int		total_pe;
140 			unsigned int		reserved_pe;
141 
142 			/* 32-bit MMIO window */
143 			unsigned int		m32_size;
144 			unsigned int		m32_segsize;
145 			unsigned int		m32_pci_base;
146 
147 			/* 64-bit MMIO window */
148 			unsigned int		m64_bar_idx;
149 			unsigned long		m64_size;
150 			unsigned long		m64_segsize;
151 			unsigned long		m64_base;
152 			unsigned long		m64_bar_alloc;
153 
154 			/* IO ports */
155 			unsigned int		io_size;
156 			unsigned int		io_segsize;
157 			unsigned int		io_pci_base;
158 
159 			/* PE allocation bitmap */
160 			unsigned long		*pe_alloc;
161 
162 			/* M32 & IO segment maps */
163 			unsigned int		*m32_segmap;
164 			unsigned int		*io_segmap;
165 			struct pnv_ioda_pe	*pe_array;
166 
167 			/* IRQ chip */
168 			int			irq_chip_init;
169 			struct irq_chip		irq_chip;
170 
171 			/* Sorted list of used PE's based
172 			 * on the sequence of creation
173 			 */
174 			struct list_head	pe_list;
175 
176 			/* Reverse map of PEs, will have to extend if
177 			 * we are to support more than 256 PEs, indexed
178 			 * bus { bus, devfn }
179 			 */
180 			unsigned char		pe_rmap[0x10000];
181 
182 			/* 32-bit TCE tables allocation */
183 			unsigned long		tce32_count;
184 
185 			/* Total "weight" for the sake of DMA resources
186 			 * allocation
187 			 */
188 			unsigned int		dma_weight;
189 			unsigned int		dma_pe_count;
190 
191 			/* Sorted list of used PE's, sorted at
192 			 * boot for resource allocation purposes
193 			 */
194 			struct list_head	pe_dma_list;
195 		} ioda;
196 	};
197 
198 	/* PHB and hub status structure */
199 	union {
200 		unsigned char			blob[PNV_PCI_DIAG_BUF_SIZE];
201 		struct OpalIoP7IOCPhbErrorData	p7ioc;
202 		struct OpalIoPhb3ErrorData	phb3;
203 		struct OpalIoP7IOCErrorData 	hub_diag;
204 	} diag;
205 
206 };
207 
208 extern struct pci_ops pnv_pci_ops;
209 #ifdef CONFIG_EEH
210 extern struct pnv_eeh_ops ioda_eeh_ops;
211 #endif
212 
213 void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
214 				unsigned char *log_buff);
215 int pnv_pci_cfg_read(struct device_node *dn,
216 		     int where, int size, u32 *val);
217 int pnv_pci_cfg_write(struct device_node *dn,
218 		      int where, int size, u32 val);
219 extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
220 				      void *tce_mem, u64 tce_size,
221 				      u64 dma_offset, unsigned page_shift);
222 extern void pnv_pci_init_p5ioc2_hub(struct device_node *np);
223 extern void pnv_pci_init_ioda_hub(struct device_node *np);
224 extern void pnv_pci_init_ioda2_phb(struct device_node *np);
225 extern void pnv_pci_ioda_tce_invalidate(struct iommu_table *tbl,
226 					__be64 *startp, __be64 *endp, bool rm);
227 extern void pnv_pci_reset_secondary_bus(struct pci_dev *dev);
228 extern int ioda_eeh_phb_reset(struct pci_controller *hose, int option);
229 
230 #endif /* __POWERNV_PCI_H */
231