pci.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * MPC86XX pci setup code
  3. *
  4. * Recode: ZHANG WEI <wei.zhang@freescale.com>
  5. * Initial author: Xianghua Xiao <x.xiao@freescale.com>
  6. *
  7. * Copyright 2006 Freescale Semiconductor Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <linux/config.h>
  15. #include <linux/types.h>
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/pci.h>
  19. #include <linux/serial.h>
  20. #include <asm/system.h>
  21. #include <asm/atomic.h>
  22. #include <asm/io.h>
  23. #include <asm/prom.h>
  24. #include <asm/immap_86xx.h>
  25. #include <asm/pci-bridge.h>
  26. #include <sysdev/fsl_soc.h>
  27. #include "mpc86xx.h"
  28. #undef DEBUG
  29. #ifdef DEBUG
  30. #define DBG(fmt, args...) printk(KERN_ERR "%s: " fmt, __FUNCTION__, ## args)
  31. #else
  32. #define DBG(fmt, args...)
  33. #endif
  34. struct pcie_outbound_window_regs {
  35. uint pexotar; /* 0x.0 - PCI Express outbound translation address register */
  36. uint pexotear; /* 0x.4 - PCI Express outbound translation extended address register */
  37. uint pexowbar; /* 0x.8 - PCI Express outbound window base address register */
  38. char res1[4];
  39. uint pexowar; /* 0x.10 - PCI Express outbound window attributes register */
  40. char res2[12];
  41. };
  42. struct pcie_inbound_window_regs {
  43. uint pexitar; /* 0x.0 - PCI Express inbound translation address register */
  44. char res1[4];
  45. uint pexiwbar; /* 0x.8 - PCI Express inbound window base address register */
  46. uint pexiwbear; /* 0x.c - PCI Express inbound window base extended address register */
  47. uint pexiwar; /* 0x.10 - PCI Express inbound window attributes register */
  48. char res2[12];
  49. };
  50. static void __init setup_pcie_atmu(struct pci_controller *hose, struct resource *rsrc)
  51. {
  52. volatile struct ccsr_pex *pcie;
  53. volatile struct pcie_outbound_window_regs *pcieow;
  54. volatile struct pcie_inbound_window_regs *pcieiw;
  55. int i = 0;
  56. DBG("PCIE memory map start 0x%x, size 0x%x\n", rsrc->start,
  57. rsrc->end - rsrc->start + 1);
  58. pcie = ioremap(rsrc->start, rsrc->end - rsrc->start + 1);
  59. /* Disable all windows (except pexowar0 since its ignored) */
  60. pcie->pexowar1 = 0;
  61. pcie->pexowar2 = 0;
  62. pcie->pexowar3 = 0;
  63. pcie->pexowar4 = 0;
  64. pcie->pexiwar1 = 0;
  65. pcie->pexiwar2 = 0;
  66. pcie->pexiwar3 = 0;
  67. pcieow = (struct pcie_outbound_window_regs *)&pcie->pexotar1;
  68. pcieiw = (struct pcie_inbound_window_regs *)&pcie->pexitar1;
  69. /* Setup outbound MEM window */
  70. for(i = 0; i < 3; i++)
  71. if (hose->mem_resources[i].flags & IORESOURCE_MEM){
  72. DBG("PCIE MEM resource start 0x%08x, size 0x%08x.\n",
  73. hose->mem_resources[i].start,
  74. hose->mem_resources[i].end
  75. - hose->mem_resources[i].start + 1);
  76. pcieow->pexotar = (hose->mem_resources[i].start) >> 12
  77. & 0x000fffff;
  78. pcieow->pexotear = 0;
  79. pcieow->pexowbar = (hose->mem_resources[i].start) >> 12
  80. & 0x000fffff;
  81. /* Enable, Mem R/W */
  82. pcieow->pexowar = 0x80044000 |
  83. (__ilog2(hose->mem_resources[i].end
  84. - hose->mem_resources[i].start + 1)
  85. - 1);
  86. pcieow++;
  87. }
  88. /* Setup outbound IO window */
  89. if (hose->io_resource.flags & IORESOURCE_IO){
  90. DBG("PCIE IO resource start 0x%08x, size 0x%08x, phy base 0x%08x.\n",
  91. hose->io_resource.start,
  92. hose->io_resource.end - hose->io_resource.start + 1,
  93. hose->io_base_phys);
  94. pcieow->pexotar = (hose->io_resource.start) >> 12 & 0x000fffff;
  95. pcieow->pexotear = 0;
  96. pcieow->pexowbar = (hose->io_base_phys) >> 12 & 0x000fffff;
  97. /* Enable, IO R/W */
  98. pcieow->pexowar = 0x80088000 | (__ilog2(hose->io_resource.end
  99. - hose->io_resource.start + 1) - 1);
  100. }
  101. /* Setup 2G inbound Memory Window @ 0 */
  102. pcieiw->pexitar = 0x00000000;
  103. pcieiw->pexiwbar = 0x00000000;
  104. /* Enable, Prefetch, Local Mem, Snoop R/W, 2G */
  105. pcieiw->pexiwar = 0xa0f5501e;
  106. }
  107. static void __init
  108. mpc86xx_setup_pcie(struct pci_controller *hose, u32 pcie_offset, u32 pcie_size)
  109. {
  110. u16 cmd;
  111. unsigned int temps;
  112. DBG("PCIE host controller register offset 0x%08x, size 0x%08x.\n",
  113. pcie_offset, pcie_size);
  114. early_read_config_word(hose, 0, 0, PCI_COMMAND, &cmd);
  115. cmd |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY
  116. | PCI_COMMAND_IO;
  117. early_write_config_word(hose, 0, 0, PCI_COMMAND, cmd);
  118. early_write_config_byte(hose, 0, 0, PCI_LATENCY_TIMER, 0x80);
  119. /* PCIE Bus, Fix the MPC8641D host bridge's location to bus 0xFF. */
  120. early_read_config_dword(hose, 0, 0, PCI_PRIMARY_BUS, &temps);
  121. temps = (temps & 0xff000000) | (0xff) | (0x0 << 8) | (0xfe << 16);
  122. early_write_config_dword(hose, 0, 0, PCI_PRIMARY_BUS, temps);
  123. }
  124. int mpc86xx_exclude_device(u_char bus, u_char devfn)
  125. {
  126. if (bus == 0 && PCI_SLOT(devfn) == 0)
  127. return PCIBIOS_DEVICE_NOT_FOUND;
  128. return PCIBIOS_SUCCESSFUL;
  129. }
  130. int __init add_bridge(struct device_node *dev)
  131. {
  132. int len;
  133. struct pci_controller *hose;
  134. struct resource rsrc;
  135. int *bus_range;
  136. int has_address = 0;
  137. int primary = 0;
  138. DBG("Adding PCIE host bridge %s\n", dev->full_name);
  139. /* Fetch host bridge registers address */
  140. has_address = (of_address_to_resource(dev, 0, &rsrc) == 0);
  141. /* Get bus range if any */
  142. bus_range = (int *) 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. hose = pcibios_alloc_controller();
  147. if (!hose)
  148. return -ENOMEM;
  149. hose->arch_data = dev;
  150. hose->set_cfg_type = 1;
  151. /* last_busno = 0xfe cause by MPC8641 PCIE bug */
  152. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  153. hose->last_busno = bus_range ? bus_range[1] : 0xfe;
  154. setup_indirect_pcie(hose, rsrc.start, rsrc.start + 0x4);
  155. /* Setup the PCIE host controller. */
  156. mpc86xx_setup_pcie(hose, rsrc.start, rsrc.end - rsrc.start + 1);
  157. if ((rsrc.start & 0xfffff) == 0x8000)
  158. primary = 1;
  159. printk(KERN_INFO "Found MPC86xx PCIE host bridge at 0x%08lx. "
  160. "Firmware bus number: %d->%d\n",
  161. rsrc.start, hose->first_busno, hose->last_busno);
  162. DBG(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
  163. hose, hose->cfg_addr, hose->cfg_data);
  164. /* Interpret the "ranges" property */
  165. /* This also maps the I/O region and sets isa_io/mem_base */
  166. pci_process_bridge_OF_ranges(hose, dev, primary);
  167. /* Setup PEX window registers */
  168. setup_pcie_atmu(hose, &rsrc);
  169. return 0;
  170. }