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