pbm.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* $Id: pbm.h,v 1.27 2001/08/12 13:18:23 davem Exp $
  2. * pbm.h: UltraSparc PCI controller software state.
  3. *
  4. * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@redhat.com)
  5. */
  6. #ifndef __SPARC64_PBM_H
  7. #define __SPARC64_PBM_H
  8. #include <linux/types.h>
  9. #include <linux/pci.h>
  10. #include <linux/ioport.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/msi.h>
  13. #include <asm/io.h>
  14. #include <asm/page.h>
  15. #include <asm/oplib.h>
  16. #include <asm/prom.h>
  17. #include <asm/of_device.h>
  18. #include <asm/iommu.h>
  19. /* The abstraction used here is that there are PCI controllers,
  20. * each with one (Sabre) or two (PSYCHO/SCHIZO) PCI bus modules
  21. * underneath. Each PCI bus module uses an IOMMU (shared by both
  22. * PBMs of a controller, or per-PBM), and if a streaming buffer
  23. * is present, each PCI bus module has it's own. (ie. the IOMMU
  24. * might be shared between PBMs, the STC is never shared)
  25. * Furthermore, each PCI bus module controls it's own autonomous
  26. * PCI bus.
  27. */
  28. struct pci_controller_info;
  29. /* This contains the software state necessary to drive a PCI
  30. * controller's IOMMU.
  31. */
  32. struct pci_iommu_arena {
  33. unsigned long *map;
  34. unsigned int hint;
  35. unsigned int limit;
  36. };
  37. struct pci_iommu {
  38. /* This protects the controller's IOMMU and all
  39. * streaming buffers underneath.
  40. */
  41. spinlock_t lock;
  42. struct pci_iommu_arena arena;
  43. /* IOMMU page table, a linear array of ioptes. */
  44. iopte_t *page_table; /* The page table itself. */
  45. /* Base PCI memory space address where IOMMU mappings
  46. * begin.
  47. */
  48. u32 page_table_map_base;
  49. /* IOMMU Controller Registers */
  50. unsigned long iommu_control; /* IOMMU control register */
  51. unsigned long iommu_tsbbase; /* IOMMU page table base register */
  52. unsigned long iommu_flush; /* IOMMU page flush register */
  53. unsigned long iommu_ctxflush; /* IOMMU context flush register */
  54. /* This is a register in the PCI controller, which if
  55. * read will have no side-effects but will guarantee
  56. * completion of all previous writes into IOMMU/STC.
  57. */
  58. unsigned long write_complete_reg;
  59. /* In order to deal with some buggy third-party PCI bridges that
  60. * do wrong prefetching, we never mark valid mappings as invalid.
  61. * Instead we point them at this dummy page.
  62. */
  63. unsigned long dummy_page;
  64. unsigned long dummy_page_pa;
  65. /* CTX allocation. */
  66. unsigned long ctx_lowest_free;
  67. unsigned long ctx_bitmap[IOMMU_NUM_CTXS / (sizeof(unsigned long) * 8)];
  68. /* Here a PCI controller driver describes the areas of
  69. * PCI memory space where DMA to/from physical memory
  70. * are addressed. Drivers interrogate the PCI layer
  71. * if their device has addressing limitations. They
  72. * do so via pci_dma_supported, and pass in a mask of
  73. * DMA address bits their device can actually drive.
  74. *
  75. * The test for being usable is:
  76. * (device_mask & dma_addr_mask) == dma_addr_mask
  77. */
  78. u32 dma_addr_mask;
  79. };
  80. extern void pci_iommu_table_init(struct pci_iommu *iommu, int tsbsize, u32 dma_offset, u32 dma_addr_mask);
  81. /* This describes a PCI bus module's streaming buffer. */
  82. struct pci_strbuf {
  83. int strbuf_enabled; /* Present and using it? */
  84. /* Streaming Buffer Control Registers */
  85. unsigned long strbuf_control; /* STC control register */
  86. unsigned long strbuf_pflush; /* STC page flush register */
  87. unsigned long strbuf_fsync; /* STC flush synchronization reg */
  88. unsigned long strbuf_ctxflush; /* STC context flush register */
  89. unsigned long strbuf_ctxmatch_base; /* STC context flush match reg */
  90. unsigned long strbuf_flushflag_pa; /* Physical address of flush flag */
  91. volatile unsigned long *strbuf_flushflag; /* The flush flag itself */
  92. /* And this is the actual flush flag area.
  93. * We allocate extra because the chips require
  94. * a 64-byte aligned area.
  95. */
  96. volatile unsigned long __flushflag_buf[(64 + (64 - 1)) / sizeof(long)];
  97. };
  98. #define PCI_STC_FLUSHFLAG_INIT(STC) \
  99. (*((STC)->strbuf_flushflag) = 0UL)
  100. #define PCI_STC_FLUSHFLAG_SET(STC) \
  101. (*((STC)->strbuf_flushflag) != 0UL)
  102. /* There can be quite a few ranges and interrupt maps on a PCI
  103. * segment. Thus...
  104. */
  105. #define PROM_PCIRNG_MAX 64
  106. #define PROM_PCIIMAP_MAX 64
  107. struct pci_pbm_info {
  108. /* PCI controller we sit under. */
  109. struct pci_controller_info *parent;
  110. /* Physical address base of controller registers. */
  111. unsigned long controller_regs;
  112. /* Physical address base of PBM registers. */
  113. unsigned long pbm_regs;
  114. /* Physical address of DMA sync register, if any. */
  115. unsigned long sync_reg;
  116. /* Opaque 32-bit system bus Port ID. */
  117. u32 portid;
  118. /* Opaque 32-bit handle used for hypervisor calls. */
  119. u32 devhandle;
  120. /* Chipset version information. */
  121. int chip_type;
  122. #define PBM_CHIP_TYPE_SABRE 1
  123. #define PBM_CHIP_TYPE_PSYCHO 2
  124. #define PBM_CHIP_TYPE_SCHIZO 3
  125. #define PBM_CHIP_TYPE_SCHIZO_PLUS 4
  126. #define PBM_CHIP_TYPE_TOMATILLO 5
  127. int chip_version;
  128. int chip_revision;
  129. /* Name used for top-level resources. */
  130. char *name;
  131. /* OBP specific information. */
  132. struct device_node *prom_node;
  133. struct linux_prom_pci_ranges *pbm_ranges;
  134. int num_pbm_ranges;
  135. struct linux_prom_pci_intmap *pbm_intmap;
  136. int num_pbm_intmap;
  137. struct linux_prom_pci_intmask *pbm_intmask;
  138. u64 ino_bitmap;
  139. /* PBM I/O and Memory space resources. */
  140. struct resource io_space;
  141. struct resource mem_space;
  142. /* Base of PCI Config space, can be per-PBM or shared. */
  143. unsigned long config_space;
  144. /* State of 66MHz capabilities on this PBM. */
  145. int is_66mhz_capable;
  146. int all_devs_66mhz;
  147. #ifdef CONFIG_PCI_MSI
  148. /* MSI info. */
  149. u32 msiq_num;
  150. u32 msiq_ent_count;
  151. u32 msiq_first;
  152. u32 msiq_first_devino;
  153. u32 msi_num;
  154. u32 msi_first;
  155. u32 msi_data_mask;
  156. u32 msix_data_width;
  157. u64 msi32_start;
  158. u64 msi64_start;
  159. u32 msi32_len;
  160. u32 msi64_len;
  161. void *msi_queues;
  162. unsigned long *msi_bitmap;
  163. #endif /* !(CONFIG_PCI_MSI) */
  164. /* This PBM's streaming buffer. */
  165. struct pci_strbuf stc;
  166. /* IOMMU state, potentially shared by both PBM segments. */
  167. struct pci_iommu *iommu;
  168. /* PCI slot mapping. */
  169. unsigned int pci_first_slot;
  170. /* Now things for the actual PCI bus probes. */
  171. unsigned int pci_first_busno;
  172. unsigned int pci_last_busno;
  173. struct pci_bus *pci_bus;
  174. };
  175. struct pci_controller_info {
  176. /* List of all PCI controllers. */
  177. struct pci_controller_info *next;
  178. /* Each controller gets a unique index, used mostly for
  179. * error logging purposes.
  180. */
  181. int index;
  182. /* Do the PBMs both exist in the same PCI domain? */
  183. int pbms_same_domain;
  184. /* The PCI bus modules controlled by us. */
  185. struct pci_pbm_info pbm_A;
  186. struct pci_pbm_info pbm_B;
  187. /* Operations which are controller specific. */
  188. void (*scan_bus)(struct pci_controller_info *);
  189. void (*base_address_update)(struct pci_dev *, int);
  190. void (*resource_adjust)(struct pci_dev *, struct resource *, struct resource *);
  191. #ifdef CONFIG_PCI_MSI
  192. int (*setup_msi_irq)(unsigned int *virt_irq_p, struct pci_dev *pdev,
  193. struct msi_desc *entry);
  194. void (*teardown_msi_irq)(unsigned int virt_irq, struct pci_dev *pdev);
  195. #endif
  196. /* Now things for the actual PCI bus probes. */
  197. struct pci_ops *pci_ops;
  198. unsigned int pci_first_busno;
  199. unsigned int pci_last_busno;
  200. };
  201. /* PCI devices which are not bridges have this placed in their pci_dev
  202. * sysdata member. This makes OBP aware PCI device drivers easier to
  203. * code.
  204. */
  205. struct pcidev_cookie {
  206. struct pci_pbm_info *pbm;
  207. struct device_node *prom_node;
  208. struct of_device *op;
  209. struct linux_prom_pci_registers prom_regs[PROMREG_MAX];
  210. int num_prom_regs;
  211. struct linux_prom_pci_registers prom_assignments[PROMREG_MAX];
  212. int num_prom_assignments;
  213. #ifdef CONFIG_PCI_MSI
  214. unsigned int msi_num;
  215. #endif
  216. };
  217. /* Currently these are the same across all PCI controllers
  218. * we support. Someday they may not be...
  219. */
  220. #define PCI_IRQ_IGN 0x000007c0 /* Interrupt Group Number */
  221. #define PCI_IRQ_INO 0x0000003f /* Interrupt Number */
  222. #endif /* !(__SPARC64_PBM_H) */