pci.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. /* Data associated with a PE, including IOMMU tracking etc.. */
  23. struct pnv_phb;
  24. struct pnv_ioda_pe {
  25. unsigned long flags;
  26. struct pnv_phb *phb;
  27. /* A PE can be associated with a single device or an
  28. * entire bus (& children). In the former case, pdev
  29. * is populated, in the later case, pbus is.
  30. */
  31. struct pci_dev *pdev;
  32. struct pci_bus *pbus;
  33. /* Effective RID (device RID for a device PE and base bus
  34. * RID with devfn 0 for a bus PE)
  35. */
  36. unsigned int rid;
  37. /* PE number */
  38. unsigned int pe_number;
  39. /* "Weight" assigned to the PE for the sake of DMA resource
  40. * allocations
  41. */
  42. unsigned int dma_weight;
  43. /* "Base" iommu table, ie, 4K TCEs, 32-bit DMA */
  44. int tce32_seg;
  45. int tce32_segcount;
  46. struct iommu_table tce32_table;
  47. phys_addr_t tce_inval_reg_phys;
  48. /* 64-bit TCE bypass region */
  49. bool tce_bypass_enabled;
  50. uint64_t tce_bypass_base;
  51. /* MSIs. MVE index is identical for for 32 and 64 bit MSI
  52. * and -1 if not supported. (It's actually identical to the
  53. * PE number)
  54. */
  55. int mve_number;
  56. /* PEs in compound case */
  57. struct pnv_ioda_pe *master;
  58. struct list_head slaves;
  59. /* Link in list of PE#s */
  60. struct list_head dma_link;
  61. struct list_head list;
  62. };
  63. /* IOC dependent EEH operations */
  64. #ifdef CONFIG_EEH
  65. struct pnv_eeh_ops {
  66. int (*post_init)(struct pci_controller *hose);
  67. int (*set_option)(struct eeh_pe *pe, int option);
  68. int (*get_state)(struct eeh_pe *pe);
  69. int (*reset)(struct eeh_pe *pe, int option);
  70. int (*get_log)(struct eeh_pe *pe, int severity,
  71. char *drv_log, unsigned long len);
  72. int (*configure_bridge)(struct eeh_pe *pe);
  73. int (*err_inject)(struct eeh_pe *pe, int type, int func,
  74. unsigned long addr, unsigned long mask);
  75. int (*next_error)(struct eeh_pe **pe);
  76. };
  77. #endif /* CONFIG_EEH */
  78. #define PNV_PHB_FLAG_EEH (1 << 0)
  79. struct pnv_phb {
  80. struct pci_controller *hose;
  81. enum pnv_phb_type type;
  82. enum pnv_phb_model model;
  83. u64 hub_id;
  84. u64 opal_id;
  85. int flags;
  86. void __iomem *regs;
  87. int initialized;
  88. spinlock_t lock;
  89. #ifdef CONFIG_EEH
  90. struct pnv_eeh_ops *eeh_ops;
  91. #endif
  92. #ifdef CONFIG_DEBUG_FS
  93. int has_dbgfs;
  94. struct dentry *dbgfs;
  95. #endif
  96. #ifdef CONFIG_PCI_MSI
  97. unsigned int msi_base;
  98. unsigned int msi32_support;
  99. struct msi_bitmap msi_bmp;
  100. #endif
  101. int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
  102. unsigned int hwirq, unsigned int virq,
  103. unsigned int is_64, struct msi_msg *msg);
  104. void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
  105. int (*dma_set_mask)(struct pnv_phb *phb, struct pci_dev *pdev,
  106. u64 dma_mask);
  107. u64 (*dma_get_required_mask)(struct pnv_phb *phb,
  108. struct pci_dev *pdev);
  109. void (*fixup_phb)(struct pci_controller *hose);
  110. u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn);
  111. void (*shutdown)(struct pnv_phb *phb);
  112. int (*init_m64)(struct pnv_phb *phb);
  113. void (*alloc_m64_pe)(struct pnv_phb *phb);
  114. int (*pick_m64_pe)(struct pnv_phb *phb, struct pci_bus *bus, int all);
  115. int (*get_pe_state)(struct pnv_phb *phb, int pe_no);
  116. void (*freeze_pe)(struct pnv_phb *phb, int pe_no);
  117. int (*unfreeze_pe)(struct pnv_phb *phb, int pe_no, int opt);
  118. union {
  119. struct {
  120. struct iommu_table iommu_table;
  121. } p5ioc2;
  122. struct {
  123. /* Global bridge info */
  124. unsigned int total_pe;
  125. unsigned int reserved_pe;
  126. /* 32-bit MMIO window */
  127. unsigned int m32_size;
  128. unsigned int m32_segsize;
  129. unsigned int m32_pci_base;
  130. /* 64-bit MMIO window */
  131. unsigned int m64_bar_idx;
  132. unsigned long m64_size;
  133. unsigned long m64_segsize;
  134. unsigned long m64_base;
  135. unsigned long m64_bar_alloc;
  136. /* IO ports */
  137. unsigned int io_size;
  138. unsigned int io_segsize;
  139. unsigned int io_pci_base;
  140. /* PE allocation bitmap */
  141. unsigned long *pe_alloc;
  142. /* M32 & IO segment maps */
  143. unsigned int *m32_segmap;
  144. unsigned int *io_segmap;
  145. struct pnv_ioda_pe *pe_array;
  146. /* IRQ chip */
  147. int irq_chip_init;
  148. struct irq_chip irq_chip;
  149. /* Sorted list of used PE's based
  150. * on the sequence of creation
  151. */
  152. struct list_head pe_list;
  153. /* Reverse map of PEs, will have to extend if
  154. * we are to support more than 256 PEs, indexed
  155. * bus { bus, devfn }
  156. */
  157. unsigned char pe_rmap[0x10000];
  158. /* 32-bit TCE tables allocation */
  159. unsigned long tce32_count;
  160. /* Total "weight" for the sake of DMA resources
  161. * allocation
  162. */
  163. unsigned int dma_weight;
  164. unsigned int dma_pe_count;
  165. /* Sorted list of used PE's, sorted at
  166. * boot for resource allocation purposes
  167. */
  168. struct list_head pe_dma_list;
  169. } ioda;
  170. };
  171. /* PHB and hub status structure */
  172. union {
  173. unsigned char blob[PNV_PCI_DIAG_BUF_SIZE];
  174. struct OpalIoP7IOCPhbErrorData p7ioc;
  175. struct OpalIoPhb3ErrorData phb3;
  176. struct OpalIoP7IOCErrorData hub_diag;
  177. } diag;
  178. };
  179. extern struct pci_ops pnv_pci_ops;
  180. #ifdef CONFIG_EEH
  181. extern struct pnv_eeh_ops ioda_eeh_ops;
  182. #endif
  183. void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
  184. unsigned char *log_buff);
  185. int pnv_pci_cfg_read(struct device_node *dn,
  186. int where, int size, u32 *val);
  187. int pnv_pci_cfg_write(struct device_node *dn,
  188. int where, int size, u32 val);
  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 ioda_eeh_phb_reset(struct pci_controller *hose, int option);
  199. #endif /* __POWERNV_PCI_H */