fsl_pci.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. int cap_x;
  85. early_read_config_word(hose, 0, 0, PCI_COMMAND, &cmd);
  86. cmd |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY
  87. | PCI_COMMAND_IO;
  88. early_write_config_word(hose, 0, 0, PCI_COMMAND, cmd);
  89. cap_x = early_find_capability(hose, 0, 0, PCI_CAP_ID_PCIX);
  90. if (cap_x) {
  91. int pci_x_cmd = cap_x + PCI_X_CMD;
  92. cmd = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
  93. | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  94. early_write_config_word(hose, 0, 0, pci_x_cmd, cmd);
  95. } else {
  96. early_write_config_byte(hose, 0, 0, PCI_LATENCY_TIMER, 0x80);
  97. }
  98. }
  99. static void __devinit quirk_fsl_pcie_transparent(struct pci_dev *dev)
  100. {
  101. struct resource *res;
  102. int i, res_idx = PCI_BRIDGE_RESOURCES;
  103. struct pci_controller *hose;
  104. /* if we aren't a PCIe don't bother */
  105. if (!pci_find_capability(dev, PCI_CAP_ID_EXP))
  106. return ;
  107. /*
  108. * Make the bridge be transparent.
  109. */
  110. dev->transparent = 1;
  111. hose = pci_bus_to_host(dev->bus);
  112. if (!hose) {
  113. printk(KERN_ERR "Can't find hose for bus %d\n",
  114. dev->bus->number);
  115. return;
  116. }
  117. /* Clear out any of the virtual P2P bridge registers */
  118. pci_write_config_word(dev, PCI_IO_BASE_UPPER16, 0);
  119. pci_write_config_word(dev, PCI_IO_LIMIT_UPPER16, 0);
  120. pci_write_config_byte(dev, PCI_IO_BASE, 0x10);
  121. pci_write_config_byte(dev, PCI_IO_LIMIT, 0);
  122. pci_write_config_word(dev, PCI_MEMORY_BASE, 0x10);
  123. pci_write_config_word(dev, PCI_MEMORY_LIMIT, 0);
  124. pci_write_config_word(dev, PCI_PREF_BASE_UPPER32, 0x0);
  125. pci_write_config_word(dev, PCI_PREF_LIMIT_UPPER32, 0x0);
  126. pci_write_config_word(dev, PCI_PREF_MEMORY_BASE, 0x10);
  127. pci_write_config_word(dev, PCI_PREF_MEMORY_LIMIT, 0);
  128. if (hose->io_resource.flags) {
  129. res = &dev->resource[res_idx++];
  130. res->start = hose->io_resource.start;
  131. res->end = hose->io_resource.end;
  132. res->flags = hose->io_resource.flags;
  133. update_bridge_resource(dev, res);
  134. }
  135. for (i = 0; i < 3; i++) {
  136. res = &dev->resource[res_idx + i];
  137. res->start = hose->mem_resources[i].start;
  138. res->end = hose->mem_resources[i].end;
  139. res->flags = hose->mem_resources[i].flags;
  140. update_bridge_resource(dev, res);
  141. }
  142. }
  143. int __init fsl_pcie_check_link(struct pci_controller *hose)
  144. {
  145. u16 val;
  146. early_read_config_word(hose, 0, 0, PCIE_LTSSM, &val);
  147. if (val < PCIE_LTSSM_L0)
  148. return 1;
  149. return 0;
  150. }
  151. void fsl_pcibios_fixup_bus(struct pci_bus *bus)
  152. {
  153. struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
  154. int i;
  155. /* deal with bogus pci_bus when we don't have anything connected on PCIe */
  156. if (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK) {
  157. if (bus->parent) {
  158. for (i = 0; i < 4; ++i)
  159. bus->resource[i] = bus->parent->resource[i];
  160. }
  161. }
  162. }
  163. int __init fsl_add_bridge(struct device_node *dev, int is_primary)
  164. {
  165. int len;
  166. struct pci_controller *hose;
  167. struct resource rsrc;
  168. const int *bus_range;
  169. pr_debug("Adding PCI host bridge %s\n", dev->full_name);
  170. /* Fetch host bridge registers address */
  171. if (of_address_to_resource(dev, 0, &rsrc)) {
  172. printk(KERN_WARNING "Can't get pci register base!");
  173. return -ENOMEM;
  174. }
  175. /* Get bus range if any */
  176. bus_range = of_get_property(dev, "bus-range", &len);
  177. if (bus_range == NULL || len < 2 * sizeof(int))
  178. printk(KERN_WARNING "Can't get bus-range for %s, assume"
  179. " bus 0\n", dev->full_name);
  180. pci_assign_all_buses = 1;
  181. hose = pcibios_alloc_controller(dev);
  182. if (!hose)
  183. return -ENOMEM;
  184. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  185. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  186. setup_indirect_pci(hose, rsrc.start, rsrc.start + 0x4,
  187. PPC_INDIRECT_TYPE_BIG_ENDIAN);
  188. setup_pci_cmd(hose);
  189. /* check PCI express link status */
  190. if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
  191. hose->indirect_type = PPC_INDIRECT_TYPE_EXT_REG |
  192. PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS;
  193. if (fsl_pcie_check_link(hose))
  194. hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
  195. }
  196. printk(KERN_INFO "Found FSL PCI host bridge at 0x%016llx."
  197. "Firmware bus number: %d->%d\n",
  198. (unsigned long long)rsrc.start, hose->first_busno,
  199. hose->last_busno);
  200. pr_debug(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
  201. hose, hose->cfg_addr, hose->cfg_data);
  202. /* Interpret the "ranges" property */
  203. /* This also maps the I/O region and sets isa_io/mem_base */
  204. pci_process_bridge_OF_ranges(hose, dev, is_primary);
  205. /* Setup PEX window registers */
  206. setup_pci_atmu(hose, &rsrc);
  207. return 0;
  208. }
  209. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0012, quirk_fsl_pcie_transparent);
  210. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0013, quirk_fsl_pcie_transparent);
  211. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0014, quirk_fsl_pcie_transparent);
  212. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0015, quirk_fsl_pcie_transparent);
  213. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0018, quirk_fsl_pcie_transparent);
  214. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0019, quirk_fsl_pcie_transparent);
  215. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x001a, quirk_fsl_pcie_transparent);
  216. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0020, quirk_fsl_pcie_transparent);
  217. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0021, quirk_fsl_pcie_transparent);
  218. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0024, quirk_fsl_pcie_transparent);
  219. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0025, quirk_fsl_pcie_transparent);
  220. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0030, quirk_fsl_pcie_transparent);
  221. DECLARE_PCI_FIXUP_EARLY(0x1957, 0x0031, quirk_fsl_pcie_transparent);
  222. DECLARE_PCI_FIXUP_EARLY(0x1957, PCI_DEVICE_ID_MPC8641, quirk_fsl_pcie_transparent);
  223. DECLARE_PCI_FIXUP_EARLY(0x1957, PCI_DEVICE_ID_MPC8641D, quirk_fsl_pcie_transparent);