pci.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. void (*fixup_phb)(struct pci_controller *hose);
  91. u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn);
  92. int (*init_m64)(struct pnv_phb *phb);
  93. void (*reserve_m64_pe)(struct pci_bus *bus,
  94. unsigned long *pe_bitmap, bool all);
  95. int (*pick_m64_pe)(struct pci_bus *bus, bool all);
  96. int (*get_pe_state)(struct pnv_phb *phb, int pe_no);
  97. void (*freeze_pe)(struct pnv_phb *phb, int pe_no);
  98. int (*unfreeze_pe)(struct pnv_phb *phb, int pe_no, int opt);
  99. union {
  100. struct {
  101. struct iommu_table iommu_table;
  102. struct iommu_table_group table_group;
  103. } p5ioc2;
  104. struct {
  105. /* Global bridge info */
  106. unsigned int total_pe;
  107. unsigned int reserved_pe;
  108. /* 32-bit MMIO window */
  109. unsigned int m32_size;
  110. unsigned int m32_segsize;
  111. unsigned int m32_pci_base;
  112. /* 64-bit MMIO window */
  113. unsigned int m64_bar_idx;
  114. unsigned long m64_size;
  115. unsigned long m64_segsize;
  116. unsigned long m64_base;
  117. unsigned long m64_bar_alloc;
  118. /* IO ports */
  119. unsigned int io_size;
  120. unsigned int io_segsize;
  121. unsigned int io_pci_base;
  122. /* PE allocation bitmap */
  123. unsigned long *pe_alloc;
  124. /* PE allocation mutex */
  125. struct mutex pe_alloc_mutex;
  126. /* M32 & IO segment maps */
  127. unsigned int *m32_segmap;
  128. unsigned int *io_segmap;
  129. struct pnv_ioda_pe *pe_array;
  130. /* IRQ chip */
  131. int irq_chip_init;
  132. struct irq_chip irq_chip;
  133. /* Sorted list of used PE's based
  134. * on the sequence of creation
  135. */
  136. struct list_head pe_list;
  137. struct mutex pe_list_mutex;
  138. /* Reverse map of PEs, will have to extend if
  139. * we are to support more than 256 PEs, indexed
  140. * bus { bus, devfn }
  141. */
  142. unsigned char pe_rmap[0x10000];
  143. /* 32-bit TCE tables allocation */
  144. unsigned long tce32_count;
  145. /* Total "weight" for the sake of DMA resources
  146. * allocation
  147. */
  148. unsigned int dma_weight;
  149. unsigned int dma_pe_count;
  150. /* Sorted list of used PE's, sorted at
  151. * boot for resource allocation purposes
  152. */
  153. struct list_head pe_dma_list;
  154. /* TCE cache invalidate registers (physical and
  155. * remapped)
  156. */
  157. phys_addr_t tce_inval_reg_phys;
  158. __be64 __iomem *tce_inval_reg;
  159. } ioda;
  160. };
  161. /* PHB and hub status structure */
  162. union {
  163. unsigned char blob[PNV_PCI_DIAG_BUF_SIZE];
  164. struct OpalIoP7IOCPhbErrorData p7ioc;
  165. struct OpalIoPhb3ErrorData phb3;
  166. struct OpalIoP7IOCErrorData hub_diag;
  167. } diag;
  168. };
  169. extern struct pci_ops pnv_pci_ops;
  170. extern int pnv_tce_build(struct iommu_table *tbl, long index, long npages,
  171. unsigned long uaddr, enum dma_data_direction direction,
  172. struct dma_attrs *attrs);
  173. extern void pnv_tce_free(struct iommu_table *tbl, long index, long npages);
  174. extern int pnv_tce_xchg(struct iommu_table *tbl, long index,
  175. unsigned long *hpa, enum dma_data_direction *direction);
  176. extern unsigned long pnv_tce_get(struct iommu_table *tbl, long index);
  177. void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
  178. unsigned char *log_buff);
  179. int pnv_pci_cfg_read(struct pci_dn *pdn,
  180. int where, int size, u32 *val);
  181. int pnv_pci_cfg_write(struct pci_dn *pdn,
  182. int where, int size, u32 val);
  183. extern struct iommu_table *pnv_pci_table_alloc(int nid);
  184. extern long pnv_pci_link_table_and_group(int node, int num,
  185. struct iommu_table *tbl,
  186. struct iommu_table_group *table_group);
  187. extern void pnv_pci_unlink_table_and_group(struct iommu_table *tbl,
  188. struct iommu_table_group *table_group);
  189. extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
  190. void *tce_mem, u64 tce_size,
  191. u64 dma_offset, unsigned page_shift);
  192. extern void pnv_pci_init_p5ioc2_hub(struct device_node *np);
  193. extern void pnv_pci_init_ioda_hub(struct device_node *np);
  194. extern void pnv_pci_init_ioda2_phb(struct device_node *np);
  195. extern void pnv_pci_ioda_tce_invalidate(struct iommu_table *tbl,
  196. __be64 *startp, __be64 *endp, bool rm);
  197. extern void pnv_pci_reset_secondary_bus(struct pci_dev *dev);
  198. extern int pnv_eeh_phb_reset(struct pci_controller *hose, int option);
  199. extern void pnv_pci_dma_dev_setup(struct pci_dev *pdev);
  200. extern int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type);
  201. extern void pnv_teardown_msi_irqs(struct pci_dev *pdev);
  202. #endif /* __POWERNV_PCI_H */