pci.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #ifndef __POWERNV_PCI_H
  2. #define __POWERNV_PCI_H
  3. #include <linux/iommu.h>
  4. #include <asm/iommu.h>
  5. #include <asm/msi_bitmap.h>
  6. struct pci_dn;
  7. enum pnv_phb_type {
  8. PNV_PHB_IODA1 = 0,
  9. PNV_PHB_IODA2 = 1,
  10. PNV_PHB_NPU = 2,
  11. };
  12. /* Precise PHB model for error management */
  13. enum pnv_phb_model {
  14. PNV_PHB_MODEL_UNKNOWN,
  15. PNV_PHB_MODEL_P7IOC,
  16. PNV_PHB_MODEL_PHB3,
  17. PNV_PHB_MODEL_NPU,
  18. };
  19. #define PNV_PCI_DIAG_BUF_SIZE 8192
  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 */
  23. #define PNV_IODA_PE_MASTER (1 << 3) /* Master PE in compound case */
  24. #define PNV_IODA_PE_SLAVE (1 << 4) /* Slave PE in compound case */
  25. #define PNV_IODA_PE_VF (1 << 5) /* PE for one VF */
  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. int device_count;
  32. /* A PE can be associated with a single device or an
  33. * entire bus (& children). In the former case, pdev
  34. * is populated, in the later case, pbus is.
  35. */
  36. #ifdef CONFIG_PCI_IOV
  37. struct pci_dev *parent_dev;
  38. #endif
  39. struct pci_dev *pdev;
  40. struct pci_bus *pbus;
  41. /* Effective RID (device RID for a device PE and base bus
  42. * RID with devfn 0 for a bus PE)
  43. */
  44. unsigned int rid;
  45. /* PE number */
  46. unsigned int pe_number;
  47. /* "Base" iommu table, ie, 4K TCEs, 32-bit DMA */
  48. struct iommu_table_group table_group;
  49. /* 64-bit TCE bypass region */
  50. bool tce_bypass_enabled;
  51. uint64_t tce_bypass_base;
  52. /* MSIs. MVE index is identical for for 32 and 64 bit MSI
  53. * and -1 if not supported. (It's actually identical to the
  54. * PE number)
  55. */
  56. int mve_number;
  57. /* PEs in compound case */
  58. struct pnv_ioda_pe *master;
  59. struct list_head slaves;
  60. /* Link in list of PE#s */
  61. struct list_head list;
  62. };
  63. #define PNV_PHB_FLAG_EEH (1 << 0)
  64. #define PNV_PHB_FLAG_CXL (1 << 1) /* Real PHB supporting the cxl kernel API */
  65. struct pnv_phb {
  66. struct pci_controller *hose;
  67. enum pnv_phb_type type;
  68. enum pnv_phb_model model;
  69. u64 hub_id;
  70. u64 opal_id;
  71. int flags;
  72. void __iomem *regs;
  73. u64 regs_phys;
  74. int initialized;
  75. spinlock_t lock;
  76. #ifdef CONFIG_DEBUG_FS
  77. int has_dbgfs;
  78. struct dentry *dbgfs;
  79. #endif
  80. #ifdef CONFIG_PCI_MSI
  81. unsigned int msi_base;
  82. unsigned int msi32_support;
  83. struct msi_bitmap msi_bmp;
  84. #endif
  85. int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
  86. unsigned int hwirq, unsigned int virq,
  87. unsigned int is_64, struct msi_msg *msg);
  88. void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
  89. void (*fixup_phb)(struct pci_controller *hose);
  90. int (*init_m64)(struct pnv_phb *phb);
  91. void (*reserve_m64_pe)(struct pci_bus *bus,
  92. unsigned long *pe_bitmap, bool all);
  93. struct pnv_ioda_pe *(*pick_m64_pe)(struct pci_bus *bus, bool all);
  94. int (*get_pe_state)(struct pnv_phb *phb, int pe_no);
  95. void (*freeze_pe)(struct pnv_phb *phb, int pe_no);
  96. int (*unfreeze_pe)(struct pnv_phb *phb, int pe_no, int opt);
  97. struct {
  98. /* Global bridge info */
  99. unsigned int total_pe_num;
  100. unsigned int reserved_pe_idx;
  101. unsigned int root_pe_idx;
  102. bool root_pe_populated;
  103. /* 32-bit MMIO window */
  104. unsigned int m32_size;
  105. unsigned int m32_segsize;
  106. unsigned int m32_pci_base;
  107. /* 64-bit MMIO window */
  108. unsigned int m64_bar_idx;
  109. unsigned long m64_size;
  110. unsigned long m64_segsize;
  111. unsigned long m64_base;
  112. unsigned long m64_bar_alloc;
  113. /* IO ports */
  114. unsigned int io_size;
  115. unsigned int io_segsize;
  116. unsigned int io_pci_base;
  117. /* PE allocation */
  118. struct mutex pe_alloc_mutex;
  119. unsigned long *pe_alloc;
  120. struct pnv_ioda_pe *pe_array;
  121. /* M32 & IO segment maps */
  122. unsigned int *m64_segmap;
  123. unsigned int *m32_segmap;
  124. unsigned int *io_segmap;
  125. /* DMA32 segment maps - IODA1 only */
  126. unsigned int dma32_count;
  127. unsigned int *dma32_segmap;
  128. /* IRQ chip */
  129. int irq_chip_init;
  130. struct irq_chip irq_chip;
  131. /* Sorted list of used PE's based
  132. * on the sequence of creation
  133. */
  134. struct list_head pe_list;
  135. struct mutex pe_list_mutex;
  136. /* Reverse map of PEs, indexed by {bus, devfn} */
  137. unsigned int pe_rmap[0x10000];
  138. } ioda;
  139. /* PHB and hub status structure */
  140. union {
  141. unsigned char blob[PNV_PCI_DIAG_BUF_SIZE];
  142. struct OpalIoP7IOCPhbErrorData p7ioc;
  143. struct OpalIoPhb3ErrorData phb3;
  144. struct OpalIoP7IOCErrorData hub_diag;
  145. } diag;
  146. #ifdef CONFIG_CXL_BASE
  147. struct cxl_afu *cxl_afu;
  148. #endif
  149. };
  150. extern struct pci_ops pnv_pci_ops;
  151. extern int pnv_tce_build(struct iommu_table *tbl, long index, long npages,
  152. unsigned long uaddr, enum dma_data_direction direction,
  153. unsigned long attrs);
  154. extern void pnv_tce_free(struct iommu_table *tbl, long index, long npages);
  155. extern int pnv_tce_xchg(struct iommu_table *tbl, long index,
  156. unsigned long *hpa, enum dma_data_direction *direction);
  157. extern unsigned long pnv_tce_get(struct iommu_table *tbl, long index);
  158. void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
  159. unsigned char *log_buff);
  160. int pnv_pci_cfg_read(struct pci_dn *pdn,
  161. int where, int size, u32 *val);
  162. int pnv_pci_cfg_write(struct pci_dn *pdn,
  163. int where, int size, u32 val);
  164. extern struct iommu_table *pnv_pci_table_alloc(int nid);
  165. extern long pnv_pci_link_table_and_group(int node, int num,
  166. struct iommu_table *tbl,
  167. struct iommu_table_group *table_group);
  168. extern void pnv_pci_unlink_table_and_group(struct iommu_table *tbl,
  169. struct iommu_table_group *table_group);
  170. extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
  171. void *tce_mem, u64 tce_size,
  172. u64 dma_offset, unsigned page_shift);
  173. extern void pnv_pci_init_ioda_hub(struct device_node *np);
  174. extern void pnv_pci_init_ioda2_phb(struct device_node *np);
  175. extern void pnv_pci_init_npu_phb(struct device_node *np);
  176. extern void pnv_pci_reset_secondary_bus(struct pci_dev *dev);
  177. extern int pnv_eeh_phb_reset(struct pci_controller *hose, int option);
  178. extern void pnv_pci_dma_dev_setup(struct pci_dev *pdev);
  179. extern void pnv_pci_dma_bus_setup(struct pci_bus *bus);
  180. extern int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type);
  181. extern void pnv_teardown_msi_irqs(struct pci_dev *pdev);
  182. extern struct pnv_ioda_pe *pnv_ioda_get_pe(struct pci_dev *dev);
  183. extern void pnv_set_msi_irq_chip(struct pnv_phb *phb, unsigned int virq);
  184. extern bool pnv_pci_enable_device_hook(struct pci_dev *dev);
  185. extern void pe_level_printk(const struct pnv_ioda_pe *pe, const char *level,
  186. const char *fmt, ...);
  187. #define pe_err(pe, fmt, ...) \
  188. pe_level_printk(pe, KERN_ERR, fmt, ##__VA_ARGS__)
  189. #define pe_warn(pe, fmt, ...) \
  190. pe_level_printk(pe, KERN_WARNING, fmt, ##__VA_ARGS__)
  191. #define pe_info(pe, fmt, ...) \
  192. pe_level_printk(pe, KERN_INFO, fmt, ##__VA_ARGS__)
  193. /* Nvlink functions */
  194. extern void pnv_npu_try_dma_set_bypass(struct pci_dev *gpdev, bool bypass);
  195. extern void pnv_pci_phb3_tce_invalidate_entire(struct pnv_phb *phb, bool rm);
  196. extern struct pnv_ioda_pe *pnv_pci_npu_setup_iommu(struct pnv_ioda_pe *npe);
  197. extern long pnv_npu_set_window(struct pnv_ioda_pe *npe, int num,
  198. struct iommu_table *tbl);
  199. extern long pnv_npu_unset_window(struct pnv_ioda_pe *npe, int num);
  200. extern void pnv_npu_take_ownership(struct pnv_ioda_pe *npe);
  201. extern void pnv_npu_release_ownership(struct pnv_ioda_pe *npe);
  202. /* cxl functions */
  203. extern bool pnv_cxl_enable_device_hook(struct pci_dev *dev);
  204. extern void pnv_cxl_disable_device(struct pci_dev *dev);
  205. extern int pnv_cxl_cx4_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type);
  206. extern void pnv_cxl_cx4_teardown_msi_irqs(struct pci_dev *pdev);
  207. /* phb ops (cxl switches these when enabling the kernel api on the phb) */
  208. extern const struct pci_controller_ops pnv_cxl_cx4_ioda_controller_ops;
  209. #endif /* __POWERNV_PCI_H */