fsl_pci.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * MPC85xx/86xx PCI/PCIE support routing.
  3. *
  4. * Copyright 2007 Freescale Semiconductor, Inc
  5. *
  6. * Initial author: Xianghua Xiao <x.xiao@freescale.com>
  7. * Recode: ZHANG WEI <wei.zhang@freescale.com>
  8. * Rewrite the routing for Frescale PCI and PCI Express
  9. * Roy Zang <tie-fei.zang@freescale.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/pci.h>
  18. #include <linux/delay.h>
  19. #include <linux/string.h>
  20. #include <linux/init.h>
  21. #include <linux/bootmem.h>
  22. #include <asm/io.h>
  23. #include <asm/prom.h>
  24. #include <asm/pci-bridge.h>
  25. #include <asm/machdep.h>
  26. #include <sysdev/fsl_soc.h>
  27. #include <sysdev/fsl_pci.h>
  28. /* atmu setup for fsl pci/pcie controller */
  29. void __init setup_pci_atmu(struct pci_controller *hose, struct resource *rsrc)
  30. {
  31. struct ccsr_pci __iomem *pci;
  32. int i;
  33. pr_debug("PCI memory map start 0x%016llx, size 0x%016llx\n",
  34. (u64)rsrc->start, (u64)rsrc->end - (u64)rsrc->start + 1);
  35. pci = ioremap(rsrc->start, rsrc->end - rsrc->start + 1);
  36. /* Disable all windows (except powar0 since its ignored) */
  37. for(i = 1; i < 5; i++)
  38. out_be32(&pci->pow[i].powar, 0);
  39. for(i = 0; i < 3; i++)
  40. out_be32(&pci->piw[i].piwar, 0);
  41. /* Setup outbound MEM window */
  42. for(i = 0; i < 3; i++)
  43. if (hose->mem_resources[i].flags & IORESOURCE_MEM){
  44. resource_size_t pci_addr_start =
  45. hose->mem_resources[i].start -
  46. hose->pci_mem_offset;
  47. pr_debug("PCI MEM resource start 0x%016llx, size 0x%016llx.\n",
  48. (u64)hose->mem_resources[i].start,
  49. (u64)hose->mem_resources[i].end
  50. - (u64)hose->mem_resources[i].start + 1);
  51. out_be32(&pci->pow[i+1].potar, (pci_addr_start >> 12));
  52. out_be32(&pci->pow[i+1].potear, 0);
  53. out_be32(&pci->pow[i+1].powbar,
  54. (hose->mem_resources[i].start >> 12));
  55. /* Enable, Mem R/W */
  56. out_be32(&pci->pow[i+1].powar, 0x80044000
  57. | (__ilog2(hose->mem_resources[i].end
  58. - hose->mem_resources[i].start + 1) - 1));
  59. }
  60. /* Setup outbound IO window */
  61. if (hose->io_resource.flags & IORESOURCE_IO){
  62. pr_debug("PCI IO resource start 0x%016llx, size 0x%016llx, "
  63. "phy base 0x%016llx.\n",
  64. (u64)hose->io_resource.start,
  65. (u64)hose->io_resource.end - (u64)hose->io_resource.start + 1,
  66. (u64)hose->io_base_phys);
  67. out_be32(&pci->pow[i+1].potar, (hose->io_resource.start >> 12));
  68. out_be32(&pci->pow[i+1].potear, 0);
  69. out_be32(&pci->pow[i+1].powbar, (hose->io_base_phys >> 12));
  70. /* Enable, IO R/W */
  71. out_be32(&pci->pow[i+1].powar, 0x80088000
  72. | (__ilog2(hose->io_resource.end
  73. - hose->io_resource.start + 1) - 1));
  74. }
  75. /* Setup 2G inbound Memory Window @ 1 */
  76. out_be32(&pci->piw[2].pitar, 0x00000000);
  77. out_be32(&pci->piw[2].piwbar,0x00000000);
  78. out_be32(&pci->piw[2].piwar, PIWAR_2G);
  79. }
  80. void __init setup_pci_cmd(struct pci_controller *hose)
  81. {
  82. u16 cmd;
  83. int cap_x;
  84. early_read_config_word(hose, 0, 0, PCI_COMMAND, &cmd);
  85. cmd |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY
  86. | PCI_COMMAND_IO;
  87. early_write_config_word(hose, 0, 0, PCI_COMMAND, cmd);
  88. cap_x = early_find_capability(hose, 0, 0, PCI_CAP_ID_PCIX);
  89. if (cap_x) {
  90. int pci_x_cmd = cap_x + PCI_X_CMD;
  91. cmd = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
  92. | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  93. early_write_config_word(hose, 0, 0, pci_x_cmd, cmd);
  94. } else {
  95. early_write_config_byte(hose, 0, 0, PCI_LATENCY_TIMER, 0x80);
  96. }
  97. }
  98. static int fsl_pcie_bus_fixup;
  99. static void __init quirk_fsl_pcie_header(struct pci_dev *dev)
  100. {
  101. /* if we aren't a PCIe don't bother */
  102. if (!pci_find_capability(dev, PCI_CAP_ID_EXP))
  103. return ;
  104. dev->class = PCI_CLASS_BRIDGE_PCI << 8;
  105. fsl_pcie_bus_fixup = 1;
  106. return ;
  107. }
  108. int __init fsl_pcie_check_link(struct pci_controller *hose)
  109. {
  110. u32 val;
  111. early_read_config_dword(hose, 0, 0, PCIE_LTSSM, &val);
  112. if (val < PCIE_LTSSM_L0)
  113. return 1;
  114. return 0;
  115. }
  116. void fsl_pcibios_fixup_bus(struct pci_bus *bus)
  117. {
  118. struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
  119. int i;
  120. if ((bus->parent == hose->bus) &&
  121. ((fsl_pcie_bus_fixup &&
  122. early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) ||
  123. (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK)))
  124. {
  125. for (i = 0; i < 4; ++i) {
  126. struct resource *res = bus->resource[i];
  127. struct resource *par = bus->parent->resource[i];
  128. if (res) {
  129. res->start = 0;
  130. res->end = 0;
  131. res->flags = 0;
  132. }
  133. if (res && par) {
  134. res->start = par->start;
  135. res->end = par->end;
  136. res->flags = par->flags;
  137. }
  138. }
  139. }
  140. }
  141. int __init fsl_add_bridge(struct device_node *dev, int is_primary)
  142. {
  143. int len;
  144. struct pci_controller *hose;
  145. struct resource rsrc;
  146. const int *bus_range;
  147. pr_debug("Adding PCI host bridge %s\n", dev->full_name);
  148. /* Fetch host bridge registers address */
  149. if (of_address_to_resource(dev, 0, &rsrc)) {
  150. printk(KERN_WARNING "Can't get pci register base!");
  151. return -ENOMEM;
  152. }
  153. /* Get bus range if any */
  154. bus_range = of_get_property(dev, "bus-range", &len);
  155. if (bus_range == NULL || len < 2 * sizeof(int))
  156. printk(KERN_WARNING "Can't get bus-range for %s, assume"
  157. " bus 0\n", dev->full_name);
  158. ppc_pci_flags |= PPC_PCI_REASSIGN_ALL_BUS;
  159. hose = pcibios_alloc_controller(dev);
  160. if (!hose)
  161. return -ENOMEM;
  162. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  163. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  164. setup_indirect_pci(hose, rsrc.start, rsrc.start + 0x4,
  165. PPC_INDIRECT_TYPE_BIG_ENDIAN);
  166. setup_pci_cmd(hose);
  167. /* check PCI express link status */
  168. if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
  169. hose->indirect_type |= PPC_INDIRECT_TYPE_EXT_REG |
  170. PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS;
  171. if (fsl_pcie_check_link(hose))
  172. hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
  173. }
  174. printk(KERN_INFO "Found FSL PCI host bridge at 0x%016llx. "
  175. "Firmware bus number: %d->%d\n",
  176. (unsigned long long)rsrc.start, hose->first_busno,
  177. hose->last_busno);
  178. pr_debug(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
  179. hose, hose->cfg_addr, hose->cfg_data);
  180. /* Interpret the "ranges" property */
  181. /* This also maps the I/O region and sets isa_io/mem_base */
  182. pci_process_bridge_OF_ranges(hose, dev, is_primary);
  183. /* Setup PEX window registers */
  184. setup_pci_atmu(hose, &rsrc);
  185. return 0;
  186. }
  187. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8548E, quirk_fsl_pcie_header);
  188. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8548, quirk_fsl_pcie_header);
  189. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8543E, quirk_fsl_pcie_header);
  190. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8543, quirk_fsl_pcie_header);
  191. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8547E, quirk_fsl_pcie_header);
  192. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8545E, quirk_fsl_pcie_header);
  193. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8545, quirk_fsl_pcie_header);
  194. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8568E, quirk_fsl_pcie_header);
  195. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8568, quirk_fsl_pcie_header);
  196. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8567E, quirk_fsl_pcie_header);
  197. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8567, quirk_fsl_pcie_header);
  198. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8533E, quirk_fsl_pcie_header);
  199. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8533, quirk_fsl_pcie_header);
  200. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8544E, quirk_fsl_pcie_header);
  201. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8544, quirk_fsl_pcie_header);
  202. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8572E, quirk_fsl_pcie_header);
  203. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8572, quirk_fsl_pcie_header);
  204. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8641, quirk_fsl_pcie_header);
  205. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8641D, quirk_fsl_pcie_header);
  206. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8610, quirk_fsl_pcie_header);