pci.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 (*next_error)(struct eeh_pe **pe);
  74. };
  75. #endif /* CONFIG_EEH */
  76. #define PNV_PHB_FLAG_EEH (1 << 0)
  77. struct pnv_phb {
  78. struct pci_controller *hose;
  79. enum pnv_phb_type type;
  80. enum pnv_phb_model model;
  81. u64 hub_id;
  82. u64 opal_id;
  83. int flags;
  84. void __iomem *regs;
  85. int initialized;
  86. spinlock_t lock;
  87. #ifdef CONFIG_EEH
  88. struct pnv_eeh_ops *eeh_ops;
  89. #endif
  90. #ifdef CONFIG_DEBUG_FS
  91. int has_dbgfs;
  92. struct dentry *dbgfs;
  93. #endif
  94. #ifdef CONFIG_PCI_MSI
  95. unsigned int msi_base;
  96. unsigned int msi32_support;
  97. struct msi_bitmap msi_bmp;
  98. #endif
  99. int (*msi_setup)(struct pnv_phb *phb, struct pci_dev *dev,
  100. unsigned int hwirq, unsigned int virq,
  101. unsigned int is_64, struct msi_msg *msg);
  102. void (*dma_dev_setup)(struct pnv_phb *phb, struct pci_dev *pdev);
  103. int (*dma_set_mask)(struct pnv_phb *phb, struct pci_dev *pdev,
  104. u64 dma_mask);
  105. void (*fixup_phb)(struct pci_controller *hose);
  106. u32 (*bdfn_to_pe)(struct pnv_phb *phb, struct pci_bus *bus, u32 devfn);
  107. void (*shutdown)(struct pnv_phb *phb);
  108. int (*init_m64)(struct pnv_phb *phb);
  109. void (*alloc_m64_pe)(struct pnv_phb *phb);
  110. int (*pick_m64_pe)(struct pnv_phb *phb, struct pci_bus *bus, int all);
  111. int (*get_pe_state)(struct pnv_phb *phb, int pe_no);
  112. void (*freeze_pe)(struct pnv_phb *phb, int pe_no);
  113. int (*unfreeze_pe)(struct pnv_phb *phb, int pe_no, int opt);
  114. union {
  115. struct {
  116. struct iommu_table iommu_table;
  117. } p5ioc2;
  118. struct {
  119. /* Global bridge info */
  120. unsigned int total_pe;
  121. unsigned int reserved_pe;
  122. /* 32-bit MMIO window */
  123. unsigned int m32_size;
  124. unsigned int m32_segsize;
  125. unsigned int m32_pci_base;
  126. /* 64-bit MMIO window */
  127. unsigned int m64_bar_idx;
  128. unsigned long m64_size;
  129. unsigned long m64_segsize;
  130. unsigned long m64_base;
  131. unsigned long m64_bar_alloc;
  132. /* IO ports */
  133. unsigned int io_size;
  134. unsigned int io_segsize;
  135. unsigned int io_pci_base;
  136. /* PE allocation bitmap */
  137. unsigned long *pe_alloc;
  138. /* M32 & IO segment maps */
  139. unsigned int *m32_segmap;
  140. unsigned int *io_segmap;
  141. struct pnv_ioda_pe *pe_array;
  142. /* IRQ chip */
  143. int irq_chip_init;
  144. struct irq_chip irq_chip;
  145. /* Sorted list of used PE's based
  146. * on the sequence of creation
  147. */
  148. struct list_head pe_list;
  149. /* Reverse map of PEs, will have to extend if
  150. * we are to support more than 256 PEs, indexed
  151. * bus { bus, devfn }
  152. */
  153. unsigned char pe_rmap[0x10000];
  154. /* 32-bit TCE tables allocation */
  155. unsigned long tce32_count;
  156. /* Total "weight" for the sake of DMA resources
  157. * allocation
  158. */
  159. unsigned int dma_weight;
  160. unsigned int dma_pe_count;
  161. /* Sorted list of used PE's, sorted at
  162. * boot for resource allocation purposes
  163. */
  164. struct list_head pe_dma_list;
  165. } ioda;
  166. };
  167. /* PHB and hub status structure */
  168. union {
  169. unsigned char blob[PNV_PCI_DIAG_BUF_SIZE];
  170. struct OpalIoP7IOCPhbErrorData p7ioc;
  171. struct OpalIoPhb3ErrorData phb3;
  172. struct OpalIoP7IOCErrorData hub_diag;
  173. } diag;
  174. };
  175. extern struct pci_ops pnv_pci_ops;
  176. #ifdef CONFIG_EEH
  177. extern struct pnv_eeh_ops ioda_eeh_ops;
  178. #endif
  179. void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
  180. unsigned char *log_buff);
  181. int pnv_pci_cfg_read(struct device_node *dn,
  182. int where, int size, u32 *val);
  183. int pnv_pci_cfg_write(struct device_node *dn,
  184. int where, int size, u32 val);
  185. extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
  186. void *tce_mem, u64 tce_size,
  187. u64 dma_offset, unsigned page_shift);
  188. extern void pnv_pci_init_p5ioc2_hub(struct device_node *np);
  189. extern void pnv_pci_init_ioda_hub(struct device_node *np);
  190. extern void pnv_pci_init_ioda2_phb(struct device_node *np);
  191. extern void pnv_pci_ioda_tce_invalidate(struct iommu_table *tbl,
  192. __be64 *startp, __be64 *endp, bool rm);
  193. extern void pnv_pci_reset_secondary_bus(struct pci_dev *dev);
  194. extern int ioda_eeh_phb_reset(struct pci_controller *hose, int option);
  195. #endif /* __POWERNV_PCI_H */