pci_impl.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* pci_impl.h: Helper definitions for PCI controller support.
  3. *
  4. * Copyright (C) 1999, 2007 David S. Miller ([email protected])
  5. */
  6. #ifndef PCI_IMPL_H
  7. #define PCI_IMPL_H
  8. #include <linux/types.h>
  9. #include <linux/spinlock.h>
  10. #include <linux/pci.h>
  11. #include <linux/msi.h>
  12. #include <linux/of_device.h>
  13. #include <asm/io.h>
  14. #include <asm/prom.h>
  15. #include <asm/iommu.h>
  16. /* The abstraction used here is that there are PCI controllers,
  17. * each with one (Sabre) or two (PSYCHO/SCHIZO) PCI bus modules
  18. * underneath. Each PCI bus module uses an IOMMU (shared by both
  19. * PBMs of a controller, or per-PBM), and if a streaming buffer
  20. * is present, each PCI bus module has it's own. (ie. the IOMMU
  21. * might be shared between PBMs, the STC is never shared)
  22. * Furthermore, each PCI bus module controls it's own autonomous
  23. * PCI bus.
  24. */
  25. #define PCI_STC_FLUSHFLAG_INIT(STC) \
  26. (*((STC)->strbuf_flushflag) = 0UL)
  27. #define PCI_STC_FLUSHFLAG_SET(STC) \
  28. (*((STC)->strbuf_flushflag) != 0UL)
  29. #ifdef CONFIG_PCI_MSI
  30. struct pci_pbm_info;
  31. struct sparc64_msiq_ops {
  32. int (*get_head)(struct pci_pbm_info *pbm, unsigned long msiqid,
  33. unsigned long *head);
  34. int (*dequeue_msi)(struct pci_pbm_info *pbm, unsigned long msiqid,
  35. unsigned long *head, unsigned long *msi);
  36. int (*set_head)(struct pci_pbm_info *pbm, unsigned long msiqid,
  37. unsigned long head);
  38. int (*msi_setup)(struct pci_pbm_info *pbm, unsigned long msiqid,
  39. unsigned long msi, int is_msi64);
  40. int (*msi_teardown)(struct pci_pbm_info *pbm, unsigned long msi);
  41. int (*msiq_alloc)(struct pci_pbm_info *pbm);
  42. void (*msiq_free)(struct pci_pbm_info *pbm);
  43. int (*msiq_build_irq)(struct pci_pbm_info *pbm, unsigned long msiqid,
  44. unsigned long devino);
  45. };
  46. void sparc64_pbm_msi_init(struct pci_pbm_info *pbm,
  47. const struct sparc64_msiq_ops *ops);
  48. struct sparc64_msiq_cookie {
  49. struct pci_pbm_info *pbm;
  50. unsigned long msiqid;
  51. };
  52. #endif
  53. struct pci_pbm_info {
  54. struct pci_pbm_info *next;
  55. struct pci_pbm_info *sibling;
  56. int index;
  57. /* Physical address base of controller registers. */
  58. unsigned long controller_regs;
  59. /* Physical address base of PBM registers. */
  60. unsigned long pbm_regs;
  61. /* Physical address of DMA sync register, if any. */
  62. unsigned long sync_reg;
  63. /* Opaque 32-bit system bus Port ID. */
  64. u32 portid;
  65. /* Opaque 32-bit handle used for hypervisor calls. */
  66. u32 devhandle;
  67. /* Chipset version information. */
  68. int chip_type;
  69. #define PBM_CHIP_TYPE_SABRE 1
  70. #define PBM_CHIP_TYPE_PSYCHO 2
  71. #define PBM_CHIP_TYPE_SCHIZO 3
  72. #define PBM_CHIP_TYPE_SCHIZO_PLUS 4
  73. #define PBM_CHIP_TYPE_TOMATILLO 5
  74. int chip_version;
  75. int chip_revision;
  76. /* Name used for top-level resources. */
  77. const char *name;
  78. /* OBP specific information. */
  79. struct platform_device *op;
  80. u64 ino_bitmap;
  81. /* PBM I/O and Memory space resources. */
  82. struct resource io_space;
  83. struct resource mem_space;
  84. struct resource mem64_space;
  85. struct resource busn;
  86. /* offset */
  87. resource_size_t io_offset;
  88. resource_size_t mem_offset;
  89. resource_size_t mem64_offset;
  90. /* Base of PCI Config space, can be per-PBM or shared. */
  91. unsigned long config_space;
  92. /* This will be 12 on PCI-E controllers, 8 elsewhere. */
  93. unsigned long config_space_reg_bits;
  94. unsigned long pci_afsr;
  95. unsigned long pci_afar;
  96. unsigned long pci_csr;
  97. /* State of 66MHz capabilities on this PBM. */
  98. int is_66mhz_capable;
  99. int all_devs_66mhz;
  100. #ifdef CONFIG_PCI_MSI
  101. /* MSI info. */
  102. u32 msiq_num;
  103. u32 msiq_ent_count;
  104. u32 msiq_first;
  105. u32 msiq_first_devino;
  106. u32 msiq_rotor;
  107. struct sparc64_msiq_cookie *msiq_irq_cookies;
  108. u32 msi_num;
  109. u32 msi_first;
  110. u32 msi_data_mask;
  111. u32 msix_data_width;
  112. u64 msi32_start;
  113. u64 msi64_start;
  114. u32 msi32_len;
  115. u32 msi64_len;
  116. void *msi_queues;
  117. unsigned long *msi_bitmap;
  118. unsigned int *msi_irq_table;
  119. int (*setup_msi_irq)(unsigned int *irq_p, struct pci_dev *pdev,
  120. struct msi_desc *entry);
  121. void (*teardown_msi_irq)(unsigned int irq, struct pci_dev *pdev);
  122. const struct sparc64_msiq_ops *msi_ops;
  123. #endif /* !(CONFIG_PCI_MSI) */
  124. /* This PBM's streaming buffer. */
  125. struct strbuf stc;
  126. /* IOMMU state, potentially shared by both PBM segments. */
  127. struct iommu *iommu;
  128. /* Now things for the actual PCI bus probes. */
  129. unsigned int pci_first_busno;
  130. unsigned int pci_last_busno;
  131. struct pci_bus *pci_bus;
  132. struct pci_ops *pci_ops;
  133. int numa_node;
  134. };
  135. extern struct pci_pbm_info *pci_pbm_root;
  136. extern int pci_num_pbms;
  137. /* PCI bus scanning and fixup support. */
  138. void pci_get_pbm_props(struct pci_pbm_info *pbm);
  139. struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm,
  140. struct device *parent);
  141. void pci_determine_mem_io_space(struct pci_pbm_info *pbm);
  142. /* Error reporting support. */
  143. void pci_scan_for_target_abort(struct pci_pbm_info *, struct pci_bus *);
  144. void pci_scan_for_master_abort(struct pci_pbm_info *, struct pci_bus *);
  145. void pci_scan_for_parity_error(struct pci_pbm_info *, struct pci_bus *);
  146. /* Configuration space access. */
  147. void pci_config_read8(u8 *addr, u8 *ret);
  148. void pci_config_read16(u16 *addr, u16 *ret);
  149. void pci_config_read32(u32 *addr, u32 *ret);
  150. void pci_config_write8(u8 *addr, u8 val);
  151. void pci_config_write16(u16 *addr, u16 val);
  152. void pci_config_write32(u32 *addr, u32 val);
  153. extern struct pci_ops sun4u_pci_ops;
  154. extern struct pci_ops sun4v_pci_ops;
  155. extern volatile int pci_poke_in_progress;
  156. extern volatile int pci_poke_cpu;
  157. extern volatile int pci_poke_faulted;
  158. #endif /* !(PCI_IMPL_H) */