pci.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #ifndef __POWERNV_PCI_H
  2. #define __POWERNV_PCI_H
  3. struct pci_dn;
  4. enum pnv_phb_type {
  5. PNV_PHB_P5IOC2 = 0,
  6. PNV_PHB_IODA1 = 1,
  7. PNV_PHB_IODA2 = 2,
  8. PNV_PHB_NPU = 3,
  9. };
  10. /* Precise PHB model for error management */
  11. enum pnv_phb_model {
  12. PNV_PHB_MODEL_UNKNOWN,
  13. PNV_PHB_MODEL_P5IOC2,
  14. PNV_PHB_MODEL_P7IOC,
  15. PNV_PHB_MODEL_PHB3,
  16. PNV_PHB_MODEL_NPU,
  17. };
  18. #define PNV_PCI_DIAG_BUF_SIZE 8192
  19. #define PNV_IODA_PE_DEV (1 << 0) /* PE has single PCI device */
  20. #define PNV_IODA_PE_BUS (1 << 1) /* PE has primary PCI bus */
  21. #define PNV_IODA_PE_BUS_ALL (1 << 2) /* PE has subordinate buses */
  22. #define PNV_IODA_PE_MASTER (1 << 3) /* Master PE in compound case */
  23. #define PNV_IODA_PE_SLAVE (1 << 4) /* Slave PE in compound case */
  24. #define PNV_IODA_PE_VF (1 << 5) /* PE for one VF */
  25. #define PNV_IODA_PE_PEER (1 << 6) /* PE has peers */
  26. /* Data associated with a PE, including IOMMU tracking etc.. */
  27. struct pnv_phb;
  28. struct pnv_ioda_pe {
  29. unsigned long flags;
  30. struct pnv_phb *phb;
  31. #define PNV_IODA_MAX_PEER_PES 8
  32. struct pnv_ioda_pe *peers[PNV_IODA_MAX_PEER_PES];
  33. /* A PE can be associated with a single device or an
  34. * entire bus (& children). In the former case, pdev
  35. * is populated, in the later case, pbus is.
  36. */
  37. #ifdef CONFIG_PCI_IOV
  38. struct pci_dev *parent_dev;
  39. #endif
  40. struct pci_dev *pdev;
  41. struct pci_bus *pbus;
  42. /* Effective RID (device RID for a device PE and base bus
  43. * RID with devfn 0 for a bus PE)
  44. */
  45. unsigned int rid;
  46. /* PE number */
  47. unsigned int pe_number;
  48. /* "Weight" assigned to the PE for the sake of DMA resource
  49. * allocations
  50. */
  51. unsigned int dma_weight;
  52. /* "Base" iommu table, ie, 4K TCEs, 32-bit DMA */
  53. int tce32_seg;
  54. int tce32_segcount;
  55. struct iommu_table_group table_group;
  56. /* 64-bit TCE bypass region */
  57. bool tce_bypass_enabled;
  58. uint64_t tce_bypass_base;
  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. /* PEs in compound case */
  65. struct pnv_ioda_pe *master;
  66. struct list_head slaves;
  67. /* Link in list of PE#s */
  68. struct list_head dma_link;
  69. struct list_head list;
  70. };
  71. #define PNV_PHB_FLAG_EEH (1 << 0)
  72. struct pnv_phb {
  73. struct pci_controller *hose;
  74. enum pnv_phb_type type;
  75. enum pnv_phb_model model;
  76. u64 hub_id;
  77. u64 opal_id;
  78. int flags;
  79. void __iomem *regs;
  80. int initialized;
  81. spinlock_t lock;
  82. #ifdef CONFIG_DEBUG_FS
  83. int has_dbgfs;
  84. struct dentry *dbgfs;
  85. #endif
  86. #ifdef CONFIG_PCI_MSI
  87. unsigned int msi_base;
  88. unsigned int msi32_support;
  89. struct msi_bitmap msi_bmp;
  90. #endif
  91. int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
  92. unsigned int hwirq, unsigned int virq,
  93. unsigned int is_64, struct msi_msg *msg);
  94. void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
  95. void (*fixup_phb)(struct pci_controller *hose);
  96. u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn);
  97. int (*init_m64)(struct pnv_phb *phb);
  98. void (*reserve_m64_pe)(struct pci_bus *bus,
  99. unsigned long *pe_bitmap, bool all);
  100. int (*pick_m64_pe)(struct pci_bus *bus, bool all);
  101. int (*get_pe_state)(struct pnv_phb *phb, int pe_no);
  102. void (*freeze_pe)(struct pnv_phb *phb, int pe_no);
  103. int (*unfreeze_pe)(struct pnv_phb *phb, int pe_no, int opt);
  104. union {
  105. struct {
  106. struct iommu_table iommu_table;
  107. struct iommu_table_group table_group;
  108. } p5ioc2;
  109. struct {
  110. /* Global bridge info */
  111. unsigned int total_pe;
  112. unsigned int reserved_pe;
  113. /* 32-bit MMIO window */
  114. unsigned int m32_size;
  115. unsigned int m32_segsize;
  116. unsigned int m32_pci_base;
  117. /* 64-bit MMIO window */
  118. unsigned int m64_bar_idx;
  119. unsigned long m64_size;
  120. unsigned long m64_segsize;
  121. unsigned long m64_base;
  122. unsigned long m64_bar_alloc;
  123. /* IO ports */
  124. unsigned int io_size;
  125. unsigned int io_segsize;
  126. unsigned int io_pci_base;
  127. /* PE allocation bitmap */
  128. unsigned long *pe_alloc;
  129. /* PE allocation mutex */
  130. struct mutex pe_alloc_mutex;
  131. /* M32 & IO segment maps */
  132. unsigned int *m32_segmap;
  133. unsigned int *io_segmap;
  134. struct pnv_ioda_pe *pe_array;
  135. /* IRQ chip */
  136. int irq_chip_init;
  137. struct irq_chip irq_chip;
  138. /* Sorted list of used PE's based
  139. * on the sequence of creation
  140. */
  141. struct list_head pe_list;
  142. struct mutex pe_list_mutex;
  143. /* 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. /* 32-bit TCE tables allocation */
  149. unsigned long tce32_count;
  150. /* Total "weight" for the sake of DMA resources
  151. * allocation
  152. */
  153. unsigned int dma_weight;
  154. unsigned int dma_pe_count;
  155. /* Sorted list of used PE's, sorted at
  156. * boot for resource allocation purposes
  157. */
  158. struct list_head pe_dma_list;
  159. /* TCE cache invalidate registers (physical and
  160. * remapped)
  161. */
  162. phys_addr_t tce_inval_reg_phys;
  163. __be64 __iomem *tce_inval_reg;
  164. } ioda;
  165. };
  166. /* PHB and hub status structure */
  167. union {
  168. unsigned char blob[PNV_PCI_DIAG_BUF_SIZE];
  169. struct OpalIoP7IOCPhbErrorData p7ioc;
  170. struct OpalIoPhb3ErrorData phb3;
  171. struct OpalIoP7IOCErrorData hub_diag;
  172. } diag;
  173. };
  174. extern struct pci_ops pnv_pci_ops;
  175. extern int pnv_tce_build(struct iommu_table *tbl, long index, long npages,
  176. unsigned long uaddr, enum dma_data_direction direction,
  177. struct dma_attrs *attrs);
  178. extern void pnv_tce_free(struct iommu_table *tbl, long index, long npages);
  179. extern int pnv_tce_xchg(struct iommu_table *tbl, long index,
  180. unsigned long *hpa, enum dma_data_direction *direction);
  181. extern unsigned long pnv_tce_get(struct iommu_table *tbl, long index);
  182. void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
  183. unsigned char *log_buff);
  184. int pnv_pci_cfg_read(struct pci_dn *pdn,
  185. int where, int size, u32 *val);
  186. int pnv_pci_cfg_write(struct pci_dn *pdn,
  187. int where, int size, u32 val);
  188. extern struct iommu_table *pnv_pci_table_alloc(int nid);
  189. extern long pnv_pci_link_table_and_group(int node, int num,
  190. struct iommu_table *tbl,
  191. struct iommu_table_group *table_group);
  192. extern void pnv_pci_unlink_table_and_group(struct iommu_table *tbl,
  193. struct iommu_table_group *table_group);
  194. extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
  195. void *tce_mem, u64 tce_size,
  196. u64 dma_offset, unsigned page_shift);
  197. extern void pnv_pci_init_p5ioc2_hub(struct device_node *np);
  198. extern void pnv_pci_init_ioda_hub(struct device_node *np);
  199. extern void pnv_pci_init_ioda2_phb(struct device_node *np);
  200. extern void pnv_pci_init_npu_phb(struct device_node *np);
  201. extern void pnv_pci_ioda_tce_invalidate(struct iommu_table *tbl,
  202. __be64 *startp, __be64 *endp, bool rm);
  203. extern void pnv_pci_reset_secondary_bus(struct pci_dev *dev);
  204. extern int pnv_eeh_phb_reset(struct pci_controller *hose, int option);
  205. extern void pnv_pci_dma_dev_setup(struct pci_dev *pdev);
  206. extern int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type);
  207. extern void pnv_teardown_msi_irqs(struct pci_dev *pdev);
  208. /* Nvlink functions */
  209. extern void pnv_npu_tce_invalidate_entire(struct pnv_ioda_pe *npe);
  210. extern void pnv_npu_tce_invalidate(struct pnv_ioda_pe *npe,
  211. struct iommu_table *tbl,
  212. unsigned long index,
  213. unsigned long npages,
  214. bool rm);
  215. extern void pnv_npu_init_dma_pe(struct pnv_ioda_pe *npe);
  216. extern void pnv_npu_setup_dma_pe(struct pnv_ioda_pe *npe);
  217. extern int pnv_npu_dma_set_bypass(struct pnv_ioda_pe *npe, bool enabled);
  218. extern int pnv_npu_dma_set_mask(struct pci_dev *npdev, u64 dma_mask);
  219. #endif /* __POWERNV_PCI_H */