blob: 3c552b3dd0c6cd7f6442c6855cda1ef370e1eedb [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.. */
26struct pnv_ioda_pe {
Gavin Shan7ebdf952012-08-20 03:49:15 +000027 unsigned long flags;
28
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000029 /* A PE can be associated with a single device or an
30 * entire bus (& children). In the former case, pdev
31 * is populated, in the later case, pbus is.
32 */
33 struct pci_dev *pdev;
34 struct pci_bus *pbus;
35
36 /* Effective RID (device RID for a device PE and base bus
37 * RID with devfn 0 for a bus PE)
38 */
39 unsigned int rid;
40
41 /* PE number */
42 unsigned int pe_number;
43
44 /* "Weight" assigned to the PE for the sake of DMA resource
45 * allocations
46 */
47 unsigned int dma_weight;
48
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000049 /* "Base" iommu table, ie, 4K TCEs, 32-bit DMA */
50 int tce32_seg;
51 int tce32_segcount;
52 struct iommu_table tce32_table;
53
54 /* XXX TODO: Add support for additional 64-bit iommus */
55
56 /* MSIs. MVE index is identical for for 32 and 64 bit MSI
57 * and -1 if not supported. (It's actually identical to the
58 * PE number)
59 */
60 int mve_number;
61
62 /* Link in list of PE#s */
Gavin Shan7ebdf952012-08-20 03:49:15 +000063 struct list_head dma_link;
64 struct list_head list;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000065};
66
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000067struct pnv_phb {
68 struct pci_controller *hose;
69 enum pnv_phb_type type;
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +000070 enum pnv_phb_model model;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000071 u64 opal_id;
72 void __iomem *regs;
Gavin Shandb1266c2012-08-20 03:49:18 +000073 int initialized;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000074 spinlock_t lock;
75
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000076#ifdef CONFIG_PCI_MSI
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000077 unsigned int msi_base;
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000078 unsigned int msi32_support;
Gavin Shanfb1b55d2013-03-05 21:12:37 +000079 struct msi_bitmap msi_bmp;
Benjamin Herrenschmidtc1a25622011-09-19 17:45:06 +000080#endif
81 int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
Gavin Shan137436c2013-04-25 19:20:59 +000082 unsigned int hwirq, unsigned int virq,
83 unsigned int is_64, struct msi_msg *msg);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +000084 void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
85 void (*fixup_phb)(struct pci_controller *hose);
86 u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn);
87
88 union {
89 struct {
90 struct iommu_table iommu_table;
91 } p5ioc2;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +000092
93 struct {
94 /* Global bridge info */
95 unsigned int total_pe;
96 unsigned int m32_size;
97 unsigned int m32_segsize;
98 unsigned int m32_pci_base;
99 unsigned int io_size;
100 unsigned int io_segsize;
101 unsigned int io_pci_base;
102
103 /* PE allocation bitmap */
104 unsigned long *pe_alloc;
105
106 /* M32 & IO segment maps */
107 unsigned int *m32_segmap;
108 unsigned int *io_segmap;
109 struct pnv_ioda_pe *pe_array;
110
Gavin Shan137436c2013-04-25 19:20:59 +0000111 /* IRQ chip */
112 int irq_chip_init;
113 struct irq_chip irq_chip;
114
Gavin Shan7ebdf952012-08-20 03:49:15 +0000115 /* Sorted list of used PE's based
116 * on the sequence of creation
117 */
118 struct list_head pe_list;
119
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000120 /* Reverse map of PEs, will have to extend if
121 * we are to support more than 256 PEs, indexed
122 * bus { bus, devfn }
123 */
124 unsigned char pe_rmap[0x10000];
125
126 /* 32-bit TCE tables allocation */
127 unsigned long tce32_count;
128
129 /* Total "weight" for the sake of DMA resources
130 * allocation
131 */
132 unsigned int dma_weight;
133 unsigned int dma_pe_count;
134
135 /* Sorted list of used PE's, sorted at
136 * boot for resource allocation purposes
137 */
Gavin Shan7ebdf952012-08-20 03:49:15 +0000138 struct list_head pe_dma_list;
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000139 } ioda;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000140 };
Benjamin Herrenschmidtcee72d52011-11-29 18:22:53 +0000141
142 /* PHB status structure */
143 union {
144 unsigned char blob[PNV_PCI_DIAG_BUF_SIZE];
145 struct OpalIoP7IOCPhbErrorData p7ioc;
146 } diag;
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000147};
148
149extern struct pci_ops pnv_pci_ops;
150
151extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
152 void *tce_mem, u64 tce_size,
153 u64 dma_offset);
154extern void pnv_pci_init_p5ioc2_hub(struct device_node *np);
Benjamin Herrenschmidt184cd4a2011-11-15 17:29:08 +0000155extern void pnv_pci_init_ioda_hub(struct device_node *np);
Gavin Shanaa0c0332013-04-25 19:20:57 +0000156extern void pnv_pci_init_ioda2_phb(struct device_node *np);
Benjamin Herrenschmidt61305a92011-09-19 17:45:05 +0000157
158
159#endif /* __POWERNV_PCI_H */