Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 1 | #ifndef __POWERNV_PCI_H |
| 2 | #define __POWERNV_PCI_H |
| 3 | |
| 4 | struct pci_dn; |
| 5 | |
| 6 | enum pnv_phb_type { |
Gavin Shan | aa0c033 | 2013-04-25 19:20:57 +0000 | [diff] [blame] | 7 | PNV_PHB_P5IOC2 = 0, |
| 8 | PNV_PHB_IODA1 = 1, |
| 9 | PNV_PHB_IODA2 = 2, |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 10 | }; |
| 11 | |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 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, |
Gavin Shan | aa0c033 | 2013-04-25 19:20:57 +0000 | [diff] [blame] | 17 | PNV_PHB_MODEL_PHB3, |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 18 | }; |
| 19 | |
Gavin Shan | 5c9d6d7 | 2013-09-06 09:00:03 +0800 | [diff] [blame] | 20 | #define PNV_PCI_DIAG_BUF_SIZE 8192 |
Gavin Shan | 7ebdf95 | 2012-08-20 03:49:15 +0000 | [diff] [blame] | 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 */ |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 24 | |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 25 | /* Data associated with a PE, including IOMMU tracking etc.. */ |
Gavin Shan | 4cce955 | 2013-04-25 19:21:00 +0000 | [diff] [blame] | 26 | struct pnv_phb; |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 27 | struct pnv_ioda_pe { |
Gavin Shan | 7ebdf95 | 2012-08-20 03:49:15 +0000 | [diff] [blame] | 28 | unsigned long flags; |
Gavin Shan | 4cce955 | 2013-04-25 19:21:00 +0000 | [diff] [blame] | 29 | struct pnv_phb *phb; |
Gavin Shan | 7ebdf95 | 2012-08-20 03:49:15 +0000 | [diff] [blame] | 30 | |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 31 | /* 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 Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 51 | /* "Base" iommu table, ie, 4K TCEs, 32-bit DMA */ |
| 52 | int tce32_seg; |
| 53 | int tce32_segcount; |
| 54 | struct iommu_table tce32_table; |
Alexey Kardashevskiy | 8e0a161 | 2013-08-28 18:37:43 +1000 | [diff] [blame] | 55 | phys_addr_t tce_inval_reg_phys; |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 56 | |
| 57 | /* XXX TODO: Add support for additional 64-bit iommus */ |
| 58 | |
| 59 | /* MSIs. MVE index is identical for for 32 and 64 bit MSI |
| 60 | * and -1 if not supported. (It's actually identical to the |
| 61 | * PE number) |
| 62 | */ |
| 63 | int mve_number; |
| 64 | |
| 65 | /* Link in list of PE#s */ |
Gavin Shan | 7ebdf95 | 2012-08-20 03:49:15 +0000 | [diff] [blame] | 66 | struct list_head dma_link; |
| 67 | struct list_head list; |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
Gavin Shan | 8747f36 | 2013-06-20 13:21:06 +0800 | [diff] [blame] | 70 | /* IOC dependent EEH operations */ |
| 71 | #ifdef CONFIG_EEH |
| 72 | struct pnv_eeh_ops { |
| 73 | int (*post_init)(struct pci_controller *hose); |
| 74 | int (*set_option)(struct eeh_pe *pe, int option); |
| 75 | int (*get_state)(struct eeh_pe *pe); |
| 76 | int (*reset)(struct eeh_pe *pe, int option); |
| 77 | int (*get_log)(struct eeh_pe *pe, int severity, |
| 78 | char *drv_log, unsigned long len); |
| 79 | int (*configure_bridge)(struct eeh_pe *pe); |
| 80 | int (*next_error)(struct eeh_pe **pe); |
| 81 | }; |
Gavin Shan | 0b9e267 | 2013-06-27 13:46:44 +0800 | [diff] [blame] | 82 | |
| 83 | #define PNV_EEH_STATE_ENABLED (1 << 0) /* EEH enabled */ |
| 84 | #define PNV_EEH_STATE_REMOVED (1 << 1) /* PHB removed */ |
| 85 | |
Gavin Shan | 8747f36 | 2013-06-20 13:21:06 +0800 | [diff] [blame] | 86 | #endif /* CONFIG_EEH */ |
| 87 | |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 88 | struct pnv_phb { |
| 89 | struct pci_controller *hose; |
| 90 | enum pnv_phb_type type; |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 91 | enum pnv_phb_model model; |
Gavin Shan | 8747f36 | 2013-06-20 13:21:06 +0800 | [diff] [blame] | 92 | u64 hub_id; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 93 | u64 opal_id; |
| 94 | void __iomem *regs; |
Gavin Shan | db1266c | 2012-08-20 03:49:18 +0000 | [diff] [blame] | 95 | int initialized; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 96 | spinlock_t lock; |
| 97 | |
Gavin Shan | 8747f36 | 2013-06-20 13:21:06 +0800 | [diff] [blame] | 98 | #ifdef CONFIG_EEH |
| 99 | struct pnv_eeh_ops *eeh_ops; |
Gavin Shan | 0b9e267 | 2013-06-27 13:46:44 +0800 | [diff] [blame] | 100 | int eeh_state; |
Gavin Shan | 8747f36 | 2013-06-20 13:21:06 +0800 | [diff] [blame] | 101 | #endif |
| 102 | |
Gavin Shan | 37c367f | 2013-06-20 18:13:25 +0800 | [diff] [blame] | 103 | #ifdef CONFIG_DEBUG_FS |
| 104 | struct dentry *dbgfs; |
| 105 | #endif |
| 106 | |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 107 | #ifdef CONFIG_PCI_MSI |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 108 | unsigned int msi_base; |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 109 | unsigned int msi32_support; |
Gavin Shan | fb1b55d | 2013-03-05 21:12:37 +0000 | [diff] [blame] | 110 | struct msi_bitmap msi_bmp; |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 111 | #endif |
| 112 | int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev, |
Gavin Shan | 137436c | 2013-04-25 19:20:59 +0000 | [diff] [blame] | 113 | unsigned int hwirq, unsigned int virq, |
| 114 | unsigned int is_64, struct msi_msg *msg); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 115 | void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev); |
| 116 | void (*fixup_phb)(struct pci_controller *hose); |
| 117 | u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 118 | void (*shutdown)(struct pnv_phb *phb); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 119 | |
| 120 | union { |
| 121 | struct { |
| 122 | struct iommu_table iommu_table; |
| 123 | } p5ioc2; |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 124 | |
| 125 | struct { |
| 126 | /* Global bridge info */ |
| 127 | unsigned int total_pe; |
Gavin Shan | 36954dc | 2013-11-04 16:32:47 +0800 | [diff] [blame] | 128 | unsigned int reserved_pe; |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 129 | unsigned int m32_size; |
| 130 | unsigned int m32_segsize; |
| 131 | unsigned int m32_pci_base; |
| 132 | unsigned int io_size; |
| 133 | unsigned int io_segsize; |
| 134 | unsigned int io_pci_base; |
| 135 | |
| 136 | /* PE allocation bitmap */ |
| 137 | unsigned long *pe_alloc; |
| 138 | |
| 139 | /* M32 & IO segment maps */ |
| 140 | unsigned int *m32_segmap; |
| 141 | unsigned int *io_segmap; |
| 142 | struct pnv_ioda_pe *pe_array; |
| 143 | |
Gavin Shan | 137436c | 2013-04-25 19:20:59 +0000 | [diff] [blame] | 144 | /* IRQ chip */ |
| 145 | int irq_chip_init; |
| 146 | struct irq_chip irq_chip; |
| 147 | |
Gavin Shan | 7ebdf95 | 2012-08-20 03:49:15 +0000 | [diff] [blame] | 148 | /* Sorted list of used PE's based |
| 149 | * on the sequence of creation |
| 150 | */ |
| 151 | struct list_head pe_list; |
| 152 | |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 153 | /* Reverse map of PEs, will have to extend if |
| 154 | * we are to support more than 256 PEs, indexed |
| 155 | * bus { bus, devfn } |
| 156 | */ |
| 157 | unsigned char pe_rmap[0x10000]; |
| 158 | |
| 159 | /* 32-bit TCE tables allocation */ |
| 160 | unsigned long tce32_count; |
| 161 | |
| 162 | /* Total "weight" for the sake of DMA resources |
| 163 | * allocation |
| 164 | */ |
| 165 | unsigned int dma_weight; |
| 166 | unsigned int dma_pe_count; |
| 167 | |
| 168 | /* Sorted list of used PE's, sorted at |
| 169 | * boot for resource allocation purposes |
| 170 | */ |
Gavin Shan | 7ebdf95 | 2012-08-20 03:49:15 +0000 | [diff] [blame] | 171 | struct list_head pe_dma_list; |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 172 | } ioda; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 173 | }; |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 174 | |
| 175 | /* PHB status structure */ |
| 176 | union { |
| 177 | unsigned char blob[PNV_PCI_DIAG_BUF_SIZE]; |
| 178 | struct OpalIoP7IOCPhbErrorData p7ioc; |
Gavin Shan | 93aef2a | 2013-11-22 16:28:45 +0800 | [diff] [blame^] | 179 | struct OpalIoPhb3ErrorData phb3; |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 180 | } diag; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | extern struct pci_ops pnv_pci_ops; |
Gavin Shan | 8747f36 | 2013-06-20 13:21:06 +0800 | [diff] [blame] | 184 | #ifdef CONFIG_EEH |
| 185 | extern struct pnv_eeh_ops ioda_eeh_ops; |
| 186 | #endif |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 187 | |
Gavin Shan | 93aef2a | 2013-11-22 16:28:45 +0800 | [diff] [blame^] | 188 | void pnv_pci_dump_phb_diag_data(struct pci_controller *hose, |
| 189 | unsigned char *log_buff); |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 190 | int pnv_pci_cfg_read(struct device_node *dn, |
| 191 | int where, int size, u32 *val); |
| 192 | int pnv_pci_cfg_write(struct device_node *dn, |
| 193 | int where, int size, u32 val); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 194 | extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl, |
| 195 | void *tce_mem, u64 tce_size, |
| 196 | u64 dma_offset); |
| 197 | extern void pnv_pci_init_p5ioc2_hub(struct device_node *np); |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 198 | extern void pnv_pci_init_ioda_hub(struct device_node *np); |
Gavin Shan | aa0c033 | 2013-04-25 19:20:57 +0000 | [diff] [blame] | 199 | extern void pnv_pci_init_ioda2_phb(struct device_node *np); |
Gavin Shan | 4cce955 | 2013-04-25 19:21:00 +0000 | [diff] [blame] | 200 | extern void pnv_pci_ioda_tce_invalidate(struct iommu_table *tbl, |
Benjamin Herrenschmidt | 3ad26e5 | 2013-10-11 18:23:53 +1100 | [diff] [blame] | 201 | __be64 *startp, __be64 *endp, bool rm); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 202 | |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 203 | #endif /* __POWERNV_PCI_H */ |