blob: 336c9dc1b314f424591d762c92ab013b46a9162a [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
20#define PNV_PCI_DIAG_BUF_SIZE 4096
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;
55
56 /* XXX TODO: Add support for additional 64-bit iommus */
57
58 /* MSIs. MVE index is identical for for 32 and 64 bit MSI
59 * and -1 if not supported. (It's actually identical to the
60 * PE number)
61 */
62 int mve_number;
63
64 /* Link in list of PE#s */
Gavin Shan7ebdf952012-08-20 03:49:15 +000065 struct list_head dma_link;
66 struct list_head list;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000067};
68
Gavin Shan8747f362013-06-20 13:21:06 +080069/* IOC dependent EEH operations */
70#ifdef CONFIG_EEH
71struct pnv_eeh_ops {
72 int (*post_init)(struct pci_controller *hose);
73 int (*set_option)(struct eeh_pe *pe, int option);
74 int (*get_state)(struct eeh_pe *pe);
75 int (*reset)(struct eeh_pe *pe, int option);
76 int (*get_log)(struct eeh_pe *pe, int severity,
77 char *drv_log, unsigned long len);
78 int (*configure_bridge)(struct eeh_pe *pe);
79 int (*next_error)(struct eeh_pe **pe);
80};
81#endif /* CONFIG_EEH */
82
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000083struct pnv_phb {
84 struct pci_controller *hose;
85 enum pnv_phb_type type;
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +000086 enum pnv_phb_model model;
Gavin Shan8747f362013-06-20 13:21:06 +080087 u64 hub_id;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000088 u64 opal_id;
89 void __iomem *regs;
Gavin Shandb1266c2012-08-20 03:49:18 +000090 int initialized;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000091 spinlock_t lock;
92
Gavin Shan8747f362013-06-20 13:21:06 +080093#ifdef CONFIG_EEH
94 struct pnv_eeh_ops *eeh_ops;
95 int eeh_enabled;
96#endif
97
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000098#ifdef CONFIG_PCI_MSI
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000099 unsigned int msi_base;
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +0000100 unsigned int msi32_support;
Gavin Shanfb1b55d2013-03-05 21:12:37 +0000101 struct msi_bitmap msi_bmp;
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +0000102#endif
103 int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
Gavin Shan137436c2013-04-25 19:20:59 +0000104 unsigned int hwirq, unsigned int virq,
105 unsigned int is_64, struct msi_msg *msg);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000106 void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
107 void (*fixup_phb)(struct pci_controller *hose);
108 u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn);
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000109 void (*shutdown)(struct pnv_phb *phb);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000110
111 union {
112 struct {
113 struct iommu_table iommu_table;
114 } p5ioc2;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000115
116 struct {
117 /* Global bridge info */
118 unsigned int total_pe;
119 unsigned int m32_size;
120 unsigned int m32_segsize;
121 unsigned int m32_pci_base;
122 unsigned int io_size;
123 unsigned int io_segsize;
124 unsigned int io_pci_base;
125
126 /* PE allocation bitmap */
127 unsigned long *pe_alloc;
128
129 /* M32 & IO segment maps */
130 unsigned int *m32_segmap;
131 unsigned int *io_segmap;
132 struct pnv_ioda_pe *pe_array;
133
Gavin Shan137436c2013-04-25 19:20:59 +0000134 /* IRQ chip */
135 int irq_chip_init;
136 struct irq_chip irq_chip;
137
Gavin Shan7ebdf952012-08-20 03:49:15 +0000138 /* Sorted list of used PE's based
139 * on the sequence of creation
140 */
141 struct list_head pe_list;
142
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000143 /* Reverse map of PEs, will have to extend if
144 * we are to support more than 256 PEs, indexed
145 * bus { bus, devfn }
146 */
147 unsigned char pe_rmap[0x10000];
148
149 /* 32-bit TCE tables allocation */
150 unsigned long tce32_count;
151
152 /* Total "weight" for the sake of DMA resources
153 * allocation
154 */
155 unsigned int dma_weight;
156 unsigned int dma_pe_count;
157
158 /* Sorted list of used PE's, sorted at
159 * boot for resource allocation purposes
160 */
Gavin Shan7ebdf952012-08-20 03:49:15 +0000161 struct list_head pe_dma_list;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000162 } ioda;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000163 };
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000164
165 /* PHB status structure */
166 union {
167 unsigned char blob[PNV_PCI_DIAG_BUF_SIZE];
168 struct OpalIoP7IOCPhbErrorData p7ioc;
169 } diag;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000170};
171
172extern struct pci_ops pnv_pci_ops;
Gavin Shan8747f362013-06-20 13:21:06 +0800173#ifdef CONFIG_EEH
174extern struct pnv_eeh_ops ioda_eeh_ops;
175#endif
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000176
177extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
178 void *tce_mem, u64 tce_size,
179 u64 dma_offset);
180extern void pnv_pci_init_p5ioc2_hub(struct device_node *np);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000181extern void pnv_pci_init_ioda_hub(struct device_node *np);
Gavin Shanaa0c0332013-04-25 19:20:57 +0000182extern void pnv_pci_init_ioda2_phb(struct device_node *np);
Gavin Shan4cce9552013-04-25 19:21:00 +0000183extern void pnv_pci_ioda_tce_invalidate(struct iommu_table *tbl,
184 u64 *startp, u64 *endp);
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000185
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000186#endif /* __POWERNV_PCI_H */