pci.h 6.8 KB

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