fsl_pci.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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%x, size 0x%x\n", rsrc->start,
  34. rsrc->end - 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. pr_debug("PCI MEM resource start 0x%08x, size 0x%08x.\n",
  45. hose->mem_resources[i].start,
  46. hose->mem_resources[i].end
  47. - hose->mem_resources[i].start + 1);
  48. out_be32(&pci->pow[i+1].potar,
  49. (hose->mem_resources[i].start >> 12)
  50. & 0x000fffff);
  51. out_be32(&pci->pow[i+1].potear, 0);
  52. out_be32(&pci->pow[i+1].powbar,
  53. (hose->mem_resources[i].start >> 12)
  54. & 0x000fffff);
  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%08x, size 0x%08x, phy base 0x%08x.\n",
  63. hose->io_resource.start,
  64. hose->io_resource.end - hose->io_resource.start + 1,
  65. hose->io_base_phys);
  66. out_be32(&pci->pow[i+1].potar, (hose->io_resource.start >> 12)
  67. & 0x000fffff);
  68. out_be32(&pci->pow[i+1].potear, 0);
  69. out_be32(&pci->pow[i+1].powbar, (hose->io_base_phys >> 12)
  70. & 0x000fffff);
  71. /* Enable, IO R/W */
  72. out_be32(&pci->pow[i+1].powar, 0x80088000
  73. | (__ilog2(hose->io_resource.end
  74. - hose->io_resource.start + 1) - 1));
  75. }
  76. /* Setup 2G inbound Memory Window @ 1 */
  77. out_be32(&pci->piw[2].pitar, 0x00000000);
  78. out_be32(&pci->piw[2].piwbar,0x00000000);
  79. out_be32(&pci->piw[2].piwar, PIWAR_2G);
  80. }
  81. void __init setup_pci_cmd(struct pci_controller *hose)
  82. {
  83. u16 cmd;
  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. early_write_config_byte(hose, 0, 0, PCI_LATENCY_TIMER, 0x80);
  89. }
  90. static void __devinit quirk_fsl_pcie_transparent(struct pci_dev *dev)
  91. {
  92. struct resource *res;
  93. int i, res_idx = PCI_BRIDGE_RESOURCES;
  94. struct pci_controller *hose;
  95. /* if we aren't a PCIe don't bother */
  96. if (!pci_find_capability(dev, PCI_CAP_ID_EXP))
  97. return ;
  98. /*
  99. * Make the bridge be transparent.
  100. */
  101. dev->transparent = 1;
  102. hose = pci_bus_to_host(dev->bus);
  103. if (!hose) {
  104. printk(KERN_ERR "Can't find hose for bus %d\n",
  105. dev->bus->number);
  106. return;
  107. }
  108. if (hose->io_resource.flags) {
  109. res = &dev->resource[res_idx++];
  110. res->start = hose->io_resource.start;
  111. res->end = hose->io_resource.end;
  112. res->flags = hose->io_resource.flags;
  113. }
  114. for (i = 0; i < 3; i++) {
  115. res = &dev->resource[res_idx + i];
  116. res->start = hose->mem_resources[i].start;
  117. res->end = hose->mem_resources[i].end;
  118. res->flags = hose->mem_resources[i].flags;
  119. }
  120. }
  121. int __init fsl_pcie_check_link(struct pci_controller *hose)
  122. {
  123. u16 val;
  124. early_read_config_word(hose, 0, 0, PCIE_LTSSM, &val);
  125. if (val < PCIE_LTSSM_L0)
  126. return 1;
  127. return 0;
  128. }
  129. int __init fsl_add_bridge(struct device_node *dev, int is_primary)
  130. {
  131. int len;
  132. struct pci_controller *hose;
  133. struct resource rsrc;
  134. const int *bus_range;
  135. pr_debug("Adding PCI host bridge %s\n", dev->full_name);
  136. /* Fetch host bridge registers address */
  137. if (of_address_to_resource(dev, 0, &rsrc)) {
  138. printk(KERN_WARNING "Can't get pci register base!");
  139. return -ENOMEM;
  140. }
  141. /* Get bus range if any */
  142. bus_range = of_get_property(dev, "bus-range", &len);
  143. if (bus_range == NULL || len < 2 * sizeof(int))
  144. printk(KERN_WARNING "Can't get bus-range for %s, assume"
  145. " bus 0\n", dev->full_name);
  146. pci_assign_all_buses = 1;
  147. hose = pcibios_alloc_controller(dev);
  148. if (!hose)
  149. return -ENOMEM;
  150. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  151. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  152. setup_indirect_pci(hose, rsrc.start, rsrc.start + 0x4);
  153. setup_pci_cmd(hose);
  154. /* check PCI express link status */
  155. if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
  156. hose->indirect_type = PPC_INDIRECT_TYPE_EXT_REG |
  157. PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS;
  158. if (fsl_pcie_check_link(hose))
  159. hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
  160. }
  161. printk(KERN_INFO "Found FSL PCI host bridge at 0x%016llx."
  162. "Firmware bus number: %d->%d\n",
  163. (unsigned long long)rsrc.start, hose->first_busno,
  164. hose->last_busno);
  165. pr_debug(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
  166. hose, hose->cfg_addr, hose->cfg_data);
  167. /* Interpret the "ranges" property */
  168. /* This also maps the I/O region and sets isa_io/mem_base */
  169. pci_process_bridge_OF_ranges(hose, dev, is_primary);
  170. /* Setup PEX window registers */
  171. setup_pci_atmu(hose, &rsrc);
  172. return 0;
  173. }
  174. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0012, quirk_fsl_pcie_transparent);
  175. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0013, quirk_fsl_pcie_transparent);
  176. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0014, quirk_fsl_pcie_transparent);
  177. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0015, quirk_fsl_pcie_transparent);
  178. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0018, quirk_fsl_pcie_transparent);
  179. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0019, quirk_fsl_pcie_transparent);
  180. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x001a, quirk_fsl_pcie_transparent);
  181. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x7010, quirk_fsl_pcie_transparent);
  182. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x7011, quirk_fsl_pcie_transparent);