fsl_pci.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 void __init setup_pci_pcsrbar(struct pci_controller *hose)
  99. {
  100. #ifdef CONFIG_PCI_MSI
  101. phys_addr_t immr_base;
  102. immr_base = get_immrbase();
  103. early_write_config_dword(hose, 0, 0, PCI_BASE_ADDRESS_0, immr_base);
  104. #endif
  105. }
  106. static int fsl_pcie_bus_fixup;
  107. static void __init quirk_fsl_pcie_header(struct pci_dev *dev)
  108. {
  109. /* if we aren't a PCIe don't bother */
  110. if (!pci_find_capability(dev, PCI_CAP_ID_EXP))
  111. return ;
  112. dev->class = PCI_CLASS_BRIDGE_PCI << 8;
  113. fsl_pcie_bus_fixup = 1;
  114. return ;
  115. }
  116. int __init fsl_pcie_check_link(struct pci_controller *hose)
  117. {
  118. u32 val;
  119. early_read_config_dword(hose, 0, 0, PCIE_LTSSM, &val);
  120. if (val < PCIE_LTSSM_L0)
  121. return 1;
  122. return 0;
  123. }
  124. void fsl_pcibios_fixup_bus(struct pci_bus *bus)
  125. {
  126. struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
  127. int i;
  128. if ((bus->parent == hose->bus) &&
  129. ((fsl_pcie_bus_fixup &&
  130. early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) ||
  131. (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK)))
  132. {
  133. for (i = 0; i < 4; ++i) {
  134. struct resource *res = bus->resource[i];
  135. struct resource *par = bus->parent->resource[i];
  136. if (res) {
  137. res->start = 0;
  138. res->end = 0;
  139. res->flags = 0;
  140. }
  141. if (res && par) {
  142. res->start = par->start;
  143. res->end = par->end;
  144. res->flags = par->flags;
  145. }
  146. }
  147. }
  148. }
  149. int __init fsl_add_bridge(struct device_node *dev, int is_primary)
  150. {
  151. int len;
  152. struct pci_controller *hose;
  153. struct resource rsrc;
  154. const int *bus_range;
  155. pr_debug("Adding PCI host bridge %s\n", dev->full_name);
  156. /* Fetch host bridge registers address */
  157. if (of_address_to_resource(dev, 0, &rsrc)) {
  158. printk(KERN_WARNING "Can't get pci register base!");
  159. return -ENOMEM;
  160. }
  161. /* Get bus range if any */
  162. bus_range = of_get_property(dev, "bus-range", &len);
  163. if (bus_range == NULL || len < 2 * sizeof(int))
  164. printk(KERN_WARNING "Can't get bus-range for %s, assume"
  165. " bus 0\n", dev->full_name);
  166. ppc_pci_flags |= PPC_PCI_REASSIGN_ALL_BUS;
  167. hose = pcibios_alloc_controller(dev);
  168. if (!hose)
  169. return -ENOMEM;
  170. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  171. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  172. setup_indirect_pci(hose, rsrc.start, rsrc.start + 0x4,
  173. PPC_INDIRECT_TYPE_BIG_ENDIAN);
  174. setup_pci_cmd(hose);
  175. /* check PCI express link status */
  176. if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
  177. hose->indirect_type |= PPC_INDIRECT_TYPE_EXT_REG |
  178. PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS;
  179. if (fsl_pcie_check_link(hose))
  180. hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
  181. }
  182. printk(KERN_INFO "Found FSL PCI host bridge at 0x%016llx. "
  183. "Firmware bus number: %d->%d\n",
  184. (unsigned long long)rsrc.start, hose->first_busno,
  185. hose->last_busno);
  186. pr_debug(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
  187. hose, hose->cfg_addr, hose->cfg_data);
  188. /* Interpret the "ranges" property */
  189. /* This also maps the I/O region and sets isa_io/mem_base */
  190. pci_process_bridge_OF_ranges(hose, dev, is_primary);
  191. /* Setup PEX window registers */
  192. setup_pci_atmu(hose, &rsrc);
  193. /* Setup PEXCSRBAR */
  194. setup_pci_pcsrbar(hose);
  195. return 0;
  196. }
  197. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8548E, quirk_fsl_pcie_header);
  198. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8548, quirk_fsl_pcie_header);
  199. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8543E, quirk_fsl_pcie_header);
  200. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8543, quirk_fsl_pcie_header);
  201. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8547E, quirk_fsl_pcie_header);
  202. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8545E, quirk_fsl_pcie_header);
  203. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8545, quirk_fsl_pcie_header);
  204. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8568E, quirk_fsl_pcie_header);
  205. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8568, quirk_fsl_pcie_header);
  206. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8567E, quirk_fsl_pcie_header);
  207. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8567, quirk_fsl_pcie_header);
  208. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8533E, quirk_fsl_pcie_header);
  209. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8533, quirk_fsl_pcie_header);
  210. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8544E, quirk_fsl_pcie_header);
  211. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8544, quirk_fsl_pcie_header);
  212. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8572E, quirk_fsl_pcie_header);
  213. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8572, quirk_fsl_pcie_header);
  214. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8536E, quirk_fsl_pcie_header);
  215. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8536, quirk_fsl_pcie_header);
  216. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8641, quirk_fsl_pcie_header);
  217. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8641D, quirk_fsl_pcie_header);
  218. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8610, quirk_fsl_pcie_header);