blob: cde169442775c1684f0cd9f2db799d17c685deb3 [file] [log] [blame]
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +00001#ifndef __POWERNV_PCI_H
2#define __POWERNV_PCI_H
3
4struct pci_dn;
5
6enum pnv_phb_type {
Gavin Shanaa0c0332013-04-25 19:20:57 +00007 PNV_PHB_P5IOC2 = 0,
8 PNV_PHB_IODA1 = 1,
9 PNV_PHB_IODA2 = 2,
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000010};
11
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +000012/* Precise PHB model for error management */
13enum pnv_phb_model {
14 PNV_PHB_MODEL_UNKNOWN,
15 PNV_PHB_MODEL_P5IOC2,
16 PNV_PHB_MODEL_P7IOC,
Gavin Shanaa0c0332013-04-25 19:20:57 +000017 PNV_PHB_MODEL_PHB3,
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +000018};
19
Gavin Shan5c9d6d72013-09-06 09:00:03 +080020#define PNV_PCI_DIAG_BUF_SIZE 8192
Gavin Shan7ebdf952012-08-20 03:49:15 +000021#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 */
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +000024
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000025/* Data associated with a PE, including IOMMU tracking etc.. */
Gavin Shan4cce9552013-04-25 19:21:00 +000026struct pnv_phb;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000027struct pnv_ioda_pe {
Gavin Shan7ebdf952012-08-20 03:49:15 +000028 unsigned long flags;
Gavin Shan4cce9552013-04-25 19:21:00 +000029 struct pnv_phb *phb;
Gavin Shan7ebdf952012-08-20 03:49:15 +000030
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000031 /* A PE can be associated with a single device or an
32 * entire bus (& children). In the former case, pdev
33 * is populated, in the later case, pbus is.
34 */
35 struct pci_dev *pdev;
36 struct pci_bus *pbus;
37
38 /* Effective RID (device RID for a device PE and base bus
39 * RID with devfn 0 for a bus PE)
40 */
41 unsigned int rid;
42
43 /* PE number */
44 unsigned int pe_number;
45
46 /* "Weight" assigned to the PE for the sake of DMA resource
47 * allocations
48 */
49 unsigned int dma_weight;
50
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000051 /* "Base" iommu table, ie, 4K TCEs, 32-bit DMA */
52 int tce32_seg;
53 int tce32_segcount;
54 struct iommu_table tce32_table;
Alexey Kardashevskiy8e0a1612013-08-28 18:37:43 +100055 phys_addr_t tce_inval_reg_phys;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000056
Benjamin Herrenschmidtcd15b042014-02-11 11:32:38 +110057 /* 64-bit TCE bypass region */
58 bool tce_bypass_enabled;
59 uint64_t tce_bypass_base;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000060
61 /* MSIs. MVE index is identical for for 32 and 64 bit MSI
62 * and -1 if not supported. (It's actually identical to the
63 * PE number)
64 */
65 int mve_number;
66
67 /* Link in list of PE#s */
Gavin Shan7ebdf952012-08-20 03:49:15 +000068 struct list_head dma_link;
69 struct list_head list;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000070};
71
Gavin Shan8747f362013-06-20 13:21:06 +080072/* IOC dependent EEH operations */
73#ifdef CONFIG_EEH
74struct pnv_eeh_ops {
75 int (*post_init)(struct pci_controller *hose);
76 int (*set_option)(struct eeh_pe *pe, int option);
77 int (*get_state)(struct eeh_pe *pe);
78 int (*reset)(struct eeh_pe *pe, int option);
79 int (*get_log)(struct eeh_pe *pe, int severity,
80 char *drv_log, unsigned long len);
81 int (*configure_bridge)(struct eeh_pe *pe);
82 int (*next_error)(struct eeh_pe **pe);
83};
Gavin Shan0b9e2672013-06-27 13:46:44 +080084
85#define PNV_EEH_STATE_ENABLED (1 << 0) /* EEH enabled */
86#define PNV_EEH_STATE_REMOVED (1 << 1) /* PHB removed */
87
Gavin Shan8747f362013-06-20 13:21:06 +080088#endif /* CONFIG_EEH */
89
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000090struct pnv_phb {
91 struct pci_controller *hose;
92 enum pnv_phb_type type;
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +000093 enum pnv_phb_model model;
Gavin Shan8747f362013-06-20 13:21:06 +080094 u64 hub_id;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000095 u64 opal_id;
96 void __iomem *regs;
Gavin Shandb1266c2012-08-20 03:49:18 +000097 int initialized;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000098 spinlock_t lock;
99
Gavin Shan8747f362013-06-20 13:21:06 +0800100#ifdef CONFIG_EEH
101 struct pnv_eeh_ops *eeh_ops;
Gavin Shan0b9e2672013-06-27 13:46:44 +0800102 int eeh_state;
Gavin Shan8747f362013-06-20 13:21:06 +0800103#endif
104
Gavin Shan37c367f2013-06-20 18:13:25 +0800105#ifdef CONFIG_DEBUG_FS
106 struct dentry *dbgfs;
107#endif
108
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +0000109#ifdef CONFIG_PCI_MSI
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +0000110 unsigned int msi_base;
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +0000111 unsigned int msi32_support;
Gavin Shanfb1b55d2013-03-05 21:12:37 +0000112 struct msi_bitmap msi_bmp;
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +0000113#endif
114 int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
Gavin Shan137436c2013-04-25 19:20:59 +0000115 unsigned int hwirq, unsigned int virq,
116 unsigned int is_64, struct msi_msg *msg);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000117 void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
Benjamin Herrenschmidtcd15b042014-02-11 11:32:38 +1100118 int (*dma_set_mask)(struct pnv_phb *phb, struct pci_dev *pdev,
119 u64 dma_mask);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000120 void (*fixup_phb)(struct pci_controller *hose);
121 u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn);
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000122 void (*shutdown)(struct pnv_phb *phb);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000123
124 union {
125 struct {
126 struct iommu_table iommu_table;
127 } p5ioc2;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000128
129 struct {
130 /* Global bridge info */
131 unsigned int total_pe;
Gavin Shan36954dc2013-11-04 16:32:47 +0800132 unsigned int reserved_pe;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000133 unsigned int m32_size;
134 unsigned int m32_segsize;
135 unsigned int m32_pci_base;
136 unsigned int io_size;
137 unsigned int io_segsize;
138 unsigned int io_pci_base;
139
140 /* PE allocation bitmap */
141 unsigned long *pe_alloc;
142
143 /* M32 & IO segment maps */
144 unsigned int *m32_segmap;
145 unsigned int *io_segmap;
146 struct pnv_ioda_pe *pe_array;
147
Gavin Shan137436c2013-04-25 19:20:59 +0000148 /* IRQ chip */
149 int irq_chip_init;
150 struct irq_chip irq_chip;
151
Gavin Shan7ebdf952012-08-20 03:49:15 +0000152 /* Sorted list of used PE's based
153 * on the sequence of creation
154 */
155 struct list_head pe_list;
156
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000157 /* Reverse map of PEs, will have to extend if
158 * we are to support more than 256 PEs, indexed
159 * bus { bus, devfn }
160 */
161 unsigned char pe_rmap[0x10000];
162
163 /* 32-bit TCE tables allocation */
164 unsigned long tce32_count;
165
166 /* Total "weight" for the sake of DMA resources
167 * allocation
168 */
169 unsigned int dma_weight;
170 unsigned int dma_pe_count;
171
172 /* Sorted list of used PE's, sorted at
173 * boot for resource allocation purposes
174 */
Gavin Shan7ebdf952012-08-20 03:49:15 +0000175 struct list_head pe_dma_list;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000176 } ioda;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000177 };
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000178
Brian W Hartca1de5d2013-12-20 13:06:01 -0600179 /* PHB and hub status structure */
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000180 union {
181 unsigned char blob[PNV_PCI_DIAG_BUF_SIZE];
182 struct OpalIoP7IOCPhbErrorData p7ioc;
Gavin Shan93aef2a2013-11-22 16:28:45 +0800183 struct OpalIoPhb3ErrorData phb3;
Brian W Hartca1de5d2013-12-20 13:06:01 -0600184 struct OpalIoP7IOCErrorData hub_diag;
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000185 } diag;
Brian W Hartca1de5d2013-12-20 13:06:01 -0600186
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000187};
188
189extern struct pci_ops pnv_pci_ops;
Gavin Shan8747f362013-06-20 13:21:06 +0800190#ifdef CONFIG_EEH
191extern struct pnv_eeh_ops ioda_eeh_ops;
192#endif
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000193
Gavin Shan93aef2a2013-11-22 16:28:45 +0800194void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
195 unsigned char *log_buff);
Gavin Shan9bf41be2013-06-27 13:46:48 +0800196int pnv_pci_cfg_read(struct device_node *dn,
197 int where, int size, u32 *val);
198int pnv_pci_cfg_write(struct device_node *dn,
199 int where, int size, u32 val);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000200extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
201 void *tce_mem, u64 tce_size,
202 u64 dma_offset);
203extern void pnv_pci_init_p5ioc2_hub(struct device_node *np);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000204extern void pnv_pci_init_ioda_hub(struct device_node *np);
Gavin Shanaa0c0332013-04-25 19:20:57 +0000205extern void pnv_pci_init_ioda2_phb(struct device_node *np);
Gavin Shan4cce9552013-04-25 19:21:00 +0000206extern void pnv_pci_ioda_tce_invalidate(struct iommu_table *tbl,
Benjamin Herrenschmidt3ad26e52013-10-11 18:23:53 +1100207 __be64 *startp, __be64 *endp, bool rm);
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000208
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000209#endif /* __POWERNV_PCI_H */