fsl_pci.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. #if defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_86xx)
  29. /* atmu setup for fsl pci/pcie controller */
  30. void __init setup_pci_atmu(struct pci_controller *hose, struct resource *rsrc)
  31. {
  32. struct ccsr_pci __iomem *pci;
  33. int i;
  34. pr_debug("PCI memory map start 0x%016llx, size 0x%016llx\n",
  35. (u64)rsrc->start, (u64)rsrc->end - (u64)rsrc->start + 1);
  36. pci = ioremap(rsrc->start, rsrc->end - rsrc->start + 1);
  37. /* Disable all windows (except powar0 since its ignored) */
  38. for(i = 1; i < 5; i++)
  39. out_be32(&pci->pow[i].powar, 0);
  40. for(i = 0; i < 3; i++)
  41. out_be32(&pci->piw[i].piwar, 0);
  42. /* Setup outbound MEM window */
  43. for(i = 0; i < 3; i++)
  44. if (hose->mem_resources[i].flags & IORESOURCE_MEM){
  45. resource_size_t pci_addr_start =
  46. hose->mem_resources[i].start -
  47. hose->pci_mem_offset;
  48. pr_debug("PCI MEM resource start 0x%016llx, size 0x%016llx.\n",
  49. (u64)hose->mem_resources[i].start,
  50. (u64)hose->mem_resources[i].end
  51. - (u64)hose->mem_resources[i].start + 1);
  52. out_be32(&pci->pow[i+1].potar, (pci_addr_start >> 12));
  53. out_be32(&pci->pow[i+1].potear, 0);
  54. out_be32(&pci->pow[i+1].powbar,
  55. (hose->mem_resources[i].start >> 12));
  56. /* Enable, Mem R/W */
  57. out_be32(&pci->pow[i+1].powar, 0x80044000
  58. | (__ilog2(hose->mem_resources[i].end
  59. - hose->mem_resources[i].start + 1) - 1));
  60. }
  61. /* Setup outbound IO window */
  62. if (hose->io_resource.flags & IORESOURCE_IO){
  63. pr_debug("PCI IO resource start 0x%016llx, size 0x%016llx, "
  64. "phy base 0x%016llx.\n",
  65. (u64)hose->io_resource.start,
  66. (u64)hose->io_resource.end - (u64)hose->io_resource.start + 1,
  67. (u64)hose->io_base_phys);
  68. out_be32(&pci->pow[i+1].potar, (hose->io_resource.start >> 12));
  69. out_be32(&pci->pow[i+1].potear, 0);
  70. out_be32(&pci->pow[i+1].powbar, (hose->io_base_phys >> 12));
  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 __init setup_pci_pcsrbar(struct pci_controller *hose)
  100. {
  101. #ifdef CONFIG_PCI_MSI
  102. phys_addr_t immr_base;
  103. immr_base = get_immrbase();
  104. early_write_config_dword(hose, 0, 0, PCI_BASE_ADDRESS_0, immr_base);
  105. #endif
  106. }
  107. static int fsl_pcie_bus_fixup;
  108. static void __init quirk_fsl_pcie_header(struct pci_dev *dev)
  109. {
  110. /* if we aren't a PCIe don't bother */
  111. if (!pci_find_capability(dev, PCI_CAP_ID_EXP))
  112. return ;
  113. dev->class = PCI_CLASS_BRIDGE_PCI << 8;
  114. fsl_pcie_bus_fixup = 1;
  115. return ;
  116. }
  117. int __init fsl_pcie_check_link(struct pci_controller *hose)
  118. {
  119. u32 val;
  120. early_read_config_dword(hose, 0, 0, PCIE_LTSSM, &val);
  121. if (val < PCIE_LTSSM_L0)
  122. return 1;
  123. return 0;
  124. }
  125. void fsl_pcibios_fixup_bus(struct pci_bus *bus)
  126. {
  127. struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
  128. int i;
  129. if ((bus->parent == hose->bus) &&
  130. ((fsl_pcie_bus_fixup &&
  131. early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) ||
  132. (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK)))
  133. {
  134. for (i = 0; i < 4; ++i) {
  135. struct resource *res = bus->resource[i];
  136. struct resource *par = bus->parent->resource[i];
  137. if (res) {
  138. res->start = 0;
  139. res->end = 0;
  140. res->flags = 0;
  141. }
  142. if (res && par) {
  143. res->start = par->start;
  144. res->end = par->end;
  145. res->flags = par->flags;
  146. }
  147. }
  148. }
  149. }
  150. int __init fsl_add_bridge(struct device_node *dev, int is_primary)
  151. {
  152. int len;
  153. struct pci_controller *hose;
  154. struct resource rsrc;
  155. const int *bus_range;
  156. pr_debug("Adding PCI host bridge %s\n", dev->full_name);
  157. /* Fetch host bridge registers address */
  158. if (of_address_to_resource(dev, 0, &rsrc)) {
  159. printk(KERN_WARNING "Can't get pci register base!");
  160. return -ENOMEM;
  161. }
  162. /* Get bus range if any */
  163. bus_range = of_get_property(dev, "bus-range", &len);
  164. if (bus_range == NULL || len < 2 * sizeof(int))
  165. printk(KERN_WARNING "Can't get bus-range for %s, assume"
  166. " bus 0\n", dev->full_name);
  167. ppc_pci_flags |= PPC_PCI_REASSIGN_ALL_BUS;
  168. hose = pcibios_alloc_controller(dev);
  169. if (!hose)
  170. return -ENOMEM;
  171. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  172. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  173. setup_indirect_pci(hose, rsrc.start, rsrc.start + 0x4,
  174. PPC_INDIRECT_TYPE_BIG_ENDIAN);
  175. setup_pci_cmd(hose);
  176. /* check PCI express link status */
  177. if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
  178. hose->indirect_type |= PPC_INDIRECT_TYPE_EXT_REG |
  179. PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS;
  180. if (fsl_pcie_check_link(hose))
  181. hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
  182. }
  183. printk(KERN_INFO "Found FSL PCI host bridge at 0x%016llx. "
  184. "Firmware bus number: %d->%d\n",
  185. (unsigned long long)rsrc.start, hose->first_busno,
  186. hose->last_busno);
  187. pr_debug(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
  188. hose, hose->cfg_addr, hose->cfg_data);
  189. /* Interpret the "ranges" property */
  190. /* This also maps the I/O region and sets isa_io/mem_base */
  191. pci_process_bridge_OF_ranges(hose, dev, is_primary);
  192. /* Setup PEX window registers */
  193. setup_pci_atmu(hose, &rsrc);
  194. /* Setup PEXCSRBAR */
  195. setup_pci_pcsrbar(hose);
  196. return 0;
  197. }
  198. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8548E, quirk_fsl_pcie_header);
  199. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8548, quirk_fsl_pcie_header);
  200. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8543E, quirk_fsl_pcie_header);
  201. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8543, quirk_fsl_pcie_header);
  202. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8547E, quirk_fsl_pcie_header);
  203. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8545E, quirk_fsl_pcie_header);
  204. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8545, quirk_fsl_pcie_header);
  205. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8568E, quirk_fsl_pcie_header);
  206. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8568, quirk_fsl_pcie_header);
  207. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8567E, quirk_fsl_pcie_header);
  208. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8567, quirk_fsl_pcie_header);
  209. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8533E, quirk_fsl_pcie_header);
  210. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8533, quirk_fsl_pcie_header);
  211. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8544E, quirk_fsl_pcie_header);
  212. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8544, quirk_fsl_pcie_header);
  213. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8572E, quirk_fsl_pcie_header);
  214. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8572, quirk_fsl_pcie_header);
  215. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8536E, quirk_fsl_pcie_header);
  216. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8536, quirk_fsl_pcie_header);
  217. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8641, quirk_fsl_pcie_header);
  218. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8641D, quirk_fsl_pcie_header);
  219. DECLARE_PCI_FIXUP_HEADER(0x1957, PCI_DEVICE_ID_MPC8610, quirk_fsl_pcie_header);
  220. #endif /* CONFIG_PPC_85xx || CONFIG_PPC_86xx */
  221. #if defined(CONFIG_PPC_83xx)
  222. int __init mpc83xx_add_bridge(struct device_node *dev)
  223. {
  224. int len;
  225. struct pci_controller *hose;
  226. struct resource rsrc;
  227. const int *bus_range;
  228. int primary = 1, has_address = 0;
  229. phys_addr_t immr = get_immrbase();
  230. pr_debug("Adding PCI host bridge %s\n", dev->full_name);
  231. /* Fetch host bridge registers address */
  232. has_address = (of_address_to_resource(dev, 0, &rsrc) == 0);
  233. /* Get bus range if any */
  234. bus_range = of_get_property(dev, "bus-range", &len);
  235. if (bus_range == NULL || len < 2 * sizeof(int)) {
  236. printk(KERN_WARNING "Can't get bus-range for %s, assume"
  237. " bus 0\n", dev->full_name);
  238. }
  239. ppc_pci_flags |= PPC_PCI_REASSIGN_ALL_BUS;
  240. hose = pcibios_alloc_controller(dev);
  241. if (!hose)
  242. return -ENOMEM;
  243. hose->first_busno = bus_range ? bus_range[0] : 0;
  244. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  245. /* MPC83xx supports up to two host controllers one at 0x8500 from immrbar
  246. * the other at 0x8600, we consider the 0x8500 the primary controller
  247. */
  248. /* PCI 1 */
  249. if ((rsrc.start & 0xfffff) == 0x8500) {
  250. setup_indirect_pci(hose, immr + 0x8300, immr + 0x8304, 0);
  251. }
  252. /* PCI 2 */
  253. if ((rsrc.start & 0xfffff) == 0x8600) {
  254. setup_indirect_pci(hose, immr + 0x8380, immr + 0x8384, 0);
  255. primary = 0;
  256. }
  257. printk(KERN_INFO "Found MPC83xx PCI host bridge at 0x%016llx. "
  258. "Firmware bus number: %d->%d\n",
  259. (unsigned long long)rsrc.start, hose->first_busno,
  260. hose->last_busno);
  261. pr_debug(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
  262. hose, hose->cfg_addr, hose->cfg_data);
  263. /* Interpret the "ranges" property */
  264. /* This also maps the I/O region and sets isa_io/mem_base */
  265. pci_process_bridge_OF_ranges(hose, dev, primary);
  266. return 0;
  267. }
  268. #endif /* CONFIG_PPC_83xx */