pci_fire.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* pci_fire.c: Sun4u platform PCI-E controller support.
  2. *
  3. * Copyright (C) 2007 David S. Miller (davem@davemloft.net)
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/pci.h>
  7. #include <linux/slab.h>
  8. #include <linux/init.h>
  9. #include <asm/oplib.h>
  10. #include <asm/prom.h>
  11. #include "pci_impl.h"
  12. #define fire_read(__reg) \
  13. ({ u64 __ret; \
  14. __asm__ __volatile__("ldxa [%1] %2, %0" \
  15. : "=r" (__ret) \
  16. : "r" (__reg), "i" (ASI_PHYS_BYPASS_EC_E) \
  17. : "memory"); \
  18. __ret; \
  19. })
  20. #define fire_write(__reg, __val) \
  21. __asm__ __volatile__("stxa %0, [%1] %2" \
  22. : /* no outputs */ \
  23. : "r" (__val), "r" (__reg), \
  24. "i" (ASI_PHYS_BYPASS_EC_E) \
  25. : "memory")
  26. static void pci_fire_scan_bus(struct pci_pbm_info *pbm)
  27. {
  28. pbm->pci_bus = pci_scan_one_pbm(pbm);
  29. /* XXX register error interrupt handlers XXX */
  30. }
  31. #define FIRE_IOMMU_CONTROL 0x40000UL
  32. #define FIRE_IOMMU_TSBBASE 0x40008UL
  33. #define FIRE_IOMMU_FLUSH 0x40100UL
  34. #define FIRE_IOMMU_FLUSHINV 0x40108UL
  35. static void pci_fire_pbm_iommu_init(struct pci_pbm_info *pbm)
  36. {
  37. struct iommu *iommu = pbm->iommu;
  38. u32 vdma[2], dma_mask;
  39. u64 control;
  40. int tsbsize;
  41. /* No virtual-dma property on these guys, use largest size. */
  42. vdma[0] = 0xc0000000; /* base */
  43. vdma[1] = 0x40000000; /* size */
  44. dma_mask = 0xffffffff;
  45. tsbsize = 128;
  46. /* Register addresses. */
  47. iommu->iommu_control = pbm->pbm_regs + FIRE_IOMMU_CONTROL;
  48. iommu->iommu_tsbbase = pbm->pbm_regs + FIRE_IOMMU_TSBBASE;
  49. iommu->iommu_flush = pbm->pbm_regs + FIRE_IOMMU_FLUSH;
  50. iommu->iommu_flushinv = pbm->pbm_regs + FIRE_IOMMU_FLUSHINV;
  51. /* We use the main control/status register of FIRE as the write
  52. * completion register.
  53. */
  54. iommu->write_complete_reg = pbm->controller_regs + 0x410000UL;
  55. /*
  56. * Invalidate TLB Entries.
  57. */
  58. fire_write(iommu->iommu_flushinv, ~(u64)0);
  59. pci_iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask);
  60. fire_write(iommu->iommu_tsbbase, __pa(iommu->page_table) | 0x7UL);
  61. control = fire_read(iommu->iommu_control);
  62. control |= (0x00000400 /* TSB cache snoop enable */ |
  63. 0x00000300 /* Cache mode */ |
  64. 0x00000002 /* Bypass enable */ |
  65. 0x00000001 /* Translation enable */);
  66. fire_write(iommu->iommu_control, control);
  67. }
  68. /* Based at pbm->controller_regs */
  69. #define FIRE_PARITY_CONTROL 0x470010UL
  70. #define FIRE_PARITY_ENAB 0x8000000000000000UL
  71. #define FIRE_FATAL_RESET_CTL 0x471028UL
  72. #define FIRE_FATAL_RESET_SPARE 0x0000000004000000UL
  73. #define FIRE_FATAL_RESET_MB 0x0000000002000000UL
  74. #define FIRE_FATAL_RESET_CPE 0x0000000000008000UL
  75. #define FIRE_FATAL_RESET_APE 0x0000000000004000UL
  76. #define FIRE_FATAL_RESET_PIO 0x0000000000000040UL
  77. #define FIRE_FATAL_RESET_JW 0x0000000000000004UL
  78. #define FIRE_FATAL_RESET_JI 0x0000000000000002UL
  79. #define FIRE_FATAL_RESET_JR 0x0000000000000001UL
  80. #define FIRE_CORE_INTR_ENABLE 0x471800UL
  81. /* Based at pbm->pbm_regs */
  82. #define FIRE_TLU_CTRL 0x80000UL
  83. #define FIRE_TLU_CTRL_TIM 0x00000000da000000UL
  84. #define FIRE_TLU_CTRL_QDET 0x0000000000000100UL
  85. #define FIRE_TLU_CTRL_CFG 0x0000000000000001UL
  86. #define FIRE_TLU_DEV_CTRL 0x90008UL
  87. #define FIRE_TLU_LINK_CTRL 0x90020UL
  88. #define FIRE_TLU_LINK_CTRL_CLK 0x0000000000000040UL
  89. #define FIRE_LPU_RESET 0xe2008UL
  90. #define FIRE_LPU_LLCFG 0xe2200UL
  91. #define FIRE_LPU_LLCFG_VC0 0x0000000000000100UL
  92. #define FIRE_LPU_FCTRL_UCTRL 0xe2240UL
  93. #define FIRE_LPU_FCTRL_UCTRL_N 0x0000000000000002UL
  94. #define FIRE_LPU_FCTRL_UCTRL_P 0x0000000000000001UL
  95. #define FIRE_LPU_TXL_FIFOP 0xe2430UL
  96. #define FIRE_LPU_LTSSM_CFG2 0xe2788UL
  97. #define FIRE_LPU_LTSSM_CFG3 0xe2790UL
  98. #define FIRE_LPU_LTSSM_CFG4 0xe2798UL
  99. #define FIRE_LPU_LTSSM_CFG5 0xe27a0UL
  100. #define FIRE_DMC_IENAB 0x31800UL
  101. #define FIRE_DMC_DBG_SEL_A 0x53000UL
  102. #define FIRE_DMC_DBG_SEL_B 0x53008UL
  103. #define FIRE_PEC_IENAB 0x51800UL
  104. static void pci_fire_hw_init(struct pci_pbm_info *pbm)
  105. {
  106. u64 val;
  107. fire_write(pbm->controller_regs + FIRE_PARITY_CONTROL,
  108. FIRE_PARITY_ENAB);
  109. fire_write(pbm->controller_regs + FIRE_FATAL_RESET_CTL,
  110. (FIRE_FATAL_RESET_SPARE |
  111. FIRE_FATAL_RESET_MB |
  112. FIRE_FATAL_RESET_CPE |
  113. FIRE_FATAL_RESET_APE |
  114. FIRE_FATAL_RESET_PIO |
  115. FIRE_FATAL_RESET_JW |
  116. FIRE_FATAL_RESET_JI |
  117. FIRE_FATAL_RESET_JR));
  118. fire_write(pbm->controller_regs + FIRE_CORE_INTR_ENABLE, ~(u64)0);
  119. val = fire_read(pbm->pbm_regs + FIRE_TLU_CTRL);
  120. val |= (FIRE_TLU_CTRL_TIM |
  121. FIRE_TLU_CTRL_QDET |
  122. FIRE_TLU_CTRL_CFG);
  123. fire_write(pbm->pbm_regs + FIRE_TLU_CTRL, val);
  124. fire_write(pbm->pbm_regs + FIRE_TLU_DEV_CTRL, 0);
  125. fire_write(pbm->pbm_regs + FIRE_TLU_LINK_CTRL,
  126. FIRE_TLU_LINK_CTRL_CLK);
  127. fire_write(pbm->pbm_regs + FIRE_LPU_RESET, 0);
  128. fire_write(pbm->pbm_regs + FIRE_LPU_LLCFG,
  129. FIRE_LPU_LLCFG_VC0);
  130. fire_write(pbm->pbm_regs + FIRE_LPU_FCTRL_UCTRL,
  131. (FIRE_LPU_FCTRL_UCTRL_N |
  132. FIRE_LPU_FCTRL_UCTRL_P));
  133. fire_write(pbm->pbm_regs + FIRE_LPU_TXL_FIFOP,
  134. ((0xffff << 16) | (0x0000 << 0)));
  135. fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG2, 3000000);
  136. fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG3, 500000);
  137. fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG4,
  138. (2 << 16) | (140 << 8));
  139. fire_write(pbm->pbm_regs + FIRE_LPU_LTSSM_CFG5, 0);
  140. fire_write(pbm->pbm_regs + FIRE_DMC_IENAB, ~(u64)0);
  141. fire_write(pbm->pbm_regs + FIRE_DMC_DBG_SEL_A, 0);
  142. fire_write(pbm->pbm_regs + FIRE_DMC_DBG_SEL_B, 0);
  143. fire_write(pbm->pbm_regs + FIRE_PEC_IENAB, ~(u64)0);
  144. }
  145. static void pci_fire_pbm_init(struct pci_controller_info *p,
  146. struct device_node *dp, u32 portid)
  147. {
  148. const struct linux_prom64_registers *regs;
  149. struct pci_pbm_info *pbm;
  150. if ((portid & 1) == 0)
  151. pbm = &p->pbm_A;
  152. else
  153. pbm = &p->pbm_B;
  154. pbm->next = pci_pbm_root;
  155. pci_pbm_root = pbm;
  156. pbm->scan_bus = pci_fire_scan_bus;
  157. pbm->pci_ops = &sun4u_pci_ops;
  158. pbm->config_space_reg_bits = 12;
  159. pbm->index = pci_num_pbms++;
  160. pbm->portid = portid;
  161. pbm->parent = p;
  162. pbm->prom_node = dp;
  163. pbm->name = dp->full_name;
  164. regs = of_get_property(dp, "reg", NULL);
  165. pbm->pbm_regs = regs[0].phys_addr;
  166. pbm->controller_regs = regs[1].phys_addr - 0x410000UL;
  167. printk("%s: SUN4U PCIE Bus Module\n", pbm->name);
  168. pci_determine_mem_io_space(pbm);
  169. pci_get_pbm_props(pbm);
  170. pci_fire_hw_init(pbm);
  171. pci_fire_pbm_iommu_init(pbm);
  172. }
  173. static inline int portid_compare(u32 x, u32 y)
  174. {
  175. if (x == (y ^ 1))
  176. return 1;
  177. return 0;
  178. }
  179. void fire_pci_init(struct device_node *dp, const char *model_name)
  180. {
  181. struct pci_controller_info *p;
  182. u32 portid = of_getintprop_default(dp, "portid", 0xff);
  183. struct iommu *iommu;
  184. struct pci_pbm_info *pbm;
  185. for (pbm = pci_pbm_root; pbm; pbm = pbm->next) {
  186. if (portid_compare(pbm->portid, portid)) {
  187. pci_fire_pbm_init(pbm->parent, dp, portid);
  188. return;
  189. }
  190. }
  191. p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
  192. if (!p)
  193. goto fatal_memory_error;
  194. iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
  195. if (!iommu)
  196. goto fatal_memory_error;
  197. p->pbm_A.iommu = iommu;
  198. iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
  199. if (!iommu)
  200. goto fatal_memory_error;
  201. p->pbm_B.iommu = iommu;
  202. /* XXX MSI support XXX */
  203. /* Like PSYCHO and SCHIZO we have a 2GB aligned area
  204. * for memory space.
  205. */
  206. pci_memspace_mask = 0x7fffffffUL;
  207. pci_fire_pbm_init(p, dp, portid);
  208. return;
  209. fatal_memory_error:
  210. prom_printf("PCI_FIRE: Fatal memory allocation error.\n");
  211. prom_halt();
  212. }