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 { |
| 7 | PNV_PHB_P5IOC2, |
| 8 | PNV_PHB_IODA1, |
| 9 | PNV_PHB_IODA2, |
| 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, |
| 17 | }; |
| 18 | |
| 19 | #define PNV_PCI_DIAG_BUF_SIZE 4096 |
Gavin Shan | 7ebdf95 | 2012-08-20 03:49:15 +0000 | [diff] [blame] | 20 | #define PNV_IODA_PE_DEV (1 << 0) /* PE has single PCI device */ |
| 21 | #define PNV_IODA_PE_BUS (1 << 1) /* PE has primary PCI bus */ |
| 22 | #define PNV_IODA_PE_BUS_ALL (1 << 2) /* PE has subordinate buses */ |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 23 | |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 24 | /* Data associated with a PE, including IOMMU tracking etc.. */ |
| 25 | struct pnv_ioda_pe { |
Gavin Shan | 7ebdf95 | 2012-08-20 03:49:15 +0000 | [diff] [blame] | 26 | unsigned long flags; |
| 27 | |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 28 | /* A PE can be associated with a single device or an |
| 29 | * entire bus (& children). In the former case, pdev |
| 30 | * is populated, in the later case, pbus is. |
| 31 | */ |
| 32 | struct pci_dev *pdev; |
| 33 | struct pci_bus *pbus; |
| 34 | |
| 35 | /* Effective RID (device RID for a device PE and base bus |
| 36 | * RID with devfn 0 for a bus PE) |
| 37 | */ |
| 38 | unsigned int rid; |
| 39 | |
| 40 | /* PE number */ |
| 41 | unsigned int pe_number; |
| 42 | |
| 43 | /* "Weight" assigned to the PE for the sake of DMA resource |
| 44 | * allocations |
| 45 | */ |
| 46 | unsigned int dma_weight; |
| 47 | |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 48 | /* "Base" iommu table, ie, 4K TCEs, 32-bit DMA */ |
| 49 | int tce32_seg; |
| 50 | int tce32_segcount; |
| 51 | struct iommu_table tce32_table; |
| 52 | |
| 53 | /* XXX TODO: Add support for additional 64-bit iommus */ |
| 54 | |
| 55 | /* MSIs. MVE index is identical for for 32 and 64 bit MSI |
| 56 | * and -1 if not supported. (It's actually identical to the |
| 57 | * PE number) |
| 58 | */ |
| 59 | int mve_number; |
| 60 | |
| 61 | /* Link in list of PE#s */ |
Gavin Shan | 7ebdf95 | 2012-08-20 03:49:15 +0000 | [diff] [blame] | 62 | struct list_head dma_link; |
| 63 | struct list_head list; |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 66 | struct pnv_phb { |
| 67 | struct pci_controller *hose; |
| 68 | enum pnv_phb_type type; |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 69 | enum pnv_phb_model model; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 70 | u64 opal_id; |
| 71 | void __iomem *regs; |
Gavin Shan | db1266c | 2012-08-20 03:49:18 +0000 | [diff] [blame] | 72 | int initialized; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 73 | spinlock_t lock; |
| 74 | |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 75 | #ifdef CONFIG_PCI_MSI |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 76 | unsigned int msi_base; |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 77 | unsigned int msi32_support; |
Gavin Shan | fb1b55d | 2013-03-05 21:12:37 +0000 | [diff] [blame^] | 78 | struct msi_bitmap msi_bmp; |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 79 | #endif |
| 80 | int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev, |
| 81 | unsigned int hwirq, unsigned int is_64, |
| 82 | struct msi_msg *msg); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 83 | void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev); |
| 84 | void (*fixup_phb)(struct pci_controller *hose); |
| 85 | u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn); |
| 86 | |
| 87 | union { |
| 88 | struct { |
| 89 | struct iommu_table iommu_table; |
| 90 | } p5ioc2; |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 91 | |
| 92 | struct { |
| 93 | /* Global bridge info */ |
| 94 | unsigned int total_pe; |
| 95 | unsigned int m32_size; |
| 96 | unsigned int m32_segsize; |
| 97 | unsigned int m32_pci_base; |
| 98 | unsigned int io_size; |
| 99 | unsigned int io_segsize; |
| 100 | unsigned int io_pci_base; |
| 101 | |
| 102 | /* PE allocation bitmap */ |
| 103 | unsigned long *pe_alloc; |
| 104 | |
| 105 | /* M32 & IO segment maps */ |
| 106 | unsigned int *m32_segmap; |
| 107 | unsigned int *io_segmap; |
| 108 | struct pnv_ioda_pe *pe_array; |
| 109 | |
Gavin Shan | 7ebdf95 | 2012-08-20 03:49:15 +0000 | [diff] [blame] | 110 | /* Sorted list of used PE's based |
| 111 | * on the sequence of creation |
| 112 | */ |
| 113 | struct list_head pe_list; |
| 114 | |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 115 | /* Reverse map of PEs, will have to extend if |
| 116 | * we are to support more than 256 PEs, indexed |
| 117 | * bus { bus, devfn } |
| 118 | */ |
| 119 | unsigned char pe_rmap[0x10000]; |
| 120 | |
| 121 | /* 32-bit TCE tables allocation */ |
| 122 | unsigned long tce32_count; |
| 123 | |
| 124 | /* Total "weight" for the sake of DMA resources |
| 125 | * allocation |
| 126 | */ |
| 127 | unsigned int dma_weight; |
| 128 | unsigned int dma_pe_count; |
| 129 | |
| 130 | /* Sorted list of used PE's, sorted at |
| 131 | * boot for resource allocation purposes |
| 132 | */ |
Gavin Shan | 7ebdf95 | 2012-08-20 03:49:15 +0000 | [diff] [blame] | 133 | struct list_head pe_dma_list; |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 134 | } ioda; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 135 | }; |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 136 | |
| 137 | /* PHB status structure */ |
| 138 | union { |
| 139 | unsigned char blob[PNV_PCI_DIAG_BUF_SIZE]; |
| 140 | struct OpalIoP7IOCPhbErrorData p7ioc; |
| 141 | } diag; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | extern struct pci_ops pnv_pci_ops; |
| 145 | |
| 146 | extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl, |
| 147 | void *tce_mem, u64 tce_size, |
| 148 | u64 dma_offset); |
| 149 | extern void pnv_pci_init_p5ioc2_hub(struct device_node *np); |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 150 | extern void pnv_pci_init_ioda_hub(struct device_node *np); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 151 | |
| 152 | |
| 153 | #endif /* __POWERNV_PCI_H */ |